mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
LibGfx: Make FontDatabase lookups take font (point) sizes as float
This will allow web content to ask for fractional sizes, which becomes important when converting between px/pt.
This commit is contained in:
parent
eeeaf410fb
commit
ee883372f6
Notes:
sideshowbarker
2024-07-17 16:42:19 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/ee883372f6
4 changed files with 13 additions and 12 deletions
|
@ -161,20 +161,20 @@ RefPtr<Gfx::Font> FontDatabase::get_by_name(StringView name)
|
|||
return it->value;
|
||||
}
|
||||
|
||||
RefPtr<Gfx::Font> FontDatabase::get(FlyString const& family, unsigned size, unsigned weight, unsigned slope, Font::AllowInexactSizeMatch allow_inexact_size_match)
|
||||
RefPtr<Gfx::Font> FontDatabase::get(FlyString const& family, float point_size, unsigned weight, unsigned slope, Font::AllowInexactSizeMatch allow_inexact_size_match)
|
||||
{
|
||||
for (auto typeface : m_private->typefaces) {
|
||||
if (typeface->family() == family && typeface->weight() == weight && typeface->slope() == slope)
|
||||
return typeface->get_font(size, allow_inexact_size_match);
|
||||
return typeface->get_font(point_size, allow_inexact_size_match);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Gfx::Font> FontDatabase::get(FlyString const& family, FlyString const& variant, unsigned size, Font::AllowInexactSizeMatch allow_inexact_size_match)
|
||||
RefPtr<Gfx::Font> FontDatabase::get(FlyString const& family, FlyString const& variant, float point_size, Font::AllowInexactSizeMatch allow_inexact_size_match)
|
||||
{
|
||||
for (auto typeface : m_private->typefaces) {
|
||||
if (typeface->family() == family && typeface->variant() == variant)
|
||||
return typeface->get_font(size, allow_inexact_size_match);
|
||||
return typeface->get_font(point_size, allow_inexact_size_match);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ public:
|
|||
static void set_fixed_width_font_query(String);
|
||||
static void set_default_fonts_lookup_path(String);
|
||||
|
||||
RefPtr<Gfx::Font> get(FlyString const& family, unsigned size, unsigned weight, unsigned slope, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No);
|
||||
RefPtr<Gfx::Font> get(FlyString const& family, FlyString const& variant, unsigned size, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No);
|
||||
RefPtr<Gfx::Font> get(FlyString const& family, float point_size, unsigned weight, unsigned slope, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No);
|
||||
RefPtr<Gfx::Font> get(FlyString const& family, FlyString const& variant, float point_size, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No);
|
||||
RefPtr<Gfx::Font> get_by_name(StringView);
|
||||
void for_each_font(Function<void(const Gfx::Font&)>);
|
||||
void for_each_fixed_width_font(Function<void(const Gfx::Font&)>);
|
||||
|
|
|
@ -48,11 +48,15 @@ void Typeface::set_ttf_font(RefPtr<TTF::Font> font)
|
|||
m_ttf_font = move(font);
|
||||
}
|
||||
|
||||
RefPtr<Font> Typeface::get_font(unsigned size, Font::AllowInexactSizeMatch allow_inexact_size_match) const
|
||||
RefPtr<Font> Typeface::get_font(float point_size, Font::AllowInexactSizeMatch allow_inexact_size_match) const
|
||||
{
|
||||
VERIFY(size < NumericLimits<int>::max());
|
||||
VERIFY(point_size > 0);
|
||||
|
||||
if (m_ttf_font)
|
||||
return adopt_ref(*new TTF::ScaledFont(*m_ttf_font, point_size, point_size));
|
||||
|
||||
RefPtr<BitmapFont> best_match;
|
||||
int size = roundf(point_size);
|
||||
int best_delta = NumericLimits<int>::max();
|
||||
|
||||
for (auto font : m_bitmap_fonts) {
|
||||
|
@ -70,9 +74,6 @@ RefPtr<Font> Typeface::get_font(unsigned size, Font::AllowInexactSizeMatch allow
|
|||
if (allow_inexact_size_match == Font::AllowInexactSizeMatch::Yes && best_match)
|
||||
return best_match;
|
||||
|
||||
if (m_ttf_font)
|
||||
return adopt_ref(*new TTF::ScaledFont(*m_ttf_font, size, size));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
void add_bitmap_font(RefPtr<BitmapFont>);
|
||||
void set_ttf_font(RefPtr<TTF::Font>);
|
||||
|
||||
RefPtr<Font> get_font(unsigned size, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No) const;
|
||||
RefPtr<Font> get_font(float point_size, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No) const;
|
||||
|
||||
private:
|
||||
FlyString m_family;
|
||||
|
|
Loading…
Reference in a new issue