Skip to content

Commit be2dd91

Browse files
committed
LibGfx+LibWeb: Store Typeface and Font-related types in RefPtr to const
1 parent ffd0259 commit be2dd91

File tree

13 files changed

+28
-28
lines changed

13 files changed

+28
-28
lines changed

Libraries/LibGfx/Font/ScaledFont.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace Gfx {
1818

19-
ScaledFont::ScaledFont(NonnullRefPtr<Typeface> typeface, float point_width, float point_height, unsigned dpi_x, unsigned dpi_y)
19+
ScaledFont::ScaledFont(NonnullRefPtr<Typeface const> typeface, float point_width, float point_height, unsigned dpi_x, unsigned dpi_y)
2020
: m_typeface(move(typeface))
2121
, m_point_width(point_width)
2222
, m_point_height(point_height)

Libraries/LibGfx/Font/ScaledFont.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Gfx {
1717

1818
class ScaledFont final : public Gfx::Font {
1919
public:
20-
ScaledFont(NonnullRefPtr<Typeface>, float point_width, float point_height, unsigned dpi_x = DEFAULT_DPI, unsigned dpi_y = DEFAULT_DPI);
20+
ScaledFont(NonnullRefPtr<Typeface const>, float point_width, float point_height, unsigned dpi_x = DEFAULT_DPI, unsigned dpi_y = DEFAULT_DPI);
2121
ScaledFontMetrics metrics() const;
2222

2323
// ^Gfx::Font
@@ -45,7 +45,7 @@ class ScaledFont final : public Gfx::Font {
4545
SkFont skia_font(float scale) const;
4646

4747
private:
48-
NonnullRefPtr<Typeface> m_typeface;
48+
NonnullRefPtr<Typeface const> m_typeface;
4949
float m_x_scale { 0.0f };
5050
float m_y_scale { 0.0f };
5151
float m_point_width { 0.0f };

Libraries/LibGfx/FontCascadeList.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
namespace Gfx {
1010

11-
void FontCascadeList::add(NonnullRefPtr<Font> font)
11+
void FontCascadeList::add(NonnullRefPtr<Font const> font)
1212
{
1313
m_fonts.append({ move(font), {} });
1414
}
1515

16-
void FontCascadeList::add(NonnullRefPtr<Font> font, Vector<UnicodeRange> unicode_ranges)
16+
void FontCascadeList::add(NonnullRefPtr<Font const> font, Vector<UnicodeRange> unicode_ranges)
1717
{
1818
m_fonts.append({ move(font), move(unicode_ranges) });
1919
}

Libraries/LibGfx/FontCascadeList.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class FontCascadeList : public RefCounted<FontCascadeList> {
2929
callback(font);
3030
}
3131

32-
void add(NonnullRefPtr<Font> font);
33-
void add(NonnullRefPtr<Font> font, Vector<UnicodeRange> unicode_ranges);
32+
void add(NonnullRefPtr<Font const> font);
33+
void add(NonnullRefPtr<Font const> font, Vector<UnicodeRange> unicode_ranges);
3434

3535
void extend(FontCascadeList const& other);
3636

@@ -39,7 +39,7 @@ class FontCascadeList : public RefCounted<FontCascadeList> {
3939
bool equals(FontCascadeList const& other) const;
4040

4141
struct Entry {
42-
NonnullRefPtr<Font> font;
42+
NonnullRefPtr<Font const> font;
4343
Optional<Vector<UnicodeRange>> unicode_ranges;
4444
};
4545

Libraries/LibGfx/TextLayout.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class GlyphRun : public AtomicRefCounted<GlyphRun> {
4444
Rtl,
4545
};
4646

47-
GlyphRun(Vector<DrawGlyph>&& glyphs, NonnullRefPtr<Font> font, TextType text_type, float width)
47+
GlyphRun(Vector<DrawGlyph>&& glyphs, NonnullRefPtr<Font const> font, TextType text_type, float width)
4848
: m_glyphs(move(glyphs))
4949
, m_font(move(font))
5050
, m_text_type(text_type)
@@ -63,7 +63,7 @@ class GlyphRun : public AtomicRefCounted<GlyphRun> {
6363

6464
private:
6565
Vector<DrawGlyph> m_glyphs;
66-
NonnullRefPtr<Font> m_font;
66+
NonnullRefPtr<Font const> m_font;
6767
TextType m_text_type;
6868
float m_width { 0 };
6969
};

Libraries/LibWeb/CSS/ComputedProperties.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class ComputedProperties final : public JS::Cell {
198198
return *m_first_available_computed_font;
199199
}
200200

201-
void set_computed_font_list(NonnullRefPtr<Gfx::FontCascadeList> font_list)
201+
void set_computed_font_list(NonnullRefPtr<Gfx::FontCascadeList const> font_list)
202202
{
203203
m_font_list = move(font_list);
204204
// https://drafts.csswg.org/css-fonts/#first-available-font
@@ -251,8 +251,8 @@ class ComputedProperties final : public JS::Cell {
251251
HashMap<PropertyID, NonnullRefPtr<CSSStyleValue const>> m_animated_property_values;
252252

253253
int m_math_depth { InitialValues::math_depth() };
254-
RefPtr<Gfx::FontCascadeList> m_font_list;
255-
RefPtr<Gfx::Font> m_first_available_computed_font;
254+
RefPtr<Gfx::FontCascadeList const> m_font_list;
255+
RefPtr<Gfx::Font const> m_first_available_computed_font;
256256

257257
Optional<CSSPixels> m_line_height;
258258

Libraries/LibWeb/CSS/ComputedValues.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ class ComputedValues {
559559
protected:
560560
struct {
561561
Color caret_color { InitialValues::caret_color() };
562-
RefPtr<Gfx::FontCascadeList> font_list {};
562+
RefPtr<Gfx::FontCascadeList const> font_list {};
563563
CSSPixels font_size { InitialValues::font_size() };
564564
int font_weight { InitialValues::font_weight() };
565565
Optional<Gfx::FontVariantAlternates> font_variant_alternates;
@@ -749,7 +749,7 @@ class MutableComputedValues final : public ComputedValues {
749749

750750
void set_aspect_ratio(AspectRatio aspect_ratio) { m_noninherited.aspect_ratio = move(aspect_ratio); }
751751
void set_caret_color(Color caret_color) { m_inherited.caret_color = caret_color; }
752-
void set_font_list(NonnullRefPtr<Gfx::FontCascadeList> font_list) { m_inherited.font_list = move(font_list); }
752+
void set_font_list(NonnullRefPtr<Gfx::FontCascadeList const> font_list) { m_inherited.font_list = move(font_list); }
753753
void set_font_size(CSSPixels font_size) { m_inherited.font_size = font_size; }
754754
void set_font_weight(int font_weight) { m_inherited.font_weight = font_weight; }
755755
void set_font_variant_alternates(Optional<Gfx::FontVariantAlternates> font_variant_alternates) { m_inherited.font_variant_alternates = font_variant_alternates; }

Libraries/LibWeb/CSS/FontFace.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727

2828
namespace Web::CSS {
2929

30-
static NonnullRefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface>>> load_vector_font(JS::Realm& realm, ByteBuffer const& data)
30+
static NonnullRefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface const>>> load_vector_font(JS::Realm& realm, ByteBuffer const& data)
3131
{
32-
auto promise = Core::Promise<NonnullRefPtr<Gfx::Typeface>>::construct();
32+
auto promise = Core::Promise<NonnullRefPtr<Gfx::Typeface const>>::construct();
3333

3434
// FIXME: 'Asynchronously' shouldn't mean 'later on the main thread'.
3535
// Can we defer this to a background thread?

Libraries/LibWeb/CSS/FontFace.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ class FontFace final : public Bindings::PlatformObject {
107107
Vector<ParsedFontFace::Source> m_urls; // [[Urls]]
108108
ByteBuffer m_binary_data {}; // [[Data]]
109109

110-
RefPtr<Gfx::Typeface> m_parsed_font;
111-
RefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface>>> m_font_load_promise;
110+
RefPtr<Gfx::Typeface const> m_parsed_font;
111+
RefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface const>>> m_font_load_promise;
112112

113113
// https://drafts.csswg.org/css-font-loading/#css-connected
114114
bool m_is_css_connected { false };

Libraries/LibWeb/CSS/StyleComputer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ void FontLoader::resource_did_load_or_fail()
229229
m_style_computer.did_load_font(m_family_name);
230230
}
231231

232-
RefPtr<Gfx::Font> FontLoader::font_with_point_size(float point_size)
232+
RefPtr<Gfx::Font const> FontLoader::font_with_point_size(float point_size)
233233
{
234234
if (!m_vector_font) {
235235
if (!resource())
@@ -261,7 +261,7 @@ void FontLoader::start_loading_next_url()
261261
set_resource(ResourceLoader::the().load_resource(Resource::Type::Generic, request));
262262
}
263263

264-
ErrorOr<NonnullRefPtr<Gfx::Typeface>> FontLoader::try_load_font()
264+
ErrorOr<NonnullRefPtr<Gfx::Typeface const>> FontLoader::try_load_font()
265265
{
266266
// 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
267267
auto mime_type = MimeSniff::MimeType::parse(resource()->mime_type());
@@ -295,7 +295,7 @@ struct StyleComputer::MatchingFontCandidate {
295295

296296
[[nodiscard]] RefPtr<Gfx::FontCascadeList const> font_with_point_size(float point_size) const
297297
{
298-
RefPtr<Gfx::FontCascadeList> font_list = Gfx::FontCascadeList::create();
298+
auto font_list = Gfx::FontCascadeList::create();
299299
if (auto* loader_list = loader_or_typeface.get_pointer<FontLoaderList*>(); loader_list) {
300300
for (auto const& loader : **loader_list) {
301301
if (auto font = loader->font_with_point_size(point_size); font)

0 commit comments

Comments
 (0)