mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:37:46 +00:00
LibPDF: Make SimpleFont::draw_glyph() fallible
This commit is contained in:
parent
843e9daa8c
commit
6c1da5db54
6 changed files with 9 additions and 7 deletions
|
@ -58,7 +58,7 @@ PDFErrorOr<Gfx::FloatPoint> SimpleFont::draw_string(Gfx::Painter& painter, Gfx::
|
||||||
else
|
else
|
||||||
glyph_width = m_missing_width;
|
glyph_width = m_missing_width;
|
||||||
|
|
||||||
draw_glyph(painter, glyph_position, glyph_width, char_code, paint_color);
|
TRY(draw_glyph(painter, glyph_position, glyph_width, char_code, paint_color));
|
||||||
|
|
||||||
auto tx = glyph_width;
|
auto tx = glyph_width;
|
||||||
tx += character_spacing;
|
tx += character_spacing;
|
||||||
|
|
|
@ -18,7 +18,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
PDFErrorOr<void> initialize(Document* document, NonnullRefPtr<DictObject> const& dict, float font_size) override;
|
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 Optional<float> get_glyph_width(u8 char_code) const = 0;
|
||||||
virtual 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, Color color) = 0;
|
||||||
RefPtr<Encoding>& encoding() { return m_encoding; }
|
RefPtr<Encoding>& encoding() { return m_encoding; }
|
||||||
RefPtr<Encoding> const& encoding() const { return m_encoding; }
|
RefPtr<Encoding> const& encoding() const { return m_encoding; }
|
||||||
|
|
||||||
|
|
|
@ -45,11 +45,12 @@ void TrueTypeFont::set_font_size(float font_size)
|
||||||
m_font = m_font->with_size((font_size * POINTS_PER_INCH) / DEFAULT_DPI);
|
m_font = m_font->with_size((font_size * POINTS_PER_INCH) / DEFAULT_DPI);
|
||||||
}
|
}
|
||||||
|
|
||||||
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, Color color)
|
||||||
{
|
{
|
||||||
// Account for the reversed font baseline
|
// Account for the reversed font baseline
|
||||||
auto position = point.translated(0, -m_font->baseline());
|
auto position = point.translated(0, -m_font->baseline());
|
||||||
painter.draw_glyph(position, char_code, *m_font, color);
|
painter.draw_glyph(position, char_code, *m_font, color);
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ class TrueTypeFont : public SimpleFont {
|
||||||
public:
|
public:
|
||||||
Optional<float> get_glyph_width(u8 char_code) const override;
|
Optional<float> get_glyph_width(u8 char_code) const override;
|
||||||
void set_font_size(float font_size) override;
|
void set_font_size(float font_size) override;
|
||||||
void draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float, u8, Color) override;
|
PDFErrorOr<void> draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float, u8, Color) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PDFErrorOr<void> initialize(Document*, NonnullRefPtr<DictObject> const&, float font_size) override;
|
PDFErrorOr<void> initialize(Document*, NonnullRefPtr<DictObject> const&, float font_size) override;
|
||||||
|
|
|
@ -62,13 +62,13 @@ void Type1Font::set_font_size(float font_size)
|
||||||
m_font = m_font->with_size((font_size * POINTS_PER_INCH) / DEFAULT_DPI);
|
m_font = m_font->with_size((font_size * POINTS_PER_INCH) / DEFAULT_DPI);
|
||||||
}
|
}
|
||||||
|
|
||||||
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, Color color)
|
||||||
{
|
{
|
||||||
if (!m_font_program) {
|
if (!m_font_program) {
|
||||||
// Account for the reversed font baseline
|
// Account for the reversed font baseline
|
||||||
auto position = point.translated(0, -m_font->baseline());
|
auto position = point.translated(0, -m_font->baseline());
|
||||||
painter.draw_glyph(position, char_code, *m_font, color);
|
painter.draw_glyph(position, char_code, *m_font, color);
|
||||||
return;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto effective_encoding = encoding();
|
auto effective_encoding = encoding();
|
||||||
|
@ -95,5 +95,6 @@ void Type1Font::draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float w
|
||||||
painter.blit_filtered(glyph_position.blit_position, *bitmap, bitmap->rect(), [color](Color pixel) -> Color {
|
painter.blit_filtered(glyph_position.blit_position, *bitmap, bitmap->rect(), [color](Color pixel) -> Color {
|
||||||
return pixel.multiply(color);
|
return pixel.multiply(color);
|
||||||
});
|
});
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ class Type1Font : public SimpleFont {
|
||||||
public:
|
public:
|
||||||
Optional<float> get_glyph_width(u8 char_code) const override;
|
Optional<float> get_glyph_width(u8 char_code) const override;
|
||||||
void set_font_size(float font_size) override;
|
void set_font_size(float font_size) override;
|
||||||
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, Color color) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PDFErrorOr<void> initialize(Document*, NonnullRefPtr<DictObject> const&, float font_size) override;
|
PDFErrorOr<void> initialize(Document*, NonnullRefPtr<DictObject> const&, float font_size) override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue