1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 #include <stdint.h> // for uint8_t, uint16_t
11 #include <sys/types.h> // for int16_t
12 #include "gfxFontFamilyList.h"
13 #include "gfxFontConstants.h" // for NS_FONT_KERNING_AUTO, etc
14 #include "gfxFontFeatures.h"
15 #include "gfxFontVariations.h"
16 #include "mozilla/FontPropertyTypes.h"
17 #include "mozilla/RefPtr.h" // for RefPtr
18 #include "nsColor.h" // for nsColor and NS_RGBA
19 #include "nsCoord.h" // for nscoord
20 #include "nsTArray.h" // for nsTArray
24 // IDs for generic fonts
25 // NOTE: 0, 1 are reserved for the special IDs of the default variable
26 // and fixed fonts in the presentation context, see nsPresContext.h
27 const uint8_t kGenericFont_NONE
= 0x00;
29 const uint8_t kGenericFont_moz_variable
=
30 0x00; // for the default variable width font
31 const uint8_t kGenericFont_moz_fixed
=
32 0x01; // our special "use the user's fixed font"
34 const uint8_t kGenericFont_serif
= 0x02;
35 const uint8_t kGenericFont_sans_serif
= 0x04;
36 const uint8_t kGenericFont_monospace
= 0x08;
37 const uint8_t kGenericFont_cursive
= 0x10;
38 const uint8_t kGenericFont_fantasy
= 0x20;
42 typedef mozilla::FontStretch FontStretch
;
43 typedef mozilla::FontSlantStyle FontSlantStyle
;
44 typedef mozilla::FontWeight FontWeight
;
46 // List of font families, either named or generic.
47 // This contains a RefPtr and a uint32_t field.
48 mozilla::FontFamilyList fontlist
;
50 // Font features from CSS font-feature-settings
51 nsTArray
<gfxFontFeature
> fontFeatureSettings
;
53 // Font variations from CSS font-variation-settings
54 nsTArray
<gfxFontVariation
> fontVariationSettings
;
56 // -- list of value tags for font-specific alternate features
57 nsTArray
<gfxAlternateValue
> alternateValues
;
59 // The logical size of the font, in nscoord units
62 // The aspect-value (ie., the ratio actualsize:actualxheight) that any
63 // actual physical font created from this font structure must have when
64 // rendering or measuring a string. A value of -1.0 means no adjustment
65 // needs to be done; otherwise the value must be nonnegative.
66 float sizeAdjust
= -1.0f
;
68 // The estimated background color behind the text. Enables a special
69 // rendering mode when NS_GET_A(.) > 0. Only used for text in the chrome.
70 nscolor fontSmoothingBackgroundColor
= NS_RGBA(0, 0, 0, 0);
72 // Language system tag, to override document language;
73 // this is an OpenType "language system" tag represented as a 32-bit integer
74 // (see http://www.microsoft.com/typography/otspec/languagetags.htm).
75 uint32_t languageOverride
= 0;
77 // Font-selection/rendering properties corresponding to CSS font-style,
78 // font-weight, font-stretch. These are all 16-bit types.
79 FontSlantStyle style
= FontSlantStyle::Normal();
80 FontWeight weight
= FontWeight::Normal();
81 FontStretch stretch
= FontStretch::Normal();
83 // Some font-variant-alternates property values require
84 // font-specific settings defined via @font-feature-values rules.
85 // These are resolved *after* font matching occurs.
87 // -- bitmask for both enumerated and functional propvals
88 uint16_t variantAlternates
= NS_FONT_VARIANT_ALTERNATES_NORMAL
;
90 // Variant subproperties
91 uint16_t variantLigatures
= NS_FONT_VARIANT_LIGATURES_NORMAL
;
92 uint16_t variantEastAsian
= NS_FONT_VARIANT_EAST_ASIAN_NORMAL
;
94 uint8_t variantCaps
= NS_FONT_VARIANT_CAPS_NORMAL
;
95 uint8_t variantNumeric
= NS_FONT_VARIANT_NUMERIC_NORMAL
;
96 uint8_t variantPosition
= NS_FONT_VARIANT_POSITION_NORMAL
;
97 uint8_t variantWidth
= NS_FONT_VARIANT_WIDTH_NORMAL
;
99 // Smoothing - controls subpixel-antialiasing (currently OSX only)
100 uint8_t smoothing
= NS_FONT_SMOOTHING_AUTO
;
103 uint8_t kerning
= NS_FONT_KERNING_AUTO
;
105 // Whether automatic optical sizing should be applied to variation fonts
106 // that include an 'opsz' axis
107 uint8_t opticalSizing
= NS_FONT_OPTICAL_SIZING_AUTO
;
109 // Synthesis setting, controls use of fake bolding/italics
110 uint8_t synthesis
= NS_FONT_SYNTHESIS_WEIGHT
| NS_FONT_SYNTHESIS_STYLE
;
112 // Force this font to not be considered a 'generic' font, even if
113 // the name is the same as a CSS generic font family.
114 bool systemFont
= false;
116 // initialize the font with a fontlist
117 nsFont(const mozilla::FontFamilyList
& aFontlist
, nscoord aSize
);
119 // initialize the font with a single generic
120 nsFont(mozilla::FontFamilyType aGenericType
, nscoord aSize
);
122 // Make a copy of the given font
123 nsFont(const nsFont
& aFont
);
125 // leave members uninitialized
130 bool operator==(const nsFont
& aOther
) const { return Equals(aOther
); }
132 bool operator!=(const nsFont
& aOther
) const { return !Equals(aOther
); }
134 bool Equals(const nsFont
& aOther
) const;
136 nsFont
& operator=(const nsFont
& aOther
);
138 enum class MaxDifference
: uint8_t { eNone
, eVisual
, eLayoutAffecting
};
140 MaxDifference
CalcDifference(const nsFont
& aOther
) const;
142 void CopyAlternates(const nsFont
& aOther
);
144 // Add featureSettings into style
145 void AddFontFeaturesToStyle(gfxFontStyle
* aStyle
, bool aVertical
) const;
147 void AddFontVariationsToStyle(gfxFontStyle
* aStyle
) const;
150 #define NS_FONT_VARIANT_NORMAL 0
151 #define NS_FONT_VARIANT_SMALL_CAPS 1
153 #endif /* nsFont_h___ */