| Index: src/core/SkTextMapState.h
|
| diff --git a/src/core/SkTextMapState.h b/src/core/SkTextMapState.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..885c15cacb24bd277bdaeb22736ebf437c62439a
|
| --- /dev/null
|
| +++ b/src/core/SkTextMapState.h
|
| @@ -0,0 +1,73 @@
|
| +/*
|
| + * Copyright 2014 Google Inc.
|
| + *
|
| + * Use of this source code is governed by a BSD-style license that can be
|
| + * found in the LICENSE file.
|
| + */
|
| +
|
| +#ifndef SkTextMapState_DEFINED
|
| +#define SkTextMapState_DEFINED
|
| +
|
| +#include "SkPoint.h"
|
| +#include "SkMatrix.h"
|
| +
|
| +class SkTextMapState {
|
| +public:
|
| + SkPoint fLoc;
|
| +
|
| + SkTextMapState(const SkMatrix& matrix, SkScalar y)
|
| + : fMatrix(matrix), fProc(matrix.getMapXYProc()), fY(y) {}
|
| +
|
| + typedef void (*Proc)(SkTextMapState&, const SkScalar pos[]);
|
| +
|
| + Proc pickProc(int scalarsPerPosition);
|
| +
|
| +private:
|
| + const SkMatrix& fMatrix;
|
| + SkMatrix::MapXYProc fProc;
|
| + SkScalar fY; // ignored by MapXYProc
|
| + // these are only used by Only... procs
|
| + SkScalar fScaleX, fTransX, fTransformedY;
|
| +
|
| + static void MapXProc(SkTextMapState& state, const SkScalar pos[]) {
|
| + state.fProc(state.fMatrix, *pos, state.fY, &state.fLoc);
|
| + }
|
| +
|
| + static void MapXYProc(SkTextMapState& state, const SkScalar pos[]) {
|
| + state.fProc(state.fMatrix, pos[0], pos[1], &state.fLoc);
|
| + }
|
| +
|
| + static void MapOnlyScaleXProc(SkTextMapState& state,
|
| + const SkScalar pos[]) {
|
| + state.fLoc.set(SkScalarMul(state.fScaleX, *pos) + state.fTransX,
|
| + state.fTransformedY);
|
| + }
|
| +
|
| + static void MapOnlyTransXProc(SkTextMapState& state,
|
| + const SkScalar pos[]) {
|
| + state.fLoc.set(*pos + state.fTransX, state.fTransformedY);
|
| + }
|
| +};
|
| +
|
| +inline SkTextMapState::Proc SkTextMapState::pickProc(int scalarsPerPosition) {
|
| + SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
|
| +
|
| + if (1 == scalarsPerPosition) {
|
| + unsigned mtype = fMatrix.getType();
|
| + if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
|
| + return MapXProc;
|
| + } else {
|
| + fScaleX = fMatrix.getScaleX();
|
| + fTransX = fMatrix.getTranslateX();
|
| + fTransformedY = SkScalarMul(fY, fMatrix.getScaleY()) +
|
| + fMatrix.getTranslateY();
|
| + return (mtype & SkMatrix::kScale_Mask) ?
|
| + MapOnlyScaleXProc : MapOnlyTransXProc;
|
| + }
|
| + } else {
|
| + return MapXYProc;
|
| + }
|
| +}
|
| +
|
| +#endif
|
| +
|
|
|