Keep the first /Subrs and /CharStrings block

Some Type1 fonts (the embedded Optima variants in orw1972.pdf) ship
two /Subrs and /CharStrings blocks wrapped in save/restore frames
gated on an Adobe hires/lores runtime switch.
In such cases, we just use the first /Subrs and /CharStrings block,
which is the one that is actually used by the font renderer in Acrobat.

It fixes #18548.
This commit is contained in:
calixteman 2026-05-20 21:41:10 +02:00 committed by Calixte Denizet
parent ea18e73de2
commit 1f8eed020f
4 changed files with 23 additions and 0 deletions

View File

@ -566,6 +566,13 @@ class Type1Parser {
},
};
let token, length, data, lenIV;
// Some fonts (e.g. those embedded in issue18548.pdf) define a second
// `/Subrs` and `/CharStrings` block that the PostScript runtime selects
// conditionally (e.g. high-resolution variants). Testing with other
// viewers shows that none of them actually use these conditional blocks,
// so we can "safely" ignore them.
let subrsParsed = false;
let charStringsParsed = false;
while ((token = this.getToken()) !== null) {
if (token !== "/") {
continue;
@ -573,6 +580,10 @@ class Type1Parser {
token = this.getToken();
switch (token) {
case "CharStrings":
if (charStringsParsed) {
break;
}
charStringsParsed = true;
// The number immediately following CharStrings must be greater or
// equal to the number of CharStrings.
this.getToken();
@ -610,6 +621,10 @@ class Type1Parser {
}
break;
case "Subrs":
if (subrsParsed) {
break;
}
subrsParsed = true;
this.readInt(); // num
this.getToken(); // read in 'array'
while (this.getToken() === "dup") {

View File

@ -922,3 +922,4 @@
!knockout_groups_test.pdf
!issue18032.pdf
!Embedded_font.pdf
!issue18548_reduced.pdf

Binary file not shown.

View File

@ -14267,5 +14267,12 @@
"md5": "b68dd5a3e6833d1af94e295fe1d60285",
"rounds": 1,
"type": "eq"
},
{
"id": "issue18548_reduced",
"file": "pdfs/issue18548_reduced.pdf",
"md5": "39d15f7f810bd89a4e5858df9c75ca4e",
"rounds": 1,
"type": "eq"
}
]