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