| 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkDescriptor.h" | 10 #include "SkDescriptor.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 , fFace(face) | 194 , fFace(face) |
| 195 { | 195 { |
| 196 fRec.getSingleMatrix(&fMatrix); | 196 fRec.getSingleMatrix(&fMatrix); |
| 197 this->forceGenerateImageFromPath(); | 197 this->forceGenerateImageFromPath(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 virtual ~SkTestScalerContext() { | 200 virtual ~SkTestScalerContext() { |
| 201 } | 201 } |
| 202 | 202 |
| 203 protected: | 203 protected: |
| 204 virtual unsigned generateGlyphCount() SK_OVERRIDE { | 204 unsigned generateGlyphCount() SK_OVERRIDE { |
| 205 return fFace->onCountGlyphs(); | 205 return fFace->onCountGlyphs(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE { | 208 uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE { |
| 209 uint16_t glyph; | 209 uint16_t glyph; |
| 210 (void) fFace->onCharsToGlyphs((const void *) &uni, SkTypeface::kUTF16_En
coding, &glyph, 1); | 210 (void) fFace->onCharsToGlyphs((const void *) &uni, SkTypeface::kUTF16_En
coding, &glyph, 1); |
| 211 return glyph; | 211 return glyph; |
| 212 } | 212 } |
| 213 | 213 |
| 214 virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE { | 214 void generateAdvance(SkGlyph* glyph) SK_OVERRIDE { |
| 215 fFace->getAdvance(glyph); | 215 fFace->getAdvance(glyph); |
| 216 | 216 |
| 217 SkVector advance; | 217 SkVector advance; |
| 218 fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX), | 218 fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX), |
| 219 SkFixedToScalar(glyph->fAdvanceY), &advance); | 219 SkFixedToScalar(glyph->fAdvanceY), &advance); |
| 220 glyph->fAdvanceX = SkScalarToFixed(advance.fX); | 220 glyph->fAdvanceX = SkScalarToFixed(advance.fX); |
| 221 glyph->fAdvanceY = SkScalarToFixed(advance.fY); | 221 glyph->fAdvanceY = SkScalarToFixed(advance.fY); |
| 222 } | 222 } |
| 223 | 223 |
| 224 virtual void generateMetrics(SkGlyph* glyph) SK_OVERRIDE { | 224 void generateMetrics(SkGlyph* glyph) SK_OVERRIDE { |
| 225 fFace->getMetrics(glyph); | 225 fFace->getMetrics(glyph); |
| 226 | 226 |
| 227 SkVector advance; | 227 SkVector advance; |
| 228 fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX), | 228 fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX), |
| 229 SkFixedToScalar(glyph->fAdvanceY), &advance); | 229 SkFixedToScalar(glyph->fAdvanceY), &advance); |
| 230 glyph->fAdvanceX = SkScalarToFixed(advance.fX); | 230 glyph->fAdvanceX = SkScalarToFixed(advance.fX); |
| 231 glyph->fAdvanceY = SkScalarToFixed(advance.fY); | 231 glyph->fAdvanceY = SkScalarToFixed(advance.fY); |
| 232 | 232 |
| 233 SkPath path; | 233 SkPath path; |
| 234 fFace->getPath(*glyph, &path); | 234 fFace->getPath(*glyph, &path); |
| 235 path.transform(fMatrix); | 235 path.transform(fMatrix); |
| 236 | 236 |
| 237 SkRect storage; | 237 SkRect storage; |
| 238 const SkPaint paint; | 238 const SkPaint paint; |
| 239 const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(), | 239 const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(), |
| 240 &storage, | 240 &storage, |
| 241 SkPaint::kFill_Style
); | 241 SkPaint::kFill_Style
); |
| 242 SkIRect ibounds; | 242 SkIRect ibounds; |
| 243 newBounds.roundOut(&ibounds); | 243 newBounds.roundOut(&ibounds); |
| 244 glyph->fLeft = ibounds.fLeft; | 244 glyph->fLeft = ibounds.fLeft; |
| 245 glyph->fTop = ibounds.fTop; | 245 glyph->fTop = ibounds.fTop; |
| 246 glyph->fWidth = ibounds.width(); | 246 glyph->fWidth = ibounds.width(); |
| 247 glyph->fHeight = ibounds.height(); | 247 glyph->fHeight = ibounds.height(); |
| 248 glyph->fMaskFormat = SkMask::kARGB32_Format; | 248 glyph->fMaskFormat = SkMask::kARGB32_Format; |
| 249 } | 249 } |
| 250 | 250 |
| 251 virtual void generateImage(const SkGlyph& glyph) SK_OVERRIDE { | 251 void generateImage(const SkGlyph& glyph) SK_OVERRIDE { |
| 252 SkPath path; | 252 SkPath path; |
| 253 fFace->getPath(glyph, &path); | 253 fFace->getPath(glyph, &path); |
| 254 | 254 |
| 255 SkBitmap bm; | 255 SkBitmap bm; |
| 256 bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHeight)
, | 256 bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHeight)
, |
| 257 glyph.fImage, glyph.rowBytes()); | 257 glyph.fImage, glyph.rowBytes()); |
| 258 bm.eraseColor(0); | 258 bm.eraseColor(0); |
| 259 | 259 |
| 260 SkCanvas canvas(bm); | 260 SkCanvas canvas(bm); |
| 261 canvas.translate(-SkIntToScalar(glyph.fLeft), | 261 canvas.translate(-SkIntToScalar(glyph.fLeft), |
| 262 -SkIntToScalar(glyph.fTop)); | 262 -SkIntToScalar(glyph.fTop)); |
| 263 canvas.concat(fMatrix); | 263 canvas.concat(fMatrix); |
| 264 SkPaint paint; | 264 SkPaint paint; |
| 265 paint.setAntiAlias(true); | 265 paint.setAntiAlias(true); |
| 266 canvas.drawPath(path, paint); | 266 canvas.drawPath(path, paint); |
| 267 } | 267 } |
| 268 | 268 |
| 269 virtual void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE { | 269 void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE { |
| 270 fFace->getPath(glyph, path); | 270 fFace->getPath(glyph, path); |
| 271 path->transform(fMatrix); | 271 path->transform(fMatrix); |
| 272 } | 272 } |
| 273 | 273 |
| 274 virtual void generateFontMetrics(SkPaint::FontMetrics* metrics) SK_OVERRIDE
{ | 274 void generateFontMetrics(SkPaint::FontMetrics* metrics) SK_OVERRIDE { |
| 275 fFace->getFontMetrics(metrics); | 275 fFace->getFontMetrics(metrics); |
| 276 if (metrics) { | 276 if (metrics) { |
| 277 SkScalar scale = fMatrix.getScaleY(); | 277 SkScalar scale = fMatrix.getScaleY(); |
| 278 metrics->fTop = SkScalarMul(metrics->fTop, scale); | 278 metrics->fTop = SkScalarMul(metrics->fTop, scale); |
| 279 metrics->fAscent = SkScalarMul(metrics->fAscent, scale); | 279 metrics->fAscent = SkScalarMul(metrics->fAscent, scale); |
| 280 metrics->fDescent = SkScalarMul(metrics->fDescent, scale); | 280 metrics->fDescent = SkScalarMul(metrics->fDescent, scale); |
| 281 metrics->fBottom = SkScalarMul(metrics->fBottom, scale); | 281 metrics->fBottom = SkScalarMul(metrics->fBottom, scale); |
| 282 metrics->fLeading = SkScalarMul(metrics->fLeading, scale); | 282 metrics->fLeading = SkScalarMul(metrics->fLeading, scale); |
| 283 metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale); | 283 metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale); |
| 284 metrics->fXMin = SkScalarMul(metrics->fXMin, scale); | 284 metrics->fXMin = SkScalarMul(metrics->fXMin, scale); |
| 285 metrics->fXMax = SkScalarMul(metrics->fXMax, scale); | 285 metrics->fXMax = SkScalarMul(metrics->fXMax, scale); |
| 286 metrics->fXHeight = SkScalarMul(metrics->fXHeight, scale); | 286 metrics->fXHeight = SkScalarMul(metrics->fXHeight, scale); |
| 287 } | 287 } |
| 288 } | 288 } |
| 289 | 289 |
| 290 private: | 290 private: |
| 291 SkTestTypeface* fFace; | 291 SkTestTypeface* fFace; |
| 292 SkMatrix fMatrix; | 292 SkMatrix fMatrix; |
| 293 }; | 293 }; |
| 294 | 294 |
| 295 SkScalerContext* SkTestTypeface::onCreateScalerContext(const SkDescriptor* desc)
const { | 295 SkScalerContext* SkTestTypeface::onCreateScalerContext(const SkDescriptor* desc)
const { |
| 296 return SkNEW_ARGS(SkTestScalerContext, (const_cast<SkTestTypeface*>(this), d
esc)); | 296 return SkNEW_ARGS(SkTestScalerContext, (const_cast<SkTestTypeface*>(this), d
esc)); |
| 297 } | 297 } |
| OLD | NEW |