1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:57:45 +00:00

LibGfx: Migrate Typeface from TTF::Font to Gfx::VectorFont

This commit is contained in:
Simon Wanner 2022-04-09 10:54:25 +02:00 committed by Andreas Kling
parent 5136c5ae1a
commit 17baf05c5a
3 changed files with 14 additions and 14 deletions

View file

@ -113,7 +113,7 @@ FontDatabase::FontDatabase()
if (auto font_or_error = TTF::Font::try_load_from_file(path); !font_or_error.is_error()) { if (auto font_or_error = TTF::Font::try_load_from_file(path); !font_or_error.is_error()) {
auto font = font_or_error.release_value(); auto font = font_or_error.release_value();
auto typeface = get_or_create_typeface(font->family(), font->variant()); auto typeface = get_or_create_typeface(font->family(), font->variant());
typeface->set_ttf_font(move(font)); typeface->set_vector_font(move(font));
} }
} }
} }

View file

@ -11,32 +11,32 @@ namespace Gfx {
unsigned Typeface::weight() const unsigned Typeface::weight() const
{ {
VERIFY(m_ttf_font || m_bitmap_fonts.size() > 0); VERIFY(m_vector_font || m_bitmap_fonts.size() > 0);
if (is_fixed_size()) if (is_fixed_size())
return m_bitmap_fonts[0]->weight(); return m_bitmap_fonts[0]->weight();
return m_ttf_font->weight(); return m_vector_font->weight();
} }
u8 Typeface::slope() const u8 Typeface::slope() const
{ {
VERIFY(m_ttf_font || m_bitmap_fonts.size() > 0); VERIFY(m_vector_font || m_bitmap_fonts.size() > 0);
if (is_fixed_size()) if (is_fixed_size())
return m_bitmap_fonts[0]->slope(); return m_bitmap_fonts[0]->slope();
return m_ttf_font->slope(); return m_vector_font->slope();
} }
bool Typeface::is_fixed_width() const bool Typeface::is_fixed_width() const
{ {
VERIFY(m_ttf_font || m_bitmap_fonts.size() > 0); VERIFY(m_vector_font || m_bitmap_fonts.size() > 0);
if (is_fixed_size()) if (is_fixed_size())
return m_bitmap_fonts[0]->is_fixed_width(); return m_bitmap_fonts[0]->is_fixed_width();
return m_ttf_font->is_fixed_width(); return m_vector_font->is_fixed_width();
} }
void Typeface::add_bitmap_font(RefPtr<BitmapFont> font) void Typeface::add_bitmap_font(RefPtr<BitmapFont> font)
@ -44,17 +44,17 @@ void Typeface::add_bitmap_font(RefPtr<BitmapFont> font)
m_bitmap_fonts.append(font); m_bitmap_fonts.append(font);
} }
void Typeface::set_ttf_font(RefPtr<TTF::Font> font) void Typeface::set_vector_font(RefPtr<VectorFont> font)
{ {
m_ttf_font = move(font); m_vector_font = move(font);
} }
RefPtr<Font> Typeface::get_font(float point_size, Font::AllowInexactSizeMatch allow_inexact_size_match) const RefPtr<Font> Typeface::get_font(float point_size, Font::AllowInexactSizeMatch allow_inexact_size_match) const
{ {
VERIFY(point_size > 0); VERIFY(point_size > 0);
if (m_ttf_font) if (m_vector_font)
return adopt_ref(*new Gfx::ScaledFont(*m_ttf_font, point_size, point_size)); return adopt_ref(*new Gfx::ScaledFont(*m_vector_font, point_size, point_size));
RefPtr<BitmapFont> best_match; RefPtr<BitmapFont> best_match;
int size = roundf(point_size); int size = roundf(point_size);

View file

@ -12,7 +12,7 @@
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibGfx/Font/BitmapFont.h> #include <LibGfx/Font/BitmapFont.h>
#include <LibGfx/Font/Font.h> #include <LibGfx/Font/Font.h>
#include <LibGfx/Font/TrueType/Font.h> #include <LibGfx/Font/VectorFont.h>
namespace Gfx { namespace Gfx {
@ -34,7 +34,7 @@ public:
void for_each_fixed_size_font(Function<void(Font const&)>) const; void for_each_fixed_size_font(Function<void(Font const&)>) const;
void add_bitmap_font(RefPtr<BitmapFont>); void add_bitmap_font(RefPtr<BitmapFont>);
void set_ttf_font(RefPtr<TTF::Font>); void set_vector_font(RefPtr<VectorFont>);
RefPtr<Font> get_font(float point_size, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No) const; RefPtr<Font> get_font(float point_size, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No) const;
@ -43,7 +43,7 @@ private:
FlyString m_variant; FlyString m_variant;
Vector<RefPtr<BitmapFont>> m_bitmap_fonts; Vector<RefPtr<BitmapFont>> m_bitmap_fonts;
RefPtr<TTF::Font> m_ttf_font; RefPtr<VectorFont> m_vector_font;
}; };
} }