mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
LibGfx: Make Font::pixel_metrics() virtual
This makes it easier for BitmapFont and ScaledFont to implement metrics lookup themselves.
This commit is contained in:
parent
344374588b
commit
e398164f10
Notes:
sideshowbarker
2024-07-17 16:32:29 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/e398164f10
5 changed files with 16 additions and 3 deletions
|
@ -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(),
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue