dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / css / font_face_2.lucb
#==============================================================================================
#
# font_face_2 - CSS::FontFace: the descriptor attributes, load(), the face's sets, and the
# supported font formats and technologies
#
# DESCRIPTION:
# Port of LibWeb/CSS/FontFace.cpp (lines 409-899): the setters of the FontFace
# attributes (parse the descriptor, update the connected @font-face rule, re-register
# with the font computer) and their `_impl`s, FontFace::load (the font loader of the
# face's ParsedFontFace and the steps when it completes), add_to_set and
# remove_from_set, and font_format_is_supported / font_tech_is_supported.
#
# Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
# Copyright (c) 2025-2026, Sam Atkins <sam@ladybird.org>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
# mark: Setting the descriptors =================================================================
## `parse_css_descriptor(Parser::ParsingParams(), AtRuleID::FontFace, DescriptorNameAndID::from_id(id), string)`.
func css_font_face_parse_descriptor(descriptor_id: css_data.DescriptorId, string: const ak.String*) -> CssStyleValue*?:
var parsing_params: CssParsingParams = ---
css_parsing_params_construct_css_parsing_mode(&parsing_params)
return parse_css_descriptor(parsing_params, css_data.AtRuleId.font_face, css_descriptor_name_and_id_from_id(descriptor_id), ak.string_bytes_as_string_view(string))
## `return WebIDL::SyntaxError::create(realm(), message)` from a setter.
func css_font_face_throw_syntax_error(this: CssFontFace*, message: str) -> never!:
try idl_throw(.idl_dom_exception(idl_syntax_error_create(bind_platform_object_realm(this.bind_platform_object()), ak.utf16_string_from_str(message))))
## The setters' `if (should_be_registered_with_font_computer()) { if (auto font_computer = this->font_computer(); ...) font_computer->unregister_font_face(*this); }`.
func css_font_face_unregister_if_registered(this: CssFontFace*):
if css_font_face_should_be_registered_with_font_computer(this):
if let font_computer = css_font_face_font_computer(this):
css_font_computer_unregister_font_face(font_computer, this)
## The setters' `if (should_be_registered_with_font_computer()) { if (auto font_computer = this->font_computer(); ...) font_computer->register_font_face(*this); }`.
func css_font_face_register_if_registered(this: CssFontFace*):
if css_font_face_should_be_registered_with_font_computer(this):
if let font_computer = css_font_face_font_computer(this):
css_font_computer_register_font_face(font_computer, this)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:410 Web::CSS::FontFace::set_family.
# https://drafts.csswg.org/css-font-loading/#dom-fontface-family
pub func css_font_face_set_family(this: CssFontFace*, string: ak.String) -> !:
# 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.
let property = css_font_face_parse_descriptor(css_data.DescriptorId.font_family, &string) else try css_font_face_throw_syntax_error(this, "FontFace.family setter: Invalid descriptor value")
if let rule = this.m_css_font_face_rule:
try css_css_font_face_descriptors_set_font_family(css_font_face_rule_descriptors(rule), ak.string_bytes_as_string_view(&string))
css_font_face_unregister_if_registered(this)
css_font_face_set_family_impl(this, property)
css_font_face_register_if_registered(this)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:438 Web::CSS::FontFace::set_family_impl.
pub func css_font_face_set_family_impl(this: CssFontFace*, value: CssStyleValue*):
let family = css_string_from_style_value(value)
this.m_family = ak.fly_string_to_string_const(&family)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:444 Web::CSS::FontFace::set_style.
# https://drafts.csswg.org/css-font-loading/#dom-fontface-style
pub func css_font_face_set_style(this: CssFontFace*, string: ak.String) -> !:
# 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.
let property = css_font_face_parse_descriptor(css_data.DescriptorId.font_style, &string) else try css_font_face_throw_syntax_error(this, "FontFace.style setter: Invalid descriptor value")
if let rule = this.m_css_font_face_rule:
try css_css_font_face_descriptors_set_font_style(css_font_face_rule_descriptors(rule), ak.string_bytes_as_string_view(&string))
css_font_face_unregister_if_registered(this)
css_font_face_set_style_impl(this, property)
css_font_face_register_if_registered(this)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:472 Web::CSS::FontFace::set_style_impl.
pub func css_font_face_set_style_impl(this: CssFontFace*, value: CssStyleValue*):
this.m_style = css_style_value_to_string(value, css_syntax.SerializationMode.normal)
this.m_cached_slope = css_compute_slope(value)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:479 Web::CSS::FontFace::set_weight.
# https://drafts.csswg.org/css-font-loading/#dom-fontface-weight
pub func css_font_face_set_weight(this: CssFontFace*, string: ak.String) -> !:
# 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.
let property = css_font_face_parse_descriptor(css_data.DescriptorId.font_weight, &string) else try css_font_face_throw_syntax_error(this, "FontFace.weight setter: Invalid descriptor value")
if let rule = this.m_css_font_face_rule:
try css_css_font_face_descriptors_set_font_weight(css_font_face_rule_descriptors(rule), ak.string_bytes_as_string_view(&string))
css_font_face_unregister_if_registered(this)
css_font_face_set_weight_impl(this, property)
css_font_face_register_if_registered(this)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:507 Web::CSS::FontFace::set_weight_impl.
pub func css_font_face_set_weight_impl(this: CssFontFace*, value: CssStyleValue*):
this.m_weight = css_style_value_to_string(value, css_syntax.SerializationMode.normal)
this.m_cached_weight_range = css_compute_weight_range(value)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:514 Web::CSS::FontFace::set_stretch.
# https://drafts.csswg.org/css-font-loading/#dom-fontface-stretch
pub func css_font_face_set_stretch(this: CssFontFace*, string: ak.String) -> !:
# 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.
# NOTE: font-stretch is now an alias for font-width
let property = css_font_face_parse_descriptor(css_data.DescriptorId.font_width, &string) else try css_font_face_throw_syntax_error(this, "FontFace.stretch setter: Invalid descriptor value")
if let rule = this.m_css_font_face_rule:
try css_css_font_face_descriptors_set_font_width(css_font_face_rule_descriptors(rule), ak.string_bytes_as_string_view(&string))
css_font_face_unregister_if_registered(this)
css_font_face_set_stretch_impl(this, property)
css_font_face_register_if_registered(this)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:543 Web::CSS::FontFace::set_stretch_impl.
pub func css_font_face_set_stretch_impl(this: CssFontFace*, value: CssStyleValue*):
this.m_stretch = css_style_value_to_string(value, css_syntax.SerializationMode.normal)
this.m_cached_width = css_compute_width(value)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:550 Web::CSS::FontFace::set_unicode_range.
# https://drafts.csswg.org/css-font-loading/#dom-fontface-unicoderange
pub func css_font_face_set_unicode_range(this: CssFontFace*, string: ak.String) -> !:
# 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.
let property = css_font_face_parse_descriptor(css_data.DescriptorId.unicode_range, &string) else try css_font_face_throw_syntax_error(this, "FontFace.unicodeRange setter: Invalid descriptor value")
if let rule = this.m_css_font_face_rule:
try css_css_font_face_descriptors_set_unicode_range(css_font_face_rule_descriptors(rule), ak.string_bytes_as_string_view(&string))
css_font_face_set_unicode_range_impl(this, property)
if css_font_face_should_be_registered_with_font_computer(this):
if let font_computer = css_font_face_font_computer(this):
css_font_computer_did_load_font(font_computer, ak.fly_string_from_string(this.m_family))
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:573 Web::CSS::FontFace::set_unicode_range_impl.
pub func css_font_face_set_unicode_range_impl(this: CssFontFace*, value: CssStyleValue*):
this.m_unicode_range = css_style_value_to_string(value, css_syntax.SerializationMode.normal)
let ranges = css_style_value_list_values(css_style_value_as_value_list(value))
ak.vector_clear_with_capacity(&this.m_unicode_ranges)
ak.vector_ensure_capacity(&this.m_unicode_ranges, ak.vector_size(&ranges))
for range in ak.vector_span_const(&ranges):
ak.vector_unchecked_append_u(&this.m_unicode_ranges, css_unicode_range_style_value_unicode_range(css_style_value_as_unicode_range(range)))
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:584 Web::CSS::FontFace::set_feature_settings.
# https://drafts.csswg.org/css-font-loading/#dom-fontface-featuresettings
pub func css_font_face_set_feature_settings(this: CssFontFace*, string: ak.String) -> !:
# 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.
let property = css_font_face_parse_descriptor(css_data.DescriptorId.font_feature_settings, &string) else try css_font_face_throw_syntax_error(this, "FontFace.featureSettings setter: Invalid descriptor value")
if let rule = this.m_css_font_face_rule:
try css_css_font_face_descriptors_set_font_feature_settings(css_font_face_rule_descriptors(rule), ak.string_bytes_as_string_view(&string))
css_font_face_set_feature_settings_impl(this, property)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:602 Web::CSS::FontFace::set_feature_settings_impl.
pub func css_font_face_set_feature_settings_impl(this: CssFontFace*, value: CssStyleValue*):
this.m_feature_settings = css_style_value_to_string(value, css_syntax.SerializationMode.normal)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:608 Web::CSS::FontFace::set_variation_settings.
# https://drafts.csswg.org/css-font-loading/#dom-fontface-variationsettings
pub func css_font_face_set_variation_settings(this: CssFontFace*, string: ak.String) -> !:
# 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.
let property = css_font_face_parse_descriptor(css_data.DescriptorId.font_variation_settings, &string) else try css_font_face_throw_syntax_error(this, "FontFace.variationSettings setter: Invalid descriptor value")
if let rule = this.m_css_font_face_rule:
try css_css_font_face_descriptors_set_font_variation_settings(css_font_face_rule_descriptors(rule), ak.string_bytes_as_string_view(&string))
css_font_face_set_variation_settings_impl(this, property)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:626 Web::CSS::FontFace::set_variation_settings_impl.
pub func css_font_face_set_variation_settings_impl(this: CssFontFace*, value: CssStyleValue*):
this.m_variation_settings = css_style_value_to_string(value, css_syntax.SerializationMode.normal)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:632 Web::CSS::FontFace::set_display.
# https://drafts.csswg.org/css-font-loading/#dom-fontface-display
pub func css_font_face_set_display(this: CssFontFace*, string: ak.String) -> !:
# 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.
let property = css_font_face_parse_descriptor(css_data.DescriptorId.font_display, &string) else try css_font_face_throw_syntax_error(this, "FontFace.display setter: Invalid descriptor value")
if let rule = this.m_css_font_face_rule:
try css_css_font_face_descriptors_set_font_display(css_font_face_rule_descriptors(rule), ak.string_bytes_as_string_view(&string))
css_font_face_set_display_impl(this, property)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:650 Web::CSS::FontFace::set_display_impl.
pub func css_font_face_set_display_impl(this: CssFontFace*, value: CssStyleValue*):
this.m_display = css_style_value_to_string(value, css_syntax.SerializationMode.normal)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:656 Web::CSS::FontFace::set_ascent_override.
# https://drafts.csswg.org/css-font-loading/#dom-fontface-ascentoverride
pub func css_font_face_set_ascent_override(this: CssFontFace*, string: ak.String) -> !:
# 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.
let property = css_font_face_parse_descriptor(css_data.DescriptorId.ascent_override, &string) else try css_font_face_throw_syntax_error(this, "FontFace.ascentOverride setter: Invalid descriptor value")
if let rule = this.m_css_font_face_rule:
try css_css_font_face_descriptors_set_ascent_override(css_font_face_rule_descriptors(rule), ak.string_bytes_as_string_view(&string))
css_font_face_set_ascent_override_impl(this, property)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:674 Web::CSS::FontFace::set_ascent_override_impl.
pub func css_font_face_set_ascent_override_impl(this: CssFontFace*, value: CssStyleValue*):
this.m_ascent_override = css_style_value_to_string(value, css_syntax.SerializationMode.normal)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:680 Web::CSS::FontFace::set_descent_override.
# https://drafts.csswg.org/css-font-loading/#dom-fontface-descentoverride
pub func css_font_face_set_descent_override(this: CssFontFace*, string: ak.String) -> !:
# 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.
let property = css_font_face_parse_descriptor(css_data.DescriptorId.descent_override, &string) else try css_font_face_throw_syntax_error(this, "FontFace.descentOverride setter: Invalid descriptor value")
if let rule = this.m_css_font_face_rule:
try css_css_font_face_descriptors_set_descent_override(css_font_face_rule_descriptors(rule), ak.string_bytes_as_string_view(&string))
css_font_face_set_descent_override_impl(this, property)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:698 Web::CSS::FontFace::set_descent_override_impl.
pub func css_font_face_set_descent_override_impl(this: CssFontFace*, value: CssStyleValue*):
this.m_descent_override = css_style_value_to_string(value, css_syntax.SerializationMode.normal)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:704 Web::CSS::FontFace::set_line_gap_override.
# https://drafts.csswg.org/css-font-loading/#dom-fontface-linegapoverride
pub func css_font_face_set_line_gap_override(this: CssFontFace*, string: ak.String) -> !:
# 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.
let property = css_font_face_parse_descriptor(css_data.DescriptorId.line_gap_override, &string) else try css_font_face_throw_syntax_error(this, "FontFace.lineGapOverride setter: Invalid descriptor value")
if let rule = this.m_css_font_face_rule:
try css_css_font_face_descriptors_set_line_gap_override(css_font_face_rule_descriptors(rule), ak.string_bytes_as_string_view(&string))
css_font_face_set_line_gap_override_impl(this, property)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:722 Web::CSS::FontFace::set_line_gap_override_impl.
pub func css_font_face_set_line_gap_override_impl(this: CssFontFace*, value: CssStyleValue*):
this.m_line_gap_override = css_style_value_to_string(value, css_syntax.SerializationMode.normal)
# mark: Loading =================================================================================
## The captures of the task load() queues when the font load completes: the face and the typeface.
struct CssFontFaceLoadCompleted:
var this: CssFontFace*
var maybe_typeface: web_fonts.Typeface*?
## load()'s step 5: the steps of the task, run synchronously.
func css_font_face_load_completed(context: void*?):
let captures = (CssFontFaceLoadCompleted*)(context else trap("no captures"))
let this = captures.this
let realm = bind_platform_object_realm(this.bind_platform_object())
var execution_context: HtmlTemporaryExecutionContext = ---
html_temporary_execution_context_construct_realm(&execution_context, realm, HtmlTemporaryExecutionContextCallbacksEnabled.yes)
defer html_temporary_execution_context_destruct(&execution_context)
# 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 captures.maybe_typeface == none:
this.m_status = BindFontFaceLoadStatus.error_
idl_reject_promise(realm, this.m_font_status_promise, css_font_face_exception_value(idl_network_error_create(realm, ak.utf16_string_from_str("Failed to load font"))))
# For each FontFaceSet font face is in:
for entry in ak.hash_table_begin(&this.m_containing_sets):
let font_face_set = *entry
# 1. Add font face to the FontFaceSet’s [[FailedFonts]] list.
ak.vector_append_t(css_font_face_set_failed_fonts(font_face_set), 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.
css_font_face_remove_from_loading_fonts(font_face_set, this)
# 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".
else:
this.m_parsed_font = captures.maybe_typeface
this.m_status = BindFontFaceLoadStatus.loaded
idl_resolve_promise(realm, this.m_font_status_promise, bind_platform_object_wrapper(this.bind_platform_object()))
if let font_computer = css_font_face_font_computer(this):
css_font_computer_register_font_face(font_computer, this)
# For each FontFaceSet font face is in:
for entry in ak.hash_table_begin(&this.m_containing_sets):
let font_face_set = *entry
# 1. Add font face to the FontFaceSet’s [[LoadedFonts]] list.
ak.vector_append_t(css_font_face_set_loaded_fonts(font_face_set), 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.
css_font_face_remove_from_loading_fonts(font_face_set, this)
this.m_font_loader = none
## load()'s on_load callback: when the load operation completes, successfully or not, queue a task.
func css_font_face_load_on_load(context: void*?, maybe_typeface: web_fonts.Typeface*?):
let this = (CssFontFace*)(context else trap("no face"))
let captures = new CssFontFaceLoadCompleted(this = this, maybe_typeface = maybe_typeface) else trap("out of memory")
_ = html_queue_global_task(HtmlTaskSource.font_loading, html_relevant_global_object((JsObject*)this), gc.create_function0(gc.cell_heap(this.cell()), ak.Function0[unit](call = css_font_face_load_completed, context = captures)))
## load()'s deferred steps 4 and 5: load the face's sources with the document's font computer.
func css_font_face_load_deferred(context: void*?):
let this = (CssFontFace*)(context else trap("no face"))
# 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.
# 5. When the load operation completes, successfully or not, queue a task to run the following steps synchronously:
let on_load = gc.create_function1(gc.cell_heap(this.cell()), ak.Function1[web_fonts.Typeface*?, unit](call = css_font_face_load_on_load, context = this))
# FIXME: We should probably put the 'font cache' on the WindowOrWorkerGlobalScope instead of tying it to the document's style computer
let global = html_relevant_global_object((JsObject*)this)
if let window = as_if_html_window((gc.Cell*)global):
let font_computer = dom_document_font_computer(html_window_document(window))
let parsed_font_face = css_font_face_parsed_font_face(this)
if let loader = css_font_computer_load_font_face(font_computer, &parsed_font_face, on_load):
this.m_font_loader = loader
css_font_loader_start_loading_next_url(loader)
else:
# FIXME: Don't know how to load fonts in workers! They don't have a StyleComputer
ak.dbgln("FIXME: Worker font loading not implemented")
## load()'s AD-HOC block: switch the containing FontFaceSets to "loading" and append the face to
## their [[LoadingFonts]], in a temporary execution context (the C++ block scope).
func css_font_face_load_switch_sets_to_loading(this: CssFontFace*):
var execution_context: HtmlTemporaryExecutionContext = ---
html_temporary_execution_context_construct_realm(&execution_context, bind_platform_object_realm(this.bind_platform_object()), HtmlTemporaryExecutionContextCallbacksEnabled.yes)
defer html_temporary_execution_context_destruct(&execution_context)
for entry in ak.hash_table_begin(&this.m_containing_sets):
let font_face_set = *entry
if ak.vector_is_empty(css_font_face_set_loading_fonts(font_face_set)):
css_font_face_set_switch_to_loading(font_face_set)
ak.vector_append_t(css_font_face_set_loading_fonts(font_face_set), this)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:728 Web::CSS::FontFace::load.
# https://drafts.csswg.org/css-font-loading/#dom-fontface-load
pub func css_font_face_load(this: CssFontFace*) -> JsPromiseCapability*:
# 1. Let font face be the FontFace object on which this method was called.
let 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 ak.vector_is_empty(&font_face.m_urls) or font_face.m_status != BindFontFaceLoadStatus.unloaded:
return css_font_face_loaded(font_face)
# 3. Otherwise, set font face’s status attribute to "loading", return font face’s [[FontStatusPromise]],
# and continue executing the rest of this algorithm asynchronously.
this.m_status = BindFontFaceLoadStatus.loading
# AD-HOC: Switch the containing FontFaceSets to "loading" for URL-backed fonts too, mirroring the step the
# constructor performs for BufferSource-backed fonts.
# Spec issue: https://github.com/w3c/csswg-drafts/issues/13235
css_font_face_load_switch_sets_to_loading(this)
platform_event_loop_plugin_deferred_invoke(platform_event_loop_plugin_the(), gc.create_function0(gc.cell_heap(this.cell()), ak.Function0[unit](call = css_font_face_load_deferred, context = this)))
return css_font_face_loaded(font_face)
# mark: Sets ====================================================================================
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:826 Web::CSS::FontFace::add_to_set.
pub func css_font_face_add_to_set(this: CssFontFace*, set: CssFontFaceSet*):
_ = ak.hash_table_set(&this.m_containing_sets, set)
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:831 Web::CSS::FontFace::remove_from_set.
pub func css_font_face_remove_from_set(this: CssFontFace*, set: CssFontFaceSet*):
_ = ak.hash_table_remove_t(&this.m_containing_sets, set)
# mark: Supported formats and technologies ======================================================
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:836 Web::CSS::font_format_is_supported.
pub func css_font_format_is_supported(name: ak.FlyString) -> bool:
# https://drafts.csswg.org/css-fonts-4/#font-format-definitions
if ak.fly_string_equals_ignoring_ascii_case_string_view(&name, ak.sv("collection")):
return web_fonts.font_format_is_supported(web_fonts.FontFormat.true_type_collection)
if ak.fly_string_equals_ignoring_ascii_case_string_view(&name, ak.sv("embedded-opentype")):
return web_fonts.font_format_is_supported(web_fonts.FontFormat.embedded_open_type)
if ak.fly_string_equals_ignoring_ascii_case_string_view(&name, ak.sv("opentype")):
return web_fonts.font_format_is_supported(web_fonts.FontFormat.open_type)
if ak.fly_string_equals_ignoring_ascii_case_string_view(&name, ak.sv("svg")):
return web_fonts.font_format_is_supported(web_fonts.FontFormat.svg)
if ak.fly_string_equals_ignoring_ascii_case_string_view(&name, ak.sv("truetype")):
return web_fonts.font_format_is_supported(web_fonts.FontFormat.true_type)
if ak.fly_string_equals_ignoring_ascii_case_string_view(&name, ak.sv("woff")):
return web_fonts.font_format_is_supported(web_fonts.FontFormat.woff)
if ak.fly_string_equals_ignoring_ascii_case_string_view(&name, ak.sv("woff2")):
return web_fonts.font_format_is_supported(web_fonts.FontFormat.woff2)
return false
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:856 Web::CSS::font_tech_is_supported.
pub func css_font_tech_is_supported_font_tech(font_tech: css_data.FontTech) -> bool:
# https://drafts.csswg.org/css-fonts-4/#font-tech-definitions
match font_tech:
.features_opentype:
return web_fonts.font_tech_is_supported(web_fonts.FontTech.features_opentype)
.features_aat:
return web_fonts.font_tech_is_supported(web_fonts.FontTech.features_aat)
.features_graphite:
return web_fonts.font_tech_is_supported(web_fonts.FontTech.features_graphite)
.variations:
return web_fonts.font_tech_is_supported(web_fonts.FontTech.variations)
.color_colrv0:
return web_fonts.font_tech_is_supported(web_fonts.FontTech.color_colrv0)
.color_colrv1:
return web_fonts.font_tech_is_supported(web_fonts.FontTech.color_colrv1)
.color_svg:
return web_fonts.font_tech_is_supported(web_fonts.FontTech.color_svg)
.color_sbix:
return web_fonts.font_tech_is_supported(web_fonts.FontTech.color_sbix)
.color_cbdt:
return web_fonts.font_tech_is_supported(web_fonts.FontTech.color_cbdt)
.palettes:
return web_fonts.font_tech_is_supported(web_fonts.FontTech.palettes)
.incremental:
return web_fonts.font_tech_is_supported(web_fonts.FontTech.incremental)
# https://drafts.csswg.org/css-fonts-5/#font-tech-definitions
.avar2:
return web_fonts.font_tech_is_supported(web_fonts.FontTech.avar2)
_:
return false
## Ported from Libraries/LibWeb/CSS/FontFace.cpp:889 Web::CSS::font_tech_is_supported.
pub func css_font_tech_is_supported_fly_string(name: ak.FlyString) -> bool:
if let keyword = css_data.keyword_from_string(ak.fly_string_bytes_as_string_view(&name)):
if let font_tech = css_data.keyword_to_font_tech(keyword):
return css_font_tech_is_supported_font_tech(font_tech)
return false