2024-05-07 10:05:29 -06:00
|
|
|
|
/*
|
|
|
|
|
|
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
2026-02-20 12:20:20 +00:00
|
|
|
|
* Copyright (c) 2025-2026, Sam Atkins <sam@ladybird.org>
|
2024-05-07 10:05:29 -06:00
|
|
|
|
*
|
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2025-04-04 15:32:53 +01:00
|
|
|
|
#include <AK/ByteBuffer.h>
|
2024-05-13 12:02:38 -06:00
|
|
|
|
#include <LibCore/Promise.h>
|
2024-11-15 04:01:23 +13:00
|
|
|
|
#include <LibGC/Heap.h>
|
2025-06-03 15:48:24 +01:00
|
|
|
|
#include <LibGfx/Font/FontSupport.h>
|
2024-06-28 20:27:00 +02:00
|
|
|
|
#include <LibGfx/Font/Typeface.h>
|
2024-07-22 14:03:58 +03:00
|
|
|
|
#include <LibGfx/Font/WOFF/Loader.h>
|
|
|
|
|
|
#include <LibGfx/Font/WOFF2/Loader.h>
|
2024-05-13 12:02:38 -06:00
|
|
|
|
#include <LibJS/Runtime/ArrayBuffer.h>
|
2024-05-07 10:05:29 -06:00
|
|
|
|
#include <LibJS/Runtime/Realm.h>
|
|
|
|
|
|
#include <LibWeb/Bindings/FontFacePrototype.h>
|
|
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2026-01-05 09:30:38 +00:00
|
|
|
|
#include <LibWeb/CSS/CSSFontFaceRule.h>
|
2026-02-19 18:30:55 +13:00
|
|
|
|
#include <LibWeb/CSS/Enums.h>
|
2025-11-06 18:27:22 +13:00
|
|
|
|
#include <LibWeb/CSS/FontComputer.h>
|
2024-05-07 10:05:29 -06:00
|
|
|
|
#include <LibWeb/CSS/FontFace.h>
|
2026-02-20 12:20:20 +00:00
|
|
|
|
#include <LibWeb/CSS/FontFaceSet.h>
|
2024-05-10 10:28:53 -06:00
|
|
|
|
#include <LibWeb/CSS/Parser/Parser.h>
|
2026-04-01 16:31:04 +01:00
|
|
|
|
#include <LibWeb/CSS/StyleComputer.h>
|
|
|
|
|
|
#include <LibWeb/CSS/StyleValues/ComputationContext.h>
|
2025-09-16 21:34:05 +12:00
|
|
|
|
#include <LibWeb/CSS/StyleValues/CustomIdentStyleValue.h>
|
2026-04-01 16:31:04 +01:00
|
|
|
|
#include <LibWeb/CSS/StyleValues/FontStyleStyleValue.h>
|
|
|
|
|
|
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
|
2026-01-10 21:33:31 +13:00
|
|
|
|
#include <LibWeb/CSS/StyleValues/StringStyleValue.h>
|
2026-04-01 16:31:04 +01:00
|
|
|
|
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
|
|
|
|
|
|
#include <LibWeb/CSS/StyleValues/UnicodeRangeStyleValue.h>
|
2026-02-11 07:33:58 +01:00
|
|
|
|
#include <LibWeb/DOM/Document.h>
|
2024-05-13 12:02:38 -06:00
|
|
|
|
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
|
2024-05-15 15:00:07 -06:00
|
|
|
|
#include <LibWeb/HTML/Window.h>
|
2024-05-13 12:02:38 -06:00
|
|
|
|
#include <LibWeb/Platform/EventLoopPlugin.h>
|
|
|
|
|
|
#include <LibWeb/WebIDL/AbstractOperations.h>
|
|
|
|
|
|
#include <LibWeb/WebIDL/Buffers.h>
|
2024-05-07 10:05:29 -06:00
|
|
|
|
#include <LibWeb/WebIDL/Promise.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
|
2026-03-22 14:09:22 -05:00
|
|
|
|
// In order to avoid conflicts with the old WinIE style of @font-face, if there is no format specified,
|
|
|
|
|
|
// we check to see if the URL ends with .eot. We will not try to load those.
|
|
|
|
|
|
// This matches the behavior of other engines (Blink, WebKit).
|
|
|
|
|
|
static bool is_unsupported_source(ParsedFontFace::Source const& source)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!source.local_or_url.has<URL>())
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (source.format.has_value())
|
|
|
|
|
|
return !font_format_is_supported(source.format.value());
|
|
|
|
|
|
return source.local_or_url.get<URL>().url().ends_with_bytes(".eot"sv);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-01 16:31:04 +01:00
|
|
|
|
static FontWeightRange compute_weight_range(StyleValue const& value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value.to_keyword() == Keyword::Auto || value.to_keyword() == Keyword::Normal)
|
|
|
|
|
|
return { 400, 400 };
|
|
|
|
|
|
|
|
|
|
|
|
auto& weight_values = value.as_value_list().values();
|
|
|
|
|
|
if (weight_values.size() == 1) {
|
|
|
|
|
|
auto one_weight = static_cast<int>(StyleComputer::compute_font_weight(weight_values[0], {})->as_number().number());
|
|
|
|
|
|
return { one_weight, one_weight };
|
|
|
|
|
|
}
|
|
|
|
|
|
if (weight_values.size() == 2) {
|
|
|
|
|
|
auto first = static_cast<int>(StyleComputer::compute_font_weight(weight_values[0], {})->as_number().number());
|
|
|
|
|
|
auto second = static_cast<int>(StyleComputer::compute_font_weight(weight_values[1], {})->as_number().number());
|
|
|
|
|
|
return { min(first, second), max(first, second) };
|
|
|
|
|
|
}
|
|
|
|
|
|
return { 400, 400 };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int compute_slope(StyleValue const& value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value.to_keyword() == Keyword::Auto || value.to_keyword() == Keyword::Normal)
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
return StyleComputer::compute_font_style(value)->as_font_style().to_font_slope();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-15 15:48:14 -06:00
|
|
|
|
static NonnullRefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface const>>> load_vector_font(JS::Realm& realm, ByteBuffer const& data)
|
2024-05-13 12:02:38 -06:00
|
|
|
|
{
|
2025-04-15 15:48:14 -06:00
|
|
|
|
auto promise = Core::Promise<NonnullRefPtr<Gfx::Typeface const>>::construct();
|
2024-05-13 12:02:38 -06:00
|
|
|
|
|
|
|
|
|
|
// FIXME: 'Asynchronously' shouldn't mean 'later on the main thread'.
|
|
|
|
|
|
// Can we defer this to a background thread?
|
2024-11-15 04:01:23 +13:00
|
|
|
|
Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(realm.heap(), [&data, promise] {
|
2024-05-13 12:02:38 -06:00
|
|
|
|
// FIXME: This should be de-duplicated with StyleComputer::FontLoader::try_load_font
|
|
|
|
|
|
// We don't have the luxury of knowing the MIME type, so we have to try all formats.
|
2024-09-04 17:29:01 +02:00
|
|
|
|
auto ttf = Gfx::Typeface::try_load_from_externally_owned_memory(data);
|
2024-05-13 12:02:38 -06:00
|
|
|
|
if (!ttf.is_error()) {
|
|
|
|
|
|
promise->resolve(ttf.release_value());
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-05-02 17:46:51 +01:00
|
|
|
|
auto woff = WOFF::try_load_from_bytes(data);
|
2024-05-13 12:02:38 -06:00
|
|
|
|
if (!woff.is_error()) {
|
|
|
|
|
|
promise->resolve(woff.release_value());
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-05-02 17:46:51 +01:00
|
|
|
|
auto woff2 = WOFF2::try_load_from_bytes(data);
|
2024-05-13 12:02:38 -06:00
|
|
|
|
if (!woff2.is_error()) {
|
|
|
|
|
|
promise->resolve(woff2.release_value());
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
promise->reject(Error::from_string_literal("Automatic format detection failed"));
|
2024-10-31 02:39:29 +13:00
|
|
|
|
}));
|
2024-05-13 12:02:38 -06:00
|
|
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
|
GC_DEFINE_ALLOCATOR(FontFace);
|
2024-05-07 10:05:29 -06:00
|
|
|
|
|
2024-05-13 12:02:38 -06:00
|
|
|
|
// https://drafts.csswg.org/css-font-loading/#font-face-constructor
|
2024-11-15 04:01:23 +13:00
|
|
|
|
GC::Ref<FontFace> FontFace::construct_impl(JS::Realm& realm, String family, FontFaceSource source, FontFaceDescriptors const& descriptors)
|
2024-05-07 10:05:29 -06:00
|
|
|
|
{
|
2024-05-13 12:02:38 -06:00
|
|
|
|
auto& vm = realm.vm();
|
|
|
|
|
|
|
|
|
|
|
|
// 1. Let font face be a fresh FontFace object. Set font face’s status attribute to "unloaded",
|
|
|
|
|
|
// Set its internal [[FontStatusPromise]] slot to a fresh pending Promise object.
|
2025-04-04 15:32:53 +01:00
|
|
|
|
auto font_face = realm.create<FontFace>(realm, WebIDL::create_promise(realm));
|
2024-05-13 12:02:38 -06:00
|
|
|
|
|
2025-04-04 15:32:53 +01:00
|
|
|
|
// Parse the family argument, and the members of the descriptors argument,
|
2024-05-13 12:02:38 -06:00
|
|
|
|
// according to the grammars of the corresponding descriptors of the CSS @font-face rule.
|
|
|
|
|
|
// If the source argument is a CSSOMString, parse it according to the grammar of the CSS src descriptor of the @font-face rule.
|
|
|
|
|
|
// If any of them fail to parse correctly, reject font face’s [[FontStatusPromise]] with a DOMException named "SyntaxError",
|
|
|
|
|
|
// set font face’s corresponding attributes to the empty string, and set font face’s status attribute to "error".
|
|
|
|
|
|
// Otherwise, set font face’s corresponding attributes to the serialization of the parsed values.
|
|
|
|
|
|
|
2025-05-02 12:19:14 +01:00
|
|
|
|
Parser::ParsingParams parsing_params { realm };
|
2026-04-01 16:31:04 +01:00
|
|
|
|
auto try_set_descriptor = [&](DescriptorID descriptor_id, String const& string, auto setter_impl) {
|
2026-03-05 00:03:57 +13:00
|
|
|
|
auto result = parse_css_descriptor(parsing_params, AtRuleID::FontFace, DescriptorNameAndID::from_id(descriptor_id), string);
|
2025-04-04 15:32:53 +01:00
|
|
|
|
if (!result) {
|
2025-08-07 19:31:52 -04:00
|
|
|
|
font_face->reject_status_promise(WebIDL::SyntaxError::create(realm, Utf16String::formatted("FontFace constructor: Invalid {}", to_string(descriptor_id))));
|
2026-04-01 16:31:04 +01:00
|
|
|
|
return;
|
2025-04-04 15:32:53 +01:00
|
|
|
|
}
|
2026-04-01 16:31:04 +01:00
|
|
|
|
(font_face.ptr()->*setter_impl)(result.release_nonnull());
|
2025-04-04 15:32:53 +01:00
|
|
|
|
};
|
2026-04-01 16:31:04 +01:00
|
|
|
|
try_set_descriptor(DescriptorID::FontFamily, family, &FontFace::set_family_impl);
|
|
|
|
|
|
try_set_descriptor(DescriptorID::FontStyle, descriptors.style, &FontFace::set_style_impl);
|
|
|
|
|
|
try_set_descriptor(DescriptorID::FontWeight, descriptors.weight, &FontFace::set_weight_impl);
|
|
|
|
|
|
try_set_descriptor(DescriptorID::FontWidth, descriptors.stretch, &FontFace::set_stretch_impl);
|
|
|
|
|
|
try_set_descriptor(DescriptorID::UnicodeRange, descriptors.unicode_range, &FontFace::set_unicode_range_impl);
|
|
|
|
|
|
try_set_descriptor(DescriptorID::FontFeatureSettings, descriptors.feature_settings, &FontFace::set_feature_settings_impl);
|
|
|
|
|
|
try_set_descriptor(DescriptorID::FontVariationSettings, descriptors.variation_settings, &FontFace::set_variation_settings_impl);
|
|
|
|
|
|
try_set_descriptor(DescriptorID::FontDisplay, descriptors.display, &FontFace::set_display_impl);
|
|
|
|
|
|
try_set_descriptor(DescriptorID::AscentOverride, descriptors.ascent_override, &FontFace::set_ascent_override_impl);
|
|
|
|
|
|
try_set_descriptor(DescriptorID::DescentOverride, descriptors.descent_override, &FontFace::set_descent_override_impl);
|
|
|
|
|
|
try_set_descriptor(DescriptorID::LineGapOverride, descriptors.line_gap_override, &FontFace::set_line_gap_override_impl);
|
2025-08-08 10:11:51 +01:00
|
|
|
|
RefPtr<StyleValue const> parsed_source;
|
2025-04-04 15:32:53 +01:00
|
|
|
|
if (auto* source_string = source.get_pointer<String>()) {
|
2026-03-05 00:03:57 +13:00
|
|
|
|
parsed_source = parse_css_descriptor(parsing_params, AtRuleID::FontFace, DescriptorNameAndID::from_id(DescriptorID::Src), *source_string);
|
2025-04-04 15:32:53 +01:00
|
|
|
|
if (!parsed_source) {
|
2025-08-07 19:31:52 -04:00
|
|
|
|
font_face->reject_status_promise(WebIDL::SyntaxError::create(realm, Utf16String::formatted("FontFace constructor: Invalid {}", to_string(DescriptorID::Src))));
|
2025-04-04 15:32:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// Return font face. If font face’s status is "error", terminate this algorithm;
|
|
|
|
|
|
// otherwise, complete the rest of these steps asynchronously.
|
|
|
|
|
|
// FIXME: Do the rest of this asynchronously.
|
|
|
|
|
|
if (font_face->status() == Bindings::FontFaceLoadStatus::Error)
|
|
|
|
|
|
return font_face;
|
|
|
|
|
|
|
|
|
|
|
|
// 2. If the source argument was a CSSOMString, set font face’s internal [[Urls]] slot to the string.
|
|
|
|
|
|
// If the source argument was a BinaryData, set font face’s internal [[Data]] slot to the passed argument.
|
|
|
|
|
|
if (source.has<String>()) {
|
|
|
|
|
|
font_face->m_urls = ParsedFontFace::sources_from_style_value(*parsed_source);
|
2026-03-22 14:09:22 -05:00
|
|
|
|
font_face->m_urls.remove_all_matching(is_unsupported_source);
|
2024-05-13 12:02:38 -06:00
|
|
|
|
} else {
|
2024-11-15 04:01:23 +13:00
|
|
|
|
auto buffer_source = source.get<GC::Root<WebIDL::BufferSource>>();
|
2024-05-13 12:02:38 -06:00
|
|
|
|
auto maybe_buffer = WebIDL::get_buffer_source_copy(buffer_source->raw_object());
|
|
|
|
|
|
if (maybe_buffer.is_error()) {
|
|
|
|
|
|
VERIFY(maybe_buffer.error().code() == ENOMEM);
|
|
|
|
|
|
auto throw_completion = vm.throw_completion<JS::InternalError>(vm.error_message(JS::VM::ErrorMessage::OutOfMemory));
|
2025-04-04 15:32:53 +01:00
|
|
|
|
font_face->reject_status_promise(throw_completion.value());
|
2024-05-13 12:02:38 -06:00
|
|
|
|
} else {
|
2025-04-04 15:32:53 +01:00
|
|
|
|
font_face->m_binary_data = maybe_buffer.release_value();
|
2024-05-13 12:02:38 -06:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-04 15:32:53 +01:00
|
|
|
|
if (font_face->m_binary_data.is_empty() && font_face->m_urls.is_empty())
|
2025-08-07 19:31:52 -04:00
|
|
|
|
font_face->reject_status_promise(WebIDL::SyntaxError::create(realm, "FontFace constructor: Invalid font source"_utf16));
|
2024-05-13 12:02:38 -06:00
|
|
|
|
|
|
|
|
|
|
// 3. If font face’s [[Data]] slot is not null, queue a task to run the following steps synchronously:
|
2025-04-04 15:32:53 +01:00
|
|
|
|
if (font_face->m_binary_data.is_empty())
|
|
|
|
|
|
return font_face;
|
2024-05-13 12:02:38 -06:00
|
|
|
|
|
2025-04-04 15:32:53 +01:00
|
|
|
|
HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font_face), GC::create_function(vm.heap(), [&realm, font_face] {
|
2026-03-02 22:00:36 +00:00
|
|
|
|
HTML::TemporaryExecutionContext context(font_face->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes);
|
2024-05-13 12:02:38 -06:00
|
|
|
|
// 1. Set font face’s status attribute to "loading".
|
2025-04-04 15:32:53 +01:00
|
|
|
|
font_face->m_status = Bindings::FontFaceLoadStatus::Loading;
|
2024-05-13 12:02:38 -06:00
|
|
|
|
|
2026-02-20 12:20:20 +00:00
|
|
|
|
// 2. For each FontFaceSet font face is in:
|
|
|
|
|
|
for (auto& font_face_set : font_face->m_containing_sets) {
|
|
|
|
|
|
// 1. If the FontFaceSet’s [[LoadingFonts]] list is empty, switch the FontFaceSet to loading.
|
|
|
|
|
|
if (font_face_set->loading_fonts().is_empty())
|
|
|
|
|
|
font_face_set->switch_to_loading();
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Append font face to the FontFaceSet’s [[LoadingFonts]] list.
|
|
|
|
|
|
font_face_set->loading_fonts().append(font_face);
|
|
|
|
|
|
}
|
2024-05-13 12:02:38 -06:00
|
|
|
|
|
|
|
|
|
|
// 3. Asynchronously, attempt to parse the data in it as a font.
|
|
|
|
|
|
// When this is completed, successfully or not, queue a task to run the following steps synchronously:
|
2025-04-04 15:32:53 +01:00
|
|
|
|
font_face->m_font_load_promise = load_vector_font(realm, font_face->m_binary_data);
|
2024-05-13 12:02:38 -06:00
|
|
|
|
|
2025-04-04 15:32:53 +01:00
|
|
|
|
font_face->m_font_load_promise->when_resolved([font = GC::make_root(font_face)](auto const& vector_font) -> ErrorOr<void> {
|
2024-11-15 04:01:23 +13:00
|
|
|
|
HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font), GC::create_function(font->heap(), [font = GC::Ref(*font), vector_font] {
|
2024-10-24 20:39:18 +13:00
|
|
|
|
HTML::TemporaryExecutionContext context(font->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes);
|
2024-05-13 12:02:38 -06:00
|
|
|
|
// 1. If the load was successful, font face now represents the parsed font;
|
|
|
|
|
|
// fulfill font face’s [[FontStatusPromise]] with font face, and set its status attribute to "loaded".
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: Are we supposed to set the properties of the FontFace based on the loaded vector font?
|
|
|
|
|
|
font->m_parsed_font = vector_font;
|
|
|
|
|
|
font->m_status = Bindings::FontFaceLoadStatus::Loaded;
|
|
|
|
|
|
WebIDL::resolve_promise(font->realm(), font->m_font_status_promise, font);
|
|
|
|
|
|
|
2026-04-01 17:01:14 +01:00
|
|
|
|
if (auto font_computer = font->font_computer(); font_computer.has_value())
|
|
|
|
|
|
font_computer->register_font_face(*font);
|
|
|
|
|
|
|
2026-02-20 12:20:20 +00:00
|
|
|
|
// For each FontFaceSet font face is in:
|
|
|
|
|
|
for (auto& font_face_set : font->m_containing_sets) {
|
|
|
|
|
|
// 1. Add font face to the FontFaceSet’s [[LoadedFonts]] list.
|
|
|
|
|
|
font_face_set->loaded_fonts().append(font);
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Remove font face from the FontFaceSet’s [[LoadingFonts]] list. If font was the last item in
|
|
|
|
|
|
// that list (and so the list is now empty), switch the FontFaceSet to loaded.
|
|
|
|
|
|
font_face_set->loading_fonts().remove_all_matching([font](auto const& entry) { return entry == font; });
|
|
|
|
|
|
if (font_face_set->loading_fonts().is_empty())
|
|
|
|
|
|
font_face_set->switch_to_loaded();
|
|
|
|
|
|
}
|
2024-05-13 12:02:38 -06:00
|
|
|
|
|
|
|
|
|
|
font->m_font_load_promise = nullptr;
|
|
|
|
|
|
}));
|
|
|
|
|
|
return {};
|
|
|
|
|
|
});
|
2025-04-04 15:32:53 +01:00
|
|
|
|
font_face->m_font_load_promise->when_rejected([font = GC::make_root(font_face)](auto const& error) {
|
2024-11-15 04:01:23 +13:00
|
|
|
|
HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font), GC::create_function(font->heap(), [font = GC::Ref(*font), error = Error::copy(error)] {
|
2024-10-24 20:39:18 +13:00
|
|
|
|
HTML::TemporaryExecutionContext context(font->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes);
|
2024-05-13 12:02:38 -06:00
|
|
|
|
// 2. Otherwise, reject font face’s [[FontStatusPromise]] with a DOMException named "SyntaxError"
|
|
|
|
|
|
// and set font face’s status attribute to "error".
|
2025-08-07 19:31:52 -04:00
|
|
|
|
font->reject_status_promise(WebIDL::SyntaxError::create(font->realm(), Utf16String::formatted("Failed to load font: {}", error)));
|
2024-05-13 12:02:38 -06:00
|
|
|
|
|
2026-02-20 12:20:20 +00:00
|
|
|
|
// For each FontFaceSet font face is in:
|
|
|
|
|
|
for (auto& font_face_set : font->m_containing_sets) {
|
|
|
|
|
|
// 1. Add font face to the FontFaceSet’s [[FailedFonts]] list.
|
|
|
|
|
|
font_face_set->failed_fonts().append(font);
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Remove font face from the FontFaceSet’s [[LoadingFonts]] list. If font was the last item in
|
|
|
|
|
|
// that list (and so the list is now empty), switch the FontFaceSet to loaded.
|
|
|
|
|
|
font_face_set->loading_fonts().remove_all_matching([font](auto const& entry) { return entry == font; });
|
|
|
|
|
|
if (font_face_set->loading_fonts().is_empty())
|
|
|
|
|
|
font_face_set->switch_to_loaded();
|
|
|
|
|
|
}
|
2024-05-13 12:02:38 -06:00
|
|
|
|
|
|
|
|
|
|
font->m_font_load_promise = nullptr;
|
|
|
|
|
|
}));
|
|
|
|
|
|
});
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
2025-04-04 15:32:53 +01:00
|
|
|
|
return font_face;
|
2024-05-07 10:05:29 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-05 09:26:24 +00:00
|
|
|
|
// https://drafts.csswg.org/css-font-loading/#font-face-css-connection
|
|
|
|
|
|
GC::Ref<FontFace> FontFace::create_css_connected(JS::Realm& realm, CSSFontFaceRule& rule)
|
|
|
|
|
|
{
|
|
|
|
|
|
HTML::TemporaryExecutionContext execution_context { realm };
|
|
|
|
|
|
|
|
|
|
|
|
auto font_face = realm.create<FontFace>(realm, WebIDL::create_promise(realm));
|
|
|
|
|
|
|
|
|
|
|
|
font_face->m_css_font_face_rule = &rule;
|
2026-01-10 16:23:23 +13:00
|
|
|
|
font_face->reparse_connected_css_font_face_rule_descriptors();
|
|
|
|
|
|
|
2026-03-05 00:03:57 +13:00
|
|
|
|
if (auto src_value = rule.descriptors()->descriptor(DescriptorNameAndID::from_id(DescriptorID::Src))) {
|
2026-01-10 16:23:23 +13:00
|
|
|
|
font_face->m_urls = ParsedFontFace::sources_from_style_value(*src_value);
|
2026-03-22 14:09:22 -05:00
|
|
|
|
font_face->m_urls.remove_all_matching(is_unsupported_source);
|
|
|
|
|
|
}
|
2026-01-10 16:23:23 +13:00
|
|
|
|
|
2026-01-05 09:50:55 +00:00
|
|
|
|
rule.set_css_connected_font_face(font_face);
|
2026-01-05 09:26:24 +00:00
|
|
|
|
|
|
|
|
|
|
return font_face;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-10 16:23:23 +13:00
|
|
|
|
void FontFace::reparse_connected_css_font_face_rule_descriptors()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto const& descriptors = m_css_font_face_rule->descriptors();
|
|
|
|
|
|
|
2026-04-01 16:31:04 +01:00
|
|
|
|
ComputationContext computation_context {
|
|
|
|
|
|
.length_resolution_context = Length::ResolutionContext::for_document(*descriptors->parent_rule()->parent_style_sheet()->owning_document())
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-03-05 00:03:57 +13:00
|
|
|
|
set_family_impl(*descriptors->descriptor(DescriptorNameAndID::from_id(DescriptorID::FontFamily)));
|
2026-04-01 16:31:04 +01:00
|
|
|
|
set_style_impl(*descriptors->descriptor_or_initial_value(DescriptorNameAndID::from_id(DescriptorID::FontStyle))->absolutized(computation_context));
|
|
|
|
|
|
set_weight_impl(*descriptors->descriptor_or_initial_value(DescriptorNameAndID::from_id(DescriptorID::FontWeight))->absolutized(computation_context));
|
2026-03-05 00:03:57 +13:00
|
|
|
|
set_stretch_impl(*descriptors->descriptor_or_initial_value(DescriptorNameAndID::from_id(DescriptorID::FontWidth)));
|
|
|
|
|
|
set_unicode_range_impl(*descriptors->descriptor_or_initial_value(DescriptorNameAndID::from_id(DescriptorID::UnicodeRange)));
|
|
|
|
|
|
set_feature_settings_impl(*descriptors->descriptor_or_initial_value(DescriptorNameAndID::from_id(DescriptorID::FontFeatureSettings)));
|
|
|
|
|
|
set_variation_settings_impl(*descriptors->descriptor_or_initial_value(DescriptorNameAndID::from_id(DescriptorID::FontVariationSettings)));
|
|
|
|
|
|
set_display_impl(*descriptors->descriptor_or_initial_value(DescriptorNameAndID::from_id(DescriptorID::FontDisplay)));
|
|
|
|
|
|
set_ascent_override_impl(*descriptors->descriptor_or_initial_value(DescriptorNameAndID::from_id(DescriptorID::AscentOverride)));
|
|
|
|
|
|
set_descent_override_impl(*descriptors->descriptor_or_initial_value(DescriptorNameAndID::from_id(DescriptorID::DescentOverride)));
|
|
|
|
|
|
set_line_gap_override_impl(*descriptors->descriptor_or_initial_value(DescriptorNameAndID::from_id(DescriptorID::LineGapOverride)));
|
2026-01-10 16:23:23 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-19 16:27:59 +00:00
|
|
|
|
ParsedFontFace FontFace::parsed_font_face() const
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_css_font_face_rule)
|
|
|
|
|
|
return m_css_font_face_rule->font_face();
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: The ParsedFontFace is kind of expensive to create. We should be using a shared sub-object for the data
|
|
|
|
|
|
return ParsedFontFace {
|
|
|
|
|
|
// Create a dummy CSSFontFaceRule so that we load relative to the document's base URL
|
|
|
|
|
|
CSSFontFaceRule::create(realm(), CSSFontFaceDescriptors::create(realm(), {})),
|
|
|
|
|
|
m_family,
|
2026-04-01 16:31:04 +01:00
|
|
|
|
m_cached_weight_range,
|
|
|
|
|
|
m_cached_slope,
|
2026-02-19 16:27:59 +00:00
|
|
|
|
Gfx::FontWidth::Normal, // FIXME: width
|
|
|
|
|
|
m_urls,
|
|
|
|
|
|
m_unicode_ranges,
|
|
|
|
|
|
{}, // FIXME: ascent_override
|
|
|
|
|
|
{}, // FIXME: descent_override
|
|
|
|
|
|
{}, // FIXME: line_gap_override
|
|
|
|
|
|
FontDisplay::Auto, // FIXME: font_display
|
|
|
|
|
|
{}, // font-named-instance doesn't exist in FontFace
|
|
|
|
|
|
{}, // font-language-override doesn't exist in FontFace
|
|
|
|
|
|
{}, // FIXME: feature_settings
|
|
|
|
|
|
{}, // FIXME: variation_settings
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-04 15:32:53 +01:00
|
|
|
|
FontFace::FontFace(JS::Realm& realm, GC::Ref<WebIDL::Promise> font_status_promise)
|
2024-05-07 10:05:29 -06:00
|
|
|
|
: Bindings::PlatformObject(realm)
|
2024-05-13 12:02:38 -06:00
|
|
|
|
, m_font_status_promise(font_status_promise)
|
2024-05-07 10:05:29 -06:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-16 10:38:35 +02:00
|
|
|
|
FontFace::~FontFace() = default;
|
|
|
|
|
|
|
2024-05-07 10:05:29 -06:00
|
|
|
|
void FontFace::initialize(JS::Realm& realm)
|
|
|
|
|
|
{
|
|
|
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(FontFace);
|
2025-04-20 16:22:57 +02:00
|
|
|
|
Base::initialize(realm);
|
2024-05-07 10:05:29 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-13 12:02:38 -06:00
|
|
|
|
void FontFace::visit_edges(JS::Cell::Visitor& visitor)
|
|
|
|
|
|
{
|
|
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
|
|
|
|
|
|
|
|
visitor.visit(m_font_status_promise);
|
2026-01-05 09:30:38 +00:00
|
|
|
|
visitor.visit(m_css_font_face_rule);
|
2026-04-01 17:01:14 +01:00
|
|
|
|
visitor.visit(m_font_loader);
|
2026-02-20 12:20:20 +00:00
|
|
|
|
for (auto const& font_face_set : m_containing_sets)
|
|
|
|
|
|
visitor.visit(font_face_set);
|
2026-01-05 09:30:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
|
GC::Ref<WebIDL::Promise> FontFace::loaded() const
|
2024-05-13 12:02:38 -06:00
|
|
|
|
{
|
2024-10-25 12:38:19 -06:00
|
|
|
|
return m_font_status_promise;
|
2024-05-13 12:02:38 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-04 15:32:53 +01:00
|
|
|
|
void FontFace::reject_status_promise(JS::Value reason)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_status != Bindings::FontFaceLoadStatus::Error) {
|
|
|
|
|
|
WebIDL::reject_promise(realm(), m_font_status_promise, reason);
|
2026-01-05 17:03:05 +00:00
|
|
|
|
WebIDL::mark_promise_as_handled(m_font_status_promise);
|
2025-04-04 15:32:53 +01:00
|
|
|
|
m_status = Bindings::FontFaceLoadStatus::Error;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-01 17:01:14 +01:00
|
|
|
|
Optional<FontComputer&> FontFace::font_computer() const
|
|
|
|
|
|
{
|
|
|
|
|
|
for (auto& font_face_set : m_containing_sets) {
|
|
|
|
|
|
auto& global = HTML::relevant_global_object(font_face_set);
|
|
|
|
|
|
if (auto* window = as_if<HTML::Window>(global))
|
|
|
|
|
|
return window->associated_document().font_computer();
|
|
|
|
|
|
}
|
|
|
|
|
|
return {};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-05 09:50:55 +00:00
|
|
|
|
void FontFace::disconnect_from_css_rule()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_css_font_face_rule = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-01 17:01:14 +01:00
|
|
|
|
RefPtr<Gfx::FontCascadeList const> FontFace::font_with_point_size(float point_size, Gfx::FontVariationSettings const& variations, Gfx::ShapeFeatures const& shape_features) const
|
|
|
|
|
|
{
|
|
|
|
|
|
auto font_list = Gfx::FontCascadeList::create();
|
|
|
|
|
|
if (m_font_loader) {
|
|
|
|
|
|
if (auto font = m_font_loader->font_with_point_size(point_size, variations, shape_features))
|
|
|
|
|
|
font_list->add(*font, m_font_loader->unicode_ranges());
|
|
|
|
|
|
} else if (m_parsed_font) {
|
|
|
|
|
|
font_list->add(m_parsed_font->font(point_size, variations, shape_features), m_unicode_ranges);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (font_list->is_empty())
|
|
|
|
|
|
return {};
|
|
|
|
|
|
return font_list;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 10:28:53 -06:00
|
|
|
|
// https://drafts.csswg.org/css-font-loading/#dom-fontface-family
|
|
|
|
|
|
WebIDL::ExceptionOr<void> FontFace::set_family(String const& string)
|
|
|
|
|
|
{
|
2025-04-04 12:33:35 +01:00
|
|
|
|
// On setting, parse the string according to the grammar for the corresponding @font-face descriptor.
|
|
|
|
|
|
// If it does not match the grammar, throw a SyntaxError; otherwise, set the attribute to the serialization of the
|
|
|
|
|
|
// parsed value.
|
|
|
|
|
|
|
2026-03-05 00:03:57 +13:00
|
|
|
|
auto property = parse_css_descriptor(Parser::ParsingParams(), AtRuleID::FontFace, DescriptorNameAndID::from_id(DescriptorID::FontFamily), string);
|
2024-05-10 10:28:53 -06:00
|
|
|
|
if (!property)
|
2025-08-07 19:31:52 -04:00
|
|
|
|
return WebIDL::SyntaxError::create(realm(), "FontFace.family setter: Invalid descriptor value"_utf16);
|
2024-05-10 10:28:53 -06:00
|
|
|
|
|
2026-01-05 09:30:38 +00:00
|
|
|
|
if (m_css_font_face_rule)
|
|
|
|
|
|
TRY(m_css_font_face_rule->descriptors()->set_font_family(string));
|
2024-05-10 10:28:53 -06:00
|
|
|
|
|
2026-04-01 17:01:14 +01:00
|
|
|
|
if (should_be_registered_with_font_computer()) {
|
|
|
|
|
|
if (auto font_computer = this->font_computer(); font_computer.has_value())
|
|
|
|
|
|
font_computer->unregister_font_face(*this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
set_family_impl(property.release_nonnull());
|
2024-05-10 10:28:53 -06:00
|
|
|
|
|
2026-04-01 17:01:14 +01:00
|
|
|
|
if (should_be_registered_with_font_computer()) {
|
|
|
|
|
|
if (auto font_computer = this->font_computer(); font_computer.has_value())
|
|
|
|
|
|
font_computer->register_font_face(*this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 10:28:53 -06:00
|
|
|
|
return {};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
void FontFace::set_family_impl(NonnullRefPtr<StyleValue const> const& value)
|
|
|
|
|
|
{
|
2026-02-04 19:59:10 +13:00
|
|
|
|
m_family = string_from_style_value(value).to_string();
|
2026-01-11 00:17:50 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 10:28:53 -06:00
|
|
|
|
// https://drafts.csswg.org/css-font-loading/#dom-fontface-style
|
|
|
|
|
|
WebIDL::ExceptionOr<void> FontFace::set_style(String const& string)
|
|
|
|
|
|
{
|
2025-04-04 12:33:35 +01:00
|
|
|
|
// On setting, parse the string according to the grammar for the corresponding @font-face descriptor.
|
|
|
|
|
|
// If it does not match the grammar, throw a SyntaxError; otherwise, set the attribute to the serialization of the
|
|
|
|
|
|
// parsed value.
|
|
|
|
|
|
|
2026-03-05 00:03:57 +13:00
|
|
|
|
auto property = parse_css_descriptor(Parser::ParsingParams(), AtRuleID::FontFace, DescriptorNameAndID::from_id(DescriptorID::FontStyle), string);
|
2024-05-10 10:28:53 -06:00
|
|
|
|
if (!property)
|
2025-08-07 19:31:52 -04:00
|
|
|
|
return WebIDL::SyntaxError::create(realm(), "FontFace.style setter: Invalid descriptor value"_utf16);
|
2024-05-10 10:28:53 -06:00
|
|
|
|
|
2026-01-05 09:30:38 +00:00
|
|
|
|
if (m_css_font_face_rule)
|
|
|
|
|
|
TRY(m_css_font_face_rule->descriptors()->set_font_style(string));
|
2024-05-10 10:28:53 -06:00
|
|
|
|
|
2026-04-01 17:01:14 +01:00
|
|
|
|
if (should_be_registered_with_font_computer()) {
|
|
|
|
|
|
if (auto font_computer = this->font_computer(); font_computer.has_value())
|
|
|
|
|
|
font_computer->unregister_font_face(*this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
set_style_impl(property.release_nonnull());
|
2024-05-10 10:28:53 -06:00
|
|
|
|
|
2026-04-01 17:01:14 +01:00
|
|
|
|
if (should_be_registered_with_font_computer()) {
|
|
|
|
|
|
if (auto font_computer = this->font_computer(); font_computer.has_value())
|
|
|
|
|
|
font_computer->register_font_face(*this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 10:28:53 -06:00
|
|
|
|
return {};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
void FontFace::set_style_impl(NonnullRefPtr<StyleValue const> const& value)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_style = value->to_string(SerializationMode::Normal);
|
2026-04-01 16:31:04 +01:00
|
|
|
|
m_cached_slope = compute_slope(*value);
|
2026-01-11 00:17:50 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 10:28:53 -06:00
|
|
|
|
// https://drafts.csswg.org/css-font-loading/#dom-fontface-weight
|
|
|
|
|
|
WebIDL::ExceptionOr<void> FontFace::set_weight(String const& string)
|
|
|
|
|
|
{
|
2025-04-04 12:33:35 +01:00
|
|
|
|
// On setting, parse the string according to the grammar for the corresponding @font-face descriptor.
|
|
|
|
|
|
// If it does not match the grammar, throw a SyntaxError; otherwise, set the attribute to the serialization of the
|
|
|
|
|
|
// parsed value.
|
|
|
|
|
|
|
2026-03-05 00:03:57 +13:00
|
|
|
|
auto property = parse_css_descriptor(Parser::ParsingParams(), AtRuleID::FontFace, DescriptorNameAndID::from_id(DescriptorID::FontWeight), string);
|
2024-05-10 10:28:53 -06:00
|
|
|
|
if (!property)
|
2025-08-07 19:31:52 -04:00
|
|
|
|
return WebIDL::SyntaxError::create(realm(), "FontFace.weight setter: Invalid descriptor value"_utf16);
|
2024-05-10 10:28:53 -06:00
|
|
|
|
|
2026-01-05 09:30:38 +00:00
|
|
|
|
if (m_css_font_face_rule)
|
|
|
|
|
|
TRY(m_css_font_face_rule->descriptors()->set_font_weight(string));
|
2024-05-10 10:28:53 -06:00
|
|
|
|
|
2026-04-01 17:01:14 +01:00
|
|
|
|
if (should_be_registered_with_font_computer()) {
|
|
|
|
|
|
if (auto font_computer = this->font_computer(); font_computer.has_value())
|
|
|
|
|
|
font_computer->unregister_font_face(*this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
set_weight_impl(property.release_nonnull());
|
2024-05-10 10:28:53 -06:00
|
|
|
|
|
2026-04-01 17:01:14 +01:00
|
|
|
|
if (should_be_registered_with_font_computer()) {
|
|
|
|
|
|
if (auto font_computer = this->font_computer(); font_computer.has_value())
|
|
|
|
|
|
font_computer->register_font_face(*this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 10:28:53 -06:00
|
|
|
|
return {};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
void FontFace::set_weight_impl(NonnullRefPtr<StyleValue const> const& value)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_weight = value->to_string(SerializationMode::Normal);
|
2026-04-01 16:31:04 +01:00
|
|
|
|
m_cached_weight_range = compute_weight_range(*value);
|
2026-01-11 00:17:50 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 10:28:53 -06:00
|
|
|
|
// https://drafts.csswg.org/css-font-loading/#dom-fontface-stretch
|
|
|
|
|
|
WebIDL::ExceptionOr<void> FontFace::set_stretch(String const& string)
|
|
|
|
|
|
{
|
2025-04-04 12:33:35 +01:00
|
|
|
|
// On setting, parse the string according to the grammar for the corresponding @font-face descriptor.
|
|
|
|
|
|
// If it does not match the grammar, throw a SyntaxError; otherwise, set the attribute to the serialization of the
|
|
|
|
|
|
// parsed value.
|
|
|
|
|
|
|
2024-09-27 14:04:59 +01:00
|
|
|
|
// NOTE: font-stretch is now an alias for font-width
|
2026-03-05 00:03:57 +13:00
|
|
|
|
auto property = parse_css_descriptor(Parser::ParsingParams(), AtRuleID::FontFace, DescriptorNameAndID::from_id(DescriptorID::FontWidth), string);
|
2024-05-10 10:28:53 -06:00
|
|
|
|
if (!property)
|
2025-08-07 19:31:52 -04:00
|
|
|
|
return WebIDL::SyntaxError::create(realm(), "FontFace.stretch setter: Invalid descriptor value"_utf16);
|
2024-05-10 10:28:53 -06:00
|
|
|
|
|
2026-01-05 09:30:38 +00:00
|
|
|
|
if (m_css_font_face_rule)
|
|
|
|
|
|
TRY(m_css_font_face_rule->descriptors()->set_font_width(string));
|
2024-05-10 10:28:53 -06:00
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
set_stretch_impl(property.release_nonnull());
|
2024-05-10 10:28:53 -06:00
|
|
|
|
|
2026-04-01 17:01:14 +01:00
|
|
|
|
if (should_be_registered_with_font_computer()) {
|
|
|
|
|
|
if (auto font_computer = this->font_computer(); font_computer.has_value())
|
|
|
|
|
|
font_computer->did_load_font(FlyString(m_family));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 10:28:53 -06:00
|
|
|
|
return {};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
void FontFace::set_stretch_impl(NonnullRefPtr<StyleValue const> const& value)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_stretch = value->to_string(SerializationMode::Normal);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 10:28:53 -06:00
|
|
|
|
// https://drafts.csswg.org/css-font-loading/#dom-fontface-unicoderange
|
2025-04-04 12:33:35 +01:00
|
|
|
|
WebIDL::ExceptionOr<void> FontFace::set_unicode_range(String const& string)
|
2024-05-10 10:28:53 -06:00
|
|
|
|
{
|
2025-04-04 12:33:35 +01:00
|
|
|
|
// On setting, parse the string according to the grammar for the corresponding @font-face descriptor.
|
|
|
|
|
|
// If it does not match the grammar, throw a SyntaxError; otherwise, set the attribute to the serialization of the
|
|
|
|
|
|
// parsed value.
|
|
|
|
|
|
|
2026-03-05 00:03:57 +13:00
|
|
|
|
auto property = parse_css_descriptor(Parser::ParsingParams(), AtRuleID::FontFace, DescriptorNameAndID::from_id(DescriptorID::UnicodeRange), string);
|
2025-04-04 12:33:35 +01:00
|
|
|
|
if (!property)
|
2025-08-07 19:31:52 -04:00
|
|
|
|
return WebIDL::SyntaxError::create(realm(), "FontFace.unicodeRange setter: Invalid descriptor value"_utf16);
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
2026-01-05 09:30:38 +00:00
|
|
|
|
if (m_css_font_face_rule)
|
|
|
|
|
|
TRY(m_css_font_face_rule->descriptors()->set_unicode_range(string));
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
set_unicode_range_impl(property.release_nonnull());
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
2026-04-01 17:01:14 +01:00
|
|
|
|
if (should_be_registered_with_font_computer()) {
|
|
|
|
|
|
if (auto font_computer = this->font_computer(); font_computer.has_value())
|
|
|
|
|
|
font_computer->did_load_font(FlyString(m_family));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-04 12:33:35 +01:00
|
|
|
|
return {};
|
2024-05-10 10:28:53 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
void FontFace::set_unicode_range_impl(NonnullRefPtr<StyleValue const> const& value)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_unicode_range = value->to_string(SerializationMode::Normal);
|
2026-04-01 16:31:04 +01:00
|
|
|
|
auto const& ranges = value->as_value_list().values();
|
|
|
|
|
|
m_unicode_ranges.clear_with_capacity();
|
|
|
|
|
|
m_unicode_ranges.ensure_capacity(ranges.size());
|
|
|
|
|
|
for (auto const& range : ranges)
|
|
|
|
|
|
m_unicode_ranges.unchecked_append(range->as_unicode_range().unicode_range());
|
2026-01-11 00:17:50 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 10:28:53 -06:00
|
|
|
|
// https://drafts.csswg.org/css-font-loading/#dom-fontface-featuresettings
|
2025-04-04 12:33:35 +01:00
|
|
|
|
WebIDL::ExceptionOr<void> FontFace::set_feature_settings(String const& string)
|
2024-05-10 10:28:53 -06:00
|
|
|
|
{
|
2025-04-04 12:33:35 +01:00
|
|
|
|
// On setting, parse the string according to the grammar for the corresponding @font-face descriptor.
|
|
|
|
|
|
// If it does not match the grammar, throw a SyntaxError; otherwise, set the attribute to the serialization of the
|
|
|
|
|
|
// parsed value.
|
|
|
|
|
|
|
2026-03-05 00:03:57 +13:00
|
|
|
|
auto property = parse_css_descriptor(Parser::ParsingParams(), AtRuleID::FontFace, DescriptorNameAndID::from_id(DescriptorID::FontFeatureSettings), string);
|
2025-04-04 12:33:35 +01:00
|
|
|
|
if (!property)
|
2025-08-07 19:31:52 -04:00
|
|
|
|
return WebIDL::SyntaxError::create(realm(), "FontFace.featureSettings setter: Invalid descriptor value"_utf16);
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
2026-01-05 09:30:38 +00:00
|
|
|
|
if (m_css_font_face_rule)
|
|
|
|
|
|
TRY(m_css_font_face_rule->descriptors()->set_font_feature_settings(string));
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
set_feature_settings_impl(property.release_nonnull());
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
|
|
|
|
|
return {};
|
2024-05-10 10:28:53 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
void FontFace::set_feature_settings_impl(NonnullRefPtr<StyleValue const> const& value)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_feature_settings = value->to_string(SerializationMode::Normal);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 10:28:53 -06:00
|
|
|
|
// https://drafts.csswg.org/css-font-loading/#dom-fontface-variationsettings
|
2025-04-04 12:33:35 +01:00
|
|
|
|
WebIDL::ExceptionOr<void> FontFace::set_variation_settings(String const& string)
|
2024-05-10 10:28:53 -06:00
|
|
|
|
{
|
2025-04-04 12:33:35 +01:00
|
|
|
|
// On setting, parse the string according to the grammar for the corresponding @font-face descriptor.
|
|
|
|
|
|
// If it does not match the grammar, throw a SyntaxError; otherwise, set the attribute to the serialization of the
|
|
|
|
|
|
// parsed value.
|
|
|
|
|
|
|
2026-03-05 00:03:57 +13:00
|
|
|
|
auto property = parse_css_descriptor(Parser::ParsingParams(), AtRuleID::FontFace, DescriptorNameAndID::from_id(DescriptorID::FontVariationSettings), string);
|
2025-04-04 12:33:35 +01:00
|
|
|
|
if (!property)
|
2025-08-07 19:31:52 -04:00
|
|
|
|
return WebIDL::SyntaxError::create(realm(), "FontFace.variationSettings setter: Invalid descriptor value"_utf16);
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
2026-01-05 09:30:38 +00:00
|
|
|
|
if (m_css_font_face_rule)
|
|
|
|
|
|
TRY(m_css_font_face_rule->descriptors()->set_font_variation_settings(string));
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
set_variation_settings_impl(property.release_nonnull());
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
|
|
|
|
|
return {};
|
2024-05-10 10:28:53 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
void FontFace::set_variation_settings_impl(NonnullRefPtr<StyleValue const> const& value)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_variation_settings = value->to_string(SerializationMode::Normal);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 10:28:53 -06:00
|
|
|
|
// https://drafts.csswg.org/css-font-loading/#dom-fontface-display
|
2025-04-04 12:33:35 +01:00
|
|
|
|
WebIDL::ExceptionOr<void> FontFace::set_display(String const& string)
|
2024-05-10 10:28:53 -06:00
|
|
|
|
{
|
2025-04-04 12:33:35 +01:00
|
|
|
|
// On setting, parse the string according to the grammar for the corresponding @font-face descriptor.
|
|
|
|
|
|
// If it does not match the grammar, throw a SyntaxError; otherwise, set the attribute to the serialization of the
|
|
|
|
|
|
// parsed value.
|
|
|
|
|
|
|
2026-03-05 00:03:57 +13:00
|
|
|
|
auto property = parse_css_descriptor(Parser::ParsingParams(), AtRuleID::FontFace, DescriptorNameAndID::from_id(DescriptorID::FontDisplay), string);
|
2025-04-04 12:33:35 +01:00
|
|
|
|
if (!property)
|
2025-08-07 19:31:52 -04:00
|
|
|
|
return WebIDL::SyntaxError::create(realm(), "FontFace.display setter: Invalid descriptor value"_utf16);
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
2026-01-05 09:30:38 +00:00
|
|
|
|
if (m_css_font_face_rule)
|
|
|
|
|
|
TRY(m_css_font_face_rule->descriptors()->set_font_display(string));
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
set_display_impl(property.release_nonnull());
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
|
|
|
|
|
return {};
|
2024-05-10 10:28:53 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
void FontFace::set_display_impl(NonnullRefPtr<StyleValue const> const& value)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_display = value->to_string(SerializationMode::Normal);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 10:28:53 -06:00
|
|
|
|
// https://drafts.csswg.org/css-font-loading/#dom-fontface-ascentoverride
|
2025-04-04 12:33:35 +01:00
|
|
|
|
WebIDL::ExceptionOr<void> FontFace::set_ascent_override(String const& string)
|
2024-05-10 10:28:53 -06:00
|
|
|
|
{
|
2025-04-04 12:33:35 +01:00
|
|
|
|
// On setting, parse the string according to the grammar for the corresponding @font-face descriptor.
|
|
|
|
|
|
// If it does not match the grammar, throw a SyntaxError; otherwise, set the attribute to the serialization of the
|
|
|
|
|
|
// parsed value.
|
|
|
|
|
|
|
2026-03-05 00:03:57 +13:00
|
|
|
|
auto property = parse_css_descriptor(Parser::ParsingParams(), AtRuleID::FontFace, DescriptorNameAndID::from_id(DescriptorID::AscentOverride), string);
|
2025-04-04 12:33:35 +01:00
|
|
|
|
if (!property)
|
2025-08-07 19:31:52 -04:00
|
|
|
|
return WebIDL::SyntaxError::create(realm(), "FontFace.ascentOverride setter: Invalid descriptor value"_utf16);
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
2026-01-05 09:30:38 +00:00
|
|
|
|
if (m_css_font_face_rule)
|
|
|
|
|
|
TRY(m_css_font_face_rule->descriptors()->set_ascent_override(string));
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
set_ascent_override_impl(property.release_nonnull());
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
|
|
|
|
|
return {};
|
2024-05-10 10:28:53 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
void FontFace::set_ascent_override_impl(NonnullRefPtr<StyleValue const> const& value)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_ascent_override = value->to_string(SerializationMode::Normal);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 10:28:53 -06:00
|
|
|
|
// https://drafts.csswg.org/css-font-loading/#dom-fontface-descentoverride
|
2025-04-04 12:33:35 +01:00
|
|
|
|
WebIDL::ExceptionOr<void> FontFace::set_descent_override(String const& string)
|
2024-05-10 10:28:53 -06:00
|
|
|
|
{
|
2025-04-04 12:33:35 +01:00
|
|
|
|
// On setting, parse the string according to the grammar for the corresponding @font-face descriptor.
|
|
|
|
|
|
// If it does not match the grammar, throw a SyntaxError; otherwise, set the attribute to the serialization of the
|
|
|
|
|
|
// parsed value.
|
|
|
|
|
|
|
2026-03-05 00:03:57 +13:00
|
|
|
|
auto property = parse_css_descriptor(Parser::ParsingParams(), AtRuleID::FontFace, DescriptorNameAndID::from_id(DescriptorID::DescentOverride), string);
|
2025-04-04 12:33:35 +01:00
|
|
|
|
if (!property)
|
2025-08-07 19:31:52 -04:00
|
|
|
|
return WebIDL::SyntaxError::create(realm(), "FontFace.descentOverride setter: Invalid descriptor value"_utf16);
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
2026-01-05 09:30:38 +00:00
|
|
|
|
if (m_css_font_face_rule)
|
|
|
|
|
|
TRY(m_css_font_face_rule->descriptors()->set_descent_override(string));
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
set_descent_override_impl(property.release_nonnull());
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
|
|
|
|
|
return {};
|
2024-05-10 10:28:53 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
void FontFace::set_descent_override_impl(NonnullRefPtr<StyleValue const> const& value)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_descent_override = value->to_string(SerializationMode::Normal);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 10:28:53 -06:00
|
|
|
|
// https://drafts.csswg.org/css-font-loading/#dom-fontface-linegapoverride
|
2025-04-04 12:33:35 +01:00
|
|
|
|
WebIDL::ExceptionOr<void> FontFace::set_line_gap_override(String const& string)
|
2024-05-10 10:28:53 -06:00
|
|
|
|
{
|
2025-04-04 12:33:35 +01:00
|
|
|
|
// On setting, parse the string according to the grammar for the corresponding @font-face descriptor.
|
|
|
|
|
|
// If it does not match the grammar, throw a SyntaxError; otherwise, set the attribute to the serialization of the
|
|
|
|
|
|
// parsed value.
|
|
|
|
|
|
|
2026-03-05 00:03:57 +13:00
|
|
|
|
auto property = parse_css_descriptor(Parser::ParsingParams(), AtRuleID::FontFace, DescriptorNameAndID::from_id(DescriptorID::LineGapOverride), string);
|
2025-04-04 12:33:35 +01:00
|
|
|
|
if (!property)
|
2025-08-07 19:31:52 -04:00
|
|
|
|
return WebIDL::SyntaxError::create(realm(), "FontFace.lineGapOverride setter: Invalid descriptor value"_utf16);
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
2026-01-05 09:30:38 +00:00
|
|
|
|
if (m_css_font_face_rule)
|
|
|
|
|
|
TRY(m_css_font_face_rule->descriptors()->set_line_gap_override(string));
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
set_line_gap_override_impl(property.release_nonnull());
|
2025-04-04 12:33:35 +01:00
|
|
|
|
|
|
|
|
|
|
return {};
|
2024-05-10 10:28:53 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 00:17:50 +13:00
|
|
|
|
void FontFace::set_line_gap_override_impl(NonnullRefPtr<StyleValue const> const& value)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_line_gap_override = value->to_string(SerializationMode::Normal);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-07 10:05:29 -06:00
|
|
|
|
// https://drafts.csswg.org/css-font-loading/#dom-fontface-load
|
2024-11-15 04:01:23 +13:00
|
|
|
|
GC::Ref<WebIDL::Promise> FontFace::load()
|
2024-05-15 15:00:07 -06:00
|
|
|
|
{
|
|
|
|
|
|
// 1. Let font face be the FontFace object on which this method was called.
|
|
|
|
|
|
auto& font_face = *this;
|
|
|
|
|
|
|
|
|
|
|
|
// 2. If font face’s [[Urls]] slot is null, or its status attribute is anything other than "unloaded",
|
|
|
|
|
|
// return font face’s [[FontStatusPromise]] and abort these steps.
|
|
|
|
|
|
if (font_face.m_urls.is_empty() || font_face.m_status != Bindings::FontFaceLoadStatus::Unloaded)
|
|
|
|
|
|
return font_face.loaded();
|
|
|
|
|
|
|
|
|
|
|
|
// 3. Otherwise, set font face’s status attribute to "loading", return font face’s [[FontStatusPromise]],
|
|
|
|
|
|
// and continue executing the rest of this algorithm asynchronously.
|
|
|
|
|
|
m_status = Bindings::FontFaceLoadStatus::Loading;
|
2026-02-23 14:31:54 +00:00
|
|
|
|
if (m_css_font_face_rule)
|
|
|
|
|
|
m_css_font_face_rule->set_loading_state(CSSStyleSheet::LoadingState::Loading);
|
2024-05-15 15:00:07 -06:00
|
|
|
|
|
2025-12-26 07:04:32 +01:00
|
|
|
|
Web::Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(heap(), [this] {
|
2024-05-15 15:00:07 -06:00
|
|
|
|
// 4. Using the value of font face’s [[Urls]] slot, attempt to load a font as defined in [CSS-FONTS-3],
|
|
|
|
|
|
// as if it was the value of a @font-face rule’s src descriptor.
|
|
|
|
|
|
|
2026-02-20 12:20:20 +00:00
|
|
|
|
// 5. When the load operation completes, successfully or not, queue a task to run the following steps synchronously:
|
2025-12-26 07:04:32 +01:00
|
|
|
|
auto on_load = GC::create_function(heap(), [this](RefPtr<Gfx::Typeface const> maybe_typeface) {
|
|
|
|
|
|
HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*this), GC::create_function(heap(), [this, maybe_typeface] {
|
|
|
|
|
|
HTML::TemporaryExecutionContext context(realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes);
|
2025-05-01 16:16:57 +01:00
|
|
|
|
// 1. If the attempt to load fails, reject font face’s [[FontStatusPromise]] with a DOMException whose name
|
|
|
|
|
|
// is "NetworkError" and set font face’s status attribute to "error".
|
|
|
|
|
|
if (!maybe_typeface) {
|
2025-12-26 07:04:32 +01:00
|
|
|
|
m_status = Bindings::FontFaceLoadStatus::Error;
|
2026-02-23 14:31:54 +00:00
|
|
|
|
if (m_css_font_face_rule)
|
|
|
|
|
|
m_css_font_face_rule->set_loading_state(CSSStyleSheet::LoadingState::Error);
|
2025-12-26 07:04:32 +01:00
|
|
|
|
WebIDL::reject_promise(realm(), m_font_status_promise, WebIDL::NetworkError::create(realm(), "Failed to load font"_utf16));
|
2024-05-15 15:00:07 -06:00
|
|
|
|
|
2026-02-20 12:20:20 +00:00
|
|
|
|
// For each FontFaceSet font face is in:
|
|
|
|
|
|
for (auto& font_face_set : m_containing_sets) {
|
|
|
|
|
|
// 1. Add font face to the FontFaceSet’s [[FailedFonts]] list.
|
|
|
|
|
|
font_face_set->failed_fonts().append(*this);
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Remove font face from the FontFaceSet’s [[LoadingFonts]] list. If font was the last item
|
|
|
|
|
|
// in that list (and so the list is now empty), switch the FontFaceSet to loaded.
|
|
|
|
|
|
font_face_set->loading_fonts().remove_all_matching([this](auto const& entry) { return entry == this; });
|
|
|
|
|
|
if (font_face_set->loading_fonts().is_empty())
|
|
|
|
|
|
font_face_set->switch_to_loaded();
|
|
|
|
|
|
}
|
2025-05-01 16:16:57 +01:00
|
|
|
|
}
|
2024-05-15 15:00:07 -06:00
|
|
|
|
|
|
|
|
|
|
// 2. Otherwise, font face now represents the loaded font; fulfill font face’s [[FontStatusPromise]] with font face
|
|
|
|
|
|
// and set font face’s status attribute to "loaded".
|
2025-05-01 16:16:57 +01:00
|
|
|
|
else {
|
2025-12-26 07:04:32 +01:00
|
|
|
|
m_parsed_font = maybe_typeface;
|
|
|
|
|
|
m_status = Bindings::FontFaceLoadStatus::Loaded;
|
|
|
|
|
|
WebIDL::resolve_promise(realm(), m_font_status_promise, this);
|
2026-02-23 14:31:54 +00:00
|
|
|
|
if (m_css_font_face_rule)
|
|
|
|
|
|
m_css_font_face_rule->set_loading_state(CSSStyleSheet::LoadingState::Loaded);
|
2024-05-15 15:00:07 -06:00
|
|
|
|
|
2026-04-01 17:01:14 +01:00
|
|
|
|
if (auto font_computer = this->font_computer(); font_computer.has_value())
|
|
|
|
|
|
font_computer->register_font_face(*this);
|
|
|
|
|
|
|
2026-02-20 12:20:20 +00:00
|
|
|
|
// For each FontFaceSet font face is in:
|
|
|
|
|
|
for (auto& font_face_set : m_containing_sets) {
|
|
|
|
|
|
// 1. Add font face to the FontFaceSet’s [[LoadedFonts]] list.
|
|
|
|
|
|
font_face_set->loaded_fonts().append(*this);
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Remove font face from the FontFaceSet’s [[LoadingFonts]] list. If font was the last item
|
|
|
|
|
|
// in that list (and so the list is now empty), switch the FontFaceSet to loaded.
|
|
|
|
|
|
font_face_set->loading_fonts().remove_all_matching([this](auto const& entry) { return entry == this; });
|
|
|
|
|
|
if (font_face_set->loading_fonts().is_empty())
|
|
|
|
|
|
font_face_set->switch_to_loaded();
|
|
|
|
|
|
}
|
2025-05-01 16:16:57 +01:00
|
|
|
|
}
|
2026-04-01 17:01:14 +01:00
|
|
|
|
|
|
|
|
|
|
m_font_loader = nullptr;
|
2024-05-15 15:00:07 -06:00
|
|
|
|
}));
|
2025-12-26 07:04:32 +01:00
|
|
|
|
});
|
2024-05-15 15:00:07 -06:00
|
|
|
|
|
|
|
|
|
|
// FIXME: We should probably put the 'font cache' on the WindowOrWorkerGlobalScope instead of tying it to the document's style computer
|
2025-12-26 07:04:32 +01:00
|
|
|
|
auto& global = HTML::relevant_global_object(*this);
|
2025-08-25 07:22:57 +01:00
|
|
|
|
if (auto* window = as_if<HTML::Window>(global)) {
|
2025-11-06 18:27:22 +13:00
|
|
|
|
auto& font_computer = const_cast<FontComputer&>(window->document()->font_computer());
|
2024-05-15 15:00:07 -06:00
|
|
|
|
|
2026-04-01 17:01:14 +01:00
|
|
|
|
if (auto loader = font_computer.load_font_face(parsed_font_face(), move(on_load))) {
|
|
|
|
|
|
m_font_loader = loader;
|
2024-05-15 15:00:07 -06:00
|
|
|
|
loader->start_loading_next_url();
|
2026-04-01 17:01:14 +01:00
|
|
|
|
}
|
2024-05-15 15:00:07 -06:00
|
|
|
|
} else {
|
|
|
|
|
|
// FIXME: Don't know how to load fonts in workers! They don't have a StyleComputer
|
|
|
|
|
|
dbgln("FIXME: Worker font loading not implemented");
|
|
|
|
|
|
}
|
2024-10-31 02:39:29 +13:00
|
|
|
|
}));
|
2025-01-04 13:39:41 +01:00
|
|
|
|
|
|
|
|
|
|
return font_face.loaded();
|
2024-05-07 10:05:29 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-20 12:20:20 +00:00
|
|
|
|
void FontFace::add_to_set(FontFaceSet& set)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_containing_sets.set(set);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FontFace::remove_from_set(FontFaceSet& set)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_containing_sets.remove(set);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-14 11:32:05 +00:00
|
|
|
|
bool font_format_is_supported(FlyString const& name)
|
|
|
|
|
|
{
|
|
|
|
|
|
// https://drafts.csswg.org/css-fonts-4/#font-format-definitions
|
|
|
|
|
|
if (name.equals_ignoring_ascii_case("collection"sv))
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_format_is_supported(Gfx::FontFormat::TrueTypeCollection);
|
2025-03-14 11:32:05 +00:00
|
|
|
|
if (name.equals_ignoring_ascii_case("embedded-opentype"sv))
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_format_is_supported(Gfx::FontFormat::EmbeddedOpenType);
|
2025-03-14 11:32:05 +00:00
|
|
|
|
if (name.equals_ignoring_ascii_case("opentype"sv))
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_format_is_supported(Gfx::FontFormat::OpenType);
|
2025-03-14 11:32:05 +00:00
|
|
|
|
if (name.equals_ignoring_ascii_case("svg"sv))
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_format_is_supported(Gfx::FontFormat::SVG);
|
2025-03-14 11:32:05 +00:00
|
|
|
|
if (name.equals_ignoring_ascii_case("truetype"sv))
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_format_is_supported(Gfx::FontFormat::TrueType);
|
2025-03-14 11:32:05 +00:00
|
|
|
|
if (name.equals_ignoring_ascii_case("woff"sv))
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_format_is_supported(Gfx::FontFormat::WOFF);
|
2025-03-14 11:32:05 +00:00
|
|
|
|
if (name.equals_ignoring_ascii_case("woff2"sv))
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_format_is_supported(Gfx::FontFormat::WOFF2);
|
2025-03-14 11:32:05 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-03 12:32:05 +01:00
|
|
|
|
bool font_tech_is_supported(FontTech font_tech)
|
2025-03-14 11:32:05 +00:00
|
|
|
|
{
|
|
|
|
|
|
// https://drafts.csswg.org/css-fonts-4/#font-tech-definitions
|
2025-06-03 12:32:05 +01:00
|
|
|
|
switch (font_tech) {
|
|
|
|
|
|
case FontTech::FeaturesOpentype:
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_tech_is_supported(Gfx::FontTech::FeaturesOpentype);
|
2025-06-03 12:32:05 +01:00
|
|
|
|
case FontTech::FeaturesAat:
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_tech_is_supported(Gfx::FontTech::FeaturesAat);
|
2025-06-03 12:32:05 +01:00
|
|
|
|
case FontTech::FeaturesGraphite:
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_tech_is_supported(Gfx::FontTech::FeaturesGraphite);
|
2025-06-03 12:32:05 +01:00
|
|
|
|
case FontTech::Variations:
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_tech_is_supported(Gfx::FontTech::Variations);
|
2025-06-03 12:32:05 +01:00
|
|
|
|
case FontTech::ColorColrv0:
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_tech_is_supported(Gfx::FontTech::ColorColrv0);
|
2025-06-03 12:32:05 +01:00
|
|
|
|
case FontTech::ColorColrv1:
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_tech_is_supported(Gfx::FontTech::ColorColrv1);
|
2025-06-03 12:32:05 +01:00
|
|
|
|
case FontTech::ColorSvg:
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_tech_is_supported(Gfx::FontTech::ColorSvg);
|
2025-06-03 12:32:05 +01:00
|
|
|
|
case FontTech::ColorSbix:
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_tech_is_supported(Gfx::FontTech::ColorSbix);
|
2025-06-03 12:32:05 +01:00
|
|
|
|
case FontTech::ColorCbdt:
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_tech_is_supported(Gfx::FontTech::ColorCbdt);
|
2025-06-03 12:32:05 +01:00
|
|
|
|
case FontTech::Palettes:
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_tech_is_supported(Gfx::FontTech::Palettes);
|
2025-06-03 12:32:05 +01:00
|
|
|
|
case FontTech::Incremental:
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_tech_is_supported(Gfx::FontTech::Incremental);
|
2025-03-14 11:32:05 +00:00
|
|
|
|
// https://drafts.csswg.org/css-fonts-5/#font-tech-definitions
|
2025-06-03 12:32:05 +01:00
|
|
|
|
case FontTech::Avar2:
|
2025-06-03 15:48:24 +01:00
|
|
|
|
return Gfx::font_tech_is_supported(Gfx::FontTech::Avar2);
|
2025-06-03 12:32:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool font_tech_is_supported(FlyString const& name)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (auto keyword = keyword_from_string(name); keyword.has_value()) {
|
|
|
|
|
|
if (auto font_tech = keyword_to_font_tech(*keyword); font_tech.has_value()) {
|
|
|
|
|
|
return font_tech_is_supported(*font_tech);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-14 11:32:05 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-07 10:05:29 -06:00
|
|
|
|
}
|