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/** 17 * @file 18 * @kit ArkUI 19 */ 20 21/// <reference path="../component/units.d.ts" /> 22 23import { Resource } from 'GlobalResource'; 24 25/** 26 * Defines the options of MeasureText. 27 * 28 * @interface MeasureOptions 29 * @syscap SystemCapability.ArkUI.ArkUI.Full 30 * @since 9 31 */ 32/** 33 * Defines the options of MeasureText. 34 * 35 * @interface MeasureOptions 36 * @syscap SystemCapability.ArkUI.ArkUI.Full 37 * @crossplatform 38 * @since 11 39 */ 40/** 41 * Defines the options of MeasureText. 42 * 43 * @interface MeasureOptions 44 * @syscap SystemCapability.ArkUI.ArkUI.Full 45 * @crossplatform 46 * @atomicservice 47 * @since 12 48 */ 49export interface MeasureOptions { 50 /** 51 * Text to display. 52 * 53 * @type { string | Resource } 54 * @syscap SystemCapability.ArkUI.ArkUI.Full 55 * @since 9 56 */ 57 /** 58 * Text to display. 59 * 60 * @type { string | Resource } 61 * @syscap SystemCapability.ArkUI.ArkUI.Full 62 * @since 10 63 */ 64 /** 65 * Text to display. 66 * 67 * @type { string | Resource } 68 * @syscap SystemCapability.ArkUI.ArkUI.Full 69 * @crossplatform 70 * @atomicservice 71 * @since 12 72 */ 73 textContent: string | Resource; 74 75 /** 76 * Text display area of width. 77 * 78 * @type { ?(number | string | Resource) } 79 * @syscap SystemCapability.ArkUI.ArkUI.Full 80 * @since 10 81 */ 82 /** 83 * Text display area of width. 84 * 85 * @type { ?(number | string | Resource) } 86 * @syscap SystemCapability.ArkUI.ArkUI.Full 87 * @crossplatform 88 * @atomicservice 89 * @since 12 90 */ 91 constraintWidth?: number | string | Resource; 92 93 /** 94 * Font Size. 95 * 96 * @type { ?(number | string | Resource) } 97 * @syscap SystemCapability.ArkUI.ArkUI.Full 98 * @since 9 99 */ 100 /** 101 * Font Size. 102 * 103 * @type { ?(number | string | Resource) } 104 * @syscap SystemCapability.ArkUI.ArkUI.Full 105 * @crossplatform 106 * @atomicservice 107 * @since 12 108 */ 109 fontSize?: number | string | Resource; 110 111 /** 112 * Font style. 113 * 114 * @type { ?(number | FontStyle) } 115 * @syscap SystemCapability.ArkUI.ArkUI.Full 116 * @since 9 117 */ 118 /** 119 * Font style. 120 * 121 * @type { ?(number | FontStyle) } 122 * @syscap SystemCapability.ArkUI.ArkUI.Full 123 * @crossplatform 124 * @atomicservice 125 * @since 12 126 */ 127 fontStyle?: number | FontStyle; 128 129 /** 130 * Font weight. 131 * 132 * @type { ?(number | string | FontWeight) } 133 * @syscap SystemCapability.ArkUI.ArkUI.Full 134 * @since 9 135 */ 136 /** 137 * Font weight. 138 * 139 * @type { ?(number | string | FontWeight) } 140 * @syscap SystemCapability.ArkUI.ArkUI.Full 141 * @crossplatform 142 * @atomicservice 143 * @since 12 144 */ 145 fontWeight?: number | string | FontWeight; 146 147 /** 148 * Font list of text. 149 * 150 * @type { ?(string | Resource) } 151 * @syscap SystemCapability.ArkUI.ArkUI.Full 152 * @since 9 153 */ 154 /** 155 * Font list of text. 156 * 157 * @type { ?(string | Resource) } 158 * @syscap SystemCapability.ArkUI.ArkUI.Full 159 * @crossplatform 160 * @atomicservice 161 * @since 12 162 */ 163 fontFamily?: string | Resource; 164 165 /** 166 * Distance between text fonts. 167 * 168 * @type { ?(number | string) } 169 * @syscap SystemCapability.ArkUI.ArkUI.Full 170 * @since 9 171 */ 172 /** 173 * Distance between text fonts. 174 * 175 * @type { ?(number | string) } 176 * @syscap SystemCapability.ArkUI.ArkUI.Full 177 * @crossplatform 178 * @atomicservice 179 * @since 12 180 */ 181 letterSpacing?: number | string; 182 183 /** 184 * Alignment of text. 185 * 186 * @type { ?(number | TextAlign) } 187 * @syscap SystemCapability.ArkUI.ArkUI.Full 188 * @since 10 189 */ 190 /** 191 * Alignment of text. 192 * 193 * @type { ?(number | TextAlign) } 194 * @syscap SystemCapability.ArkUI.ArkUI.Full 195 * @crossplatform 196 * @atomicservice 197 * @since 12 198 */ 199 textAlign?: number | TextAlign; 200 201 /** 202 * Overflow mode of the font. 203 * 204 * @type { ?(number | TextOverflow) } 205 * @syscap SystemCapability.ArkUI.ArkUI.Full 206 * @since 10 207 */ 208 /** 209 * Overflow mode of the font. 210 * 211 * @type { ?(number | TextOverflow) } 212 * @syscap SystemCapability.ArkUI.ArkUI.Full 213 * @crossplatform 214 * @atomicservice 215 * @since 12 216 */ 217 overflow?: number | TextOverflow; 218 219 /** 220 * Maximum number of lines of text. 221 * 222 * @type { ?number } 223 * @syscap SystemCapability.ArkUI.ArkUI.Full 224 * @since 10 225 */ 226 /** 227 * Maximum number of lines of text. 228 * 229 * @type { ?number } 230 * @syscap SystemCapability.ArkUI.ArkUI.Full 231 * @crossplatform 232 * @atomicservice 233 * @since 12 234 */ 235 maxLines?: number; 236 237 /** 238 * Vertical center mode of the font. 239 * 240 * @type { ?(number | string | Resource) } 241 * @syscap SystemCapability.ArkUI.ArkUI.Full 242 * @since 10 243 */ 244 /** 245 * Vertical center mode of the font. 246 * 247 * @type { ?(number | string | Resource) } 248 * @syscap SystemCapability.ArkUI.ArkUI.Full 249 * @crossplatform 250 * @atomicservice 251 * @since 12 252 */ 253 lineHeight?: number | string | Resource; 254 255 /** 256 * Baseline offset. 257 * 258 * @type { ?(number | string) } 259 * @syscap SystemCapability.ArkUI.ArkUI.Full 260 * @since 10 261 */ 262 /** 263 * Baseline offset. 264 * 265 * @type { ?(number | string) } 266 * @syscap SystemCapability.ArkUI.ArkUI.Full 267 * @crossplatform 268 * @atomicservice 269 * @since 12 270 */ 271 baselineOffset?: number | string; 272 273 /** 274 * Type of letter in the text font 275 * 276 * @type { ?(number | TextCase) } 277 * @syscap SystemCapability.ArkUI.ArkUI.Full 278 * @since 10 279 */ 280 /** 281 * Type of letter in the text font 282 * 283 * @type { ?(number | TextCase) } 284 * @syscap SystemCapability.ArkUI.ArkUI.Full 285 * @crossplatform 286 * @atomicservice 287 * @since 12 288 */ 289 textCase?: number | TextCase; 290 291 /** 292 * Specify the indentation of the first line in a text-block. 293 * 294 * @type { ?(number | string) } 295 * @syscap SystemCapability.ArkUI.ArkUI.Full 296 * @crossplatform 297 * @since 11 298 */ 299 /** 300 * Specify the indentation of the first line in a text-block. 301 * 302 * @type { ?(number | string) } 303 * @syscap SystemCapability.ArkUI.ArkUI.Full 304 * @crossplatform 305 * @atomicservice 306 * @since 12 307 */ 308 textIndent?: number | string; 309 310 /** 311 * Set the word break type. 312 * 313 * @type { ?WordBreak } 314 * @syscap SystemCapability.ArkUI.ArkUI.Full 315 * @crossplatform 316 * @since 11 317 */ 318 /** 319 * Set the word break type. 320 * 321 * @type { ?WordBreak } 322 * @syscap SystemCapability.ArkUI.ArkUI.Full 323 * @crossplatform 324 * @atomicservice 325 * @since 12 326 */ 327 wordBreak?: WordBreak; 328} 329 330/** 331 * Defines the Measure interface. 332 * 333 * @syscap SystemCapability.ArkUI.ArkUI.Full 334 * @since 9 335 */ 336/** 337 * Defines the Measure interface. 338 * 339 * @syscap SystemCapability.ArkUI.ArkUI.Full 340 * @crossplatform 341 * @atomicservice 342 * @since 12 343 */ 344export default class MeasureText { 345 /** 346 * Displays the textWidth. 347 * 348 * @param { MeasureOptions } options - Options. 349 * @returns { number } 350 * @syscap SystemCapability.ArkUI.ArkUI.Full 351 * @since 9 352 */ 353 /** 354 * Displays the textWidth. 355 * 356 * @param { MeasureOptions } options - Options. 357 * @returns { number } 358 * @syscap SystemCapability.ArkUI.ArkUI.Full 359 * @crossplatform 360 * @since 11 361 */ 362 /** 363 * Displays the textWidth. 364 * 365 * @param { MeasureOptions } options - Options. 366 * @returns { number } 367 * @syscap SystemCapability.ArkUI.ArkUI.Full 368 * @crossplatform 369 * @atomicservice 370 * @since 12 371 */ 372 static measureText(options: MeasureOptions): number; 373 374 /** 375 * Displays the text width and height. 376 * 377 * @param { MeasureOptions } options - Options of measure area occupied by text. 378 * @returns { SizeOptions } width and height for text to display \ 379 * @syscap SystemCapability.ArkUI.ArkUI.Full 380 * @since 10 381 */ 382 /** 383 * Displays the text width and height. 384 * 385 * @param { MeasureOptions } options - Options of measure area occupied by text. 386 * @returns { SizeOptions } width and height for text to display \ 387 * @syscap SystemCapability.ArkUI.ArkUI.Full 388 * @crossplatform 389 * @since 11 390 */ 391 /** 392 * Displays the text width and height. 393 * 394 * @param { MeasureOptions } options - Options of measure area occupied by text. 395 * @returns { SizeOptions } width and height for text to display \ 396 * @syscap SystemCapability.ArkUI.ArkUI.Full 397 * @crossplatform 398 * @atomicservice 399 * @since 12 400 */ 401 static measureTextSize(options: MeasureOptions): SizeOptions; 402} 403