dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / css / style_values / font_style_style_value.lucb
#==============================================================================================
#
# font_style_style_value - FontStyleStyleValue: normal, italic, oblique and oblique <angle>
#
# DESCRIPTION:
# Port of LibWeb/CSS/StyleValues/FontStyleStyleValue.cpp (lines 1-72) and the inline
# members of FontStyleStyleValue.h. to_font_slope's function-local statics cache
# Gfx::name_to_slope of constant names; the port calls name_to_slope, which gives the same
# answer each time.
#
# Copyright (c) 2025, Tim Ledbetter <tim.ledbetter@ladybird.org>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
## Ported from Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.h:15 Web::CSS::FontStyleStyleValue::create.
pub func css_font_style_style_value_create(font_style: css_data.FontStyleKeyword, angle_value: CssStyleValue*? = none) -> CssFontStyleStyleValue*:
let this = &(new CssFontStyleStyleValue[1] --- else trap("out of memory"))[0]
css_font_style_style_value_construct(this, font_style, angle_value)
return this
## Ported from Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.cpp:16 Web::CSS::FontStyleStyleValue::FontStyleStyleValue.
pub func css_font_style_style_value_construct(this: CssFontStyleStyleValue*, font_style: css_data.FontStyleKeyword, angle_value: CssStyleValue*?):
css_style_value_construct(this.css_style_value(), CssStyleValueType.font_style)
css_style_value_set_class(this.css_style_value(), (const CssStyleValueVTable*)&css_font_style_style_value_vtable, &css_font_style_style_value_class)
this.m_font_style = font_style
this.m_angle_value = angle_value
## Ported from Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.h:22 Web::CSS::FontStyleStyleValue::font_style.
pub func css_font_style_style_value_font_style(this: CssFontStyleStyleValue*) -> css_data.FontStyleKeyword:
return this.m_font_style
## Ported from Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.h:23 Web::CSS::FontStyleStyleValue::angle.
pub func css_font_style_style_value_angle(this: CssFontStyleStyleValue*) -> CssStyleValue*?:
return this.m_angle_value
## Ported from Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.cpp:25 Web::CSS::FontStyleStyleValue::to_font_slope.
pub func css_font_style_style_value_to_font_slope(this: CssFontStyleStyleValue*) -> i32:
# FIXME: Implement `left`, `right`, and `oblique <angle>`
match css_font_style_style_value_font_style(css_style_value_as_font_style(this.css_style_value())):
.italic:
return web_fonts.name_to_slope(ak.sv("Italic"))
.oblique:
return web_fonts.name_to_slope(ak.sv("Oblique"))
_:
return web_fonts.name_to_slope(ak.sv("Normal"))
## Ported from Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.cpp:42 Web::CSS::FontStyleStyleValue::serialize (override).
pub func css_font_style_style_value_serialize_impl(base: CssStyleValue*, builder: ak.StringBuilder*, mode: css_syntax.SerializationMode):
let this = (CssFontStyleStyleValue*)base
var angle_string: ak.String? = none
if let angle_value = this.m_angle_value:
let angle_text = css_style_value_to_string(angle_value, mode)
angle_string = angle_text
if this.m_font_style == css_data.FontStyleKeyword.oblique and ak.string_eq_string_view(&angle_text, ak.sv("0deg")):
ak.string_builder_append(builder, "normal")
return
ak.string_builder_append_string_view(builder, css_data.to_string_font_style_keyword(this.m_font_style))
# https://drafts.csswg.org/css-fonts/#valdef-font-style-oblique-angle--90deg-90deg
# The lack of an <angle> represents 14deg. (Note that a font might internally provide its own mapping for "oblique", but the mapping within the font is disregarded.)
if let text = angle_string:
if not ak.string_eq_string_view(&text, ak.sv("14deg")):
css_appendff(builder, " {}", [css_arg_string(&text)])
## Ported from Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.cpp:59 Web::CSS::FontStyleStyleValue::absolutized (override).
pub func css_font_style_style_value_absolutized_impl(base: CssStyleValue*, computation_context: CssComputationContext) -> CssStyleValue*:
let this = (CssFontStyleStyleValue*)base
var absolutized_angle: CssStyleValue*? = none
if let angle_value = this.m_angle_value:
absolutized_angle = css_style_value_absolutized(angle_value, computation_context)
if css_optional_style_values_equal(absolutized_angle, this.m_angle_value):
return base
return css_font_style_style_value_create(this.m_font_style, absolutized_angle).css_style_value()
## Ported from Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.h:30 Web::CSS::FontStyleStyleValue::equals (override).
pub func css_font_style_style_value_equals_impl(base: CssStyleValue*, other: CssStyleValue*) -> bool:
let this = (CssFontStyleStyleValue*)base
if css_style_value_type(base) != css_style_value_type(other):
return false
let other_font_style = css_style_value_as_font_style(other)
return this.m_font_style == other_font_style.m_font_style and css_optional_style_values_equal(this.m_angle_value, other_font_style.m_angle_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.h:38 Web::CSS::FontStyleStyleValue::properties_equal.
pub func css_font_style_style_value_properties_equal(this: CssFontStyleStyleValue*, other: CssFontStyleStyleValue*) -> bool:
return this.m_font_style == other.m_font_style and css_optional_style_values_equal(this.m_angle_value, other.m_angle_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.h:40 Web::CSS::FontStyleStyleValue::is_computationally_independent (override).
pub func css_font_style_style_value_is_computationally_independent_impl(base: CssStyleValue*) -> bool:
let this = (CssFontStyleStyleValue*)base
let angle_value = this.m_angle_value else return true
return css_style_value_is_computationally_independent(angle_value)