1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:47:47 +00:00

LibGfx: Make FontDatabase API use FlyString for family and variant

This reduces work done by font lookups.
This commit is contained in:
Andreas Kling 2022-03-16 13:11:26 +01:00
parent cb6b372a3b
commit a2b9609793
3 changed files with 10 additions and 9 deletions

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/FlyString.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/QuickSort.h>
#include <LibCore/DirIterator.h>
@ -164,7 +165,7 @@ RefPtr<Gfx::Font> FontDatabase::get_by_name(StringView name)
return it->value;
}
RefPtr<Gfx::Font> FontDatabase::get(String const& family, unsigned size, unsigned weight, unsigned slope, Font::AllowInexactSizeMatch allow_inexact_size_match)
RefPtr<Gfx::Font> FontDatabase::get(FlyString const& family, unsigned 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)
@ -173,7 +174,7 @@ RefPtr<Gfx::Font> FontDatabase::get(String const& family, unsigned size, unsigne
return nullptr;
}
RefPtr<Gfx::Font> FontDatabase::get(String const& family, const String& variant, unsigned size, Font::AllowInexactSizeMatch allow_inexact_size_match)
RefPtr<Gfx::Font> FontDatabase::get(FlyString const& family, FlyString const& variant, unsigned size, Font::AllowInexactSizeMatch allow_inexact_size_match)
{
for (auto typeface : m_private->typefaces) {
if (typeface->family() == family && typeface->variant() == variant)

View file

@ -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(const String& family, unsigned size, unsigned weight, unsigned slope, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No);
RefPtr<Gfx::Font> get(const String& family, const String& variant, unsigned size, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No);
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_by_name(StringView);
void for_each_font(Function<void(const Gfx::Font&)>);
void for_each_fixed_width_font(Function<void(const Gfx::Font&)>);

View file

@ -6,9 +6,9 @@
#pragma once
#include <AK/FlyString.h>
#include <AK/Function.h>
#include <AK/RefCounted.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibGfx/BitmapFont.h>
#include <LibGfx/Font.h>
@ -24,8 +24,8 @@ public:
{
}
String family() const { return m_family; }
String variant() const { return m_variant; }
FlyString const& family() const { return m_family; }
FlyString const& variant() const { return m_variant; }
unsigned weight() const;
u8 slope() const;
@ -39,8 +39,8 @@ public:
RefPtr<Font> get_font(unsigned size, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No) const;
private:
String m_family;
String m_variant;
FlyString m_family;
FlyString m_variant;
Vector<RefPtr<BitmapFont>> m_bitmap_fonts;
RefPtr<TTF::Font> m_ttf_font;