• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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
16/// <reference path="../component/units.d.ts" />
17
18import { Resource } from 'GlobalResource';
19
20/**
21 * Defines the options of MeasureText.
22 *
23 * @interface MeasureOptions
24 * @syscap SystemCapability.ArkUI.ArkUI.Full
25 * @since 9
26 */
27export interface MeasureOptions {
28  /**
29   * Text to display.
30   *
31   * @type { string | Resource }
32   * @syscap SystemCapability.ArkUI.ArkUI.Full
33   * @since 9
34   */
35  /**
36   * Text to display.
37   *
38   * @type { string | Resource }
39   * @syscap SystemCapability.ArkUI.ArkUI.Full
40   * @since 10
41   */
42  textContent: string | Resource;
43
44  /**
45   * Text display area of width.
46   *
47   * @type { ?(number | string | Resource) }
48   * @syscap SystemCapability.ArkUI.ArkUI.Full
49   * @since 10
50   */
51  constraintWidth?: number | string | Resource;
52
53  /**
54   * Font Size.
55   *
56   * @type { ?(number | string | Resource) }
57   * @syscap SystemCapability.ArkUI.ArkUI.Full
58   * @since 9
59   */
60  fontSize?: number | string | Resource;
61
62  /**
63   * Font style.
64   *
65   * @type { ?(number | FontStyle) }
66   * @syscap SystemCapability.ArkUI.ArkUI.Full
67   * @since 9
68   */
69  fontStyle?: number | FontStyle;
70
71  /**
72   * Font weight.
73   *
74   * @type { ?(number | string | FontWeight) }
75   * @syscap SystemCapability.ArkUI.ArkUI.Full
76   * @since 9
77   */
78  fontWeight?: number | string | FontWeight;
79
80  /**
81   * Font list of text.
82   *
83   * @type { ?(string | Resource) }
84   * @syscap SystemCapability.ArkUI.ArkUI.Full
85   * @since 9
86   */
87  fontFamily?: string | Resource;
88
89  /**
90   * Distance between text fonts.
91   *
92   * @type { ?(number | string) }
93   * @syscap SystemCapability.ArkUI.ArkUI.Full
94   * @since 9
95   */
96  letterSpacing?: number | string;
97
98  /**
99   * Alignment of text.
100   *
101   * @type { ?(number | TextAlign) }
102   * @syscap SystemCapability.ArkUI.ArkUI.Full
103   * @since 10
104   */
105  textAlign?: number | TextAlign;
106
107  /**
108   * Overflow mode of the font.
109   *
110   * @type { ?(number | TextOverflow) }
111   * @syscap SystemCapability.ArkUI.ArkUI.Full
112   * @since 10
113   */
114  overflow?: number | TextOverflow;
115
116  /**
117   * Maximum number of lines of text.
118   *
119   * @type { ?number }
120   * @syscap SystemCapability.ArkUI.ArkUI.Full
121   * @since 10
122   */
123  maxLines?: number;
124
125  /**
126   * Vertical center mode of the font.
127   *
128   * @type { ?(number | string | Resource) }
129   * @syscap SystemCapability.ArkUI.ArkUI.Full
130   * @since 10
131   */
132  lineHeight?: number | string | Resource;
133
134  /**
135   * Baseline offset.
136   *
137   * @type { ?(number | string) }
138   * @syscap SystemCapability.ArkUI.ArkUI.Full
139   * @since 10
140   */
141  baselineOffset?: number | string;
142
143  /**
144   * Type of letter in the text font
145   *
146   * @type { ?(number | TextCase) }
147   * @syscap SystemCapability.ArkUI.ArkUI.Full
148   * @since 10
149   */
150  textCase?: number | TextCase;
151}
152
153/**
154 * Defines the Measure interface.
155 *
156 * @syscap SystemCapability.ArkUI.ArkUI.Full
157 * @since 9
158 */
159export default class MeasureText {
160  /**
161   * Displays the textWidth.
162   *
163   * @param { MeasureOptions } options - Options.
164   * @returns { number }
165   * @syscap SystemCapability.ArkUI.ArkUI.Full
166   * @since 9
167   */
168  static measureText(options: MeasureOptions): number;
169
170  /**
171   * Displays the text width and height.
172   *
173   * @param { MeasureOptions } options - Options of measure area occupied by text.
174   * @returns { SizeOptions } width and height for text to display \
175   * @syscap SystemCapability.ArkUI.ArkUI.Full
176   * @since 10
177   */
178  static measureTextSize(options: MeasureOptions): SizeOptions;
179}
180