From 6f783929dd01b0049e872ae3cefb5800988d79b7 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 13 Oct 2023 10:34:27 -0400 Subject: [PATCH] LibPDF: Implement support for CFF charset format 2 I haven't seen this being used in the wild (yet), but it's easy to implement, and with this we support all charset formats. So we can now mention if we see a format we don't know about. --- Userland/Libraries/LibPDF/Fonts/CFF.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Userland/Libraries/LibPDF/Fonts/CFF.cpp b/Userland/Libraries/LibPDF/Fonts/CFF.cpp index d12c27841b..de377affa2 100644 --- a/Userland/Libraries/LibPDF/Fonts/CFF.cpp +++ b/Userland/Libraries/LibPDF/Fonts/CFF.cpp @@ -637,6 +637,18 @@ PDFErrorOr> CFF::parse_charset(Reader&& reader, size for (SID sid = first_sid; left >= 0; left--, sid++) TRY(names.try_append(resolve_sid(sid, strings))); } + } else if (format == 2) { + // CFF spec, "Table 20 Format 2" + // "Format 2 differs from format 1 only in the size of the Left field in each range." + while (names.size() < glyph_count - 1) { + // CFF spec, "Table 21 Range2 Format" + auto first_sid = TRY(reader.try_read>()); + int left = TRY(reader.try_read()); + for (SID sid = first_sid; left >= 0; left--, sid++) + TRY(names.try_append(resolve_sid(sid, strings))); + } + } else { + dbgln("CFF: Unknown charset format {}", format); } return names; }