mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 20:59:16 +00:00
LibWeb: Parse oblique font-style
with an angle value
This commit is contained in:
parent
e537e426c1
commit
c0f9b11070
Notes:
github-actions[bot]
2025-05-03 10:06:24 +00:00
Author: https://github.com/tcl3
Commit: c0f9b11070
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4552
Reviewed-by: https://github.com/konradekk
13 changed files with 172 additions and 31 deletions
42
Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.cpp
Normal file
42
Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Tim Ledbetter <tim.ledbetter@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "FontStyleStyleValue.h"
|
||||
#include <LibWeb/CSS/CSSStyleValue.h>
|
||||
#include <LibWeb/CSS/Serialize.h>
|
||||
#include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
FontStyleStyleValue::FontStyleStyleValue(FontStyle font_style, ValueComparingRefPtr<CSSStyleValue const> angle_value)
|
||||
: StyleValueWithDefaultOperators(Type::FontStyle)
|
||||
, m_font_style(font_style)
|
||||
, m_angle_value(angle_value)
|
||||
{
|
||||
}
|
||||
|
||||
FontStyleStyleValue::~FontStyleStyleValue() = default;
|
||||
|
||||
String FontStyleStyleValue::to_string(SerializationMode mode) const
|
||||
{
|
||||
Optional<String> angle_string;
|
||||
if (m_angle_value) {
|
||||
angle_string = m_angle_value->to_string(mode);
|
||||
if (m_font_style == FontStyle::Oblique && angle_string == "0deg"sv)
|
||||
return "normal"_string;
|
||||
}
|
||||
StringBuilder builder;
|
||||
builder.append(CSS::to_string(m_font_style));
|
||||
// https://drafts.csswg.org/css-fonts/#valdef-font-style-oblique-angle--90deg-90deg
|
||||
// The lack of an <angle> represents 14deg. (Note that a font might internally provide its own mapping for "oblique", but the mapping within the font is disregarded.)
|
||||
static auto default_angle = Angle::make_degrees(14);
|
||||
if (angle_string.has_value() && !(m_angle_value->is_angle() && m_angle_value->as_angle().angle() == default_angle))
|
||||
builder.appendff(" {}", angle_string);
|
||||
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue