LibGfx+LibWeb: Store Typeface and Font-related types in RefPtr to const

This commit is contained in:
Andrew Kaster 2025-04-15 15:48:14 -06:00 committed by Andrew Kaster
parent ffd0259bef
commit be2dd91289
Notes: github-actions[bot] 2025-04-16 16:44:15 +00:00
13 changed files with 28 additions and 28 deletions

View file

@ -16,7 +16,7 @@
namespace Gfx {
ScaledFont::ScaledFont(NonnullRefPtr<Typeface> typeface, float point_width, float point_height, unsigned dpi_x, unsigned dpi_y)
ScaledFont::ScaledFont(NonnullRefPtr<Typeface const> typeface, float point_width, float point_height, unsigned dpi_x, unsigned dpi_y)
: m_typeface(move(typeface))
, m_point_width(point_width)
, m_point_height(point_height)

View file

@ -17,7 +17,7 @@ namespace Gfx {
class ScaledFont final : public Gfx::Font {
public:
ScaledFont(NonnullRefPtr<Typeface>, float point_width, float point_height, unsigned dpi_x = DEFAULT_DPI, unsigned dpi_y = DEFAULT_DPI);
ScaledFont(NonnullRefPtr<Typeface const>, float point_width, float point_height, unsigned dpi_x = DEFAULT_DPI, unsigned dpi_y = DEFAULT_DPI);
ScaledFontMetrics metrics() const;
// ^Gfx::Font
@ -45,7 +45,7 @@ public:
SkFont skia_font(float scale) const;
private:
NonnullRefPtr<Typeface> m_typeface;
NonnullRefPtr<Typeface const> m_typeface;
float m_x_scale { 0.0f };
float m_y_scale { 0.0f };
float m_point_width { 0.0f };

View file

@ -8,12 +8,12 @@
namespace Gfx {
void FontCascadeList::add(NonnullRefPtr<Font> font)
void FontCascadeList::add(NonnullRefPtr<Font const> font)
{
m_fonts.append({ move(font), {} });
}
void FontCascadeList::add(NonnullRefPtr<Font> font, Vector<UnicodeRange> unicode_ranges)
void FontCascadeList::add(NonnullRefPtr<Font const> font, Vector<UnicodeRange> unicode_ranges)
{
m_fonts.append({ move(font), move(unicode_ranges) });
}

View file

@ -29,8 +29,8 @@ public:
callback(font);
}
void add(NonnullRefPtr<Font> font);
void add(NonnullRefPtr<Font> font, Vector<UnicodeRange> unicode_ranges);
void add(NonnullRefPtr<Font const> font);
void add(NonnullRefPtr<Font const> font, Vector<UnicodeRange> unicode_ranges);
void extend(FontCascadeList const& other);
@ -39,7 +39,7 @@ public:
bool equals(FontCascadeList const& other) const;
struct Entry {
NonnullRefPtr<Font> font;
NonnullRefPtr<Font const> font;
Optional<Vector<UnicodeRange>> unicode_ranges;
};

View file

@ -44,7 +44,7 @@ public:
Rtl,
};
GlyphRun(Vector<DrawGlyph>&& glyphs, NonnullRefPtr<Font> font, TextType text_type, float width)
GlyphRun(Vector<DrawGlyph>&& glyphs, NonnullRefPtr<Font const> font, TextType text_type, float width)
: m_glyphs(move(glyphs))
, m_font(move(font))
, m_text_type(text_type)
@ -63,7 +63,7 @@ public:
private:
Vector<DrawGlyph> m_glyphs;
NonnullRefPtr<Font> m_font;
NonnullRefPtr<Font const> m_font;
TextType m_text_type;
float m_width { 0 };
};

View file

@ -198,7 +198,7 @@ public:
return *m_first_available_computed_font;
}
void set_computed_font_list(NonnullRefPtr<Gfx::FontCascadeList> font_list)
void set_computed_font_list(NonnullRefPtr<Gfx::FontCascadeList const> font_list)
{
m_font_list = move(font_list);
// https://drafts.csswg.org/css-fonts/#first-available-font
@ -251,8 +251,8 @@ private:
HashMap<PropertyID, NonnullRefPtr<CSSStyleValue const>> m_animated_property_values;
int m_math_depth { InitialValues::math_depth() };
RefPtr<Gfx::FontCascadeList> m_font_list;
RefPtr<Gfx::Font> m_first_available_computed_font;
RefPtr<Gfx::FontCascadeList const> m_font_list;
RefPtr<Gfx::Font const> m_first_available_computed_font;
Optional<CSSPixels> m_line_height;

View file

@ -559,7 +559,7 @@ public:
protected:
struct {
Color caret_color { InitialValues::caret_color() };
RefPtr<Gfx::FontCascadeList> font_list {};
RefPtr<Gfx::FontCascadeList const> font_list {};
CSSPixels font_size { InitialValues::font_size() };
int font_weight { InitialValues::font_weight() };
Optional<Gfx::FontVariantAlternates> font_variant_alternates;
@ -749,7 +749,7 @@ public:
void set_aspect_ratio(AspectRatio aspect_ratio) { m_noninherited.aspect_ratio = move(aspect_ratio); }
void set_caret_color(Color caret_color) { m_inherited.caret_color = caret_color; }
void set_font_list(NonnullRefPtr<Gfx::FontCascadeList> font_list) { m_inherited.font_list = move(font_list); }
void set_font_list(NonnullRefPtr<Gfx::FontCascadeList const> font_list) { m_inherited.font_list = move(font_list); }
void set_font_size(CSSPixels font_size) { m_inherited.font_size = font_size; }
void set_font_weight(int font_weight) { m_inherited.font_weight = font_weight; }
void set_font_variant_alternates(Optional<Gfx::FontVariantAlternates> font_variant_alternates) { m_inherited.font_variant_alternates = font_variant_alternates; }

View file

@ -27,9 +27,9 @@
namespace Web::CSS {
static NonnullRefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface>>> load_vector_font(JS::Realm& realm, ByteBuffer const& data)
static NonnullRefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface const>>> load_vector_font(JS::Realm& realm, ByteBuffer const& data)
{
auto promise = Core::Promise<NonnullRefPtr<Gfx::Typeface>>::construct();
auto promise = Core::Promise<NonnullRefPtr<Gfx::Typeface const>>::construct();
// FIXME: 'Asynchronously' shouldn't mean 'later on the main thread'.
// Can we defer this to a background thread?

View file

@ -107,8 +107,8 @@ private:
Vector<ParsedFontFace::Source> m_urls; // [[Urls]]
ByteBuffer m_binary_data {}; // [[Data]]
RefPtr<Gfx::Typeface> m_parsed_font;
RefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface>>> m_font_load_promise;
RefPtr<Gfx::Typeface const> m_parsed_font;
RefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface const>>> m_font_load_promise;
// https://drafts.csswg.org/css-font-loading/#css-connected
bool m_is_css_connected { false };

View file

@ -229,7 +229,7 @@ void FontLoader::resource_did_load_or_fail()
m_style_computer.did_load_font(m_family_name);
}
RefPtr<Gfx::Font> FontLoader::font_with_point_size(float point_size)
RefPtr<Gfx::Font const> FontLoader::font_with_point_size(float point_size)
{
if (!m_vector_font) {
if (!resource())
@ -261,7 +261,7 @@ void FontLoader::start_loading_next_url()
set_resource(ResourceLoader::the().load_resource(Resource::Type::Generic, request));
}
ErrorOr<NonnullRefPtr<Gfx::Typeface>> FontLoader::try_load_font()
ErrorOr<NonnullRefPtr<Gfx::Typeface const>> 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 mime_type = MimeSniff::MimeType::parse(resource()->mime_type());
@ -295,7 +295,7 @@ struct StyleComputer::MatchingFontCandidate {
[[nodiscard]] RefPtr<Gfx::FontCascadeList const> font_with_point_size(float point_size) const
{
RefPtr<Gfx::FontCascadeList> font_list = Gfx::FontCascadeList::create();
auto font_list = Gfx::FontCascadeList::create();
if (auto* loader_list = loader_or_typeface.get_pointer<FontLoaderList*>(); loader_list) {
for (auto const& loader : **loader_list) {
if (auto font = loader->font_with_point_size(point_size); font)

View file

@ -320,9 +320,9 @@ public:
virtual ~FontLoader() override;
Vector<Gfx::UnicodeRange> const& unicode_ranges() const { return m_unicode_ranges; }
RefPtr<Gfx::Typeface> vector_font() const { return m_vector_font; }
RefPtr<Gfx::Typeface const> vector_font() const { return m_vector_font; }
RefPtr<Gfx::Font> font_with_point_size(float point_size);
RefPtr<Gfx::Font const> font_with_point_size(float point_size);
void start_loading_next_url();
bool is_loading() const { return resource() && resource()->is_pending(); }
@ -334,12 +334,12 @@ private:
void resource_did_load_or_fail();
ErrorOr<NonnullRefPtr<Gfx::Typeface>> try_load_font();
ErrorOr<NonnullRefPtr<Gfx::Typeface const>> try_load_font();
StyleComputer& m_style_computer;
FlyString m_family_name;
Vector<Gfx::UnicodeRange> m_unicode_ranges;
RefPtr<Gfx::Typeface> m_vector_font;
RefPtr<Gfx::Typeface const> m_vector_font;
Vector<::URL::URL> m_urls;
Function<void(FontLoader const&)> m_on_load;
Function<void()> m_on_fail;

View file

@ -30,7 +30,7 @@ public:
struct Chunk {
Utf8View view;
NonnullRefPtr<Gfx::Font> font;
NonnullRefPtr<Gfx::Font const> font;
size_t start { 0 };
size_t length { 0 };
bool has_breaking_newline { false };

View file

@ -31,7 +31,7 @@ private:
DevicePixelRect timeline_rect;
String timestamp;
RefPtr<Gfx::Font> timestamp_font;
RefPtr<Gfx::Font const> timestamp_font;
DevicePixelRect timestamp_rect;
DevicePixelRect speaker_button_rect;