From eeada4678c6fc495d3f90a2dd181ab0ad7fd4902 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 16 Oct 2023 16:28:13 -0400 Subject: [PATCH] LibPDF: Postpone CFF encoding processing after Top DICT has been read The encoding offset defaults to 0, i.e. the Standard Encoding. That means reading the encoding only if the tag is present causes us to not read it if a font uses the Standard Encoding. Now, we always read an encoding, even if it's the (implicit) default one. --- Userland/Libraries/LibPDF/Fonts/CFF.cpp | 33 +++++++++++++------------ 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/Userland/Libraries/LibPDF/Fonts/CFF.cpp b/Userland/Libraries/LibPDF/Fonts/CFF.cpp index a6851a17f9..e9ce4224df 100644 --- a/Userland/Libraries/LibPDF/Fonts/CFF.cpp +++ b/Userland/Libraries/LibPDF/Fonts/CFF.cpp @@ -72,8 +72,7 @@ PDFErrorOr> CFF::create(ReadonlyBytes const& cff_bytes, RefPt // CFF spec, "8 Top DICT INDEX" int charset_offset = 0; - Vector encoding_codes; // Maps GID to its codepoint. - HashMap encoding_supplemental; // Maps codepoint to SID. + int encoding_offset = 0; auto charstrings_offset = 0; Vector subroutines; float defaultWidthX = 0; @@ -113,22 +112,8 @@ PDFErrorOr> CFF::create(ReadonlyBytes const& cff_bytes, RefPt dbgln("CFF: has unimplemented SyntheticBase, might not look right"); break; case TopDictOperator::Encoding: { - auto encoding_offset = 0; if (!operands.is_empty()) encoding_offset = operands[0].get(); - - // CFF spec, "Table 16 Encoding ID" - switch (encoding_offset) { - case 0: - dbgln("CFF: Built-in Standard Encoding not yet implemented"); - break; - case 1: - dbgln("CFF: Built-in Expert Encoding not yet implemented"); - break; - default: - encoding_codes = TRY(parse_encoding(Reader(cff_bytes.slice(encoding_offset)), encoding_supplemental)); - break; - } break; } case TopDictOperator::Charset: { @@ -186,6 +171,22 @@ PDFErrorOr> CFF::create(ReadonlyBytes const& cff_bytes, RefPt // Create glyphs (now that we have the subroutines) and associate missing information to store them and their encoding auto glyphs = TRY(parse_charstrings(Reader(cff_bytes.slice(charstrings_offset)), subroutines)); + // CFF spec, "Table 16 Encoding ID" + // FIXME: Only read this if the built-in encoding is actually needed? (ie. `if (!encoding)`) + Vector encoding_codes; // Maps GID to its codepoint. + HashMap encoding_supplemental; // Maps codepoint to SID. + switch (encoding_offset) { + case 0: + dbgln("CFF: Built-in Standard Encoding not yet implemented"); + break; + case 1: + dbgln("CFF: Built-in Expert Encoding not yet implemented"); + break; + default: + encoding_codes = TRY(parse_encoding(Reader(cff_bytes.slice(encoding_offset)), encoding_supplemental)); + break; + } + // CFF spec, "Table 22 Charset ID" Vector charset; switch (charset_offset) {