OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "GrFontScaler.h" | 9 #include "GrFontScaler.h" |
10 #include "SkDescriptor.h" | 10 #include "SkDescriptor.h" |
11 #include "SkDistanceFieldGen.h" | 11 #include "SkDistanceFieldGen.h" |
12 #include "GrDistanceFieldGenFromVector.h" | |
13 #include "SkGlyphCache.h" | 12 #include "SkGlyphCache.h" |
14 | 13 |
15 /////////////////////////////////////////////////////////////////////////////// | 14 /////////////////////////////////////////////////////////////////////////////// |
16 | 15 |
17 GrFontScaler::GrFontScaler(SkGlyphCache* strike) { | 16 GrFontScaler::GrFontScaler(SkGlyphCache* strike) { |
18 fStrike = strike; | 17 fStrike = strike; |
19 fKey = nullptr; | 18 fKey = nullptr; |
20 } | 19 } |
21 | 20 |
22 GrFontScaler::~GrFontScaler() { | 21 GrFontScaler::~GrFontScaler() { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 src = (const char*)src + srcRB; | 163 src = (const char*)src + srcRB; |
165 dst = (char*)dst + dstRB; | 164 dst = (char*)dst + dstRB; |
166 } | 165 } |
167 } | 166 } |
168 return true; | 167 return true; |
169 } | 168 } |
170 | 169 |
171 bool GrFontScaler::getPackedGlyphDFImage(const SkGlyph& glyph, int width, int he
ight, void* dst) { | 170 bool GrFontScaler::getPackedGlyphDFImage(const SkGlyph& glyph, int width, int he
ight, void* dst) { |
172 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width); | 171 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width); |
173 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height); | 172 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height); |
174 const SkPath* path = fStrike->findPath(glyph); | 173 const void* image = fStrike->findImage(glyph); |
175 if (nullptr == path) { | 174 if (nullptr == image) { |
| 175 return false; |
| 176 } |
| 177 // now generate the distance field |
| 178 SkASSERT(dst); |
| 179 SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); |
| 180 if (SkMask::kA8_Format == maskFormat) { |
| 181 // make the distance field from the image |
| 182 SkGenerateDistanceFieldFromA8Image((unsigned char*)dst, |
| 183 (unsigned char*)image, |
| 184 glyph.fWidth, glyph.fHeight, |
| 185 glyph.rowBytes()); |
| 186 } else if (SkMask::kBW_Format == maskFormat) { |
| 187 // make the distance field from the image |
| 188 SkGenerateDistanceFieldFromBWImage((unsigned char*)dst, |
| 189 (unsigned char*)image, |
| 190 glyph.fWidth, glyph.fHeight, |
| 191 glyph.rowBytes()); |
| 192 } else { |
176 return false; | 193 return false; |
177 } | 194 } |
178 | 195 |
179 SkMatrix drawMatrix; | |
180 drawMatrix.setTranslate((SkScalar)-glyph.fLeft, (SkScalar)-glyph.fTop); | |
181 | |
182 // now generate the distance field | |
183 SkASSERT(dst); | |
184 // Generate signed distance field directly from SkPath | |
185 GrGenerateDistanceFieldFromPath((unsigned char*)dst, | |
186 *path, drawMatrix, | |
187 width, height, width * sizeof(unsigned char)
); | |
188 | |
189 return true; | 196 return true; |
190 } | 197 } |
191 | 198 |
192 const SkPath* GrFontScaler::getGlyphPath(const SkGlyph& glyph) { | 199 const SkPath* GrFontScaler::getGlyphPath(const SkGlyph& glyph) { |
193 return fStrike->findPath(glyph); | 200 return fStrike->findPath(glyph); |
194 } | 201 } |
195 | 202 |
196 const SkGlyph& GrFontScaler::grToSkGlyph(GrGlyph::PackedID id) { | 203 const SkGlyph& GrFontScaler::grToSkGlyph(GrGlyph::PackedID id) { |
197 return fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(id), | 204 return fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(id), |
198 GrGlyph::UnpackFixedX(id), | 205 GrGlyph::UnpackFixedX(id), |
199 GrGlyph::UnpackFixedY(id)); | 206 GrGlyph::UnpackFixedY(id)); |
200 } | 207 } |
OLD | NEW |