@@ -1635,8 +1635,6 @@ function cloneNode(node, javascriptEnabled) {
1635
1635
var child = node . firstChild ;
1636
1636
while ( child ) {
1637
1637
if ( javascriptEnabled === true || child . nodeType !== 1 || child . nodeName !== 'SCRIPT' ) {
1638
- console . log ( clone ) ;
1639
-
1640
1638
clone . appendChild ( cloneNode ( child , javascriptEnabled ) ) ;
1641
1639
}
1642
1640
child = child . nextSibling ;
@@ -4027,13 +4025,14 @@ module.exports = Renderer;
4027
4025
} , { "./log" :15 } ] , 23 :[ function ( require , module , exports ) {
4028
4026
var Renderer = require ( '../renderer' ) ;
4029
4027
var LinearGradientContainer = require ( '../lineargradientcontainer' ) ;
4028
+ var Utils = require ( '../utils' ) ;
4030
4029
var log = require ( '../log' ) ;
4031
4030
4032
4031
function CanvasRenderer ( width , height ) {
4033
- this . ratio = window . devicePixelRatio ;
4032
+ this . ratio = Utils . getDeviceRatio ( ) ;
4034
4033
4035
- width = this . applyRatio ( width ) ;
4036
- height = this . applyRatio ( height ) ;
4034
+ width = Utils . applyRatio ( width ) ;
4035
+ height = Utils . applyRatio ( height ) ;
4037
4036
4038
4037
Renderer . apply ( this , arguments ) ;
4039
4038
this . canvas = this . options . canvas || this . document . createElement ( "canvas" ) ;
@@ -4057,62 +4056,16 @@ function CanvasRenderer(width, height) {
4057
4056
4058
4057
CanvasRenderer . prototype = Object . create ( Renderer . prototype ) ;
4059
4058
4060
- CanvasRenderer . prototype . applyRatio = function ( value ) {
4061
- return value * this . ratio ;
4062
- }
4063
-
4064
- CanvasRenderer . prototype . applyRatioToBounds = function ( bounds ) {
4065
- bounds . width = bounds . width * this . ratio ;
4066
- bounds . top = bounds . top * this . ratio ;
4067
-
4068
- //In case this is a size
4069
- try {
4070
- bounds . left = bounds . left * this . ratio ;
4071
- bounds . height = bounds . height * this . ratio ;
4072
- } catch ( e ) {
4073
-
4074
- }
4075
-
4076
- return bounds ;
4077
- }
4078
-
4079
- CanvasRenderer . prototype . applyRatioToPosition = function ( position ) {
4080
- position . left = position . left * this . ratio ;
4081
- position . height = position . height * this . ratio ;
4082
-
4083
- return bounds ;
4084
- }
4085
-
4086
- CanvasRenderer . prototype . applyRatioToShape = function ( shape ) {
4087
- for ( var i = 0 ; i < shape . length ; i ++ ) {
4088
- if ( shape [ i ] instanceof Array ) {
4089
- for ( var k = 1 ; k < shape [ i ] . length ; k ++ ) {
4090
- shape [ i ] [ k ] = this . applyRatio ( shape [ i ] [ k ] ) ;
4091
- }
4092
- }
4093
- }
4094
- return shape ;
4095
- }
4096
-
4097
- CanvasRenderer . prototype . applyRatioToFontSize = function ( fontSize ) {
4098
- var numericPart = parseFloat ( fontSize ) * this . ratio ;
4099
- var stringPart = fontSize . replace ( / [ 0 - 9 ] / g, '' ) ;
4100
-
4101
- fontSize = numericPart + stringPart ;
4102
-
4103
- return fontSize ;
4104
- }
4105
-
4106
4059
CanvasRenderer . prototype . setFillStyle = function ( fillStyle ) {
4107
4060
this . ctx . fillStyle = typeof ( fillStyle ) === "object" && ! ! fillStyle . isColor ? fillStyle . toString ( ) : fillStyle ;
4108
4061
return this . ctx ;
4109
4062
} ;
4110
4063
4111
4064
CanvasRenderer . prototype . rectangle = function ( left , top , width , height , color ) {
4112
- left = this . applyRatio ( left ) ;
4113
- top = this . applyRatio ( top ) ;
4114
- width = this . applyRatio ( width ) ;
4115
- height = this . applyRatio ( height ) ;
4065
+ left = Utils . applyRatio ( left ) ;
4066
+ top = Utils . applyRatio ( top ) ;
4067
+ width = Utils . applyRatio ( width ) ;
4068
+ height = Utils . applyRatio ( height ) ;
4116
4069
4117
4070
this . setFillStyle ( color ) . fillRect ( left , top , width , height ) ;
4118
4071
} ;
@@ -4126,17 +4079,17 @@ CanvasRenderer.prototype.circle = function(left, top, size, color) {
4126
4079
} ;
4127
4080
4128
4081
CanvasRenderer . prototype . circleStroke = function ( left , top , size , color , stroke , strokeColor ) {
4129
- left = this . applyRatio ( left ) ;
4130
- top = this . applyRatio ( top ) ;
4131
- size = this . applyRatio ( size ) ;
4082
+ left = Utils . applyRatio ( left ) ;
4083
+ top = Utils . applyRatio ( top ) ;
4084
+ size = Utils . applyRatio ( size ) ;
4132
4085
4133
4086
this . circle ( left , top , size , color ) ;
4134
4087
this . ctx . strokeStyle = strokeColor . toString ( ) ;
4135
4088
this . ctx . stroke ( ) ;
4136
4089
} ;
4137
4090
4138
4091
CanvasRenderer . prototype . drawShape = function ( shape , color ) {
4139
- shape = this . applyRatioToShape ( shape ) ;
4092
+ shape = Utils . applyRatioToShape ( shape ) ;
4140
4093
4141
4094
this . shape ( shape ) ;
4142
4095
this . setFillStyle ( color ) . fill ( ) ;
@@ -4158,14 +4111,16 @@ CanvasRenderer.prototype.taints = function(imageContainer) {
4158
4111
} ;
4159
4112
4160
4113
CanvasRenderer . prototype . drawImage = function ( imageContainer , sx , sy , sw , sh , dx , dy , dw , dh ) {
4161
- sx = this . applyRatio ( sx ) ;
4162
- sy = this . applyRatio ( sy ) ;
4163
- //sw = this.applyRatio(sw);
4164
- //sh = this.applyRatio(sh);
4165
- dx = this . applyRatio ( dx ) ;
4166
- dy = this . applyRatio ( dy ) ;
4167
- dw = this . applyRatio ( dw ) ;
4168
- dh = this . applyRatio ( dh ) ;
4114
+ //Do not scale source coordinates
4115
+ //sx = Utils.applyRatio(sx);
4116
+ //sy = Utils.applyRatio(sy);
4117
+ //sw = Utils.applyRatio(sw);
4118
+ //sh = Utils.applyRatio(sh);
4119
+
4120
+ dx = Utils . applyRatio ( dx ) ;
4121
+ dy = Utils . applyRatio ( dy ) ;
4122
+ dw = Utils . applyRatio ( dw ) ;
4123
+ dh = Utils . applyRatio ( dh ) ;
4169
4124
4170
4125
if ( ! this . taints ( imageContainer ) || this . options . allowTaint ) {
4171
4126
this . ctx . drawImage ( imageContainer . image , sx , sy , sw , sh , dx , dy , dw , dh ) ;
@@ -4175,8 +4130,8 @@ CanvasRenderer.prototype.drawImage = function(imageContainer, sx, sy, sw, sh, dx
4175
4130
CanvasRenderer . prototype . clip = function ( shapes , callback , context ) {
4176
4131
this . ctx . save ( ) ;
4177
4132
shapes . filter ( hasEntries ) . forEach ( function ( shape ) {
4178
- shape = this . applyRatioToShape ( shape ) ;
4179
- this . shape ( shape ) . clip ( ) ;
4133
+ shape = Utils . applyRatioToShape ( shape ) ;
4134
+ this . shape ( shape ) // .clip();
4180
4135
} , this ) ;
4181
4136
callback . call ( context ) ;
4182
4137
this . ctx . restore ( ) ;
@@ -4196,13 +4151,13 @@ CanvasRenderer.prototype.shape = function(shape) {
4196
4151
} ;
4197
4152
4198
4153
CanvasRenderer . prototype . font = function ( color , style , variant , weight , size , family ) {
4199
- size = this . applyRatioToFontSize ( size ) ;
4154
+ size = Utils . applyRatioToFontSize ( size ) ;
4200
4155
this . setFillStyle ( color ) . font = [ style , variant , weight , size , family ] . join ( " " ) . split ( "," ) [ 0 ] ;
4201
4156
} ;
4202
4157
4203
4158
CanvasRenderer . prototype . fontShadow = function ( color , offsetX , offsetY , blur ) {
4204
- offsetX = this . applyRatio ( offsetX ) ;
4205
- offsetY = this . applyRatio ( offsetY ) ;
4159
+ offsetX = Utils . applyRatio ( offsetX ) ;
4160
+ offsetY = Utils . applyRatio ( offsetY ) ;
4206
4161
4207
4162
this . setVariable ( "shadowColor" , color . toString ( ) )
4208
4163
. setVariable ( "shadowOffsetY" , offsetX )
@@ -4234,20 +4189,20 @@ CanvasRenderer.prototype.setVariable = function(property, value) {
4234
4189
} ;
4235
4190
4236
4191
CanvasRenderer . prototype . text = function ( text , left , bottom ) {
4237
- left = this . applyRatio ( left ) ;
4238
- bottom = this . applyRatio ( bottom ) ;
4192
+ left = Utils . applyRatio ( left ) ;
4193
+ bottom = Utils . applyRatio ( bottom ) ;
4239
4194
4240
4195
this . ctx . fillText ( text , left , bottom ) ;
4241
4196
} ;
4242
4197
4243
4198
CanvasRenderer . prototype . backgroundRepeatShape = function ( imageContainer , backgroundPosition , size , bounds , left , top , width , height , borderData ) {
4244
4199
debugger ;
4245
- size = this . applyRatio ( size ) ;
4246
- bounds = this . applyRatioToBounds ( bounds ) ;
4247
- left = this . applyRatio ( left ) ;
4248
- top = this . applyRatio ( top ) ;
4249
- width = this . applyRatio ( width ) ;
4250
- height = this . applyRatio ( height ) ;
4200
+ size = Utils . applyRatio ( size ) ;
4201
+ bounds = Utils . applyRatioToBounds ( bounds ) ;
4202
+ left = Utils . applyRatio ( left ) ;
4203
+ top = Utils . applyRatio ( top ) ;
4204
+ width = Utils . applyRatio ( width ) ;
4205
+ height = Utils . applyRatio ( height ) ;
4251
4206
4252
4207
var shape = [
4253
4208
[ "line" , Math . round ( left ) , Math . round ( top ) ] ,
@@ -4262,11 +4217,11 @@ CanvasRenderer.prototype.backgroundRepeatShape = function(imageContainer, backgr
4262
4217
4263
4218
CanvasRenderer . prototype . renderBackgroundRepeat = function ( imageContainer , backgroundPosition , size , bounds , borderLeft , borderTop ) {
4264
4219
debugger ;
4265
- bounds = this . applyRatioToBounds ( bounds ) ;
4266
- size = this . applyRatioToBounds ( size ) ;
4267
- backgroundPosition = this . applyRatioToBounds ( backgroundPosition ) ;
4268
- borderLeft = this . applyRatio ( borderLeft ) ;
4269
- borderTop = this . applyRatio ( borderTop ) ;
4220
+ bounds = Utils . applyRatioToBounds ( bounds ) ;
4221
+ size = Utils . applyRatioToBounds ( size ) ;
4222
+ backgroundPosition = Utils . applyRatioToBounds ( backgroundPosition ) ;
4223
+ borderLeft = Utils . applyRatio ( borderLeft ) ;
4224
+ borderTop = Utils . applyRatio ( borderTop ) ;
4270
4225
4271
4226
var offsetX = Math . round ( bounds . left + backgroundPosition . left + borderLeft ) , offsetY = Math . round ( bounds . top + backgroundPosition . top + borderTop ) ;
4272
4227
this . setFillStyle ( this . ctx . createPattern ( this . resizeImage ( imageContainer , size ) , "repeat" ) ) ;
@@ -4277,7 +4232,7 @@ CanvasRenderer.prototype.renderBackgroundRepeat = function(imageContainer, backg
4277
4232
4278
4233
CanvasRenderer . prototype . renderBackgroundGradient = function ( gradientImage , bounds ) {
4279
4234
debugger ;
4280
- bounds = this . applyRatioToBounds ( bounds ) ;
4235
+ bounds = Utils . applyRatioToBounds ( bounds ) ;
4281
4236
4282
4237
if ( gradientImage instanceof LinearGradientContainer ) {
4283
4238
var gradient = this . ctx . createLinearGradient (
@@ -4293,7 +4248,7 @@ CanvasRenderer.prototype.renderBackgroundGradient = function(gradientImage, boun
4293
4248
} ;
4294
4249
4295
4250
CanvasRenderer . prototype . resizeImage = function ( imageContainer , size ) {
4296
- size = this . applyRatioToBounds ( size ) ;
4251
+ size = Utils . applyRatioToBounds ( size ) ;
4297
4252
4298
4253
var image = imageContainer . image ;
4299
4254
if ( image . width === size . width && image . height === size . height ) {
@@ -4314,7 +4269,7 @@ function hasEntries(array) {
4314
4269
4315
4270
module . exports = CanvasRenderer ;
4316
4271
4317
- } , { "../lineargradientcontainer" :14 , "../log" :15 , "../renderer" :22 } ] , 24 :[ function ( require , module , exports ) {
4272
+ } , { "../lineargradientcontainer" :14 , "../log" :15 , "../renderer" :22 , "../utils" : 29 } ] , 24 :[ function ( require , module , exports ) {
4318
4273
var NodeContainer = require ( './nodecontainer' ) ;
4319
4274
4320
4275
function StackingContext ( hasOwnStacking , opacity , element , parent ) {
@@ -4676,6 +4631,58 @@ exports.parseBackgrounds = function(backgroundImage) {
4676
4631
return results ;
4677
4632
} ;
4678
4633
4634
+ exports . getDeviceRatio = function ( ) {
4635
+ return window . devicePixelRatio ;
4636
+ } ;
4637
+
4638
+ exports . applyRatio = function ( value ) {
4639
+ return value * exports . getDeviceRatio ( ) ;
4640
+ }
4641
+
4642
+ exports . applyRatioToBounds = function ( bounds ) {
4643
+ bounds . width = bounds . width * exports . getDeviceRatio ( ) ;
4644
+ bounds . top = bounds . top * exports . getDeviceRatio ( ) ;
4645
+
4646
+ //In case this is a size
4647
+ try {
4648
+ bounds . left = bounds . left * exports . getDeviceRatio ( ) ;
4649
+ bounds . height = bounds . height * exports . getDeviceRatio ( ) ;
4650
+ } catch ( e ) {
4651
+
4652
+ }
4653
+
4654
+ return bounds ;
4655
+ }
4656
+
4657
+ exports . applyRatioToPosition = function ( position ) {
4658
+ position . left = position . left * exports . getDeviceRatio ( ) ;
4659
+ position . height = position . height * exports . getDeviceRatio ( ) ;
4660
+
4661
+ return bounds ;
4662
+ }
4663
+
4664
+ exports . applyRatioToShape = function ( shape ) {
4665
+ for ( var i = 0 ; i < shape . length ; i ++ ) {
4666
+ if ( shape [ i ] instanceof Array ) {
4667
+ for ( var k = 1 ; k < shape [ i ] . length ; k ++ ) {
4668
+ shape [ i ] [ k ] = this . applyRatio ( shape [ i ] [ k ] ) ;
4669
+ }
4670
+ }
4671
+ }
4672
+ return shape ;
4673
+ }
4674
+
4675
+ exports . applyRatioToFontSize = function ( fontSize ) {
4676
+ var numericPart = parseFloat ( fontSize ) * exports . getDeviceRatio ( ) ;
4677
+ var stringPart = fontSize . replace ( / [ 0 - 9 ] / g, '' ) ;
4678
+
4679
+ fontSize = numericPart + stringPart ;
4680
+
4681
+ return fontSize ;
4682
+ }
4683
+
4684
+
4685
+
4679
4686
} , { } ] , 30 :[ function ( require , module , exports ) {
4680
4687
var GradientContainer = require ( './gradientcontainer' ) ;
4681
4688
0 commit comments