OLD | NEW |
---|---|
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 Loading... | |
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) { | |
jvanverth1
2014/06/09 13:48:07
If I understand this correctly, this seems ineffic
Kimmo Kinnunen
2014/06/11 12:33:24
I'm not an expert, but afaik function pointers are
| |
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 |
OLD | NEW |