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

build 175 #3705

Merged
merged 1 commit into from
Feb 16, 2017
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
**Version 1.7.5**

- Improvement: draw textbackgroundColor in one single pass when possible @stefanhayden [#3698](https://github.com/kangax/fabric.js/pull/3698)
- Improvement: fire selection changed event just if text is editing [#3702](https://github.com/kangax/fabric.js/pull/3702)
- Improvement: Add object property 'needsItsOwnCache' [#3703](https://github.com/kangax/fabric.js/pull/3703)
- Improvement: Skip unnecessary transform if they can be detected with a single if [#3704](https://github.com/kangax/fabric.js/pull/3704)

**Version 1.7.4**

- Fix: Moved all the touch event to passive false so that they behave as before chrome changes [#3690](https://github.com/kangax/fabric.js/pull/3690)
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: "1.7.4" };
var fabric = fabric || { version: "1.7.5" };
if (typeof exports !== 'undefined') {
exports.fabric = fabric;
}
Expand Down
2 changes: 1 addition & 1 deletion ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Remove the template from below and provide thoughtful commentary *and code sampl

<!-- BUG TEMPLATE -->
## Version
1.7.4
1.7.5

## Test Case
http://jsfiddle.net/fabricjs/Da7SP/
Expand Down
72 changes: 52 additions & 20 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=json,gestures minifier=uglifyjs` */
/*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */

var fabric = fabric || { version: "1.7.4" };
var fabric = fabric || { version: "1.7.5" };
if (typeof exports !== 'undefined') {
exports.fabric = fabric;
}
Expand Down Expand Up @@ -12338,6 +12338,16 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
*/
dirty: false,

/**
* When set to `true`, force the object to have its own cache, even if it is inside a group
* it may be needed when your object behave in a particular way on the cache and always needs
* its own isolated canvas to render correctly.
* since 1.7.5
* @type Boolean
* @default false
*/
needsItsOwnCache: false,

/**
* List of properties to consider when checking if state
* of an object is changed (fabric.Object#hasStateChanged)
Expand Down Expand Up @@ -12466,13 +12476,13 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
}
var center = fromLeft ? this._getLeftTopCoords() : this.getCenterPoint();
ctx.translate(center.x, center.y);
ctx.rotate(degreesToRadians(this.angle));
this.angle && ctx.rotate(degreesToRadians(this.angle));
ctx.scale(
this.scaleX * (this.flipX ? -1 : 1),
this.scaleY * (this.flipY ? -1 : 1)
);
ctx.transform(1, 0, Math.tan(degreesToRadians(this.skewX)), 1, 0, 0);
ctx.transform(1, Math.tan(degreesToRadians(this.skewY)), 0, 1, 0, 0);
this.skewX && ctx.transform(1, 0, Math.tan(degreesToRadians(this.skewX)), 1, 0, 0);
this.skewY && ctx.transform(1, Math.tan(degreesToRadians(this.skewY)), 0, 1, 0, 0);
},

/**
Expand Down Expand Up @@ -12679,7 +12689,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
ctx.transform.apply(ctx, this.transformMatrix);
}
this.clipTo && fabric.util.clipContext(this, ctx);
if (this.objectCaching && !this.group) {
if (this.objectCaching && (!this.group || this.needsItsOwnCache)) {
if (this.isCacheDirty(noTransform)) {
this.statefullCache && this.saveState({ propertySet: 'cacheProperties' });
this.drawObject(this._cacheContext, noTransform);
Expand Down Expand Up @@ -23402,7 +23412,9 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {
lineWidth, lineLeftOffset,
leftOffset = this._getLeftOffset(),
topOffset = this._getTopOffset(),
line, _char, style;
colorCache = '',
line, _char, style, leftCache,
topCache, widthCache, heightCache;
ctx.save();
for (var i = 0, len = this._textLines.length; i < len; i++) {
heightOfLine = this._getHeightOfLine(ctx, i);
Expand All @@ -23415,22 +23427,40 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {

lineWidth = this._getLineWidth(ctx, i);
lineLeftOffset = this._getLineLeftOffset(lineWidth);

leftCache = topCache = widthCache = heightCache = 0;
for (var j = 0, jlen = line.length; j < jlen; j++) {
style = this._getStyleDeclaration(i, j);
if (!style || !style.textBackgroundColor) {
style = this._getStyleDeclaration(i, j) || {};

if (colorCache !== style.textBackgroundColor) {
if (heightCache && widthCache) {
ctx.fillStyle = colorCache;
ctx.fillRect(leftCache, topCache, widthCache, heightCache);
}
leftCache = topCache = widthCache = heightCache = 0;
colorCache = style.textBackgroundColor || '';
}

if (!style.textBackgroundColor) {
colorCache = '';
continue;
}
_char = line[j];

ctx.fillStyle = style.textBackgroundColor;

ctx.fillRect(
leftOffset + lineLeftOffset + this._getWidthOfCharsAt(ctx, i, j),
topOffset + lineTopOffset,
this._getWidthOfChar(ctx, _char, i, j),
heightOfLine / this.lineHeight
);
if (colorCache === style.textBackgroundColor) {
colorCache = style.textBackgroundColor;
if (!leftCache) {
leftCache = leftOffset + lineLeftOffset + this._getWidthOfCharsAt(ctx, i, j);
}
topCache = topOffset + lineTopOffset;
widthCache += this._getWidthOfChar(ctx, _char, i, j);
heightCache = heightOfLine / this.lineHeight;
}
}
// if a textBackgroundColor ends on the last character of a line
if (heightCache && widthCache) {
ctx.fillStyle = colorCache;
ctx.fillRect(leftCache, topCache, widthCache, heightCache);
leftCache = topCache = widthCache = heightCache = 0;
}
lineTopOffset += heightOfLine;
}
Expand Down Expand Up @@ -24117,7 +24147,7 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {

this._tick();
this.fire('editing:entered');

this._fireSelectionChanged();
if (!this.canvas) {
return this;
}
Expand Down Expand Up @@ -24814,8 +24844,10 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
this.selectionStart = newSelection;
this.selectionEnd = newSelection;
}
this._fireSelectionChanged();
this._updateTextarea();
if (this.isEditing) {
this._fireSelectionChanged();
this._updateTextarea();
}
},

/**
Expand Down
14 changes: 7 additions & 7 deletions dist/fabric.min.js

Large diffs are not rendered by default.

Binary file modified dist/fabric.min.js.gz
Binary file not shown.
50 changes: 38 additions & 12 deletions dist/fabric.require.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var fabric = fabric || {
version: "1.7.4"
version: "1.7.5"
};

if (typeof exports !== "undefined") {
Expand Down Expand Up @@ -5963,6 +5963,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, {
statefullCache: false,
noScaleCache: true,
dirty: false,
needsItsOwnCache: false,
stateProperties: ("top left width height scaleX scaleY flipX flipY originX originY transformMatrix " + "stroke strokeWidth strokeDashArray strokeLineCap strokeLineJoin strokeMiterLimit " + "angle opacity fill fillRule globalCompositeOperation shadow clipTo visible backgroundColor " + "skewX skewY").split(" "),
cacheProperties: ("fill stroke strokeWidth strokeDashArray width height stroke strokeWidth strokeDashArray" + " strokeLineCap strokeLineJoin strokeMiterLimit fillRule backgroundColor").split(" "),
initialize: function(options) {
Expand Down Expand Up @@ -6026,10 +6027,10 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, {
}
var center = fromLeft ? this._getLeftTopCoords() : this.getCenterPoint();
ctx.translate(center.x, center.y);
ctx.rotate(degreesToRadians(this.angle));
this.angle && ctx.rotate(degreesToRadians(this.angle));
ctx.scale(this.scaleX * (this.flipX ? -1 : 1), this.scaleY * (this.flipY ? -1 : 1));
ctx.transform(1, 0, Math.tan(degreesToRadians(this.skewX)), 1, 0, 0);
ctx.transform(1, Math.tan(degreesToRadians(this.skewY)), 0, 1, 0, 0);
this.skewX && ctx.transform(1, 0, Math.tan(degreesToRadians(this.skewX)), 1, 0, 0);
this.skewY && ctx.transform(1, Math.tan(degreesToRadians(this.skewY)), 0, 1, 0, 0);
},
toObject: function(propertiesToInclude) {
var NUM_FRACTION_DIGITS = fabric.Object.NUM_FRACTION_DIGITS, object = {
Expand Down Expand Up @@ -6155,7 +6156,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, {
ctx.transform.apply(ctx, this.transformMatrix);
}
this.clipTo && fabric.util.clipContext(this, ctx);
if (this.objectCaching && !this.group) {
if (this.objectCaching && (!this.group || this.needsItsOwnCache)) {
if (this.isCacheDirty(noTransform)) {
this.statefullCache && this.saveState({
propertySet: "cacheProperties"
Expand Down Expand Up @@ -10942,7 +10943,7 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {
},
_renderTextLinesBackground: function(ctx) {
this.callSuper("_renderTextLinesBackground", ctx);
var lineTopOffset = 0, heightOfLine, lineWidth, lineLeftOffset, leftOffset = this._getLeftOffset(), topOffset = this._getTopOffset(), line, _char, style;
var lineTopOffset = 0, heightOfLine, lineWidth, lineLeftOffset, leftOffset = this._getLeftOffset(), topOffset = this._getTopOffset(), colorCache = "", line, _char, style, leftCache, topCache, widthCache, heightCache;
ctx.save();
for (var i = 0, len = this._textLines.length; i < len; i++) {
heightOfLine = this._getHeightOfLine(ctx, i);
Expand All @@ -10953,14 +10954,36 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {
}
lineWidth = this._getLineWidth(ctx, i);
lineLeftOffset = this._getLineLeftOffset(lineWidth);
leftCache = topCache = widthCache = heightCache = 0;
for (var j = 0, jlen = line.length; j < jlen; j++) {
style = this._getStyleDeclaration(i, j);
if (!style || !style.textBackgroundColor) {
style = this._getStyleDeclaration(i, j) || {};
if (colorCache !== style.textBackgroundColor) {
if (heightCache && widthCache) {
ctx.fillStyle = colorCache;
ctx.fillRect(leftCache, topCache, widthCache, heightCache);
}
leftCache = topCache = widthCache = heightCache = 0;
colorCache = style.textBackgroundColor || "";
}
if (!style.textBackgroundColor) {
colorCache = "";
continue;
}
_char = line[j];
ctx.fillStyle = style.textBackgroundColor;
ctx.fillRect(leftOffset + lineLeftOffset + this._getWidthOfCharsAt(ctx, i, j), topOffset + lineTopOffset, this._getWidthOfChar(ctx, _char, i, j), heightOfLine / this.lineHeight);
if (colorCache === style.textBackgroundColor) {
colorCache = style.textBackgroundColor;
if (!leftCache) {
leftCache = leftOffset + lineLeftOffset + this._getWidthOfCharsAt(ctx, i, j);
}
topCache = topOffset + lineTopOffset;
widthCache += this._getWidthOfChar(ctx, _char, i, j);
heightCache = heightOfLine / this.lineHeight;
}
}
if (heightCache && widthCache) {
ctx.fillStyle = colorCache;
ctx.fillRect(leftCache, topCache, widthCache, heightCache);
leftCache = topCache = widthCache = heightCache = 0;
}
lineTopOffset += heightOfLine;
}
Expand Down Expand Up @@ -11344,6 +11367,7 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {
this._textBeforeEdit = this.text;
this._tick();
this.fire("editing:entered");
this._fireSelectionChanged();
if (!this.canvas) {
return this;
}
Expand Down Expand Up @@ -11797,8 +11821,10 @@ fabric.util.object.extend(fabric.IText.prototype, {
this.selectionStart = newSelection;
this.selectionEnd = newSelection;
}
this._fireSelectionChanged();
this._updateTextarea();
if (this.isEditing) {
this._fireSelectionChanged();
this._updateTextarea();
}
},
getSelectionStartFromPointer: function(e) {
var mouseOffset = this.getLocalPointer(e), prevWidth = 0, width = 0, height = 0, charIndex = 0, newSelectionStart, line;
Expand Down
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": "1.7.4",
"version": "1.7.5",
"author": "Juriy Zaytsev <[email protected]>",
"contributors": [
{
Expand Down