@visactor/vrender-core 0.21.0-alpha.11 → 0.21.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/color-string/interpolate.js +1 -1
- package/cjs/color-string/store.js +1 -1
- package/cjs/common/3d-interceptor.js +2 -1
- package/cjs/common/canvas-utils.js +0 -1
- package/cjs/common/render-command-list.js +2 -1
- package/cjs/common/simplify.js +1 -2
- package/cjs/common/text.js +1 -1
- package/cjs/common/utils.d.ts +1 -0
- package/cjs/common/utils.js +10 -3
- package/cjs/common/utils.js.map +1 -1
- package/cjs/core/contributions/textMeasure/layout.js +7 -6
- package/cjs/core/contributions/textMeasure/layout.js.map +1 -1
- package/cjs/graphic/text.d.ts +1 -1
- package/cjs/graphic/text.js +6 -6
- package/cjs/graphic/text.js.map +1 -1
- package/dist/index.es.js +18 -9
- package/es/color-string/interpolate.js +1 -1
- package/es/color-string/store.js +1 -1
- package/es/common/3d-interceptor.js +2 -1
- package/es/common/canvas-utils.js +1 -2
- package/es/common/render-command-list.js +2 -1
- package/es/common/simplify.js +1 -2
- package/es/common/text.js +1 -1
- package/es/common/utils.d.ts +1 -0
- package/es/common/utils.js +7 -2
- package/es/common/utils.js.map +1 -1
- package/es/core/contributions/textMeasure/layout.js +7 -6
- package/es/core/contributions/textMeasure/layout.js.map +1 -1
- package/es/graphic/text.d.ts +1 -1
- package/es/graphic/text.js +6 -6
- package/es/graphic/text.js.map +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -8407,13 +8407,17 @@ class RafBasedSTO {
|
|
|
8407
8407
|
}
|
|
8408
8408
|
RafBasedSTO.TimeOut = 1000 / 60;
|
|
8409
8409
|
const rafBasedSto = new RafBasedSTO();
|
|
8410
|
-
const
|
|
8410
|
+
const _calculateLineHeight = (lineHeight, fontSize) => {
|
|
8411
8411
|
if (isString(lineHeight) && lineHeight[lineHeight.length - 1] === '%') {
|
|
8412
8412
|
const scale = Number.parseFloat(lineHeight.substring(0, lineHeight.length - 1)) / 100;
|
|
8413
8413
|
return fontSize * scale;
|
|
8414
8414
|
}
|
|
8415
8415
|
return lineHeight;
|
|
8416
8416
|
};
|
|
8417
|
+
const calculateLineHeight = (lineHeight, fontSize) => {
|
|
8418
|
+
const _lh = _calculateLineHeight(lineHeight, fontSize);
|
|
8419
|
+
return isNaN(_lh) ? _lh : Math.max(fontSize, _lh);
|
|
8420
|
+
};
|
|
8417
8421
|
|
|
8418
8422
|
class IncreaseCount extends ACustomAnimate {
|
|
8419
8423
|
constructor(from, to, duration, easing, params) {
|
|
@@ -19156,7 +19160,7 @@ class CanvasTextLayout {
|
|
|
19156
19160
|
bbox.xOffset = -bbox.width;
|
|
19157
19161
|
}
|
|
19158
19162
|
else {
|
|
19159
|
-
|
|
19163
|
+
bbox.xOffset = 0;
|
|
19160
19164
|
}
|
|
19161
19165
|
if (textBaseline === 'top') {
|
|
19162
19166
|
bbox.yOffset = 0;
|
|
@@ -19270,6 +19274,11 @@ class CanvasTextLayout {
|
|
|
19270
19274
|
line.topOffset -= (lineHeight - actualHeightWithBuf) / 2;
|
|
19271
19275
|
}
|
|
19272
19276
|
}
|
|
19277
|
+
if (textBaseline === 'alphabetic') {
|
|
19278
|
+
const fontBoundingHeight = line.ascent + line.descent;
|
|
19279
|
+
const ratio = lineHeight / fontBoundingHeight;
|
|
19280
|
+
line.topOffset = lineHeight / 2 + ((line.ascent - line.descent) / 2) * ratio + origin[1];
|
|
19281
|
+
}
|
|
19273
19282
|
}
|
|
19274
19283
|
origin[1] += lineHeight;
|
|
19275
19284
|
return line;
|
|
@@ -19418,7 +19427,7 @@ class Text extends Graphic {
|
|
|
19418
19427
|
updateSingallineAABBBounds(text) {
|
|
19419
19428
|
this.updateMultilineAABBBounds([text]);
|
|
19420
19429
|
const layoutData = this.cache.layoutData;
|
|
19421
|
-
if (layoutData) {
|
|
19430
|
+
if (layoutData && layoutData.lines && layoutData.lines.length) {
|
|
19422
19431
|
const line = layoutData.lines[0];
|
|
19423
19432
|
this.cache.clipedText = line.str;
|
|
19424
19433
|
this.cache.clipedWidth = line.width;
|
|
@@ -19447,7 +19456,7 @@ class Text extends Graphic {
|
|
|
19447
19456
|
const attribute = this.attribute;
|
|
19448
19457
|
const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, wrap = textTheme.wrap, measureMode = textTheme.measureMode, lineWidth = textTheme.lineWidth, whiteSpace = textTheme.whiteSpace, suffixPosition = textTheme.suffixPosition, ignoreBuf = textTheme.ignoreBuf, keepCenterInLine = textTheme.keepCenterInLine } = attribute;
|
|
19449
19458
|
const buf = ignoreBuf ? 0 : this.guessLineHeightBuf(fontSize);
|
|
19450
|
-
const lineHeight = this.getLineHeight(attribute, textTheme
|
|
19459
|
+
const lineHeight = this.getLineHeight(attribute, textTheme, buf);
|
|
19451
19460
|
if (whiteSpace === 'normal' || wrap) {
|
|
19452
19461
|
return this.updateWrapAABBBounds(text);
|
|
19453
19462
|
}
|
|
@@ -19481,7 +19490,7 @@ class Text extends Graphic {
|
|
|
19481
19490
|
const textTheme = this.getGraphicTheme();
|
|
19482
19491
|
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, measureMode = textTheme.measureMode, suffixPosition = textTheme.suffixPosition, heightLimit = 0, lineClamp, keepCenterInLine = textTheme.keepCenterInLine } = this.attribute;
|
|
19483
19492
|
const buf = ignoreBuf ? 0 : this.guessLineHeightBuf(fontSize);
|
|
19484
|
-
const lineHeight = this.getLineHeight(this.attribute, textTheme
|
|
19493
|
+
const lineHeight = this.getLineHeight(this.attribute, textTheme, buf);
|
|
19485
19494
|
if (!this.shouldUpdateShape() && ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.layoutData)) {
|
|
19486
19495
|
const bbox = this.cache.layoutData.bbox;
|
|
19487
19496
|
this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
|
|
@@ -19609,7 +19618,7 @@ class Text extends Graphic {
|
|
|
19609
19618
|
let width;
|
|
19610
19619
|
const attribute = this.attribute;
|
|
19611
19620
|
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, suffixPosition = textTheme.suffixPosition } = attribute;
|
|
19612
|
-
const lineHeight = this.getLineHeight(attribute, textTheme);
|
|
19621
|
+
const lineHeight = this.getLineHeight(attribute, textTheme, 0);
|
|
19613
19622
|
let { textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline } = attribute;
|
|
19614
19623
|
if (!verticalMode) {
|
|
19615
19624
|
const t = textAlign;
|
|
@@ -19679,9 +19688,9 @@ class Text extends Graphic {
|
|
|
19679
19688
|
const attribute = this.attribute;
|
|
19680
19689
|
return (_b = (_a = attribute.maxLineWidth) !== null && _a !== void 0 ? _a : attribute.maxWidth) !== null && _b !== void 0 ? _b : theme.maxWidth;
|
|
19681
19690
|
}
|
|
19682
|
-
getLineHeight(attribute, textTheme) {
|
|
19691
|
+
getLineHeight(attribute, textTheme, buf) {
|
|
19683
19692
|
var _a;
|
|
19684
|
-
return ((_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize));
|
|
19693
|
+
return ((_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize) + buf);
|
|
19685
19694
|
}
|
|
19686
19695
|
needUpdateTags(keys, k = TEXT_UPDATE_TAG_KEY) {
|
|
19687
19696
|
return super.needUpdateTags(keys, k);
|
|
@@ -28729,4 +28738,4 @@ const registerFlexLayoutPlugin = () => {
|
|
|
28729
28738
|
Factory.registerPlugin('FlexLayoutPlugin', FlexLayoutPlugin);
|
|
28730
28739
|
};
|
|
28731
28740
|
|
|
28732
|
-
export { ACustomAnimate, ARC3D_NUMBER_TYPE, ARC_NUMBER_TYPE, AREA_NUMBER_TYPE, AbstractGraphicRender, Animate, AnimateGroup, AnimateGroup1, AnimateMode, AnimateStatus, AnimateStepType, Application, Arc, Arc3d, Arc3dRender, ArcRender, ArcRenderContribution, Area, AreaRender, AreaRenderContribution, AttributeAnimate, AttributeUpdateType, AutoEnablePlugins, BaseCanvas, BaseEnvContribution, BaseRender, BaseRenderContributionTime, BaseWindowHandlerContribution, Basis, BeforeRenderConstribution, BoundsContext, BoundsPicker, CIRCLE_NUMBER_TYPE, Canvas3DDrawItemInterceptor, Canvas3DPickItemInterceptor, CanvasFactory, CanvasTextLayout, CbAnimate, Circle, CircleRender, CircleRenderContribution, ClipAngleAnimate, ClipDirectionAnimate, ClipGraphicAnimate, ClipRadiusAnimate, ColorInterpolate, ColorStore, ColorType, CommonDrawItemInterceptorContribution, CommonRenderContribution, Container, ContainerModule, Context2dFactory, ContributionProvider, CurveContext, CurveTypeEnum, CustomEvent, CustomPath2D, CustomSymbolClass, DebugDrawItemInterceptorContribution, DefaultArcAllocate, DefaultArcAttribute, DefaultArcRenderContribution, DefaultAreaAllocate, DefaultAreaAttribute, DefaultAreaTextureRenderContribution, DefaultAttribute, DefaultBaseBackgroundRenderContribution, DefaultBaseInteractiveRenderContribution, DefaultBaseTextureRenderContribution, DefaultCanvasAllocate, DefaultCanvasArcRender, DefaultCanvasAreaRender, DefaultCanvasCircleRender, DefaultCanvasGroupRender, DefaultCanvasImageRender, DefaultCanvasLineRender, DefaultCanvasPathRender, DefaultCanvasPolygonRender, DefaultCanvasRectRender, DefaultCanvasSymbolRender, DefaultCanvasTextRender, DefaultCircleAllocate, DefaultCircleAttribute, DefaultCircleRenderContribution, DefaultConnectAttribute, DefaultDebugAttribute, DefaultFillStyle, DefaultGlobal, DefaultGlobalPickerService, DefaultGlyphAttribute, DefaultGraphicAllocate, DefaultGraphicMemoryManager, DefaultGraphicService, DefaultGraphicUtil, DefaultGroupAttribute, DefaultGroupBackgroundRenderContribution, DefaultImageAttribute, DefaultImageBackgroundRenderContribution, DefaultImageRenderContribution, DefaultLayerService, DefaultLayout, DefaultLineAllocate, DefaultLineAttribute, DefaultMat4Allocate, DefaultMatrixAllocate, DefaultMorphingAnimateConfig, DefaultPathAllocate, DefaultPathAttribute, DefaultPickService, DefaultPickStyle, DefaultPolygonAttribute, DefaultRect3dAttribute, DefaultRectAllocate, DefaultRectAttribute, DefaultRectRenderContribution, DefaultRenderService, DefaultRichTextAttribute, DefaultRichTextIconAttribute, DefaultStateAnimateConfig, DefaultStrokeStyle, DefaultStyle, DefaultSymbolAllocate, DefaultSymbolAttribute, DefaultSymbolRenderContribution, DefaultTextAllocate, DefaultTextAttribute, DefaultTextMeasureContribution, DefaultTextStyle, DefaultTicker, DefaultTimeline, DefaultTransform, DefaultTransformUtil, DefaultWindow, Direction$1 as Direction, DirectionalLight, DrawContribution, DrawItemInterceptor, DynamicLayerHandlerContribution, Edge, EmptyContext2d, EnvContribution, EventManager, EventSystem, EventTarget, FORMAT_ELEMENT_COMMAND, FORMAT_TEXT_COMMAND, Factory, FadeInPlus, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, FlexLayoutPlugin, GLYPH_NUMBER_TYPE, GRAPHIC_UPDATE_TAG_KEY, GROUP_NUMBER_TYPE, Generator, GlobalPickerService, Glyph, GlyphRender, Graphic, GraphicAnimate, GraphicCreator$1 as GraphicCreator, GraphicPicker, GraphicRender, GraphicService, GraphicUtil, Group, GroupFadeIn, GroupFadeOut, GroupRender, GroupRenderContribution, GroupUpdateAABBBoundsMode, HtmlAttributePlugin, IContainPointMode, IMAGE_NUMBER_TYPE, Image, ImageRender, ImageRenderContribution, IncreaseCount, IncrementalDrawContribution, InputText, InteractiveDrawItemInterceptorContribution, InteractivePickItemInterceptorContribution, InteractiveSubRenderContribution, LINE_NUMBER_TYPE, Layer, LayerService, Line$1 as Line, LineRender, Linear, LinearClosed, ManualTickHandler, ManualTicker, Mat4Allocate, MatrixAllocate, MeasureModeEnum, Meteor, MonotoneX, MonotoneY, MorphingPath, MotionPath, MultiToOneMorphingPath, NOWORK_ANIMATE_ATTR, Node, OrthoCamera, PATH_NUMBER_TYPE, POLYGON_NUMBER_TYPE, PURE_STYLE_KEY, PYRAMID3D_NUMBER_TYPE, Path, PathRender, PathRenderContribution, PickItemInterceptor, PickerService, PluginService, Polygon, PolygonRender, PolygonRenderContribution, Pyramid3d, Pyramid3dRender, RAFTickHandler, RECT3D_NUMBER_TYPE, RECT_NUMBER_TYPE, RICHTEXT_NUMBER_TYPE, RafBasedSTO, ReactAttributePlugin, Rect, Rect3DRender, Rect3d, RectRender, RectRenderContribution, ReflectSegContext, RenderSelector, RenderService, ResourceLoader, RichText, RichTextEditPlugin, RichTextRender, RotateBySphereAnimate, SVG_ATTRIBUTE_MAP, SVG_ATTRIBUTE_MAP_KEYS, SVG_PARSE_ATTRIBUTE_MAP, SVG_PARSE_ATTRIBUTE_MAP_KEYS, SYMBOL_NUMBER_TYPE, SegContext, ShadowRoot, ShadowRootDrawItemInterceptorContribution, ShadowRootPickItemInterceptorContribution, SplitRectAfterRenderContribution, SplitRectBeforeRenderContribution, Stage, StaticLayerHandlerContribution, Step$1 as Step, StreamLight, SubAnimate, Symbol$1 as Symbol, SymbolRender, SymbolRenderContribution, TEXT_NUMBER_TYPE, TagPointsUpdate, Text, TextDirection, TextMeasureContribution, TextRender, TextRenderContribution, Theme, TimeOutTickHandler, TransformUtil, UpdateTag, VGlobal, VWindow, ViewTransform3dPlugin, VirtualLayerHandlerContribution, WILDCARD, WindowHandlerContribution, WrapText, XMLParser, _interpolateColor, addArcToBezierPath, addAttributeToPrototype, alignBezierCurves, alignSubpath, application, applyTransformOnBezierCurves, arc3dModule, arcModule, areaModule, bezier, bezierCurversToPath, binarySplitPolygon, bindContributionProvider, bindContributionProviderNoSingletonScope, boundStroke, builtInSymbolStrMap, builtinSymbols, builtinSymbolsMap, calcLineCache, calculateArcCornerRadius, calculateLineHeight, canvasAllocate, centroidOfSubpath, circleBounds, circleModule, clock, cloneGraphic, colorEqual, colorStringInterpolationToStr, container, cornerTangents, createArc, createArc3d, createArea, createCircle, createColor, createConicalGradient, createGlyph, createGroup, createImage, createLine, createMat4, createPath, createPolygon, createPyramid3d, createRect, createRect3d, createRectPath, createRichText, createShadowRoot, createStage, createSymbol, createText, createWrapText, cubicCalc, cubicLength, cubicPointAt, cubicSubdivide, defaultArcAllocate, defaultArcBackgroundRenderContribution, defaultArcRenderContribution, defaultArcTextureRenderContribution, defaultAreaAllocate, defaultBaseBackgroundRenderContribution, defaultBaseTextureRenderContribution, defaultCircleAllocate, defaultCircleBackgroundRenderContribution, defaultCircleRenderContribution, defaultCircleTextureRenderContribution, defaultGraphicMemoryManager, defaultGroupBackgroundRenderContribution, defaultImageBackgroundRenderContribution, defaultImageRenderContribution, defaultLineAllocate, defaultPathAllocate, defaultRectAllocate, defaultRectBackgroundRenderContribution, defaultRectRenderContribution, defaultRectTextureRenderContribution, defaultSymbolAllocate, defaultSymbolBackgroundRenderContribution, defaultSymbolRenderContribution, defaultSymbolTextureRenderContribution, defaultTextAllocate, defaultTicker, defaultTimeline, drawArc, drawArcPath$1 as drawArcPath, drawAreaSegments, drawIncrementalAreaSegments, drawIncrementalSegments, drawPathProxy, drawSegments, enumCommandMap, fillVisible, findBestMorphingRotation, findNextGraphic, flatten_simplify, foreach, foreachAsync, genBasisSegments, genBasisTypeSegments, genLinearClosedSegments, genLinearClosedTypeSegments, genLinearSegments, genLinearTypeSegments, genMonotoneXSegments, genMonotoneXTypeSegments, genMonotoneYSegments, genMonotoneYTypeSegments, genNumberType, genStepSegments, genStepTypeSegments, getAttributeFromDefaultAttrList, getConicGradientAt, getCurrentEnv, getExtraModelMatrix, getModelMatrix, getRichTextBounds, getScaledStroke, getTextBounds, getTheme, getThemeFromGroup, globalTheme, glyphModule, graphicCreator, graphicService, graphicUtil, identityMat4, imageModule, incrementalAddTo, inject, injectable, interpolateColor, interpolateGradientConicalColor, interpolateGradientLinearColor, interpolateGradientRadialColor, interpolatePureColorArray, intersect, isBrowserEnv, isNodeEnv, isSvg, isTransformKey, isXML, layerService, lineModule, lookAt, mat3Tomat4, mat4Allocate, matrixAllocate, morphPath, multiInject, multiToOneMorph, multiplyMat4Mat3, multiplyMat4Mat4, named, newThemeObj, oneToMultiMorph, ortho, parsePadding, parseStroke, parseSvgPath, pathModule, pathToBezierCurves, point$3 as point, pointEqual, pointInterpolation, pointInterpolationHighPerformance, pointsEqual, pointsInterpolation, polygonModule, preLoadAllModule, pyramid3dModule, rafBasedSto, rect3dModule, rectFillVisible, rectModule, rectStrokeVisible, recursiveCallBinarySplit, registerArc3dGraphic, registerArcGraphic, registerAreaGraphic, registerCircleGraphic, registerDirectionalLight, registerFlexLayoutPlugin, registerGlyphGraphic, registerGroupGraphic, registerHtmlAttributePlugin, registerImageGraphic, registerLineGraphic, registerOrthoCamera, registerPathGraphic, registerPolygonGraphic, registerPyramid3dGraphic, registerReactAttributePlugin, registerRect3dGraphic, registerRectGraphic, registerRichtextGraphic, registerShadowRootGraphic, registerSymbolGraphic, registerTextGraphic, registerViewTransform3dPlugin, registerWrapTextGraphic, renderCommandList, rewriteProto, richtextModule, rotateX, rotateY, rotateZ, runFill, runStroke, scaleMat4, segments, shouldUseMat4, snapLength, splitArc, splitArea, splitCircle, splitGraphic, splitLine, splitPath, splitPolygon, splitRect, splitToGrids, strCommandMap, strokeVisible, symbolModule, textAttributesToStyle, textDrawOffsetX, textDrawOffsetY, textLayoutOffsetY, textModule, transformKeys, transformMat4, transformUtil, translate, verticalLayout, vglobal, waitForAllSubLayers, wrapCanvas, wrapContext, xul };
|
|
28741
|
+
export { ACustomAnimate, ARC3D_NUMBER_TYPE, ARC_NUMBER_TYPE, AREA_NUMBER_TYPE, AbstractGraphicRender, Animate, AnimateGroup, AnimateGroup1, AnimateMode, AnimateStatus, AnimateStepType, Application, Arc, Arc3d, Arc3dRender, ArcRender, ArcRenderContribution, Area, AreaRender, AreaRenderContribution, AttributeAnimate, AttributeUpdateType, AutoEnablePlugins, BaseCanvas, BaseEnvContribution, BaseRender, BaseRenderContributionTime, BaseWindowHandlerContribution, Basis, BeforeRenderConstribution, BoundsContext, BoundsPicker, CIRCLE_NUMBER_TYPE, Canvas3DDrawItemInterceptor, Canvas3DPickItemInterceptor, CanvasFactory, CanvasTextLayout, CbAnimate, Circle, CircleRender, CircleRenderContribution, ClipAngleAnimate, ClipDirectionAnimate, ClipGraphicAnimate, ClipRadiusAnimate, ColorInterpolate, ColorStore, ColorType, CommonDrawItemInterceptorContribution, CommonRenderContribution, Container, ContainerModule, Context2dFactory, ContributionProvider, CurveContext, CurveTypeEnum, CustomEvent, CustomPath2D, CustomSymbolClass, DebugDrawItemInterceptorContribution, DefaultArcAllocate, DefaultArcAttribute, DefaultArcRenderContribution, DefaultAreaAllocate, DefaultAreaAttribute, DefaultAreaTextureRenderContribution, DefaultAttribute, DefaultBaseBackgroundRenderContribution, DefaultBaseInteractiveRenderContribution, DefaultBaseTextureRenderContribution, DefaultCanvasAllocate, DefaultCanvasArcRender, DefaultCanvasAreaRender, DefaultCanvasCircleRender, DefaultCanvasGroupRender, DefaultCanvasImageRender, DefaultCanvasLineRender, DefaultCanvasPathRender, DefaultCanvasPolygonRender, DefaultCanvasRectRender, DefaultCanvasSymbolRender, DefaultCanvasTextRender, DefaultCircleAllocate, DefaultCircleAttribute, DefaultCircleRenderContribution, DefaultConnectAttribute, DefaultDebugAttribute, DefaultFillStyle, DefaultGlobal, DefaultGlobalPickerService, DefaultGlyphAttribute, DefaultGraphicAllocate, DefaultGraphicMemoryManager, DefaultGraphicService, DefaultGraphicUtil, DefaultGroupAttribute, DefaultGroupBackgroundRenderContribution, DefaultImageAttribute, DefaultImageBackgroundRenderContribution, DefaultImageRenderContribution, DefaultLayerService, DefaultLayout, DefaultLineAllocate, DefaultLineAttribute, DefaultMat4Allocate, DefaultMatrixAllocate, DefaultMorphingAnimateConfig, DefaultPathAllocate, DefaultPathAttribute, DefaultPickService, DefaultPickStyle, DefaultPolygonAttribute, DefaultRect3dAttribute, DefaultRectAllocate, DefaultRectAttribute, DefaultRectRenderContribution, DefaultRenderService, DefaultRichTextAttribute, DefaultRichTextIconAttribute, DefaultStateAnimateConfig, DefaultStrokeStyle, DefaultStyle, DefaultSymbolAllocate, DefaultSymbolAttribute, DefaultSymbolRenderContribution, DefaultTextAllocate, DefaultTextAttribute, DefaultTextMeasureContribution, DefaultTextStyle, DefaultTicker, DefaultTimeline, DefaultTransform, DefaultTransformUtil, DefaultWindow, Direction$1 as Direction, DirectionalLight, DrawContribution, DrawItemInterceptor, DynamicLayerHandlerContribution, Edge, EmptyContext2d, EnvContribution, EventManager, EventSystem, EventTarget, FORMAT_ELEMENT_COMMAND, FORMAT_TEXT_COMMAND, Factory, FadeInPlus, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, FlexLayoutPlugin, GLYPH_NUMBER_TYPE, GRAPHIC_UPDATE_TAG_KEY, GROUP_NUMBER_TYPE, Generator, GlobalPickerService, Glyph, GlyphRender, Graphic, GraphicAnimate, GraphicCreator$1 as GraphicCreator, GraphicPicker, GraphicRender, GraphicService, GraphicUtil, Group, GroupFadeIn, GroupFadeOut, GroupRender, GroupRenderContribution, GroupUpdateAABBBoundsMode, HtmlAttributePlugin, IContainPointMode, IMAGE_NUMBER_TYPE, Image, ImageRender, ImageRenderContribution, IncreaseCount, IncrementalDrawContribution, InputText, InteractiveDrawItemInterceptorContribution, InteractivePickItemInterceptorContribution, InteractiveSubRenderContribution, LINE_NUMBER_TYPE, Layer, LayerService, Line$1 as Line, LineRender, Linear, LinearClosed, ManualTickHandler, ManualTicker, Mat4Allocate, MatrixAllocate, MeasureModeEnum, Meteor, MonotoneX, MonotoneY, MorphingPath, MotionPath, MultiToOneMorphingPath, NOWORK_ANIMATE_ATTR, Node, OrthoCamera, PATH_NUMBER_TYPE, POLYGON_NUMBER_TYPE, PURE_STYLE_KEY, PYRAMID3D_NUMBER_TYPE, Path, PathRender, PathRenderContribution, PickItemInterceptor, PickerService, PluginService, Polygon, PolygonRender, PolygonRenderContribution, Pyramid3d, Pyramid3dRender, RAFTickHandler, RECT3D_NUMBER_TYPE, RECT_NUMBER_TYPE, RICHTEXT_NUMBER_TYPE, RafBasedSTO, ReactAttributePlugin, Rect, Rect3DRender, Rect3d, RectRender, RectRenderContribution, ReflectSegContext, RenderSelector, RenderService, ResourceLoader, RichText, RichTextEditPlugin, RichTextRender, RotateBySphereAnimate, SVG_ATTRIBUTE_MAP, SVG_ATTRIBUTE_MAP_KEYS, SVG_PARSE_ATTRIBUTE_MAP, SVG_PARSE_ATTRIBUTE_MAP_KEYS, SYMBOL_NUMBER_TYPE, SegContext, ShadowRoot, ShadowRootDrawItemInterceptorContribution, ShadowRootPickItemInterceptorContribution, SplitRectAfterRenderContribution, SplitRectBeforeRenderContribution, Stage, StaticLayerHandlerContribution, Step$1 as Step, StreamLight, SubAnimate, Symbol$1 as Symbol, SymbolRender, SymbolRenderContribution, TEXT_NUMBER_TYPE, TagPointsUpdate, Text, TextDirection, TextMeasureContribution, TextRender, TextRenderContribution, Theme, TimeOutTickHandler, TransformUtil, UpdateTag, VGlobal, VWindow, ViewTransform3dPlugin, VirtualLayerHandlerContribution, WILDCARD, WindowHandlerContribution, WrapText, XMLParser, _calculateLineHeight, _interpolateColor, addArcToBezierPath, addAttributeToPrototype, alignBezierCurves, alignSubpath, application, applyTransformOnBezierCurves, arc3dModule, arcModule, areaModule, bezier, bezierCurversToPath, binarySplitPolygon, bindContributionProvider, bindContributionProviderNoSingletonScope, boundStroke, builtInSymbolStrMap, builtinSymbols, builtinSymbolsMap, calcLineCache, calculateArcCornerRadius, calculateLineHeight, canvasAllocate, centroidOfSubpath, circleBounds, circleModule, clock, cloneGraphic, colorEqual, colorStringInterpolationToStr, container, cornerTangents, createArc, createArc3d, createArea, createCircle, createColor, createConicalGradient, createGlyph, createGroup, createImage, createLine, createMat4, createPath, createPolygon, createPyramid3d, createRect, createRect3d, createRectPath, createRichText, createShadowRoot, createStage, createSymbol, createText, createWrapText, cubicCalc, cubicLength, cubicPointAt, cubicSubdivide, defaultArcAllocate, defaultArcBackgroundRenderContribution, defaultArcRenderContribution, defaultArcTextureRenderContribution, defaultAreaAllocate, defaultBaseBackgroundRenderContribution, defaultBaseTextureRenderContribution, defaultCircleAllocate, defaultCircleBackgroundRenderContribution, defaultCircleRenderContribution, defaultCircleTextureRenderContribution, defaultGraphicMemoryManager, defaultGroupBackgroundRenderContribution, defaultImageBackgroundRenderContribution, defaultImageRenderContribution, defaultLineAllocate, defaultPathAllocate, defaultRectAllocate, defaultRectBackgroundRenderContribution, defaultRectRenderContribution, defaultRectTextureRenderContribution, defaultSymbolAllocate, defaultSymbolBackgroundRenderContribution, defaultSymbolRenderContribution, defaultSymbolTextureRenderContribution, defaultTextAllocate, defaultTicker, defaultTimeline, drawArc, drawArcPath$1 as drawArcPath, drawAreaSegments, drawIncrementalAreaSegments, drawIncrementalSegments, drawPathProxy, drawSegments, enumCommandMap, fillVisible, findBestMorphingRotation, findNextGraphic, flatten_simplify, foreach, foreachAsync, genBasisSegments, genBasisTypeSegments, genLinearClosedSegments, genLinearClosedTypeSegments, genLinearSegments, genLinearTypeSegments, genMonotoneXSegments, genMonotoneXTypeSegments, genMonotoneYSegments, genMonotoneYTypeSegments, genNumberType, genStepSegments, genStepTypeSegments, getAttributeFromDefaultAttrList, getConicGradientAt, getCurrentEnv, getExtraModelMatrix, getModelMatrix, getRichTextBounds, getScaledStroke, getTextBounds, getTheme, getThemeFromGroup, globalTheme, glyphModule, graphicCreator, graphicService, graphicUtil, identityMat4, imageModule, incrementalAddTo, inject, injectable, interpolateColor, interpolateGradientConicalColor, interpolateGradientLinearColor, interpolateGradientRadialColor, interpolatePureColorArray, intersect, isBrowserEnv, isNodeEnv, isSvg, isTransformKey, isXML, layerService, lineModule, lookAt, mat3Tomat4, mat4Allocate, matrixAllocate, morphPath, multiInject, multiToOneMorph, multiplyMat4Mat3, multiplyMat4Mat4, named, newThemeObj, oneToMultiMorph, ortho, parsePadding, parseStroke, parseSvgPath, pathModule, pathToBezierCurves, point$3 as point, pointEqual, pointInterpolation, pointInterpolationHighPerformance, pointsEqual, pointsInterpolation, polygonModule, preLoadAllModule, pyramid3dModule, rafBasedSto, rect3dModule, rectFillVisible, rectModule, rectStrokeVisible, recursiveCallBinarySplit, registerArc3dGraphic, registerArcGraphic, registerAreaGraphic, registerCircleGraphic, registerDirectionalLight, registerFlexLayoutPlugin, registerGlyphGraphic, registerGroupGraphic, registerHtmlAttributePlugin, registerImageGraphic, registerLineGraphic, registerOrthoCamera, registerPathGraphic, registerPolygonGraphic, registerPyramid3dGraphic, registerReactAttributePlugin, registerRect3dGraphic, registerRectGraphic, registerRichtextGraphic, registerShadowRootGraphic, registerSymbolGraphic, registerTextGraphic, registerViewTransform3dPlugin, registerWrapTextGraphic, renderCommandList, rewriteProto, richtextModule, rotateX, rotateY, rotateZ, runFill, runStroke, scaleMat4, segments, shouldUseMat4, snapLength, splitArc, splitArea, splitCircle, splitGraphic, splitLine, splitPath, splitPolygon, splitRect, splitToGrids, strCommandMap, strokeVisible, symbolModule, textAttributesToStyle, textDrawOffsetX, textDrawOffsetY, textLayoutOffsetY, textModule, transformKeys, transformMat4, transformUtil, translate, verticalLayout, vglobal, waitForAllSubLayers, wrapCanvas, wrapContext, xul };
|
|
@@ -97,4 +97,4 @@ export function colorStringInterpolationToStr(fromColor, toColor, ratio) {
|
|
|
97
97
|
return ColorStore.Get(fromColor, ColorType.Color255, _fromColorRGB), ColorStore.Get(toColor, ColorType.Color255, _toColorRGB),
|
|
98
98
|
`rgba(${Math.round(_fromColorRGB[0] + (_toColorRGB[0] - _fromColorRGB[0]) * ratio)},${Math.round(_fromColorRGB[1] + (_toColorRGB[1] - _fromColorRGB[1]) * ratio)},${Math.round(_fromColorRGB[2] + (_toColorRGB[2] - _fromColorRGB[2]) * ratio)},${_fromColorRGB[3] + (_toColorRGB[3] - _fromColorRGB[3]) * ratio})`;
|
|
99
99
|
}
|
|
100
|
-
//# sourceMappingURL=interpolate.js.map
|
|
100
|
+
//# sourceMappingURL=interpolate.js.map
|
package/es/color-string/store.js
CHANGED
|
@@ -48,5 +48,4 @@ function createConicGradient(context, color, x, y, w, h) {
|
|
|
48
48
|
return color.stops.forEach((stop => {
|
|
49
49
|
canvasGradient.addColorStop(stop.offset, stop.color);
|
|
50
50
|
})), canvasGradient.GetPattern(w + x, h + y, undefined);
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=canvas-utils.js.map
|
|
51
|
+
}
|
package/es/common/simplify.js
CHANGED
|
@@ -29,5 +29,4 @@ function simplifyDouglasPeucker(points, sqTolerance) {
|
|
|
29
29
|
export function flatten_simplify(points, tolerance, highestQuality) {
|
|
30
30
|
if (points.length <= 10) return points;
|
|
31
31
|
return points = highestQuality ? points : simplifyRadialDist(points, void 0 !== tolerance ? tolerance * tolerance : 1);
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=simplify.js.map
|
|
32
|
+
}
|
package/es/common/text.js
CHANGED
|
@@ -24,4 +24,4 @@ export function textAttributesToStyle(attrs) {
|
|
|
24
24
|
attrs.underline ? style["text-decoration"] = "underline" : attrs.lineThrough && (style["text-decoration"] = "line-through"),
|
|
25
25
|
attrs.fill && isString(attrs.fill) && (style.color = attrs.fill), style;
|
|
26
26
|
}
|
|
27
|
-
//# sourceMappingURL=text.js.map
|
|
27
|
+
//# sourceMappingURL=text.js.map
|
package/es/common/utils.d.ts
CHANGED
|
@@ -38,4 +38,5 @@ export declare class RafBasedSTO {
|
|
|
38
38
|
appendDuration(d: number): void;
|
|
39
39
|
}
|
|
40
40
|
export declare const rafBasedSto: RafBasedSTO;
|
|
41
|
+
export declare const _calculateLineHeight: (lineHeight: string | number, fontSize: number) => number;
|
|
41
42
|
export declare const calculateLineHeight: (lineHeight: string | number, fontSize: number) => number;
|
package/es/common/utils.js
CHANGED
|
@@ -141,10 +141,15 @@ RafBasedSTO.TimeOut = 1e3 / 60;
|
|
|
141
141
|
|
|
142
142
|
export const rafBasedSto = new RafBasedSTO;
|
|
143
143
|
|
|
144
|
-
export const
|
|
144
|
+
export const _calculateLineHeight = (lineHeight, fontSize) => {
|
|
145
145
|
if (isString(lineHeight) && "%" === lineHeight[lineHeight.length - 1]) {
|
|
146
146
|
return fontSize * (Number.parseFloat(lineHeight.substring(0, lineHeight.length - 1)) / 100);
|
|
147
147
|
}
|
|
148
148
|
return lineHeight;
|
|
149
149
|
};
|
|
150
|
-
|
|
150
|
+
|
|
151
|
+
export const calculateLineHeight = (lineHeight, fontSize) => {
|
|
152
|
+
const _lh = _calculateLineHeight(lineHeight, fontSize);
|
|
153
|
+
return isNaN(_lh) ? _lh : Math.max(fontSize, _lh);
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=utils.js.map
|
package/es/common/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/common/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAK3G,MAAM,CAAN,IAAY,IAOX;AAPD,WAAY,IAAI;IACd,6BAAc,CAAA;IACd,iCAAgB,CAAA;IAChB,mCAAiB,CAAA;IACjB,+BAAe,CAAA;IAEf,8B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EAAE,CAAC,EACtF,IAAI,GAAG,EAAE,CACV,CAAC;IACJ,CAAC;;AAvCM,mBAAO,GAAG,IAAI,GAAG,EAAE,CAAC;AA0C7B,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAE7C,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,UAA2B,EAAE,QAAgB,EAAU,EAAE;IAC3F,IAAI,QAAQ,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE;QACrE,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACtF,OAAO,QAAQ,GAAG,KAAK,CAAC;KACzB;IACD,OAAO,UAAoB,CAAC;AAC9B,CAAC,CAAC","file":"utils.js","sourcesContent":["import type { IBounds, IPointLike } from '@visactor/vutils';\nimport { isBoolean, halfPi, pi, pi2, sin, cos, isArray, pointAt, Point, isString } from '@visactor/vutils';\nimport type { IGraphicAttribute, IStrokeStyle } from '../interface';\n\n// todo: 迁移到@visactor/vutils\n\nexport enum Edge {\n Top = 0b000001,\n Right = 0b000010,\n Bottom = 0b000100,\n Left = 0b001000,\n\n ALL = 0b001111\n}\n\n// 公共的stroke数组,避免大量数组生成\nconst _strokeVec4: [boolean | string, boolean | string, boolean | string, boolean | string] = [\n false,\n false,\n false,\n false\n];\n/**\n * 解析stroke配置\n * @param stroke\n * @returns\n */\nexport const parseStroke = (\n stroke: IStrokeStyle['stroke']\n): {\n isFullStroke: boolean;\n stroke: (boolean | string)[];\n} => {\n let isFullStroke: boolean = true;\n // 首先判断\n if (isBoolean(stroke, true)) {\n for (let i = 0; i < 4; i++) {\n _strokeVec4[i] = stroke as boolean;\n isFullStroke &&= !!(_strokeVec4[i] ?? true);\n }\n isFullStroke = stroke as boolean;\n } else if (Array.isArray(stroke)) {\n // array\n for (let i = 0; i < 4; i++) {\n _strokeVec4[i] = !!stroke[i];\n isFullStroke &&= !!_strokeVec4[i];\n }\n } else {\n _strokeVec4[0] = false;\n _strokeVec4[1] = false;\n _strokeVec4[2] = false;\n _strokeVec4[3] = false;\n }\n\n return {\n isFullStroke,\n stroke: _strokeVec4\n };\n};\n\n// 公共的padding数组,避免大量数组生成\nconst _paddingVec4: [number, number, number, number] = [0, 0, 0, 0];\n/**\n * 解析padding配置\n * @param padding\n * @returns\n */\nexport const parsePadding = (\n padding: IGraphicAttribute['boundsPadding']\n): number | [number, number, number, number] => {\n if (!padding) {\n return 0;\n }\n if (isArray(padding)) {\n if (padding.length === 0) {\n return 0;\n } else if (padding.length === 1) {\n return padding[0];\n } else if (padding.length === 2) {\n _paddingVec4[0] = padding[0];\n _paddingVec4[2] = padding[0];\n _paddingVec4[1] = padding[1];\n _paddingVec4[3] = padding[1];\n return _paddingVec4;\n }\n // 不考虑三个数的情况,三个数是用户传错了\n return padding as [number, number, number, number];\n }\n\n return padding as number;\n};\n\nconst _coords: [IPointLike, IPointLike, IPointLike, IPointLike] = [\n { x: 0, y: 0 },\n { x: 0, y: 0 },\n { x: 0, y: 0 },\n { x: 0, y: 0 }\n];\nconst indexList = [1, 2, 3, 0, 1, 2, 3, 0];\n/**\n * 计算circle一段弧线的bounds\n * @param startAngle 小于2pi\n * @param endAngle\n * @param radius\n * @param bounds\n */\nexport function circleBounds(startAngle: number, endAngle: number, radius: number, bounds: IBounds) {\n // startAngle小于2pi\n // endAngle - startAngle小于2pi\n while (startAngle >= pi2) {\n startAngle -= pi2;\n }\n while (startAngle < 0) {\n startAngle += pi2;\n }\n while (startAngle > endAngle) {\n endAngle += pi2;\n }\n _coords[0].x = radius;\n // _coords[0].y = 0;\n // _coords[1].x = 0;\n _coords[1].y = radius;\n _coords[2].x = -radius;\n // _coords[2].y = -radius;\n // _coords[3].x = 0;\n _coords[3].y = -radius;\n\n // (0,pi/2], (pi/2, pi], (pi, pi/2*3], (pi/2*3, 2pi]\n // 1, 2, 3, 0\n const startIdx = Math.ceil(startAngle / halfPi) % 4;\n const endIdx = Math.ceil(endAngle / halfPi) % 4;\n // console.log(startAngle, endAngle, cos(startAngle), sin(startAngle), cos(endAngle), sin(endAngle));\n bounds.add(cos(startAngle) * radius, sin(startAngle) * radius);\n bounds.add(cos(endAngle) * radius, sin(endAngle) * radius);\n if (startIdx !== endIdx || endAngle - startAngle > pi) {\n let match = false;\n for (let i = 0; i < indexList.length; i++) {\n if (!match && startIdx === indexList[i]) {\n match = true;\n const p = _coords[startIdx];\n bounds.add(p.x, p.y);\n continue;\n } else if (match && endIdx === indexList[i]) {\n break;\n }\n if (match) {\n const p = _coords[indexList[i]];\n bounds.add(p.x, p.y);\n }\n }\n }\n // const delta = Math.floor((endAngle - startAngle) / halfPi);\n // for (let i = 0; i < delta; i++) {\n // const p = _coords[(startIdx + i) % 4];\n // bounds.add(p.x, p.y);\n // }\n\n // // 计算y1, y2\n // const y2 = halfPi >= startAngle && halfPi <= endAngle ? radius : max(sin(startAngle), sin(endAngle)) * radius;\n // const y1 =\n // halfPi + pi >= startAngle && halfPi + pi <= endAngle ? -radius : min(sin(startAngle), sin(endAngle)) * radius;\n // const x2 = pi2 >= startAngle && pi2 <= endAngle ? radius : max(cos(startAngle), cos(endAngle)) * radius;\n // const x1 = pi >= startAngle && pi <= endAngle ? -radius : min(cos(startAngle), cos(endAngle)) * radius;\n\n // // bounds.set(x1, y1, x2, y2);\n // bounds.add(x1, y1);\n // bounds.add(x2, y2);\n}\n\n/**\n * 比较两个点数组是否相同\n * @param pointsA 数组A\n * @param pointsB 数组B\n */\nexport function pointsEqual(pointsA: IPointLike[] | IPointLike, pointsB: IPointLike[] | IPointLike): boolean {\n if (!pointsA || !pointsB) {\n return false;\n } // 需要传入pointsA和pointsB\n if (Array.isArray(pointsA) && Array.isArray(pointsB)) {\n // 如果pointsA和pointsB是数组\n if (pointsA.length !== pointsB.length) {\n return false;\n }\n return pointsA.every((point, index) => pointEqual(point, pointsB[index]));\n }\n if (!Number.isNaN((pointsA as IPointLike).x + (pointsA as IPointLike).y)) {\n // 如果pointA是IPoint(防止参数是undefined)\n return pointEqual(pointsA as IPointLike, pointsB as IPointLike);\n }\n return false;\n}\n\n/**\n * 比较两个点是否相同\n * @param pointA 点A\n * @param pointB 点B\n */\nexport function pointEqual(pointA: IPointLike, pointB: IPointLike): boolean {\n return (\n pointA.x === pointB.x &&\n pointA.y === pointB.y &&\n pointA.x1 === pointB.x1 &&\n pointA.y1 === pointB.y1 &&\n pointA.defined === pointB.defined\n );\n}\n\n/**\n * 两点插值\n * @param pointA 点A\n * @param pointB 点B\n * @param ratio 比例\n */\nexport function pointInterpolation(pointA: IPointLike, pointB: IPointLike, ratio: number): IPointLike {\n const { x, y } = pointAt(pointA.x, pointA.y, pointB.x, pointB.y, ratio);\n const { x: x1, y: y1 } = pointAt(pointA.x1, pointA.y1, pointB.x1, pointB.y1, ratio);\n\n const point = new Point(x as number, y as number, x1, y1);\n point.defined = pointB.defined;\n return point;\n}\n\n/**\n * 两点插值\n * @param pointA 点A\n * @param pointB 点B\n * @param ratio 比例\n */\nexport function pointInterpolationHighPerformance(\n pointA: IPointLike,\n pointB: IPointLike,\n ratio: number,\n point: IPointLike\n): IPointLike {\n const { x, y } = pointAt(pointA.x, pointA.y, pointB.x, pointB.y, ratio);\n const { x: x1, y: y1 } = pointAt(pointA.x1, pointA.y1, pointB.x1, pointB.y1, ratio);\n // const point = new Point(x as number, y as number, x1, y1);\n point.x = x as number;\n point.y = y as number;\n point.x1 = x1;\n point.y1 = y1;\n point.defined = pointB.defined;\n return point;\n}\n\n/**\n * 点数组插值\n * @param pointsA 点数组A\n * @param pointsB 点数组B\n * @param ratio 比例\n */\nexport function pointsInterpolation(\n pointsA: IPointLike[] | IPointLike,\n pointsB: IPointLike[] | IPointLike,\n ratio: number\n): IPointLike[] {\n if (!pointsA || !pointsB) {\n return [];\n } // 需要传入pointsA和pointsB\n if (!Array.isArray(pointsA)) {\n pointsA = [pointsA];\n }\n if (!Array.isArray(pointsB)) {\n pointsB = [pointsB];\n }\n\n let points: IPointLike[] = [];\n if (pointsA.length > pointsB.length) {\n // 如果变短了,那么后面点的直接clip\n points = pointsB.map(point => {\n const p = new Point(point.x, point.y, point.x1, point.y1);\n p.defined = point.defined;\n return p;\n });\n for (let i = 0; i < pointsB.length; i++) {\n points[i] = pointInterpolation(pointsA[i], pointsB[i], ratio);\n }\n } else {\n // 如果变长了,加上后面的点\n points = pointsB.map(point => {\n const p = new Point(point.x, point.y, point.x1, point.y1);\n p.defined = point.defined;\n return p;\n });\n for (let i = 0; i < pointsA.length; i++) {\n points[i] = pointInterpolation(pointsA[i], pointsB[i], ratio);\n }\n }\n return points;\n}\n\nexport const transformKeys = [\n 'x',\n 'y',\n 'dx',\n 'dy',\n 'scaleX',\n 'scaleY',\n 'angle',\n 'anchor',\n 'postMatrix',\n 'scrollX',\n 'scrollY'\n];\nexport const isTransformKey = (key: string) => {\n return transformKeys.includes(key);\n};\n\nexport function getAttributeFromDefaultAttrList(attr: Record<string, any> | Record<string, any>[], key: string) {\n if (isArray(attr)) {\n let val;\n for (let i = 0; i < attr.length && val === undefined; i++) {\n val = attr[i][key];\n }\n return val;\n }\n return attr[key];\n}\n\nexport class RafBasedSTO {\n static TimeOut = 1000 / 60;\n durations: number[];\n timeout: number;\n lastDate: number;\n durationsListThreshold: number;\n\n constructor(timeout: number = RafBasedSTO.TimeOut) {\n this.durations = [];\n this.timeout = timeout;\n this.lastDate = 0;\n this.durationsListThreshold = 30;\n }\n\n call(cb: FrameRequestCallback) {\n this.lastDate = Date.now();\n return setTimeout(\n () => {\n this.appendDuration(Date.now() - this.lastDate);\n cb(0);\n },\n this.timeout,\n true\n );\n }\n\n clear(h: number) {\n clearTimeout(h);\n }\n\n appendDuration(d: number) {\n this.durations.push(d);\n if (this.durations.length > this.durationsListThreshold) {\n this.durations.shift();\n }\n // 最多60fps, 最少30fps\n this.timeout = Math.min(\n Math.max(this.durations.reduce((a, b) => a + b, 0) / this.durations.length, 1000 / 60),\n 1000 / 30\n );\n }\n}\n\nexport const rafBasedSto = new RafBasedSTO();\n\nexport const calculateLineHeight = (lineHeight: string | number, fontSize: number): number => {\n if (isString(lineHeight) && lineHeight[lineHeight.length - 1] === '%') {\n const scale = Number.parseFloat(lineHeight.substring(0, lineHeight.length - 1)) / 100;\n return fontSize * scale;\n }\n return lineHeight as number;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/common/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAK3G,MAAM,CAAN,IAAY,IAOX;AAPD,WAAY,IAAI;IACd,6BAAc,CAAA;IACd,iCAAgB,CAAA;IAChB,mCAAiB,CAAA;IACjB,+BAAe,CAAA;IAEf,8BAAc,CAAA;AAChB,CAAC,EAPW,IAAI,KAAJ,IAAI,QAOf;AAGD,MAAM,WAAW,GAA6E;IAC5F,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;CACN,CAAC;AAMF,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,MAA8B,EAI9B,EAAE;;IACF,IAAI,YAAY,GAAY,IAAI,CAAC;IAEjC,IAAI,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE;QAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;YAC1B,WAAW,CAAC,CAAC,CAAC,GAAG,MAAiB,CAAC;YACnC,YAAY,KAAZ,YAAY,GAAK,CAAC,CAAC,CAAC,MAAA,WAAW,CAAC,CAAC,CAAC,mCAAI,IAAI,CAAC,EAAC;SAC7C;QACD,YAAY,GAAG,MAAiB,CAAC;KAClC;SAAM,IAA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AC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,UAA2B,EAAE,QAAgB,EAAU,EAAE;IAC3F,MAAM,GAAG,GAAG,oBAAoB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IACvD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AACpD,CAAC,CAAC","file":"utils.js","sourcesContent":["import type { IBounds, IPointLike } from '@visactor/vutils';\nimport { isBoolean, halfPi, pi, pi2, sin, cos, isArray, pointAt, Point, isString } from '@visactor/vutils';\nimport type { IGraphicAttribute, IStrokeStyle } from '../interface';\n\n// todo: 迁移到@visactor/vutils\n\nexport enum Edge {\n Top = 0b000001,\n Right = 0b000010,\n Bottom = 0b000100,\n Left = 0b001000,\n\n ALL = 0b001111\n}\n\n// 公共的stroke数组,避免大量数组生成\nconst _strokeVec4: [boolean | string, boolean | string, boolean | string, boolean | string] = [\n false,\n false,\n false,\n false\n];\n/**\n * 解析stroke配置\n * @param stroke\n * @returns\n */\nexport const parseStroke = (\n stroke: IStrokeStyle['stroke']\n): {\n isFullStroke: boolean;\n stroke: (boolean | string)[];\n} => {\n let isFullStroke: boolean = true;\n // 首先判断\n if (isBoolean(stroke, true)) {\n for (let i = 0; i < 4; i++) {\n _strokeVec4[i] = stroke as boolean;\n isFullStroke &&= !!(_strokeVec4[i] ?? true);\n }\n isFullStroke = stroke as boolean;\n } else if (Array.isArray(stroke)) {\n // array\n for (let i = 0; i < 4; i++) {\n _strokeVec4[i] = !!stroke[i];\n isFullStroke &&= !!_strokeVec4[i];\n }\n } else {\n _strokeVec4[0] = false;\n _strokeVec4[1] = false;\n _strokeVec4[2] = false;\n _strokeVec4[3] = false;\n }\n\n return {\n isFullStroke,\n stroke: _strokeVec4\n };\n};\n\n// 公共的padding数组,避免大量数组生成\nconst _paddingVec4: [number, number, number, number] = [0, 0, 0, 0];\n/**\n * 解析padding配置\n * @param padding\n * @returns\n */\nexport const parsePadding = (\n padding: IGraphicAttribute['boundsPadding']\n): number | [number, number, number, number] => {\n if (!padding) {\n return 0;\n }\n if (isArray(padding)) {\n if (padding.length === 0) {\n return 0;\n } else if (padding.length === 1) {\n return padding[0];\n } else if (padding.length === 2) {\n _paddingVec4[0] = padding[0];\n _paddingVec4[2] = padding[0];\n _paddingVec4[1] = padding[1];\n _paddingVec4[3] = padding[1];\n return _paddingVec4;\n }\n // 不考虑三个数的情况,三个数是用户传错了\n return padding as [number, number, number, number];\n }\n\n return padding as number;\n};\n\nconst _coords: [IPointLike, IPointLike, IPointLike, IPointLike] = [\n { x: 0, y: 0 },\n { x: 0, y: 0 },\n { x: 0, y: 0 },\n { x: 0, y: 0 }\n];\nconst indexList = [1, 2, 3, 0, 1, 2, 3, 0];\n/**\n * 计算circle一段弧线的bounds\n * @param startAngle 小于2pi\n * @param endAngle\n * @param radius\n * @param bounds\n */\nexport function circleBounds(startAngle: number, endAngle: number, radius: number, bounds: IBounds) {\n // startAngle小于2pi\n // endAngle - startAngle小于2pi\n while (startAngle >= pi2) {\n startAngle -= pi2;\n }\n while (startAngle < 0) {\n startAngle += pi2;\n }\n while (startAngle > endAngle) {\n endAngle += pi2;\n }\n _coords[0].x = radius;\n // _coords[0].y = 0;\n // _coords[1].x = 0;\n _coords[1].y = radius;\n _coords[2].x = -radius;\n // _coords[2].y = -radius;\n // _coords[3].x = 0;\n _coords[3].y = -radius;\n\n // (0,pi/2], (pi/2, pi], (pi, pi/2*3], (pi/2*3, 2pi]\n // 1, 2, 3, 0\n const startIdx = Math.ceil(startAngle / halfPi) % 4;\n const endIdx = Math.ceil(endAngle / halfPi) % 4;\n // console.log(startAngle, endAngle, cos(startAngle), sin(startAngle), cos(endAngle), sin(endAngle));\n bounds.add(cos(startAngle) * radius, sin(startAngle) * radius);\n bounds.add(cos(endAngle) * radius, sin(endAngle) * radius);\n if (startIdx !== endIdx || endAngle - startAngle > pi) {\n let match = false;\n for (let i = 0; i < indexList.length; i++) {\n if (!match && startIdx === indexList[i]) {\n match = true;\n const p = _coords[startIdx];\n bounds.add(p.x, p.y);\n continue;\n } else if (match && endIdx === indexList[i]) {\n break;\n }\n if (match) {\n const p = _coords[indexList[i]];\n bounds.add(p.x, p.y);\n }\n }\n }\n // const delta = Math.floor((endAngle - startAngle) / halfPi);\n // for (let i = 0; i < delta; i++) {\n // const p = _coords[(startIdx + i) % 4];\n // bounds.add(p.x, p.y);\n // }\n\n // // 计算y1, y2\n // const y2 = halfPi >= startAngle && halfPi <= endAngle ? radius : max(sin(startAngle), sin(endAngle)) * radius;\n // const y1 =\n // halfPi + pi >= startAngle && halfPi + pi <= endAngle ? -radius : min(sin(startAngle), sin(endAngle)) * radius;\n // const x2 = pi2 >= startAngle && pi2 <= endAngle ? radius : max(cos(startAngle), cos(endAngle)) * radius;\n // const x1 = pi >= startAngle && pi <= endAngle ? -radius : min(cos(startAngle), cos(endAngle)) * radius;\n\n // // bounds.set(x1, y1, x2, y2);\n // bounds.add(x1, y1);\n // bounds.add(x2, y2);\n}\n\n/**\n * 比较两个点数组是否相同\n * @param pointsA 数组A\n * @param pointsB 数组B\n */\nexport function pointsEqual(pointsA: IPointLike[] | IPointLike, pointsB: IPointLike[] | IPointLike): boolean {\n if (!pointsA || !pointsB) {\n return false;\n } // 需要传入pointsA和pointsB\n if (Array.isArray(pointsA) && Array.isArray(pointsB)) {\n // 如果pointsA和pointsB是数组\n if (pointsA.length !== pointsB.length) {\n return false;\n }\n return pointsA.every((point, index) => pointEqual(point, pointsB[index]));\n }\n if (!Number.isNaN((pointsA as IPointLike).x + (pointsA as IPointLike).y)) {\n // 如果pointA是IPoint(防止参数是undefined)\n return pointEqual(pointsA as IPointLike, pointsB as IPointLike);\n }\n return false;\n}\n\n/**\n * 比较两个点是否相同\n * @param pointA 点A\n * @param pointB 点B\n */\nexport function pointEqual(pointA: IPointLike, pointB: IPointLike): boolean {\n return (\n pointA.x === pointB.x &&\n pointA.y === pointB.y &&\n pointA.x1 === pointB.x1 &&\n pointA.y1 === pointB.y1 &&\n pointA.defined === pointB.defined\n );\n}\n\n/**\n * 两点插值\n * @param pointA 点A\n * @param pointB 点B\n * @param ratio 比例\n */\nexport function pointInterpolation(pointA: IPointLike, pointB: IPointLike, ratio: number): IPointLike {\n const { x, y } = pointAt(pointA.x, pointA.y, pointB.x, pointB.y, ratio);\n const { x: x1, y: y1 } = pointAt(pointA.x1, pointA.y1, pointB.x1, pointB.y1, ratio);\n\n const point = new Point(x as number, y as number, x1, y1);\n point.defined = pointB.defined;\n return point;\n}\n\n/**\n * 两点插值\n * @param pointA 点A\n * @param pointB 点B\n * @param ratio 比例\n */\nexport function pointInterpolationHighPerformance(\n pointA: IPointLike,\n pointB: IPointLike,\n ratio: number,\n point: IPointLike\n): IPointLike {\n const { x, y } = pointAt(pointA.x, pointA.y, pointB.x, pointB.y, ratio);\n const { x: x1, y: y1 } = pointAt(pointA.x1, pointA.y1, pointB.x1, pointB.y1, ratio);\n // const point = new Point(x as number, y as number, x1, y1);\n point.x = x as number;\n point.y = y as number;\n point.x1 = x1;\n point.y1 = y1;\n point.defined = pointB.defined;\n return point;\n}\n\n/**\n * 点数组插值\n * @param pointsA 点数组A\n * @param pointsB 点数组B\n * @param ratio 比例\n */\nexport function pointsInterpolation(\n pointsA: IPointLike[] | IPointLike,\n pointsB: IPointLike[] | IPointLike,\n ratio: number\n): IPointLike[] {\n if (!pointsA || !pointsB) {\n return [];\n } // 需要传入pointsA和pointsB\n if (!Array.isArray(pointsA)) {\n pointsA = [pointsA];\n }\n if (!Array.isArray(pointsB)) {\n pointsB = [pointsB];\n }\n\n let points: IPointLike[] = [];\n if (pointsA.length > pointsB.length) {\n // 如果变短了,那么后面点的直接clip\n points = pointsB.map(point => {\n const p = new Point(point.x, point.y, point.x1, point.y1);\n p.defined = point.defined;\n return p;\n });\n for (let i = 0; i < pointsB.length; i++) {\n points[i] = pointInterpolation(pointsA[i], pointsB[i], ratio);\n }\n } else {\n // 如果变长了,加上后面的点\n points = pointsB.map(point => {\n const p = new Point(point.x, point.y, point.x1, point.y1);\n p.defined = point.defined;\n return p;\n });\n for (let i = 0; i < pointsA.length; i++) {\n points[i] = pointInterpolation(pointsA[i], pointsB[i], ratio);\n }\n }\n return points;\n}\n\nexport const transformKeys = [\n 'x',\n 'y',\n 'dx',\n 'dy',\n 'scaleX',\n 'scaleY',\n 'angle',\n 'anchor',\n 'postMatrix',\n 'scrollX',\n 'scrollY'\n];\nexport const isTransformKey = (key: string) => {\n return transformKeys.includes(key);\n};\n\nexport function getAttributeFromDefaultAttrList(attr: Record<string, any> | Record<string, any>[], key: string) {\n if (isArray(attr)) {\n let val;\n for (let i = 0; i < attr.length && val === undefined; i++) {\n val = attr[i][key];\n }\n return val;\n }\n return attr[key];\n}\n\nexport class RafBasedSTO {\n static TimeOut = 1000 / 60;\n durations: number[];\n timeout: number;\n lastDate: number;\n durationsListThreshold: number;\n\n constructor(timeout: number = RafBasedSTO.TimeOut) {\n this.durations = [];\n this.timeout = timeout;\n this.lastDate = 0;\n this.durationsListThreshold = 30;\n }\n\n call(cb: FrameRequestCallback) {\n this.lastDate = Date.now();\n return setTimeout(\n () => {\n this.appendDuration(Date.now() - this.lastDate);\n cb(0);\n },\n this.timeout,\n true\n );\n }\n\n clear(h: number) {\n clearTimeout(h);\n }\n\n appendDuration(d: number) {\n this.durations.push(d);\n if (this.durations.length > this.durationsListThreshold) {\n this.durations.shift();\n }\n // 最多60fps, 最少30fps\n this.timeout = Math.min(\n Math.max(this.durations.reduce((a, b) => a + b, 0) / this.durations.length, 1000 / 60),\n 1000 / 30\n );\n }\n}\n\nexport const rafBasedSto = new RafBasedSTO();\n\nexport const _calculateLineHeight = (lineHeight: string | number, fontSize: number): number => {\n if (isString(lineHeight) && lineHeight[lineHeight.length - 1] === '%') {\n const scale = Number.parseFloat(lineHeight.substring(0, lineHeight.length - 1)) / 100;\n return fontSize * scale;\n }\n return lineHeight as number;\n};\n\nexport const calculateLineHeight = (lineHeight: string | number, fontSize: number): number => {\n const _lh = _calculateLineHeight(lineHeight, fontSize);\n return isNaN(_lh) ? _lh : Math.max(fontSize, _lh);\n};\n"]}
|
|
@@ -5,11 +5,8 @@ export class CanvasTextLayout {
|
|
|
5
5
|
this.fontFamily = fontFamily, this.textOptions = options, this.textMeasure = textMeasure;
|
|
6
6
|
}
|
|
7
7
|
LayoutBBox(bbox, textAlign, textBaseline, linesLayout) {
|
|
8
|
-
if ("left" === textAlign || "start" === textAlign
|
|
9
|
-
|
|
10
|
-
bbox.xOffset = -bbox.width;
|
|
11
|
-
}
|
|
12
|
-
if ("top" === textBaseline) bbox.yOffset = 0; else if ("middle" === textBaseline) bbox.yOffset = bbox.height / -2; else if ("alphabetic" === textBaseline) {
|
|
8
|
+
if (bbox.xOffset = "left" === textAlign || "start" === textAlign ? 0 : "center" === textAlign ? bbox.width / -2 : "right" === textAlign || "end" === textAlign ? -bbox.width : 0,
|
|
9
|
+
"top" === textBaseline) bbox.yOffset = 0; else if ("middle" === textBaseline) bbox.yOffset = bbox.height / -2; else if ("alphabetic" === textBaseline) {
|
|
13
10
|
let percent = .79;
|
|
14
11
|
if (1 === linesLayout.length) {
|
|
15
12
|
const lineInfo = linesLayout[0];
|
|
@@ -80,7 +77,11 @@ export class CanvasTextLayout {
|
|
|
80
77
|
line.topOffset = lineHeight / 2 + (line.ascent - line.descent) / 2 + origin[1],
|
|
81
78
|
!line.keepCenterInLine) {
|
|
82
79
|
const buf = 0, actualHeightWithBuf = line.ascent + line.descent + buf;
|
|
83
|
-
actualHeightWithBuf < lineHeight - buf && ("bottom" === textBaseline ? line.topOffset += (lineHeight - actualHeightWithBuf) / 2 : "top" === textBaseline && (line.topOffset -= (lineHeight - actualHeightWithBuf) / 2))
|
|
80
|
+
if (actualHeightWithBuf < lineHeight - buf && ("bottom" === textBaseline ? line.topOffset += (lineHeight - actualHeightWithBuf) / 2 : "top" === textBaseline && (line.topOffset -= (lineHeight - actualHeightWithBuf) / 2)),
|
|
81
|
+
"alphabetic" === textBaseline) {
|
|
82
|
+
const ratio = lineHeight / (line.ascent + line.descent);
|
|
83
|
+
line.topOffset = lineHeight / 2 + (line.ascent - line.descent) / 2 * ratio + origin[1];
|
|
84
|
+
}
|
|
84
85
|
}
|
|
85
86
|
return origin[1] += lineHeight, line;
|
|
86
87
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/contributions/textMeasure/layout.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,OAAO,gBAAgB;IAK3B,YAAY,UAAkB,EAAE,OAAwB,EAAE,WAAyB;QACjF,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IASD,UAAU,CACR,IAAoB,EACpB,SAAwB,EACxB,YAA8B,EAC9B,WAA6B;QAE7B,IAAI,SAAS,KAAK,MAAM,IAAI,SAAS,KAAK,OAAO,EAAE;YACjD,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;SAClB;aAAM,IAAI,SAAS,KAAK,QAAQ,EAAE;YACjC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;SAChC;aAAM,IAAI,SAAS,KAAK,OAAO,IAAI,SAAS,KAAK,KAAK,EAAE;YACvD,IAAI,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;SAC5B;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;SACjC;QAED,IAAI,YAAY,KAAK,KAAK,EAAE;YAC1B,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;SAClB;aAAM,IAAI,YAAY,KAAK,QAAQ,EAAE;YACpC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,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AAgB,EAAE;YAC1B,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC;YAChD,MAAM,GAAG,GAAG,CAAC,CAAC;YACd,MAAM,mBAAmB,GAAG,YAAY,GAAG,GAAG,CAAC;YAC/C,IAAI,mBAAmB,GAAG,UAAU,GAAG,GAAG,EAAE;gBAC1C,IAAI,YAAY,KAAK,QAAQ,EAAE;oBAC7B,IAAI,CAAC,SAAS,IAAI,CAAC,UAAU,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;iBAC1D;qBAAM,IAAI,YAAY,KAAK,KAAK,EAAE;oBACjC,IAAI,CAAC,SAAS,IAAI,CAAC,UAAU,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;iBAC1D;aACF;SACF;QAED,MAAM,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC;QAExB,OAAO,IAAI,CAAC;IACd,CAAC;CACF","file":"layout.js","sourcesContent":["import type { vec2 } from '@visactor/vutils';\nimport type { ITextMeasure, TextOptionsType } from '../../../interface/text';\nimport type { TextLayoutBBox, LayoutItemType, LayoutType, TextAlignType, TextBaselineType } from '../../../interface';\nimport { MeasureModeEnum } from '../../../interface';\n\nexport class CanvasTextLayout {\n private fontFamily: string;\n private textOptions: TextOptionsType;\n private textMeasure: ITextMeasure;\n\n constructor(fontFamily: string, options: TextOptionsType, textMeasure: ITextMeasure) {\n this.fontFamily = fontFamily;\n this.textOptions = options;\n this.textMeasure = textMeasure;\n }\n\n /**\n * 布局外部的盒子,盒子的alphabetic属性模拟文字的效果\n * @param bbox\n * @param textAlign\n * @param textBaseline\n * @returns\n */\n LayoutBBox(\n bbox: TextLayoutBBox,\n textAlign: TextAlignType,\n textBaseline: TextBaselineType,\n linesLayout: LayoutItemType[]\n ): TextLayoutBBox {\n if (textAlign === 'left' || textAlign === 'start') {\n bbox.xOffset = 0;\n } else if (textAlign === 'center') {\n bbox.xOffset = bbox.width / -2;\n } else if (textAlign === 'right' || textAlign === 'end') {\n bbox.xOffset = -bbox.width;\n } else {\n throw new Error('非法的textAlign');\n }\n\n if (textBaseline === 'top') {\n bbox.yOffset = 0;\n } else if (textBaseline === 'middle') {\n bbox.yOffset = bbox.height / -2;\n } else if (textBaseline === 'alphabetic') {\n // 如果仅有一行,要保证和直接使用canvas绘制的textBaseline一致\n let percent = 0.79;\n if (linesLayout.length === 1) {\n const lineInfo = linesLayout[0];\n percent = lineInfo.ascent / (lineInfo.ascent + lineInfo.descent);\n }\n bbox.yOffset = bbox.height * -percent;\n } else {\n bbox.yOffset = -bbox.height;\n }\n\n return bbox;\n }\n\n /**\n * 给定拆分好的每行字符串进行布局,如果传入lineWidth,那么后面的字符就拆分\n * @param lines\n * @param lineWidth\n */\n GetLayoutByLines(\n lines: (string | number)[],\n textAlign: TextAlignType,\n textBaseline: TextBaselineType,\n lineHeight: number,\n suffix: string = '',\n wordBreak: boolean,\n params?: {\n lineWidth?: number;\n suffixPosition?: 'start' | 'end' | 'middle';\n measureMode?: MeasureModeEnum;\n keepCenterInLine?: boolean;\n }\n ): LayoutType {\n const {\n lineWidth,\n suffixPosition = 'end',\n measureMode = MeasureModeEnum.actualBounding,\n keepCenterInLine = false\n } = params ?? {};\n lines = lines.map(l => l.toString()) as string[];\n const linesLayout: LayoutItemType[] = [];\n // bbox高度可能大于totalHeight\n const bboxWH: vec2 = [0, 0];\n if (typeof lineWidth === 'number' && lineWidth !== Infinity) {\n // 直接使用lineWidth,并拆分字符串\n let width: number;\n for (let i = 0, len = lines.length; i < len; i++) {\n const metrics = this.textMeasure.measureTextPixelADscentAndWidth(\n lines[i] as string,\n this.textOptions,\n measureMode\n );\n width = Math.min(metrics.width, lineWidth);\n linesLayout.push({\n str:\n metrics.width <= lineWidth\n ? lines[i].toString()\n : this.textMeasure.clipTextWithSuffix(\n lines[i] as string,\n this.textOptions,\n width,\n suffix,\n wordBreak,\n suffixPosition\n ).str,\n width,\n ascent: metrics.ascent,\n descent: metrics.descent,\n keepCenterInLine\n });\n }\n bboxWH[0] = lineWidth;\n } else {\n // 使用所有行中最长的作为lineWidth\n let _lineWidth = 0;\n let width: number;\n let text: string;\n for (let i = 0, len = lines.length; i < len; i++) {\n text = lines[i] as string;\n const metrics = this.textMeasure.measureTextPixelADscentAndWidth(\n lines[i] as string,\n this.textOptions,\n measureMode\n );\n width = metrics.width;\n _lineWidth = Math.max(_lineWidth, width);\n linesLayout.push({ str: text, width, ascent: metrics.ascent, descent: metrics.descent, keepCenterInLine });\n }\n bboxWH[0] = _lineWidth;\n }\n bboxWH[1] = linesLayout.length * lineHeight;\n\n bboxWH[0] = linesLayout.reduce((a, b) => Math.max(a, b.width), 0);\n\n const bbox: TextLayoutBBox = {\n xOffset: 0,\n yOffset: 0,\n width: bboxWH[0],\n height: bboxWH[1]\n };\n\n this.LayoutBBox(bbox, textAlign, textBaseline, linesLayout);\n\n return this.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);\n }\n\n /**\n * 给定了bbox,使用拆分好的每行字符串进行布局\n * @param bbox\n * @param lines\n * @param textAlign\n * @param textBaseline\n * @param lineHeight\n * @returns\n */\n layoutWithBBox(\n bbox: TextLayoutBBox,\n lines: LayoutItemType[],\n textAlign: TextAlignType,\n textBaseline: TextBaselineType,\n lineHeight: number\n ): LayoutType {\n const origin: vec2 = [0, 0];\n const totalLineHeight = lines.length * lineHeight; // 总高度\n // origin在y方向需要初始化,然后递增即可\n if (textBaseline === 'top') {\n // origin[1] = 0;\n } else if (textBaseline === 'middle') {\n origin[1] = (bbox.height - totalLineHeight) / 2;\n } else if (textBaseline === 'bottom') {\n origin[1] = bbox.height - totalLineHeight;\n }\n\n for (let i = 0; i < lines.length; i++) {\n this.lineOffset(bbox, lines[i], textAlign, textBaseline, lineHeight, origin);\n }\n\n return {\n bbox,\n lines,\n fontFamily: this.fontFamily,\n fontSize: this.textOptions.fontSize,\n fontWeight: this.textOptions.fontWeight,\n lineHeight,\n textAlign,\n textBaseline\n };\n }\n\n /**\n * 计算line在bbox中的位置,需要配合layoutWithBBox使用\n * @param bbox\n * @param line\n * @param textAlign\n * @param textBaseline\n * @param lineHeight\n * @param origin 这个line的左上角位置,会复用并修改\n */\n private lineOffset(\n bbox: TextLayoutBBox,\n line: LayoutItemType,\n textAlign: TextAlignType,\n textBaseline: TextBaselineType,\n lineHeight: number,\n origin: vec2\n ): LayoutItemType {\n if (textAlign === 'left' || textAlign === 'start') {\n line.leftOffset = 0;\n } else if (textAlign === 'center') {\n line.leftOffset = (bbox.width - line.width) / 2;\n } else if (textAlign === 'right' || textAlign === 'end') {\n line.leftOffset = bbox.width - line.width;\n }\n\n line.topOffset = lineHeight / 2 + (line.ascent - line.descent) / 2 + origin[1];\n\n if (!line.keepCenterInLine) {\n const actualHeight = line.ascent + line.descent;\n const buf = 0;\n const actualHeightWithBuf = actualHeight + buf;\n if (actualHeightWithBuf < lineHeight - buf) {\n if (textBaseline === 'bottom') {\n line.topOffset += (lineHeight - actualHeightWithBuf) / 2;\n } else if (textBaseline === 'top') {\n line.topOffset -= (lineHeight - actualHeightWithBuf) / 2;\n }\n }\n }\n\n origin[1] += lineHeight;\n\n return line;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/core/contributions/textMeasure/layout.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,OAAO,gBAAgB;IAK3B,YAAY,UAAkB,EAAE,OAAwB,EAAE,WAAyB;QACjF,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IASD,UAAU,CACR,IAAoB,EACpB,SAAwB,EACxB,YAA8B,EAC9B,WAA6B;QAE7B,IAAI,SAAS,KAAK,MAAM,IAAI,SAAS,KAAK,OAAO,EAAE;YACjD,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;SAClB;aAAM,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AAC,GAAG,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;aAC1F;SACF;QAED,MAAM,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC;QAExB,OAAO,IAAI,CAAC;IACd,CAAC;CACF","file":"layout.js","sourcesContent":["import type { vec2 } from '@visactor/vutils';\nimport type { ITextMeasure, TextOptionsType } from '../../../interface/text';\nimport type { TextLayoutBBox, LayoutItemType, LayoutType, TextAlignType, TextBaselineType } from '../../../interface';\nimport { MeasureModeEnum } from '../../../interface';\n\nexport class CanvasTextLayout {\n private fontFamily: string;\n private textOptions: TextOptionsType;\n private textMeasure: ITextMeasure;\n\n constructor(fontFamily: string, options: TextOptionsType, textMeasure: ITextMeasure) {\n this.fontFamily = fontFamily;\n this.textOptions = options;\n this.textMeasure = textMeasure;\n }\n\n /**\n * 布局外部的盒子,盒子的alphabetic属性模拟文字的效果\n * @param bbox\n * @param textAlign\n * @param textBaseline\n * @returns\n */\n LayoutBBox(\n bbox: TextLayoutBBox,\n textAlign: TextAlignType,\n textBaseline: TextBaselineType,\n linesLayout: LayoutItemType[]\n ): TextLayoutBBox {\n if (textAlign === 'left' || textAlign === 'start') {\n bbox.xOffset = 0;\n } else if (textAlign === 'center') {\n bbox.xOffset = bbox.width / -2;\n } else if (textAlign === 'right' || textAlign === 'end') {\n bbox.xOffset = -bbox.width;\n } else {\n bbox.xOffset = 0;\n }\n\n if (textBaseline === 'top') {\n bbox.yOffset = 0;\n } else if (textBaseline === 'middle') {\n bbox.yOffset = bbox.height / -2;\n } else if (textBaseline === 'alphabetic') {\n // 如果仅有一行,要保证和直接使用canvas绘制的textBaseline一致\n let percent = 0.79;\n if (linesLayout.length === 1) {\n const lineInfo = linesLayout[0];\n percent = lineInfo.ascent / (lineInfo.ascent + lineInfo.descent);\n }\n bbox.yOffset = bbox.height * -percent;\n } else {\n bbox.yOffset = -bbox.height;\n }\n\n return bbox;\n }\n\n /**\n * 给定拆分好的每行字符串进行布局,如果传入lineWidth,那么后面的字符就拆分\n * @param lines\n * @param lineWidth\n */\n GetLayoutByLines(\n lines: (string | number)[],\n textAlign: TextAlignType,\n textBaseline: TextBaselineType,\n lineHeight: number,\n suffix: string = '',\n wordBreak: boolean,\n params?: {\n lineWidth?: number;\n suffixPosition?: 'start' | 'end' | 'middle';\n measureMode?: MeasureModeEnum;\n keepCenterInLine?: boolean;\n }\n ): LayoutType {\n const {\n lineWidth,\n suffixPosition = 'end',\n measureMode = MeasureModeEnum.actualBounding,\n keepCenterInLine = false\n } = params ?? {};\n lines = lines.map(l => l.toString()) as string[];\n const linesLayout: LayoutItemType[] = [];\n // bbox高度可能大于totalHeight\n const bboxWH: vec2 = [0, 0];\n if (typeof lineWidth === 'number' && lineWidth !== Infinity) {\n // 直接使用lineWidth,并拆分字符串\n let width: number;\n for (let i = 0, len = lines.length; i < len; i++) {\n const metrics = this.textMeasure.measureTextPixelADscentAndWidth(\n lines[i] as string,\n this.textOptions,\n measureMode\n );\n width = Math.min(metrics.width, lineWidth);\n linesLayout.push({\n str:\n metrics.width <= lineWidth\n ? lines[i].toString()\n : this.textMeasure.clipTextWithSuffix(\n lines[i] as string,\n this.textOptions,\n width,\n suffix,\n wordBreak,\n suffixPosition\n ).str,\n width,\n ascent: metrics.ascent,\n descent: metrics.descent,\n keepCenterInLine\n });\n }\n bboxWH[0] = lineWidth;\n } else {\n // 使用所有行中最长的作为lineWidth\n let _lineWidth = 0;\n let width: number;\n let text: string;\n for (let i = 0, len = lines.length; i < len; i++) {\n text = lines[i] as string;\n const metrics = this.textMeasure.measureTextPixelADscentAndWidth(\n lines[i] as string,\n this.textOptions,\n measureMode\n );\n width = metrics.width;\n _lineWidth = Math.max(_lineWidth, width);\n linesLayout.push({ str: text, width, ascent: metrics.ascent, descent: metrics.descent, keepCenterInLine });\n }\n bboxWH[0] = _lineWidth;\n }\n bboxWH[1] = linesLayout.length * lineHeight;\n\n bboxWH[0] = linesLayout.reduce((a, b) => Math.max(a, b.width), 0);\n\n const bbox: TextLayoutBBox = {\n xOffset: 0,\n yOffset: 0,\n width: bboxWH[0],\n height: bboxWH[1]\n };\n\n this.LayoutBBox(bbox, textAlign, textBaseline, linesLayout);\n\n return this.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);\n }\n\n /**\n * 给定了bbox,使用拆分好的每行字符串进行布局\n * @param bbox\n * @param lines\n * @param textAlign\n * @param textBaseline\n * @param lineHeight\n * @returns\n */\n layoutWithBBox(\n bbox: TextLayoutBBox,\n lines: LayoutItemType[],\n textAlign: TextAlignType,\n textBaseline: TextBaselineType,\n lineHeight: number\n ): LayoutType {\n const origin: vec2 = [0, 0];\n const totalLineHeight = lines.length * lineHeight; // 总高度\n // origin在y方向需要初始化,然后递增即可\n if (textBaseline === 'top') {\n // origin[1] = 0;\n } else if (textBaseline === 'middle') {\n origin[1] = (bbox.height - totalLineHeight) / 2;\n } else if (textBaseline === 'bottom') {\n origin[1] = bbox.height - totalLineHeight;\n }\n\n for (let i = 0; i < lines.length; i++) {\n this.lineOffset(bbox, lines[i], textAlign, textBaseline, lineHeight, origin);\n }\n\n return {\n bbox,\n lines,\n fontFamily: this.fontFamily,\n fontSize: this.textOptions.fontSize,\n fontWeight: this.textOptions.fontWeight,\n lineHeight,\n textAlign,\n textBaseline\n };\n }\n\n /**\n * 计算line在bbox中的位置,需要配合layoutWithBBox使用\n * @param bbox\n * @param line\n * @param textAlign\n * @param textBaseline\n * @param lineHeight\n * @param origin 这个line的左上角位置,会复用并修改\n */\n private lineOffset(\n bbox: TextLayoutBBox,\n line: LayoutItemType,\n textAlign: TextAlignType,\n textBaseline: TextBaselineType,\n lineHeight: number,\n origin: vec2\n ): LayoutItemType {\n if (textAlign === 'left' || textAlign === 'start') {\n line.leftOffset = 0;\n } else if (textAlign === 'center') {\n line.leftOffset = (bbox.width - line.width) / 2;\n } else if (textAlign === 'right' || textAlign === 'end') {\n line.leftOffset = bbox.width - line.width;\n }\n\n line.topOffset = lineHeight / 2 + (line.ascent - line.descent) / 2 + origin[1];\n\n // 在行内进行偏移\n if (!line.keepCenterInLine) {\n const actualHeight = line.ascent + line.descent;\n const buf = 0;\n const actualHeightWithBuf = actualHeight + buf;\n if (actualHeightWithBuf < lineHeight - buf) {\n if (textBaseline === 'bottom') {\n line.topOffset += (lineHeight - actualHeightWithBuf) / 2;\n } else if (textBaseline === 'top') {\n line.topOffset -= (lineHeight - actualHeightWithBuf) / 2;\n }\n }\n if (textBaseline === 'alphabetic') {\n const fontBoundingHeight = line.ascent + line.descent;\n const ratio = lineHeight / fontBoundingHeight;\n line.topOffset = lineHeight / 2 + ((line.ascent - line.descent) / 2) * ratio + origin[1];\n }\n }\n\n origin[1] += lineHeight;\n\n return line;\n }\n}\n"]}
|
package/es/graphic/text.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export declare class Text extends Graphic<ITextGraphicAttribute> implements ITex
|
|
|
62
62
|
updateWrapAABBBounds(text: (number | string) | (number | string)[]): import("@visactor/vutils").IBounds;
|
|
63
63
|
updateVerticalMultilineAABBBounds(text: (number | string)[]): IAABBBounds;
|
|
64
64
|
protected getMaxWidth(theme: ITextGraphicAttribute): number;
|
|
65
|
-
protected getLineHeight(attribute: ITextGraphicAttribute, textTheme: ITextGraphicAttribute): number;
|
|
65
|
+
protected getLineHeight(attribute: ITextGraphicAttribute, textTheme: ITextGraphicAttribute, buf: number): number;
|
|
66
66
|
protected needUpdateTags(keys: string[], k?: string[]): boolean;
|
|
67
67
|
protected needUpdateTag(key: string, k?: string[]): boolean;
|
|
68
68
|
clone(): Text;
|
package/es/graphic/text.js
CHANGED
|
@@ -102,7 +102,7 @@ export class Text extends Graphic {
|
|
|
102
102
|
updateSingallineAABBBounds(text) {
|
|
103
103
|
this.updateMultilineAABBBounds([ text ]);
|
|
104
104
|
const layoutData = this.cache.layoutData;
|
|
105
|
-
if (layoutData) {
|
|
105
|
+
if (layoutData && layoutData.lines && layoutData.lines.length) {
|
|
106
106
|
const line = layoutData.lines[0];
|
|
107
107
|
this.cache.clipedText = line.str, this.cache.clipedWidth = line.width;
|
|
108
108
|
}
|
|
@@ -118,7 +118,7 @@ export class Text extends Graphic {
|
|
|
118
118
|
}
|
|
119
119
|
updateHorizontalMultilineAABBBounds(text) {
|
|
120
120
|
var _a;
|
|
121
|
-
const textTheme = this.getGraphicTheme(), attribute = this.attribute, {fontFamily: fontFamily = textTheme.fontFamily, textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline, fontSize: fontSize = textTheme.fontSize, fontWeight: fontWeight = textTheme.fontWeight, ellipsis: ellipsis = textTheme.ellipsis, maxLineWidth: maxLineWidth, stroke: stroke = textTheme.stroke, wrap: wrap = textTheme.wrap, measureMode: measureMode = textTheme.measureMode, lineWidth: lineWidth = textTheme.lineWidth, whiteSpace: whiteSpace = textTheme.whiteSpace, suffixPosition: suffixPosition = textTheme.suffixPosition, ignoreBuf: ignoreBuf = textTheme.ignoreBuf, keepCenterInLine: keepCenterInLine = textTheme.keepCenterInLine} = attribute, buf = ignoreBuf ? 0 : this.guessLineHeightBuf(fontSize), lineHeight = this.getLineHeight(attribute, textTheme
|
|
121
|
+
const textTheme = this.getGraphicTheme(), attribute = this.attribute, {fontFamily: fontFamily = textTheme.fontFamily, textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline, fontSize: fontSize = textTheme.fontSize, fontWeight: fontWeight = textTheme.fontWeight, ellipsis: ellipsis = textTheme.ellipsis, maxLineWidth: maxLineWidth, stroke: stroke = textTheme.stroke, wrap: wrap = textTheme.wrap, measureMode: measureMode = textTheme.measureMode, lineWidth: lineWidth = textTheme.lineWidth, whiteSpace: whiteSpace = textTheme.whiteSpace, suffixPosition: suffixPosition = textTheme.suffixPosition, ignoreBuf: ignoreBuf = textTheme.ignoreBuf, keepCenterInLine: keepCenterInLine = textTheme.keepCenterInLine} = attribute, buf = ignoreBuf ? 0 : this.guessLineHeightBuf(fontSize), lineHeight = this.getLineHeight(attribute, textTheme, buf);
|
|
122
122
|
if ("normal" === whiteSpace || wrap) return this.updateWrapAABBBounds(text);
|
|
123
123
|
if (!this.shouldUpdateShape() && (null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData)) {
|
|
124
124
|
const bbox = this.cache.layoutData.bbox;
|
|
@@ -141,7 +141,7 @@ export class Text extends Graphic {
|
|
|
141
141
|
}
|
|
142
142
|
updateWrapAABBBounds(text) {
|
|
143
143
|
var _a, _b, _c;
|
|
144
|
-
const textTheme = this.getGraphicTheme(), {fontFamily: fontFamily = textTheme.fontFamily, textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline, fontSize: fontSize = textTheme.fontSize, ellipsis: ellipsis = textTheme.ellipsis, maxLineWidth: maxLineWidth, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, wordBreak: wordBreak = textTheme.wordBreak, fontWeight: fontWeight = textTheme.fontWeight, ignoreBuf: ignoreBuf = textTheme.ignoreBuf, measureMode: measureMode = textTheme.measureMode, suffixPosition: suffixPosition = textTheme.suffixPosition, heightLimit: heightLimit = 0, lineClamp: lineClamp, keepCenterInLine: keepCenterInLine = textTheme.keepCenterInLine} = this.attribute, buf = ignoreBuf ? 0 : this.guessLineHeightBuf(fontSize), lineHeight = this.getLineHeight(this.attribute, textTheme
|
|
144
|
+
const textTheme = this.getGraphicTheme(), {fontFamily: fontFamily = textTheme.fontFamily, textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline, fontSize: fontSize = textTheme.fontSize, ellipsis: ellipsis = textTheme.ellipsis, maxLineWidth: maxLineWidth, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, wordBreak: wordBreak = textTheme.wordBreak, fontWeight: fontWeight = textTheme.fontWeight, ignoreBuf: ignoreBuf = textTheme.ignoreBuf, measureMode: measureMode = textTheme.measureMode, suffixPosition: suffixPosition = textTheme.suffixPosition, heightLimit: heightLimit = 0, lineClamp: lineClamp, keepCenterInLine: keepCenterInLine = textTheme.keepCenterInLine} = this.attribute, buf = ignoreBuf ? 0 : this.guessLineHeightBuf(fontSize), lineHeight = this.getLineHeight(this.attribute, textTheme, buf);
|
|
145
145
|
if (!this.shouldUpdateShape() && (null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData)) {
|
|
146
146
|
const bbox = this.cache.layoutData.bbox;
|
|
147
147
|
return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height),
|
|
@@ -239,7 +239,7 @@ export class Text extends Graphic {
|
|
|
239
239
|
var _a, _b;
|
|
240
240
|
const textTheme = this.getGraphicTheme(), textMeasure = application.graphicUtil.textMeasure;
|
|
241
241
|
let width;
|
|
242
|
-
const attribute = this.attribute, {maxLineWidth: maxLineWidth = textTheme.maxLineWidth, ellipsis: ellipsis = textTheme.ellipsis, fontFamily: fontFamily = textTheme.fontFamily, fontSize: fontSize = textTheme.fontSize, fontWeight: fontWeight = textTheme.fontWeight, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, verticalMode: verticalMode = textTheme.verticalMode, suffixPosition: suffixPosition = textTheme.suffixPosition} = attribute, lineHeight = this.getLineHeight(attribute, textTheme);
|
|
242
|
+
const attribute = this.attribute, {maxLineWidth: maxLineWidth = textTheme.maxLineWidth, ellipsis: ellipsis = textTheme.ellipsis, fontFamily: fontFamily = textTheme.fontFamily, fontSize: fontSize = textTheme.fontSize, fontWeight: fontWeight = textTheme.fontWeight, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, verticalMode: verticalMode = textTheme.verticalMode, suffixPosition: suffixPosition = textTheme.suffixPosition} = attribute, lineHeight = this.getLineHeight(attribute, textTheme, 0);
|
|
243
243
|
let {textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline} = attribute;
|
|
244
244
|
if (!verticalMode) {
|
|
245
245
|
const t = textAlign;
|
|
@@ -292,9 +292,9 @@ export class Text extends Graphic {
|
|
|
292
292
|
const attribute = this.attribute;
|
|
293
293
|
return null !== (_b = null !== (_a = attribute.maxLineWidth) && void 0 !== _a ? _a : attribute.maxWidth) && void 0 !== _b ? _b : theme.maxWidth;
|
|
294
294
|
}
|
|
295
|
-
getLineHeight(attribute, textTheme) {
|
|
295
|
+
getLineHeight(attribute, textTheme, buf) {
|
|
296
296
|
var _a;
|
|
297
|
-
return null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : attribute.fontSize || textTheme.fontSize;
|
|
297
|
+
return null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
|
|
298
298
|
}
|
|
299
299
|
needUpdateTags(keys, k = TEXT_UPDATE_TAG_KEY) {
|
|
300
300
|
return super.needUpdateTags(keys, k);
|