1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:07:45 +00:00

LibPDF: Make SimpleFont font matrix configurable

Type 3 fonts can set it to a custom value.
This commit is contained in:
Nico Weber 2023-11-15 07:46:04 -05:00 committed by Sam Atkins
parent 4cd1a2d319
commit 9632d8ee49
2 changed files with 9 additions and 2 deletions

View file

@ -52,11 +52,11 @@ PDFErrorOr<Gfx::FloatPoint> SimpleFont::draw_string(Gfx::Painter& painter, Gfx::
// and use the default width for the given font otherwise. // and use the default width for the given font otherwise.
float glyph_width; float glyph_width;
if (auto width = m_widths.get(char_code); width.has_value()) if (auto width = m_widths.get(char_code); width.has_value())
glyph_width = font_size * width.value() / 1000.0f; glyph_width = font_size * width.value() * m_font_matrix.x_scale();
else if (auto width = get_glyph_width(char_code); width.has_value()) else if (auto width = get_glyph_width(char_code); width.has_value())
glyph_width = width.value(); glyph_width = width.value();
else else
glyph_width = m_missing_width; 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, paint_color));

View file

@ -22,11 +22,18 @@ protected:
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; }
Gfx::AffineTransform& font_matrix() { return m_font_matrix; }
private: private:
RefPtr<Encoding> m_encoding; RefPtr<Encoding> m_encoding;
RefPtr<StreamObject> m_to_unicode; RefPtr<StreamObject> m_to_unicode;
HashMap<u8, u16> m_widths; HashMap<u8, u16> m_widths;
u16 m_missing_width { 0 }; u16 m_missing_width { 0 };
// "For all font types except Type 3, the units of glyph space are one-thousandth of a unit of text space;
// for a Type 3 font, the transformation from glyph space to text space is defined by a font matrix specified
// in an explicit FontMatrix entry in the font."
Gfx::AffineTransform m_font_matrix { 1.0f / 1000.0f, 0, 0, 1.0f / 1000.0f, 0, 0 };
}; };
} }