Bug 1732219 - Add API for fetching the preview image. r=geckoview-reviewers,agi,mconley
[gecko.git] / gfx / src / nsFont.h
blobf842f8246dc76a480dd3d87dfb32733cc98b5d6f
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/FontPropertyTypes.h"
14 #include "mozilla/ServoStyleConstsInlines.h"
15 #include "mozilla/StyleColorInlines.h" // for StyleRGBA
16 #include "nsTArray.h" // for nsTArray
18 struct gfxFontFeature;
19 struct gfxFontStyle;
21 // Font structure.
22 struct nsFont final {
23 typedef mozilla::FontStretch FontStretch;
24 typedef mozilla::FontSlantStyle FontSlantStyle;
25 typedef mozilla::FontWeight FontWeight;
27 // List of font families, either named or generic.
28 mozilla::StyleFontFamily family;
30 // Font features from CSS font-feature-settings
31 CopyableTArray<gfxFontFeature> fontFeatureSettings;
33 // Font variations from CSS font-variation-settings
34 CopyableTArray<gfxFontVariation> fontVariationSettings;
36 // The logical size of the font, in CSS Pixels
37 mozilla::NonNegativeLength size{0};
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();
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();
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;
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();
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;
66 // Variant subproperties
67 uint16_t variantLigatures = NS_FONT_VARIANT_LIGATURES_NORMAL;
68 uint16_t variantEastAsian = NS_FONT_VARIANT_EAST_ASIAN_NORMAL;
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;
75 // Smoothing - controls subpixel-antialiasing (currently OSX only)
76 uint8_t smoothing = NS_FONT_SMOOTHING_AUTO;
78 // Kerning
79 uint8_t kerning = NS_FONT_KERNING_AUTO;
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;
85 // Synthesis setting, controls use of fake bolding/italics/small-caps
86 uint8_t synthesis = NS_FONT_SYNTHESIS_WEIGHT | NS_FONT_SYNTHESIS_STYLE |
87 NS_FONT_SYNTHESIS_SMALL_CAPS;
89 // initialize the font with a fontlist
90 nsFont(const mozilla::StyleFontFamily&, mozilla::Length aSize);
92 // initialize the font with a single generic
93 nsFont(mozilla::StyleGenericFontFamily, mozilla::Length aSize);
95 // Make a copy of the given font
96 nsFont(const nsFont& aFont);
98 // leave members uninitialized
99 nsFont() = default;
100 ~nsFont();
102 bool operator==(const nsFont& aOther) const { return Equals(aOther); }
104 bool operator!=(const nsFont& aOther) const { return !Equals(aOther); }
106 bool Equals(const nsFont& aOther) const;
108 nsFont& operator=(const nsFont& aOther);
110 enum class MaxDifference : uint8_t { eNone, eVisual, eLayoutAffecting };
112 MaxDifference CalcDifference(const nsFont& aOther) const;
114 // Add featureSettings into style
115 void AddFontFeaturesToStyle(gfxFontStyle* aStyle, bool aVertical) const;
117 void AddFontVariationsToStyle(gfxFontStyle* aStyle) const;
120 #define NS_FONT_VARIANT_NORMAL 0
121 #define NS_FONT_VARIANT_SMALL_CAPS 1
123 #endif /* nsFont_h___ */