Skip to content

Commit

Permalink
Version 1.6.0-rc.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kangax committed Jul 22, 2015
1 parent 3b99fc1 commit 5d752d2
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 119 deletions.
8 changes: 4 additions & 4 deletions 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.5.0" };
var fabric = fabric || { version: "1.6.0-rc.1" };
if (typeof exports !== 'undefined') {
exports.fabric = fabric;
}
Expand Down Expand Up @@ -64,7 +64,7 @@ fabric.reNum = '(?:[-+]?(?:\\d+|\\d*\\.\\d+)(?:e[-+]?\\d+)?)';
* Device Pixel Ratio
* @see https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/HTML-canvas-guide/SettingUptheCanvas/SettingUptheCanvas.html
*/
fabric.devicePixelRatio = fabric.window.devicePixelRatio ||
fabric.window.webkitDevicePixelRatio ||
fabric.window.mozDevicePixelRatio ||
fabric.devicePixelRatio = fabric.window.devicePixelRatio ||
fabric.window.webkitDevicePixelRatio ||
fabric.window.mozDevicePixelRatio ||
1;
154 changes: 81 additions & 73 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.5.0" };
var fabric = fabric || { version: "1.6.0-rc.1" };
if (typeof exports !== 'undefined') {
exports.fabric = fabric;
}
Expand Down Expand Up @@ -65,9 +65,9 @@ fabric.reNum = '(?:[-+]?(?:\\d+|\\d*\\.\\d+)(?:e[-+]?\\d+)?)';
* Device Pixel Ratio
* @see https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/HTML-canvas-guide/SettingUptheCanvas/SettingUptheCanvas.html
*/
fabric.devicePixelRatio = fabric.window.devicePixelRatio ||
fabric.window.webkitDevicePixelRatio ||
fabric.window.mozDevicePixelRatio ||
fabric.devicePixelRatio = fabric.window.devicePixelRatio ||
fabric.window.webkitDevicePixelRatio ||
fabric.window.mozDevicePixelRatio ||
1;


Expand Down Expand Up @@ -12620,39 +12620,27 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
setCoords: function() {
var theta = degreesToRadians(this.angle),
vpt = this.getViewportTransform(),
f = function (p) {
return fabric.util.transformPoint(p, vpt);
},
p = this._calculateCurrentDimensions(false),
currentWidth = p.x, currentHeight = p.y;
dim = this._calculateCurrentDimensions(true),
currentWidth = dim.x, currentHeight = dim.y;

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

var _hypotenuse = Math.sqrt(
Math.pow(currentWidth / 2, 2) +
Math.pow(currentHeight / 2, 2)),

_angle = Math.atan(
isFinite(currentHeight / currentWidth)
? currentHeight / currentWidth
: 0),

// offset added for rotate and scale actions
var sinTh = Math.sin(theta),
cosTh = Math.cos(theta),
_angle = currentWidth > 0 ? Math.atan(currentHeight / currentWidth) : 0,
_hypotenuse = (currentWidth / Math.cos(_angle)) / 2,
offsetX = Math.cos(_angle + theta) * _hypotenuse,
offsetY = Math.sin(_angle + theta) * _hypotenuse,
sinTh = Math.sin(theta),
cosTh = Math.cos(theta),
coords = this.getCenterPoint(),
wh = new fabric.Point(currentWidth, currentHeight),
_tl = new fabric.Point(coords.x - offsetX, coords.y - offsetY),
_tr = new fabric.Point(_tl.x + (wh.x * cosTh), _tl.y + (wh.x * sinTh)),
bl = f(new fabric.Point(_tl.x - (wh.y * sinTh), _tl.y + (wh.y * cosTh))),
br = f(new fabric.Point(_tr.x - (wh.y * sinTh), _tr.y + (wh.y * cosTh))),
tl = f(_tl),
tr = f(_tr),

// offset added for rotate and scale actions
coords = fabric.util.transformPoint(this.getCenterPoint(), vpt),
tl = new fabric.Point(coords.x - offsetX, coords.y - offsetY),
tr = new fabric.Point(tl.x + (currentWidth * cosTh), tl.y + (currentWidth * sinTh)),
bl = new fabric.Point(tl.x - (currentHeight * sinTh), tl.y + (currentHeight * cosTh)),
br = new fabric.Point(coords.x + offsetX, coords.y + offsetY),
ml = new fabric.Point((tl.x + bl.x)/2, (tl.y + bl.y)/2),
mt = new fabric.Point((tr.x + tl.x)/2, (tr.y + tl.y)/2),
mr = new fabric.Point((br.x + tr.x)/2, (br.y + tr.y)/2),
Expand Down Expand Up @@ -13021,7 +13009,9 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
_setCornerCoords: function() {
var coords = this.oCoords,
newTheta = degreesToRadians(45 - this.angle),
cornerHypotenuse = Math.sqrt(2 * Math.pow(this.cornerSize, 2)) / 2,
/* Math.sqrt(2 * Math.pow(this.cornerSize, 2)) / 2, */
/* 0.707106 stands for sqrt(2)/2 */
cornerHypotenuse = this.cornerSize * 0.707106,
cosHalfOffset = cornerHypotenuse * Math.cos(newTheta),
sinHalfOffset = cornerHypotenuse * Math.sin(newTheta),
x, y;
Expand Down Expand Up @@ -19796,10 +19786,11 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
}
this._textLines = this._splitTextIntoLines();
this._clearCache();
var currentTextAlign = this.textAlign;
this.textAlign = 'left';
//if textAlign is 'justify' i have to disable caching
//when calculating width of text and widths of line.
this._cacheLinesWidth = (this.textAlign !== 'justify');
this.width = this._getTextWidth(ctx);
this.textAlign = currentTextAlign;
this._cacheLinesWidth = true;
this.height = this._getTextHeight(ctx);
},

Expand All @@ -19818,14 +19809,14 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
*/
_render: function(ctx) {
this.clipTo && fabric.util.clipContext(this, ctx);
ctx.save();
this._setOpacity(ctx);
this._setShadow(ctx);
this._setupCompositeOperation(ctx);
this._renderTextBackground(ctx);
this._setStrokeStyles(ctx);
this._setFillStyles(ctx);
this._renderText(ctx);
this._renderTextDecoration(ctx);
ctx.restore();
this.clipTo && ctx.restore();
},

Expand All @@ -19838,16 +19829,18 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
this._translateForTextAlign(ctx);
this._renderTextFill(ctx);
this._renderTextStroke(ctx);

this._translateForTextAlign(ctx, true);
},

/**
* @private
* @param {CanvasRenderingContext2D} ctx Context to render on
* @param {Boolean} back Indicates if translate back or forward
*/
_translateForTextAlign: function(ctx) {
_translateForTextAlign: function(ctx, back) {
if (this.textAlign !== 'left' && this.textAlign !== 'justify') {
ctx.translate(this.textAlign === 'center' ? (this.width / 2) : this.width, 0);
var sign = back ? -1 : 1;
ctx.translate(this.textAlign === 'center' ? (sign * this.width / 2) : sign * this.width, 0);
}
},

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

ctx.save();
ctx.fillStyle = this.backgroundColor;

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

ctx.restore();
},

/**
* @private
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_renderTextLinesBackground: function(ctx) {
var lineTopOffset = 0, heightOfLine = this._getHeightOfLine();
if (!this.textBackgroundColor) {
return;
}
var lineTopOffset = 0, heightOfLine = this._getHeightOfLine(),
lineWidth, lineLeftOffset;

ctx.save();
ctx.fillStyle = this.textBackgroundColor;

for (var i = 0, len = this._textLines.length; i < len; i++) {

if (this._textLines[i] !== '') {

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

lineWidth = this._getLineWidth(ctx, i);
lineLeftOffset = this._getLineLeftOffset(lineWidth);
ctx.fillRect(
this._getLeftOffset() + lineLeftOffset,
this._getTopOffset() + lineTopOffset,
Expand All @@ -20113,7 +20100,6 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
}
lineTopOffset += heightOfLine;
}
ctx.restore();
},

/**
Expand Down Expand Up @@ -20161,14 +20147,32 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
/**
* @private
* @param {CanvasRenderingContext2D} ctx Context to render on
* @param {Number} lineIndex line number
* @return {Number} Line width
*/
_getLineWidth: function(ctx, lineIndex) {
if (this.__lineWidths[lineIndex]) {
return this.__lineWidths[lineIndex];
}
this.__lineWidths[lineIndex] = ctx.measureText(this._textLines[lineIndex]).width;
return this.__lineWidths[lineIndex];
var width, wordCount, line = this._textLines[lineIndex];
if (line === '') {
width = 0;
}
else if (this.textAlign === 'justify' && this._cacheLinesWidth) {
wordCount = line.split(' ');
//consider not justify last line, not for now.
if (wordCount.length > 1) {
width = this.width;
}
else {
width = ctx.measureText(line).width;
}
}
else {
width = ctx.measureText(line).width;
}
this._cacheLinesWidth && (this.__lineWidths[lineIndex] = width);
return width;
},

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

/** @ignore */
function renderLinesAtOffset(offsets) {
var i, lineHeight = 0, len, j, oLen;
var i, lineHeight = 0, len, j, oLen, lineWidth,
lineLeftOffset, heightOfLine;

for (i = 0, len = _this._textLines.length; i < len; i++) {

var lineWidth = _this._getLineWidth(ctx, i),
lineLeftOffset = _this._getLineLeftOffset(lineWidth),
heightOfLine = _this._getHeightOfLine(ctx, i);
lineWidth = _this._getLineWidth(ctx, i),
lineLeftOffset = _this._getLineLeftOffset(lineWidth),
heightOfLine = _this._getHeightOfLine(ctx, i);

for (j = 0, oLen = offsets.length; j < oLen; j++) {
ctx.fillRect(
Expand All @@ -20212,7 +20218,6 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
if (this.textDecoration.indexOf('overline') > -1) {
offsets.push(-0.12);
}

if (offsets.length > 0) {
renderLinesAtOffset(offsets);
}
Expand Down Expand Up @@ -20250,8 +20255,6 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
if (!noTransform) {
this.transform(ctx);
}
this._setStrokeStyles(ctx);
this._setFillStyles(ctx);
if (this.transformMatrix) {
ctx.transform.apply(ctx, this.transformMatrix);
}
Expand Down Expand Up @@ -22716,7 +22719,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
fabric.document.body.appendChild(this.hiddenTextarea);

fabric.util.addListener(this.hiddenTextarea, 'keydown', this.onKeyDown.bind(this));
fabric.util.addListener(this.hiddenTextarea, 'keypress', this.onKeyPress.bind(this));
fabric.util.addListener(this.hiddenTextarea, 'input', this.onInput.bind(this));
fabric.util.addListener(this.hiddenTextarea, 'copy', this.copy.bind(this));
fabric.util.addListener(this.hiddenTextarea, 'paste', this.paste.bind(this));

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

/**
* Handles onInput event
* @param {Event} e Event object
*/
onInput: function(e) {
if (!this.isEditing || this._cancelOnInput) {
this._cancelOnInput = false;
return;
}
var offset = this.selectionStart || 0,
textLength = this.text.length,
newTextLength = this.hiddenTextarea.value.length,
diff = newTextLength - textLength,
charsToInsert = this.hiddenTextarea.value.slice(offset, offset + diff);
this.insertChars(charsToInsert);
e.stopPropagation();
},

/**
* Forward delete
*/
Expand Down Expand Up @@ -22835,6 +22856,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
if (copiedText) {
this.insertChars(copiedText, useCopiedStyle);
}
this._cancelOnInput = true;
},

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

/**
* Handles keypress event
* @param {Event} e Event object
*/
onKeyPress: function(e) {
if (!this.isEditing || e.metaKey || e.ctrlKey) {
return;
}
if (e.which !== 0) {
this.insertChars(String.fromCharCode(e.which));
}
e.stopPropagation();
},

/**
* Gets start offset of a selection
* @param {Event} e Event object
Expand Down
12 changes: 6 additions & 6 deletions dist/fabric.min.js

Large diffs are not rendered by default.

Binary file modified dist/fabric.min.js.gz
Binary file not shown.
Loading

0 comments on commit 5d752d2

Please sign in to comment.