michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsFont_h___ michael@0: #define nsFont_h___ michael@0: michael@0: #include // for uint8_t, uint16_t michael@0: #include // for int16_t michael@0: #include "gfxCore.h" // for NS_GFX michael@0: #include "gfxFontFeatures.h" michael@0: #include "nsAutoPtr.h" // for nsRefPtr michael@0: #include "nsCoord.h" // for nscoord michael@0: #include "nsStringFwd.h" // for nsSubstring michael@0: #include "nsString.h" // for nsString michael@0: #include "nsTArray.h" // for nsTArray michael@0: michael@0: struct gfxFontStyle; michael@0: michael@0: // XXX we need a method to enumerate all of the possible fonts on the michael@0: // system across family, weight, style, size, etc. But not here! michael@0: michael@0: // Enumerator callback function. Return false to stop michael@0: typedef bool (*nsFontFamilyEnumFunc)(const nsString& aFamily, bool aGeneric, void *aData); michael@0: michael@0: // IDs for generic fonts michael@0: // NOTE: 0, 1 are reserved for the special IDs of the default variable michael@0: // and fixed fonts in the presentation context, see nsPresContext.h michael@0: const uint8_t kGenericFont_NONE = 0x00; michael@0: // Special michael@0: const uint8_t kGenericFont_moz_variable = 0x00; // for the default variable width font michael@0: const uint8_t kGenericFont_moz_fixed = 0x01; // our special "use the user's fixed font" michael@0: // CSS michael@0: const uint8_t kGenericFont_serif = 0x02; michael@0: const uint8_t kGenericFont_sans_serif = 0x04; michael@0: const uint8_t kGenericFont_monospace = 0x08; michael@0: const uint8_t kGenericFont_cursive = 0x10; michael@0: const uint8_t kGenericFont_fantasy = 0x20; michael@0: michael@0: // Font structure. michael@0: struct NS_GFX nsFont { michael@0: // The family name of the font michael@0: nsString name; michael@0: michael@0: // The style of font (normal, italic, oblique; see gfxFontConstants.h) michael@0: uint8_t style; michael@0: michael@0: // Force this font to not be considered a 'generic' font, even if michael@0: // the name is the same as a CSS generic font family. michael@0: bool systemFont; michael@0: michael@0: // The variant of the font (normal, small-caps) michael@0: uint8_t variant; michael@0: michael@0: // Variant subproperties michael@0: // (currently -moz- versions, will replace variant above eventually) michael@0: uint8_t variantCaps; michael@0: uint8_t variantNumeric; michael@0: uint8_t variantPosition; michael@0: michael@0: uint16_t variantLigatures; michael@0: uint16_t variantEastAsian; michael@0: michael@0: // Some font-variant-alternates property values require michael@0: // font-specific settings defined via @font-feature-values rules. michael@0: // These are resolved *after* font matching occurs. michael@0: michael@0: // -- bitmask for both enumerated and functional propvals michael@0: uint16_t variantAlternates; michael@0: michael@0: // The decorations on the font (underline, overline, michael@0: // line-through). The decorations can be binary or'd together. michael@0: uint8_t decorations; michael@0: michael@0: // Smoothing - controls subpixel-antialiasing (currently OSX only) michael@0: uint8_t smoothing; michael@0: michael@0: // The weight of the font; see gfxFontConstants.h. michael@0: uint16_t weight; michael@0: michael@0: // The stretch of the font (the sum of various NS_FONT_STRETCH_* michael@0: // constants; see gfxFontConstants.h). michael@0: int16_t stretch; michael@0: michael@0: // Kerning michael@0: uint8_t kerning; michael@0: michael@0: // Synthesis setting, controls use of fake bolding/italics michael@0: uint8_t synthesis; michael@0: michael@0: // The logical size of the font, in nscoord units michael@0: nscoord size; michael@0: michael@0: // The aspect-value (ie., the ratio actualsize:actualxheight) that any michael@0: // actual physical font created from this font structure must have when michael@0: // rendering or measuring a string. A value of 0 means no adjustment michael@0: // needs to be done. michael@0: float sizeAdjust; michael@0: michael@0: // -- list of value tags for font-specific alternate features michael@0: nsTArray alternateValues; michael@0: michael@0: // -- object used to look these up once the font is matched michael@0: nsRefPtr featureValueLookup; michael@0: michael@0: // Font features from CSS font-feature-settings michael@0: nsTArray fontFeatureSettings; michael@0: michael@0: // Language system tag, to override document language; michael@0: // this is an OpenType "language system" tag represented as a 32-bit integer michael@0: // (see http://www.microsoft.com/typography/otspec/languagetags.htm). michael@0: nsString languageOverride; michael@0: michael@0: // Initialize the font struct with an ASCII name michael@0: nsFont(const char* aName, uint8_t aStyle, uint8_t aVariant, michael@0: uint16_t aWeight, int16_t aStretch, uint8_t aDecoration, michael@0: nscoord aSize); michael@0: michael@0: // Initialize the font struct with a (potentially) unicode name michael@0: nsFont(const nsSubstring& aName, uint8_t aStyle, uint8_t aVariant, michael@0: uint16_t aWeight, int16_t aStretch, uint8_t aDecoration, michael@0: nscoord aSize); michael@0: michael@0: // Make a copy of the given font michael@0: nsFont(const nsFont& aFont); michael@0: michael@0: nsFont(); michael@0: ~nsFont(); michael@0: michael@0: bool operator==(const nsFont& aOther) const { michael@0: return Equals(aOther); michael@0: } michael@0: michael@0: bool Equals(const nsFont& aOther) const ; michael@0: // Compare ignoring differences in 'variant' and 'decoration' michael@0: bool BaseEquals(const nsFont& aOther) const; michael@0: michael@0: nsFont& operator=(const nsFont& aOther); michael@0: michael@0: void CopyAlternates(const nsFont& aOther); michael@0: michael@0: // Add featureSettings into style michael@0: void AddFontFeaturesToStyle(gfxFontStyle *aStyle) const; michael@0: michael@0: // Utility method to interpret name string michael@0: // enumerates all families specified by this font only michael@0: // returns true if completed, false if stopped michael@0: // enclosing quotes will be removed, and whitespace compressed (as needed) michael@0: bool EnumerateFamilies(nsFontFamilyEnumFunc aFunc, void* aData) const; michael@0: void GetFirstFamily(nsString& aFamily) const; michael@0: michael@0: // Utility method to return the ID of a generic font michael@0: static void GetGenericID(const nsString& aGeneric, uint8_t* aID); michael@0: }; michael@0: michael@0: #define NS_FONT_VARIANT_NORMAL 0 michael@0: #define NS_FONT_VARIANT_SMALL_CAPS 1 michael@0: michael@0: #define NS_FONT_DECORATION_NONE 0x0 michael@0: #define NS_FONT_DECORATION_UNDERLINE 0x1 michael@0: #define NS_FONT_DECORATION_OVERLINE 0x2 michael@0: #define NS_FONT_DECORATION_LINE_THROUGH 0x4 michael@0: michael@0: #endif /* nsFont_h___ */