Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/core/SkTextMapState.h

Issue 196133014: Implement text rendering with NVPR (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase and fix postext Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkTextMapState_DEFINED
9 #define SkTextMapState_DEFINED
10
11 #include "SkPoint.h"
12 #include "SkMatrix.h"
13
14 class SkTextMapState {
15 public:
16 SkPoint fLoc;
17
18 SkTextMapState(const SkMatrix& matrix, SkScalar y)
19 : fMatrix(matrix), fProc(matrix.getMapXYProc()), fY(y) {}
20
21 typedef void (*Proc)(SkTextMapState&, const SkScalar pos[]);
22
23 Proc pickProc(int scalarsPerPosition);
24
25 private:
26 const SkMatrix& fMatrix;
27 SkMatrix::MapXYProc fProc;
28 SkScalar fY; // ignored by MapXYProc
29 // these are only used by Only... procs
30 SkScalar fScaleX, fTransX, fTransformedY;
31
32 static void MapXProc(SkTextMapState& state, const SkScalar pos[]) {
33 state.fProc(state.fMatrix, *pos, state.fY, &state.fLoc);
34 }
35
36 static void MapXYProc(SkTextMapState& state, const SkScalar pos[]) {
37 state.fProc(state.fMatrix, pos[0], pos[1], &state.fLoc);
38 }
39
40 static void MapOnlyScaleXProc(SkTextMapState& state,
41 const SkScalar pos[]) {
42 state.fLoc.set(SkScalarMul(state.fScaleX, *pos) + state.fTransX,
43 state.fTransformedY);
44 }
45
46 static void MapOnlyTransXProc(SkTextMapState& state,
47 const SkScalar pos[]) {
48 state.fLoc.set(*pos + state.fTransX, state.fTransformedY);
49 }
50 };
51
52 inline SkTextMapState::Proc SkTextMapState::pickProc(int scalarsPerPosition) {
53 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
54
55 if (1 == scalarsPerPosition) {
56 unsigned mtype = fMatrix.getType();
57 if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
58 return MapXProc;
59 } else {
60 fScaleX = fMatrix.getScaleX();
61 fTransX = fMatrix.getTranslateX();
62 fTransformedY = SkScalarMul(fY, fMatrix.getScaleY()) +
63 fMatrix.getTranslateY();
64 return (mtype & SkMatrix::kScale_Mask) ?
65 MapOnlyScaleXProc : MapOnlyTransXProc;
66 }
67 } else {
68 return MapXYProc;
69 }
70 }
71
72 #endif
73
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698