diff --git a/CHANGELOG.md b/CHANGELOG.md index 27931ad4..743adcfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,6 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## Not released: - ## 7.0.0 - 2020-06-23 * **BREAKING** `inherit` option is removed from `visible` and `listening`. They now just have boolean values `true` or `false`. If you do `group.listening(false);` then whole group and all its children will be removed from the hitGraph (and they will not listen to events). Probably 99% `Konva` applications will be not affected by this *breaking change*. diff --git a/konva.js b/konva.js index d715e558..f3726dc8 100644 --- a/konva.js +++ b/konva.js @@ -8,7 +8,7 @@ * Konva JavaScript Framework v7.0.0 * http://konvajs.org/ * Licensed under the MIT - * Date: Tue Jun 23 2020 + * Date: Thu Jun 25 2020 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) @@ -13274,6 +13274,20 @@ ], // cached variables attrChangeListLen$1 = ATTR_CHANGE_LIST$1.length; + function normalizeFontFamily(fontFamily) { + return fontFamily + .split(',') + .map(function (family) { + family = family.trim(); + var hasSpace = family.indexOf(' ') >= 0; + var hasQuotes = family.indexOf('"') >= 0 || family.indexOf("'") >= 0; + if (hasSpace && !hasQuotes) { + family = "\"" + family + "\""; + } + return family; + }) + .join(', '); + } var dummyContext$1; function getDummyContext$1() { if (dummyContext$1) { @@ -13586,9 +13600,7 @@ SPACE$1 + (this.fontSize() + PX_SPACE) + // wrap font family into " so font families with spaces works ok - '"' + - this.fontFamily() + - '"'); + normalizeFontFamily(this.fontFamily())); }; Text.prototype._addTextLine = function (line) { if (this.align() === JUSTIFY) { diff --git a/konva.min.js b/konva.min.js index 1736864d..ef350249 100644 --- a/konva.min.js +++ b/konva.min.js @@ -3,10 +3,10 @@ * Konva JavaScript Framework v7.0.0 * http://konvajs.org/ * Licensed under the MIT - * Date: Tue Jun 23 2020 + * Date: Thu Jun 25 2020 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) * * @license - */var e=Math.PI/180;function t(t){var e=t.toLowerCase(),i=/(chrome)[ /]([\w.]+)/.exec(e)||/(webkit)[ /]([\w.]+)/.exec(e)||/(opera)(?:.*version|)[ /]([\w.]+)/.exec(e)||/(msie) ([\w.]+)/.exec(e)||e.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(e)||[],n=!!t.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i),r=!!t.match(/IEMobile/i);return{browser:i[1]||"",version:i[2]||"0",isIE:function(t){var e=t.indexOf("msie ");if(0>16&255,g:e>>8&255,b:255&e}},getRandomColor:function(){for(var t=(16777215*Math.random()<<0).toString(16);t.length<6;)t="0"+t;return"#"+t},get:function(t,e){return void 0===t?e:t},getRGB:function(t){var e;return t in d?{r:(e=d[t])[0],g:e[1],b:e[2]}:"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=u.exec(t.replace(/ /g,"")),{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10)}):{r:0,g:0,b:0}},colorToRGBA:function(t){return t=t||"black",A._namedColorToRBA(t)||A._hex3ColorToRGBA(t)||A._hex6ColorToRGBA(t)||A._rgbColorToRGBA(t)||A._rgbaColorToRGBA(t)||A._hslColorToRGBA(t)},_namedColorToRBA:function(t){var e=d[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA:function(t){if(0===t.indexOf("rgb(")){var e=(t=t.match(/rgb\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA:function(t){if(0===t.indexOf("rgba(")){var e=(t=t.match(/rgba\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_hex6ColorToRGBA:function(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1}},_hex3ColorToRGBA:function(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1}},_hslColorToRGBA:function(t){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(t)){var e=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(t),i=(e[0],e.slice(1)),n=Number(i[0])/360,r=Number(i[1])/100,o=Number(i[2])/100,a=void 0,s=void 0,h=void 0;if(0==r)return h=255*o,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};for(var l=2*o-(a=o<.5?o*(1+r):o+r-o*r),c=[0,0,0],d=0;d<3;d++)(s=n+1/3*-(d-1))<0&&s++,1t.x+t.width||e.x+e.widtht.y+t.height||e.y+e.heighte.length&&(r=e,e=t,t=r),n=0;n=this.parent.children.length)&&A.warn("Unexpected value "+t+" for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to "+(this.parent.children.length-1)+".");var e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this},dt.prototype.getAbsoluteOpacity=function(){return this._getCache(Z,this._getAbsoluteOpacity)},dt.prototype._getAbsoluteOpacity=function(){var t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t},dt.prototype.moveTo=function(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this},dt.prototype.toObject=function(){var t,e,i,n={},r=this.getAttrs();for(t in n.attrs={},r)e=r[t],A.isObject(e)&&!A._isPlainObject(e)&&!A._isArray(e)||(i="function"==typeof this[t]&&this[t],delete r[t],(i?i.call(this):null)!==(r[t]=e)&&(n.attrs[t]=e));return n.className=this.getClassName(),A._prepareToStringify(n)},dt.prototype.toJSON=function(){return JSON.stringify(this.toObject())},dt.prototype.getParent=function(){return this.parent},dt.prototype.findAncestors=function(t,e,i){var n=[];e&&this._isMatch(t)&&n.push(this);for(var r=this.parent;r;){if(r===i)return n;r._isMatch(t)&&n.push(r),r=r.parent}return n},dt.prototype.isAncestorOf=function(t){return!1},dt.prototype.findAncestor=function(t,e,i){return this.findAncestors(t,e,i)[0]},dt.prototype._isMatch=function(t){if(!t)return!1;if("function"==typeof t)return t(this);for(var e,i=t.replace(/ /g,"").split(","),n=i.length,r=0;rthis.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())},Ae.prototype.getTime=function(){return this._time},Ae.prototype.setPosition=function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},Ae.prototype.getPosition=function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},Ae.prototype.play=function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},Ae.prototype.reverse=function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},Ae.prototype.seek=function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},Ae.prototype.reset=function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},Ae.prototype.finish=function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},Ae.prototype.update=function(){this.setPosition(this.getPosition(this._time))},Ae.prototype.onEnterFrame=function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},Ae.prototype.pause=function(){this.state=1,this.fire("onPause")},Ae.prototype.getTimer=function(){return(new Date).getTime()},Ae);function Ae(t,e,i,n,r,o,a){this.prop=t,this.propFunc=e,this.begin=n,this._pos=n,this.duration=o,this._change=0,this.prevPos=0,this.yoyo=a,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.func=i,this._change=r-this.begin,this.pause()}var Me=(Ge.prototype._addAttr=function(t,e){var i,n,r,o,a,s,h,l,c=this.node,d=c._id,p=Ge.tweens[d][t];if(p&&delete Ge.attrs[d][p][t],i=c.getAttr(t),A._isArray(e))if(n=[],o=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(s=i,i=A._prepareArrayForTween(i,e,c.closed())):(a=e,e=A._prepareArrayForTween(e,i,c.closed()))),0===t.indexOf("fill"))for(r=0;rthis.dataArray[i].pathLength;)t-=this.dataArray[i].pathLength,++i;if(i===n)return{x:(e=this.dataArray[i-1].points.slice(-2))[0],y:e[1]};if(t<.01)return{x:(e=this.dataArray[i].points.slice(0,2))[0],y:e[1]};var r=this.dataArray[i],o=r.points;switch(r.command){case"L":return ci.getPointOnLine(t,r.start.x,r.start.y,o[0],o[1]);case"C":return ci.getPointOnCubicBezier(t/r.pathLength,r.start.x,r.start.y,o[0],o[1],o[2],o[3],o[4],o[5]);case"Q":return ci.getPointOnQuadraticBezier(t/r.pathLength,r.start.x,r.start.y,o[0],o[1],o[2],o[3]);case"A":var a=o[0],s=o[1],h=o[2],l=o[3],c=o[4],d=o[5],p=o[6];return c+=d*t/r.pathLength,ci.getPointOnEllipticalArc(a,s,h,l,c,p)}return null},ci.getLineLength=function(t,e,i,n){return Math.sqrt((i-t)*(i-t)+(n-e)*(n-e))},ci.getPointOnLine=function(t,e,i,n,r,o,a){void 0===o&&(o=e),void 0===a&&(a=i);var s=(r-i)/(n-e+1e-8),h=Math.sqrt(t*t/(1+s*s));n>>1,A=_.slice(0,1+T),M=this._getTextWidth(A)+v;M<=l?(w=1+T,P=A+(g?"…":""),k=M):C=T}if(!P)break;if(!f||0<(S=(" "===(x=_[P.length])||"-"===x)&&k<=l?P.length:Math.max(P.lastIndexOf(" "),P.lastIndexOf("-"))+1)&&(w=S,P=P.slice(0,w),k=this._getTextWidth(P)),P=P.trimRight(),this._addTextLine(P),i=Math.max(i,k),d+=n,!u||s&&ce?g=li.getPointOnLine(e,f.x,f.y,v.points[0],v.points[1],f.x,f.y):v=void 0;break;case"A":var a=v.points[4],s=v.points[5],h=v.points[4]+s;0===m?m=a+1e-8:iv.pathLength?1e-8:e/v.pathLength:il.x?-1:1,d=this.findOne(".top-left").y()>l.y?-1:1,w=s*this.cos*c,C=s*this.sin*d,this.findOne(".top-left").x(l.x-w),this.findOne(".top-left").y(l.y-C)):"top-center"===this._movingAnchorName?this.findOne(".top-left").y(e.y()):"top-right"===this._movingAnchorName?(a&&(l=p?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-left").x(),y:this.findOne(".bottom-left").y()},s=Math.sqrt(Math.pow(e.x()-l.x,2)+Math.pow(l.y-e.y(),2)),c=this.findOne(".top-right").x()l.y?-1:1,w=s*this.cos*c,C=s*this.sin*d,this.findOne(".top-right").x(l.x+w),this.findOne(".top-right").y(l.y-C)),h=e.position(),this.findOne(".top-left").y(h.y),this.findOne(".bottom-right").x(h.x)):"middle-left"===this._movingAnchorName?this.findOne(".top-left").x(e.x()):"middle-right"===this._movingAnchorName?this.findOne(".bottom-right").x(e.x()):"bottom-left"===this._movingAnchorName?(a&&(l=p?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-right").x(),y:this.findOne(".top-right").y()},s=Math.sqrt(Math.pow(l.x-e.x(),2)+Math.pow(e.y()-l.y,2)),c=l.x>N,0!==w?(w=255/w,P[a]=(h*B>>N)*w,P[a+1]=(l*B>>N)*w,P[a+2]=(c*B>>N)*w):P[a]=P[a+1]=P[a+2]=0,h-=p,l-=u,c-=f,d-=g,p-=O.r,u-=O.g,f-=O.b,g-=O.a,r=s+((r=i+e+1)>N,0>N)*w,P[r+1]=(l*B>>N)*w,P[r+2]=(c*B>>N)*w):P[r]=P[r+1]=P[r+2]=0,h-=p,l-=u,c-=f,d-=g,p-=O.r,u-=O.g,f-=O.b,g-=O.a,r=i+((r=n+R)>16&255,g:e>>8&255,b:255&e}},getRandomColor:function(){for(var t=(16777215*Math.random()<<0).toString(16);t.length<6;)t="0"+t;return"#"+t},get:function(t,e){return void 0===t?e:t},getRGB:function(t){var e;return t in d?{r:(e=d[t])[0],g:e[1],b:e[2]}:"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=u.exec(t.replace(/ /g,"")),{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10)}):{r:0,g:0,b:0}},colorToRGBA:function(t){return t=t||"black",A._namedColorToRBA(t)||A._hex3ColorToRGBA(t)||A._hex6ColorToRGBA(t)||A._rgbColorToRGBA(t)||A._rgbaColorToRGBA(t)||A._hslColorToRGBA(t)},_namedColorToRBA:function(t){var e=d[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA:function(t){if(0===t.indexOf("rgb(")){var e=(t=t.match(/rgb\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA:function(t){if(0===t.indexOf("rgba(")){var e=(t=t.match(/rgba\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_hex6ColorToRGBA:function(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1}},_hex3ColorToRGBA:function(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1}},_hslColorToRGBA:function(t){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(t)){var e=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(t),i=(e[0],e.slice(1)),n=Number(i[0])/360,r=Number(i[1])/100,o=Number(i[2])/100,a=void 0,s=void 0,h=void 0;if(0==r)return h=255*o,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};for(var l=2*o-(a=o<.5?o*(1+r):o+r-o*r),c=[0,0,0],d=0;d<3;d++)(s=n+1/3*-(d-1))<0&&s++,1t.x+t.width||e.x+e.widtht.y+t.height||e.y+e.heighte.length&&(r=e,e=t,t=r),n=0;n=this.parent.children.length)&&A.warn("Unexpected value "+t+" for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to "+(this.parent.children.length-1)+".");var e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this},dt.prototype.getAbsoluteOpacity=function(){return this._getCache(Z,this._getAbsoluteOpacity)},dt.prototype._getAbsoluteOpacity=function(){var t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t},dt.prototype.moveTo=function(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this},dt.prototype.toObject=function(){var t,e,i,n={},r=this.getAttrs();for(t in n.attrs={},r)e=r[t],A.isObject(e)&&!A._isPlainObject(e)&&!A._isArray(e)||(i="function"==typeof this[t]&&this[t],delete r[t],(i?i.call(this):null)!==(r[t]=e)&&(n.attrs[t]=e));return n.className=this.getClassName(),A._prepareToStringify(n)},dt.prototype.toJSON=function(){return JSON.stringify(this.toObject())},dt.prototype.getParent=function(){return this.parent},dt.prototype.findAncestors=function(t,e,i){var n=[];e&&this._isMatch(t)&&n.push(this);for(var r=this.parent;r;){if(r===i)return n;r._isMatch(t)&&n.push(r),r=r.parent}return n},dt.prototype.isAncestorOf=function(t){return!1},dt.prototype.findAncestor=function(t,e,i){return this.findAncestors(t,e,i)[0]},dt.prototype._isMatch=function(t){if(!t)return!1;if("function"==typeof t)return t(this);for(var e,i=t.replace(/ /g,"").split(","),n=i.length,r=0;rthis.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())},Ae.prototype.getTime=function(){return this._time},Ae.prototype.setPosition=function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},Ae.prototype.getPosition=function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},Ae.prototype.play=function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},Ae.prototype.reverse=function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},Ae.prototype.seek=function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},Ae.prototype.reset=function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},Ae.prototype.finish=function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},Ae.prototype.update=function(){this.setPosition(this.getPosition(this._time))},Ae.prototype.onEnterFrame=function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},Ae.prototype.pause=function(){this.state=1,this.fire("onPause")},Ae.prototype.getTimer=function(){return(new Date).getTime()},Ae);function Ae(t,e,i,n,r,o,a){this.prop=t,this.propFunc=e,this.begin=n,this._pos=n,this.duration=o,this._change=0,this.prevPos=0,this.yoyo=a,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.func=i,this._change=r-this.begin,this.pause()}var Me=(Ge.prototype._addAttr=function(t,e){var i,n,r,o,a,s,h,l,c=this.node,d=c._id,p=Ge.tweens[d][t];if(p&&delete Ge.attrs[d][p][t],i=c.getAttr(t),A._isArray(e))if(n=[],o=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(s=i,i=A._prepareArrayForTween(i,e,c.closed())):(a=e,e=A._prepareArrayForTween(e,i,c.closed()))),0===t.indexOf("fill"))for(r=0;rthis.dataArray[i].pathLength;)t-=this.dataArray[i].pathLength,++i;if(i===n)return{x:(e=this.dataArray[i-1].points.slice(-2))[0],y:e[1]};if(t<.01)return{x:(e=this.dataArray[i].points.slice(0,2))[0],y:e[1]};var r=this.dataArray[i],o=r.points;switch(r.command){case"L":return ci.getPointOnLine(t,r.start.x,r.start.y,o[0],o[1]);case"C":return ci.getPointOnCubicBezier(t/r.pathLength,r.start.x,r.start.y,o[0],o[1],o[2],o[3],o[4],o[5]);case"Q":return ci.getPointOnQuadraticBezier(t/r.pathLength,r.start.x,r.start.y,o[0],o[1],o[2],o[3]);case"A":var a=o[0],s=o[1],h=o[2],l=o[3],c=o[4],d=o[5],p=o[6];return c+=d*t/r.pathLength,ci.getPointOnEllipticalArc(a,s,h,l,c,p)}return null},ci.getLineLength=function(t,e,i,n){return Math.sqrt((i-t)*(i-t)+(n-e)*(n-e))},ci.getPointOnLine=function(t,e,i,n,r,o,a){void 0===o&&(o=e),void 0===a&&(a=i);var s=(r-i)/(n-e+1e-8),h=Math.sqrt(t*t/(1+s*s));n>>1,A=_.slice(0,1+T),M=this._getTextWidth(A)+v;M<=l?(w=1+T,P=A+(g?"…":""),k=M):C=T}if(!P)break;if(!f||0<(S=(" "===(x=_[P.length])||"-"===x)&&k<=l?P.length:Math.max(P.lastIndexOf(" "),P.lastIndexOf("-"))+1)&&(w=S,P=P.slice(0,w),k=this._getTextWidth(P)),P=P.trimRight(),this._addTextLine(P),i=Math.max(i,k),d+=n,!u||s&&ce?g=li.getPointOnLine(e,f.x,f.y,v.points[0],v.points[1],f.x,f.y):v=void 0;break;case"A":var a=v.points[4],s=v.points[5],h=v.points[4]+s;0===m?m=a+1e-8:iv.pathLength?1e-8:e/v.pathLength:il.x?-1:1,d=this.findOne(".top-left").y()>l.y?-1:1,w=s*this.cos*c,C=s*this.sin*d,this.findOne(".top-left").x(l.x-w),this.findOne(".top-left").y(l.y-C)):"top-center"===this._movingAnchorName?this.findOne(".top-left").y(e.y()):"top-right"===this._movingAnchorName?(a&&(l=p?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-left").x(),y:this.findOne(".bottom-left").y()},s=Math.sqrt(Math.pow(e.x()-l.x,2)+Math.pow(l.y-e.y(),2)),c=this.findOne(".top-right").x()l.y?-1:1,w=s*this.cos*c,C=s*this.sin*d,this.findOne(".top-right").x(l.x+w),this.findOne(".top-right").y(l.y-C)),h=e.position(),this.findOne(".top-left").y(h.y),this.findOne(".bottom-right").x(h.x)):"middle-left"===this._movingAnchorName?this.findOne(".top-left").x(e.x()):"middle-right"===this._movingAnchorName?this.findOne(".bottom-right").x(e.x()):"bottom-left"===this._movingAnchorName?(a&&(l=p?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-right").x(),y:this.findOne(".top-right").y()},s=Math.sqrt(Math.pow(l.x-e.x(),2)+Math.pow(e.y()-l.y,2)),c=l.x>N,0!==w?(w=255/w,P[a]=(h*B>>N)*w,P[a+1]=(l*B>>N)*w,P[a+2]=(c*B>>N)*w):P[a]=P[a+1]=P[a+2]=0,h-=p,l-=u,c-=f,d-=g,p-=O.r,u-=O.g,f-=O.b,g-=O.a,r=s+((r=i+e+1)>N,0>N)*w,P[r+1]=(l*B>>N)*w,P[r+2]=(c*B>>N)*w):P[r]=P[r+1]=P[r+2]=0,h-=p,l-=u,c-=f,d-=g,p-=O.r,u-=O.g,f-=O.b,g-=O.a,r=i+((r=n+R) { + family = family.trim(); + const hasSpace = family.indexOf(' ') >= 0; + const hasQuotes = family.indexOf('"') >= 0 || family.indexOf("'") >= 0; + if (hasSpace && !hasQuotes) { + family = `"${family}"`; + } + return family; + }) + .join(', '); +} + var dummyContext; function getDummyContext() { if (dummyContext) { @@ -361,6 +377,7 @@ export class Text extends Shape { this.fontFamily() ); } + return ( this.fontStyle() + SPACE + @@ -368,9 +385,7 @@ export class Text extends Shape { SPACE + (this.fontSize() + PX_SPACE) + // wrap font family into " so font families with spaces works ok - '"' + - this.fontFamily() + - '"' + normalizeFontFamily(this.fontFamily()) ); } _addTextLine(line) { diff --git a/test/performance/jump-text.html b/test/performance/jump-text.html new file mode 100644 index 00000000..bc6336b1 --- /dev/null +++ b/test/performance/jump-text.html @@ -0,0 +1,165 @@ + + + + + + +
+ + + + + + diff --git a/test/unit/shapes/Text-test.js b/test/unit/shapes/Text-test.js index fb5ceb38..40b1a801 100644 --- a/test/unit/shapes/Text-test.js +++ b/test/unit/shapes/Text-test.js @@ -559,7 +559,33 @@ suite('Text', function () { stage.add(layer); var trace = - 'clearRect(0,0,578,200);save();transform(1,0,0,1,10,10);font=normal normal 80px "Arial";textBaseline=middle;textAlign=left;translate(0,0);save();save();beginPath();moveTo(0,80);lineTo(189,80);stroke();restore();fillStyle=red;fillText(h,0,40);fillStyle=red;fillText(e,49,40);fillStyle=red;fillText(l,98,40);fillStyle=red;fillText(l,121,40);fillStyle=red;fillText(o,144,40);restore();save();save();beginPath();moveTo(0,160);lineTo(211,160);stroke();restore();fillStyle=red;fillText(w,0,120);fillStyle=red;fillText(o,63,120);fillStyle=red;fillText(r,112,120);fillStyle=red;fillText(l,144,120);fillStyle=red;fillText(d,167,120);restore();restore();'; + 'clearRect(0,0,578,200);save();transform(1,0,0,1,10,10);font=normal normal 80px Arial;textBaseline=middle;textAlign=left;translate(0,0);save();save();beginPath();moveTo(0,80);lineTo(189,80);stroke();restore();fillStyle=red;fillText(h,0,40);fillStyle=red;fillText(e,49,40);fillStyle=red;fillText(l,98,40);fillStyle=red;fillText(l,121,40);fillStyle=red;fillText(o,144,40);restore();save();save();beginPath();moveTo(0,160);lineTo(211,160);stroke();restore();fillStyle=red;fillText(w,0,120);fillStyle=red;fillText(o,63,120);fillStyle=red;fillText(r,112,120);fillStyle=red;fillText(l,144,120);fillStyle=red;fillText(d,167,120);restore();restore();'; + + assert.equal(layer.getContext().getTrace(), trace); + }); + + // ====================================================== + test('test text with crazy font families', function () { + var stage = addStage(); + var layer = new Konva.Layer(); + stage.add(layer); + + var text = new Konva.Text({ + text: 'hello', + fontFamily: 'Arial', + }); + layer.add(text); + layer.draw(); + + text.fontFamily('Font Awesome'); + layer.draw(); + text.fontFamily('Font Awesome, Arial'); + layer.draw(); + text.fontFamily('"Font Awesome", Arial'); + layer.draw(); + + var trace = + 'clearRect(0,0,578,200);clearRect(0,0,578,200);save();transform(1,0,0,1,0,0);font=normal normal 12px Arial;textBaseline=middle;textAlign=left;translate(0,0);save();fillStyle=black;fillText(hello,0,6);restore();restore();clearRect(0,0,578,200);save();transform(1,0,0,1,0,0);font=normal normal 12px "Font Awesome";textBaseline=middle;textAlign=left;translate(0,0);save();fillStyle=black;fillText(hello,0,6);restore();restore();clearRect(0,0,578,200);save();transform(1,0,0,1,0,0);font=normal normal 12px "Font Awesome", Arial;textBaseline=middle;textAlign=left;translate(0,0);save();fillStyle=black;fillText(hello,0,6);restore();restore();clearRect(0,0,578,200);save();transform(1,0,0,1,0,0);font=normal normal 12px "Font Awesome", Arial;textBaseline=middle;textAlign=left;translate(0,0);save();fillStyle=black;fillText(hello,0,6);restore();restore();'; assert.equal(layer.getContext().getTrace(), trace); }); @@ -703,7 +729,7 @@ suite('Text', function () { stage.add(layer); var trace = - 'clearRect(0,0,578,200);save();transform(1,0,0,1,10,10);beginPath();rect(0,0,200,100);closePath();lineWidth=2;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,10,10);font=normal normal 16px "Arial";textBaseline=middle;textAlign=left;translate(10,42);save();fillStyle=#555;fillText(Some awesome text,17.523,8);restore();restore();'; + 'clearRect(0,0,578,200);save();transform(1,0,0,1,10,10);beginPath();rect(0,0,200,100);closePath();lineWidth=2;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,10,10);font=normal normal 16px Arial;textBaseline=middle;textAlign=left;translate(10,42);save();fillStyle=#555;fillText(Some awesome text,17.523,8);restore();restore();'; assert.equal(layer.getContext().getTrace(), trace); }); @@ -942,7 +968,7 @@ suite('Text', function () { // this text should look like it is positioned in y = 40 var trace = - 'clearRect(0,0,578,200);save();transform(1,0,0,1,0,0);beginPath();rect(0,0,100,120);closePath();lineWidth=2;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,0,0);font=normal normal 40px "Arial";textBaseline=middle;textAlign=left;translate(0,0);save();fillStyle=black;fillText(Some good text,0,60);restore();restore();'; + 'clearRect(0,0,578,200);save();transform(1,0,0,1,0,0);beginPath();rect(0,0,100,120);closePath();lineWidth=2;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,0,0);font=normal normal 40px Arial;textBaseline=middle;textAlign=left;translate(0,0);save();fillStyle=black;fillText(Some good text,0,60);restore();restore();'; assert.equal(layer.getContext().getTrace(), trace); });