@visactor/vrender-core 0.20.16 → 0.21.0-alpha.10

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 (108) hide show
  1. package/cjs/animate/Ticker/default-ticker.d.ts +4 -2
  2. package/cjs/animate/Ticker/default-ticker.js +8 -5
  3. package/cjs/animate/Ticker/default-ticker.js.map +1 -1
  4. package/cjs/animate/custom-animate.d.ts +2 -0
  5. package/cjs/animate/custom-animate.js +11 -2
  6. package/cjs/animate/custom-animate.js.map +1 -1
  7. package/cjs/common/color-utils.js +2 -2
  8. package/cjs/common/color-utils.js.map +1 -1
  9. package/cjs/core/contributions/textMeasure/AtextMeasure.d.ts +56 -4
  10. package/cjs/core/contributions/textMeasure/AtextMeasure.js +107 -14
  11. package/cjs/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
  12. package/cjs/core/contributions/textMeasure/layout.d.ts +7 -3
  13. package/cjs/core/contributions/textMeasure/layout.js +40 -39
  14. package/cjs/core/contributions/textMeasure/layout.js.map +1 -1
  15. package/cjs/core/stage.d.ts +2 -0
  16. package/cjs/core/stage.js +9 -5
  17. package/cjs/core/stage.js.map +1 -1
  18. package/cjs/graphic/config.d.ts +1 -1
  19. package/cjs/graphic/config.js +4 -2
  20. package/cjs/graphic/config.js.map +1 -1
  21. package/cjs/graphic/graphic-service/graphic-service.d.ts +2 -0
  22. package/cjs/graphic/graphic-service/graphic-service.js +10 -5
  23. package/cjs/graphic/graphic-service/graphic-service.js.map +1 -1
  24. package/cjs/graphic/richtext/line.js +2 -9
  25. package/cjs/graphic/richtext/line.js.map +1 -1
  26. package/cjs/graphic/richtext/paragraph.js +3 -2
  27. package/cjs/graphic/richtext/paragraph.js.map +1 -1
  28. package/cjs/graphic/richtext/utils.d.ts +1 -2
  29. package/cjs/graphic/richtext/utils.js +3 -5
  30. package/cjs/graphic/richtext/utils.js.map +1 -1
  31. package/cjs/graphic/text.d.ts +11 -11
  32. package/cjs/graphic/text.js +99 -170
  33. package/cjs/graphic/text.js.map +1 -1
  34. package/cjs/graphic/wrap-text.js +12 -4
  35. package/cjs/graphic/wrap-text.js.map +1 -1
  36. package/cjs/interface/animate.d.ts +3 -1
  37. package/cjs/interface/animate.js.map +1 -1
  38. package/cjs/interface/graphic/text.d.ts +9 -3
  39. package/cjs/interface/graphic/text.js +6 -1
  40. package/cjs/interface/graphic/text.js.map +1 -1
  41. package/cjs/interface/graphic-service.d.ts +2 -0
  42. package/cjs/interface/graphic-service.js.map +1 -1
  43. package/cjs/interface/stage.d.ts +1 -0
  44. package/cjs/interface/stage.js.map +1 -1
  45. package/cjs/interface/text.d.ts +9 -1
  46. package/cjs/interface/text.js.map +1 -1
  47. package/cjs/plugins/builtin-plugin/dirty-bounds-plugin.js +3 -0
  48. package/cjs/plugins/builtin-plugin/dirty-bounds-plugin.js.map +1 -1
  49. package/cjs/render/contributions/render/draw-interceptor.js +2 -3
  50. package/cjs/render/contributions/render/draw-interceptor.js.map +1 -1
  51. package/cjs/render/contributions/render/text-render.d.ts +1 -1
  52. package/cjs/render/contributions/render/text-render.js +24 -46
  53. package/cjs/render/contributions/render/text-render.js.map +1 -1
  54. package/dist/index.es.js +2725 -2712
  55. package/es/animate/Ticker/default-ticker.d.ts +4 -2
  56. package/es/animate/Ticker/default-ticker.js +9 -6
  57. package/es/animate/Ticker/default-ticker.js.map +1 -1
  58. package/es/animate/custom-animate.d.ts +2 -0
  59. package/es/animate/custom-animate.js +11 -2
  60. package/es/animate/custom-animate.js.map +1 -1
  61. package/es/common/color-utils.js +2 -2
  62. package/es/common/color-utils.js.map +1 -1
  63. package/es/core/contributions/textMeasure/AtextMeasure.d.ts +56 -4
  64. package/es/core/contributions/textMeasure/AtextMeasure.js +108 -13
  65. package/es/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
  66. package/es/core/contributions/textMeasure/layout.d.ts +7 -3
  67. package/es/core/contributions/textMeasure/layout.js +40 -39
  68. package/es/core/contributions/textMeasure/layout.js.map +1 -1
  69. package/es/core/stage.d.ts +2 -0
  70. package/es/core/stage.js +9 -5
  71. package/es/core/stage.js.map +1 -1
  72. package/es/graphic/config.d.ts +1 -1
  73. package/es/graphic/config.js +5 -1
  74. package/es/graphic/config.js.map +1 -1
  75. package/es/graphic/graphic-service/graphic-service.d.ts +2 -0
  76. package/es/graphic/graphic-service/graphic-service.js +11 -4
  77. package/es/graphic/graphic-service/graphic-service.js.map +1 -1
  78. package/es/graphic/richtext/line.js +3 -10
  79. package/es/graphic/richtext/line.js.map +1 -1
  80. package/es/graphic/richtext/paragraph.js +3 -2
  81. package/es/graphic/richtext/paragraph.js.map +1 -1
  82. package/es/graphic/richtext/utils.d.ts +1 -2
  83. package/es/graphic/richtext/utils.js +2 -6
  84. package/es/graphic/richtext/utils.js.map +1 -1
  85. package/es/graphic/text.d.ts +11 -11
  86. package/es/graphic/text.js +98 -165
  87. package/es/graphic/text.js.map +1 -1
  88. package/es/graphic/wrap-text.js +12 -4
  89. package/es/graphic/wrap-text.js.map +1 -1
  90. package/es/interface/animate.d.ts +3 -1
  91. package/es/interface/animate.js.map +1 -1
  92. package/es/interface/graphic/text.d.ts +9 -3
  93. package/es/interface/graphic/text.js +6 -1
  94. package/es/interface/graphic/text.js.map +1 -1
  95. package/es/interface/graphic-service.d.ts +2 -0
  96. package/es/interface/graphic-service.js.map +1 -1
  97. package/es/interface/stage.d.ts +1 -0
  98. package/es/interface/stage.js.map +1 -1
  99. package/es/interface/text.d.ts +9 -1
  100. package/es/interface/text.js.map +1 -1
  101. package/es/plugins/builtin-plugin/dirty-bounds-plugin.js +3 -0
  102. package/es/plugins/builtin-plugin/dirty-bounds-plugin.js.map +1 -1
  103. package/es/render/contributions/render/draw-interceptor.js +2 -3
  104. package/es/render/contributions/render/draw-interceptor.js.map +1 -1
  105. package/es/render/contributions/render/text-render.d.ts +1 -1
  106. package/es/render/contributions/render/text-render.js +23 -45
  107. package/es/render/contributions/render/text-render.js.map +1 -1
  108. package/package.json +4 -4
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,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,uBAAuB,CAAC,CAAC;QAChE,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;KAChD;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AA3BD,8CA2BC;AAED,SAAgB,aAAa,CAAC,SAAsC,EAAE,GAAsB;IAC1F,IAAI,QAAQ,GAAG,CAAC,SAAS,IAAI,SAAS,CAAC,QAAQ,CAAC,IAAI,iBAAiB,CAAC,QAAQ,CAAC;IAE/E,IAAI,SAAS,EAAE;QACb,QAAQ,SAAS,CAAC,MAAM,EAAE;YACxB,KAAK,OAAO,CAAC;YACb,KAAK,KAAK;gBACR,QAAQ,IAAI,GAAG,CAAC;gBAChB,MAAM;SACT;KACF;IAED,OAAO,CACL,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QAC1C,GAAG;QACH,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QAC3C,GAAG;QACH,CAAC,QAAQ,IAAI,EAAE,CAAC;QAChB,KAAK;QACL,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,iBAAiB,CAAC,UAAU,CAAC,CACtE,CAAC;AACJ,CAAC;AArBD,sCAqBC","file":"utils.js","sourcesContent":["import type { IBoundsLike } from '@visactor/vutils';\nimport { application } from '../../application';\nimport { createColor } from '../../common/canvas-utils';\nimport type { IContext2d, ITextStyleParams, IRichTextParagraphCharacter } from '../../interface';\n\nexport const DIRECTION_KEY = {\n horizontal: {\n width: 'width',\n height: 'height',\n left: 'left',\n top: 'top',\n x: 'x',\n y: 'y',\n bottom: 'bottom'\n },\n vertical: {\n width: 'height',\n height: 'width',\n left: 'top',\n top: 'left',\n x: 'y',\n y: 'x',\n bottom: 'right'\n }\n};\n\nconst defaultFormatting = {\n fontSize: 16,\n fontFamily: 'sans-serif',\n fill: true,\n stroke: false,\n fontWeight: 'normal',\n lineHeight: 'normal',\n fontStyle: 'normal', // normal, italic, oblique\n textDecoration: 'none', // none, underline, line-through\n textAlign: 'left', // left, right, center\n script: 'normal' // normal, sub, super\n};\nconst nbsp = String.fromCharCode(160);\n\nexport const regLetter = /\\w|\\(|\\)|-/;\nconst regPunctuation = /[.?!,;:/,。?!、;:]/;\nexport const regFirstSpace = /\\S/;\n\nconst setTextStyle = (ctx: IContext2d, character: IRichTextParagraphCharacter) => {\n let fontSize = character.fontSize || 16;\n switch (character.script) {\n case 'super':\n case 'sub':\n fontSize *= 0.8;\n break;\n }\n\n ctx.setTextStyle({\n textAlign: 'left',\n textBaseline: character.textBaseline || 'alphabetic',\n fontStyle: character.fontStyle || '',\n fontWeight: character.fontWeight || '',\n fontSize,\n fontFamily: character.fontFamily || 'sans-serif'\n } as ITextStyleParams);\n};\n\n// Applies the style of a run to the canvas context\nexport function applyFillStyle(ctx: IContext2d, character: IRichTextParagraphCharacter, b?: IBoundsLike) {\n const fillStyle = (character && (character.fill as string)) || defaultFormatting.fill;\n if (!fillStyle) {\n ctx.globalAlpha = 0;\n return;\n }\n\n const { fillOpacity = 1, opacity = 1 } = character;\n\n ctx.globalAlpha = fillOpacity * opacity;\n ctx.fillStyle = b ? createColor(ctx, fillStyle, { AABBBounds: b }) : (fillStyle as string);\n\n setTextStyle(ctx, character);\n}\n\nexport function applyStrokeStyle(ctx: IContext2d, character: IRichTextParagraphCharacter) {\n const strokeStyle = (character && (character.stroke as string)) || (defaultFormatting.stroke as any);\n if (!strokeStyle) {\n ctx.globalAlpha = 0;\n return;\n }\n\n const { strokeOpacity = 1, opacity = 1 } = character;\n\n ctx.globalAlpha = strokeOpacity * opacity;\n ctx.lineWidth = character && typeof character.lineWidth === 'number' ? character.lineWidth : 1;\n ctx.strokeStyle = strokeStyle as string;\n\n setTextStyle(ctx, character);\n}\n\nexport function prepareContext(ctx: IContext2d) {\n ctx.setTextStyle({\n textAlign: 'left',\n textBaseline: 'bottom'\n });\n}\n\n// 确认达到availableWidth的字符串截取index\nexport function getStrByWithDom(\n desc: string,\n width: number,\n style: string,\n guessIndex: number,\n needTestLetter?: boolean\n): number {\n desc = desc.replace(/\\s/g, nbsp);\n\n // 测量用DOM\n const span = document.createElement('span');\n span.setAttribute('style', style);\n span.style.visibility = 'hidden';\n span.style.whiteSpace = 'nowrap';\n document.body.appendChild(span);\n\n // 测量从头到当前位置宽度以及从头到下一个字符位置宽度\n let index = guessIndex;\n let temp = desc.slice(0, index);\n span.innerText = temp;\n let tempWidth = span.offsetWidth;\n\n let tempNext = desc.slice(0, index + 1);\n span.innerText = tempNext;\n let tempWidthNext = span.offsetWidth;\n\n // 到当前位置宽度 < width && 到下一个字符位置宽度 > width时,认为找到准确阶段位置\n while (tempWidth > width || tempWidthNext <= width) {\n if (tempWidth > width) {\n index--;\n } else {\n index++;\n }\n\n temp = desc.slice(0, index);\n span.innerText = temp;\n tempWidth = span.offsetWidth;\n\n tempNext = desc.slice(0, index + 1);\n span.innerText = tempNext;\n tempWidthNext = span.offsetWidth;\n }\n\n // 处理特殊情况\n if (needTestLetter) {\n index = testLetter(desc, index);\n }\n\n document.body.removeChild(span);\n return index;\n}\nexport function getStrByWithCanvas(\n desc: string,\n width: number,\n character: IRichTextParagraphCharacter,\n // ctx: IContext2d,\n guessIndex: number,\n needTestLetter?: boolean\n): number {\n if (!width || width <= 0) {\n return 0;\n }\n const textMeasure = application.graphicUtil.textMeasure;\n // const measurement = textMeasure.measureText(text, character);\n\n // 测量从头到当前位置宽度以及从头到下一个字符位置宽度\n let index = guessIndex;\n let temp = desc.slice(0, index);\n let tempWidth = Math.floor(textMeasure.measureText(temp, character as any).width);\n\n let tempNext = desc.slice(0, index + 1);\n let tempWidthNext = Math.floor(textMeasure.measureText(tempNext, character as any).width);\n\n // 到当前位置宽度 < width && 到下一个字符位置宽度 > width时,认为找到准确阶段位置\n while (tempWidth > width || tempWidthNext <= width) {\n if (tempWidth > width) {\n index--;\n } else {\n index++;\n }\n\n if (index > desc.length) {\n index = desc.length;\n break;\n } else if (index < 0) {\n index = 0;\n break;\n }\n\n temp = desc.slice(0, index);\n tempWidth = Math.floor(textMeasure.measureText(temp, character as any).width);\n\n tempNext = desc.slice(0, index + 1);\n tempWidthNext = Math.floor(textMeasure.measureText(tempNext, character as any).width);\n }\n\n // 处理特殊情况\n if (needTestLetter) {\n index = testLetter(desc, index);\n }\n\n return index;\n}\n\n/**\n * 向前找到单词结尾处换行\n * @param string\n * @param index\n * @param negativeWrongMatch 如果为true,那么如果无法匹配就会向后找到单词的结尾,否则就直接返回index\n * @returns\n */\nexport function testLetter(string: string, index: number, negativeWrongMatch: boolean = false): number {\n let i = index;\n // 切分前后都是英文字母数字下划线,向前找到非英文字母处换行\n while (\n (regLetter.test(string[i - 1]) && regLetter.test(string[i])) ||\n // 行首标点符号处理\n regPunctuation.test(string[i])\n ) {\n i--;\n // 无法满足所有条件,放弃匹配,直接截断,避免陷入死循环\n if (i <= 0) {\n return negativeWrongMatch ? testLetter2(string, index) : index;\n }\n }\n return i;\n}\n\n/**\n * 向后找到单词结尾处换行\n * @param string\n * @param index\n * @returns\n */\nexport function testLetter2(string: string, index: number) {\n let i = index;\n // 切分前后都是英文字母数字下划线,向前找到非英文字母处换行\n while (\n (regLetter.test(string[i - 1]) && regLetter.test(string[i])) ||\n // 行首标点符号处理\n regPunctuation.test(string[i])\n ) {\n i++;\n // 无法满足所有条件,放弃匹配,直接截断,避免陷入死循环\n if (i >= string.length) {\n return i;\n }\n }\n return i;\n}\n\n// 测量文字详细信息\nexport function measureTextDom(\n text: string,\n style: string\n): { ascent?: number; height?: number; descent?: number; width?: number } {\n let div;\n\n const span = document.createElement('span');\n const block = document.createElement('div');\n div = document.createElement('div');\n\n block.style.display = 'inline-block';\n block.style.width = '1px';\n block.style.height = '0';\n\n div.style.visibility = 'hidden';\n div.style.position = 'absolute';\n div.style.top = '0';\n div.style.left = '0';\n div.style.width = '500px';\n div.style.height = '200px';\n div.style.whiteSpace = 'nowrap';\n\n div.appendChild(span);\n div.appendChild(block);\n document.body.appendChild(div);\n\n const result: { ascent?: number; height?: number; descent?: number; width?: number } = {};\n try {\n span.setAttribute('style', style);\n span.style.whiteSpace = 'nowrap';\n span.style.display = 'inline-block';\n\n span.innerHTML = '';\n span.appendChild(document.createTextNode(text.replace(/\\s/g, nbsp)));\n\n block.style.verticalAlign = 'baseline';\n result.ascent = block.offsetTop - span.offsetTop;\n block.style.verticalAlign = 'bottom';\n result.height = block.offsetTop - span.offsetTop;\n result.descent = result.height - result.ascent;\n result.width = span.offsetWidth;\n } finally {\n div.parentNode?.removeChild(div);\n div = null;\n }\n return result;\n}\n\n// 测量文字详细信息\nexport function measureTextCanvas(\n text: string,\n character: IRichTextParagraphCharacter\n): { ascent: number; height: number; descent: number; width: number } {\n const textMeasure = application.graphicUtil.textMeasure;\n const measurement = textMeasure.measureText(text, character as any) as TextMetrics;\n const result: { ascent: number; height: number; descent: number; width: number } = {\n ascent: 0,\n height: 0,\n descent: 0,\n width: 0\n };\n if (\n typeof measurement.actualBoundingBoxAscent !== 'number' ||\n typeof measurement.actualBoundingBoxDescent !== 'number'\n ) {\n result.width = Math.floor(measurement.width);\n result.height = character.fontSize || 0;\n result.ascent = result.height;\n result.descent = 0;\n } else {\n result.width = Math.floor(measurement.width);\n result.height = Math.floor(measurement.actualBoundingBoxAscent + measurement.actualBoundingBoxDescent);\n result.ascent = Math.floor(measurement.actualBoundingBoxAscent);\n result.descent = result.height - result.ascent;\n }\n return result;\n}\n\nexport function getFontString(character: IRichTextParagraphCharacter, ctx: IContext2d | null) {\n let fontSize = (character && character.fontSize) || defaultFormatting.fontSize;\n\n if (character) {\n switch (character.script) {\n case 'super':\n case 'sub':\n fontSize *= 0.8;\n break;\n }\n }\n\n return (\n ((character && character.fontStyle) || '') +\n ' ' +\n ((character && character.fontWeight) || '') +\n ' ' +\n (fontSize || 12) +\n 'px ' +\n ((character && character.fontFamily) || defaultFormatting.fontF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IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AA3BD,8CA2BC;AAED,SAAgB,aAAa,CAAC,SAAsC,EAAE,GAAsB;IAC1F,IAAI,QAAQ,GAAG,CAAC,SAAS,IAAI,SAAS,CAAC,QAAQ,CAAC,IAAI,iBAAiB,CAAC,QAAQ,CAAC;IAE/E,IAAI,SAAS,EAAE;QACb,QAAQ,SAAS,CAAC,MAAM,EAAE;YACxB,KAAK,OAAO,CAAC;YACb,KAAK,KAAK;gBACR,QAAQ,IAAI,GAAG,CAAC;gBAChB,MAAM;SACT;KACF;IAED,OAAO,CACL,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QAC1C,GAAG;QACH,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QAC3C,GAAG;QACH,CAAC,QAAQ,IAAI,EAAE,CAAC;QAChB,KAAK;QACL,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,iBAAiB,CAAC,UAAU,CAAC,CACtE,CAAC;AACJ,CAAC;AArBD,sCAqBC","file":"utils.js","sourcesContent":["import { application } from '../../application';\nimport type { IContext2d, ITextStyleParams, IRichTextParagraphCharacter } from '../../interface';\n\nexport const DIRECTION_KEY = {\n horizontal: {\n width: 'width',\n height: 'height',\n left: 'left',\n top: 'top',\n x: 'x',\n y: 'y',\n bottom: 'bottom'\n },\n vertical: {\n width: 'height',\n height: 'width',\n left: 'top',\n top: 'left',\n x: 'y',\n y: 'x',\n bottom: 'right'\n }\n};\n\nconst defaultFormatting = {\n fontSize: 16,\n fontFamily: 'sans-serif',\n fill: true,\n stroke: false,\n fontWeight: 'normal',\n lineHeight: 'normal',\n fontStyle: 'normal', // normal, italic, oblique\n textDecoration: 'none', // none, underline, line-through\n textAlign: 'left', // left, right, center\n script: 'normal' // normal, sub, super\n};\nconst nbsp = String.fromCharCode(160);\n\nexport const regLetter = /\\w|\\(|\\)|-/;\nconst regPunctuation = /[.?!,;:/,。?!、;:]/;\nexport const regFirstSpace = /\\S/;\n\nconst setTextStyle = (ctx: IContext2d, character: IRichTextParagraphCharacter) => {\n let fontSize = character.fontSize || 16;\n switch (character.script) {\n case 'super':\n case 'sub':\n fontSize *= 0.8;\n break;\n }\n\n ctx.setTextStyle({\n textAlign: 'left',\n textBaseline: character.textBaseline || 'alphabetic',\n fontStyle: character.fontStyle || '',\n fontWeight: character.fontWeight || '',\n fontSize,\n fontFamily: character.fontFamily || 'sans-serif'\n } as ITextStyleParams);\n};\n\n// Applies the style of a run to the canvas context\nexport function applyFillStyle(ctx: IContext2d, character: IRichTextParagraphCharacter) {\n const fillStyle = (character && (character.fill as string)) || defaultFormatting.fill;\n if (!fillStyle) {\n ctx.globalAlpha = 0;\n return;\n }\n\n const { fillOpacity = 1, opacity = 1 } = character;\n\n ctx.globalAlpha = fillOpacity * opacity;\n ctx.fillStyle = fillStyle as string;\n\n setTextStyle(ctx, character);\n}\n\nexport function applyStrokeStyle(ctx: IContext2d, character: IRichTextParagraphCharacter) {\n const strokeStyle = (character && (character.stroke as string)) || (defaultFormatting.stroke as any);\n if (!strokeStyle) {\n ctx.globalAlpha = 0;\n return;\n }\n\n const { strokeOpacity = 1, opacity = 1 } = character;\n\n ctx.globalAlpha = strokeOpacity * opacity;\n ctx.lineWidth = character && typeof character.lineWidth === 'number' ? character.lineWidth : 1;\n ctx.strokeStyle = strokeStyle as string;\n\n setTextStyle(ctx, character);\n}\n\nexport function prepareContext(ctx: IContext2d) {\n ctx.setTextStyle({\n textAlign: 'left',\n textBaseline: 'bottom'\n });\n}\n\n// 确认达到availableWidth的字符串截取index\nexport function getStrByWithDom(\n desc: string,\n width: number,\n style: string,\n guessIndex: number,\n needTestLetter?: boolean\n): number {\n desc = desc.replace(/\\s/g, nbsp);\n\n // 测量用DOM\n const span = document.createElement('span');\n span.setAttribute('style', style);\n span.style.visibility = 'hidden';\n span.style.whiteSpace = 'nowrap';\n document.body.appendChild(span);\n\n // 测量从头到当前位置宽度以及从头到下一个字符位置宽度\n let index = guessIndex;\n let temp = desc.slice(0, index);\n span.innerText = temp;\n let tempWidth = span.offsetWidth;\n\n let tempNext = desc.slice(0, index + 1);\n span.innerText = tempNext;\n let tempWidthNext = span.offsetWidth;\n\n // 到当前位置宽度 < width && 到下一个字符位置宽度 > width时,认为找到准确阶段位置\n while (tempWidth > width || tempWidthNext <= width) {\n if (tempWidth > width) {\n index--;\n } else {\n index++;\n }\n\n temp = desc.slice(0, index);\n span.innerText = temp;\n tempWidth = span.offsetWidth;\n\n tempNext = desc.slice(0, index + 1);\n span.innerText = tempNext;\n tempWidthNext = span.offsetWidth;\n }\n\n // 处理特殊情况\n if (needTestLetter) {\n index = testLetter(desc, index);\n }\n\n document.body.removeChild(span);\n return index;\n}\nexport function getStrByWithCanvas(\n desc: string,\n width: number,\n character: IRichTextParagraphCharacter,\n // ctx: IContext2d,\n guessIndex: number,\n needTestLetter?: boolean\n): number {\n if (!width || width <= 0) {\n return 0;\n }\n const textMeasure = application.graphicUtil.textMeasure;\n // const measurement = textMeasure.measureText(text, character);\n\n // 测量从头到当前位置宽度以及从头到下一个字符位置宽度\n let index = guessIndex;\n let temp = desc.slice(0, index);\n let tempWidth = Math.floor(textMeasure.measureText(temp, character as any).width);\n\n let tempNext = desc.slice(0, index + 1);\n let tempWidthNext = Math.floor(textMeasure.measureText(tempNext, character as any).width);\n\n // 到当前位置宽度 < width && 到下一个字符位置宽度 > width时,认为找到准确阶段位置\n while (tempWidth > width || tempWidthNext <= width) {\n if (tempWidth > width) {\n index--;\n } else {\n index++;\n }\n\n if (index > desc.length) {\n index = desc.length;\n break;\n } else if (index < 0) {\n index = 0;\n break;\n }\n\n temp = desc.slice(0, index);\n tempWidth = Math.floor(textMeasure.measureText(temp, character as any).width);\n\n tempNext = desc.slice(0, index + 1);\n tempWidthNext = Math.floor(textMeasure.measureText(tempNext, character as any).width);\n }\n\n // 处理特殊情况\n if (needTestLetter) {\n index = testLetter(desc, index);\n }\n\n return index;\n}\n\n/**\n * 向前找到单词结尾处换行\n * @param string\n * @param index\n * @param negativeWrongMatch 如果为true,那么如果无法匹配就会向后找到单词的结尾,否则就直接返回index\n * @returns\n */\nexport function testLetter(string: string, index: number, negativeWrongMatch: boolean = false): number {\n let i = index;\n // 切分前后都是英文字母数字下划线,向前找到非英文字母处换行\n while (\n (regLetter.test(string[i - 1]) && regLetter.test(string[i])) ||\n // 行首标点符号处理\n regPunctuation.test(string[i])\n ) {\n i--;\n // 无法满足所有条件,放弃匹配,直接截断,避免陷入死循环\n if (i <= 0) {\n return negativeWrongMatch ? testLetter2(string, index) : index;\n }\n }\n return i;\n}\n\n/**\n * 向后找到单词结尾处换行\n * @param string\n * @param index\n * @returns\n */\nexport function testLetter2(string: string, index: number) {\n let i = index;\n // 切分前后都是英文字母数字下划线,向前找到非英文字母处换行\n while (\n (regLetter.test(string[i - 1]) && regLetter.test(string[i])) ||\n // 行首标点符号处理\n regPunctuation.test(string[i])\n ) {\n i++;\n // 无法满足所有条件,放弃匹配,直接截断,避免陷入死循环\n if (i >= string.length) {\n return i;\n }\n }\n return i;\n}\n\n// 测量文字详细信息\nexport function measureTextDom(\n text: string,\n style: string\n): { ascent?: number; height?: number; descent?: number; width?: number } {\n let div;\n\n const span = document.createElement('span');\n const block = document.createElement('div');\n div = document.createElement('div');\n\n block.style.display = 'inline-block';\n block.style.width = '1px';\n block.style.height = '0';\n\n div.style.visibility = 'hidden';\n div.style.position = 'absolute';\n div.style.top = '0';\n div.style.left = '0';\n div.style.width = '500px';\n div.style.height = '200px';\n div.style.whiteSpace = 'nowrap';\n\n div.appendChild(span);\n div.appendChild(block);\n document.body.appendChild(div);\n\n const result: { ascent?: number; height?: number; descent?: number; width?: number } = {};\n try {\n span.setAttribute('style', style);\n span.style.whiteSpace = 'nowrap';\n span.style.display = 'inline-block';\n\n span.innerHTML = '';\n span.appendChild(document.createTextNode(text.replace(/\\s/g, nbsp)));\n\n block.style.verticalAlign = 'baseline';\n result.ascent = block.offsetTop - span.offsetTop;\n block.style.verticalAlign = 'bottom';\n result.height = block.offsetTop - span.offsetTop;\n result.descent = result.height - result.ascent;\n result.width = span.offsetWidth;\n } finally {\n div.parentNode?.removeChild(div);\n div = null;\n }\n return result;\n}\n\n// 测量文字详细信息\nexport function measureTextCanvas(\n text: string,\n character: IRichTextParagraphCharacter\n): { ascent: number; height: number; descent: number; width: number } {\n const textMeasure = application.graphicUtil.textMeasure;\n const measurement = textMeasure.measureText(text, character as any) as TextMetrics;\n const result: { ascent: number; height: number; descent: number; width: number } = {\n ascent: 0,\n height: 0,\n descent: 0,\n width: 0\n };\n if (\n typeof measurement.actualBoundingBoxAscent !== 'number' ||\n typeof measurement.actualBoundingBoxDescent !== 'number'\n ) {\n result.width = Math.floor(measurement.width);\n result.height = character.fontSize || 0;\n result.ascent = result.height;\n result.descent = 0;\n } else {\n result.width = Math.floor(measurement.width);\n result.height = Math.floor(measurement.actualBoundingBoxAscent + measurement.actualBoundingBoxDescent);\n result.ascent = Math.floor(measurement.actualBoundingBoxAscent);\n result.descent = result.height - result.ascent;\n }\n return result;\n}\n\nexport function getFontString(character: IRichTextParagraphCharacter, ctx: IContext2d | null) {\n let fontSize = (character && character.fontSize) || defaultFormatting.fontSize;\n\n if (character) {\n switch (character.script) {\n case 'super':\n case 'sub':\n fontSize *= 0.8;\n break;\n }\n }\n\n return (\n ((character && character.fontStyle) || '') +\n ' ' +\n ((character && character.fontWeight) || '') +\n ' ' +\n (fontSize || 12) +\n 'px ' +\n ((character && character.fontFamily) || defaultFormatting.fontFamily)\n );\n}\n"]}
@@ -48,7 +48,6 @@ export declare class Text extends Graphic<ITextGraphicAttribute> implements ITex
48
48
  get clipedWidth(): number | undefined;
49
49
  get cliped(): boolean | undefined;
50
50
  get multilineLayout(): LayoutType | undefined;
51
- private isSimplify;
52
51
  get isMultiLine(): boolean;
53
52
  constructor(params?: ITextGraphicAttribute);
54
53
  isValid(): boolean;
@@ -56,10 +55,18 @@ export declare class Text extends Graphic<ITextGraphicAttribute> implements ITex
56
55
  getGraphicTheme(): Required<ITextGraphicAttribute>;
57
56
  protected doUpdateOBBBounds(): IOBBBounds;
58
57
  protected updateAABBBounds(attribute: ITextGraphicAttribute, textTheme: Required<ITextGraphicAttribute>, aabbBounds: IAABBBounds): import("@visactor/vutils").IBounds;
59
- updateWrapAABBBounds(text: (number | string) | (number | string)[]): import("@visactor/vutils").IBounds;
60
58
  updateSingallineAABBBounds(text: number | string): IAABBBounds;
61
- updateMultilineAABBBounds(text: (number | string)[]): IAABBBounds;
62
- updateHorizontalSinglelineAABBBounds(text: number | string): IAABBBounds;
59
+ protected updateMultilineAABBBounds(text: (number | string)[]): IAABBBounds;
60
+ guessLineHeightBuf(fontSize: number): number;
61
+ updateHorizontalMultilineAABBBounds(text: (number | string)[]): IAABBBounds;
62
+ updateWrapAABBBounds(text: (number | string) | (number | string)[]): import("@visactor/vutils").IBounds;
63
+ updateVerticalMultilineAABBBounds(text: (number | string)[]): IAABBBounds;
64
+ protected getMaxWidth(theme: ITextGraphicAttribute): number;
65
+ protected getLineHeight(attribute: ITextGraphicAttribute, textTheme: ITextGraphicAttribute): number;
66
+ protected needUpdateTags(keys: string[], k?: string[]): boolean;
67
+ protected needUpdateTag(key: string, k?: string[]): boolean;
68
+ clone(): Text;
69
+ getNoWorkAnimateAttr(): Record<string, number>;
63
70
  getBaselineMapAlign(): Record<string, string>;
64
71
  getAlignMapBaseline(): Record<string, string>;
65
72
  static baselineMapAlign: {
@@ -72,12 +79,5 @@ export declare class Text extends Graphic<ITextGraphicAttribute> implements ITex
72
79
  right: string;
73
80
  center: string;
74
81
  };
75
- updateVerticalSinglelineAABBBounds(text: number | string): IAABBBounds;
76
- updateHorizontalMultilineAABBBounds(text: (number | string)[]): IAABBBounds;
77
- updateVerticalMultilineAABBBounds(text: (number | string)[]): IAABBBounds;
78
- protected needUpdateTags(keys: string[], k?: string[]): boolean;
79
- protected needUpdateTag(key: string, k?: string[]): boolean;
80
- clone(): Text;
81
- getNoWorkAnimateAttr(): Record<string, number>;
82
82
  }
83
83
  export declare function createText(attributes: ITextGraphicAttribute): IText;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  }), exports.createText = exports.Text = void 0;
6
6
 
7
- const vutils_1 = require("@visactor/vutils"), text_1 = require("../common/text"), layout_1 = require("../core/contributions/textMeasure/layout"), application_1 = require("../application"), graphic_1 = require("./graphic"), theme_1 = require("./theme"), utils_1 = require("../common/utils"), constants_1 = require("./constants"), tools_1 = require("./tools"), TEXT_UPDATE_TAG_KEY = [ "text", "maxLineWidth", "textAlign", "textBaseline", "heightLimit", "lineClamp", "fontSize", "fontFamily", "fontWeight", "ellipsis", "lineHeight", "direction", "wordBreak", "heightLimit", "lineClamp", ...graphic_1.GRAPHIC_UPDATE_TAG_KEY ];
7
+ const vutils_1 = require("@visactor/vutils"), text_1 = require("../common/text"), layout_1 = require("../core/contributions/textMeasure/layout"), application_1 = require("../application"), graphic_1 = require("./graphic"), theme_1 = require("./theme"), utils_1 = require("../common/utils"), constants_1 = require("./constants"), tools_1 = require("./tools"), TEXT_UPDATE_TAG_KEY = [ "text", "maxLineWidth", "maxWidth", "textAlign", "textBaseline", "heightLimit", "lineClamp", "fontSize", "fontFamily", "fontWeight", "ellipsis", "lineHeight", "direction", "wordBreak", "heightLimit", "lineClamp", ...graphic_1.GRAPHIC_UPDATE_TAG_KEY ];
8
8
 
9
9
  class Text extends graphic_1.Graphic {
10
10
  get font() {
@@ -14,18 +14,17 @@ class Text extends graphic_1.Graphic {
14
14
  }
15
15
  get clipedText() {
16
16
  var _a;
17
- const attribute = this.attribute, textTheme = this.getGraphicTheme();
18
- if (!this.isSimplify()) return;
19
- const {maxLineWidth: maxLineWidth = textTheme.maxLineWidth} = attribute;
20
- return Number.isFinite(maxLineWidth) ? (this.tryUpdateAABBBounds(), this.cache.clipedText) : (null !== (_a = attribute.text) && void 0 !== _a ? _a : textTheme.text).toString();
17
+ const attribute = this.attribute, textTheme = this.getGraphicTheme(), maxWidth = this.getMaxWidth(textTheme);
18
+ return Number.isFinite(maxWidth) ? (this.tryUpdateAABBBounds(), this.cache.clipedText) : (null !== (_a = attribute.text) && void 0 !== _a ? _a : textTheme.text).toString();
21
19
  }
22
20
  get clipedWidth() {
23
- if (this.isSimplify()) return this.tryUpdateAABBBounds(), this.cache.clipedWidth;
21
+ return this.tryUpdateAABBBounds(), this.cache.clipedWidth;
24
22
  }
25
23
  get cliped() {
26
24
  var _a, _b;
27
- const textTheme = this.getGraphicTheme(), attribute = this.attribute, {maxLineWidth: maxLineWidth = textTheme.maxLineWidth, text: text, whiteSpace: whiteSpace = textTheme.whiteSpace} = attribute;
28
- if (!Number.isFinite(maxLineWidth)) return !1;
25
+ const textTheme = this.getGraphicTheme(), attribute = this.attribute, maxWidth = this.getMaxWidth(textTheme);
26
+ if (!Number.isFinite(maxWidth)) return !1;
27
+ const {text: text} = this.attribute;
29
28
  if (this.tryUpdateAABBBounds(), null === (_b = null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData) || void 0 === _b ? void 0 : _b.lines) {
30
29
  let mergedText = "";
31
30
  this.cache.layoutData.lines.forEach((item => {
@@ -36,10 +35,7 @@ class Text extends graphic_1.Graphic {
36
35
  return "vertical" === attribute.direction && this.cache.verticalList && this.cache.verticalList[0] ? this.cache.verticalList[0].map((item => item.text)).join("") !== attribute.text.toString() : null != this.clipedText && this.clipedText !== attribute.text.toString();
37
36
  }
38
37
  get multilineLayout() {
39
- if (this.isMultiLine) return this.tryUpdateAABBBounds(), this.cache.layoutData;
40
- }
41
- isSimplify() {
42
- return !this.isMultiLine && "vertical" !== this.attribute.direction;
38
+ return this.tryUpdateAABBBounds(), this.cache.layoutData;
43
39
  }
44
40
  get isMultiLine() {
45
41
  return Array.isArray(this.attribute.text) || "normal" === this.attribute.whiteSpace;
@@ -95,20 +91,60 @@ class Text extends graphic_1.Graphic {
95
91
  (0, vutils_1.transformBoundsWithMatrix)(aabbBounds, aabbBounds, this.transMatrix),
96
92
  aabbBounds;
97
93
  }
94
+ updateSingallineAABBBounds(text) {
95
+ this.updateMultilineAABBBounds([ text ]);
96
+ const layoutData = this.cache.layoutData;
97
+ if (layoutData) {
98
+ const line = layoutData.lines[0];
99
+ this.cache.clipedText = line.str, this.cache.clipedWidth = line.width;
100
+ }
101
+ return this._AABBBounds;
102
+ }
103
+ updateMultilineAABBBounds(text) {
104
+ const textTheme = this.getGraphicTheme(), {direction: direction = textTheme.direction, underlineOffset: underlineOffset = textTheme.underlineOffset} = this.attribute, b = "horizontal" === direction ? this.updateHorizontalMultilineAABBBounds(text) : this.updateVerticalMultilineAABBBounds(text);
105
+ return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset),
106
+ b;
107
+ }
108
+ guessLineHeightBuf(fontSize) {
109
+ return fontSize ? .1 * fontSize : 0;
110
+ }
111
+ updateHorizontalMultilineAABBBounds(text) {
112
+ var _a;
113
+ const textTheme = this.getGraphicTheme(), attribute = this.attribute, {fontFamily: fontFamily = textTheme.fontFamily, textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline, fontSize: fontSize = textTheme.fontSize, fontWeight: fontWeight = textTheme.fontWeight, ellipsis: ellipsis = textTheme.ellipsis, maxLineWidth: maxLineWidth, stroke: stroke = textTheme.stroke, wrap: wrap = textTheme.wrap, measureMode: measureMode = textTheme.measureMode, lineWidth: lineWidth = textTheme.lineWidth, whiteSpace: whiteSpace = textTheme.whiteSpace, suffixPosition: suffixPosition = textTheme.suffixPosition, ignoreBuf: ignoreBuf = textTheme.ignoreBuf} = attribute, buf = ignoreBuf ? 0 : this.guessLineHeightBuf(fontSize), lineHeight = this.getLineHeight(attribute, textTheme) + buf;
114
+ if ("normal" === whiteSpace || wrap) return this.updateWrapAABBBounds(text);
115
+ if (!this.shouldUpdateShape() && (null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData)) {
116
+ const bbox = this.cache.layoutData.bbox;
117
+ return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height),
118
+ stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
119
+ }
120
+ const textMeasure = application_1.application.graphicUtil.textMeasure, layoutData = new layout_1.CanvasTextLayout(fontFamily, {
121
+ fontSize: fontSize,
122
+ fontWeight: fontWeight,
123
+ fontFamily: fontFamily,
124
+ lineHeight: lineHeight
125
+ }, textMeasure).GetLayoutByLines(text, textAlign, textBaseline, lineHeight, !0 === ellipsis ? textTheme.ellipsis : ellipsis || void 0, !1, {
126
+ lineWidth: maxLineWidth,
127
+ suffixPosition: suffixPosition,
128
+ measureMode: measureMode
129
+ }), {bbox: bbox} = layoutData;
130
+ return this.cache.layoutData = layoutData, this.clearUpdateShapeTag(), this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height),
131
+ stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
132
+ }
98
133
  updateWrapAABBBounds(text) {
99
- var _a, _b, _c, _d;
100
- const textTheme = this.getGraphicTheme(), {fontFamily: fontFamily = textTheme.fontFamily, textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline, fontSize: fontSize = textTheme.fontSize, ellipsis: ellipsis = textTheme.ellipsis, maxLineWidth: maxLineWidth, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, wordBreak: wordBreak = textTheme.wordBreak, fontWeight: fontWeight = textTheme.fontWeight, ignoreBuf: ignoreBuf = textTheme.ignoreBuf, suffixPosition: suffixPosition = textTheme.suffixPosition, heightLimit: heightLimit = 0, lineClamp: lineClamp} = this.attribute, lineHeight = null !== (_a = (0,
101
- utils_1.calculateLineHeight)(this.attribute.lineHeight, this.attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : this.attribute.fontSize || textTheme.fontSize, buf = ignoreBuf ? 0 : 2;
102
- if (!this.shouldUpdateShape() && (null === (_b = this.cache) || void 0 === _b ? void 0 : _b.layoutData)) {
134
+ var _a, _b, _c;
135
+ const textTheme = this.getGraphicTheme(), {fontFamily: fontFamily = textTheme.fontFamily, textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline, fontSize: fontSize = textTheme.fontSize, ellipsis: ellipsis = textTheme.ellipsis, maxLineWidth: maxLineWidth, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, wordBreak: wordBreak = textTheme.wordBreak, fontWeight: fontWeight = textTheme.fontWeight, ignoreBuf: ignoreBuf = textTheme.ignoreBuf, measureMode: measureMode = textTheme.measureMode, suffixPosition: suffixPosition = textTheme.suffixPosition, heightLimit: heightLimit = 0, lineClamp: lineClamp} = this.attribute, buf = ignoreBuf ? 0 : this.guessLineHeightBuf(fontSize), lineHeight = this.getLineHeight(this.attribute, textTheme) + buf;
136
+ if (!this.shouldUpdateShape() && (null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData)) {
103
137
  const bbox = this.cache.layoutData.bbox;
104
138
  return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height),
105
139
  stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
106
140
  }
107
- const textMeasure = application_1.application.graphicUtil.textMeasure, layoutObj = new layout_1.CanvasTextLayout(fontFamily, {
141
+ const textMeasure = application_1.application.graphicUtil.textMeasure, textOptions = {
108
142
  fontSize: fontSize,
109
143
  fontWeight: fontWeight,
110
- fontFamily: fontFamily
111
- }, textMeasure), lines = (0, vutils_1.isArray)(text) ? text.map((l => l.toString())) : [ text.toString() ], linesLayout = [], bboxWH = [ 0, 0 ];
144
+ fontFamily: fontFamily,
145
+ lineHeight: lineHeight
146
+ }, layoutObj = new layout_1.CanvasTextLayout(fontFamily, textOptions, textMeasure), lines = (0,
147
+ vutils_1.isArray)(text) ? text.map((l => l.toString())) : [ text.toString() ], linesLayout = [], bboxWH = [ 0, 0 ];
112
148
  let lineCountLimit = 1 / 0;
113
149
  if (heightLimit > 0 && (lineCountLimit = Math.max(Math.floor(heightLimit / lineHeight), 1)),
114
150
  lineClamp && (lineCountLimit = Math.min(lineCountLimit, lineClamp)), "number" == typeof maxLineWidth && maxLineWidth !== 1 / 0) {
@@ -116,30 +152,35 @@ class Text extends graphic_1.Graphic {
116
152
  const str = lines[i];
117
153
  let needCut = !0;
118
154
  if (i === lineCountLimit - 1) {
119
- const clip = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition, i !== lines.length - 1);
155
+ const clip = textMeasure.clipTextWithSuffix(str, textOptions, maxLineWidth, ellipsis, !1, suffixPosition, i !== lines.length - 1), matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions, measureMode);
120
156
  linesLayout.push({
121
157
  str: clip.str,
122
- width: clip.width
158
+ width: clip.width,
159
+ ascent: matrics.ascent,
160
+ descent: matrics.descent
123
161
  });
124
162
  break;
125
163
  }
126
- const clip = layoutObj.textMeasure.clipText(str, layoutObj.textOptions, maxLineWidth, "break-all" !== wordBreak, "keep-all" === wordBreak);
164
+ const clip = textMeasure.clipText(str, textOptions, maxLineWidth, "break-all" !== wordBreak, "keep-all" === wordBreak);
127
165
  if ("" !== str && "" === clip.str || clip.wordBreaked) {
128
166
  if (ellipsis) {
129
- const clipEllipsis = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
130
- clip.str = null !== (_c = clipEllipsis.str) && void 0 !== _c ? _c : "", clip.width = null !== (_d = clipEllipsis.width) && void 0 !== _d ? _d : 0;
167
+ const clipEllipsis = textMeasure.clipTextWithSuffix(str, textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
168
+ clip.str = null !== (_b = clipEllipsis.str) && void 0 !== _b ? _b : "", clip.width = null !== (_c = clipEllipsis.width) && void 0 !== _c ? _c : 0;
131
169
  } else clip.str = "", clip.width = 0;
132
170
  needCut = !1;
133
171
  }
172
+ const matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions, measureMode);
134
173
  linesLayout.push({
135
174
  str: clip.str,
136
- width: clip.width
175
+ width: clip.width,
176
+ ascent: matrics.ascent,
177
+ descent: matrics.descent
137
178
  });
138
179
  let cutLength = clip.str.length;
139
180
  if (!clip.wordBreaked || "" !== str && "" === clip.str || (needCut = !0, cutLength = clip.wordBreaked),
140
181
  clip.str.length === str.length) ; else if (needCut) {
141
- let newStr = str.substring(cutLength);
142
- "keep-all" === wordBreak && (newStr = newStr.replace(/^\s+/g, "")), lines.splice(i + 1, 0, newStr);
182
+ const newStr = str.substring(cutLength);
183
+ lines.splice(i + 1, 0, newStr);
143
184
  }
144
185
  }
145
186
  let maxWidth = 0;
@@ -150,175 +191,48 @@ class Text extends graphic_1.Graphic {
150
191
  let width, text, lineWidth = 0;
151
192
  for (let i = 0, len = lines.length; i < len; i++) {
152
193
  if (i === lineCountLimit - 1) {
153
- const clip = layoutObj.textMeasure.clipTextWithSuffix(lines[i], layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
194
+ const clip = textMeasure.clipTextWithSuffix(lines[i], textOptions, maxLineWidth, ellipsis, !1, suffixPosition), matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions, measureMode);
154
195
  linesLayout.push({
155
196
  str: clip.str,
156
- width: clip.width
197
+ width: clip.width,
198
+ ascent: matrics.ascent,
199
+ descent: matrics.descent
157
200
  }), lineWidth = Math.max(lineWidth, clip.width);
158
201
  break;
159
202
  }
160
- text = lines[i], width = layoutObj.textMeasure.measureTextWidth(text, layoutObj.textOptions, "break-word" === wordBreak),
161
- lineWidth = Math.max(lineWidth, width), linesLayout.push({
203
+ text = lines[i], width = textMeasure.measureTextWidth(text, textOptions), lineWidth = Math.max(lineWidth, width);
204
+ const matrics = textMeasure.measureTextPixelADscentAndWidth(text, textOptions, measureMode);
205
+ linesLayout.push({
162
206
  str: text,
163
- width: width
207
+ width: width,
208
+ ascent: matrics.ascent,
209
+ descent: matrics.descent
164
210
  });
165
211
  }
166
212
  bboxWH[0] = lineWidth;
167
213
  }
168
- bboxWH[1] = linesLayout.length * (lineHeight + buf);
214
+ bboxWH[1] = linesLayout.length * lineHeight;
169
215
  const bbox = {
170
216
  xOffset: 0,
171
217
  yOffset: 0,
172
218
  width: bboxWH[0],
173
219
  height: bboxWH[1]
174
220
  };
175
- layoutObj.LayoutBBox(bbox, textAlign, textBaseline);
221
+ layoutObj.LayoutBBox(bbox, textAlign, textBaseline, linesLayout);
176
222
  const layoutData = layoutObj.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
177
223
  return this.cache.layoutData = layoutData, this.clearUpdateShapeTag(), this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height),
178
224
  stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
179
225
  }
180
- updateSingallineAABBBounds(text) {
181
- const textTheme = this.getGraphicTheme(), {direction: direction = textTheme.direction, underlineOffset: underlineOffset = textTheme.underlineOffset} = this.attribute, b = "horizontal" === direction ? this.updateHorizontalSinglelineAABBBounds(text) : this.updateVerticalSinglelineAABBBounds(text);
182
- return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset),
183
- b;
184
- }
185
- updateMultilineAABBBounds(text) {
186
- const textTheme = this.getGraphicTheme(), {direction: direction = textTheme.direction, underlineOffset: underlineOffset = textTheme.underlineOffset} = this.attribute, b = "horizontal" === direction ? this.updateHorizontalMultilineAABBBounds(text) : this.updateVerticalMultilineAABBBounds(text);
187
- return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset),
188
- b;
189
- }
190
- updateHorizontalSinglelineAABBBounds(text) {
191
- var _a, _b;
192
- const textTheme = this.getGraphicTheme(), {wrap: wrap = textTheme.wrap} = this.attribute;
193
- if (wrap) return this.updateWrapAABBBounds([ text ]);
194
- const textMeasure = application_1.application.graphicUtil.textMeasure;
195
- let width, str;
196
- const attribute = this.attribute, {maxLineWidth: maxLineWidth = textTheme.maxLineWidth, ellipsis: ellipsis = textTheme.ellipsis, textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline, fontFamily: fontFamily = textTheme.fontFamily, fontSize: fontSize = textTheme.fontSize, fontWeight: fontWeight = textTheme.fontWeight, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, ignoreBuf: ignoreBuf = textTheme.ignoreBuf, whiteSpace: whiteSpace = textTheme.whiteSpace, suffixPosition: suffixPosition = textTheme.suffixPosition} = attribute;
197
- if ("normal" === whiteSpace) return this.updateWrapAABBBounds(text);
198
- const buf = ignoreBuf ? 0 : Math.max(2, .075 * fontSize), textFontSize = attribute.fontSize || textTheme.fontSize, lineHeight = null !== (_a = (0,
199
- utils_1.calculateLineHeight)(attribute.lineHeight, textFontSize)) && void 0 !== _a ? _a : textFontSize + buf;
200
- if (!this.shouldUpdateShape() && this.cache) {
201
- width = null !== (_b = this.cache.clipedWidth) && void 0 !== _b ? _b : 0;
202
- const dx = (0, text_1.textDrawOffsetX)(textAlign, width), dy = (0, text_1.textLayoutOffsetY)(textBaseline, lineHeight, fontSize);
203
- return this._AABBBounds.set(dx, dy, dx + width, dy + lineHeight), stroke && this._AABBBounds.expand(lineWidth / 2),
204
- this._AABBBounds;
205
- }
206
- if (Number.isFinite(maxLineWidth)) {
207
- if (ellipsis) {
208
- const strEllipsis = !0 === ellipsis ? textTheme.ellipsis : ellipsis, data = textMeasure.clipTextWithSuffix(text.toString(), {
209
- fontSize: fontSize,
210
- fontWeight: fontWeight,
211
- fontFamily: fontFamily
212
- }, maxLineWidth, strEllipsis, !1, suffixPosition);
213
- str = data.str, width = data.width;
214
- } else {
215
- const data = textMeasure.clipText(text.toString(), {
216
- fontSize: fontSize,
217
- fontWeight: fontWeight,
218
- fontFamily: fontFamily
219
- }, maxLineWidth, !1);
220
- str = data.str, width = data.width;
221
- }
222
- this.cache.clipedText = str, this.cache.clipedWidth = width;
223
- } else width = textMeasure.measureTextWidth(text.toString(), {
224
- fontSize: fontSize,
225
- fontWeight: fontWeight,
226
- fontFamily: fontFamily
227
- }), this.cache.clipedText = text.toString(), this.cache.clipedWidth = width;
228
- this.clearUpdateShapeTag();
229
- const dx = (0, text_1.textDrawOffsetX)(textAlign, width);
230
- let lh = lineHeight;
231
- application_1.application.global && application_1.application.global.isSafari() && (lh += .2 * fontSize);
232
- const dy = (0, text_1.textLayoutOffsetY)(textBaseline, lh, fontSize, buf);
233
- return this._AABBBounds.set(dx, dy, dx + width, dy + lh), stroke && this._AABBBounds.expand(lineWidth / 2),
234
- this._AABBBounds;
235
- }
236
- getBaselineMapAlign() {
237
- return Text.baselineMapAlign;
238
- }
239
- getAlignMapBaseline() {
240
- return Text.alignMapBaseline;
241
- }
242
- updateVerticalSinglelineAABBBounds(text) {
243
- var _a, _b, _c;
244
- const textTheme = this.getGraphicTheme(), textMeasure = application_1.application.graphicUtil.textMeasure;
245
- let width;
246
- const attribute = this.attribute, {ignoreBuf: ignoreBuf = textTheme.ignoreBuf} = attribute, buf = ignoreBuf ? 0 : 2, {maxLineWidth: maxLineWidth = textTheme.maxLineWidth, ellipsis: ellipsis = textTheme.ellipsis, fontSize: fontSize = textTheme.fontSize, fontWeight: fontWeight = textTheme.fontWeight, fontFamily: fontFamily = textTheme.fontFamily, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, verticalMode: verticalMode = textTheme.verticalMode, suffixPosition: suffixPosition = textTheme.suffixPosition} = attribute, lineHeight = null !== (_a = (0,
247
- utils_1.calculateLineHeight)(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
248
- let {textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline} = attribute;
249
- if (!verticalMode) {
250
- const t = textAlign;
251
- textAlign = null !== (_b = Text.baselineMapAlign[textBaseline]) && void 0 !== _b ? _b : "left",
252
- textBaseline = null !== (_c = Text.alignMapBaseline[t]) && void 0 !== _c ? _c : "top";
253
- }
254
- if (!this.shouldUpdateShape() && this.cache) {
255
- width = this.cache.clipedWidth;
256
- const dx = (0, text_1.textDrawOffsetX)(textAlign, width), dy = (0, text_1.textLayoutOffsetY)(textBaseline, lineHeight, fontSize);
257
- return this._AABBBounds.set(dy, dx, dy + lineHeight, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2),
258
- this._AABBBounds;
259
- }
260
- let verticalList = [ (0, tools_1.verticalLayout)(text.toString()) ];
261
- if (Number.isFinite(maxLineWidth)) {
262
- if (ellipsis) {
263
- const strEllipsis = !0 === ellipsis ? textTheme.ellipsis : ellipsis, data = textMeasure.clipTextWithSuffixVertical(verticalList[0], {
264
- fontSize: fontSize,
265
- fontWeight: fontWeight,
266
- fontFamily: fontFamily
267
- }, maxLineWidth, strEllipsis, !1, suffixPosition);
268
- verticalList = [ data.verticalList ], width = data.width;
269
- } else {
270
- const data = textMeasure.clipTextVertical(verticalList[0], {
271
- fontSize: fontSize,
272
- fontWeight: fontWeight,
273
- fontFamily: fontFamily
274
- }, maxLineWidth, !1);
275
- verticalList = [ data.verticalList ], width = data.width;
276
- }
277
- this.cache.verticalList = verticalList, this.cache.clipedWidth = width;
278
- } else width = 0, verticalList[0].forEach((t => {
279
- const w = t.direction === tools_1.TextDirection.HORIZONTAL ? fontSize : textMeasure.measureTextWidth(t.text, {
280
- fontSize: fontSize,
281
- fontWeight: fontWeight,
282
- fontFamily: fontFamily
283
- });
284
- width += w, t.width = w;
285
- })), this.cache.verticalList = verticalList, this.cache.clipedWidth = width;
286
- this.clearUpdateShapeTag();
287
- const dx = (0, text_1.textDrawOffsetX)(textAlign, width), dy = (0, text_1.textLayoutOffsetY)(textBaseline, lineHeight, fontSize);
288
- return this._AABBBounds.set(dy, dx, dy + lineHeight, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2),
289
- this._AABBBounds;
290
- }
291
- updateHorizontalMultilineAABBBounds(text) {
292
- var _a, _b;
293
- const textTheme = this.getGraphicTheme(), {wrap: wrap = textTheme.wrap} = this.attribute;
294
- if (wrap) return this.updateWrapAABBBounds(text);
295
- const attribute = this.attribute, {fontFamily: fontFamily = textTheme.fontFamily, textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline, fontSize: fontSize = textTheme.fontSize, fontWeight: fontWeight = textTheme.fontWeight, ellipsis: ellipsis = textTheme.ellipsis, maxLineWidth: maxLineWidth, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, whiteSpace: whiteSpace = textTheme.whiteSpace, suffixPosition: suffixPosition = textTheme.suffixPosition} = attribute, lineHeight = null !== (_a = (0,
296
- utils_1.calculateLineHeight)(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : attribute.fontSize || textTheme.fontSize;
297
- if ("normal" === whiteSpace) return this.updateWrapAABBBounds(text);
298
- if (!this.shouldUpdateShape() && (null === (_b = this.cache) || void 0 === _b ? void 0 : _b.layoutData)) {
299
- const bbox = this.cache.layoutData.bbox;
300
- return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height),
301
- stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
302
- }
303
- const textMeasure = application_1.application.graphicUtil.textMeasure, layoutData = new layout_1.CanvasTextLayout(fontFamily, {
304
- fontSize: fontSize,
305
- fontWeight: fontWeight,
306
- fontFamily: fontFamily
307
- }, textMeasure).GetLayoutByLines(text, textAlign, textBaseline, lineHeight, !0 === ellipsis ? textTheme.ellipsis : ellipsis || void 0, !1, maxLineWidth, suffixPosition), {bbox: bbox} = layoutData;
308
- return this.cache.layoutData = layoutData, this.clearUpdateShapeTag(), this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height),
309
- stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
310
- }
311
226
  updateVerticalMultilineAABBBounds(text) {
312
- var _a, _b, _c;
227
+ var _a, _b;
313
228
  const textTheme = this.getGraphicTheme(), textMeasure = application_1.application.graphicUtil.textMeasure;
314
229
  let width;
315
- const attribute = this.attribute, {ignoreBuf: ignoreBuf = textTheme.ignoreBuf} = attribute, buf = ignoreBuf ? 0 : 2, {maxLineWidth: maxLineWidth = textTheme.maxLineWidth, ellipsis: ellipsis = textTheme.ellipsis, fontFamily: fontFamily = textTheme.fontFamily, fontSize: fontSize = textTheme.fontSize, fontWeight: fontWeight = textTheme.fontWeight, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, verticalMode: verticalMode = textTheme.verticalMode, suffixPosition: suffixPosition = textTheme.suffixPosition} = attribute, lineHeight = null !== (_a = (0,
316
- utils_1.calculateLineHeight)(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
230
+ const attribute = this.attribute, {maxLineWidth: maxLineWidth = textTheme.maxLineWidth, ellipsis: ellipsis = textTheme.ellipsis, fontFamily: fontFamily = textTheme.fontFamily, fontSize: fontSize = textTheme.fontSize, fontWeight: fontWeight = textTheme.fontWeight, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, verticalMode: verticalMode = textTheme.verticalMode, suffixPosition: suffixPosition = textTheme.suffixPosition} = attribute, lineHeight = this.getLineHeight(attribute, textTheme);
317
231
  let {textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline} = attribute;
318
232
  if (!verticalMode) {
319
233
  const t = textAlign;
320
- textAlign = null !== (_b = Text.baselineMapAlign[textBaseline]) && void 0 !== _b ? _b : "left",
321
- textBaseline = null !== (_c = Text.alignMapBaseline[t]) && void 0 !== _c ? _c : "top";
234
+ textAlign = null !== (_a = Text.baselineMapAlign[textBaseline]) && void 0 !== _a ? _a : "left",
235
+ textBaseline = null !== (_b = Text.alignMapBaseline[t]) && void 0 !== _b ? _b : "top";
322
236
  }
323
237
  if (width = 0, !this.shouldUpdateShape() && this.cache) {
324
238
  this.cache.verticalList.forEach((item => {
@@ -363,6 +277,15 @@ class Text extends graphic_1.Graphic {
363
277
  return this._AABBBounds.set(dy, dx, dy + height, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2),
364
278
  this._AABBBounds;
365
279
  }
280
+ getMaxWidth(theme) {
281
+ var _a, _b;
282
+ const attribute = this.attribute;
283
+ return null !== (_b = null !== (_a = attribute.maxLineWidth) && void 0 !== _a ? _a : attribute.maxWidth) && void 0 !== _b ? _b : theme.maxWidth;
284
+ }
285
+ getLineHeight(attribute, textTheme) {
286
+ var _a;
287
+ return null !== (_a = (0, utils_1.calculateLineHeight)(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : attribute.fontSize || textTheme.fontSize;
288
+ }
366
289
  needUpdateTags(keys, k = TEXT_UPDATE_TAG_KEY) {
367
290
  return super.needUpdateTags(keys, k);
368
291
  }
@@ -375,6 +298,12 @@ class Text extends graphic_1.Graphic {
375
298
  getNoWorkAnimateAttr() {
376
299
  return Text.NOWORK_ANIMATE_ATTR;
377
300
  }
301
+ getBaselineMapAlign() {
302
+ return Text.baselineMapAlign;
303
+ }
304
+ getAlignMapBaseline() {
305
+ return Text.alignMapBaseline;
306
+ }
378
307
  }
379
308
 
380
309
  function createText(attributes) {