@visactor/vrender-core 0.22.0 → 0.22.2

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 (134) hide show
  1. package/cjs/canvas/contributions/base-canvas.d.ts +1 -0
  2. package/cjs/canvas/contributions/base-canvas.js +3 -0
  3. package/cjs/canvas/contributions/base-canvas.js.map +1 -1
  4. package/cjs/common/custom-path2d.js +8 -6
  5. package/cjs/common/custom-path2d.js.map +1 -1
  6. package/cjs/graphic/config.js +7 -3
  7. package/cjs/graphic/config.js.map +1 -1
  8. package/cjs/graphic/graphic.d.ts +8 -3
  9. package/cjs/graphic/graphic.js +52 -10
  10. package/cjs/graphic/graphic.js.map +1 -1
  11. package/cjs/graphic/group.d.ts +1 -0
  12. package/cjs/graphic/group.js +5 -0
  13. package/cjs/graphic/group.js.map +1 -1
  14. package/cjs/graphic/image.d.ts +3 -2
  15. package/cjs/graphic/image.js +23 -13
  16. package/cjs/graphic/image.js.map +1 -1
  17. package/cjs/graphic/richtext/line.js +11 -1
  18. package/cjs/graphic/richtext/line.js.map +1 -1
  19. package/cjs/graphic/richtext/paragraph.d.ts +8 -1
  20. package/cjs/graphic/richtext/paragraph.js +5 -16
  21. package/cjs/graphic/richtext/paragraph.js.map +1 -1
  22. package/cjs/graphic/richtext.js +11 -7
  23. package/cjs/graphic/richtext.js.map +1 -1
  24. package/cjs/graphic/symbol.d.ts +1 -1
  25. package/cjs/graphic/symbol.js +20 -37
  26. package/cjs/graphic/symbol.js.map +1 -1
  27. package/cjs/graphic/text.d.ts +1 -0
  28. package/cjs/graphic/text.js +3 -0
  29. package/cjs/graphic/text.js.map +1 -1
  30. package/cjs/interface/graphic/arc.js.map +1 -1
  31. package/cjs/interface/graphic/area.js.map +1 -1
  32. package/cjs/interface/graphic/circle.js.map +1 -1
  33. package/cjs/interface/graphic/group.d.ts +1 -0
  34. package/cjs/interface/graphic/group.js.map +1 -1
  35. package/cjs/interface/graphic/image.d.ts +2 -0
  36. package/cjs/interface/graphic/image.js.map +1 -1
  37. package/cjs/interface/graphic/line.js.map +1 -1
  38. package/cjs/interface/graphic/polygon.js.map +1 -1
  39. package/cjs/interface/graphic/rect.js.map +1 -1
  40. package/cjs/interface/graphic/richText.d.ts +4 -0
  41. package/cjs/interface/graphic/richText.js.map +1 -1
  42. package/cjs/interface/graphic/symbol.d.ts +1 -0
  43. package/cjs/interface/graphic/symbol.js.map +1 -1
  44. package/cjs/interface/graphic/text.js.map +1 -1
  45. package/cjs/interface/graphic.d.ts +5 -0
  46. package/cjs/interface/graphic.js.map +1 -1
  47. package/cjs/plugins/builtin-plugin/auto-refresh-plugin.d.ts +1 -0
  48. package/cjs/plugins/builtin-plugin/auto-refresh-plugin.js +9 -3
  49. package/cjs/plugins/builtin-plugin/auto-refresh-plugin.js.map +1 -1
  50. package/cjs/plugins/builtin-plugin/edit-module.js +3 -2
  51. package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
  52. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +6 -3
  53. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +49 -31
  54. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  55. package/cjs/render/contributions/render/base-render.js +5 -2
  56. package/cjs/render/contributions/render/base-render.js.map +1 -1
  57. package/cjs/render/contributions/render/contributions/base-contribution-render.d.ts +14 -0
  58. package/cjs/render/contributions/render/contributions/base-contribution-render.js +36 -1
  59. package/cjs/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  60. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.d.ts +2 -1
  61. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js +20 -3
  62. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
  63. package/cjs/render/contributions/render/group-render.js +26 -4
  64. package/cjs/render/contributions/render/group-render.js.map +1 -1
  65. package/cjs/render/contributions/render/image-render.js +5 -3
  66. package/cjs/render/contributions/render/image-render.js.map +1 -1
  67. package/dist/index.es.js +4946 -4648
  68. package/es/canvas/contributions/base-canvas.d.ts +1 -0
  69. package/es/canvas/contributions/base-canvas.js +3 -0
  70. package/es/canvas/contributions/base-canvas.js.map +1 -1
  71. package/es/common/custom-path2d.js +8 -6
  72. package/es/common/custom-path2d.js.map +1 -1
  73. package/es/graphic/config.js +7 -3
  74. package/es/graphic/config.js.map +1 -1
  75. package/es/graphic/graphic.d.ts +8 -3
  76. package/es/graphic/graphic.js +58 -12
  77. package/es/graphic/graphic.js.map +1 -1
  78. package/es/graphic/group.d.ts +1 -0
  79. package/es/graphic/group.js +5 -0
  80. package/es/graphic/group.js.map +1 -1
  81. package/es/graphic/image.d.ts +3 -2
  82. package/es/graphic/image.js +23 -13
  83. package/es/graphic/image.js.map +1 -1
  84. package/es/graphic/richtext/line.js +11 -1
  85. package/es/graphic/richtext/line.js.map +1 -1
  86. package/es/graphic/richtext/paragraph.d.ts +8 -1
  87. package/es/graphic/richtext/paragraph.js +5 -16
  88. package/es/graphic/richtext/paragraph.js.map +1 -1
  89. package/es/graphic/richtext.js +11 -7
  90. package/es/graphic/richtext.js.map +1 -1
  91. package/es/graphic/symbol.d.ts +1 -1
  92. package/es/graphic/symbol.js +19 -42
  93. package/es/graphic/symbol.js.map +1 -1
  94. package/es/graphic/text.d.ts +1 -0
  95. package/es/graphic/text.js +3 -0
  96. package/es/graphic/text.js.map +1 -1
  97. package/es/interface/graphic/arc.js.map +1 -1
  98. package/es/interface/graphic/area.js.map +1 -1
  99. package/es/interface/graphic/circle.js.map +1 -1
  100. package/es/interface/graphic/group.d.ts +1 -0
  101. package/es/interface/graphic/group.js.map +1 -1
  102. package/es/interface/graphic/image.d.ts +2 -0
  103. package/es/interface/graphic/image.js.map +1 -1
  104. package/es/interface/graphic/line.js.map +1 -1
  105. package/es/interface/graphic/polygon.js.map +1 -1
  106. package/es/interface/graphic/rect.js.map +1 -1
  107. package/es/interface/graphic/richText.d.ts +4 -0
  108. package/es/interface/graphic/richText.js.map +1 -1
  109. package/es/interface/graphic/symbol.d.ts +1 -0
  110. package/es/interface/graphic/symbol.js.map +1 -1
  111. package/es/interface/graphic/text.js.map +1 -1
  112. package/es/interface/graphic.d.ts +5 -0
  113. package/es/interface/graphic.js.map +1 -1
  114. package/es/plugins/builtin-plugin/auto-refresh-plugin.d.ts +1 -0
  115. package/es/plugins/builtin-plugin/auto-refresh-plugin.js +9 -3
  116. package/es/plugins/builtin-plugin/auto-refresh-plugin.js.map +1 -1
  117. package/es/plugins/builtin-plugin/edit-module.js +3 -2
  118. package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
  119. package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +6 -3
  120. package/es/plugins/builtin-plugin/richtext-edit-plugin.js +49 -31
  121. package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  122. package/es/render/contributions/render/base-render.js +5 -1
  123. package/es/render/contributions/render/base-render.js.map +1 -1
  124. package/es/render/contributions/render/contributions/base-contribution-render.d.ts +14 -0
  125. package/es/render/contributions/render/contributions/base-contribution-render.js +31 -0
  126. package/es/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  127. package/es/render/contributions/render/contributions/base-texture-contribution-render.d.ts +2 -1
  128. package/es/render/contributions/render/contributions/base-texture-contribution-render.js +22 -2
  129. package/es/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
  130. package/es/render/contributions/render/group-render.js +27 -3
  131. package/es/render/contributions/render/group-render.js.map +1 -1
  132. package/es/render/contributions/render/image-render.js +4 -3
  133. package/es/render/contributions/render/image-render.js.map +1 -1
  134. package/package.json +3 -3
@@ -11,19 +11,17 @@ class Image extends graphic_1.Graphic {
11
11
  super(params), this.type = "image", this.numberType = constants_1.IMAGE_NUMBER_TYPE,
12
12
  this.loadImage(this.attribute.image);
13
13
  }
14
- get width() {
15
- var _a;
16
- return null !== (_a = this.attribute.width) && void 0 !== _a ? _a : 0;
14
+ getImageElement() {
15
+ const {image: image} = this.attribute;
16
+ if (!image || !this.resources) return null;
17
+ const res = this.resources.get(image);
18
+ return "success" !== res.state ? null : res.data;
17
19
  }
18
- set width(width) {
19
- this.attribute.width === width && (this.attribute.width = width, this.addUpdateShapeAndBoundsTag());
20
+ get width() {
21
+ return this.tryUpdateAABBBounds(), this._actualWidth;
20
22
  }
21
23
  get height() {
22
- var _a;
23
- return null !== (_a = this.attribute.height) && void 0 !== _a ? _a : 0;
24
- }
25
- set height(height) {
26
- this.attribute.height === height && (this.attribute.height = height, this.addUpdateShapeAndBoundsTag());
24
+ return this.tryUpdateAABBBounds(), this._actualHeight;
27
25
  }
28
26
  get repeatX() {
29
27
  var _a;
@@ -48,7 +46,7 @@ class Image extends graphic_1.Graphic {
48
46
  imageLoadSuccess(url, image, cb) {
49
47
  super.imageLoadSuccess(url, image, (() => {
50
48
  this.successCallback && this.successCallback();
51
- }));
49
+ })), this.addUpdateBoundTag();
52
50
  }
53
51
  imageLoadFail(url, cb) {
54
52
  super.imageLoadFail(url, (() => {
@@ -66,8 +64,20 @@ class Image extends graphic_1.Graphic {
66
64
  }
67
65
  updateAABBBounds(attribute, imageTheme, aabbBounds) {
68
66
  if (!this.updatePathProxyAABBBounds(aabbBounds)) {
69
- const {width: width = imageTheme.width, height: height = imageTheme.height} = attribute;
70
- aabbBounds.set(0, 0, width, height);
67
+ const {maxWidth: maxWidth = imageTheme.maxWidth, maxHeight: maxHeight = imageTheme.maxHeight} = attribute;
68
+ let {width: width, height: height} = attribute;
69
+ if (null == width || null == height) {
70
+ const imageElement = this.getImageElement();
71
+ if (imageElement) {
72
+ const imageWidth = imageElement.width, imageHeight = imageElement.height;
73
+ if (null != width) height = width * (imageHeight / imageWidth); else if (null != height) width = height * (imageWidth / imageHeight); else {
74
+ const imageRatio = imageWidth / imageHeight;
75
+ imageRatio > maxWidth / maxHeight ? (width = maxWidth, height = maxWidth / imageRatio) : (height = maxHeight,
76
+ width = maxHeight * imageRatio);
77
+ }
78
+ } else width = maxWidth, height = maxHeight;
79
+ }
80
+ this._actualWidth = width, this._actualHeight = height, aabbBounds.set(0, 0, width, height);
71
81
  }
72
82
  const {tb1: tb1, tb2: tb2} = application_1.application.graphicService.updateTempAABBBounds(aabbBounds);
73
83
  return (0, common_outer_boder_bounds_1.updateBoundsOfCommonOuterBorder)(attribute, imageTheme, tb1),
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/image.ts"],"names":[],"mappings":";;;AAEA,uCAAiF;AACjF,qCAAiD;AACjD,mCAAmC;AACnC,gDAA6C;AAC7C,2CAAgD;AAChD,2FAA8F;AAE9F,MAAM,oBAAoB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,gCAAsB,CAAC,CAAC;AAMrF,MAAa,KAAM,SAAQ,iBAA+B;IAaxD,YAAY,MAA8B;QACxC,KAAK,CAAC,MAAM,CAAC,CAAC;QAbhB,SAAI,GAAY,OAAO,CAAC;QActB,IAAI,CAAC,UAAU,GAAG,6BAAiB,CAAC;QAEpC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,IAAI,KAAK;;QACP,OAAO,MAAA,IAAI,CAAC,SAAS,CAAC,KAAK,mCAAI,CAAC,CAAC;IACnC,CAAC;IACD,IAAI,KAAK,CAAC,KAAa;QACrB,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,KAAK,KAAK,EAAE;YAClC,IAAI,CAAC,SAAS,CAAC,KAAK,GAAG,KAAK,CAAC;YAC7B,IAAI,CAAC,0BAA0B,EAAE,CAAC;SACnC;IACH,CAAC;IAED,IAAI,MAAM;;QACR,OAAO,MAAA,IAAI,CAAC,SAAS,CAAC,MAAM,mCAAI,CAAC,CAAC;IACpC,CAAC;IACD,IAAI,MAAM,CAAC,MAAc;QACvB,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,MAAM,EAAE;YACpC,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC;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CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAE7C,yBAAW,CAAC,cAAc,CAAC,mBAAmB,CAAC,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAC/F,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,mBAAmB,CAAC,IAAY;QAC9B,OAAQ,8BAA6B,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAES,cAAc,CAAC,IAAc;QACrC,OAAO,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;IAC1D,CAAC;IACS,aAAa,CAAC,GAAW;QACjC,OAAO,KAAK,CAAC,aAAa,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC;IACxD,CAAC;IAED,KAAK;QACH,OAAO,IAAI,KAAK,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IAC1C,CAAC;IAED,oBAAoB;QAClB,OAAO,KAAK,CAAC,mBAAmB,CAAC;IACnC,CAAC;;AA7IH,sBA8IC;AAxIQ,yBAAmB,mBACxB,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,CAAC,EACV,OAAO,EAAE,CAAC,IACP,6BAAmB,EACtB;AAqIJ,SAAgB,WAAW,CAAC,UAAkC;IAC5D,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;AAC/B,CAAC;AAFD,kCAEC","file":"image.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport type { IImage, IImageGraphicAttribute, IRepeatType, ISetAttributeContext } from '../interface';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { DefaultImageAttribute } from './config';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport { IMAGE_NUMBER_TYPE } from './constants';\nimport { updateBoundsOfCommonOuterBorder } from './graphic-service/common-outer-boder-bounds';\n\nconst IMAGE_UPDATE_TAG_KEY = ['width', 'height', 'image', ...GRAPHIC_UPDATE_TAG_KEY];\n\n/**\n * TODO image 需要考虑加载问题 等load模块\n * 同时需要在Graphic增加 图片填充 or 图片按形状clip功能\n */\nexport class Image extends Graphic<IImageGraphicAttribute> implements IImage {\n type: 'image' = 'image';\n // 资源加载完成后回调,外部通过回调获取图片资源尺寸\n successCallback?: () => void;\n failCallback?: () => void;\n\n static NOWORK_ANIMATE_ATTR = {\n image: 1,\n repeatX: 1,\n repeatY: 1,\n ...NOWORK_ANIMATE_ATTR\n };\n\n constructor(params: IImageGraphicAttribute) {\n super(params);\n this.numberType = IMAGE_NUMBER_TYPE;\n\n this.loadImage(this.attribute.image);\n }\n\n get width(): number {\n return this.attribute.width ?? 0;\n }\n set width(width: number) {\n if (this.attribute.width === width) {\n this.attribute.width = width;\n this.addUpdateShapeAndBoundsTag();\n }\n }\n\n get height(): number {\n return this.attribute.height ?? 0;\n }\n set height(height: number) {\n if (this.attribute.height === height) {\n this.attribute.height = height;\n this.addUpdateShapeAndBoundsTag();\n }\n }\n get repeatX(): IRepeatType {\n return this.attribute.repeatX ?? 'no-repeat';\n }\n set repeatX(repeatX: IRepeatType) {\n if (this.attribute.repeatX === repeatX) {\n this.attribute.repeatX = repeatX;\n }\n }\n get repeatY(): IRepeatType {\n return this.attribute.repeatY ?? 'no-repeat';\n }\n set repeatY(repeatY: IRepeatType) {\n if (this.attribute.repeatY === repeatY) {\n this.attribute.repeatY = repeatY;\n }\n }\n get image(): string | HTMLImageElement | HTMLCanvasElement {\n return this.attribute.image;\n }\n set image(image: string | HTMLImageElement | HTMLCanvasElement) {\n if (image !== this.attribute.image) {\n this.attribute.image = image;\n this.loadImage(this.attribute.image);\n // this.addUpdateShapeAndBoundsTag();\n }\n }\n\n imageLoadSuccess(url: string, image: HTMLImageElement, cb?: () => void): void {\n super.imageLoadSuccess(url, image, () => {\n if (this.successCallback) {\n this.successCallback();\n }\n });\n }\n\n imageLoadFail(url: string, cb?: () => void): void {\n super.imageLoadFail(url, () => {\n if (this.failCallback) {\n this.failCallback();\n }\n });\n }\n\n setAttributes(\n params: Partial<IImageGraphicAttribute>,\n forceUpdateTag?: boolean,\n context?: ISetAttributeContext\n ): void {\n if (params.image) {\n this.loadImage(params.image);\n }\n return super.setAttributes(params, forceUpdateTag, context);\n }\n\n setAttribute(key: string, value: any, forceUpdateTag?: boolean, context?: ISetAttributeContext): void {\n if (key === 'image') {\n this.loadImage(value);\n }\n return super.setAttribute(key, value, forceUpdateTag, context);\n }\n\n getGraphicTheme(): Required<IImageGraphicAttribute> {\n return getTheme(this).image;\n }\n\n protected updateAABBBounds(\n attribute: IImageGraphicAttribute,\n imageTheme: Required<IImageGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n const { width = imageTheme.width, height = imageTheme.height } = attribute;\n aabbBounds.set(0, 0, width, height);\n }\n\n const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds);\n\n updateBoundsOfCommonOuterBorder(attribute, imageTheme, tb1);\n aabbBounds.union(tb1);\n tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);\n\n application.graphicService.transformAABBBounds(attribute, aabbBounds, imageTheme, false, this);\n return aabbBounds;\n }\n\n getDefaultAttribute(name: string) {\n return (DefaultImageAttribute as any)[name];\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, IMAGE_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, IMAGE_UPDATE_TAG_KEY);\n }\n\n clone() {\n return new Image({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Image.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createImage(attributes: IImageGraphicAttribute): IImage {\n return new Image(attributes);\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/image.ts"],"names":[],"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AoB,CAAC,CAAC;IAC1D,CAAC;IACS,aAAa,CAAC,GAAW;QACjC,OAAO,KAAK,CAAC,aAAa,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC;IACxD,CAAC;IAED,KAAK;QACH,OAAO,IAAI,KAAK,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IAC1C,CAAC;IAED,oBAAoB;QAClB,OAAO,KAAK,CAAC,mBAAmB,CAAC;IACnC,CAAC;;AA5LH,sBA6LC;AArLQ,yBAAmB,mBACxB,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,CAAC,EACV,OAAO,EAAE,CAAC,IACP,6BAAmB,EACtB;AAkLJ,SAAgB,WAAW,CAAC,UAAkC;IAC5D,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;AAC/B,CAAC;AAFD,kCAEC","file":"image.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport type { IImage, IImageGraphicAttribute, IRepeatType, ISetAttributeContext } from '../interface';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { DefaultImageAttribute } from './config';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport { IMAGE_NUMBER_TYPE } from './constants';\nimport { updateBoundsOfCommonOuterBorder } from './graphic-service/common-outer-boder-bounds';\n\nconst IMAGE_UPDATE_TAG_KEY = ['width', 'height', 'image', ...GRAPHIC_UPDATE_TAG_KEY];\n\n/**\n * TODO image 需要考虑加载问题 等load模块\n * 同时需要在Graphic增加 图片填充 or 图片按形状clip功能\n */\nexport class Image extends Graphic<IImageGraphicAttribute> implements IImage {\n type: 'image' = 'image';\n // 资源加载完成后回调,外部通过回调获取图片资源尺寸\n successCallback?: () => void;\n failCallback?: () => void;\n declare _actualWidth?: number;\n declare _actualHeight?: number;\n\n static NOWORK_ANIMATE_ATTR = {\n image: 1,\n repeatX: 1,\n repeatY: 1,\n ...NOWORK_ANIMATE_ATTR\n };\n\n constructor(params: IImageGraphicAttribute) {\n super(params);\n this.numberType = IMAGE_NUMBER_TYPE;\n\n this.loadImage(this.attribute.image);\n }\n\n getImageElement(): HTMLImageElement | HTMLCanvasElement | null {\n const { image } = this.attribute;\n if (!image || !this.resources) {\n return null;\n }\n const res = this.resources.get(image);\n if (res.state !== 'success') {\n return null;\n }\n return res.data;\n }\n\n get width(): number {\n this.tryUpdateAABBBounds();\n return this._actualWidth;\n }\n // set width(width: number) {\n // if (this.attribute.width === width) {\n // this.attribute.width = width;\n // this.addUpdateShapeAndBoundsTag();\n // }\n // }\n\n get height(): number {\n this.tryUpdateAABBBounds();\n return this._actualHeight;\n }\n // set height(height: number) {\n // if (this.attribute.height === height) {\n // this.attribute.height = height;\n // this.addUpdateShapeAndBoundsTag();\n // }\n // }\n get repeatX(): IRepeatType {\n return this.attribute.repeatX ?? 'no-repeat';\n }\n set repeatX(repeatX: IRepeatType) {\n if (this.attribute.repeatX === repeatX) {\n this.attribute.repeatX = repeatX;\n }\n }\n get repeatY(): IRepeatType {\n return this.attribute.repeatY ?? 'no-repeat';\n }\n set repeatY(repeatY: IRepeatType) {\n if (this.attribute.repeatY === repeatY) {\n this.attribute.repeatY = repeatY;\n }\n }\n get image(): string | HTMLImageElement | HTMLCanvasElement {\n return this.attribute.image;\n }\n set image(image: string | HTMLImageElement | HTMLCanvasElement) {\n if (image !== this.attribute.image) {\n this.attribute.image = image;\n this.loadImage(this.attribute.image);\n // this.addUpdateShapeAndBoundsTag();\n }\n }\n\n imageLoadSuccess(url: string, image: HTMLImageElement, cb?: () => void): void {\n super.imageLoadSuccess(url, image, () => {\n if (this.successCallback) {\n this.successCallback();\n }\n });\n this.addUpdateBoundTag();\n }\n\n imageLoadFail(url: string, cb?: () => void): void {\n super.imageLoadFail(url, () => {\n if (this.failCallback) {\n this.failCallback();\n }\n });\n }\n\n setAttributes(\n params: Partial<IImageGraphicAttribute>,\n forceUpdateTag?: boolean,\n context?: ISetAttributeContext\n ): void {\n if (params.image) {\n this.loadImage(params.image);\n }\n return super.setAttributes(params, forceUpdateTag, context);\n }\n\n setAttribute(key: string, value: any, forceUpdateTag?: boolean, context?: ISetAttributeContext): void {\n if (key === 'image') {\n this.loadImage(value);\n }\n return super.setAttribute(key, value, forceUpdateTag, context);\n }\n\n getGraphicTheme(): Required<IImageGraphicAttribute> {\n return getTheme(this).image;\n }\n\n protected updateAABBBounds(\n attribute: IImageGraphicAttribute,\n imageTheme: Required<IImageGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n const { maxWidth = imageTheme.maxWidth, maxHeight = imageTheme.maxHeight } = attribute;\n let { width, height } = attribute;\n if (width == null || height == null) {\n const imageElement = this.getImageElement();\n if (imageElement) {\n // 如果给了width或者height,那就使用已给的width或者height来按比例缩放,否则就在maxWidth和maxHeight之间按比例缩放\n const imageWidth = imageElement.width;\n const imageHeight = imageElement.height;\n if (width != null) {\n height = width * (imageHeight / imageWidth);\n } else if (height != null) {\n width = height * (imageWidth / imageHeight);\n } else {\n // 如果width和height都没有给,那就使用maxWidth和maxHeight来按比例缩放\n const imageRatio = imageWidth / imageHeight;\n const maxWHRatio = maxWidth / maxHeight;\n if (imageRatio > maxWHRatio) {\n width = maxWidth;\n height = maxWidth / imageRatio;\n } else {\n height = maxHeight;\n width = maxHeight * imageRatio;\n }\n }\n } else {\n width = maxWidth;\n height = maxHeight;\n }\n }\n this._actualWidth = width;\n this._actualHeight = height;\n aabbBounds.set(0, 0, width, height);\n }\n\n const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds);\n\n updateBoundsOfCommonOuterBorder(attribute, imageTheme, tb1);\n aabbBounds.union(tb1);\n tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);\n\n application.graphicService.transformAABBBounds(attribute, aabbBounds, imageTheme, false, this);\n return aabbBounds;\n }\n\n getDefaultAttribute(name: string) {\n return (DefaultImageAttribute as any)[name];\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, IMAGE_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, IMAGE_UPDATE_TAG_KEY);\n }\n\n clone() {\n return new Image({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Image.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createImage(attributes: IImageGraphicAttribute): IImage {\n return new Image(attributes);\n}\n"]}
@@ -76,8 +76,18 @@ class Line {
76
76
  paragraph.ellipsis = "hide", otherParagraphWidth += paragraph.width;
77
77
  }
78
78
  }
79
+ let fillStyle = "", globalAlpha = -1, currBgList = [];
80
+ const bgList = [ currBgList ];
79
81
  this.paragraphs.forEach(((paragraph, index) => {
80
- paragraph instanceof icon_1.RichTextIcon || paragraph.drawBackground(ctx, y, this.ascent, x, 0 === index, this.textAlign, this.height);
82
+ if (paragraph instanceof icon_1.RichTextIcon) return;
83
+ const data = paragraph.drawBackground(ctx, y, this.ascent, x, 0 === index, this.textAlign, this.height);
84
+ data && (fillStyle === data.fillStyle && globalAlpha === data.globalAlpha || (currBgList = [],
85
+ bgList.push(currBgList), fillStyle = data.fillStyle, globalAlpha = data.globalAlpha),
86
+ currBgList.push(data));
87
+ })), bgList.forEach((bg => {
88
+ if (0 === bg.length) return;
89
+ const data = bg[0], end = bg[bg.length - 1];
90
+ ctx.fillStyle = data.fillStyle, ctx.globalAlpha = data.globalAlpha, ctx.fillRect(data.left, data.top, end.right - data.left, end.bottom - data.top);
81
91
  })), this.paragraphs.forEach(((paragraph, index) => {
82
92
  if (paragraph instanceof icon_1.RichTextIcon) return paragraph.setAttributes({
83
93
  x: x + paragraph._x,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/richtext/line.ts"],"names":[],"mappings":";;;;;AAEA,iCAAsC;AACtC,4DAAoC;AACpC,mCAA4G;AA8B5G,MAAqB,IAAI;IAevB,YACE,IAAY,EACZ,KAAa,EACb,QAAgB,EAChB,MAAc,EACd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AS,EAAE,SAAS,CAAC,iBAAiB,CAAC,CAAC;YAChG,MAAM,aAAa,GAAG,KAAK,IAAI,CAAC,CAAC;YACjC,IAAI,aAAa,IAAI,IAAI,CAAC,UAAU,GAAG,mBAAmB,EAAE;gBAE1D,SAAS,CAAC,QAAQ,GAAG,KAAK,CAAC;gBAC3B,SAAS,CAAC,aAAa,GAAG,aAAa,CAAC;gBACxC,MAAM;aACP;iBAAM,IAAI,aAAa,IAAI,IAAI,CAAC,UAAU,GAAG,mBAAmB,GAAG,SAAS,CAAC,KAAK,EAAE;gBAEnF,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC;gBAC/B,SAAS,CAAC,aAAa,GAAG,aAAa,CAAC;gBACxC,SAAS,CAAC,2BAA2B,GAAG,IAAI,CAAC,UAAU,GAAG,mBAAmB,CAAC;gBAE9E,MAAM;aACP;iBAAM;gBAEL,SAAS,CAAC,QAAQ,GAAG,MAAM,CAAC;gBAC5B,mBAAmB,IAAI,SAAS,CAAC,KAAK,CAAC;aACxC;SACF;QAED,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;YAC3C,IAAI,SAAS,YAAY,mBAAY,EAAE;gBACrC,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC;aAC1B;iBAAM;gBACL,KAAK,IAAI,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACvD;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AApPD,uBAoPC","file":"line.js","sourcesContent":["// import { IContext2d } from '../../IContext';\nimport type { IContext2d, IRichTextIcon } from '../../interface';\nimport { RichTextIcon } from './icon';\nimport Paragraph from './paragraph';\nimport { applyFillStyle, applyStrokeStyle, DIRECTION_KEY, measureTextCanvas, regFirstSpace } from './utils';\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 行\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/line.js\nexport default class Line {\n left: number;\n top: number;\n width: number;\n height: number;\n baseline: number;\n ascent: number;\n descent: number;\n paragraphs: (Paragraph | RichTextIcon)[];\n actualWidth: number;\n blankWidth: number;\n textAlign: string;\n direction: 'horizontal' | 'vertical';\n directionKey: { width: string; height: string; left: string; x: string; y: string };\n\n constructor(\n left: number,\n width: number,\n baseline: number,\n ascent: number,\n descent: number,\n lineBuffer: (Paragraph | RichTextIcon)[],\n direction: 'horizontal' | 'vertical',\n isWidthMax: boolean\n ) {\n this.left = left;\n this.width = width;\n this.baseline = baseline;\n this.ascent = ascent;\n this.descent = descent;\n // this.height = ascent + descent;\n this.top = baseline - ascent;\n this.paragraphs = lineBuffer.map(p => p);\n this.textAlign =\n (this.paragraphs[0] instanceof RichTextIcon\n ? this.paragraphs[0].attribute.textAlign\n : this.paragraphs[0].character.textAlign) || 'left'; // 对齐方式选择第一个paragraph属性\n this.direction = direction;\n this.directionKey = DIRECTION_KEY[this.direction];\n\n this.actualWidth = 0;\n let maxHeight = 0;\n this.paragraphs.forEach((word, index) => {\n // 每行中第一个字符不能是空格\n if (index === 0 && word instanceof Paragraph) {\n const result = regFirstSpace.exec(word.text);\n if (result?.index !== 0) {\n word.text = word.text.slice(result?.index);\n word.updateWidth();\n }\n }\n this.actualWidth += word[this.directionKey.width];\n maxHeight = Math.max(word[this.directionKey.height], maxHeight);\n });\n this.height = maxHeight;\n\n this.blankWidth = !isWidthMax ? this.width - this.actualWidth : 0;\n\n this.calcOffset(width, isWidthMax);\n }\n\n calcOffset(width: number, isWidthMax: boolean) {\n // 处理对齐方式,计算左侧偏移距离和字符之间间距\n const directionKey = this.directionKey;\n const maxHeight = this.height;\n let x = this.left;\n let spacing = 0;\n if (this.actualWidth < width && !isWidthMax) {\n if (this.textAlign === 'right' || this.textAlign === 'end') {\n x = width - this.actualWidth;\n } else if (this.textAlign === 'center') {\n x = (width - this.actualWidth) / 2;\n } else if (this.textAlign === 'justify') {\n if (this.paragraphs.length < 2) {\n // 只有一个paragraph两端对齐居中显示\n x = (width - this.actualWidth) / 2;\n } else {\n spacing = (width - this.actualWidth) / (this.paragraphs.length - 1);\n }\n }\n }\n\n this.paragraphs.map(function (paragraph) {\n if (paragraph instanceof RichTextIcon) {\n // paragraph.setAttribute(directionKey.x, x);\n paragraph['_' + directionKey.x] = x;\n x += paragraph[directionKey.width] + spacing;\n // 处理纵向对齐\n paragraph['_' + directionKey.y] =\n paragraph.attribute.textBaseline === 'top'\n ? 0\n : paragraph.attribute.textBaseline === 'bottom'\n ? maxHeight - paragraph.height\n : (maxHeight - paragraph.height) / 2;\n } else {\n paragraph[directionKey.left] = x;\n x += paragraph[directionKey.width] + spacing;\n }\n });\n }\n\n draw(\n ctx: IContext2d,\n lastLine: boolean,\n x: number,\n y: number,\n drawEllipsis: boolean | string,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) {\n if (drawEllipsis && (lastLine || this.paragraphs.some(p => (p as Paragraph).overflow))) {\n // 检测是否需要省略号,因为会有多行同时省略的情况\n let emptyOverflow = true;\n let skipEllipsis = false;\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if ((paragraph as Paragraph).overflow) {\n emptyOverflow = emptyOverflow && (paragraph as Paragraph).text === '';\n } else {\n if (emptyOverflow) {\n skipEllipsis = true;\n break;\n }\n }\n }\n\n // 处理省略号\n let otherParagraphWidth = 0;\n if (!skipEllipsis) {\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if ((paragraph as Paragraph).overflow) {\n if ((paragraph as Paragraph).text === '') {\n break;\n }\n continue;\n }\n if (paragraph instanceof RichTextIcon) {\n break; // todo: 处理最后为图标,显示省略号的情况\n }\n if (this.direction === 'vertical' && paragraph.direction !== 'vertical') {\n paragraph.verticalEllipsis = true;\n break;\n }\n const ellipsis = drawEllipsis === true ? '...' : drawEllipsis || '';\n paragraph.ellipsisStr = ellipsis;\n // const { width } = measureText('...', paragraph.style);\n const { width } = measureTextCanvas(ellipsis, paragraph.character, paragraph.ascentDescentMode);\n const ellipsisWidth = width || 0;\n if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {\n // 省略号可以直接接在后面paragraph\n lastLine && (paragraph.ellipsis = 'add');\n\n break;\n } else if (ellipsisWidth <= this.blankWidth + otherParagraphWidth + paragraph.width) {\n // 省略号需要替换paragraph中的字符\n paragraph.ellipsis = 'replace';\n paragraph.ellipsisWidth = ellipsisWidth;\n paragraph.ellipsisOtherParagraphWidth = this.blankWidth + otherParagraphWidth;\n\n break;\n } else {\n // 省略号需要的width大于paragraph的width,隐藏paragraph,向前搜索\n paragraph.ellipsis = 'hide';\n otherParagraphWidth += paragraph.width;\n }\n }\n }\n }\n\n // 绘制背景\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n return;\n }\n paragraph.drawBackground(ctx, y, this.ascent, x, index === 0, this.textAlign, this.height);\n });\n // 正常绘制\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n // 更新icon位置\n paragraph.setAttributes({\n x: x + paragraph._x,\n y: y + paragraph._y\n });\n\n // 绘制icon\n drawIcon(paragraph, ctx, x + paragraph._x, y + paragraph._y, this.ascent);\n return;\n }\n const b = {\n x1: this.left,\n y1: this.top,\n x2: this.left + this.actualWidth,\n y2: this.top + this.height\n };\n applyStrokeStyle(ctx, paragraph.character);\n // 下面绘制underline和line-through时需要设置FillStyle\n applyFillStyle(ctx, paragraph.character, b);\n paragraph.draw(ctx, y, this.ascent, x, index === 0, this.textAlign, this.height);\n });\n }\n\n getWidthWithEllips(ellipsis: string) {\n // 处理省略号\n let otherParagraphWidth = 0;\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if (paragraph instanceof RichTextIcon) {\n break; // todo: 处理最后为图标,显示省略号的情况\n }\n\n const { width } = measureTextCanvas(ellipsis, paragraph.character, paragraph.ascentDescentMode);\n const ellipsisWidth = width || 0;\n if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {\n // 省略号可以直接接在后面paragraph\n paragraph.ellipsis = 'add';\n paragraph.ellipsisWidth = ellipsisWidth;\n break;\n } else if (ellipsisWidth <= this.blankWidth + otherParagraphWidth + paragraph.width) {\n // 省略号需要替换paragraph中的字符\n paragraph.ellipsis = 'replace';\n paragraph.ellipsisWidth = ellipsisWidth;\n paragraph.ellipsisOtherParagraphWidth = this.blankWidth + otherParagraphWidth;\n\n break;\n } else {\n // 省略号需要的width大于paragraph的width,隐藏paragraph,向前搜索\n paragraph.ellipsis = 'hide';\n otherParagraphWidth += paragraph.width;\n }\n }\n\n let width = 0;\n // 正常绘制\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n width += paragraph.width; // todo: 处理direction\n } else {\n width += paragraph.getWidthWithEllips(this.direction);\n }\n });\n\n return width;\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/richtext/line.ts"],"names":[],"mappings":";;;;;AAEA,iCAAsC;AACtC,4DAAoC;AACpC,mCAA4G;AA8B5G,MAAqB,IAAI;IAevB,YACE,IAAY,EACZ,KAAa,EACb,QAAgB,EAChB,MAAc,EACd,OAAe,EACf,UAAwC,EACxC,SAAoC,EACpC,UAAmB;QAEnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,GAAG,GAAG,QAAQ,GAAG,MAAM,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACzC,IAAI,CAAC,SAAS;YACZ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY,mBAAY;gBACzC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS;gBACxC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC;QACxD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,qBAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAElD,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAEtC,IAAI,KAAK,KAAK,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I,SAAS,YAAY,mBAAY,EAAE;gBACrC,MAAM;aACP;YAED,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,yBAAiB,EAAC,QAAQ,EAAE,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,iBAAiB,CAAC,CAAC;YAChG,MAAM,aAAa,GAAG,KAAK,IAAI,CAAC,CAAC;YACjC,IAAI,aAAa,IAAI,IAAI,CAAC,UAAU,GAAG,mBAAmB,EAAE;gBAE1D,SAAS,CAAC,QAAQ,GAAG,KAAK,CAAC;gBAC3B,SAAS,CAAC,aAAa,GAAG,aAAa,CAAC;gBACxC,MAAM;aACP;iBAAM,IAAI,aAAa,IAAI,IAAI,CAAC,UAAU,GAAG,mBAAmB,GAAG,SAAS,CAAC,KAAK,EAAE;gBAEnF,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC;gBAC/B,SAAS,CAAC,aAAa,GAAG,aAAa,CAAC;gBACxC,SAAS,CAAC,2BAA2B,GAAG,IAAI,CAAC,UAAU,GAAG,mBAAmB,CAAC;gBAE9E,MAAM;aACP;iBAAM;gBAEL,SAAS,CAAC,QAAQ,GAAG,MAAM,CAAC;gBAC5B,mBAAmB,IAAI,SAAS,CAAC,KAAK,CAAC;aACxC;SACF;QAED,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;YAC3C,IAAI,SAAS,YAAY,mBAAY,EAAE;gBACrC,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC;aAC1B;iBAAM;gBACL,KAAK,IAAI,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACvD;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAtRD,uBAsRC","file":"line.js","sourcesContent":["// import { IContext2d } from '../../IContext';\nimport type { IContext2d, IRichTextIcon } from '../../interface';\nimport { RichTextIcon } from './icon';\nimport Paragraph from './paragraph';\nimport { applyFillStyle, applyStrokeStyle, DIRECTION_KEY, measureTextCanvas, regFirstSpace } from './utils';\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 行\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/line.js\nexport default class Line {\n left: number;\n top: number;\n width: number;\n height: number;\n baseline: number;\n ascent: number;\n descent: number;\n paragraphs: (Paragraph | RichTextIcon)[];\n actualWidth: number;\n blankWidth: number;\n textAlign: string;\n direction: 'horizontal' | 'vertical';\n directionKey: { width: string; height: string; left: string; x: string; y: string };\n\n constructor(\n left: number,\n width: number,\n baseline: number,\n ascent: number,\n descent: number,\n lineBuffer: (Paragraph | RichTextIcon)[],\n direction: 'horizontal' | 'vertical',\n isWidthMax: boolean\n ) {\n this.left = left;\n this.width = width;\n this.baseline = baseline;\n this.ascent = ascent;\n this.descent = descent;\n // this.height = ascent + descent;\n this.top = baseline - ascent;\n this.paragraphs = lineBuffer.map(p => p);\n this.textAlign =\n (this.paragraphs[0] instanceof RichTextIcon\n ? this.paragraphs[0].attribute.textAlign\n : this.paragraphs[0].character.textAlign) || 'left'; // 对齐方式选择第一个paragraph属性\n this.direction = direction;\n this.directionKey = DIRECTION_KEY[this.direction];\n\n this.actualWidth = 0;\n let maxHeight = 0;\n this.paragraphs.forEach((word, index) => {\n // 每行中第一个字符不能是空格\n if (index === 0 && word instanceof Paragraph) {\n const result = regFirstSpace.exec(word.text);\n if (result?.index !== 0) {\n word.text = word.text.slice(result?.index);\n word.updateWidth();\n }\n }\n this.actualWidth += word[this.directionKey.width];\n maxHeight = Math.max(word[this.directionKey.height], maxHeight);\n });\n this.height = maxHeight;\n\n this.blankWidth = !isWidthMax ? this.width - this.actualWidth : 0;\n\n this.calcOffset(width, isWidthMax);\n }\n\n calcOffset(width: number, isWidthMax: boolean) {\n // 处理对齐方式,计算左侧偏移距离和字符之间间距\n const directionKey = this.directionKey;\n const maxHeight = this.height;\n let x = this.left;\n let spacing = 0;\n if (this.actualWidth < width && !isWidthMax) {\n if (this.textAlign === 'right' || this.textAlign === 'end') {\n x = width - this.actualWidth;\n } else if (this.textAlign === 'center') {\n x = (width - this.actualWidth) / 2;\n } else if (this.textAlign === 'justify') {\n if (this.paragraphs.length < 2) {\n // 只有一个paragraph两端对齐居中显示\n x = (width - this.actualWidth) / 2;\n } else {\n spacing = (width - this.actualWidth) / (this.paragraphs.length - 1);\n }\n }\n }\n\n this.paragraphs.map(function (paragraph) {\n if (paragraph instanceof RichTextIcon) {\n // paragraph.setAttribute(directionKey.x, x);\n paragraph['_' + directionKey.x] = x;\n x += paragraph[directionKey.width] + spacing;\n // 处理纵向对齐\n paragraph['_' + directionKey.y] =\n paragraph.attribute.textBaseline === 'top'\n ? 0\n : paragraph.attribute.textBaseline === 'bottom'\n ? maxHeight - paragraph.height\n : (maxHeight - paragraph.height) / 2;\n } else {\n paragraph[directionKey.left] = x;\n x += paragraph[directionKey.width] + spacing;\n }\n });\n }\n\n draw(\n ctx: IContext2d,\n lastLine: boolean,\n x: number,\n y: number,\n drawEllipsis: boolean | string,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) {\n if (drawEllipsis && (lastLine || this.paragraphs.some(p => (p as Paragraph).overflow))) {\n // 检测是否需要省略号,因为会有多行同时省略的情况\n let emptyOverflow = true;\n let skipEllipsis = false;\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if ((paragraph as Paragraph).overflow) {\n emptyOverflow = emptyOverflow && (paragraph as Paragraph).text === '';\n } else {\n if (emptyOverflow) {\n skipEllipsis = true;\n break;\n }\n }\n }\n\n // 处理省略号\n let otherParagraphWidth = 0;\n if (!skipEllipsis) {\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if ((paragraph as Paragraph).overflow) {\n if ((paragraph as Paragraph).text === '') {\n break;\n }\n continue;\n }\n if (paragraph instanceof RichTextIcon) {\n break; // todo: 处理最后为图标,显示省略号的情况\n }\n if (this.direction === 'vertical' && paragraph.direction !== 'vertical') {\n paragraph.verticalEllipsis = true;\n break;\n }\n const ellipsis = drawEllipsis === true ? '...' : drawEllipsis || '';\n paragraph.ellipsisStr = ellipsis;\n // const { width } = measureText('...', paragraph.style);\n const { width } = measureTextCanvas(ellipsis, paragraph.character, paragraph.ascentDescentMode);\n const ellipsisWidth = width || 0;\n if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {\n // 省略号可以直接接在后面paragraph\n lastLine && (paragraph.ellipsis = 'add');\n\n break;\n } else if (ellipsisWidth <= this.blankWidth + otherParagraphWidth + paragraph.width) {\n // 省略号需要替换paragraph中的字符\n paragraph.ellipsis = 'replace';\n paragraph.ellipsisWidth = ellipsisWidth;\n paragraph.ellipsisOtherParagraphWidth = this.blankWidth + otherParagraphWidth;\n\n break;\n } else {\n // 省略号需要的width大于paragraph的width,隐藏paragraph,向前搜索\n paragraph.ellipsis = 'hide';\n otherParagraphWidth += paragraph.width;\n }\n }\n }\n }\n\n // 绘制背景\n // 属性相同的背景,合并绘制\n let fillStyle = '';\n let globalAlpha = -1;\n let currBgList: {\n fillStyle: string;\n globalAlpha: number;\n left: number;\n top: number;\n right: number;\n bottom: number;\n }[] = [];\n const bgList = [currBgList];\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n return;\n }\n const data = paragraph.drawBackground(ctx, y, this.ascent, x, index === 0, this.textAlign, this.height);\n if (!data) {\n return;\n }\n if (!(fillStyle === data.fillStyle && globalAlpha === data.globalAlpha)) {\n currBgList = [];\n bgList.push(currBgList);\n fillStyle = data.fillStyle;\n globalAlpha = data.globalAlpha;\n }\n currBgList.push(data);\n });\n // 绘制背景\n bgList.forEach(bg => {\n if (bg.length === 0) {\n return;\n }\n const data = bg[0];\n const end = bg[bg.length - 1];\n ctx.fillStyle = data.fillStyle;\n ctx.globalAlpha = data.globalAlpha;\n ctx.fillRect(data.left, data.top, end.right - data.left, end.bottom - data.top);\n });\n\n // 正常绘制\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n // 更新icon位置\n paragraph.setAttributes({\n x: x + paragraph._x,\n y: y + paragraph._y\n });\n\n // 绘制icon\n drawIcon(paragraph, ctx, x + paragraph._x, y + paragraph._y, this.ascent);\n return;\n }\n const b = {\n x1: this.left,\n y1: this.top,\n x2: this.left + this.actualWidth,\n y2: this.top + this.height\n };\n applyStrokeStyle(ctx, paragraph.character);\n // 下面绘制underline和line-through时需要设置FillStyle\n applyFillStyle(ctx, paragraph.character, b);\n paragraph.draw(ctx, y, this.ascent, x, index === 0, this.textAlign, this.height);\n });\n }\n\n getWidthWithEllips(ellipsis: string) {\n // 处理省略号\n let otherParagraphWidth = 0;\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if (paragraph instanceof RichTextIcon) {\n break; // todo: 处理最后为图标,显示省略号的情况\n }\n\n const { width } = measureTextCanvas(ellipsis, paragraph.character, paragraph.ascentDescentMode);\n const ellipsisWidth = width || 0;\n if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {\n // 省略号可以直接接在后面paragraph\n paragraph.ellipsis = 'add';\n paragraph.ellipsisWidth = ellipsisWidth;\n break;\n } else if (ellipsisWidth <= this.blankWidth + otherParagraphWidth + paragraph.width) {\n // 省略号需要替换paragraph中的字符\n paragraph.ellipsis = 'replace';\n paragraph.ellipsisWidth = ellipsisWidth;\n paragraph.ellipsisOtherParagraphWidth = this.blankWidth + otherParagraphWidth;\n\n break;\n } else {\n // 省略号需要的width大于paragraph的width,隐藏paragraph,向前搜索\n paragraph.ellipsis = 'hide';\n otherParagraphWidth += paragraph.width;\n }\n }\n\n let width = 0;\n // 正常绘制\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n width += paragraph.width; // todo: 处理direction\n } else {\n width += paragraph.getWidthWithEllips(this.direction);\n }\n });\n\n return width;\n }\n}\n"]}
@@ -25,7 +25,14 @@ export default class Paragraph {
25
25
  overflow?: boolean;
26
26
  constructor(text: string, newLine: boolean, character: IRichTextParagraphCharacter, ascentDescentMode?: 'actual' | 'font');
27
27
  updateWidth(): void;
28
- drawBackground(ctx: IContext2d, top: number, ascent: number, deltaLeft: number, isLineFirst: boolean, textAlign: string, lineHeight: number): void;
28
+ drawBackground(ctx: IContext2d, top: number, ascent: number, deltaLeft: number, isLineFirst: boolean, textAlign: string, lineHeight: number): {
29
+ fillStyle: string;
30
+ globalAlpha: number;
31
+ left: number;
32
+ top: number;
33
+ right: number;
34
+ bottom: number;
35
+ };
29
36
  draw(ctx: IContext2d, top: number, ascent: number, deltaLeft: number, isLineFirst: boolean, textAlign: string, lineHeight: number): void;
30
37
  getWidthWithEllips(direction: string): number;
31
38
  }
@@ -42,7 +42,7 @@ class Paragraph {
42
42
  this.width = this.heightOrigin, this.height = this.widthOrigin);
43
43
  }
44
44
  drawBackground(ctx, top, ascent, deltaLeft, isLineFirst, textAlign, lineHeight) {
45
- if (!this.character.background || this.character.backgroundOpacity && !(this.character.backgroundOpacity > 0)) return;
45
+ if ("" === this.text || "\n" === this.text || !this.character.background || this.character.backgroundOpacity && !(this.character.backgroundOpacity > 0)) return;
46
46
  let baseline = top + ascent, text = this.text, left = this.left + deltaLeft;
47
47
  baseline += this.top;
48
48
  let direction = this.direction;
@@ -56,22 +56,11 @@ class Paragraph {
56
56
  }
57
57
  }
58
58
  }
59
- switch (this.character.script) {
60
- case "super":
61
- baseline -= this.ascent * (1 / 3);
62
- break;
63
-
64
- case "sub":
65
- baseline += this.descent / 2;
66
- }
67
- "vertical" === direction && (ctx.save(), ctx.rotateAbout(Math.PI / 2, left, baseline),
68
- ctx.translate(-this.heightOrigin || -this.lineHeight / 2, -this.descent / 2), ctx.translate(left, baseline),
69
- left = 0, baseline = 0);
70
- const fillStyle = ctx.fillStyle, globalAlpha = ctx.globalAlpha;
71
- ctx.fillStyle = this.character.background, void 0 !== this.character.backgroundOpacity && (ctx.globalAlpha = this.character.backgroundOpacity);
72
59
  const lrtb = getFixedLRTB(left, left + (this.widthOrigin || this.width), top, top + lineHeight);
73
- ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top),
74
- ctx.fillStyle = fillStyle, ctx.globalAlpha = globalAlpha;
60
+ return Object.assign(Object.assign({}, lrtb), {
61
+ fillStyle: this.character.background,
62
+ globalAlpha: this.character.backgroundOpacity
63
+ });
75
64
  }
76
65
  draw(ctx, top, ascent, deltaLeft, isLineFirst, textAlign, lineHeight) {
77
66
  let baseline = top + ascent, text = this.text, left = this.left + deltaLeft;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/richtext/paragraph.ts"],"names":[],"mappings":";;;AAAA,8CAAyD;AAEzD,mCAAgE;AAEhE,SAAS,YAAY,CAAC,IAAY,EAAE,KAAa,EAAE,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CAAC,aAAa,GAAG,YAAY,CAAC;SAClD;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAxYD,4BAwYC;AAED,SAAgB,iBAAiB,CAAC,SAAoB,EAAE,KAAa;IACnE,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1C,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,iBAAiB,CAAC,CAAC;IACrG,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,iBAAiB,CAAC,CAAC;IAExF,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAClB,CAAC;AAPD,8CAOC","file":"paragraph.js","sourcesContent":["import { calculateLineHeight } from '../../common/utils';\nimport type { IContext2d, IRichTextParagraphCharacter } from '../../interface';\nimport { measureTextCanvas, getStrByWithCanvas } from './utils';\n\nfunction getFixedLRTB(left: number, right: number, top: number, bottom: number) {\n const leftInt = Math.round(left);\n const topInt = Math.round(top);\n const rightInt = Math.round(right);\n const bottomInt = Math.round(bottom);\n const _left = left > leftInt ? leftInt : leftInt - 0.5;\n const _top = top > topInt ? topInt : topInt - 0.5;\n const _right = rightInt > right ? rightInt : rightInt + 0.5;\n const _bottom = bottomInt > bottom ? bottomInt : bottomInt + 0.5;\n return {\n left: _left,\n top: _top,\n right: _right,\n bottom: _bottom\n };\n}\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 文字段\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/text.js\nexport default class Paragraph {\n text: string;\n ascent: number;\n descent: number;\n width: number;\n height: number;\n lineHeight: number;\n fontSize: number;\n length: number;\n newLine: boolean;\n character: IRichTextParagraphCharacter;\n left: number;\n top: number;\n // rotate?: number;\n direction?: 'horizontal' | 'vertical';\n // bounds?: Bounds;\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n ascentDescentMode?: 'actual' | 'font';\n\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisStr: string;\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n overflow?: boolean;\n\n constructor(\n text: string,\n newLine: boolean,\n character: IRichTextParagraphCharacter,\n ascentDescentMode?: 'actual' | 'font'\n ) {\n // 测量文字\n this.fontSize = character.fontSize || 16;\n this.textBaseline = character.textBaseline || 'alphabetic';\n this.ascentDescentMode = ascentDescentMode;\n\n // 处理行高:\n // lineHeight为数字时,大于fontSize取lineHeight,小于fontSize时取fontSize\n // lineHeight不为数字时,统一认为lineHeight为'normal',值取1.2 * fontSize\n const lineHeight = calculateLineHeight(character.lineHeight, this.fontSize);\n if (typeof lineHeight === 'number') {\n this.lineHeight = lineHeight > this.fontSize ? lineHeight : this.fontSize;\n } else {\n this.lineHeight = Math.floor(1.2 * this.fontSize);\n }\n\n this.height = this.lineHeight;\n\n const { ascent, height, descent, width } = measureTextCanvas(text, character, this.ascentDescentMode);\n\n let halfDetaHeight = 0;\n let deltaAscent = 0;\n let deltaDescent = 0;\n if (this.height > height) {\n // measureTextCanvas测量出的是纯文字高度,this.height是考虑行高后的高度\n // 如果this.height > height,将超过的高度平均分配到ascent和descent上\n halfDetaHeight = (this.height - height) / 2;\n deltaAscent = Math.ceil(halfDetaHeight);\n deltaDescent = Math.floor(halfDetaHeight);\n }\n\n if (this.textBaseline === 'top') {\n this.ascent = halfDetaHeight;\n this.descent = height - halfDetaHeight;\n } else if (this.textBaseline === 'bottom') {\n this.ascent = height - halfDetaHeight;\n this.descent = halfDetaHeight;\n } else if (this.textBaseline === 'middle') {\n this.ascent = this.height / 2;\n this.descent = this.height / 2;\n } else {\n this.ascent = ascent + deltaAscent;\n this.descent = descent + deltaDescent;\n }\n\n this.length = text.length;\n this.width = width || 0;\n this.text = text || '';\n this.newLine = newLine || false;\n this.character = character;\n\n this.left = 0;\n this.top = 0;\n\n this.ellipsis = 'normal';\n this.ellipsisWidth = 0;\n this.ellipsisOtherParagraphWidth = 0;\n\n // 处理旋转\n if (character.direction === 'vertical') {\n this.direction = character.direction;\n this.widthOrigin = this.width;\n this.heightOrigin = this.height;\n // const bounds = new Bounds();\n // bounds.set(0, 0, this.width, this.height);\n // bounds.rotate(Math.PI / 2, this.width / 2, this.height / 2);\n // this.bounds = bounds;\n // this.width = bounds.width();\n // this.height = bounds.height();\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n this.lineHeight = this.height;\n }\n this.ellipsisStr = '...';\n }\n\n updateWidth() {\n const { width } = measureTextCanvas(this.text, this.character, this.ascentDescentMode);\n this.width = width;\n if (this.direction === 'vertical') {\n this.widthOrigin = this.width;\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n }\n }\n\n drawBackground(\n ctx: IContext2d,\n top: number,\n ascent: number,\n deltaLeft: number,\n isLineFirst: boolean,\n textAlign: string,\n lineHeight: number\n ) {\n if (!(this.character.background && (!this.character.backgroundOpacity || this.character.backgroundOpacity > 0))) {\n return;\n }\n let baseline = top + ascent;\n let text = this.text;\n let left = this.left + deltaLeft;\n baseline += this.top;\n let direction = this.direction;\n\n if (this.verticalEllipsis) {\n text = this.ellipsisStr;\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n left -= this.ellipsisWidth;\n }\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, this.width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n (direction === 'vertical' ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n const { width } = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);\n if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n left -= this.ellipsisWidth - width;\n }\n }\n }\n\n // prepareContext(ctx);\n switch (this.character.script) {\n case 'super':\n baseline -= this.ascent * (1 / 3);\n break;\n case 'sub':\n baseline += this.descent / 2;\n break;\n }\n\n // 处理旋转\n if (direction === 'vertical') {\n ctx.save();\n ctx.rotateAbout(Math.PI / 2, left, baseline);\n ctx.translate(-(this.heightOrigin as number) || -this.lineHeight / 2, -this.descent / 2);\n ctx.translate(left, baseline);\n left = 0;\n baseline = 0;\n }\n\n const fillStyle = ctx.fillStyle;\n const globalAlpha = ctx.globalAlpha;\n ctx.fillStyle = this.character.background;\n if (this.character.backgroundOpacity !== void 0) {\n ctx.globalAlpha = this.character.backgroundOpacity;\n }\n // 背景稍微扩充一些buf,否则会出现白线\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + lineHeight;\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n ctx.fillStyle = fillStyle;\n ctx.globalAlpha = globalAlpha;\n }\n\n draw(\n ctx: IContext2d,\n top: number,\n ascent: number,\n deltaLeft: number,\n isLineFirst: boolean,\n textAlign: string,\n lineHeight: number\n ) {\n let baseline = top + ascent;\n let text = this.text;\n let left = this.left + deltaLeft;\n baseline += this.top;\n let direction = this.direction;\n\n if (this.verticalEllipsis) {\n text = this.ellipsisStr;\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n left -= this.ellipsisWidth;\n }\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, this.width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n (direction === 'vertical' ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n const { width } = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);\n if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n left -= this.ellipsisWidth - width;\n }\n }\n }\n\n // prepareContext(ctx);\n switch (this.character.script) {\n case 'super':\n baseline -= this.ascent * (1 / 3);\n break;\n case 'sub':\n baseline += this.descent / 2;\n break;\n }\n\n // if (isLineFirst) {\n // const result = regFirstSpace.exec(text);\n // if (result?.index !== 0) {\n // text = text.slice(result?.index);\n // }\n // }\n\n // 处理旋转\n if (direction === 'vertical') {\n ctx.save();\n ctx.rotateAbout(Math.PI / 2, left, baseline);\n ctx.translate(-(this.heightOrigin as number) || -this.lineHeight / 2, -this.descent / 2);\n ctx.translate(left, baseline);\n left = 0;\n baseline = 0;\n }\n\n // if (this.character.fill) {\n // if (this.character.background && (!this.character.backgroundOpacity || this.character.backgroundOpacity > 0)) {\n // const fillStyle = ctx.fillStyle;\n // const globalAlpha = ctx.globalAlpha;\n // ctx.fillStyle = this.character.background;\n // if (this.character.backgroundOpacity !== void 0) {\n // ctx.globalAlpha = this.character.backgroundOpacity;\n // }\n // // 背景稍微扩充一些buf,否则会出现白线\n // const right = left + (this.widthOrigin || this.width);\n // const bottom = top + lineHeight;\n // const lrtb = getFixedLRTB(left, right, top, bottom);\n // ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n // ctx.fillStyle = fillStyle;\n // ctx.globalAlpha = globalAlpha;\n // }\n // }\n\n const { lineWidth = 1 } = this.character;\n if (this.character.stroke && lineWidth) {\n ctx.strokeText(text, left, baseline);\n }\n\n if (this.character.fill) {\n ctx.fillText(text, left, baseline);\n }\n\n if (this.character.fill) {\n if (this.character.lineThrough || this.character.underline) {\n if (this.character.underline) {\n const top = 1 + baseline;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(\n lrtb.left,\n 1 + baseline,\n lrtb.right - lrtb.left,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n if (this.character.lineThrough) {\n const top = 1 + baseline - this.ascent / 2;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(\n lrtb.left,\n 1 + baseline - this.ascent / 2,\n lrtb.right - lrtb.left,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n } else if (this.character.textDecoration === 'underline') {\n const top = 1 + baseline;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(\n lrtb.left,\n 1 + baseline,\n lrtb.right - lrtb.left,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n } else if (this.character.textDecoration === 'line-through') {\n const top = 1 + baseline - this.ascent / 2;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(\n lrtb.left,\n 1 + baseline - this.ascent / 2,\n lrtb.right - lrtb.left,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n }\n\n if (direction === 'vertical') {\n ctx.restore();\n }\n }\n\n getWidthWithEllips(direction: string): number {\n let text = this.text;\n // const direction = this.direction;\n const width = direction === 'vertical' ? this.height : this.width;\n // const height = direction === 'vertical' ? this.width: this.height;\n\n if (this.ellipsis === 'hide') {\n return width;\n } else if (this.ellipsis === 'add') {\n return width + this.ellipsisWidth;\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n const { width: measureWidth } = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);\n return width + this.ellipsisWidth - measureWidth;\n }\n return width;\n }\n}\n\nexport function seperateParagraph(paragraph: Paragraph, index: number) {\n const text1 = paragraph.text.slice(0, index);\n const text2 = paragraph.text.slice(index);\n const p1 = new Paragraph(text1, paragraph.newLine, paragraph.character, paragraph.ascentDescentMode);\n const p2 = new Paragraph(text2, true, paragraph.character, paragraph.ascentDescentMode);\n\n return [p1, p2];\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/richtext/paragraph.ts"],"names":[],"mappings":";;;AAAA,8CAAyD;AAEzD,mCAAgE;AAEhE,SAAS,YAAY,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW,EAAE,MAAc;IAC5E,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACrC,MAAM,KAAK,GAAG,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,GAAG,GAAG,CAAC;IACvD,MAAM,IAAI,GAAG,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC;IAClD,MAAM,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,GAAG,GAAG,CAAC;IAC5D,MAAM,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC;IACjE,OAAO;QACL,IAAI,EAAE,KAAK;QACX,GAAG,EAAE,IAAI;QACT,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,OAAO;KAChB,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port type { IContext2d, IRichTextParagraphCharacter } from '../../interface';\nimport { measureTextCanvas, getStrByWithCanvas } from './utils';\n\nfunction getFixedLRTB(left: number, right: number, top: number, bottom: number) {\n const leftInt = Math.round(left);\n const topInt = Math.round(top);\n const rightInt = Math.round(right);\n const bottomInt = Math.round(bottom);\n const _left = left > leftInt ? leftInt : leftInt - 0.5;\n const _top = top > topInt ? topInt : topInt - 0.5;\n const _right = rightInt > right ? rightInt : rightInt + 0.5;\n const _bottom = bottomInt > bottom ? bottomInt : bottomInt + 0.5;\n return {\n left: _left,\n top: _top,\n right: _right,\n bottom: _bottom\n };\n}\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 文字段\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/text.js\nexport default class Paragraph {\n text: string;\n ascent: number;\n descent: number;\n width: number;\n height: number;\n lineHeight: number;\n fontSize: number;\n length: number;\n newLine: boolean;\n character: IRichTextParagraphCharacter;\n left: number;\n top: number;\n // rotate?: number;\n direction?: 'horizontal' | 'vertical';\n // bounds?: Bounds;\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n ascentDescentMode?: 'actual' | 'font';\n\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisStr: string;\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n overflow?: boolean;\n\n constructor(\n text: string,\n newLine: boolean,\n character: IRichTextParagraphCharacter,\n ascentDescentMode?: 'actual' | 'font'\n ) {\n // 测量文字\n this.fontSize = character.fontSize || 16;\n this.textBaseline = character.textBaseline || 'alphabetic';\n this.ascentDescentMode = ascentDescentMode;\n\n // 处理行高:\n // lineHeight为数字时,大于fontSize取lineHeight,小于fontSize时取fontSize\n // lineHeight不为数字时,统一认为lineHeight为'normal',值取1.2 * fontSize\n const lineHeight = calculateLineHeight(character.lineHeight, this.fontSize);\n if (typeof lineHeight === 'number') {\n this.lineHeight = lineHeight > this.fontSize ? lineHeight : this.fontSize;\n } else {\n this.lineHeight = Math.floor(1.2 * this.fontSize);\n }\n\n this.height = this.lineHeight;\n\n const { ascent, height, descent, width } = measureTextCanvas(text, character, this.ascentDescentMode);\n\n let halfDetaHeight = 0;\n let deltaAscent = 0;\n let deltaDescent = 0;\n if (this.height > height) {\n // measureTextCanvas测量出的是纯文字高度,this.height是考虑行高后的高度\n // 如果this.height > height,将超过的高度平均分配到ascent和descent上\n halfDetaHeight = (this.height - height) / 2;\n deltaAscent = Math.ceil(halfDetaHeight);\n deltaDescent = Math.floor(halfDetaHeight);\n }\n\n if (this.textBaseline === 'top') {\n this.ascent = halfDetaHeight;\n this.descent = height - halfDetaHeight;\n } else if (this.textBaseline === 'bottom') {\n this.ascent = height - halfDetaHeight;\n this.descent = halfDetaHeight;\n } else if (this.textBaseline === 'middle') {\n this.ascent = this.height / 2;\n this.descent = this.height / 2;\n } else {\n this.ascent = ascent + deltaAscent;\n this.descent = descent + deltaDescent;\n }\n\n this.length = text.length;\n this.width = width || 0;\n this.text = text || '';\n this.newLine = newLine || false;\n this.character = character;\n\n this.left = 0;\n this.top = 0;\n\n this.ellipsis = 'normal';\n this.ellipsisWidth = 0;\n this.ellipsisOtherParagraphWidth = 0;\n\n // 处理旋转\n if (character.direction === 'vertical') {\n this.direction = character.direction;\n this.widthOrigin = this.width;\n this.heightOrigin = this.height;\n // const bounds = new Bounds();\n // bounds.set(0, 0, this.width, this.height);\n // bounds.rotate(Math.PI / 2, this.width / 2, this.height / 2);\n // this.bounds = bounds;\n // this.width = bounds.width();\n // this.height = bounds.height();\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n this.lineHeight = this.height;\n }\n this.ellipsisStr = '...';\n }\n\n updateWidth() {\n const { width } = measureTextCanvas(this.text, this.character, this.ascentDescentMode);\n this.width = width;\n if (this.direction === 'vertical') {\n this.widthOrigin = this.width;\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n }\n }\n\n drawBackground(\n ctx: IContext2d,\n top: number,\n ascent: number,\n deltaLeft: number,\n isLineFirst: boolean,\n textAlign: string,\n lineHeight: number\n ) {\n if (\n !(\n this.text !== '' &&\n this.text !== '\\n' &&\n this.character.background &&\n (!this.character.backgroundOpacity || this.character.backgroundOpacity > 0)\n )\n ) {\n return;\n }\n let baseline = top + ascent;\n let text = this.text;\n let left = this.left + deltaLeft;\n baseline += this.top;\n let direction = this.direction;\n\n if (this.verticalEllipsis) {\n text = this.ellipsisStr;\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n left -= this.ellipsisWidth;\n }\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, this.width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n (direction === 'vertical' ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n const { width } = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);\n if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n left -= this.ellipsisWidth - width;\n }\n }\n }\n // 背景稍微扩充一些buf,否则会出现白线\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + lineHeight;\n const lrtb = getFixedLRTB(left, right, top, bottom);\n\n return {\n ...lrtb,\n fillStyle: this.character.background,\n globalAlpha: this.character.backgroundOpacity\n };\n }\n\n draw(\n ctx: IContext2d,\n top: number,\n ascent: number,\n deltaLeft: number,\n isLineFirst: boolean,\n textAlign: string,\n lineHeight: number\n ) {\n let baseline = top + ascent;\n let text = this.text;\n let left = this.left + deltaLeft;\n baseline += this.top;\n let direction = this.direction;\n\n if (this.verticalEllipsis) {\n text = this.ellipsisStr;\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n left -= this.ellipsisWidth;\n }\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, this.width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n (direction === 'vertical' ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n const { width } = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);\n if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n left -= this.ellipsisWidth - width;\n }\n }\n }\n\n // prepareContext(ctx);\n switch (this.character.script) {\n case 'super':\n baseline -= this.ascent * (1 / 3);\n break;\n case 'sub':\n baseline += this.descent / 2;\n break;\n }\n\n // if (isLineFirst) {\n // const result = regFirstSpace.exec(text);\n // if (result?.index !== 0) {\n // text = text.slice(result?.index);\n // }\n // }\n\n // 处理旋转\n if (direction === 'vertical') {\n ctx.save();\n ctx.rotateAbout(Math.PI / 2, left, baseline);\n ctx.translate(-(this.heightOrigin as number) || -this.lineHeight / 2, -this.descent / 2);\n ctx.translate(left, baseline);\n left = 0;\n baseline = 0;\n }\n\n // if (this.character.fill) {\n // if (this.character.background && (!this.character.backgroundOpacity || this.character.backgroundOpacity > 0)) {\n // const fillStyle = ctx.fillStyle;\n // const globalAlpha = ctx.globalAlpha;\n // ctx.fillStyle = this.character.background;\n // if (this.character.backgroundOpacity !== void 0) {\n // ctx.globalAlpha = this.character.backgroundOpacity;\n // }\n // // 背景稍微扩充一些buf,否则会出现白线\n // const right = left + (this.widthOrigin || this.width);\n // const bottom = top + lineHeight;\n // const lrtb = getFixedLRTB(left, right, top, bottom);\n // ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n // ctx.fillStyle = fillStyle;\n // ctx.globalAlpha = globalAlpha;\n // }\n // }\n\n const { lineWidth = 1 } = this.character;\n if (this.character.stroke && lineWidth) {\n ctx.strokeText(text, left, baseline);\n }\n\n if (this.character.fill) {\n ctx.fillText(text, left, baseline);\n }\n\n if (this.character.fill) {\n if (this.character.lineThrough || this.character.underline) {\n if (this.character.underline) {\n const top = 1 + baseline;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(\n lrtb.left,\n 1 + baseline,\n lrtb.right - lrtb.left,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n if (this.character.lineThrough) {\n const top = 1 + baseline - this.ascent / 2;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(\n lrtb.left,\n 1 + baseline - this.ascent / 2,\n lrtb.right - lrtb.left,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n } else if (this.character.textDecoration === 'underline') {\n const top = 1 + baseline;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(\n lrtb.left,\n 1 + baseline,\n lrtb.right - lrtb.left,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n } else if (this.character.textDecoration === 'line-through') {\n const top = 1 + baseline - this.ascent / 2;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(\n lrtb.left,\n 1 + baseline - this.ascent / 2,\n lrtb.right - lrtb.left,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n }\n\n if (direction === 'vertical') {\n ctx.restore();\n }\n }\n\n getWidthWithEllips(direction: string): number {\n let text = this.text;\n // const direction = this.direction;\n const width = direction === 'vertical' ? this.height : this.width;\n // const height = direction === 'vertical' ? this.width: this.height;\n\n if (this.ellipsis === 'hide') {\n return width;\n } else if (this.ellipsis === 'add') {\n return width + this.ellipsisWidth;\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n const { width: measureWidth } = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);\n return width + this.ellipsisWidth - measureWidth;\n }\n return width;\n }\n}\n\nexport function seperateParagraph(paragraph: Paragraph, index: number) {\n const text1 = paragraph.text.slice(0, index);\n const text2 = paragraph.text.slice(index);\n const p1 = new Paragraph(text1, paragraph.newLine, paragraph.character, paragraph.ascentDescentMode);\n const p2 = new Paragraph(text2, true, paragraph.character, paragraph.ascentDescentMode);\n\n return [p1, p2];\n}\n"]}
@@ -176,7 +176,7 @@ class RichText extends graphic_1.Graphic {
176
176
  return aabbBounds.translate(deltaX, deltaY), application_1.application.graphicService.updateTempAABBBounds(aabbBounds),
177
177
  null == attribute.forceBoundsHeight && null == attribute.forceBoundsWidth || application_1.application.graphicService.updateHTMLTextAABBBounds(attribute, richtextTheme, aabbBounds),
178
178
  application_1.application.graphicService.transformAABBBounds(attribute, aabbBounds, richtextTheme, !1, this),
179
- aabbBounds;
179
+ 0 === aabbBounds.width() && 0 === aabbBounds.height() && aabbBounds.clear(), aabbBounds;
180
180
  }
181
181
  needUpdateTags(keys) {
182
182
  return super.needUpdateTags(keys, RICHTEXT_UPDATE_TAG_KEY);
@@ -202,8 +202,7 @@ class RichText extends graphic_1.Graphic {
202
202
  return !1;
203
203
  }
204
204
  combinedStyleToCharacter(config) {
205
- const {fill: fill, stroke: stroke, fontSize: fontSize, fontFamily: fontFamily, fontStyle: fontStyle, fontWeight: fontWeight, lineWidth: lineWidth, opacity: opacity, fillOpacity: fillOpacity, strokeOpacity: strokeOpacity} = this.attribute;
206
- return Object.assign({
205
+ const {fill: fill, stroke: stroke, fontSize: fontSize, fontFamily: fontFamily, fontStyle: fontStyle, fontWeight: fontWeight, lineWidth: lineWidth, opacity: opacity, fillOpacity: fillOpacity, lineHeight: lineHeight, strokeOpacity: strokeOpacity, upgradeAttrs: upgradeAttrs} = this.attribute, out = Object.assign({
207
206
  fill: fill,
208
207
  stroke: stroke,
209
208
  fontSize: fontSize,
@@ -215,10 +214,12 @@ class RichText extends graphic_1.Graphic {
215
214
  fillOpacity: fillOpacity,
216
215
  strokeOpacity: strokeOpacity
217
216
  }, config);
217
+ return (null == upgradeAttrs ? void 0 : upgradeAttrs.lineHeight) && (out.lineHeight = lineHeight),
218
+ out;
218
219
  }
219
220
  doUpdateFrameCache(tc) {
220
221
  var _a;
221
- const {maxWidth: maxWidth, maxHeight: maxHeight, width: width, height: height, ellipsis: ellipsis, wordBreak: wordBreak, verticalDirection: verticalDirection, textAlign: textAlign, textBaseline: textBaseline, layoutDirection: layoutDirection, singleLine: singleLine, disableAutoWrapLine: disableAutoWrapLine, editable: editable, ascentDescentMode: ascentDescentMode} = this.attribute;
222
+ const {maxWidth: maxWidth, maxHeight: maxHeight, width: width, height: height, ellipsis: ellipsis, wordBreak: wordBreak, verticalDirection: verticalDirection, textAlign: textAlign, textBaseline: textBaseline, layoutDirection: layoutDirection, singleLine: singleLine, disableAutoWrapLine: disableAutoWrapLine, editable: editable, ascentDescentMode: ascentDescentMode, upgradeAttrs: upgradeAttrs} = this.attribute, enableMultiBreakLine = upgradeAttrs && upgradeAttrs.multiBreakLine;
222
223
  let {textConfig: _tc = []} = this.attribute;
223
224
  editable && _tc.length > 0 && !RichText.AllSingleCharacter(_tc) && (_tc = RichText.TransformTextConfig2SingleCharacter(_tc),
224
225
  this.attribute.textConfig = _tc);
@@ -239,11 +240,14 @@ class RichText extends graphic_1.Graphic {
239
240
  if ((0, vutils_1.isNumber)(richTextConfig.text) && (richTextConfig.text = `${richTextConfig.text}`),
240
241
  richTextConfig.text && richTextConfig.text.includes("\n")) {
241
242
  const textParts = richTextConfig.text.split("\n");
242
- for (let j = 0; j < textParts.length; j++) paragraphs.push(new paragraph_1.default(textParts[j], 0 !== j, richTextConfig, ascentDescentMode));
243
+ for (let j = 0; j < textParts.length; j++) if (0 === j) paragraphs.push(new paragraph_1.default(textParts[j], !1, richTextConfig, ascentDescentMode)); else if (textParts[j] || i === textConfig.length - 1) paragraphs.push(new paragraph_1.default(textParts[j], !0, richTextConfig, ascentDescentMode)); else {
244
+ const nextRichTextConfig = this.combinedStyleToCharacter(textConfig[i + 1]);
245
+ paragraphs.push(new paragraph_1.default(textParts[j], !0, nextRichTextConfig, ascentDescentMode));
246
+ }
243
247
  } else richTextConfig.text && paragraphs.push(new paragraph_1.default(richTextConfig.text, !1, richTextConfig, ascentDescentMode));
244
248
  }
245
249
  const maxWidthFinite = "number" == typeof maxWidth && Number.isFinite(maxWidth) && maxWidth > 0, maxHeightFinite = "number" == typeof maxHeight && Number.isFinite(maxHeight) && maxHeight > 0, richTextWidthEnable = "number" == typeof width && Number.isFinite(width) && width > 0 && (!maxWidthFinite || width <= maxWidth), richTextHeightEnable = "number" == typeof height && Number.isFinite(height) && height > 0 && (!maxHeightFinite || height <= maxHeight), frameWidth = richTextWidthEnable ? width : maxWidthFinite ? maxWidth : 0, frameHeight = richTextHeightEnable ? height : maxHeightFinite ? maxHeight : 0, frame = new frame_1.default(0, 0, frameWidth || 0, frameHeight || 0, ellipsis, wordBreak, verticalDirection, textAlign, textBaseline, layoutDirection || "horizontal", !richTextWidthEnable && maxWidthFinite, !richTextHeightEnable && maxHeightFinite, singleLine || !1, null === (_a = this._frameCache) || void 0 === _a ? void 0 : _a.icons), wrapper = new wrapper_1.default(frame);
246
- if (wrapper.newLine = editable, disableAutoWrapLine) {
250
+ if (wrapper.newLine = enableMultiBreakLine, disableAutoWrapLine) {
247
251
  let lineCount = 0, skip = !1;
248
252
  for (let i = 0; i < paragraphs.length; i++) {
249
253
  const p = paragraphs[i];
@@ -262,7 +266,7 @@ class RichText extends graphic_1.Graphic {
262
266
  l.calcOffset(offsetSize, !1);
263
267
  }));
264
268
  }
265
- editable && frame.lines.forEach((item => {
269
+ enableMultiBreakLine && frame.lines.forEach((item => {
266
270
  const lastParagraphs = item.paragraphs;
267
271
  item.paragraphs = item.paragraphs.filter((p => "" !== p.text)), 0 === item.paragraphs.length && lastParagraphs.length && (lastParagraphs[0].text = "\n",
268
272
  item.paragraphs.push(lastParagraphs[0]));