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