Bug 1891710: part 2) Enable <Element-outerHTML.html> WPT for Trusted Types. r=smaug
[gecko.git] / gfx / src / nsFont.h
blob1557896663342d72c4b61abd93b453e363219643
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/. */
7 #ifndef nsFont_h___
8 #define nsFont_h___
10 #include <cstdint>
11 #include "gfxFontConstants.h" // for NS_FONT_KERNING_AUTO, etc
12 #include "gfxFontVariations.h"
13 #include "mozilla/ServoStyleConsts.h"
14 #include "mozilla/StyleColorInlines.h" // for StyleAbsoluteColor
15 #include "nsTArray.h" // for nsTArray
17 struct gfxFontFeature;
18 struct gfxFontStyle;
20 // Font structure.
21 struct nsFont final {
22 typedef mozilla::FontStretch FontStretch;
23 typedef mozilla::FontSlantStyle FontSlantStyle;
24 typedef mozilla::FontWeight FontWeight;
26 // List of font families, either named or generic.
27 mozilla::StyleFontFamily family;
29 // Font features from CSS font-feature-settings
30 CopyableTArray<gfxFontFeature> fontFeatureSettings;
32 // Font variations from CSS font-variation-settings
33 CopyableTArray<gfxFontVariation> fontVariationSettings;
35 // The logical size of the font, in CSS Pixels
36 mozilla::NonNegativeLength size{0};
38 // The aspect-value (ie., the ratio actualsize:actualxheight) that any
39 // actual physical font created from this font structure must have when
40 // rendering or measuring a string. The value must be nonnegative.
41 mozilla::StyleFontSizeAdjust sizeAdjust =
42 mozilla::StyleFontSizeAdjust::None();
44 // Language system tag, to override document language;
45 // this is an OpenType "language system" tag represented as a 32-bit integer
46 // (see http://www.microsoft.com/typography/otspec/languagetags.htm).
47 uint32_t languageOverride = 0;
49 // Font-selection/rendering properties corresponding to CSS font-style,
50 // font-weight, font-stretch. These are all 16-bit types.
51 FontSlantStyle style = FontSlantStyle::NORMAL;
52 FontWeight weight = FontWeight::NORMAL;
53 FontStretch stretch = FontStretch::NORMAL;
55 // Some font-variant-alternates property values require
56 // font-specific settings defined via @font-feature-values rules.
57 // These are resolved *after* font matching occurs.
58 mozilla::StyleFontVariantAlternates variantAlternates;
60 // Variant subproperties
61 uint16_t variantLigatures = NS_FONT_VARIANT_LIGATURES_NORMAL;
62 uint16_t variantEastAsian = NS_FONT_VARIANT_EAST_ASIAN_NORMAL;
64 uint8_t variantCaps = NS_FONT_VARIANT_CAPS_NORMAL;
65 uint8_t variantNumeric = NS_FONT_VARIANT_NUMERIC_NORMAL;
66 uint8_t variantPosition = NS_FONT_VARIANT_POSITION_NORMAL;
67 uint8_t variantWidth = NS_FONT_VARIANT_WIDTH_NORMAL;
68 StyleFontVariantEmoji variantEmoji = StyleFontVariantEmoji::Normal;
70 // Smoothing - controls subpixel-antialiasing (currently OSX only)
71 uint8_t smoothing = NS_FONT_SMOOTHING_AUTO;
73 // Kerning
74 uint8_t kerning = NS_FONT_KERNING_AUTO;
76 // Whether automatic optical sizing should be applied to variation fonts
77 // that include an 'opsz' axis
78 uint8_t opticalSizing = NS_FONT_OPTICAL_SIZING_AUTO;
80 // Synthesis setting, controls use of fake bolding/italics/small-caps
81 mozilla::StyleFontSynthesis synthesisWeight =
82 mozilla::StyleFontSynthesis::Auto;
83 mozilla::StyleFontSynthesis synthesisStyle =
84 mozilla::StyleFontSynthesis::Auto;
85 mozilla::StyleFontSynthesis synthesisSmallCaps =
86 mozilla::StyleFontSynthesis::Auto;
87 mozilla::StyleFontSynthesis synthesisPosition =
88 mozilla::StyleFontSynthesis::Auto;
90 // initialize the font with a fontlist
91 nsFont(const mozilla::StyleFontFamily&, mozilla::Length aSize);
93 // initialize the font with a single generic
94 nsFont(mozilla::StyleGenericFontFamily, mozilla::Length aSize);
96 // Make a copy of the given font
97 nsFont(const nsFont& aFont);
99 // leave members uninitialized
100 nsFont() = default;
101 ~nsFont();
103 bool operator==(const nsFont& aOther) const { return Equals(aOther); }
105 bool operator!=(const nsFont& aOther) const { return !Equals(aOther); }
107 bool Equals(const nsFont& aOther) const;
109 nsFont& operator=(const nsFont& aOther);
111 enum class MaxDifference : uint8_t { eNone, eVisual, eLayoutAffecting };
113 MaxDifference CalcDifference(const nsFont& aOther) const;
115 // Add featureSettings into style
116 void AddFontFeaturesToStyle(gfxFontStyle* aStyle, bool aVertical) const;
118 void AddFontVariationsToStyle(gfxFontStyle* aStyle) const;
121 #define NS_FONT_VARIANT_NORMAL 0
122 #define NS_FONT_VARIANT_SMALL_CAPS 1
124 #endif /* nsFont_h___ */