fabric-vectr 6.7.15 → 6.7.17
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/dist/dist/index.d.mts +13871 -0
- package/dist/dist/index.d.mts.map +1 -0
- package/dist/dist/index.mjs +26926 -0
- package/dist/dist/index.mjs.map +1 -0
- package/dist/dist/src/util/internals/cloneStyles.d.mts +2 -0
- package/dist/dist/src/util/internals/cloneStyles.d.mts.map +1 -0
- package/dist/dist/src/util/internals/cloneStyles.mjs +15 -0
- package/dist/dist/src/util/internals/cloneStyles.mjs.map +1 -0
- package/dist/extensions/aligning_guidelines/constant.js +9 -0
- package/dist/extensions/aligning_guidelines/constant.js.map +1 -0
- package/dist/extensions/aligning_guidelines/index.js +132 -0
- package/dist/extensions/aligning_guidelines/index.js.map +1 -0
- package/dist/extensions/aligning_guidelines/typedefs.js +2 -0
- package/dist/extensions/aligning_guidelines/typedefs.js.map +1 -0
- package/dist/extensions/aligning_guidelines/util/basic.js +12 -0
- package/dist/extensions/aligning_guidelines/util/basic.js.map +1 -0
- package/dist/extensions/aligning_guidelines/util/basic.spec.d.ts +2 -0
- package/dist/extensions/aligning_guidelines/util/basic.spec.d.ts.map +1 -0
- package/dist/extensions/aligning_guidelines/util/basic.spec.js +30 -0
- package/dist/extensions/aligning_guidelines/util/basic.spec.js.map +1 -0
- package/dist/extensions/aligning_guidelines/util/collect-line.js +129 -0
- package/dist/extensions/aligning_guidelines/util/collect-line.js.map +1 -0
- package/dist/extensions/aligning_guidelines/util/collect-point.js +78 -0
- package/dist/extensions/aligning_guidelines/util/collect-point.js.map +1 -0
- package/dist/extensions/aligning_guidelines/util/draw.js +67 -0
- package/dist/extensions/aligning_guidelines/util/draw.js.map +1 -0
- package/dist/extensions/aligning_guidelines/util/get-objects-by-target.js +44 -0
- package/dist/extensions/aligning_guidelines/util/get-objects-by-target.js.map +1 -0
- package/dist/extensions/data_updaters/origins/index.js +36 -0
- package/dist/extensions/data_updaters/origins/index.js.map +1 -0
- package/dist/extensions/data_updaters/origins/index.spec.d.ts +2 -0
- package/dist/extensions/data_updaters/origins/index.spec.d.ts.map +1 -0
- package/dist/extensions/data_updaters/origins/index.spec.js +94 -0
- package/dist/extensions/data_updaters/origins/index.spec.js.map +1 -0
- package/dist/extensions/index.js +3 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/fabric.js +101 -0
- package/dist/fabric.js.map +1 -0
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +6 -3
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +6 -3
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +37 -0
- package/dist/index.node.js.map +1 -0
- package/dist/index.node.mjs +6 -3
- package/dist/index.node.mjs.map +1 -1
- package/dist/package.json +178 -0
- package/dist/package.json.min.mjs +1 -1
- package/dist/package.json.mjs +1 -1
- package/dist/src/ClassRegistry.js +49 -0
- package/dist/src/ClassRegistry.js.map +1 -0
- package/dist/src/Collection.js +295 -0
- package/dist/src/Collection.js.map +1 -0
- package/dist/src/CommonMethods.js +58 -0
- package/dist/src/CommonMethods.js.map +1 -0
- package/dist/src/EventTypeDefs.js +2 -0
- package/dist/src/EventTypeDefs.js.map +1 -0
- package/dist/src/Intersection.js +250 -0
- package/dist/src/Intersection.js.map +1 -0
- package/dist/src/LayoutManager/ActiveSelectionLayoutManager.js +47 -0
- package/dist/src/LayoutManager/ActiveSelectionLayoutManager.js.map +1 -0
- package/dist/src/LayoutManager/LayoutManager.js +238 -0
- package/dist/src/LayoutManager/LayoutManager.js.map +1 -0
- package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.js +60 -0
- package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.js.map +1 -0
- package/dist/src/LayoutManager/LayoutStrategies/FitContentLayout.js +18 -0
- package/dist/src/LayoutManager/LayoutStrategies/FitContentLayout.js.map +1 -0
- package/dist/src/LayoutManager/LayoutStrategies/FixedLayout.js +17 -0
- package/dist/src/LayoutManager/LayoutStrategies/FixedLayout.js.map +1 -0
- package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.js +80 -0
- package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.js.map +1 -0
- package/dist/src/LayoutManager/LayoutStrategies/utils.js +28 -0
- package/dist/src/LayoutManager/LayoutStrategies/utils.js.map +1 -0
- package/dist/src/LayoutManager/constants.js +7 -0
- package/dist/src/LayoutManager/constants.js.map +1 -0
- package/dist/src/LayoutManager/index.js +7 -0
- package/dist/src/LayoutManager/index.js.map +1 -0
- package/dist/src/LayoutManager/types.js +2 -0
- package/dist/src/LayoutManager/types.js.map +1 -0
- package/dist/src/Observable.js +107 -0
- package/dist/src/Observable.js.map +1 -0
- package/dist/src/Pattern/Pattern.js +152 -0
- package/dist/src/Pattern/Pattern.js.map +1 -0
- package/dist/src/Pattern/index.js +3 -0
- package/dist/src/Pattern/index.js.map +1 -0
- package/dist/src/Pattern/types.js +2 -0
- package/dist/src/Pattern/types.js.map +1 -0
- package/dist/src/Point.js +330 -0
- package/dist/src/Point.js.map +1 -0
- package/dist/src/Shadow.js +125 -0
- package/dist/src/Shadow.js.map +1 -0
- package/dist/src/benchmarks/boundingBoxFromPoint.d.mts +2 -0
- package/dist/src/benchmarks/boundingBoxFromPoint.d.mts.map +1 -0
- package/dist/src/benchmarks/boundingBoxFromPoint.mjs +54 -0
- package/dist/src/benchmarks/boundingBoxFromPoint.mjs.map +1 -0
- package/dist/src/benchmarks/calcCornerCoords.d.mts +2 -0
- package/dist/src/benchmarks/calcCornerCoords.d.mts.map +1 -0
- package/dist/src/benchmarks/calcCornerCoords.mjs +78 -0
- package/dist/src/benchmarks/calcCornerCoords.mjs.map +1 -0
- package/dist/src/benchmarks/calcTransformMatrix.d.mts +2 -0
- package/dist/src/benchmarks/calcTransformMatrix.d.mts.map +1 -0
- package/dist/src/benchmarks/calcTransformMatrix.mjs +71 -0
- package/dist/src/benchmarks/calcTransformMatrix.mjs.map +1 -0
- package/dist/src/benchmarks/cloneStyles.d.mts +2 -0
- package/dist/src/benchmarks/cloneStyles.d.mts.map +1 -0
- package/dist/src/benchmarks/cloneStyles.mjs +56 -0
- package/dist/src/benchmarks/cloneStyles.mjs.map +1 -0
- package/dist/src/benchmarks/pathCloning.d.mts +2 -0
- package/dist/src/benchmarks/pathCloning.d.mts.map +1 -0
- package/dist/src/benchmarks/pathCloning.mjs +94 -0
- package/dist/src/benchmarks/pathCloning.mjs.map +1 -0
- package/dist/src/benchmarks/pathData.d.mts +3 -0
- package/dist/src/benchmarks/pathData.d.mts.map +1 -0
- package/dist/src/benchmarks/pathData.mjs +3 -0
- package/dist/src/benchmarks/pathData.mjs.map +1 -0
- package/dist/src/benchmarks/raycasting.d.mts +2 -0
- package/dist/src/benchmarks/raycasting.d.mts.map +1 -0
- package/dist/src/benchmarks/raycasting.mjs +134 -0
- package/dist/src/benchmarks/raycasting.mjs.map +1 -0
- package/dist/src/benchmarks/transformMatrixKey.d.mts +2 -0
- package/dist/src/benchmarks/transformMatrixKey.d.mts.map +1 -0
- package/dist/src/benchmarks/transformMatrixKey.mjs +81 -0
- package/dist/src/benchmarks/transformMatrixKey.mjs.map +1 -0
- package/dist/src/brushes/BaseBrush.js +121 -0
- package/dist/src/brushes/BaseBrush.js.map +1 -0
- package/dist/src/brushes/CircleBrush.js +117 -0
- package/dist/src/brushes/CircleBrush.js.map +1 -0
- package/dist/src/brushes/PatternBrush.js +49 -0
- package/dist/src/brushes/PatternBrush.js.map +1 -0
- package/dist/src/brushes/PencilBrush.js +259 -0
- package/dist/src/brushes/PencilBrush.js.map +1 -0
- package/dist/src/brushes/SprayBrush.js +174 -0
- package/dist/src/brushes/SprayBrush.js.map +1 -0
- package/dist/src/brushes/typedefs.js +2 -0
- package/dist/src/brushes/typedefs.js.map +1 -0
- package/dist/src/cache.js +69 -0
- package/dist/src/cache.js.map +1 -0
- package/dist/src/canvas/Canvas.js +1366 -0
- package/dist/src/canvas/Canvas.js.map +1 -0
- package/dist/src/canvas/CanvasOptions.js +31 -0
- package/dist/src/canvas/CanvasOptions.js.map +1 -0
- package/dist/src/canvas/DOMManagers/CanvasDOMManager.js +97 -0
- package/dist/src/canvas/DOMManagers/CanvasDOMManager.js.map +1 -0
- package/dist/src/canvas/DOMManagers/StaticCanvasDOMManager.js +63 -0
- package/dist/src/canvas/DOMManagers/StaticCanvasDOMManager.js.map +1 -0
- package/dist/src/canvas/DOMManagers/util.js +56 -0
- package/dist/src/canvas/DOMManagers/util.js.map +1 -0
- package/dist/src/canvas/SelectableCanvas.js +1141 -0
- package/dist/src/canvas/SelectableCanvas.js.map +1 -0
- package/dist/src/canvas/StaticCanvas.js +1085 -0
- package/dist/src/canvas/StaticCanvas.js.map +1 -0
- package/dist/src/canvas/StaticCanvasOptions.js +23 -0
- package/dist/src/canvas/StaticCanvasOptions.js.map +1 -0
- package/dist/src/canvas/TextEditingManager.js +54 -0
- package/dist/src/canvas/TextEditingManager.js.map +1 -0
- package/dist/src/canvas/canvas_gestures.mixin.js +181 -0
- package/dist/src/canvas/canvas_gestures.mixin.js.map +1 -0
- package/dist/src/color/Color.js +301 -0
- package/dist/src/color/Color.js.map +1 -0
- package/dist/src/color/color_map.js +155 -0
- package/dist/src/color/color_map.js.map +1 -0
- package/dist/src/color/constants.js +111 -0
- package/dist/src/color/constants.js.map +1 -0
- package/dist/src/color/typedefs.js +2 -0
- package/dist/src/color/typedefs.js.map +1 -0
- package/dist/src/color/util.js +73 -0
- package/dist/src/color/util.js.map +1 -0
- package/dist/src/config.js +140 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/constants.js +38 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/controls/Control.js +241 -0
- package/dist/src/controls/Control.js.map +1 -0
- package/dist/src/controls/changeWidth.js +31 -0
- package/dist/src/controls/changeWidth.js.map +1 -0
- package/dist/src/controls/commonControls.js +91 -0
- package/dist/src/controls/commonControls.js.map +1 -0
- package/dist/src/controls/controlRendering.js +81 -0
- package/dist/src/controls/controlRendering.js.map +1 -0
- package/dist/src/controls/drag.js +22 -0
- package/dist/src/controls/drag.js.map +1 -0
- package/dist/src/controls/fireEvent.js +9 -0
- package/dist/src/controls/fireEvent.js.map +1 -0
- package/dist/src/controls/index.js +14 -0
- package/dist/src/controls/index.js.map +1 -0
- package/dist/src/controls/pathControl.js +137 -0
- package/dist/src/controls/pathControl.js.map +1 -0
- package/dist/src/controls/polyControl.js +66 -0
- package/dist/src/controls/polyControl.js.map +1 -0
- package/dist/src/controls/rotate.js +57 -0
- package/dist/src/controls/rotate.js.map +1 -0
- package/dist/src/controls/scale.js +190 -0
- package/dist/src/controls/scale.js.map +1 -0
- package/dist/src/controls/scaleSkew.js +66 -0
- package/dist/src/controls/scaleSkew.js.map +1 -0
- package/dist/src/controls/skew.js +147 -0
- package/dist/src/controls/skew.js.map +1 -0
- package/dist/src/controls/util.js +89 -0
- package/dist/src/controls/util.js.map +1 -0
- package/dist/src/controls/wrapWithFireEvent.js +22 -0
- package/dist/src/controls/wrapWithFireEvent.js.map +1 -0
- package/dist/src/controls/wrapWithFixedAnchor.js +16 -0
- package/dist/src/controls/wrapWithFixedAnchor.js.map +1 -0
- package/dist/src/env/browser.js +18 -0
- package/dist/src/env/browser.js.map +1 -0
- package/dist/src/env/index.js +37 -0
- package/dist/src/env/index.js.map +1 -0
- package/dist/src/env/node.js +37 -0
- package/dist/src/env/node.js.map +1 -0
- package/dist/src/env/types.js +2 -0
- package/dist/src/env/types.js.map +1 -0
- package/dist/src/filters/BaseFilter.js +304 -0
- package/dist/src/filters/BaseFilter.js.map +1 -0
- package/dist/src/filters/BlendColor.js +147 -0
- package/dist/src/filters/BlendColor.js.map +1 -0
- package/dist/src/filters/BlendImage.js +149 -0
- package/dist/src/filters/BlendImage.js.map +1 -0
- package/dist/src/filters/Blur.js +167 -0
- package/dist/src/filters/Blur.js.map +1 -0
- package/dist/src/filters/Boilerplate.js +61 -0
- package/dist/src/filters/Boilerplate.js.map +1 -0
- package/dist/src/filters/Brightness.js +51 -0
- package/dist/src/filters/Brightness.js.map +1 -0
- package/dist/src/filters/Canvas2dFilterBackend.js +51 -0
- package/dist/src/filters/Canvas2dFilterBackend.js.map +1 -0
- package/dist/src/filters/ColorMatrix.js +92 -0
- package/dist/src/filters/ColorMatrix.js.map +1 -0
- package/dist/src/filters/ColorMatrixFilters.js +45 -0
- package/dist/src/filters/ColorMatrixFilters.js.map +1 -0
- package/dist/src/filters/Composed.js +55 -0
- package/dist/src/filters/Composed.js.map +1 -0
- package/dist/src/filters/Contrast.js +51 -0
- package/dist/src/filters/Contrast.js.map +1 -0
- package/dist/src/filters/Convolute.js +132 -0
- package/dist/src/filters/Convolute.js.map +1 -0
- package/dist/src/filters/FilterBackend.js +34 -0
- package/dist/src/filters/FilterBackend.js.map +1 -0
- package/dist/src/filters/GLProbes/GLProbe.js +3 -0
- package/dist/src/filters/GLProbes/GLProbe.js.map +1 -0
- package/dist/src/filters/GLProbes/NodeGLProbe.js +15 -0
- package/dist/src/filters/GLProbes/NodeGLProbe.js.map +1 -0
- package/dist/src/filters/GLProbes/WebGLProbe.js +39 -0
- package/dist/src/filters/GLProbes/WebGLProbe.js.map +1 -0
- package/dist/src/filters/Gamma.js +80 -0
- package/dist/src/filters/Gamma.js.map +1 -0
- package/dist/src/filters/Grayscale.js +69 -0
- package/dist/src/filters/Grayscale.js.map +1 -0
- package/dist/src/filters/HueRotation.js +61 -0
- package/dist/src/filters/HueRotation.js.map +1 -0
- package/dist/src/filters/Invert.js +58 -0
- package/dist/src/filters/Invert.js.map +1 -0
- package/dist/src/filters/Noise.js +54 -0
- package/dist/src/filters/Noise.js.map +1 -0
- package/dist/src/filters/Pixelate.js +66 -0
- package/dist/src/filters/Pixelate.js.map +1 -0
- package/dist/src/filters/RemoveColor.js +74 -0
- package/dist/src/filters/RemoveColor.js.map +1 -0
- package/dist/src/filters/Resize.js +399 -0
- package/dist/src/filters/Resize.js.map +1 -0
- package/dist/src/filters/Saturation.js +55 -0
- package/dist/src/filters/Saturation.js.map +1 -0
- package/dist/src/filters/Vibrance.js +57 -0
- package/dist/src/filters/Vibrance.js.map +1 -0
- package/dist/src/filters/WebGLFilterBackend.js +269 -0
- package/dist/src/filters/WebGLFilterBackend.js.map +1 -0
- package/dist/src/filters/filters.js +21 -0
- package/dist/src/filters/filters.js.map +1 -0
- package/dist/src/filters/index.js +7 -0
- package/dist/src/filters/index.js.map +1 -0
- package/dist/src/filters/shaders/baseFilter.js +16 -0
- package/dist/src/filters/shaders/baseFilter.js.map +1 -0
- package/dist/src/filters/shaders/blendColor.js +32 -0
- package/dist/src/filters/shaders/blendColor.js.map +1 -0
- package/dist/src/filters/shaders/blendImage.js +42 -0
- package/dist/src/filters/shaders/blendImage.js.map +1 -0
- package/dist/src/filters/shaders/blur.js +31 -0
- package/dist/src/filters/shaders/blur.js.map +1 -0
- package/dist/src/filters/shaders/brightness.js +12 -0
- package/dist/src/filters/shaders/brightness.js.map +1 -0
- package/dist/src/filters/shaders/colorMatrix.js +13 -0
- package/dist/src/filters/shaders/colorMatrix.js.map +1 -0
- package/dist/src/filters/shaders/constrast.js +12 -0
- package/dist/src/filters/shaders/constrast.js.map +1 -0
- package/dist/src/filters/shaders/convolute.js +155 -0
- package/dist/src/filters/shaders/convolute.js.map +1 -0
- package/dist/src/filters/shaders/gamma.js +16 -0
- package/dist/src/filters/shaders/gamma.js.map +1 -0
- package/dist/src/filters/shaders/grayscale.js +35 -0
- package/dist/src/filters/shaders/grayscale.js.map +1 -0
- package/dist/src/filters/shaders/invert.js +20 -0
- package/dist/src/filters/shaders/invert.js.map +1 -0
- package/dist/src/filters/shaders/noise.js +17 -0
- package/dist/src/filters/shaders/noise.js.map +1 -0
- package/dist/src/filters/shaders/pixelate.js +20 -0
- package/dist/src/filters/shaders/pixelate.js.map +1 -0
- package/dist/src/filters/shaders/removeColor.js +14 -0
- package/dist/src/filters/shaders/removeColor.js.map +1 -0
- package/dist/src/filters/shaders/saturation.js +16 -0
- package/dist/src/filters/shaders/saturation.js.map +1 -0
- package/dist/src/filters/shaders/vibrance.js +17 -0
- package/dist/src/filters/shaders/vibrance.js.map +1 -0
- package/dist/src/filters/typedefs.js +2 -0
- package/dist/src/filters/typedefs.js.map +1 -0
- package/dist/src/filters/utils.js +36 -0
- package/dist/src/filters/utils.js.map +1 -0
- package/dist/src/gradient/Gradient.d.ts.map +1 -1
- package/dist/src/gradient/Gradient.js +244 -0
- package/dist/src/gradient/Gradient.js.map +1 -0
- package/dist/src/gradient/Gradient.min.mjs +1 -1
- package/dist/src/gradient/Gradient.min.mjs.map +1 -1
- package/dist/src/gradient/Gradient.mjs +2 -1
- package/dist/src/gradient/Gradient.mjs.map +1 -1
- package/dist/src/gradient/constants.js +12 -0
- package/dist/src/gradient/constants.js.map +1 -0
- package/dist/src/gradient/index.js +3 -0
- package/dist/src/gradient/index.js.map +1 -0
- package/dist/src/gradient/parser/misc.js +11 -0
- package/dist/src/gradient/parser/misc.js.map +1 -0
- package/dist/src/gradient/parser/parseColorStops.js +42 -0
- package/dist/src/gradient/parser/parseColorStops.js.map +1 -0
- package/dist/src/gradient/parser/parseCoords.js +60 -0
- package/dist/src/gradient/parser/parseCoords.js.map +1 -0
- package/dist/src/gradient/typedefs.js +2 -0
- package/dist/src/gradient/typedefs.js.map +1 -0
- package/dist/src/mixins/eraser_brush.mixin.js +732 -0
- package/dist/src/mixins/eraser_brush.mixin.js.map +1 -0
- package/dist/src/parkinglot/canvas_animation.mixin.js +102 -0
- package/dist/src/parkinglot/canvas_animation.mixin.js.map +1 -0
- package/dist/src/parkinglot/straighten.js +53 -0
- package/dist/src/parkinglot/straighten.js.map +1 -0
- package/dist/src/parser/applyViewboxTransform.js +146 -0
- package/dist/src/parser/applyViewboxTransform.js.map +1 -0
- package/dist/src/parser/attributes.js +27 -0
- package/dist/src/parser/attributes.js.map +1 -0
- package/dist/src/parser/constants.js +70 -0
- package/dist/src/parser/constants.js.map +1 -0
- package/dist/src/parser/doesSomeParentMatch.js +15 -0
- package/dist/src/parser/doesSomeParentMatch.js.map +1 -0
- package/dist/src/parser/elementMatchesRule.js +15 -0
- package/dist/src/parser/elementMatchesRule.js.map +1 -0
- package/dist/src/parser/elements_parser.js +164 -0
- package/dist/src/parser/elements_parser.js.map +1 -0
- package/dist/src/parser/getCSSRules.js +62 -0
- package/dist/src/parser/getCSSRules.js.map +1 -0
- package/dist/src/parser/getGlobalStylesForElement.js +17 -0
- package/dist/src/parser/getGlobalStylesForElement.js.map +1 -0
- package/dist/src/parser/getGradientDefs.js +30 -0
- package/dist/src/parser/getGradientDefs.js.map +1 -0
- package/dist/src/parser/getMultipleNodes.js +10 -0
- package/dist/src/parser/getMultipleNodes.js.map +1 -0
- package/dist/src/parser/getPatternDefs.js +70 -0
- package/dist/src/parser/getPatternDefs.js.map +1 -0
- package/dist/src/parser/getSvgRegex.js +4 -0
- package/dist/src/parser/getSvgRegex.js.map +1 -0
- package/dist/src/parser/getTagName.js +2 -0
- package/dist/src/parser/getTagName.js.map +1 -0
- package/dist/src/parser/hasInvalidAncestor.js +17 -0
- package/dist/src/parser/hasInvalidAncestor.js.map +1 -0
- package/dist/src/parser/loadSVGFromString.js +23 -0
- package/dist/src/parser/loadSVGFromString.js.map +1 -0
- package/dist/src/parser/loadSVGFromURL.js +39 -0
- package/dist/src/parser/loadSVGFromURL.js.map +1 -0
- package/dist/src/parser/normalizeAttr.js +3 -0
- package/dist/src/parser/normalizeAttr.js.map +1 -0
- package/dist/src/parser/normalizeValue.js +79 -0
- package/dist/src/parser/normalizeValue.js.map +1 -0
- package/dist/src/parser/parseAttributes.js +66 -0
- package/dist/src/parser/parseAttributes.js.map +1 -0
- package/dist/src/parser/parseFontDeclaration.js +38 -0
- package/dist/src/parser/parseFontDeclaration.js.map +1 -0
- package/dist/src/parser/parsePointsAttribute.js +28 -0
- package/dist/src/parser/parsePointsAttribute.js.map +1 -0
- package/dist/src/parser/parseSVGDocument.js +74 -0
- package/dist/src/parser/parseSVGDocument.js.map +1 -0
- package/dist/src/parser/parseStyleAttribute.js +23 -0
- package/dist/src/parser/parseStyleAttribute.js.map +1 -0
- package/dist/src/parser/parseStyleObject.js +15 -0
- package/dist/src/parser/parseStyleObject.js.map +1 -0
- package/dist/src/parser/parseStyleString.js +18 -0
- package/dist/src/parser/parseStyleString.js.map +1 -0
- package/dist/src/parser/parseTransformAttribute.js +76 -0
- package/dist/src/parser/parseTransformAttribute.js.map +1 -0
- package/dist/src/parser/parseUseDirectives.js +76 -0
- package/dist/src/parser/parseUseDirectives.js.map +1 -0
- package/dist/src/parser/percent.js +21 -0
- package/dist/src/parser/percent.js.map +1 -0
- package/dist/src/parser/recursivelyParseGradientsXlink.js +36 -0
- package/dist/src/parser/recursivelyParseGradientsXlink.js.map +1 -0
- package/dist/src/parser/selectorMatches.js +24 -0
- package/dist/src/parser/selectorMatches.js.map +1 -0
- package/dist/src/parser/setStrokeFillOpacity.js +35 -0
- package/dist/src/parser/setStrokeFillOpacity.js.map +1 -0
- package/dist/src/parser/typedefs.js +2 -0
- package/dist/src/parser/typedefs.js.map +1 -0
- package/dist/src/shapes/ActiveSelection.js +195 -0
- package/dist/src/shapes/ActiveSelection.js.map +1 -0
- package/dist/src/shapes/Circle.js +155 -0
- package/dist/src/shapes/Circle.js.map +1 -0
- package/dist/src/shapes/Ellipse.js +120 -0
- package/dist/src/shapes/Ellipse.js.map +1 -0
- package/dist/src/shapes/Group.js +549 -0
- package/dist/src/shapes/Group.js.map +1 -0
- package/dist/src/shapes/IText/DraggableTextDelegate.js +326 -0
- package/dist/src/shapes/IText/DraggableTextDelegate.js.map +1 -0
- package/dist/src/shapes/IText/IText.js +545 -0
- package/dist/src/shapes/IText/IText.js.map +1 -0
- package/dist/src/shapes/IText/ITextBehavior.js +848 -0
- package/dist/src/shapes/IText/ITextBehavior.js.map +1 -0
- package/dist/src/shapes/IText/ITextClickBehavior.js +196 -0
- package/dist/src/shapes/IText/ITextClickBehavior.js.map +1 -0
- package/dist/src/shapes/IText/ITextKeyBehavior.js +522 -0
- package/dist/src/shapes/IText/ITextKeyBehavior.js.map +1 -0
- package/dist/src/shapes/IText/constants.js +47 -0
- package/dist/src/shapes/IText/constants.js.map +1 -0
- package/dist/src/shapes/Image.js +589 -0
- package/dist/src/shapes/Image.js.map +1 -0
- package/dist/src/shapes/Line.js +195 -0
- package/dist/src/shapes/Line.js.map +1 -0
- package/dist/src/shapes/Object/FabricObject.js +12 -0
- package/dist/src/shapes/Object/FabricObject.js.map +1 -0
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.js +255 -0
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.js.map +1 -0
- package/dist/src/shapes/Object/InteractiveObject.js +478 -0
- package/dist/src/shapes/Object/InteractiveObject.js.map +1 -0
- package/dist/src/shapes/Object/Object.js +1392 -0
- package/dist/src/shapes/Object/Object.js.map +1 -0
- package/dist/src/shapes/Object/ObjectGeometry.js +537 -0
- package/dist/src/shapes/Object/ObjectGeometry.js.map +1 -0
- package/dist/src/shapes/Object/defaultValues.js +109 -0
- package/dist/src/shapes/Object/defaultValues.js.map +1 -0
- package/dist/src/shapes/Object/types/BaseProps.js +2 -0
- package/dist/src/shapes/Object/types/BaseProps.js.map +1 -0
- package/dist/src/shapes/Object/types/BorderProps.js +2 -0
- package/dist/src/shapes/Object/types/BorderProps.js.map +1 -0
- package/dist/src/shapes/Object/types/ControlProps.js +2 -0
- package/dist/src/shapes/Object/types/ControlProps.js.map +1 -0
- package/dist/src/shapes/Object/types/FabricObjectProps.js +2 -0
- package/dist/src/shapes/Object/types/FabricObjectProps.js.map +1 -0
- package/dist/src/shapes/Object/types/FillStrokeProps.js +2 -0
- package/dist/src/shapes/Object/types/FillStrokeProps.js.map +1 -0
- package/dist/src/shapes/Object/types/LockInteractionProps.js +2 -0
- package/dist/src/shapes/Object/types/LockInteractionProps.js.map +1 -0
- package/dist/src/shapes/Object/types/ObjectProps.js +2 -0
- package/dist/src/shapes/Object/types/ObjectProps.js.map +1 -0
- package/dist/src/shapes/Object/types/ObjectTransformProps.js +2 -0
- package/dist/src/shapes/Object/types/ObjectTransformProps.js.map +1 -0
- package/dist/src/shapes/Object/types/SerializedObjectProps.js +2 -0
- package/dist/src/shapes/Object/types/SerializedObjectProps.js.map +1 -0
- package/dist/src/shapes/Object/types/index.js +2 -0
- package/dist/src/shapes/Object/types/index.js.map +1 -0
- package/dist/src/shapes/Path.js +267 -0
- package/dist/src/shapes/Path.js.map +1 -0
- package/dist/src/shapes/Polygon.js +12 -0
- package/dist/src/shapes/Polygon.js.map +1 -0
- package/dist/src/shapes/Polyline.js +307 -0
- package/dist/src/shapes/Polyline.js.map +1 -0
- package/dist/src/shapes/Rect.js +131 -0
- package/dist/src/shapes/Rect.js.map +1 -0
- package/dist/src/shapes/Text/StyledText.js +261 -0
- package/dist/src/shapes/Text/StyledText.js.map +1 -0
- package/dist/src/shapes/Text/Text.js +1258 -0
- package/dist/src/shapes/Text/Text.js.map +1 -0
- package/dist/src/shapes/Text/TextSVGExportMixin.js +339 -0
- package/dist/src/shapes/Text/TextSVGExportMixin.js.map +1 -0
- package/dist/src/shapes/Text/constants.js +94 -0
- package/dist/src/shapes/Text/constants.js.map +1 -0
- package/dist/src/shapes/Textbox.d.ts.map +1 -1
- package/dist/src/shapes/Textbox.js +910 -0
- package/dist/src/shapes/Textbox.js.map +1 -0
- package/dist/src/shapes/Textbox.min.mjs +1 -1
- package/dist/src/shapes/Textbox.min.mjs.map +1 -1
- package/dist/src/shapes/Textbox.mjs +4 -1
- package/dist/src/shapes/Textbox.mjs.map +1 -1
- package/dist/src/shapes/Triangle.js +47 -0
- package/dist/src/shapes/Triangle.js.map +1 -0
- package/dist/src/typedefs.js +2 -0
- package/dist/src/typedefs.js.map +1 -0
- package/dist/src/util/animation/AnimationBase.js +94 -0
- package/dist/src/util/animation/AnimationBase.js.map +1 -0
- package/dist/src/util/animation/AnimationFrameProvider.js +8 -0
- package/dist/src/util/animation/AnimationFrameProvider.js.map +1 -0
- package/dist/src/util/animation/AnimationRegistry.js +49 -0
- package/dist/src/util/animation/AnimationRegistry.js.map +1 -0
- package/dist/src/util/animation/ArrayAnimation.js +18 -0
- package/dist/src/util/animation/ArrayAnimation.js.map +1 -0
- package/dist/src/util/animation/ColorAnimation.js +43 -0
- package/dist/src/util/animation/ColorAnimation.js.map +1 -0
- package/dist/src/util/animation/ValueAnimation.js +18 -0
- package/dist/src/util/animation/ValueAnimation.js.map +1 -0
- package/dist/src/util/animation/animate.js +19 -0
- package/dist/src/util/animation/animate.js.map +1 -0
- package/dist/src/util/animation/easing.js +265 -0
- package/dist/src/util/animation/easing.js.map +1 -0
- package/dist/src/util/animation/index.js +3 -0
- package/dist/src/util/animation/index.js.map +1 -0
- package/dist/src/util/animation/types.js +2 -0
- package/dist/src/util/animation/types.js.map +1 -0
- package/dist/src/util/applyMixins.js +14 -0
- package/dist/src/util/applyMixins.js.map +1 -0
- package/dist/src/util/dom_event.js +21 -0
- package/dist/src/util/dom_event.js.map +1 -0
- package/dist/src/util/dom_misc.js +42 -0
- package/dist/src/util/dom_misc.js.map +1 -0
- package/dist/src/util/dom_style.js +19 -0
- package/dist/src/util/dom_style.js.map +1 -0
- package/dist/src/util/index.js +36 -0
- package/dist/src/util/index.js.map +1 -0
- package/dist/src/util/internals/applyCanvasTransform.js +15 -0
- package/dist/src/util/internals/applyCanvasTransform.js.map +1 -0
- package/dist/src/util/internals/cleanupSvgAttribute.js +8 -0
- package/dist/src/util/internals/cleanupSvgAttribute.js.map +1 -0
- package/dist/src/util/internals/cloneDeep.js +8 -0
- package/dist/src/util/internals/cloneDeep.js.map +1 -0
- package/dist/src/util/internals/cloneStyles.js +11 -0
- package/dist/src/util/internals/cloneStyles.js.map +1 -0
- package/dist/src/util/internals/console.js +14 -0
- package/dist/src/util/internals/console.js.map +1 -0
- package/dist/src/util/internals/dom_request.js +39 -0
- package/dist/src/util/internals/dom_request.js.map +1 -0
- package/dist/src/util/internals/findRight.js +9 -0
- package/dist/src/util/internals/findRight.js.map +1 -0
- package/dist/src/util/internals/getRandomInt.js +8 -0
- package/dist/src/util/internals/getRandomInt.js.map +1 -0
- package/dist/src/util/internals/ifNaN.js +10 -0
- package/dist/src/util/internals/ifNaN.js.map +1 -0
- package/dist/src/util/internals/removeFromArray.js +15 -0
- package/dist/src/util/internals/removeFromArray.js.map +1 -0
- package/dist/src/util/internals/uid.js +3 -0
- package/dist/src/util/internals/uid.js.map +1 -0
- package/dist/src/util/lang_string.js +93 -0
- package/dist/src/util/lang_string.js.map +1 -0
- package/dist/src/util/misc/boundingBoxFromPoints.js +26 -0
- package/dist/src/util/misc/boundingBoxFromPoints.js.map +1 -0
- package/dist/src/util/misc/capValue.js +2 -0
- package/dist/src/util/misc/capValue.js.map +1 -0
- package/dist/src/util/misc/cos.js +23 -0
- package/dist/src/util/misc/cos.js.map +1 -0
- package/dist/src/util/misc/dom.js +55 -0
- package/dist/src/util/misc/dom.js.map +1 -0
- package/dist/src/util/misc/findScaleTo.js +19 -0
- package/dist/src/util/misc/findScaleTo.js.map +1 -0
- package/dist/src/util/misc/groupSVGElements.js +15 -0
- package/dist/src/util/misc/groupSVGElements.js.map +1 -0
- package/dist/src/util/misc/isTransparent.js +23 -0
- package/dist/src/util/misc/isTransparent.js.map +1 -0
- package/dist/src/util/misc/matrix.js +238 -0
- package/dist/src/util/misc/matrix.js.map +1 -0
- package/dist/src/util/misc/mergeClipPaths.js +39 -0
- package/dist/src/util/misc/mergeClipPaths.js.map +1 -0
- package/dist/src/util/misc/objectEnlive.js +136 -0
- package/dist/src/util/misc/objectEnlive.js.map +1 -0
- package/dist/src/util/misc/objectTransforms.js +89 -0
- package/dist/src/util/misc/objectTransforms.js.map +1 -0
- package/dist/src/util/misc/pick.js +23 -0
- package/dist/src/util/misc/pick.js.map +1 -0
- package/dist/src/util/misc/planeChange.js +68 -0
- package/dist/src/util/misc/planeChange.js.map +1 -0
- package/dist/src/util/misc/projectStroke/StrokeLineCapProjections.js +105 -0
- package/dist/src/util/misc/projectStroke/StrokeLineCapProjections.js.map +1 -0
- package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.js +219 -0
- package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.js.map +1 -0
- package/dist/src/util/misc/projectStroke/StrokeProjectionsBase.js +42 -0
- package/dist/src/util/misc/projectStroke/StrokeProjectionsBase.js.map +1 -0
- package/dist/src/util/misc/projectStroke/index.js +61 -0
- package/dist/src/util/misc/projectStroke/index.js.map +1 -0
- package/dist/src/util/misc/projectStroke/types.js +2 -0
- package/dist/src/util/misc/projectStroke/types.js.map +1 -0
- package/dist/src/util/misc/radiansDegreesConversion.js +14 -0
- package/dist/src/util/misc/radiansDegreesConversion.js.map +1 -0
- package/dist/src/util/misc/resolveOrigin.js +17 -0
- package/dist/src/util/misc/resolveOrigin.js.map +1 -0
- package/dist/src/util/misc/rotatePoint.js +10 -0
- package/dist/src/util/misc/rotatePoint.js.map +1 -0
- package/dist/src/util/misc/sin.js +25 -0
- package/dist/src/util/misc/sin.js.map +1 -0
- package/dist/src/util/misc/svgExport.js +13 -0
- package/dist/src/util/misc/svgExport.js.map +1 -0
- package/dist/src/util/misc/svgParsing.js +129 -0
- package/dist/src/util/misc/svgParsing.js.map +1 -0
- package/dist/src/util/misc/textStyles.js +107 -0
- package/dist/src/util/misc/textStyles.js.map +1 -0
- package/dist/src/util/misc/toFixed.js +8 -0
- package/dist/src/util/misc/toFixed.js.map +1 -0
- package/dist/src/util/misc/vectors.js +77 -0
- package/dist/src/util/misc/vectors.js.map +1 -0
- package/dist/src/util/path/index.js +743 -0
- package/dist/src/util/path/index.js.map +1 -0
- package/dist/src/util/path/regex.js +33 -0
- package/dist/src/util/path/regex.js.map +1 -0
- package/dist/src/util/path/typechecks.js +67 -0
- package/dist/src/util/path/typechecks.js.map +1 -0
- package/dist/src/util/path/typedefs.js +2 -0
- package/dist/src/util/path/typedefs.js.map +1 -0
- package/dist/src/util/transform_matrix_removal.js +46 -0
- package/dist/src/util/transform_matrix_removal.js.map +1 -0
- package/dist/src/util/typeAssertions.js +21 -0
- package/dist/src/util/typeAssertions.js.map +1 -0
- package/dist-extensions/src/gradient/Gradient.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Textbox.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/gradient/Gradient.ts +5 -2
- package/src/shapes/Textbox.ts +4 -1
|
@@ -0,0 +1,1258 @@
|
|
|
1
|
+
import { cache } from '../../cache';
|
|
2
|
+
import { FILL, STROKE } from '../../constants';
|
|
3
|
+
import { StyledText } from './StyledText';
|
|
4
|
+
import { SHARED_ATTRIBUTES } from '../../parser/attributes';
|
|
5
|
+
import { classRegistry } from '../../ClassRegistry';
|
|
6
|
+
import { graphemeSplit } from '../../util/lang_string';
|
|
7
|
+
import { createCanvasElementFor } from '../../util/misc/dom';
|
|
8
|
+
import { hasStyleChanged, stylesFromArray, stylesToArray, } from '../../util/misc/textStyles';
|
|
9
|
+
import { getPathSegmentsInfo, getPointOnPath } from '../../util/path';
|
|
10
|
+
import { cacheProperties } from '../Object/FabricObject';
|
|
11
|
+
import { TextSVGExportMixin } from './TextSVGExportMixin';
|
|
12
|
+
import { applyMixins } from '../../util/applyMixins';
|
|
13
|
+
import { additionalProps, textDefaultValues, textLayoutProperties, JUSTIFY, JUSTIFY_CENTER, JUSTIFY_LEFT, JUSTIFY_RIGHT, TEXT_DECORATION_THICKNESS, } from './constants';
|
|
14
|
+
import { CENTER, LEFT, RIGHT, TOP, BOTTOM } from '../../constants';
|
|
15
|
+
import { isFiller } from '../../util/typeAssertions';
|
|
16
|
+
import { renderCircleControl, renderSquareControl } from '../../controls';
|
|
17
|
+
let measuringContext;
|
|
18
|
+
/**
|
|
19
|
+
* Return a context for measurement of text string.
|
|
20
|
+
* if created it gets stored for reuse
|
|
21
|
+
*/
|
|
22
|
+
function getMeasuringContext() {
|
|
23
|
+
if (!measuringContext) {
|
|
24
|
+
const canvas = createCanvasElementFor({
|
|
25
|
+
width: 0,
|
|
26
|
+
height: 0,
|
|
27
|
+
});
|
|
28
|
+
measuringContext = canvas.getContext('2d');
|
|
29
|
+
}
|
|
30
|
+
return measuringContext;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Text class
|
|
34
|
+
* @tutorial {@link http://fabricjs.com/fabric-intro-part-2#text}
|
|
35
|
+
*/
|
|
36
|
+
export class FabricText extends StyledText {
|
|
37
|
+
/**
|
|
38
|
+
* Properties that requires a text layout recalculation when changed
|
|
39
|
+
* @type string[]
|
|
40
|
+
* @protected
|
|
41
|
+
*/
|
|
42
|
+
static textLayoutProperties = textLayoutProperties;
|
|
43
|
+
/**
|
|
44
|
+
* contains characters bounding boxes
|
|
45
|
+
* This variable is considered to be protected.
|
|
46
|
+
* But for how mixins are implemented right now, we can't leave it private
|
|
47
|
+
* @protected
|
|
48
|
+
*/
|
|
49
|
+
__charBounds = [];
|
|
50
|
+
static cacheProperties = [...cacheProperties, ...additionalProps];
|
|
51
|
+
static ownDefaults = textDefaultValues;
|
|
52
|
+
/**
|
|
53
|
+
* James add
|
|
54
|
+
* 是否启用计算文字高度
|
|
55
|
+
*/
|
|
56
|
+
static enableCalcTextHeight;
|
|
57
|
+
static type = 'Text';
|
|
58
|
+
static getDefaults() {
|
|
59
|
+
return { ...super.getDefaults(), ...FabricText.ownDefaults };
|
|
60
|
+
}
|
|
61
|
+
constructor(text, options) {
|
|
62
|
+
super();
|
|
63
|
+
Object.assign(this, FabricText.ownDefaults);
|
|
64
|
+
this.setOptions(options);
|
|
65
|
+
if (!this.styles) {
|
|
66
|
+
this.styles = {};
|
|
67
|
+
}
|
|
68
|
+
this.text = text;
|
|
69
|
+
this.initialized = true;
|
|
70
|
+
if (this.path) {
|
|
71
|
+
this.setPathInfo();
|
|
72
|
+
}
|
|
73
|
+
this.initDimensions();
|
|
74
|
+
this.setCoords();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* If text has a path, it will add the extra information needed
|
|
78
|
+
* for path and text calculations
|
|
79
|
+
*/
|
|
80
|
+
setPathInfo() {
|
|
81
|
+
const path = this.path;
|
|
82
|
+
if (path) {
|
|
83
|
+
path.segmentsInfo = getPathSegmentsInfo(path.path);
|
|
84
|
+
// James modified 检查空路径的话,设置path为空
|
|
85
|
+
if (!path.width && !path.height) {
|
|
86
|
+
console.log(this, 'text path empty');
|
|
87
|
+
this.path = undefined;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* @private
|
|
93
|
+
* Divides text into lines of text and lines of graphemes.
|
|
94
|
+
*/
|
|
95
|
+
_splitText() {
|
|
96
|
+
const newLines = this._splitTextIntoLines(this.text);
|
|
97
|
+
this.textLines = newLines.lines;
|
|
98
|
+
this._textLines = newLines.graphemeLines;
|
|
99
|
+
this._unwrappedTextLines = newLines._unwrappedLines;
|
|
100
|
+
this._text = newLines.graphemeText;
|
|
101
|
+
return newLines;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Initialize or update text dimensions.
|
|
105
|
+
* Updates this.width and this.height with the proper values.
|
|
106
|
+
* Does not return dimensions.
|
|
107
|
+
*/
|
|
108
|
+
initDimensions() {
|
|
109
|
+
this._splitText();
|
|
110
|
+
this._clearCache();
|
|
111
|
+
this.dirty = true;
|
|
112
|
+
if (this.path) {
|
|
113
|
+
this.width = this.path.width;
|
|
114
|
+
this.height = this.path.height;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
this.width =
|
|
118
|
+
this.calcTextWidth() || this.cursorWidth || this.MIN_TEXT_WIDTH;
|
|
119
|
+
this.height = this.calcTextHeight();
|
|
120
|
+
}
|
|
121
|
+
if (this.textAlign.includes(JUSTIFY)) {
|
|
122
|
+
// once text is measured we need to make space fatter to make justified text.
|
|
123
|
+
this.enlargeSpaces();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Enlarge space boxes and shift the others
|
|
128
|
+
*/
|
|
129
|
+
enlargeSpaces() {
|
|
130
|
+
let diffSpace, currentLineWidth, numberOfSpaces, accumulatedSpace, line, charBound, spaces;
|
|
131
|
+
for (let i = 0, len = this._textLines.length; i < len; i++) {
|
|
132
|
+
if (this.textAlign !== JUSTIFY &&
|
|
133
|
+
(i === len - 1 || this.isEndOfWrapping(i))) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
accumulatedSpace = 0;
|
|
137
|
+
line = this._textLines[i];
|
|
138
|
+
currentLineWidth = this.getLineWidth(i);
|
|
139
|
+
if (currentLineWidth < this.width &&
|
|
140
|
+
(spaces = this.textLines[i].match(this._reSpacesAndTabs))) {
|
|
141
|
+
numberOfSpaces = spaces.length;
|
|
142
|
+
diffSpace = (this.width - currentLineWidth) / numberOfSpaces;
|
|
143
|
+
for (let j = 0; j <= line.length; j++) {
|
|
144
|
+
charBound = this.__charBounds[i][j];
|
|
145
|
+
if (this._reSpaceAndTab.test(line[j])) {
|
|
146
|
+
charBound.width += diffSpace;
|
|
147
|
+
charBound.kernedWidth += diffSpace;
|
|
148
|
+
charBound.left += accumulatedSpace;
|
|
149
|
+
accumulatedSpace += diffSpace;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
charBound.left += accumulatedSpace;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Detect if the text line is ended with an hard break
|
|
160
|
+
* text and itext do not have wrapping, return false
|
|
161
|
+
* @return {Boolean}
|
|
162
|
+
*/
|
|
163
|
+
isEndOfWrapping(lineIndex) {
|
|
164
|
+
return lineIndex === this._textLines.length - 1;
|
|
165
|
+
}
|
|
166
|
+
missingNewlineOffset(_lineIndex) {
|
|
167
|
+
return 1;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Returns 2d representation (lineIndex and charIndex) of cursor
|
|
171
|
+
* @param {Number} selectionStart
|
|
172
|
+
* @param {Boolean} [skipWrapping] consider the location for unwrapped lines. useful to manage styles.
|
|
173
|
+
*/
|
|
174
|
+
get2DCursorLocation(selectionStart, skipWrapping) {
|
|
175
|
+
const lines = skipWrapping ? this._unwrappedTextLines : this._textLines;
|
|
176
|
+
let i;
|
|
177
|
+
for (i = 0; i < lines.length; i++) {
|
|
178
|
+
if (selectionStart <= lines[i].length) {
|
|
179
|
+
return {
|
|
180
|
+
lineIndex: i,
|
|
181
|
+
charIndex: selectionStart,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
selectionStart -=
|
|
185
|
+
lines[i].length + this.missingNewlineOffset(i, skipWrapping);
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
lineIndex: i - 1,
|
|
189
|
+
charIndex: lines[i - 1].length < selectionStart
|
|
190
|
+
? lines[i - 1].length
|
|
191
|
+
: selectionStart,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Returns string representation of an instance
|
|
196
|
+
* @return {String} String representation of text object
|
|
197
|
+
*/
|
|
198
|
+
toString() {
|
|
199
|
+
return `#<Text (${this.complexity()}): { "text": "${this.text}", "fontFamily": "${this.fontFamily}" }>`;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Return the dimension and the zoom level needed to create a cache canvas
|
|
203
|
+
* big enough to host the object to be cached.
|
|
204
|
+
* @private
|
|
205
|
+
* @param {Object} dim.x width of object to be cached
|
|
206
|
+
* @param {Object} dim.y height of object to be cached
|
|
207
|
+
* @return {Object}.width width of canvas
|
|
208
|
+
* @return {Object}.height height of canvas
|
|
209
|
+
* @return {Object}.zoomX zoomX zoom value to unscale the canvas before drawing cache
|
|
210
|
+
* @return {Object}.zoomY zoomY zoom value to unscale the canvas before drawing cache
|
|
211
|
+
*/
|
|
212
|
+
_getCacheCanvasDimensions() {
|
|
213
|
+
const dims = super._getCacheCanvasDimensions();
|
|
214
|
+
const fontSize = this.fontSize;
|
|
215
|
+
dims.width += fontSize * dims.zoomX * 2;
|
|
216
|
+
dims.height += fontSize * dims.zoomY * 2;
|
|
217
|
+
return dims;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* @private
|
|
221
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
222
|
+
*/
|
|
223
|
+
_render(ctx) {
|
|
224
|
+
const path = this.path;
|
|
225
|
+
path && !path.isNotVisible() && path._render(ctx);
|
|
226
|
+
this._setTextStyles(ctx);
|
|
227
|
+
this._renderTextLinesBackground(ctx);
|
|
228
|
+
this._renderTextDecoration(ctx, 'underline');
|
|
229
|
+
this._renderText(ctx);
|
|
230
|
+
this._renderTextDecoration(ctx, 'overline');
|
|
231
|
+
this._renderTextDecoration(ctx, 'linethrough');
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* @private
|
|
235
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
236
|
+
*/
|
|
237
|
+
_renderText(ctx) {
|
|
238
|
+
if (this.paintFirst === STROKE) {
|
|
239
|
+
this._renderTextStroke(ctx);
|
|
240
|
+
this._renderTextFill(ctx);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
this._renderTextFill(ctx);
|
|
244
|
+
this._renderTextStroke(ctx);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Set the font parameter of the context with the object properties or with charStyle
|
|
249
|
+
* @private
|
|
250
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
251
|
+
* @param {Object} [charStyle] object with font style properties
|
|
252
|
+
* @param {String} [charStyle.fontFamily] Font Family
|
|
253
|
+
* @param {Number} [charStyle.fontSize] Font size in pixels. ( without px suffix )
|
|
254
|
+
* @param {String} [charStyle.fontWeight] Font weight
|
|
255
|
+
* @param {String} [charStyle.fontStyle] Font style (italic|normal)
|
|
256
|
+
*/
|
|
257
|
+
_setTextStyles(ctx, charStyle, forMeasuring) {
|
|
258
|
+
ctx.textBaseline = 'alphabetic';
|
|
259
|
+
if (this.path) {
|
|
260
|
+
switch (this.pathAlign) {
|
|
261
|
+
case CENTER:
|
|
262
|
+
ctx.textBaseline = 'middle';
|
|
263
|
+
break;
|
|
264
|
+
case 'ascender':
|
|
265
|
+
ctx.textBaseline = TOP;
|
|
266
|
+
break;
|
|
267
|
+
case 'descender':
|
|
268
|
+
ctx.textBaseline = BOTTOM;
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
ctx.font = this._getFontDeclaration(charStyle, forMeasuring);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* calculate and return the text Width measuring each line.
|
|
276
|
+
* @private
|
|
277
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
278
|
+
* @return {Number} Maximum width of Text object
|
|
279
|
+
*/
|
|
280
|
+
calcTextWidth() {
|
|
281
|
+
let maxWidth = this.getLineWidth(0);
|
|
282
|
+
for (let i = 1, len = this._textLines.length; i < len; i++) {
|
|
283
|
+
const currentLineWidth = this.getLineWidth(i);
|
|
284
|
+
if (currentLineWidth > maxWidth) {
|
|
285
|
+
maxWidth = currentLineWidth;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return maxWidth;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* @private
|
|
292
|
+
* @param {String} method Method name ("fillText" or "strokeText")
|
|
293
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
294
|
+
* @param {String} line Text to render
|
|
295
|
+
* @param {Number} left Left position of text
|
|
296
|
+
* @param {Number} top Top position of text
|
|
297
|
+
* @param {Number} lineIndex Index of a line in a text
|
|
298
|
+
*/
|
|
299
|
+
_renderTextLine(method, ctx, line, left, top, lineIndex) {
|
|
300
|
+
this._renderChars(method, ctx, line, left, top, lineIndex);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Renders the text background for lines, taking care of style
|
|
304
|
+
* @private
|
|
305
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
306
|
+
*/
|
|
307
|
+
_renderTextLinesBackground(ctx) {
|
|
308
|
+
if (!this.textBackgroundColor && !this.styleHas('textBackgroundColor')) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const originalFill = ctx.fillStyle, leftOffset = this._getLeftOffset();
|
|
312
|
+
let lineTopOffset = this._getTopOffset();
|
|
313
|
+
for (let i = 0, len = this._textLines.length; i < len; i++) {
|
|
314
|
+
const heightOfLine = this.getHeightOfLine(i);
|
|
315
|
+
if (!this.textBackgroundColor &&
|
|
316
|
+
!this.styleHas('textBackgroundColor', i)) {
|
|
317
|
+
lineTopOffset += heightOfLine;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
const jlen = this._textLines[i].length;
|
|
321
|
+
const lineLeftOffset = this._getLineLeftOffset(i);
|
|
322
|
+
let boxWidth = 0;
|
|
323
|
+
let boxStart = 0;
|
|
324
|
+
let drawStart;
|
|
325
|
+
let currentColor;
|
|
326
|
+
let lastColor = this.getValueOfPropertyAt(i, 0, 'textBackgroundColor');
|
|
327
|
+
for (let j = 0; j < jlen; j++) {
|
|
328
|
+
// at this point charbox are either standard or full with pathInfo if there is a path.
|
|
329
|
+
const charBox = this.__charBounds[i][j];
|
|
330
|
+
currentColor = this.getValueOfPropertyAt(i, j, 'textBackgroundColor');
|
|
331
|
+
// James modified
|
|
332
|
+
if (this.path && !this.isEditing) {
|
|
333
|
+
ctx.save();
|
|
334
|
+
ctx.translate(charBox.renderLeft, charBox.renderTop);
|
|
335
|
+
ctx.rotate(charBox.angle);
|
|
336
|
+
ctx.fillStyle = currentColor;
|
|
337
|
+
currentColor &&
|
|
338
|
+
ctx.fillRect(-charBox.width / 2, (-heightOfLine / this.lineHeight) * (1 - this._fontSizeFraction), charBox.width, heightOfLine / this.lineHeight);
|
|
339
|
+
ctx.restore();
|
|
340
|
+
}
|
|
341
|
+
else if (currentColor !== lastColor) {
|
|
342
|
+
drawStart = leftOffset + lineLeftOffset + boxStart;
|
|
343
|
+
if (this.direction === 'rtl') {
|
|
344
|
+
drawStart = this.width - drawStart - boxWidth;
|
|
345
|
+
}
|
|
346
|
+
ctx.fillStyle = lastColor;
|
|
347
|
+
lastColor &&
|
|
348
|
+
ctx.fillRect(drawStart, lineTopOffset, boxWidth, heightOfLine / this.lineHeight);
|
|
349
|
+
boxStart = charBox.left;
|
|
350
|
+
boxWidth = charBox.width;
|
|
351
|
+
lastColor = currentColor;
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
boxWidth += charBox.kernedWidth;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (currentColor && !this.path) {
|
|
358
|
+
drawStart = leftOffset + lineLeftOffset + boxStart;
|
|
359
|
+
if (this.direction === 'rtl') {
|
|
360
|
+
drawStart = this.width - drawStart - boxWidth;
|
|
361
|
+
}
|
|
362
|
+
ctx.fillStyle = currentColor;
|
|
363
|
+
ctx.fillRect(drawStart, lineTopOffset, boxWidth, heightOfLine / this.lineHeight);
|
|
364
|
+
}
|
|
365
|
+
lineTopOffset += heightOfLine;
|
|
366
|
+
}
|
|
367
|
+
ctx.fillStyle = originalFill;
|
|
368
|
+
// if there is text background color no
|
|
369
|
+
// other shadows should be casted
|
|
370
|
+
this._removeShadow(ctx);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* measure and return the width of a single character.
|
|
374
|
+
* possibly overridden to accommodate different measure logic or
|
|
375
|
+
* to hook some external lib for character measurement
|
|
376
|
+
* @private
|
|
377
|
+
* @param {String} _char, char to be measured
|
|
378
|
+
* @param {Object} charStyle style of char to be measured
|
|
379
|
+
* @param {String} [previousChar] previous char
|
|
380
|
+
* @param {Object} [prevCharStyle] style of previous char
|
|
381
|
+
*/
|
|
382
|
+
_measureChar(_char, charStyle, previousChar, prevCharStyle) {
|
|
383
|
+
const fontCache = cache.getFontCache(charStyle), fontDeclaration = this._getFontDeclaration(charStyle), couple = previousChar + _char, stylesAreEqual = previousChar &&
|
|
384
|
+
fontDeclaration === this._getFontDeclaration(prevCharStyle), fontMultiplier = charStyle.fontSize / this.CACHE_FONT_SIZE;
|
|
385
|
+
let width, coupleWidth, previousWidth, kernedWidth;
|
|
386
|
+
if (previousChar && fontCache[previousChar] !== undefined) {
|
|
387
|
+
previousWidth = fontCache[previousChar];
|
|
388
|
+
}
|
|
389
|
+
if (fontCache[_char] !== undefined) {
|
|
390
|
+
kernedWidth = width = fontCache[_char];
|
|
391
|
+
}
|
|
392
|
+
if (stylesAreEqual && fontCache[couple] !== undefined) {
|
|
393
|
+
coupleWidth = fontCache[couple];
|
|
394
|
+
kernedWidth = coupleWidth - previousWidth;
|
|
395
|
+
}
|
|
396
|
+
if (width === undefined ||
|
|
397
|
+
previousWidth === undefined ||
|
|
398
|
+
coupleWidth === undefined) {
|
|
399
|
+
const ctx = getMeasuringContext();
|
|
400
|
+
// send a TRUE to specify measuring font size CACHE_FONT_SIZE
|
|
401
|
+
this._setTextStyles(ctx, charStyle, true);
|
|
402
|
+
if (width === undefined) {
|
|
403
|
+
kernedWidth = width = ctx.measureText(_char).width;
|
|
404
|
+
fontCache[_char] = width;
|
|
405
|
+
}
|
|
406
|
+
if (previousWidth === undefined && stylesAreEqual && previousChar) {
|
|
407
|
+
previousWidth = ctx.measureText(previousChar).width;
|
|
408
|
+
fontCache[previousChar] = previousWidth;
|
|
409
|
+
}
|
|
410
|
+
if (stylesAreEqual && coupleWidth === undefined) {
|
|
411
|
+
// we can measure the kerning couple and subtract the width of the previous character
|
|
412
|
+
coupleWidth = ctx.measureText(couple).width;
|
|
413
|
+
fontCache[couple] = coupleWidth;
|
|
414
|
+
// safe to use the non-null since if undefined we defined it before.
|
|
415
|
+
kernedWidth = coupleWidth - previousWidth;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return {
|
|
419
|
+
width: width * fontMultiplier,
|
|
420
|
+
kernedWidth: kernedWidth * fontMultiplier,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Computes height of character at given position
|
|
425
|
+
* @param {Number} line the line index number
|
|
426
|
+
* @param {Number} _char the character index number
|
|
427
|
+
* @return {Number} fontSize of the character
|
|
428
|
+
*/
|
|
429
|
+
getHeightOfChar(line, _char) {
|
|
430
|
+
return this.getValueOfPropertyAt(line, _char, 'fontSize');
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* measure a text line measuring all characters.
|
|
434
|
+
* @param {Number} lineIndex line number
|
|
435
|
+
*/
|
|
436
|
+
measureLine(lineIndex) {
|
|
437
|
+
const lineInfo = this._measureLine(lineIndex);
|
|
438
|
+
if (this.charSpacing !== 0) {
|
|
439
|
+
lineInfo.width -= this._getWidthOfCharSpacing();
|
|
440
|
+
}
|
|
441
|
+
if (lineInfo.width < 0) {
|
|
442
|
+
lineInfo.width = 0;
|
|
443
|
+
}
|
|
444
|
+
return lineInfo;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* measure every grapheme of a line, populating __charBounds
|
|
448
|
+
* @param {Number} lineIndex
|
|
449
|
+
* @return {Object} object.width total width of characters
|
|
450
|
+
* @return {Object} object.numOfSpaces length of chars that match this._reSpacesAndTabs
|
|
451
|
+
*/
|
|
452
|
+
_measureLine(lineIndex) {
|
|
453
|
+
let width = 0, prevGrapheme, graphemeInfo;
|
|
454
|
+
const reverse = this.pathSide === RIGHT, path = this.path, line = this._textLines[lineIndex], llength = line.length, lineBounds = new Array(llength);
|
|
455
|
+
this.__charBounds[lineIndex] = lineBounds;
|
|
456
|
+
for (let i = 0; i < llength; i++) {
|
|
457
|
+
const grapheme = line[i];
|
|
458
|
+
graphemeInfo = this._getGraphemeBox(grapheme, lineIndex, i, prevGrapheme);
|
|
459
|
+
lineBounds[i] = graphemeInfo;
|
|
460
|
+
width += graphemeInfo.kernedWidth;
|
|
461
|
+
prevGrapheme = grapheme;
|
|
462
|
+
}
|
|
463
|
+
// this latest bound box represent the last character of the line
|
|
464
|
+
// to simplify cursor handling in interactive mode.
|
|
465
|
+
lineBounds[llength] = {
|
|
466
|
+
left: graphemeInfo ? graphemeInfo.left + graphemeInfo.width : 0,
|
|
467
|
+
width: 0,
|
|
468
|
+
kernedWidth: 0,
|
|
469
|
+
height: this.fontSize,
|
|
470
|
+
deltaY: 0,
|
|
471
|
+
};
|
|
472
|
+
if (path && path.segmentsInfo) {
|
|
473
|
+
let positionInPath = 0;
|
|
474
|
+
const totalPathLength = path.segmentsInfo[path.segmentsInfo.length - 1].length;
|
|
475
|
+
switch (this.textAlign) {
|
|
476
|
+
case LEFT:
|
|
477
|
+
positionInPath = reverse ? totalPathLength - width : 0;
|
|
478
|
+
break;
|
|
479
|
+
case CENTER:
|
|
480
|
+
positionInPath = (totalPathLength - width) / 2;
|
|
481
|
+
break;
|
|
482
|
+
case RIGHT:
|
|
483
|
+
positionInPath = reverse ? 0 : totalPathLength - width;
|
|
484
|
+
break;
|
|
485
|
+
//todo - add support for justify
|
|
486
|
+
}
|
|
487
|
+
positionInPath += this.pathStartOffset * (reverse ? -1 : 1);
|
|
488
|
+
for (let i = reverse ? llength - 1 : 0; reverse ? i >= 0 : i < llength; reverse ? i-- : i++) {
|
|
489
|
+
graphemeInfo = lineBounds[i];
|
|
490
|
+
// James modified
|
|
491
|
+
/* if (positionInPath > totalPathLength) {
|
|
492
|
+
positionInPath %= totalPathLength;
|
|
493
|
+
} else if (positionInPath < 0) {
|
|
494
|
+
positionInPath += totalPathLength;
|
|
495
|
+
} */
|
|
496
|
+
// 超过路径范围外不显示
|
|
497
|
+
var visible = false;
|
|
498
|
+
var tolerance = 2;
|
|
499
|
+
if (positionInPath >= 0 - tolerance &&
|
|
500
|
+
positionInPath + graphemeInfo.kernedWidth <=
|
|
501
|
+
totalPathLength + tolerance) {
|
|
502
|
+
visible = true;
|
|
503
|
+
}
|
|
504
|
+
if (visible) {
|
|
505
|
+
// it would probably much faster to send all the grapheme position for a line
|
|
506
|
+
// and calculate path position/angle at once.
|
|
507
|
+
this._setGraphemeOnPath(positionInPath, graphemeInfo);
|
|
508
|
+
}
|
|
509
|
+
positionInPath += graphemeInfo.kernedWidth;
|
|
510
|
+
graphemeInfo.visible = visible;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return { width: width, numOfSpaces: 0 };
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Calculate the angle and the left,top position of the char that follow a path.
|
|
517
|
+
* It appends it to graphemeInfo to be reused later at rendering
|
|
518
|
+
* @private
|
|
519
|
+
* @param {Number} positionInPath to be measured
|
|
520
|
+
* @param {GraphemeBBox} graphemeInfo current grapheme box information
|
|
521
|
+
* @param {Object} startingPoint position of the point
|
|
522
|
+
*/
|
|
523
|
+
_setGraphemeOnPath(positionInPath, graphemeInfo) {
|
|
524
|
+
const centerPosition = positionInPath + graphemeInfo.kernedWidth / 2, path = this.path;
|
|
525
|
+
// we are at currentPositionOnPath. we want to know what point on the path is.
|
|
526
|
+
const info = getPointOnPath(path.path, centerPosition, path.segmentsInfo);
|
|
527
|
+
graphemeInfo.renderLeft = info.x - path.pathOffset.x;
|
|
528
|
+
graphemeInfo.renderTop = info.y - path.pathOffset.y;
|
|
529
|
+
graphemeInfo.angle = info.angle + (this.pathSide === RIGHT ? Math.PI : 0);
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
*
|
|
533
|
+
* @param {String} grapheme to be measured
|
|
534
|
+
* @param {Number} lineIndex index of the line where the char is
|
|
535
|
+
* @param {Number} charIndex position in the line
|
|
536
|
+
* @param {String} [prevGrapheme] character preceding the one to be measured
|
|
537
|
+
* @returns {GraphemeBBox} grapheme bbox
|
|
538
|
+
*/
|
|
539
|
+
_getGraphemeBox(grapheme, lineIndex, charIndex, prevGrapheme, skipLeft) {
|
|
540
|
+
const style = this.getCompleteStyleDeclaration(lineIndex, charIndex), prevStyle = prevGrapheme
|
|
541
|
+
? this.getCompleteStyleDeclaration(lineIndex, charIndex - 1)
|
|
542
|
+
: {}, info = this._measureChar(grapheme, style, prevGrapheme, prevStyle);
|
|
543
|
+
let kernedWidth = info.kernedWidth, width = info.width, charSpacing;
|
|
544
|
+
if (this.charSpacing !== 0) {
|
|
545
|
+
charSpacing = this._getWidthOfCharSpacing();
|
|
546
|
+
width += charSpacing;
|
|
547
|
+
kernedWidth += charSpacing;
|
|
548
|
+
}
|
|
549
|
+
const box = {
|
|
550
|
+
width,
|
|
551
|
+
left: 0,
|
|
552
|
+
height: style.fontSize,
|
|
553
|
+
kernedWidth,
|
|
554
|
+
deltaY: style.deltaY,
|
|
555
|
+
};
|
|
556
|
+
if (charIndex > 0 && !skipLeft) {
|
|
557
|
+
const previousBox = this.__charBounds[lineIndex][charIndex - 1];
|
|
558
|
+
box.left =
|
|
559
|
+
previousBox.left + previousBox.width + info.kernedWidth - info.width;
|
|
560
|
+
}
|
|
561
|
+
return box;
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Calculate height of line at 'lineIndex'
|
|
565
|
+
* @param {Number} lineIndex index of line to calculate
|
|
566
|
+
* @return {Number}
|
|
567
|
+
*/
|
|
568
|
+
getHeightOfLine(lineIndex) {
|
|
569
|
+
if (this.__lineHeights[lineIndex]) {
|
|
570
|
+
return this.__lineHeights[lineIndex];
|
|
571
|
+
}
|
|
572
|
+
// char 0 is measured before the line cycle because it needs to char
|
|
573
|
+
// emptylines
|
|
574
|
+
let maxHeight = this.getHeightOfChar(lineIndex, 0);
|
|
575
|
+
for (let i = 1, len = this._textLines[lineIndex].length; i < len; i++) {
|
|
576
|
+
maxHeight = Math.max(this.getHeightOfChar(lineIndex, i), maxHeight);
|
|
577
|
+
}
|
|
578
|
+
return (this.__lineHeights[lineIndex] =
|
|
579
|
+
maxHeight * this.lineHeight * this._fontSizeMult);
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Calculate text box height
|
|
583
|
+
*/
|
|
584
|
+
calcTextHeight() {
|
|
585
|
+
let lineHeight, height = 0;
|
|
586
|
+
for (let i = 0, len = this._textLines.length; i < len; i++) {
|
|
587
|
+
lineHeight = this.getHeightOfLine(i);
|
|
588
|
+
height += i === len - 1 ? lineHeight / this.lineHeight : lineHeight;
|
|
589
|
+
}
|
|
590
|
+
return height;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* @private
|
|
594
|
+
* @return {Number} Left offset
|
|
595
|
+
*/
|
|
596
|
+
_getLeftOffset() {
|
|
597
|
+
return this.direction === 'ltr' ? -this.width / 2 : this.width / 2;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* @private
|
|
601
|
+
* @return {Number} Top offset
|
|
602
|
+
*/
|
|
603
|
+
_getTopOffset() {
|
|
604
|
+
return -this.height / 2;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* James add
|
|
608
|
+
* 是否应该按行隐藏文字
|
|
609
|
+
* @returns
|
|
610
|
+
*/
|
|
611
|
+
_shouldHideTextLine() {
|
|
612
|
+
return !this.isEditing && !this.path;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* James modified
|
|
616
|
+
* 框子外的文字不绘制
|
|
617
|
+
* @private
|
|
618
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
619
|
+
* @param {String} method Method name ("fillText" or "strokeText")
|
|
620
|
+
*/
|
|
621
|
+
_renderTextCommon(ctx, method) {
|
|
622
|
+
ctx.save();
|
|
623
|
+
let lineHeights = 0;
|
|
624
|
+
const left = this._getLeftOffset(), top = this._getTopOffset();
|
|
625
|
+
// 存在隐藏文字
|
|
626
|
+
this.hasHideText = false;
|
|
627
|
+
for (let i = 0, len = this._textLines.length; i < len; i++) {
|
|
628
|
+
const heightOfLine = this.getHeightOfLine(i), maxHeight = heightOfLine / this.lineHeight, leftOffset = this._getLineLeftOffset(i);
|
|
629
|
+
// 非编辑状态超过box 不显示
|
|
630
|
+
if (this._shouldHideTextLine() &&
|
|
631
|
+
lineHeights + maxHeight * 0.8 > this.height) {
|
|
632
|
+
this.hasHideText = true;
|
|
633
|
+
break;
|
|
634
|
+
}
|
|
635
|
+
this._renderTextLine(method, ctx, this._textLines[i], left + leftOffset, top + lineHeights + maxHeight, i);
|
|
636
|
+
lineHeights += heightOfLine;
|
|
637
|
+
}
|
|
638
|
+
ctx.restore();
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* James add
|
|
642
|
+
* 增加隐藏文字图标
|
|
643
|
+
*/
|
|
644
|
+
showHideTextIcon() {
|
|
645
|
+
const control = this.controls?.['mb'];
|
|
646
|
+
if (control) {
|
|
647
|
+
control.render = (ctx, left, top, styleOverride, fabricObject) => {
|
|
648
|
+
styleOverride = styleOverride || {};
|
|
649
|
+
if (this.hasHideText) {
|
|
650
|
+
styleOverride = {
|
|
651
|
+
...styleOverride,
|
|
652
|
+
cornerStrokeColor: '#FF0000',
|
|
653
|
+
cornerSize: 10,
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
switch (styleOverride.cornerStyle || fabricObject.cornerStyle) {
|
|
657
|
+
case 'circle':
|
|
658
|
+
renderCircleControl.call(control, ctx, left, top, styleOverride, fabricObject);
|
|
659
|
+
break;
|
|
660
|
+
default:
|
|
661
|
+
renderSquareControl.call(control, ctx, left, top, styleOverride, fabricObject);
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* @private
|
|
668
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
669
|
+
*/
|
|
670
|
+
_renderTextFill(ctx) {
|
|
671
|
+
if (!this.fill && !this.styleHas(FILL)) {
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
this._renderTextCommon(ctx, 'fillText');
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* @private
|
|
678
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
679
|
+
*/
|
|
680
|
+
_renderTextStroke(ctx) {
|
|
681
|
+
if ((!this.stroke || this.strokeWidth === 0) && this.isEmptyStyles()) {
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
if (this.shadow && !this.shadow.affectStroke) {
|
|
685
|
+
this._removeShadow(ctx);
|
|
686
|
+
}
|
|
687
|
+
ctx.save();
|
|
688
|
+
this._setLineDash(ctx, this.strokeDashArray);
|
|
689
|
+
ctx.beginPath();
|
|
690
|
+
this._renderTextCommon(ctx, 'strokeText');
|
|
691
|
+
ctx.closePath();
|
|
692
|
+
ctx.restore();
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* @private
|
|
696
|
+
* @param {String} method fillText or strokeText.
|
|
697
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
698
|
+
* @param {Array} line Content of the line, splitted in an array by grapheme
|
|
699
|
+
* @param {Number} left
|
|
700
|
+
* @param {Number} top
|
|
701
|
+
* @param {Number} lineIndex
|
|
702
|
+
*/
|
|
703
|
+
_renderChars(method, ctx, line, left, top, lineIndex) {
|
|
704
|
+
const lineHeight = this.getHeightOfLine(lineIndex), isJustify = this.textAlign.includes(JUSTIFY), path = this.path, shortCut = !isJustify &&
|
|
705
|
+
this.charSpacing === 0 &&
|
|
706
|
+
this.isEmptyStyles(lineIndex) &&
|
|
707
|
+
!path, isLtr = this.direction === 'ltr', sign = this.direction === 'ltr' ? 1 : -1,
|
|
708
|
+
// James modified
|
|
709
|
+
// 修改为之前绘制 direction rtl的方式,5.3.0版本的绘制方式显示有问题
|
|
710
|
+
// this was changed in the PR #7674
|
|
711
|
+
// currentDirection = ctx.canvas.getAttribute('dir');
|
|
712
|
+
currentDirection = ctx.direction;
|
|
713
|
+
let actualStyle, nextStyle, charsToRender = '', charBox, boxWidth = 0, timeToRender, drawingLeft;
|
|
714
|
+
ctx.save();
|
|
715
|
+
if (currentDirection !== this.direction) {
|
|
716
|
+
ctx.canvas.setAttribute('dir', isLtr ? 'ltr' : 'rtl');
|
|
717
|
+
// James modified
|
|
718
|
+
ctx.direction = isLtr ? 'ltr' : 'rtl';
|
|
719
|
+
ctx.textAlign = isLtr ? LEFT : RIGHT;
|
|
720
|
+
}
|
|
721
|
+
top -= (lineHeight * this._fontSizeFraction) / this.lineHeight;
|
|
722
|
+
if (shortCut) {
|
|
723
|
+
// render all the line in one pass without checking
|
|
724
|
+
// drawingLeft = isLtr ? left : left - this.getLineWidth(lineIndex);
|
|
725
|
+
// James modified
|
|
726
|
+
this._renderChar(method, ctx, lineIndex, 0, line.join(''), left, top);
|
|
727
|
+
ctx.restore();
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
for (let i = 0, len = line.length - 1; i <= len; i++) {
|
|
731
|
+
timeToRender = i === len || this.charSpacing || path;
|
|
732
|
+
charsToRender += line[i];
|
|
733
|
+
charBox = this.__charBounds[lineIndex][i];
|
|
734
|
+
if (boxWidth === 0) {
|
|
735
|
+
left += sign * (charBox.kernedWidth - charBox.width);
|
|
736
|
+
boxWidth += charBox.width;
|
|
737
|
+
}
|
|
738
|
+
else {
|
|
739
|
+
boxWidth += charBox.kernedWidth;
|
|
740
|
+
}
|
|
741
|
+
if (isJustify && !timeToRender) {
|
|
742
|
+
if (this._reSpaceAndTab.test(line[i])) {
|
|
743
|
+
timeToRender = true;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
if (!timeToRender) {
|
|
747
|
+
// if we have charSpacing, we render char by char
|
|
748
|
+
actualStyle =
|
|
749
|
+
actualStyle || this.getCompleteStyleDeclaration(lineIndex, i);
|
|
750
|
+
nextStyle = this.getCompleteStyleDeclaration(lineIndex, i + 1);
|
|
751
|
+
timeToRender = hasStyleChanged(actualStyle, nextStyle, false);
|
|
752
|
+
}
|
|
753
|
+
if (timeToRender) {
|
|
754
|
+
// James modified
|
|
755
|
+
if (path && !this.isEditing) {
|
|
756
|
+
if (charBox.visible) {
|
|
757
|
+
ctx.save();
|
|
758
|
+
ctx.translate(charBox.renderLeft, charBox.renderTop);
|
|
759
|
+
ctx.rotate(charBox.angle);
|
|
760
|
+
this._renderChar(method, ctx, lineIndex, i, charsToRender, -boxWidth / 2, 0);
|
|
761
|
+
ctx.restore();
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
else {
|
|
765
|
+
drawingLeft = left;
|
|
766
|
+
this._renderChar(method, ctx, lineIndex, i, charsToRender, drawingLeft, top);
|
|
767
|
+
}
|
|
768
|
+
charsToRender = '';
|
|
769
|
+
actualStyle = nextStyle;
|
|
770
|
+
left += sign * boxWidth;
|
|
771
|
+
boxWidth = 0;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
ctx.restore();
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* This function try to patch the missing gradientTransform on canvas gradients.
|
|
778
|
+
* transforming a context to transform the gradient, is going to transform the stroke too.
|
|
779
|
+
* we want to transform the gradient but not the stroke operation, so we create
|
|
780
|
+
* a transformed gradient on a pattern and then we use the pattern instead of the gradient.
|
|
781
|
+
* this method has drawbacks: is slow, is in low resolution, needs a patch for when the size
|
|
782
|
+
* is limited.
|
|
783
|
+
* @private
|
|
784
|
+
* @param {TFiller} filler a fabric gradient instance
|
|
785
|
+
* @return {CanvasPattern} a pattern to use as fill/stroke style
|
|
786
|
+
*/
|
|
787
|
+
_applyPatternGradientTransformText(filler) {
|
|
788
|
+
// TODO: verify compatibility with strokeUniform
|
|
789
|
+
const width = this.width + this.strokeWidth, height = this.height + this.strokeWidth, pCanvas = createCanvasElementFor({
|
|
790
|
+
width,
|
|
791
|
+
height,
|
|
792
|
+
}), pCtx = pCanvas.getContext('2d');
|
|
793
|
+
pCanvas.width = width;
|
|
794
|
+
pCanvas.height = height;
|
|
795
|
+
pCtx.beginPath();
|
|
796
|
+
pCtx.moveTo(0, 0);
|
|
797
|
+
pCtx.lineTo(width, 0);
|
|
798
|
+
pCtx.lineTo(width, height);
|
|
799
|
+
pCtx.lineTo(0, height);
|
|
800
|
+
pCtx.closePath();
|
|
801
|
+
pCtx.translate(width / 2, height / 2);
|
|
802
|
+
pCtx.fillStyle = filler.toLive(pCtx);
|
|
803
|
+
this._applyPatternGradientTransform(pCtx, filler);
|
|
804
|
+
pCtx.fill();
|
|
805
|
+
return pCtx.createPattern(pCanvas, 'no-repeat');
|
|
806
|
+
}
|
|
807
|
+
handleFiller(ctx, property, filler) {
|
|
808
|
+
let offsetX, offsetY;
|
|
809
|
+
if (isFiller(filler)) {
|
|
810
|
+
if (filler.gradientUnits === 'percentage' ||
|
|
811
|
+
filler.gradientTransform ||
|
|
812
|
+
filler.patternTransform) {
|
|
813
|
+
// need to transform gradient in a pattern.
|
|
814
|
+
// this is a slow process. If you are hitting this codepath, and the object
|
|
815
|
+
// is not using caching, you should consider switching it on.
|
|
816
|
+
// we need a canvas as big as the current object caching canvas.
|
|
817
|
+
offsetX = -this.width / 2;
|
|
818
|
+
offsetY = -this.height / 2;
|
|
819
|
+
ctx.translate(offsetX, offsetY);
|
|
820
|
+
ctx[property] = this._applyPatternGradientTransformText(filler);
|
|
821
|
+
return { offsetX, offsetY };
|
|
822
|
+
}
|
|
823
|
+
else {
|
|
824
|
+
// is a simple gradient or pattern
|
|
825
|
+
ctx[property] = filler.toLive(ctx);
|
|
826
|
+
return this._applyPatternGradientTransform(ctx, filler);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
else {
|
|
830
|
+
// is a color
|
|
831
|
+
ctx[property] = filler;
|
|
832
|
+
}
|
|
833
|
+
return { offsetX: 0, offsetY: 0 };
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* This function prepare the canvas for a stroke style, and stroke and strokeWidth
|
|
837
|
+
* need to be sent in as defined
|
|
838
|
+
* @param {CanvasRenderingContext2D} ctx
|
|
839
|
+
* @param {CompleteTextStyleDeclaration} style with stroke and strokeWidth defined
|
|
840
|
+
* @returns
|
|
841
|
+
*/
|
|
842
|
+
_setStrokeStyles(ctx, { stroke, strokeWidth, }) {
|
|
843
|
+
ctx.lineWidth = strokeWidth;
|
|
844
|
+
ctx.lineCap = this.strokeLineCap;
|
|
845
|
+
ctx.lineDashOffset = this.strokeDashOffset;
|
|
846
|
+
ctx.lineJoin = this.strokeLineJoin;
|
|
847
|
+
ctx.miterLimit = this.strokeMiterLimit;
|
|
848
|
+
return this.handleFiller(ctx, 'strokeStyle', stroke);
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* This function prepare the canvas for a ill style, and fill
|
|
852
|
+
* need to be sent in as defined
|
|
853
|
+
* @param {CanvasRenderingContext2D} ctx
|
|
854
|
+
* @param {CompleteTextStyleDeclaration} style with ill defined
|
|
855
|
+
* @returns
|
|
856
|
+
*/
|
|
857
|
+
_setFillStyles(ctx, { fill }) {
|
|
858
|
+
return this.handleFiller(ctx, 'fillStyle', fill);
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* @private
|
|
862
|
+
* @param {String} method
|
|
863
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
864
|
+
* @param {Number} lineIndex
|
|
865
|
+
* @param {Number} charIndex
|
|
866
|
+
* @param {String} _char
|
|
867
|
+
* @param {Number} left Left coordinate
|
|
868
|
+
* @param {Number} top Top coordinate
|
|
869
|
+
* @param {Number} lineHeight Height of the line
|
|
870
|
+
*/
|
|
871
|
+
_renderChar(method, ctx, lineIndex, charIndex, _char, left, top) {
|
|
872
|
+
const decl = this._getStyleDeclaration(lineIndex, charIndex), fullDecl = this.getCompleteStyleDeclaration(lineIndex, charIndex), shouldFill = method === 'fillText' && fullDecl.fill, shouldStroke = method === 'strokeText' && fullDecl.stroke && fullDecl.strokeWidth;
|
|
873
|
+
if (!shouldStroke && !shouldFill) {
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
ctx.save();
|
|
877
|
+
ctx.font = this._getFontDeclaration(fullDecl);
|
|
878
|
+
if (decl.textBackgroundColor) {
|
|
879
|
+
this._removeShadow(ctx);
|
|
880
|
+
}
|
|
881
|
+
if (decl.deltaY) {
|
|
882
|
+
top += decl.deltaY;
|
|
883
|
+
}
|
|
884
|
+
if (shouldFill) {
|
|
885
|
+
const fillOffsets = this._setFillStyles(ctx, fullDecl);
|
|
886
|
+
ctx.fillText(_char, left - fillOffsets.offsetX, top - fillOffsets.offsetY);
|
|
887
|
+
}
|
|
888
|
+
if (shouldStroke) {
|
|
889
|
+
const strokeOffsets = this._setStrokeStyles(ctx, fullDecl);
|
|
890
|
+
ctx.strokeText(_char, left - strokeOffsets.offsetX, top - strokeOffsets.offsetY);
|
|
891
|
+
}
|
|
892
|
+
ctx.restore();
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* Turns the character into a 'superior figure' (i.e. 'superscript')
|
|
896
|
+
* @param {Number} start selection start
|
|
897
|
+
* @param {Number} end selection end
|
|
898
|
+
*/
|
|
899
|
+
setSuperscript(start, end) {
|
|
900
|
+
this._setScript(start, end, this.superscript);
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Turns the character into an 'inferior figure' (i.e. 'subscript')
|
|
904
|
+
* @param {Number} start selection start
|
|
905
|
+
* @param {Number} end selection end
|
|
906
|
+
*/
|
|
907
|
+
setSubscript(start, end) {
|
|
908
|
+
this._setScript(start, end, this.subscript);
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Applies 'schema' at given position
|
|
912
|
+
* @private
|
|
913
|
+
* @param {Number} start selection start
|
|
914
|
+
* @param {Number} end selection end
|
|
915
|
+
* @param {Number} schema
|
|
916
|
+
*/
|
|
917
|
+
_setScript(start, end, schema) {
|
|
918
|
+
const loc = this.get2DCursorLocation(start, true), fontSize = this.getValueOfPropertyAt(loc.lineIndex, loc.charIndex, 'fontSize'), dy = this.getValueOfPropertyAt(loc.lineIndex, loc.charIndex, 'deltaY'), style = {
|
|
919
|
+
fontSize: fontSize * schema.size,
|
|
920
|
+
deltaY: dy + fontSize * schema.baseline,
|
|
921
|
+
};
|
|
922
|
+
this.setSelectionStyles(style, start, end);
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* @private
|
|
926
|
+
* @param {Number} lineIndex index text line
|
|
927
|
+
* @return {Number} Line left offset
|
|
928
|
+
*/
|
|
929
|
+
_getLineLeftOffset(lineIndex) {
|
|
930
|
+
const lineWidth = this.getLineWidth(lineIndex), lineDiff = this.width - lineWidth, textAlign = this.textAlign, direction = this.direction, isEndOfWrapping = this.isEndOfWrapping(lineIndex);
|
|
931
|
+
let leftOffset = 0;
|
|
932
|
+
if (textAlign === JUSTIFY ||
|
|
933
|
+
(textAlign === JUSTIFY_CENTER && !isEndOfWrapping) ||
|
|
934
|
+
(textAlign === JUSTIFY_RIGHT && !isEndOfWrapping) ||
|
|
935
|
+
(textAlign === JUSTIFY_LEFT && !isEndOfWrapping)) {
|
|
936
|
+
return 0;
|
|
937
|
+
}
|
|
938
|
+
if (textAlign === CENTER) {
|
|
939
|
+
leftOffset = lineDiff / 2;
|
|
940
|
+
}
|
|
941
|
+
if (textAlign === RIGHT) {
|
|
942
|
+
leftOffset = lineDiff;
|
|
943
|
+
}
|
|
944
|
+
if (textAlign === JUSTIFY_CENTER) {
|
|
945
|
+
leftOffset = lineDiff / 2;
|
|
946
|
+
}
|
|
947
|
+
if (textAlign === JUSTIFY_RIGHT) {
|
|
948
|
+
leftOffset = lineDiff;
|
|
949
|
+
}
|
|
950
|
+
if (direction === 'rtl') {
|
|
951
|
+
if (textAlign === RIGHT ||
|
|
952
|
+
textAlign === JUSTIFY ||
|
|
953
|
+
textAlign === JUSTIFY_RIGHT) {
|
|
954
|
+
leftOffset = 0;
|
|
955
|
+
}
|
|
956
|
+
else if (textAlign === LEFT || textAlign === JUSTIFY_LEFT) {
|
|
957
|
+
leftOffset = -lineDiff;
|
|
958
|
+
}
|
|
959
|
+
else if (textAlign === CENTER || textAlign === JUSTIFY_CENTER) {
|
|
960
|
+
leftOffset = -lineDiff / 2;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
return leftOffset;
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* @private
|
|
967
|
+
*/
|
|
968
|
+
_clearCache() {
|
|
969
|
+
this._forceClearCache = false;
|
|
970
|
+
this.__lineWidths = [];
|
|
971
|
+
this.__lineHeights = [];
|
|
972
|
+
this.__charBounds = [];
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Measure a single line given its index. Used to calculate the initial
|
|
976
|
+
* text bounding box. The values are calculated and stored in __lineWidths cache.
|
|
977
|
+
* @private
|
|
978
|
+
* @param {Number} lineIndex line number
|
|
979
|
+
* @return {Number} Line width
|
|
980
|
+
*/
|
|
981
|
+
getLineWidth(lineIndex) {
|
|
982
|
+
if (this.__lineWidths[lineIndex] !== undefined) {
|
|
983
|
+
return this.__lineWidths[lineIndex];
|
|
984
|
+
}
|
|
985
|
+
const { width } = this.measureLine(lineIndex);
|
|
986
|
+
this.__lineWidths[lineIndex] = width;
|
|
987
|
+
return width;
|
|
988
|
+
}
|
|
989
|
+
_getWidthOfCharSpacing() {
|
|
990
|
+
if (this.charSpacing !== 0) {
|
|
991
|
+
return (this.fontSize * this.charSpacing) / 1000;
|
|
992
|
+
}
|
|
993
|
+
return 0;
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* Retrieves the value of property at given character position
|
|
997
|
+
* @param {Number} lineIndex the line number
|
|
998
|
+
* @param {Number} charIndex the character number
|
|
999
|
+
* @param {String} property the property name
|
|
1000
|
+
* @returns the value of 'property'
|
|
1001
|
+
*/
|
|
1002
|
+
getValueOfPropertyAt(lineIndex, charIndex, property) {
|
|
1003
|
+
const charStyle = this._getStyleDeclaration(lineIndex, charIndex);
|
|
1004
|
+
return (charStyle[property] ?? this[property]);
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* @private
|
|
1008
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
1009
|
+
*/
|
|
1010
|
+
_renderTextDecoration(ctx, type) {
|
|
1011
|
+
if (!this[type] && !this.styleHas(type)) {
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
let topOffset = this._getTopOffset();
|
|
1015
|
+
const leftOffset = this._getLeftOffset(), path = this.path, charSpacing = this._getWidthOfCharSpacing(), offsetAligner = type === 'linethrough' ? 0.5 : type === 'overline' ? 1 : 0, offsetY = this.offsets[type];
|
|
1016
|
+
for (let i = 0, len = this._textLines.length; i < len; i++) {
|
|
1017
|
+
const heightOfLine = this.getHeightOfLine(i);
|
|
1018
|
+
if (!this[type] && !this.styleHas(type, i)) {
|
|
1019
|
+
topOffset += heightOfLine;
|
|
1020
|
+
continue;
|
|
1021
|
+
}
|
|
1022
|
+
const line = this._textLines[i];
|
|
1023
|
+
const maxHeight = heightOfLine / this.lineHeight;
|
|
1024
|
+
const lineLeftOffset = this._getLineLeftOffset(i);
|
|
1025
|
+
let boxStart = 0;
|
|
1026
|
+
let boxWidth = 0;
|
|
1027
|
+
let lastDecoration = this.getValueOfPropertyAt(i, 0, type);
|
|
1028
|
+
let lastFill = this.getValueOfPropertyAt(i, 0, FILL);
|
|
1029
|
+
let lastTickness = this.getValueOfPropertyAt(i, 0, TEXT_DECORATION_THICKNESS);
|
|
1030
|
+
let currentDecoration = lastDecoration;
|
|
1031
|
+
let currentFill = lastFill;
|
|
1032
|
+
let currentTickness = lastTickness;
|
|
1033
|
+
const top = topOffset + maxHeight * (1 - this._fontSizeFraction);
|
|
1034
|
+
let size = this.getHeightOfChar(i, 0);
|
|
1035
|
+
let dy = this.getValueOfPropertyAt(i, 0, 'deltaY');
|
|
1036
|
+
for (let j = 0, jlen = line.length; j < jlen; j++) {
|
|
1037
|
+
const charBox = this.__charBounds[i][j];
|
|
1038
|
+
currentDecoration = this.getValueOfPropertyAt(i, j, type);
|
|
1039
|
+
currentFill = this.getValueOfPropertyAt(i, j, FILL);
|
|
1040
|
+
currentTickness = this.getValueOfPropertyAt(i, j, TEXT_DECORATION_THICKNESS);
|
|
1041
|
+
const currentSize = this.getHeightOfChar(i, j);
|
|
1042
|
+
const currentDy = this.getValueOfPropertyAt(i, j, 'deltaY');
|
|
1043
|
+
if (path && currentDecoration && currentFill) {
|
|
1044
|
+
const finalTickness = (this.fontSize * currentTickness) / 1000;
|
|
1045
|
+
ctx.save();
|
|
1046
|
+
// bug? verify lastFill is a valid fill here.
|
|
1047
|
+
ctx.fillStyle = lastFill;
|
|
1048
|
+
ctx.translate(charBox.renderLeft, charBox.renderTop);
|
|
1049
|
+
ctx.rotate(charBox.angle);
|
|
1050
|
+
ctx.fillRect(-charBox.kernedWidth / 2, offsetY * currentSize + currentDy - offsetAligner * finalTickness, charBox.kernedWidth, finalTickness);
|
|
1051
|
+
ctx.restore();
|
|
1052
|
+
}
|
|
1053
|
+
else if ((currentDecoration !== lastDecoration ||
|
|
1054
|
+
currentFill !== lastFill ||
|
|
1055
|
+
currentSize !== size ||
|
|
1056
|
+
currentTickness !== lastTickness ||
|
|
1057
|
+
currentDy !== dy) &&
|
|
1058
|
+
boxWidth > 0) {
|
|
1059
|
+
const finalTickness = (this.fontSize * lastTickness) / 1000;
|
|
1060
|
+
let drawStart = leftOffset + lineLeftOffset + boxStart;
|
|
1061
|
+
if (this.direction === 'rtl') {
|
|
1062
|
+
drawStart = this.width - drawStart - boxWidth;
|
|
1063
|
+
}
|
|
1064
|
+
if (lastDecoration && lastFill && lastTickness) {
|
|
1065
|
+
// bug? verify lastFill is a valid fill here.
|
|
1066
|
+
ctx.fillStyle = lastFill;
|
|
1067
|
+
ctx.fillRect(drawStart, top + offsetY * size + dy - offsetAligner * finalTickness, boxWidth, finalTickness);
|
|
1068
|
+
}
|
|
1069
|
+
boxStart = charBox.left;
|
|
1070
|
+
boxWidth = charBox.width;
|
|
1071
|
+
lastDecoration = currentDecoration;
|
|
1072
|
+
lastTickness = currentTickness;
|
|
1073
|
+
lastFill = currentFill;
|
|
1074
|
+
size = currentSize;
|
|
1075
|
+
dy = currentDy;
|
|
1076
|
+
}
|
|
1077
|
+
else {
|
|
1078
|
+
boxWidth += charBox.kernedWidth;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
let drawStart = leftOffset + lineLeftOffset + boxStart;
|
|
1082
|
+
if (this.direction === 'rtl') {
|
|
1083
|
+
drawStart = this.width - drawStart - boxWidth;
|
|
1084
|
+
}
|
|
1085
|
+
ctx.fillStyle = currentFill;
|
|
1086
|
+
const finalTickness = (this.fontSize * currentTickness) / 1000;
|
|
1087
|
+
currentDecoration &&
|
|
1088
|
+
currentFill &&
|
|
1089
|
+
currentTickness &&
|
|
1090
|
+
ctx.fillRect(drawStart, top + offsetY * size + dy - offsetAligner * finalTickness, boxWidth - charSpacing, finalTickness);
|
|
1091
|
+
topOffset += heightOfLine;
|
|
1092
|
+
}
|
|
1093
|
+
// if there is text background color no
|
|
1094
|
+
// other shadows should be casted
|
|
1095
|
+
this._removeShadow(ctx);
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* return font declaration string for canvas context
|
|
1099
|
+
* @param {Object} [styleObject] object
|
|
1100
|
+
* @returns {String} font declaration formatted for canvas context.
|
|
1101
|
+
*/
|
|
1102
|
+
_getFontDeclaration({ fontFamily = this.fontFamily, fontStyle = this.fontStyle, fontWeight = this.fontWeight, fontSize = this.fontSize, } = {}, forMeasuring) {
|
|
1103
|
+
const parsedFontFamily = fontFamily.includes("'") ||
|
|
1104
|
+
fontFamily.includes('"') ||
|
|
1105
|
+
fontFamily.includes(',') ||
|
|
1106
|
+
FabricText.genericFonts.includes(fontFamily.toLowerCase())
|
|
1107
|
+
? fontFamily
|
|
1108
|
+
: `"${fontFamily}"`;
|
|
1109
|
+
return [
|
|
1110
|
+
fontStyle,
|
|
1111
|
+
fontWeight,
|
|
1112
|
+
`${forMeasuring ? this.CACHE_FONT_SIZE : fontSize}px`,
|
|
1113
|
+
parsedFontFamily,
|
|
1114
|
+
].join(' ');
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Renders text instance on a specified context
|
|
1118
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
1119
|
+
*/
|
|
1120
|
+
render(ctx) {
|
|
1121
|
+
if (!this.visible) {
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
if (this.canvas &&
|
|
1125
|
+
this.canvas.skipOffscreen &&
|
|
1126
|
+
!this.group &&
|
|
1127
|
+
!this.isOnScreen()) {
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
if (this._forceClearCache) {
|
|
1131
|
+
this.initDimensions();
|
|
1132
|
+
}
|
|
1133
|
+
super.render(ctx);
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Override this method to customize grapheme splitting
|
|
1137
|
+
* @todo the util `graphemeSplit` needs to be injectable in some way.
|
|
1138
|
+
* is more comfortable to inject the correct util rather than having to override text
|
|
1139
|
+
* in the middle of the prototype chain
|
|
1140
|
+
* @param {string} value
|
|
1141
|
+
* @returns {string[]} array of graphemes
|
|
1142
|
+
*/
|
|
1143
|
+
graphemeSplit(value) {
|
|
1144
|
+
return graphemeSplit(value);
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Returns the text as an array of lines.
|
|
1148
|
+
* @param {String} text text to split
|
|
1149
|
+
* @returns Lines in the text
|
|
1150
|
+
*/
|
|
1151
|
+
_splitTextIntoLines(text) {
|
|
1152
|
+
// James modified 生成换行数据, 如果是path则不进行换行(删除换行字符)
|
|
1153
|
+
text = this.path ? text.replaceAll(/\r?\n/g, '') : text;
|
|
1154
|
+
const lines = text.split(this._reNewline), newLines = new Array(lines.length), newLine = ['\n'];
|
|
1155
|
+
let newText = [];
|
|
1156
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1157
|
+
newLines[i] = this.graphemeSplit(lines[i]);
|
|
1158
|
+
newText = newText.concat(newLines[i], newLine);
|
|
1159
|
+
}
|
|
1160
|
+
newText.pop();
|
|
1161
|
+
return {
|
|
1162
|
+
_unwrappedLines: newLines,
|
|
1163
|
+
lines: lines,
|
|
1164
|
+
graphemeText: newText,
|
|
1165
|
+
graphemeLines: newLines,
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* Returns object representation of an instance
|
|
1170
|
+
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
|
|
1171
|
+
* @return {Object} Object representation of an instance
|
|
1172
|
+
*/
|
|
1173
|
+
toObject(propertiesToInclude = []) {
|
|
1174
|
+
return {
|
|
1175
|
+
...super.toObject([...additionalProps, ...propertiesToInclude]),
|
|
1176
|
+
styles: stylesToArray(this.styles, this.text),
|
|
1177
|
+
...(this.path ? { path: this.path.toObject() } : {}),
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
set(key, value) {
|
|
1181
|
+
const { textLayoutProperties } = this.constructor;
|
|
1182
|
+
super.set(key, value);
|
|
1183
|
+
let needsDims = false;
|
|
1184
|
+
let isAddingPath = false;
|
|
1185
|
+
if (typeof key === 'object') {
|
|
1186
|
+
for (const _key in key) {
|
|
1187
|
+
if (_key === 'path') {
|
|
1188
|
+
this.setPathInfo();
|
|
1189
|
+
}
|
|
1190
|
+
needsDims = needsDims || textLayoutProperties.includes(_key);
|
|
1191
|
+
isAddingPath = isAddingPath || _key === 'path';
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
else {
|
|
1195
|
+
needsDims = textLayoutProperties.includes(key);
|
|
1196
|
+
isAddingPath = key === 'path';
|
|
1197
|
+
}
|
|
1198
|
+
if (isAddingPath) {
|
|
1199
|
+
this.setPathInfo();
|
|
1200
|
+
}
|
|
1201
|
+
if (needsDims && this.initialized) {
|
|
1202
|
+
this.initDimensions();
|
|
1203
|
+
this.setCoords();
|
|
1204
|
+
}
|
|
1205
|
+
return this;
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Returns complexity of an instance
|
|
1209
|
+
* @return {Number} complexity
|
|
1210
|
+
*/
|
|
1211
|
+
complexity() {
|
|
1212
|
+
return 1;
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* List of generic font families
|
|
1216
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/font-family#generic-name
|
|
1217
|
+
*/
|
|
1218
|
+
static genericFonts = [
|
|
1219
|
+
'serif',
|
|
1220
|
+
'sans-serif',
|
|
1221
|
+
'monospace',
|
|
1222
|
+
'cursive',
|
|
1223
|
+
'fantasy',
|
|
1224
|
+
'system-ui',
|
|
1225
|
+
'ui-serif',
|
|
1226
|
+
'ui-sans-serif',
|
|
1227
|
+
'ui-monospace',
|
|
1228
|
+
'ui-rounded',
|
|
1229
|
+
'math',
|
|
1230
|
+
'emoji',
|
|
1231
|
+
'fangsong',
|
|
1232
|
+
];
|
|
1233
|
+
/* _FROM_SVG_START_ */
|
|
1234
|
+
/**
|
|
1235
|
+
* List of attribute names to account for when parsing SVG element (used by {@link FabricText.fromElement})
|
|
1236
|
+
* @static
|
|
1237
|
+
* @memberOf Text
|
|
1238
|
+
* @see: http://www.w3.org/TR/SVG/text.html#TextElement
|
|
1239
|
+
*/
|
|
1240
|
+
static ATTRIBUTE_NAMES = SHARED_ATTRIBUTES.concat('x', 'y', 'dx', 'dy', 'font-family', 'font-style', 'font-weight', 'font-size', 'letter-spacing', 'text-decoration', 'text-anchor');
|
|
1241
|
+
/* _FROM_SVG_END_ */
|
|
1242
|
+
/**
|
|
1243
|
+
* Returns FabricText instance from an object representation
|
|
1244
|
+
* @param {Object} object plain js Object to create an instance from
|
|
1245
|
+
* @returns {Promise<FabricText>}
|
|
1246
|
+
*/
|
|
1247
|
+
static fromObject(object) {
|
|
1248
|
+
return this._fromObject({
|
|
1249
|
+
...object,
|
|
1250
|
+
styles: stylesFromArray(object.styles || {}, object.text),
|
|
1251
|
+
}, {
|
|
1252
|
+
extraParam: 'text',
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
applyMixins(FabricText, [TextSVGExportMixin]);
|
|
1257
|
+
classRegistry.setClass(FabricText);
|
|
1258
|
+
//# sourceMappingURL=Text.js.map
|