• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 lineMetrics2 {
18  @State startIndexA: number = 0
19  @State endIndexA: number = 0
20  @State ascentA: number = 0
21  @State descentA: number = 0
22  @State heightA: number = 0
23  @State widthA: number = 0
24  @State leftA: number = 0
25  @State baselineA: number = 0
26  @State lineNumberA: number = 0
27  @State topHeightA: number = 0
28  @State flags: 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.startIndexA + '').id('LineMetrics_1')
37      Text(this.endIndexA + '').id('LineMetrics_2')
38      Text(this.topHeightA + '').id('LineMetrics_3')
39      Text(this.ascentA + '').id('LineMetrics_5')
40      Text(this.descentA + '').id('LineMetrics_6')
41      Text(this.heightA + '').id('LineMetrics_7')
42      Text(this.widthA + '').id('LineMetrics_8')
43      Text(this.leftA + '').id('LineMetrics_9')
44      Text(this.baselineA + '').id('LineMetrics_10')
45      Text(this.lineNumberA + '').id('LineMetrics_11')
46      Button('getLineMetrics(1)')
47      .id('LineMetrics_4')
48      .onClick(() => {
49        let layoutManager: LayoutManager = this.controller.getLayoutManager()
50        let lineMetrics = layoutManager.getLineMetrics(0)
51        lineMetrics.startIndex = 1
52        this.startIndexA = Math.round(lineMetrics.startIndex)
53        lineMetrics.endIndex = 7
54        this.endIndexA = Math.round(lineMetrics.endIndex)
55        lineMetrics.topHeight = 10
56        this.topHeightA = Math.round(lineMetrics.topHeight)
57        lineMetrics.ascent = 5
58        this.ascentA = Math.round(lineMetrics.ascent)
59        lineMetrics.descent = 6
60        this.descentA = Math.round(lineMetrics.descent)
61        lineMetrics.height = 6
62        this.heightA = Math.round(lineMetrics.height)
63        lineMetrics.width = 6
64        this.widthA = Math.round(lineMetrics.width)
65        lineMetrics.left = 6
66        this.leftA = Math.round(lineMetrics.left)
67        lineMetrics.baseline = 6
68        this.baselineA = Math.round(lineMetrics.baseline)
69        lineMetrics.lineNumber = 6
70        this.lineNumberA = Math.round(lineMetrics.lineNumber)
71        console.log('aaa_1',JSON.stringify(lineMetrics))
72      })
73    }
74    .width('100%')
75    .height('100%')
76  }
77}