@@ -63,6 +63,9 @@ const FULL_CHUNK_HEIGHT = 16;
6363// creating a new DOMMatrix object each time we need it.
6464const SCALE_MATRIX = new DOMMatrix ( ) ;
6565
66+ // Used to get some coordinates.
67+ const XY = new Float32Array ( 2 ) ;
68+
6669/**
6770 * Overrides certain methods on a 2d ctx so that when they are called they
6871 * will also call the same method on the destCtx. The methods that are
@@ -522,9 +525,9 @@ class CanvasExtraState {
522525 }
523526 // Stroked paths can be outside of the path bounding box by 1/2 the line
524527 // width.
525- const scale = Util . singularValueDecompose2dScale ( transform ) ;
526- const xStrokePad = ( scale [ 0 ] * this . lineWidth ) / 2 ;
527- const yStrokePad = ( scale [ 1 ] * this . lineWidth ) / 2 ;
528+ Util . singularValueDecompose2dScale ( transform , XY ) ;
529+ const xStrokePad = ( XY [ 0 ] * this . lineWidth ) / 2 ;
530+ const yStrokePad = ( XY [ 1 ] * this . lineWidth ) / 2 ;
528531 box [ 0 ] -= xStrokePad ;
529532 box [ 1 ] -= yStrokePad ;
530533 box [ 2 ] += xStrokePad ;
@@ -777,15 +780,14 @@ function getImageSmoothingEnabled(transform, interpolate) {
777780 return true ;
778781 }
779782
780- const scale = Util . singularValueDecompose2dScale ( transform ) ;
783+ Util . singularValueDecompose2dScale ( transform , XY ) ;
781784 // Round to a 32bit float so that `<=` check below will pass for numbers that
782785 // are very close, but not exactly the same 64bit floats.
783- scale [ 0 ] = Math . fround ( scale [ 0 ] ) ;
784- scale [ 1 ] = Math . fround ( scale [ 1 ] ) ;
785786 const actualScale = Math . fround (
786787 OutputScale . pixelRatio * PixelsPerInch . PDF_TO_CSS_UNITS
787788 ) ;
788- return scale [ 0 ] <= actualScale && scale [ 1 ] <= actualScale ;
789+ // `XY` is a Float32Array.
790+ return XY [ 0 ] <= actualScale && XY [ 1 ] <= actualScale ;
789791}
790792
791793const LINE_CAP_STYLES = [ "butt" , "round" , "square" ] ;
@@ -1958,12 +1960,12 @@ class CanvasGraphics {
19581960 [ a , b , c , d , 0 , 0 ] ,
19591961 invPatternTransform
19601962 ) ;
1961- const [ sx , sy ] = Util . singularValueDecompose2dScale ( transf ) ;
1963+ Util . singularValueDecompose2dScale ( transf , XY ) ;
19621964
19631965 // Cancel the pattern scaling of the line width.
19641966 // If sx and sy are different, unfortunately we can't do anything and
19651967 // we'll have a rendering bug.
1966- ctx . lineWidth *= Math . max ( sx , sy ) / fontSize ;
1968+ ctx . lineWidth *= Math . max ( XY [ 0 ] , XY [ 1 ] ) / fontSize ;
19671969 ctx . stroke (
19681970 this . #getScaledPath( path , currentTransform , patternStrokeTransform )
19691971 ) ;
@@ -2639,9 +2641,7 @@ class CanvasGraphics {
26392641 rect [ 2 ] = width ;
26402642 rect [ 3 ] = height ;
26412643
2642- const [ scaleX , scaleY ] = Util . singularValueDecompose2dScale (
2643- getCurrentTransform ( this . ctx )
2644- ) ;
2644+ Util . singularValueDecompose2dScale ( getCurrentTransform ( this . ctx ) , XY ) ;
26452645 const { viewportScale } = this ;
26462646 const canvasWidth = Math . ceil (
26472647 width * this . outputScaleX * viewportScale
@@ -2659,7 +2659,7 @@ class CanvasGraphics {
26592659 this . annotationCanvas . savedCtx = this . ctx ;
26602660 this . ctx = context ;
26612661 this . ctx . save ( ) ;
2662- this . ctx . setTransform ( scaleX , 0 , 0 , - scaleY , 0 , height * scaleY ) ;
2662+ this . ctx . setTransform ( XY [ 0 ] , 0 , 0 , - XY [ 1 ] , 0 , height * XY [ 1 ] ) ;
26632663
26642664 resetCtxToDefault ( this . ctx ) ;
26652665 } else {
0 commit comments