Commit graph

15 commits

Author SHA1 Message Date
Andreas Kling
7bc7e80042 LibWeb: Only invalidate affected elements when @font-face font loads
Previously, when a @font-face font finished loading, we would clear the
entire computed font cache and invalidate style for the whole document.

This was overly conservative since most elements don't use the newly
loaded font. We now take a targeted approach inspired by Firefox:

1. Only clear cache entries that reference the loaded font family
2. Walk the DOM tree (including shadow trees) and only invalidate
   elements whose font-family property (or pseudo-elements' font-family)
   actually references the loaded font

This significantly reduces style invalidation work on pages with many
elements but only some using custom fonts.
2026-01-26 12:40:36 +01:00
Callum Law
52c09a6e87 LibWeb: Remove unnecessary call to FontDatabase::get()
This method was only called when `font_matching_algorithm` failed to
match a font (i.e. there are no fonts with a matching family name) in
which case this method would also fail to match a font.
2026-01-21 23:49:25 +01:00
Callum Law
73fbe24892 LibWeb: Add early return from font_matching_algorithm
We also add a `VERIFY_NOT_REACHED()` to make it clear that we will
always return a font if there is atleast one font in
`matching_family_fonts`
2026-01-21 23:49:25 +01:00
Callum Law
c35ecc8b1c LibWeb: Respect font-width for variable fonts 2026-01-21 23:49:25 +01:00
Callum Law
2f7848913b LibWeb: Always respect font-variation-settings
Previously we wouldn't respect font-variation-settings for fonts matched
through `font_matching_algorithm` (i.e. any fonts which didn't have an
exact loaded match).
2026-01-21 23:49:25 +01:00
Callum Law
44415fcbe7 LibWeb: Rename FontLoader::m_vector_font to m_typeface
The `VectorFont` type was renamed to `Typeface` in d5926a3 but this
member variable was never updated.

The getter for this was also unused so has been removed
2026-01-21 23:49:25 +01:00
Tim Ledbetter
3e704e0fd6 LibGfx+LibWeb: Fall back to system fonts for missing glyphs
When rendering text, if none of the fonts in the cascade list contain a
glyph for a given code point, we now query Skia's font manager to find
a system font that can render it.
2026-01-21 14:01:35 +01:00
Callum Law
7c544175e5 LibWeb: Cache compute_font_for_style_values
We already cached the result of `font_matching_algorithm` but we can
instead cache the entire function.
2026-01-11 14:10:37 +01:00
Shannon Booth
d901e937b6 LibWeb/CSS: Do not give internal stylesheets a location URL
This fixes Acid3 numbered test 72.
2026-01-09 10:54:11 +00:00
Tim Ledbetter
6e0bdd79e4 LibWeb: Mark FontFace as CSS-disconnected when font-face rule is removed 2026-01-05 16:15:58 +00:00
Tim Ledbetter
dab22f770d LibWeb: Add a corresponding FontFace object for a parsed @font-face rule 2026-01-05 16:15:58 +00:00
Tim Ledbetter
2a8db3b1f9 LibWeb: Propagate FontFace changes to CSSFontFaceRule 2026-01-05 16:15:58 +00:00
Andreas Kling
e2d5802942 LibJS: Don't capture CSS::FontFace in GC::Root while loading fonts
This prevents a reference cycle that was leaking entire realms on
test-web.
2025-12-26 11:57:00 +01:00
Callum Law
dca80ad5eb LibWeb: Account for animated values when computing font
Computing the font for an element in `compute_font` is premature since
we are yet to apply animated properties - instead we should compute the
value on the fly (with a cache to avoid unnecessary work) to ensure we
are respecting the latest values
2025-12-05 10:03:15 +00:00
Callum Law
6c236d04d8 LibWeb: Separate font computation logic from StyleComputer
Font computation and loading is distinct enough from style computation
that it makes more sense to have this in it's own class.

This will be useful later when we move the font loading process to
`ComputedProperties` in order to respect animated values.
2025-12-05 10:03:15 +00:00