mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-06-24 17:05:47 +02: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;
|
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();
|
ctx.save();
|
||||||
const pattern = current.fillColor.getPattern(
|
const pattern = current.fillColor.getPattern(
|
||||||
ctx,
|
ctx,
|
||||||
@ -2076,7 +2089,7 @@ class CanvasGraphics {
|
|||||||
ctx.fillStyle = pattern;
|
ctx.fillStyle = pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current.patternStroke) {
|
if (needsStroke && current.patternStroke) {
|
||||||
ctx.save();
|
ctx.save();
|
||||||
const pattern = current.strokeColor.getPattern(
|
const pattern = current.strokeColor.getPattern(
|
||||||
ctx,
|
ctx,
|
||||||
@ -2093,12 +2106,7 @@ class CanvasGraphics {
|
|||||||
let lineWidth = current.lineWidth;
|
let lineWidth = current.lineWidth;
|
||||||
const scale = current.textMatrixScale;
|
const scale = current.textMatrixScale;
|
||||||
if (scale === 0 || lineWidth === 0) {
|
if (scale === 0 || lineWidth === 0) {
|
||||||
const fillStrokeMode =
|
if (needsStroke) {
|
||||||
current.textRenderingMode & TextRenderingMode.FILL_STROKE_MASK;
|
|
||||||
if (
|
|
||||||
fillStrokeMode === TextRenderingMode.STROKE ||
|
|
||||||
fillStrokeMode === TextRenderingMode.FILL_STROKE
|
|
||||||
) {
|
|
||||||
lineWidth = this.getSinglePixelWidth();
|
lineWidth = this.getSinglePixelWidth();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user