diff --git a/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp b/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp index 5c1890ea22..671047d449 100644 --- a/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp +++ b/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp @@ -49,43 +49,39 @@ PDFErrorOr Type1Font::initialize(Document* document, NonnullRefPtr Type1Font::get_glyph_width(u8 char_code) const { - if (m_font) - return m_font->glyph_width(char_code); + if (m_fallback_font_painter) + return m_fallback_font_painter->get_glyph_width(char_code); return OptionalNone {}; } void Type1Font::set_font_size(float font_size) { - if (m_font) - m_font = m_font->with_size((font_size * POINTS_PER_INCH) / DEFAULT_DPI); + if (m_fallback_font_painter) + m_fallback_font_painter->set_font_size(font_size); } PDFErrorOr Type1Font::draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Renderer const& renderer) { auto style = renderer.state().paint_style; - if (!m_font_program) { - // Undo shift in Glyf::Glyph::append_simple_path() via OpenType::Font::rasterize_glyph(). - auto position = point.translated(0, -m_font->pixel_metrics().ascent); - // FIXME: Bounding box and sample point look to be pretty wrong - if (style.has()) { - painter.draw_glyph(position, char_code, *m_font, style.get()); - } else { - style.get>()->paint(Gfx::IntRect(position.x(), position.y(), width, 0), [&](auto sample) { - painter.draw_glyph(position, char_code, *m_font, sample(Gfx::IntPoint(position.x(), position.y()))); - }); - } - return {}; - } + if (!m_font_program) + return m_fallback_font_painter->draw_glyph(painter, point, width, char_code, renderer); auto effective_encoding = encoding(); if (!effective_encoding) diff --git a/Userland/Libraries/LibPDF/Fonts/Type1Font.h b/Userland/Libraries/LibPDF/Fonts/Type1Font.h index 454905e22d..d327f96a00 100644 --- a/Userland/Libraries/LibPDF/Fonts/Type1Font.h +++ b/Userland/Libraries/LibPDF/Fonts/Type1Font.h @@ -8,6 +8,7 @@ #include #include +#include #include namespace PDF { @@ -34,7 +35,7 @@ protected: private: DeprecatedFlyString m_base_font_name; RefPtr m_font_program; - RefPtr m_font; + OwnPtr m_fallback_font_painter; HashMap> m_glyph_cache; };