mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 14:35:08 +00:00
LibWeb: Add pc CSS unit
This commit is contained in:
parent
aa71dae03c
commit
043b31ad9a
3 changed files with 16 additions and 5 deletions
|
@ -74,6 +74,8 @@ const char* Length::unit_name() const
|
||||||
return "mm";
|
return "mm";
|
||||||
case Type::Q:
|
case Type::Q:
|
||||||
return "Q";
|
return "Q";
|
||||||
|
case Type::Pc:
|
||||||
|
return "pc";
|
||||||
case Type::Ex:
|
case Type::Ex:
|
||||||
return "ex";
|
return "ex";
|
||||||
case Type::Em:
|
case Type::Em:
|
||||||
|
|
|
@ -43,6 +43,7 @@ public:
|
||||||
Q,
|
Q,
|
||||||
Px,
|
Px,
|
||||||
Pt,
|
Pt,
|
||||||
|
Pc,
|
||||||
Ex,
|
Ex,
|
||||||
Em,
|
Em,
|
||||||
Rem,
|
Rem,
|
||||||
|
@ -100,6 +101,7 @@ public:
|
||||||
|| m_type == Type::Mm
|
|| m_type == Type::Mm
|
||||||
|| m_type == Type::Px
|
|| m_type == Type::Px
|
||||||
|| m_type == Type::Pt
|
|| m_type == Type::Pt
|
||||||
|
|| m_type == Type::Pc
|
||||||
|| m_type == Type::Q;
|
|| m_type == Type::Q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,21 +121,25 @@ public:
|
||||||
{
|
{
|
||||||
if (is_relative())
|
if (is_relative())
|
||||||
return relative_length_to_px(layout_node);
|
return relative_length_to_px(layout_node);
|
||||||
|
constexpr float inch_pixels = 96.0f;
|
||||||
|
constexpr float centimeter_pixels = (inch_pixels / 2.54f);
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case Type::Auto:
|
case Type::Auto:
|
||||||
return 0;
|
return 0;
|
||||||
case Type::Cm:
|
case Type::Cm:
|
||||||
return m_value * (96.0f / 2.54f); // 1cm = 96px/2.54
|
return m_value * centimeter_pixels; // 1cm = 96px/2.54
|
||||||
case Type::In:
|
case Type::In:
|
||||||
return m_value * 96.0f; // 1in = 2.54 cm = 96px
|
return m_value * inch_pixels; // 1in = 2.54 cm = 96px
|
||||||
case Type::Px:
|
case Type::Px:
|
||||||
return m_value; // 1px = 1/96th of 1in
|
return m_value; // 1px = 1/96th of 1in
|
||||||
case Type::Pt:
|
case Type::Pt:
|
||||||
return m_value * 1.33333333f; // 1pt = 1/72th of 1in
|
return m_value * ((1.0f / 72.0f) * inch_pixels); // 1pt = 1/72th of 1in
|
||||||
|
case Type::Pc:
|
||||||
|
return m_value * ((1.0f / 6.0f) * inch_pixels); // 1pc = 1/6th of 1in
|
||||||
case Type::Mm:
|
case Type::Mm:
|
||||||
return m_value * (0.1f * (96.0f / 2.54f)); // 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 * (0.025f * (96.0f / 2.54f)); // 1Q = 1/40th of 1cm
|
return m_value * ((1.0f / 40.0f) * centimeter_pixels); // 1Q = 1/40th of 1cm
|
||||||
case Type::Undefined:
|
case Type::Undefined:
|
||||||
case Type::Percentage:
|
case Type::Percentage:
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -284,6 +284,9 @@ static CSS::Length parse_length(const CSS::ParsingContext& context, const String
|
||||||
} else if (view.ends_with("pt", CaseSensitivity::CaseInsensitive)) {
|
} else if (view.ends_with("pt", CaseSensitivity::CaseInsensitive)) {
|
||||||
type = CSS::Length::Type::Pt;
|
type = CSS::Length::Type::Pt;
|
||||||
value = try_parse_float(view.substring_view(0, view.length() - 2));
|
value = try_parse_float(view.substring_view(0, view.length() - 2));
|
||||||
|
} else if (view.ends_with("pc", CaseSensitivity::CaseInsensitive)) {
|
||||||
|
type = CSS::Length::Type::Pc;
|
||||||
|
value = try_parse_float(view.substring_view(0, view.length() - 2));
|
||||||
} else if (view.ends_with("mm", CaseSensitivity::CaseInsensitive)) {
|
} else if (view.ends_with("mm", CaseSensitivity::CaseInsensitive)) {
|
||||||
type = CSS::Length::Type::Mm;
|
type = CSS::Length::Type::Mm;
|
||||||
value = try_parse_float(view.substring_view(0, view.length() - 2));
|
value = try_parse_float(view.substring_view(0, view.length() - 2));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue