Skip to content

LibWeb: Implement the font-size-adjust property - #6477

Closed
tcl3 wants to merge 4 commits into
LadybirdBrowser:masterfrom
tcl3:libweb_font_size_adjust
Closed

tcl3 wants to merge 4 commits into
LadybirdBrowser:masterfrom
tcl3:libweb_font_size_adjust

Conversation

@tcl3

@tcl3 tcl3 commented Oct 14, 2025

Copy link
Copy Markdown
Member

This PR implements the font-size-adjust property, which can be used to control how fonts are scaled based on various metrics. It can be used to ensure fallback fonts remain readable when their metrics differ significantly from the preferred font.

I believe the reason that some of the relevant reftests don't pass is that we are using font metrics that have been converted to CSSPixels, which results in noticable precision loss.

I'm also still trying to track down why I'm not getting the correct values when using from-font.

Results in a diff of +743/-7 WPT subtests in the css/css-fonts directory.

@tcl3
tcl3 requested a review from AtkinsSJ as a code owner October 14, 2025 15:42
auto first_value = parse_css_value_for_property(PropertyID::FontSizeAdjust, tokens);
if (!first_value)
return nullptr;
if (first_value->is_number() || first_value->is_calculated() || first_value->to_keyword() == Keyword::FromFont) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If/when #6426 is merged this won't be enough since <number> may produce a TreeCountingFunctionStyleValue - perhaps it should instead be written more like:

if (auto maybe_number_value = parse_number_value(tokens)) {
	if (tokens.has_next_token())
		return nullptr;
	transaction.commit();
	return maybe_number_value ;
}

auto keyword_value = parse_keyword_value(tokens);

if (!keyword_value)
	return nullptr;

if (keyword_value->to_keyword() == Keyword::FromFont) {
	if (tokens.has_next_token())
		return nullptr;
	transaction.commit();
	return keyword_value;
}

auto font_metric_keyword = keyword_to_font_metric(keyword_value->to_keyword());

if (!font_metric_keyword.has_value())
	return nullptr;

...

if (first_value->is_keyword() && first_value->as_keyword().keyword() == Keyword::ExHeight)
return second_value;

if (second_value->is_keyword() && second_value->as_keyword().keyword() == Keyword::ExHeight)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is ever true since we check above that second_value is NumberStyleValue, CalculatedStyleValue or from-font.

VERIFY_NOT_REACHED();
}

NonnullRefPtr<StyleValue const> StyleComputer::compute_font_size_adjust(NonnullRefPtr<StyleValue const> const& specified_value, ComputationContext const& computation_context)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have already absolutized the StyleValue at the start of compute_value_of_property so we can:

  • Rename the parameter to absolutized_value in line with the other non-font computation functions.
  • Not pass a length resolution context to resolve_number in a couple places below
  • Update this function to just take a FontMetrics rather than a full ComputationContext

Edit: I see now that we also call this from compute_font where we don't absolutize the value.


NonnullRefPtr<StyleValue const> StyleComputer::compute_font_size_adjust(NonnullRefPtr<StyleValue const> const& specified_value, ComputationContext const& computation_context)
{
if (specified_value->is_keyword() && specified_value->to_keyword() == Keyword::None)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a spec link

auto number = 0.0;
if (value_list[1]->is_number()) {
number = value_list[1]->as_number().number();
} else if (value.is_calculated() && value.as_calculated().resolves_to_number()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we not already converted CalculatedStyleValue to NumberStyleValue in compute_font_size_adjust?

number = *resolved_metric;
} else {
font_metric_keyword = keyword;
VERIFY_NOT_REACHED();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these changes be ammended into the "LibWeb: Resolve font-size-adjust computed value" commit?

m_attempted_pseudo_class_matches = results;
}

float adjusted_font_size() const { return m_adjusted_font_size; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't respect animated values of font-size-adjust

Comment thread Libraries/LibWeb/CSS/StyleComputer.cpp Outdated
auto const& font_size_adjust_specified_value = style.property(PropertyID::FontSizeAdjust, ComputedProperties::WithAnimationsApplied::No);
style.set_property(
PropertyID::FontSizeAdjust,
compute_font_size_adjust(font_size_adjust_specified_value, font_computation_context),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not great that we are calling compute_font_size_adjust twice for non-animated values (once here and then again in compute_property_values), ideally we would only compute the values required for creating a length resolution context here and then do compute_font_for_style_values at NodeWithStyle::apply_style() time, avoiding this call - it would have the added benefit of respecting animated values.

font_computation_context's length resolution context is based on the parent element where I presume we should be using one based on this element.

@github-actions github-actions Bot added the conflicts Pull request has merge conflicts that need resolution label Oct 17, 2025
@github-actions

Copy link
Copy Markdown

Your pull request has conflicts that need to be resolved before it can be reviewed and merged. Make sure to rebase your branch on top of the latest master.

@tcl3
tcl3 marked this pull request as draft October 25, 2025 21:21
@tcl3
tcl3 force-pushed the libweb_font_size_adjust branch from 42e1bbf to 54df618 Compare October 25, 2025 21:22
@github-actions github-actions Bot added conflicts Pull request has merge conflicts that need resolution and removed conflicts Pull request has merge conflicts that need resolution labels Oct 25, 2025
@github-actions

Copy link
Copy Markdown

Your pull request has conflicts that need to be resolved before it can be reviewed and merged. Make sure to rebase your branch on top of the latest master.

@tcl3
tcl3 force-pushed the libweb_font_size_adjust branch from 54df618 to 43a15fe Compare October 27, 2025 15:35
@github-actions github-actions Bot added conflicts Pull request has merge conflicts that need resolution and removed conflicts Pull request has merge conflicts that need resolution labels Oct 27, 2025
@github-actions

github-actions Bot commented Nov 3, 2025

Copy link
Copy Markdown

Your pull request has conflicts that need to be resolved before it can be reviewed and merged. Make sure to rebase your branch on top of the latest master.

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!

@github-actions github-actions Bot added the stale label Nov 25, 2025
@github-actions

github-actions Bot commented Dec 2, 2025

Copy link
Copy Markdown

This pull request has been closed because it has not had recent activity. Feel free to open a new pull request if you wish to still contribute these changes. Thank you for your contributions!

@github-actions github-actions Bot closed this Dec 2, 2025
@tcl3 tcl3 reopened this Dec 2, 2025
@tcl3
tcl3 force-pushed the libweb_font_size_adjust branch from 43a15fe to dce911b Compare December 2, 2025 03:45
@github-actions github-actions Bot removed the conflicts Pull request has merge conflicts that need resolution label Dec 2, 2025
@tcl3 tcl3 removed the stale label Dec 2, 2025
@github-actions github-actions Bot added the conflicts Pull request has merge conflicts that need resolution label Dec 5, 2025
@github-actions

github-actions Bot commented Dec 5, 2025

Copy link
Copy Markdown

Your pull request has conflicts that need to be resolved before it can be reviewed and merged. Make sure to rebase your branch on top of the latest master.

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!

@github-actions github-actions Bot added the stale label Dec 27, 2025
@tcl3
tcl3 force-pushed the libweb_font_size_adjust branch from dce911b to ddf335d Compare January 3, 2026 23:26
@github-actions github-actions Bot removed the conflicts Pull request has merge conflicts that need resolution label Jan 3, 2026
@tcl3
tcl3 force-pushed the libweb_font_size_adjust branch from ddf335d to 0bbabaa Compare January 3, 2026 23:27
@tcl3 tcl3 removed the stale label Jan 3, 2026
@github-actions github-actions Bot added the conflicts Pull request has merge conflicts that need resolution label Jan 13, 2026
@github-actions

Copy link
Copy Markdown

Your pull request has conflicts that need to be resolved before it can be reviewed and merged. Make sure to rebase your branch on top of the latest master.

@github-actions

github-actions Bot commented Feb 4, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!

@github-actions github-actions Bot added the stale label Feb 4, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been closed because it has not had recent activity. Feel free to open a new pull request if you wish to still contribute these changes. Thank you for your contributions!

@github-actions github-actions Bot closed this Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts Pull request has merge conflicts that need resolution stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants