aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkFindAndPlaceGlyph.h
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@google.com>2018-05-02 13:53:53 +0000
committerGravatar Mike Klein <mtklein@google.com>2018-05-02 13:54:54 +0000
commitc76e26a6bb8af9ac9b0c7226851b2ded12d18687 (patch)
tree368bb3cfb1d09e08cfb59cbf666b3e1769267640 /src/core/SkFindAndPlaceGlyph.h
parent78a9aed075ecb342545d913bc92ef9abc6431b49 (diff)
Revert "Remove devKerning"
This reverts commit c86c5c0144b85d0bc8ec791f9609ee2d4e7d835a. Reason for revert: 4 of 5 Original change's description: > Remove devKerning > > Dev kerning is not supported by any scalers. This is > mostly removed. The remaining fields fRsbDelta and > fLsbDelta are kept to keep Android compiling. > > Change-Id: If1a9ee9bb599d4e1bdf4b3751ac0c65246350809 > Reviewed-on: https://skia-review.googlesource.com/124921 > Reviewed-by: Ben Wagner <bungeman@google.com> > Commit-Queue: Herb Derby <herb@google.com> TBR=bungeman@google.com,herb@google.com,reed@google.com Change-Id: If865f702868192a1b72cd811baa996dd1282bbce No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/125263 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Mike Klein <mtklein@google.com>
Diffstat (limited to 'src/core/SkFindAndPlaceGlyph.h')
-rw-r--r--src/core/SkFindAndPlaceGlyph.h38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/core/SkFindAndPlaceGlyph.h b/src/core/SkFindAndPlaceGlyph.h
index 00417152ab..d92edb6b17 100644
--- a/src/core/SkFindAndPlaceGlyph.h
+++ b/src/core/SkFindAndPlaceGlyph.h
@@ -9,6 +9,7 @@
#define SkFindAndPositionGlyph_DEFINED
#include "SkArenaAlloc.h"
+#include "SkAutoKern.h"
#include "SkGlyph.h"
#include "SkGlyphCache.h"
#include "SkMatrixPriv.h"
@@ -319,8 +320,8 @@ private:
virtual ~GlyphFindAndPlaceInterface() { }
// findAndPositionGlyph calculates the position of the glyph, finds the glyph, and
- // returns the position of where the next glyph will be using the glyph's advance. The
- // returned position is used by drawText, but ignored by drawPosText.
+ // returns the position of where the next glyph will be using the glyph's advance and
+ // possibly kerning. The returned position is used by drawText, but ignored by drawPosText.
// The compiler should prune all this calculation if the return value is not used.
//
// This should be a pure virtual, but some versions of GCC <= 4.8 have a bug that causes a
@@ -382,20 +383,31 @@ private:
GlyphFinderInterface* fGlyphFinder;
};
+ enum SelectKerning {
+ kNoKerning = false,
+ kUseKerning = true
+ };
+
// GlyphFindAndPlaceFullPixel handles finding and placing glyphs when no sub-pixel
- // positioning is requested.
- template<typename ProcessOneGlyph, SkPaint::Align kTextAlignment>
+ // positioning is requested. The kUseKerning argument should be true for drawText, and false
+ // for drawPosText.
+ template<typename ProcessOneGlyph, SkPaint::Align kTextAlignment, SelectKerning kUseKerning>
class GlyphFindAndPlaceFullPixel final : public GlyphFindAndPlaceInterface<ProcessOneGlyph> {
public:
explicit GlyphFindAndPlaceFullPixel(GlyphFinderInterface* glyphFinder)
: fGlyphFinder(glyphFinder) {
+ // Kerning can only be used with SkPaint::kLeft_Align
+ static_assert(!kUseKerning || SkPaint::kLeft_Align == kTextAlignment,
+ "Kerning can only be used with left aligned text.");
}
SkPoint findAndPositionGlyph(
const char** text, SkPoint position, ProcessOneGlyph&& processOneGlyph) override {
SkPoint finalPosition = position;
const SkGlyph& glyph = fGlyphFinder->lookupGlyph(text);
-
+ if (kUseKerning) {
+ finalPosition += {fAutoKern.adjust(glyph), 0.0f};
+ }
if (glyph.fWidth > 0) {
finalPosition -= TextAlignmentAdjustment(kTextAlignment, glyph);
processOneGlyph(glyph, finalPosition, {SK_ScalarHalf, SK_ScalarHalf});
@@ -406,6 +418,8 @@ private:
private:
GlyphFinderInterface* fGlyphFinder;
+
+ SkAutoKern fAutoKern;
};
template <typename ProcessOneGlyph, SkPaint::Align kTextAlignment>
@@ -432,12 +446,14 @@ private:
SkScalar x = 0, y = 0;
const char* stop = text + byteLength;
+ SkAutoKern autokern;
+
while (text < stop) {
// don't need x, y here, since all subpixel variants will have the
// same advance
const SkGlyph& glyph = glyphFinder->lookupGlyph(&text);
- x += SkFloatToScalar(glyph.fAdvanceX);
+ x += autokern.adjust(glyph) + SkFloatToScalar(glyph.fAdvanceX);
y += SkFloatToScalar(glyph.fAdvanceY);
}
SkASSERT(text == stop);
@@ -527,17 +543,18 @@ inline void SkFindAndPlaceGlyph::ProcessPosText(
switch (textAlignment) {
case SkPaint::kLeft_Align:
findAndPosition = arena.make<
- GlyphFindAndPlaceFullPixel<ProcessOneGlyph, SkPaint::kLeft_Align>>(glyphFinder);
+ GlyphFindAndPlaceFullPixel<ProcessOneGlyph,
+ SkPaint::kLeft_Align, kNoKerning>>(glyphFinder);
break;
case SkPaint::kCenter_Align:
findAndPosition = arena.make<
GlyphFindAndPlaceFullPixel<ProcessOneGlyph,
- SkPaint::kCenter_Align>>(glyphFinder);
+ SkPaint::kCenter_Align, kNoKerning>>(glyphFinder);
break;
case SkPaint::kRight_Align:
findAndPosition = arena.make<
GlyphFindAndPlaceFullPixel<ProcessOneGlyph,
- SkPaint::kRight_Align>>(glyphFinder);
+ SkPaint::kRight_Align, kNoKerning>>(glyphFinder);
break;
}
}
@@ -578,7 +595,8 @@ inline void SkFindAndPlaceGlyph::ProcessText(
findAndPosition = getSubpixel<ProcessOneGlyph, SkPaint::kLeft_Align>(
&arena, axisAlignment, glyphFinder);
} else {
- using FullPixel = GlyphFindAndPlaceFullPixel<ProcessOneGlyph, SkPaint::kLeft_Align>;
+ using FullPixel =
+ GlyphFindAndPlaceFullPixel<ProcessOneGlyph, SkPaint::kLeft_Align, kUseKerning>;
findAndPosition = arena.make<FullPixel>(glyphFinder);
}