fabric 5.4.0-browser → 5.4.1-browser

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "fabric",
3
3
  "description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.",
4
4
  "homepage": "http://fabricjs.com/",
5
- "version": "5.4.0-browser",
5
+ "version": "5.4.1-browser",
6
6
  "author": "Juriy Zaytsev <kangax@gmail.com>",
7
7
  "contributors": [
8
8
  {
@@ -1,6 +1,9 @@
1
1
  /* _TO_SVG_START_ */
2
2
  (function() {
3
3
  var toFixed = fabric.util.toFixed,
4
+ radiansToDegrees = fabric.util.radiansToDegrees,
5
+ calcRotateMatrix = fabric.util.calcRotateMatrix,
6
+ transformPoint = fabric.util.transformPoint,
4
7
  multipleSpacesRegex = / +/g;
5
8
 
6
9
  fabric.util.object.extend(fabric.Text.prototype, /** @lends fabric.Text.prototype */ {
@@ -22,10 +25,20 @@
22
25
  * @return {String} svg representation of an instance
23
26
  */
24
27
  toSVG: function(reviver) {
25
- return this._createBaseSVGMarkup(
28
+ var textSvg = this._createBaseSVGMarkup(
26
29
  this._toSVG(),
27
30
  { reviver: reviver, noStyle: true, withShadow: true }
28
31
  );
32
+ if (this.path) {
33
+ return (
34
+ textSvg +
35
+ this._createBaseSVGMarkup(this.path._toSVG(), {
36
+ reviver: reviver,
37
+ withShadow: true,
38
+ })
39
+ );
40
+ }
41
+ return textSvg;
29
42
  },
30
43
 
31
44
  /**
@@ -91,19 +104,31 @@
91
104
  /**
92
105
  * @private
93
106
  */
94
- _createTextCharSpan: function(_char, styleDecl, left, top) {
107
+ _createTextCharSpan: function(_char, styleDecl, left, top, charBox) {
95
108
  var shouldUseWhitespace = _char !== _char.trim() || _char.match(multipleSpacesRegex),
96
109
  styleProps = this.getSvgSpanStyles(styleDecl, shouldUseWhitespace),
97
110
  fillStyles = styleProps ? 'style="' + styleProps + '"' : '',
98
111
  dy = styleDecl.deltaY, dySpan = '',
99
- NUM_FRACTION_DIGITS = fabric.Object.NUM_FRACTION_DIGITS;
112
+ NUM_FRACTION_DIGITS = fabric.Object.NUM_FRACTION_DIGITS,
113
+ angleAttr = '';
100
114
  if (dy) {
101
115
  dySpan = ' dy="' + toFixed(dy, NUM_FRACTION_DIGITS) + '" ';
102
116
  }
117
+ if (charBox.renderLeft !== undefined) {
118
+ var angle = charBox.angle;
119
+ angleAttr = ' rotate="' + toFixed(radiansToDegrees(angle), fabric.Object.NUM_FRACTION_DIGITS) + '" ';
120
+ var wBy2 = charBox.width / 2,
121
+ m = calcRotateMatrix({ angle: radiansToDegrees(angle) });
122
+ m[4] = charBox.renderLeft;
123
+ m[5] = charBox.renderTop;
124
+ var renderPoint = transformPoint({ x: -wBy2, y: 0 }, m);
125
+ left = renderPoint.x;
126
+ top = renderPoint.y;
127
+ }
103
128
  return [
104
129
  '<tspan x="', toFixed(left, NUM_FRACTION_DIGITS), '" y="',
105
130
  toFixed(top, NUM_FRACTION_DIGITS), '" ', dySpan,
106
- fillStyles, '>',
131
+ fillStyles, angleAttr, '>',
107
132
  fabric.util.string.escapeXml(_char),
108
133
  '</tspan>'
109
134
  ].join('');
@@ -123,7 +148,7 @@
123
148
 
124
149
  textTopOffset += lineHeight * (1 - this._fontSizeFraction) / this.lineHeight;
125
150
  for (var i = 0, len = line.length - 1; i <= len; i++) {
126
- timeToRender = i === len || this.charSpacing;
151
+ timeToRender = i === len || this.charSpacing || this.path;
127
152
  charsToRender += line[i];
128
153
  charBox = this.__charBounds[lineIndex][i];
129
154
  if (boxWidth === 0) {
@@ -146,7 +171,7 @@
146
171
  }
147
172
  if (timeToRender) {
148
173
  style = this._getStyleDeclaration(lineIndex, i) || { };
149
- textSpans.push(this._createTextCharSpan(charsToRender, style, textLeftOffset, textTopOffset));
174
+ textSpans.push(this._createTextCharSpan(charsToRender, style, textLeftOffset, textTopOffset, charBox));
150
175
  charsToRender = '';
151
176
  actualStyle = nextStyle;
152
177
  textLeftOffset += boxWidth;