Bladeren bron

LibPDF: Pass Renderer to SimpleFont::draw_glyph()

This makes it available in Type3Font::draw_glyph().

No behavior change.
Nico Weber 1 jaar geleden
bovenliggende
commit
126a0be595

+ 1 - 3
Userland/Libraries/LibPDF/Fonts/SimpleFont.cpp

@@ -48,8 +48,6 @@ PDFErrorOr<void> SimpleFont::initialize(Document* document, NonnullRefPtr<DictOb
 
 PDFErrorOr<Gfx::FloatPoint> 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<Gfx::FloatPoint> 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;

+ 1 - 1
Userland/Libraries/LibPDF/Fonts/SimpleFont.h

@@ -18,7 +18,7 @@ public:
 protected:
     PDFErrorOr<void> initialize(Document* document, NonnullRefPtr<DictObject> const& dict, float font_size) override;
     virtual Optional<float> get_glyph_width(u8 char_code) const = 0;
-    virtual PDFErrorOr<void> draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Color color) = 0;
+    virtual PDFErrorOr<void> draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Renderer const&) = 0;
     RefPtr<Encoding>& encoding() { return m_encoding; }
     RefPtr<Encoding> const& encoding() const { return m_encoding; }
 

+ 4 - 1
Userland/Libraries/LibPDF/Fonts/TrueTypeFont.cpp

@@ -10,6 +10,7 @@
 #include <LibGfx/Painter.h>
 #include <LibPDF/CommonNames.h>
 #include <LibPDF/Fonts/TrueTypeFont.h>
+#include <LibPDF/Renderer.h>
 
 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<void> TrueTypeFont::draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float, u8 char_code, Color color)
+PDFErrorOr<void> 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);

+ 1 - 1
Userland/Libraries/LibPDF/Fonts/TrueTypeFont.h

@@ -16,7 +16,7 @@ class TrueTypeFont : public SimpleFont {
 public:
     Optional<float> get_glyph_width(u8 char_code) const override;
     void set_font_size(float font_size) override;
-    PDFErrorOr<void> draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float, u8, Color) override;
+    PDFErrorOr<void> draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float, u8, Renderer const&) override;
 
     DeprecatedFlyString base_font_name() const { return m_base_font_name; }
 

+ 4 - 1
Userland/Libraries/LibPDF/Fonts/Type1Font.cpp

@@ -10,6 +10,7 @@
 #include <LibPDF/Fonts/CFF.h>
 #include <LibPDF/Fonts/PS1FontProgram.h>
 #include <LibPDF/Fonts/Type1Font.h>
+#include <LibPDF/Renderer.h>
 
 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<void> Type1Font::draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Color color)
+PDFErrorOr<void> 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());

+ 1 - 1
Userland/Libraries/LibPDF/Fonts/Type1Font.h

@@ -24,7 +24,7 @@ class Type1Font : public SimpleFont {
 public:
     Optional<float> get_glyph_width(u8 char_code) const override;
     void set_font_size(float font_size) override;
-    PDFErrorOr<void> draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Color color) override;
+    PDFErrorOr<void> 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; }
 

+ 1 - 1
Userland/Libraries/LibPDF/Fonts/Type3Font.cpp

@@ -53,7 +53,7 @@ void Type3Font::set_font_size(float)
 {
 }
 
-PDFErrorOr<void> Type3Font::draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float, u8 char_code, Color)
+PDFErrorOr<void> 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:""

+ 1 - 1
Userland/Libraries/LibPDF/Fonts/Type3Font.h

@@ -14,7 +14,7 @@ class Type3Font : public SimpleFont {
 public:
     Optional<float> get_glyph_width(u8 char_code) const override;
     void set_font_size(float font_size) override;
-    PDFErrorOr<void> draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Color color) override;
+    PDFErrorOr<void> draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Renderer const&) override;
 
 protected:
     PDFErrorOr<void> initialize(Document*, NonnullRefPtr<DictObject> const&, float font_size) override;