mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-29 07:48:47 +00:00
Read the descriptor style values instead of producing a ParsedFontFace first, as this means we know if a descriptor is actually present, or has been defaulted to an initial value. This lets us correctly skip the unicode-range if it was not explicitly set. Firefox and Chromium both serialize using the "font-stretch" name, (which is an alias for font-width) which follows the outdated cssom spec, so I've done so too to match them. The one thing that we still do differently in this test is that those browsers check explicitly if `font-stretch` was set, and ignore when `font-width` is. I've also inlined the `serialize_a_local()` function to the one place it's used. The style value to_string() method was already wrapping the string in quotes, so calling serialize_a_string() on it was producing `local("\this mess\"")`. It's clearer what's happening when the code isn't split up.
73 lines
2.3 KiB
C++
73 lines
2.3 KiB
C++
/*
|
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibWeb/CSS/Serialize.h>
|
|
#include <LibWeb/CSS/StyleValues/FontSourceStyleValue.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
FontSourceStyleValue::FontSourceStyleValue(Source source, Optional<FlyString> format)
|
|
: StyleValueWithDefaultOperators(Type::FontSource)
|
|
, m_source(move(source))
|
|
, m_format(move(format))
|
|
{
|
|
}
|
|
|
|
FontSourceStyleValue::~FontSourceStyleValue() = default;
|
|
|
|
String FontSourceStyleValue::to_string(SerializationMode) const
|
|
{
|
|
// <font-src> = <url> [ format(<font-format>)]? [ tech( <font-tech>#)]? | local(<family-name>)
|
|
return m_source.visit(
|
|
[](Local const& local) {
|
|
// local(<family-name>)
|
|
|
|
// https://www.w3.org/TR/cssom-1/#serialize-a-local
|
|
// To serialize a LOCAL means to create a string represented by "local(",
|
|
// followed by the serialization of the LOCAL as a string, followed by ")".
|
|
StringBuilder builder;
|
|
builder.append("local("sv);
|
|
builder.append(local.name->to_string(SerializationMode::Normal));
|
|
builder.append(')');
|
|
return builder.to_string_without_validation();
|
|
},
|
|
[this](URL::URL const& url) {
|
|
// <url> [ format(<font-format>)]? [ tech( <font-tech>#)]?
|
|
// FIXME: tech()
|
|
StringBuilder builder;
|
|
serialize_a_url(builder, url.to_string());
|
|
|
|
if (m_format.has_value()) {
|
|
builder.append(" format("sv);
|
|
serialize_an_identifier(builder, *m_format);
|
|
builder.append(")"sv);
|
|
}
|
|
|
|
return builder.to_string_without_validation();
|
|
});
|
|
}
|
|
|
|
bool FontSourceStyleValue::properties_equal(FontSourceStyleValue const& other) const
|
|
{
|
|
bool sources_equal = m_source.visit(
|
|
[&other](Local const& local) {
|
|
if (auto* other_local = other.m_source.get_pointer<Local>()) {
|
|
return local.name == other_local->name;
|
|
}
|
|
return false;
|
|
},
|
|
[&other](URL::URL const& url) {
|
|
if (auto* other_url = other.m_source.get_pointer<URL::URL>()) {
|
|
return url == *other_url;
|
|
}
|
|
return false;
|
|
});
|
|
|
|
return sources_equal
|
|
&& m_format == other.m_format;
|
|
}
|
|
|
|
}
|