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