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 
18  bool operator==(const SkFontMetrics& that) {
19  return
20  this->fFlags == that.fFlags &&
21  this->fTop == that.fTop &&
22  this->fAscent == that.fAscent &&
23  this->fDescent == that.fDescent &&
24  this->fBottom == that.fBottom &&
25  this->fLeading == that.fLeading &&
26  this->fAvgCharWidth == that.fAvgCharWidth &&
27  this->fMaxCharWidth == that.fMaxCharWidth &&
28  this->fXMin == that.fXMin &&
29  this->fXMax == that.fXMax &&
30  this->fXHeight == that.fXHeight &&
31  this->fCapHeight == that.fCapHeight &&
32  this->fUnderlineThickness == that.fUnderlineThickness &&
33  this->fUnderlinePosition == that.fUnderlinePosition &&
34  this->fStrikeoutThickness == that.fStrikeoutThickness &&
35  this->fStrikeoutPosition == that.fStrikeoutPosition;
36  }
37 
44  kUnderlineThicknessIsValid_Flag = 1 << 0,
45  kUnderlinePositionIsValid_Flag = 1 << 1,
46  kStrikeoutThicknessIsValid_Flag = 1 << 2,
47  kStrikeoutPositionIsValid_Flag = 1 << 3,
48  kBoundsInvalid_Flag = 1 << 4,
49  };
50 
51  uint32_t fFlags;
67 
75  bool hasUnderlineThickness(SkScalar* thickness) const {
76  if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) {
77  *thickness = fUnderlineThickness;
78  return true;
79  }
80  return false;
81  }
82 
90  bool hasUnderlinePosition(SkScalar* position) const {
91  if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
92  *position = fUnderlinePosition;
93  return true;
94  }
95  return false;
96  }
97 
105  bool hasStrikeoutThickness(SkScalar* thickness) const {
106  if (SkToBool(fFlags & kStrikeoutThicknessIsValid_Flag)) {
107  *thickness = fStrikeoutThickness;
108  return true;
109  }
110  return false;
111  }
112 
120  bool hasStrikeoutPosition(SkScalar* position) const {
121  if (SkToBool(fFlags & kStrikeoutPositionIsValid_Flag)) {
122  *position = fStrikeoutPosition;
123  return true;
124  }
125  return false;
126  }
127 
133  bool hasBounds() const {
134  return !SkToBool(fFlags & kBoundsInvalid_Flag);
135  }
136 };
137 
138 #endif
SkFontMetrics::fAscent
SkScalar fAscent
distance to reserve above baseline, typically negative
Definition: SkFontMetrics.h:53
SkFontMetrics::fXHeight
SkScalar fXHeight
height of lower-case 'x', zero if unknown, typically negative
Definition: SkFontMetrics.h:61
SkFontMetrics::fTop
SkScalar fTop
greatest extent above origin of any glyph bounding box, typically negative; deprecated with variable ...
Definition: SkFontMetrics.h:52
SkFontMetrics::fXMin
SkScalar fXMin
greatest extent to left of origin of any glyph bounding box, typically negative; deprecated with vari...
Definition: SkFontMetrics.h:59
SkFontMetrics::fUnderlineThickness
SkScalar fUnderlineThickness
underline thickness
Definition: SkFontMetrics.h:63
SkFontMetrics::fStrikeoutPosition
SkScalar fStrikeoutPosition
distance from baseline to bottom of stroke, typically negative
Definition: SkFontMetrics.h:66
SkFontMetrics::hasStrikeoutPosition
bool hasStrikeoutPosition(SkScalar *position) const
Returns true if SkFontMetrics has a valid strikeout position, and sets position to that value.
Definition: SkFontMetrics.h:120
SkFontMetrics::fLeading
SkScalar fLeading
distance to add between lines, typically positive or zero
Definition: SkFontMetrics.h:56
SkFontMetrics::fFlags
uint32_t fFlags
FontMetricsFlags indicating which metrics are valid.
Definition: SkFontMetrics.h:51
SkFontMetrics::fDescent
SkScalar fDescent
distance to reserve below baseline, typically positive
Definition: SkFontMetrics.h:54
SkScalar.h
SkFontMetrics
Definition: SkFontMetrics.h:17
SkToBool
static constexpr bool SkToBool(const T &x)
Definition: SkTypes.h:497
SK_API
#define SK_API
Definition: SkTypes.h:181
SkFontMetrics::fStrikeoutThickness
SkScalar fStrikeoutThickness
strikeout thickness
Definition: SkFontMetrics.h:65
SkFontMetrics::hasBounds
bool hasBounds() const
Returns true if SkFontMetrics has a valid fTop, fBottom, fXMin, and fXMax.
Definition: SkFontMetrics.h:133
SkFontMetrics::hasUnderlinePosition
bool hasUnderlinePosition(SkScalar *position) const
Returns true if SkFontMetrics has a valid underline position, and sets position to that value.
Definition: SkFontMetrics.h:90
SkFontMetrics::hasUnderlineThickness
bool hasUnderlineThickness(SkScalar *thickness) const
Returns true if SkFontMetrics has a valid underline thickness, and sets thickness to that value.
Definition: SkFontMetrics.h:75
SkScalar
float SkScalar
Definition: SkScalar.h:16
SkFontMetrics::fMaxCharWidth
SkScalar fMaxCharWidth
maximum character width, zero if unknown
Definition: SkFontMetrics.h:58
SkFontMetrics::fCapHeight
SkScalar fCapHeight
height of an upper-case letter, zero if unknown, typically negative
Definition: SkFontMetrics.h:62
SkFontMetrics::fXMax
SkScalar fXMax
greatest extent to right of origin of any glyph bounding box, typically positive; deprecated with var...
Definition: SkFontMetrics.h:60
SkFontMetrics::hasStrikeoutThickness
bool hasStrikeoutThickness(SkScalar *thickness) const
Returns true if SkFontMetrics has a valid strikeout thickness, and sets thickness to that value.
Definition: SkFontMetrics.h:105
SkFontMetrics::fUnderlinePosition
SkScalar fUnderlinePosition
distance from baseline to top of stroke, typically positive
Definition: SkFontMetrics.h:64
SkFontMetrics::fAvgCharWidth
SkScalar fAvgCharWidth
average character width, zero if unknown
Definition: SkFontMetrics.h:57
SkFontMetrics::operator==
bool operator==(const SkFontMetrics &that)
Definition: SkFontMetrics.h:18
SkFontMetrics::FontMetricsFlags
FontMetricsFlags
Definition: SkFontMetrics.h:43
SkFontMetrics::fBottom
SkScalar fBottom
greatest extent below origin of any glyph bounding box, typically positive; deprecated with variable ...
Definition: SkFontMetrics.h:55