mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 06:04:57 +00:00
LibGfx: Add ScaledFont::scaled_with_size()
It's like ScaledFont::with_size(), except that it guarantees that the result is non-null and ScaledFont. (Smart pointers don't allow covariant return types, else we could just narrow down the return type of with_size() while still overriding the base method.) No behavior change.
This commit is contained in:
parent
bc21ed151e
commit
7d9294b9a4
2 changed files with 8 additions and 2 deletions
|
@ -153,13 +153,18 @@ u8 ScaledFont::glyph_fixed_width() const
|
|||
return glyph_metrics(glyph_id_for_code_point(' ')).advance_width;
|
||||
}
|
||||
|
||||
RefPtr<Font> ScaledFont::with_size(float point_size) const
|
||||
NonnullRefPtr<ScaledFont> ScaledFont::scaled_with_size(float point_size) const
|
||||
{
|
||||
if (point_size == m_point_height && point_size == m_point_width)
|
||||
return const_cast<ScaledFont*>(this);
|
||||
return *const_cast<ScaledFont*>(this);
|
||||
return m_font->scaled_font(point_size);
|
||||
}
|
||||
|
||||
RefPtr<Font> ScaledFont::with_size(float point_size) const
|
||||
{
|
||||
return scaled_with_size(point_size);
|
||||
}
|
||||
|
||||
Gfx::FontPixelMetrics ScaledFont::pixel_metrics() const
|
||||
{
|
||||
return m_pixel_metrics;
|
||||
|
|
|
@ -69,6 +69,7 @@ public:
|
|||
virtual String qualified_name() const override { return MUST(String::formatted("{} {} {} {}", family(), presentation_size(), weight(), slope())); }
|
||||
virtual String human_readable_name() const override { return MUST(String::formatted("{} {} {}", family(), variant(), presentation_size())); }
|
||||
|
||||
virtual NonnullRefPtr<ScaledFont> scaled_with_size(float point_size) const;
|
||||
virtual RefPtr<Font> with_size(float point_size) const override;
|
||||
|
||||
virtual bool has_color_bitmaps() const override { return m_font->has_color_bitmaps(); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue