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

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

Issue 335573002: Extract "text align proc" functions as reusable classes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address review comments 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
« no previous file with comments | « src/core/SkDraw.cpp ('k') | src/core/SkTextMapStateProc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkDrawProcs_DEFINED 8 #ifndef SkDrawProcs_DEFINED
9 #define SkDrawProcs_DEFINED 9 #define SkDrawProcs_DEFINED
10 10
11 #include "SkBlitter.h" 11 #include "SkBlitter.h"
12 #include "SkDraw.h" 12 #include "SkDraw.h"
13 #include "SkGlyph.h"
13 14
14 class SkAAClip; 15 class SkAAClip;
15 class SkBlitter; 16 class SkBlitter;
16 17
17 struct SkDraw1Glyph { 18 struct SkDraw1Glyph {
18 const SkDraw* fDraw; 19 const SkDraw* fDraw;
19 const SkRegion* fClip; 20 const SkRegion* fClip;
20 const SkAAClip* fAAClip; 21 const SkAAClip* fAAClip;
21 SkBlitter* fBlitter; 22 SkBlitter* fBlitter;
22 SkGlyphCache* fCache; 23 SkGlyphCache* fCache;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 return true; 80 return true;
80 } 81 }
81 82
82 if (!paint.isAntiAlias()) { 83 if (!paint.isAntiAlias()) {
83 return false; 84 return false;
84 } 85 }
85 86
86 return SkDrawTreatAAStrokeAsHairline(strokeWidth, matrix, coverage); 87 return SkDrawTreatAAStrokeAsHairline(strokeWidth, matrix, coverage);
87 } 88 }
88 89
90 class SkTextAlignProc {
91 public:
92 SkTextAlignProc(SkPaint::Align align)
93 : fAlign(align) {
94 }
95
96 // Returns the position of the glyph in fixed point, which may be rounded or not
97 // by the caller e.g. subpixel doesn't round.
98 // @param point interpreted as SkFixed [x, y].
99 void operator()(const SkPoint& loc, const SkGlyph& glyph, SkIPoint* dst) {
100 if (SkPaint::kLeft_Align == fAlign) {
101 dst->set(SkScalarToFixed(loc.fX), SkScalarToFixed(loc.fY));
102 } else if (SkPaint::kCenter_Align == fAlign) {
103 dst->set(SkScalarToFixed(loc.fX) - (glyph.fAdvanceX >> 1),
104 SkScalarToFixed(loc.fY) - (glyph.fAdvanceY >> 1));
105 } else {
106 SkASSERT(SkPaint::kRight_Align == fAlign);
107 dst->set(SkScalarToFixed(loc.fX) - glyph.fAdvanceX,
108 SkScalarToFixed(loc.fY) - glyph.fAdvanceY);
109 }
110 }
111 private:
112 const SkPaint::Align fAlign;
113 };
114
115 class SkTextAlignProcScalar {
116 public:
117 SkTextAlignProcScalar(SkPaint::Align align)
118 : fAlign(align) {
119 }
120
121 // Returns the glyph position, which may be rounded or not by the caller
122 // e.g. subpixel doesn't round.
123 void operator()(const SkPoint& loc, const SkGlyph& glyph, SkPoint* dst) {
124 if (SkPaint::kLeft_Align == fAlign) {
125 dst->set(loc.fX, loc.fY);
126 } else if (SkPaint::kCenter_Align == fAlign) {
127 dst->set(loc.fX - SkFixedToScalar(glyph.fAdvanceX >> 1),
128 loc.fY - SkFixedToScalar(glyph.fAdvanceY >> 1));
129 } else {
130 SkASSERT(SkPaint::kRight_Align == fAlign);
131 dst->set(loc.fX - SkFixedToScalar(glyph.fAdvanceX),
132 loc.fY - SkFixedToScalar(glyph.fAdvanceY));
133 }
134 }
135 private:
136 const SkPaint::Align fAlign;
137 };
138
89 #endif 139 #endif
OLDNEW
« no previous file with comments | « src/core/SkDraw.cpp ('k') | src/core/SkTextMapStateProc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698