Bug 1097499 part 10 - Add fwid/hwid/twid/qwid font feature support to gfx. r=jfkthame

MozReview-Commit-ID: 3ex2Q998gZN

--HG--
extra : source : 8160d13c7d1ab0fd0845625082b90066a37be6c3
This commit is contained in:
Xidorn Quan 2016-04-22 09:18:41 +10:00
parent d8f6beea61
commit 1003b99e78
3 changed files with 33 additions and 0 deletions

View File

@ -50,6 +50,7 @@ nsFont::Init()
variantLigatures = 0;
variantNumeric = 0;
variantPosition = NS_FONT_VARIANT_POSITION_NORMAL;
variantWidth = NS_FONT_VARIANT_WIDTH_NORMAL;
}
nsFont::nsFont(const nsFont& aOther) = default;
@ -81,6 +82,7 @@ bool nsFont::Equals(const nsFont& aOther) const
(variantLigatures == aOther.variantLigatures) &&
(variantNumeric == aOther.variantNumeric) &&
(variantPosition == aOther.variantPosition) &&
(variantWidth == aOther.variantWidth) &&
(alternateValues == aOther.alternateValues) &&
(featureValueLookup == aOther.featureValueLookup) &&
(smoothing == aOther.smoothing)) {
@ -170,6 +172,23 @@ AddFontFeaturesBitmask(uint32_t aValue, uint32_t aMin, uint32_t aMax,
}
}
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
@ -256,6 +275,13 @@ void nsFont::AddFontFeaturesToStyle(gfxFontStyle *aStyle) const
// -- 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) &&

View File

@ -55,6 +55,7 @@ struct nsFont {
uint8_t variantCaps;
uint8_t variantNumeric;
uint8_t variantPosition;
uint8_t variantWidth;
uint16_t variantLigatures;
uint16_t variantEastAsian;

View File

@ -203,6 +203,12 @@ enum {
#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)