Expand font-weight and font-stretch to take any number
[WebKit.git] / Source / WebCore / platform / text / TextFlags.h
index d4ab7fb..63a9f8c 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef TextFlags_h
-#define TextFlags_h
-
-// <rdar://problem/16980736>: Web fonts crash on certain OSes when using CTFontManagerCreateFontDescriptorFromData()
-// FIXME: When we have moved entirely to CORETEXT_WEB_FONTS, remove the isCustomFont member variable from Font, since it will no longer be used.
-// See https://bug-145873-attachments.webkit.org/attachment.cgi?id=254710
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101000
-#define CORETEXT_WEB_FONTS 0
-#else
-#define CORETEXT_WEB_FONTS 1
-#endif
+#pragma once
 
 namespace WebCore {
 
@@ -61,16 +51,19 @@ enum ExpansionBehaviorFlags {
     AllowLeadingExpansion = 1 << 2,
     ForceLeadingExpansion = 2 << 2,
     LeadingExpansionMask = 3 << 2,
+
+    DefaultExpansion = AllowTrailingExpansion | ForbidLeadingExpansion,
 };
 typedef unsigned ExpansionBehavior;
 
 enum FontSynthesisValues {
     FontSynthesisNone = 0x0,
     FontSynthesisWeight = 0x1,
-    FontSynthesisStyle = 0x2
+    FontSynthesisStyle = 0x2,
+    FontSynthesisSmallCaps = 0x4
 };
 typedef unsigned FontSynthesis;
-const unsigned FontSynthesisWidth = 2;
+const unsigned FontSynthesisWidth = 3;
 
 enum class FontVariantLigatures {
     Normal,
@@ -139,8 +132,8 @@ enum class FontVariantEastAsianVariant {
 
 enum class FontVariantEastAsianWidth {
     Normal,
-    FullWidth,
-    ProportionalWidth
+    Full,
+    Proportional
 };
 
 enum class FontVariantEastAsianRuby {
@@ -221,6 +214,46 @@ struct FontVariantSettings {
             && eastAsianRuby == FontVariantEastAsianRuby::Normal;
     }
 
+    bool operator==(const FontVariantSettings& other) const
+    {
+        return commonLigatures == other.commonLigatures
+            && discretionaryLigatures == other.discretionaryLigatures
+            && historicalLigatures == other.historicalLigatures
+            && contextualAlternates == other.contextualAlternates
+            && position == other.position
+            && caps == other.caps
+            && numericFigure == other.numericFigure
+            && numericSpacing == other.numericSpacing
+            && numericFraction == other.numericFraction
+            && numericOrdinal == other.numericOrdinal
+            && numericSlashedZero == other.numericSlashedZero
+            && alternates == other.alternates
+            && eastAsianVariant == other.eastAsianVariant
+            && eastAsianWidth == other.eastAsianWidth
+            && eastAsianRuby == other.eastAsianRuby;
+    }
+
+    bool operator!=(const FontVariantSettings& other) const { return !(*this == other); }
+
+    unsigned uniqueValue() const
+    {
+        return static_cast<unsigned>(commonLigatures) << 26
+            | static_cast<unsigned>(discretionaryLigatures) << 24
+            | static_cast<unsigned>(historicalLigatures) << 22
+            | static_cast<unsigned>(contextualAlternates) << 20
+            | static_cast<unsigned>(position) << 18
+            | static_cast<unsigned>(caps) << 15
+            | static_cast<unsigned>(numericFigure) << 13
+            | static_cast<unsigned>(numericSpacing) << 11
+            | static_cast<unsigned>(numericFraction) << 9
+            | static_cast<unsigned>(numericOrdinal) << 8
+            | static_cast<unsigned>(numericSlashedZero) << 7
+            | static_cast<unsigned>(alternates) << 6
+            | static_cast<unsigned>(eastAsianVariant) << 3
+            | static_cast<unsigned>(eastAsianWidth) << 1
+            | static_cast<unsigned>(eastAsianRuby) << 0;
+    }
+
     FontVariantLigatures commonLigatures;
     FontVariantLigatures discretionaryLigatures;
     FontVariantLigatures historicalLigatures;
@@ -238,6 +271,63 @@ struct FontVariantSettings {
     FontVariantEastAsianRuby eastAsianRuby;
 };
 
+struct FontVariantLigaturesValues {
+    FontVariantLigaturesValues(
+        FontVariantLigatures commonLigatures,
+        FontVariantLigatures discretionaryLigatures,
+        FontVariantLigatures historicalLigatures,
+        FontVariantLigatures contextualAlternates)
+            : commonLigatures(commonLigatures)
+            , discretionaryLigatures(discretionaryLigatures)
+            , historicalLigatures(historicalLigatures)
+            , contextualAlternates(contextualAlternates)
+    {
+    }
+
+    FontVariantLigatures commonLigatures;
+    FontVariantLigatures discretionaryLigatures;
+    FontVariantLigatures historicalLigatures;
+    FontVariantLigatures contextualAlternates;
+};
+
+struct FontVariantNumericValues {
+    FontVariantNumericValues(
+        FontVariantNumericFigure figure,
+        FontVariantNumericSpacing spacing,
+        FontVariantNumericFraction fraction,
+        FontVariantNumericOrdinal ordinal,
+        FontVariantNumericSlashedZero slashedZero)
+            : figure(figure)
+            , spacing(spacing)
+            , fraction(fraction)
+            , ordinal(ordinal)
+            , slashedZero(slashedZero)
+    {
+    }
+
+    FontVariantNumericFigure figure;
+    FontVariantNumericSpacing spacing;
+    FontVariantNumericFraction fraction;
+    FontVariantNumericOrdinal ordinal;
+    FontVariantNumericSlashedZero slashedZero;
+};
+
+struct FontVariantEastAsianValues {
+    FontVariantEastAsianValues(
+        FontVariantEastAsianVariant variant,
+        FontVariantEastAsianWidth width,
+        FontVariantEastAsianRuby ruby)
+            : variant(variant)
+            , width(width)
+            , ruby(ruby)
+    {
+    }
+
+    FontVariantEastAsianVariant variant;
+    FontVariantEastAsianWidth width;
+    FontVariantEastAsianRuby ruby;
+};
+
 enum FontWidthVariant {
     RegularWidth,
     HalfWidth,
@@ -250,68 +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,
-    FontVariantNormalBit,
-    FontVariantSmallCapsBit,
-    FontWeight100Bit,
-    FontWeight200Bit,
-    FontWeight300Bit,
-    FontWeight400Bit,
-    FontWeight500Bit,
-    FontWeight600Bit,
-    FontWeight700Bit,
-    FontWeight800Bit,
-    FontWeight900Bit,
-    FontTraitsMaskWidth
-};
-
-enum FontTraitsMask {
-    FontStyleNormalMask = 1 << FontStyleNormalBit,
-    FontStyleItalicMask = 1 << FontStyleItalicBit,
-    FontStyleMask = FontStyleNormalMask | FontStyleItalicMask,
-
-    FontVariantNormalMask = 1 << FontVariantNormalBit,
-    FontVariantSmallCapsMask = 1 << FontVariantSmallCapsBit,
-    FontVariantMask = FontVariantNormalMask | FontVariantSmallCapsMask,
-
-    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
-};
-
 enum class Kerning {
     Auto,
     Normal,
@@ -319,5 +352,3 @@ enum class Kerning {
 };
 
 }
-
-#endif