gfx/src/nsFont.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsFont_h___
michael@0 7 #define nsFont_h___
michael@0 8
michael@0 9 #include <stdint.h> // for uint8_t, uint16_t
michael@0 10 #include <sys/types.h> // for int16_t
michael@0 11 #include "gfxCore.h" // for NS_GFX
michael@0 12 #include "gfxFontFeatures.h"
michael@0 13 #include "nsAutoPtr.h" // for nsRefPtr
michael@0 14 #include "nsCoord.h" // for nscoord
michael@0 15 #include "nsStringFwd.h" // for nsSubstring
michael@0 16 #include "nsString.h" // for nsString
michael@0 17 #include "nsTArray.h" // for nsTArray
michael@0 18
michael@0 19 struct gfxFontStyle;
michael@0 20
michael@0 21 // XXX we need a method to enumerate all of the possible fonts on the
michael@0 22 // system across family, weight, style, size, etc. But not here!
michael@0 23
michael@0 24 // Enumerator callback function. Return false to stop
michael@0 25 typedef bool (*nsFontFamilyEnumFunc)(const nsString& aFamily, bool aGeneric, void *aData);
michael@0 26
michael@0 27 // IDs for generic fonts
michael@0 28 // NOTE: 0, 1 are reserved for the special IDs of the default variable
michael@0 29 // and fixed fonts in the presentation context, see nsPresContext.h
michael@0 30 const uint8_t kGenericFont_NONE = 0x00;
michael@0 31 // Special
michael@0 32 const uint8_t kGenericFont_moz_variable = 0x00; // for the default variable width font
michael@0 33 const uint8_t kGenericFont_moz_fixed = 0x01; // our special "use the user's fixed font"
michael@0 34 // CSS
michael@0 35 const uint8_t kGenericFont_serif = 0x02;
michael@0 36 const uint8_t kGenericFont_sans_serif = 0x04;
michael@0 37 const uint8_t kGenericFont_monospace = 0x08;
michael@0 38 const uint8_t kGenericFont_cursive = 0x10;
michael@0 39 const uint8_t kGenericFont_fantasy = 0x20;
michael@0 40
michael@0 41 // Font structure.
michael@0 42 struct NS_GFX nsFont {
michael@0 43 // The family name of the font
michael@0 44 nsString name;
michael@0 45
michael@0 46 // The style of font (normal, italic, oblique; see gfxFontConstants.h)
michael@0 47 uint8_t style;
michael@0 48
michael@0 49 // Force this font to not be considered a 'generic' font, even if
michael@0 50 // the name is the same as a CSS generic font family.
michael@0 51 bool systemFont;
michael@0 52
michael@0 53 // The variant of the font (normal, small-caps)
michael@0 54 uint8_t variant;
michael@0 55
michael@0 56 // Variant subproperties
michael@0 57 // (currently -moz- versions, will replace variant above eventually)
michael@0 58 uint8_t variantCaps;
michael@0 59 uint8_t variantNumeric;
michael@0 60 uint8_t variantPosition;
michael@0 61
michael@0 62 uint16_t variantLigatures;
michael@0 63 uint16_t variantEastAsian;
michael@0 64
michael@0 65 // Some font-variant-alternates property values require
michael@0 66 // font-specific settings defined via @font-feature-values rules.
michael@0 67 // These are resolved *after* font matching occurs.
michael@0 68
michael@0 69 // -- bitmask for both enumerated and functional propvals
michael@0 70 uint16_t variantAlternates;
michael@0 71
michael@0 72 // The decorations on the font (underline, overline,
michael@0 73 // line-through). The decorations can be binary or'd together.
michael@0 74 uint8_t decorations;
michael@0 75
michael@0 76 // Smoothing - controls subpixel-antialiasing (currently OSX only)
michael@0 77 uint8_t smoothing;
michael@0 78
michael@0 79 // The weight of the font; see gfxFontConstants.h.
michael@0 80 uint16_t weight;
michael@0 81
michael@0 82 // The stretch of the font (the sum of various NS_FONT_STRETCH_*
michael@0 83 // constants; see gfxFontConstants.h).
michael@0 84 int16_t stretch;
michael@0 85
michael@0 86 // Kerning
michael@0 87 uint8_t kerning;
michael@0 88
michael@0 89 // Synthesis setting, controls use of fake bolding/italics
michael@0 90 uint8_t synthesis;
michael@0 91
michael@0 92 // The logical size of the font, in nscoord units
michael@0 93 nscoord size;
michael@0 94
michael@0 95 // The aspect-value (ie., the ratio actualsize:actualxheight) that any
michael@0 96 // actual physical font created from this font structure must have when
michael@0 97 // rendering or measuring a string. A value of 0 means no adjustment
michael@0 98 // needs to be done.
michael@0 99 float sizeAdjust;
michael@0 100
michael@0 101 // -- list of value tags for font-specific alternate features
michael@0 102 nsTArray<gfxAlternateValue> alternateValues;
michael@0 103
michael@0 104 // -- object used to look these up once the font is matched
michael@0 105 nsRefPtr<gfxFontFeatureValueSet> featureValueLookup;
michael@0 106
michael@0 107 // Font features from CSS font-feature-settings
michael@0 108 nsTArray<gfxFontFeature> fontFeatureSettings;
michael@0 109
michael@0 110 // Language system tag, to override document language;
michael@0 111 // this is an OpenType "language system" tag represented as a 32-bit integer
michael@0 112 // (see http://www.microsoft.com/typography/otspec/languagetags.htm).
michael@0 113 nsString languageOverride;
michael@0 114
michael@0 115 // Initialize the font struct with an ASCII name
michael@0 116 nsFont(const char* aName, uint8_t aStyle, uint8_t aVariant,
michael@0 117 uint16_t aWeight, int16_t aStretch, uint8_t aDecoration,
michael@0 118 nscoord aSize);
michael@0 119
michael@0 120 // Initialize the font struct with a (potentially) unicode name
michael@0 121 nsFont(const nsSubstring& aName, uint8_t aStyle, uint8_t aVariant,
michael@0 122 uint16_t aWeight, int16_t aStretch, uint8_t aDecoration,
michael@0 123 nscoord aSize);
michael@0 124
michael@0 125 // Make a copy of the given font
michael@0 126 nsFont(const nsFont& aFont);
michael@0 127
michael@0 128 nsFont();
michael@0 129 ~nsFont();
michael@0 130
michael@0 131 bool operator==(const nsFont& aOther) const {
michael@0 132 return Equals(aOther);
michael@0 133 }
michael@0 134
michael@0 135 bool Equals(const nsFont& aOther) const ;
michael@0 136 // Compare ignoring differences in 'variant' and 'decoration'
michael@0 137 bool BaseEquals(const nsFont& aOther) const;
michael@0 138
michael@0 139 nsFont& operator=(const nsFont& aOther);
michael@0 140
michael@0 141 void CopyAlternates(const nsFont& aOther);
michael@0 142
michael@0 143 // Add featureSettings into style
michael@0 144 void AddFontFeaturesToStyle(gfxFontStyle *aStyle) const;
michael@0 145
michael@0 146 // Utility method to interpret name string
michael@0 147 // enumerates all families specified by this font only
michael@0 148 // returns true if completed, false if stopped
michael@0 149 // enclosing quotes will be removed, and whitespace compressed (as needed)
michael@0 150 bool EnumerateFamilies(nsFontFamilyEnumFunc aFunc, void* aData) const;
michael@0 151 void GetFirstFamily(nsString& aFamily) const;
michael@0 152
michael@0 153 // Utility method to return the ID of a generic font
michael@0 154 static void GetGenericID(const nsString& aGeneric, uint8_t* aID);
michael@0 155 };
michael@0 156
michael@0 157 #define NS_FONT_VARIANT_NORMAL 0
michael@0 158 #define NS_FONT_VARIANT_SMALL_CAPS 1
michael@0 159
michael@0 160 #define NS_FONT_DECORATION_NONE 0x0
michael@0 161 #define NS_FONT_DECORATION_UNDERLINE 0x1
michael@0 162 #define NS_FONT_DECORATION_OVERLINE 0x2
michael@0 163 #define NS_FONT_DECORATION_LINE_THROUGH 0x4
michael@0 164
michael@0 165 #endif /* nsFont_h___ */

mercurial