1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15@Entry
16@Component
17struct runMetrics1 {
18  @State AvgCharWidth: number = 0
19  @State MaxCharWidth: number = 0
20  @State XMin: number = 0
21  @State XMax: number = 0
22  @State XHeight: number = 0
23  @State Width: number = 0
24  @State CapHeight: number = 0
25  @State UnderlineThickness: number = 0
26  @State UnderlinePosition: number = 0
27  @State StrikethroughThickness: number = 0
28  @State StrikethroughPosition: number = 0
29  @State text: string = '点击'
30  controller: TextController = new TextController()
31  @State textStr: string = 'qwertyu'
32
33  build() {
34    Column() {
35      Text(this.textStr, { controller: this.controller })
36      Text(this.AvgCharWidth + '').id('runMetrics_1')
37      Text(this.MaxCharWidth + '').id('runMetrics_2')
38      Text(this.XMin + '').id('runMetrics_3')
39      Text(this.XMax + '').id('runMetrics_4')
40      Text(this.XHeight + '').id('runMetrics_5')
41      Text(this.CapHeight + '').id('runMetrics_6')
42      Text(this.UnderlineThickness + '').id('runMetrics_7')
43      Text(this.UnderlinePosition + '').id('runMetrics_8')
44      Text(this.StrikethroughThickness + '').id('runMetrics_9')
45      Text(this.StrikethroughPosition + '').id('runMetrics_10')
46      Button('runMetrics')
47        .id('runMetrics_11')
48        .onClick(() => {
49        let layoutManager: LayoutManager = this.controller.getLayoutManager()
50        let lineMetrics = layoutManager.getLineMetrics(0)
51        console.log('aaa', JSON.stringify(lineMetrics))
52        let runMetrics1 = lineMetrics.runMetrics
53        runMetrics1.forEach((key, value) => {
54          key.fontMetrics.avgCharWidth = 10
55          this.AvgCharWidth = key.fontMetrics.avgCharWidth
56          key.fontMetrics.maxCharWidth = 59
57          this.MaxCharWidth = key.fontMetrics.maxCharWidth
58          key.fontMetrics.xMin = -10
59          this.XMin = key.fontMetrics.xMin
60          key.fontMetrics.xMax = 50
61          this.XMax = key.fontMetrics.xMax
62          key.fontMetrics.xHeight = 10
63          this.XHeight = key.fontMetrics.xHeight
64          key.fontMetrics.capHeight = 15
65          this.CapHeight = key.fontMetrics.capHeight
66          key.fontMetrics.underlineThickness = 1
67          this.UnderlineThickness = key.fontMetrics.underlineThickness
68          key.fontMetrics.underlinePosition = 5
69          this.UnderlinePosition = key.fontMetrics.underlinePosition
70          key.fontMetrics.strikethroughThickness = 1
71          this.StrikethroughThickness = key.fontMetrics.strikethroughThickness
72          key.fontMetrics.strikethroughPosition = -5
73          this.StrikethroughPosition = key.fontMetrics.strikethroughPosition
74          console.info('key', key)
75          console.info('key1', JSON.stringify(key))
76        })
77      })
78    }
79    .width('100%')
80    .height('100%')
81  }
82}