mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-06 16:19:23 +00:00
LibGfx+LibWeb: Store Typeface and Font-related types in RefPtr to const
This commit is contained in:
parent
ffd0259bef
commit
be2dd91289
Notes:
github-actions[bot]
2025-04-16 16:44:15 +00:00
Author: https://github.com/ADKaster
Commit: be2dd91289
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4362
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/Hendiadyoin1
13 changed files with 28 additions and 28 deletions
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
namespace Gfx {
|
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_typeface(move(typeface))
|
||||||
, m_point_width(point_width)
|
, m_point_width(point_width)
|
||||||
, m_point_height(point_height)
|
, m_point_height(point_height)
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace Gfx {
|
||||||
|
|
||||||
class ScaledFont final : public Gfx::Font {
|
class ScaledFont final : public Gfx::Font {
|
||||||
public:
|
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;
|
ScaledFontMetrics metrics() const;
|
||||||
|
|
||||||
// ^Gfx::Font
|
// ^Gfx::Font
|
||||||
|
@ -45,7 +45,7 @@ public:
|
||||||
SkFont skia_font(float scale) const;
|
SkFont skia_font(float scale) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NonnullRefPtr<Typeface> m_typeface;
|
NonnullRefPtr<Typeface const> m_typeface;
|
||||||
float m_x_scale { 0.0f };
|
float m_x_scale { 0.0f };
|
||||||
float m_y_scale { 0.0f };
|
float m_y_scale { 0.0f };
|
||||||
float m_point_width { 0.0f };
|
float m_point_width { 0.0f };
|
||||||
|
|
|
@ -8,12 +8,12 @@
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
||||||
void FontCascadeList::add(NonnullRefPtr<Font> font)
|
void FontCascadeList::add(NonnullRefPtr<Font const> font)
|
||||||
{
|
{
|
||||||
m_fonts.append({ move(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) });
|
m_fonts.append({ move(font), move(unicode_ranges) });
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ public:
|
||||||
callback(font);
|
callback(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(NonnullRefPtr<Font> font);
|
void add(NonnullRefPtr<Font const> font);
|
||||||
void add(NonnullRefPtr<Font> font, Vector<UnicodeRange> unicode_ranges);
|
void add(NonnullRefPtr<Font const> font, Vector<UnicodeRange> unicode_ranges);
|
||||||
|
|
||||||
void extend(FontCascadeList const& other);
|
void extend(FontCascadeList const& other);
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ public:
|
||||||
bool equals(FontCascadeList const& other) const;
|
bool equals(FontCascadeList const& other) const;
|
||||||
|
|
||||||
struct Entry {
|
struct Entry {
|
||||||
NonnullRefPtr<Font> font;
|
NonnullRefPtr<Font const> font;
|
||||||
Optional<Vector<UnicodeRange>> unicode_ranges;
|
Optional<Vector<UnicodeRange>> unicode_ranges;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ public:
|
||||||
Rtl,
|
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_glyphs(move(glyphs))
|
||||||
, m_font(move(font))
|
, m_font(move(font))
|
||||||
, m_text_type(text_type)
|
, m_text_type(text_type)
|
||||||
|
@ -63,7 +63,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<DrawGlyph> m_glyphs;
|
Vector<DrawGlyph> m_glyphs;
|
||||||
NonnullRefPtr<Font> m_font;
|
NonnullRefPtr<Font const> m_font;
|
||||||
TextType m_text_type;
|
TextType m_text_type;
|
||||||
float m_width { 0 };
|
float m_width { 0 };
|
||||||
};
|
};
|
||||||
|
|
|
@ -198,7 +198,7 @@ public:
|
||||||
return *m_first_available_computed_font;
|
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);
|
m_font_list = move(font_list);
|
||||||
// https://drafts.csswg.org/css-fonts/#first-available-font
|
// https://drafts.csswg.org/css-fonts/#first-available-font
|
||||||
|
@ -251,8 +251,8 @@ private:
|
||||||
HashMap<PropertyID, NonnullRefPtr<CSSStyleValue const>> m_animated_property_values;
|
HashMap<PropertyID, NonnullRefPtr<CSSStyleValue const>> m_animated_property_values;
|
||||||
|
|
||||||
int m_math_depth { InitialValues::math_depth() };
|
int m_math_depth { InitialValues::math_depth() };
|
||||||
RefPtr<Gfx::FontCascadeList> m_font_list;
|
RefPtr<Gfx::FontCascadeList const> m_font_list;
|
||||||
RefPtr<Gfx::Font> m_first_available_computed_font;
|
RefPtr<Gfx::Font const> m_first_available_computed_font;
|
||||||
|
|
||||||
Optional<CSSPixels> m_line_height;
|
Optional<CSSPixels> m_line_height;
|
||||||
|
|
||||||
|
|
|
@ -559,7 +559,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
struct {
|
struct {
|
||||||
Color caret_color { InitialValues::caret_color() };
|
Color caret_color { InitialValues::caret_color() };
|
||||||
RefPtr<Gfx::FontCascadeList> font_list {};
|
RefPtr<Gfx::FontCascadeList const> font_list {};
|
||||||
CSSPixels font_size { InitialValues::font_size() };
|
CSSPixels font_size { InitialValues::font_size() };
|
||||||
int font_weight { InitialValues::font_weight() };
|
int font_weight { InitialValues::font_weight() };
|
||||||
Optional<Gfx::FontVariantAlternates> font_variant_alternates;
|
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_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_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_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_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; }
|
void set_font_variant_alternates(Optional<Gfx::FontVariantAlternates> font_variant_alternates) { m_inherited.font_variant_alternates = font_variant_alternates; }
|
||||||
|
|
|
@ -27,9 +27,9 @@
|
||||||
|
|
||||||
namespace Web::CSS {
|
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'.
|
// FIXME: 'Asynchronously' shouldn't mean 'later on the main thread'.
|
||||||
// Can we defer this to a background thread?
|
// Can we defer this to a background thread?
|
||||||
|
|
|
@ -107,8 +107,8 @@ private:
|
||||||
Vector<ParsedFontFace::Source> m_urls; // [[Urls]]
|
Vector<ParsedFontFace::Source> m_urls; // [[Urls]]
|
||||||
ByteBuffer m_binary_data {}; // [[Data]]
|
ByteBuffer m_binary_data {}; // [[Data]]
|
||||||
|
|
||||||
RefPtr<Gfx::Typeface> m_parsed_font;
|
RefPtr<Gfx::Typeface const> m_parsed_font;
|
||||||
RefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface>>> m_font_load_promise;
|
RefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface const>>> m_font_load_promise;
|
||||||
|
|
||||||
// https://drafts.csswg.org/css-font-loading/#css-connected
|
// https://drafts.csswg.org/css-font-loading/#css-connected
|
||||||
bool m_is_css_connected { false };
|
bool m_is_css_connected { false };
|
||||||
|
|
|
@ -229,7 +229,7 @@ void FontLoader::resource_did_load_or_fail()
|
||||||
m_style_computer.did_load_font(m_family_name);
|
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 (!m_vector_font) {
|
||||||
if (!resource())
|
if (!resource())
|
||||||
|
@ -261,7 +261,7 @@ void FontLoader::start_loading_next_url()
|
||||||
set_resource(ResourceLoader::the().load_resource(Resource::Type::Generic, request));
|
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
|
// 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());
|
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
|
[[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) {
|
if (auto* loader_list = loader_or_typeface.get_pointer<FontLoaderList*>(); loader_list) {
|
||||||
for (auto const& loader : **loader_list) {
|
for (auto const& loader : **loader_list) {
|
||||||
if (auto font = loader->font_with_point_size(point_size); font)
|
if (auto font = loader->font_with_point_size(point_size); font)
|
||||||
|
|
|
@ -320,9 +320,9 @@ public:
|
||||||
virtual ~FontLoader() override;
|
virtual ~FontLoader() override;
|
||||||
|
|
||||||
Vector<Gfx::UnicodeRange> const& unicode_ranges() const { return m_unicode_ranges; }
|
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();
|
void start_loading_next_url();
|
||||||
|
|
||||||
bool is_loading() const { return resource() && resource()->is_pending(); }
|
bool is_loading() const { return resource() && resource()->is_pending(); }
|
||||||
|
@ -334,12 +334,12 @@ private:
|
||||||
|
|
||||||
void resource_did_load_or_fail();
|
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;
|
StyleComputer& m_style_computer;
|
||||||
FlyString m_family_name;
|
FlyString m_family_name;
|
||||||
Vector<Gfx::UnicodeRange> m_unicode_ranges;
|
Vector<Gfx::UnicodeRange> m_unicode_ranges;
|
||||||
RefPtr<Gfx::Typeface> m_vector_font;
|
RefPtr<Gfx::Typeface const> m_vector_font;
|
||||||
Vector<::URL::URL> m_urls;
|
Vector<::URL::URL> m_urls;
|
||||||
Function<void(FontLoader const&)> m_on_load;
|
Function<void(FontLoader const&)> m_on_load;
|
||||||
Function<void()> m_on_fail;
|
Function<void()> m_on_fail;
|
||||||
|
|
|
@ -30,7 +30,7 @@ public:
|
||||||
|
|
||||||
struct Chunk {
|
struct Chunk {
|
||||||
Utf8View view;
|
Utf8View view;
|
||||||
NonnullRefPtr<Gfx::Font> font;
|
NonnullRefPtr<Gfx::Font const> font;
|
||||||
size_t start { 0 };
|
size_t start { 0 };
|
||||||
size_t length { 0 };
|
size_t length { 0 };
|
||||||
bool has_breaking_newline { false };
|
bool has_breaking_newline { false };
|
||||||
|
|
|
@ -31,7 +31,7 @@ private:
|
||||||
DevicePixelRect timeline_rect;
|
DevicePixelRect timeline_rect;
|
||||||
|
|
||||||
String timestamp;
|
String timestamp;
|
||||||
RefPtr<Gfx::Font> timestamp_font;
|
RefPtr<Gfx::Font const> timestamp_font;
|
||||||
DevicePixelRect timestamp_rect;
|
DevicePixelRect timestamp_rect;
|
||||||
|
|
||||||
DevicePixelRect speaker_button_rect;
|
DevicePixelRect speaker_button_rect;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue