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 lineMetrics1 { 18 @State StartIndex: number = 0 19 @State EndIndex: number = 0 20 @State Ascent: number = 0 21 @State Descent: number = 0 22 @State Height: number = 0 23 @State Width: number = 0 24 @State Left: number = 0 25 @State Baseline: number = 0 26 @State LineNumber: number = 0 27 @State TopHeight: 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.StartIndex + '').id('LineMetrics_1') 37 Text(this.EndIndex + '').id('LineMetrics_2') 38 Text(this.TopHeight + '').id('LineMetrics_3') 39 Button('getLineMetrics(1)') 40 .id('LineMetrics_4') 41 .onClick(() => { 42 let layoutManager: LayoutManager = this.controller.getLayoutManager() 43 let lineMetrics = layoutManager.getLineMetrics(0) 44 lineMetrics.startIndex = 1 45 this.StartIndex = Math.round(lineMetrics.startIndex) 46 lineMetrics.endIndex = 7 47 this.EndIndex = Math.round(lineMetrics.endIndex) 48 lineMetrics.topHeight = 10 49 this.TopHeight = Math.round(lineMetrics.topHeight) 50 console.log('aaa_1',JSON.stringify(lineMetrics)) 51 }) 52 } 53 .width('100%') 54 .height('100%') 55 } 56}