From 96a4936567762bf8fc80cf0d0d2fe5993365781b Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 12 Oct 2023 11:05:02 -0400 Subject: [PATCH] LibPDF: Checking for built-in CFF encodings Only prints a warning for them for now. Also warn on the not-yet-implemented encoding supplement. --- Userland/Libraries/LibPDF/Fonts/CFF.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibPDF/Fonts/CFF.cpp b/Userland/Libraries/LibPDF/Fonts/CFF.cpp index 90428f13df..4b60978056 100644 --- a/Userland/Libraries/LibPDF/Fonts/CFF.cpp +++ b/Userland/Libraries/LibPDF/Fonts/CFF.cpp @@ -115,7 +115,19 @@ PDFErrorOr> CFF::create(ReadonlyBytes const& cff_bytes, RefPt auto encoding_offset = 0; if (!operands.is_empty()) encoding_offset = operands[0].get(); - encoding_codes = TRY(parse_encoding(Reader(cff_bytes.slice(encoding_offset)))); + + // 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)))); + break; + } break; } case TopDictOperator::Charset: { @@ -704,7 +716,7 @@ PDFErrorOr> CFF::parse_encoding(Reader&& reader) // CFF spec, "12 Encodings" Vector encoding_codes; auto format_raw = TRY(reader.try_read()); - // TODO: support encoding supplements when highest bit is set + auto format = format_raw & 0x7f; if (format == 0) { auto n_codes = TRY(reader.try_read()); @@ -722,6 +734,11 @@ PDFErrorOr> CFF::parse_encoding(Reader&& reader) } } else return error(DeprecatedString::formatted("Invalid encoding format: {}", format)); + + // TODO: support encoding supplements when highest bit is set (tables 14 and 15). + if (format_raw & 0x80) + dbgln("CFF: Support for multiply-encoded glyphs not yet implemented"); + return encoding_codes; }