@@ -20,7 +20,8 @@ var CanvasTextEditor = function(doc, options) {
2020 fontSize : 14 ,
2121 padding : 5 ,
2222 width : 640 ,
23- height : 480
23+ height : 480 ,
24+ dpr : window . devicePixelRatio || 1 ,
2425 } ;
2526
2627 if ( typeof options === 'object' ) {
@@ -172,7 +173,7 @@ CanvasTextEditor.prototype._createCanvas = function() {
172173 this . canvas = document . createElement ( 'canvas' ) ;
173174 this . canvas . style . display = 'block' ;
174175 this . context = this . canvas . getContext ( '2d' ) ;
175- this . resize ( this . options . width , this . options . height ) ;
176+ this . resize ( this . options . width , this . options . height , this . options . dpr ) ;
176177 this . render ( ) ;
177178 this . wrapper . appendChild ( this . canvas ) ;
178179} ;
@@ -394,9 +395,12 @@ CanvasTextEditor.prototype.getDocument = function() {
394395 * @param {Number } width
395396 * @param {Number } height
396397 */
397- CanvasTextEditor . prototype . resize = function ( width , height ) {
398- this . canvas . width = width ;
399- this . canvas . height = height ;
398+ CanvasTextEditor . prototype . resize = function ( width , height , dpr ) {
399+ this . canvas . width = width * dpr ;
400+ this . canvas . height = height * dpr ;
401+ this . canvas . style . width = `${ width } px` ;
402+ this . canvas . style . height = `${ height } px` ;
403+ this . context . scale ( dpr , dpr ) ;
400404 // We need to update context settings every time we resize
401405 this . context . font = this . _metrics . getSize ( ) + 'px ' + this . _metrics . getFamily ( ) ;
402406} ;
0 commit comments