From 358870998684a1b30e7f79f60fa55e30754bcb32 Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Sun, 15 Jan 2023 11:29:12 +0800 Subject: [PATCH] LibPDF: Load Type1C fonts when found Now that our CFF parser is working we can load Type1C fonts in PDF, which are backed by a CFF stream. --- Userland/Libraries/LibPDF/CommonNames.h | 1 + Userland/Libraries/LibPDF/Fonts/Type1Font.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/Userland/Libraries/LibPDF/CommonNames.h b/Userland/Libraries/LibPDF/CommonNames.h index 907f3ff524..33a487733d 100644 --- a/Userland/Libraries/LibPDF/CommonNames.h +++ b/Userland/Libraries/LibPDF/CommonNames.h @@ -132,6 +132,7 @@ A(Title) \ A(ToUnicode) \ A(Type) \ + A(Type1C) \ A(U) \ A(UCR) \ A(UseBlackPTComp) \ diff --git a/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp b/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp index 76ff822a52..fd93c815de 100644 --- a/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp +++ b/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -19,6 +20,16 @@ PDFErrorOr Type1Font::parse_data(Document* document, NonnullRef if (!data.is_standard_font) { auto descriptor = TRY(dict->get_dict(document, CommonNames::FontDescriptor)); + if (descriptor->contains(CommonNames::FontFile3)) { + auto font_file_stream = TRY(descriptor->get_stream(document, CommonNames::FontFile3)); + auto font_file_dict = font_file_stream->dict(); + if (font_file_dict->contains(CommonNames::Subtype) && font_file_dict->get_name(CommonNames::Subtype)->name() == CommonNames::Type1C) { + data.font_program = TRY(CFF::create(font_file_stream->bytes(), data.encoding)); + if (!data.encoding) + data.encoding = data.font_program->encoding(); + return data; + } + } if (!descriptor->contains(CommonNames::FontFile)) return data;