Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / css / style_values / font_source_style_value.lucb

#==============================================================================================
#
#   font_source_style_value - FontSourceStyleValue: one <font-src> of @font-face's src
#
#   DESCRIPTION:
#       Port of LibWeb/CSS/StyleValues/FontSourceStyleValue.cpp (lines 1-77) and the inline
#       members of FontSourceStyleValue.h: local(<family-name>) or <url> with format() and tech().
#
#       Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibWeb/CSS/StyleValues/FontSourceStyleValue.h:22 Web::CSS::FontSourceStyleValue::create.
pub func css_font_source_style_value_create(source: CssFontSourceStyleValueSource, format_: ak.FlyString?, tech: ak.Vector[css_data.FontTech]) -> CssFontSourceStyleValue*:
    let this = &(new CssFontSourceStyleValue[1] --- else trap("out of memory"))[0]
    css_font_source_style_value_construct(this, source, format_, tech)
    return this

## Ported from Libraries/LibWeb/CSS/StyleValues/FontSourceStyleValue.cpp:13 Web::CSS::FontSourceStyleValue::FontSourceStyleValue.
pub func css_font_source_style_value_construct(this: CssFontSourceStyleValue*, source: CssFontSourceStyleValueSource, format_: ak.FlyString?, tech: ak.Vector[css_data.FontTech]):
    css_style_value_construct(this.css_style_value(), CssStyleValueType.font_source)
    css_style_value_set_class(this.css_style_value(), (const CssStyleValueVTable*)&css_font_source_style_value_vtable, &css_font_source_style_value_class)
    this.m_source = source
    this.m_format = format_
    this.m_tech = tech

## Ported from Libraries/LibWeb/CSS/StyleValues/FontSourceStyleValue.h:28 Web::CSS::FontSourceStyleValue::source.
pub func css_font_source_style_value_source(this: CssFontSourceStyleValue*) -> CssFontSourceStyleValueSource:
    return this.m_source

## Ported from Libraries/LibWeb/CSS/StyleValues/FontSourceStyleValue.h:29 Web::CSS::FontSourceStyleValue::format.
pub func css_font_source_style_value_format(this: CssFontSourceStyleValue*) -> ak.FlyString?:
    return this.m_format

## Ported from Libraries/LibWeb/CSS/StyleValues/FontSourceStyleValue.h:30 Web::CSS::FontSourceStyleValue::tech.
pub func css_font_source_style_value_tech(this: CssFontSourceStyleValue*) -> ak.Vector[css_data.FontTech]:
    return this.m_tech

## serialize's tech lambda: `b.append(CSS::to_string(tech))`.
func css_font_source_serialize_tech(context: void*?, builder: ak.StringBuilder*, tech: const css_data.FontTech*) -> unit:
    _ = context
    ak.string_builder_append_string_view(builder, css_data.to_string_font_tech(*tech))

## Ported from Libraries/LibWeb/CSS/StyleValues/FontSourceStyleValue.cpp:23 Web::CSS::FontSourceStyleValue::serialize (override).
pub func css_font_source_style_value_serialize_impl(base: CssStyleValue*, builder: ak.StringBuilder*, arg1: css_syntax.SerializationMode):
    _ = arg1
    let this = (CssFontSourceStyleValue*)base
    # <font-src> = <url> [ format(<font-format>)]? [ tech( <font-tech>#)]? | local(<family-name>)
    match this.m_source:
        .css_font_source_style_value_local(local_source):
            # local(<family-name>)
            # 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 ")".
            ak.string_builder_append(builder, "local(")
            css_style_value_serialize(local_source.name, builder, css_syntax.SerializationMode.normal)
            ak.string_builder_append_u8(builder, ')')
        .css_url(url):
            # <url> [ format(<font-format>)]? [ tech( <font-tech>#)]?
            let url_text = css_url_to_string(&url)
            ak.string_builder_append_string_view(builder, ak.string_bytes_as_string_view(&url_text))
            if let format_ = this.m_format:
                ak.string_builder_append(builder, " format(")
                css_syntax.serialize_an_identifier_string_builder(builder, ak.fly_string_bytes_as_string_view(&format_))
                ak.string_builder_append(builder, ")")
            if not ak.vector_is_empty(&this.m_tech):
                ak.string_builder_append(builder, " tech(")
                css_serialize_a_comma_separated_list(builder, &this.m_tech, ak.Function2[ak.StringBuilder*, const css_data.FontTech*, unit](call = css_font_source_serialize_tech, context = none))
                ak.string_builder_append(builder, ")")

## Ported from Libraries/LibWeb/CSS/StyleValues/FontSourceStyleValue.cpp:57 Web::CSS::FontSourceStyleValue::properties_equal.
pub func css_font_source_style_value_properties_equal(this: CssFontSourceStyleValue*, other: CssFontSourceStyleValue*) -> bool:
    var sources_equal = false
    match this.m_source:
        .css_font_source_style_value_local(local_source):
            match other.m_source:
                # NB: Local::name is a NonnullRefPtr, so this compares the pointers.
                .css_font_source_style_value_local(other_local): sources_equal = local_source.name == other_local.name
                _: sources_equal = false
        .css_url(url):
            match other.m_source:
                .css_url(other_url): sources_equal = css_url_eq(&url, other_url)
                _: sources_equal = false

    return sources_equal and css_optional_fly_strings_equal(this.m_format, other.m_format)

## Ported from Libraries/LibWeb/CSS/StyleValues/FontSourceStyleValue.h:36 Web::CSS::FontSourceStyleValue::is_computationally_independent (override).
pub func css_font_source_style_value_is_computationally_independent_impl(base: CssStyleValue*) -> bool:
    _ = base
    return true

## Ported from Libraries/LibWeb/CSS/StyleValues/StyleValue.h:202 Web::CSS::StyleValueWithDefaultOperators::equals for Web::CSS::FontSourceStyleValue (CRTP helper) (override).
pub func css_font_source_style_value_equals_impl(base: CssStyleValue*, other: CssStyleValue*) -> bool:
    if css_style_value_type(base) != css_style_value_type(other):
        return false
    return css_font_source_style_value_properties_equal((CssFontSourceStyleValue*)base, (CssFontSourceStyleValue*)other)