@@ -940,8 +940,7 @@ function html2canvas(nodeList, options) {
940940
941941 var node = ( ( nodeList === undefined ) ? [ document . documentElement ] : ( ( nodeList . length ) ? nodeList : [ nodeList ] ) ) [ 0 ] ;
942942 node . setAttribute ( html2canvasNodeAttribute + index , index ) ;
943- // EK 2017-03-24: Edited from `node.ownerDocument.defaultView.innerWidth, node.ownerDocument.defaultView.innerHeight,`.
944- return renderDocument ( node . ownerDocument , options , node . clientWidth , node . clientHeight , index ) . then ( function ( canvas ) {
943+ return renderDocument ( node . ownerDocument , options , node . ownerDocument . defaultView . innerWidth , node . ownerDocument . defaultView . innerHeight , index ) . then ( function ( canvas ) {
945944 if ( typeof ( options . onrendered ) === "function" ) {
946945 log ( "options.onrendered is deprecated, html2canvas returns a Promise containing the canvas" ) ;
947946 options . onrendered ( canvas ) ;
@@ -987,8 +986,9 @@ function renderWindow(node, container, options, windowWidth, windowHeight) {
987986 var support = new Support ( clonedWindow . document ) ;
988987 var imageLoader = new ImageLoader ( options , support ) ;
989988 var bounds = getBounds ( node ) ;
990- var width = options . type === "view" ? windowWidth : documentWidth ( clonedWindow . document ) ;
991- var height = options . type === "view" ? windowHeight : documentHeight ( clonedWindow . document ) ;
989+ // EK 2017-03-24: Fix offscreen rendering - changed from documentHeight(clonedWindow.document), which is just set by windowWidth anyway!.
990+ var width = options . type === "view" ? windowWidth : bounds . right ;
991+ var height = options . type === "view" ? windowHeight : bounds . bottom ;
992992 var renderer = new options . renderer ( width , height , imageLoader , options , document ) ;
993993 var parser = new NodeParser ( node , renderer , support , imageLoader , options ) ;
994994 return parser . ready . then ( function ( ) {
@@ -1751,10 +1751,11 @@ NodeContainer.prototype.parseTransformMatrix = function() {
17511751 return this . transformMatrix ;
17521752} ;
17531753
1754+ // EK 2017-03-25: Inverse transformation matrix for clip fix.
17541755NodeContainer . prototype . inverseTransform = function ( ) {
17551756 var transformData = this . parseTransform ( ) ;
17561757 return { origin : transformData . origin , matrix : matrixInverse ( transformData . matrix ) } ;
1757- }
1758+ } ;
17581759
17591760NodeContainer . prototype . parseBounds = function ( ) {
17601761 return this . bounds || ( this . bounds = this . hasTransform ( ) ? offsetBounds ( this . node ) : getBounds ( this . node ) ) ;
@@ -1797,8 +1798,9 @@ function parseMatrix(match) {
17971798 }
17981799}
17991800
1801+ // EK 2017-03-25: Inverse matrix for clip fix.
18001802function matrixInverse ( m ) {
1801- // EK 2017-03-25: This is specifically programmed to work for transform matrices.
1803+ // This is programmed specifically for transform matrices, which have a fixed structure .
18021804 var a = m [ 0 ] , b = m [ 2 ] , c = m [ 4 ] , d = m [ 1 ] , e = m [ 3 ] , f = m [ 5 ] ;
18031805 var det = a * e - b * d ;
18041806 var M = [ e , - d , - b , a , b * f - c * e , c * d - a * f ] . map ( function ( val ) { return val / det } ) ;
@@ -2226,7 +2228,7 @@ NodeParser.prototype.paintRadio = function(container) {
22262228 if ( container . node . checked ) {
22272229 this . renderer . circle ( Math . ceil ( bounds . left + size / 4 ) + 1 , Math . ceil ( bounds . top + size / 4 ) + 1 , Math . floor ( size / 2 ) , new Color ( '#424242' ) ) ;
22282230 }
2229- } , this ) ;
2231+ } , this , container ) ;
22302232} ;
22312233
22322234NodeParser . prototype . paintFormValue = function ( container ) {
@@ -2261,13 +2263,13 @@ NodeParser.prototype.paintFormValue = function(container) {
22612263NodeParser . prototype . paintText = function ( container ) {
22622264 container . applyTextTransform ( ) ;
22632265 var characters = punycode . ucs2 . decode ( container . node . data ) ;
2264- // EK 2017-03-25 : Ligature fix.
2266+ // EK 2017-03-26 : Ligature fix.
22652267 var wordRendering = ( ! this . options . letterRendering || noLetterSpacing ( container ) ) && ! hasUnicode ( container . node . data ) ;
22662268 var textList = wordRendering ? getWords ( characters ) : characters . map ( function ( character ) {
22672269 return punycode . ucs2 . encode ( [ character ] ) ;
22682270 } ) ;
22692271 if ( ! wordRendering ) {
2270- container . parent . node . style . fontFeatureSettings = '"liga" 0 ' ;
2272+ container . parent . node . style . fontVariantLigatures = 'none ' ;
22712273 }
22722274
22732275 var weight = container . parent . fontWeight ( ) ;
@@ -2992,7 +2994,7 @@ function CanvasRenderer(width, height) {
29922994 if ( ! this . options . canvas ) {
29932995 // EK 2017-03-25: Add scale/dpi.
29942996 if ( this . options . dpi ) {
2995- // Default canvas is 96dpi (1 CSS inch = 96px).
2997+ // Default canvas is 96dpi (1 CSS inch = 96px).
29962998 this . options . scale = this . options . dpi / 96 ;
29972999 }
29983000 if ( this . options . scale ) {
@@ -3046,13 +3048,13 @@ CanvasRenderer.prototype.shadow = function(left, top, width, height, shadows) {
30463048 }
30473049 var drawShadow = function ( shadow ) {
30483050 var info = parseShadow ( shadow ) ;
3049- if ( ! info . inset ) {
3050- context . shadowOffsetX = info . x ;
3051- context . shadowOffsetY = info . y ;
3052- context . shadowColor = info . color ;
3053- context . shadowBlur = info . blur ;
3054- context . fill ( ) ;
3055- }
3051+ if ( ! info . inset ) {
3052+ context . shadowOffsetX = info . x ;
3053+ context . shadowOffsetY = info . y ;
3054+ context . shadowColor = info . color ;
3055+ context . shadowBlur = info . blur ;
3056+ context . fill ( ) ;
3057+ }
30563058 }
30573059
30583060 // Create a bounding rectangle with arbitrary opaque color.
@@ -3108,16 +3110,17 @@ CanvasRenderer.prototype.drawImage = function(imageContainer, sx, sy, sw, sh, dx
31083110
31093111CanvasRenderer . prototype . clip = function ( shapes , callback , context , container ) {
31103112 // EK 2017-03-25: Clip transform fix.
3111- var hasTransform = container && container . hasTransform ( ) ;
31123113 this . ctx . save ( ) ;
3113- if ( hasTransform ) {
3114+ if ( container && container . hasTransform ( ) ) {
31143115 this . setTransform ( container . inverseTransform ( ) ) ;
3115- }
3116- shapes . filter ( hasEntries ) . forEach ( function ( shape ) {
3117- this . shape ( shape ) . clip ( ) ;
3118- } , this ) ;
3119- if ( hasTransform ) {
3116+ shapes . filter ( hasEntries ) . forEach ( function ( shape ) {
3117+ this . shape ( shape ) . clip ( ) ;
3118+ } , this ) ;
31203119 this . setTransform ( container . parseTransform ( ) ) ;
3120+ } else {
3121+ shapes . filter ( hasEntries ) . forEach ( function ( shape ) {
3122+ this . shape ( shape ) . clip ( ) ;
3123+ } , this ) ;
31213124 }
31223125 callback . call ( context ) ;
31233126 this . ctx . restore ( ) ;
@@ -3147,19 +3150,10 @@ CanvasRenderer.prototype.shape = function(shape) {
31473150 this . ctx . closePath ( ) ;
31483151 return this . ctx ;
31493152} ;
3150- CanvasRenderer . prototype . shape2 = function ( shape ) {
3151- this . ctx . beginPath ( ) ;
3152- shape . forEach ( function ( point , index ) {
3153- if ( point [ 0 ] === "rect" ) {
3154- this . ctx . rect . apply ( this . ctx , point . slice ( 1 ) ) ;
3155- } else {
3156- this . ctx [ ( index === 0 ) ? "moveTo" : point [ 0 ] + "To" ] . apply ( this . ctx , point . slice ( 1 ) ) ;
3157- }
3158- } , this ) ;
3159- return this . ctx ;
3160- } ;
31613153
31623154CanvasRenderer . prototype . font = function ( color , style , variant , weight , size , family ) {
3155+ // EK 2017-03-26: Ligature fix.
3156+ variant = / ^ ( n o r m a l | s m a l l - c a p s ) $ / i. test ( variant ) ? variant : '' ;
31633157 this . setFillStyle ( color ) . font = [ style , variant , weight , size , family ] . join ( " " ) . split ( "," ) [ 0 ] ;
31643158} ;
31653159
0 commit comments