fabric 5.3.0 → 6.0.0-beta1
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/.babelrc +11 -0
- package/.babelrcAlt +19 -0
- package/.browserslistrc +5 -0
- package/.eslintrc.js +43 -0
- package/.eslintrc.json +38 -46
- package/.eslintrc_tests +12 -0
- package/.gitattributes +2 -0
- package/.prettierignore +16 -0
- package/.prettierrc +4 -0
- package/CHANGELOG.md +491 -189
- package/CONTRIBUTING.md +226 -58
- package/README.md +188 -239
- package/bower.json +1 -3
- package/dist/fabric.d.ts +1021 -0
- package/dist/index.cjs +28027 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.min.js +1 -0
- package/dist/index.mjs +27964 -0
- package/dist/index.mjs.map +1 -0
- package/dist/index.node.cjs +28092 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.d.ts +15 -0
- package/dist/index.node.mjs +28035 -0
- package/dist/index.node.mjs.map +1 -0
- package/dist/src/Collection.d.ts +126 -0
- package/dist/src/CommonMethods.d.ts +32 -0
- package/dist/src/EventTypeDefs.d.ts +226 -0
- package/dist/src/Intersection.d.ts +100 -0
- package/dist/src/Observable.d.ts +54 -0
- package/dist/src/Pattern.d.ts +104 -0
- package/dist/src/Point.d.ts +232 -0
- package/dist/src/Shadow.d.ts +87 -0
- package/dist/src/brushes/BaseBrush.d.ts +105 -0
- package/dist/src/brushes/CircleBrush.d.ts +49 -0
- package/dist/src/brushes/PatternBrush.d.ts +23 -0
- package/dist/src/brushes/PencilBrush.d.ts +92 -0
- package/dist/src/brushes/SprayBrush.d.ts +79 -0
- package/dist/src/cache.d.ts +46 -0
- package/dist/src/canvas/Canvas.d.ts +567 -0
- package/dist/src/canvas/SelectableCanvas.d.ts +723 -0
- package/dist/src/canvas/StaticCanvas.d.ts +751 -0
- package/dist/src/canvas/TextEditingManager.d.ts +17 -0
- package/dist/src/canvas/canvas_gestures.mixin.d.ts +2 -0
- package/dist/src/color/Color.d.ts +174 -0
- package/dist/src/color/color_map.d.ts +155 -0
- package/dist/src/color/constants.d.ts +22 -0
- package/dist/src/color/util.d.ts +12 -0
- package/dist/src/config.d.ts +115 -0
- package/dist/src/constants.d.ts +14 -0
- package/dist/src/controls/Control.d.ts +228 -0
- package/dist/src/controls/changeWidth.d.ts +13 -0
- package/dist/src/controls/controls.render.d.ts +29 -0
- package/dist/src/controls/default_controls.d.ts +50 -0
- package/dist/src/controls/drag.d.ts +12 -0
- package/dist/src/controls/polyControl.d.ts +5 -0
- package/dist/src/controls/rotate.d.ts +12 -0
- package/dist/src/controls/scale.d.ts +47 -0
- package/dist/src/controls/scaleSkew.d.ts +39 -0
- package/dist/src/controls/skew.d.ts +33 -0
- package/dist/src/controls/util.d.ts +41 -0
- package/dist/src/controls/wrapWithFireEvent.d.ts +8 -0
- package/dist/src/controls/wrapWithFixedAnchor.d.ts +9 -0
- package/dist/src/env/browser.d.ts +3 -0
- package/dist/src/env/index.d.ts +7 -0
- package/dist/src/env/node.d.ts +3 -0
- package/dist/src/env/types.d.ts +15 -0
- package/dist/src/filters/BaseFilter.d.ts +156 -0
- package/dist/src/filters/BlendColor.d.ts +80 -0
- package/dist/src/filters/BlendImage.d.ts +90 -0
- package/dist/src/filters/Blur.d.ts +50 -0
- package/dist/src/filters/Boilerplate.d.ts +46 -0
- package/dist/src/filters/Brightness.d.ts +46 -0
- package/dist/src/filters/Canvas2dFilterBackend.d.ts +27 -0
- package/dist/src/filters/ColorMatrix.d.ts +62 -0
- package/dist/src/filters/ColorMatrixFilters.d.ts +1169 -0
- package/dist/src/filters/Composed.d.ts +47 -0
- package/dist/src/filters/Contrast.d.ts +44 -0
- package/dist/src/filters/Convolute.d.ts +82 -0
- package/dist/src/filters/FilterBackend.d.ts +14 -0
- package/dist/src/filters/Gamma.d.ts +53 -0
- package/dist/src/filters/Grayscale.d.ts +45 -0
- package/dist/src/filters/HueRotation.d.ts +24 -0
- package/dist/src/filters/Invert.d.ts +54 -0
- package/dist/src/filters/Noise.d.ts +53 -0
- package/dist/src/filters/Pixelate.d.ts +43 -0
- package/dist/src/filters/RemoveColor.d.ts +62 -0
- package/dist/src/filters/Resize.d.ts +134 -0
- package/dist/src/filters/Saturation.d.ts +47 -0
- package/dist/src/filters/Vibrance.d.ts +47 -0
- package/dist/src/filters/WebGLFilterBackend.d.ts +126 -0
- package/dist/src/filters/WebGLProbe.d.ts +28 -0
- package/dist/src/filters/typedefs.d.ts +49 -0
- package/dist/src/gradient/Gradient.d.ts +149 -0
- package/dist/src/gradient/constants.d.ts +15 -0
- package/dist/src/gradient/parser/index.d.ts +4 -0
- package/dist/src/gradient/parser/misc.d.ts +4 -0
- package/dist/src/gradient/parser/parseColorStops.d.ts +6 -0
- package/dist/src/gradient/parser/parseCoords.d.ts +17 -0
- package/dist/src/gradient/typedefs.d.ts +93 -0
- package/dist/src/mixins/eraser_brush.mixin.d.ts +2 -0
- package/dist/src/mixins/stateful.mixin.d.ts +18 -0
- package/dist/src/parkinglot/canvas_animation.mixin.d.ts +2 -0
- package/dist/src/parkinglot/straighten.d.ts +2 -0
- package/dist/src/parser/applyViewboxTransform.d.ts +5 -0
- package/dist/src/parser/attributes.d.ts +6 -0
- package/dist/src/parser/constants.d.ts +54 -0
- package/dist/src/parser/doesSomeParentMatch.d.ts +2 -0
- package/dist/src/parser/elementById.d.ts +6 -0
- package/dist/src/parser/elementMatchesRule.d.ts +5 -0
- package/dist/src/parser/elements_parser.d.ts +3 -0
- package/dist/src/parser/getCSSRules.d.ts +7 -0
- package/dist/src/parser/getGlobalStylesForElement.d.ts +5 -0
- package/dist/src/parser/getGradientDefs.d.ts +7 -0
- package/dist/src/parser/getMultipleNodes.d.ts +2 -0
- package/dist/src/parser/getSvgRegex.d.ts +2 -0
- package/dist/src/parser/hasAncestorWithNodeName.d.ts +2 -0
- package/dist/src/parser/loadSVGFromString.d.ts +12 -0
- package/dist/src/parser/loadSVGFromURL.d.ts +13 -0
- package/dist/src/parser/normalizeAttr.d.ts +2 -0
- package/dist/src/parser/normalizeValue.d.ts +2 -0
- package/dist/src/parser/parseAttributes.d.ts +9 -0
- package/dist/src/parser/parseElements.d.ts +11 -0
- package/dist/src/parser/parseFontDeclaration.d.ts +10 -0
- package/dist/src/parser/parsePointsAttribute.d.ts +12 -0
- package/dist/src/parser/parseSVGDocument.d.ts +15 -0
- package/dist/src/parser/parseStyleAttribute.d.ts +9 -0
- package/dist/src/parser/parseStyleObject.d.ts +2 -0
- package/dist/src/parser/parseStyleString.d.ts +2 -0
- package/dist/src/parser/parseTransformAttribute.d.ts +10 -0
- package/dist/src/parser/parseUseDirectives.d.ts +2 -0
- package/dist/src/parser/percent.d.ts +9 -0
- package/dist/src/parser/recursivelyParseGradientsXlink.d.ts +2 -0
- package/dist/src/parser/rotateMatrix.d.ts +2 -0
- package/dist/src/parser/scaleMatrix.d.ts +2 -0
- package/dist/src/parser/selectorMatches.d.ts +2 -0
- package/dist/src/parser/setStrokeFillOpacity.d.ts +6 -0
- package/dist/src/parser/skewMatrix.d.ts +2 -0
- package/dist/src/parser/translateMatrix.d.ts +2 -0
- package/dist/src/shapes/ActiveSelection.d.ts +66 -0
- package/dist/src/shapes/Circle.d.ts +80 -0
- package/dist/src/shapes/Ellipse.d.ts +74 -0
- package/dist/src/shapes/Group.d.ts +381 -0
- package/dist/src/shapes/IText/DraggableTextDelegate.d.ts +78 -0
- package/dist/src/shapes/IText/IText.d.ts +322 -0
- package/dist/src/shapes/IText/ITextBehavior.d.ts +285 -0
- package/dist/src/shapes/IText/ITextClickBehavior.d.ts +81 -0
- package/dist/src/shapes/IText/ITextKeyBehavior.d.ts +193 -0
- package/dist/src/shapes/IText/constants.d.ts +13 -0
- package/dist/src/shapes/Image.d.ts +283 -0
- package/dist/src/shapes/Line.d.ts +117 -0
- package/dist/src/shapes/Object/AnimatableObject.d.ts +33 -0
- package/dist/src/shapes/Object/FabricObject.d.ts +9 -0
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.d.ts +74 -0
- package/dist/src/shapes/Object/InteractiveObject.d.ts +282 -0
- package/dist/src/shapes/Object/Object.d.ts +906 -0
- package/dist/src/shapes/Object/ObjectGeometry.d.ts +343 -0
- package/dist/src/shapes/Object/ObjectOrigin.d.ts +178 -0
- package/dist/src/shapes/Object/StackedObject.d.ts +62 -0
- package/dist/src/shapes/Object/defaultValues.d.ts +77 -0
- package/dist/src/shapes/Path.d.ts +123 -0
- package/dist/src/shapes/Polygon.d.ts +7 -0
- package/dist/src/shapes/Polyline.d.ts +130 -0
- package/dist/src/shapes/Rect.d.ts +62 -0
- package/dist/src/shapes/Text/StyledText.d.ts +118 -0
- package/dist/src/shapes/Text/Text.d.ts +656 -0
- package/dist/src/shapes/Text/TextSVGExportMixin.d.ts +32 -0
- package/dist/src/shapes/Textbox.d.ts +170 -0
- package/dist/src/shapes/Triangle.d.ts +17 -0
- package/dist/src/typedefs.d.ts +93 -0
- package/dist/src/util/animation/AnimationBase.d.ts +54 -0
- package/dist/src/util/animation/AnimationFrameProvider.d.ts +8 -0
- package/dist/src/util/animation/AnimationRegistry.d.ts +29 -0
- package/dist/src/util/animation/ArrayAnimation.d.ts +10 -0
- package/dist/src/util/animation/ColorAnimation.d.ts +11 -0
- package/dist/src/util/animation/ValueAnimation.d.ts +10 -0
- package/dist/src/util/animation/animate.d.ts +37 -0
- package/dist/src/util/animation/easing.d.ts +130 -0
- package/dist/src/util/animation/types.d.ts +87 -0
- package/dist/src/util/applyMixins.d.ts +8 -0
- package/dist/src/util/class_registry.d.ts +14 -0
- package/dist/src/util/dom_event.d.ts +5 -0
- package/dist/src/util/dom_misc.d.ts +40 -0
- package/dist/src/util/dom_request.d.ts +14 -0
- package/dist/src/util/dom_style.d.ts +7 -0
- package/dist/src/util/fireEvent.d.ts +3 -0
- package/dist/src/util/internals/cloneDeep.d.ts +2 -0
- package/dist/src/util/internals/getRandomInt.d.ts +8 -0
- package/dist/src/util/internals/ifNaN.d.ts +8 -0
- package/dist/src/util/internals/index.d.ts +4 -0
- package/dist/src/util/internals/removeFromArray.d.ts +9 -0
- package/dist/src/util/internals/uid.d.ts +2 -0
- package/dist/src/util/lang_class.d.ts +12 -0
- package/dist/src/util/lang_string.d.ts +22 -0
- package/dist/src/util/misc/boundingBoxFromPoints.d.ts +9 -0
- package/dist/src/util/misc/capValue.d.ts +2 -0
- package/dist/src/util/misc/cos.d.ts +10 -0
- package/dist/src/util/misc/dom.d.ts +28 -0
- package/dist/src/util/misc/findScaleTo.d.ts +29 -0
- package/dist/src/util/misc/groupSVGElements.d.ts +9 -0
- package/dist/src/util/misc/isTransparent.d.ts +11 -0
- package/dist/src/util/misc/matrix.d.ts +92 -0
- package/dist/src/util/misc/mergeClipPaths.d.ts +23 -0
- package/dist/src/util/misc/objectEnlive.d.ts +56 -0
- package/dist/src/util/misc/objectTransforms.d.ts +68 -0
- package/dist/src/util/misc/pick.d.ts +8 -0
- package/dist/src/util/misc/planeChange.d.ts +84 -0
- package/dist/src/util/misc/projectStroke/StrokeLineCapProjections.d.ts +51 -0
- package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.d.ts +81 -0
- package/dist/src/util/misc/projectStroke/StrokeProjectionsBase.d.ts +25 -0
- package/dist/src/util/misc/projectStroke/index.d.ts +11 -0
- package/dist/src/util/misc/projectStroke/types.d.ts +23 -0
- package/dist/src/util/misc/radiansDegreesConversion.d.ts +14 -0
- package/dist/src/util/misc/resolveOrigin.d.ts +9 -0
- package/dist/src/util/misc/rotatePoint.d.ts +12 -0
- package/dist/src/util/misc/sin.d.ts +10 -0
- package/dist/src/util/misc/svgParsing.d.ts +53 -0
- package/dist/src/util/misc/textStyles.d.ts +32 -0
- package/dist/src/util/misc/toFixed.d.ts +8 -0
- package/dist/src/util/misc/vectors.d.ts +57 -0
- package/dist/src/util/path.d.ts +108 -0
- package/dist/src/util/transform_matrix_removal.d.ts +14 -0
- package/dist/src/util/types.d.ts +19 -0
- package/fabric.ts +427 -0
- package/index.node.ts +43 -0
- package/index.ts +1 -0
- package/package.json +90 -39
- package/publish.js +0 -26
- package/rollup.config.mjs +79 -0
- package/rollup.test.config.js +24 -0
- package/scripts/build.mjs +50 -0
- package/scripts/buildLock.mjs +115 -0
- package/scripts/buildReporter.mjs +15 -0
- package/scripts/buildStats.mjs +139 -0
- package/scripts/dirname.mjs +14 -0
- package/scripts/index.mjs +679 -0
- package/scripts/transform_files.mjs +504 -0
- package/src/Collection.ts +311 -0
- package/src/CommonMethods.ts +63 -0
- package/src/EventTypeDefs.ts +294 -0
- package/src/Intersection.ts +273 -0
- package/src/Observable.ts +175 -0
- package/src/Pattern.ts +211 -0
- package/src/Point.ts +388 -0
- package/src/Shadow.ts +215 -0
- package/src/brushes/{base_brush.class.js → BaseBrush.ts} +65 -42
- package/src/brushes/CircleBrush.ts +145 -0
- package/src/brushes/PatternBrush.ts +70 -0
- package/src/brushes/PencilBrush.ts +300 -0
- package/src/brushes/SprayBrush.ts +219 -0
- package/src/cache.ts +89 -0
- package/src/canvas/Canvas.ts +1672 -0
- package/src/canvas/SelectableCanvas.ts +1636 -0
- package/src/canvas/StaticCanvas.ts +1709 -0
- package/src/canvas/TextEditingManager.ts +48 -0
- package/src/canvas/canvas_gestures.mixin.ts +207 -0
- package/src/color/Color.ts +404 -0
- package/src/color/color_map.ts +154 -0
- package/src/color/constants.ts +26 -0
- package/src/color/util.ts +32 -0
- package/src/config.ts +159 -0
- package/src/constants.ts +19 -0
- package/src/controls/Control.ts +377 -0
- package/src/controls/changeWidth.ts +52 -0
- package/src/controls/controls.render.ts +138 -0
- package/src/controls/default_controls.ts +132 -0
- package/src/controls/drag.ts +31 -0
- package/src/controls/polyControl.ts +135 -0
- package/src/controls/rotate.ts +87 -0
- package/src/controls/scale.ts +277 -0
- package/src/controls/scaleSkew.ts +92 -0
- package/src/controls/skew.ts +242 -0
- package/src/controls/util.ts +154 -0
- package/src/controls/wrapWithFireEvent.ts +25 -0
- package/src/controls/wrapWithFixedAnchor.ts +20 -0
- package/src/env/browser.ts +28 -0
- package/src/env/index.ts +19 -0
- package/src/env/node.ts +52 -0
- package/src/env/types.ts +15 -0
- package/src/filters/{base_filter.class.js → BaseFilter.ts} +201 -149
- package/src/filters/BlendColor.ts +258 -0
- package/src/filters/BlendImage.ts +254 -0
- package/src/filters/Blur.ts +202 -0
- package/src/filters/Boilerplate.ts +91 -0
- package/src/filters/Brightness.ts +93 -0
- package/src/filters/Canvas2dFilterBackend.ts +65 -0
- package/src/filters/ColorMatrix.ts +156 -0
- package/src/filters/ColorMatrixFilters.ts +106 -0
- package/src/filters/Composed.ts +85 -0
- package/src/filters/Contrast.ts +94 -0
- package/src/filters/Convolute.ts +341 -0
- package/src/filters/FilterBackend.ts +32 -0
- package/src/filters/Gamma.ts +127 -0
- package/src/filters/Grayscale.ts +137 -0
- package/src/filters/HueRotation.ts +66 -0
- package/src/filters/Invert.ts +117 -0
- package/src/filters/Noise.ts +109 -0
- package/src/filters/Pixelate.ts +114 -0
- package/src/filters/RemoveColor.ts +148 -0
- package/src/filters/Resize.ts +540 -0
- package/src/filters/Saturation.ts +100 -0
- package/src/filters/Vibrance.ts +103 -0
- package/src/filters/WebGLFilterBackend.ts +430 -0
- package/src/filters/WebGLProbe.ts +62 -0
- package/src/filters/typedefs.ts +65 -0
- package/src/gradient/Gradient.ts +401 -0
- package/src/gradient/constants.ts +12 -0
- package/src/gradient/parser/index.ts +3 -0
- package/src/gradient/parser/misc.ts +13 -0
- package/src/gradient/parser/parseColorStops.ts +55 -0
- package/src/gradient/parser/parseCoords.ts +73 -0
- package/src/gradient/typedefs.ts +104 -0
- package/src/mixins/{eraser_brush.mixin.js → eraser_brush.mixin.ts} +350 -239
- package/src/mixins/stateful.mixin.ts +104 -0
- package/src/parkinglot/canvas_animation.mixin.ts +121 -0
- package/src/parkinglot/straighten.ts +58 -0
- package/src/parser/applyViewboxTransform.ts +162 -0
- package/src/parser/attributes.ts +25 -0
- package/src/parser/constants.ts +118 -0
- package/src/parser/doesSomeParentMatch.ts +19 -0
- package/src/parser/elementById.ts +23 -0
- package/src/parser/elementMatchesRule.ts +19 -0
- package/src/parser/elements_parser.ts +191 -0
- package/src/parser/getCSSRules.ts +62 -0
- package/src/parser/getGlobalStylesForElement.ts +19 -0
- package/src/parser/getGradientDefs.ts +32 -0
- package/src/parser/getMultipleNodes.ts +15 -0
- package/src/parser/getSvgRegex.ts +5 -0
- package/src/parser/hasAncestorWithNodeName.ts +14 -0
- package/src/parser/loadSVGFromString.ts +26 -0
- package/src/parser/loadSVGFromURL.ts +40 -0
- package/src/parser/normalizeAttr.ts +10 -0
- package/src/parser/normalizeValue.ts +63 -0
- package/src/parser/parseAttributes.ts +90 -0
- package/src/parser/parseElements.ts +28 -0
- package/src/parser/parseFontDeclaration.ts +44 -0
- package/src/parser/parsePointsAttribute.ts +36 -0
- package/src/parser/parseSVGDocument.ts +106 -0
- package/src/parser/parseStyleAttribute.ts +27 -0
- package/src/parser/parseStyleObject.ts +15 -0
- package/src/parser/parseStyleString.ts +16 -0
- package/src/parser/parseTransformAttribute.ts +155 -0
- package/src/parser/parseUseDirectives.ts +79 -0
- package/src/parser/percent.ts +27 -0
- package/src/parser/recursivelyParseGradientsXlink.ts +42 -0
- package/src/parser/rotateMatrix.ts +21 -0
- package/src/parser/scaleMatrix.ts +9 -0
- package/src/parser/selectorMatches.ts +25 -0
- package/src/parser/setStrokeFillOpacity.ts +40 -0
- package/src/parser/skewMatrix.ts +6 -0
- package/src/parser/translateMatrix.ts +8 -0
- package/src/shapes/ActiveSelection.ts +157 -0
- package/src/shapes/Circle.ts +205 -0
- package/src/shapes/Ellipse.ts +154 -0
- package/src/shapes/Group.ts +1053 -0
- package/src/shapes/IText/DraggableTextDelegate.ts +394 -0
- package/src/shapes/IText/IText.ts +666 -0
- package/src/shapes/IText/ITextBehavior.ts +1055 -0
- package/src/shapes/IText/ITextClickBehavior.ts +321 -0
- package/src/shapes/IText/ITextKeyBehavior.ts +683 -0
- package/src/shapes/IText/constants.ts +47 -0
- package/src/shapes/Image.ts +789 -0
- package/src/shapes/Line.ts +329 -0
- package/src/shapes/Object/AnimatableObject.ts +106 -0
- package/src/shapes/Object/FabricObject.ts +19 -0
- package/src/shapes/Object/FabricObjectSVGExportMixin.ts +277 -0
- package/src/shapes/Object/InteractiveObject.ts +645 -0
- package/src/shapes/Object/Object.ts +1896 -0
- package/src/shapes/Object/ObjectGeometry.ts +830 -0
- package/src/shapes/Object/ObjectOrigin.ts +354 -0
- package/src/shapes/Object/StackedObject.ts +191 -0
- package/src/shapes/Object/defaultValues.ts +112 -0
- package/src/shapes/Path.ts +395 -0
- package/src/shapes/Polygon.ts +19 -0
- package/src/shapes/Polyline.ts +333 -0
- package/src/shapes/Rect.ts +199 -0
- package/src/shapes/Text/StyledText.ts +319 -0
- package/src/shapes/Text/Text.ts +1948 -0
- package/src/shapes/Text/TextSVGExportMixin.ts +288 -0
- package/src/shapes/Textbox.ts +471 -0
- package/src/shapes/Triangle.ts +45 -0
- package/src/typedefs.ts +119 -0
- package/src/util/animation/AnimationBase.ts +166 -0
- package/src/util/animation/AnimationFrameProvider.ts +28 -0
- package/src/util/animation/AnimationRegistry.ts +58 -0
- package/src/util/animation/ArrayAnimation.ts +27 -0
- package/src/util/animation/ColorAnimation.ts +74 -0
- package/src/util/animation/ValueAnimation.ts +29 -0
- package/src/util/animation/animate.ts +74 -0
- package/src/util/animation/easing.ts +327 -0
- package/src/util/animation/types.ts +136 -0
- package/src/util/applyMixins.ts +22 -0
- package/src/util/class_registry.ts +54 -0
- package/src/util/dom_event.ts +28 -0
- package/src/util/dom_misc.ts +138 -0
- package/src/util/dom_request.ts +64 -0
- package/src/util/dom_style.ts +20 -0
- package/src/util/fireEvent.ts +15 -0
- package/src/util/internals/cloneDeep.ts +2 -0
- package/src/util/internals/getRandomInt.ts +8 -0
- package/src/util/internals/ifNaN.ts +9 -0
- package/src/util/internals/index.ts +3 -0
- package/src/util/internals/removeFromArray.ts +14 -0
- package/src/util/internals/uid.ts +3 -0
- package/src/util/lang_class.ts +90 -0
- package/src/util/lang_string.ts +79 -0
- package/src/util/misc/boundingBoxFromPoints.ts +37 -0
- package/src/util/misc/capValue.ts +2 -0
- package/src/util/misc/cos.ts +24 -0
- package/src/util/misc/dom.ts +50 -0
- package/src/util/misc/findScaleTo.ts +44 -0
- package/src/util/misc/groupSVGElements.ts +15 -0
- package/src/util/misc/isTransparent.ts +51 -0
- package/src/util/misc/matrix.ts +207 -0
- package/src/util/misc/mergeClipPaths.ts +40 -0
- package/src/util/misc/objectEnlive.ts +189 -0
- package/src/util/misc/objectTransforms.ts +129 -0
- package/src/util/misc/pick.ts +17 -0
- package/src/util/misc/planeChange.ts +136 -0
- package/src/util/misc/projectStroke/StrokeLineCapProjections.ts +112 -0
- package/src/util/misc/projectStroke/StrokeLineJoinProjections.ts +231 -0
- package/src/util/misc/projectStroke/StrokeProjectionsBase.ts +75 -0
- package/src/util/misc/projectStroke/index.ts +53 -0
- package/src/util/misc/projectStroke/types.ts +24 -0
- package/src/util/misc/radiansDegreesConversion.ts +18 -0
- package/src/util/misc/resolveOrigin.ts +22 -0
- package/src/util/misc/rotatePoint.ts +15 -0
- package/src/util/misc/sin.ts +26 -0
- package/src/util/misc/svgParsing.ts +181 -0
- package/src/util/misc/textStyles.ts +133 -0
- package/src/util/misc/toFixed.ts +8 -0
- package/src/util/misc/vectors.ts +82 -0
- package/src/util/path.ts +941 -0
- package/src/util/transform_matrix_removal.ts +60 -0
- package/src/util/types.ts +78 -0
- package/tsconfig.json +106 -0
- package/HEADER.js +0 -203
- package/build.js +0 -287
- package/dist/fabric.js +0 -31187
- package/dist/fabric.min.js +0 -1
- package/old-travis-reference.yml +0 -97
- package/src/brushes/circle_brush.class.js +0 -144
- package/src/brushes/pattern_brush.class.js +0 -61
- package/src/brushes/pencil_brush.class.js +0 -310
- package/src/brushes/spray_brush.class.js +0 -219
- package/src/canvas.class.js +0 -1312
- package/src/color.class.js +0 -636
- package/src/control.class.js +0 -339
- package/src/controls.actions.js +0 -740
- package/src/controls.render.js +0 -99
- package/src/elements_parser.js +0 -152
- package/src/filters/2d_backend.class.js +0 -65
- package/src/filters/blendcolor_filter.class.js +0 -251
- package/src/filters/blendimage_filter.class.js +0 -247
- package/src/filters/blur_filter.class.js +0 -217
- package/src/filters/brightness_filter.class.js +0 -113
- package/src/filters/colormatrix_filter.class.js +0 -159
- package/src/filters/composed_filter.class.js +0 -72
- package/src/filters/contrast_filter.class.js +0 -113
- package/src/filters/convolute_filter.class.js +0 -352
- package/src/filters/filter_boilerplate.js +0 -111
- package/src/filters/filter_generator.js +0 -85
- package/src/filters/gamma_filter.class.js +0 -136
- package/src/filters/grayscale_filter.class.js +0 -154
- package/src/filters/hue_rotation.class.js +0 -107
- package/src/filters/invert_filter.class.js +0 -111
- package/src/filters/noise_filter.class.js +0 -134
- package/src/filters/pixelate_filter.class.js +0 -137
- package/src/filters/removecolor_filter.class.js +0 -173
- package/src/filters/resize_filter.class.js +0 -490
- package/src/filters/saturate_filter.class.js +0 -119
- package/src/filters/vibrance_filter.class.js +0 -122
- package/src/filters/webgl_backend.class.js +0 -396
- package/src/globalFabric.js +0 -4
- package/src/gradient.class.js +0 -490
- package/src/intersection.class.js +0 -172
- package/src/log.js +0 -11
- package/src/mixins/animation.mixin.js +0 -231
- package/src/mixins/canvas_dataurl_exporter.mixin.js +0 -97
- package/src/mixins/canvas_events.mixin.js +0 -974
- package/src/mixins/canvas_gestures.mixin.js +0 -149
- package/src/mixins/canvas_grouping.mixin.js +0 -177
- package/src/mixins/canvas_serialization.mixin.js +0 -228
- package/src/mixins/collection.mixin.js +0 -170
- package/src/mixins/default_controls.js +0 -114
- package/src/mixins/itext.svg_export.js +0 -241
- package/src/mixins/itext_behavior.mixin.js +0 -940
- package/src/mixins/itext_click_behavior.mixin.js +0 -278
- package/src/mixins/itext_key_behavior.mixin.js +0 -694
- package/src/mixins/object.svg_export.js +0 -258
- package/src/mixins/object_geometry.mixin.js +0 -683
- package/src/mixins/object_interactivity.mixin.js +0 -314
- package/src/mixins/object_origin.mixin.js +0 -255
- package/src/mixins/object_stacking.mixin.js +0 -80
- package/src/mixins/object_straightening.mixin.js +0 -80
- package/src/mixins/observable.mixin.js +0 -141
- package/src/mixins/shared_methods.mixin.js +0 -94
- package/src/mixins/stateful.mixin.js +0 -107
- package/src/mixins/text_style.mixin.js +0 -324
- package/src/parser.js +0 -1090
- package/src/pattern.class.js +0 -189
- package/src/point.class.js +0 -337
- package/src/shadow.class.js +0 -195
- package/src/shapes/active_selection.class.js +0 -155
- package/src/shapes/circle.class.js +0 -210
- package/src/shapes/ellipse.class.js +0 -181
- package/src/shapes/group.class.js +0 -593
- package/src/shapes/image.class.js +0 -764
- package/src/shapes/itext.class.js +0 -526
- package/src/shapes/line.class.js +0 -324
- package/src/shapes/object.class.js +0 -2008
- package/src/shapes/path.class.js +0 -384
- package/src/shapes/polygon.class.js +0 -81
- package/src/shapes/polyline.class.js +0 -268
- package/src/shapes/rect.class.js +0 -187
- package/src/shapes/text.class.js +0 -1696
- package/src/shapes/textbox.class.js +0 -461
- package/src/shapes/triangle.class.js +0 -93
- package/src/static_canvas.class.js +0 -1881
- package/src/util/anim_ease.js +0 -398
- package/src/util/animate.js +0 -254
- package/src/util/animate_color.js +0 -74
- package/src/util/dom_event.js +0 -50
- package/src/util/dom_misc.js +0 -300
- package/src/util/dom_request.js +0 -54
- package/src/util/dom_style.js +0 -70
- package/src/util/lang_array.js +0 -94
- package/src/util/lang_class.js +0 -115
- package/src/util/lang_object.js +0 -75
- package/src/util/lang_string.js +0 -110
- package/src/util/misc.js +0 -1330
- package/src/util/named_accessors.mixin.js +0 -428
- package/src/util/path.js +0 -829
package/src/shapes/text.class.js
DELETED
|
@@ -1,1696 +0,0 @@
|
|
|
1
|
-
(function(global) {
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
var fabric = global.fabric || (global.fabric = { }),
|
|
6
|
-
clone = fabric.util.object.clone;
|
|
7
|
-
|
|
8
|
-
if (fabric.Text) {
|
|
9
|
-
fabric.warn('fabric.Text is already defined');
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
var additionalProps =
|
|
14
|
-
('fontFamily fontWeight fontSize text underline overline linethrough' +
|
|
15
|
-
' textAlign fontStyle lineHeight textBackgroundColor charSpacing styles' +
|
|
16
|
-
' direction path pathStartOffset pathSide pathAlign').split(' ');
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Text class
|
|
20
|
-
* @class fabric.Text
|
|
21
|
-
* @extends fabric.Object
|
|
22
|
-
* @return {fabric.Text} thisArg
|
|
23
|
-
* @tutorial {@link http://fabricjs.com/fabric-intro-part-2#text}
|
|
24
|
-
* @see {@link fabric.Text#initialize} for constructor definition
|
|
25
|
-
*/
|
|
26
|
-
fabric.Text = fabric.util.createClass(fabric.Object, /** @lends fabric.Text.prototype */ {
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Properties which when set cause object to change dimensions
|
|
30
|
-
* @type Array
|
|
31
|
-
* @private
|
|
32
|
-
*/
|
|
33
|
-
_dimensionAffectingProps: [
|
|
34
|
-
'fontSize',
|
|
35
|
-
'fontWeight',
|
|
36
|
-
'fontFamily',
|
|
37
|
-
'fontStyle',
|
|
38
|
-
'lineHeight',
|
|
39
|
-
'text',
|
|
40
|
-
'charSpacing',
|
|
41
|
-
'textAlign',
|
|
42
|
-
'styles',
|
|
43
|
-
'path',
|
|
44
|
-
'pathStartOffset',
|
|
45
|
-
'pathSide',
|
|
46
|
-
'pathAlign'
|
|
47
|
-
],
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @private
|
|
51
|
-
*/
|
|
52
|
-
_reNewline: /\r?\n/,
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Use this regular expression to filter for whitespaces that is not a new line.
|
|
56
|
-
* Mostly used when text is 'justify' aligned.
|
|
57
|
-
* @private
|
|
58
|
-
*/
|
|
59
|
-
_reSpacesAndTabs: /[ \t\r]/g,
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Use this regular expression to filter for whitespace that is not a new line.
|
|
63
|
-
* Mostly used when text is 'justify' aligned.
|
|
64
|
-
* @private
|
|
65
|
-
*/
|
|
66
|
-
_reSpaceAndTab: /[ \t\r]/,
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Use this regular expression to filter consecutive groups of non spaces.
|
|
70
|
-
* Mostly used when text is 'justify' aligned.
|
|
71
|
-
* @private
|
|
72
|
-
*/
|
|
73
|
-
_reWords: /\S+/g,
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Type of an object
|
|
77
|
-
* @type String
|
|
78
|
-
* @default
|
|
79
|
-
*/
|
|
80
|
-
type: 'text',
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Font size (in pixels)
|
|
84
|
-
* @type Number
|
|
85
|
-
* @default
|
|
86
|
-
*/
|
|
87
|
-
fontSize: 40,
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Font weight (e.g. bold, normal, 400, 600, 800)
|
|
91
|
-
* @type {(Number|String)}
|
|
92
|
-
* @default
|
|
93
|
-
*/
|
|
94
|
-
fontWeight: 'normal',
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Font family
|
|
98
|
-
* @type String
|
|
99
|
-
* @default
|
|
100
|
-
*/
|
|
101
|
-
fontFamily: 'Times New Roman',
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Text decoration underline.
|
|
105
|
-
* @type Boolean
|
|
106
|
-
* @default
|
|
107
|
-
*/
|
|
108
|
-
underline: false,
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Text decoration overline.
|
|
112
|
-
* @type Boolean
|
|
113
|
-
* @default
|
|
114
|
-
*/
|
|
115
|
-
overline: false,
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Text decoration linethrough.
|
|
119
|
-
* @type Boolean
|
|
120
|
-
* @default
|
|
121
|
-
*/
|
|
122
|
-
linethrough: false,
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Text alignment. Possible values: "left", "center", "right", "justify",
|
|
126
|
-
* "justify-left", "justify-center" or "justify-right".
|
|
127
|
-
* @type String
|
|
128
|
-
* @default
|
|
129
|
-
*/
|
|
130
|
-
textAlign: 'left',
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Font style . Possible values: "", "normal", "italic" or "oblique".
|
|
134
|
-
* @type String
|
|
135
|
-
* @default
|
|
136
|
-
*/
|
|
137
|
-
fontStyle: 'normal',
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Line height
|
|
141
|
-
* @type Number
|
|
142
|
-
* @default
|
|
143
|
-
*/
|
|
144
|
-
lineHeight: 1.16,
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Superscript schema object (minimum overlap)
|
|
148
|
-
* @type {Object}
|
|
149
|
-
* @default
|
|
150
|
-
*/
|
|
151
|
-
superscript: {
|
|
152
|
-
size: 0.60, // fontSize factor
|
|
153
|
-
baseline: -0.35 // baseline-shift factor (upwards)
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Subscript schema object (minimum overlap)
|
|
158
|
-
* @type {Object}
|
|
159
|
-
* @default
|
|
160
|
-
*/
|
|
161
|
-
subscript: {
|
|
162
|
-
size: 0.60, // fontSize factor
|
|
163
|
-
baseline: 0.11 // baseline-shift factor (downwards)
|
|
164
|
-
},
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Background color of text lines
|
|
168
|
-
* @type String
|
|
169
|
-
* @default
|
|
170
|
-
*/
|
|
171
|
-
textBackgroundColor: '',
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* List of properties to consider when checking if
|
|
175
|
-
* state of an object is changed ({@link fabric.Object#hasStateChanged})
|
|
176
|
-
* as well as for history (undo/redo) purposes
|
|
177
|
-
* @type Array
|
|
178
|
-
*/
|
|
179
|
-
stateProperties: fabric.Object.prototype.stateProperties.concat(additionalProps),
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* List of properties to consider when checking if cache needs refresh
|
|
183
|
-
* @type Array
|
|
184
|
-
*/
|
|
185
|
-
cacheProperties: fabric.Object.prototype.cacheProperties.concat(additionalProps),
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* When defined, an object is rendered via stroke and this property specifies its color.
|
|
189
|
-
* <b>Backwards incompatibility note:</b> This property was named "strokeStyle" until v1.1.6
|
|
190
|
-
* @type String
|
|
191
|
-
* @default
|
|
192
|
-
*/
|
|
193
|
-
stroke: null,
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Shadow object representing shadow of this shape.
|
|
197
|
-
* <b>Backwards incompatibility note:</b> This property was named "textShadow" (String) until v1.2.11
|
|
198
|
-
* @type fabric.Shadow
|
|
199
|
-
* @default
|
|
200
|
-
*/
|
|
201
|
-
shadow: null,
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* fabric.Path that the text should follow.
|
|
205
|
-
* since 4.6.0 the path will be drawn automatically.
|
|
206
|
-
* if you want to make the path visible, give it a stroke and strokeWidth or fill value
|
|
207
|
-
* if you want it to be hidden, assign visible = false to the path.
|
|
208
|
-
* This feature is in BETA, and SVG import/export is not yet supported.
|
|
209
|
-
* @type fabric.Path
|
|
210
|
-
* @example
|
|
211
|
-
* var textPath = new fabric.Text('Text on a path', {
|
|
212
|
-
* top: 150,
|
|
213
|
-
* left: 150,
|
|
214
|
-
* textAlign: 'center',
|
|
215
|
-
* charSpacing: -50,
|
|
216
|
-
* path: new fabric.Path('M 0 0 C 50 -100 150 -100 200 0', {
|
|
217
|
-
* strokeWidth: 1,
|
|
218
|
-
* visible: false
|
|
219
|
-
* }),
|
|
220
|
-
* pathSide: 'left',
|
|
221
|
-
* pathStartOffset: 0
|
|
222
|
-
* });
|
|
223
|
-
* @default
|
|
224
|
-
*/
|
|
225
|
-
path: null,
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Offset amount for text path starting position
|
|
229
|
-
* Only used when text has a path
|
|
230
|
-
* @type Number
|
|
231
|
-
* @default
|
|
232
|
-
*/
|
|
233
|
-
pathStartOffset: 0,
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Which side of the path the text should be drawn on.
|
|
237
|
-
* Only used when text has a path
|
|
238
|
-
* @type {String} 'left|right'
|
|
239
|
-
* @default
|
|
240
|
-
*/
|
|
241
|
-
pathSide: 'left',
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* How text is aligned to the path. This property determines
|
|
245
|
-
* the perpendicular position of each character relative to the path.
|
|
246
|
-
* (one of "baseline", "center", "ascender", "descender")
|
|
247
|
-
* This feature is in BETA, and its behavior may change
|
|
248
|
-
* @type String
|
|
249
|
-
* @default
|
|
250
|
-
*/
|
|
251
|
-
pathAlign: 'baseline',
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* @private
|
|
255
|
-
*/
|
|
256
|
-
_fontSizeFraction: 0.222,
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* @private
|
|
260
|
-
*/
|
|
261
|
-
offsets: {
|
|
262
|
-
underline: 0.10,
|
|
263
|
-
linethrough: -0.315,
|
|
264
|
-
overline: -0.88
|
|
265
|
-
},
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Text Line proportion to font Size (in pixels)
|
|
269
|
-
* @type Number
|
|
270
|
-
* @default
|
|
271
|
-
*/
|
|
272
|
-
_fontSizeMult: 1.13,
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* additional space between characters
|
|
276
|
-
* expressed in thousands of em unit
|
|
277
|
-
* @type Number
|
|
278
|
-
* @default
|
|
279
|
-
*/
|
|
280
|
-
charSpacing: 0,
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Object containing character styles - top-level properties -> line numbers,
|
|
284
|
-
* 2nd-level properties - character numbers
|
|
285
|
-
* @type Object
|
|
286
|
-
* @default
|
|
287
|
-
*/
|
|
288
|
-
styles: null,
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Reference to a context to measure text char or couple of chars
|
|
292
|
-
* the cacheContext of the canvas will be used or a freshly created one if the object is not on canvas
|
|
293
|
-
* once created it will be referenced on fabric._measuringContext to avoid creating a canvas for every
|
|
294
|
-
* text object created.
|
|
295
|
-
* @type {CanvasRenderingContext2D}
|
|
296
|
-
* @default
|
|
297
|
-
*/
|
|
298
|
-
_measuringContext: null,
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Baseline shift, styles only, keep at 0 for the main text object
|
|
302
|
-
* @type {Number}
|
|
303
|
-
* @default
|
|
304
|
-
*/
|
|
305
|
-
deltaY: 0,
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* WARNING: EXPERIMENTAL. NOT SUPPORTED YET
|
|
309
|
-
* determine the direction of the text.
|
|
310
|
-
* This has to be set manually together with textAlign and originX for proper
|
|
311
|
-
* experience.
|
|
312
|
-
* some interesting link for the future
|
|
313
|
-
* https://www.w3.org/International/questions/qa-bidi-unicode-controls
|
|
314
|
-
* @since 4.5.0
|
|
315
|
-
* @type {String} 'ltr|rtl'
|
|
316
|
-
* @default
|
|
317
|
-
*/
|
|
318
|
-
direction: 'ltr',
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Array of properties that define a style unit (of 'styles').
|
|
322
|
-
* @type {Array}
|
|
323
|
-
* @default
|
|
324
|
-
*/
|
|
325
|
-
_styleProperties: [
|
|
326
|
-
'stroke',
|
|
327
|
-
'strokeWidth',
|
|
328
|
-
'fill',
|
|
329
|
-
'fontFamily',
|
|
330
|
-
'fontSize',
|
|
331
|
-
'fontWeight',
|
|
332
|
-
'fontStyle',
|
|
333
|
-
'underline',
|
|
334
|
-
'overline',
|
|
335
|
-
'linethrough',
|
|
336
|
-
'deltaY',
|
|
337
|
-
'textBackgroundColor',
|
|
338
|
-
],
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* contains characters bounding boxes
|
|
342
|
-
*/
|
|
343
|
-
__charBounds: [],
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* use this size when measuring text. To avoid IE11 rounding errors
|
|
347
|
-
* @type {Number}
|
|
348
|
-
* @default
|
|
349
|
-
* @readonly
|
|
350
|
-
* @private
|
|
351
|
-
*/
|
|
352
|
-
CACHE_FONT_SIZE: 400,
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* contains the min text width to avoid getting 0
|
|
356
|
-
* @type {Number}
|
|
357
|
-
* @default
|
|
358
|
-
*/
|
|
359
|
-
MIN_TEXT_WIDTH: 2,
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Constructor
|
|
363
|
-
* @param {String} text Text string
|
|
364
|
-
* @param {Object} [options] Options object
|
|
365
|
-
* @return {fabric.Text} thisArg
|
|
366
|
-
*/
|
|
367
|
-
initialize: function(text, options) {
|
|
368
|
-
this.styles = options ? (options.styles || { }) : { };
|
|
369
|
-
this.text = text;
|
|
370
|
-
this.__skipDimension = true;
|
|
371
|
-
this.callSuper('initialize', options);
|
|
372
|
-
if (this.path) {
|
|
373
|
-
this.setPathInfo();
|
|
374
|
-
}
|
|
375
|
-
this.__skipDimension = false;
|
|
376
|
-
this.initDimensions();
|
|
377
|
-
this.setCoords();
|
|
378
|
-
this.setupState({ propertySet: '_dimensionAffectingProps' });
|
|
379
|
-
},
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* If text has a path, it will add the extra information needed
|
|
383
|
-
* for path and text calculations
|
|
384
|
-
* @return {fabric.Text} thisArg
|
|
385
|
-
*/
|
|
386
|
-
setPathInfo: function() {
|
|
387
|
-
var path = this.path;
|
|
388
|
-
if (path) {
|
|
389
|
-
path.segmentsInfo = fabric.util.getPathSegmentsInfo(path.path);
|
|
390
|
-
}
|
|
391
|
-
},
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* Return a context for measurement of text string.
|
|
395
|
-
* if created it gets stored for reuse
|
|
396
|
-
* this is for internal use, please do not use it
|
|
397
|
-
* @private
|
|
398
|
-
* @param {String} text Text string
|
|
399
|
-
* @param {Object} [options] Options object
|
|
400
|
-
* @return {fabric.Text} thisArg
|
|
401
|
-
*/
|
|
402
|
-
getMeasuringContext: function() {
|
|
403
|
-
// if we did not return we have to measure something.
|
|
404
|
-
if (!fabric._measuringContext) {
|
|
405
|
-
fabric._measuringContext = this.canvas && this.canvas.contextCache ||
|
|
406
|
-
fabric.util.createCanvasElement().getContext('2d');
|
|
407
|
-
}
|
|
408
|
-
return fabric._measuringContext;
|
|
409
|
-
},
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* @private
|
|
413
|
-
* Divides text into lines of text and lines of graphemes.
|
|
414
|
-
*/
|
|
415
|
-
_splitText: function() {
|
|
416
|
-
var newLines = this._splitTextIntoLines(this.text);
|
|
417
|
-
this.textLines = newLines.lines;
|
|
418
|
-
this._textLines = newLines.graphemeLines;
|
|
419
|
-
this._unwrappedTextLines = newLines._unwrappedLines;
|
|
420
|
-
this._text = newLines.graphemeText;
|
|
421
|
-
return newLines;
|
|
422
|
-
},
|
|
423
|
-
|
|
424
|
-
/**
|
|
425
|
-
* Initialize or update text dimensions.
|
|
426
|
-
* Updates this.width and this.height with the proper values.
|
|
427
|
-
* Does not return dimensions.
|
|
428
|
-
*/
|
|
429
|
-
initDimensions: function() {
|
|
430
|
-
if (this.__skipDimension) {
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
this._splitText();
|
|
434
|
-
this._clearCache();
|
|
435
|
-
if (this.path) {
|
|
436
|
-
this.width = this.path.width;
|
|
437
|
-
this.height = this.path.height;
|
|
438
|
-
}
|
|
439
|
-
else {
|
|
440
|
-
this.width = this.calcTextWidth() || this.cursorWidth || this.MIN_TEXT_WIDTH;
|
|
441
|
-
this.height = this.calcTextHeight();
|
|
442
|
-
}
|
|
443
|
-
if (this.textAlign.indexOf('justify') !== -1) {
|
|
444
|
-
// once text is measured we need to make space fatter to make justified text.
|
|
445
|
-
this.enlargeSpaces();
|
|
446
|
-
}
|
|
447
|
-
this.saveState({ propertySet: '_dimensionAffectingProps' });
|
|
448
|
-
},
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
* Enlarge space boxes and shift the others
|
|
452
|
-
*/
|
|
453
|
-
enlargeSpaces: function() {
|
|
454
|
-
var diffSpace, currentLineWidth, numberOfSpaces, accumulatedSpace, line, charBound, spaces;
|
|
455
|
-
for (var i = 0, len = this._textLines.length; i < len; i++) {
|
|
456
|
-
if (this.textAlign !== 'justify' && (i === len - 1 || this.isEndOfWrapping(i))) {
|
|
457
|
-
continue;
|
|
458
|
-
}
|
|
459
|
-
accumulatedSpace = 0;
|
|
460
|
-
line = this._textLines[i];
|
|
461
|
-
currentLineWidth = this.getLineWidth(i);
|
|
462
|
-
if (currentLineWidth < this.width && (spaces = this.textLines[i].match(this._reSpacesAndTabs))) {
|
|
463
|
-
numberOfSpaces = spaces.length;
|
|
464
|
-
diffSpace = (this.width - currentLineWidth) / numberOfSpaces;
|
|
465
|
-
for (var j = 0, jlen = line.length; j <= jlen; j++) {
|
|
466
|
-
charBound = this.__charBounds[i][j];
|
|
467
|
-
if (this._reSpaceAndTab.test(line[j])) {
|
|
468
|
-
charBound.width += diffSpace;
|
|
469
|
-
charBound.kernedWidth += diffSpace;
|
|
470
|
-
charBound.left += accumulatedSpace;
|
|
471
|
-
accumulatedSpace += diffSpace;
|
|
472
|
-
}
|
|
473
|
-
else {
|
|
474
|
-
charBound.left += accumulatedSpace;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
},
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
* Detect if the text line is ended with an hard break
|
|
483
|
-
* text and itext do not have wrapping, return false
|
|
484
|
-
* @return {Boolean}
|
|
485
|
-
*/
|
|
486
|
-
isEndOfWrapping: function(lineIndex) {
|
|
487
|
-
return lineIndex === this._textLines.length - 1;
|
|
488
|
-
},
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* Detect if a line has a linebreak and so we need to account for it when moving
|
|
492
|
-
* and counting style.
|
|
493
|
-
* It return always for text and Itext.
|
|
494
|
-
* @return Number
|
|
495
|
-
*/
|
|
496
|
-
missingNewlineOffset: function() {
|
|
497
|
-
return 1;
|
|
498
|
-
},
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
* Returns string representation of an instance
|
|
502
|
-
* @return {String} String representation of text object
|
|
503
|
-
*/
|
|
504
|
-
toString: function() {
|
|
505
|
-
return '#<fabric.Text (' + this.complexity() +
|
|
506
|
-
'): { "text": "' + this.text + '", "fontFamily": "' + this.fontFamily + '" }>';
|
|
507
|
-
},
|
|
508
|
-
|
|
509
|
-
/**
|
|
510
|
-
* Return the dimension and the zoom level needed to create a cache canvas
|
|
511
|
-
* big enough to host the object to be cached.
|
|
512
|
-
* @private
|
|
513
|
-
* @param {Object} dim.x width of object to be cached
|
|
514
|
-
* @param {Object} dim.y height of object to be cached
|
|
515
|
-
* @return {Object}.width width of canvas
|
|
516
|
-
* @return {Object}.height height of canvas
|
|
517
|
-
* @return {Object}.zoomX zoomX zoom value to unscale the canvas before drawing cache
|
|
518
|
-
* @return {Object}.zoomY zoomY zoom value to unscale the canvas before drawing cache
|
|
519
|
-
*/
|
|
520
|
-
_getCacheCanvasDimensions: function() {
|
|
521
|
-
var dims = this.callSuper('_getCacheCanvasDimensions');
|
|
522
|
-
var fontSize = this.fontSize;
|
|
523
|
-
dims.width += fontSize * dims.zoomX;
|
|
524
|
-
dims.height += fontSize * dims.zoomY;
|
|
525
|
-
return dims;
|
|
526
|
-
},
|
|
527
|
-
|
|
528
|
-
/**
|
|
529
|
-
* @private
|
|
530
|
-
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
531
|
-
*/
|
|
532
|
-
_render: function(ctx) {
|
|
533
|
-
var path = this.path;
|
|
534
|
-
path && !path.isNotVisible() && path._render(ctx);
|
|
535
|
-
this._setTextStyles(ctx);
|
|
536
|
-
this._renderTextLinesBackground(ctx);
|
|
537
|
-
this._renderTextDecoration(ctx, 'underline');
|
|
538
|
-
this._renderText(ctx);
|
|
539
|
-
this._renderTextDecoration(ctx, 'overline');
|
|
540
|
-
this._renderTextDecoration(ctx, 'linethrough');
|
|
541
|
-
},
|
|
542
|
-
|
|
543
|
-
/**
|
|
544
|
-
* @private
|
|
545
|
-
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
546
|
-
*/
|
|
547
|
-
_renderText: function(ctx) {
|
|
548
|
-
if (this.paintFirst === 'stroke') {
|
|
549
|
-
this._renderTextStroke(ctx);
|
|
550
|
-
this._renderTextFill(ctx);
|
|
551
|
-
}
|
|
552
|
-
else {
|
|
553
|
-
this._renderTextFill(ctx);
|
|
554
|
-
this._renderTextStroke(ctx);
|
|
555
|
-
}
|
|
556
|
-
},
|
|
557
|
-
|
|
558
|
-
/**
|
|
559
|
-
* Set the font parameter of the context with the object properties or with charStyle
|
|
560
|
-
* @private
|
|
561
|
-
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
562
|
-
* @param {Object} [charStyle] object with font style properties
|
|
563
|
-
* @param {String} [charStyle.fontFamily] Font Family
|
|
564
|
-
* @param {Number} [charStyle.fontSize] Font size in pixels. ( without px suffix )
|
|
565
|
-
* @param {String} [charStyle.fontWeight] Font weight
|
|
566
|
-
* @param {String} [charStyle.fontStyle] Font style (italic|normal)
|
|
567
|
-
*/
|
|
568
|
-
_setTextStyles: function(ctx, charStyle, forMeasuring) {
|
|
569
|
-
ctx.textBaseline = 'alphabetical';
|
|
570
|
-
if (this.path) {
|
|
571
|
-
switch (this.pathAlign) {
|
|
572
|
-
case 'center':
|
|
573
|
-
ctx.textBaseline = 'middle';
|
|
574
|
-
break;
|
|
575
|
-
case 'ascender':
|
|
576
|
-
ctx.textBaseline = 'top';
|
|
577
|
-
break;
|
|
578
|
-
case 'descender':
|
|
579
|
-
ctx.textBaseline = 'bottom';
|
|
580
|
-
break;
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
ctx.font = this._getFontDeclaration(charStyle, forMeasuring);
|
|
584
|
-
},
|
|
585
|
-
|
|
586
|
-
/**
|
|
587
|
-
* calculate and return the text Width measuring each line.
|
|
588
|
-
* @private
|
|
589
|
-
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
590
|
-
* @return {Number} Maximum width of fabric.Text object
|
|
591
|
-
*/
|
|
592
|
-
calcTextWidth: function() {
|
|
593
|
-
var maxWidth = this.getLineWidth(0);
|
|
594
|
-
|
|
595
|
-
for (var i = 1, len = this._textLines.length; i < len; i++) {
|
|
596
|
-
var currentLineWidth = this.getLineWidth(i);
|
|
597
|
-
if (currentLineWidth > maxWidth) {
|
|
598
|
-
maxWidth = currentLineWidth;
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
return maxWidth;
|
|
602
|
-
},
|
|
603
|
-
|
|
604
|
-
/**
|
|
605
|
-
* @private
|
|
606
|
-
* @param {String} method Method name ("fillText" or "strokeText")
|
|
607
|
-
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
608
|
-
* @param {String} line Text to render
|
|
609
|
-
* @param {Number} left Left position of text
|
|
610
|
-
* @param {Number} top Top position of text
|
|
611
|
-
* @param {Number} lineIndex Index of a line in a text
|
|
612
|
-
*/
|
|
613
|
-
_renderTextLine: function(method, ctx, line, left, top, lineIndex) {
|
|
614
|
-
this._renderChars(method, ctx, line, left, top, lineIndex);
|
|
615
|
-
},
|
|
616
|
-
|
|
617
|
-
/**
|
|
618
|
-
* Renders the text background for lines, taking care of style
|
|
619
|
-
* @private
|
|
620
|
-
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
621
|
-
*/
|
|
622
|
-
_renderTextLinesBackground: function(ctx) {
|
|
623
|
-
if (!this.textBackgroundColor && !this.styleHas('textBackgroundColor')) {
|
|
624
|
-
return;
|
|
625
|
-
}
|
|
626
|
-
var heightOfLine,
|
|
627
|
-
lineLeftOffset, originalFill = ctx.fillStyle,
|
|
628
|
-
line, lastColor,
|
|
629
|
-
leftOffset = this._getLeftOffset(),
|
|
630
|
-
lineTopOffset = this._getTopOffset(),
|
|
631
|
-
boxStart = 0, boxWidth = 0, charBox, currentColor, path = this.path,
|
|
632
|
-
drawStart;
|
|
633
|
-
|
|
634
|
-
for (var i = 0, len = this._textLines.length; i < len; i++) {
|
|
635
|
-
heightOfLine = this.getHeightOfLine(i);
|
|
636
|
-
if (!this.textBackgroundColor && !this.styleHas('textBackgroundColor', i)) {
|
|
637
|
-
lineTopOffset += heightOfLine;
|
|
638
|
-
continue;
|
|
639
|
-
}
|
|
640
|
-
line = this._textLines[i];
|
|
641
|
-
lineLeftOffset = this._getLineLeftOffset(i);
|
|
642
|
-
boxWidth = 0;
|
|
643
|
-
boxStart = 0;
|
|
644
|
-
lastColor = this.getValueOfPropertyAt(i, 0, 'textBackgroundColor');
|
|
645
|
-
for (var j = 0, jlen = line.length; j < jlen; j++) {
|
|
646
|
-
charBox = this.__charBounds[i][j];
|
|
647
|
-
currentColor = this.getValueOfPropertyAt(i, j, 'textBackgroundColor');
|
|
648
|
-
if (path) {
|
|
649
|
-
ctx.save();
|
|
650
|
-
ctx.translate(charBox.renderLeft, charBox.renderTop);
|
|
651
|
-
ctx.rotate(charBox.angle);
|
|
652
|
-
ctx.fillStyle = currentColor;
|
|
653
|
-
currentColor && ctx.fillRect(
|
|
654
|
-
-charBox.width / 2,
|
|
655
|
-
-heightOfLine / this.lineHeight * (1 - this._fontSizeFraction),
|
|
656
|
-
charBox.width,
|
|
657
|
-
heightOfLine / this.lineHeight
|
|
658
|
-
);
|
|
659
|
-
ctx.restore();
|
|
660
|
-
}
|
|
661
|
-
else if (currentColor !== lastColor) {
|
|
662
|
-
drawStart = leftOffset + lineLeftOffset + boxStart;
|
|
663
|
-
if (this.direction === 'rtl') {
|
|
664
|
-
drawStart = this.width - drawStart - boxWidth;
|
|
665
|
-
}
|
|
666
|
-
ctx.fillStyle = lastColor;
|
|
667
|
-
lastColor && ctx.fillRect(
|
|
668
|
-
drawStart,
|
|
669
|
-
lineTopOffset,
|
|
670
|
-
boxWidth,
|
|
671
|
-
heightOfLine / this.lineHeight
|
|
672
|
-
);
|
|
673
|
-
boxStart = charBox.left;
|
|
674
|
-
boxWidth = charBox.width;
|
|
675
|
-
lastColor = currentColor;
|
|
676
|
-
}
|
|
677
|
-
else {
|
|
678
|
-
boxWidth += charBox.kernedWidth;
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
if (currentColor && !path) {
|
|
682
|
-
drawStart = leftOffset + lineLeftOffset + boxStart;
|
|
683
|
-
if (this.direction === 'rtl') {
|
|
684
|
-
drawStart = this.width - drawStart - boxWidth;
|
|
685
|
-
}
|
|
686
|
-
ctx.fillStyle = currentColor;
|
|
687
|
-
ctx.fillRect(
|
|
688
|
-
drawStart,
|
|
689
|
-
lineTopOffset,
|
|
690
|
-
boxWidth,
|
|
691
|
-
heightOfLine / this.lineHeight
|
|
692
|
-
);
|
|
693
|
-
}
|
|
694
|
-
lineTopOffset += heightOfLine;
|
|
695
|
-
}
|
|
696
|
-
ctx.fillStyle = originalFill;
|
|
697
|
-
// if there is text background color no
|
|
698
|
-
// other shadows should be casted
|
|
699
|
-
this._removeShadow(ctx);
|
|
700
|
-
},
|
|
701
|
-
|
|
702
|
-
/**
|
|
703
|
-
* @private
|
|
704
|
-
* @param {Object} decl style declaration for cache
|
|
705
|
-
* @param {String} decl.fontFamily fontFamily
|
|
706
|
-
* @param {String} decl.fontStyle fontStyle
|
|
707
|
-
* @param {String} decl.fontWeight fontWeight
|
|
708
|
-
* @return {Object} reference to cache
|
|
709
|
-
*/
|
|
710
|
-
getFontCache: function(decl) {
|
|
711
|
-
var fontFamily = decl.fontFamily.toLowerCase();
|
|
712
|
-
if (!fabric.charWidthsCache[fontFamily]) {
|
|
713
|
-
fabric.charWidthsCache[fontFamily] = { };
|
|
714
|
-
}
|
|
715
|
-
var cache = fabric.charWidthsCache[fontFamily],
|
|
716
|
-
cacheProp = decl.fontStyle.toLowerCase() + '_' + (decl.fontWeight + '').toLowerCase();
|
|
717
|
-
if (!cache[cacheProp]) {
|
|
718
|
-
cache[cacheProp] = { };
|
|
719
|
-
}
|
|
720
|
-
return cache[cacheProp];
|
|
721
|
-
},
|
|
722
|
-
|
|
723
|
-
/**
|
|
724
|
-
* measure and return the width of a single character.
|
|
725
|
-
* possibly overridden to accommodate different measure logic or
|
|
726
|
-
* to hook some external lib for character measurement
|
|
727
|
-
* @private
|
|
728
|
-
* @param {String} _char, char to be measured
|
|
729
|
-
* @param {Object} charStyle style of char to be measured
|
|
730
|
-
* @param {String} [previousChar] previous char
|
|
731
|
-
* @param {Object} [prevCharStyle] style of previous char
|
|
732
|
-
*/
|
|
733
|
-
_measureChar: function(_char, charStyle, previousChar, prevCharStyle) {
|
|
734
|
-
// first i try to return from cache
|
|
735
|
-
var fontCache = this.getFontCache(charStyle), fontDeclaration = this._getFontDeclaration(charStyle),
|
|
736
|
-
previousFontDeclaration = this._getFontDeclaration(prevCharStyle), couple = previousChar + _char,
|
|
737
|
-
stylesAreEqual = fontDeclaration === previousFontDeclaration, width, coupleWidth, previousWidth,
|
|
738
|
-
fontMultiplier = charStyle.fontSize / this.CACHE_FONT_SIZE, kernedWidth;
|
|
739
|
-
|
|
740
|
-
if (previousChar && fontCache[previousChar] !== undefined) {
|
|
741
|
-
previousWidth = fontCache[previousChar];
|
|
742
|
-
}
|
|
743
|
-
if (fontCache[_char] !== undefined) {
|
|
744
|
-
kernedWidth = width = fontCache[_char];
|
|
745
|
-
}
|
|
746
|
-
if (stylesAreEqual && fontCache[couple] !== undefined) {
|
|
747
|
-
coupleWidth = fontCache[couple];
|
|
748
|
-
kernedWidth = coupleWidth - previousWidth;
|
|
749
|
-
}
|
|
750
|
-
if (width === undefined || previousWidth === undefined || coupleWidth === undefined) {
|
|
751
|
-
var ctx = this.getMeasuringContext();
|
|
752
|
-
// send a TRUE to specify measuring font size CACHE_FONT_SIZE
|
|
753
|
-
this._setTextStyles(ctx, charStyle, true);
|
|
754
|
-
}
|
|
755
|
-
if (width === undefined) {
|
|
756
|
-
kernedWidth = width = ctx.measureText(_char).width;
|
|
757
|
-
fontCache[_char] = width;
|
|
758
|
-
}
|
|
759
|
-
if (previousWidth === undefined && stylesAreEqual && previousChar) {
|
|
760
|
-
previousWidth = ctx.measureText(previousChar).width;
|
|
761
|
-
fontCache[previousChar] = previousWidth;
|
|
762
|
-
}
|
|
763
|
-
if (stylesAreEqual && coupleWidth === undefined) {
|
|
764
|
-
// we can measure the kerning couple and subtract the width of the previous character
|
|
765
|
-
coupleWidth = ctx.measureText(couple).width;
|
|
766
|
-
fontCache[couple] = coupleWidth;
|
|
767
|
-
kernedWidth = coupleWidth - previousWidth;
|
|
768
|
-
}
|
|
769
|
-
return { width: width * fontMultiplier, kernedWidth: kernedWidth * fontMultiplier };
|
|
770
|
-
},
|
|
771
|
-
|
|
772
|
-
/**
|
|
773
|
-
* Computes height of character at given position
|
|
774
|
-
* @param {Number} line the line index number
|
|
775
|
-
* @param {Number} _char the character index number
|
|
776
|
-
* @return {Number} fontSize of the character
|
|
777
|
-
*/
|
|
778
|
-
getHeightOfChar: function(line, _char) {
|
|
779
|
-
return this.getValueOfPropertyAt(line, _char, 'fontSize');
|
|
780
|
-
},
|
|
781
|
-
|
|
782
|
-
/**
|
|
783
|
-
* measure a text line measuring all characters.
|
|
784
|
-
* @param {Number} lineIndex line number
|
|
785
|
-
* @return {Number} Line width
|
|
786
|
-
*/
|
|
787
|
-
measureLine: function(lineIndex) {
|
|
788
|
-
var lineInfo = this._measureLine(lineIndex);
|
|
789
|
-
if (this.charSpacing !== 0) {
|
|
790
|
-
lineInfo.width -= this._getWidthOfCharSpacing();
|
|
791
|
-
}
|
|
792
|
-
if (lineInfo.width < 0) {
|
|
793
|
-
lineInfo.width = 0;
|
|
794
|
-
}
|
|
795
|
-
return lineInfo;
|
|
796
|
-
},
|
|
797
|
-
|
|
798
|
-
/**
|
|
799
|
-
* measure every grapheme of a line, populating __charBounds
|
|
800
|
-
* @param {Number} lineIndex
|
|
801
|
-
* @return {Object} object.width total width of characters
|
|
802
|
-
* @return {Object} object.widthOfSpaces length of chars that match this._reSpacesAndTabs
|
|
803
|
-
*/
|
|
804
|
-
_measureLine: function(lineIndex) {
|
|
805
|
-
var width = 0, i, grapheme, line = this._textLines[lineIndex], prevGrapheme,
|
|
806
|
-
graphemeInfo, numOfSpaces = 0, lineBounds = new Array(line.length),
|
|
807
|
-
positionInPath = 0, startingPoint, totalPathLength, path = this.path,
|
|
808
|
-
reverse = this.pathSide === 'right';
|
|
809
|
-
|
|
810
|
-
this.__charBounds[lineIndex] = lineBounds;
|
|
811
|
-
for (i = 0; i < line.length; i++) {
|
|
812
|
-
grapheme = line[i];
|
|
813
|
-
graphemeInfo = this._getGraphemeBox(grapheme, lineIndex, i, prevGrapheme);
|
|
814
|
-
lineBounds[i] = graphemeInfo;
|
|
815
|
-
width += graphemeInfo.kernedWidth;
|
|
816
|
-
prevGrapheme = grapheme;
|
|
817
|
-
}
|
|
818
|
-
// this latest bound box represent the last character of the line
|
|
819
|
-
// to simplify cursor handling in interactive mode.
|
|
820
|
-
lineBounds[i] = {
|
|
821
|
-
left: graphemeInfo ? graphemeInfo.left + graphemeInfo.width : 0,
|
|
822
|
-
width: 0,
|
|
823
|
-
kernedWidth: 0,
|
|
824
|
-
height: this.fontSize
|
|
825
|
-
};
|
|
826
|
-
if (path) {
|
|
827
|
-
totalPathLength = path.segmentsInfo[path.segmentsInfo.length - 1].length;
|
|
828
|
-
startingPoint = fabric.util.getPointOnPath(path.path, 0, path.segmentsInfo);
|
|
829
|
-
startingPoint.x += path.pathOffset.x;
|
|
830
|
-
startingPoint.y += path.pathOffset.y;
|
|
831
|
-
switch (this.textAlign) {
|
|
832
|
-
case 'left':
|
|
833
|
-
positionInPath = reverse ? (totalPathLength - width) : 0;
|
|
834
|
-
break;
|
|
835
|
-
case 'center':
|
|
836
|
-
positionInPath = (totalPathLength - width) / 2;
|
|
837
|
-
break;
|
|
838
|
-
case 'right':
|
|
839
|
-
positionInPath = reverse ? 0 : (totalPathLength - width);
|
|
840
|
-
break;
|
|
841
|
-
//todo - add support for justify
|
|
842
|
-
}
|
|
843
|
-
positionInPath += this.pathStartOffset * (reverse ? -1 : 1);
|
|
844
|
-
for (i = reverse ? line.length - 1 : 0;
|
|
845
|
-
reverse ? i >= 0 : i < line.length;
|
|
846
|
-
reverse ? i-- : i++) {
|
|
847
|
-
graphemeInfo = lineBounds[i];
|
|
848
|
-
if (positionInPath > totalPathLength) {
|
|
849
|
-
positionInPath %= totalPathLength;
|
|
850
|
-
}
|
|
851
|
-
else if (positionInPath < 0) {
|
|
852
|
-
positionInPath += totalPathLength;
|
|
853
|
-
}
|
|
854
|
-
// it would probably much faster to send all the grapheme position for a line
|
|
855
|
-
// and calculate path position/angle at once.
|
|
856
|
-
this._setGraphemeOnPath(positionInPath, graphemeInfo, startingPoint);
|
|
857
|
-
positionInPath += graphemeInfo.kernedWidth;
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
return { width: width, numOfSpaces: numOfSpaces };
|
|
861
|
-
},
|
|
862
|
-
|
|
863
|
-
/**
|
|
864
|
-
* Calculate the angle and the left,top position of the char that follow a path.
|
|
865
|
-
* It appends it to graphemeInfo to be reused later at rendering
|
|
866
|
-
* @private
|
|
867
|
-
* @param {Number} positionInPath to be measured
|
|
868
|
-
* @param {Object} graphemeInfo current grapheme box information
|
|
869
|
-
* @param {Object} startingPoint position of the point
|
|
870
|
-
*/
|
|
871
|
-
_setGraphemeOnPath: function(positionInPath, graphemeInfo, startingPoint) {
|
|
872
|
-
var centerPosition = positionInPath + graphemeInfo.kernedWidth / 2,
|
|
873
|
-
path = this.path;
|
|
874
|
-
|
|
875
|
-
// we are at currentPositionOnPath. we want to know what point on the path is.
|
|
876
|
-
var info = fabric.util.getPointOnPath(path.path, centerPosition, path.segmentsInfo);
|
|
877
|
-
graphemeInfo.renderLeft = info.x - startingPoint.x;
|
|
878
|
-
graphemeInfo.renderTop = info.y - startingPoint.y;
|
|
879
|
-
graphemeInfo.angle = info.angle + (this.pathSide === 'right' ? Math.PI : 0);
|
|
880
|
-
},
|
|
881
|
-
|
|
882
|
-
/**
|
|
883
|
-
* Measure and return the info of a single grapheme.
|
|
884
|
-
* needs the the info of previous graphemes already filled
|
|
885
|
-
* @private
|
|
886
|
-
* @param {String} grapheme to be measured
|
|
887
|
-
* @param {Number} lineIndex index of the line where the char is
|
|
888
|
-
* @param {Number} charIndex position in the line
|
|
889
|
-
* @param {String} [prevGrapheme] character preceding the one to be measured
|
|
890
|
-
*/
|
|
891
|
-
_getGraphemeBox: function(grapheme, lineIndex, charIndex, prevGrapheme, skipLeft) {
|
|
892
|
-
var style = this.getCompleteStyleDeclaration(lineIndex, charIndex),
|
|
893
|
-
prevStyle = prevGrapheme ? this.getCompleteStyleDeclaration(lineIndex, charIndex - 1) : { },
|
|
894
|
-
info = this._measureChar(grapheme, style, prevGrapheme, prevStyle),
|
|
895
|
-
kernedWidth = info.kernedWidth,
|
|
896
|
-
width = info.width, charSpacing;
|
|
897
|
-
|
|
898
|
-
if (this.charSpacing !== 0) {
|
|
899
|
-
charSpacing = this._getWidthOfCharSpacing();
|
|
900
|
-
width += charSpacing;
|
|
901
|
-
kernedWidth += charSpacing;
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
var box = {
|
|
905
|
-
width: width,
|
|
906
|
-
left: 0,
|
|
907
|
-
height: style.fontSize,
|
|
908
|
-
kernedWidth: kernedWidth,
|
|
909
|
-
deltaY: style.deltaY,
|
|
910
|
-
};
|
|
911
|
-
if (charIndex > 0 && !skipLeft) {
|
|
912
|
-
var previousBox = this.__charBounds[lineIndex][charIndex - 1];
|
|
913
|
-
box.left = previousBox.left + previousBox.width + info.kernedWidth - info.width;
|
|
914
|
-
}
|
|
915
|
-
return box;
|
|
916
|
-
},
|
|
917
|
-
|
|
918
|
-
/**
|
|
919
|
-
* Calculate height of line at 'lineIndex'
|
|
920
|
-
* @param {Number} lineIndex index of line to calculate
|
|
921
|
-
* @return {Number}
|
|
922
|
-
*/
|
|
923
|
-
getHeightOfLine: function(lineIndex) {
|
|
924
|
-
if (this.__lineHeights[lineIndex]) {
|
|
925
|
-
return this.__lineHeights[lineIndex];
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
var line = this._textLines[lineIndex],
|
|
929
|
-
// char 0 is measured before the line cycle because it nneds to char
|
|
930
|
-
// emptylines
|
|
931
|
-
maxHeight = this.getHeightOfChar(lineIndex, 0);
|
|
932
|
-
for (var i = 1, len = line.length; i < len; i++) {
|
|
933
|
-
maxHeight = Math.max(this.getHeightOfChar(lineIndex, i), maxHeight);
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
return this.__lineHeights[lineIndex] = maxHeight * this.lineHeight * this._fontSizeMult;
|
|
937
|
-
},
|
|
938
|
-
|
|
939
|
-
/**
|
|
940
|
-
* Calculate text box height
|
|
941
|
-
*/
|
|
942
|
-
calcTextHeight: function() {
|
|
943
|
-
var lineHeight, height = 0;
|
|
944
|
-
for (var i = 0, len = this._textLines.length; i < len; i++) {
|
|
945
|
-
lineHeight = this.getHeightOfLine(i);
|
|
946
|
-
height += (i === len - 1 ? lineHeight / this.lineHeight : lineHeight);
|
|
947
|
-
}
|
|
948
|
-
return height;
|
|
949
|
-
},
|
|
950
|
-
|
|
951
|
-
/**
|
|
952
|
-
* @private
|
|
953
|
-
* @return {Number} Left offset
|
|
954
|
-
*/
|
|
955
|
-
_getLeftOffset: function() {
|
|
956
|
-
return this.direction === 'ltr' ? -this.width / 2 : this.width / 2;
|
|
957
|
-
},
|
|
958
|
-
|
|
959
|
-
/**
|
|
960
|
-
* @private
|
|
961
|
-
* @return {Number} Top offset
|
|
962
|
-
*/
|
|
963
|
-
_getTopOffset: function() {
|
|
964
|
-
return -this.height / 2;
|
|
965
|
-
},
|
|
966
|
-
|
|
967
|
-
/**
|
|
968
|
-
* @private
|
|
969
|
-
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
970
|
-
* @param {String} method Method name ("fillText" or "strokeText")
|
|
971
|
-
*/
|
|
972
|
-
_renderTextCommon: function(ctx, method) {
|
|
973
|
-
ctx.save();
|
|
974
|
-
var lineHeights = 0, left = this._getLeftOffset(), top = this._getTopOffset();
|
|
975
|
-
for (var i = 0, len = this._textLines.length; i < len; i++) {
|
|
976
|
-
var heightOfLine = this.getHeightOfLine(i),
|
|
977
|
-
maxHeight = heightOfLine / this.lineHeight,
|
|
978
|
-
leftOffset = this._getLineLeftOffset(i);
|
|
979
|
-
this._renderTextLine(
|
|
980
|
-
method,
|
|
981
|
-
ctx,
|
|
982
|
-
this._textLines[i],
|
|
983
|
-
left + leftOffset,
|
|
984
|
-
top + lineHeights + maxHeight,
|
|
985
|
-
i
|
|
986
|
-
);
|
|
987
|
-
lineHeights += heightOfLine;
|
|
988
|
-
}
|
|
989
|
-
ctx.restore();
|
|
990
|
-
},
|
|
991
|
-
|
|
992
|
-
/**
|
|
993
|
-
* @private
|
|
994
|
-
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
995
|
-
*/
|
|
996
|
-
_renderTextFill: function(ctx) {
|
|
997
|
-
if (!this.fill && !this.styleHas('fill')) {
|
|
998
|
-
return;
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
this._renderTextCommon(ctx, 'fillText');
|
|
1002
|
-
},
|
|
1003
|
-
|
|
1004
|
-
/**
|
|
1005
|
-
* @private
|
|
1006
|
-
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
1007
|
-
*/
|
|
1008
|
-
_renderTextStroke: function(ctx) {
|
|
1009
|
-
if ((!this.stroke || this.strokeWidth === 0) && this.isEmptyStyles()) {
|
|
1010
|
-
return;
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
if (this.shadow && !this.shadow.affectStroke) {
|
|
1014
|
-
this._removeShadow(ctx);
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
ctx.save();
|
|
1018
|
-
this._setLineDash(ctx, this.strokeDashArray);
|
|
1019
|
-
ctx.beginPath();
|
|
1020
|
-
this._renderTextCommon(ctx, 'strokeText');
|
|
1021
|
-
ctx.closePath();
|
|
1022
|
-
ctx.restore();
|
|
1023
|
-
},
|
|
1024
|
-
|
|
1025
|
-
/**
|
|
1026
|
-
* @private
|
|
1027
|
-
* @param {String} method fillText or strokeText.
|
|
1028
|
-
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
1029
|
-
* @param {Array} line Content of the line, splitted in an array by grapheme
|
|
1030
|
-
* @param {Number} left
|
|
1031
|
-
* @param {Number} top
|
|
1032
|
-
* @param {Number} lineIndex
|
|
1033
|
-
*/
|
|
1034
|
-
_renderChars: function(method, ctx, line, left, top, lineIndex) {
|
|
1035
|
-
// set proper line offset
|
|
1036
|
-
var lineHeight = this.getHeightOfLine(lineIndex),
|
|
1037
|
-
isJustify = this.textAlign.indexOf('justify') !== -1,
|
|
1038
|
-
actualStyle,
|
|
1039
|
-
nextStyle,
|
|
1040
|
-
charsToRender = '',
|
|
1041
|
-
charBox,
|
|
1042
|
-
boxWidth = 0,
|
|
1043
|
-
timeToRender,
|
|
1044
|
-
path = this.path,
|
|
1045
|
-
shortCut = !isJustify && this.charSpacing === 0 && this.isEmptyStyles(lineIndex) && !path,
|
|
1046
|
-
isLtr = this.direction === 'ltr', sign = this.direction === 'ltr' ? 1 : -1,
|
|
1047
|
-
drawingLeft, currentDirection = ctx.canvas.getAttribute('dir');
|
|
1048
|
-
ctx.save();
|
|
1049
|
-
if (currentDirection !== this.direction) {
|
|
1050
|
-
ctx.canvas.setAttribute('dir', isLtr ? 'ltr' : 'rtl');
|
|
1051
|
-
ctx.direction = isLtr ? 'ltr' : 'rtl';
|
|
1052
|
-
ctx.textAlign = isLtr ? 'left' : 'right';
|
|
1053
|
-
}
|
|
1054
|
-
top -= lineHeight * this._fontSizeFraction / this.lineHeight;
|
|
1055
|
-
if (shortCut) {
|
|
1056
|
-
// render all the line in one pass without checking
|
|
1057
|
-
// drawingLeft = isLtr ? left : left - this.getLineWidth(lineIndex);
|
|
1058
|
-
this._renderChar(method, ctx, lineIndex, 0, line.join(''), left, top, lineHeight);
|
|
1059
|
-
ctx.restore();
|
|
1060
|
-
return;
|
|
1061
|
-
}
|
|
1062
|
-
for (var i = 0, len = line.length - 1; i <= len; i++) {
|
|
1063
|
-
timeToRender = i === len || this.charSpacing || path;
|
|
1064
|
-
charsToRender += line[i];
|
|
1065
|
-
charBox = this.__charBounds[lineIndex][i];
|
|
1066
|
-
if (boxWidth === 0) {
|
|
1067
|
-
left += sign * (charBox.kernedWidth - charBox.width);
|
|
1068
|
-
boxWidth += charBox.width;
|
|
1069
|
-
}
|
|
1070
|
-
else {
|
|
1071
|
-
boxWidth += charBox.kernedWidth;
|
|
1072
|
-
}
|
|
1073
|
-
if (isJustify && !timeToRender) {
|
|
1074
|
-
if (this._reSpaceAndTab.test(line[i])) {
|
|
1075
|
-
timeToRender = true;
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
if (!timeToRender) {
|
|
1079
|
-
// if we have charSpacing, we render char by char
|
|
1080
|
-
actualStyle = actualStyle || this.getCompleteStyleDeclaration(lineIndex, i);
|
|
1081
|
-
nextStyle = this.getCompleteStyleDeclaration(lineIndex, i + 1);
|
|
1082
|
-
timeToRender = fabric.util.hasStyleChanged(actualStyle, nextStyle, false);
|
|
1083
|
-
}
|
|
1084
|
-
if (timeToRender) {
|
|
1085
|
-
if (path) {
|
|
1086
|
-
ctx.save();
|
|
1087
|
-
ctx.translate(charBox.renderLeft, charBox.renderTop);
|
|
1088
|
-
ctx.rotate(charBox.angle);
|
|
1089
|
-
this._renderChar(method, ctx, lineIndex, i, charsToRender, -boxWidth / 2, 0, lineHeight);
|
|
1090
|
-
ctx.restore();
|
|
1091
|
-
}
|
|
1092
|
-
else {
|
|
1093
|
-
drawingLeft = left;
|
|
1094
|
-
this._renderChar(method, ctx, lineIndex, i, charsToRender, drawingLeft, top, lineHeight);
|
|
1095
|
-
}
|
|
1096
|
-
charsToRender = '';
|
|
1097
|
-
actualStyle = nextStyle;
|
|
1098
|
-
left += sign * boxWidth;
|
|
1099
|
-
boxWidth = 0;
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
ctx.restore();
|
|
1103
|
-
},
|
|
1104
|
-
|
|
1105
|
-
/**
|
|
1106
|
-
* This function try to patch the missing gradientTransform on canvas gradients.
|
|
1107
|
-
* transforming a context to transform the gradient, is going to transform the stroke too.
|
|
1108
|
-
* we want to transform the gradient but not the stroke operation, so we create
|
|
1109
|
-
* a transformed gradient on a pattern and then we use the pattern instead of the gradient.
|
|
1110
|
-
* this method has drawbacks: is slow, is in low resolution, needs a patch for when the size
|
|
1111
|
-
* is limited.
|
|
1112
|
-
* @private
|
|
1113
|
-
* @param {fabric.Gradient} filler a fabric gradient instance
|
|
1114
|
-
* @return {CanvasPattern} a pattern to use as fill/stroke style
|
|
1115
|
-
*/
|
|
1116
|
-
_applyPatternGradientTransformText: function(filler) {
|
|
1117
|
-
var pCanvas = fabric.util.createCanvasElement(), pCtx,
|
|
1118
|
-
// TODO: verify compatibility with strokeUniform
|
|
1119
|
-
width = this.width + this.strokeWidth, height = this.height + this.strokeWidth;
|
|
1120
|
-
pCanvas.width = width;
|
|
1121
|
-
pCanvas.height = height;
|
|
1122
|
-
pCtx = pCanvas.getContext('2d');
|
|
1123
|
-
pCtx.beginPath(); pCtx.moveTo(0, 0); pCtx.lineTo(width, 0); pCtx.lineTo(width, height);
|
|
1124
|
-
pCtx.lineTo(0, height); pCtx.closePath();
|
|
1125
|
-
pCtx.translate(width / 2, height / 2);
|
|
1126
|
-
pCtx.fillStyle = filler.toLive(pCtx);
|
|
1127
|
-
this._applyPatternGradientTransform(pCtx, filler);
|
|
1128
|
-
pCtx.fill();
|
|
1129
|
-
return pCtx.createPattern(pCanvas, 'no-repeat');
|
|
1130
|
-
},
|
|
1131
|
-
|
|
1132
|
-
handleFiller: function(ctx, property, filler) {
|
|
1133
|
-
var offsetX, offsetY;
|
|
1134
|
-
if (filler.toLive) {
|
|
1135
|
-
if (filler.gradientUnits === 'percentage' || filler.gradientTransform || filler.patternTransform) {
|
|
1136
|
-
// need to transform gradient in a pattern.
|
|
1137
|
-
// this is a slow process. If you are hitting this codepath, and the object
|
|
1138
|
-
// is not using caching, you should consider switching it on.
|
|
1139
|
-
// we need a canvas as big as the current object caching canvas.
|
|
1140
|
-
offsetX = -this.width / 2;
|
|
1141
|
-
offsetY = -this.height / 2;
|
|
1142
|
-
ctx.translate(offsetX, offsetY);
|
|
1143
|
-
ctx[property] = this._applyPatternGradientTransformText(filler);
|
|
1144
|
-
return { offsetX: offsetX, offsetY: offsetY };
|
|
1145
|
-
}
|
|
1146
|
-
else {
|
|
1147
|
-
// is a simple gradient or pattern
|
|
1148
|
-
ctx[property] = filler.toLive(ctx, this);
|
|
1149
|
-
return this._applyPatternGradientTransform(ctx, filler);
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
else {
|
|
1153
|
-
// is a color
|
|
1154
|
-
ctx[property] = filler;
|
|
1155
|
-
}
|
|
1156
|
-
return { offsetX: 0, offsetY: 0 };
|
|
1157
|
-
},
|
|
1158
|
-
|
|
1159
|
-
_setStrokeStyles: function(ctx, decl) {
|
|
1160
|
-
ctx.lineWidth = decl.strokeWidth;
|
|
1161
|
-
ctx.lineCap = this.strokeLineCap;
|
|
1162
|
-
ctx.lineDashOffset = this.strokeDashOffset;
|
|
1163
|
-
ctx.lineJoin = this.strokeLineJoin;
|
|
1164
|
-
ctx.miterLimit = this.strokeMiterLimit;
|
|
1165
|
-
return this.handleFiller(ctx, 'strokeStyle', decl.stroke);
|
|
1166
|
-
},
|
|
1167
|
-
|
|
1168
|
-
_setFillStyles: function(ctx, decl) {
|
|
1169
|
-
return this.handleFiller(ctx, 'fillStyle', decl.fill);
|
|
1170
|
-
},
|
|
1171
|
-
|
|
1172
|
-
/**
|
|
1173
|
-
* @private
|
|
1174
|
-
* @param {String} method
|
|
1175
|
-
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
1176
|
-
* @param {Number} lineIndex
|
|
1177
|
-
* @param {Number} charIndex
|
|
1178
|
-
* @param {String} _char
|
|
1179
|
-
* @param {Number} left Left coordinate
|
|
1180
|
-
* @param {Number} top Top coordinate
|
|
1181
|
-
* @param {Number} lineHeight Height of the line
|
|
1182
|
-
*/
|
|
1183
|
-
_renderChar: function(method, ctx, lineIndex, charIndex, _char, left, top) {
|
|
1184
|
-
var decl = this._getStyleDeclaration(lineIndex, charIndex),
|
|
1185
|
-
fullDecl = this.getCompleteStyleDeclaration(lineIndex, charIndex),
|
|
1186
|
-
shouldFill = method === 'fillText' && fullDecl.fill,
|
|
1187
|
-
shouldStroke = method === 'strokeText' && fullDecl.stroke && fullDecl.strokeWidth,
|
|
1188
|
-
fillOffsets, strokeOffsets;
|
|
1189
|
-
|
|
1190
|
-
if (!shouldStroke && !shouldFill) {
|
|
1191
|
-
return;
|
|
1192
|
-
}
|
|
1193
|
-
ctx.save();
|
|
1194
|
-
|
|
1195
|
-
shouldFill && (fillOffsets = this._setFillStyles(ctx, fullDecl));
|
|
1196
|
-
shouldStroke && (strokeOffsets = this._setStrokeStyles(ctx, fullDecl));
|
|
1197
|
-
|
|
1198
|
-
ctx.font = this._getFontDeclaration(fullDecl);
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
if (decl && decl.textBackgroundColor) {
|
|
1202
|
-
this._removeShadow(ctx);
|
|
1203
|
-
}
|
|
1204
|
-
if (decl && decl.deltaY) {
|
|
1205
|
-
top += decl.deltaY;
|
|
1206
|
-
}
|
|
1207
|
-
shouldFill && ctx.fillText(_char, left - fillOffsets.offsetX, top - fillOffsets.offsetY);
|
|
1208
|
-
shouldStroke && ctx.strokeText(_char, left - strokeOffsets.offsetX, top - strokeOffsets.offsetY);
|
|
1209
|
-
ctx.restore();
|
|
1210
|
-
},
|
|
1211
|
-
|
|
1212
|
-
/**
|
|
1213
|
-
* Turns the character into a 'superior figure' (i.e. 'superscript')
|
|
1214
|
-
* @param {Number} start selection start
|
|
1215
|
-
* @param {Number} end selection end
|
|
1216
|
-
* @returns {fabric.Text} thisArg
|
|
1217
|
-
* @chainable
|
|
1218
|
-
*/
|
|
1219
|
-
setSuperscript: function(start, end) {
|
|
1220
|
-
return this._setScript(start, end, this.superscript);
|
|
1221
|
-
},
|
|
1222
|
-
|
|
1223
|
-
/**
|
|
1224
|
-
* Turns the character into an 'inferior figure' (i.e. 'subscript')
|
|
1225
|
-
* @param {Number} start selection start
|
|
1226
|
-
* @param {Number} end selection end
|
|
1227
|
-
* @returns {fabric.Text} thisArg
|
|
1228
|
-
* @chainable
|
|
1229
|
-
*/
|
|
1230
|
-
setSubscript: function(start, end) {
|
|
1231
|
-
return this._setScript(start, end, this.subscript);
|
|
1232
|
-
},
|
|
1233
|
-
|
|
1234
|
-
/**
|
|
1235
|
-
* Applies 'schema' at given position
|
|
1236
|
-
* @private
|
|
1237
|
-
* @param {Number} start selection start
|
|
1238
|
-
* @param {Number} end selection end
|
|
1239
|
-
* @param {Number} schema
|
|
1240
|
-
* @returns {fabric.Text} thisArg
|
|
1241
|
-
* @chainable
|
|
1242
|
-
*/
|
|
1243
|
-
_setScript: function(start, end, schema) {
|
|
1244
|
-
var loc = this.get2DCursorLocation(start, true),
|
|
1245
|
-
fontSize = this.getValueOfPropertyAt(loc.lineIndex, loc.charIndex, 'fontSize'),
|
|
1246
|
-
dy = this.getValueOfPropertyAt(loc.lineIndex, loc.charIndex, 'deltaY'),
|
|
1247
|
-
style = { fontSize: fontSize * schema.size, deltaY: dy + fontSize * schema.baseline };
|
|
1248
|
-
this.setSelectionStyles(style, start, end);
|
|
1249
|
-
return this;
|
|
1250
|
-
},
|
|
1251
|
-
|
|
1252
|
-
/**
|
|
1253
|
-
* @private
|
|
1254
|
-
* @param {Number} lineIndex index text line
|
|
1255
|
-
* @return {Number} Line left offset
|
|
1256
|
-
*/
|
|
1257
|
-
_getLineLeftOffset: function(lineIndex) {
|
|
1258
|
-
var lineWidth = this.getLineWidth(lineIndex),
|
|
1259
|
-
lineDiff = this.width - lineWidth, textAlign = this.textAlign, direction = this.direction,
|
|
1260
|
-
isEndOfWrapping, leftOffset = 0, isEndOfWrapping = this.isEndOfWrapping(lineIndex);
|
|
1261
|
-
if (textAlign === 'justify'
|
|
1262
|
-
|| (textAlign === 'justify-center' && !isEndOfWrapping)
|
|
1263
|
-
|| (textAlign === 'justify-right' && !isEndOfWrapping)
|
|
1264
|
-
|| (textAlign === 'justify-left' && !isEndOfWrapping)
|
|
1265
|
-
) {
|
|
1266
|
-
return 0;
|
|
1267
|
-
}
|
|
1268
|
-
if (textAlign === 'center') {
|
|
1269
|
-
leftOffset = lineDiff / 2;
|
|
1270
|
-
}
|
|
1271
|
-
if (textAlign === 'right') {
|
|
1272
|
-
leftOffset = lineDiff;
|
|
1273
|
-
}
|
|
1274
|
-
if (textAlign === 'justify-center') {
|
|
1275
|
-
leftOffset = lineDiff / 2;
|
|
1276
|
-
}
|
|
1277
|
-
if (textAlign === 'justify-right') {
|
|
1278
|
-
leftOffset = lineDiff;
|
|
1279
|
-
}
|
|
1280
|
-
if (direction === 'rtl') {
|
|
1281
|
-
leftOffset -= lineDiff;
|
|
1282
|
-
}
|
|
1283
|
-
return leftOffset;
|
|
1284
|
-
},
|
|
1285
|
-
|
|
1286
|
-
/**
|
|
1287
|
-
* @private
|
|
1288
|
-
*/
|
|
1289
|
-
_clearCache: function() {
|
|
1290
|
-
this.__lineWidths = [];
|
|
1291
|
-
this.__lineHeights = [];
|
|
1292
|
-
this.__charBounds = [];
|
|
1293
|
-
},
|
|
1294
|
-
|
|
1295
|
-
/**
|
|
1296
|
-
* @private
|
|
1297
|
-
*/
|
|
1298
|
-
_shouldClearDimensionCache: function() {
|
|
1299
|
-
var shouldClear = this._forceClearCache;
|
|
1300
|
-
shouldClear || (shouldClear = this.hasStateChanged('_dimensionAffectingProps'));
|
|
1301
|
-
if (shouldClear) {
|
|
1302
|
-
this.dirty = true;
|
|
1303
|
-
this._forceClearCache = false;
|
|
1304
|
-
}
|
|
1305
|
-
return shouldClear;
|
|
1306
|
-
},
|
|
1307
|
-
|
|
1308
|
-
/**
|
|
1309
|
-
* Measure a single line given its index. Used to calculate the initial
|
|
1310
|
-
* text bounding box. The values are calculated and stored in __lineWidths cache.
|
|
1311
|
-
* @private
|
|
1312
|
-
* @param {Number} lineIndex line number
|
|
1313
|
-
* @return {Number} Line width
|
|
1314
|
-
*/
|
|
1315
|
-
getLineWidth: function(lineIndex) {
|
|
1316
|
-
if (this.__lineWidths[lineIndex] !== undefined) {
|
|
1317
|
-
return this.__lineWidths[lineIndex];
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
var lineInfo = this.measureLine(lineIndex);
|
|
1321
|
-
var width = lineInfo.width;
|
|
1322
|
-
this.__lineWidths[lineIndex] = width;
|
|
1323
|
-
return width;
|
|
1324
|
-
},
|
|
1325
|
-
|
|
1326
|
-
_getWidthOfCharSpacing: function() {
|
|
1327
|
-
if (this.charSpacing !== 0) {
|
|
1328
|
-
return this.fontSize * this.charSpacing / 1000;
|
|
1329
|
-
}
|
|
1330
|
-
return 0;
|
|
1331
|
-
},
|
|
1332
|
-
|
|
1333
|
-
/**
|
|
1334
|
-
* Retrieves the value of property at given character position
|
|
1335
|
-
* @param {Number} lineIndex the line number
|
|
1336
|
-
* @param {Number} charIndex the character number
|
|
1337
|
-
* @param {String} property the property name
|
|
1338
|
-
* @returns the value of 'property'
|
|
1339
|
-
*/
|
|
1340
|
-
getValueOfPropertyAt: function(lineIndex, charIndex, property) {
|
|
1341
|
-
var charStyle = this._getStyleDeclaration(lineIndex, charIndex);
|
|
1342
|
-
if (charStyle && typeof charStyle[property] !== 'undefined') {
|
|
1343
|
-
return charStyle[property];
|
|
1344
|
-
}
|
|
1345
|
-
return this[property];
|
|
1346
|
-
},
|
|
1347
|
-
|
|
1348
|
-
/**
|
|
1349
|
-
* @private
|
|
1350
|
-
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
1351
|
-
*/
|
|
1352
|
-
_renderTextDecoration: function(ctx, type) {
|
|
1353
|
-
if (!this[type] && !this.styleHas(type)) {
|
|
1354
|
-
return;
|
|
1355
|
-
}
|
|
1356
|
-
var heightOfLine, size, _size,
|
|
1357
|
-
lineLeftOffset, dy, _dy,
|
|
1358
|
-
line, lastDecoration,
|
|
1359
|
-
leftOffset = this._getLeftOffset(),
|
|
1360
|
-
topOffset = this._getTopOffset(), top,
|
|
1361
|
-
boxStart, boxWidth, charBox, currentDecoration,
|
|
1362
|
-
maxHeight, currentFill, lastFill, path = this.path,
|
|
1363
|
-
charSpacing = this._getWidthOfCharSpacing(),
|
|
1364
|
-
offsetY = this.offsets[type];
|
|
1365
|
-
|
|
1366
|
-
for (var i = 0, len = this._textLines.length; i < len; i++) {
|
|
1367
|
-
heightOfLine = this.getHeightOfLine(i);
|
|
1368
|
-
if (!this[type] && !this.styleHas(type, i)) {
|
|
1369
|
-
topOffset += heightOfLine;
|
|
1370
|
-
continue;
|
|
1371
|
-
}
|
|
1372
|
-
line = this._textLines[i];
|
|
1373
|
-
maxHeight = heightOfLine / this.lineHeight;
|
|
1374
|
-
lineLeftOffset = this._getLineLeftOffset(i);
|
|
1375
|
-
boxStart = 0;
|
|
1376
|
-
boxWidth = 0;
|
|
1377
|
-
lastDecoration = this.getValueOfPropertyAt(i, 0, type);
|
|
1378
|
-
lastFill = this.getValueOfPropertyAt(i, 0, 'fill');
|
|
1379
|
-
top = topOffset + maxHeight * (1 - this._fontSizeFraction);
|
|
1380
|
-
size = this.getHeightOfChar(i, 0);
|
|
1381
|
-
dy = this.getValueOfPropertyAt(i, 0, 'deltaY');
|
|
1382
|
-
for (var j = 0, jlen = line.length; j < jlen; j++) {
|
|
1383
|
-
charBox = this.__charBounds[i][j];
|
|
1384
|
-
currentDecoration = this.getValueOfPropertyAt(i, j, type);
|
|
1385
|
-
currentFill = this.getValueOfPropertyAt(i, j, 'fill');
|
|
1386
|
-
_size = this.getHeightOfChar(i, j);
|
|
1387
|
-
_dy = this.getValueOfPropertyAt(i, j, 'deltaY');
|
|
1388
|
-
if (path && currentDecoration && currentFill) {
|
|
1389
|
-
ctx.save();
|
|
1390
|
-
ctx.fillStyle = lastFill;
|
|
1391
|
-
ctx.translate(charBox.renderLeft, charBox.renderTop);
|
|
1392
|
-
ctx.rotate(charBox.angle);
|
|
1393
|
-
ctx.fillRect(
|
|
1394
|
-
-charBox.kernedWidth / 2,
|
|
1395
|
-
offsetY * _size + _dy,
|
|
1396
|
-
charBox.kernedWidth,
|
|
1397
|
-
this.fontSize / 15
|
|
1398
|
-
);
|
|
1399
|
-
ctx.restore();
|
|
1400
|
-
}
|
|
1401
|
-
else if (
|
|
1402
|
-
(currentDecoration !== lastDecoration || currentFill !== lastFill || _size !== size || _dy !== dy)
|
|
1403
|
-
&& boxWidth > 0
|
|
1404
|
-
) {
|
|
1405
|
-
var drawStart = leftOffset + lineLeftOffset + boxStart;
|
|
1406
|
-
if (this.direction === 'rtl') {
|
|
1407
|
-
drawStart = this.width - drawStart - boxWidth;
|
|
1408
|
-
}
|
|
1409
|
-
if (lastDecoration && lastFill) {
|
|
1410
|
-
ctx.fillStyle = lastFill;
|
|
1411
|
-
ctx.fillRect(
|
|
1412
|
-
drawStart,
|
|
1413
|
-
top + offsetY * size + dy,
|
|
1414
|
-
boxWidth,
|
|
1415
|
-
this.fontSize / 15
|
|
1416
|
-
);
|
|
1417
|
-
}
|
|
1418
|
-
boxStart = charBox.left;
|
|
1419
|
-
boxWidth = charBox.width;
|
|
1420
|
-
lastDecoration = currentDecoration;
|
|
1421
|
-
lastFill = currentFill;
|
|
1422
|
-
size = _size;
|
|
1423
|
-
dy = _dy;
|
|
1424
|
-
}
|
|
1425
|
-
else {
|
|
1426
|
-
boxWidth += charBox.kernedWidth;
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
var drawStart = leftOffset + lineLeftOffset + boxStart;
|
|
1430
|
-
if (this.direction === 'rtl') {
|
|
1431
|
-
drawStart = this.width - drawStart - boxWidth;
|
|
1432
|
-
}
|
|
1433
|
-
ctx.fillStyle = currentFill;
|
|
1434
|
-
currentDecoration && currentFill && ctx.fillRect(
|
|
1435
|
-
drawStart,
|
|
1436
|
-
top + offsetY * size + dy,
|
|
1437
|
-
boxWidth - charSpacing,
|
|
1438
|
-
this.fontSize / 15
|
|
1439
|
-
);
|
|
1440
|
-
topOffset += heightOfLine;
|
|
1441
|
-
}
|
|
1442
|
-
// if there is text background color no
|
|
1443
|
-
// other shadows should be casted
|
|
1444
|
-
this._removeShadow(ctx);
|
|
1445
|
-
},
|
|
1446
|
-
|
|
1447
|
-
/**
|
|
1448
|
-
* return font declaration string for canvas context
|
|
1449
|
-
* @param {Object} [styleObject] object
|
|
1450
|
-
* @returns {String} font declaration formatted for canvas context.
|
|
1451
|
-
*/
|
|
1452
|
-
_getFontDeclaration: function(styleObject, forMeasuring) {
|
|
1453
|
-
var style = styleObject || this, family = this.fontFamily,
|
|
1454
|
-
fontIsGeneric = fabric.Text.genericFonts.indexOf(family.toLowerCase()) > -1;
|
|
1455
|
-
var fontFamily = family === undefined ||
|
|
1456
|
-
family.indexOf('\'') > -1 || family.indexOf(',') > -1 ||
|
|
1457
|
-
family.indexOf('"') > -1 || fontIsGeneric
|
|
1458
|
-
? style.fontFamily : '"' + style.fontFamily + '"';
|
|
1459
|
-
return [
|
|
1460
|
-
// node-canvas needs "weight style", while browsers need "style weight"
|
|
1461
|
-
// verify if this can be fixed in JSDOM
|
|
1462
|
-
(fabric.isLikelyNode ? style.fontWeight : style.fontStyle),
|
|
1463
|
-
(fabric.isLikelyNode ? style.fontStyle : style.fontWeight),
|
|
1464
|
-
forMeasuring ? this.CACHE_FONT_SIZE + 'px' : style.fontSize + 'px',
|
|
1465
|
-
fontFamily
|
|
1466
|
-
].join(' ');
|
|
1467
|
-
},
|
|
1468
|
-
|
|
1469
|
-
/**
|
|
1470
|
-
* Renders text instance on a specified context
|
|
1471
|
-
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
1472
|
-
*/
|
|
1473
|
-
render: function(ctx) {
|
|
1474
|
-
// do not render if object is not visible
|
|
1475
|
-
if (!this.visible) {
|
|
1476
|
-
return;
|
|
1477
|
-
}
|
|
1478
|
-
if (this.canvas && this.canvas.skipOffscreen && !this.group && !this.isOnScreen()) {
|
|
1479
|
-
return;
|
|
1480
|
-
}
|
|
1481
|
-
if (this._shouldClearDimensionCache()) {
|
|
1482
|
-
this.initDimensions();
|
|
1483
|
-
}
|
|
1484
|
-
this.callSuper('render', ctx);
|
|
1485
|
-
},
|
|
1486
|
-
|
|
1487
|
-
/**
|
|
1488
|
-
* Returns the text as an array of lines.
|
|
1489
|
-
* @param {String} text text to split
|
|
1490
|
-
* @returns {Array} Lines in the text
|
|
1491
|
-
*/
|
|
1492
|
-
_splitTextIntoLines: function(text) {
|
|
1493
|
-
var lines = text.split(this._reNewline),
|
|
1494
|
-
newLines = new Array(lines.length),
|
|
1495
|
-
newLine = ['\n'],
|
|
1496
|
-
newText = [];
|
|
1497
|
-
for (var i = 0; i < lines.length; i++) {
|
|
1498
|
-
newLines[i] = fabric.util.string.graphemeSplit(lines[i]);
|
|
1499
|
-
newText = newText.concat(newLines[i], newLine);
|
|
1500
|
-
}
|
|
1501
|
-
newText.pop();
|
|
1502
|
-
return { _unwrappedLines: newLines, lines: lines, graphemeText: newText, graphemeLines: newLines };
|
|
1503
|
-
},
|
|
1504
|
-
|
|
1505
|
-
/**
|
|
1506
|
-
* Returns object representation of an instance
|
|
1507
|
-
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
|
|
1508
|
-
* @return {Object} Object representation of an instance
|
|
1509
|
-
*/
|
|
1510
|
-
toObject: function(propertiesToInclude) {
|
|
1511
|
-
var allProperties = additionalProps.concat(propertiesToInclude);
|
|
1512
|
-
var obj = this.callSuper('toObject', allProperties);
|
|
1513
|
-
obj.styles = fabric.util.stylesToArray(this.styles, this.text);
|
|
1514
|
-
if (obj.path) {
|
|
1515
|
-
obj.path = this.path.toObject();
|
|
1516
|
-
}
|
|
1517
|
-
return obj;
|
|
1518
|
-
},
|
|
1519
|
-
|
|
1520
|
-
/**
|
|
1521
|
-
* Sets property to a given value. When changing position/dimension -related properties (left, top, scale, angle, etc.) `set` does not update position of object's borders/controls. If you need to update those, call `setCoords()`.
|
|
1522
|
-
* @param {String|Object} key Property name or object (if object, iterate over the object properties)
|
|
1523
|
-
* @param {Object|Function} value Property value (if function, the value is passed into it and its return value is used as a new one)
|
|
1524
|
-
* @return {fabric.Object} thisArg
|
|
1525
|
-
* @chainable
|
|
1526
|
-
*/
|
|
1527
|
-
set: function(key, value) {
|
|
1528
|
-
this.callSuper('set', key, value);
|
|
1529
|
-
var needsDims = false;
|
|
1530
|
-
var isAddingPath = false;
|
|
1531
|
-
if (typeof key === 'object') {
|
|
1532
|
-
for (var _key in key) {
|
|
1533
|
-
if (_key === 'path') {
|
|
1534
|
-
this.setPathInfo();
|
|
1535
|
-
}
|
|
1536
|
-
needsDims = needsDims || this._dimensionAffectingProps.indexOf(_key) !== -1;
|
|
1537
|
-
isAddingPath = isAddingPath || _key === 'path';
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
else {
|
|
1541
|
-
needsDims = this._dimensionAffectingProps.indexOf(key) !== -1;
|
|
1542
|
-
isAddingPath = key === 'path';
|
|
1543
|
-
}
|
|
1544
|
-
if (isAddingPath) {
|
|
1545
|
-
this.setPathInfo();
|
|
1546
|
-
}
|
|
1547
|
-
if (needsDims) {
|
|
1548
|
-
this.initDimensions();
|
|
1549
|
-
this.setCoords();
|
|
1550
|
-
}
|
|
1551
|
-
return this;
|
|
1552
|
-
},
|
|
1553
|
-
|
|
1554
|
-
/**
|
|
1555
|
-
* Returns complexity of an instance
|
|
1556
|
-
* @return {Number} complexity
|
|
1557
|
-
*/
|
|
1558
|
-
complexity: function() {
|
|
1559
|
-
return 1;
|
|
1560
|
-
}
|
|
1561
|
-
});
|
|
1562
|
-
|
|
1563
|
-
/* _FROM_SVG_START_ */
|
|
1564
|
-
/**
|
|
1565
|
-
* List of attribute names to account for when parsing SVG element (used by {@link fabric.Text.fromElement})
|
|
1566
|
-
* @static
|
|
1567
|
-
* @memberOf fabric.Text
|
|
1568
|
-
* @see: http://www.w3.org/TR/SVG/text.html#TextElement
|
|
1569
|
-
*/
|
|
1570
|
-
fabric.Text.ATTRIBUTE_NAMES = fabric.SHARED_ATTRIBUTES.concat(
|
|
1571
|
-
'x y dx dy font-family font-style font-weight font-size letter-spacing text-decoration text-anchor'.split(' '));
|
|
1572
|
-
|
|
1573
|
-
/**
|
|
1574
|
-
* Default SVG font size
|
|
1575
|
-
* @static
|
|
1576
|
-
* @memberOf fabric.Text
|
|
1577
|
-
*/
|
|
1578
|
-
fabric.Text.DEFAULT_SVG_FONT_SIZE = 16;
|
|
1579
|
-
|
|
1580
|
-
/**
|
|
1581
|
-
* Returns fabric.Text instance from an SVG element (<b>not yet implemented</b>)
|
|
1582
|
-
* @static
|
|
1583
|
-
* @memberOf fabric.Text
|
|
1584
|
-
* @param {SVGElement} element Element to parse
|
|
1585
|
-
* @param {Function} callback callback function invoked after parsing
|
|
1586
|
-
* @param {Object} [options] Options object
|
|
1587
|
-
*/
|
|
1588
|
-
fabric.Text.fromElement = function(element, callback, options) {
|
|
1589
|
-
if (!element) {
|
|
1590
|
-
return callback(null);
|
|
1591
|
-
}
|
|
1592
|
-
|
|
1593
|
-
var parsedAttributes = fabric.parseAttributes(element, fabric.Text.ATTRIBUTE_NAMES),
|
|
1594
|
-
parsedAnchor = parsedAttributes.textAnchor || 'left';
|
|
1595
|
-
options = fabric.util.object.extend((options ? clone(options) : { }), parsedAttributes);
|
|
1596
|
-
|
|
1597
|
-
options.top = options.top || 0;
|
|
1598
|
-
options.left = options.left || 0;
|
|
1599
|
-
if (parsedAttributes.textDecoration) {
|
|
1600
|
-
var textDecoration = parsedAttributes.textDecoration;
|
|
1601
|
-
if (textDecoration.indexOf('underline') !== -1) {
|
|
1602
|
-
options.underline = true;
|
|
1603
|
-
}
|
|
1604
|
-
if (textDecoration.indexOf('overline') !== -1) {
|
|
1605
|
-
options.overline = true;
|
|
1606
|
-
}
|
|
1607
|
-
if (textDecoration.indexOf('line-through') !== -1) {
|
|
1608
|
-
options.linethrough = true;
|
|
1609
|
-
}
|
|
1610
|
-
delete options.textDecoration;
|
|
1611
|
-
}
|
|
1612
|
-
if ('dx' in parsedAttributes) {
|
|
1613
|
-
options.left += parsedAttributes.dx;
|
|
1614
|
-
}
|
|
1615
|
-
if ('dy' in parsedAttributes) {
|
|
1616
|
-
options.top += parsedAttributes.dy;
|
|
1617
|
-
}
|
|
1618
|
-
if (!('fontSize' in options)) {
|
|
1619
|
-
options.fontSize = fabric.Text.DEFAULT_SVG_FONT_SIZE;
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
var textContent = '';
|
|
1623
|
-
|
|
1624
|
-
// The XML is not properly parsed in IE9 so a workaround to get
|
|
1625
|
-
// textContent is through firstChild.data. Another workaround would be
|
|
1626
|
-
// to convert XML loaded from a file to be converted using DOMParser (same way loadSVGFromString() does)
|
|
1627
|
-
if (!('textContent' in element)) {
|
|
1628
|
-
if ('firstChild' in element && element.firstChild !== null) {
|
|
1629
|
-
if ('data' in element.firstChild && element.firstChild.data !== null) {
|
|
1630
|
-
textContent = element.firstChild.data;
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
else {
|
|
1635
|
-
textContent = element.textContent;
|
|
1636
|
-
}
|
|
1637
|
-
|
|
1638
|
-
textContent = textContent.replace(/^\s+|\s+$|\n+/g, '').replace(/\s+/g, ' ');
|
|
1639
|
-
var originalStrokeWidth = options.strokeWidth;
|
|
1640
|
-
options.strokeWidth = 0;
|
|
1641
|
-
|
|
1642
|
-
var text = new fabric.Text(textContent, options),
|
|
1643
|
-
textHeightScaleFactor = text.getScaledHeight() / text.height,
|
|
1644
|
-
lineHeightDiff = (text.height + text.strokeWidth) * text.lineHeight - text.height,
|
|
1645
|
-
scaledDiff = lineHeightDiff * textHeightScaleFactor,
|
|
1646
|
-
textHeight = text.getScaledHeight() + scaledDiff,
|
|
1647
|
-
offX = 0;
|
|
1648
|
-
/*
|
|
1649
|
-
Adjust positioning:
|
|
1650
|
-
x/y attributes in SVG correspond to the bottom-left corner of text bounding box
|
|
1651
|
-
fabric output by default at top, left.
|
|
1652
|
-
*/
|
|
1653
|
-
if (parsedAnchor === 'center') {
|
|
1654
|
-
offX = text.getScaledWidth() / 2;
|
|
1655
|
-
}
|
|
1656
|
-
if (parsedAnchor === 'right') {
|
|
1657
|
-
offX = text.getScaledWidth();
|
|
1658
|
-
}
|
|
1659
|
-
text.set({
|
|
1660
|
-
left: text.left - offX,
|
|
1661
|
-
top: text.top - (textHeight - text.fontSize * (0.07 + text._fontSizeFraction)) / text.lineHeight,
|
|
1662
|
-
strokeWidth: typeof originalStrokeWidth !== 'undefined' ? originalStrokeWidth : 1,
|
|
1663
|
-
});
|
|
1664
|
-
callback(text);
|
|
1665
|
-
};
|
|
1666
|
-
/* _FROM_SVG_END_ */
|
|
1667
|
-
|
|
1668
|
-
/**
|
|
1669
|
-
* Returns fabric.Text instance from an object representation
|
|
1670
|
-
* @static
|
|
1671
|
-
* @memberOf fabric.Text
|
|
1672
|
-
* @param {Object} object plain js Object to create an instance from
|
|
1673
|
-
* @param {Function} [callback] Callback to invoke when an fabric.Text instance is created
|
|
1674
|
-
*/
|
|
1675
|
-
fabric.Text.fromObject = function(object, callback) {
|
|
1676
|
-
var objectCopy = clone(object), path = object.path;
|
|
1677
|
-
delete objectCopy.path;
|
|
1678
|
-
return fabric.Object._fromObject('Text', objectCopy, function(textInstance) {
|
|
1679
|
-
textInstance.styles = fabric.util.stylesFromArray(object.styles, object.text);
|
|
1680
|
-
if (path) {
|
|
1681
|
-
fabric.Object._fromObject('Path', path, function(pathInstance) {
|
|
1682
|
-
textInstance.set('path', pathInstance);
|
|
1683
|
-
callback(textInstance);
|
|
1684
|
-
}, 'path');
|
|
1685
|
-
}
|
|
1686
|
-
else {
|
|
1687
|
-
callback(textInstance);
|
|
1688
|
-
}
|
|
1689
|
-
}, 'text');
|
|
1690
|
-
};
|
|
1691
|
-
|
|
1692
|
-
fabric.Text.genericFonts = ['sans-serif', 'serif', 'cursive', 'fantasy', 'monospace'];
|
|
1693
|
-
|
|
1694
|
-
fabric.util.createAccessors && fabric.util.createAccessors(fabric.Text);
|
|
1695
|
-
|
|
1696
|
-
})(typeof exports !== 'undefined' ? exports : this);
|