mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 10:17:35 +00:00
LibWeb: Split Length::absolute_length_to_px() out from to_px()
In cases where we know the Length is absolute, we know we don't need to pass in a Layout::Node or FontMetrics etc, and yet we were required to before. Splitting it means jumping through less hoops that we don't have to. :^)
This commit is contained in:
parent
fd51b02f9d
commit
f354fd72f1
1 changed files with 7 additions and 5 deletions
|
@ -109,13 +109,18 @@ public:
|
||||||
|
|
||||||
ALWAYS_INLINE float to_px(Gfx::IntRect const& viewport_rect, Gfx::FontMetrics const& font_metrics, float root_font_size) const
|
ALWAYS_INLINE float to_px(Gfx::IntRect const& viewport_rect, Gfx::FontMetrics const& font_metrics, float root_font_size) const
|
||||||
{
|
{
|
||||||
|
if (is_auto())
|
||||||
|
return 0;
|
||||||
if (is_relative())
|
if (is_relative())
|
||||||
return relative_length_to_px(viewport_rect, font_metrics, root_font_size);
|
return relative_length_to_px(viewport_rect, font_metrics, root_font_size);
|
||||||
|
return absolute_length_to_px();
|
||||||
|
}
|
||||||
|
|
||||||
|
ALWAYS_INLINE float absolute_length_to_px() const
|
||||||
|
{
|
||||||
constexpr float inch_pixels = 96.0f;
|
constexpr float inch_pixels = 96.0f;
|
||||||
constexpr float centimeter_pixels = (inch_pixels / 2.54f);
|
constexpr float centimeter_pixels = (inch_pixels / 2.54f);
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case Type::Auto:
|
|
||||||
return 0;
|
|
||||||
case Type::Cm:
|
case Type::Cm:
|
||||||
return m_value * centimeter_pixels; // 1cm = 96px/2.54
|
return m_value * centimeter_pixels; // 1cm = 96px/2.54
|
||||||
case Type::In:
|
case Type::In:
|
||||||
|
@ -130,9 +135,6 @@ public:
|
||||||
return m_value * ((1.0f / 10.0f) * centimeter_pixels); // 1mm = 1/10th of 1cm
|
return m_value * ((1.0f / 10.0f) * centimeter_pixels); // 1mm = 1/10th of 1cm
|
||||||
case Type::Q:
|
case Type::Q:
|
||||||
return m_value * ((1.0f / 40.0f) * centimeter_pixels); // 1Q = 1/40th of 1cm
|
return m_value * ((1.0f / 40.0f) * centimeter_pixels); // 1Q = 1/40th of 1cm
|
||||||
case Type::Undefined:
|
|
||||||
case Type::Percentage:
|
|
||||||
case Type::Calculated:
|
|
||||||
default:
|
default:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue