split out fontmetrics into its own struct
Future CLs will migrate all callers to use SkFontMetrics,
so we can remove the SkPaint typedef.
Next migrate the world to use SkFont::getMetrics() instead
Bug: skia:2664
Change-Id: I2aa45cd88762c3d3589c12f5074974af7fb85410
Reviewed-on: https://skia-review.googlesource.com/c/168641
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/gm/fontmgr.cpp b/gm/fontmgr.cpp
index e544a3e..5b69ecf 100644
--- a/gm/fontmgr.cpp
+++ b/gm/fontmgr.cpp
@@ -229,7 +229,7 @@
boundsPaint.setStyle(SkPaint::kStroke_Style);
canvas->drawRect(fontBounds, boundsPaint);
- SkPaint::FontMetrics fm;
+ SkFontMetrics fm;
glyphPaint.getFontMetrics(&fm);
SkPaint metricsPaint(boundsPaint);
metricsPaint.setStyle(SkPaint::kFill_Style);
diff --git a/include/core/SkFontMetrics.h b/include/core/SkFontMetrics.h
new file mode 100644
index 0000000..19bc91f
--- /dev/null
+++ b/include/core/SkFontMetrics.h
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkFontMetrics_DEFINED
+#define SkFontMetrics_DEFINED
+
+#include "SkScalar.h"
+
+struct SK_API SkFontMetrics {
+
+ /** \enum SkPaint::FontMetrics::FontMetricsFlags
+ FontMetricsFlags are set in fFlags when underline and strikeout metrics are valid;
+ the underline or strikeout metric may be valid and zero.
+ Fonts with embedded bitmaps may not have valid underline or strikeout metrics.
+ */
+ enum FontMetricsFlags {
+ kUnderlineThicknessIsValid_Flag = 1 << 0, //!< set if fUnderlineThickness is valid
+ kUnderlinePositionIsValid_Flag = 1 << 1, //!< set if fUnderlinePosition is valid
+ kStrikeoutThicknessIsValid_Flag = 1 << 2, //!< set if fStrikeoutThickness is valid
+ kStrikeoutPositionIsValid_Flag = 1 << 3, //!< set if fStrikeoutPosition is valid
+ };
+
+ uint32_t fFlags; //!< is set to FontMetricsFlags when metrics are valid
+ SkScalar fTop; //!< extent above baseline
+ SkScalar fAscent; //!< distance to reserve above baseline
+ SkScalar fDescent; //!< distance to reserve below baseline
+ SkScalar fBottom; //!< extent below baseline
+ SkScalar fLeading; //!< distance to add between lines
+ SkScalar fAvgCharWidth; //!< average character width
+ SkScalar fMaxCharWidth; //!< maximum character width
+ SkScalar fXMin; //!< minimum x
+ SkScalar fXMax; //!< maximum x
+ SkScalar fXHeight; //!< height of lower-case 'x'
+ SkScalar fCapHeight; //!< height of an upper-case letter
+ SkScalar fUnderlineThickness; //!< underline thickness
+ SkScalar fUnderlinePosition; //!< underline position relative to baseline
+ SkScalar fStrikeoutThickness; //!< strikeout thickness
+ SkScalar fStrikeoutPosition; //!< strikeout position relative to baseline
+
+ /** Returns true if SkPaint::FontMetrics has a valid underline thickness, and sets
+ thickness to that value. If the underline thickness is not valid,
+ return false, and ignore thickness.
+
+ @param thickness storage for underline width
+ @return true if font specifies underline width
+ */
+ bool hasUnderlineThickness(SkScalar* thickness) const {
+ if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) {
+ *thickness = fUnderlineThickness;
+ return true;
+ }
+ return false;
+ }
+
+ /** Returns true if SkPaint::FontMetrics has a valid underline position, and sets
+ position to that value. If the underline position is not valid,
+ return false, and ignore position.
+
+ @param position storage for underline position
+ @return true if font specifies underline position
+ */
+ bool hasUnderlinePosition(SkScalar* position) const {
+ if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
+ *position = fUnderlinePosition;
+ return true;
+ }
+ return false;
+ }
+
+ /** Returns true if SkPaint::FontMetrics has a valid strikeout thickness, and sets
+ thickness to that value. If the underline thickness is not valid,
+ return false, and ignore thickness.
+
+ @param thickness storage for strikeout width
+ @return true if font specifies strikeout width
+ */
+ bool hasStrikeoutThickness(SkScalar* thickness) const {
+ if (SkToBool(fFlags & kStrikeoutThicknessIsValid_Flag)) {
+ *thickness = fStrikeoutThickness;
+ return true;
+ }
+ return false;
+ }
+
+ /** Returns true if SkPaint::FontMetrics has a valid strikeout position, and sets
+ position to that value. If the underline position is not valid,
+ return false, and ignore position.
+
+ @param position storage for strikeout position
+ @return true if font specifies strikeout position
+ */
+ bool hasStrikeoutPosition(SkScalar* position) const {
+ if (SkToBool(fFlags & kStrikeoutPositionIsValid_Flag)) {
+ *position = fStrikeoutPosition;
+ return true;
+ }
+ return false;
+ }
+
+};
+
+#endif
+
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index 16125ba..8bfd0c3 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -22,6 +22,7 @@
#include "SkBlendMode.h"
#include "SkColor.h"
#include "SkFilterQuality.h"
+#include "SkFontMetrics.h"
#include "SkFontTypes.h"
#include "SkMatrix.h"
#include "SkRefCnt.h"
@@ -950,98 +951,7 @@
fStrikeoutThickness and fStrikeoutPosition have a bit set in fFlags if their values
are valid, since their value may be zero.
*/
- struct FontMetrics {
-
- /** \enum SkPaint::FontMetrics::FontMetricsFlags
- FontMetricsFlags are set in fFlags when underline and strikeout metrics are valid;
- the underline or strikeout metric may be valid and zero.
- Fonts with embedded bitmaps may not have valid underline or strikeout metrics.
- */
- enum FontMetricsFlags {
- kUnderlineThicknessIsValid_Flag = 1 << 0, //!< set if fUnderlineThickness is valid
- kUnderlinePositionIsValid_Flag = 1 << 1, //!< set if fUnderlinePosition is valid
- kStrikeoutThicknessIsValid_Flag = 1 << 2, //!< set if fStrikeoutThickness is valid
- kStrikeoutPositionIsValid_Flag = 1 << 3, //!< set if fStrikeoutPosition is valid
- };
-
- uint32_t fFlags; //!< is set to FontMetricsFlags when metrics are valid
- SkScalar fTop; //!< extent above baseline
- SkScalar fAscent; //!< distance to reserve above baseline
- SkScalar fDescent; //!< distance to reserve below baseline
- SkScalar fBottom; //!< extent below baseline
- SkScalar fLeading; //!< distance to add between lines
- SkScalar fAvgCharWidth; //!< average character width
- SkScalar fMaxCharWidth; //!< maximum character width
- SkScalar fXMin; //!< minimum x
- SkScalar fXMax; //!< maximum x
- SkScalar fXHeight; //!< height of lower-case 'x'
- SkScalar fCapHeight; //!< height of an upper-case letter
- SkScalar fUnderlineThickness; //!< underline thickness
- SkScalar fUnderlinePosition; //!< underline position relative to baseline
- SkScalar fStrikeoutThickness; //!< strikeout thickness
- SkScalar fStrikeoutPosition; //!< strikeout position relative to baseline
-
- /** Returns true if SkPaint::FontMetrics has a valid underline thickness, and sets
- thickness to that value. If the underline thickness is not valid,
- return false, and ignore thickness.
-
- @param thickness storage for underline width
- @return true if font specifies underline width
- */
- bool hasUnderlineThickness(SkScalar* thickness) const {
- if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) {
- *thickness = fUnderlineThickness;
- return true;
- }
- return false;
- }
-
- /** Returns true if SkPaint::FontMetrics has a valid underline position, and sets
- position to that value. If the underline position is not valid,
- return false, and ignore position.
-
- @param position storage for underline position
- @return true if font specifies underline position
- */
- bool hasUnderlinePosition(SkScalar* position) const {
- if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
- *position = fUnderlinePosition;
- return true;
- }
- return false;
- }
-
- /** Returns true if SkPaint::FontMetrics has a valid strikeout thickness, and sets
- thickness to that value. If the underline thickness is not valid,
- return false, and ignore thickness.
-
- @param thickness storage for strikeout width
- @return true if font specifies strikeout width
- */
- bool hasStrikeoutThickness(SkScalar* thickness) const {
- if (SkToBool(fFlags & kStrikeoutThicknessIsValid_Flag)) {
- *thickness = fStrikeoutThickness;
- return true;
- }
- return false;
- }
-
- /** Returns true if SkPaint::FontMetrics has a valid strikeout position, and sets
- position to that value. If the underline position is not valid,
- return false, and ignore position.
-
- @param position storage for strikeout position
- @return true if font specifies strikeout position
- */
- bool hasStrikeoutPosition(SkScalar* position) const {
- if (SkToBool(fFlags & kStrikeoutPositionIsValid_Flag)) {
- *position = fStrikeoutPosition;
- return true;
- }
- return false;
- }
-
- };
+ typedef SkFontMetrics FontMetrics;
/** Returns SkPaint::FontMetrics associated with SkTypeface.
The return value is the recommended spacing between lines: the sum of metrics
@@ -1054,7 +964,7 @@
@param metrics storage for SkPaint::FontMetrics from SkTypeface; may be nullptr
@return recommended spacing between lines
*/
- SkScalar getFontMetrics(FontMetrics* metrics) const;
+ SkScalar getFontMetrics(SkFontMetrics* metrics) const;
/** Returns the recommended spacing between lines: the sum of metrics
descent, ascent, and leading.
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp
index 9b2a7c0..ac8a4fc 100644
--- a/src/core/SkGlyphCache.cpp
+++ b/src/core/SkGlyphCache.cpp
@@ -24,7 +24,7 @@
SkGlyphCache::SkGlyphCache(
const SkDescriptor& desc,
std::unique_ptr<SkScalerContext> scaler,
- const SkPaint::FontMetrics& fontMetrics)
+ const SkFontMetrics& fontMetrics)
: fDesc{desc}
, fScalerContext{std::move(scaler)}
, fFontMetrics{fontMetrics}
diff --git a/src/core/SkGlyphCache.h b/src/core/SkGlyphCache.h
index fb8a08e..38aeb16 100644
--- a/src/core/SkGlyphCache.h
+++ b/src/core/SkGlyphCache.h
@@ -34,7 +34,7 @@
public:
SkGlyphCache(const SkDescriptor& desc,
std::unique_ptr<SkScalerContext> scaler,
- const SkPaint::FontMetrics&);
+ const SkFontMetrics&);
~SkGlyphCache() override;
const SkDescriptor& getDescriptor() const;
@@ -123,7 +123,7 @@
/** Return the vertical metrics for this strike.
*/
- const SkPaint::FontMetrics& getFontMetrics() const {
+ const SkFontMetrics& getFontMetrics() const {
return fFontMetrics;
}
@@ -221,7 +221,7 @@
const SkAutoDescriptor fDesc;
const std::unique_ptr<SkScalerContext> fScalerContext;
- SkPaint::FontMetrics fFontMetrics;
+ SkFontMetrics fFontMetrics;
// Map from a combined GlyphID and sub-pixel position to a SkGlyph.
SkTHashTable<SkGlyph, SkPackedGlyphID, SkGlyph::HashTraits> fGlyphMap;
diff --git a/src/core/SkPaint_text.cpp b/src/core/SkPaint_text.cpp
index 1a18901..fcbc7d4 100644
--- a/src/core/SkPaint_text.cpp
+++ b/src/core/SkPaint_text.cpp
@@ -472,7 +472,7 @@
///////////////////////////////////////////////////////////////////////////////
-SkScalar SkPaint::getFontMetrics(FontMetrics* metrics) const {
+SkScalar SkPaint::getFontMetrics(SkFontMetrics* metrics) const {
SkCanonicalizePaint canon(*this);
const SkPaint& paint = canon.getPaint();
SkScalar scale = canon.getScale();