1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:07:34 +00:00

LibGfx: Remove code point parameter from Gfx::Font::Metrics

Everyone was asking for the glyph width of 'M' anyway. We can just make
that request implicit and simplify the API.
This commit is contained in:
Andreas Kling 2022-03-28 11:57:44 +02:00
parent b0955fd269
commit 2f7b6af87e
5 changed files with 9 additions and 9 deletions

View file

@ -372,12 +372,12 @@ Font const& Font::bold_variant() const
return *m_bold_variant;
}
FontMetrics Font::metrics(u32 code_point) const
FontMetrics Font::metrics() const
{
return FontMetrics {
.size = (float)presentation_size(),
.x_height = (float)x_height(),
.glyph_width = (float)glyph_width(code_point),
.glyph_width = (float)glyph_width('M'),
.glyph_spacing = (float)glyph_spacing(),
};
}

View file

@ -103,7 +103,7 @@ public:
virtual NonnullRefPtr<Font> clone() const = 0;
virtual ~Font() {};
FontMetrics metrics(u32 code_point) const;
FontMetrics metrics() const;
virtual u8 presentation_size() const = 0;
virtual int pixel_size() const = 0;

View file

@ -106,7 +106,7 @@ float Length::to_px(Layout::Node const& layout_node) const
auto* root_element = layout_node.document().document_element();
if (!root_element || !root_element->layout_node())
return 0;
return to_px(viewport_rect, layout_node.font().metrics('M'), layout_node.computed_values().font_size(), root_element->layout_node()->computed_values().font_size());
return to_px(viewport_rect, layout_node.font().metrics(), layout_node.computed_values().font_size(), root_element->layout_node()->computed_values().font_size());
}
String Length::to_string() const

View file

@ -166,7 +166,7 @@ bool MediaFeature::compare(HTML::Window const& window, MediaFeatureValue left, C
Gfx::IntRect viewport_rect { 0, 0, window.inner_width(), window.inner_height() };
auto const& initial_font = window.associated_document().style_computer().initial_font();
Gfx::FontMetrics const& initial_font_metrics = initial_font.metrics('M');
Gfx::FontMetrics const& initial_font_metrics = initial_font.metrics();
float initial_font_size = initial_font.presentation_size();
left_px = left.length().to_px(viewport_rect, initial_font_metrics, initial_font_size, initial_font_size);

View file

@ -776,7 +776,7 @@ float StyleComputer::root_element_font_size() const
if (!maybe_root_value.has_value())
return default_root_element_font_size;
return maybe_root_value.value()->to_length().to_px(viewport_rect(), computed_root_style->computed_font().metrics('M'), default_root_element_font_size, default_root_element_font_size);
return maybe_root_value.value()->to_length().to_px(viewport_rect(), computed_root_style->computed_font().metrics(), default_root_element_font_size, default_root_element_font_size);
}
void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* element, Optional<CSS::Selector::PseudoElement> pseudo_element) const
@ -860,9 +860,9 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
Gfx::FontMetrics font_metrics;
if (parent_element && parent_element->computed_css_values())
font_metrics = parent_element->computed_css_values()->computed_font().metrics('M');
font_metrics = parent_element->computed_css_values()->computed_font().metrics();
else
font_metrics = Gfx::FontDatabase::default_font().metrics('M');
font_metrics = Gfx::FontDatabase::default_font().metrics();
auto parent_font_size = [&]() -> float {
if (!parent_element || !parent_element->computed_css_values())
@ -1003,7 +1003,7 @@ Gfx::Font const& StyleComputer::initial_font() const
void StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const*, Optional<CSS::Selector::PseudoElement>) const
{
auto font_metrics = style.computed_font().metrics('M');
auto font_metrics = style.computed_font().metrics();
float root_font_size = root_element_font_size();
float font_size = style.property(CSS::PropertyID::FontSize).value()->to_length().to_px(viewport_rect(), font_metrics, root_font_size, root_font_size);