Bug 549861. Add constants needed to support font-variant subproperties. r=dbaron

This commit is contained in:
John Daggett 2013-05-13 18:45:36 +09:00
parent df6ad21c72
commit 2d8bb34591
3 changed files with 234 additions and 19 deletions

View File

@ -11,8 +11,7 @@
nsFont::nsFont(const char* aName, uint8_t aStyle, uint8_t aVariant,
uint16_t aWeight, int16_t aStretch, uint8_t aDecoration,
nscoord aSize, float aSizeAdjust,
const nsString* aLanguageOverride)
nscoord aSize)
{
NS_ASSERTION(aName && IsASCII(nsDependentCString(aName)),
"Must only pass ASCII names here");
@ -24,16 +23,21 @@ nsFont::nsFont(const char* aName, uint8_t aStyle, uint8_t aVariant,
stretch = aStretch;
decorations = aDecoration;
size = aSize;
sizeAdjust = aSizeAdjust;
if (aLanguageOverride) {
languageOverride = *aLanguageOverride;
}
sizeAdjust = 0.0;
kerning = NS_FONT_KERNING_AUTO;
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;
}
nsFont::nsFont(const nsString& aName, uint8_t aStyle, uint8_t aVariant,
uint16_t aWeight, int16_t aStretch, uint8_t aDecoration,
nscoord aSize, float aSizeAdjust,
const nsString* aLanguageOverride)
nscoord aSize)
: name(aName)
{
style = aStyle;
@ -43,10 +47,16 @@ nsFont::nsFont(const nsString& aName, uint8_t aStyle, uint8_t aVariant,
stretch = aStretch;
decorations = aDecoration;
size = aSize;
sizeAdjust = aSizeAdjust;
if (aLanguageOverride) {
languageOverride = *aLanguageOverride;
}
sizeAdjust = 0.0;
kerning = NS_FONT_KERNING_AUTO;
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;
}
nsFont::nsFont(const nsFont& aOther)
@ -60,8 +70,16 @@ nsFont::nsFont(const nsFont& aOther)
decorations = aOther.decorations;
size = aOther.size;
sizeAdjust = aOther.sizeAdjust;
languageOverride = aOther.languageOverride;
kerning = aOther.kerning;
synthesis = aOther.synthesis;
fontFeatureSettings = aOther.fontFeatureSettings;
languageOverride = aOther.languageOverride;
variantAlternates = aOther.variantAlternates;
variantCaps = aOther.variantCaps;
variantEastAsian = aOther.variantEastAsian;
variantLigatures = aOther.variantLigatures;
variantNumeric = aOther.variantNumeric;
variantPosition = aOther.variantPosition;
}
nsFont::nsFont()
@ -81,8 +99,16 @@ bool nsFont::BaseEquals(const nsFont& aOther) const
(size == aOther.size) &&
(sizeAdjust == aOther.sizeAdjust) &&
name.Equals(aOther.name, nsCaseInsensitiveStringComparator()) &&
(kerning == aOther.kerning) &&
(synthesis == aOther.synthesis) &&
(fontFeatureSettings == aOther.fontFeatureSettings) &&
(languageOverride == aOther.languageOverride) &&
(fontFeatureSettings == aOther.fontFeatureSettings)) {
(variantAlternates == aOther.variantAlternates) &&
(variantCaps == aOther.variantCaps) &&
(variantEastAsian == aOther.variantEastAsian) &&
(variantLigatures == aOther.variantLigatures) &&
(variantNumeric == aOther.variantNumeric) &&
(variantPosition == aOther.variantPosition)) {
return true;
}
return false;
@ -109,8 +135,16 @@ nsFont& nsFont::operator=(const nsFont& aOther)
decorations = aOther.decorations;
size = aOther.size;
sizeAdjust = aOther.sizeAdjust;
languageOverride = aOther.languageOverride;
kerning = aOther.kerning;
synthesis = aOther.synthesis;
fontFeatureSettings = aOther.fontFeatureSettings;
languageOverride = aOther.languageOverride;
variantAlternates = aOther.variantAlternates;
variantCaps = aOther.variantCaps;
variantEastAsian = aOther.variantEastAsian;
variantLigatures = aOther.variantLigatures;
variantNumeric = aOther.variantNumeric;
variantPosition = aOther.variantPosition;
return *this;
}

View File

@ -50,6 +50,22 @@ struct NS_GFX nsFont {
// The variant of the font (normal, small-caps)
uint8_t variant;
// Variant subproperties
// (currently -moz- versions, will replace variant above eventually)
uint8_t variantCaps;
uint8_t variantLigatures;
uint8_t variantNumeric;
uint8_t variantPosition;
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.
// -- bitmask for both enumerated and functional propvals
uint16_t variantAlternates;
// The decorations on the font (underline, overline,
// line-through). The decorations can be binary or'd together.
uint8_t decorations;
@ -78,17 +94,21 @@ struct NS_GFX nsFont {
// (see http://www.microsoft.com/typography/otspec/languagetags.htm).
nsString languageOverride;
// Kerning
uint8_t kerning;
// Synthesis setting, controls use of fake bolding/italics
uint8_t synthesis;
// Initialize the font struct with an ASCII name
nsFont(const char* aName, uint8_t aStyle, uint8_t aVariant,
uint16_t aWeight, int16_t aStretch, uint8_t aDecoration,
nscoord aSize, float aSizeAdjust=0.0f,
const nsString* aLanguageOverride = nullptr);
nscoord aSize);
// Initialize the font struct with a (potentially) unicode name
nsFont(const nsString& aName, uint8_t aStyle, uint8_t aVariant,
uint16_t aWeight, int16_t aStretch, uint8_t aDecoration,
nscoord aSize, float aSizeAdjust=0.0f,
const nsString* aLanguageOverride = nullptr);
nscoord aSize);
// Make a copy of the given font
nsFont(const nsFont& aFont);

View File

@ -30,4 +30,165 @@
#define NS_FONT_STRETCH_EXTRA_EXPANDED 3
#define NS_FONT_STRETCH_ULTRA_EXPANDED 4
#define NS_FONT_KERNING_AUTO 0
#define NS_FONT_KERNING_NONE 1
#define NS_FONT_KERNING_NORMAL 2
#define NS_FONT_SYNTHESIS_WEIGHT 0x1
#define NS_FONT_SYNTHESIS_STYLE 0x2
enum {
eFeatureAlternates_historical,
eFeatureAlternates_stylistic,
eFeatureAlternates_styleset,
eFeatureAlternates_character_variant,
eFeatureAlternates_swash,
eFeatureAlternates_ornaments,
eFeatureAlternates_annotation,
eFeatureAlternates_numFeatures
};
// alternates - simple enumerated values
#define NS_FONT_VARIANT_ALTERNATES_HISTORICAL (1 << eFeatureAlternates_historical)
// alternates - values that use functional syntax
#define NS_FONT_VARIANT_ALTERNATES_STYLISTIC (1 << eFeatureAlternates_stylistic)
#define NS_FONT_VARIANT_ALTERNATES_STYLESET (1 << eFeatureAlternates_styleset)
#define NS_FONT_VARIANT_ALTERNATES_CHARACTER_VARIANT (1 << eFeatureAlternates_character_variant)
#define NS_FONT_VARIANT_ALTERNATES_SWASH (1 << eFeatureAlternates_swash)
#define NS_FONT_VARIANT_ALTERNATES_ORNAMENTS (1 << eFeatureAlternates_ornaments)
#define NS_FONT_VARIANT_ALTERNATES_ANNOTATION (1 << eFeatureAlternates_annotation)
#define NS_FONT_VARIANT_ALTERNATES_ENUMERATED_MASK \
NS_FONT_VARIANT_ALTERNATES_HISTORICAL
#define NS_FONT_VARIANT_ALTERNATES_FUNCTIONAL_MASK ( \
NS_FONT_VARIANT_ALTERNATES_STYLISTIC | \
NS_FONT_VARIANT_ALTERNATES_STYLESET | \
NS_FONT_VARIANT_ALTERNATES_CHARACTER_VARIANT | \
NS_FONT_VARIANT_ALTERNATES_SWASH | \
NS_FONT_VARIANT_ALTERNATES_ORNAMENTS | \
NS_FONT_VARIANT_ALTERNATES_ANNOTATION )
#define NS_FONT_VARIANT_CAPS_NORMAL 0
#define NS_FONT_VARIANT_CAPS_SMALLCAPS 1
#define NS_FONT_VARIANT_CAPS_ALLSMALL 2
#define NS_FONT_VARIANT_CAPS_PETITECAPS 3
#define NS_FONT_VARIANT_CAPS_ALLPETITE 4
#define NS_FONT_VARIANT_CAPS_TITLING 5
#define NS_FONT_VARIANT_CAPS_UNICASE 6
enum {
eFeatureEastAsian_jis78,
eFeatureEastAsian_jis83,
eFeatureEastAsian_jis90,
eFeatureEastAsian_jis04,
eFeatureEastAsian_simplified,
eFeatureEastAsian_traditional,
eFeatureEastAsian_full_width,
eFeatureEastAsian_prop_width,
eFeatureEastAsian_ruby,
eFeatureEastAsian_numFeatures
};
#define NS_FONT_VARIANT_EAST_ASIAN_JIS78 (1 << eFeatureEastAsian_jis78)
#define NS_FONT_VARIANT_EAST_ASIAN_JIS83 (1 << eFeatureEastAsian_jis83)
#define NS_FONT_VARIANT_EAST_ASIAN_JIS90 (1 << eFeatureEastAsian_jis90)
#define NS_FONT_VARIANT_EAST_ASIAN_JIS04 (1 << eFeatureEastAsian_jis04)
#define NS_FONT_VARIANT_EAST_ASIAN_SIMPLIFIED (1 << eFeatureEastAsian_simplified)
#define NS_FONT_VARIANT_EAST_ASIAN_TRADITIONAL (1 << eFeatureEastAsian_traditional)
#define NS_FONT_VARIANT_EAST_ASIAN_FULL_WIDTH (1 << eFeatureEastAsian_full_width)
#define NS_FONT_VARIANT_EAST_ASIAN_PROP_WIDTH (1 << eFeatureEastAsian_prop_width)
#define NS_FONT_VARIANT_EAST_ASIAN_RUBY (1 << eFeatureEastAsian_ruby)
#define NS_FONT_VARIANT_EAST_ASIAN_VARIANT_MASK ( \
NS_FONT_VARIANT_EAST_ASIAN_JIS78 | \
NS_FONT_VARIANT_EAST_ASIAN_JIS83 | \
NS_FONT_VARIANT_EAST_ASIAN_JIS90 | \
NS_FONT_VARIANT_EAST_ASIAN_JIS04 | \
NS_FONT_VARIANT_EAST_ASIAN_SIMPLIFIED | \
NS_FONT_VARIANT_EAST_ASIAN_TRADITIONAL )
#define NS_FONT_VARIANT_EAST_ASIAN_WIDTH_MASK ( \
NS_FONT_VARIANT_EAST_ASIAN_FULL_WIDTH | \
NS_FONT_VARIANT_EAST_ASIAN_PROP_WIDTH )
enum {
eFeatureLigatures_common,
eFeatureLigatures_no_common,
eFeatureLigatures_discretionary,
eFeatureLigatures_no_discretionary,
eFeatureLigatures_historical,
eFeatureLigatures_no_historical,
eFeatureLigatures_contextual,
eFeatureLigatures_no_contextual,
eFeatureLigatures_numFeatures
};
#define NS_FONT_VARIANT_LIGATURES_COMMON (1 << eFeatureLigatures_common)
#define NS_FONT_VARIANT_LIGATURES_NO_COMMON (1 << eFeatureLigatures_no_common)
#define NS_FONT_VARIANT_LIGATURES_DISCRETIONARY (1 << eFeatureLigatures_discretionary)
#define NS_FONT_VARIANT_LIGATURES_NO_DISCRETIONARY (1 << eFeatureLigatures_no_discretionary)
#define NS_FONT_VARIANT_LIGATURES_HISTORICAL (1 << eFeatureLigatures_historical)
#define NS_FONT_VARIANT_LIGATURES_NO_HISTORICAL (1 << eFeatureLigatures_no_historical)
#define NS_FONT_VARIANT_LIGATURES_CONTEXTUAL (1 << eFeatureLigatures_contextual)
#define NS_FONT_VARIANT_LIGATURES_NO_CONTEXTUAL (1 << eFeatureLigatures_no_contextual)
#define NS_FONT_VARIANT_LIGATURES_COMMON_MASK ( \
NS_FONT_VARIANT_LIGATURES_COMMON | \
NS_FONT_VARIANT_LIGATURES_NO_COMMON )
#define NS_FONT_VARIANT_LIGATURES_DISCRETIONARY_MASK ( \
NS_FONT_VARIANT_LIGATURES_DISCRETIONARY | \
NS_FONT_VARIANT_LIGATURES_NO_DISCRETIONARY )
#define NS_FONT_VARIANT_LIGATURES_HISTORICAL_MASK ( \
NS_FONT_VARIANT_LIGATURES_HISTORICAL | \
NS_FONT_VARIANT_LIGATURES_NO_HISTORICAL )
#define NS_FONT_VARIANT_LIGATURES_CONTEXTUAL_MASK \
NS_FONT_VARIANT_LIGATURES_CONTEXTUAL | \
NS_FONT_VARIANT_LIGATURES_NO_CONTEXTUAL
enum {
eFeatureNumeric_lining,
eFeatureNumeric_oldstyle,
eFeatureNumeric_proportional,
eFeatureNumeric_tabular,
eFeatureNumeric_diagonal_fractions,
eFeatureNumeric_stacked_fractions,
eFeatureNumeric_slashedzero,
eFeatureNumeric_ordinal,
eFeatureNumeric_numFeatures
};
#define NS_FONT_VARIANT_NUMERIC_LINING (1 << eFeatureNumeric_lining)
#define NS_FONT_VARIANT_NUMERIC_OLDSTYLE (1 << eFeatureNumeric_oldstyle)
#define NS_FONT_VARIANT_NUMERIC_PROPORTIONAL (1 << eFeatureNumeric_proportional)
#define NS_FONT_VARIANT_NUMERIC_TABULAR (1 << eFeatureNumeric_tabular)
#define NS_FONT_VARIANT_NUMERIC_DIAGONAL_FRACTIONS (1 << eFeatureNumeric_diagonal_fractions)
#define NS_FONT_VARIANT_NUMERIC_STACKED_FRACTIONS (1 << eFeatureNumeric_stacked_fractions)
#define NS_FONT_VARIANT_NUMERIC_SLASHZERO (1 << eFeatureNumeric_slashedzero)
#define NS_FONT_VARIANT_NUMERIC_ORDINAL (1 << eFeatureNumeric_ordinal)
#define NS_FONT_VARIANT_NUMERIC_FIGURE_MASK \
NS_FONT_VARIANT_NUMERIC_LINING | \
NS_FONT_VARIANT_NUMERIC_OLDSTYLE
#define NS_FONT_VARIANT_NUMERIC_SPACING_MASK \
NS_FONT_VARIANT_NUMERIC_PROPORTIONAL | \
NS_FONT_VARIANT_NUMERIC_TABULAR
#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
#endif