mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-31 15:32:51 +00:00
LibWeb/CSS: Make "CSSStyleValue -> list of font sources" code accessible
We'll want this in FontFace.
This commit is contained in:
parent
3288c71953
commit
0121e7028f
Notes:
github-actions[bot]
2025-04-07 09:01:54 +00:00
Author: https://github.com/AtkinsSJ
Commit: 0121e7028f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4224
2 changed files with 34 additions and 26 deletions
|
@ -21,16 +21,40 @@
|
|||
|
||||
namespace Web::CSS {
|
||||
|
||||
ParsedFontFace ParsedFontFace::from_descriptors(CSSFontFaceDescriptors const& descriptors)
|
||||
static FlyString extract_font_name(CSSStyleValue const& value)
|
||||
{
|
||||
auto extract_font_name = [](CSSStyleValue const& value) {
|
||||
if (value.is_string())
|
||||
return value.as_string().string_value();
|
||||
if (value.is_custom_ident())
|
||||
return value.as_custom_ident().custom_ident();
|
||||
return FlyString {};
|
||||
if (value.is_string())
|
||||
return value.as_string().string_value();
|
||||
if (value.is_custom_ident())
|
||||
return value.as_custom_ident().custom_ident();
|
||||
return FlyString {};
|
||||
}
|
||||
|
||||
Vector<ParsedFontFace::Source> ParsedFontFace::sources_from_style_value(CSSStyleValue const& style_value)
|
||||
{
|
||||
Vector<Source> sources;
|
||||
auto add_source = [&sources](FontSourceStyleValue const& font_source) {
|
||||
font_source.source().visit(
|
||||
[&](FontSourceStyleValue::Local const& local) {
|
||||
sources.empend(extract_font_name(local.name), OptionalNone {});
|
||||
},
|
||||
[&](URL::URL const& url) {
|
||||
// FIXME: tech()
|
||||
sources.empend(url, font_source.format());
|
||||
});
|
||||
};
|
||||
|
||||
if (style_value.is_font_source()) {
|
||||
add_source(style_value.as_font_source());
|
||||
} else if (style_value.is_value_list()) {
|
||||
for (auto const& source : style_value.as_value_list().values())
|
||||
add_source(source->as_font_source());
|
||||
}
|
||||
return sources;
|
||||
}
|
||||
|
||||
ParsedFontFace ParsedFontFace::from_descriptors(CSSFontFaceDescriptors const& descriptors)
|
||||
{
|
||||
auto extract_percentage_or_normal = [](CSSStyleValue const& value) -> Optional<Percentage> {
|
||||
if (value.is_percentage())
|
||||
return value.as_percentage().percentage();
|
||||
|
@ -61,25 +85,8 @@ ParsedFontFace ParsedFontFace::from_descriptors(CSSFontFaceDescriptors const& de
|
|||
width = value->to_font_width();
|
||||
|
||||
Vector<Source> sources;
|
||||
if (auto value = descriptors.descriptor_or_initial_value(DescriptorID::Src)) {
|
||||
auto add_source = [&sources, extract_font_name](FontSourceStyleValue const& font_source) {
|
||||
font_source.source().visit(
|
||||
[&](FontSourceStyleValue::Local const& local) {
|
||||
sources.empend(extract_font_name(local.name), OptionalNone {});
|
||||
},
|
||||
[&](URL::URL const& url) {
|
||||
// FIXME: tech()
|
||||
sources.empend(url, font_source.format());
|
||||
});
|
||||
};
|
||||
|
||||
if (value->is_font_source()) {
|
||||
add_source(value->as_font_source());
|
||||
} else if (value->is_value_list()) {
|
||||
for (auto const& source : value->as_value_list().values())
|
||||
add_source(source->as_font_source());
|
||||
}
|
||||
}
|
||||
if (auto value = descriptors.descriptor_or_initial_value(DescriptorID::Src))
|
||||
sources = sources_from_style_value(*value);
|
||||
|
||||
Vector<Gfx::UnicodeRange> unicode_ranges;
|
||||
if (auto value = descriptors.descriptor_or_initial_value(DescriptorID::UnicodeRange)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue