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