fabric 2.6.0 → 2.7.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.7.0]
4
+ - Add: strokeUniform property, avoid stroke scaling with paths [#5473](https://github.com/fabricjs/fabric.js/pull/5473)
5
+ - Fix: fix bug in image setSrc [#5502](https://github.com/fabricjs/fabric.js/pull/5502)
6
+ - Add: strokeUniform import/export svg [#5527](https://github.com/fabricjs/fabric.js/pull/5527)
7
+ - Fix: GraphemeSplit and toSvg for circle [#5544](https://github.com/fabricjs/fabric.js/pull/5544)
8
+ - Improvement: support running in a XML document [#5530](https://github.com/fabricjs/fabric.js/pull/5530)
9
+
3
10
  ## [2.6.0]
4
11
  - Fix: avoid ie11 to throw on weird draw images [#5428](https://github.com/fabricjs/fabric.js/pull/5428)
5
12
  - Fix: a rare case of invisible clipPath [#5477](https://github.com/fabricjs/fabric.js/pull/5477)
package/dist/fabric.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* build: `node build.js modules=ALL exclude=gestures,accessors requirejs minifier=uglifyjs` */
2
2
  /*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */
3
3
 
4
- var fabric = fabric || { version: '2.6.0' };
4
+ var fabric = fabric || { version: '2.7.0' };
5
5
  if (typeof exports !== 'undefined') {
6
6
  exports.fabric = fabric;
7
7
  }
@@ -11,7 +11,10 @@ else if (typeof define === 'function' && define.amd) {
11
11
  }
12
12
  /* _AMD_END_ */
13
13
  if (typeof document !== 'undefined' && typeof window !== 'undefined') {
14
- fabric.document = document;
14
+ if (document instanceof HTMLDocument)
15
+ fabric.document = document;
16
+ else
17
+ fabric.document = document.implementation.createHTMLDocument("");
15
18
  fabric.window = window;
16
19
  }
17
20
  else {
@@ -56,7 +59,7 @@ fabric.SHARED_ATTRIBUTES = [
56
59
  'stroke', 'stroke-dasharray', 'stroke-linecap', 'stroke-dashoffset',
57
60
  'stroke-linejoin', 'stroke-miterlimit',
58
61
  'stroke-opacity', 'stroke-width',
59
- 'id', 'paint-order',
62
+ 'id', 'paint-order', 'vector-effect',
60
63
  'instantiated_by_use', 'clip-path'
61
64
  ];
62
65
  /* _FROM_SVG_END_ */
@@ -3411,6 +3414,7 @@ if (typeof console !== 'undefined') {
3411
3414
  opacity: 'opacity',
3412
3415
  'clip-path': 'clipPath',
3413
3416
  'clip-rule': 'clipRule',
3417
+ 'vector-effect': 'strokeUniform'
3414
3418
  },
3415
3419
 
3416
3420
  colorAttributes = {
@@ -3442,6 +3446,9 @@ if (typeof console !== 'undefined') {
3442
3446
  if ((attr === 'fill' || attr === 'stroke') && value === 'none') {
3443
3447
  value = '';
3444
3448
  }
3449
+ else if (attr === 'vector-effect') {
3450
+ value = value === 'non-scaling-stroke';
3451
+ }
3445
3452
  else if (attr === 'strokeDashArray') {
3446
3453
  if (value === 'none') {
3447
3454
  value = null;
@@ -9849,8 +9856,12 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
9849
9856
 
9850
9857
  /**
9851
9858
  * @private
9859
+ * @param {Boolean} alreadySelected true if target is already selected
9860
+ * @param {String} corner a string representing the corner ml, mr, tl ...
9861
+ * @param {Event} e Event object
9862
+ * @param {fabric.Object} [target] inserted back to help overriding. Unused
9852
9863
  */
9853
- _getActionFromCorner: function(alreadySelected, corner, e) {
9864
+ _getActionFromCorner: function(alreadySelected, corner, e /* target */) {
9854
9865
  if (!corner || !alreadySelected) {
9855
9866
  return 'drag';
9856
9867
  }
@@ -9881,7 +9892,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
9881
9892
 
9882
9893
  var pointer = this.getPointer(e),
9883
9894
  corner = target._findTargetCorner(this.getPointer(e, true)),
9884
- action = this._getActionFromCorner(alreadySelected, corner, e),
9895
+ action = this._getActionFromCorner(alreadySelected, corner, e, target),
9885
9896
  origin = this._getOriginFromCorner(target, corner);
9886
9897
 
9887
9898
  this._currentTransform = {
@@ -12957,6 +12968,18 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
12957
12968
  */
12958
12969
  noScaleCache: true,
12959
12970
 
12971
+ /**
12972
+ * When `false`, the stoke width will scale with the object.
12973
+ * When `true`, the stroke will always match the exact pixel size entered for stroke width.
12974
+ * default to false
12975
+ * @since 2.6.0
12976
+ * @type Boolean
12977
+ * @default false
12978
+ * @type Boolean
12979
+ * @default false
12980
+ */
12981
+ strokeUniform: false,
12982
+
12960
12983
  /**
12961
12984
  * When set to `true`, object's cache will be rerendered next render call.
12962
12985
  * since 1.7.0
@@ -12992,7 +13015,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
12992
13015
  'top left width height scaleX scaleY flipX flipY originX originY transformMatrix ' +
12993
13016
  'stroke strokeWidth strokeDashArray strokeLineCap strokeDashOffset strokeLineJoin strokeMiterLimit ' +
12994
13017
  'angle opacity fill globalCompositeOperation shadow clipTo visible backgroundColor ' +
12995
- 'skewX skewY fillRule paintFirst clipPath'
13018
+ 'skewX skewY fillRule paintFirst clipPath strokeUniform'
12996
13019
  ).split(' '),
12997
13020
 
12998
13021
  /**
@@ -13003,7 +13026,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
13003
13026
  * @type Array
13004
13027
  */
13005
13028
  cacheProperties: (
13006
- 'fill stroke strokeWidth strokeDashArray width height paintFirst' +
13029
+ 'fill stroke strokeWidth strokeDashArray width height paintFirst strokeUniform' +
13007
13030
  ' strokeLineCap strokeDashOffset strokeLineJoin strokeMiterLimit backgroundColor clipPath'
13008
13031
  ).split(' '),
13009
13032
 
@@ -13724,6 +13747,9 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
13724
13747
  else {
13725
13748
  alternative && alternative(ctx);
13726
13749
  }
13750
+ if (this.strokeUniform) {
13751
+ ctx.setLineDash(ctx.getLineDash().map(function(value) { return value * ctx.lineWidth; }));
13752
+ }
13727
13753
  },
13728
13754
 
13729
13755
  /**
@@ -13861,6 +13887,9 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
13861
13887
  }
13862
13888
 
13863
13889
  ctx.save();
13890
+ if (this.strokeUniform) {
13891
+ ctx.scale(1 / this.scaleX, 1 / this.scaleY);
13892
+ }
13864
13893
  this._setLineDash(ctx, this.strokeDashArray, this._renderDashedStroke);
13865
13894
  this._applyPatternGradientTransform(ctx, this.stroke);
13866
13895
  ctx.stroke();
@@ -15220,12 +15249,25 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
15220
15249
  if (typeof skewY === 'undefined') {
15221
15250
  skewY = this.skewY;
15222
15251
  }
15223
- var dimensions = this._getNonTransformedDimensions();
15224
- if (skewX === 0 && skewY === 0) {
15225
- return { x: dimensions.x * this.scaleX, y: dimensions.y * this.scaleY };
15252
+ var dimensions = this._getNonTransformedDimensions(), dimX, dimY,
15253
+ noSkew = skewX === 0 && skewY === 0;
15254
+
15255
+ if (this.strokeUniform) {
15256
+ dimX = this.width;
15257
+ dimY = this.height;
15226
15258
  }
15227
- var dimX = dimensions.x / 2, dimY = dimensions.y / 2,
15228
- points = [
15259
+ else {
15260
+ dimX = dimensions.x;
15261
+ dimY = dimensions.y;
15262
+ }
15263
+ if (noSkew) {
15264
+ return this._finalizeDiemensions(dimX * this.scaleX, dimY * this.scaleY);
15265
+ }
15266
+ else {
15267
+ dimX /= 2;
15268
+ dimY /= 2;
15269
+ }
15270
+ var points = [
15229
15271
  {
15230
15272
  x: -dimX,
15231
15273
  y: -dimY
@@ -15248,9 +15290,23 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
15248
15290
  points[i] = fabric.util.transformPoint(points[i], transformMatrix);
15249
15291
  }
15250
15292
  bbox = fabric.util.makeBoundingBoxFromPoints(points);
15251
- return { x: bbox.width, y: bbox.height };
15293
+ return this._finalizeDiemensions(bbox.width, bbox.height);
15252
15294
  },
15253
15295
 
15296
+ /*
15297
+ * Calculate object bounding boxdimensions from its properties scale, skew.
15298
+ * @param Number width width of the bbox
15299
+ * @param Number height height of the bbox
15300
+ * @private
15301
+ * @return {Object} .x finalized width dimension
15302
+ * @return {Object} .y finalized height dimension
15303
+ */
15304
+ _finalizeDiemensions: function(width, height) {
15305
+ return this.strokeUniform ?
15306
+ { x: width + this.strokeWidth, y: height + this.strokeWidth }
15307
+ :
15308
+ { x: width, y: height };
15309
+ },
15254
15310
  /*
15255
15311
  * Calculate object dimensions for controls. include padding and canvas zoom
15256
15312
  * private
@@ -15563,6 +15619,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
15563
15619
  styleInfo = noStyle ? '' : 'style="' + this.getSvgStyles() + '" ',
15564
15620
  shadowInfo = withShadow ? 'style="' + this.getSvgFilter() + '" ' : '',
15565
15621
  clipPath = this.clipPath,
15622
+ vectorEffect = this.strokeUniform ? 'vector-effect="non-scaling-stroke" ' : '',
15566
15623
  absoluteClipPath = this.clipPath && this.clipPath.absolutePositioned,
15567
15624
  commonPieces, markup = [], clipPathMarkup,
15568
15625
  // insert commons in the markup, style and svgCommons
@@ -15587,6 +15644,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
15587
15644
  );
15588
15645
  commonPieces = [
15589
15646
  styleInfo,
15647
+ vectorEffect,
15590
15648
  noStyle ? '' : this.addPaintOrder(), ' ',
15591
15649
  additionalTransform ? 'transform="' + additionalTransform + '" ' : '',
15592
15650
  ].join('');
@@ -16820,7 +16878,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
16820
16878
  '<path d="M ' + startX + ' ' + startY,
16821
16879
  ' A ' + this.radius + ' ' + this.radius,
16822
16880
  ' 0 ', +largeFlag + ' 1', ' ' + endX + ' ' + endY,
16823
- '"', 'COMMON_PARTS', ' />\n'
16881
+ '" ', 'COMMON_PARTS', ' />\n'
16824
16882
  ];
16825
16883
  }
16826
16884
  return svgString;
@@ -19479,6 +19537,15 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
19479
19537
  */
19480
19538
  strokeWidth: 0,
19481
19539
 
19540
+ /**
19541
+ * When calling {@link fabric.Image.getSrc}, return value from element src with `element.getAttribute('src')`.
19542
+ * This allows for relative urls as image src.
19543
+ * @since 2.7.0
19544
+ * @type Boolean
19545
+ * @default
19546
+ */
19547
+ srcFromAttribute: false,
19548
+
19482
19549
  /**
19483
19550
  * private
19484
19551
  * contains last value of scaleX to detect
@@ -19527,7 +19594,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
19527
19594
 
19528
19595
  /**
19529
19596
  * key used to retrieve the texture representing this image
19530
- * since 2.0.0
19597
+ * @since 2.0.0
19531
19598
  * @type String
19532
19599
  * @default
19533
19600
  */
@@ -19535,7 +19602,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
19535
19602
 
19536
19603
  /**
19537
19604
  * Image crop in pixels from original image size.
19538
- * since 2.0.0
19605
+ * @since 2.0.0
19539
19606
  * @type Number
19540
19607
  * @default
19541
19608
  */
@@ -19543,7 +19610,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
19543
19610
 
19544
19611
  /**
19545
19612
  * Image crop in pixels from original image size.
19546
- * since 2.0.0
19613
+ * @since 2.0.0
19547
19614
  * @type Number
19548
19615
  * @default
19549
19616
  */
@@ -19783,7 +19850,13 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
19783
19850
  if (element.toDataURL) {
19784
19851
  return element.toDataURL();
19785
19852
  }
19786
- return element.src;
19853
+
19854
+ if (this.srcFromAttribute) {
19855
+ return element.getAttribute('src');
19856
+ }
19857
+ else {
19858
+ return element.src;
19859
+ }
19787
19860
  }
19788
19861
  else {
19789
19862
  return this.src || '';
@@ -19802,7 +19875,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
19802
19875
  fabric.util.loadImage(src, function(img) {
19803
19876
  this.setElement(img, options);
19804
19877
  this._setWidthHeight();
19805
- callback(this);
19878
+ callback && callback(this);
19806
19879
  }, this, options && options.crossOrigin);
19807
19880
  return this;
19808
19881
  },
@@ -28663,7 +28736,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
28663
28736
  * Use this regular expression to split strings in breakable lines
28664
28737
  * @private
28665
28738
  */
28666
- _wordJoiners: /[ \t\r\u200B\u200C]/,
28739
+ _wordJoiners: /[ \t\r]/,
28667
28740
 
28668
28741
  /**
28669
28742
  * Use this boolean property in order to split strings that have no white space concept.
@@ -28722,7 +28795,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
28722
28795
  charCount++;
28723
28796
  realLineCount++;
28724
28797
  }
28725
- else if (this._reSpaceAndTab.test(textInfo.graphemeText[charCount]) && i > 0) {
28798
+ else if (!this.graphemeSplit && this._reSpaceAndTab.test(textInfo.graphemeText[charCount]) && i > 0) {
28726
28799
  // this case deals with space's that are removed from end of lines when wrapping
28727
28800
  realLineCharCount++;
28728
28801
  charCount++;
@@ -28944,7 +29017,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
28944
29017
  lineWidth += additionalSpace;
28945
29018
  }
28946
29019
 
28947
- if (!lineJustStarted) {
29020
+ if (!lineJustStarted && !splitByGrapheme) {
28948
29021
  line.push(infix);
28949
29022
  }
28950
29023
  line = line.concat(word);
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": "2.6.0",
5
+ "version": "2.7.0",
6
6
  "authors": "Juriy Zaytsev <kangax@gmail.com>",
7
7
  "contributors": [
8
8
  {