mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:17:44 +00:00
LibWeb: Wrap font metrics into a struct
Rather than passing an increasingly-unwieldy number of font parameters individually to every function that resolves lengths, let's wrap them up. This is frustratingly close to being `Gfx::FontPixelMetrics`, but bitmap fonts cause issues: We choose the closest font to what the CSS requests, but that might have a wildly different size than what the page expects, so we have to fudge the numbers. No behaviour changes.
This commit is contained in:
parent
4a191875a9
commit
0679b4e0b9
14 changed files with 107 additions and 62 deletions
|
@ -18,6 +18,14 @@
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
|
||||||
|
Length::FontMetrics::FontMetrics(CSSPixels font_size, Gfx::FontPixelMetrics const& pixel_metrics, CSSPixels line_height)
|
||||||
|
: font_size(font_size)
|
||||||
|
, x_height(pixel_metrics.x_height)
|
||||||
|
, zero_advance(pixel_metrics.advance_of_ascii_zero + pixel_metrics.glyph_spacing)
|
||||||
|
, line_height(line_height)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Length::Length(int value, Type type)
|
Length::Length(int value, Type type)
|
||||||
: m_type(type)
|
: m_type(type)
|
||||||
, m_value(value)
|
, m_value(value)
|
||||||
|
@ -59,22 +67,21 @@ Length Length::resolved(Layout::Node const& layout_node) const
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSSPixels Length::relative_length_to_px(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const
|
CSSPixels Length::relative_length_to_px(CSSPixelRect const& viewport_rect, FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const
|
||||||
{
|
{
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case Type::Em:
|
case Type::Em:
|
||||||
return m_value * font_size;
|
return m_value * font_metrics.font_size;
|
||||||
case Type::Rem:
|
case Type::Rem:
|
||||||
return m_value * root_font_size;
|
return m_value * root_font_metrics.font_size;
|
||||||
case Type::Ex:
|
case Type::Ex:
|
||||||
return m_value * font_metrics.x_height;
|
return m_value * font_metrics.x_height;
|
||||||
case Type::Ch:
|
case Type::Ch:
|
||||||
// FIXME: Use layout_node.font().pixel_size() when writing-mode is not horizontal-tb (it has to be implemented first)
|
return m_value * font_metrics.zero_advance;
|
||||||
return m_value * (font_metrics.advance_of_ascii_zero + font_metrics.glyph_spacing);
|
|
||||||
case Type::Lh:
|
case Type::Lh:
|
||||||
return m_value * line_height;
|
return m_value * font_metrics.line_height;
|
||||||
case Type::Rlh:
|
case Type::Rlh:
|
||||||
return m_value * root_line_height;
|
return m_value * root_font_metrics.line_height;
|
||||||
case Type::Vw:
|
case Type::Vw:
|
||||||
return viewport_rect.width() * (m_value / 100);
|
return viewport_rect.width() * (m_value / 100);
|
||||||
case Type::Vh:
|
case Type::Vh:
|
||||||
|
@ -99,7 +106,19 @@ CSSPixels Length::to_px(Layout::Node const& layout_node) const
|
||||||
auto* root_element = layout_node.document().document_element();
|
auto* root_element = layout_node.document().document_element();
|
||||||
if (!root_element || !root_element->layout_node())
|
if (!root_element || !root_element->layout_node())
|
||||||
return 0;
|
return 0;
|
||||||
return to_px(viewport_rect, layout_node.font().pixel_metrics(), layout_node.computed_values().font_size(), root_element->layout_node()->computed_values().font_size(), layout_node.line_height(), root_element->layout_node()->line_height());
|
|
||||||
|
FontMetrics font_metrics {
|
||||||
|
layout_node.computed_values().font_size(),
|
||||||
|
layout_node.font().pixel_metrics(),
|
||||||
|
layout_node.line_height()
|
||||||
|
};
|
||||||
|
FontMetrics root_font_metrics {
|
||||||
|
root_element->layout_node()->computed_values().font_size(),
|
||||||
|
root_element->layout_node()->font().pixel_metrics(),
|
||||||
|
root_element->layout_node()->line_height()
|
||||||
|
};
|
||||||
|
|
||||||
|
return to_px(viewport_rect, font_metrics, root_font_metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<String> Length::to_string() const
|
ErrorOr<String> Length::to_string() const
|
||||||
|
@ -193,20 +212,20 @@ Optional<Length::Type> Length::unit_from_name(StringView name)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Length> Length::absolutize(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const
|
Optional<Length> Length::absolutize(CSSPixelRect const& viewport_rect, FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const
|
||||||
{
|
{
|
||||||
if (is_px())
|
if (is_px())
|
||||||
return {};
|
return {};
|
||||||
if (is_absolute() || is_relative()) {
|
if (is_absolute() || is_relative()) {
|
||||||
auto px = to_px(viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height);
|
auto px = to_px(viewport_rect, font_metrics, root_font_metrics);
|
||||||
return CSS::Length::make_px(px);
|
return CSS::Length::make_px(px);
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Length Length::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const
|
Length Length::absolutized(CSSPixelRect const& viewport_rect, FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const
|
||||||
{
|
{
|
||||||
return absolutize(viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height).value_or(*this);
|
return absolutize(viewport_rect, font_metrics, root_font_metrics).value_or(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,15 @@ public:
|
||||||
Auto,
|
Auto,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct FontMetrics {
|
||||||
|
FontMetrics(CSSPixels font_size, Gfx::FontPixelMetrics const&, CSSPixels line_height);
|
||||||
|
|
||||||
|
CSSPixels font_size;
|
||||||
|
CSSPixels x_height;
|
||||||
|
CSSPixels zero_advance;
|
||||||
|
CSSPixels line_height;
|
||||||
|
};
|
||||||
|
|
||||||
static Optional<Type> unit_from_name(StringView);
|
static Optional<Type> unit_from_name(StringView);
|
||||||
|
|
||||||
Length(int value, Type type);
|
Length(int value, Type type);
|
||||||
|
@ -98,12 +107,12 @@ public:
|
||||||
|
|
||||||
CSSPixels to_px(Layout::Node const&) const;
|
CSSPixels to_px(Layout::Node const&) const;
|
||||||
|
|
||||||
ALWAYS_INLINE CSSPixels to_px(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const
|
ALWAYS_INLINE CSSPixels to_px(CSSPixelRect const& viewport_rect, FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const
|
||||||
{
|
{
|
||||||
if (is_auto())
|
if (is_auto())
|
||||||
return 0;
|
return 0;
|
||||||
if (is_relative())
|
if (is_relative())
|
||||||
return relative_length_to_px(viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height);
|
return relative_length_to_px(viewport_rect, font_metrics, root_font_metrics);
|
||||||
return absolute_length_to_px();
|
return absolute_length_to_px();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,11 +147,11 @@ public:
|
||||||
return m_type == other.m_type && m_value == other.m_value;
|
return m_type == other.m_type && m_value == other.m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSSPixels relative_length_to_px(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const;
|
CSSPixels relative_length_to_px(CSSPixelRect const& viewport_rect, FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const;
|
||||||
|
|
||||||
// Returns empty optional if it's already absolute.
|
// Returns empty optional if it's already absolute.
|
||||||
Optional<Length> absolutize(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const;
|
Optional<Length> absolutize(CSSPixelRect const& viewport_rect, FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const;
|
||||||
Length absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const;
|
Length absolutized(CSSPixelRect const& viewport_rect, FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char const* unit_name() const;
|
char const* unit_name() const;
|
||||||
|
|
|
@ -167,11 +167,10 @@ bool MediaFeature::compare(HTML::Window const& window, MediaFeatureValue left, C
|
||||||
|
|
||||||
auto const& initial_font = window.associated_document().style_computer().initial_font();
|
auto const& initial_font = window.associated_document().style_computer().initial_font();
|
||||||
Gfx::FontPixelMetrics const& initial_font_metrics = initial_font.pixel_metrics();
|
Gfx::FontPixelMetrics const& initial_font_metrics = initial_font.pixel_metrics();
|
||||||
float initial_font_size = initial_font.presentation_size();
|
Length::FontMetrics font_metrics { static_cast<CSSPixels>(initial_font.presentation_size()), initial_font_metrics, initial_font_metrics.line_spacing() };
|
||||||
float initial_line_height = initial_font_metrics.line_spacing();
|
|
||||||
|
|
||||||
left_px = left.length().to_px(viewport_rect, initial_font_metrics, initial_font_size, initial_font_size, initial_line_height, initial_line_height);
|
left_px = left.length().to_px(viewport_rect, font_metrics, font_metrics);
|
||||||
right_px = right.length().to_px(viewport_rect, initial_font_metrics, initial_font_size, initial_font_size, initial_line_height, initial_line_height);
|
right_px = right.length().to_px(viewport_rect, font_metrics, font_metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (comparison) {
|
switch (comparison) {
|
||||||
|
|
|
@ -1049,9 +1049,9 @@ CSSPixels StyleComputer::root_element_font_size() const
|
||||||
|
|
||||||
auto root_value = computed_root_style->property(CSS::PropertyID::FontSize);
|
auto root_value = computed_root_style->property(CSS::PropertyID::FontSize);
|
||||||
|
|
||||||
auto font_metrics = computed_root_style->computed_font().pixel_metrics();
|
auto font_pixel_metrics = computed_root_style->computed_font().pixel_metrics();
|
||||||
auto line_height = font_metrics.line_spacing();
|
Length::FontMetrics font_metrics { default_root_element_font_size, font_pixel_metrics, font_pixel_metrics.line_spacing() };
|
||||||
return root_value->to_length().to_px(viewport_rect(), font_metrics, default_root_element_font_size, default_root_element_font_size, line_height, line_height);
|
return root_value->to_length().to_px(viewport_rect(), font_metrics, font_metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
CSSPixels StyleComputer::root_element_line_height() const
|
CSSPixels StyleComputer::root_element_line_height() const
|
||||||
|
@ -1066,10 +1066,9 @@ CSSPixels StyleComputer::root_element_line_height() const
|
||||||
if (!computed_root_style)
|
if (!computed_root_style)
|
||||||
return default_root_element_line_height;
|
return default_root_element_line_height;
|
||||||
|
|
||||||
auto font_metrics = computed_root_style->computed_font().pixel_metrics();
|
auto font_pixel_metrics = computed_root_style->computed_font().pixel_metrics();
|
||||||
auto font_size = root_element_font_size();
|
Length::FontMetrics font_metrics { root_element_font_size(), font_pixel_metrics, font_pixel_metrics.line_spacing() };
|
||||||
auto line_height = font_metrics.line_spacing();
|
return computed_root_style->line_height(viewport_rect(), font_metrics, font_metrics);
|
||||||
return computed_root_style->line_height(viewport_rect(), font_metrics, font_size, font_size, line_height, line_height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* element, Optional<CSS::Selector::PseudoElement> pseudo_element) const
|
void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* element, Optional<CSS::Selector::PseudoElement> pseudo_element) const
|
||||||
|
@ -1218,11 +1217,14 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
|
||||||
auto root_font_size = root_element_font_size();
|
auto root_font_size = root_element_font_size();
|
||||||
auto root_line_height = root_element_line_height();
|
auto root_line_height = root_element_line_height();
|
||||||
|
|
||||||
Gfx::FontPixelMetrics font_metrics;
|
Gfx::FontPixelMetrics font_pixel_metrics;
|
||||||
if (parent_element && parent_element->computed_css_values())
|
if (parent_element && parent_element->computed_css_values())
|
||||||
font_metrics = parent_element->computed_css_values()->computed_font().pixel_metrics();
|
font_pixel_metrics = parent_element->computed_css_values()->computed_font().pixel_metrics();
|
||||||
else
|
else
|
||||||
font_metrics = Platform::FontPlugin::the().default_font().pixel_metrics();
|
font_pixel_metrics = Platform::FontPlugin::the().default_font().pixel_metrics();
|
||||||
|
|
||||||
|
// FIXME: Use metrics from root font!!!
|
||||||
|
Length::FontMetrics root_font_metrics { root_font_size, font_pixel_metrics, root_line_height };
|
||||||
|
|
||||||
auto parent_font_size = [&]() -> CSSPixels {
|
auto parent_font_size = [&]() -> CSSPixels {
|
||||||
if (!parent_element || !parent_element->computed_css_values())
|
if (!parent_element || !parent_element->computed_css_values())
|
||||||
|
@ -1231,8 +1233,10 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
|
||||||
if (value->is_length()) {
|
if (value->is_length()) {
|
||||||
auto length = static_cast<LengthStyleValue const&>(*value).to_length();
|
auto length = static_cast<LengthStyleValue const&>(*value).to_length();
|
||||||
auto parent_line_height = parent_or_root_element_line_height(parent_element, {});
|
auto parent_line_height = parent_or_root_element_line_height(parent_element, {});
|
||||||
if (length.is_absolute() || length.is_relative())
|
if (length.is_absolute() || length.is_relative()) {
|
||||||
return length.to_px(viewport_rect(), font_metrics, font_size_in_px, root_font_size, parent_line_height, root_line_height);
|
Length::FontMetrics font_metrics { font_size_in_px, font_pixel_metrics, parent_line_height };
|
||||||
|
return length.to_px(viewport_rect(), font_metrics, root_font_metrics);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return font_size_in_px;
|
return font_size_in_px;
|
||||||
};
|
};
|
||||||
|
@ -1251,7 +1255,8 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
|
||||||
}
|
}
|
||||||
if (maybe_length.has_value()) {
|
if (maybe_length.has_value()) {
|
||||||
auto parent_line_height = parent_or_root_element_line_height(element, pseudo_element);
|
auto parent_line_height = parent_or_root_element_line_height(element, pseudo_element);
|
||||||
auto px = maybe_length.value().to_px(viewport_rect(), font_metrics, parent_font_size(), root_font_size, parent_line_height, root_line_height).value();
|
Length::FontMetrics font_metrics { parent_font_size(), font_pixel_metrics, parent_line_height };
|
||||||
|
auto px = maybe_length.value().to_px(viewport_rect(), font_metrics, root_font_metrics).value();
|
||||||
if (px != 0)
|
if (px != 0)
|
||||||
font_size_in_px = px;
|
font_size_in_px = px;
|
||||||
}
|
}
|
||||||
|
@ -1379,11 +1384,17 @@ CSSPixels StyleComputer::parent_or_root_element_line_height(DOM::Element const*
|
||||||
auto root_font_size = root_element_font_size();
|
auto root_font_size = root_element_font_size();
|
||||||
auto root_line_height = root_element_line_height();
|
auto root_line_height = root_element_line_height();
|
||||||
auto* computed_values = parent_element->computed_css_values();
|
auto* computed_values = parent_element->computed_css_values();
|
||||||
|
auto parent_font_pixel_metrics = parent_element->layout_node()
|
||||||
|
? parent_element->layout_node()->font().pixel_metrics()
|
||||||
|
: Gfx::FontDatabase::default_font().pixel_metrics();
|
||||||
auto parent_font_size = computed_values->property(CSS::PropertyID::FontSize)->to_length();
|
auto parent_font_size = computed_values->property(CSS::PropertyID::FontSize)->to_length();
|
||||||
// FIXME: Can the parent font size be non-absolute here?
|
// FIXME: Can the parent font size be non-absolute here?
|
||||||
auto parent_font_size_value = parent_font_size.is_absolute() ? parent_font_size.absolute_length_to_px() : root_font_size;
|
auto parent_font_size_value = parent_font_size.is_absolute() ? parent_font_size.absolute_length_to_px() : root_font_size;
|
||||||
auto parent_parent_line_height = parent_or_root_element_line_height(parent_element, {});
|
auto parent_parent_line_height = parent_or_root_element_line_height(parent_element, {});
|
||||||
return computed_values->line_height(viewport_rect(), computed_values->computed_font().pixel_metrics(), parent_font_size_value, root_font_size, parent_parent_line_height, root_line_height);
|
Length::FontMetrics parent_font_metrics { parent_font_size_value, parent_font_pixel_metrics, parent_parent_line_height };
|
||||||
|
// FIXME: Use root font metrics!!!
|
||||||
|
Length::FontMetrics root_font_metrics { root_font_size, parent_font_pixel_metrics, root_line_height };
|
||||||
|
return computed_values->line_height(viewport_rect(), parent_font_metrics, root_font_metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const* element, Optional<CSS::Selector::PseudoElement> pseudo_element) const
|
void StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const* element, Optional<CSS::Selector::PseudoElement> pseudo_element) const
|
||||||
|
@ -1391,9 +1402,15 @@ void StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const
|
||||||
auto root_line_height = root_element_line_height();
|
auto root_line_height = root_element_line_height();
|
||||||
auto parent_or_root_line_height = parent_or_root_element_line_height(element, pseudo_element);
|
auto parent_or_root_line_height = parent_or_root_element_line_height(element, pseudo_element);
|
||||||
|
|
||||||
auto font_metrics = style.computed_font().pixel_metrics();
|
auto font_pixel_metrics = style.computed_font().pixel_metrics();
|
||||||
auto root_font_size = root_element_font_size();
|
auto root_font_size = root_element_font_size();
|
||||||
auto font_size = style.property(CSS::PropertyID::FontSize)->to_length().to_px(viewport_rect(), font_metrics, root_font_size, root_font_size, parent_or_root_line_height, root_line_height);
|
|
||||||
|
Length::FontMetrics font_metrics { root_font_size, font_pixel_metrics, parent_or_root_line_height };
|
||||||
|
// FIXME: Use root font metrics!!!
|
||||||
|
Length::FontMetrics root_font_metrics { root_font_size, font_pixel_metrics, root_line_height };
|
||||||
|
|
||||||
|
auto font_size = style.property(CSS::PropertyID::FontSize)->to_length().to_px(viewport_rect(), font_metrics, root_font_metrics);
|
||||||
|
font_metrics.font_size = font_size;
|
||||||
|
|
||||||
// NOTE: Percentage line-height values are relative to the font-size of the element.
|
// NOTE: Percentage line-height values are relative to the font-size of the element.
|
||||||
// We have to resolve them right away, so that the *computed* line-height is ready for inheritance.
|
// We have to resolve them right away, so that the *computed* line-height is ready for inheritance.
|
||||||
|
@ -1405,7 +1422,8 @@ void StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const
|
||||||
Length::make_px(font_size * line_height_value_slot->as_percentage().percentage().as_fraction()));
|
Length::make_px(font_size * line_height_value_slot->as_percentage().percentage().as_fraction()));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto line_height = style.line_height(viewport_rect(), font_metrics, font_size.value(), root_font_size.value(), parent_or_root_line_height, root_line_height);
|
auto line_height = style.line_height(viewport_rect(), font_metrics, root_font_metrics);
|
||||||
|
font_metrics.line_height = line_height;
|
||||||
|
|
||||||
// NOTE: line-height might be using lh which should be resolved against the parent line height (like we did here already)
|
// NOTE: line-height might be using lh which should be resolved against the parent line height (like we did here already)
|
||||||
if (line_height_value_slot && line_height_value_slot->is_length())
|
if (line_height_value_slot && line_height_value_slot->is_length())
|
||||||
|
@ -1415,7 +1433,7 @@ void StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const
|
||||||
auto& value_slot = style.m_property_values[i];
|
auto& value_slot = style.m_property_values[i];
|
||||||
if (!value_slot)
|
if (!value_slot)
|
||||||
continue;
|
continue;
|
||||||
value_slot = value_slot->absolutized(viewport_rect(), font_metrics, font_size.value(), root_font_size.value(), line_height, root_line_height);
|
value_slot = value_slot->absolutized(viewport_rect(), font_metrics, root_font_metrics);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -153,34 +153,34 @@ NonnullRefPtr<Gfx::Font const> StyleProperties::font_fallback(bool monospace, bo
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: This implementation is almost identical to line_height(Layout::Node) below. Maybe they can be combined somehow.
|
// FIXME: This implementation is almost identical to line_height(Layout::Node) below. Maybe they can be combined somehow.
|
||||||
CSSPixels StyleProperties::line_height(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels parent_line_height, CSSPixels root_line_height) const
|
CSSPixels StyleProperties::line_height(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const
|
||||||
{
|
{
|
||||||
auto line_height = property(CSS::PropertyID::LineHeight);
|
auto line_height = property(CSS::PropertyID::LineHeight);
|
||||||
|
|
||||||
if (line_height->is_identifier() && line_height->to_identifier() == ValueID::Normal)
|
if (line_height->is_identifier() && line_height->to_identifier() == ValueID::Normal)
|
||||||
return font_metrics.line_spacing();
|
return font_metrics.line_height;
|
||||||
|
|
||||||
if (line_height->is_length()) {
|
if (line_height->is_length()) {
|
||||||
auto line_height_length = line_height->to_length();
|
auto line_height_length = line_height->to_length();
|
||||||
if (!line_height_length.is_auto())
|
if (!line_height_length.is_auto())
|
||||||
return line_height_length.to_px(viewport_rect, font_metrics, font_size, root_font_size, parent_line_height, root_line_height);
|
return line_height_length.to_px(viewport_rect, font_metrics, root_font_metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line_height->is_numeric())
|
if (line_height->is_numeric())
|
||||||
return Length(line_height->to_number(), Length::Type::Em).to_px(viewport_rect, font_metrics, font_size, root_font_size, parent_line_height, root_line_height);
|
return Length(line_height->to_number(), Length::Type::Em).to_px(viewport_rect, font_metrics, root_font_metrics);
|
||||||
|
|
||||||
if (line_height->is_percentage()) {
|
if (line_height->is_percentage()) {
|
||||||
// Percentages are relative to 1em. https://www.w3.org/TR/css-inline-3/#valdef-line-height-percentage
|
// Percentages are relative to 1em. https://www.w3.org/TR/css-inline-3/#valdef-line-height-percentage
|
||||||
auto& percentage = line_height->as_percentage().percentage();
|
auto& percentage = line_height->as_percentage().percentage();
|
||||||
return Length(percentage.as_fraction(), Length::Type::Em).to_px(viewport_rect, font_metrics, font_size, root_font_size, parent_line_height, root_line_height);
|
return Length(percentage.as_fraction(), Length::Type::Em).to_px(viewport_rect, font_metrics, root_font_metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line_height->is_calculated()) {
|
if (line_height->is_calculated()) {
|
||||||
// FIXME: Handle `line-height: calc(...)` despite not having a LayoutNode here.
|
// FIXME: Handle `line-height: calc(...)` despite not having a LayoutNode here.
|
||||||
return font_metrics.line_spacing();
|
return font_metrics.line_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
return font_metrics.line_spacing();
|
return font_metrics.line_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSSPixels StyleProperties::line_height(Layout::Node const& layout_node) const
|
CSSPixels StyleProperties::line_height(Layout::Node const& layout_node) const
|
||||||
|
|
|
@ -111,7 +111,7 @@ public:
|
||||||
m_font = move(font);
|
m_font = move(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
CSSPixels line_height(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const&, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const;
|
CSSPixels line_height(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const;
|
||||||
CSSPixels line_height(Layout::Node const&) const;
|
CSSPixels line_height(Layout::Node const&) const;
|
||||||
|
|
||||||
bool operator==(StyleProperties const&) const;
|
bool operator==(StyleProperties const&) const;
|
||||||
|
|
|
@ -338,7 +338,7 @@ StyleValueList const& StyleValue::as_value_list() const
|
||||||
return static_cast<StyleValueList const&>(*this);
|
return static_cast<StyleValueList const&>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueComparingNonnullRefPtr<StyleValue const> StyleValue::absolutized(CSSPixelRect const&, Gfx::FontPixelMetrics const&, CSSPixels, CSSPixels, CSSPixels, CSSPixels) const
|
ValueComparingNonnullRefPtr<StyleValue const> StyleValue::absolutized(CSSPixelRect const&, Length::FontMetrics const&, Length::FontMetrics const&) const
|
||||||
{
|
{
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,7 +287,7 @@ public:
|
||||||
virtual bool has_number() const { return false; }
|
virtual bool has_number() const { return false; }
|
||||||
virtual bool has_integer() const { return false; }
|
virtual bool has_integer() const { return false; }
|
||||||
|
|
||||||
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const;
|
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const;
|
||||||
|
|
||||||
virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const { return {}; }
|
virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const { return {}; }
|
||||||
ValueID to_identifier() const;
|
ValueID to_identifier() const;
|
||||||
|
|
|
@ -18,16 +18,16 @@ ErrorOr<String> BorderRadiusStyleValue::to_string() const
|
||||||
return String::formatted("{} / {}", TRY(m_properties.horizontal_radius.to_string()), TRY(m_properties.vertical_radius.to_string()));
|
return String::formatted("{} / {}", TRY(m_properties.horizontal_radius.to_string()), TRY(m_properties.vertical_radius.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueComparingNonnullRefPtr<StyleValue const> BorderRadiusStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const
|
ValueComparingNonnullRefPtr<StyleValue const> BorderRadiusStyleValue::absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const
|
||||||
{
|
{
|
||||||
if (m_properties.horizontal_radius.is_percentage() && m_properties.vertical_radius.is_percentage())
|
if (m_properties.horizontal_radius.is_percentage() && m_properties.vertical_radius.is_percentage())
|
||||||
return *this;
|
return *this;
|
||||||
auto absolutized_horizontal_radius = m_properties.horizontal_radius;
|
auto absolutized_horizontal_radius = m_properties.horizontal_radius;
|
||||||
auto absolutized_vertical_radius = m_properties.vertical_radius;
|
auto absolutized_vertical_radius = m_properties.vertical_radius;
|
||||||
if (!m_properties.horizontal_radius.is_percentage())
|
if (!m_properties.horizontal_radius.is_percentage())
|
||||||
absolutized_horizontal_radius = m_properties.horizontal_radius.length().absolutized(viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height);
|
absolutized_horizontal_radius = m_properties.horizontal_radius.length().absolutized(viewport_rect, font_metrics, root_font_metrics);
|
||||||
if (!m_properties.vertical_radius.is_percentage())
|
if (!m_properties.vertical_radius.is_percentage())
|
||||||
absolutized_vertical_radius = m_properties.vertical_radius.length().absolutized(viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height);
|
absolutized_vertical_radius = m_properties.vertical_radius.length().absolutized(viewport_rect, font_metrics, root_font_metrics);
|
||||||
return BorderRadiusStyleValue::create(absolutized_horizontal_radius, absolutized_vertical_radius);
|
return BorderRadiusStyleValue::create(absolutized_horizontal_radius, absolutized_vertical_radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ private:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const override;
|
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const override;
|
||||||
|
|
||||||
struct Properties {
|
struct Properties {
|
||||||
bool is_elliptical;
|
bool is_elliptical;
|
||||||
|
|
|
@ -27,9 +27,9 @@ ValueComparingNonnullRefPtr<LengthStyleValue> LengthStyleValue::create(Length co
|
||||||
return adopt_ref(*new LengthStyleValue(length));
|
return adopt_ref(*new LengthStyleValue(length));
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueComparingNonnullRefPtr<StyleValue const> LengthStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const
|
ValueComparingNonnullRefPtr<StyleValue const> LengthStyleValue::absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const
|
||||||
{
|
{
|
||||||
if (auto length = m_length.absolutize(viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height); length.has_value())
|
if (auto length = m_length.absolutize(viewport_rect, font_metrics, root_font_metrics); length.has_value())
|
||||||
return LengthStyleValue::create(length.release_value());
|
return LengthStyleValue::create(length.release_value());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ public:
|
||||||
virtual bool has_length() const override { return true; }
|
virtual bool has_length() const override { return true; }
|
||||||
virtual ErrorOr<String> to_string() const override { return m_length.to_string(); }
|
virtual ErrorOr<String> to_string() const override { return m_length.to_string(); }
|
||||||
virtual Length to_length() const override { return m_length; }
|
virtual Length to_length() const override { return m_length; }
|
||||||
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const override;
|
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const override;
|
||||||
|
|
||||||
bool properties_equal(LengthStyleValue const& other) const { return m_length == other.m_length; }
|
bool properties_equal(LengthStyleValue const& other) const { return m_length == other.m_length; }
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,12 @@ ErrorOr<String> ShadowStyleValue::to_string() const
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueComparingNonnullRefPtr<StyleValue const> ShadowStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const
|
ValueComparingNonnullRefPtr<StyleValue const> ShadowStyleValue::absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const
|
||||||
{
|
{
|
||||||
auto absolutized_offset_x = m_properties.offset_x.absolutized(viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height);
|
auto absolutized_offset_x = m_properties.offset_x.absolutized(viewport_rect, font_metrics, root_font_metrics);
|
||||||
auto absolutized_offset_y = m_properties.offset_y.absolutized(viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height);
|
auto absolutized_offset_y = m_properties.offset_y.absolutized(viewport_rect, font_metrics, root_font_metrics);
|
||||||
auto absolutized_blur_radius = m_properties.blur_radius.absolutized(viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height);
|
auto absolutized_blur_radius = m_properties.blur_radius.absolutized(viewport_rect, font_metrics, root_font_metrics);
|
||||||
auto absolutized_spread_distance = m_properties.spread_distance.absolutized(viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height);
|
auto absolutized_spread_distance = m_properties.spread_distance.absolutized(viewport_rect, font_metrics, root_font_metrics);
|
||||||
return ShadowStyleValue::create(m_properties.color, absolutized_offset_x, absolutized_offset_y, absolutized_blur_radius, absolutized_spread_distance, m_properties.placement);
|
return ShadowStyleValue::create(m_properties.color, absolutized_offset_x, absolutized_offset_y, absolutized_blur_radius, absolutized_spread_distance, m_properties.placement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ private:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const override;
|
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const override;
|
||||||
|
|
||||||
struct Properties {
|
struct Properties {
|
||||||
Color color;
|
Color color;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue