@visactor/vrender-core 0.16.14-alpha.3 → 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.
@@ -18,9 +18,7 @@ export declare class DefaultGraphicUtil implements IGraphicUtil {
18
18
  width: number;
19
19
  height: number;
20
20
  };
21
- createTextMeasureInstance(textSpec?: Partial<ITextAttribute>, option?: Partial<ITextMeasureOption>, getCanvasForMeasure?: () => any): TextMeasure<Omit<ITextAttribute, "lineHeight"> & {
22
- lineHeight?: number;
23
- }>;
21
+ createTextMeasureInstance(textSpec?: Partial<ITextAttribute>, option?: Partial<ITextMeasureOption>, getCanvasForMeasure?: () => any): TextMeasure<ITextAttribute>;
24
22
  }
25
23
  export declare class DefaultTransformUtil implements ITransformUtil {
26
24
  private matrix;
@@ -16,7 +16,7 @@ Object.defineProperty(exports, "__esModule", {
16
16
  value: !0
17
17
  }), exports.DefaultTransformUtil = exports.DefaultGraphicUtil = void 0;
18
18
 
19
- const inversify_lite_1 = require("../common/inversify-lite"), textMeasure_contribution_1 = require("./contributions/textMeasure/textMeasure-contribution"), contribution_provider_1 = require("../common/contribution-provider"), util_1 = require("../canvas/util"), config_1 = require("../graphic/config"), vutils_1 = require("@visactor/vutils"), constants_1 = require("../constants"), utils_1 = require("../common/utils");
19
+ const inversify_lite_1 = require("../common/inversify-lite"), textMeasure_contribution_1 = require("./contributions/textMeasure/textMeasure-contribution"), contribution_provider_1 = require("../common/contribution-provider"), util_1 = require("../canvas/util"), config_1 = require("../graphic/config"), vutils_1 = require("@visactor/vutils"), constants_1 = require("../constants");
20
20
 
21
21
  let DefaultGraphicUtil = class {
22
22
  constructor(contributions, global) {
@@ -63,9 +63,7 @@ let DefaultGraphicUtil = class {
63
63
  getCanvasForMeasure: getCanvasForMeasure || (() => this.canvas),
64
64
  getTextBounds: void 0,
65
65
  specialCharSet: "-/: .,@%'\"~" + vutils_1.TextMeasure.ALPHABET_CHAR_SET + vutils_1.TextMeasure.ALPHABET_CHAR_SET.toUpperCase()
66
- }, null != option ? option : {}), Object.assign(Object.assign({}, textSpec), {
67
- lineHeight: (0, utils_1.calculateLineHeight)(null == textSpec ? void 0 : textSpec.lineHeight, null == textSpec ? void 0 : textSpec.fontSize)
68
- }));
66
+ }, null != option ? option : {}), textSpec);
69
67
  }
70
68
  };
71
69
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/graphic-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6DAAqE;AAGrE,mGAA+F;AAE/F,2EAAuE;AACvE,yCAA4C;AAC5C,8CAAqD;AAErD,6CAAuD;AAEvD,4CAAuC;AACvC,2CAAsD;AAG/C,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAM7B,YAGqB,aAAkD,EACpC,MAAe;QAD7B,kBAAa,GAAb,aAAa,CAAqC;QACpC,WAAM,GAAN,MAAM,CAAS;QAEhD,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE;YACtE,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;YACxB,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,WAAW;QACb,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;YACtB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;SAC9C;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,SAAS,CAAC,MAAe,EAAE,GAAY;QACrC,IAAI,IAAI,CAAC,UAAU,EAAE;YACnB,OAAO;SACR;QACD,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC;YACxB,YAAY,EAA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,2BAAU,GAAE;;GACA,oBAAoB,CA2IhC;AA3IY,oDAAoB","file":"graphic-utils.js","sourcesContent":["import { injectable, inject, named } from '../common/inversify-lite';\nimport type { ICanvas, IContext2d, EnvType, IGlobal, ITextAttribute, IContributionProvider } from '../interface';\nimport type { ITextMeasure, TextOptionsType } from '../interface/text';\nimport { TextMeasureContribution } from './contributions/textMeasure/textMeasure-contribution';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { ContributionProvider } from '../common/contribution-provider';\nimport { wrapCanvas } from '../canvas/util';\nimport { DefaultTextStyle } from '../graphic/config';\nimport type { IMatrix, IPointLike, ITextMeasureOption } from '@visactor/vutils';\nimport { Matrix, TextMeasure } from '@visactor/vutils';\nimport type { IGraphicUtil, ITransformUtil, TransformType } from '../interface/core';\nimport { VGlobal } from '../constants';\nimport { calculateLineHeight } from '../common/utils';\n\n@injectable()\nexport class DefaultGraphicUtil implements IGraphicUtil {\n canvas?: ICanvas;\n context?: IContext2d | null;\n _textMeasure: ITextMeasure;\n configured: boolean;\n\n constructor(\n @inject(ContributionProvider)\n @named(TextMeasureContribution)\n protected readonly contributions: IContributionProvider<ITextMeasure>,\n @inject(VGlobal) public readonly global: IGlobal\n ) {\n this.configured = false;\n this.global.hooks.onSetEnv.tap('graphic-util', (lastEnv, env, global) => {\n this.configured = false;\n this.configure(global, env);\n });\n }\n\n get textMeasure(): ITextMeasure {\n if (!this._textMeasure) {\n this.configure(this.global, this.global.env);\n }\n return this._textMeasure;\n }\n\n configure(global: IGlobal, env: EnvType) {\n if (this.configured) {\n return;\n }\n const canvas = wrapCanvas({\n nativeCanvas: global.createCanvas({ width: 100, height: 100 })\n });\n this.canvas = canvas;\n this.context = canvas.getContext('2d');\n this.contributions.getContributions().forEach(contribution => {\n contribution.configure(this, env);\n });\n this.configured = true;\n }\n\n bindTextMeasure(tm: ITextMeasure) {\n this._textMeasure = tm;\n }\n\n measureText(\n text: string,\n tc: TextOptionsType,\n method: 'native' | 'simple' | 'quick' = 'native'\n ): { width: number; height: number } {\n this.configure(this.global, this.global.env);\n const m = this.global.measureTextMethod;\n this.global.measureTextMethod = method;\n const data = {\n width: this._textMeasure.measureTextWidth(text, tc),\n height: tc.fontSize ?? DefaultTextStyle.fontSize\n };\n this.global.measureTextMethod = m;\n return data;\n }\n\n createTextMeasureInstance(\n textSpec?: Partial<ITextAttribute>,\n option?: Partial<ITextMeasureOption>,\n getCanvasForMeasure?: () => any\n ) {\n this.configure(this.global, this.global.env);\n return new TextMeasure<Omit<ITextAttribute, 'lineHeight'> & { lineHeight?: number }>(\n {\n defaultFontParams: {\n fontFamily: DefaultTextStyle.fontFamily,\n fontSize: DefaultTextStyle.fontSize\n },\n getCanvasForMeasure: getCanvasForMeasure || (() => this.canvas),\n getTextBounds: undefined,\n specialCharSet: '-/: .,@%\\'\"~' + TextMeasure.ALPHABET_CHAR_SET + TextMeasure.ALPHABET_CHAR_SET.toUpperCase(),\n ...(option ?? {})\n },\n {\n ...textSpec,\n lineHeight: calculateLineHeight(textSpec?.lineHeight, textSpec?.fontSize)\n }\n );\n }\n}\n\nenum TransformMode {\n transform = 0,\n matrix = 1\n}\n\nconst _matrix = new Matrix();\n\n@injectable()\nexport class DefaultTransformUtil implements ITransformUtil {\n private matrix: IMatrix;\n private originTransform: TransformType;\n\n private outSourceMatrix: IMatrix;\n private outTargetMatrix: IMatrix;\n\n private mode: TransformMode;\n constructor() {\n this.matrix = new Matrix();\n }\n init(origin: TransformType): this {\n this.mode = TransformMode.transform;\n this.originTransform = origin;\n this.matrix.reset();\n return this;\n }\n fromMatrix(source: IMatrix, target: IMatrix): this {\n this.mode = TransformMode.matrix;\n this.outSourceMatrix = source;\n this.outTargetMatrix = target;\n return this;\n }\n\n // translate: (x: number, y: number) => Transform;\n // translateTo: (x: number, y: number) => Transform;\n private scaleMatrix(sx: number, sy: number, center?: IPointLike): this {\n // if (this.outSourceMatrix !== this.outTargetMatrix) {\n // // copy\n // const m = this.outSourceMatrix;\n // this.outTargetMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n // }\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n if (center) {\n const { x, y } = center;\n this.outTargetMatrix.translate(x, y);\n this.outTargetMatrix.scale(sx, sy);\n this.outTargetMatrix.translate(-x, -y);\n } else {\n this.outTargetMatrix.scale(sx, sy);\n }\n\n // _matrix.reset();\n // if (center) {\n // const { x, y } = center;\n // _matrix.translate(x, y);\n // _matrix.scale(sx, sy);\n // _matrix.translate(-x, -y);\n // } else {\n // _matrix.scale(sx, sy);\n // }\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n\n private rotateMatrix(angle: number, center?: IPointLike): this {\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n if (center) {\n const { x, y } = center;\n this.outTargetMatrix.translate(x, y);\n this.outTargetMatrix.rotate(angle);\n this.outTargetMatrix.translate(-x, -y);\n } else {\n this.outTargetMatrix.rotate(angle);\n }\n\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n scale(sx: number, sy: number, center?: IPointLike): this {\n if (this.mode === TransformMode.matrix) {\n return this.scaleMatrix(sx, sy, center);\n }\n return this;\n }\n rotate(angle: number, center?: IPointLike): this {\n if (this.mode === TransformMode.matrix) {\n return this.rotateMatrix(angle, center);\n }\n return this;\n }\n private translateMatrix(dx: number, dy: number): this {\n // if (this.outSourceMatrix !== this.outTargetMatrix) {\n // // copy\n // const m = this.outSourceMatrix;\n // this.outTargetMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n // }\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n this.outTargetMatrix.translate(dx, dy);\n\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n translate(dx: number, dy: number): this {\n if (this.mode === TransformMode.matrix) {\n return this.translateMatrix(dx, dy);\n }\n return this;\n }\n // scaleTo: (sx: number, sy: number, center: IPointLike) => Transform;\n // rotate: (rx: number, ry: number, center: IPointLike) => Transform;\n // rotateTo: (rx: number, ry: number, center: IPointLike) => Transform;\n // 语法糖\n // interactive: (dx: number, dy: number, dsx: number, dsy: number, drx: number, dry: number) => Transform;\n // // 扩展padding像素,用于外描边,内描边\n // extend: (origin: TransformType, padding: number) => Transform;\n // 将所有的transform生成为一次的transform\n simplify(target: TransformType): this {\n if (this.mode === TransformMode.matrix) {\n return this.simplifyMatrix(target);\n }\n return this;\n }\n private simplifyMatrix(target: TransformType): this {\n // let { a, b, c, d, e, f } = this.outTargetMatrix;\n // if (a === 0 || d === 0) return this;\n // const { dx=0, dy=0 } = target;\n // // 不处理dx和dy\n // e -= dx;\n // f -= dy;\n // const tanTheta = b / a;\n // const angle = Math.atan(tanTheta);\n // const cosTheta = cos(angle);\n // const sinTheta = sin(angle);\n // const sx = cosTheta !== 0 ? (a / cosTheta) : (b / sinTheta);\n // const sy = sinTheta !== 0 ? (-c / sinTheta) : (d / cosTheta);\n // const x = e;\n // const y = f;\n // target.x = x;\n // target.y = y;\n // target.dx = dx;\n return this;\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/core/graphic-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6DAAqE;AAGrE,mGAA+F;AAE/F,2EAAuE;AACvE,yCAA4C;AAC5C,8CAAqD;AAErD,6CAAuD;AAEvD,4CAAuC;AAGhC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAM7B,YAGqB,aAAkD,EACpC,MAA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AC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;QAChG,OAAO,IAAI,CAAC;IACd,CAAC;IACD,SAAS,CAAC,EAAU,EAAE,EAAU;QAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,MAAM,EAAE;YACtC,OAAO,IAAI,CAAC,eAAe,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;SACrC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IASD,QAAQ,CAAC,MAAqB;QAC5B,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,MAAM,EAAE;YACtC,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;SACpC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACO,cAAc,CAAC,MAAqB;QAkB1C,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA3IY,oBAAoB;IADhC,IAAA,2BAAU,GAAE;;GACA,oBAAoB,CA2IhC;AA3IY,oDAAoB","file":"graphic-utils.js","sourcesContent":["import { injectable, inject, named } from '../common/inversify-lite';\nimport type { ICanvas, IContext2d, EnvType, IGlobal, ITextAttribute, IContributionProvider } from '../interface';\nimport type { ITextMeasure, TextOptionsType } from '../interface/text';\nimport { TextMeasureContribution } from './contributions/textMeasure/textMeasure-contribution';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { ContributionProvider } from '../common/contribution-provider';\nimport { wrapCanvas } from '../canvas/util';\nimport { DefaultTextStyle } from '../graphic/config';\nimport type { IMatrix, IPointLike, ITextMeasureOption } from '@visactor/vutils';\nimport { Matrix, TextMeasure } from '@visactor/vutils';\nimport type { IGraphicUtil, ITransformUtil, TransformType } from '../interface/core';\nimport { VGlobal } from '../constants';\n\n@injectable()\nexport class DefaultGraphicUtil implements IGraphicUtil {\n canvas?: ICanvas;\n context?: IContext2d | null;\n _textMeasure: ITextMeasure;\n configured: boolean;\n\n constructor(\n @inject(ContributionProvider)\n @named(TextMeasureContribution)\n protected readonly contributions: IContributionProvider<ITextMeasure>,\n @inject(VGlobal) public readonly global: IGlobal\n ) {\n this.configured = false;\n this.global.hooks.onSetEnv.tap('graphic-util', (lastEnv, env, global) => {\n this.configured = false;\n this.configure(global, env);\n });\n }\n\n get textMeasure(): ITextMeasure {\n if (!this._textMeasure) {\n this.configure(this.global, this.global.env);\n }\n return this._textMeasure;\n }\n\n configure(global: IGlobal, env: EnvType) {\n if (this.configured) {\n return;\n }\n const canvas = wrapCanvas({\n nativeCanvas: global.createCanvas({ width: 100, height: 100 })\n });\n this.canvas = canvas;\n this.context = canvas.getContext('2d');\n this.contributions.getContributions().forEach(contribution => {\n contribution.configure(this, env);\n });\n this.configured = true;\n }\n\n bindTextMeasure(tm: ITextMeasure) {\n this._textMeasure = tm;\n }\n\n measureText(\n text: string,\n tc: TextOptionsType,\n method: 'native' | 'simple' | 'quick' = 'native'\n ): { width: number; height: number } {\n this.configure(this.global, this.global.env);\n const m = this.global.measureTextMethod;\n this.global.measureTextMethod = method;\n const data = {\n width: this._textMeasure.measureTextWidth(text, tc),\n height: tc.fontSize ?? DefaultTextStyle.fontSize\n };\n this.global.measureTextMethod = m;\n return data;\n }\n\n createTextMeasureInstance(\n textSpec?: Partial<ITextAttribute>,\n option?: Partial<ITextMeasureOption>,\n getCanvasForMeasure?: () => any\n ) {\n this.configure(this.global, this.global.env);\n return new TextMeasure<ITextAttribute>(\n {\n defaultFontParams: {\n fontFamily: DefaultTextStyle.fontFamily,\n fontSize: DefaultTextStyle.fontSize\n },\n getCanvasForMeasure: getCanvasForMeasure || (() => this.canvas),\n getTextBounds: undefined,\n specialCharSet: '-/: .,@%\\'\"~' + TextMeasure.ALPHABET_CHAR_SET + TextMeasure.ALPHABET_CHAR_SET.toUpperCase(),\n ...(option ?? {})\n },\n textSpec\n );\n }\n}\n\nenum TransformMode {\n transform = 0,\n matrix = 1\n}\n\nconst _matrix = new Matrix();\n\n@injectable()\nexport class DefaultTransformUtil implements ITransformUtil {\n private matrix: IMatrix;\n private originTransform: TransformType;\n\n private outSourceMatrix: IMatrix;\n private outTargetMatrix: IMatrix;\n\n private mode: TransformMode;\n constructor() {\n this.matrix = new Matrix();\n }\n init(origin: TransformType): this {\n this.mode = TransformMode.transform;\n this.originTransform = origin;\n this.matrix.reset();\n return this;\n }\n fromMatrix(source: IMatrix, target: IMatrix): this {\n this.mode = TransformMode.matrix;\n this.outSourceMatrix = source;\n this.outTargetMatrix = target;\n return this;\n }\n\n // translate: (x: number, y: number) => Transform;\n // translateTo: (x: number, y: number) => Transform;\n private scaleMatrix(sx: number, sy: number, center?: IPointLike): this {\n // if (this.outSourceMatrix !== this.outTargetMatrix) {\n // // copy\n // const m = this.outSourceMatrix;\n // this.outTargetMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n // }\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n if (center) {\n const { x, y } = center;\n this.outTargetMatrix.translate(x, y);\n this.outTargetMatrix.scale(sx, sy);\n this.outTargetMatrix.translate(-x, -y);\n } else {\n this.outTargetMatrix.scale(sx, sy);\n }\n\n // _matrix.reset();\n // if (center) {\n // const { x, y } = center;\n // _matrix.translate(x, y);\n // _matrix.scale(sx, sy);\n // _matrix.translate(-x, -y);\n // } else {\n // _matrix.scale(sx, sy);\n // }\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n\n private rotateMatrix(angle: number, center?: IPointLike): this {\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n if (center) {\n const { x, y } = center;\n this.outTargetMatrix.translate(x, y);\n this.outTargetMatrix.rotate(angle);\n this.outTargetMatrix.translate(-x, -y);\n } else {\n this.outTargetMatrix.rotate(angle);\n }\n\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n scale(sx: number, sy: number, center?: IPointLike): this {\n if (this.mode === TransformMode.matrix) {\n return this.scaleMatrix(sx, sy, center);\n }\n return this;\n }\n rotate(angle: number, center?: IPointLike): this {\n if (this.mode === TransformMode.matrix) {\n return this.rotateMatrix(angle, center);\n }\n return this;\n }\n private translateMatrix(dx: number, dy: number): this {\n // if (this.outSourceMatrix !== this.outTargetMatrix) {\n // // copy\n // const m = this.outSourceMatrix;\n // this.outTargetMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n // }\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n this.outTargetMatrix.translate(dx, dy);\n\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n translate(dx: number, dy: number): this {\n if (this.mode === TransformMode.matrix) {\n return this.translateMatrix(dx, dy);\n }\n return this;\n }\n // scaleTo: (sx: number, sy: number, center: IPointLike) => Transform;\n // rotate: (rx: number, ry: number, center: IPointLike) => Transform;\n // rotateTo: (rx: number, ry: number, center: IPointLike) => Transform;\n // 语法糖\n // interactive: (dx: number, dy: number, dsx: number, dsy: number, drx: number, dry: number) => Transform;\n // // 扩展padding像素,用于外描边,内描边\n // extend: (origin: TransformType, padding: number) => Transform;\n // 将所有的transform生成为一次的transform\n simplify(target: TransformType): this {\n if (this.mode === TransformMode.matrix) {\n return this.simplifyMatrix(target);\n }\n return this;\n }\n private simplifyMatrix(target: TransformType): this {\n // let { a, b, c, d, e, f } = this.outTargetMatrix;\n // if (a === 0 || d === 0) return this;\n // const { dx=0, dy=0 } = target;\n // // 不处理dx和dy\n // e -= dx;\n // f -= dy;\n // const tanTheta = b / a;\n // const angle = Math.atan(tanTheta);\n // const cosTheta = cos(angle);\n // const sinTheta = sin(angle);\n // const sx = cosTheta !== 0 ? (a / cosTheta) : (b / sinTheta);\n // const sy = sinTheta !== 0 ? (-c / sinTheta) : (d / cosTheta);\n // const x = e;\n // const y = f;\n // target.x = x;\n // target.y = y;\n // target.dx = dx;\n return this;\n }\n}\n"]}
@@ -4,14 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  }), exports.seperateParagraph = void 0;
6
6
 
7
- const utils_1 = require("./utils");
7
+ const utils_1 = require("../../common/utils"), utils_2 = require("./utils");
8
8
 
9
9
  class Paragraph {
10
10
  constructor(text, newLine, character) {
11
- this.fontSize = character.fontSize || 16, this.textBaseline = character.textBaseline || "alphabetic",
12
- "number" == typeof character.lineHeight ? this.lineHeight = character.lineHeight > this.fontSize ? character.lineHeight : this.fontSize : this.lineHeight = Math.floor(1.2 * this.fontSize),
11
+ this.fontSize = character.fontSize || 16, this.textBaseline = character.textBaseline || "alphabetic";
12
+ const lineHeight = (0, utils_1.calculateLineHeight)(character.lineHeight, this.fontSize);
13
+ this.lineHeight = "number" == typeof lineHeight ? lineHeight > this.fontSize ? lineHeight : this.fontSize : Math.floor(1.2 * this.fontSize),
13
14
  this.height = this.lineHeight;
14
- const {ascent: ascent, height: height, descent: descent, width: width} = (0, utils_1.measureTextCanvas)(text, character);
15
+ const {ascent: ascent, height: height, descent: descent, width: width} = (0, utils_2.measureTextCanvas)(text, character);
15
16
  let halfDetaHeight = 0, deltaAscent = 0, deltaDescent = 0;
16
17
  this.height > height && (halfDetaHeight = (this.height - height) / 2, deltaAscent = Math.ceil(halfDetaHeight),
17
18
  deltaDescent = Math.floor(halfDetaHeight)), "top" === this.textBaseline ? (this.ascent = halfDetaHeight,
@@ -25,7 +26,7 @@ class Paragraph {
25
26
  this.height = this.widthOrigin, this.lineHeight = this.height);
26
27
  }
27
28
  updateWidth() {
28
- const {width: width} = (0, utils_1.measureTextCanvas)(this.text, this.character);
29
+ const {width: width} = (0, utils_2.measureTextCanvas)(this.text, this.character);
29
30
  this.width = width, "vertical" === this.direction && (this.widthOrigin = this.width,
30
31
  this.width = this.heightOrigin, this.height = this.widthOrigin);
31
32
  }
@@ -36,9 +37,9 @@ class Paragraph {
36
37
  if (this.verticalEllipsis) text = "...", direction = "vertical", baseline -= this.ellipsisWidth / 2; else {
37
38
  if ("hide" === this.ellipsis) return;
38
39
  if ("add" === this.ellipsis) text += "...", "right" === textAlign && (left -= this.ellipsisWidth); else if ("replace" === this.ellipsis) {
39
- const index = (0, utils_1.getStrByWithCanvas)(text, ("vertical" === direction ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.character, text.length - 1);
40
+ const index = (0, utils_2.getStrByWithCanvas)(text, ("vertical" === direction ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.character, text.length - 1);
40
41
  if (text = text.slice(0, index), text += "...", "right" === textAlign) {
41
- const {width: width} = (0, utils_1.measureTextCanvas)(this.text.slice(index), this.character);
42
+ const {width: width} = (0, utils_2.measureTextCanvas)(this.text.slice(index), this.character);
42
43
  "vertical" === direction || (left -= this.ellipsisWidth - width);
43
44
  }
44
45
  }
@@ -53,8 +54,8 @@ class Paragraph {
53
54
  }
54
55
  "vertical" === direction && (ctx.save(), ctx.rotateAbout(Math.PI / 2, left, baseline),
55
56
  ctx.translate(-this.heightOrigin || -this.lineHeight / 2, -this.descent / 2), ctx.translate(left, baseline),
56
- left = 0, baseline = 0), this.character.stroke && ((0, utils_1.applyStrokeStyle)(ctx, this.character),
57
- ctx.strokeText(text, left, baseline)), (0, utils_1.applyFillStyle)(ctx, this.character),
57
+ left = 0, baseline = 0), this.character.stroke && ((0, utils_2.applyStrokeStyle)(ctx, this.character),
58
+ ctx.strokeText(text, left, baseline)), (0, utils_2.applyFillStyle)(ctx, this.character),
58
59
  this.character.fill && ctx.fillText(text, left, baseline), this.character.fill && ("boolean" == typeof this.character.lineThrough || "boolean" == typeof this.character.underline ? (this.character.underline && ctx.fillRect(left, 1 + baseline, this.widthOrigin || this.width, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1),
59
60
  this.character.lineThrough && ctx.fillRect(left, 1 + baseline - this.ascent / 2, this.widthOrigin || this.width, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1)) : "underline" === this.character.textDecoration ? ctx.fillRect(left, 1 + baseline, this.widthOrigin || this.width, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1) : "line-through" === this.character.textDecoration && ctx.fillRect(left, 1 + baseline - this.ascent / 2, this.widthOrigin || this.width, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1)),
60
61
  "vertical" === direction && ctx.restore();
@@ -65,9 +66,9 @@ class Paragraph {
65
66
  if ("hide" === this.ellipsis) return width;
66
67
  if ("add" === this.ellipsis) return width + this.ellipsisWidth;
67
68
  if ("replace" === this.ellipsis) {
68
- const index = (0, utils_1.getStrByWithCanvas)(text, width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.character, text.length - 1);
69
+ const index = (0, utils_2.getStrByWithCanvas)(text, width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.character, text.length - 1);
69
70
  text = text.slice(0, index), text += "...";
70
- const {width: measureWidth} = (0, utils_1.measureTextCanvas)(this.text.slice(index), this.character);
71
+ const {width: measureWidth} = (0, utils_2.measureTextCanvas)(this.text.slice(index), this.character);
71
72
  return width + this.ellipsisWidth - measureWidth;
72
73
  }
73
74
  return width;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/richtext/paragraph.ts"],"names":[],"mappings":";;;AACA,mCAAkG;AA8BlG,MAAqB,SAAS;IAyB5B,YAAY,IAAY,EAAE,OAAgB,EAAE,SAAsC;QAEhF,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,IAAI,EAAE,CAAC;QACzC,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC,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file":"paragraph.js","sourcesContent":["import type { IContext2d, IRichTextParagraphCharacter } from '../../interface';\nimport { measureTextCanvas, applyFillStyle, applyStrokeStyle, getStrByWithCanvas } from './utils';\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 文字段\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/text.js\nexport default class Paragraph {\n text: string;\n ascent: number;\n descent: number;\n width: number;\n height: number;\n lineHeight: number;\n fontSize: number;\n length: number;\n newLine: boolean;\n character: IRichTextParagraphCharacter;\n left: number;\n top: number;\n // rotate?: number;\n direction?: 'horizontal' | 'vertical';\n // bounds?: Bounds;\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n\n constructor(text: string, newLine: boolean, character: IRichTextParagraphCharacter) {\n // 测量文字\n this.fontSize = character.fontSize || 16;\n this.textBaseline = character.textBaseline || 'alphabetic';\n\n // 处理行高:\n // lineHeight为数字时,大于fontSize取lineHeight,小于fontSize时取fontSize\n // lineHeight不为数字时,统一认为lineHeight为'normal',值取1.2 * fontSize\n if (typeof character.lineHeight === 'number') {\n this.lineHeight = character.lineHeight > this.fontSize ? character.lineHeight : this.fontSize;\n } else {\n this.lineHeight = Math.floor(1.2 * this.fontSize);\n }\n\n this.height = this.lineHeight;\n\n const { ascent, height, descent, width } = measureTextCanvas(text, character);\n\n let halfDetaHeight = 0;\n let deltaAscent = 0;\n let deltaDescent = 0;\n if (this.height > height) {\n // measureTextCanvas测量出的是纯文字高度,this.height是考虑行高后的高度\n // 如果this.height > height,将超过的高度平均分配到ascent和descent上\n halfDetaHeight = (this.height - height) / 2;\n deltaAscent = Math.ceil(halfDetaHeight);\n deltaDescent = Math.floor(halfDetaHeight);\n }\n\n if (this.textBaseline === 'top') {\n this.ascent = halfDetaHeight;\n this.descent = height - halfDetaHeight;\n } else if (this.textBaseline === 'bottom') {\n this.ascent = height - halfDetaHeight;\n this.descent = halfDetaHeight;\n } else if (this.textBaseline === 'middle') {\n this.ascent = this.height / 2;\n this.descent = this.height / 2;\n } else {\n this.ascent = ascent + deltaAscent;\n this.descent = descent + deltaDescent;\n }\n\n this.length = text.length;\n this.width = width || 0;\n this.text = text || '';\n this.newLine = newLine || false;\n this.character = character;\n\n this.left = 0;\n this.top = 0;\n\n this.ellipsis = 'normal';\n this.ellipsisWidth = 0;\n this.ellipsisOtherParagraphWidth = 0;\n\n // 处理旋转\n if (character.direction === 'vertical') {\n this.direction = character.direction;\n this.widthOrigin = this.width;\n this.heightOrigin = this.height;\n // const bounds = new Bounds();\n // bounds.set(0, 0, this.width, this.height);\n // bounds.rotate(Math.PI / 2, this.width / 2, this.height / 2);\n // this.bounds = bounds;\n // this.width = bounds.width();\n // this.height = bounds.height();\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n this.lineHeight = this.height;\n }\n }\n\n updateWidth() {\n const { width } = measureTextCanvas(this.text, this.character);\n this.width = width;\n if (this.direction === 'vertical') {\n this.widthOrigin = this.width;\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n }\n }\n\n draw(ctx: IContext2d, baseline: number, deltaLeft: number, isLineFirst: boolean, textAlign: string) {\n let text = this.text;\n let left = this.left + deltaLeft;\n baseline += this.top;\n let direction = this.direction;\n\n if (this.verticalEllipsis) {\n text = '...';\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += '...';\n\n if (textAlign === 'right') {\n left -= this.ellipsisWidth;\n }\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, this.width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n (direction === 'vertical' ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += '...';\n\n if (textAlign === 'right') {\n const { width } = measureTextCanvas(this.text.slice(index), this.character);\n if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n left -= this.ellipsisWidth - width;\n }\n }\n }\n\n // prepareContext(ctx);\n switch (this.character.script) {\n case 'super':\n baseline -= this.ascent * (1 / 3);\n break;\n case 'sub':\n baseline += this.descent / 2;\n break;\n }\n\n // if (isLineFirst) {\n // const result = regFirstSpace.exec(text);\n // if (result?.index !== 0) {\n // text = text.slice(result?.index);\n // }\n // }\n\n // 处理旋转\n if (direction === 'vertical') {\n ctx.save();\n ctx.rotateAbout(Math.PI / 2, left, baseline);\n ctx.translate(-(this.heightOrigin as number) || -this.lineHeight / 2, -this.descent / 2);\n ctx.translate(left, baseline);\n left = 0;\n baseline = 0;\n }\n\n if (this.character.stroke) {\n applyStrokeStyle(ctx, this.character);\n ctx.strokeText(text, left, baseline);\n }\n\n // 下面绘制underline和line-through时需要设置FillStyle\n applyFillStyle(ctx, this.character);\n\n if (this.character.fill) {\n ctx.fillText(text, left, baseline);\n }\n\n if (this.character.fill) {\n if (typeof this.character.lineThrough === 'boolean' || typeof this.character.underline === 'boolean') {\n if (this.character.underline) {\n ctx.fillRect(\n left,\n 1 + baseline,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n if (this.character.lineThrough) {\n ctx.fillRect(\n left,\n 1 + baseline - this.ascent / 2,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n } else if (this.character.textDecoration === 'underline') {\n ctx.fillRect(\n left,\n 1 + baseline,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n } else if (this.character.textDecoration === 'line-through') {\n ctx.fillRect(\n left,\n 1 + baseline - this.ascent / 2,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n }\n\n if (direction === 'vertical') {\n ctx.restore();\n }\n }\n\n getWidthWithEllips(direction: string): number {\n let text = this.text;\n // const direction = this.direction;\n const width = direction === 'vertical' ? this.height : this.width;\n // const height = direction === 'vertical' ? this.width: this.height;\n\n if (this.ellipsis === 'hide') {\n return width;\n } else if (this.ellipsis === 'add') {\n return width + this.ellipsisWidth;\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += '...';\n\n const { width: measureWidth } = measureTextCanvas(this.text.slice(index), this.character);\n return width + this.ellipsisWidth - measureWidth;\n }\n return width;\n }\n}\n\nexport function seperateParagraph(paragraph: Paragraph, index: number) {\n const text1 = paragraph.text.slice(0, index);\n const text2 = paragraph.text.slice(index);\n const p1 = new Paragraph(text1, paragraph.newLine, paragraph.character);\n const p2 = new Paragraph(text2, true, paragraph.character);\n\n return [p1, p2];\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/richtext/paragraph.ts"],"names":[],"mappings":";;;AAAA,8CAAyD;AAEzD,mCAAkG;AA8BlG,MAAqB,SAAS;IAyB5B,YAAY,IAAY,EAAE,OAAgB,EAAE,SAAsC;QAEhF,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,IAAI,EAAE,CAAC;QACzC,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC,YAAY,IAAI,YAAY,CAAC;QAK3D,MAAM,UAAU,GAAG,IAAA,2BAAmB,EAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC5E,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;YAClC,IAAI,CAAC,UAAU,GAAG,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;SAC3E;aAAM;YACL,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;SACnD;QAED,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC;QAE9B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,IAAA,yBAAiB,EAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAE9E,IAAI,cAAc,GAAG,CAAC,CAAC;QACvB,IAAI,WAAW,GAAG,CAAC,CAAC;QACpB,IAAI,YAAY,GAAG,CAAC,CAAC;QACrB,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM,EAAE;YAGxB,c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KAAK,CAAC;IACf,CAAC;CACF;AA/PD,4BA+PC;AAED,SAAgB,iBAAiB,CAAC,SAAoB,EAAE,KAAa;IACnE,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1C,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACxE,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAE3D,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAClB,CAAC;AAPD,8CAOC","file":"paragraph.js","sourcesContent":["import { calculateLineHeight } from '../../common/utils';\nimport type { IContext2d, IRichTextParagraphCharacter } from '../../interface';\nimport { measureTextCanvas, applyFillStyle, applyStrokeStyle, getStrByWithCanvas } from './utils';\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 文字段\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/text.js\nexport default class Paragraph {\n text: string;\n ascent: number;\n descent: number;\n width: number;\n height: number;\n lineHeight: number;\n fontSize: number;\n length: number;\n newLine: boolean;\n character: IRichTextParagraphCharacter;\n left: number;\n top: number;\n // rotate?: number;\n direction?: 'horizontal' | 'vertical';\n // bounds?: Bounds;\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n\n constructor(text: string, newLine: boolean, character: IRichTextParagraphCharacter) {\n // 测量文字\n this.fontSize = character.fontSize || 16;\n this.textBaseline = character.textBaseline || 'alphabetic';\n\n // 处理行高:\n // lineHeight为数字时,大于fontSize取lineHeight,小于fontSize时取fontSize\n // lineHeight不为数字时,统一认为lineHeight为'normal',值取1.2 * fontSize\n const lineHeight = calculateLineHeight(character.lineHeight, this.fontSize);\n if (typeof lineHeight === 'number') {\n this.lineHeight = lineHeight > this.fontSize ? lineHeight : this.fontSize;\n } else {\n this.lineHeight = Math.floor(1.2 * this.fontSize);\n }\n\n this.height = this.lineHeight;\n\n const { ascent, height, descent, width } = measureTextCanvas(text, character);\n\n let halfDetaHeight = 0;\n let deltaAscent = 0;\n let deltaDescent = 0;\n if (this.height > height) {\n // measureTextCanvas测量出的是纯文字高度,this.height是考虑行高后的高度\n // 如果this.height > height,将超过的高度平均分配到ascent和descent上\n halfDetaHeight = (this.height - height) / 2;\n deltaAscent = Math.ceil(halfDetaHeight);\n deltaDescent = Math.floor(halfDetaHeight);\n }\n\n if (this.textBaseline === 'top') {\n this.ascent = halfDetaHeight;\n this.descent = height - halfDetaHeight;\n } else if (this.textBaseline === 'bottom') {\n this.ascent = height - halfDetaHeight;\n this.descent = halfDetaHeight;\n } else if (this.textBaseline === 'middle') {\n this.ascent = this.height / 2;\n this.descent = this.height / 2;\n } else {\n this.ascent = ascent + deltaAscent;\n this.descent = descent + deltaDescent;\n }\n\n this.length = text.length;\n this.width = width || 0;\n this.text = text || '';\n this.newLine = newLine || false;\n this.character = character;\n\n this.left = 0;\n this.top = 0;\n\n this.ellipsis = 'normal';\n this.ellipsisWidth = 0;\n this.ellipsisOtherParagraphWidth = 0;\n\n // 处理旋转\n if (character.direction === 'vertical') {\n this.direction = character.direction;\n this.widthOrigin = this.width;\n this.heightOrigin = this.height;\n // const bounds = new Bounds();\n // bounds.set(0, 0, this.width, this.height);\n // bounds.rotate(Math.PI / 2, this.width / 2, this.height / 2);\n // this.bounds = bounds;\n // this.width = bounds.width();\n // this.height = bounds.height();\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n this.lineHeight = this.height;\n }\n }\n\n updateWidth() {\n const { width } = measureTextCanvas(this.text, this.character);\n this.width = width;\n if (this.direction === 'vertical') {\n this.widthOrigin = this.width;\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n }\n }\n\n draw(ctx: IContext2d, baseline: number, deltaLeft: number, isLineFirst: boolean, textAlign: string) {\n let text = this.text;\n let left = this.left + deltaLeft;\n baseline += this.top;\n let direction = this.direction;\n\n if (this.verticalEllipsis) {\n text = '...';\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += '...';\n\n if (textAlign === 'right') {\n left -= this.ellipsisWidth;\n }\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, this.width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n (direction === 'vertical' ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += '...';\n\n if (textAlign === 'right') {\n const { width } = measureTextCanvas(this.text.slice(index), this.character);\n if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n left -= this.ellipsisWidth - width;\n }\n }\n }\n\n // prepareContext(ctx);\n switch (this.character.script) {\n case 'super':\n baseline -= this.ascent * (1 / 3);\n break;\n case 'sub':\n baseline += this.descent / 2;\n break;\n }\n\n // if (isLineFirst) {\n // const result = regFirstSpace.exec(text);\n // if (result?.index !== 0) {\n // text = text.slice(result?.index);\n // }\n // }\n\n // 处理旋转\n if (direction === 'vertical') {\n ctx.save();\n ctx.rotateAbout(Math.PI / 2, left, baseline);\n ctx.translate(-(this.heightOrigin as number) || -this.lineHeight / 2, -this.descent / 2);\n ctx.translate(left, baseline);\n left = 0;\n baseline = 0;\n }\n\n if (this.character.stroke) {\n applyStrokeStyle(ctx, this.character);\n ctx.strokeText(text, left, baseline);\n }\n\n // 下面绘制underline和line-through时需要设置FillStyle\n applyFillStyle(ctx, this.character);\n\n if (this.character.fill) {\n ctx.fillText(text, left, baseline);\n }\n\n if (this.character.fill) {\n if (typeof this.character.lineThrough === 'boolean' || typeof this.character.underline === 'boolean') {\n if (this.character.underline) {\n ctx.fillRect(\n left,\n 1 + baseline,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n if (this.character.lineThrough) {\n ctx.fillRect(\n left,\n 1 + baseline - this.ascent / 2,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n } else if (this.character.textDecoration === 'underline') {\n ctx.fillRect(\n left,\n 1 + baseline,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n } else if (this.character.textDecoration === 'line-through') {\n ctx.fillRect(\n left,\n 1 + baseline - this.ascent / 2,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n }\n\n if (direction === 'vertical') {\n ctx.restore();\n }\n }\n\n getWidthWithEllips(direction: string): number {\n let text = this.text;\n // const direction = this.direction;\n const width = direction === 'vertical' ? this.height : this.width;\n // const height = direction === 'vertical' ? this.width: this.height;\n\n if (this.ellipsis === 'hide') {\n return width;\n } else if (this.ellipsis === 'add') {\n return width + this.ellipsisWidth;\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += '...';\n\n const { width: measureWidth } = measureTextCanvas(this.text.slice(index), this.character);\n return width + this.ellipsisWidth - measureWidth;\n }\n return width;\n }\n}\n\nexport function seperateParagraph(paragraph: Paragraph, index: number) {\n const text1 = paragraph.text.slice(0, index);\n const text2 = paragraph.text.slice(index);\n const p1 = new Paragraph(text1, paragraph.newLine, paragraph.character);\n const p2 = new Paragraph(text2, true, paragraph.character);\n\n return [p1, p2];\n}\n"]}
@@ -15,9 +15,7 @@ export interface IGraphicUtil {
15
15
  height: number;
16
16
  };
17
17
  bindTextMeasure: (tm: ITextMeasure) => void;
18
- createTextMeasureInstance: (textSpec?: Partial<ITextAttribute>, option?: Partial<ITextMeasureOption>, getCanvasForMeasure?: () => any) => TextMeasure<Omit<ITextAttribute, 'lineHeight'> & {
19
- lineHeight?: number;
20
- }>;
18
+ createTextMeasureInstance: (textSpec?: Partial<ITextAttribute>, option?: Partial<ITextMeasureOption>, getCanvasForMeasure?: () => any) => TextMeasure<ITextAttribute>;
21
19
  }
22
20
  export type TransformType = Pick<IGraphicAttribute, 'x' | 'y' | 'scaleX' | 'scaleY' | 'angle' | 'dx' | 'dy'> & {
23
21
  anchor?: IGraphicAttribute['anchor'];
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interface/core.ts"],"names":[],"mappings":"","file":"core.js","sourcesContent":["import type { ICanvas } from './canvas';\nimport type { IContext2d } from './context';\nimport type { IGraphicAttribute } from './graphic';\nimport type { ITextAttribute } from './graphic/text';\nimport type { ILayer, ILayerParams } from './layer';\nimport type { IStage } from './stage';\nimport type { ITextMeasure, TextOptionsType } from './text';\nimport type { IMatrix, IPointLike, ITextMeasureOption, TextMeasure } from '@visactor/vutils';\n\nexport interface IGraphicUtil {\n canvas?: ICanvas;\n context?: IContext2d | null;\n textMeasure: ITextMeasure;\n measureText: (text: string, tc: TextOptionsType) => { width: number; height: number };\n bindTextMeasure: (tm: ITextMeasure) => void;\n createTextMeasureInstance: (\n textSpec?: Partial<ITextAttribute>,\n option?: Partial<ITextMeasureOption>,\n getCanvasForMeasure?: () => any\n ) => TextMeasure<Omit<ITextAttribute, 'lineHeight'> & { lineHeight?: number }>;\n}\n\nexport type TransformType = Pick<IGraphicAttribute, 'x' | 'y' | 'scaleX' | 'scaleY' | 'angle' | 'dx' | 'dy'> & {\n anchor?: IGraphicAttribute['anchor'];\n};\nexport interface ITransformUtil {\n init: (origin: TransformType) => ITransformUtil;\n fromMatrix: (source: IMatrix, target: IMatrix) => ITransformUtil;\n scale: (sx: number, sy: number, center?: IPointLike) => ITransformUtil;\n rotate: (angle: number, center?: IPointLike) => ITransformUtil;\n translate: (dx: number, dy: number) => ITransformUtil;\n}\n\nexport interface ILayerService {\n createLayer: (stage: IStage, options?: Partial<ILayerParams>) => ILayer;\n // stage绘制前调用\n prepareStageLayer: (stage: IStage) => void;\n releaseLayer: (stage: IStage, layer: ILayer) => void;\n restLayerCount: (stage: IStage) => number;\n getStageLayer: (stage: IStage) => ILayer[];\n layerCount: (stage: IStage) => number;\n}\n"]}
1
+ {"version":3,"sources":["../src/interface/core.ts"],"names":[],"mappings":"","file":"core.js","sourcesContent":["import type { ICanvas } from './canvas';\nimport type { IContext2d } from './context';\nimport type { IGraphicAttribute } from './graphic';\nimport type { ITextAttribute } from './graphic/text';\nimport type { ILayer, ILayerParams } from './layer';\nimport type { IStage } from './stage';\nimport type { ITextMeasure, TextOptionsType } from './text';\nimport type { IMatrix, IPointLike, ITextMeasureOption, TextMeasure } from '@visactor/vutils';\n\nexport interface IGraphicUtil {\n canvas?: ICanvas;\n context?: IContext2d | null;\n textMeasure: ITextMeasure;\n measureText: (text: string, tc: TextOptionsType) => { width: number; height: number };\n bindTextMeasure: (tm: ITextMeasure) => void;\n createTextMeasureInstance: (\n textSpec?: Partial<ITextAttribute>,\n option?: Partial<ITextMeasureOption>,\n getCanvasForMeasure?: () => any\n ) => TextMeasure<ITextAttribute>;\n}\n\nexport type TransformType = Pick<IGraphicAttribute, 'x' | 'y' | 'scaleX' | 'scaleY' | 'angle' | 'dx' | 'dy'> & {\n anchor?: IGraphicAttribute['anchor'];\n};\nexport interface ITransformUtil {\n init: (origin: TransformType) => ITransformUtil;\n fromMatrix: (source: IMatrix, target: IMatrix) => ITransformUtil;\n scale: (sx: number, sy: number, center?: IPointLike) => ITransformUtil;\n rotate: (angle: number, center?: IPointLike) => ITransformUtil;\n translate: (dx: number, dy: number) => ITransformUtil;\n}\n\nexport interface ILayerService {\n createLayer: (stage: IStage, options?: Partial<ILayerParams>) => ILayer;\n // stage绘制前调用\n prepareStageLayer: (stage: IStage) => void;\n releaseLayer: (stage: IStage, layer: ILayer) => void;\n restLayerCount: (stage: IStage) => number;\n getStageLayer: (stage: IStage) => ILayer[];\n layerCount: (stage: IStage) => number;\n}\n"]}
@@ -26,7 +26,7 @@ export type RichTextFontStyle = 'normal' | 'italic' | 'oblique';
26
26
  export type RichTextTextDecoration = 'none' | 'underline' | 'line-through';
27
27
  export type RichTextScript = 'normal' | 'sub' | 'super';
28
28
  export type IRichTextBasicCharacter = {
29
- lineHeight?: number;
29
+ lineHeight?: number | string;
30
30
  textAlign?: CanvasTextAlign;
31
31
  textBaseline?: CanvasTextBaseline;
32
32
  direction?: RichTextLayoutDirectionType;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interface/graphic/richText.ts"],"names":[],"mappings":"","file":"richText.js","sourcesContent":["import type { IColor } from '../color';\nimport type { IContext2d } from '../context';\nimport type { IGraphicAttribute, IGraphic } from '../graphic';\nimport type { IImage, IImageGraphicAttribute } from './image';\n\nexport type IRichTextAttribute = {\n width: number;\n height: number;\n ellipsis: boolean | string;\n wordBreak: RichTextWordBreak;\n verticalDirection: RichTextVerticalDirection;\n maxHeight: number;\n maxWidth: number;\n textAlign: RichTextGlobalAlignType;\n textBaseline: RichTextGlobalBaselineType;\n layoutDirection: RichTextLayoutDirectionType;\n textConfig: IRichTextCharacter[];\n singleLine: boolean;\n};\n\nexport type IRichTextGraphicAttribute = Partial<IGraphicAttribute> & Partial<IRichTextAttribute>;\n\nexport type RichTextWordBreak = 'break-word' | 'break-all';\nexport type RichTextVerticalDirection = 'top' | 'middle' | 'bottom';\nexport type RichTextGlobalAlignType = 'left' | 'right' | 'center';\nexport type RichTextGlobalBaselineType = 'top' | 'middle' | 'bottom';\nexport type RichTextLayoutDirectionType = 'horizontal' | 'vertical';\nexport type RichTextFontStyle = 'normal' | 'italic' | 'oblique';\nexport type RichTextTextDecoration = 'none' | 'underline' | 'line-through';\n// export type RichTextTextAlign = 'left' | 'right' | 'center';\nexport type RichTextScript = 'normal' | 'sub' | 'super';\n\nexport type IRichTextBasicCharacter = {\n lineHeight?: number;\n textAlign?: CanvasTextAlign; // left, right, center\n textBaseline?: CanvasTextBaseline;\n direction?: RichTextLayoutDirectionType;\n};\n\nexport type IRichTextParagraphCharacter = IRichTextBasicCharacter & {\n text: string;\n fontSize?: number;\n fontFamily?: string;\n fill?: IColor | boolean;\n stroke?: IColor | boolean;\n fontWeight?: string;\n // lineHeight?: number;\n fontStyle?: RichTextFontStyle; // normal, italic, oblique\n textDecoration?: RichTextTextDecoration; // none, underline, line-through\n // textAlign?: RichTextTextAlign; // left, right, center\n script?: RichTextScript; // normal, sub, super\n underline?: boolean;\n lineThrough?: boolean;\n // direction?: RichTextLayoutDirectionType;\n};\n\nexport type IRichTextImageCharacter = IRichTextBasicCharacter & {\n // 图片基础属性\n image: string | HTMLImageElement | HTMLCanvasElement;\n width: number;\n height: number;\n\n // hover相关属性\n // backgroundShow?: boolean; // 是否显示background\n backgroundShowMode?: 'always' | 'hover';\n backgroundFill?: boolean | IColor; // 背景矩形填充颜色\n backgroundFillOpacity?: number; // 背景矩形填充透明度\n backgroundStroke?: boolean | IColor; // 背景矩形边框颜色\n backgroundStrokeOpacity?: number; // 背景矩形边框透明度\n backgroundRadius?: number; // 背景矩形圆角\n // background size 同时控制了该icon的响应范围\n backgroundWidth?: number;\n backgroundHeight?: number;\n\n // 唯一标识符\n id?: string;\n\n // lineHeight?: number;\n // textAlign?: RichTextTextAlign; // left, right, center\n // direction?: RichTextLayoutDirectionType;\n margin?: number | number[];\n\n funcType?: string;\n hoverImage?: string | HTMLImageElement | HTMLCanvasElement;\n};\n\nexport type IRichTextCharacter = IRichTextParagraphCharacter | IRichTextImageCharacter;\n\nexport type IRichTextIconGraphicAttribute = IImageGraphicAttribute & {\n id?: string;\n backgroundShowMode?: 'always' | 'hover' | 'never';\n backgroundFill?: boolean | IColor; // 背景矩形填充颜色\n backgroundFillOpacity?: number; // 背景矩形填充透明度\n backgroundStroke?: boolean | IColor; // 背景矩形边框颜色\n backgroundStrokeOpacity?: number; // 背景矩形边框透明度\n backgroundRadius?: number; // 背景矩形圆角\n backgroundWidth?: number;\n backgroundHeight?: number;\n\n // lineHeight?: number;\n textAlign?: CanvasTextAlign; // left, right, center\n textBaseline?: CanvasTextBaseline;\n direction?: RichTextLayoutDirectionType;\n\n margin?: number | number[];\n\n // backgroundShow?: boolean;\n};\n\nexport interface IRichTextParagraph {\n text: string;\n ascent: number;\n descent: number;\n width: number;\n height: number;\n lineHeight: number;\n fontSize: number;\n length: number;\n newLine: boolean;\n character: IRichTextParagraphCharacter;\n left: number;\n top: number;\n direction?: 'horizontal' | 'vertical';\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n updateWidth: () => void;\n draw: (ctx: IContext2d, baseline: number, deltaLeft: number, isLineFirst: boolean, textAlign: string) => void;\n getWidthWithEllips: (direction: string) => number;\n}\n\nexport interface IRichTextLine {\n left: number;\n top: number;\n width: number;\n height: number;\n baseline: number;\n ascent: number;\n descent: number;\n paragraphs: (IRichTextParagraph | IRichTextIcon)[];\n actualWidth: number;\n blankWidth: number;\n textAlign: string;\n direction: 'horizontal' | 'vertical';\n directionKey: {\n width: string;\n height: string;\n left: string;\n x: string;\n y: string;\n };\n draw: (\n ctx: IContext2d,\n lastLine: boolean,\n x: number,\n y: number,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) => void;\n getWidthWithEllips: () => number;\n}\n\nexport interface IRichTextFrame {\n left: number;\n top: number;\n bottom: number;\n right: number;\n width: number;\n height: number;\n actualHeight: number;\n ellipsis: boolean | string;\n wordBreak: 'break-word' | 'break-all';\n verticalDirection: 'top' | 'middle' | 'bottom';\n lines: IRichTextLine[];\n globalAlign: 'left' | 'center' | 'right';\n globalBaseline: 'top' | 'middle' | 'bottom';\n layoutDirection: 'horizontal' | 'vertical';\n directionKey: {\n width: string;\n height: string;\n left: string;\n top: string;\n bottom: string;\n };\n isWidthMax: boolean;\n isHeightMax: boolean;\n singleLine: boolean;\n icons: Map<string, IRichTextIcon>;\n draw: (\n ctx: IContext2d,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) => boolean;\n getActualSize: () => {\n width: number;\n height: number;\n };\n getRawActualSize: () => {\n width: number;\n height: number;\n };\n getActualSizeWidthEllipsis: () => {\n width: number;\n height: number;\n };\n}\n\nexport interface IRichText extends IGraphic<IRichTextGraphicAttribute> {\n getFrameCache: () => IRichTextFrame;\n}\n\nexport interface IRichTextIcon extends IImage {\n attribute: IRichTextIconGraphicAttribute;\n richtextId?: string;\n globalX?: number;\n globalY?: number;\n\n _x: number;\n _y: number;\n _hovered: boolean;\n _marginArray: [number, number, number, number];\n\n setHoverState: (hovered: boolean) => void;\n}\n"]}
1
+ {"version":3,"sources":["../src/interface/graphic/richText.ts"],"names":[],"mappings":"","file":"richText.js","sourcesContent":["import type { IColor } from '../color';\nimport type { IContext2d } from '../context';\nimport type { IGraphicAttribute, IGraphic } from '../graphic';\nimport type { IImage, IImageGraphicAttribute } from './image';\n\nexport type IRichTextAttribute = {\n width: number;\n height: number;\n ellipsis: boolean | string;\n wordBreak: RichTextWordBreak;\n verticalDirection: RichTextVerticalDirection;\n maxHeight: number;\n maxWidth: number;\n textAlign: RichTextGlobalAlignType;\n textBaseline: RichTextGlobalBaselineType;\n layoutDirection: RichTextLayoutDirectionType;\n textConfig: IRichTextCharacter[];\n singleLine: boolean;\n};\n\nexport type IRichTextGraphicAttribute = Partial<IGraphicAttribute> & Partial<IRichTextAttribute>;\n\nexport type RichTextWordBreak = 'break-word' | 'break-all';\nexport type RichTextVerticalDirection = 'top' | 'middle' | 'bottom';\nexport type RichTextGlobalAlignType = 'left' | 'right' | 'center';\nexport type RichTextGlobalBaselineType = 'top' | 'middle' | 'bottom';\nexport type RichTextLayoutDirectionType = 'horizontal' | 'vertical';\nexport type RichTextFontStyle = 'normal' | 'italic' | 'oblique';\nexport type RichTextTextDecoration = 'none' | 'underline' | 'line-through';\n// export type RichTextTextAlign = 'left' | 'right' | 'center';\nexport type RichTextScript = 'normal' | 'sub' | 'super';\n\nexport type IRichTextBasicCharacter = {\n lineHeight?: number | string;\n textAlign?: CanvasTextAlign; // left, right, center\n textBaseline?: CanvasTextBaseline;\n direction?: RichTextLayoutDirectionType;\n};\n\nexport type IRichTextParagraphCharacter = IRichTextBasicCharacter & {\n text: string;\n fontSize?: number;\n fontFamily?: string;\n fill?: IColor | boolean;\n stroke?: IColor | boolean;\n fontWeight?: string;\n // lineHeight?: number;\n fontStyle?: RichTextFontStyle; // normal, italic, oblique\n textDecoration?: RichTextTextDecoration; // none, underline, line-through\n // textAlign?: RichTextTextAlign; // left, right, center\n script?: RichTextScript; // normal, sub, super\n underline?: boolean;\n lineThrough?: boolean;\n // direction?: RichTextLayoutDirectionType;\n};\n\nexport type IRichTextImageCharacter = IRichTextBasicCharacter & {\n // 图片基础属性\n image: string | HTMLImageElement | HTMLCanvasElement;\n width: number;\n height: number;\n\n // hover相关属性\n // backgroundShow?: boolean; // 是否显示background\n backgroundShowMode?: 'always' | 'hover';\n backgroundFill?: boolean | IColor; // 背景矩形填充颜色\n backgroundFillOpacity?: number; // 背景矩形填充透明度\n backgroundStroke?: boolean | IColor; // 背景矩形边框颜色\n backgroundStrokeOpacity?: number; // 背景矩形边框透明度\n backgroundRadius?: number; // 背景矩形圆角\n // background size 同时控制了该icon的响应范围\n backgroundWidth?: number;\n backgroundHeight?: number;\n\n // 唯一标识符\n id?: string;\n\n // lineHeight?: number;\n // textAlign?: RichTextTextAlign; // left, right, center\n // direction?: RichTextLayoutDirectionType;\n margin?: number | number[];\n\n funcType?: string;\n hoverImage?: string | HTMLImageElement | HTMLCanvasElement;\n};\n\nexport type IRichTextCharacter = IRichTextParagraphCharacter | IRichTextImageCharacter;\n\nexport type IRichTextIconGraphicAttribute = IImageGraphicAttribute & {\n id?: string;\n backgroundShowMode?: 'always' | 'hover' | 'never';\n backgroundFill?: boolean | IColor; // 背景矩形填充颜色\n backgroundFillOpacity?: number; // 背景矩形填充透明度\n backgroundStroke?: boolean | IColor; // 背景矩形边框颜色\n backgroundStrokeOpacity?: number; // 背景矩形边框透明度\n backgroundRadius?: number; // 背景矩形圆角\n backgroundWidth?: number;\n backgroundHeight?: number;\n\n // lineHeight?: number;\n textAlign?: CanvasTextAlign; // left, right, center\n textBaseline?: CanvasTextBaseline;\n direction?: RichTextLayoutDirectionType;\n\n margin?: number | number[];\n\n // backgroundShow?: boolean;\n};\n\nexport interface IRichTextParagraph {\n text: string;\n ascent: number;\n descent: number;\n width: number;\n height: number;\n lineHeight: number;\n fontSize: number;\n length: number;\n newLine: boolean;\n character: IRichTextParagraphCharacter;\n left: number;\n top: number;\n direction?: 'horizontal' | 'vertical';\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n updateWidth: () => void;\n draw: (ctx: IContext2d, baseline: number, deltaLeft: number, isLineFirst: boolean, textAlign: string) => void;\n getWidthWithEllips: (direction: string) => number;\n}\n\nexport interface IRichTextLine {\n left: number;\n top: number;\n width: number;\n height: number;\n baseline: number;\n ascent: number;\n descent: number;\n paragraphs: (IRichTextParagraph | IRichTextIcon)[];\n actualWidth: number;\n blankWidth: number;\n textAlign: string;\n direction: 'horizontal' | 'vertical';\n directionKey: {\n width: string;\n height: string;\n left: string;\n x: string;\n y: string;\n };\n draw: (\n ctx: IContext2d,\n lastLine: boolean,\n x: number,\n y: number,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) => void;\n getWidthWithEllips: () => number;\n}\n\nexport interface IRichTextFrame {\n left: number;\n top: number;\n bottom: number;\n right: number;\n width: number;\n height: number;\n actualHeight: number;\n ellipsis: boolean | string;\n wordBreak: 'break-word' | 'break-all';\n verticalDirection: 'top' | 'middle' | 'bottom';\n lines: IRichTextLine[];\n globalAlign: 'left' | 'center' | 'right';\n globalBaseline: 'top' | 'middle' | 'bottom';\n layoutDirection: 'horizontal' | 'vertical';\n directionKey: {\n width: string;\n height: string;\n left: string;\n top: string;\n bottom: string;\n };\n isWidthMax: boolean;\n isHeightMax: boolean;\n singleLine: boolean;\n icons: Map<string, IRichTextIcon>;\n draw: (\n ctx: IContext2d,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) => boolean;\n getActualSize: () => {\n width: number;\n height: number;\n };\n getRawActualSize: () => {\n width: number;\n height: number;\n };\n getActualSizeWidthEllipsis: () => {\n width: number;\n height: number;\n };\n}\n\nexport interface IRichText extends IGraphic<IRichTextGraphicAttribute> {\n getFrameCache: () => IRichTextFrame;\n}\n\nexport interface IRichTextIcon extends IImage {\n attribute: IRichTextIconGraphicAttribute;\n richtextId?: string;\n globalX?: number;\n globalY?: number;\n\n _x: number;\n _y: number;\n _hovered: boolean;\n _marginArray: [number, number, number, number];\n\n setHoverState: (hovered: boolean) => void;\n}\n"]}