Commit graph

30 commits

Author SHA1 Message Date
Callum Law
8fb55a31a9 LibWeb: Pass @font-feature-values data when resolving shape features 2026-03-20 16:08:32 -05:00
Callum Law
02c572c21e LibWeb: Clear font cache when @font-feature-values rule modified
We now clear the computed font cache whenever a `@font-feature-values`
rule is added, removed, or has one of it's descriptors modified.

This isn't observable yet since we don't actually respect
`@font-feature-values` rules, but that will come in a later commit
2026-03-20 16:08:32 -05:00
Callum Law
cc5d1a9b4d LibWeb: Rename did_load_font to clear_computed_font_cache
This will be used in cases other than font loading in the future (i.e.
changes to `@font-feature-values` rules)
2026-03-20 16:08:32 -05:00
Aliaksandr Kalenik
d8b8a7d3f3 LibWeb: Mark only font-using elements for style update on font load
Instead of calling invalidate_style(CSSFontLoaded) which marks the
entire subtree for style recomputation, use set_needs_style_update(true)
to mark only individual elements that reference the loaded font family.

This is correct because element_uses_font_family() checks the computed
(inherited) font-family value, so descendants inheriting the font will
match individually, while descendants that override font-family to a
different font are skipped entirely.
2026-03-11 02:10:15 +01:00
Sam Atkins
5e3f4d71cc LibWeb/CSS: Remove number_of_css_font_faces_with_loading_in_progress()
This is now unused as of the previous commit.
2026-02-24 15:44:32 +00:00
Sam Atkins
4ea87db0a8 LibWeb/CSS: Load all fonts through FontFace::load()
The spec requires us to follow the steps in FontFace::load() whenever a
font is loaded. The simplest way to do so, is to make that the only way
we load fonts. :^)

To support this, FontFace::load() uses its connected CSSFontFaceRule's
ParsedFontFace if it's available.

The 1 regression in generic-family-keywords-003.html seems to be a false
positive: we don't support the system-ui font keyword.
2026-02-24 15:44:32 +00:00
Sam Atkins
c9350374a1 LibWeb/CSS: Update a couple of font-related comments 2026-02-24 10:05:09 +00:00
Sam Atkins
f657a4b71b LibWeb/CSS: Parse @font-face { font-weight } with two values
WPT has coverage for matching but not parsing, so the test is homemade.
2026-02-24 10:05:09 +00:00
Sam Atkins
2660db3f52 LibWeb/CSS: Make FontFaceKey weights a range of values
For now, both the `min` and `max` are the single value we had before.
2026-02-24 10:05:09 +00:00
Sam Atkins
9e85e52db9 LibWeb/CSS: Reuse OwnFontFaceKey::hash() in hash traits 2026-02-24 10:05:09 +00:00
Callum Law
d998a0aeeb LibWeb: Add generic string_from_style_value method
Reduces duplication in line with `Time::from_style_value()`,
`Angle::from_style_value()` etc
2026-02-17 12:25:27 +00:00
Aliaksandr Kalenik
901cc28272 LibWeb: Reduce recompilation impact of DOM/Document.h
Remove 11 heavy includes from Document.h that were only needed for
pointer/reference types (already forward-declared in Forward.h), and
extract the nested ViewportClient interface to a standalone header.

This reduces Document.h's recompilation cascade from ~1228 files to
~717 files (42% reduction). Headers like BrowsingContext.h that were
previously transitively included see even larger improvements (from
~1228 down to ~73 dependents).
2026-02-11 20:02:28 +01:00
Callum Law
11d524bda4 LibWeb: Support CSS font-optical-sizing property 2026-02-03 11:44:25 +00:00
Callum Law
b55023fad3 LibGfx+LibWeb: Resolve font features per font rather than per element
Previously we would resolve font features
(https://drafts.csswg.org/css-fonts-4/#feature-variation-precedence)
per element, while this works for the current subset of the font feature
resolution algorithm that we support, some as yet unimplemented parts
require us to know whether we are resolving against a CSS @font-face
rule, and if so which one (e.g. applying descriptors from the @font-face
rule, deciding which @font-feature-values rules to apply, etc).

To achieve this we store the data required to resolve font features in a
struct and pass that to `FontComputer` which resolves the font features
and stores them with the computed `Font`.

We no longer need to invalidate the font shaping cache when features
change since the features are defined per font (and therefore won't ever
change).
2026-02-02 14:11:43 +00:00
Callum Law
5917a8c1c8 LibGfx+LibWeb: Allow setting FontVariationSettings for default font
While our default font supporting variations is unlikely, this is
nevertheless required for our fallback font to be considered equal to
it's non-default/fallback equivalent (i.e. `font-family: serif`) which
in turn is required for LineBuilder to merge chunks into a single
fragment.
2026-02-02 14:11:43 +00:00
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