Expand font-weight and font-stretch to take any number
[WebKit.git] / Source / WebCore / platform / text / TextFlags.h
index a729a97..63a9f8c 100644 (file)
@@ -25,8 +25,6 @@
 
 #pragma once
 
-#include <wtf/NeverDestroyed.h>
-
 namespace WebCore {
 
 enum TextRenderingMode { AutoTextRendering, OptimizeSpeed, OptimizeLegibility, GeometricPrecision };
@@ -342,218 +340,11 @@ const unsigned FontWidthVariantWidth = 2;
 
 COMPILE_ASSERT(!(LastFontWidthVariant >> FontWidthVariantWidth), FontWidthVariantWidth_is_correct);
 
-enum FontWeight {
-    FontWeight100,
-    FontWeight200,
-    FontWeight300,
-    FontWeight400,
-    FontWeight500,
-    FontWeight600,
-    FontWeight700,
-    FontWeight800,
-    FontWeight900,
-    FontWeightNormal = FontWeight400,
-    FontWeightBold = FontWeight700
-};
-
-enum FontItalic {
-    FontItalicOff = 0,
-    FontItalicOn = 1
-};
-
 enum FontSmallCaps {
     FontSmallCapsOff = 0,
     FontSmallCapsOn = 1
 };
 
-enum {
-    FontStyleNormalBit = 0,
-    FontStyleItalicBit,
-    FontWeight100Bit,
-    FontWeight200Bit,
-    FontWeight300Bit,
-    FontWeight400Bit,
-    FontWeight500Bit,
-    FontWeight600Bit,
-    FontWeight700Bit,
-    FontWeight800Bit,
-    FontWeight900Bit,
-    FontTraitsMaskWidth
-};
-
-enum FontTraitsMask {
-    FontStyleNormalMask = 1 << FontStyleNormalBit,
-    FontStyleItalicMask = 1 << FontStyleItalicBit,
-    FontStyleMask = FontStyleNormalMask | FontStyleItalicMask,
-
-    FontWeight100Mask = 1 << FontWeight100Bit,
-    FontWeight200Mask = 1 << FontWeight200Bit,
-    FontWeight300Mask = 1 << FontWeight300Bit,
-    FontWeight400Mask = 1 << FontWeight400Bit,
-    FontWeight500Mask = 1 << FontWeight500Bit,
-    FontWeight600Mask = 1 << FontWeight600Bit,
-    FontWeight700Mask = 1 << FontWeight700Bit,
-    FontWeight800Mask = 1 << FontWeight800Bit,
-    FontWeight900Mask = 1 << FontWeight900Bit,
-    FontWeightMask = FontWeight100Mask | FontWeight200Mask | FontWeight300Mask | FontWeight400Mask | FontWeight500Mask | FontWeight600Mask | FontWeight700Mask | FontWeight800Mask | FontWeight900Mask
-};
-
-// Unclamped, unchecked, signed fixed-point number representing a value used for font variations.
-// Sixteen bits in total, one sign bit, two fractional bits, means the smallest positive representable value is 0.25,
-// the maximum representable value is 8191.75, and the minimum representable value is -8192.
-class FontSelectionValue {
-public:
-    FontSelectionValue() = default;
-
-    // Explicit because it is lossy.
-    explicit FontSelectionValue(int x)
-        : m_backing(x * fractionalEntropy)
-    {
-    }
-
-    // Explicit because it is lossy.
-    explicit FontSelectionValue(float x)
-        : m_backing(x * fractionalEntropy)
-    {
-    }
-
-    operator float() const
-    {
-        // floats have 23 fractional bits, but only 14 fractional bits are necessary, so every value can be represented losslessly.
-        return m_backing / static_cast<float>(fractionalEntropy);
-    }
-
-    FontSelectionValue operator+(const FontSelectionValue other) const
-    {
-        return FontSelectionValue(m_backing + other.m_backing, RawTag::RawTag);
-    }
-
-    FontSelectionValue operator-(const FontSelectionValue other) const
-    {
-        return FontSelectionValue(m_backing - other.m_backing, RawTag::RawTag);
-    }
-
-    FontSelectionValue operator*(const FontSelectionValue other) const
-    {
-        return FontSelectionValue(static_cast<int32_t>(m_backing) * other.m_backing / fractionalEntropy, RawTag::RawTag);
-    }
-
-    FontSelectionValue operator/(const FontSelectionValue other) const
-    {
-        return FontSelectionValue(static_cast<int32_t>(m_backing) / other.m_backing * fractionalEntropy, RawTag::RawTag);
-    }
-
-    FontSelectionValue operator-() const
-    {
-        return FontSelectionValue(-m_backing, RawTag::RawTag);
-    }
-
-    bool operator==(const FontSelectionValue other) const
-    {
-        return m_backing == other.m_backing;
-    }
-
-    bool operator!=(const FontSelectionValue other) const
-    {
-        return !operator==(other);
-    }
-
-    bool operator<(const FontSelectionValue other) const
-    {
-        return m_backing < other.m_backing;
-    }
-
-    bool operator<=(const FontSelectionValue other) const
-    {
-        return m_backing <= other.m_backing;
-    }
-
-    bool operator>(const FontSelectionValue other) const
-    {
-        return m_backing > other.m_backing;
-    }
-
-    bool operator>=(const FontSelectionValue other) const
-    {
-        return m_backing >= other.m_backing;
-    }
-
-    int16_t rawValue() const
-    {
-        return m_backing;
-    }
-
-    static FontSelectionValue maximumValue()
-    {
-        static NeverDestroyed<FontSelectionValue> result = FontSelectionValue(std::numeric_limits<int16_t>::max(), RawTag::RawTag);
-        return result.get();
-    }
-
-    static FontSelectionValue minimumValue()
-    {
-        static NeverDestroyed<FontSelectionValue> result = FontSelectionValue(std::numeric_limits<int16_t>::min(), RawTag::RawTag);
-        return result.get();
-    }
-
-private:
-    enum class RawTag { RawTag };
-
-    FontSelectionValue(int16_t rawValue, RawTag)
-        : m_backing(rawValue)
-    {
-    }
-
-    static constexpr int fractionalEntropy = 4;
-    int16_t m_backing { 0 };
-};
-
-// [Inclusive, Inclusive]
-struct FontSelectionRange {
-    bool isValid() const
-    {
-        return minimum <= maximum;
-    }
-
-    void expand(const FontSelectionRange& other)
-    {
-        ASSERT(other.isValid());
-        if (!isValid())
-            *this = other;
-        else {
-            minimum = std::min(minimum, other.minimum);
-            maximum = std::max(maximum, other.maximum);
-        }
-        ASSERT(isValid());
-    }
-
-    bool includes(FontSelectionValue target) const
-    {
-        return target >= minimum && target <= maximum;
-    }
-
-    FontSelectionValue minimum { FontSelectionValue(1) };
-    FontSelectionValue maximum { FontSelectionValue(0) };
-};
-
-struct FontSelectionRequest {
-    FontSelectionValue weight;
-    FontSelectionValue width;
-    FontSelectionValue slope;
-};
-
-struct FontSelectionCapabilities {
-    void expand(const FontSelectionCapabilities& capabilities)
-    {
-        weight.expand(capabilities.weight);
-        width.expand(capabilities.width);
-        slope.expand(capabilities.slope);
-    }
-
-    FontSelectionRange weight;
-    FontSelectionRange width;
-    FontSelectionRange slope;
-};
-
 enum class Kerning {
     Auto,
     Normal,