2025-04-02 17:01:16 +01:00
|
|
|
/*
|
|
|
|
|
* 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 {
|
|
|
|
|
|
2025-06-03 12:32:05 +01:00
|
|
|
FontSourceStyleValue::FontSourceStyleValue(Source source, Optional<FlyString> format, Vector<FontTech> tech)
|
2025-04-02 17:01:16 +01:00
|
|
|
: StyleValueWithDefaultOperators(Type::FontSource)
|
|
|
|
|
, m_source(move(source))
|
|
|
|
|
, m_format(move(format))
|
2025-06-03 12:32:05 +01:00
|
|
|
, m_tech(move(tech))
|
2025-04-02 17:01:16 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FontSourceStyleValue::~FontSourceStyleValue() = default;
|
|
|
|
|
|
2026-01-08 12:02:18 +00:00
|
|
|
void FontSourceStyleValue::serialize(StringBuilder& builder, SerializationMode) const
|
2025-04-02 17:01:16 +01:00
|
|
|
{
|
|
|
|
|
// <font-src> = <url> [ format(<font-format>)]? [ tech( <font-tech>#)]? | local(<family-name>)
|
2026-01-08 12:02:18 +00:00
|
|
|
m_source.visit(
|
|
|
|
|
[&builder](Local const& local) {
|
2025-04-02 17:01:16 +01:00
|
|
|
// local(<family-name>)
|
2025-04-04 12:18:53 +01:00
|
|
|
|
|
|
|
|
// 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 ")".
|
|
|
|
|
builder.append("local("sv);
|
2026-01-08 12:02:18 +00:00
|
|
|
local.name->serialize(builder, SerializationMode::Normal);
|
2025-04-04 12:18:53 +01:00
|
|
|
builder.append(')');
|
2025-04-02 17:01:16 +01:00
|
|
|
},
|
2026-01-08 12:02:18 +00:00
|
|
|
[this, &builder](URL const& url) {
|
2025-04-02 17:01:16 +01:00
|
|
|
// <url> [ format(<font-format>)]? [ tech( <font-tech>#)]?
|
2025-05-02 12:07:22 +01:00
|
|
|
builder.append(url.to_string());
|
2025-04-02 17:01:16 +01:00
|
|
|
|
|
|
|
|
if (m_format.has_value()) {
|
|
|
|
|
builder.append(" format("sv);
|
|
|
|
|
serialize_an_identifier(builder, *m_format);
|
|
|
|
|
builder.append(")"sv);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-03 12:32:05 +01:00
|
|
|
if (!m_tech.is_empty()) {
|
|
|
|
|
builder.append(" tech("sv);
|
2026-01-08 12:02:18 +00:00
|
|
|
serialize_a_comma_separated_list(builder, m_tech, [](auto& b, FontTech const tech) {
|
|
|
|
|
return b.append(CSS::to_string(tech));
|
2025-06-03 12:32:05 +01:00
|
|
|
});
|
|
|
|
|
builder.append(")"sv);
|
|
|
|
|
}
|
2025-04-02 17:01:16 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
},
|
2025-05-02 12:07:22 +01:00
|
|
|
[&other](URL const& url) {
|
|
|
|
|
if (auto* other_url = other.m_source.get_pointer<URL>()) {
|
2025-04-02 17:01:16 +01:00
|
|
|
return url == *other_url;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return sources_equal
|
|
|
|
|
&& m_format == other.m_format;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|