mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
LibGfx: Migrate Typeface from TTF::Font to Gfx::VectorFont
This commit is contained in:
parent
5136c5ae1a
commit
17baf05c5a
Notes:
sideshowbarker
2024-07-17 14:12:49 +09:00
Author: https://github.com/skyrising Commit: https://github.com/SerenityOS/serenity/commit/17baf05c5a Pull-request: https://github.com/SerenityOS/serenity/pull/13595
3 changed files with 14 additions and 14 deletions
|
@ -113,7 +113,7 @@ FontDatabase::FontDatabase()
|
|||
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 typeface = get_or_create_typeface(font->family(), font->variant());
|
||||
typeface->set_ttf_font(move(font));
|
||||
typeface->set_vector_font(move(font));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,32 +11,32 @@ namespace Gfx {
|
|||
|
||||
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())
|
||||
return m_bitmap_fonts[0]->weight();
|
||||
|
||||
return m_ttf_font->weight();
|
||||
return m_vector_font->weight();
|
||||
}
|
||||
|
||||
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())
|
||||
return m_bitmap_fonts[0]->slope();
|
||||
|
||||
return m_ttf_font->slope();
|
||||
return m_vector_font->slope();
|
||||
}
|
||||
|
||||
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())
|
||||
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)
|
||||
|
@ -44,17 +44,17 @@ void Typeface::add_bitmap_font(RefPtr<BitmapFont> 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
|
||||
{
|
||||
VERIFY(point_size > 0);
|
||||
|
||||
if (m_ttf_font)
|
||||
return adopt_ref(*new Gfx::ScaledFont(*m_ttf_font, point_size, point_size));
|
||||
if (m_vector_font)
|
||||
return adopt_ref(*new Gfx::ScaledFont(*m_vector_font, point_size, point_size));
|
||||
|
||||
RefPtr<BitmapFont> best_match;
|
||||
int size = roundf(point_size);
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <AK/Vector.h>
|
||||
#include <LibGfx/Font/BitmapFont.h>
|
||||
#include <LibGfx/Font/Font.h>
|
||||
#include <LibGfx/Font/TrueType/Font.h>
|
||||
#include <LibGfx/Font/VectorFont.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
|
@ -34,7 +34,7 @@ public:
|
|||
void for_each_fixed_size_font(Function<void(Font const&)>) const;
|
||||
|
||||
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;
|
||||
|
||||
|
@ -43,7 +43,7 @@ private:
|
|||
FlyString m_variant;
|
||||
|
||||
Vector<RefPtr<BitmapFont>> m_bitmap_fonts;
|
||||
RefPtr<TTF::Font> m_ttf_font;
|
||||
RefPtr<VectorFont> m_vector_font;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue