2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkTextMapStateProc_DEFINED
9 #define SkTextMapStateProc_DEFINED
14 class SkTextMapStateProc {
16 SkTextMapStateProc(const SkMatrix& matrix, SkScalar y, int scalarsPerPosition)
18 , fProc(matrix.getMapXYProc())
20 , fScaleX(fMatrix.getScaleX())
21 , fTransX(fMatrix.getTranslateX()) {
22 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
23 if (1 == scalarsPerPosition) {
24 unsigned mtype = fMatrix.getType();
25 if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
28 fY = SkScalarMul(y, fMatrix.getScaleY()) +
29 fMatrix.getTranslateY();
30 if (mtype & SkMatrix::kScale_Mask) {
31 fMapCase = kOnlyScaleX;
33 fMapCase = kOnlyTransX;
41 void operator()(const SkScalar pos[], SkPoint* loc) const;
44 const SkMatrix& fMatrix;
51 const SkMatrix::MapXYProc fProc;
52 SkScalar fY; // Ignored by kXY case.
53 SkScalar fScaleX, fTransX; // These are only used by Only... cases.
56 inline void SkTextMapStateProc::operator()(const SkScalar pos[], SkPoint* loc) const {
59 fProc(fMatrix, pos[0], pos[1], loc);
62 loc->set(SkScalarMul(fScaleX, *pos) + fTransX, fY);
65 loc->set(*pos + fTransX, fY);
70 fProc(fMatrix, *pos, fY, loc);