diff options
author | Florin Malita <fmalita@google.com> | 2014-09-26 10:33:37 -0400 |
---|---|---|
committer | Florin Malita <fmalita@google.com> | 2014-09-26 10:33:37 -0400 |
commit | c13bc571d3e61a43b87eb97f0719abd304cafaf2 (patch) | |
tree | 819036c0fc5634ddf7784a036c0f1fe2ce914b9a /src/core/SkTextMapStateProc.h | |
parent | 2cce421bdf836ea269ddc98ffbb688acb8dd544e (diff) |
Fix SkTextBlob offset semantics.
Implement proper x/y drawTextBlob() handling by plumbing a
drawPosText() offset parameter (to act as an additional glyph pos
translation) throughout the device layer.
The new offset superceeds the existing constY, with a minor semantic
tweak: whereas previous implementations were ignoring constY in 2D
positioning mode (scalarsPerGlyph == 2), now the offset is always
observed, in all positioning modes. We can do this because existing
drawPosText() clients always pass constY == 0 for full positioning mode.
R=reed@google.com, jvanverth@google.com, robertphillips@google.com
Review URL: https://codereview.chromium.org/605533002
Diffstat (limited to 'src/core/SkTextMapStateProc.h')
-rw-r--r-- | src/core/SkTextMapStateProc.h | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/core/SkTextMapStateProc.h b/src/core/SkTextMapStateProc.h index 5a8dcaa3b1..8ef9389b3a 100644 --- a/src/core/SkTextMapStateProc.h +++ b/src/core/SkTextMapStateProc.h @@ -13,20 +13,22 @@ class SkTextMapStateProc { public: - SkTextMapStateProc(const SkMatrix& matrix, SkScalar y, int scalarsPerPosition) + SkTextMapStateProc(const SkMatrix& matrix, const SkPoint& offset, int scalarsPerPosition) : fMatrix(matrix) , fProc(matrix.getMapXYProc()) - , fY(y) - , fScaleX(fMatrix.getScaleX()) - , fTransX(fMatrix.getTranslateX()) { + , fOffset(offset) + , fScaleX(fMatrix.getScaleX()) { SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); if (1 == scalarsPerPosition) { unsigned mtype = fMatrix.getType(); if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) { fMapCase = kX; } else { - fY = SkScalarMul(y, fMatrix.getScaleY()) + - fMatrix.getTranslateY(); + // Bake the matrix scale/translation components into fOffset, + // to expedite proc computations. + fOffset.set(SkScalarMul(offset.x(), fMatrix.getScaleX()) + fMatrix.getTranslateX(), + SkScalarMul(offset.y(), fMatrix.getScaleY()) + fMatrix.getTranslateY()); + if (mtype & SkMatrix::kScale_Mask) { fMapCase = kOnlyScaleX; } else { @@ -49,25 +51,25 @@ private: kX } fMapCase; const SkMatrix::MapXYProc fProc; - SkScalar fY; // Ignored by kXY case. - SkScalar fScaleX, fTransX; // These are only used by Only... cases. + SkPoint fOffset; // In kOnly* mode, this includes the matrix translation component. + SkScalar fScaleX; // This is only used by kOnly... cases. }; inline void SkTextMapStateProc::operator()(const SkScalar pos[], SkPoint* loc) const { switch(fMapCase) { case kXY: - fProc(fMatrix, pos[0], pos[1], loc); + fProc(fMatrix, pos[0] + fOffset.x(), pos[1] + fOffset.y(), loc); break; case kOnlyScaleX: - loc->set(SkScalarMul(fScaleX, *pos) + fTransX, fY); + loc->set(SkScalarMul(fScaleX, *pos) + fOffset.x(), fOffset.y()); break; case kOnlyTransX: - loc->set(*pos + fTransX, fY); + loc->set(*pos + fOffset.x(), fOffset.y()); break; default: SkASSERT(false); case kX: - fProc(fMatrix, *pos, fY, loc); + fProc(fMatrix, *pos + fOffset.x(), fOffset.y(), loc); break; } } |