@visactor/vrender-core 0.21.0-alpha.3 → 0.21.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/cjs/common/3d-interceptor.js +1 -2
  2. package/cjs/common/bounds-context.js +2 -1
  3. package/cjs/common/morphing-utils.js +1 -1
  4. package/cjs/common/path-svg.js +1 -1
  5. package/cjs/common/polygon.js +2 -2
  6. package/cjs/common/rect-utils.js +1 -1
  7. package/cjs/common/render-area.js +1 -1
  8. package/cjs/common/render-command-list.js +1 -2
  9. package/cjs/common/render-curve.js +1 -1
  10. package/cjs/common/render-utils.js +1 -1
  11. package/cjs/common/seg-context.js +1 -1
  12. package/cjs/common/simplify.js +1 -1
  13. package/cjs/common/sort.js +1 -1
  14. package/cjs/common/split-path.js +1 -1
  15. package/cjs/common/store.js +1 -1
  16. package/cjs/common/text.js.map +1 -1
  17. package/cjs/core/application.js +2 -1
  18. package/cjs/core/camera.js +1 -1
  19. package/cjs/core/constants.js +1 -1
  20. package/cjs/core/contributions/textMeasure/AtextMeasure.d.ts +4 -55
  21. package/cjs/core/contributions/textMeasure/AtextMeasure.js +13 -92
  22. package/cjs/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
  23. package/cjs/core/contributions/textMeasure/layout.d.ts +1 -0
  24. package/cjs/core/contributions/textMeasure/layout.js +30 -20
  25. package/cjs/core/contributions/textMeasure/layout.js.map +1 -1
  26. package/cjs/core/core-modules.js +1 -1
  27. package/cjs/core/global-module.js +2 -0
  28. package/cjs/core/global.js +1 -1
  29. package/cjs/core/graphic-utils.js +1 -1
  30. package/cjs/core/index.js +1 -1
  31. package/cjs/core/layer-service.js +1 -1
  32. package/cjs/core/layer.js +1 -1
  33. package/cjs/core/light.js +1 -1
  34. package/cjs/core/stage.js +1 -1
  35. package/cjs/core/window.js +1 -1
  36. package/cjs/graphic/config.js +0 -1
  37. package/cjs/graphic/config.js.map +1 -1
  38. package/cjs/graphic/text.d.ts +11 -10
  39. package/cjs/graphic/text.js +174 -91
  40. package/cjs/graphic/text.js.map +1 -1
  41. package/cjs/graphic/wrap-text.js +4 -12
  42. package/cjs/graphic/wrap-text.js.map +1 -1
  43. package/cjs/interface/graphic/text.d.ts +3 -3
  44. package/cjs/interface/graphic/text.js.map +1 -1
  45. package/cjs/interface/text.d.ts +1 -6
  46. package/cjs/interface/text.js.map +1 -1
  47. package/cjs/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
  48. package/cjs/render/contributions/render/contributions/image-contribution-render.js +3 -2
  49. package/cjs/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
  50. package/cjs/render/contributions/render/image-render.js +6 -4
  51. package/cjs/render/contributions/render/image-render.js.map +1 -1
  52. package/cjs/render/contributions/render/text-render.js +23 -1
  53. package/cjs/render/contributions/render/text-render.js.map +1 -1
  54. package/cjs/resource-loader/loader.js +1 -1
  55. package/cjs/resource-loader/loader.js.map +1 -1
  56. package/dist/index.es.js +431 -340
  57. package/es/common/3d-interceptor.js +1 -2
  58. package/es/common/bounds-context.js +2 -1
  59. package/es/common/morphing-utils.js +1 -1
  60. package/es/common/path-svg.js +1 -1
  61. package/es/common/polygon.js +1 -1
  62. package/es/common/rect-utils.js +1 -1
  63. package/es/common/render-area.js +1 -1
  64. package/es/common/render-command-list.js +1 -2
  65. package/es/common/render-curve.js +1 -1
  66. package/es/common/render-utils.js +1 -1
  67. package/es/common/seg-context.js +1 -1
  68. package/es/common/simplify.js +1 -1
  69. package/es/common/sort.js +1 -1
  70. package/es/common/split-path.js +1 -1
  71. package/es/common/store.js +1 -1
  72. package/es/common/text.js.map +1 -1
  73. package/es/core/application.js +2 -1
  74. package/es/core/camera.js +1 -1
  75. package/es/core/constants.js +1 -1
  76. package/es/core/contributions/textMeasure/AtextMeasure.d.ts +4 -55
  77. package/es/core/contributions/textMeasure/AtextMeasure.js +13 -92
  78. package/es/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
  79. package/es/core/contributions/textMeasure/layout.d.ts +1 -0
  80. package/es/core/contributions/textMeasure/layout.js +30 -20
  81. package/es/core/contributions/textMeasure/layout.js.map +1 -1
  82. package/es/core/core-modules.js +1 -1
  83. package/es/core/global-module.js +2 -0
  84. package/es/core/global.js +1 -1
  85. package/es/core/graphic-utils.js +1 -1
  86. package/es/core/index.js +1 -1
  87. package/es/core/layer-service.js +1 -1
  88. package/es/core/layer.js +1 -1
  89. package/es/core/light.js +1 -1
  90. package/es/core/stage.js +1 -1
  91. package/es/core/window.js +1 -1
  92. package/es/graphic/config.js +0 -1
  93. package/es/graphic/config.js.map +1 -1
  94. package/es/graphic/text.d.ts +11 -10
  95. package/es/graphic/text.js +169 -90
  96. package/es/graphic/text.js.map +1 -1
  97. package/es/graphic/wrap-text.js +4 -12
  98. package/es/graphic/wrap-text.js.map +1 -1
  99. package/es/interface/graphic/text.d.ts +3 -3
  100. package/es/interface/graphic/text.js.map +1 -1
  101. package/es/interface/text.d.ts +1 -6
  102. package/es/interface/text.js.map +1 -1
  103. package/es/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
  104. package/es/render/contributions/render/contributions/image-contribution-render.js +3 -2
  105. package/es/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
  106. package/es/render/contributions/render/image-render.js +6 -4
  107. package/es/render/contributions/render/image-render.js.map +1 -1
  108. package/es/render/contributions/render/text-render.js +23 -1
  109. package/es/render/contributions/render/text-render.js.map +1 -1
  110. package/es/resource-loader/loader.js +1 -1
  111. package/es/resource-loader/loader.js.map +1 -1
  112. package/package.json +2 -2
  113. package/cjs/graphic/text2.d.ts +0 -81
  114. package/cjs/graphic/text2.js +0 -288
  115. package/cjs/graphic/text2.js.map +0 -1
  116. package/es/graphic/text2.d.ts +0 -81
  117. package/es/graphic/text2.js +0 -293
  118. package/es/graphic/text2.js.map +0 -1
package/dist/index.es.js CHANGED
@@ -3016,7 +3016,6 @@ const DefaultStrokeStyle = Object.assign({ outerBorder: Object.assign(Object.ass
3016
3016
  const DefaultTextStyle = {
3017
3017
  text: '',
3018
3018
  maxLineWidth: Infinity,
3019
- maxWidth: Infinity,
3020
3019
  textAlign: 'left',
3021
3020
  textBaseline: 'alphabetic',
3022
3021
  fontSize: 16,
@@ -3250,33 +3249,13 @@ let ATextMeasure = class ATextMeasure {
3250
3249
  this.context = service.context;
3251
3250
  service.bindTextMeasure(this);
3252
3251
  }
3253
- _measureTextWithoutAlignBaseline(text, options, compatible) {
3252
+ measureTextWidth(text, options) {
3253
+ if (!this.context) {
3254
+ return this.estimate(text, options).width;
3255
+ }
3254
3256
  this.context.setTextStyleWithoutAlignBaseline(options);
3255
- const metrics = this.context.measureText(text);
3256
- return compatible ? this.compatibleMetrics(metrics, options) : metrics;
3257
- }
3258
- _measureTextWithAlignBaseline(text, options, compatible) {
3259
- this.context.setTextStyle(options);
3260
- const metrics = this.context.measureText(text);
3261
- return compatible ? this.compatibleMetrics(metrics, options) : metrics;
3262
- }
3263
- compatibleMetrics(metrics, options) {
3264
- if (metrics.actualBoundingBoxAscent == null ||
3265
- metrics.actualBoundingBoxDescent == null ||
3266
- metrics.fontBoundingBoxAscent == null ||
3267
- metrics.fontBoundingBoxDescent == null) {
3268
- const { ascent, descent } = this.measureTextBoundADscentEstimate(options);
3269
- metrics.actualBoundingBoxAscent = ascent;
3270
- metrics.actualBoundingBoxDescent = descent;
3271
- metrics.fontBoundingBoxAscent = ascent;
3272
- metrics.fontBoundingBoxDescent = descent;
3273
- }
3274
- if (metrics.actualBoundingBoxLeft == null || metrics.actualBoundingBoxRight == null) {
3275
- const { left, right } = this.measureTextBoundLeftRightEstimate(options);
3276
- metrics.actualBoundingBoxLeft = left;
3277
- metrics.actualBoundingBoxRight = right;
3278
- }
3279
- return metrics;
3257
+ const textMeasure = this.context.measureText(text);
3258
+ return textMeasure.width;
3280
3259
  }
3281
3260
  estimate(text, { fontSize = DefaultTextAttribute.fontSize }) {
3282
3261
  let eCharLen = 0;
@@ -3289,125 +3268,24 @@ let ATextMeasure = class ATextMeasure {
3289
3268
  height: fontSize
3290
3269
  };
3291
3270
  }
3292
- measureTextWidth(text, options, textMeasure) {
3293
- if (!this.context) {
3294
- return this.estimate(text, options).width;
3295
- }
3296
- textMeasure = textMeasure !== null && textMeasure !== void 0 ? textMeasure : this._measureTextWithoutAlignBaseline(text, options);
3297
- return textMeasure.width;
3298
- }
3299
- measureTextBoundsWidth(text, options, textMeasure) {
3300
- if (!this.context) {
3301
- return this.estimate(text, options).width;
3302
- }
3303
- textMeasure = textMeasure !== null && textMeasure !== void 0 ? textMeasure : this._measureTextWithoutAlignBaseline(text, options);
3304
- return textMeasure.width;
3305
- }
3306
- measureTextBoundsLeftRight(text, options, textMeasure) {
3307
- if (!this.context) {
3308
- return this.measureTextBoundLeftRightEstimate(options);
3309
- }
3310
- textMeasure = textMeasure !== null && textMeasure !== void 0 ? textMeasure : this._measureTextWithAlignBaseline(text, options, true);
3311
- return {
3312
- left: textMeasure.actualBoundingBoxLeft,
3313
- right: textMeasure.actualBoundingBoxRight
3314
- };
3315
- }
3316
- measureTextPixelHeight(text, options, textMeasure) {
3271
+ measureTextPixelHeight(text, options) {
3317
3272
  var _a;
3318
3273
  if (!this.context) {
3319
3274
  return (_a = options.fontSize) !== null && _a !== void 0 ? _a : DefaultTextStyle.fontSize;
3320
3275
  }
3321
- textMeasure = textMeasure !== null && textMeasure !== void 0 ? textMeasure : this._measureTextWithoutAlignBaseline(text, options, true);
3276
+ this.context.setTextStyleWithoutAlignBaseline(options);
3277
+ const textMeasure = this.context.measureText(text);
3322
3278
  return Math.abs(textMeasure.actualBoundingBoxAscent - textMeasure.actualBoundingBoxDescent);
3323
3279
  }
3324
- measureTextPixelADscent(text, options, textMeasure) {
3325
- if (!this.context) {
3326
- return this.measureTextBoundADscentEstimate(options);
3327
- }
3328
- textMeasure = textMeasure !== null && textMeasure !== void 0 ? textMeasure : this._measureTextWithAlignBaseline(text, options, true);
3329
- return {
3330
- ascent: textMeasure.actualBoundingBoxAscent,
3331
- descent: textMeasure.actualBoundingBoxDescent
3332
- };
3333
- }
3334
- measureTextBoundHieght(text, options, textMeasure) {
3280
+ measureTextBoundHieght(text, options) {
3335
3281
  var _a;
3336
3282
  if (!this.context) {
3337
3283
  return (_a = options.fontSize) !== null && _a !== void 0 ? _a : DefaultTextStyle.fontSize;
3338
3284
  }
3339
- textMeasure = textMeasure !== null && textMeasure !== void 0 ? textMeasure : this._measureTextWithoutAlignBaseline(text, options, true);
3285
+ this.context.setTextStyleWithoutAlignBaseline(options);
3286
+ const textMeasure = this.context.measureText(text);
3340
3287
  return Math.abs(textMeasure.fontBoundingBoxAscent - textMeasure.fontBoundingBoxDescent);
3341
3288
  }
3342
- measureTextBoundADscent(text, options, textMeasure) {
3343
- if (!this.context) {
3344
- return this.measureTextBoundADscentEstimate(options);
3345
- }
3346
- textMeasure = textMeasure !== null && textMeasure !== void 0 ? textMeasure : this._measureTextWithAlignBaseline(text, options, true);
3347
- return {
3348
- ascent: textMeasure.fontBoundingBoxAscent,
3349
- descent: textMeasure.fontBoundingBoxDescent
3350
- };
3351
- }
3352
- measureTextBoundADscentEstimate(options) {
3353
- var _a;
3354
- const fontSize = (_a = options.fontSize) !== null && _a !== void 0 ? _a : DefaultTextStyle.fontSize;
3355
- const { textBaseline } = options;
3356
- if (textBaseline === 'bottom') {
3357
- return {
3358
- ascent: fontSize,
3359
- descent: 0
3360
- };
3361
- }
3362
- else if (textBaseline === 'middle') {
3363
- return {
3364
- ascent: fontSize / 2,
3365
- descent: fontSize / 2
3366
- };
3367
- }
3368
- else if (textBaseline === 'alphabetic') {
3369
- return {
3370
- ascent: 0.79 * fontSize,
3371
- descent: 0.21 * fontSize
3372
- };
3373
- }
3374
- return {
3375
- ascent: 0,
3376
- descent: fontSize
3377
- };
3378
- }
3379
- measureTextBoundLeftRightEstimate(options) {
3380
- var _a;
3381
- const fontSize = (_a = options.fontSize) !== null && _a !== void 0 ? _a : DefaultTextStyle.fontSize;
3382
- const { textAlign } = options;
3383
- if (textAlign === 'center') {
3384
- return {
3385
- left: fontSize / 2,
3386
- right: fontSize / 2
3387
- };
3388
- }
3389
- else if (textAlign === 'right' || textAlign === 'end') {
3390
- return {
3391
- left: fontSize,
3392
- right: 0
3393
- };
3394
- }
3395
- return {
3396
- left: 0,
3397
- right: fontSize
3398
- };
3399
- }
3400
- measureTextPixelADscentAndWidth(text, options) {
3401
- if (!this.context) {
3402
- return Object.assign(Object.assign({}, this.measureTextBoundADscentEstimate(options)), { width: this.estimate(text, options).width });
3403
- }
3404
- const out = this._measureTextWithoutAlignBaseline(text, options, true);
3405
- return {
3406
- ascent: out.actualBoundingBoxAscent,
3407
- descent: out.actualBoundingBoxDescent,
3408
- width: out.width
3409
- };
3410
- }
3411
3289
  measureText(text, options) {
3412
3290
  if (!this.context) {
3413
3291
  return this.estimate(text, options);
@@ -10932,10 +10810,10 @@ class ResourceLoader {
10932
10810
  static GetFile(url, type) {
10933
10811
  let data = ResourceLoader.cache.get(url);
10934
10812
  if (data) {
10935
- if (data.loadState === 'init' || data.loadState === 'fail') {
10813
+ if (data.loadState === 'fail') {
10936
10814
  return Promise.reject();
10937
10815
  }
10938
- else if (data.loadState === 'loading') {
10816
+ else if (data.loadState === 'init' || data.loadState === 'loading') {
10939
10817
  return data.dataPromise.then(data => data.data);
10940
10818
  }
10941
10819
  return Promise.resolve(data.data);
@@ -15996,8 +15874,13 @@ class DefaultImageRenderContribution extends DefaultRectRenderContribution {
15996
15874
  this.useStyle = true;
15997
15875
  this.order = 0;
15998
15876
  }
15999
- drawShape(rect, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb) {
16000
- return super.drawShape(rect, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb);
15877
+ drawShape(image, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb) {
15878
+ if (image.isGifImage && image.renderFrame && image.playing) {
15879
+ image.renderFrame(context, x, y);
15880
+ }
15881
+ else {
15882
+ return super.drawShape(image, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb);
15883
+ }
16001
15884
  }
16002
15885
  }
16003
15886
  const defaultImageRenderContribution = new DefaultImageRenderContribution();
@@ -17966,82 +17849,132 @@ let DefaultCanvasTextRender = class DefaultCanvasTextRender extends BaseRender {
17966
17849
  context.setTransformForCurrent();
17967
17850
  }
17968
17851
  };
17969
- context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z);
17970
- if (direction === 'horizontal') {
17971
- const { multilineLayout } = text;
17972
- if (!multilineLayout) {
17973
- context.highPerformanceRestore();
17974
- return;
17975
- }
17976
- const { xOffset, yOffset } = multilineLayout.bbox;
17977
- if (doStroke) {
17978
- if (strokeCb) {
17979
- strokeCb(context, text.attribute, textAttribute);
17852
+ if (text.isMultiLine) {
17853
+ context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z);
17854
+ if (direction === 'horizontal') {
17855
+ const { multilineLayout } = text;
17856
+ if (!multilineLayout) {
17857
+ context.highPerformanceRestore();
17858
+ return;
17980
17859
  }
17981
- else if (sVisible) {
17982
- context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute);
17983
- multilineLayout.lines.forEach(line => {
17984
- context.strokeText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z);
17985
- });
17860
+ const { xOffset, yOffset } = multilineLayout.bbox;
17861
+ if (doStroke) {
17862
+ if (strokeCb) {
17863
+ strokeCb(context, text.attribute, textAttribute);
17864
+ }
17865
+ else if (sVisible) {
17866
+ context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute);
17867
+ multilineLayout.lines.forEach(line => {
17868
+ context.strokeText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z);
17869
+ });
17870
+ }
17871
+ }
17872
+ if (doFill) {
17873
+ if (fillCb) {
17874
+ fillCb(context, text.attribute, textAttribute);
17875
+ }
17876
+ else if (fVisible) {
17877
+ context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute);
17878
+ multilineLayout.lines.forEach(line => {
17879
+ context.fillText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z);
17880
+ this.drawUnderLine(underline, lineThrough, text, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y - textDrawOffsetY('bottom', fontSize) - 0.05 * fontSize, z, textAttribute, context, {
17881
+ width: line.width
17882
+ });
17883
+ });
17884
+ }
17986
17885
  }
17987
17886
  }
17988
- if (doFill) {
17989
- if (fillCb) {
17990
- fillCb(context, text.attribute, textAttribute);
17887
+ else {
17888
+ text.tryUpdateAABBBounds();
17889
+ const cache = text.cache;
17890
+ const { verticalList } = cache;
17891
+ context.textAlign = 'left';
17892
+ context.textBaseline = 'top';
17893
+ const totalHeight = lineHeight * verticalList.length;
17894
+ let totalW = 0;
17895
+ verticalList.forEach(verticalData => {
17896
+ const _w = verticalData.reduce((a, b) => a + (b.width || 0), 0);
17897
+ totalW = max(_w, totalW);
17898
+ });
17899
+ let offsetY = 0;
17900
+ let offsetX = 0;
17901
+ if (textBaseline === 'bottom') {
17902
+ offsetX = -totalHeight;
17991
17903
  }
17992
- else if (fVisible) {
17993
- context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute);
17994
- multilineLayout.lines.forEach(line => {
17995
- context.fillText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z);
17996
- this.drawUnderLine(underline, lineThrough, text, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y - textDrawOffsetY('bottom', fontSize) - 0.05 * fontSize, z, textAttribute, context, {
17997
- width: line.width
17998
- });
17999
- });
17904
+ else if (textBaseline === 'middle') {
17905
+ offsetX = -totalHeight / 2;
17906
+ }
17907
+ if (textAlign === 'center') {
17908
+ offsetY -= totalW / 2;
18000
17909
  }
17910
+ else if (textAlign === 'right') {
17911
+ offsetY -= totalW;
17912
+ }
17913
+ verticalList.forEach((verticalData, i) => {
17914
+ const currentW = verticalData.reduce((a, b) => a + (b.width || 0), 0);
17915
+ const dw = totalW - currentW;
17916
+ let currentOffsetY = offsetY;
17917
+ if (textAlign === 'center') {
17918
+ currentOffsetY += dw / 2;
17919
+ }
17920
+ else if (textAlign === 'right') {
17921
+ currentOffsetY += dw;
17922
+ }
17923
+ verticalData.forEach(item => {
17924
+ const { text, width, direction } = item;
17925
+ drawText(text, totalHeight - (i + 1) * lineHeight + offsetX, currentOffsetY, direction);
17926
+ currentOffsetY += width;
17927
+ });
17928
+ });
18001
17929
  }
18002
17930
  }
18003
17931
  else {
18004
- text.tryUpdateAABBBounds();
18005
- const cache = text.cache;
18006
- const { verticalList } = cache;
18007
- context.textAlign = 'left';
18008
- context.textBaseline = 'top';
18009
- const totalHeight = lineHeight * verticalList.length;
18010
- let totalW = 0;
18011
- verticalList.forEach(verticalData => {
18012
- const _w = verticalData.reduce((a, b) => a + (b.width || 0), 0);
18013
- totalW = max(_w, totalW);
18014
- });
18015
- let offsetY = 0;
18016
- let offsetX = 0;
18017
- if (textBaseline === 'bottom') {
18018
- offsetX = -totalHeight;
18019
- }
18020
- else if (textBaseline === 'middle') {
18021
- offsetX = -totalHeight / 2;
18022
- }
18023
- if (textAlign === 'center') {
18024
- offsetY -= totalW / 2;
18025
- }
18026
- else if (textAlign === 'right') {
18027
- offsetY -= totalW;
18028
- }
18029
- verticalList.forEach((verticalData, i) => {
18030
- const currentW = verticalData.reduce((a, b) => a + (b.width || 0), 0);
18031
- const dw = totalW - currentW;
18032
- let currentOffsetY = offsetY;
18033
- if (textAlign === 'center') {
18034
- currentOffsetY += dw / 2;
17932
+ if (direction === 'horizontal') {
17933
+ context.setTextStyle(text.attribute, textAttribute, z);
17934
+ const t = text.clipedText;
17935
+ let dy = 0;
17936
+ if (lineHeight !== fontSize) {
17937
+ if (textBaseline === 'top') {
17938
+ dy = (lineHeight - fontSize) / 2;
17939
+ }
17940
+ else if (textBaseline === 'middle') ;
17941
+ else if (textBaseline === 'bottom') {
17942
+ dy = -(lineHeight - fontSize) / 2;
17943
+ }
17944
+ else ;
18035
17945
  }
18036
- else if (textAlign === 'right') {
18037
- currentOffsetY += dw;
17946
+ drawText(t, 0, dy, 0);
17947
+ }
17948
+ else {
17949
+ text.tryUpdateAABBBounds();
17950
+ const cache = text.cache;
17951
+ if (cache) {
17952
+ context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z);
17953
+ const { verticalList } = cache;
17954
+ let offsetY = 0;
17955
+ const totalW = verticalList[0].reduce((a, b) => a + (b.width || 0), 0);
17956
+ let offsetX = 0;
17957
+ if (textBaseline === 'bottom') {
17958
+ offsetX = -lineHeight;
17959
+ }
17960
+ else if (textBaseline === 'middle') {
17961
+ offsetX = -lineHeight / 2;
17962
+ }
17963
+ if (textAlign === 'center') {
17964
+ offsetY -= totalW / 2;
17965
+ }
17966
+ else if (textAlign === 'right') {
17967
+ offsetY -= totalW;
17968
+ }
17969
+ context.textAlign = 'left';
17970
+ context.textBaseline = 'top';
17971
+ verticalList[0].forEach(item => {
17972
+ const { text, width, direction } = item;
17973
+ drawText(text, offsetX, offsetY, direction);
17974
+ offsetY += width;
17975
+ });
18038
17976
  }
18039
- verticalData.forEach(item => {
18040
- const { text, width, direction } = item;
18041
- drawText(text, totalHeight - (i + 1) * lineHeight + offsetX, currentOffsetY, direction);
18042
- currentOffsetY += width;
18043
- });
18044
- });
17977
+ }
18045
17978
  }
18046
17979
  transform3dMatrixToContextMatrix && this.restoreTransformUseContext2d(text, textAttribute, z, context);
18047
17980
  this.afterRenderStep(text, context, x, y, doFill, doStroke, fVisible, sVisible, textAttribute, drawContext, fillCb, strokeCb);
@@ -18522,16 +18455,18 @@ let DefaultCanvasImageRender = class DefaultCanvasImageRender extends BaseRender
18522
18455
  }
18523
18456
  draw(image, renderService, drawContext) {
18524
18457
  const { image: url } = image.attribute;
18525
- if (!url || !image.resources) {
18526
- return;
18527
- }
18528
- const res = image.resources.get(url);
18529
- if (res.state === 'loading' && isString(url)) {
18530
- ResourceLoader.improveImageLoading(url);
18531
- return;
18532
- }
18533
- else if (res.state !== 'success') {
18534
- return;
18458
+ if (!image.isGifImage) {
18459
+ if (!url || !image.resources) {
18460
+ return;
18461
+ }
18462
+ const res = image.resources.get(url);
18463
+ if (res.state === 'loading' && isString(url)) {
18464
+ ResourceLoader.improveImageLoading(url);
18465
+ return;
18466
+ }
18467
+ else if (res.state !== 'success') {
18468
+ return;
18469
+ }
18535
18470
  }
18536
18471
  const { context } = renderService.drawParams;
18537
18472
  if (!context) {
@@ -19111,6 +19046,40 @@ class CanvasTextLayout {
19111
19046
  }
19112
19047
  return bbox;
19113
19048
  }
19049
+ GetLayout(str, width, height, textAlign, textBaseline, lineHeight, suffix, wordBreak, suffixPosition) {
19050
+ const linesLayout = [];
19051
+ const bboxWH = [width, height];
19052
+ const bboxOffset = [0, 0];
19053
+ while (str.length > 0) {
19054
+ const { str: clipText } = this.textMeasure.clipTextWithSuffix(str, this.textOptions, width, suffix, wordBreak, suffixPosition);
19055
+ linesLayout.push({
19056
+ str: clipText,
19057
+ width: this.textMeasure.measureTextWidth(clipText, this.textOptions)
19058
+ });
19059
+ str = str.substring(clipText.length);
19060
+ }
19061
+ if (textAlign === 'left' || textAlign === 'start') ;
19062
+ else if (textAlign === 'center') {
19063
+ bboxOffset[0] = bboxWH[0] / -2;
19064
+ }
19065
+ else if (textAlign === 'right' || textAlign === 'end') {
19066
+ bboxOffset[0] = -bboxWH[0];
19067
+ }
19068
+ if (textBaseline === 'top') ;
19069
+ else if (textBaseline === 'middle') {
19070
+ bboxOffset[1] = bboxWH[1] / -2;
19071
+ }
19072
+ else if (textBaseline === 'bottom') {
19073
+ bboxOffset[1] = -bboxWH[1];
19074
+ }
19075
+ const bbox = {
19076
+ xOffset: bboxOffset[0],
19077
+ yOffset: bboxOffset[1],
19078
+ width: bboxWH[0],
19079
+ height: bboxWH[1]
19080
+ };
19081
+ return this.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
19082
+ }
19114
19083
  GetLayoutByLines(lines, textAlign, textBaseline, lineHeight, suffix = '', wordBreak, lineWidth, suffixPosition = 'end') {
19115
19084
  lines = lines.map(l => l.toString());
19116
19085
  const linesLayout = [];
@@ -19118,13 +19087,10 @@ class CanvasTextLayout {
19118
19087
  if (typeof lineWidth === 'number' && lineWidth !== Infinity) {
19119
19088
  let width;
19120
19089
  for (let i = 0, len = lines.length; i < len; i++) {
19121
- const metrics = this.textMeasure.measureTextPixelADscentAndWidth(lines[i], this.textOptions);
19122
- width = Math.min(metrics.width, lineWidth);
19090
+ width = Math.min(this.textMeasure.measureTextWidth(lines[i], this.textOptions), lineWidth);
19123
19091
  linesLayout.push({
19124
19092
  str: this.textMeasure.clipTextWithSuffix(lines[i], this.textOptions, width, suffix, wordBreak, suffixPosition).str,
19125
- width,
19126
- ascent: metrics.ascent,
19127
- descent: metrics.descent
19093
+ width
19128
19094
  });
19129
19095
  }
19130
19096
  bboxWH[0] = lineWidth;
@@ -19135,10 +19101,9 @@ class CanvasTextLayout {
19135
19101
  let text;
19136
19102
  for (let i = 0, len = lines.length; i < len; i++) {
19137
19103
  text = lines[i];
19138
- const metrics = this.textMeasure.measureTextPixelADscentAndWidth(lines[i], this.textOptions);
19139
- width = metrics.width;
19104
+ width = this.textMeasure.measureTextWidth(text, this.textOptions);
19140
19105
  lineWidth = Math.max(lineWidth, width);
19141
- linesLayout.push({ str: text, width, ascent: metrics.ascent, descent: metrics.descent });
19106
+ linesLayout.push({ str: text, width });
19142
19107
  }
19143
19108
  bboxWH[0] = lineWidth;
19144
19109
  }
@@ -19187,7 +19152,7 @@ class CanvasTextLayout {
19187
19152
  else if (textAlign === 'right' || textAlign === 'end') {
19188
19153
  line.leftOffset = bbox.width - line.width;
19189
19154
  }
19190
- line.topOffset = lineHeight / 2 + (line.ascent - line.descent) / 2 + origin[1];
19155
+ line.topOffset = (lineHeight - this.textOptions.fontSize) / 2 + this.textOptions.fontSize * 0.79 + origin[1];
19191
19156
  origin[1] += lineHeight;
19192
19157
  return line;
19193
19158
  }
@@ -19196,7 +19161,6 @@ class CanvasTextLayout {
19196
19161
  const TEXT_UPDATE_TAG_KEY = [
19197
19162
  'text',
19198
19163
  'maxLineWidth',
19199
- 'maxWidth',
19200
19164
  'textAlign',
19201
19165
  'textBaseline',
19202
19166
  'heightLimit',
@@ -19224,14 +19188,20 @@ class Text extends Graphic {
19224
19188
  var _a;
19225
19189
  const attribute = this.attribute;
19226
19190
  const textTheme = this.getGraphicTheme();
19227
- const maxWidth = this.getMaxWidth(textTheme);
19228
- if (!Number.isFinite(maxWidth)) {
19191
+ if (!this.isSimplify()) {
19192
+ return undefined;
19193
+ }
19194
+ const { maxLineWidth = textTheme.maxLineWidth } = attribute;
19195
+ if (!Number.isFinite(maxLineWidth)) {
19229
19196
  return ((_a = attribute.text) !== null && _a !== void 0 ? _a : textTheme.text).toString();
19230
19197
  }
19231
19198
  this.tryUpdateAABBBounds();
19232
19199
  return this.cache.clipedText;
19233
19200
  }
19234
19201
  get clipedWidth() {
19202
+ if (!this.isSimplify()) {
19203
+ return undefined;
19204
+ }
19235
19205
  this.tryUpdateAABBBounds();
19236
19206
  return this.cache.clipedWidth;
19237
19207
  }
@@ -19239,11 +19209,10 @@ class Text extends Graphic {
19239
19209
  var _a, _b;
19240
19210
  const textTheme = this.getGraphicTheme();
19241
19211
  const attribute = this.attribute;
19242
- const maxWidth = this.getMaxWidth(textTheme);
19243
- if (!Number.isFinite(maxWidth)) {
19212
+ const { maxLineWidth = textTheme.maxLineWidth, text, whiteSpace = textTheme.whiteSpace } = attribute;
19213
+ if (!Number.isFinite(maxLineWidth)) {
19244
19214
  return false;
19245
19215
  }
19246
- const { text } = this.attribute;
19247
19216
  this.tryUpdateAABBBounds();
19248
19217
  if ((_b = (_a = this.cache) === null || _a === void 0 ? void 0 : _a.layoutData) === null || _b === void 0 ? void 0 : _b.lines) {
19249
19218
  let mergedText = '';
@@ -19262,9 +19231,15 @@ class Text extends Graphic {
19262
19231
  return this.clipedText !== attribute.text.toString();
19263
19232
  }
19264
19233
  get multilineLayout() {
19234
+ if (!this.isMultiLine) {
19235
+ return undefined;
19236
+ }
19265
19237
  this.tryUpdateAABBBounds();
19266
19238
  return this.cache.layoutData;
19267
19239
  }
19240
+ isSimplify() {
19241
+ return !this.isMultiLine && this.attribute.direction !== 'vertical';
19242
+ }
19268
19243
  get isMultiLine() {
19269
19244
  return Array.isArray(this.attribute.text) || this.attribute.whiteSpace === 'normal';
19270
19245
  }
@@ -19332,66 +19307,13 @@ class Text extends Graphic {
19332
19307
  transformBoundsWithMatrix(aabbBounds, aabbBounds, this.transMatrix);
19333
19308
  return aabbBounds;
19334
19309
  }
19335
- updateSingallineAABBBounds(text) {
19336
- this.updateMultilineAABBBounds([text]);
19337
- const layoutData = this.cache.layoutData;
19338
- if (layoutData) {
19339
- const line = layoutData.lines[0];
19340
- this.cache.clipedText = line.str;
19341
- this.cache.clipedWidth = line.width;
19342
- }
19343
- return this._AABBBounds;
19344
- }
19345
- updateMultilineAABBBounds(text) {
19346
- const textTheme = this.getGraphicTheme();
19347
- const { direction = textTheme.direction, underlineOffset = textTheme.underlineOffset } = this.attribute;
19348
- const b = direction === 'horizontal'
19349
- ? this.updateHorizontalMultilineAABBBounds(text)
19350
- : this.updateVerticalMultilineAABBBounds(text);
19351
- if (direction === 'horizontal') {
19352
- if (underlineOffset) {
19353
- this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset);
19354
- }
19355
- }
19356
- return b;
19357
- }
19358
- updateHorizontalMultilineAABBBounds(text) {
19359
- var _a;
19360
- const textTheme = this.getGraphicTheme();
19361
- const attribute = this.attribute;
19362
- const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, wrap = textTheme.wrap, ignoreBuf = textTheme.ignoreBuf, lineWidth = textTheme.lineWidth, whiteSpace = textTheme.whiteSpace, suffixPosition = textTheme.suffixPosition } = attribute;
19363
- const buf = ignoreBuf ? 0 : 2;
19364
- const lineHeight = this.getLineHeight(attribute, textTheme) + buf;
19365
- if (whiteSpace === 'normal' || wrap) {
19366
- return this.updateWrapAABBBounds(text);
19367
- }
19368
- if (!this.shouldUpdateShape() && ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.layoutData)) {
19369
- const bbox = this.cache.layoutData.bbox;
19370
- this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
19371
- if (stroke) {
19372
- this._AABBBounds.expand(lineWidth / 2);
19373
- }
19374
- return this._AABBBounds;
19375
- }
19376
- const textMeasure = application.graphicUtil.textMeasure;
19377
- const layoutObj = new CanvasTextLayout(fontFamily, { fontSize, fontWeight, fontFamily }, textMeasure);
19378
- const layoutData = layoutObj.GetLayoutByLines(text, textAlign, textBaseline, lineHeight, ellipsis === true ? textTheme.ellipsis : ellipsis || undefined, false, maxLineWidth, suffixPosition);
19379
- const { bbox } = layoutData;
19380
- this.cache.layoutData = layoutData;
19381
- this.clearUpdateShapeTag();
19382
- this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
19383
- if (stroke) {
19384
- this._AABBBounds.expand(lineWidth / 2);
19385
- }
19386
- return this._AABBBounds;
19387
- }
19388
19310
  updateWrapAABBBounds(text) {
19389
- var _a, _b, _c;
19311
+ var _a, _b, _c, _d;
19390
19312
  const textTheme = this.getGraphicTheme();
19391
19313
  const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, fontWeight = textTheme.fontWeight, ignoreBuf = textTheme.ignoreBuf, suffixPosition = textTheme.suffixPosition, heightLimit = 0, lineClamp } = this.attribute;
19314
+ const lineHeight = (_a = calculateLineHeight(this.attribute.lineHeight, this.attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (this.attribute.fontSize || textTheme.fontSize);
19392
19315
  const buf = ignoreBuf ? 0 : 2;
19393
- const lineHeight = this.getLineHeight(this.attribute, textTheme) + buf;
19394
- if (!this.shouldUpdateShape() && ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.layoutData)) {
19316
+ if (!this.shouldUpdateShape() && ((_b = this.cache) === null || _b === void 0 ? void 0 : _b.layoutData)) {
19395
19317
  const bbox = this.cache.layoutData.bbox;
19396
19318
  this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
19397
19319
  if (stroke) {
@@ -19400,8 +19322,7 @@ class Text extends Graphic {
19400
19322
  return this._AABBBounds;
19401
19323
  }
19402
19324
  const textMeasure = application.graphicUtil.textMeasure;
19403
- const textOptions = { fontSize, fontWeight, fontFamily };
19404
- const layoutObj = new CanvasTextLayout(fontFamily, textOptions, textMeasure);
19325
+ const layoutObj = new CanvasTextLayout(fontFamily, { fontSize, fontWeight, fontFamily }, textMeasure);
19405
19326
  const lines = isArray(text) ? text.map(l => l.toString()) : [text.toString()];
19406
19327
  const linesLayout = [];
19407
19328
  const bboxWH = [0, 0];
@@ -19418,22 +19339,19 @@ class Text extends Graphic {
19418
19339
  const str = lines[i];
19419
19340
  let needCut = true;
19420
19341
  if (i === lineCountLimit - 1) {
19421
- const clip = textMeasure.clipTextWithSuffix(str, textOptions, maxLineWidth, ellipsis, false, suffixPosition, i !== lines.length - 1);
19422
- const matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions);
19342
+ const clip = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, false, suffixPosition, i !== lines.length - 1);
19423
19343
  linesLayout.push({
19424
19344
  str: clip.str,
19425
- width: clip.width,
19426
- ascent: matrics.ascent,
19427
- descent: matrics.descent
19345
+ width: clip.width
19428
19346
  });
19429
19347
  break;
19430
19348
  }
19431
- const clip = textMeasure.clipText(str, textOptions, maxLineWidth, wordBreak === 'break-word');
19432
- if (str !== '' && clip.str === '') {
19349
+ const clip = layoutObj.textMeasure.clipText(str, layoutObj.textOptions, maxLineWidth, wordBreak !== 'break-all', wordBreak === 'keep-all');
19350
+ if ((str !== '' && clip.str === '') || clip.wordBreaked) {
19433
19351
  if (ellipsis) {
19434
- const clipEllipsis = textMeasure.clipTextWithSuffix(str, textOptions, maxLineWidth, ellipsis, false, suffixPosition);
19435
- clip.str = (_b = clipEllipsis.str) !== null && _b !== void 0 ? _b : '';
19436
- clip.width = (_c = clipEllipsis.width) !== null && _c !== void 0 ? _c : 0;
19352
+ const clipEllipsis = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, false, suffixPosition);
19353
+ clip.str = (_c = clipEllipsis.str) !== null && _c !== void 0 ? _c : '';
19354
+ clip.width = (_d = clipEllipsis.width) !== null && _d !== void 0 ? _d : 0;
19437
19355
  }
19438
19356
  else {
19439
19357
  clip.str = '';
@@ -19441,16 +19359,21 @@ class Text extends Graphic {
19441
19359
  }
19442
19360
  needCut = false;
19443
19361
  }
19444
- const matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions);
19445
19362
  linesLayout.push({
19446
19363
  str: clip.str,
19447
- width: clip.width,
19448
- ascent: matrics.ascent,
19449
- descent: matrics.descent
19364
+ width: clip.width
19450
19365
  });
19366
+ let cutLength = clip.str.length;
19367
+ if (clip.wordBreaked && !(str !== '' && clip.str === '')) {
19368
+ needCut = true;
19369
+ cutLength = clip.wordBreaked;
19370
+ }
19451
19371
  if (clip.str.length === str.length) ;
19452
19372
  else if (needCut) {
19453
- const newStr = str.substring(clip.str.length);
19373
+ let newStr = str.substring(cutLength);
19374
+ if (wordBreak === 'keep-all') {
19375
+ newStr = newStr.replace(/^\s+/g, '');
19376
+ }
19454
19377
  lines.splice(i + 1, 0, newStr);
19455
19378
  }
19456
19379
  }
@@ -19467,26 +19390,22 @@ class Text extends Graphic {
19467
19390
  let text;
19468
19391
  for (let i = 0, len = lines.length; i < len; i++) {
19469
19392
  if (i === lineCountLimit - 1) {
19470
- const clip = textMeasure.clipTextWithSuffix(lines[i], textOptions, maxLineWidth, ellipsis, false, suffixPosition);
19471
- const matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions);
19393
+ const clip = layoutObj.textMeasure.clipTextWithSuffix(lines[i], layoutObj.textOptions, maxLineWidth, ellipsis, false, suffixPosition);
19472
19394
  linesLayout.push({
19473
19395
  str: clip.str,
19474
- width: clip.width,
19475
- ascent: matrics.ascent,
19476
- descent: matrics.descent
19396
+ width: clip.width
19477
19397
  });
19478
19398
  lineWidth = Math.max(lineWidth, clip.width);
19479
19399
  break;
19480
19400
  }
19481
19401
  text = lines[i];
19482
- width = textMeasure.measureTextWidth(text, textOptions);
19402
+ width = layoutObj.textMeasure.measureTextWidth(text, layoutObj.textOptions, wordBreak === 'break-word');
19483
19403
  lineWidth = Math.max(lineWidth, width);
19484
- const matrics = textMeasure.measureTextPixelADscentAndWidth(text, textOptions);
19485
- linesLayout.push({ str: text, width, ascent: matrics.ascent, descent: matrics.descent });
19404
+ linesLayout.push({ str: text, width });
19486
19405
  }
19487
19406
  bboxWH[0] = lineWidth;
19488
19407
  }
19489
- bboxWH[1] = linesLayout.length * lineHeight;
19408
+ bboxWH[1] = linesLayout.length * (lineHeight + buf);
19490
19409
  const bbox = {
19491
19410
  xOffset: 0,
19492
19411
  yOffset: 0,
@@ -19503,19 +19422,212 @@ class Text extends Graphic {
19503
19422
  }
19504
19423
  return this._AABBBounds;
19505
19424
  }
19506
- updateVerticalMultilineAABBBounds(text) {
19425
+ updateSingallineAABBBounds(text) {
19426
+ const textTheme = this.getGraphicTheme();
19427
+ const { direction = textTheme.direction, underlineOffset = textTheme.underlineOffset } = this.attribute;
19428
+ const b = direction === 'horizontal'
19429
+ ? this.updateHorizontalSinglelineAABBBounds(text)
19430
+ : this.updateVerticalSinglelineAABBBounds(text);
19431
+ if (direction === 'horizontal') {
19432
+ if (underlineOffset) {
19433
+ this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset);
19434
+ }
19435
+ }
19436
+ return b;
19437
+ }
19438
+ updateMultilineAABBBounds(text) {
19439
+ const textTheme = this.getGraphicTheme();
19440
+ const { direction = textTheme.direction, underlineOffset = textTheme.underlineOffset } = this.attribute;
19441
+ const b = direction === 'horizontal'
19442
+ ? this.updateHorizontalMultilineAABBBounds(text)
19443
+ : this.updateVerticalMultilineAABBBounds(text);
19444
+ if (direction === 'horizontal') {
19445
+ if (underlineOffset) {
19446
+ this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset);
19447
+ }
19448
+ }
19449
+ return b;
19450
+ }
19451
+ updateHorizontalSinglelineAABBBounds(text) {
19452
+ var _a, _b;
19453
+ const textTheme = this.getGraphicTheme();
19454
+ const { wrap = textTheme.wrap } = this.attribute;
19455
+ if (wrap) {
19456
+ return this.updateWrapAABBBounds([text]);
19457
+ }
19458
+ const textMeasure = application.graphicUtil.textMeasure;
19459
+ let width;
19460
+ let str;
19461
+ const attribute = this.attribute;
19462
+ const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontFamily = textTheme.fontFamily, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, ignoreBuf = textTheme.ignoreBuf, whiteSpace = textTheme.whiteSpace, suffixPosition = textTheme.suffixPosition } = attribute;
19463
+ if (whiteSpace === 'normal') {
19464
+ return this.updateWrapAABBBounds(text);
19465
+ }
19466
+ const buf = ignoreBuf ? 0 : Math.max(2, fontSize * 0.075);
19467
+ const textFontSize = attribute.fontSize || textTheme.fontSize;
19468
+ const lineHeight = (_a = calculateLineHeight(attribute.lineHeight, textFontSize)) !== null && _a !== void 0 ? _a : textFontSize + buf;
19469
+ if (!this.shouldUpdateShape() && this.cache) {
19470
+ width = (_b = this.cache.clipedWidth) !== null && _b !== void 0 ? _b : 0;
19471
+ const dx = textDrawOffsetX(textAlign, width);
19472
+ const dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
19473
+ this._AABBBounds.set(dx, dy, dx + width, dy + lineHeight);
19474
+ if (stroke) {
19475
+ this._AABBBounds.expand(lineWidth / 2);
19476
+ }
19477
+ return this._AABBBounds;
19478
+ }
19479
+ if (Number.isFinite(maxLineWidth)) {
19480
+ if (ellipsis) {
19481
+ const strEllipsis = (ellipsis === true ? textTheme.ellipsis : ellipsis);
19482
+ const data = textMeasure.clipTextWithSuffix(text.toString(), { fontSize, fontWeight, fontFamily }, maxLineWidth, strEllipsis, false, suffixPosition);
19483
+ str = data.str;
19484
+ width = data.width;
19485
+ }
19486
+ else {
19487
+ const data = textMeasure.clipText(text.toString(), { fontSize, fontWeight, fontFamily }, maxLineWidth, false);
19488
+ str = data.str;
19489
+ width = data.width;
19490
+ }
19491
+ this.cache.clipedText = str;
19492
+ this.cache.clipedWidth = width;
19493
+ }
19494
+ else {
19495
+ width = textMeasure.measureTextWidth(text.toString(), { fontSize, fontWeight, fontFamily });
19496
+ this.cache.clipedText = text.toString();
19497
+ this.cache.clipedWidth = width;
19498
+ }
19499
+ this.clearUpdateShapeTag();
19500
+ const dx = textDrawOffsetX(textAlign, width);
19501
+ let lh = lineHeight;
19502
+ if (application.global && application.global.isSafari()) {
19503
+ lh += fontSize * 0.2;
19504
+ }
19505
+ const dy = textLayoutOffsetY(textBaseline, lh, fontSize, buf);
19506
+ this._AABBBounds.set(dx, dy, dx + width, dy + lh);
19507
+ if (stroke) {
19508
+ this._AABBBounds.expand(lineWidth / 2);
19509
+ }
19510
+ return this._AABBBounds;
19511
+ }
19512
+ getBaselineMapAlign() {
19513
+ return Text.baselineMapAlign;
19514
+ }
19515
+ getAlignMapBaseline() {
19516
+ return Text.alignMapBaseline;
19517
+ }
19518
+ updateVerticalSinglelineAABBBounds(text) {
19519
+ var _a, _b, _c;
19520
+ const textTheme = this.getGraphicTheme();
19521
+ const textMeasure = application.graphicUtil.textMeasure;
19522
+ let width;
19523
+ const attribute = this.attribute;
19524
+ const { ignoreBuf = textTheme.ignoreBuf } = attribute;
19525
+ const buf = ignoreBuf ? 0 : 2;
19526
+ const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, fontFamily = textTheme.fontFamily, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, verticalMode = textTheme.verticalMode, suffixPosition = textTheme.suffixPosition } = attribute;
19527
+ const lineHeight = (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
19528
+ let { textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline } = attribute;
19529
+ if (!verticalMode) {
19530
+ const t = textAlign;
19531
+ textAlign = (_b = Text.baselineMapAlign[textBaseline]) !== null && _b !== void 0 ? _b : 'left';
19532
+ textBaseline = (_c = Text.alignMapBaseline[t]) !== null && _c !== void 0 ? _c : 'top';
19533
+ }
19534
+ if (!this.shouldUpdateShape() && this.cache) {
19535
+ width = this.cache.clipedWidth;
19536
+ const dx = textDrawOffsetX(textAlign, width);
19537
+ const dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
19538
+ this._AABBBounds.set(dy, dx, dy + lineHeight, dx + width);
19539
+ if (stroke) {
19540
+ this._AABBBounds.expand(lineWidth / 2);
19541
+ }
19542
+ return this._AABBBounds;
19543
+ }
19544
+ let verticalList = [
19545
+ verticalLayout(text.toString())
19546
+ ];
19547
+ if (Number.isFinite(maxLineWidth)) {
19548
+ if (ellipsis) {
19549
+ const strEllipsis = (ellipsis === true ? textTheme.ellipsis : ellipsis);
19550
+ const data = textMeasure.clipTextWithSuffixVertical(verticalList[0], { fontSize, fontWeight, fontFamily }, maxLineWidth, strEllipsis, false, suffixPosition);
19551
+ verticalList = [data.verticalList];
19552
+ width = data.width;
19553
+ }
19554
+ else {
19555
+ const data = textMeasure.clipTextVertical(verticalList[0], { fontSize, fontWeight, fontFamily }, maxLineWidth, false);
19556
+ verticalList = [data.verticalList];
19557
+ width = data.width;
19558
+ }
19559
+ this.cache.verticalList = verticalList;
19560
+ this.cache.clipedWidth = width;
19561
+ }
19562
+ else {
19563
+ width = 0;
19564
+ verticalList[0].forEach(t => {
19565
+ const w = t.direction === TextDirection.HORIZONTAL
19566
+ ? fontSize
19567
+ : textMeasure.measureTextWidth(t.text, { fontSize, fontWeight, fontFamily });
19568
+ width += w;
19569
+ t.width = w;
19570
+ });
19571
+ this.cache.verticalList = verticalList;
19572
+ this.cache.clipedWidth = width;
19573
+ }
19574
+ this.clearUpdateShapeTag();
19575
+ const dx = textDrawOffsetX(textAlign, width);
19576
+ const dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
19577
+ this._AABBBounds.set(dy, dx, dy + lineHeight, dx + width);
19578
+ if (stroke) {
19579
+ this._AABBBounds.expand(lineWidth / 2);
19580
+ }
19581
+ return this._AABBBounds;
19582
+ }
19583
+ updateHorizontalMultilineAABBBounds(text) {
19507
19584
  var _a, _b;
19508
19585
  const textTheme = this.getGraphicTheme();
19586
+ const { wrap = textTheme.wrap } = this.attribute;
19587
+ if (wrap) {
19588
+ return this.updateWrapAABBBounds(text);
19589
+ }
19590
+ const attribute = this.attribute;
19591
+ const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, whiteSpace = textTheme.whiteSpace, suffixPosition = textTheme.suffixPosition } = attribute;
19592
+ const lineHeight = (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize);
19593
+ if (whiteSpace === 'normal') {
19594
+ return this.updateWrapAABBBounds(text);
19595
+ }
19596
+ if (!this.shouldUpdateShape() && ((_b = this.cache) === null || _b === void 0 ? void 0 : _b.layoutData)) {
19597
+ const bbox = this.cache.layoutData.bbox;
19598
+ this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
19599
+ if (stroke) {
19600
+ this._AABBBounds.expand(lineWidth / 2);
19601
+ }
19602
+ return this._AABBBounds;
19603
+ }
19604
+ const textMeasure = application.graphicUtil.textMeasure;
19605
+ const layoutObj = new CanvasTextLayout(fontFamily, { fontSize, fontWeight, fontFamily }, textMeasure);
19606
+ const layoutData = layoutObj.GetLayoutByLines(text, textAlign, textBaseline, lineHeight, ellipsis === true ? textTheme.ellipsis : ellipsis || undefined, false, maxLineWidth, suffixPosition);
19607
+ const { bbox } = layoutData;
19608
+ this.cache.layoutData = layoutData;
19609
+ this.clearUpdateShapeTag();
19610
+ this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
19611
+ if (stroke) {
19612
+ this._AABBBounds.expand(lineWidth / 2);
19613
+ }
19614
+ return this._AABBBounds;
19615
+ }
19616
+ updateVerticalMultilineAABBBounds(text) {
19617
+ var _a, _b, _c;
19618
+ const textTheme = this.getGraphicTheme();
19509
19619
  const textMeasure = application.graphicUtil.textMeasure;
19510
19620
  let width;
19511
19621
  const attribute = this.attribute;
19622
+ const { ignoreBuf = textTheme.ignoreBuf } = attribute;
19623
+ const buf = ignoreBuf ? 0 : 2;
19512
19624
  const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, fontFamily = textTheme.fontFamily, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, verticalMode = textTheme.verticalMode, suffixPosition = textTheme.suffixPosition } = attribute;
19513
- const lineHeight = this.getLineHeight(attribute, textTheme);
19625
+ const lineHeight = (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
19514
19626
  let { textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline } = attribute;
19515
19627
  if (!verticalMode) {
19516
19628
  const t = textAlign;
19517
- textAlign = (_a = Text.baselineMapAlign[textBaseline]) !== null && _a !== void 0 ? _a : 'left';
19518
- textBaseline = (_b = Text.alignMapBaseline[t]) !== null && _b !== void 0 ? _b : 'top';
19629
+ textAlign = (_b = Text.baselineMapAlign[textBaseline]) !== null && _b !== void 0 ? _b : 'left';
19630
+ textBaseline = (_c = Text.alignMapBaseline[t]) !== null && _c !== void 0 ? _c : 'top';
19519
19631
  }
19520
19632
  width = 0;
19521
19633
  if (!this.shouldUpdateShape() && this.cache) {
@@ -19575,15 +19687,6 @@ class Text extends Graphic {
19575
19687
  }
19576
19688
  return this._AABBBounds;
19577
19689
  }
19578
- getMaxWidth(theme) {
19579
- var _a, _b;
19580
- const attribute = this.attribute;
19581
- return (_b = (_a = attribute.maxLineWidth) !== null && _a !== void 0 ? _a : attribute.maxWidth) !== null && _b !== void 0 ? _b : theme.maxWidth;
19582
- }
19583
- getLineHeight(attribute, textTheme) {
19584
- var _a;
19585
- return ((_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize));
19586
- }
19587
19690
  needUpdateTags(keys, k = TEXT_UPDATE_TAG_KEY) {
19588
19691
  return super.needUpdateTags(keys, k);
19589
19692
  }
@@ -19596,12 +19699,6 @@ class Text extends Graphic {
19596
19699
  getNoWorkAnimateAttr() {
19597
19700
  return Text.NOWORK_ANIMATE_ATTR;
19598
19701
  }
19599
- getBaselineMapAlign() {
19600
- return Text.baselineMapAlign;
19601
- }
19602
- getAlignMapBaseline() {
19603
- return Text.alignMapBaseline;
19604
- }
19605
19702
  }
19606
19703
  Text.NOWORK_ANIMATE_ATTR = Object.assign({ ellipsis: 1, wordBreak: 1, direction: 1, textAlign: 1, textBaseline: 1, fontFamily: 1, fontWeight: 1 }, NOWORK_ANIMATE_ATTR);
19607
19704
  Text.baselineMapAlign = {
@@ -19665,9 +19762,7 @@ class WrapText extends Text {
19665
19762
  const clip = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, false, suffixPosition);
19666
19763
  linesLayout.push({
19667
19764
  str: clip.str,
19668
- width: clip.width,
19669
- ascent: 0,
19670
- descent: 0
19765
+ width: clip.width
19671
19766
  });
19672
19767
  break;
19673
19768
  }
@@ -19686,9 +19781,7 @@ class WrapText extends Text {
19686
19781
  }
19687
19782
  linesLayout.push({
19688
19783
  str: clip.str,
19689
- width: clip.width,
19690
- ascent: 0,
19691
- descent: 0
19784
+ width: clip.width
19692
19785
  });
19693
19786
  if (clip.str.length === str.length) ;
19694
19787
  else if (needCut) {
@@ -19712,9 +19805,7 @@ class WrapText extends Text {
19712
19805
  const clip = layoutObj.textMeasure.clipTextWithSuffix(lines[i], layoutObj.textOptions, maxLineWidth, ellipsis, false, suffixPosition);
19713
19806
  linesLayout.push({
19714
19807
  str: clip.str,
19715
- width: clip.width,
19716
- ascent: 0,
19717
- descent: 0
19808
+ width: clip.width
19718
19809
  });
19719
19810
  lineWidth = Math.max(lineWidth, clip.width);
19720
19811
  break;
@@ -19722,7 +19813,7 @@ class WrapText extends Text {
19722
19813
  text = lines[i];
19723
19814
  width = layoutObj.textMeasure.measureTextWidth(text, layoutObj.textOptions, wordBreak === 'break-word');
19724
19815
  lineWidth = Math.max(lineWidth, width);
19725
- linesLayout.push({ str: text, width, ascent: 0, descent: 0 });
19816
+ linesLayout.push({ str: text, width });
19726
19817
  }
19727
19818
  bboxWH[0] = lineWidth;
19728
19819
  }