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