diff options
author | Herb Derby <herb@google.com> | 2018-03-12 12:43:54 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-12 17:12:53 +0000 |
commit | d34c63344296870676c7ea55af0ff526a475a869 (patch) | |
tree | 77ac483b2325bb64efd971a724d00b7fe63caf76 | |
parent | b1cdc786f976027adc9f51ed309a34aebbcbb34c (diff) |
Make SubpixelAlignment public
And, change the logic to handle NaN and Inf.
Small cleanup.
BUG=skia:7515
Change-Id: Ib02ad8f4bc66df57d226d4440ef6214fd2f813d6
Reviewed-on: https://skia-review.googlesource.com/113742
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
-rw-r--r-- | src/core/SkFindAndPlaceGlyph.h | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/src/core/SkFindAndPlaceGlyph.h b/src/core/SkFindAndPlaceGlyph.h index 7ef4a465b3..d3cf327e63 100644 --- a/src/core/SkFindAndPlaceGlyph.h +++ b/src/core/SkFindAndPlaceGlyph.h @@ -48,6 +48,30 @@ public: SkPaint::Align textAlignment, SkGlyphCache* cache, ProcessOneGlyph&& processOneGlyph); + // The SubpixelAlignment function produces a suitable position for the glyph cache to + // produce the correct sub-pixel alignment. If a position is aligned with an axis a shortcut + // of 0 is used for the sub-pixel position. + static SkIPoint SubpixelAlignment(SkAxisAlignment axisAlignment, SkPoint position) { + + if (!SkScalarsAreFinite(position.fX, position.fY)) { + return {0, 0}; + } + + // Only the fractional part of position.fX and position.fY matter, because the result of + // this function will just be passed to FixedToSub. + switch (axisAlignment) { + case kX_SkAxisAlignment: + return {SkScalarToFixed(SkScalarFraction(position.fX) + kSubpixelRounding), 0}; + case kY_SkAxisAlignment: + return {0, SkScalarToFixed(SkScalarFraction(position.fY) + kSubpixelRounding)}; + case kNone_SkAxisAlignment: + return {SkScalarToFixed(SkScalarFraction(position.fX) + kSubpixelRounding), + SkScalarToFixed(SkScalarFraction(position.fY) + kSubpixelRounding)}; + } + SK_ABORT("Should not get here."); + return {0, 0}; + } + private: // GlyphFinderInterface is the polymorphic base for classes that parse a stream of chars into // the right UniChar (or GlyphID) and lookup up the glyph on the cache. The concrete @@ -269,7 +293,7 @@ private: // The "call" to SkFixedToScalar is actually a macro. It's macros all the way down. // Needs to be a macro because you can't have a const float unless you make it constexpr. - #define kSubpixelRounding (SkFixedToScalar(SkGlyph::kSubpixelRound)) + static constexpr SkScalar kSubpixelRounding = SkFixedToScalar(SkGlyph::kSubpixelRound); // The SubpixelPositionRounding function returns a point suitable for rounding a sub-pixel // positioned glyph. @@ -286,27 +310,6 @@ private: return {0.0f, 0.0f}; } - // The SubpixelAlignment function produces a suitable position for the glyph cache to - // produce the correct sub-pixel alignment. If a position is aligned with an axis a shortcut - // of 0 is used for the sub-pixel position. - static SkIPoint SubpixelAlignment(SkAxisAlignment axisAlignment, SkPoint position) { - // Only the fractional part of position.fX and position.fY matter, because the result of - // this function will just be passed to FixedToSub. - switch (axisAlignment) { - case kX_SkAxisAlignment: - return {SkScalarToFixed(SkScalarFraction(position.fX) + kSubpixelRounding), 0}; - case kY_SkAxisAlignment: - return {0, SkScalarToFixed(SkScalarFraction(position.fY) + kSubpixelRounding)}; - case kNone_SkAxisAlignment: - return {SkScalarToFixed(SkScalarFraction(position.fX) + kSubpixelRounding), - SkScalarToFixed(SkScalarFraction(position.fY) + kSubpixelRounding)}; - } - SK_ABORT("Should not get here."); - return {0, 0}; - } - - #undef kSubpixelRounding - // GlyphFindAndPlaceInterface given the text and position finds the correct glyph and does // glyph specific position adjustment. The findAndPositionGlyph method takes text and // position and calls processOneGlyph with the correct glyph, final position and rounding @@ -363,9 +366,7 @@ private: } // Find the glyph. - SkIPoint lookupPosition = SkScalarsAreFinite(position.fX, position.fY) - ? SubpixelAlignment(kAxisAlignment, position) - : SkIPoint{0, 0}; + SkIPoint lookupPosition = SubpixelAlignment(kAxisAlignment, position); const SkGlyph& renderGlyph = fGlyphFinder->lookupGlyphXY(text, lookupPosition.fX, lookupPosition.fY); |