gfx/src/nsFont.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/src/nsFont.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,165 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsFont_h___
    1.10 +#define nsFont_h___
    1.11 +
    1.12 +#include <stdint.h>                     // for uint8_t, uint16_t
    1.13 +#include <sys/types.h>                  // for int16_t
    1.14 +#include "gfxCore.h"                    // for NS_GFX
    1.15 +#include "gfxFontFeatures.h"
    1.16 +#include "nsAutoPtr.h"                  // for nsRefPtr
    1.17 +#include "nsCoord.h"                    // for nscoord
    1.18 +#include "nsStringFwd.h"                // for nsSubstring
    1.19 +#include "nsString.h"               // for nsString
    1.20 +#include "nsTArray.h"                   // for nsTArray
    1.21 +
    1.22 +struct gfxFontStyle;
    1.23 +
    1.24 +// XXX we need a method to enumerate all of the possible fonts on the
    1.25 +// system across family, weight, style, size, etc. But not here!
    1.26 +
    1.27 +// Enumerator callback function. Return false to stop
    1.28 +typedef bool (*nsFontFamilyEnumFunc)(const nsString& aFamily, bool aGeneric, void *aData);
    1.29 +
    1.30 +// IDs for generic fonts
    1.31 +// NOTE: 0, 1 are reserved for the special IDs of the default variable
    1.32 +// and fixed fonts in the presentation context, see nsPresContext.h
    1.33 +const uint8_t kGenericFont_NONE         = 0x00;
    1.34 +// Special
    1.35 +const uint8_t kGenericFont_moz_variable = 0x00; // for the default variable width font
    1.36 +const uint8_t kGenericFont_moz_fixed    = 0x01; // our special "use the user's fixed font"
    1.37 +// CSS
    1.38 +const uint8_t kGenericFont_serif        = 0x02;
    1.39 +const uint8_t kGenericFont_sans_serif   = 0x04;
    1.40 +const uint8_t kGenericFont_monospace    = 0x08;
    1.41 +const uint8_t kGenericFont_cursive      = 0x10;
    1.42 +const uint8_t kGenericFont_fantasy      = 0x20;
    1.43 +
    1.44 +// Font structure.
    1.45 +struct NS_GFX nsFont {
    1.46 +  // The family name of the font
    1.47 +  nsString name;
    1.48 +
    1.49 +  // The style of font (normal, italic, oblique; see gfxFontConstants.h)
    1.50 +  uint8_t style;
    1.51 +
    1.52 +  // Force this font to not be considered a 'generic' font, even if
    1.53 +  // the name is the same as a CSS generic font family.
    1.54 +  bool systemFont;
    1.55 +
    1.56 +  // The variant of the font (normal, small-caps)
    1.57 +  uint8_t variant;
    1.58 +
    1.59 +  // Variant subproperties
    1.60 +  // (currently -moz- versions, will replace variant above eventually)
    1.61 +  uint8_t variantCaps;
    1.62 +  uint8_t variantNumeric;
    1.63 +  uint8_t variantPosition;
    1.64 +
    1.65 +  uint16_t variantLigatures;
    1.66 +  uint16_t variantEastAsian;
    1.67 +
    1.68 +  // Some font-variant-alternates property values require
    1.69 +  // font-specific settings defined via @font-feature-values rules.
    1.70 +  // These are resolved *after* font matching occurs.
    1.71 +
    1.72 +  // -- bitmask for both enumerated and functional propvals
    1.73 +  uint16_t variantAlternates;
    1.74 +
    1.75 +  // The decorations on the font (underline, overline,
    1.76 +  // line-through). The decorations can be binary or'd together.
    1.77 +  uint8_t decorations;
    1.78 +
    1.79 +  // Smoothing - controls subpixel-antialiasing (currently OSX only)
    1.80 +  uint8_t smoothing;
    1.81 +
    1.82 +  // The weight of the font; see gfxFontConstants.h.
    1.83 +  uint16_t weight;
    1.84 +
    1.85 +  // The stretch of the font (the sum of various NS_FONT_STRETCH_*
    1.86 +  // constants; see gfxFontConstants.h).
    1.87 +  int16_t stretch;
    1.88 +
    1.89 +  // Kerning
    1.90 +  uint8_t kerning;
    1.91 +
    1.92 +  // Synthesis setting, controls use of fake bolding/italics
    1.93 +  uint8_t synthesis;
    1.94 +
    1.95 +  // The logical size of the font, in nscoord units
    1.96 +  nscoord size;
    1.97 +
    1.98 +  // The aspect-value (ie., the ratio actualsize:actualxheight) that any
    1.99 +  // actual physical font created from this font structure must have when
   1.100 +  // rendering or measuring a string. A value of 0 means no adjustment
   1.101 +  // needs to be done.
   1.102 +  float sizeAdjust;
   1.103 +
   1.104 +  // -- list of value tags for font-specific alternate features
   1.105 +  nsTArray<gfxAlternateValue> alternateValues;
   1.106 +
   1.107 +  // -- object used to look these up once the font is matched
   1.108 +  nsRefPtr<gfxFontFeatureValueSet> featureValueLookup;
   1.109 +
   1.110 +  // Font features from CSS font-feature-settings
   1.111 +  nsTArray<gfxFontFeature> fontFeatureSettings;
   1.112 +
   1.113 +  // Language system tag, to override document language;
   1.114 +  // this is an OpenType "language system" tag represented as a 32-bit integer
   1.115 +  // (see http://www.microsoft.com/typography/otspec/languagetags.htm).
   1.116 +  nsString languageOverride;
   1.117 +
   1.118 +  // Initialize the font struct with an ASCII name
   1.119 +  nsFont(const char* aName, uint8_t aStyle, uint8_t aVariant,
   1.120 +         uint16_t aWeight, int16_t aStretch, uint8_t aDecoration,
   1.121 +         nscoord aSize);
   1.122 +
   1.123 +  // Initialize the font struct with a (potentially) unicode name
   1.124 +  nsFont(const nsSubstring& aName, uint8_t aStyle, uint8_t aVariant,
   1.125 +         uint16_t aWeight, int16_t aStretch, uint8_t aDecoration,
   1.126 +         nscoord aSize);
   1.127 +
   1.128 +  // Make a copy of the given font
   1.129 +  nsFont(const nsFont& aFont);
   1.130 +
   1.131 +  nsFont();
   1.132 +  ~nsFont();
   1.133 +
   1.134 +  bool operator==(const nsFont& aOther) const {
   1.135 +    return Equals(aOther);
   1.136 +  }
   1.137 +
   1.138 +  bool Equals(const nsFont& aOther) const ;
   1.139 +  // Compare ignoring differences in 'variant' and 'decoration'
   1.140 +  bool BaseEquals(const nsFont& aOther) const;
   1.141 +
   1.142 +  nsFont& operator=(const nsFont& aOther);
   1.143 +
   1.144 +  void CopyAlternates(const nsFont& aOther);
   1.145 +
   1.146 +  // Add featureSettings into style
   1.147 +  void AddFontFeaturesToStyle(gfxFontStyle *aStyle) const;
   1.148 +
   1.149 +  // Utility method to interpret name string
   1.150 +  // enumerates all families specified by this font only
   1.151 +  // returns true if completed, false if stopped
   1.152 +  // enclosing quotes will be removed, and whitespace compressed (as needed)
   1.153 +  bool EnumerateFamilies(nsFontFamilyEnumFunc aFunc, void* aData) const;
   1.154 +  void GetFirstFamily(nsString& aFamily) const;
   1.155 +
   1.156 +  // Utility method to return the ID of a generic font
   1.157 +  static void GetGenericID(const nsString& aGeneric, uint8_t* aID);
   1.158 +};
   1.159 +
   1.160 +#define NS_FONT_VARIANT_NORMAL            0
   1.161 +#define NS_FONT_VARIANT_SMALL_CAPS        1
   1.162 +
   1.163 +#define NS_FONT_DECORATION_NONE           0x0
   1.164 +#define NS_FONT_DECORATION_UNDERLINE      0x1
   1.165 +#define NS_FONT_DECORATION_OVERLINE       0x2
   1.166 +#define NS_FONT_DECORATION_LINE_THROUGH   0x4
   1.167 +
   1.168 +#endif /* nsFont_h___ */

mercurial