LibGfx+LibWeb: Rename Gfx::VectorFont to Gfx::Typeface

Typeface is a more widely used name for the data represented by
class previously named VectorFont.

Now:
- Typeface represents decoded font that is not ready for rendering
- ScaledFont represents the combination of typeface and size for
  rendering
This commit is contained in:
Aliaksandr Kalenik 2024-06-28 20:27:00 +02:00 committed by Andreas Kling
parent e2726ce8e4
commit d5926a3231
Notes: sideshowbarker 2024-07-17 06:40:21 +09:00
15 changed files with 45 additions and 45 deletions

View File

@ -45,7 +45,7 @@ shared_library("LibGfx") {
"Font/OpenType/Tables.cpp",
"Font/ScaledFont.cpp",
"Font/Typeface.cpp",
"Font/VectorFont.cpp",
"Font/Typeface.cpp",
"Font/WOFF/Font.cpp",
"Font/WOFF2/Font.cpp",
"FontCascadeList.cpp",

View File

@ -20,7 +20,7 @@ set(SOURCES
Font/OpenType/Hinting/Opcodes.cpp
Font/OpenType/Tables.cpp
Font/ScaledFont.cpp
Font/VectorFont.cpp
Font/Typeface.cpp
Font/WOFF/Font.cpp
Font/WOFF2/Font.cpp
GradientPainting.cpp

View File

@ -24,7 +24,7 @@ FontDatabase& FontDatabase::the()
}
struct FontDatabase::Private {
HashMap<FlyString, Vector<NonnullRefPtr<VectorFont>>, AK::ASCIICaseInsensitiveFlyStringTraits> typeface_by_family;
HashMap<FlyString, Vector<NonnullRefPtr<Typeface>>, AK::ASCIICaseInsensitiveFlyStringTraits> typeface_by_family;
};
void FontDatabase::load_all_fonts_from_uri(StringView uri)
@ -47,7 +47,7 @@ void FontDatabase::load_all_fonts_from_uri(StringView uri)
if (auto font_or_error = OpenType::Font::try_load_from_resource(resource); !font_or_error.is_error()) {
auto font = font_or_error.release_value();
auto& family = m_private->typeface_by_family.ensure(font->family(), [] {
return Vector<NonnullRefPtr<VectorFont>> {};
return Vector<NonnullRefPtr<Typeface>> {};
});
family.append(font);
}
@ -55,7 +55,7 @@ void FontDatabase::load_all_fonts_from_uri(StringView uri)
if (auto font_or_error = WOFF::Font::try_load_from_resource(resource); !font_or_error.is_error()) {
auto font = font_or_error.release_value();
auto& family = m_private->typeface_by_family.ensure(font->family(), [] {
return Vector<NonnullRefPtr<VectorFont>> {};
return Vector<NonnullRefPtr<Typeface>> {};
});
family.append(font);
}
@ -94,7 +94,7 @@ RefPtr<Gfx::Font> FontDatabase::get(FlyString const& family, FlyString const& va
return nullptr;
}
void FontDatabase::for_each_typeface_with_family_name(FlyString const& family_name, Function<void(VectorFont const&)> callback)
void FontDatabase::for_each_typeface_with_family_name(FlyString const& family_name, Function<void(Typeface const&)> callback)
{
auto it = m_private->typeface_by_family.find(family_name);
if (it == m_private->typeface_by_family.end())

View File

@ -12,7 +12,7 @@
#include <AK/HashMap.h>
#include <AK/OwnPtr.h>
#include <LibGfx/Font/FontWeight.h>
#include <LibGfx/Font/VectorFont.h>
#include <LibGfx/Font/Typeface.h>
#include <LibGfx/Forward.h>
namespace Gfx {
@ -24,7 +24,7 @@ public:
RefPtr<Gfx::Font> get(FlyString const& family, float point_size, unsigned weight, unsigned width, unsigned slope);
RefPtr<Gfx::Font> get(FlyString const& family, FlyString const& variant, float point_size);
void for_each_typeface_with_family_name(FlyString const& family_name, Function<void(VectorFont const&)>);
void for_each_typeface_with_family_name(FlyString const& family_name, Function<void(Typeface const&)>);
void load_all_fonts_from_uri(StringView);

View File

@ -17,7 +17,7 @@
#include <LibGfx/Font/OpenType/Cmap.h>
#include <LibGfx/Font/OpenType/Glyf.h>
#include <LibGfx/Font/OpenType/Tables.h>
#include <LibGfx/Font/VectorFont.h>
#include <LibGfx/Font/Typeface.h>
namespace OpenType {
@ -45,7 +45,7 @@ struct FontOptions {
u32 skip_tables { 0 };
};
class Font : public Gfx::VectorFont {
class Font : public Gfx::Typeface {
AK_MAKE_NONCOPYABLE(Font);
public:

View File

@ -10,7 +10,7 @@
namespace Gfx {
ScaledFont::ScaledFont(NonnullRefPtr<VectorFont> font, float point_width, float point_height, unsigned dpi_x, unsigned dpi_y)
ScaledFont::ScaledFont(NonnullRefPtr<Typeface> font, float point_width, float point_height, unsigned dpi_x, unsigned dpi_y)
: m_font(move(font))
, m_point_width(point_width)
, m_point_height(point_height)

View File

@ -10,7 +10,7 @@
#include <AK/HashMap.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Font/Font.h>
#include <LibGfx/Font/VectorFont.h>
#include <LibGfx/Font/Typeface.h>
namespace Gfx {
@ -23,7 +23,7 @@ struct GlyphIndexWithSubpixelOffset {
class ScaledFont final : public Gfx::Font {
public:
ScaledFont(NonnullRefPtr<VectorFont>, float point_width, float point_height, unsigned dpi_x = DEFAULT_DPI, unsigned dpi_y = DEFAULT_DPI);
ScaledFont(NonnullRefPtr<Typeface>, float point_width, float point_height, unsigned dpi_x = DEFAULT_DPI, unsigned dpi_y = DEFAULT_DPI);
u32 glyph_id_for_code_point(u32 code_point) const { return m_font->glyph_id_for_code_point(code_point); }
ScaledFontMetrics metrics() const { return m_font->metrics(m_x_scale, m_y_scale); }
ScaledGlyphMetrics glyph_metrics(u32 glyph_id) const { return m_font->glyph_metrics(glyph_id, m_x_scale, m_y_scale, m_point_width, m_point_height); }
@ -58,7 +58,7 @@ public:
virtual bool has_color_bitmaps() const override { return m_font->has_color_bitmaps(); }
private:
NonnullRefPtr<VectorFont> m_font;
NonnullRefPtr<Typeface> m_font;
float m_x_scale { 0.0f };
float m_y_scale { 0.0f };
float m_point_width { 0.0f };

View File

@ -5,21 +5,21 @@
*/
#include <LibGfx/Font/ScaledFont.h>
#include <LibGfx/Font/VectorFont.h>
#include <LibGfx/Font/Typeface.h>
namespace Gfx {
VectorFont::VectorFont() = default;
VectorFont::~VectorFont() = default;
Typeface::Typeface() = default;
Typeface::~Typeface() = default;
NonnullRefPtr<ScaledFont> VectorFont::scaled_font(float point_size) const
NonnullRefPtr<ScaledFont> Typeface::scaled_font(float point_size) const
{
auto it = m_scaled_fonts.find(point_size);
if (it != m_scaled_fonts.end())
return *it->value;
// FIXME: It might be nice to have a global cap on the number of fonts we cache
// instead of doing it at the per-VectorFont level like this.
// instead of doing it at the per-Typeface level like this.
constexpr size_t max_cached_font_size_count = 128;
if (m_scaled_fonts.size() > max_cached_font_size_count)
m_scaled_fonts.remove(m_scaled_fonts.begin());

View File

@ -39,9 +39,9 @@ struct ScaledGlyphMetrics {
float left_side_bearing;
};
class VectorFont : public RefCounted<VectorFont> {
class Typeface : public RefCounted<Typeface> {
public:
virtual ~VectorFont();
virtual ~Typeface();
virtual ScaledFontMetrics metrics(float x_scale, float y_scale) const = 0;
virtual ScaledGlyphMetrics glyph_metrics(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const = 0;
virtual float glyph_advance(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const = 0;
@ -63,7 +63,7 @@ public:
[[nodiscard]] NonnullRefPtr<ScaledFont> scaled_font(float point_size) const;
protected:
VectorFont();
Typeface();
private:
mutable HashMap<float, NonnullRefPtr<ScaledFont>> m_scaled_fonts;

View File

@ -13,11 +13,11 @@
#include <AK/RefCounted.h>
#include <LibCore/MappedFile.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Font/VectorFont.h>
#include <LibGfx/Font/Typeface.h>
namespace WOFF {
class Font : public Gfx::VectorFont {
class Font : public Gfx::Typeface {
AK_MAKE_NONCOPYABLE(Font);
public:
@ -43,14 +43,14 @@ public:
virtual bool has_color_bitmaps() const override { return m_input_font->has_color_bitmaps(); }
private:
Font(NonnullRefPtr<Gfx::VectorFont const> input_font, ByteBuffer input_font_buffer)
Font(NonnullRefPtr<Gfx::Typeface const> input_font, ByteBuffer input_font_buffer)
: m_input_font_buffer(move(input_font_buffer))
, m_input_font(move(input_font))
{
}
ByteBuffer m_input_font_buffer;
NonnullRefPtr<Gfx::VectorFont const> m_input_font;
NonnullRefPtr<Gfx::Typeface const> m_input_font;
};
}

View File

@ -13,11 +13,11 @@
#include <AK/Stream.h>
#include <AK/String.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Font/VectorFont.h>
#include <LibGfx/Font/Typeface.h>
namespace WOFF2 {
class Font : public Gfx::VectorFont {
class Font : public Gfx::Typeface {
AK_MAKE_NONCOPYABLE(Font);
public:
@ -44,14 +44,14 @@ public:
virtual bool has_color_bitmaps() const override { return m_input_font->has_color_bitmaps(); }
private:
Font(NonnullRefPtr<Gfx::VectorFont> input_font, ByteBuffer input_font_buffer)
Font(NonnullRefPtr<Gfx::Typeface> input_font, ByteBuffer input_font_buffer)
: m_input_font_buffer(move(input_font_buffer))
, m_input_font(move(input_font))
{
}
ByteBuffer m_input_font_buffer;
NonnullRefPtr<Gfx::VectorFont> m_input_font;
NonnullRefPtr<Gfx::Typeface> m_input_font;
};
}

View File

@ -6,7 +6,7 @@
#include <LibCore/Promise.h>
#include <LibGfx/Font/OpenType/Font.h>
#include <LibGfx/Font/VectorFont.h>
#include <LibGfx/Font/Typeface.h>
#include <LibGfx/Font/WOFF/Font.h>
#include <LibGfx/Font/WOFF2/Font.h>
#include <LibJS/Heap/Heap.h>
@ -26,9 +26,9 @@
namespace Web::CSS {
static NonnullRefPtr<Core::Promise<NonnullRefPtr<Gfx::VectorFont>>> load_vector_font(ByteBuffer const& data)
static NonnullRefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface>>> load_vector_font(ByteBuffer const& data)
{
auto promise = Core::Promise<NonnullRefPtr<Gfx::VectorFont>>::construct();
auto promise = Core::Promise<NonnullRefPtr<Gfx::Typeface>>::construct();
// FIXME: 'Asynchronously' shouldn't mean 'later on the main thread'.
// Can we defer this to a background thread?

View File

@ -6,7 +6,7 @@
#pragma once
#include <LibGfx/Font/VectorFont.h>
#include <LibGfx/Font/Typeface.h>
#include <LibURL/URL.h>
#include <LibWeb/Bindings/FontFacePrototype.h>
#include <LibWeb/Bindings/PlatformObject.h>
@ -104,8 +104,8 @@ private:
Vector<ParsedFontFace::Source> m_urls; // [[Urls]]
ByteBuffer m_binary_data; // [[Data]]
RefPtr<Gfx::VectorFont> m_parsed_font;
RefPtr<Core::Promise<NonnullRefPtr<Gfx::VectorFont>>> m_font_load_promise;
RefPtr<Gfx::Typeface> m_parsed_font;
RefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface>>> m_font_load_promise;
// https://drafts.csswg.org/css-font-loading/#css-connected
bool m_is_css_connected { false };

View File

@ -21,7 +21,7 @@
#include <LibGfx/Font/FontStyleMapping.h>
#include <LibGfx/Font/OpenType/Font.h>
#include <LibGfx/Font/ScaledFont.h>
#include <LibGfx/Font/VectorFont.h>
#include <LibGfx/Font/Typeface.h>
#include <LibGfx/Font/WOFF/Font.h>
#include <LibGfx/Font/WOFF2/Font.h>
#include <LibWeb/Animations/AnimationEffect.h>
@ -162,7 +162,7 @@ void FontLoader::start_loading_next_url()
set_resource(ResourceLoader::the().load_resource(Resource::Type::Generic, request));
}
ErrorOr<NonnullRefPtr<Gfx::VectorFont>> FontLoader::try_load_font()
ErrorOr<NonnullRefPtr<Gfx::Typeface>> FontLoader::try_load_font()
{
// FIXME: This could maybe use the format() provided in @font-face as well, since often the mime type is just application/octet-stream and we have to try every format
auto const& mime_type = resource()->mime_type();
@ -197,7 +197,7 @@ ErrorOr<NonnullRefPtr<Gfx::VectorFont>> FontLoader::try_load_font()
struct StyleComputer::MatchingFontCandidate {
FontFaceKey key;
Variant<FontLoaderList*, Gfx::VectorFont const*> loader_or_typeface;
Variant<FontLoaderList*, Gfx::Typeface const*> loader_or_typeface;
[[nodiscard]] RefPtr<Gfx::FontCascadeList const> font_with_point_size(float point_size) const
{
@ -210,7 +210,7 @@ struct StyleComputer::MatchingFontCandidate {
return font_list;
}
font_list->add(loader_or_typeface.get<Gfx::VectorFont const*>()->scaled_font(point_size));
font_list->add(loader_or_typeface.get<Gfx::Typeface const*>()->scaled_font(point_size));
return font_list;
}
};
@ -1853,7 +1853,7 @@ RefPtr<Gfx::FontCascadeList const> StyleComputer::font_matching_algorithm(FontFa
if (font_key_and_loader.key.family_name.equals_ignoring_ascii_case(key.family_name))
matching_family_fonts.empend(font_key_and_loader.key, const_cast<FontLoaderList*>(&font_key_and_loader.value));
}
Gfx::FontDatabase::the().for_each_typeface_with_family_name(key.family_name, [&](Gfx::VectorFont const& typeface) {
Gfx::FontDatabase::the().for_each_typeface_with_family_name(key.family_name, [&](Gfx::Typeface const& typeface) {
matching_family_fonts.empend(
FontFaceKey {
.family_name = typeface.family(),

View File

@ -10,7 +10,7 @@
#include <AK/HashMap.h>
#include <AK/Optional.h>
#include <AK/OwnPtr.h>
#include <LibGfx/Font/VectorFont.h>
#include <LibGfx/Font/Typeface.h>
#include <LibWeb/Animations/KeyframeEffect.h>
#include <LibWeb/CSS/CSSFontFaceRule.h>
#include <LibWeb/CSS/CSSKeyframesRule.h>
@ -238,7 +238,7 @@ public:
virtual ~FontLoader() override;
Vector<Gfx::UnicodeRange> const& unicode_ranges() const { return m_unicode_ranges; }
RefPtr<Gfx::VectorFont> vector_font() const { return m_vector_font; }
RefPtr<Gfx::Typeface> vector_font() const { return m_vector_font; }
virtual void resource_did_load() override;
virtual void resource_did_fail() override;
@ -247,12 +247,12 @@ public:
void start_loading_next_url();
private:
ErrorOr<NonnullRefPtr<Gfx::VectorFont>> try_load_font();
ErrorOr<NonnullRefPtr<Gfx::Typeface>> try_load_font();
StyleComputer& m_style_computer;
FlyString m_family_name;
Vector<Gfx::UnicodeRange> m_unicode_ranges;
RefPtr<Gfx::VectorFont> m_vector_font;
RefPtr<Gfx::Typeface> m_vector_font;
Vector<URL::URL> m_urls;
Function<void(FontLoader const&)> m_on_load;
Function<void()> m_on_fail;