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/. */
6 
7 #ifndef nsFont_h___
8 #define nsFont_h___
9 
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 "mozilla/StyleColorInlines.h"  // for StyleRGBA
19 #include "nsCoord.h"                    // for nscoord
20 #include "nsTArray.h"                   // for nsTArray
21 
22 struct gfxFontStyle;
23 
24 // Font structure.
25 struct nsFont final {
26   typedef mozilla::FontStretch FontStretch;
27   typedef mozilla::FontSlantStyle FontSlantStyle;
28   typedef mozilla::FontWeight FontWeight;
29 
30   // List of font families, either named or generic.
31   // This contains a RefPtr and a uint32_t field.
32   mozilla::FontFamilyList fontlist;
33 
34   // Font features from CSS font-feature-settings
35   CopyableTArray<gfxFontFeature> fontFeatureSettings;
36 
37   // Font variations from CSS font-variation-settings
38   CopyableTArray<gfxFontVariation> fontVariationSettings;
39 
40   // The logical size of the font, in nscoord units
41   nscoord size = 0;
42 
43   // The aspect-value (ie., the ratio actualsize:actualxheight) that any
44   // actual physical font created from this font structure must have when
45   // rendering or measuring a string. A value of -1.0 means no adjustment
46   // needs to be done; otherwise the value must be nonnegative.
47   float sizeAdjust = -1.0f;
48 
49   // The estimated background color behind the text. Enables a special
50   // rendering mode when NS_GET_A(.) > 0. Only used for text in the chrome.
51   mozilla::StyleRGBA fontSmoothingBackgroundColor =
52       mozilla::StyleRGBA::Transparent();
53 
54   // Language system tag, to override document language;
55   // this is an OpenType "language system" tag represented as a 32-bit integer
56   // (see http://www.microsoft.com/typography/otspec/languagetags.htm).
57   uint32_t languageOverride = 0;
58 
59   // Font-selection/rendering properties corresponding to CSS font-style,
60   // font-weight, font-stretch. These are all 16-bit types.
61   FontSlantStyle style = FontSlantStyle::Normal();
62   FontWeight weight = FontWeight::Normal();
63   FontStretch stretch = FontStretch::Normal();
64 
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.
68   mozilla::StyleVariantAlternatesList variantAlternates;
69 
70   // Variant subproperties
71   uint16_t variantLigatures = NS_FONT_VARIANT_LIGATURES_NORMAL;
72   uint16_t variantEastAsian = NS_FONT_VARIANT_EAST_ASIAN_NORMAL;
73 
74   uint8_t variantCaps = NS_FONT_VARIANT_CAPS_NORMAL;
75   uint8_t variantNumeric = NS_FONT_VARIANT_NUMERIC_NORMAL;
76   uint8_t variantPosition = NS_FONT_VARIANT_POSITION_NORMAL;
77   uint8_t variantWidth = NS_FONT_VARIANT_WIDTH_NORMAL;
78 
79   // Smoothing - controls subpixel-antialiasing (currently OSX only)
80   uint8_t smoothing = NS_FONT_SMOOTHING_AUTO;
81 
82   // Kerning
83   uint8_t kerning = NS_FONT_KERNING_AUTO;
84 
85   // Whether automatic optical sizing should be applied to variation fonts
86   // that include an 'opsz' axis
87   uint8_t opticalSizing = NS_FONT_OPTICAL_SIZING_AUTO;
88 
89   // Synthesis setting, controls use of fake bolding/italics
90   uint8_t synthesis = NS_FONT_SYNTHESIS_WEIGHT | NS_FONT_SYNTHESIS_STYLE;
91 
92   // Force this font to not be considered a 'generic' font, even if
93   // the name is the same as a CSS generic font family.
94   bool systemFont = false;
95 
96   // initialize the font with a fontlist
97   nsFont(const mozilla::FontFamilyList& aFontlist, nscoord aSize);
98 
99   // initialize the font with a single generic
100   nsFont(mozilla::StyleGenericFontFamily, nscoord aSize);
101 
102   // Make a copy of the given font
103   nsFont(const nsFont& aFont);
104 
105   // leave members uninitialized
106   nsFont() = default;
107   ~nsFont();
108 
109   bool operator==(const nsFont& aOther) const { return Equals(aOther); }
110 
111   bool operator!=(const nsFont& aOther) const { return !Equals(aOther); }
112 
113   bool Equals(const nsFont& aOther) const;
114 
115   nsFont& operator=(const nsFont& aOther);
116 
117   enum class MaxDifference : uint8_t { eNone, eVisual, eLayoutAffecting };
118 
119   MaxDifference CalcDifference(const nsFont& aOther) const;
120 
121   // Add featureSettings into style
122   void AddFontFeaturesToStyle(gfxFontStyle* aStyle, bool aVertical) const;
123 
124   void AddFontVariationsToStyle(gfxFontStyle* aStyle) const;
125 };
126 
127 #define NS_FONT_VARIANT_NORMAL 0
128 #define NS_FONT_VARIANT_SMALL_CAPS 1
129 
130 #endif /* nsFont_h___ */
131