diff --git a/README.md b/README.md index a5b58e9..22aec38 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ __Options:__ ```textDecoration```: (String) - additional text decoration * 'none' - no decoration - * 'underline' - text is underlined according to `context.strokeStyle` + * 'underline' - text is underlined according to `context.strokeStyle` and `context.lineWidth` NOTE: if a single word is too long to fit the width with specified font size, it will break on any letter unless ```sizeToFill``` option is enabled. diff --git a/canvas-text-wrapper.min.js b/canvas-text-wrapper.min.js index 97cbb88..c2332ca 100644 --- a/canvas-text-wrapper.min.js +++ b/canvas-text-wrapper.min.js @@ -1 +1 @@ -!function(a){function b(b,c,d){"use strict";function e(a){A||(A=r.sizeToFill?t.font.split(/\b\d+px\b/i):r.font.split(/\b\d+px\b/i)),t.font=A[0]+a+"px"+A[1]}function f(){isNaN(r.lineHeight)?-1!==r.lineHeight.toString().indexOf("px")?K=parseInt(r.lineHeight):-1!==r.lineHeight.toString().indexOf("%")&&(K=parseInt(r.lineHeight)/100*F):K=F*r.lineHeight}function g(){if(r.sizeToFill){var a=c.trim().split(/\s+/).length,b=0;do h(++b);while(E>G&&H.join(" ").split(/\s+/).length==a);h(--b)}else i();r.justifyLines&&"auto"===r.lineBreak&&l(),o(),m()}function h(a){e(a),K=a,i()}function i(){if(r.allowNewLine)for(var a=c.trim().split("\n"),b=0,d=0;bD){for(var h=0;t.measureText(b+f[h]).width<=D&&hD)break;for(;t.measureText(H[c]+a[b]).width<=D&&ba)&&(a=c,b=d);var e,f,g,h,i,j=" ";for(d=0;d=e))){H[d]=H[d].trim().split(/\s+/).join(j),f=t.measureText(j).width,g=(a-t.measureText(H[d]).width)/f,h=g/(e-1),i="";for(var k=0;h>k;k++)i+=j;H[d]=H[d].trim().split(j).join(i)}}function m(){for(var a=0;a1){var w={};for(var s in t)w[s]=t[s];var x=b.width,y=b.height;u=v,b.width=x*u,b.height=y*u,b.style.width=x*u*.5+"px",b.style.height=y*u*.5+"px";for(var s in w)try{t[s]=w[s]}catch(z){}t.scale(u,u)}var A,B=(r.fitParent?b.parentNode.clientWidth:b.width)/u,C=(r.fitParent?b.parentNode.clientHeight:b.height)/u,D=B-2*r.paddingX,E=C-2*r.paddingY,F=r.font.match(/\d+(px|em|%)/g)?+r.font.match(/\d+(px|em|%)/g)[0].match(/\d+/g):18,G=0,H=[],I=[],J={x:0,y:0},K=0;e(F),f(),p(),g()}"module"in a&&"exports"in module?module.exports=b:a.CanvasTextWrapper=b}(this); \ No newline at end of file +!function(a){function b(b,c,d){"use strict";function e(a){B||(B=s.sizeToFill?u.font.split(/\b\d+px\b/i):s.font.split(/\b\d+px\b/i)),u.font=B[0]+a+"px"+B[1]}function f(){isNaN(s.lineHeight)?-1!==s.lineHeight.toString().indexOf("px")?L=parseInt(s.lineHeight):-1!==s.lineHeight.toString().indexOf("%")&&(L=parseInt(s.lineHeight)/100*G):L=G*s.lineHeight}function g(){if(s.sizeToFill){var a=c.trim().split(/\s+/).length,b=0;do h(++b);while(F>H&&I.join(" ").split(/\s+/).length==a);h(--b)}else i();s.justifyLines&&"auto"===s.lineBreak&&l(),p(),n()}function h(a){e(a),L=a,i()}function i(){if(s.allowNewLine)for(var a=c.trim().split("\n"),b=0,d=0;bE){for(var h=0;u.measureText(b+f[h]).width<=E&&hE)break;for(;u.measureText(I[c]+a[b]).width<=E&&ba)&&(a=c,b=d);var e,f,g,h,i,j=" ";for(d=0;d=e))){I[d]=I[d].trim().split(/\s+/).join(j),f=u.measureText(j).width,g=(a-u.measureText(I[d]).width)/f,h=g/(e-1),i="";for(var k=0;h>k;k++)i+=j;I[d]=I[d].trim().split(j).join(i)}}function m(a,b,c){var d=u.measureText(a).width;switch(u.textAlign){case"center":b-=d/2;break;case"right":b-=d}u.beginPath(),u.moveTo(b,c),u.lineTo(b+d,c),u.stroke()}function n(){for(var a=0;a1){var x={};for(var t in u)x[t]=u[t];var y=b.width,z=b.height;v=w,b.width=y*v,b.height=z*v,b.style.width=y*v*.5+"px",b.style.height=z*v*.5+"px";for(var t in x)try{u[t]=x[t]}catch(A){}u.scale(v,v)}var B,C=(s.fitParent?b.parentNode.clientWidth:b.width)/v,D=(s.fitParent?b.parentNode.clientHeight:b.height)/v,E=C-2*s.paddingX,F=D-2*s.paddingY,G=s.font.match(/\d+(px|em|%)/g)?+s.font.match(/\d+(px|em|%)/g)[0].match(/\d+/g):18,H=0,I=[],J=[],K={x:0,y:0},L=0;e(G),f(),q(),g()}"module"in a&&"exports"in module?module.exports=b:a.CanvasTextWrapper=b}(this); \ No newline at end of file diff --git a/package.json b/package.json index ebee60b..3518744 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "canvas-text-wrapper", "description": "Split canvas text into lines on specified rule with optional alignment, padding, and more. Supports HDPI screens.", - "version": "0.8.3", + "version": "0.9.0", "license": "MIT", "main": "canvas-text-wrapper.js", "keywords": [