From 6e86ad65e90f3d3e8ab849b0e217574aff75bc8d Mon Sep 17 00:00:00 2001 From: Jonne Ransijn Date: Sat, 26 Oct 2024 15:45:34 +0200 Subject: [PATCH] LibGfx: Use `FlyString` for family name This value gets converted to FlyString a lot, so let's just make it a FlyString in the first place! --- Userland/Libraries/LibGfx/Font/Font.h | 2 +- Userland/Libraries/LibGfx/Font/ScaledFont.h | 3 ++- Userland/Libraries/LibGfx/Font/Typeface.h | 2 +- Userland/Libraries/LibGfx/Font/TypefaceSkia.cpp | 4 ++-- Userland/Libraries/LibGfx/Font/TypefaceSkia.h | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibGfx/Font/Font.h b/Userland/Libraries/LibGfx/Font/Font.h index c1f08b8463d..0377048a938 100644 --- a/Userland/Libraries/LibGfx/Font/Font.h +++ b/Userland/Libraries/LibGfx/Font/Font.h @@ -85,7 +85,7 @@ public: virtual float width(StringView) const = 0; virtual float width(Utf8View const&) const = 0; - virtual String family() const = 0; + virtual FlyString family() const = 0; virtual NonnullRefPtr with_size(float point_size) const = 0; diff --git a/Userland/Libraries/LibGfx/Font/ScaledFont.h b/Userland/Libraries/LibGfx/Font/ScaledFont.h index 72327729021..24c681da6b5 100644 --- a/Userland/Libraries/LibGfx/Font/ScaledFont.h +++ b/Userland/Libraries/LibGfx/Font/ScaledFont.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include #include @@ -36,7 +37,7 @@ public: virtual u8 baseline() const override { return m_point_height; } // FIXME: Read from font virtual float width(StringView) const override; virtual float width(Utf8View const&) const override; - virtual String family() const override { return m_typeface->family(); } + virtual FlyString family() const override { return m_typeface->family(); } virtual NonnullRefPtr scaled_with_size(float point_size) const; virtual NonnullRefPtr with_size(float point_size) const override; diff --git a/Userland/Libraries/LibGfx/Font/Typeface.h b/Userland/Libraries/LibGfx/Font/Typeface.h index 8eb594aacf7..813e17f62ec 100644 --- a/Userland/Libraries/LibGfx/Font/Typeface.h +++ b/Userland/Libraries/LibGfx/Font/Typeface.h @@ -47,7 +47,7 @@ public: virtual u32 glyph_count() const = 0; virtual u16 units_per_em() const = 0; virtual u32 glyph_id_for_code_point(u32 code_point) const = 0; - virtual String family() const = 0; + virtual FlyString family() const = 0; virtual u16 weight() const = 0; virtual u16 width() const = 0; virtual u8 slope() const = 0; diff --git a/Userland/Libraries/LibGfx/Font/TypefaceSkia.cpp b/Userland/Libraries/LibGfx/Font/TypefaceSkia.cpp index 9be2ef443c5..fe55a0f2416 100644 --- a/Userland/Libraries/LibGfx/Font/TypefaceSkia.cpp +++ b/Userland/Libraries/LibGfx/Font/TypefaceSkia.cpp @@ -114,12 +114,12 @@ void TypefaceSkia::populate_glyph_page(GlyphPage& glyph_page, size_t page_index) } } -String TypefaceSkia::family() const +FlyString TypefaceSkia::family() const { if (!m_family.has_value()) { SkString family_name; impl().skia_typeface->getFamilyName(&family_name); - m_family = String::from_utf8_without_validation(ReadonlyBytes { family_name.c_str(), family_name.size() }); + m_family = FlyString::from_utf8_without_validation(ReadonlyBytes { family_name.c_str(), family_name.size() }); } return m_family.value(); } diff --git a/Userland/Libraries/LibGfx/Font/TypefaceSkia.h b/Userland/Libraries/LibGfx/Font/TypefaceSkia.h index 567857c2109..38f2a76e569 100644 --- a/Userland/Libraries/LibGfx/Font/TypefaceSkia.h +++ b/Userland/Libraries/LibGfx/Font/TypefaceSkia.h @@ -19,7 +19,7 @@ public: virtual u32 glyph_count() const override; virtual u16 units_per_em() const override; virtual u32 glyph_id_for_code_point(u32 code_point) const override; - virtual String family() const override; + virtual FlyString family() const override; virtual u16 weight() const override; virtual u16 width() const override; virtual u8 slope() const override; @@ -39,7 +39,7 @@ private: ReadonlyBytes m_buffer; unsigned m_ttc_index { 0 }; - mutable Optional m_family; + mutable Optional m_family; // This cache stores information per code point. // It's segmented into pages with data about 256 code points each.