@@ -2062,7 +2062,20 @@ class CanvasGraphics {
20622062 }
20632063
20642064 let patternFillTransform , patternStrokeTransform ;
2065- if ( current . patternFill ) {
2065+
2066+ // Only compute pattern transforms if the text rendering mode actually
2067+ // uses fill/stroke. This avoids expensive pattern calculations each call
2068+ // when a patternFill/patternStroke is set, but unused.
2069+ const fillStrokeMode =
2070+ current . textRenderingMode & TextRenderingMode . FILL_STROKE_MASK ;
2071+ const needsFill =
2072+ fillStrokeMode === TextRenderingMode . FILL ||
2073+ fillStrokeMode === TextRenderingMode . FILL_STROKE ;
2074+ const needsStroke =
2075+ fillStrokeMode === TextRenderingMode . STROKE ||
2076+ fillStrokeMode === TextRenderingMode . FILL_STROKE ;
2077+
2078+ if ( needsFill && current . patternFill ) {
20662079 ctx . save ( ) ;
20672080 const pattern = current . fillColor . getPattern (
20682081 ctx ,
@@ -2076,7 +2089,7 @@ class CanvasGraphics {
20762089 ctx . fillStyle = pattern ;
20772090 }
20782091
2079- if ( current . patternStroke ) {
2092+ if ( needsStroke && current . patternStroke ) {
20802093 ctx . save ( ) ;
20812094 const pattern = current . strokeColor . getPattern (
20822095 ctx ,
@@ -2093,12 +2106,7 @@ class CanvasGraphics {
20932106 let lineWidth = current . lineWidth ;
20942107 const scale = current . textMatrixScale ;
20952108 if ( scale === 0 || lineWidth === 0 ) {
2096- const fillStrokeMode =
2097- current . textRenderingMode & TextRenderingMode . FILL_STROKE_MASK ;
2098- if (
2099- fillStrokeMode === TextRenderingMode . STROKE ||
2100- fillStrokeMode === TextRenderingMode . FILL_STROKE
2101- ) {
2109+ if ( needsStroke ) {
21022110 lineWidth = this . getSinglePixelWidth ( ) ;
21032111 }
21042112 } else {
0 commit comments