diff --git a/Userland/Libraries/LibPDF/CommonNames.h b/Userland/Libraries/LibPDF/CommonNames.h index d23bdb8987..6a05211514 100644 --- a/Userland/Libraries/LibPDF/CommonNames.h +++ b/Userland/Libraries/LibPDF/CommonNames.h @@ -32,6 +32,7 @@ X(CF) \ X(CFM) \ X(CIDFontType0) \ + X(CIDFontType0C) \ X(CIDFontType2) \ X(CIDSystemInfo) \ X(CIDToGIDMap) \ diff --git a/Userland/Libraries/LibPDF/Fonts/Type0Font.cpp b/Userland/Libraries/LibPDF/Fonts/Type0Font.cpp index 62b8143339..78596fc86a 100644 --- a/Userland/Libraries/LibPDF/Fonts/Type0Font.cpp +++ b/Userland/Libraries/LibPDF/Fonts/Type0Font.cpp @@ -6,6 +6,7 @@ #include #include +#include #include namespace PDF { @@ -18,9 +19,50 @@ public: class CIDFontType0 : public CIDFontType { public: + static PDFErrorOr> create(Document*, NonnullRefPtr const& descendant); + PDFErrorOr draw_string(Gfx::Painter&, Gfx::FloatPoint, ByteString const&) override; + +private: + CIDFontType0(RefPtr font_program) + : m_font_program(move(font_program)) + { + } + + RefPtr m_font_program; }; +PDFErrorOr> CIDFontType0::create(Document* document, NonnullRefPtr const& descendant) +{ + auto descriptor = TRY(descendant->get_dict(document, CommonNames::FontDescriptor)); + + RefPtr font_program; + + // See spec comment in CIDFontType0::draw_string(). + if (descriptor->contains(CommonNames::FontFile3)) { + auto font_file_stream = TRY(descriptor->get_stream(document, CommonNames::FontFile3)); + auto font_file_dict = font_file_stream->dict(); + DeprecatedFlyString subtype; + if (font_file_dict->contains(CommonNames::Subtype)) + subtype = font_file_dict->get_name(CommonNames::Subtype)->name(); + if (subtype == CommonNames::CIDFontType0C) { + // FIXME: Call CFF::create() and assign the result to font_program once CFF::create() can handle CID-keyed fonts. + return Error::rendering_unsupported_error("Type0 font CIDFontType0: support for CIDFontType0C not yet implemented"); + } else { + // FIXME: Add support for /OpenType. + dbgln("CIDFontType0: unsupported FontFile3 subtype '{}'", subtype); + return Error::rendering_unsupported_error("Type0 font CIDFontType0: support for non-CIDFontType0C not yet implemented"); + } + } + + if (!font_program) { + // FIXME: Should we use a fallback font? How common is this for type 0 fonts? + return Error::malformed_error("CIDFontType0: missing FontFile3"); + } + + return TRY(adopt_nonnull_own_or_enomem(new (nothrow) CIDFontType0(move(font_program)))); +} + PDFErrorOr CIDFontType0::draw_string(Gfx::Painter&, Gfx::FloatPoint, ByteString const&) { // ISO 32000 (PDF 2.0) 9.7.4.2 Glyph selection in CIDFonts @@ -114,7 +156,7 @@ PDFErrorOr Type0Font::initialize(Document* document, NonnullRefPtrget_name(document, CommonNames::Subtype))->name(); if (subtype == CommonNames::CIDFontType0) { // CFF-based - m_cid_font_type = TRY(try_make()); + m_cid_font_type = TRY(CIDFontType0::create(document, descendant_font)); } else if (subtype == CommonNames::CIDFontType2) { // TrueType-based m_cid_font_type = TRY(CIDFontType2::create(document, descendant_font, font_size));