mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:07:36 +00:00
LibWeb: Make CSSPixels and Length use 64-bit (double) floating point
This fixes a plethora of rounding problems on many websites. In the future, we may want to replace this with fixed-point arithmetic (bug #18566) for performance (and consistency with other engines), but in the meantime this makes the web look a bit better. :^) There's a lot more things that could be converted to doubles, which would reduce the amount of casting necessary in this patch. We can do that incrementally, however.
This commit is contained in:
parent
30262d7023
commit
655d9d1462
80 changed files with 298 additions and 299 deletions
|
@ -83,7 +83,7 @@ public:
|
|||
static Optional<Type> unit_from_name(StringView);
|
||||
|
||||
Length(int value, Type type);
|
||||
Length(float value, Type type);
|
||||
Length(double value, Type type);
|
||||
~Length();
|
||||
|
||||
static Length make_auto();
|
||||
|
@ -154,7 +154,7 @@ public:
|
|||
}
|
||||
|
||||
Type type() const { return m_type; }
|
||||
float raw_value() const { return m_value; }
|
||||
double raw_value() const { return m_value; }
|
||||
|
||||
CSSPixels to_px(Layout::Node const&) const;
|
||||
|
||||
|
@ -171,8 +171,8 @@ public:
|
|||
|
||||
ALWAYS_INLINE CSSPixels absolute_length_to_px() const
|
||||
{
|
||||
constexpr float inch_pixels = 96.0f;
|
||||
constexpr float centimeter_pixels = (inch_pixels / 2.54f);
|
||||
constexpr double inch_pixels = 96.0;
|
||||
constexpr double centimeter_pixels = (inch_pixels / 2.54);
|
||||
switch (m_type) {
|
||||
case Type::Cm:
|
||||
return m_value * centimeter_pixels; // 1cm = 96px/2.54
|
||||
|
@ -181,13 +181,13 @@ public:
|
|||
case Type::Px:
|
||||
return m_value; // 1px = 1/96th of 1in
|
||||
case Type::Pt:
|
||||
return m_value * ((1.0f / 72.0f) * inch_pixels); // 1pt = 1/72th of 1in
|
||||
return m_value * ((1.0 / 72.0) * inch_pixels); // 1pt = 1/72th of 1in
|
||||
case Type::Pc:
|
||||
return m_value * ((1.0f / 6.0f) * inch_pixels); // 1pc = 1/6th of 1in
|
||||
return m_value * ((1.0 / 6.0) * inch_pixels); // 1pc = 1/6th of 1in
|
||||
case Type::Mm:
|
||||
return m_value * ((1.0f / 10.0f) * centimeter_pixels); // 1mm = 1/10th of 1cm
|
||||
return m_value * ((1.0 / 10.0) * centimeter_pixels); // 1mm = 1/10th of 1cm
|
||||
case Type::Q:
|
||||
return m_value * ((1.0f / 40.0f) * centimeter_pixels); // 1Q = 1/40th of 1cm
|
||||
return m_value * ((1.0 / 40.0) * centimeter_pixels); // 1Q = 1/40th of 1cm
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ private:
|
|||
char const* unit_name() const;
|
||||
|
||||
Type m_type;
|
||||
float m_value { 0 };
|
||||
double m_value { 0 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue