Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/nsFont.h
Line
Count
Source (jump to first uncovered line)
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 "nsColor.h"                    // for nsColor and NS_RGBA
19
#include "nsCoord.h"                    // for nscoord
20
#include "nsTArray.h"                   // for nsTArray
21
22
struct gfxFontStyle;
23
24
// IDs for generic fonts
25
// NOTE: 0, 1 are reserved for the special IDs of the default variable
26
// and fixed fonts in the presentation context, see nsPresContext.h
27
const uint8_t kGenericFont_NONE         = 0x00;
28
// Special
29
const uint8_t kGenericFont_moz_variable = 0x00; // for the default variable width font
30
const uint8_t kGenericFont_moz_fixed    = 0x01; // our special "use the user's fixed font"
31
// CSS
32
const uint8_t kGenericFont_serif        = 0x02;
33
const uint8_t kGenericFont_sans_serif   = 0x04;
34
const uint8_t kGenericFont_monospace    = 0x08;
35
const uint8_t kGenericFont_cursive      = 0x10;
36
const uint8_t kGenericFont_fantasy      = 0x20;
37
38
// Font structure.
39
struct nsFont {
40
  typedef mozilla::FontStretch FontStretch;
41
  typedef mozilla::FontSlantStyle FontSlantStyle;
42
  typedef mozilla::FontWeight FontWeight;
43
44
  // List of font families, either named or generic.
45
  // This contains a RefPtr and a uint32_t field.
46
  mozilla::FontFamilyList fontlist;
47
48
  // Font features from CSS font-feature-settings
49
  nsTArray<gfxFontFeature> fontFeatureSettings;
50
51
  // Font variations from CSS font-variation-settings
52
  nsTArray<gfxFontVariation> fontVariationSettings;
53
54
  // -- list of value tags for font-specific alternate features
55
  nsTArray<gfxAlternateValue> alternateValues;
56
57
  // -- object used to look these up once the font is matched
58
  RefPtr<gfxFontFeatureValueSet> featureValueLookup;
59
60
  // The logical size of the font, in nscoord units
61
  nscoord size = 0;
62
63
  // The aspect-value (ie., the ratio actualsize:actualxheight) that any
64
  // actual physical font created from this font structure must have when
65
  // rendering or measuring a string. A value of -1.0 means no adjustment
66
  // needs to be done; otherwise the value must be nonnegative.
67
  float sizeAdjust = -1.0f;
68
69
  // The estimated background color behind the text. Enables a special
70
  // rendering mode when NS_GET_A(.) > 0. Only used for text in the chrome.
71
  nscolor fontSmoothingBackgroundColor = NS_RGBA(0,0,0,0);
72
73
  // Language system tag, to override document language;
74
  // this is an OpenType "language system" tag represented as a 32-bit integer
75
  // (see http://www.microsoft.com/typography/otspec/languagetags.htm).
76
  uint32_t languageOverride = 0;
77
78
  // Font-selection/rendering properties corresponding to CSS font-style,
79
  // font-weight, font-stretch. These are all 16-bit types.
80
  FontSlantStyle style = FontSlantStyle::Normal();
81
  FontWeight weight = FontWeight::Normal();
82
  FontStretch stretch = FontStretch::Normal();
83
84
  // Some font-variant-alternates property values require
85
  // font-specific settings defined via @font-feature-values rules.
86
  // These are resolved *after* font matching occurs.
87
88
  // -- bitmask for both enumerated and functional propvals
89
  uint16_t variantAlternates = NS_FONT_VARIANT_ALTERNATES_NORMAL;
90
91
  // Variant subproperties
92
  uint16_t variantLigatures = NS_FONT_VARIANT_LIGATURES_NORMAL;
93
  uint16_t variantEastAsian = NS_FONT_VARIANT_EAST_ASIAN_NORMAL;
94
95
  uint8_t variantCaps = NS_FONT_VARIANT_CAPS_NORMAL;
96
  uint8_t variantNumeric = NS_FONT_VARIANT_NUMERIC_NORMAL;
97
  uint8_t variantPosition = NS_FONT_VARIANT_POSITION_NORMAL;
98
  uint8_t variantWidth = NS_FONT_VARIANT_WIDTH_NORMAL;
99
100
  // Smoothing - controls subpixel-antialiasing (currently OSX only)
101
  uint8_t smoothing = NS_FONT_SMOOTHING_AUTO;
102
103
  // Kerning
104
  uint8_t kerning = NS_FONT_KERNING_AUTO;
105
106
  // Whether automatic optical sizing should be applied to variation fonts
107
  // that include an 'opsz' axis
108
  uint8_t opticalSizing = NS_FONT_OPTICAL_SIZING_AUTO;
109
110
  // Synthesis setting, controls use of fake bolding/italics
111
  uint8_t synthesis = NS_FONT_SYNTHESIS_WEIGHT | NS_FONT_SYNTHESIS_STYLE;
112
113
  // Force this font to not be considered a 'generic' font, even if
114
  // the name is the same as a CSS generic font family.
115
  bool systemFont = false;
116
117
  // initialize the font with a fontlist
118
  nsFont(const mozilla::FontFamilyList& aFontlist, nscoord aSize);
119
120
  // initialize the font with a single generic
121
  nsFont(mozilla::FontFamilyType aGenericType, nscoord aSize);
122
123
  // Make a copy of the given font
124
  nsFont(const nsFont& aFont);
125
126
  // leave members uninitialized
127
  nsFont();
128
129
  ~nsFont();
130
131
0
  bool operator==(const nsFont& aOther) const {
132
0
    return Equals(aOther);
133
0
  }
134
135
0
  bool operator!=(const nsFont& aOther) const {
136
0
    return !Equals(aOther);
137
0
  }
138
139
  bool Equals(const nsFont& aOther) const;
140
141
  nsFont& operator=(const nsFont& aOther);
142
143
  enum class MaxDifference : uint8_t {
144
    eNone,
145
    eVisual,
146
    eLayoutAffecting
147
  };
148
149
  MaxDifference CalcDifference(const nsFont& aOther) const;
150
151
  void CopyAlternates(const nsFont& aOther);
152
153
  // Add featureSettings into style
154
  void AddFontFeaturesToStyle(gfxFontStyle *aStyle,
155
                              bool aVertical) const;
156
157
  void AddFontVariationsToStyle(gfxFontStyle *aStyle) const;
158
};
159
160
#define NS_FONT_VARIANT_NORMAL            0
161
#define NS_FONT_VARIANT_SMALL_CAPS        1
162
163
#endif /* nsFont_h___ */