/* * Copyright (c) 2022, Matthew Olsson * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace PDF { class PDFFont : public RefCounted { public: enum class Type { Type0, Type1, TrueType }; // This is used both by Type 1 and TrueType fonts. struct CommonData { RefPtr font; RefPtr to_unicode; RefPtr encoding; HashMap widths; u16 missing_width; bool is_standard_font; PDFErrorOr load_from_dict(Document*, NonnullRefPtr, float font_size); }; static PDFErrorOr> create(Document*, NonnullRefPtr, float font_size); virtual ~PDFFont() = default; virtual u32 char_code_to_code_point(u16 char_code) const = 0; virtual float get_char_width(u16 char_code) const = 0; virtual void draw_glyph(Gfx::Painter& painter, Gfx::IntPoint point, float width, u32 char_code, Color color) = 0; virtual bool is_standard_font() const { return m_is_standard_font; } virtual Type type() const = 0; protected: static Tuple replacement_for_standard_latin_font(StringView); bool m_is_standard_font { false }; }; }