Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibWeb: Make default monospace font size 13px #2020

Conversation

kostyafarber
Copy link
Contributor

This is the default font size used in Chrome and Firefox and my theory is some WPT tests make the same assumption. As an example, https://wpt.live/css/css-text/tab-size/tab-size-spacing-001.html will pass once PR #1999 is merged if we explicitly set the font-size to be 13px.

I figured this out when comparing the size of the space character across Chrome and Ladybird, which we were sizing to large and hence overshooting the
red square in the aforementioned WPT test. I'd like to think that this is true across all WPT tests that measure pixels and use monospace as their font-family :^) but this is unsubstantiated.

This is the default font size used in Chrome and Firefox and my theory
is some WPT tests make the same assumption. As an example,
https://wpt.live/css/css-text/tab-size/tab-size-spacing-001.html will
pass once PR LadybirdBrowser#1999 is merged if we explicitly set the font-size to be
13px.

I figured this out when comparing the size of the space character across
Chrome and Ladybird, which we were sizing to large and hence
overshooting the
red square in the aforementioned WPT test. I'd like to think that this
is true across all WPT tests that measure pixels and use monospace as
their font-family :^) but this is unsubstantiated.
@@ -1986,6 +1986,7 @@ RefPtr<Gfx::FontCascadeList const> StyleComputer::compute_font_for_style_values(
case Keyword::Monospace:
case Keyword::UiMonospace:
generic_font = Platform::GenericFont::Monospace;
font_size_in_pt = 13 * 0.75f;
Copy link
Collaborator

Choose a reason for hiding this comment

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

So if we hit find_generic_font you override the calculated font size? That doesn't seem like the right solution; shouldn't you change the default font size of 16 at line 1814?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if I change that from 16 to 13 it'll change it for all fonts but we only want to change it for monospaced fonts (i.e font-family: monospace)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could do something like this so we don't override it until the very end

auto found_font = StyleProperties::font_fallback(monospace, bold);
font_size_in_pt = monospace ? 13 * 0.75f : font_size_in_pt;
font_list->set_last_resort_font(found_font->with_size(font_size_in_pt));

Copy link
Contributor Author

@kostyafarber kostyafarber Oct 28, 2024

Choose a reason for hiding this comment

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

or yeah would need a way to modify CSSPixels font_size_in_px = 16; for only monospaced font's but we don't know that at that point, we would only want to set that is 13 for the generic monospaced font if of course no font-size value has been provided.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It might help if you can find if this is something that is in a spec somewhere, or if it's custom behavior by both Chrome and Firefox (user agent stylesheet?), etc. Just changing something because WPT expects it is not always the right course of action; e.g. maybe their assumption is wrong and we need to report an issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's a fair point, I did search the default css in the spec and there is no mention of it, nothing online either. I can only see that this is the behaviour on Firefox and Chrome (if you go into appearance settings it's set there). That's what the FIXME on the line you speak of is working towards I believe (letting the user specify).

Can you please point me to where I'd open an issue or investigate this? In the meantime I can have a search around the WPT tests to see where they specify font-family: monospace and see if any rely on calculations based off of a default value of 13px for this font, which like you've said is probably an assumption to accomodate current existing behaviour that actually isn't in any spec.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, the FIXME is to support user font sizes, and WPT should probably never rely on those.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I guess these by default if the user hasn’t specified anything (for the generic fonts) is 13px for monospaced and 16px for everything else (for Chrome and Firefox) which yeah isn’t ideal for WPT to be relying on if that is the case.

Probably better to explicitly set the size in the tests if using monospace or something like that.

I think I may poke around and see if other tests are making this assumption if I can deduce that, and perhaps open or discuss the issue on WPT. Is this the usual process for these types of things?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've opened an issue web-platform-tests/wpt#48840 will close this for now and see what comes out of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants