Skip to content

Commit ee6dbcc

Browse files
Lubrsikalenikaliaksandr
authored andcommitted
LibWeb: Apply HTMLFontElement's face attribute's presentational hint
Fixes font selection on https://stagsnet.net/
1 parent e33174f commit ee6dbcc

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

Libraries/LibWeb/HTML/HTMLFontElement.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,23 @@ bool HTMLFontElement::is_presentational_hint(FlyString const& name) const
125125
void HTMLFontElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
126126
{
127127
for_each_attribute([&](auto& name, auto& value) {
128-
if (name.equals_ignoring_ascii_case("color"sv)) {
128+
if (name == AttributeNames::color) {
129129
// https://html.spec.whatwg.org/multipage/rendering.html#phrasing-content-3:rules-for-parsing-a-legacy-colour-value
130130
auto color = parse_legacy_color_value(value);
131131
if (color.has_value())
132132
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Color, CSS::CSSColorValue::create_from_color(color.value(), CSS::ColorSyntax::Legacy));
133-
} else if (name.equals_ignoring_ascii_case("size"sv)) {
133+
} else if (name == AttributeNames::size) {
134134
// When a font element has a size attribute, the user agent is expected to use the following steps, known as the rules for parsing a legacy font size, to treat the attribute as a presentational hint setting the element's 'font-size' property:
135135
auto font_size_or_empty = parse_legacy_font_size(value);
136136
if (font_size_or_empty.has_value()) {
137137
auto font_size = string_from_keyword(font_size_or_empty.release_value());
138138
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingParams { document() }, font_size, CSS::PropertyID::FontSize))
139139
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::FontSize, parsed_value.release_nonnull());
140140
}
141+
} else if (name == AttributeNames::face) {
142+
// When a font element has a face attribute, the user agent is expected to treat the attribute as a presentational hint setting the element's 'font-family' property to the attribute's value.
143+
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingParams { document() }, value, CSS::PropertyID::FontFamily))
144+
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::FontFamily, parsed_value.release_nonnull());
141145
}
142146
});
143147
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<link rel="match" href="../../expected/HTML/HTMLFontElement-face-attribute-ref.html" />
4+
<style>
5+
span {
6+
font-family: 'Arial', sans-serif;
7+
}
8+
</style>
9+
</head>
10+
<body>
11+
<span>Well hello friends!</span>
12+
</body>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<link rel="match" href="../../expected/HTML/HTMLFontElement-face-attribute-ref.html" />
4+
</head>
5+
<body>
6+
<font face="'Arial', sans-serif"><span>Well hello friends!</span></font>
7+
</body>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
foo<font face="monospace" style="font-family: monospace;">bar</font>
2-
<font face="sans-serif" style="font-family: sans-serif;">foo</font><font face="sans-serif" style="font-family: sans-serif;"><font style="">bar</font></font>
1+
foo<font face="monospace">bar</font>
2+
<font face="sans-serif">foobar</font>

0 commit comments

Comments
 (0)