diff --git a/Userland/Libraries/LibPDF/Fonts/PDFFont.h b/Userland/Libraries/LibPDF/Fonts/PDFFont.h index 0b28012c57..fb732addf2 100644 --- a/Userland/Libraries/LibPDF/Fonts/PDFFont.h +++ b/Userland/Libraries/LibPDF/Fonts/PDFFont.h @@ -6,18 +6,33 @@ #pragma once +#include #include namespace PDF { class PDFFont : public RefCounted { public: + enum class Type { + Type0, + Type1, + TrueType + }; + static PDFErrorOr> create(Document*, NonnullRefPtr); virtual ~PDFFont() = default; virtual u32 char_code_to_code_point(u16 char_code) const = 0; virtual float get_char_width(u16 char_code, float font_size) const = 0; + + virtual void draw_glyph(Gfx::Painter& painter, Gfx::IntPoint const& point, float width, u32 code_point, Color color) = 0; + + virtual bool is_standard_font() const { return m_is_standard_font; } + virtual Type type() const = 0; + +protected: + bool m_is_standard_font { false }; }; } diff --git a/Userland/Libraries/LibPDF/Fonts/TrueTypeFont.h b/Userland/Libraries/LibPDF/Fonts/TrueTypeFont.h index ffef41717e..b2ffcbce75 100644 --- a/Userland/Libraries/LibPDF/Fonts/TrueTypeFont.h +++ b/Userland/Libraries/LibPDF/Fonts/TrueTypeFont.h @@ -21,6 +21,10 @@ public: u32 char_code_to_code_point(u16 char_code) const override; float get_char_width(u16 char_code, float font_size) const override; + void draw_glyph(Gfx::Painter&, Gfx::IntPoint const&, float, u32, Color) override {}; + + Type type() const override { return PDFFont::Type::TrueType; } + private: NonnullRefPtr m_ttf_font; Type1Font::Data m_data; diff --git a/Userland/Libraries/LibPDF/Fonts/Type0Font.h b/Userland/Libraries/LibPDF/Fonts/Type0Font.h index 7f17d96f5e..9221867d78 100644 --- a/Userland/Libraries/LibPDF/Fonts/Type0Font.h +++ b/Userland/Libraries/LibPDF/Fonts/Type0Font.h @@ -26,6 +26,10 @@ public: u32 char_code_to_code_point(u16 char_code) const override; float get_char_width(u16 char_code, float font_size) const override; + void draw_glyph(Gfx::Painter&, Gfx::IntPoint const&, float, u32, Color) override {}; + + Type type() const override { return PDFFont::Type::Type0; } + private: CIDSystemInfo m_system_info; HashMap m_widths; diff --git a/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp b/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp index cd95238182..4e8327f640 100644 --- a/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp +++ b/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp @@ -68,7 +68,7 @@ PDFErrorOr Type1Font::parse_data(Document* document, NonnullRef if (descriptor->contains(CommonNames::MissingWidth)) missing_width = descriptor->get_value(CommonNames::MissingWidth).to_int(); - return Type1Font::Data { to_unicode, encoding.release_nonnull(), move(widths), missing_width }; + return Type1Font::Data { to_unicode, encoding.release_nonnull(), move(widths), missing_width, false }; } PDFErrorOr> Type1Font::create(Document* document, NonnullRefPtr dict) @@ -80,6 +80,7 @@ PDFErrorOr> Type1Font::create(Document* document, Nonnu Type1Font::Type1Font(Data data) : m_data(move(data)) { + m_is_standard_font = data.is_standard_font; } u32 Type1Font::char_code_to_code_point(u16 char_code) const diff --git a/Userland/Libraries/LibPDF/Fonts/Type1Font.h b/Userland/Libraries/LibPDF/Fonts/Type1Font.h index 18608cb215..75acb2739d 100644 --- a/Userland/Libraries/LibPDF/Fonts/Type1Font.h +++ b/Userland/Libraries/LibPDF/Fonts/Type1Font.h @@ -19,6 +19,7 @@ public: NonnullRefPtr encoding; HashMap widths; u16 missing_width; + bool is_standard_font; }; static PDFErrorOr parse_data(Document*, NonnullRefPtr font_dict); @@ -31,6 +32,10 @@ public: u32 char_code_to_code_point(u16 char_code) const override; float get_char_width(u16 char_code, float font_size) const override; + void draw_glyph(Gfx::Painter&, Gfx::IntPoint const&, float, u32, Color) override {}; + + Type type() const override { return PDFFont::Type::Type1; } + private: Data m_data; };