LibGfx: Make Font::pixel_metrics() virtual

This makes it easier for BitmapFont and ScaledFont to implement metrics
lookup themselves.
This commit is contained in:
Andreas Kling 2022-03-28 12:11:09 +02:00
parent 344374588b
commit e398164f10
Notes: sideshowbarker 2024-07-17 16:32:29 +09:00
5 changed files with 16 additions and 3 deletions

View file

@ -372,10 +372,10 @@ Font const& Font::bold_variant() const
return *m_bold_variant;
}
FontPixelMetrics Font::pixel_metrics() const
FontPixelMetrics BitmapFont::pixel_metrics() const
{
return FontPixelMetrics {
.size = (float)presentation_size(),
.size = (float)pixel_size(),
.x_height = (float)x_height(),
.advance_of_ascii_zero = (float)glyph_width('0'),
.glyph_spacing = (float)glyph_spacing(),

View file

@ -23,6 +23,8 @@ public:
NonnullRefPtr<Font> clone() const override;
static NonnullRefPtr<BitmapFont> create(u8 glyph_height, u8 glyph_width, bool fixed, size_t glyph_count);
virtual FontPixelMetrics pixel_metrics() const override;
NonnullRefPtr<BitmapFont> masked_character_set() const;
NonnullRefPtr<BitmapFont> unmasked_character_set() const;

View file

@ -103,7 +103,7 @@ public:
virtual NonnullRefPtr<Font> clone() const = 0;
virtual ~Font() {};
FontPixelMetrics pixel_metrics() const;
virtual FontPixelMetrics pixel_metrics() const = 0;
virtual u8 presentation_size() const = 0;
virtual int pixel_size() const = 0;

View file

@ -724,6 +724,16 @@ u8 ScaledFont::glyph_fixed_width() const
return glyph_metrics(glyph_id_for_code_point(' ')).advance_width;
}
Gfx::FontPixelMetrics ScaledFont::pixel_metrics() const
{
return Gfx::FontPixelMetrics {
.size = (float)pixel_size(),
.x_height = (float)x_height(),
.advance_of_ascii_zero = (float)glyph_width('0'),
.glyph_spacing = (float)glyph_spacing(),
};
}
u16 OS2::weight_class() const
{
return be_u16(m_slice.offset_pointer((u32)Offsets::WeightClass));

View file

@ -128,6 +128,7 @@ public:
virtual u8 presentation_size() const override { return m_point_height; }
virtual int pixel_size() const override { return m_point_height * 1.33333333f; }
virtual float point_size() const override { return m_point_height; }
virtual Gfx::FontPixelMetrics pixel_metrics() const override;
virtual u8 slope() const override { return m_font->slope(); }
virtual u16 weight() const override { return m_font->weight(); }
virtual Gfx::Glyph glyph(u32 code_point) const override;