mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibWeb/CSS: Add FontSourceStyleValue
This will be used by the `@font { src: ... }` descriptor once we parse descriptors as style values.
This commit is contained in:
parent
79093291b5
commit
60c536bdd5
Notes:
github-actions[bot]
2025-04-04 09:42:16 +00:00
Author: https://github.com/AtkinsSJ
Commit: 60c536bdd5
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4206
8 changed files with 186 additions and 0 deletions
67
Libraries/LibWeb/CSS/StyleValues/FontSourceStyleValue.cpp
Normal file
67
Libraries/LibWeb/CSS/StyleValues/FontSourceStyleValue.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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>)
|
||||
StringBuilder builder;
|
||||
serialize_a_local(builder, local.name->to_string(SerializationMode::Normal));
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue