Use canvas context text primitives when the font file is missing

It fixes #20065.

The only to get a path (from the path generator) is when the font is embedded.
So when we need a path (disableFontFace: true or when we want to use a pattern for stroking/filling), it's impossible
to fulfil.
This commit is contained in:
Calixte Denizet 2025-07-17 18:01:47 +02:00
parent e4585c2452
commit 8b17e5ecd8
4 changed files with 168 additions and 5 deletions

View File

@ -1625,6 +1625,9 @@ class CanvasGraphics {
const newPath = new Path2D(); const newPath = new Path2D();
const invTransf = ctx.getTransform().invertSelf(); const invTransf = ctx.getTransform().invertSelf();
for (const { transform, x, y, fontSize, path } of paths) { for (const { transform, x, y, fontSize, path } of paths) {
if (!path) {
continue; // Skip empty paths.
}
newPath.addPath( newPath.addPath(
path, path,
new DOMMatrix(transform) new DOMMatrix(transform)
@ -1768,15 +1771,16 @@ class CanvasGraphics {
let path; let path;
if ( if (
font.disableFontFace || (font.disableFontFace ||
isAddToPathSet || isAddToPathSet ||
patternFill || patternFill ||
patternStroke patternStroke) &&
!font.missingFile
) { ) {
path = font.getPathGenerator(this.commonObjs, character); path = font.getPathGenerator(this.commonObjs, character);
} }
if (font.disableFontFace || patternFill || patternStroke) { if (path && (font.disableFontFace || patternFill || patternStroke)) {
ctx.save(); ctx.save();
ctx.translate(x, y); ctx.translate(x, y);
ctx.scale(fontSize, -fontSize); ctx.scale(fontSize, -fontSize);

View File

@ -733,3 +733,4 @@
!firefox_logo.pdf !firefox_logo.pdf
!issue20062.pdf !issue20062.pdf
!issue20102.pdf !issue20102.pdf
!issue20065.pdf

150
test/pdfs/issue20065.pdf Executable file

File diff suppressed because one or more lines are too long

View File

@ -12213,5 +12213,13 @@
"popupRef": "27R" "popupRef": "27R"
} }
} }
},
{
"id": "issue20065",
"file": "pdfs/issue20065.pdf",
"md5": "39ad13514d0b0108e4ae42f4b1422839",
"rounds": 1,
"disableFontFace": true,
"type": "eq"
} }
] ]