=this.text.length&&this.selectionEnd>=this.text.length)return;this.abortCursorAnimation(),this._currentCursorOpacity=1,e.shiftKey?this.moveCursorRightWithShift(e):this.moveCursorRightWithoutShift(e),this.initDelayedCursor()},moveCursorRightWithShift:function(e){this._selectionDirection==="left"&&this.selectionStart!==this.selectionEnd?this._moveRight(e,"selectionStart"):(this._selectionDirection="right",this._moveRight(e,"selectionEnd"),this.text.charAt(this.selectionEnd-1)==="\n"&&this.selectionEnd++,this.selectionEnd>this.text.length&&(this.selectionEnd=this.text.length))},moveCursorRightWithoutShift:function(e){this._selectionDirection="right",this.selectionStart===this.selectionEnd?(this._moveRight(e,"selectionStart"),this.selectionEnd=this.selectionStart):(this.selectionEnd+=this.getNumNewLinesInSelectedText(),this.selectionEnd>this.text.length&&(this.selectionEnd=this.text.length),this.selectionStart=this.selectionEnd)},removeChars:function(e){this.selectionStart===this.selectionEnd?this._removeCharsNearCursor(e):this._removeCharsFromTo(this.selectionStart,this.selectionEnd),this.selectionEnd=this.selectionStart,this._removeExtraneousStyles(),this.canvas&&this.canvas.renderAll().renderAll(),this.setCoords(),this.fire("text:changed")},_removeCharsNearCursor:function(e){if(this.selectionStart!==0)if(e.metaKey){var t=this.findLineBoundaryLeft(this.selectionStart);this._removeCharsFromTo(t,this.selectionStart),this.selectionStart=t}else if(e.altKey){var n=this.findWordBoundaryLeft(this.selectionStart);this._removeCharsFromTo(n,this.selectionStart),this.selectionStart=n}else{var r=this.text.slice(this.selectionStart-1,this.selectionStart)==="\n";this.removeStyleObject(r),this.selectionStart--,this.text=this.text.slice(0,this.selectionStart)+this.text.slice(this.selectionStart+1)}}}),fabric.util.object.extend(fabric.IText.prototype,{_setSVGTextLineText:function(e,t,n,r,i,s){this.styles[t]?this._setSVGTextLineChars(e,t,n,r,i,s):this.callSuper("_setSVGTextLineText",e,t,n,r,i)},_setSVGTextLineChars:function(e,t,n,r,i,s){var o=t===0||this.useNative?"y":"dy",u=e.split(""),a=0,f=this._getSVGLineLeftOffset(t),l=this._getSVGLineTopOffset(t),c=this._getHeightOfLine(this.ctx,t);for(var h=0,p=u.length;h'].join("")},_createTextCharSpan:function(e,t,n,r,i,s){var o=this.getSvgStyles.call(fabric.util.object.extend({visible:!0,fill:this.fill,stroke:this.stroke,type:"text"},t));return['',fabric.util.string.escapeXml(e),""].join("")}}),function(){function request(e,t,n){var r=URL.parse(e);r.port||(r.port=r.protocol.indexOf("https:")===0?443:80);var i=r.port===443?HTTPS:HTTP,s=i.request({hostname:r.hostname,port:r.port,path:r.path,method:"GET"},function(e){var r="";t&&e.setEncoding(t),e.on("end",function(){n(r)}),e.on("data",function(t){e.statusCode===200&&(r+=t)})});s.on("error",function(e){e.errno===process.ECONNREFUSED?fabric.log("ECONNREFUSED: connection refused to "+r.hostname+":"+r.port):fabric.log(e.message)}),s.end()}function request_fs(e,t){var n=require("fs");n.readFile(e,function(e,n){if(e)throw fabric.log(e),e;t(n)})}if(typeof document!="undefined"&&typeof window!="undefined")return;var DOMParser=(new require("xmldom")).DOMParser,URL=require("url"),HTTP=require("http"),HTTPS=require("https"),Canvas=require("canvas"),Image=require("canvas").Image;fabric.util.loadImage=function(e,t,n){var r=function(r){i.src=new Buffer(r,"binary"),i._src=e,t&&t.call(n,i)},i=new Image;e&&(e instanceof Buffer||e.indexOf("data")===0)?(i.src=i._src=e,t&&t.call(n,i)):e&&e.indexOf("http")!==0?request_fs(e,r):e&&request(e,"binary",r)},fabric.loadSVGFromURL=function(e,t,n){e=e.replace(/^\n\s*/,"").replace(/\?.*$/,"").trim(),e.indexOf("http")!==0?request_fs(e,function(e){fabric.loadSVGFromString(e,t,n)}):request(e,"",function(e){fabric.loadSVGFromString(e,t,n)})},fabric.loadSVGFromString=function(e,t,n){var r=(new DOMParser).parseFromString(e);fabric.parseSVGDocument(r.documentElement,function(e,n){t&&t(e,n)},n)},fabric.util.getScript=function(url,callback){request(url,"",function(body){eval(body),callback&&callback()})},fabric.Image.fromObject=function(e,t){fabric.util.loadImage(e.src,function(n){var r=new fabric.Image(n);r._initConfig(e),r._initFilters(e,function(e){r.filters=e||[],t&&t(r)})})},fabric.createCanvasForNode=function(e,t){var n=fabric.document.createElement("canvas"),r=new Canvas(e||600,t||600);n.style={},n.width=r.width,n.height=r.height;var i=fabric.Canvas||fabric.StaticCanvas,s=new i(n);return s.contextContainer=r.getContext("2d"),s.nodeCanvas=r,s.Font=Canvas.Font,s},fabric.StaticCanvas.prototype.createPNGStream=function(){return this.nodeCanvas.createPNGStream()},fabric.StaticCanvas.prototype.createJPEGStream=function(e){return this.nodeCanvas.createJPEGStream(e)};var origSetWidth=fabric.StaticCanvas.prototype.setWidth;fabric.StaticCanvas.prototype.setWidth=function(e){return origSetWidth.call(this,e),this.nodeCanvas.width=e,this},fabric.Canvas&&(fabric.Canvas.prototype.setWidth=fabric.StaticCanvas.prototype.setWidth);var origSetHeight=fabric.StaticCanvas.prototype.setHeight;fabric.StaticCanvas.prototype.setHeight=function(e){return origSetHeight.call(this,e),this.nodeCanvas.height=e,this},fabric.Canvas&&(fabric.Canvas.prototype.setHeight=fabric.StaticCanvas.prototype.setHeight)}();
\ No newline at end of file
diff --git a/dist/all.min.js.gz b/dist/all.min.js.gz
index bba01085..09b11004 100644
Binary files a/dist/all.min.js.gz and b/dist/all.min.js.gz differ
diff --git a/dist/all.require.js b/dist/all.require.js
index cfcc7cdb..a996b201 100644
--- a/dist/all.require.js
+++ b/dist/all.require.js
@@ -20018,8 +20018,7 @@ fabric.util.object.extend(fabric.Text.prototype, {
(function() {
- var clone = fabric.util.object.clone,
- toFixed = fabric.util.toFixed;
+ var clone = fabric.util.object.clone;
/**
* IText class (introduced in v1.4)
@@ -20934,131 +20933,7 @@ fabric.util.object.extend(fabric.Text.prototype, {
return fabric.util.object.extend(this.callSuper('toObject', propertiesToInclude), {
styles: clone(this.styles)
});
- },
-
- /* _TO_SVG_START_ */
- /**
- * Returns SVG representation of an instance
- * @return {String} svg representation of an instance
- */
- //toSVG: function(reviver) {
- //if (this.isEmptyStyles()) {
- // return this.callSuper('toSVG', reviver);
- //}
-
- // TODO: add support for styled text SVG output
- //}
-
- /**
- * @private
- */
- _setSVGTextLineText: function(textLine, lineIndex, textSpans, lineHeight, lineTopOffsetMultiplier, textBgRects) {
- if (!this.styles[lineIndex]) {
- this.callSuper('_setSVGTextLineText',
- textLine, lineIndex, textSpans, lineHeight, lineTopOffsetMultiplier);
- }
- else {
- this._setSVGTextLineChars(
- textLine, lineIndex, textSpans, lineHeight, lineTopOffsetMultiplier, textBgRects);
- }
- },
-
- /**
- * @private
- */
- _setSVGTextLineChars: function(textLine, lineIndex, textSpans, lineHeight, lineTopOffsetMultiplier, textBgRects) {
-
- var yProp = lineIndex === 0 || this.useNative ? 'y' : 'dy',
- chars = textLine.split(''),
- charOffset = 0,
- lineLeftOffset = this._getSVGLineLeftOffset(lineIndex),
- lineTopOffset = this._getSVGLineTopOffset(lineIndex),
- heightOfLine = this._getHeightOfLine(this.ctx, lineIndex);
-
- for (var i = 0, len = chars.length; i < len; i++) {
- var styleDecl = this.styles[lineIndex][i] || { };
-
- textSpans.push(
- this._createTextCharSpan(
- chars[i], styleDecl, lineLeftOffset, lineTopOffset, yProp, charOffset));
-
- var charWidth = this._getWidthOfChar(this.ctx, chars[i], lineIndex, i);
-
- if (styleDecl.textBackgroundColor) {
- textBgRects.push(
- this._createTextCharBg(
- styleDecl, lineLeftOffset, lineTopOffset, heightOfLine, charWidth, charOffset));
- }
-
- charOffset += charWidth;
- }
- },
-
- /**
- * @private
- */
- _getSVGLineLeftOffset: function(lineIndex) {
- return (this._boundaries && this._boundaries[lineIndex])
- ? toFixed(this._boundaries[lineIndex].left, 2)
- : 0;
- },
-
- /**
- * @private
- */
- _getSVGLineTopOffset: function(lineIndex) {
- var lineTopOffset = 0;
- for (var j = 0; j <= lineIndex; j++) {
- lineTopOffset += this._getHeightOfLine(this.ctx, j);
- }
- return lineTopOffset - this.height / 2;
- },
-
- /**
- * @private
- */
- _createTextCharBg: function(styleDecl, lineLeftOffset, lineTopOffset, heightOfLine, charWidth, charOffset) {
- return [
- ''
- ].join('');
- },
-
- /**
- * @private
- */
- _createTextCharSpan: function(_char, styleDecl, lineLeftOffset, lineTopOffset, yProp, charOffset) {
-
- var fillStyles = this.getSvgStyles.call(fabric.util.object.extend({
- visible: true,
- fill: this.fill,
- stroke: this.stroke,
- type: 'text'
- }, styleDecl));
-
- return [
- '',
-
- fabric.util.string.escapeXml(_char),
- ''
- ].join('');
}
- /* _TO_SVG_END_ */
});
/**
@@ -22564,6 +22439,122 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
});
+/* _TO_SVG_START_ */
+fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.prototype */ {
+
+ /**
+ * @private
+ */
+ _setSVGTextLineText: function(textLine, lineIndex, textSpans, lineHeight, lineTopOffsetMultiplier, textBgRects) {
+ if (!this.styles[lineIndex]) {
+ this.callSuper('_setSVGTextLineText',
+ textLine, lineIndex, textSpans, lineHeight, lineTopOffsetMultiplier);
+ }
+ else {
+ this._setSVGTextLineChars(
+ textLine, lineIndex, textSpans, lineHeight, lineTopOffsetMultiplier, textBgRects);
+ }
+ },
+
+ /**
+ * @private
+ */
+ _setSVGTextLineChars: function(textLine, lineIndex, textSpans, lineHeight, lineTopOffsetMultiplier, textBgRects) {
+
+ var yProp = lineIndex === 0 || this.useNative ? 'y' : 'dy',
+ chars = textLine.split(''),
+ charOffset = 0,
+ lineLeftOffset = this._getSVGLineLeftOffset(lineIndex),
+ lineTopOffset = this._getSVGLineTopOffset(lineIndex),
+ heightOfLine = this._getHeightOfLine(this.ctx, lineIndex);
+
+ for (var i = 0, len = chars.length; i < len; i++) {
+ var styleDecl = this.styles[lineIndex][i] || { };
+
+ textSpans.push(
+ this._createTextCharSpan(
+ chars[i], styleDecl, lineLeftOffset, lineTopOffset, yProp, charOffset));
+
+ var charWidth = this._getWidthOfChar(this.ctx, chars[i], lineIndex, i);
+
+ if (styleDecl.textBackgroundColor) {
+ textBgRects.push(
+ this._createTextCharBg(
+ styleDecl, lineLeftOffset, lineTopOffset, heightOfLine, charWidth, charOffset));
+ }
+
+ charOffset += charWidth;
+ }
+ },
+
+ /**
+ * @private
+ */
+ _getSVGLineLeftOffset: function(lineIndex) {
+ return (this._boundaries && this._boundaries[lineIndex])
+ ? fabric.util.toFixed(this._boundaries[lineIndex].left, 2)
+ : 0;
+ },
+
+ /**
+ * @private
+ */
+ _getSVGLineTopOffset: function(lineIndex) {
+ var lineTopOffset = 0;
+ for (var j = 0; j <= lineIndex; j++) {
+ lineTopOffset += this._getHeightOfLine(this.ctx, j);
+ }
+ return lineTopOffset - this.height / 2;
+ },
+
+ /**
+ * @private
+ */
+ _createTextCharBg: function(styleDecl, lineLeftOffset, lineTopOffset, heightOfLine, charWidth, charOffset) {
+ return [
+ ''
+ ].join('');
+ },
+
+ /**
+ * @private
+ */
+ _createTextCharSpan: function(_char, styleDecl, lineLeftOffset, lineTopOffset, yProp, charOffset) {
+
+ var fillStyles = this.getSvgStyles.call(fabric.util.object.extend({
+ visible: true,
+ fill: this.fill,
+ stroke: this.stroke,
+ type: 'text'
+ }, styleDecl));
+
+ return [
+ '',
+
+ fabric.util.string.escapeXml(_char),
+ ''
+ ].join('');
+ }
+});
+/* _TO_SVG_END_ */
+
+
(function() {
if (typeof document !== 'undefined' && typeof window !== 'undefined') {
diff --git a/src/mixins/itext.svg_export.js b/src/mixins/itext.svg_export.js
new file mode 100644
index 00000000..41299b4f
--- /dev/null
+++ b/src/mixins/itext.svg_export.js
@@ -0,0 +1,114 @@
+/* _TO_SVG_START_ */
+fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.prototype */ {
+
+ /**
+ * @private
+ */
+ _setSVGTextLineText: function(textLine, lineIndex, textSpans, lineHeight, lineTopOffsetMultiplier, textBgRects) {
+ if (!this.styles[lineIndex]) {
+ this.callSuper('_setSVGTextLineText',
+ textLine, lineIndex, textSpans, lineHeight, lineTopOffsetMultiplier);
+ }
+ else {
+ this._setSVGTextLineChars(
+ textLine, lineIndex, textSpans, lineHeight, lineTopOffsetMultiplier, textBgRects);
+ }
+ },
+
+ /**
+ * @private
+ */
+ _setSVGTextLineChars: function(textLine, lineIndex, textSpans, lineHeight, lineTopOffsetMultiplier, textBgRects) {
+
+ var yProp = lineIndex === 0 || this.useNative ? 'y' : 'dy',
+ chars = textLine.split(''),
+ charOffset = 0,
+ lineLeftOffset = this._getSVGLineLeftOffset(lineIndex),
+ lineTopOffset = this._getSVGLineTopOffset(lineIndex),
+ heightOfLine = this._getHeightOfLine(this.ctx, lineIndex);
+
+ for (var i = 0, len = chars.length; i < len; i++) {
+ var styleDecl = this.styles[lineIndex][i] || { };
+
+ textSpans.push(
+ this._createTextCharSpan(
+ chars[i], styleDecl, lineLeftOffset, lineTopOffset, yProp, charOffset));
+
+ var charWidth = this._getWidthOfChar(this.ctx, chars[i], lineIndex, i);
+
+ if (styleDecl.textBackgroundColor) {
+ textBgRects.push(
+ this._createTextCharBg(
+ styleDecl, lineLeftOffset, lineTopOffset, heightOfLine, charWidth, charOffset));
+ }
+
+ charOffset += charWidth;
+ }
+ },
+
+ /**
+ * @private
+ */
+ _getSVGLineLeftOffset: function(lineIndex) {
+ return (this._boundaries && this._boundaries[lineIndex])
+ ? fabric.util.toFixed(this._boundaries[lineIndex].left, 2)
+ : 0;
+ },
+
+ /**
+ * @private
+ */
+ _getSVGLineTopOffset: function(lineIndex) {
+ var lineTopOffset = 0;
+ for (var j = 0; j <= lineIndex; j++) {
+ lineTopOffset += this._getHeightOfLine(this.ctx, j);
+ }
+ return lineTopOffset - this.height / 2;
+ },
+
+ /**
+ * @private
+ */
+ _createTextCharBg: function(styleDecl, lineLeftOffset, lineTopOffset, heightOfLine, charWidth, charOffset) {
+ return [
+ ''
+ ].join('');
+ },
+
+ /**
+ * @private
+ */
+ _createTextCharSpan: function(_char, styleDecl, lineLeftOffset, lineTopOffset, yProp, charOffset) {
+
+ var fillStyles = this.getSvgStyles.call(fabric.util.object.extend({
+ visible: true,
+ fill: this.fill,
+ stroke: this.stroke,
+ type: 'text'
+ }, styleDecl));
+
+ return [
+ '',
+
+ fabric.util.string.escapeXml(_char),
+ ''
+ ].join('');
+ }
+});
+/* _TO_SVG_END_ */
diff --git a/src/shapes/itext.class.js b/src/shapes/itext.class.js
index ad2801dc..7decf59a 100644
--- a/src/shapes/itext.class.js
+++ b/src/shapes/itext.class.js
@@ -1,7 +1,6 @@
(function() {
- var clone = fabric.util.object.clone,
- toFixed = fabric.util.toFixed;
+ var clone = fabric.util.object.clone;
/**
* IText class (introduced in v1.4)
@@ -916,131 +915,7 @@
return fabric.util.object.extend(this.callSuper('toObject', propertiesToInclude), {
styles: clone(this.styles)
});
- },
-
- /* _TO_SVG_START_ */
- /**
- * Returns SVG representation of an instance
- * @return {String} svg representation of an instance
- */
- //toSVG: function(reviver) {
- //if (this.isEmptyStyles()) {
- // return this.callSuper('toSVG', reviver);
- //}
-
- // TODO: add support for styled text SVG output
- //}
-
- /**
- * @private
- */
- _setSVGTextLineText: function(textLine, lineIndex, textSpans, lineHeight, lineTopOffsetMultiplier, textBgRects) {
- if (!this.styles[lineIndex]) {
- this.callSuper('_setSVGTextLineText',
- textLine, lineIndex, textSpans, lineHeight, lineTopOffsetMultiplier);
- }
- else {
- this._setSVGTextLineChars(
- textLine, lineIndex, textSpans, lineHeight, lineTopOffsetMultiplier, textBgRects);
- }
- },
-
- /**
- * @private
- */
- _setSVGTextLineChars: function(textLine, lineIndex, textSpans, lineHeight, lineTopOffsetMultiplier, textBgRects) {
-
- var yProp = lineIndex === 0 || this.useNative ? 'y' : 'dy',
- chars = textLine.split(''),
- charOffset = 0,
- lineLeftOffset = this._getSVGLineLeftOffset(lineIndex),
- lineTopOffset = this._getSVGLineTopOffset(lineIndex),
- heightOfLine = this._getHeightOfLine(this.ctx, lineIndex);
-
- for (var i = 0, len = chars.length; i < len; i++) {
- var styleDecl = this.styles[lineIndex][i] || { };
-
- textSpans.push(
- this._createTextCharSpan(
- chars[i], styleDecl, lineLeftOffset, lineTopOffset, yProp, charOffset));
-
- var charWidth = this._getWidthOfChar(this.ctx, chars[i], lineIndex, i);
-
- if (styleDecl.textBackgroundColor) {
- textBgRects.push(
- this._createTextCharBg(
- styleDecl, lineLeftOffset, lineTopOffset, heightOfLine, charWidth, charOffset));
- }
-
- charOffset += charWidth;
- }
- },
-
- /**
- * @private
- */
- _getSVGLineLeftOffset: function(lineIndex) {
- return (this._boundaries && this._boundaries[lineIndex])
- ? toFixed(this._boundaries[lineIndex].left, 2)
- : 0;
- },
-
- /**
- * @private
- */
- _getSVGLineTopOffset: function(lineIndex) {
- var lineTopOffset = 0;
- for (var j = 0; j <= lineIndex; j++) {
- lineTopOffset += this._getHeightOfLine(this.ctx, j);
- }
- return lineTopOffset - this.height / 2;
- },
-
- /**
- * @private
- */
- _createTextCharBg: function(styleDecl, lineLeftOffset, lineTopOffset, heightOfLine, charWidth, charOffset) {
- return [
- ''
- ].join('');
- },
-
- /**
- * @private
- */
- _createTextCharSpan: function(_char, styleDecl, lineLeftOffset, lineTopOffset, yProp, charOffset) {
-
- var fillStyles = this.getSvgStyles.call(fabric.util.object.extend({
- visible: true,
- fill: this.fill,
- stroke: this.stroke,
- type: 'text'
- }, styleDecl));
-
- return [
- '',
-
- fabric.util.string.escapeXml(_char),
- ''
- ].join('');
}
- /* _TO_SVG_END_ */
});
/**