Skip to content

Commit 1add80b

Browse files
committed
Version 1.6.0-rc.1
1 parent 44eb376 commit 1add80b

6 files changed

+136
-119
lines changed

HEADER.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */
22

3-
var fabric = fabric || { version: "1.5.0" };
3+
var fabric = fabric || { version: "1.6.0-rc.1" };
44
if (typeof exports !== 'undefined') {
55
exports.fabric = fabric;
66
}
@@ -64,7 +64,7 @@ fabric.reNum = '(?:[-+]?(?:\\d+|\\d*\\.\\d+)(?:e[-+]?\\d+)?)';
6464
* Device Pixel Ratio
6565
* @see https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/HTML-canvas-guide/SettingUptheCanvas/SettingUptheCanvas.html
6666
*/
67-
fabric.devicePixelRatio = fabric.window.devicePixelRatio ||
68-
fabric.window.webkitDevicePixelRatio ||
69-
fabric.window.mozDevicePixelRatio ||
67+
fabric.devicePixelRatio = fabric.window.devicePixelRatio ||
68+
fabric.window.webkitDevicePixelRatio ||
69+
fabric.window.mozDevicePixelRatio ||
7070
1;

dist/fabric.js

+81-73
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* build: `node build.js modules=ALL exclude=json,gestures minifier=uglifyjs` */
22
/*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */
33

4-
var fabric = fabric || { version: "1.5.0" };
4+
var fabric = fabric || { version: "1.6.0-rc.1" };
55
if (typeof exports !== 'undefined') {
66
exports.fabric = fabric;
77
}
@@ -65,9 +65,9 @@ fabric.reNum = '(?:[-+]?(?:\\d+|\\d*\\.\\d+)(?:e[-+]?\\d+)?)';
6565
* Device Pixel Ratio
6666
* @see https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/HTML-canvas-guide/SettingUptheCanvas/SettingUptheCanvas.html
6767
*/
68-
fabric.devicePixelRatio = fabric.window.devicePixelRatio ||
69-
fabric.window.webkitDevicePixelRatio ||
70-
fabric.window.mozDevicePixelRatio ||
68+
fabric.devicePixelRatio = fabric.window.devicePixelRatio ||
69+
fabric.window.webkitDevicePixelRatio ||
70+
fabric.window.mozDevicePixelRatio ||
7171
1;
7272

7373

@@ -12620,39 +12620,27 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
1262012620
setCoords: function() {
1262112621
var theta = degreesToRadians(this.angle),
1262212622
vpt = this.getViewportTransform(),
12623-
f = function (p) {
12624-
return fabric.util.transformPoint(p, vpt);
12625-
},
12626-
p = this._calculateCurrentDimensions(false),
12627-
currentWidth = p.x, currentHeight = p.y;
12623+
dim = this._calculateCurrentDimensions(true),
12624+
currentWidth = dim.x, currentHeight = dim.y;
1262812625

1262912626
// If width is negative, make postive. Fixes path selection issue
1263012627
if (currentWidth < 0) {
1263112628
currentWidth = Math.abs(currentWidth);
1263212629
}
1263312630

12634-
var _hypotenuse = Math.sqrt(
12635-
Math.pow(currentWidth / 2, 2) +
12636-
Math.pow(currentHeight / 2, 2)),
12637-
12638-
_angle = Math.atan(
12639-
isFinite(currentHeight / currentWidth)
12640-
? currentHeight / currentWidth
12641-
: 0),
12642-
12643-
// offset added for rotate and scale actions
12631+
var sinTh = Math.sin(theta),
12632+
cosTh = Math.cos(theta),
12633+
_angle = currentWidth > 0 ? Math.atan(currentHeight / currentWidth) : 0,
12634+
_hypotenuse = (currentWidth / Math.cos(_angle)) / 2,
1264412635
offsetX = Math.cos(_angle + theta) * _hypotenuse,
1264512636
offsetY = Math.sin(_angle + theta) * _hypotenuse,
12646-
sinTh = Math.sin(theta),
12647-
cosTh = Math.cos(theta),
12648-
coords = this.getCenterPoint(),
12649-
wh = new fabric.Point(currentWidth, currentHeight),
12650-
_tl = new fabric.Point(coords.x - offsetX, coords.y - offsetY),
12651-
_tr = new fabric.Point(_tl.x + (wh.x * cosTh), _tl.y + (wh.x * sinTh)),
12652-
bl = f(new fabric.Point(_tl.x - (wh.y * sinTh), _tl.y + (wh.y * cosTh))),
12653-
br = f(new fabric.Point(_tr.x - (wh.y * sinTh), _tr.y + (wh.y * cosTh))),
12654-
tl = f(_tl),
12655-
tr = f(_tr),
12637+
12638+
// offset added for rotate and scale actions
12639+
coords = fabric.util.transformPoint(this.getCenterPoint(), vpt),
12640+
tl = new fabric.Point(coords.x - offsetX, coords.y - offsetY),
12641+
tr = new fabric.Point(tl.x + (currentWidth * cosTh), tl.y + (currentWidth * sinTh)),
12642+
bl = new fabric.Point(tl.x - (currentHeight * sinTh), tl.y + (currentHeight * cosTh)),
12643+
br = new fabric.Point(coords.x + offsetX, coords.y + offsetY),
1265612644
ml = new fabric.Point((tl.x + bl.x)/2, (tl.y + bl.y)/2),
1265712645
mt = new fabric.Point((tr.x + tl.x)/2, (tr.y + tl.y)/2),
1265812646
mr = new fabric.Point((br.x + tr.x)/2, (br.y + tr.y)/2),
@@ -13021,7 +13009,9 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
1302113009
_setCornerCoords: function() {
1302213010
var coords = this.oCoords,
1302313011
newTheta = degreesToRadians(45 - this.angle),
13024-
cornerHypotenuse = Math.sqrt(2 * Math.pow(this.cornerSize, 2)) / 2,
13012+
/* Math.sqrt(2 * Math.pow(this.cornerSize, 2)) / 2, */
13013+
/* 0.707106 stands for sqrt(2)/2 */
13014+
cornerHypotenuse = this.cornerSize * 0.707106,
1302513015
cosHalfOffset = cornerHypotenuse * Math.cos(newTheta),
1302613016
sinHalfOffset = cornerHypotenuse * Math.sin(newTheta),
1302713017
x, y;
@@ -19796,10 +19786,11 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
1979619786
}
1979719787
this._textLines = this._splitTextIntoLines();
1979819788
this._clearCache();
19799-
var currentTextAlign = this.textAlign;
19800-
this.textAlign = 'left';
19789+
//if textAlign is 'justify' i have to disable caching
19790+
//when calculating width of text and widths of line.
19791+
this._cacheLinesWidth = (this.textAlign !== 'justify');
1980119792
this.width = this._getTextWidth(ctx);
19802-
this.textAlign = currentTextAlign;
19793+
this._cacheLinesWidth = true;
1980319794
this.height = this._getTextHeight(ctx);
1980419795
},
1980519796

@@ -19818,14 +19809,14 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
1981819809
*/
1981919810
_render: function(ctx) {
1982019811
this.clipTo && fabric.util.clipContext(this, ctx);
19821-
ctx.save();
1982219812
this._setOpacity(ctx);
1982319813
this._setShadow(ctx);
1982419814
this._setupCompositeOperation(ctx);
1982519815
this._renderTextBackground(ctx);
19816+
this._setStrokeStyles(ctx);
19817+
this._setFillStyles(ctx);
1982619818
this._renderText(ctx);
1982719819
this._renderTextDecoration(ctx);
19828-
ctx.restore();
1982919820
this.clipTo && ctx.restore();
1983019821
},
1983119822

@@ -19838,16 +19829,18 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
1983819829
this._translateForTextAlign(ctx);
1983919830
this._renderTextFill(ctx);
1984019831
this._renderTextStroke(ctx);
19841-
19832+
this._translateForTextAlign(ctx, true);
1984219833
},
1984319834

1984419835
/**
1984519836
* @private
1984619837
* @param {CanvasRenderingContext2D} ctx Context to render on
19838+
* @param {Boolean} back Indicates if translate back or forward
1984719839
*/
19848-
_translateForTextAlign: function(ctx) {
19840+
_translateForTextAlign: function(ctx, back) {
1984919841
if (this.textAlign !== 'left' && this.textAlign !== 'justify') {
19850-
ctx.translate(this.textAlign === 'center' ? (this.width / 2) : this.width, 0);
19842+
var sign = back ? -1 : 1;
19843+
ctx.translate(this.textAlign === 'center' ? (sign * this.width / 2) : sign * this.width, 0);
1985119844
}
1985219845
},
1985319846

@@ -20071,7 +20064,6 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
2007120064
return;
2007220065
}
2007320066

20074-
ctx.save();
2007520067
ctx.fillStyle = this.backgroundColor;
2007620068

2007720069
ctx.fillRect(
@@ -20081,29 +20073,24 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
2008120073
this.height
2008220074
);
2008320075

20084-
ctx.restore();
2008520076
},
2008620077

2008720078
/**
2008820079
* @private
2008920080
* @param {CanvasRenderingContext2D} ctx Context to render on
2009020081
*/
2009120082
_renderTextLinesBackground: function(ctx) {
20092-
var lineTopOffset = 0, heightOfLine = this._getHeightOfLine();
2009320083
if (!this.textBackgroundColor) {
2009420084
return;
2009520085
}
20086+
var lineTopOffset = 0, heightOfLine = this._getHeightOfLine(),
20087+
lineWidth, lineLeftOffset;
2009620088

20097-
ctx.save();
2009820089
ctx.fillStyle = this.textBackgroundColor;
20099-
2010020090
for (var i = 0, len = this._textLines.length; i < len; i++) {
20101-
2010220091
if (this._textLines[i] !== '') {
20103-
20104-
var lineWidth = this._getLineWidth(ctx, i),
20105-
lineLeftOffset = this._getLineLeftOffset(lineWidth);
20106-
20092+
lineWidth = this._getLineWidth(ctx, i);
20093+
lineLeftOffset = this._getLineLeftOffset(lineWidth);
2010720094
ctx.fillRect(
2010820095
this._getLeftOffset() + lineLeftOffset,
2010920096
this._getTopOffset() + lineTopOffset,
@@ -20113,7 +20100,6 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
2011320100
}
2011420101
lineTopOffset += heightOfLine;
2011520102
}
20116-
ctx.restore();
2011720103
},
2011820104

2011920105
/**
@@ -20161,14 +20147,32 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
2016120147
/**
2016220148
* @private
2016320149
* @param {CanvasRenderingContext2D} ctx Context to render on
20150+
* @param {Number} lineIndex line number
2016420151
* @return {Number} Line width
2016520152
*/
2016620153
_getLineWidth: function(ctx, lineIndex) {
2016720154
if (this.__lineWidths[lineIndex]) {
2016820155
return this.__lineWidths[lineIndex];
2016920156
}
20170-
this.__lineWidths[lineIndex] = ctx.measureText(this._textLines[lineIndex]).width;
20171-
return this.__lineWidths[lineIndex];
20157+
var width, wordCount, line = this._textLines[lineIndex];
20158+
if (line === '') {
20159+
width = 0;
20160+
}
20161+
else if (this.textAlign === 'justify' && this._cacheLinesWidth) {
20162+
wordCount = line.split(' ');
20163+
//consider not justify last line, not for now.
20164+
if (wordCount.length > 1) {
20165+
width = this.width;
20166+
}
20167+
else {
20168+
width = ctx.measureText(line).width;
20169+
}
20170+
}
20171+
else {
20172+
width = ctx.measureText(line).width;
20173+
}
20174+
this._cacheLinesWidth && (this.__lineWidths[lineIndex] = width);
20175+
return width;
2017220176
},
2017320177

2017420178
/**
@@ -20185,12 +20189,14 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
2018520189

2018620190
/** @ignore */
2018720191
function renderLinesAtOffset(offsets) {
20188-
var i, lineHeight = 0, len, j, oLen;
20192+
var i, lineHeight = 0, len, j, oLen, lineWidth,
20193+
lineLeftOffset, heightOfLine;
20194+
2018920195
for (i = 0, len = _this._textLines.length; i < len; i++) {
2019020196

20191-
var lineWidth = _this._getLineWidth(ctx, i),
20192-
lineLeftOffset = _this._getLineLeftOffset(lineWidth),
20193-
heightOfLine = _this._getHeightOfLine(ctx, i);
20197+
lineWidth = _this._getLineWidth(ctx, i),
20198+
lineLeftOffset = _this._getLineLeftOffset(lineWidth),
20199+
heightOfLine = _this._getHeightOfLine(ctx, i);
2019420200

2019520201
for (j = 0, oLen = offsets.length; j < oLen; j++) {
2019620202
ctx.fillRect(
@@ -20212,7 +20218,6 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
2021220218
if (this.textDecoration.indexOf('overline') > -1) {
2021320219
offsets.push(-0.12);
2021420220
}
20215-
2021620221
if (offsets.length > 0) {
2021720222
renderLinesAtOffset(offsets);
2021820223
}
@@ -20250,8 +20255,6 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
2025020255
if (!noTransform) {
2025120256
this.transform(ctx);
2025220257
}
20253-
this._setStrokeStyles(ctx);
20254-
this._setFillStyles(ctx);
2025520258
if (this.transformMatrix) {
2025620259
ctx.transform.apply(ctx, this.transformMatrix);
2025720260
}
@@ -22716,7 +22719,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
2271622719
fabric.document.body.appendChild(this.hiddenTextarea);
2271722720

2271822721
fabric.util.addListener(this.hiddenTextarea, 'keydown', this.onKeyDown.bind(this));
22719-
fabric.util.addListener(this.hiddenTextarea, 'keypress', this.onKeyPress.bind(this));
22722+
fabric.util.addListener(this.hiddenTextarea, 'input', this.onInput.bind(this));
2272022723
fabric.util.addListener(this.hiddenTextarea, 'copy', this.copy.bind(this));
2272122724
fabric.util.addListener(this.hiddenTextarea, 'paste', this.paste.bind(this));
2272222725

@@ -22780,6 +22783,24 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
2278022783
this.canvas && this.canvas.renderAll();
2278122784
},
2278222785

22786+
/**
22787+
* Handles onInput event
22788+
* @param {Event} e Event object
22789+
*/
22790+
onInput: function(e) {
22791+
if (!this.isEditing || this._cancelOnInput) {
22792+
this._cancelOnInput = false;
22793+
return;
22794+
}
22795+
var offset = this.selectionStart || 0,
22796+
textLength = this.text.length,
22797+
newTextLength = this.hiddenTextarea.value.length,
22798+
diff = newTextLength - textLength,
22799+
charsToInsert = this.hiddenTextarea.value.slice(offset, offset + diff);
22800+
this.insertChars(charsToInsert);
22801+
e.stopPropagation();
22802+
},
22803+
2278322804
/**
2278422805
* Forward delete
2278522806
*/
@@ -22835,6 +22856,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
2283522856
if (copiedText) {
2283622857
this.insertChars(copiedText, useCopiedStyle);
2283722858
}
22859+
this._cancelOnInput = true;
2283822860
},
2283922861

2284022862
/**
@@ -22859,20 +22881,6 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
2285922881
return e && (e.clipboardData || fabric.window.clipboardData);
2286022882
},
2286122883

22862-
/**
22863-
* Handles keypress event
22864-
* @param {Event} e Event object
22865-
*/
22866-
onKeyPress: function(e) {
22867-
if (!this.isEditing || e.metaKey || e.ctrlKey) {
22868-
return;
22869-
}
22870-
if (e.which !== 0) {
22871-
this.insertChars(String.fromCharCode(e.which));
22872-
}
22873-
e.stopPropagation();
22874-
},
22875-
2287622884
/**
2287722885
* Gets start offset of a selection
2287822886
* @param {Event} e Event object

dist/fabric.min.js

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/fabric.min.js.gz

66 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)