Bug 1097499 part 10 - Add fwid/hwid/twid/qwid font feature support to gfx. r=jfkthame
authorXidorn Quan <quanxunzhen@gmail.com>
Fri, 22 Apr 2016 09:18:41 +1000
changeset 332277 de351d24e7d74b1d76a9bcec89296b487e81f273
parent 332276 1d4eea6eb300398971025a95baed98c068fe146b
child 332278 f851031ac21e42334c1e63cc20b3b4639ad98658
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1097499
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1097499 part 10 - Add fwid/hwid/twid/qwid font feature support to gfx. r=jfkthame MozReview-Commit-ID: 3ex2Q998gZN
gfx/src/nsFont.cpp
gfx/src/nsFont.h
gfx/thebes/gfxFontConstants.h
--- a/gfx/src/nsFont.cpp
+++ b/gfx/src/nsFont.cpp
@@ -45,16 +45,17 @@ nsFont::Init()
   synthesis = NS_FONT_SYNTHESIS_WEIGHT | NS_FONT_SYNTHESIS_STYLE;
 
   variantAlternates = 0;
   variantCaps = NS_FONT_VARIANT_CAPS_NORMAL;
   variantEastAsian = 0;
   variantLigatures = 0;
   variantNumeric = 0;
   variantPosition = NS_FONT_VARIANT_POSITION_NORMAL;
+  variantWidth = NS_FONT_VARIANT_WIDTH_NORMAL;
 }
 
 nsFont::nsFont(const nsFont& aOther) = default;
 
 nsFont::nsFont()
 {
 }
 
@@ -76,16 +77,17 @@ bool nsFont::Equals(const nsFont& aOther
       (fontFeatureSettings == aOther.fontFeatureSettings) &&
       (languageOverride == aOther.languageOverride) &&
       (variantAlternates == aOther.variantAlternates) &&
       (variantCaps == aOther.variantCaps) &&
       (variantEastAsian == aOther.variantEastAsian) &&
       (variantLigatures == aOther.variantLigatures) &&
       (variantNumeric == aOther.variantNumeric) &&
       (variantPosition == aOther.variantPosition) &&
+      (variantWidth == aOther.variantWidth) &&
       (alternateValues == aOther.alternateValues) &&
       (featureValueLookup == aOther.featureValueLookup) &&
       (smoothing == aOther.smoothing)) {
     return true;
   }
   return false;
 }
 
@@ -165,16 +167,33 @@ AddFontFeaturesBitmask(uint32_t aValue, 
   for (i = 0, m = aMin; m <= aMax; i++, m <<= 1) {
     if (m & aValue) {
       const gfxFontFeature& feature = aFeatureDefaults[i];
       aFeaturesOut.AppendElement(feature);
     }
   }
 }
 
+static uint32_t
+FontFeatureTagForVariantWidth(uint32_t aVariantWidth)
+{
+  switch (aVariantWidth) {
+    case NS_FONT_VARIANT_WIDTH_FULL:
+      return TRUETYPE_TAG('f','w','i','d');
+    case NS_FONT_VARIANT_WIDTH_HALF:
+      return TRUETYPE_TAG('h','w','i','d');
+    case NS_FONT_VARIANT_WIDTH_THIRD:
+      return TRUETYPE_TAG('t','w','i','d');
+    case NS_FONT_VARIANT_WIDTH_QUARTER:
+      return TRUETYPE_TAG('q','w','i','d');
+    default:
+      return 0;
+  }
+}
+
 void nsFont::AddFontFeaturesToStyle(gfxFontStyle *aStyle) const
 {
   // add in font-variant features
   gfxFontFeature setting;
 
   // -- kerning
   setting.mTag = TRUETYPE_TAG('k','e','r','n');
   switch (kerning) {
@@ -251,16 +270,23 @@ void nsFont::AddFontFeaturesToStyle(gfxF
                            NS_FONT_VARIANT_NUMERIC_LINING,
                            NS_FONT_VARIANT_NUMERIC_ORDINAL,
                            numericDefaults, aStyle->featureSettings);
   }
 
   // -- position
   aStyle->variantSubSuper = variantPosition;
 
+  // -- width
+  setting.mTag = FontFeatureTagForVariantWidth(variantWidth);
+  if (setting.mTag) {
+    setting.mValue = 1;
+    aStyle->featureSettings.AppendElement(setting);
+  }
+
   // indicate common-path case when neither variantCaps or variantSubSuper are set
   aStyle->noFallbackVariantFeatures =
     (aStyle->variantCaps == NS_FONT_VARIANT_CAPS_NORMAL) &&
     (variantPosition == NS_FONT_VARIANT_POSITION_NORMAL);
 
   // add in features from font-feature-settings
   aStyle->featureSettings.AppendElements(fontFeatureSettings);
 
--- a/gfx/src/nsFont.h
+++ b/gfx/src/nsFont.h
@@ -50,16 +50,17 @@ struct nsFont {
   // Force this font to not be considered a 'generic' font, even if
   // the name is the same as a CSS generic font family.
   bool systemFont;
 
   // Variant subproperties
   uint8_t variantCaps;
   uint8_t variantNumeric;
   uint8_t variantPosition;
+  uint8_t variantWidth;
 
   uint16_t variantLigatures;
   uint16_t variantEastAsian;
 
   // Some font-variant-alternates property values require
   // font-specific settings defined via @font-feature-values rules.
   // These are resolved *after* font matching occurs.
 
--- a/gfx/thebes/gfxFontConstants.h
+++ b/gfx/thebes/gfxFontConstants.h
@@ -198,16 +198,22 @@ enum {
 #define NS_FONT_VARIANT_NUMERIC_FRACTION_MASK \
     NS_FONT_VARIANT_NUMERIC_DIAGONAL_FRACTIONS | \
     NS_FONT_VARIANT_NUMERIC_STACKED_FRACTIONS
 
 #define NS_FONT_VARIANT_POSITION_NORMAL             0
 #define NS_FONT_VARIANT_POSITION_SUPER              1
 #define NS_FONT_VARIANT_POSITION_SUB                2
 
+#define NS_FONT_VARIANT_WIDTH_NORMAL  0
+#define NS_FONT_VARIANT_WIDTH_FULL    1
+#define NS_FONT_VARIANT_WIDTH_HALF    2
+#define NS_FONT_VARIANT_WIDTH_THIRD   3
+#define NS_FONT_VARIANT_WIDTH_QUARTER 4
+
 // based on fixed offset values used within WebKit
 #define NS_FONT_SUBSCRIPT_OFFSET_RATIO     (0.20)
 #define NS_FONT_SUPERSCRIPT_OFFSET_RATIO   (0.34)
 
 // this roughly corresponds to font-size: smaller behavior
 // at smaller sizes <20px the ratio is closer to 0.8 while at
 // larger sizes >45px the ratio is closer to 0.667 and in between
 // a blend of values is used