OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #include "SkAdvancedTypefaceMetrics.h" | 8 #include "SkAdvancedTypefaceMetrics.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 fPaths[index] = path; | 113 fPaths[index] = path; |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 SkTestTypeface::SkTestTypeface(SkTestFont* testFont, const SkFontStyle& style) | 117 SkTestTypeface::SkTestTypeface(SkTestFont* testFont, const SkFontStyle& style) |
118 : SkTypeface(style, SkTypefaceCache::NewFontID(), false) | 118 : SkTypeface(style, SkTypefaceCache::NewFontID(), false) |
119 , fTestFont(testFont) { | 119 , fTestFont(testFont) { |
120 } | 120 } |
121 | 121 |
122 void SkTestTypeface::getAdvance(SkGlyph* glyph) { | 122 void SkTestTypeface::getAdvance(SkGlyph* glyph) { |
123 glyph->fAdvanceX = fTestFont->fWidths[glyph->getGlyphID()]; | 123 // TODO(benjaminwagner): Update users to use floats. |
| 124 glyph->fAdvanceX = SkFixedToFloat(fTestFont->fWidths[glyph->getGlyphID()]); |
124 glyph->fAdvanceY = 0; | 125 glyph->fAdvanceY = 0; |
125 } | 126 } |
126 | 127 |
127 void SkTestTypeface::getFontMetrics(SkPaint::FontMetrics* metrics) { | 128 void SkTestTypeface::getFontMetrics(SkPaint::FontMetrics* metrics) { |
128 *metrics = fTestFont->fMetrics; | 129 *metrics = fTestFont->fMetrics; |
129 } | 130 } |
130 | 131 |
131 void SkTestTypeface::getMetrics(SkGlyph* glyph) { | 132 void SkTestTypeface::getMetrics(SkGlyph* glyph) { |
132 glyph->fAdvanceX = fTestFont->fWidths[glyph->getGlyphID()]; | 133 // TODO(benjaminwagner): Update users to use floats. |
| 134 glyph->fAdvanceX = SkFixedToFloat(fTestFont->fWidths[glyph->getGlyphID()]); |
133 glyph->fAdvanceY = 0; | 135 glyph->fAdvanceY = 0; |
134 } | 136 } |
135 | 137 |
136 void SkTestTypeface::getPath(const SkGlyph& glyph, SkPath* path) { | 138 void SkTestTypeface::getPath(const SkGlyph& glyph, SkPath* path) { |
137 *path = *fTestFont->fPaths[glyph.getGlyphID()]; | 139 *path = *fTestFont->fPaths[glyph.getGlyphID()]; |
138 } | 140 } |
139 | 141 |
140 void SkTestTypeface::onFilterRec(SkScalerContextRec* rec) const { | 142 void SkTestTypeface::onFilterRec(SkScalerContextRec* rec) const { |
141 rec->setHinting(SkPaint::kNo_Hinting); | 143 rec->setHinting(SkPaint::kNo_Hinting); |
142 } | 144 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 201 |
200 uint16_t generateCharToGlyph(SkUnichar uni) override { | 202 uint16_t generateCharToGlyph(SkUnichar uni) override { |
201 uint16_t glyph; | 203 uint16_t glyph; |
202 (void) fFace->onCharsToGlyphs((const void *) &uni, SkTypeface::kUTF16_En
coding, &glyph, 1); | 204 (void) fFace->onCharsToGlyphs((const void *) &uni, SkTypeface::kUTF16_En
coding, &glyph, 1); |
203 return glyph; | 205 return glyph; |
204 } | 206 } |
205 | 207 |
206 void generateAdvance(SkGlyph* glyph) override { | 208 void generateAdvance(SkGlyph* glyph) override { |
207 fFace->getAdvance(glyph); | 209 fFace->getAdvance(glyph); |
208 | 210 |
209 const SkVector advance = fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX)
, | 211 const SkVector advance = fMatrix.mapXY(SkFloatToScalar(glyph->fAdvanceX)
, |
210 SkFixedToScalar(glyph->fAdvanceY)
); | 212 SkFloatToScalar(glyph->fAdvanceY)
); |
211 glyph->fAdvanceX = SkScalarToFixed(advance.fX); | 213 glyph->fAdvanceX = SkScalarToFloat(advance.fX); |
212 glyph->fAdvanceY = SkScalarToFixed(advance.fY); | 214 glyph->fAdvanceY = SkScalarToFloat(advance.fY); |
213 } | 215 } |
214 | 216 |
215 void generateMetrics(SkGlyph* glyph) override { | 217 void generateMetrics(SkGlyph* glyph) override { |
216 fFace->getMetrics(glyph); | 218 fFace->getMetrics(glyph); |
217 | 219 |
218 const SkVector advance = fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX)
, | 220 const SkVector advance = fMatrix.mapXY(SkFloatToScalar(glyph->fAdvanceX)
, |
219 SkFixedToScalar(glyph->fAdvanceY)
); | 221 SkFloatToScalar(glyph->fAdvanceY)
); |
220 glyph->fAdvanceX = SkScalarToFixed(advance.fX); | 222 glyph->fAdvanceX = SkScalarToFloat(advance.fX); |
221 glyph->fAdvanceY = SkScalarToFixed(advance.fY); | 223 glyph->fAdvanceY = SkScalarToFloat(advance.fY); |
222 | 224 |
223 SkPath path; | 225 SkPath path; |
224 fFace->getPath(*glyph, &path); | 226 fFace->getPath(*glyph, &path); |
225 path.transform(fMatrix); | 227 path.transform(fMatrix); |
226 | 228 |
227 SkRect storage; | 229 SkRect storage; |
228 const SkPaint paint; | 230 const SkPaint paint; |
229 const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(), | 231 const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(), |
230 &storage, | 232 &storage, |
231 SkPaint::kFill_Style
); | 233 SkPaint::kFill_Style
); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 } | 279 } |
278 | 280 |
279 private: | 281 private: |
280 SkTestTypeface* fFace; | 282 SkTestTypeface* fFace; |
281 SkMatrix fMatrix; | 283 SkMatrix fMatrix; |
282 }; | 284 }; |
283 | 285 |
284 SkScalerContext* SkTestTypeface::onCreateScalerContext(const SkDescriptor* desc)
const { | 286 SkScalerContext* SkTestTypeface::onCreateScalerContext(const SkDescriptor* desc)
const { |
285 return new SkTestScalerContext(const_cast<SkTestTypeface*>(this), desc); | 287 return new SkTestScalerContext(const_cast<SkTestTypeface*>(this), desc); |
286 } | 288 } |
OLD | NEW |