diff --git a/README.md b/README.md index bad97a1..5d71d1d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ canvas-text-wrapper ================= -v0.6.6 +##v0.6.7 ## Syntax diff --git a/bower.json b/bower.json index ac97db7..39968bf 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "canvas-text-wrapper", - "version": "0.6.6", + "version": "0.6.7", "ignore": [ "**/.*", "**/*.log", diff --git a/canvas-text-wrapper.js b/canvas-text-wrapper.js index a1c800a..65a8200 100644 --- a/canvas-text-wrapper.js +++ b/canvas-text-wrapper.js @@ -1,6 +1,6 @@ /*! canvas-text-wrapper * https://github.com/namniak/canvas-text-wrapper - * Version: 0.6.6 + * Version: 0.6.7 * MIT License (http://www.opensource.org/licenses/mit-license.html) */ @@ -37,7 +37,9 @@ context.textBaseline = 'bottom'; var scale = 1; - if (opts.renderHDPI && global.devicePixelRatio) { + var devicePixelRatio = (typeof global !== 'undefined') ? global.devicePixelRatio : root.devicePixelRatio; + + if (opts.renderHDPI && devicePixelRatio > 1) { var tempCtx = {}; // store context settings in a temp object before scaling otherwise they will be lost @@ -47,7 +49,7 @@ var canvasWidth = canvas.width; var canvasHeight = canvas.height; - scale = global.devicePixelRatio; + scale = devicePixelRatio; canvas.width = canvasWidth * scale; canvas.height = canvasHeight * scale; diff --git a/canvas-text-wrapper.min.js b/canvas-text-wrapper.min.js index 2070fd2..ded4103 100644 --- a/canvas-text-wrapper.min.js +++ b/canvas-text-wrapper.min.js @@ -1,6 +1,6 @@ /*! canvas-text-wrapper * https://github.com/namniak/canvas-text-wrapper - * Version: 0.6.6 + * Version: 0.6.7 * MIT License (http://www.opensource.org/licenses/mit-license.html) */ -!function(a){function b(a,b,c){"use strict";function d(a){y||(y=q.sizeToFill?s.font.split(/\b\d+px\b/i):q.font.split(/\b\d+px\b/i)),s.font=y[0]+a+"px"+y[1]}function e(){isNaN(q.lineHeight)?-1!==q.lineHeight.toString().indexOf("px")?I=parseInt(q.lineHeight):-1!==q.lineHeight.toString().indexOf("%")&&(I=parseInt(q.lineHeight)/100*D):I=D*q.lineHeight}function f(){if(q.sizeToFill){var a=b.trim().split(/\s+/).length,c=0;do g(++c);while(C>E&&F.join(" ").split(/\s+/).length==a);g(--c)}else h();q.justifyLines&&"auto"===q.lineBreak&&k(),n(),l()}function g(a){d(a),I=a,h()}function h(){if(q.allowNewLine)for(var a=b.trim().split("\n"),c=0,d=0;cB){for(var h=0;s.measureText(b+f[h]).width<=B&&ha)&&(a=c,b=d);var e,f,g,h,i,j=" ";for(d=0;d=e))){F[d]=F[d].trim().split(/\s+/).join(j),f=s.measureText(j).width,g=(a-s.measureText(F[d]).width)/f,h=g/(e-1),i="";for(var k=0;h>k;k++)i+=j;F[d]=F[d].trim().split(j).join(i)}}function l(){for(var a=0;aG&&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&&ha)&&(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 diff --git a/package.json b/package.json index 73682da..789704e 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.6.6", + "version": "0.6.7", "license": "MIT", "main": "canvas-text-wrapper.min.js", "keywords": [ @@ -25,6 +25,7 @@ "test": "beefy test/test.js --live --open" }, "devDependencies": { + "grunt": "^0.4.5", "grunt-contrib-uglify": "^0.9.1", "uglify-save-license": "^0.4.1" }