@visactor/vrender-core 0.22.0-vstory.11 → 0.22.0-vstory.12

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 (116) hide show
  1. package/cjs/animate/animate.js +1 -1
  2. package/cjs/animate/animate.js.map +1 -1
  3. package/cjs/animate/custom-animate.js +2 -1
  4. package/cjs/animate/custom-animate.js.map +1 -1
  5. package/cjs/common/render-area.d.ts +0 -4
  6. package/cjs/common/render-area.js +16 -76
  7. package/cjs/common/render-area.js.map +1 -1
  8. package/cjs/common/render-curve.d.ts +1 -1
  9. package/cjs/common/render-curve.js.map +1 -1
  10. package/cjs/common/segment/step.js +1 -1
  11. package/cjs/common/segment/step.js.map +1 -1
  12. package/cjs/core/global.d.ts +3 -0
  13. package/cjs/core/global.js +7 -1
  14. package/cjs/core/global.js.map +1 -1
  15. package/cjs/graphic/config.js +1 -0
  16. package/cjs/graphic/config.js.map +1 -1
  17. package/cjs/graphic/graphic.js +4 -4
  18. package/cjs/graphic/graphic.js.map +1 -1
  19. package/cjs/graphic/group.d.ts +0 -1
  20. package/cjs/graphic/group.js +0 -5
  21. package/cjs/graphic/group.js.map +1 -1
  22. package/cjs/graphic/line.js +2 -2
  23. package/cjs/graphic/line.js.map +1 -1
  24. package/cjs/graphic/richtext/line.js +3 -13
  25. package/cjs/graphic/richtext/line.js.map +1 -1
  26. package/cjs/graphic/richtext/paragraph.d.ts +3 -9
  27. package/cjs/graphic/richtext/paragraph.js +33 -20
  28. package/cjs/graphic/richtext/paragraph.js.map +1 -1
  29. package/cjs/graphic/richtext/utils.d.ts +1 -1
  30. package/cjs/graphic/richtext/utils.js +6 -7
  31. package/cjs/graphic/richtext/utils.js.map +1 -1
  32. package/cjs/graphic/richtext.d.ts +1 -2
  33. package/cjs/graphic/richtext.js +3 -9
  34. package/cjs/graphic/richtext.js.map +1 -1
  35. package/cjs/interface/color.js.map +1 -1
  36. package/cjs/interface/global.d.ts +1 -0
  37. package/cjs/interface/global.js.map +1 -1
  38. package/cjs/interface/graphic/richText.d.ts +1 -1
  39. package/cjs/interface/graphic/richText.js.map +1 -1
  40. package/cjs/interface/graphic.d.ts +2 -2
  41. package/cjs/interface/graphic.js.map +1 -1
  42. package/cjs/plugins/builtin-plugin/edit-module.js +8 -4
  43. package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
  44. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +3 -4
  45. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +74 -86
  46. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  47. package/cjs/render/contributions/render/area-render.d.ts +1 -1
  48. package/cjs/render/contributions/render/area-render.js +16 -36
  49. package/cjs/render/contributions/render/area-render.js.map +1 -1
  50. package/cjs/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
  51. package/cjs/render/contributions/render/contributions/image-contribution-render.js +2 -2
  52. package/cjs/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
  53. package/cjs/render/contributions/render/image-render.js.map +1 -1
  54. package/cjs/render/contributions/render/line-render.js +9 -31
  55. package/cjs/render/contributions/render/line-render.js.map +1 -1
  56. package/cjs/resource-loader/loader.js +1 -1
  57. package/cjs/resource-loader/loader.js.map +1 -1
  58. package/dist/index.es.js +183 -441
  59. package/es/animate/animate.js +4 -3
  60. package/es/animate/animate.js.map +1 -1
  61. package/es/animate/custom-animate.js +2 -1
  62. package/es/animate/custom-animate.js.map +1 -1
  63. package/es/common/render-area.d.ts +0 -4
  64. package/es/common/render-area.js +16 -76
  65. package/es/common/render-area.js.map +1 -1
  66. package/es/common/render-curve.d.ts +1 -1
  67. package/es/common/render-curve.js.map +1 -1
  68. package/es/common/segment/step.js +1 -1
  69. package/es/common/segment/step.js.map +1 -1
  70. package/es/core/global.d.ts +3 -0
  71. package/es/core/global.js +8 -1
  72. package/es/core/global.js.map +1 -1
  73. package/es/graphic/config.js +1 -0
  74. package/es/graphic/config.js.map +1 -1
  75. package/es/graphic/graphic.js +5 -5
  76. package/es/graphic/graphic.js.map +1 -1
  77. package/es/graphic/group.d.ts +0 -1
  78. package/es/graphic/group.js +0 -5
  79. package/es/graphic/group.js.map +1 -1
  80. package/es/graphic/line.js +2 -2
  81. package/es/graphic/line.js.map +1 -1
  82. package/es/graphic/richtext/line.js +3 -13
  83. package/es/graphic/richtext/line.js.map +1 -1
  84. package/es/graphic/richtext/paragraph.d.ts +3 -9
  85. package/es/graphic/richtext/paragraph.js +33 -20
  86. package/es/graphic/richtext/paragraph.js.map +1 -1
  87. package/es/graphic/richtext/utils.d.ts +1 -1
  88. package/es/graphic/richtext/utils.js +6 -7
  89. package/es/graphic/richtext/utils.js.map +1 -1
  90. package/es/graphic/richtext.d.ts +1 -2
  91. package/es/graphic/richtext.js +3 -9
  92. package/es/graphic/richtext.js.map +1 -1
  93. package/es/interface/color.js.map +1 -1
  94. package/es/interface/global.d.ts +1 -0
  95. package/es/interface/global.js.map +1 -1
  96. package/es/interface/graphic/richText.d.ts +1 -1
  97. package/es/interface/graphic/richText.js.map +1 -1
  98. package/es/interface/graphic.d.ts +2 -2
  99. package/es/interface/graphic.js.map +1 -1
  100. package/es/plugins/builtin-plugin/edit-module.js +8 -4
  101. package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
  102. package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +3 -4
  103. package/es/plugins/builtin-plugin/richtext-edit-plugin.js +74 -86
  104. package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  105. package/es/render/contributions/render/area-render.d.ts +1 -1
  106. package/es/render/contributions/render/area-render.js +16 -36
  107. package/es/render/contributions/render/area-render.js.map +1 -1
  108. package/es/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
  109. package/es/render/contributions/render/contributions/image-contribution-render.js +2 -2
  110. package/es/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
  111. package/es/render/contributions/render/image-render.js.map +1 -1
  112. package/es/render/contributions/render/line-render.js +9 -31
  113. package/es/render/contributions/render/line-render.js.map +1 -1
  114. package/es/resource-loader/loader.js +1 -1
  115. package/es/resource-loader/loader.js.map +1 -1
  116. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/line.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,mBAAmB,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,sBAAsB,CAAC,CAAC;AAE3G,MAAM,OAAO,IAAK,SAAQ,OAA8B;IAGtD,YAAY,SAAgC,EAAE;QAC5C,KAAK,CAAC,MAAM,CAAC,CAAC;QAHhB,SAAI,GAAW,MAAM,CAAC;QAIpB,IAAI,CAAC,UAAU,GAAG,gBAAgB,CAAC;IACrC,CAAC;IAQD,OAAO;QACL,OAAO,KAAK,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC5C,CAAC;IACO,QAAQ;QACd,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,OAAO,IAAI,CAAC;SACb;QACD,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;QAC5C,IAAI,QAAQ,EAAE;YACZ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;gBACzB,OAAO,KAAK,CAAC;aACd;YACD,OAAO,IAAI,CAAC;SACb;aAAM,IAAI,MAAM,EAAE;YACjB,IAAI,MAAM,CAA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ILine, ILineGraphicAttribute } from '../interface';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport { pointsInterpolation } from '../common/utils';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport { LINE_NUMBER_TYPE } from './constants';\n\nconst LINE_UPDATE_TAG_KEY = ['segments', 'points', 'curveType', 'curveTension', ...GRAPHIC_UPDATE_TAG_KEY];\n\nexport class Line extends Graphic<ILineGraphicAttribute> implements ILine {\n type: 'line' = 'line';\n\n constructor(params: ILineGraphicAttribute = {}) {\n super(params);\n this.numberType = LINE_NUMBER_TYPE;\n }\n\n static NOWORK_ANIMATE_ATTR = {\n segments: 1,\n curveType: 1,\n ...NOWORK_ANIMATE_ATTR\n };\n\n isValid(): boolean {\n return super.isValid() && this._isValid();\n }\n private _isValid(): boolean {\n if (this.pathProxy) {\n return true;\n }\n const { points, segments } = this.attribute;\n if (segments) {\n if (segments.length === 0) {\n return false;\n }\n return true;\n } else if (points) {\n if (points.length <= 1) {\n return false;\n }\n return true;\n }\n return false;\n }\n\n protected _interpolate(key: string, ratio: number, lastStepVal: any, nextStepVal: any, nextAttributes: any): void {\n if (key === 'points') {\n (nextAttributes as any).points = pointsInterpolation(lastStepVal, nextStepVal, ratio);\n }\n }\n\n getGraphicTheme(): Required<ILineGraphicAttribute> {\n return getTheme(this).line;\n }\n\n protected updateAABBBounds(\n attribute: ILineGraphicAttribute,\n lineTheme: Required<ILineGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n attribute.segments\n ? this.updateLineAABBBoundsBySegments(attribute, lineTheme, aabbBounds)\n : this.updateLineAABBBoundsByPoints(attribute, lineTheme, aabbBounds);\n }\n\n application.graphicService.updateTempAABBBounds(aabbBounds);\n\n const { lineJoin = lineTheme.lineJoin } = attribute;\n application.graphicService.transformAABBBounds(attribute, aabbBounds, lineTheme, lineJoin === 'miter', this);\n return aabbBounds;\n }\n\n protected updateLineAABBBoundsByPoints(\n attribute: ILineGraphicAttribute,\n lineTheme: Required<ILineGraphicAttribute>,\n aabbBounds: IAABBBounds,\n graphic?: ILine\n ): IAABBBounds {\n const { points = lineTheme.points, connectedType } = attribute;\n const b = aabbBounds;\n points.forEach(p => {\n if (p.defined !== false || connectedType === 'zero' || connectedType === 'connect') {\n b.add(p.x, p.y);\n }\n });\n return b;\n }\n protected updateLineAABBBoundsBySegments(\n attribute: ILineGraphicAttribute,\n lineTheme: Required<ILineGraphicAttribute>,\n aabbBounds: IAABBBounds,\n graphic?: ILine\n ): IAABBBounds {\n const { segments = lineTheme.segments, connectedType } = attribute;\n const b = aabbBounds;\n segments.forEach(s => {\n s.points.forEach(p => {\n if (p.defined !== false || connectedType === 'zero' || connectedType === 'connect') {\n b.add(p.x, p.y);\n }\n });\n });\n return b;\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, LINE_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, LINE_UPDATE_TAG_KEY);\n }\n\n toCustomPath() {\n const attribute = this.attribute;\n const path = new CustomPath2D();\n const segments = attribute.segments;\n\n const parsePoints = (points: IPointLike[]) => {\n if (points && points.length) {\n let isFirst = true;\n points.forEach(point => {\n if (point.defined === false) {\n return;\n }\n if (isFirst) {\n path.moveTo(point.x, point.y);\n } else {\n path.lineTo(point.x, point.y);\n }\n\n isFirst = false;\n });\n }\n };\n\n if (segments && segments.length) {\n segments.forEach(seg => {\n parsePoints(seg.points);\n });\n } else if (attribute.points) {\n parsePoints(attribute.points);\n }\n\n return path;\n }\n\n clone() {\n return new Line({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Line.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createLine(attributes: ILineGraphicAttribute): ILine {\n return new Line(attributes);\n}\n\n// addAttributeToPrototype(DefaultLineStyle, Line,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K,CAAC,EAAE;oBACrB,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK,EAAE;wBAC3B,OAAO;qBACR;oBACD,IAAI,OAAO,EAAE;wBACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;qBAC/B;yBAAM;wBACL,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;qBAC/B;oBAED,OAAO,GAAG,KAAK,CAAC;gBAClB,CAAC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC;QAEF,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,EAAE;YAC/B,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;gBACrB,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAC1B,CAAC,CAAC,CAAC;SACJ;aAAM,IAAI,SAAS,CAAC,MAAM,EAAE;YAC3B,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;SAC/B;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,OAAO,IAAI,IAAI,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IACzC,CAAC;IAED,oBAAoB;QAClB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;;AAxIM,wBAAmB,mBACxB,QAAQ,EAAE,CAAC,EACX,SAAS,EAAE,CAAC,IACT,mBAAmB,EACtB;AAuIJ,MAAM,UAAU,UAAU,CAAC,UAAiC;IAC1D,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC","file":"line.js","sourcesContent":["import type { IAABBBounds, IPointLike } from '@visactor/vutils';\nimport type { ILine, ILineGraphicAttribute } from '../interface';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport { pointsInterpolation } from '../common/utils';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport { LINE_NUMBER_TYPE } from './constants';\n\nconst LINE_UPDATE_TAG_KEY = ['segments', 'points', 'curveType', 'curveTension', ...GRAPHIC_UPDATE_TAG_KEY];\n\nexport class Line extends Graphic<ILineGraphicAttribute> implements ILine {\n type: 'line' = 'line';\n\n constructor(params: ILineGraphicAttribute = {}) {\n super(params);\n this.numberType = LINE_NUMBER_TYPE;\n }\n\n static NOWORK_ANIMATE_ATTR = {\n segments: 1,\n curveType: 1,\n ...NOWORK_ANIMATE_ATTR\n };\n\n isValid(): boolean {\n return super.isValid() && this._isValid();\n }\n private _isValid(): boolean {\n if (this.pathProxy) {\n return true;\n }\n const { points, segments } = this.attribute;\n if (segments) {\n if (segments.length === 0) {\n return false;\n }\n return true;\n } else if (points) {\n if (points.length <= 1) {\n return false;\n }\n return true;\n }\n return false;\n }\n\n protected _interpolate(key: string, ratio: number, lastStepVal: any, nextStepVal: any, nextAttributes: any): void {\n if (key === 'points') {\n (nextAttributes as any).points = pointsInterpolation(lastStepVal, nextStepVal, ratio);\n }\n }\n\n getGraphicTheme(): Required<ILineGraphicAttribute> {\n return getTheme(this).line;\n }\n\n protected updateAABBBounds(\n attribute: ILineGraphicAttribute,\n lineTheme: Required<ILineGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n attribute.segments\n ? this.updateLineAABBBoundsBySegments(attribute, lineTheme, aabbBounds)\n : this.updateLineAABBBoundsByPoints(attribute, lineTheme, aabbBounds);\n }\n\n application.graphicService.updateTempAABBBounds(aabbBounds);\n\n const { lineJoin = lineTheme.lineJoin } = attribute;\n application.graphicService.transformAABBBounds(attribute, aabbBounds, lineTheme, lineJoin === 'miter', this);\n return aabbBounds;\n }\n\n protected updateLineAABBBoundsByPoints(\n attribute: ILineGraphicAttribute,\n lineTheme: Required<ILineGraphicAttribute>,\n aabbBounds: IAABBBounds,\n graphic?: ILine\n ): IAABBBounds {\n const { points = lineTheme.points, connectedType } = attribute;\n const b = aabbBounds;\n points.forEach(p => {\n if (p.defined !== false || connectedType === 'connect') {\n b.add(p.x, p.y);\n }\n });\n return b;\n }\n protected updateLineAABBBoundsBySegments(\n attribute: ILineGraphicAttribute,\n lineTheme: Required<ILineGraphicAttribute>,\n aabbBounds: IAABBBounds,\n graphic?: ILine\n ): IAABBBounds {\n const { segments = lineTheme.segments, connectedType } = attribute;\n const b = aabbBounds;\n segments.forEach(s => {\n s.points.forEach(p => {\n if (p.defined !== false || connectedType === 'connect') {\n b.add(p.x, p.y);\n }\n });\n });\n return b;\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, LINE_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, LINE_UPDATE_TAG_KEY);\n }\n\n toCustomPath() {\n const attribute = this.attribute;\n const path = new CustomPath2D();\n const segments = attribute.segments;\n\n const parsePoints = (points: IPointLike[]) => {\n if (points && points.length) {\n let isFirst = true;\n points.forEach(point => {\n if (point.defined === false) {\n return;\n }\n if (isFirst) {\n path.moveTo(point.x, point.y);\n } else {\n path.lineTo(point.x, point.y);\n }\n\n isFirst = false;\n });\n }\n };\n\n if (segments && segments.length) {\n segments.forEach(seg => {\n parsePoints(seg.points);\n });\n } else if (attribute.points) {\n parsePoints(attribute.points);\n }\n\n return path;\n }\n\n clone() {\n return new Line({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Line.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createLine(attributes: ILineGraphicAttribute): ILine {\n return new Line(attributes);\n}\n\n// addAttributeToPrototype(DefaultLineStyle, Line, PURE_STYLE_KEY);\n"]}
@@ -55,7 +55,7 @@ export default class Line {
55
55
  }
56
56
  const ellipsis = !0 === drawEllipsis ? "..." : drawEllipsis || "";
57
57
  paragraph.ellipsisStr = ellipsis;
58
- const {width: width} = measureTextCanvas(ellipsis, paragraph.character), ellipsisWidth = width || 0;
58
+ const {width: width} = measureTextCanvas(ellipsis, paragraph.character, paragraph.ascentDescentMode), ellipsisWidth = width || 0;
59
59
  if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {
60
60
  lastLine && (paragraph.ellipsis = "add");
61
61
  break;
@@ -67,18 +67,8 @@ export default class Line {
67
67
  paragraph.ellipsis = "hide", otherParagraphWidth += paragraph.width;
68
68
  }
69
69
  }
70
- let fillStyle = "", globalAlpha = -1, currBgList = [];
71
- const bgList = [ currBgList ];
72
70
  this.paragraphs.forEach(((paragraph, index) => {
73
- if (paragraph instanceof RichTextIcon) return;
74
- const data = paragraph.drawBackground(ctx, y, this.ascent, x, 0 === index, this.textAlign, this.height);
75
- data && (fillStyle === data.fillStyle && globalAlpha === data.globalAlpha || (currBgList = [],
76
- bgList.push(currBgList), fillStyle = data.fillStyle, globalAlpha = data.globalAlpha),
77
- currBgList.push(data));
78
- })), bgList.forEach((bg => {
79
- if (0 === bg.length) return;
80
- const data = bg[0], end = bg[bg.length - 1];
81
- ctx.fillStyle = data.fillStyle, ctx.globalAlpha = data.globalAlpha, ctx.fillRect(data.left, data.top, end.right - data.left, end.bottom - data.top);
71
+ paragraph instanceof RichTextIcon || paragraph.drawBackground(ctx, y, this.ascent, x, 0 === index, this.textAlign, this.height);
82
72
  })), this.paragraphs.forEach(((paragraph, index) => {
83
73
  if (paragraph instanceof RichTextIcon) return paragraph.setAttributes({
84
74
  x: x + paragraph._x,
@@ -99,7 +89,7 @@ export default class Line {
99
89
  for (let i = this.paragraphs.length - 1; i >= 0; i--) {
100
90
  const paragraph = this.paragraphs[i];
101
91
  if (paragraph instanceof RichTextIcon) break;
102
- const {width: width} = measureTextCanvas(ellipsis, paragraph.character), ellipsisWidth = width || 0;
92
+ const {width: width} = measureTextCanvas(ellipsis, paragraph.character, paragraph.ascentDescentMode), ellipsisWidth = width || 0;
103
93
  if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {
104
94
  paragraph.ellipsis = "add",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../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);\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);\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,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AA8B5G,MAAM,CAAC,OAAO,OAAO,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,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;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,YAAY,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","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"]}
@@ -16,22 +16,16 @@ export default class Paragraph {
16
16
  widthOrigin?: number;
17
17
  heightOrigin?: number;
18
18
  textBaseline?: CanvasTextBaseline;
19
+ ascentDescentMode?: 'actual' | 'font';
19
20
  ellipsis: 'normal' | 'add' | 'replace' | 'hide';
20
21
  ellipsisStr: string;
21
22
  ellipsisWidth: number;
22
23
  ellipsisOtherParagraphWidth: number;
23
24
  verticalEllipsis?: boolean;
24
25
  overflow?: boolean;
25
- constructor(text: string, newLine: boolean, character: IRichTextParagraphCharacter);
26
+ constructor(text: string, newLine: boolean, character: IRichTextParagraphCharacter, ascentDescentMode?: 'actual' | 'font');
26
27
  updateWidth(): void;
27
- drawBackground(ctx: IContext2d, top: number, ascent: number, deltaLeft: number, isLineFirst: boolean, textAlign: string, lineHeight: number): {
28
- fillStyle: string;
29
- globalAlpha: number;
30
- left: number;
31
- top: number;
32
- right: number;
33
- bottom: number;
34
- };
28
+ drawBackground(ctx: IContext2d, top: number, ascent: number, deltaLeft: number, isLineFirst: boolean, textAlign: string, lineHeight: number): void;
35
29
  draw(ctx: IContext2d, top: number, ascent: number, deltaLeft: number, isLineFirst: boolean, textAlign: string, lineHeight: number): void;
36
30
  getWidthWithEllips(direction: string): number;
37
31
  }
@@ -3,21 +3,23 @@ import { calculateLineHeight } from "../../common/utils";
3
3
  import { measureTextCanvas, getStrByWithCanvas } from "./utils";
4
4
 
5
5
  function getFixedLRTB(left, right, top, bottom) {
6
+ const leftInt = Math.round(left), topInt = Math.round(top), rightInt = Math.round(right), bottomInt = Math.round(bottom);
6
7
  return {
7
- left: Math.round(left),
8
- top: Math.round(top),
9
- right: Math.round(right),
10
- bottom: Math.round(bottom)
8
+ left: left > leftInt ? leftInt : leftInt - .5,
9
+ top: top > topInt ? topInt : topInt - .5,
10
+ right: rightInt > right ? rightInt : rightInt + .5,
11
+ bottom: bottomInt > bottom ? bottomInt : bottomInt + .5
11
12
  };
12
13
  }
13
14
 
14
15
  export default class Paragraph {
15
- constructor(text, newLine, character) {
16
- this.fontSize = character.fontSize || 16, this.textBaseline = character.textBaseline || "alphabetic";
16
+ constructor(text, newLine, character, ascentDescentMode) {
17
+ this.fontSize = character.fontSize || 16, this.textBaseline = character.textBaseline || "alphabetic",
18
+ this.ascentDescentMode = ascentDescentMode;
17
19
  const lineHeight = calculateLineHeight(character.lineHeight, this.fontSize);
18
20
  this.lineHeight = "number" == typeof lineHeight ? lineHeight > this.fontSize ? lineHeight : this.fontSize : Math.floor(1.2 * this.fontSize),
19
21
  this.height = this.lineHeight;
20
- const {ascent: ascent, height: height, descent: descent, width: width} = measureTextCanvas(text, character);
22
+ const {ascent: ascent, height: height, descent: descent, width: width} = measureTextCanvas(text, character, this.ascentDescentMode);
21
23
  let halfDetaHeight = 0, deltaAscent = 0, deltaDescent = 0;
22
24
  this.height > height && (halfDetaHeight = (this.height - height) / 2, deltaAscent = Math.ceil(halfDetaHeight),
23
25
  deltaDescent = Math.floor(halfDetaHeight)), "top" === this.textBaseline ? (this.ascent = halfDetaHeight,
@@ -31,7 +33,7 @@ export default class Paragraph {
31
33
  this.height = this.widthOrigin, this.lineHeight = this.height), this.ellipsisStr = "...";
32
34
  }
33
35
  updateWidth() {
34
- const {width: width} = measureTextCanvas(this.text, this.character);
36
+ const {width: width} = measureTextCanvas(this.text, this.character, this.ascentDescentMode);
35
37
  this.width = width, "vertical" === this.direction && (this.widthOrigin = this.width,
36
38
  this.width = this.heightOrigin, this.height = this.widthOrigin);
37
39
  }
@@ -45,16 +47,27 @@ export default class Paragraph {
45
47
  if ("add" === this.ellipsis) text += this.ellipsisStr, "right" !== textAlign && "end" !== textAlign || (left -= this.ellipsisWidth); else if ("replace" === this.ellipsis) {
46
48
  const index = getStrByWithCanvas(text, ("vertical" === direction ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.character, text.length - 1);
47
49
  if (text = text.slice(0, index), text += this.ellipsisStr, "right" === textAlign || "end" === textAlign) {
48
- const {width: width} = measureTextCanvas(this.text.slice(index), this.character);
50
+ const {width: width} = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);
49
51
  "vertical" === direction || (left -= this.ellipsisWidth - width);
50
52
  }
51
53
  }
52
54
  }
55
+ switch (this.character.script) {
56
+ case "super":
57
+ baseline -= this.ascent * (1 / 3);
58
+ break;
59
+
60
+ case "sub":
61
+ baseline += this.descent / 2;
62
+ }
63
+ "vertical" === direction && (ctx.save(), ctx.rotateAbout(Math.PI / 2, left, baseline),
64
+ ctx.translate(-this.heightOrigin || -this.lineHeight / 2, -this.descent / 2), ctx.translate(left, baseline),
65
+ left = 0, baseline = 0);
66
+ const fillStyle = ctx.fillStyle, globalAlpha = ctx.globalAlpha;
67
+ ctx.fillStyle = this.character.background, void 0 !== this.character.backgroundOpacity && (ctx.globalAlpha = this.character.backgroundOpacity);
53
68
  const lrtb = getFixedLRTB(left, left + (this.widthOrigin || this.width), top, top + lineHeight);
54
- return Object.assign(Object.assign({}, lrtb), {
55
- fillStyle: this.character.background,
56
- globalAlpha: this.character.backgroundOpacity
57
- });
69
+ ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top),
70
+ ctx.fillStyle = fillStyle, ctx.globalAlpha = globalAlpha;
58
71
  }
59
72
  draw(ctx, top, ascent, deltaLeft, isLineFirst, textAlign, lineHeight) {
60
73
  let baseline = top + ascent, text = this.text, left = this.left + deltaLeft;
@@ -65,7 +78,7 @@ export default class Paragraph {
65
78
  if ("add" === this.ellipsis) text += this.ellipsisStr, "right" !== textAlign && "end" !== textAlign || (left -= this.ellipsisWidth); else if ("replace" === this.ellipsis) {
66
79
  const index = getStrByWithCanvas(text, ("vertical" === direction ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.character, text.length - 1);
67
80
  if (text = text.slice(0, index), text += this.ellipsisStr, "right" === textAlign || "end" === textAlign) {
68
- const {width: width} = measureTextCanvas(this.text.slice(index), this.character);
81
+ const {width: width} = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);
69
82
  "vertical" === direction || (left -= this.ellipsisWidth - width);
70
83
  }
71
84
  }
@@ -86,18 +99,18 @@ export default class Paragraph {
86
99
  this.character.fill && ctx.fillText(text, left, baseline), this.character.fill) if (this.character.lineThrough || this.character.underline) {
87
100
  if (this.character.underline) {
88
101
  const top = 1 + baseline, lrtb = getFixedLRTB(left, left + (this.widthOrigin || this.width), top, top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1));
89
- ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);
102
+ ctx.fillRect(lrtb.left, 1 + baseline, lrtb.right - lrtb.left, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);
90
103
  }
91
104
  if (this.character.lineThrough) {
92
105
  const top = 1 + baseline - this.ascent / 2, lrtb = getFixedLRTB(left, left + (this.widthOrigin || this.width), top, top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1));
93
- ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);
106
+ ctx.fillRect(lrtb.left, 1 + baseline - this.ascent / 2, lrtb.right - lrtb.left, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);
94
107
  }
95
108
  } else if ("underline" === this.character.textDecoration) {
96
109
  const top = 1 + baseline, lrtb = getFixedLRTB(left, left + (this.widthOrigin || this.width), top, top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1));
97
- ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);
110
+ ctx.fillRect(lrtb.left, 1 + baseline, lrtb.right - lrtb.left, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);
98
111
  } else if ("line-through" === this.character.textDecoration) {
99
112
  const top = 1 + baseline - this.ascent / 2, lrtb = getFixedLRTB(left, left + (this.widthOrigin || this.width), top, top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1));
100
- ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);
113
+ ctx.fillRect(lrtb.left, 1 + baseline - this.ascent / 2, lrtb.right - lrtb.left, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);
101
114
  }
102
115
  "vertical" === direction && ctx.restore();
103
116
  }
@@ -109,7 +122,7 @@ export default class Paragraph {
109
122
  if ("replace" === this.ellipsis) {
110
123
  const index = getStrByWithCanvas(text, width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.character, text.length - 1);
111
124
  text = text.slice(0, index), text += this.ellipsisStr;
112
- const {width: measureWidth} = measureTextCanvas(this.text.slice(index), this.character);
125
+ const {width: measureWidth} = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);
113
126
  return width + this.ellipsisWidth - measureWidth;
114
127
  }
115
128
  return width;
@@ -118,6 +131,6 @@ export default class Paragraph {
118
131
 
119
132
  export function seperateParagraph(paragraph, index) {
120
133
  const text1 = paragraph.text.slice(0, index), text2 = paragraph.text.slice(index);
121
- return [ new Paragraph(text1, paragraph.newLine, paragraph.character), new Paragraph(text2, !0, paragraph.character) ];
134
+ return [ new Paragraph(text1, paragraph.newLine, paragraph.character, paragraph.ascentDescentMode), new Paragraph(text2, !0, paragraph.character, paragraph.ascentDescentMode) ];
122
135
  }
123
136
  //# sourceMappingURL=paragraph.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/richtext/paragraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;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,MA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AC,KAAK,CAAC,CAAC;IAC1C,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACxE,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAE3D,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAClB,CAAC","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 // 会导致背景色重叠\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: leftInt,\n top: topInt,\n right: rightInt,\n bottom: bottomInt\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\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisStr: string;\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n overflow?: boolean;\n\n constructor(text: string, newLine: boolean, character: IRichTextParagraphCharacter) {\n // 测量文字\n this.fontSize = character.fontSize || 16;\n this.textBaseline = character.textBaseline || 'alphabetic';\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);\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);\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);\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);\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(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\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(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\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(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\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(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\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);\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);\n const p2 = new Paragraph(text2, true, paragraph.character);\n\n return [p1, p2];\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/richtext/paragraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;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,CA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Q,KAAK,SAAS,EAAE;YAGtC,MAAM,KAAK,GAAG,kBAAkB,CAC9B,IAAI,EACJ,KAAK,GAAG,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,2BAA2B,EAC7D,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,MAAM,GAAG,CAAC,CAChB,CAAC;YACF,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YAC5B,IAAI,IAAI,IAAI,CAAC,WAAW,CAAC;YAEzB,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAClH,OAAO,KAAK,GAAG,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;SAClD;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,MAAM,UAAU,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","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"]}
@@ -39,7 +39,7 @@ export declare function measureTextDom(text: string, style: string): {
39
39
  descent?: number;
40
40
  width?: number;
41
41
  };
42
- export declare function measureTextCanvas(text: string, character: IRichTextParagraphCharacter): {
42
+ export declare function measureTextCanvas(text: string, character: IRichTextParagraphCharacter, mode?: 'actual' | 'font'): {
43
43
  ascent: number;
44
44
  height: number;
45
45
  descent: number;
@@ -170,18 +170,17 @@ export function measureTextDom(text, style) {
170
170
  return result;
171
171
  }
172
172
 
173
- export function measureTextCanvas(text, character) {
173
+ export function measureTextCanvas(text, character, mode = "actual") {
174
174
  const measurement = application.graphicUtil.textMeasure.measureText(text, character), result = {
175
175
  ascent: 0,
176
176
  height: 0,
177
177
  descent: 0,
178
178
  width: 0
179
- };
180
- return "number" != typeof measurement.fontBoundingBoxAscent || "number" != typeof measurement.fontBoundingBoxDescent ? (result.width = measurement.width,
181
- result.height = character.fontSize || 0, result.ascent = result.height, result.descent = 0) : (result.width = measurement.width,
182
- result.height = Math.floor(measurement.fontBoundingBoxAscent + measurement.fontBoundingBoxDescent),
183
- result.ascent = Math.floor(measurement.fontBoundingBoxAscent), result.descent = result.height - result.ascent),
184
- result;
179
+ }, ascent = "actual" === mode ? measurement.actualBoundingBoxAscent : measurement.fontBoundingBoxAscent, descent = "actual" === mode ? measurement.actualBoundingBoxDescent : measurement.fontBoundingBoxDescent;
180
+ return "number" != typeof ascent || "number" != typeof descent ? (result.width = Math.floor(measurement.width),
181
+ result.height = character.fontSize || 0, result.ascent = result.height, result.descent = 0) : (result.width = Math.floor(measurement.width),
182
+ result.height = Math.floor(ascent + descent), result.ascent = Math.floor(ascent),
183
+ result.descent = result.height - result.ascent), result;
185
184
  }
186
185
 
187
186
  export function getFontString(character, ctx) {