Skia
2D Graphics Library
SkFontMetrics.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkFontMetrics_DEFINED
9 #define SkFontMetrics_DEFINED
10 
11 #include "include/core/SkScalar.h"
12 #include "include/private/base/SkTo.h"
13 
18 struct SK_API SkFontMetrics {
19  bool operator==(const SkFontMetrics& that) {
20  return
21  this->fFlags == that.fFlags &&
22  this->fTop == that.fTop &&
23  this->fAscent == that.fAscent &&
24  this->fDescent == that.fDescent &&
25  this->fBottom == that.fBottom &&
26  this->fLeading == that.fLeading &&
27  this->fAvgCharWidth == that.fAvgCharWidth &&
28  this->fMaxCharWidth == that.fMaxCharWidth &&
29  this->fXMin == that.fXMin &&
30  this->fXMax == that.fXMax &&
31  this->fXHeight == that.fXHeight &&
32  this->fCapHeight == that.fCapHeight &&
33  this->fUnderlineThickness == that.fUnderlineThickness &&
34  this->fUnderlinePosition == that.fUnderlinePosition &&
35  this->fStrikeoutThickness == that.fStrikeoutThickness &&
36  this->fStrikeoutPosition == that.fStrikeoutPosition;
37  }
38 
45  kUnderlineThicknessIsValid_Flag = 1 << 0,
46  kUnderlinePositionIsValid_Flag = 1 << 1,
47  kStrikeoutThicknessIsValid_Flag = 1 << 2,
48  kStrikeoutPositionIsValid_Flag = 1 << 3,
49  kBoundsInvalid_Flag = 1 << 4,
50  };
51 
52  uint32_t fFlags;
68 
76  bool hasUnderlineThickness(SkScalar* thickness) const {
77  if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) {
78  *thickness = fUnderlineThickness;
79  return true;
80  }
81  return false;
82  }
83 
91  bool hasUnderlinePosition(SkScalar* position) const {
92  if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
93  *position = fUnderlinePosition;
94  return true;
95  }
96  return false;
97  }
98 
106  bool hasStrikeoutThickness(SkScalar* thickness) const {
107  if (SkToBool(fFlags & kStrikeoutThicknessIsValid_Flag)) {
108  *thickness = fStrikeoutThickness;
109  return true;
110  }
111  return false;
112  }
113 
121  bool hasStrikeoutPosition(SkScalar* position) const {
122  if (SkToBool(fFlags & kStrikeoutPositionIsValid_Flag)) {
123  *position = fStrikeoutPosition;
124  return true;
125  }
126  return false;
127  }
128 
134  bool hasBounds() const {
135  return !SkToBool(fFlags & kBoundsInvalid_Flag);
136  }
137 };
138 
139 #endif
float SkScalar
Definition: SkScalar.h:14
The metrics of an SkFont.
Definition: SkFontMetrics.h:18
SkScalar fTop
greatest extent above origin of any glyph bounding box, typically negative; deprecated with variable ...
Definition: SkFontMetrics.h:53
SkScalar fLeading
distance to add between lines, typically positive or zero
Definition: SkFontMetrics.h:57
SkScalar fAvgCharWidth
average character width, zero if unknown
Definition: SkFontMetrics.h:58
bool hasBounds() const
Returns true if SkFontMetrics has a valid fTop, fBottom, fXMin, and fXMax.
Definition: SkFontMetrics.h:134
SkScalar fStrikeoutPosition
distance from baseline to bottom of stroke, typically negative
Definition: SkFontMetrics.h:67
SkScalar fStrikeoutThickness
strikeout thickness
Definition: SkFontMetrics.h:66
SkScalar fMaxCharWidth
maximum character width, zero if unknown
Definition: SkFontMetrics.h:59
bool operator==(const SkFontMetrics &that)
Definition: SkFontMetrics.h:19
SkScalar fBottom
greatest extent below origin of any glyph bounding box, typically positive; deprecated with variable ...
Definition: SkFontMetrics.h:56
bool hasUnderlinePosition(SkScalar *position) const
Returns true if SkFontMetrics has a valid underline position, and sets position to that value.
Definition: SkFontMetrics.h:91
uint32_t fFlags
FontMetricsFlags indicating which metrics are valid.
Definition: SkFontMetrics.h:52
SkScalar fAscent
distance to reserve above baseline, typically negative
Definition: SkFontMetrics.h:54
bool hasUnderlineThickness(SkScalar *thickness) const
Returns true if SkFontMetrics has a valid underline thickness, and sets thickness to that value.
Definition: SkFontMetrics.h:76
SkScalar fXHeight
height of lower-case 'x', zero if unknown, typically negative
Definition: SkFontMetrics.h:62
bool hasStrikeoutPosition(SkScalar *position) const
Returns true if SkFontMetrics has a valid strikeout position, and sets position to that value.
Definition: SkFontMetrics.h:121
SkScalar fUnderlineThickness
underline thickness
Definition: SkFontMetrics.h:64
FontMetricsFlags
FontMetricsFlags indicate when certain metrics are valid; the underline or strikeout metrics may be v...
Definition: SkFontMetrics.h:44
SkScalar fDescent
distance to reserve below baseline, typically positive
Definition: SkFontMetrics.h:55
SkScalar fCapHeight
height of an upper-case letter, zero if unknown, typically negative
Definition: SkFontMetrics.h:63
bool hasStrikeoutThickness(SkScalar *thickness) const
Returns true if SkFontMetrics has a valid strikeout thickness, and sets thickness to that value.
Definition: SkFontMetrics.h:106
SkScalar fXMin
greatest extent to left of origin of any glyph bounding box, typically negative; deprecated with vari...
Definition: SkFontMetrics.h:60
SkScalar fUnderlinePosition
distance from baseline to top of stroke, typically positive
Definition: SkFontMetrics.h:65
SkScalar fXMax
greatest extent to right of origin of any glyph bounding box, typically positive; deprecated with var...
Definition: SkFontMetrics.h:61