Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fabric 3.1.0 #5733

Merged
merged 1 commit into from
Jun 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [3.1.0]
- Fix: unbreak IE10. [#5678](https://github.com/fabricjs/fabric.js/pull/5678)
- Improvement: Support scientific notation with uppercase E. [#5731](https://github.com/fabricjs/fabric.js/pull/5731)
- Add: PencilBrush brush now support `decimate` property to remove dots that are too near to each other. [#5718](https://github.com/fabricjs/fabric.js/pull/5718)

## [3.0.0]
- Breaking: removed support for node 4 and 6. [#5356](https://github.com/fabricjs/fabric.js/pull/5356)
- Breaking: changed objectCaching meaning to disable caching only if possible. [#5566](https://github.com/fabricjs/fabric.js/pull/5566)
Expand Down
2 changes: 1 addition & 1 deletion HEADER.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */

var fabric = fabric || { version: '3.0.0' };
var fabric = fabric || { version: '3.1.0' };
if (typeof exports !== 'undefined') {
exports.fabric = fabric;
}
Expand Down
78 changes: 55 additions & 23 deletions dist/fabric.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* build: `node build.js modules=ALL exclude=gestures,accessors requirejs minifier=uglifyjs` */
/*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */

var fabric = fabric || { version: '3.0.0' };
var fabric = fabric || { version: '3.1.0' };
if (typeof exports !== 'undefined') {
exports.fabric = fabric;
}
Expand All @@ -11,7 +11,7 @@ else if (typeof define === 'function' && define.amd) {
}
/* _AMD_END_ */
if (typeof document !== 'undefined' && typeof window !== 'undefined') {
if (document instanceof HTMLDocument) {
if (document instanceof (typeof HTMLDocument !== 'undefined' ? HTMLDocument : Document)) {
fabric.document = document;
}
else {
Expand Down Expand Up @@ -73,7 +73,7 @@ fabric.SHARED_ATTRIBUTES = [
* Pixel per Inch as a default value set to 96. Can be changed for more realistic conversion.
*/
fabric.DPI = 96;
fabric.reNum = '(?:[-+]?(?:\\d+|\\d*\\.\\d+)(?:e[-+]?\\d+)?)';
fabric.reNum = '(?:[-+]?(?:\\d+|\\d*\\.\\d+)(?:[eE][-+]?\\d+)?)';
fabric.fontPaths = { };
fabric.iMatrix = [1, 0, 0, 1, 0, 0];

Expand Down Expand Up @@ -8598,6 +8598,11 @@ fabric.BaseBrush = fabric.util.createClass(/** @lends fabric.BaseBrush.prototype
ctx.shadowOffsetY = this.shadow.offsetY * zoom;
},

needsFullRender: function() {
var color = new fabric.Color(this.color);
return color.getAlpha() < 1 || !!this.shadow;
},

/**
* Removes brush shadow styles
* @private
Expand All @@ -8612,14 +8617,20 @@ fabric.BaseBrush = fabric.util.createClass(/** @lends fabric.BaseBrush.prototype


(function() {

/**
* PencilBrush class
* @class fabric.PencilBrush
* @extends fabric.BaseBrush
*/
fabric.PencilBrush = fabric.util.createClass(fabric.BaseBrush, /** @lends fabric.PencilBrush.prototype */ {

/**
* Discard points that are less than `decimate` pixel distant from each other
* @type Number
* @default 0.4
*/
decimate: 0.4,

/**
* Constructor
* @param {fabric.Canvas} canvas
Expand Down Expand Up @@ -8658,7 +8669,7 @@ fabric.BaseBrush = fabric.util.createClass(/** @lends fabric.BaseBrush.prototype
*/
onMouseMove: function(pointer) {
if (this._captureDrawingPath(pointer) && this._points.length > 1) {
if (this.needsFullRender) {
if (this.needsFullRender()) {
// redraw curve
// clear top canvas
this.canvas.clearContext(this.canvas.contextTop);
Expand Down Expand Up @@ -8719,8 +8730,6 @@ fabric.BaseBrush = fabric.util.createClass(/** @lends fabric.BaseBrush.prototype
_reset: function() {
this._points.length = 0;
this._setBrushStyles();
var color = new fabric.Color(this.color);
this.needsFullRender = (color.getAlpha() < 1);
this._setShadow();
},

Expand Down Expand Up @@ -8781,7 +8790,7 @@ fabric.BaseBrush = fabric.util.createClass(/** @lends fabric.BaseBrush.prototype
var path = [], i, width = this.width / 1000,
p1 = new fabric.Point(points[0].x, points[0].y),
p2 = new fabric.Point(points[1].x, points[1].y),
len = points.length, multSignX = 1, multSignY = 1, manyPoints = len > 2;
len = points.length, multSignX = 1, multSignY = 0, manyPoints = len > 2;

if (manyPoints) {
multSignX = points[2].x < p2.x ? -1 : points[2].x === p2.x ? 0 : 1;
Expand Down Expand Up @@ -8824,10 +8833,6 @@ fabric.BaseBrush = fabric.util.createClass(/** @lends fabric.BaseBrush.prototype
strokeLineJoin: this.strokeLineJoin,
strokeDashArray: this.strokeDashArray,
});
var position = new fabric.Point(path.left + path.width / 2, path.top + path.height / 2);
position = path.translateToGivenOrigin(position, 'center', 'center', path.originX, path.originY);
path.top = position.y;
path.left = position.x;
if (this.shadow) {
this.shadow.affectStroke = true;
path.setShadow(this.shadow);
Expand All @@ -8836,6 +8841,26 @@ fabric.BaseBrush = fabric.util.createClass(/** @lends fabric.BaseBrush.prototype
return path;
},

/**
* Decimate poins array with the decimate value
*/
decimatePoints: function(points, distance) {
if (points.length <= 2) {
return points;
}
var zoom = this.canvas.getZoom(), adjustedDistance = Math.pow(distance / zoom, 2),
i, l = points.length - 1, lastPoint = points[0], newPoints = [lastPoint],
cDistance;
for (i = 1; i < l; i++) {
cDistance = Math.pow(lastPoint.x - points[i].x, 2) + Math.pow(lastPoint.y - points[i].y, 2);
if (cDistance >= adjustedDistance) {
lastPoint = points[i];
newPoints.push(lastPoint);
}
}
return newPoints;
},

/**
* On mouseup after drawing the path on contextTop canvas
* we use the points captured to create an new fabric path object
Expand All @@ -8844,7 +8869,9 @@ fabric.BaseBrush = fabric.util.createClass(/** @lends fabric.BaseBrush.prototype
_finalizeAndAddPath: function() {
var ctx = this.canvas.contextTop;
ctx.closePath();

if (this.decimate) {
this._points = this.decimatePoints(this._points, this.decimate);
}
var pathData = this.convertPointsToSVGPath(this._points).join('');
if (pathData === 'M 0 0 Q 0 0 0 0 L 0 0') {
// do not create 0 width/height paths, as they are
Expand Down Expand Up @@ -8901,13 +8928,16 @@ fabric.CircleBrush = fabric.util.createClass(fabric.BaseBrush, /** @lends fabric
var point = this.addPoint(pointer),
ctx = this.canvas.contextTop;
this._saveAndTransform(ctx);
this.dot(ctx, point);
ctx.restore();
},

dot: function(ctx, point) {
ctx.fillStyle = point.fill;
ctx.beginPath();
ctx.arc(point.x, point.y, point.radius, 0, Math.PI * 2, false);
ctx.closePath();
ctx.fill();

ctx.restore();
},

/**
Expand All @@ -8926,15 +8956,10 @@ fabric.CircleBrush = fabric.util.createClass(fabric.BaseBrush, /** @lends fabric
*/
_render: function() {
var ctx = this.canvas.contextTop, i, len,
points = this.points, point;
points = this.points;
this._saveAndTransform(ctx);
for (i = 0, len = points.length; i < len; i++) {
point = points[i];
ctx.fillStyle = point.fill;
ctx.beginPath();
ctx.arc(point.x, point.y, point.radius, 0, Math.PI * 2, false);
ctx.closePath();
ctx.fill();
this.dot(ctx, points[i]);
}
ctx.restore();
},
Expand All @@ -8944,7 +8969,14 @@ fabric.CircleBrush = fabric.util.createClass(fabric.BaseBrush, /** @lends fabric
* @param {Object} pointer
*/
onMouseMove: function(pointer) {
this.drawDot(pointer);
if (this.needsFullRender()) {
this.canvas.clearContext(this.canvas.contextTop);
this.addPoint(pointer);
this._render();
}
else {
this.drawDot(pointer);
}
},

/**
Expand Down
2 changes: 1 addition & 1 deletion dist/fabric.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "fabric",
"description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.",
"homepage": "http://fabricjs.com/",
"version": "3.0.0",
"version": "3.1.0",
"authors": "Juriy Zaytsev <kangax@gmail.com>",
"contributors": [
{
Expand Down