mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:07:45 +00:00
Everywhere: Fully qualify font names by including their slope
Fixes typefaces of the same weight but different slopes being incorrectly returned for each other by FontDatabase.
This commit is contained in:
parent
87a149c9a4
commit
96895cd22c
15 changed files with 39 additions and 25 deletions
|
@ -345,7 +345,7 @@ ALWAYS_INLINE int BitmapFont::unicode_view_width(T const& view) const
|
|||
|
||||
String BitmapFont::qualified_name() const
|
||||
{
|
||||
return String::formatted("{} {} {}", family(), presentation_size(), weight());
|
||||
return String::formatted("{} {} {} {}", family(), presentation_size(), weight(), slope());
|
||||
}
|
||||
|
||||
String BitmapFont::variant() const
|
||||
|
@ -366,7 +366,7 @@ Font const& Font::bold_variant() const
|
|||
{
|
||||
if (m_bold_variant)
|
||||
return *m_bold_variant;
|
||||
m_bold_variant = Gfx::FontDatabase::the().get(family(), presentation_size(), 700);
|
||||
m_bold_variant = Gfx::FontDatabase::the().get(family(), presentation_size(), 700, 0);
|
||||
if (!m_bold_variant)
|
||||
m_bold_variant = this;
|
||||
return *m_bold_variant;
|
||||
|
|
|
@ -138,11 +138,12 @@ RefPtr<Gfx::Font> FontDatabase::get_by_name(StringView name)
|
|||
auto it = m_private->full_name_to_font_map.find(name);
|
||||
if (it == m_private->full_name_to_font_map.end()) {
|
||||
auto parts = name.split_view(" "sv);
|
||||
if (parts.size() >= 3) {
|
||||
if (parts.size() >= 4) {
|
||||
auto slope = parts.take_last().to_int().value_or(0);
|
||||
auto weight = parts.take_last().to_int().value_or(0);
|
||||
auto size = parts.take_last().to_int().value_or(0);
|
||||
auto family = String::join(' ', parts);
|
||||
return get(family, size, weight);
|
||||
return get(family, size, weight, slope);
|
||||
}
|
||||
dbgln("Font lookup failed: '{}'", name);
|
||||
return nullptr;
|
||||
|
@ -150,10 +151,10 @@ RefPtr<Gfx::Font> FontDatabase::get_by_name(StringView name)
|
|||
return it->value;
|
||||
}
|
||||
|
||||
RefPtr<Gfx::Font> FontDatabase::get(const String& family, unsigned size, unsigned weight)
|
||||
RefPtr<Gfx::Font> FontDatabase::get(const String& family, unsigned size, unsigned weight, unsigned slope)
|
||||
{
|
||||
for (auto typeface : m_private->typefaces) {
|
||||
if (typeface->family() == family && typeface->weight() == weight)
|
||||
if (typeface->family() == family && typeface->weight() == weight && typeface->slope() == slope)
|
||||
return typeface->get_font(size);
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
static void set_default_font_query(String);
|
||||
static void set_fixed_width_font_query(String);
|
||||
|
||||
RefPtr<Gfx::Font> get(const String& family, unsigned size, unsigned weight);
|
||||
RefPtr<Gfx::Font> get(const String& family, unsigned size, unsigned weight, unsigned slope);
|
||||
RefPtr<Gfx::Font> get(const String& family, const String& variant, unsigned size);
|
||||
RefPtr<Gfx::Font> get_by_name(StringView);
|
||||
void for_each_font(Function<void(const Gfx::Font&)>);
|
||||
|
|
|
@ -145,7 +145,7 @@ public:
|
|||
virtual size_t glyph_count() const override { return m_font->glyph_count(); }
|
||||
virtual String family() const override { return m_font->family(); }
|
||||
virtual String variant() const override { return m_font->variant(); }
|
||||
virtual String qualified_name() const override { return String::formatted("{} {} {}", family(), presentation_size(), weight()); }
|
||||
virtual String qualified_name() const override { return String::formatted("{} {} {} {}", family(), presentation_size(), weight(), slope()); }
|
||||
|
||||
private:
|
||||
NonnullRefPtr<TTF::Font> m_font;
|
||||
|
|
|
@ -18,6 +18,16 @@ unsigned Typeface::weight() const
|
|||
return m_ttf_font->weight();
|
||||
}
|
||||
|
||||
u8 Typeface::slope() const
|
||||
{
|
||||
VERIFY(m_ttf_font || m_bitmap_fonts.size() > 0);
|
||||
|
||||
if (is_fixed_size())
|
||||
return m_bitmap_fonts[0]->slope();
|
||||
|
||||
return m_ttf_font->slope();
|
||||
}
|
||||
|
||||
bool Typeface::is_fixed_width() const
|
||||
{
|
||||
VERIFY(m_ttf_font || m_bitmap_fonts.size() > 0);
|
||||
|
|
|
@ -27,6 +27,7 @@ public:
|
|||
String family() const { return m_family; }
|
||||
String variant() const { return m_variant; }
|
||||
unsigned weight() const;
|
||||
u8 slope() const;
|
||||
|
||||
bool is_fixed_width() const;
|
||||
bool is_fixed_size() const { return !m_bitmap_fonts.is_empty(); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue