mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-02-08 00:21:11 +01:00
Merge pull request #20499 from AtiX/master
Improves text rendering performance by skipping unnecessary pattern calculations
This commit is contained in:
commit
f824f38e30
@ -2062,7 +2062,20 @@ class CanvasGraphics {
|
||||
}
|
||||
|
||||
let patternFillTransform, patternStrokeTransform;
|
||||
if (current.patternFill) {
|
||||
|
||||
// Only compute pattern transforms if the text rendering mode actually
|
||||
// uses fill/stroke. This avoids expensive pattern calculations each call
|
||||
// when a patternFill/patternStroke is set, but unused.
|
||||
const fillStrokeMode =
|
||||
current.textRenderingMode & TextRenderingMode.FILL_STROKE_MASK;
|
||||
const needsFill =
|
||||
fillStrokeMode === TextRenderingMode.FILL ||
|
||||
fillStrokeMode === TextRenderingMode.FILL_STROKE;
|
||||
const needsStroke =
|
||||
fillStrokeMode === TextRenderingMode.STROKE ||
|
||||
fillStrokeMode === TextRenderingMode.FILL_STROKE;
|
||||
|
||||
if (needsFill && current.patternFill) {
|
||||
ctx.save();
|
||||
const pattern = current.fillColor.getPattern(
|
||||
ctx,
|
||||
@ -2076,7 +2089,7 @@ class CanvasGraphics {
|
||||
ctx.fillStyle = pattern;
|
||||
}
|
||||
|
||||
if (current.patternStroke) {
|
||||
if (needsStroke && current.patternStroke) {
|
||||
ctx.save();
|
||||
const pattern = current.strokeColor.getPattern(
|
||||
ctx,
|
||||
@ -2093,12 +2106,7 @@ class CanvasGraphics {
|
||||
let lineWidth = current.lineWidth;
|
||||
const scale = current.textMatrixScale;
|
||||
if (scale === 0 || lineWidth === 0) {
|
||||
const fillStrokeMode =
|
||||
current.textRenderingMode & TextRenderingMode.FILL_STROKE_MASK;
|
||||
if (
|
||||
fillStrokeMode === TextRenderingMode.STROKE ||
|
||||
fillStrokeMode === TextRenderingMode.FILL_STROKE
|
||||
) {
|
||||
if (needsStroke) {
|
||||
lineWidth = this.getSinglePixelWidth();
|
||||
}
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user