mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
LibPDF: Resize fonts when the text and line matrices change
This commit is contained in:
parent
9a0e1dde42
commit
5f8fd47214
8 changed files with 26 additions and 0 deletions
|
@ -26,6 +26,7 @@ public:
|
|||
|
||||
virtual ~PDFFont() = default;
|
||||
|
||||
virtual void set_font_size(float font_size) = 0;
|
||||
virtual PDFErrorOr<Gfx::FloatPoint> draw_string(Gfx::Painter&, Gfx::FloatPoint, DeprecatedString const&, Color const&, float font_size, float character_spacing, float horizontal_scaling) = 0;
|
||||
|
||||
virtual Type type() const = 0;
|
||||
|
|
|
@ -40,6 +40,11 @@ float TrueTypeFont::get_glyph_width(u8 char_code) const
|
|||
return m_font->glyph_width(char_code);
|
||||
}
|
||||
|
||||
void TrueTypeFont::set_font_size(float font_size)
|
||||
{
|
||||
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)
|
||||
{
|
||||
// Account for the reversed font baseline
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace PDF {
|
|||
class TrueTypeFont : public SimpleFont {
|
||||
public:
|
||||
float get_glyph_width(u8 char_code) const override;
|
||||
void set_font_size(float font_size) override;
|
||||
void draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float, u8, Color) override;
|
||||
Type type() const override { return PDFFont::Type::TrueType; }
|
||||
|
||||
|
|
|
@ -87,6 +87,10 @@ float Type0Font::get_char_width(u16 char_code) const
|
|||
return static_cast<float>(width) / 1000.0f;
|
||||
}
|
||||
|
||||
void Type0Font::set_font_size(float)
|
||||
{
|
||||
}
|
||||
|
||||
PDFErrorOr<Gfx::FloatPoint> Type0Font::draw_string(Gfx::Painter&, Gfx::FloatPoint, DeprecatedString const&, Color const&, float, float, float)
|
||||
{
|
||||
return Error::rendering_unsupported_error("Type0 font not implemented yet");
|
||||
|
|
|
@ -19,6 +19,7 @@ struct CIDSystemInfo {
|
|||
|
||||
class Type0Font : public PDFFont {
|
||||
public:
|
||||
void set_font_size(float font_size) override;
|
||||
PDFErrorOr<Gfx::FloatPoint> draw_string(Gfx::Painter&, Gfx::FloatPoint pos, DeprecatedString const&, Color const&, float, float, float) override;
|
||||
Type type() const override { return PDFFont::Type::Type0; }
|
||||
|
||||
|
|
|
@ -54,6 +54,12 @@ float Type1Font::get_glyph_width(u8 char_code) const
|
|||
return m_font->glyph_width(char_code);
|
||||
}
|
||||
|
||||
void Type1Font::set_font_size(float font_size)
|
||||
{
|
||||
if (m_font)
|
||||
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)
|
||||
{
|
||||
if (!m_font_program) {
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace PDF {
|
|||
class Type1Font : public SimpleFont {
|
||||
public:
|
||||
float get_glyph_width(u8 char_code) const 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;
|
||||
Type type() const override { return PDFFont::Type::Type1; }
|
||||
|
||||
|
|
|
@ -458,6 +458,13 @@ RENDERER_HANDLER(text_set_matrix_and_line_matrix)
|
|||
m_text_line_matrix = new_transform;
|
||||
m_text_matrix = new_transform;
|
||||
m_text_rendering_matrix_is_dirty = true;
|
||||
|
||||
// Settings the text/line matrix retroactively affects fonts
|
||||
if (text_state().font) {
|
||||
auto new_text_rendering_matrix = calculate_text_rendering_matrix();
|
||||
text_state().font->set_font_size(text_state().font_size * new_text_rendering_matrix.x_scale());
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue