@visactor/vrender-core 0.16.14-alpha.4 → 0.16.14-alpha.5
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.
- package/cjs/common/utils.d.ts +1 -0
- package/cjs/common/utils.js +10 -1
- package/cjs/common/utils.js.map +1 -1
- package/cjs/core/stage.d.ts +1 -0
- package/cjs/core/stage.js +7 -3
- package/cjs/core/stage.js.map +1 -1
- package/cjs/graphic/config.js +4 -1
- package/cjs/graphic/config.js.map +1 -1
- package/cjs/graphic/richtext/paragraph.js +12 -11
- package/cjs/graphic/richtext/paragraph.js.map +1 -1
- package/cjs/graphic/text.d.ts +1 -0
- package/cjs/graphic/text.js +93 -7
- package/cjs/graphic/text.js.map +1 -1
- package/cjs/graphic/wrap-text.js +6 -5
- package/cjs/graphic/wrap-text.js.map +1 -1
- package/cjs/interface/graphic/richText.d.ts +1 -1
- package/cjs/interface/graphic/richText.js.map +1 -1
- package/cjs/interface/graphic/text.d.ts +4 -1
- package/cjs/interface/graphic/text.js.map +1 -1
- package/cjs/render/contributions/render/text-render.js +2 -2
- package/cjs/render/contributions/render/text-render.js.map +1 -1
- package/dist/index.js +165 -17
- package/dist/index.min.js +1 -1
- package/es/common/utils.d.ts +1 -0
- package/es/common/utils.js +8 -1
- package/es/common/utils.js.map +1 -1
- package/es/core/stage.d.ts +1 -0
- package/es/core/stage.js +7 -3
- package/es/core/stage.js.map +1 -1
- package/es/graphic/config.js +4 -1
- package/es/graphic/config.js.map +1 -1
- package/es/graphic/richtext/paragraph.js +5 -2
- package/es/graphic/richtext/paragraph.js.map +1 -1
- package/es/graphic/text.d.ts +1 -0
- package/es/graphic/text.js +90 -9
- package/es/graphic/text.js.map +1 -1
- package/es/graphic/wrap-text.js +6 -4
- package/es/graphic/wrap-text.js.map +1 -1
- package/es/interface/graphic/richText.d.ts +1 -1
- package/es/interface/graphic/richText.js.map +1 -1
- package/es/interface/graphic/text.d.ts +4 -1
- package/es/interface/graphic/text.js.map +1 -1
- package/es/render/contributions/render/text-render.js +3 -1
- package/es/render/contributions/render/text-render.js.map +1 -1
- package/package.json +2 -2
|
@@ -36,7 +36,7 @@ export type ITextAttribute = {
|
|
|
36
36
|
ellipsis: boolean | string;
|
|
37
37
|
fontVariant: string;
|
|
38
38
|
fontStyle: string;
|
|
39
|
-
lineHeight: number;
|
|
39
|
+
lineHeight: number | string;
|
|
40
40
|
underline: number;
|
|
41
41
|
lineThrough: number;
|
|
42
42
|
scaleIn3d: boolean;
|
|
@@ -44,6 +44,9 @@ export type ITextAttribute = {
|
|
|
44
44
|
verticalMode: number;
|
|
45
45
|
wordBreak: 'break-word' | 'break-all';
|
|
46
46
|
ignoreBuf: boolean;
|
|
47
|
+
whiteSpace: 'normal' | 'no-wrap';
|
|
48
|
+
heightLimit?: number;
|
|
49
|
+
lineClamp?: number;
|
|
47
50
|
};
|
|
48
51
|
export type ITextCache = {
|
|
49
52
|
clipedText?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/graphic/text.ts"],"names":[],"mappings":"","file":"text.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport type { IGraphicAttribute, IGraphic } from '../graphic';\n\nexport interface TextLayoutBBox {\n width: number; // 包围盒的宽度\n height: number; // 包围盒的高度\n xOffset: number;\n yOffset: number;\n}\n\nexport interface LayoutItemType {\n str: string; // 这行的字符串\n leftOffset?: number; // 该行距离左侧的偏移\n topOffset?: number; // 该行距离右侧的偏移\n width: number;\n}\n\nexport interface SimplifyLayoutType {\n lines: LayoutItemType[];\n}\n\nexport interface LayoutType {\n bbox: TextLayoutBBox;\n lines: LayoutItemType[];\n fontFamily: string;\n fontSize: number;\n fontWeight?: string | number;\n lineHeight: number;\n textAlign: TextAlignType;\n textBaseline: TextBaselineType;\n}\n\nexport type ITextAttribute = {\n text: string | number | string[] | number[];\n maxLineWidth: number;\n textAlign: TextAlignType;\n textBaseline: TextBaselineType;\n fontSize: number;\n fontFamily: string;\n fontWeight: string | number;\n ellipsis: boolean | string;\n fontVariant: string;\n fontStyle: string;\n lineHeight: number;\n underline: number;\n lineThrough: number;\n scaleIn3d: boolean;\n direction: 'horizontal' | 'vertical';\n verticalMode: number; // 垂直布局的模式,0代表默认(横向textAlign,纵向textBaseline),1代表特殊(横向textBaseline,纵向textAlign)\n wordBreak: 'break-word' | 'break-all';\n ignoreBuf: boolean;\n // textDecoration: number;\n // textDecorationWidth: number;\n // padding?: number | number[];\n};\nexport type ITextCache = {\n // 单行文本的时候缓存用\n clipedText?: string;\n clipedWidth?: number;\n // 多行文本的布局缓存\n layoutData?: LayoutType;\n verticalList?: { text: string; width?: number; direction: number }[][];\n};\n\nexport type ITextGraphicAttribute = Partial<IGraphicAttribute> & Partial<ITextAttribute>;\n\nexport type IWrapTextGraphicAttribute = ITextGraphicAttribute & {\n heightLimit?: number;\n lineClamp?: number;\n};\n\nexport interface IText extends IGraphic<ITextGraphicAttribute> {\n // 判断是否被ellipisised\n clipedText?: string;\n clipedWidth?: number;\n cliped?: boolean;\n multilineLayout?: LayoutType;\n font?: string;\n cache?: ITextCache;\n\n getBaselineMapAlign: () => Record<string, string>;\n getAlignMapBaseline: () => Record<string, string>;\n\n updateMultilineAABBBounds: (text: (number | string)[]) => IAABBBounds;\n updateSingallineAABBBounds: (text: number | string) => IAABBBounds;\n}\n\nexport type TextAlignType = 'left' | 'right' | 'center' | 'start' | 'end';\nexport type TextBaselineType = 'top' | 'middle' | 'bottom' | 'alphabetic';\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/interface/graphic/text.ts"],"names":[],"mappings":"","file":"text.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport type { IGraphicAttribute, IGraphic } from '../graphic';\n\nexport interface TextLayoutBBox {\n width: number; // 包围盒的宽度\n height: number; // 包围盒的高度\n xOffset: number;\n yOffset: number;\n}\n\nexport interface LayoutItemType {\n str: string; // 这行的字符串\n leftOffset?: number; // 该行距离左侧的偏移\n topOffset?: number; // 该行距离右侧的偏移\n width: number;\n}\n\nexport interface SimplifyLayoutType {\n lines: LayoutItemType[];\n}\n\nexport interface LayoutType {\n bbox: TextLayoutBBox;\n lines: LayoutItemType[];\n fontFamily: string;\n fontSize: number;\n fontWeight?: string | number;\n lineHeight: number;\n textAlign: TextAlignType;\n textBaseline: TextBaselineType;\n}\n\nexport type ITextAttribute = {\n text: string | number | string[] | number[];\n maxLineWidth: number;\n textAlign: TextAlignType;\n textBaseline: TextBaselineType;\n fontSize: number;\n fontFamily: string;\n fontWeight: string | number;\n ellipsis: boolean | string;\n fontVariant: string;\n fontStyle: string;\n lineHeight: number | string;\n underline: number;\n lineThrough: number;\n scaleIn3d: boolean;\n direction: 'horizontal' | 'vertical';\n verticalMode: number; // 垂直布局的模式,0代表默认(横向textAlign,纵向textBaseline),1代表特殊(横向textBaseline,纵向textAlign)\n wordBreak: 'break-word' | 'break-all';\n ignoreBuf: boolean;\n whiteSpace: 'normal' | 'no-wrap';\n heightLimit?: number;\n lineClamp?: number;\n // textDecoration: number;\n // textDecorationWidth: number;\n // padding?: number | number[];\n};\nexport type ITextCache = {\n // 单行文本的时候缓存用\n clipedText?: string;\n clipedWidth?: number;\n // 多行文本的布局缓存\n layoutData?: LayoutType;\n verticalList?: { text: string; width?: number; direction: number }[][];\n};\n\nexport type ITextGraphicAttribute = Partial<IGraphicAttribute> & Partial<ITextAttribute>;\n\nexport type IWrapTextGraphicAttribute = ITextGraphicAttribute & {\n heightLimit?: number;\n lineClamp?: number;\n};\n\nexport interface IText extends IGraphic<ITextGraphicAttribute> {\n // 判断是否被ellipisised\n clipedText?: string;\n clipedWidth?: number;\n cliped?: boolean;\n multilineLayout?: LayoutType;\n font?: string;\n cache?: ITextCache;\n\n getBaselineMapAlign: () => Record<string, string>;\n getAlignMapBaseline: () => Record<string, string>;\n\n updateMultilineAABBBounds: (text: (number | string)[]) => IAABBBounds;\n updateSingallineAABBBounds: (text: number | string) => IAABBBounds;\n}\n\nexport type TextAlignType = 'left' | 'right' | 'center' | 'start' | 'end';\nexport type TextBaselineType = 'top' | 'middle' | 'bottom' | 'alphabetic';\n"]}
|
|
@@ -16,7 +16,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
16
16
|
value: !0
|
|
17
17
|
}), exports.DefaultCanvasTextRender = void 0;
|
|
18
18
|
|
|
19
|
-
const inversify_lite_1 = require("../../../common/inversify-lite"), theme_1 = require("../../../graphic/theme"), constants_1 = require("../../../graphic/constants"), text_1 = require("../../../common/text"), base_render_1 = require("./base-render"), contribution_provider_1 = require("../../../common/contribution-provider"), constants_2 = require("./contributions/constants"), matrix_allocate_1 = require("../../../allocator/matrix-allocate"), vutils_1 = require("@visactor/vutils");
|
|
19
|
+
const inversify_lite_1 = require("../../../common/inversify-lite"), theme_1 = require("../../../graphic/theme"), constants_1 = require("../../../graphic/constants"), text_1 = require("../../../common/text"), base_render_1 = require("./base-render"), contribution_provider_1 = require("../../../common/contribution-provider"), constants_2 = require("./contributions/constants"), matrix_allocate_1 = require("../../../allocator/matrix-allocate"), vutils_1 = require("@visactor/vutils"), utils_1 = require("../../../common/utils");
|
|
20
20
|
|
|
21
21
|
let DefaultCanvasTextRender = class extends base_render_1.BaseRender {
|
|
22
22
|
constructor(textRenderContribitions) {
|
|
@@ -32,7 +32,7 @@ let DefaultCanvasTextRender = class extends base_render_1.BaseRender {
|
|
|
32
32
|
textAlign = null !== (_a = text.getBaselineMapAlign()[textBaseline]) && void 0 !== _a ? _a : "left",
|
|
33
33
|
textBaseline = null !== (_b = text.getAlignMapBaseline()[t]) && void 0 !== _b ? _b : "top";
|
|
34
34
|
}
|
|
35
|
-
const lineHeight = null !== (_c = text.attribute.lineHeight) && void 0 !== _c ? _c : fontSize, data = this.valid(text, textAttribute, fillCb, strokeCb);
|
|
35
|
+
const lineHeight = null !== (_c = (0, utils_1.calculateLineHeight)(text.attribute.lineHeight, fontSize)) && void 0 !== _c ? _c : fontSize, data = this.valid(text, textAttribute, fillCb, strokeCb);
|
|
36
36
|
if (!data) return;
|
|
37
37
|
const {fVisible: fVisible, sVisible: sVisible, doFill: doFill, doStroke: doStroke} = data, transform3dMatrixToContextMatrix = !keepDirIn3d, z = this.z || 0;
|
|
38
38
|
context.beginPath(), context.setShadowBlendStyle && context.setShadowBlendStyle(text, text.attribute, textAttribute),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/render/contributions/render/text-render.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAA2E;AAC3E,kDAAkD;AAClD,0DAA8D;AAa9D,+CAA0E;AAG1E,+CAA2C;AAC3C,iFAA6E;AAC7E,yDAAmE;AAEnE,wEAAoE;AACpE,6CAAuC;AAGhC,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,SAAQ,wBAAiB;IAI5D,YAGqB,uBAAuE;QAE1F,KAAK,EAAE,CAAC;QAFW,4BAAuB,GAAvB,uBAAuB,CAAgD;QAL5F,eAAU,GAAW,4BAAgB,CAAC;QAQpC,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IACrC,CAAC;IAED,SAAS,CACP,IAAW,EACX,OAAmB,EACnB,CAAS,EACT,CAAS,EACT,WAAyB,EACzB,MAAiC,EACjC,MAIY,EACZ,QAIY;;QAEZ,MAAM,aAAa,GAAG,IAAA,gBAAQ,EAAC,IAAI,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CAAC,CAAC,IAAI,CAAC;QACzD,MAAM,EACJ,IAAI,EAAE,GAAG,EACT,IAAI,GAAG,aAAa,CAAC,IAAI,EACzB,MAAM,GAAG,aAAa,CAAC,MAAM,EAC7B,WAAW,GAAG,aAAa,CAAC,WAAW,EACvC,aAAa,GAAG,aAAa,CAAC,aAAa,EAC3C,OAAO,GAAG,aAAa,CAAC,OAAO,EAC/B,SAAS,GAAG,aAAa,CAAC,SAAS,EACnC,OAAO,GAAG,aAAa,CAAC,OAAO,EAC/B,SAAS,GAAG,aAAa,CAAC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AAM,CAAC,CAAC,GAAG,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;YACnC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;YACvC,OAAO,CAAC,MAAM,EAAE,CAAC;SAClB;QACD,MAAM,GAAG,CAAC,CAAC,CAAC;QACZ,IAAI,WAAW,EAAE;YACf,SAAS,CAAC,SAAS,GAAG,WAAW,CAAC;YAClC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC;YAC7D,OAAO,CAAC,SAAS,EAAE,CAAC;YACpB,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,QAAQ,GAAG,CAAC,GAAG,MAAM,CAAC;YAC/C,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;YACnC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;YACvC,OAAO,CAAC,MAAM,EAAE,CAAC;SAClB;IACH,CAAC;CACF,CAAA;AAxXY,uBAAuB;IADnC,IAAA,2BAAU,GAAE;IAMR,WAAA,IAAA,uBAAM,EAAC,4CAAoB,CAAC,CAAA;IAC5B,WAAA,IAAA,sBAAK,EAAC,kCAAsB,CAAC,CAAA;;GANrB,uBAAuB,CAwXnC;AAxXY,0DAAuB","file":"text-render.js","sourcesContent":["import { inject, injectable, named } from '../../../common/inversify-lite';\nimport { getTheme } from '../../../graphic/theme';\nimport { TEXT_NUMBER_TYPE } from '../../../graphic/constants';\nimport type {\n IGraphicAttribute,\n IContext2d,\n IMarkAttribute,\n IThemeAttribute,\n IDrawContext,\n IRenderService,\n IGraphicRender,\n IGraphicRenderDrawParams,\n ITextRenderContribution,\n IContributionProvider\n} from '../../../interface';\nimport { textDrawOffsetX, textLayoutOffsetY } from '../../../common/text';\nimport type { IText, ITextGraphicAttribute } from '../../../interface/graphic/text';\nimport { fillVisible, runFill, runStroke, strokeVisible } from './utils';\nimport { BaseRender } from './base-render';\nimport { ContributionProvider } from '../../../common/contribution-provider';\nimport { TextRenderContribution } from './contributions/constants';\nimport { BaseRenderContributionTime } from '../../../common/enums';\nimport { matrixAllocate } from '../../../allocator/matrix-allocate';\nimport { max } from '@visactor/vutils';\n\n@injectable()\nexport class DefaultCanvasTextRender extends BaseRender<IText> implements IGraphicRender {\n type: 'text';\n numberType: number = TEXT_NUMBER_TYPE;\n\n constructor(\n @inject(ContributionProvider)\n @named(TextRenderContribution)\n protected readonly textRenderContribitions: IContributionProvider<ITextRenderContribution>\n ) {\n super();\n this.init(textRenderContribitions);\n }\n\n drawShape(\n text: IText,\n context: IContext2d,\n x: number,\n y: number,\n drawContext: IDrawContext,\n params?: IGraphicRenderDrawParams,\n fillCb?: (\n ctx: IContext2d,\n markAttribute: Partial<IMarkAttribute & IGraphicAttribute>,\n themeAttribute: IThemeAttribute\n ) => boolean,\n strokeCb?: (\n ctx: IContext2d,\n markAttribute: Partial<IMarkAttribute & IGraphicAttribute>,\n themeAttribute: IThemeAttribute\n ) => boolean\n ) {\n const textAttribute = getTheme(text, params?.theme).text;\n const {\n text: str,\n fill = textAttribute.fill,\n stroke = textAttribute.stroke,\n fillOpacity = textAttribute.fillOpacity,\n strokeOpacity = textAttribute.strokeOpacity,\n opacity = textAttribute.opacity,\n lineWidth = textAttribute.lineWidth,\n visible = textAttribute.visible,\n underline = textAttribute.underline,\n lineThrough = textAttribute.lineThrough,\n keepDirIn3d = textAttribute.keepDirIn3d,\n direction = textAttribute.direction,\n // lineHeight = textAttribute.lineHeight,\n fontSize = textAttribute.fontSize,\n verticalMode = textAttribute.verticalMode,\n x: originX = textAttribute.x,\n y: originY = textAttribute.y\n } = text.attribute;\n\n let { textAlign = textAttribute.textAlign, textBaseline = textAttribute.textBaseline } = text.attribute;\n if (!verticalMode && direction === 'vertical') {\n const t = textAlign;\n textAlign = text.getBaselineMapAlign()[textBaseline] ?? ('left' as any);\n textBaseline = text.getAlignMapBaseline()[t] ?? ('top' as any);\n }\n const lineHeight = text.attribute.lineHeight ?? fontSize;\n\n const data = this.valid(text, textAttribute, fillCb, strokeCb);\n if (!data) {\n return;\n }\n const { fVisible, sVisible, doFill, doStroke } = data;\n\n // 文字如果需要变换,那就需要将3dmatrix转成context的2dmatrix\n const transform3dMatrixToContextMatrix = !keepDirIn3d;\n\n const z = this.z || 0;\n\n context.beginPath();\n\n // shadow\n context.setShadowBlendStyle && context.setShadowBlendStyle(text, text.attribute, textAttribute);\n\n this.beforeRenderStep(\n text,\n context,\n x,\n y,\n doFill,\n doStroke,\n fVisible,\n sVisible,\n textAttribute,\n drawContext,\n fillCb,\n strokeCb\n );\n\n transform3dMatrixToContextMatrix && this.transformUseContext2d(text, textAttribute, z, context);\n\n const drawText = (t: string, offsetX: number, offsetY: number, direction: number) => {\n let _x = x + offsetX;\n const _y = y + offsetY;\n if (direction) {\n context.highPerformanceSave();\n _x += fontSize;\n const matrix = matrixAllocate.allocate(1, 0, 0, 1, 0, 0);\n // matrix.translate(fontSize, 0);\n matrix.rotateByCenter(Math.PI / 2, _x, _y);\n context.transformFromMatrix(matrix, true);\n matrixAllocate.free(matrix);\n }\n\n if (doStroke) {\n if (strokeCb) {\n strokeCb(context, text.attribute, textAttribute);\n } else if (sVisible) {\n context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute);\n context.strokeText(t, _x, _y, z);\n }\n }\n if (doFill) {\n if (fillCb) {\n fillCb(context, text.attribute, textAttribute);\n } else if (fVisible) {\n context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute);\n context.fillText(t, _x, _y, z);\n this.drawUnderLine(underline, lineThrough, text, _x, _y, z, textAttribute, context);\n }\n }\n\n if (direction) {\n context.highPerformanceRestore();\n context.setTransformForCurrent();\n }\n };\n if (Array.isArray(str)) {\n context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z);\n if (direction === 'horizontal') {\n const { multilineLayout } = text;\n if (!multilineLayout) {\n context.highPerformanceRestore();\n return;\n } // 如果不存在的话,需要render层自行布局\n const { xOffset, yOffset } = multilineLayout.bbox;\n if (doStroke) {\n if (strokeCb) {\n strokeCb(context, text.attribute, textAttribute);\n } else if (sVisible) {\n context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute);\n multilineLayout.lines.forEach(line => {\n context.strokeText(\n line.str,\n (line.leftOffset || 0) + xOffset + x,\n (line.topOffset || 0) + yOffset + y,\n z\n );\n });\n }\n }\n if (doFill) {\n if (fillCb) {\n fillCb(context, text.attribute, textAttribute);\n } else if (fVisible) {\n context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute);\n multilineLayout.lines.forEach(line => {\n context.fillText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z);\n this.drawMultiUnderLine(\n underline,\n lineThrough,\n text,\n (line.leftOffset || 0) + x, // 中下划线都是从文字左侧开始,因此不需要+xOffset\n (line.topOffset || 0) + yOffset + y,\n z,\n line.width,\n textAttribute,\n context\n );\n });\n }\n }\n } else {\n const cache = text.cache;\n const { verticalList } = cache;\n context.textAlign = 'left';\n context.textBaseline = 'top';\n const totalHeight = lineHeight * verticalList.length;\n let totalW = 0;\n verticalList.forEach(verticalData => {\n const _w = verticalData.reduce((a, b) => a + (b.width || 0), 0);\n totalW = max(_w, totalW);\n });\n let offsetY = 0;\n let offsetX = 0;\n if (textBaseline === 'bottom') {\n offsetX = -totalHeight;\n } else if (textBaseline === 'middle') {\n offsetX = -totalHeight / 2;\n }\n if (textAlign === 'center') {\n offsetY -= totalW / 2;\n } else if (textAlign === 'right') {\n offsetY -= totalW;\n }\n verticalList.forEach((verticalData, i) => {\n const currentW = verticalData.reduce((a, b) => a + (b.width || 0), 0);\n const dw = totalW - currentW;\n let currentOffsetY = offsetY;\n if (textAlign === 'center') {\n currentOffsetY += dw / 2;\n } else if (textAlign === 'right') {\n currentOffsetY += dw;\n }\n verticalData.forEach(item => {\n const { text, width, direction } = item;\n drawText(text, totalHeight - (i + 1) * lineHeight + offsetX, currentOffsetY, direction);\n currentOffsetY += width;\n });\n });\n }\n } else {\n const cache = text.cache;\n if (direction === 'horizontal') {\n context.setTextStyle(text.attribute, textAttribute, z);\n const t = text.clipedText as string;\n let dy = 0;\n if (lineHeight !== fontSize) {\n if (textBaseline === 'top') {\n dy = (lineHeight - fontSize) / 2;\n } else if (textBaseline === 'middle') {\n // middle do nothing\n } else if (textBaseline === 'bottom') {\n dy = -(lineHeight - fontSize) / 2;\n } else {\n // alphabetic do nothing\n // dy = (lineHeight - fontSize) / 2 - fontSize * 0.79;\n }\n }\n drawText(t, 0, dy, 0);\n } else if (cache) {\n context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z);\n const { verticalList } = cache;\n let offsetY = 0;\n const totalW = verticalList[0].reduce((a, b) => a + (b.width || 0), 0);\n let offsetX = 0;\n if (textBaseline === 'bottom') {\n offsetX = -lineHeight;\n } else if (textBaseline === 'middle') {\n offsetX = -lineHeight / 2;\n }\n if (textAlign === 'center') {\n offsetY -= totalW / 2;\n } else if (textAlign === 'right') {\n offsetY -= totalW;\n }\n context.textAlign = 'left';\n context.textBaseline = 'top';\n verticalList[0].forEach(item => {\n const { text, width, direction } = item;\n drawText(text, offsetX, offsetY, direction);\n offsetY += width;\n });\n }\n }\n transform3dMatrixToContextMatrix && this.restoreTransformUseContext2d(text, textAttribute, z, context);\n\n this.afterRenderStep(\n text,\n context,\n x,\n y,\n doFill,\n doStroke,\n fVisible,\n sVisible,\n textAttribute,\n drawContext,\n fillCb,\n strokeCb\n );\n }\n\n draw(text: IText, renderService: IRenderService, drawContext: IDrawContext, params?: IGraphicRenderDrawParams) {\n const textAttribute = getTheme(text, params?.theme).text;\n const { keepDirIn3d = textAttribute.keepDirIn3d } = text.attribute;\n // 文字如果需要变换,那就一定要计算3d矩阵\n const computed3dMatrix = !keepDirIn3d;\n this._draw(text, textAttribute, computed3dMatrix, drawContext, params);\n }\n\n drawUnderLine(\n underline: number,\n lineThrough: number,\n text: IText,\n x: number,\n y: number,\n z: number,\n textAttribute: Required<ITextGraphicAttribute>,\n context: IContext2d\n ) {\n if (lineThrough + underline <= 0) {\n return;\n }\n\n const {\n textAlign = textAttribute.textAlign,\n textBaseline = textAttribute.textBaseline,\n fontSize = textAttribute.fontSize,\n fill = textAttribute.fill,\n opacity = textAttribute.opacity,\n fillOpacity = textAttribute.fillOpacity\n } = text.attribute;\n const w = text.clipedWidth;\n const offsetX = textDrawOffsetX(textAlign, w);\n const offsetY = textLayoutOffsetY(textBaseline, fontSize, fontSize);\n const attribute = { lineWidth: 0, stroke: fill, opacity, strokeOpacity: fillOpacity };\n if (underline) {\n attribute.lineWidth = underline;\n context.setStrokeStyle(text, attribute, x, y, textAttribute);\n context.beginPath();\n const dy = y + offsetY + fontSize;\n context.moveTo(x + offsetX, dy, z);\n context.lineTo(x + offsetX + w, dy, z);\n context.stroke();\n }\n if (lineThrough) {\n attribute.lineWidth = lineThrough;\n context.setStrokeStyle(text, attribute, x, y, textAttribute);\n context.beginPath();\n const dy = y + offsetY + fontSize / 2;\n context.moveTo(x + offsetX, dy, z);\n context.lineTo(x + offsetX + w, dy, z);\n context.stroke();\n }\n }\n\n drawMultiUnderLine(\n underline: number,\n lineThrough: number,\n text: IText,\n x: number,\n y: number,\n z: number,\n w: number,\n textAttribute: Required<ITextGraphicAttribute>,\n context: IContext2d\n ) {\n if (lineThrough + underline <= 0) {\n return;\n }\n\n const {\n textAlign = textAttribute.textAlign,\n fontSize = textAttribute.fontSize,\n fill = textAttribute.fill,\n opacity = textAttribute.opacity,\n fillOpacity = textAttribute.fillOpacity\n } = text.attribute;\n\n const offsetX = textDrawOffsetX(textAlign, w);\n const offsetY = textLayoutOffsetY('alphabetic', fontSize, fontSize);\n const attribute = { lineWidth: 0, stroke: fill, opacity, strokeOpacity: fillOpacity };\n let deltaY = -3;\n if (underline) {\n attribute.lineWidth = underline;\n context.setStrokeStyle(text, attribute, x, y, textAttribute);\n context.beginPath();\n const dy = y + offsetY + fontSize + deltaY;\n context.moveTo(x + offsetX, dy, z);\n context.lineTo(x + offsetX + w, dy, z);\n context.stroke();\n }\n deltaY = -1;\n if (lineThrough) {\n attribute.lineWidth = lineThrough;\n context.setStrokeStyle(text, attribute, x, y, textAttribute);\n context.beginPath();\n const dy = y + offsetY + fontSize / 2 + deltaY;\n context.moveTo(x + offsetX, dy, z);\n context.lineTo(x + offsetX + w, dy, z);\n context.stroke();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/render/contributions/render/text-render.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAA2E;AAC3E,kDAAkD;AAClD,0DAA8D;AAa9D,+CAA0E;AAE1E,+CAA2C;AAC3C,iFAA6E;AAC7E,yDAAmE;AACnE,wEAAoE;AACpE,6CAAuC;AACvC,iDAA4D;AAGrD,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,SAAQ,wBAAiB;IAI5D,YAGqB,uBAAuE;QAE1F,KAAK,EAAE,CAAC;QAFW,4BAAuB,GAAvB,uBAAuB,CAAgD;QAL5F,eAAU,GAAW,4BAAgB,CAAC;QAQpC,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IACrC,CAAC;IAED,SAAS,CACP,IAAW,EACX,OAAmB,EACnB,CAAS,EACT,CAAS,EACT,WAAyB,EACzB,MAAiC,EACjC,MAIY,EACZ,QAIY;;QAEZ,MAAM,aAAa,GAAG,IAAA,gBAAQ,EAAC,IAAI,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CAAC,CAAC,IAAI,CAAC;QACzD,MAAM,EACJ,IAAI,EAAE,GAAG,EACT,IAAI,GAAG,aAAa,CAAC,IAAI,EACzB,MAAM,GAAG,aAAa,CAAC,MAAM,EAC7B,WAAW,GAAG,aAAa,CAAC,WAAW,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CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC;YAC7D,OAAO,CAAC,SAAS,EAAE,CAAC;YACpB,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;YAC3C,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;YACnC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;YACvC,OAAO,CAAC,MAAM,EAAE,CAAC;SAClB;QACD,MAAM,GAAG,CAAC,CAAC,CAAC;QACZ,IAAI,WAAW,EAAE;YACf,SAAS,CAAC,SAAS,GAAG,WAAW,CAAC;YAClC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC;YAC7D,OAAO,CAAC,SAAS,EAAE,CAAC;YACpB,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,QAAQ,GAAG,CAAC,GAAG,MAAM,CAAC;YAC/C,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;YACnC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;YACvC,OAAO,CAAC,MAAM,EAAE,CAAC;SAClB;IACH,CAAC;CACF,CAAA;AAxXY,uBAAuB;IADnC,IAAA,2BAAU,GAAE;IAMR,WAAA,IAAA,uBAAM,EAAC,4CAAoB,CAAC,CAAA;IAC5B,WAAA,IAAA,sBAAK,EAAC,kCAAsB,CAAC,CAAA;;GANrB,uBAAuB,CAwXnC;AAxXY,0DAAuB","file":"text-render.js","sourcesContent":["import { inject, injectable, named } from '../../../common/inversify-lite';\nimport { getTheme } from '../../../graphic/theme';\nimport { TEXT_NUMBER_TYPE } from '../../../graphic/constants';\nimport type {\n IGraphicAttribute,\n IContext2d,\n IMarkAttribute,\n IThemeAttribute,\n IDrawContext,\n IRenderService,\n IGraphicRender,\n IGraphicRenderDrawParams,\n ITextRenderContribution,\n IContributionProvider\n} from '../../../interface';\nimport { textDrawOffsetX, textLayoutOffsetY } from '../../../common/text';\nimport type { IText, ITextGraphicAttribute } from '../../../interface/graphic/text';\nimport { BaseRender } from './base-render';\nimport { ContributionProvider } from '../../../common/contribution-provider';\nimport { TextRenderContribution } from './contributions/constants';\nimport { matrixAllocate } from '../../../allocator/matrix-allocate';\nimport { max } from '@visactor/vutils';\nimport { calculateLineHeight } from '../../../common/utils';\n\n@injectable()\nexport class DefaultCanvasTextRender extends BaseRender<IText> implements IGraphicRender {\n type: 'text';\n numberType: number = TEXT_NUMBER_TYPE;\n\n constructor(\n @inject(ContributionProvider)\n @named(TextRenderContribution)\n protected readonly textRenderContribitions: IContributionProvider<ITextRenderContribution>\n ) {\n super();\n this.init(textRenderContribitions);\n }\n\n drawShape(\n text: IText,\n context: IContext2d,\n x: number,\n y: number,\n drawContext: IDrawContext,\n params?: IGraphicRenderDrawParams,\n fillCb?: (\n ctx: IContext2d,\n markAttribute: Partial<IMarkAttribute & IGraphicAttribute>,\n themeAttribute: IThemeAttribute\n ) => boolean,\n strokeCb?: (\n ctx: IContext2d,\n markAttribute: Partial<IMarkAttribute & IGraphicAttribute>,\n themeAttribute: IThemeAttribute\n ) => boolean\n ) {\n const textAttribute = getTheme(text, params?.theme).text;\n const {\n text: str,\n fill = textAttribute.fill,\n stroke = textAttribute.stroke,\n fillOpacity = textAttribute.fillOpacity,\n strokeOpacity = textAttribute.strokeOpacity,\n opacity = textAttribute.opacity,\n lineWidth = textAttribute.lineWidth,\n visible = textAttribute.visible,\n underline = textAttribute.underline,\n lineThrough = textAttribute.lineThrough,\n keepDirIn3d = textAttribute.keepDirIn3d,\n direction = textAttribute.direction,\n // lineHeight = textAttribute.lineHeight,\n fontSize = textAttribute.fontSize,\n verticalMode = textAttribute.verticalMode,\n x: originX = textAttribute.x,\n y: originY = textAttribute.y\n } = text.attribute;\n\n let { textAlign = textAttribute.textAlign, textBaseline = textAttribute.textBaseline } = text.attribute;\n if (!verticalMode && direction === 'vertical') {\n const t = textAlign;\n textAlign = text.getBaselineMapAlign()[textBaseline] ?? ('left' as any);\n textBaseline = text.getAlignMapBaseline()[t] ?? ('top' as any);\n }\n const lineHeight = calculateLineHeight(text.attribute.lineHeight, fontSize) ?? fontSize;\n\n const data = this.valid(text, textAttribute, fillCb, strokeCb);\n if (!data) {\n return;\n }\n const { fVisible, sVisible, doFill, doStroke } = data;\n\n // 文字如果需要变换,那就需要将3dmatrix转成context的2dmatrix\n const transform3dMatrixToContextMatrix = !keepDirIn3d;\n\n const z = this.z || 0;\n\n context.beginPath();\n\n // shadow\n context.setShadowBlendStyle && context.setShadowBlendStyle(text, text.attribute, textAttribute);\n\n this.beforeRenderStep(\n text,\n context,\n x,\n y,\n doFill,\n doStroke,\n fVisible,\n sVisible,\n textAttribute,\n drawContext,\n fillCb,\n strokeCb\n );\n\n transform3dMatrixToContextMatrix && this.transformUseContext2d(text, textAttribute, z, context);\n\n const drawText = (t: string, offsetX: number, offsetY: number, direction: number) => {\n let _x = x + offsetX;\n const _y = y + offsetY;\n if (direction) {\n context.highPerformanceSave();\n _x += fontSize;\n const matrix = matrixAllocate.allocate(1, 0, 0, 1, 0, 0);\n // matrix.translate(fontSize, 0);\n matrix.rotateByCenter(Math.PI / 2, _x, _y);\n context.transformFromMatrix(matrix, true);\n matrixAllocate.free(matrix);\n }\n\n if (doStroke) {\n if (strokeCb) {\n strokeCb(context, text.attribute, textAttribute);\n } else if (sVisible) {\n context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute);\n context.strokeText(t, _x, _y, z);\n }\n }\n if (doFill) {\n if (fillCb) {\n fillCb(context, text.attribute, textAttribute);\n } else if (fVisible) {\n context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute);\n context.fillText(t, _x, _y, z);\n this.drawUnderLine(underline, lineThrough, text, _x, _y, z, textAttribute, context);\n }\n }\n\n if (direction) {\n context.highPerformanceRestore();\n context.setTransformForCurrent();\n }\n };\n if (Array.isArray(str)) {\n context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z);\n if (direction === 'horizontal') {\n const { multilineLayout } = text;\n if (!multilineLayout) {\n context.highPerformanceRestore();\n return;\n } // 如果不存在的话,需要render层自行布局\n const { xOffset, yOffset } = multilineLayout.bbox;\n if (doStroke) {\n if (strokeCb) {\n strokeCb(context, text.attribute, textAttribute);\n } else if (sVisible) {\n context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute);\n multilineLayout.lines.forEach(line => {\n context.strokeText(\n line.str,\n (line.leftOffset || 0) + xOffset + x,\n (line.topOffset || 0) + yOffset + y,\n z\n );\n });\n }\n }\n if (doFill) {\n if (fillCb) {\n fillCb(context, text.attribute, textAttribute);\n } else if (fVisible) {\n context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute);\n multilineLayout.lines.forEach(line => {\n context.fillText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z);\n this.drawMultiUnderLine(\n underline,\n lineThrough,\n text,\n (line.leftOffset || 0) + x, // 中下划线都是从文字左侧开始,因此不需要+xOffset\n (line.topOffset || 0) + yOffset + y,\n z,\n line.width,\n textAttribute,\n context\n );\n });\n }\n }\n } else {\n const cache = text.cache;\n const { verticalList } = cache;\n context.textAlign = 'left';\n context.textBaseline = 'top';\n const totalHeight = lineHeight * verticalList.length;\n let totalW = 0;\n verticalList.forEach(verticalData => {\n const _w = verticalData.reduce((a, b) => a + (b.width || 0), 0);\n totalW = max(_w, totalW);\n });\n let offsetY = 0;\n let offsetX = 0;\n if (textBaseline === 'bottom') {\n offsetX = -totalHeight;\n } else if (textBaseline === 'middle') {\n offsetX = -totalHeight / 2;\n }\n if (textAlign === 'center') {\n offsetY -= totalW / 2;\n } else if (textAlign === 'right') {\n offsetY -= totalW;\n }\n verticalList.forEach((verticalData, i) => {\n const currentW = verticalData.reduce((a, b) => a + (b.width || 0), 0);\n const dw = totalW - currentW;\n let currentOffsetY = offsetY;\n if (textAlign === 'center') {\n currentOffsetY += dw / 2;\n } else if (textAlign === 'right') {\n currentOffsetY += dw;\n }\n verticalData.forEach(item => {\n const { text, width, direction } = item;\n drawText(text, totalHeight - (i + 1) * lineHeight + offsetX, currentOffsetY, direction);\n currentOffsetY += width;\n });\n });\n }\n } else {\n const cache = text.cache;\n if (direction === 'horizontal') {\n context.setTextStyle(text.attribute, textAttribute, z);\n const t = text.clipedText as string;\n let dy = 0;\n if (lineHeight !== fontSize) {\n if (textBaseline === 'top') {\n dy = (lineHeight - fontSize) / 2;\n } else if (textBaseline === 'middle') {\n // middle do nothing\n } else if (textBaseline === 'bottom') {\n dy = -(lineHeight - fontSize) / 2;\n } else {\n // alphabetic do nothing\n // dy = (lineHeight - fontSize) / 2 - fontSize * 0.79;\n }\n }\n drawText(t, 0, dy, 0);\n } else if (cache) {\n context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z);\n const { verticalList } = cache;\n let offsetY = 0;\n const totalW = verticalList[0].reduce((a, b) => a + (b.width || 0), 0);\n let offsetX = 0;\n if (textBaseline === 'bottom') {\n offsetX = -lineHeight;\n } else if (textBaseline === 'middle') {\n offsetX = -lineHeight / 2;\n }\n if (textAlign === 'center') {\n offsetY -= totalW / 2;\n } else if (textAlign === 'right') {\n offsetY -= totalW;\n }\n context.textAlign = 'left';\n context.textBaseline = 'top';\n verticalList[0].forEach(item => {\n const { text, width, direction } = item;\n drawText(text, offsetX, offsetY, direction);\n offsetY += width;\n });\n }\n }\n transform3dMatrixToContextMatrix && this.restoreTransformUseContext2d(text, textAttribute, z, context);\n\n this.afterRenderStep(\n text,\n context,\n x,\n y,\n doFill,\n doStroke,\n fVisible,\n sVisible,\n textAttribute,\n drawContext,\n fillCb,\n strokeCb\n );\n }\n\n draw(text: IText, renderService: IRenderService, drawContext: IDrawContext, params?: IGraphicRenderDrawParams) {\n const textAttribute = getTheme(text, params?.theme).text;\n const { keepDirIn3d = textAttribute.keepDirIn3d } = text.attribute;\n // 文字如果需要变换,那就一定要计算3d矩阵\n const computed3dMatrix = !keepDirIn3d;\n this._draw(text, textAttribute, computed3dMatrix, drawContext, params);\n }\n\n drawUnderLine(\n underline: number,\n lineThrough: number,\n text: IText,\n x: number,\n y: number,\n z: number,\n textAttribute: Required<ITextGraphicAttribute>,\n context: IContext2d\n ) {\n if (lineThrough + underline <= 0) {\n return;\n }\n\n const {\n textAlign = textAttribute.textAlign,\n textBaseline = textAttribute.textBaseline,\n fontSize = textAttribute.fontSize,\n fill = textAttribute.fill,\n opacity = textAttribute.opacity,\n fillOpacity = textAttribute.fillOpacity\n } = text.attribute;\n const w = text.clipedWidth;\n const offsetX = textDrawOffsetX(textAlign, w);\n const offsetY = textLayoutOffsetY(textBaseline, fontSize, fontSize);\n const attribute = { lineWidth: 0, stroke: fill, opacity, strokeOpacity: fillOpacity };\n if (underline) {\n attribute.lineWidth = underline;\n context.setStrokeStyle(text, attribute, x, y, textAttribute);\n context.beginPath();\n const dy = y + offsetY + fontSize;\n context.moveTo(x + offsetX, dy, z);\n context.lineTo(x + offsetX + w, dy, z);\n context.stroke();\n }\n if (lineThrough) {\n attribute.lineWidth = lineThrough;\n context.setStrokeStyle(text, attribute, x, y, textAttribute);\n context.beginPath();\n const dy = y + offsetY + fontSize / 2;\n context.moveTo(x + offsetX, dy, z);\n context.lineTo(x + offsetX + w, dy, z);\n context.stroke();\n }\n }\n\n drawMultiUnderLine(\n underline: number,\n lineThrough: number,\n text: IText,\n x: number,\n y: number,\n z: number,\n w: number,\n textAttribute: Required<ITextGraphicAttribute>,\n context: IContext2d\n ) {\n if (lineThrough + underline <= 0) {\n return;\n }\n\n const {\n textAlign = textAttribute.textAlign,\n fontSize = textAttribute.fontSize,\n fill = textAttribute.fill,\n opacity = textAttribute.opacity,\n fillOpacity = textAttribute.fillOpacity\n } = text.attribute;\n\n const offsetX = textDrawOffsetX(textAlign, w);\n const offsetY = textLayoutOffsetY('alphabetic', fontSize, fontSize);\n const attribute = { lineWidth: 0, stroke: fill, opacity, strokeOpacity: fillOpacity };\n let deltaY = -3;\n if (underline) {\n attribute.lineWidth = underline;\n context.setStrokeStyle(text, attribute, x, y, textAttribute);\n context.beginPath();\n const dy = y + offsetY + fontSize + deltaY;\n context.moveTo(x + offsetX, dy, z);\n context.lineTo(x + offsetX + w, dy, z);\n context.stroke();\n }\n deltaY = -1;\n if (lineThrough) {\n attribute.lineWidth = lineThrough;\n context.setStrokeStyle(text, attribute, x, y, textAttribute);\n context.beginPath();\n const dy = y + offsetY + fontSize / 2 + deltaY;\n context.moveTo(x + offsetX, dy, z);\n context.lineTo(x + offsetX + w, dy, z);\n context.stroke();\n }\n }\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -4294,7 +4294,10 @@
|
|
|
4294
4294
|
direction: 'horizontal',
|
|
4295
4295
|
wordBreak: 'break-all',
|
|
4296
4296
|
ignoreBuf: false,
|
|
4297
|
-
verticalMode: 0
|
|
4297
|
+
verticalMode: 0,
|
|
4298
|
+
whiteSpace: 'no-wrap',
|
|
4299
|
+
heightLimit: Infinity,
|
|
4300
|
+
lineClamp: Infinity
|
|
4298
4301
|
};
|
|
4299
4302
|
const DefaultStyle = Object.assign(Object.assign(Object.assign({ opacity: 1, background: null, texture: null, textureColor: 'black', textureSize: 10, texturePadding: 2, backgroundMode: 0, blur: 0, cursor: null, html: null }, DefaultFillStyle), DefaultStrokeStyle), DefaultLayout);
|
|
4300
4303
|
const DefaultConnectAttribute = {
|
|
@@ -9013,6 +9016,13 @@
|
|
|
9013
9016
|
}
|
|
9014
9017
|
RafBasedSTO.TimeOut = 1000 / 60;
|
|
9015
9018
|
const rafBasedSto = new RafBasedSTO();
|
|
9019
|
+
const calculateLineHeight = (lineHeight, fontSize) => {
|
|
9020
|
+
if (vutils.isString(lineHeight) && lineHeight[lineHeight.length - 1] === '%') {
|
|
9021
|
+
const scale = Number.parseFloat(lineHeight.substring(0, lineHeight.length - 1)) / 100;
|
|
9022
|
+
return fontSize * scale;
|
|
9023
|
+
}
|
|
9024
|
+
return lineHeight;
|
|
9025
|
+
};
|
|
9016
9026
|
|
|
9017
9027
|
class IncreaseCount extends ACustomAnimate {
|
|
9018
9028
|
constructor(from, to, duration, easing, params) {
|
|
@@ -14314,6 +14324,8 @@
|
|
|
14314
14324
|
const TEXT_UPDATE_TAG_KEY = [
|
|
14315
14325
|
'text',
|
|
14316
14326
|
'maxLineWidth',
|
|
14327
|
+
'heightLimit',
|
|
14328
|
+
'lineClamp',
|
|
14317
14329
|
'fontSize',
|
|
14318
14330
|
'fontFamily',
|
|
14319
14331
|
'fontWeight',
|
|
@@ -14398,6 +14410,113 @@
|
|
|
14398
14410
|
this.clearUpdateBoundTag();
|
|
14399
14411
|
return bounds;
|
|
14400
14412
|
}
|
|
14413
|
+
updateWrapAABBBounds(text) {
|
|
14414
|
+
var _a, _b, _c, _d;
|
|
14415
|
+
const textTheme = getTheme(this).text;
|
|
14416
|
+
const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, fontWeight = textTheme.fontWeight, ignoreBuf = textTheme.ignoreBuf, heightLimit = 0, lineClamp } = this.attribute;
|
|
14417
|
+
const lineHeight = (_a = calculateLineHeight(this.attribute.lineHeight, this.attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (this.attribute.fontSize || textTheme.fontSize);
|
|
14418
|
+
const buf = ignoreBuf ? 0 : 2;
|
|
14419
|
+
if (!this.shouldUpdateShape() && ((_b = this.cache) === null || _b === void 0 ? void 0 : _b.layoutData)) {
|
|
14420
|
+
const bbox = this.cache.layoutData.bbox;
|
|
14421
|
+
this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
|
|
14422
|
+
if (stroke) {
|
|
14423
|
+
this._AABBBounds.expand(lineWidth / 2);
|
|
14424
|
+
}
|
|
14425
|
+
return this._AABBBounds;
|
|
14426
|
+
}
|
|
14427
|
+
const textMeasure = application.graphicUtil.textMeasure;
|
|
14428
|
+
const layoutObj = new CanvasTextLayout(fontFamily, { fontSize, fontWeight, fontFamily }, textMeasure);
|
|
14429
|
+
const lines = vutils.isArray(text) ? text.map(l => l.toString()) : [text.toString()];
|
|
14430
|
+
const linesLayout = [];
|
|
14431
|
+
const bboxWH = [0, 0];
|
|
14432
|
+
let lineCountLimit = Infinity;
|
|
14433
|
+
if (heightLimit > 0) {
|
|
14434
|
+
lineCountLimit = Math.max(Math.floor(heightLimit / lineHeight), 1);
|
|
14435
|
+
}
|
|
14436
|
+
if (lineClamp) {
|
|
14437
|
+
lineCountLimit = Math.min(lineCountLimit, lineClamp);
|
|
14438
|
+
}
|
|
14439
|
+
if (typeof maxLineWidth === 'number' && maxLineWidth !== Infinity) {
|
|
14440
|
+
if (maxLineWidth > 0) {
|
|
14441
|
+
for (let i = 0; i < lines.length; i++) {
|
|
14442
|
+
const str = lines[i];
|
|
14443
|
+
let needCut = true;
|
|
14444
|
+
if (i === lineCountLimit - 1) {
|
|
14445
|
+
const clip = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, false);
|
|
14446
|
+
linesLayout.push({
|
|
14447
|
+
str: clip.str,
|
|
14448
|
+
width: clip.width
|
|
14449
|
+
});
|
|
14450
|
+
break;
|
|
14451
|
+
}
|
|
14452
|
+
const clip = layoutObj.textMeasure.clipText(str, layoutObj.textOptions, maxLineWidth, wordBreak === 'break-word');
|
|
14453
|
+
if (str !== '' && clip.str === '') {
|
|
14454
|
+
if (ellipsis) {
|
|
14455
|
+
const clipEllipsis = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, false);
|
|
14456
|
+
clip.str = (_c = clipEllipsis.str) !== null && _c !== void 0 ? _c : '';
|
|
14457
|
+
clip.width = (_d = clipEllipsis.width) !== null && _d !== void 0 ? _d : 0;
|
|
14458
|
+
}
|
|
14459
|
+
else {
|
|
14460
|
+
clip.str = '';
|
|
14461
|
+
clip.width = 0;
|
|
14462
|
+
}
|
|
14463
|
+
needCut = false;
|
|
14464
|
+
}
|
|
14465
|
+
linesLayout.push({
|
|
14466
|
+
str: clip.str,
|
|
14467
|
+
width: clip.width
|
|
14468
|
+
});
|
|
14469
|
+
if (clip.str.length === str.length) ;
|
|
14470
|
+
else if (needCut) {
|
|
14471
|
+
const newStr = str.substring(clip.str.length);
|
|
14472
|
+
lines.splice(i + 1, 0, newStr);
|
|
14473
|
+
}
|
|
14474
|
+
}
|
|
14475
|
+
}
|
|
14476
|
+
let maxWidth = 0;
|
|
14477
|
+
linesLayout.forEach(layout => {
|
|
14478
|
+
maxWidth = Math.max(maxWidth, layout.width);
|
|
14479
|
+
});
|
|
14480
|
+
bboxWH[0] = maxWidth;
|
|
14481
|
+
}
|
|
14482
|
+
else {
|
|
14483
|
+
let lineWidth = 0;
|
|
14484
|
+
let width;
|
|
14485
|
+
let text;
|
|
14486
|
+
for (let i = 0, len = lines.length; i < len; i++) {
|
|
14487
|
+
if (i === lineCountLimit - 1) {
|
|
14488
|
+
const clip = layoutObj.textMeasure.clipTextWithSuffix(lines[i], layoutObj.textOptions, maxLineWidth, ellipsis, false);
|
|
14489
|
+
linesLayout.push({
|
|
14490
|
+
str: clip.str,
|
|
14491
|
+
width: clip.width
|
|
14492
|
+
});
|
|
14493
|
+
lineWidth = Math.max(lineWidth, clip.width);
|
|
14494
|
+
break;
|
|
14495
|
+
}
|
|
14496
|
+
text = lines[i];
|
|
14497
|
+
width = layoutObj.textMeasure.measureTextWidth(text, layoutObj.textOptions, wordBreak === 'break-word');
|
|
14498
|
+
lineWidth = Math.max(lineWidth, width);
|
|
14499
|
+
linesLayout.push({ str: text, width });
|
|
14500
|
+
}
|
|
14501
|
+
bboxWH[0] = lineWidth;
|
|
14502
|
+
}
|
|
14503
|
+
bboxWH[1] = linesLayout.length * (lineHeight + buf);
|
|
14504
|
+
const bbox = {
|
|
14505
|
+
xOffset: 0,
|
|
14506
|
+
yOffset: 0,
|
|
14507
|
+
width: bboxWH[0],
|
|
14508
|
+
height: bboxWH[1]
|
|
14509
|
+
};
|
|
14510
|
+
layoutObj.LayoutBBox(bbox, textAlign, textBaseline);
|
|
14511
|
+
const layoutData = layoutObj.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
|
|
14512
|
+
this.cache.layoutData = layoutData;
|
|
14513
|
+
this.clearUpdateShapeTag();
|
|
14514
|
+
this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
|
|
14515
|
+
if (stroke) {
|
|
14516
|
+
this._AABBBounds.expand(lineWidth / 2);
|
|
14517
|
+
}
|
|
14518
|
+
return this._AABBBounds;
|
|
14519
|
+
}
|
|
14401
14520
|
updateSingallineAABBBounds(text) {
|
|
14402
14521
|
const textTheme = getTheme(this).text;
|
|
14403
14522
|
const { direction = textTheme.direction } = this.attribute;
|
|
@@ -14419,9 +14538,13 @@
|
|
|
14419
14538
|
let width;
|
|
14420
14539
|
let str;
|
|
14421
14540
|
const attribute = this.attribute;
|
|
14422
|
-
const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontFamily = textTheme.fontFamily, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, ignoreBuf = textTheme.ignoreBuf } = attribute;
|
|
14541
|
+
const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontFamily = textTheme.fontFamily, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, ignoreBuf = textTheme.ignoreBuf, whiteSpace = textTheme.whiteSpace } = attribute;
|
|
14542
|
+
if (whiteSpace === 'normal') {
|
|
14543
|
+
return this.updateWrapAABBBounds(text);
|
|
14544
|
+
}
|
|
14423
14545
|
const buf = ignoreBuf ? 0 : Math.max(2, fontSize * 0.075);
|
|
14424
|
-
const
|
|
14546
|
+
const textFontSize = attribute.fontSize || textTheme.fontSize;
|
|
14547
|
+
const lineHeight = (_a = calculateLineHeight(attribute.lineHeight, textFontSize)) !== null && _a !== void 0 ? _a : textFontSize + buf;
|
|
14425
14548
|
if (!this.shouldUpdateShape() && this.cache) {
|
|
14426
14549
|
width = (_b = this.cache.clipedWidth) !== null && _b !== void 0 ? _b : 0;
|
|
14427
14550
|
const dx = textDrawOffsetX(textAlign, width);
|
|
@@ -14479,7 +14602,8 @@
|
|
|
14479
14602
|
const attribute = this.attribute;
|
|
14480
14603
|
const { ignoreBuf = textTheme.ignoreBuf } = attribute;
|
|
14481
14604
|
const buf = ignoreBuf ? 0 : 2;
|
|
14482
|
-
const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, fontFamily = textTheme.fontFamily, stroke = textTheme.stroke,
|
|
14605
|
+
const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, fontFamily = textTheme.fontFamily, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, verticalMode = textTheme.verticalMode } = attribute;
|
|
14606
|
+
const lineHeight = (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
|
|
14483
14607
|
let { textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline } = attribute;
|
|
14484
14608
|
if (!verticalMode) {
|
|
14485
14609
|
const t = textAlign;
|
|
@@ -14536,11 +14660,15 @@
|
|
|
14536
14660
|
return this._AABBBounds;
|
|
14537
14661
|
}
|
|
14538
14662
|
updateHorizontalMultilineAABBBounds(text) {
|
|
14539
|
-
var _a;
|
|
14663
|
+
var _a, _b;
|
|
14540
14664
|
const textTheme = getTheme(this).text;
|
|
14541
14665
|
const attribute = this.attribute;
|
|
14542
|
-
const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight,
|
|
14543
|
-
|
|
14666
|
+
const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, whiteSpace = textTheme.whiteSpace } = attribute;
|
|
14667
|
+
const lineHeight = (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize);
|
|
14668
|
+
if (whiteSpace === 'normal') {
|
|
14669
|
+
return this.updateWrapAABBBounds(text);
|
|
14670
|
+
}
|
|
14671
|
+
if (!this.shouldUpdateShape() && ((_b = this.cache) === null || _b === void 0 ? void 0 : _b.layoutData)) {
|
|
14544
14672
|
const bbox = this.cache.layoutData.bbox;
|
|
14545
14673
|
this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
|
|
14546
14674
|
if (stroke) {
|
|
@@ -14568,7 +14696,8 @@
|
|
|
14568
14696
|
const attribute = this.attribute;
|
|
14569
14697
|
const { ignoreBuf = textTheme.ignoreBuf } = attribute;
|
|
14570
14698
|
const buf = ignoreBuf ? 0 : 2;
|
|
14571
|
-
const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, fontFamily = textTheme.fontFamily, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, stroke = textTheme.stroke,
|
|
14699
|
+
const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, fontFamily = textTheme.fontFamily, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, verticalMode = textTheme.verticalMode } = attribute;
|
|
14700
|
+
const lineHeight = (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
|
|
14572
14701
|
let { textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline } = attribute;
|
|
14573
14702
|
if (!verticalMode) {
|
|
14574
14703
|
const t = textAlign;
|
|
@@ -14675,11 +14804,12 @@
|
|
|
14675
14804
|
return text != null && text !== '';
|
|
14676
14805
|
}
|
|
14677
14806
|
updateMultilineAABBBounds(text) {
|
|
14678
|
-
var _a, _b, _c;
|
|
14807
|
+
var _a, _b, _c, _d;
|
|
14679
14808
|
const textTheme = getTheme(this).text;
|
|
14680
|
-
const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize,
|
|
14809
|
+
const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, fontWeight = textTheme.fontWeight, ignoreBuf = textTheme.ignoreBuf, heightLimit = 0, lineClamp } = this.attribute;
|
|
14810
|
+
const lineHeight = (_a = calculateLineHeight(this.attribute.lineHeight, this.attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (this.attribute.fontSize || textTheme.fontSize);
|
|
14681
14811
|
const buf = ignoreBuf ? 0 : 2;
|
|
14682
|
-
if (!this.shouldUpdateShape() && ((
|
|
14812
|
+
if (!this.shouldUpdateShape() && ((_b = this.cache) === null || _b === void 0 ? void 0 : _b.layoutData)) {
|
|
14683
14813
|
const bbox = this.cache.layoutData.bbox;
|
|
14684
14814
|
this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
|
|
14685
14815
|
if (stroke) {
|
|
@@ -14716,8 +14846,8 @@
|
|
|
14716
14846
|
if (str !== '' && clip.str === '') {
|
|
14717
14847
|
if (ellipsis) {
|
|
14718
14848
|
const clipEllipsis = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, false);
|
|
14719
|
-
clip.str = (
|
|
14720
|
-
clip.width = (
|
|
14849
|
+
clip.str = (_c = clipEllipsis.str) !== null && _c !== void 0 ? _c : '';
|
|
14850
|
+
clip.width = (_d = clipEllipsis.width) !== null && _d !== void 0 ? _d : 0;
|
|
14721
14851
|
}
|
|
14722
14852
|
else {
|
|
14723
14853
|
clip.str = '';
|
|
@@ -16343,8 +16473,9 @@
|
|
|
16343
16473
|
constructor(text, newLine, character) {
|
|
16344
16474
|
this.fontSize = character.fontSize || 16;
|
|
16345
16475
|
this.textBaseline = character.textBaseline || 'alphabetic';
|
|
16346
|
-
|
|
16347
|
-
|
|
16476
|
+
const lineHeight = calculateLineHeight(character.lineHeight, this.fontSize);
|
|
16477
|
+
if (typeof lineHeight === 'number') {
|
|
16478
|
+
this.lineHeight = lineHeight > this.fontSize ? lineHeight : this.fontSize;
|
|
16348
16479
|
}
|
|
16349
16480
|
else {
|
|
16350
16481
|
this.lineHeight = Math.floor(1.2 * this.fontSize);
|
|
@@ -20861,7 +20992,7 @@
|
|
|
20861
20992
|
textAlign = (_a = text.getBaselineMapAlign()[textBaseline]) !== null && _a !== void 0 ? _a : 'left';
|
|
20862
20993
|
textBaseline = (_b = text.getAlignMapBaseline()[t]) !== null && _b !== void 0 ? _b : 'top';
|
|
20863
20994
|
}
|
|
20864
|
-
const lineHeight = (_c = text.attribute.lineHeight) !== null && _c !== void 0 ? _c : fontSize;
|
|
20995
|
+
const lineHeight = (_c = calculateLineHeight(text.attribute.lineHeight, fontSize)) !== null && _c !== void 0 ? _c : fontSize;
|
|
20865
20996
|
const data = this.valid(text, textAttribute, fillCb, strokeCb);
|
|
20866
20997
|
if (!data) {
|
|
20867
20998
|
return;
|
|
@@ -26124,6 +26255,19 @@
|
|
|
26124
26255
|
this.setAttributes({ background: this._background });
|
|
26125
26256
|
}
|
|
26126
26257
|
}
|
|
26258
|
+
preventRender(prevent) {
|
|
26259
|
+
if (prevent) {
|
|
26260
|
+
this._skipRender = -Infinity;
|
|
26261
|
+
}
|
|
26262
|
+
else {
|
|
26263
|
+
if (this.params && this.params.optimize && this.params.optimize.skipRenderWithOutRange !== false) {
|
|
26264
|
+
this._skipRender = this.window.isVisible() ? 0 : 1;
|
|
26265
|
+
}
|
|
26266
|
+
else {
|
|
26267
|
+
this._skipRender = 0;
|
|
26268
|
+
}
|
|
26269
|
+
}
|
|
26270
|
+
}
|
|
26127
26271
|
optmize(params) {
|
|
26128
26272
|
this.optmizeRender(params === null || params === void 0 ? void 0 : params.skipRenderWithOutRange);
|
|
26129
26273
|
}
|
|
@@ -26131,8 +26275,11 @@
|
|
|
26131
26275
|
if (!skipRenderWithOutRange) {
|
|
26132
26276
|
return;
|
|
26133
26277
|
}
|
|
26134
|
-
this._skipRender = this.window.isVisible() ? 0 : 1;
|
|
26278
|
+
this._skipRender = this._skipRender < 0 ? this._skipRender : this.window.isVisible() ? 0 : 1;
|
|
26135
26279
|
this.window.onVisibleChange(visible => {
|
|
26280
|
+
if (this._skipRender < 0) {
|
|
26281
|
+
return;
|
|
26282
|
+
}
|
|
26136
26283
|
if (visible) {
|
|
26137
26284
|
if (this.dirtyBounds) {
|
|
26138
26285
|
this.dirtyBounds.setValue(0, 0, this._viewBox.width(), this._viewBox.height());
|
|
@@ -27500,6 +27647,7 @@
|
|
|
27500
27647
|
exports.builtinSymbols = builtinSymbols;
|
|
27501
27648
|
exports.builtinSymbolsMap = builtinSymbolsMap;
|
|
27502
27649
|
exports.calcLineCache = calcLineCache$1;
|
|
27650
|
+
exports.calculateLineHeight = calculateLineHeight;
|
|
27503
27651
|
exports.centroidOfSubpath = centroidOfSubpath;
|
|
27504
27652
|
exports.circleBounds = circleBounds;
|
|
27505
27653
|
exports.clock = clock;
|