mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:07:35 +00:00
LibGfx: Convert FontDatabase APIs to use FlyString
This commit is contained in:
parent
e4d14e1afc
commit
13db3c5ce0
15 changed files with 66 additions and 62 deletions
|
@ -409,14 +409,14 @@ String BitmapFont::variant() const
|
|||
|
||||
RefPtr<Font> BitmapFont::with_size(float point_size) const
|
||||
{
|
||||
return Gfx::FontDatabase::the().get(family().to_deprecated_string(), point_size, weight(), width(), slope());
|
||||
return Gfx::FontDatabase::the().get(family(), point_size, weight(), width(), slope());
|
||||
}
|
||||
|
||||
Font const& Font::bold_variant() const
|
||||
{
|
||||
if (m_bold_variant)
|
||||
return *m_bold_variant;
|
||||
m_bold_variant = Gfx::FontDatabase::the().get(family().to_deprecated_string(), presentation_size(), 700, Gfx::FontWidth::Normal, 0);
|
||||
m_bold_variant = Gfx::FontDatabase::the().get(family(), presentation_size(), 700, Gfx::FontWidth::Normal, 0);
|
||||
if (!m_bold_variant)
|
||||
m_bold_variant = this;
|
||||
return *m_bold_variant;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/DeprecatedFlyString.h>
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/Queue.h>
|
||||
#include <AK/QuickSort.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
|
@ -117,7 +118,7 @@ Font& FontDatabase::default_fixed_width_font()
|
|||
|
||||
struct FontDatabase::Private {
|
||||
HashMap<DeprecatedString, NonnullRefPtr<Gfx::Font>, CaseInsensitiveStringTraits> full_name_to_font_map;
|
||||
HashMap<DeprecatedFlyString, Vector<NonnullRefPtr<Typeface>>, CaseInsensitiveStringTraits> typefaces;
|
||||
HashMap<FlyString, Vector<NonnullRefPtr<Typeface>>, AK::ASCIICaseInsensitiveFlyStringTraits> typefaces;
|
||||
};
|
||||
|
||||
void FontDatabase::load_all_fonts_from_path(DeprecatedString const& root)
|
||||
|
@ -144,20 +145,20 @@ void FontDatabase::load_all_fonts_from_path(DeprecatedString const& root)
|
|||
if (auto font_or_error = Gfx::BitmapFont::try_load_from_file(path); !font_or_error.is_error()) {
|
||||
auto font = font_or_error.release_value();
|
||||
m_private->full_name_to_font_map.set(font->qualified_name().to_deprecated_string(), *font);
|
||||
auto typeface = get_or_create_typeface(font->family().to_deprecated_string(), font->variant().to_deprecated_string());
|
||||
auto typeface = get_or_create_typeface(font->family(), font->variant());
|
||||
typeface->add_bitmap_font(font);
|
||||
}
|
||||
} else if (path.ends_with(".ttf"sv)) {
|
||||
// FIXME: What about .otf
|
||||
if (auto font_or_error = OpenType::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().to_deprecated_string(), font->variant().to_deprecated_string());
|
||||
auto typeface = get_or_create_typeface(font->family(), font->variant());
|
||||
typeface->set_vector_font(move(font));
|
||||
}
|
||||
} else if (path.ends_with(".woff"sv)) {
|
||||
if (auto font_or_error = WOFF::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().to_deprecated_string(), font->variant().to_deprecated_string());
|
||||
auto typeface = get_or_create_typeface(font->family(), font->variant());
|
||||
typeface->set_vector_font(move(font));
|
||||
}
|
||||
}
|
||||
|
@ -204,7 +205,7 @@ RefPtr<Gfx::Font> FontDatabase::get_by_name(StringView name)
|
|||
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 = DeprecatedString::join(' ', parts);
|
||||
auto family = MUST(String::join(' ', parts));
|
||||
return get(family, size, weight, Gfx::FontWidth::Normal, slope);
|
||||
}
|
||||
dbgln("Font lookup failed: '{}'", name);
|
||||
|
@ -213,7 +214,7 @@ RefPtr<Gfx::Font> FontDatabase::get_by_name(StringView name)
|
|||
return it->value;
|
||||
}
|
||||
|
||||
RefPtr<Gfx::Font> FontDatabase::get(DeprecatedFlyString const& family, float point_size, unsigned weight, unsigned width, unsigned slope, Font::AllowInexactSizeMatch allow_inexact_size_match)
|
||||
RefPtr<Gfx::Font> FontDatabase::get(FlyString const& family, float point_size, unsigned weight, unsigned width, unsigned slope, Font::AllowInexactSizeMatch allow_inexact_size_match)
|
||||
{
|
||||
auto it = m_private->typefaces.find(family);
|
||||
if (it == m_private->typefaces.end())
|
||||
|
@ -225,7 +226,7 @@ RefPtr<Gfx::Font> FontDatabase::get(DeprecatedFlyString const& family, float poi
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Gfx::Font> FontDatabase::get(DeprecatedFlyString const& family, DeprecatedFlyString const& variant, float point_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)
|
||||
{
|
||||
auto it = m_private->typefaces.find(family);
|
||||
if (it == m_private->typefaces.end())
|
||||
|
@ -237,7 +238,7 @@ RefPtr<Gfx::Font> FontDatabase::get(DeprecatedFlyString const& family, Deprecate
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Typeface> FontDatabase::get_or_create_typeface(DeprecatedString const& family, DeprecatedString const& variant)
|
||||
RefPtr<Typeface> FontDatabase::get_or_create_typeface(FlyString const& family, FlyString const& variant)
|
||||
{
|
||||
auto it = m_private->typefaces.find(family);
|
||||
if (it != m_private->typefaces.end()) {
|
||||
|
@ -260,9 +261,9 @@ void FontDatabase::for_each_typeface(Function<void(Typeface const&)> callback)
|
|||
}
|
||||
}
|
||||
|
||||
void FontDatabase::for_each_typeface_with_family_name(String const& family_name, Function<void(Typeface const&)> callback)
|
||||
void FontDatabase::for_each_typeface_with_family_name(FlyString const& family_name, Function<void(Typeface const&)> callback)
|
||||
{
|
||||
auto it = m_private->typefaces.find(family_name.bytes_as_string_view());
|
||||
auto it = m_private->typefaces.find(family_name);
|
||||
if (it == m_private->typefaces.end())
|
||||
return;
|
||||
for (auto const& typeface : it->value)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
|
@ -48,14 +49,14 @@ public:
|
|||
static void set_fixed_width_font_query(DeprecatedString);
|
||||
static void set_default_fonts_lookup_path(DeprecatedString);
|
||||
|
||||
RefPtr<Gfx::Font> get(DeprecatedFlyString const& family, float point_size, unsigned weight, unsigned width, unsigned slope, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No);
|
||||
RefPtr<Gfx::Font> get(DeprecatedFlyString const& family, DeprecatedFlyString const& variant, float point_size, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No);
|
||||
RefPtr<Gfx::Font> get(FlyString const& family, float point_size, unsigned weight, unsigned width, 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(Gfx::Font const&)>);
|
||||
void for_each_fixed_width_font(Function<void(Gfx::Font const&)>);
|
||||
|
||||
void for_each_typeface(Function<void(Typeface const&)>);
|
||||
void for_each_typeface_with_family_name(String const& family_name, Function<void(Typeface const&)>);
|
||||
void for_each_typeface_with_family_name(FlyString const& family_name, Function<void(Typeface const&)>);
|
||||
|
||||
void load_all_fonts_from_path(DeprecatedString const&);
|
||||
|
||||
|
@ -63,7 +64,7 @@ private:
|
|||
FontDatabase();
|
||||
~FontDatabase() = default;
|
||||
|
||||
RefPtr<Typeface> get_or_create_typeface(DeprecatedString const& family, DeprecatedString const& variant);
|
||||
RefPtr<Typeface> get_or_create_typeface(FlyString const& family, FlyString const& variant);
|
||||
|
||||
struct Private;
|
||||
OwnPtr<Private> m_private;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedFlyString.h>
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/Vector.h>
|
||||
|
@ -18,14 +19,14 @@ namespace Gfx {
|
|||
|
||||
class Typeface : public RefCounted<Typeface> {
|
||||
public:
|
||||
Typeface(DeprecatedString const& family, DeprecatedString const& variant)
|
||||
: m_family(family)
|
||||
, m_variant(variant)
|
||||
Typeface(FlyString family, FlyString variant)
|
||||
: m_family(move(family))
|
||||
, m_variant(move(variant))
|
||||
{
|
||||
}
|
||||
|
||||
DeprecatedFlyString const& family() const { return m_family; }
|
||||
DeprecatedFlyString const& variant() const { return m_variant; }
|
||||
FlyString const& family() const { return m_family; }
|
||||
FlyString const& variant() const { return m_variant; }
|
||||
unsigned weight() const;
|
||||
unsigned width() const;
|
||||
u8 slope() const;
|
||||
|
@ -40,8 +41,8 @@ public:
|
|||
RefPtr<Font> get_font(float point_size, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No) const;
|
||||
|
||||
private:
|
||||
DeprecatedFlyString m_family;
|
||||
DeprecatedFlyString m_variant;
|
||||
FlyString m_family;
|
||||
FlyString m_variant;
|
||||
|
||||
Vector<RefPtr<BitmapFont>> m_bitmap_fonts;
|
||||
RefPtr<VectorFont> m_vector_font;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue