@@ -998,6 +998,15 @@ function renderWindow(node, container, options, windowWidth, windowHeight) {
998
998
canvas = crop ( renderer . canvas , { width : renderer . canvas . width , height : renderer . canvas . height , top : 0 , left : 0 , x : 0 , y : 0 } ) ;
999
999
} else if ( node === clonedWindow . document . body || node === clonedWindow . document . documentElement || options . canvas != null ) {
1000
1000
canvas = renderer . canvas ;
1001
+ } else if ( options . scale ) {
1002
+ var origBounds = { width : options . width != null ? options . width : bounds . width , height : options . height != null ? options . height : bounds . height , top : bounds . top , left : bounds . left , x : 0 , y : 0 } ;
1003
+ var cropBounds = { } ;
1004
+ for ( var key in origBounds ) {
1005
+ if ( origBounds . hasOwnProperty ( key ) ) { cropBounds [ key ] = origBounds [ key ] * options . scale ; }
1006
+ }
1007
+ canvas = crop ( renderer . canvas , cropBounds ) ;
1008
+ canvas . style . width = origBounds . width + 'px' ;
1009
+ canvas . style . height = origBounds . height + 'px' ;
1001
1010
} else {
1002
1011
canvas = crop ( renderer . canvas , { width : options . width != null ? options . width : bounds . width , height : options . height != null ? options . height : bounds . height , top : bounds . top , left : bounds . left , x : 0 , y : 0 } ) ;
1003
1012
}
@@ -2944,11 +2953,22 @@ var log = _dereq_('../log');
2944
2953
function CanvasRenderer ( width , height ) {
2945
2954
Renderer . apply ( this , arguments ) ;
2946
2955
this . canvas = this . options . canvas || this . document . createElement ( "canvas" ) ;
2956
+ this . ctx = this . canvas . getContext ( "2d" ) ;
2947
2957
if ( ! this . options . canvas ) {
2948
- this . canvas . width = width ;
2949
- this . canvas . height = height ;
2958
+ if ( this . options . dpi ) {
2959
+ this . options . scale = this . options . dpi / 96 ; // 1 CSS inch = 96px.
2960
+ }
2961
+ if ( this . options . scale ) {
2962
+ this . canvas . style . width = width + 'px' ;
2963
+ this . canvas . style . height = height + 'px' ;
2964
+ this . canvas . width = Math . floor ( width * this . options . scale ) ;
2965
+ this . canvas . height = Math . floor ( height * this . options . scale ) ;
2966
+ this . ctx . scale ( this . options . scale , this . options . scale ) ;
2967
+ } else {
2968
+ this . canvas . width = width ;
2969
+ this . canvas . height = height ;
2970
+ }
2950
2971
}
2951
- this . ctx = this . canvas . getContext ( "2d" ) ;
2952
2972
this . taintCtx = this . document . createElement ( "canvas" ) . getContext ( "2d" ) ;
2953
2973
this . ctx . textBaseline = "bottom" ;
2954
2974
this . variables = { } ;
@@ -3080,9 +3100,13 @@ CanvasRenderer.prototype.backgroundRepeatShape = function(imageContainer, backgr
3080
3100
CanvasRenderer . prototype . renderBackgroundRepeat = function ( imageContainer , backgroundPosition , size , bounds , borderLeft , borderTop ) {
3081
3101
var offsetX = Math . round ( bounds . left + backgroundPosition . left + borderLeft ) , offsetY = Math . round ( bounds . top + backgroundPosition . top + borderTop ) ;
3082
3102
this . setFillStyle ( this . ctx . createPattern ( this . resizeImage ( imageContainer , size ) , "repeat" ) ) ;
3103
+ this . ctx . save ( ) ;
3083
3104
this . ctx . translate ( offsetX , offsetY ) ;
3105
+ if ( this . options . scale ) {
3106
+ this . ctx . scale ( 1 / this . options . scale , 1 / this . options . scale ) ;
3107
+ }
3084
3108
this . ctx . fill ( ) ;
3085
- this . ctx . translate ( - offsetX , - offsetY ) ;
3109
+ this . ctx . restore ( ) ;
3086
3110
} ;
3087
3111
3088
3112
CanvasRenderer . prototype . renderBackgroundGradient = function ( gradientImage , bounds ) {
@@ -3100,16 +3124,21 @@ CanvasRenderer.prototype.renderBackgroundGradient = function(gradientImage, boun
3100
3124
} ;
3101
3125
3102
3126
CanvasRenderer . prototype . resizeImage = function ( imageContainer , size ) {
3127
+ var width = size . width , height = size . height ;
3128
+ if ( this . options . scale ) {
3129
+ width *= this . options . scale ;
3130
+ height *= this . options . scale ;
3131
+ }
3103
3132
var image = imageContainer . image ;
3104
- if ( image . width === size . width && image . height === size . height ) {
3133
+ if ( image . width === width && image . height === height ) {
3105
3134
return image ;
3106
3135
}
3107
3136
3108
3137
var ctx , canvas = document . createElement ( 'canvas' ) ;
3109
- canvas . width = size . width ;
3110
- canvas . height = size . height ;
3138
+ canvas . width = width ;
3139
+ canvas . height = height ;
3111
3140
ctx = canvas . getContext ( "2d" ) ;
3112
- ctx . drawImage ( image , 0 , 0 , image . width , image . height , 0 , 0 , size . width , size . height ) ;
3141
+ ctx . drawImage ( image , 0 , 0 , image . width , image . height , 0 , 0 , width , height ) ;
3113
3142
return canvas ;
3114
3143
} ;
3115
3144
0 commit comments