From 126a0be595963a214804f6d8f4899c6f62433e93 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 14 Nov 2023 10:18:36 -0500 Subject: [PATCH] LibPDF: Pass Renderer to SimpleFont::draw_glyph() This makes it available in Type3Font::draw_glyph(). No behavior change. --- Userland/Libraries/LibPDF/Fonts/SimpleFont.cpp | 4 +--- Userland/Libraries/LibPDF/Fonts/SimpleFont.h | 2 +- Userland/Libraries/LibPDF/Fonts/TrueTypeFont.cpp | 5 ++++- Userland/Libraries/LibPDF/Fonts/TrueTypeFont.h | 2 +- Userland/Libraries/LibPDF/Fonts/Type1Font.cpp | 5 ++++- Userland/Libraries/LibPDF/Fonts/Type1Font.h | 2 +- Userland/Libraries/LibPDF/Fonts/Type3Font.cpp | 2 +- Userland/Libraries/LibPDF/Fonts/Type3Font.h | 2 +- 8 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibPDF/Fonts/SimpleFont.cpp b/Userland/Libraries/LibPDF/Fonts/SimpleFont.cpp index 8d2cec0fa14..1f1846460b1 100644 --- a/Userland/Libraries/LibPDF/Fonts/SimpleFont.cpp +++ b/Userland/Libraries/LibPDF/Fonts/SimpleFont.cpp @@ -48,8 +48,6 @@ PDFErrorOr SimpleFont::initialize(Document* document, NonnullRefPtr SimpleFont::draw_string(Gfx::Painter& painter, Gfx::FloatPoint glyph_position, DeprecatedString const& string, Renderer const& renderer) { - Color const& paint_color = renderer.state().paint_color; - auto const& text_rendering_matrix = renderer.calculate_text_rendering_matrix(); auto font_size = text_rendering_matrix.x_scale() * renderer.text_state().font_size; @@ -68,7 +66,7 @@ PDFErrorOr SimpleFont::draw_string(Gfx::Painter& painter, Gfx:: else glyph_width = m_missing_width; // FIXME: times m_font_matrix.x_scale() probably? - TRY(draw_glyph(painter, glyph_position, glyph_width, char_code, paint_color)); + TRY(draw_glyph(painter, glyph_position, glyph_width, char_code, renderer)); auto tx = glyph_width; tx += character_spacing; diff --git a/Userland/Libraries/LibPDF/Fonts/SimpleFont.h b/Userland/Libraries/LibPDF/Fonts/SimpleFont.h index e1b599e8bc9..df9fccef5fc 100644 --- a/Userland/Libraries/LibPDF/Fonts/SimpleFont.h +++ b/Userland/Libraries/LibPDF/Fonts/SimpleFont.h @@ -18,7 +18,7 @@ public: protected: PDFErrorOr initialize(Document* document, NonnullRefPtr const& dict, float font_size) override; virtual Optional get_glyph_width(u8 char_code) const = 0; - virtual PDFErrorOr draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Color color) = 0; + virtual PDFErrorOr draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Renderer const&) = 0; RefPtr& encoding() { return m_encoding; } RefPtr const& encoding() const { return m_encoding; } diff --git a/Userland/Libraries/LibPDF/Fonts/TrueTypeFont.cpp b/Userland/Libraries/LibPDF/Fonts/TrueTypeFont.cpp index 974956865a5..9e0b36aca1b 100644 --- a/Userland/Libraries/LibPDF/Fonts/TrueTypeFont.cpp +++ b/Userland/Libraries/LibPDF/Fonts/TrueTypeFont.cpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace PDF { @@ -47,8 +48,10 @@ void TrueTypeFont::set_font_size(float font_size) m_font = m_font->with_size((font_size * POINTS_PER_INCH) / DEFAULT_DPI); } -PDFErrorOr TrueTypeFont::draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float, u8 char_code, Color color) +PDFErrorOr TrueTypeFont::draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float, u8 char_code, Renderer const& renderer) { + auto color = renderer.state().paint_color; + // Account for the reversed font baseline auto position = point.translated(0, -m_font->baseline()); painter.draw_glyph(position, char_code, *m_font, color); diff --git a/Userland/Libraries/LibPDF/Fonts/TrueTypeFont.h b/Userland/Libraries/LibPDF/Fonts/TrueTypeFont.h index 37f03d12c67..0636fa03e01 100644 --- a/Userland/Libraries/LibPDF/Fonts/TrueTypeFont.h +++ b/Userland/Libraries/LibPDF/Fonts/TrueTypeFont.h @@ -16,7 +16,7 @@ class TrueTypeFont : public SimpleFont { public: Optional get_glyph_width(u8 char_code) const override; void set_font_size(float font_size) override; - PDFErrorOr draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float, u8, Color) override; + PDFErrorOr draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float, u8, Renderer const&) override; DeprecatedFlyString base_font_name() const { return m_base_font_name; } diff --git a/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp b/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp index e571e3f0b47..bd67c6ec129 100644 --- a/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp +++ b/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace PDF { @@ -64,8 +65,10 @@ void Type1Font::set_font_size(float font_size) m_font = m_font->with_size((font_size * POINTS_PER_INCH) / DEFAULT_DPI); } -PDFErrorOr Type1Font::draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Color color) +PDFErrorOr Type1Font::draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Renderer const& renderer) { + auto color = renderer.state().paint_color; + if (!m_font_program) { // Account for the reversed font baseline auto position = point.translated(0, -m_font->baseline()); diff --git a/Userland/Libraries/LibPDF/Fonts/Type1Font.h b/Userland/Libraries/LibPDF/Fonts/Type1Font.h index cbe8c2c6453..454905e22d5 100644 --- a/Userland/Libraries/LibPDF/Fonts/Type1Font.h +++ b/Userland/Libraries/LibPDF/Fonts/Type1Font.h @@ -24,7 +24,7 @@ class Type1Font : public SimpleFont { public: Optional get_glyph_width(u8 char_code) const override; void set_font_size(float font_size) override; - PDFErrorOr draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Color color) override; + PDFErrorOr draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Renderer const&) override; DeprecatedFlyString base_font_name() const { return m_base_font_name; } diff --git a/Userland/Libraries/LibPDF/Fonts/Type3Font.cpp b/Userland/Libraries/LibPDF/Fonts/Type3Font.cpp index 17844a023a0..b4cb50d5ca5 100644 --- a/Userland/Libraries/LibPDF/Fonts/Type3Font.cpp +++ b/Userland/Libraries/LibPDF/Fonts/Type3Font.cpp @@ -53,7 +53,7 @@ void Type3Font::set_font_size(float) { } -PDFErrorOr Type3Font::draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float, u8 char_code, Color) +PDFErrorOr Type3Font::draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float, u8 char_code, Renderer const&) { // "For each character code shown by a text-showing operator that uses a Type 3 font, // the consumer application does the following:"" diff --git a/Userland/Libraries/LibPDF/Fonts/Type3Font.h b/Userland/Libraries/LibPDF/Fonts/Type3Font.h index b05adfbc776..efb513a74ee 100644 --- a/Userland/Libraries/LibPDF/Fonts/Type3Font.h +++ b/Userland/Libraries/LibPDF/Fonts/Type3Font.h @@ -14,7 +14,7 @@ class Type3Font : public SimpleFont { public: Optional get_glyph_width(u8 char_code) const override; void set_font_size(float font_size) override; - PDFErrorOr draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Color color) override; + PDFErrorOr draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Renderer const&) override; protected: PDFErrorOr initialize(Document*, NonnullRefPtr const&, float font_size) override;