From a28275657bdbb8752e68bced0ea739311f41f3e2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 24 May 2023 19:58:52 +0200 Subject: [PATCH] LibWeb: Include weight and style in CSSFontFaceRule serialization --- .../Libraries/LibWeb/CSS/CSSFontFaceRule.cpp | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp index 34895f99bd..50df341ed7 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp @@ -1,10 +1,11 @@ /* * Copyright (c) 2022-2023, Sam Atkins - * Copyright (c) 2022, Andreas Kling + * Copyright (c) 2022-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -102,15 +103,39 @@ DeprecatedString CSSFontFaceRule::serialized() const // followed by the result of performing serialize a <'font-stretch'>, // followed by the string ";", i.e., SEMICOLON (U+003B). - // FIXME: 10. If rule’s associated font-weight descriptor is present, a single SPACE (U+0020), - // followed by the string "font-weight:", followed by a single SPACE (U+0020), - // followed by the result of performing serialize a <'font-weight'>, - // followed by the string ";", i.e., SEMICOLON (U+003B). + // 10. If rule’s associated font-weight descriptor is present, a single SPACE (U+0020), + // followed by the string "font-weight:", followed by a single SPACE (U+0020), + // followed by the result of performing serialize a <'font-weight'>, + // followed by the string ";", i.e., SEMICOLON (U+003B). + if (m_font_face.weight().has_value()) { + auto weight = m_font_face.weight().value(); + builder.append(" font-weight: "sv); + if (weight == 400) + builder.append("normal"sv); + else if (weight == 700) + builder.append("bold"sv); + else + builder.appendff("{}", weight); + builder.append(";"sv); + } - // FIXME: 11. If rule’s associated font-style descriptor is present, a single SPACE (U+0020), - // followed by the string "font-style:", followed by a single SPACE (U+0020), - // followed by the result of performing serialize a <'font-style'>, - // followed by the string ";", i.e., SEMICOLON (U+003B). + // 11. If rule’s associated font-style descriptor is present, a single SPACE (U+0020), + // followed by the string "font-style:", followed by a single SPACE (U+0020), + // followed by the result of performing serialize a <'font-style'>, + // followed by the string ";", i.e., SEMICOLON (U+003B). + if (m_font_face.slope().has_value()) { + auto slope = m_font_face.slope().value(); + builder.append(" font-style: "sv); + if (slope == Gfx::name_to_slope("Normal"sv)) + builder.append("normal"sv); + else if (slope == Gfx::name_to_slope("Italic"sv)) + builder.append("italic"sv); + else { + dbgln("FIXME: CSSFontFaceRule::serialized() does not support slope {}", slope); + builder.append("italic"sv); + } + builder.append(";"sv); + } // 12. A single SPACE (U+0020), followed by the string "}", i.e., RIGHT CURLY BRACKET (U+007D). builder.append(" }"sv);