Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2006-2012 The Android Open Source Project | 2 * Copyright 2006-2012 The Android Open Source Project |
| 3 * Copyright 2012 Mozilla Foundation | 3 * Copyright 2012 Mozilla Foundation |
| 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 "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 case SkMask::kLCD16_Format: | 327 case SkMask::kLCD16_Format: |
| 328 return kAlpha_8_SkColorType; | 328 return kAlpha_8_SkColorType; |
| 329 case SkMask::kARGB32_Format: | 329 case SkMask::kARGB32_Format: |
| 330 return kN32_SkColorType; | 330 return kN32_SkColorType; |
| 331 default: | 331 default: |
| 332 SkDEBUGFAIL("unsupported destination SkBitmap::Config"); | 332 SkDEBUGFAIL("unsupported destination SkBitmap::Config"); |
| 333 return kAlpha_8_SkColorType; | 333 return kAlpha_8_SkColorType; |
| 334 } | 334 } |
| 335 } | 335 } |
| 336 | 336 |
| 337 void SkScalerContext_FreeType_Base::generateGlyphImage(FT_Face face, const SkGly ph& glyph) { | 337 void SkScalerContext_FreeType_Base::generateGlyphImage( |
| 338 FT_Face face, | |
| 339 const SkGlyph& glyph, | |
| 340 const SkMatrix& bitmapTransform) | |
| 341 { | |
| 338 const bool doBGR = SkToBool(fRec.fFlags & SkScalerContext::kLCD_BGROrder_Fla g); | 342 const bool doBGR = SkToBool(fRec.fFlags & SkScalerContext::kLCD_BGROrder_Fla g); |
| 339 const bool doVert = SkToBool(fRec.fFlags & SkScalerContext::kLCD_Vertical_Fl ag); | 343 const bool doVert = SkToBool(fRec.fFlags & SkScalerContext::kLCD_Vertical_Fl ag); |
| 340 | 344 |
| 341 switch ( face->glyph->format ) { | 345 switch ( face->glyph->format ) { |
| 342 case FT_GLYPH_FORMAT_OUTLINE: { | 346 case FT_GLYPH_FORMAT_OUTLINE: { |
| 343 FT_Outline* outline = &face->glyph->outline; | 347 FT_Outline* outline = &face->glyph->outline; |
| 344 FT_BBox bbox; | 348 FT_BBox bbox; |
| 345 FT_Bitmap target; | 349 FT_Bitmap target; |
| 346 | 350 |
| 347 int dx = 0, dy = 0; | 351 int dx = 0, dy = 0; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 | 408 |
| 405 if (fRec.fFlags & SkScalerContext::kEmbolden_Flag && | 409 if (fRec.fFlags & SkScalerContext::kEmbolden_Flag && |
| 406 !(face->style_flags & FT_STYLE_FLAG_BOLD)) | 410 !(face->style_flags & FT_STYLE_FLAG_BOLD)) |
| 407 { | 411 { |
| 408 FT_GlyphSlot_Own_Bitmap(face->glyph); | 412 FT_GlyphSlot_Own_Bitmap(face->glyph); |
| 409 FT_Bitmap_Embolden(face->glyph->library, &face->glyph->bitmap, | 413 FT_Bitmap_Embolden(face->glyph->library, &face->glyph->bitmap, |
| 410 kBitmapEmboldenStrength, 0); | 414 kBitmapEmboldenStrength, 0); |
| 411 } | 415 } |
| 412 | 416 |
| 413 // If no scaling needed, directly copy glyph bitmap. | 417 // If no scaling needed, directly copy glyph bitmap. |
| 414 if (glyph.fWidth == face->glyph->bitmap.width && | 418 if (bitmapTransform.isIdentity()) { |
| 415 glyph.fHeight == face->glyph->bitmap.rows && | |
| 416 glyph.fTop == -face->glyph->bitmap_top && | |
| 417 glyph.fLeft == face->glyph->bitmap_left) | |
| 418 { | |
| 419 SkMask dstMask; | 419 SkMask dstMask; |
| 420 glyph.toMask(&dstMask); | 420 glyph.toMask(&dstMask); |
| 421 copyFTBitmap(face->glyph->bitmap, dstMask); | 421 copyFTBitmap(face->glyph->bitmap, dstMask); |
| 422 break; | 422 break; |
| 423 } | 423 } |
| 424 | 424 |
| 425 // Otherwise, scale the bitmap. | 425 // Otherwise, scale the bitmap. |
| 426 | 426 |
| 427 // Copy the FT_Bitmap into an SkBitmap (either A8 or ARGB) | 427 // Copy the FT_Bitmap into an SkBitmap (either A8 or ARGB) |
| 428 SkBitmap unscaledBitmap; | 428 SkBitmap unscaledBitmap; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 452 kPremul_SkAlphaType), | 452 kPremul_SkAlphaType), |
| 453 bitmapRowBytes); | 453 bitmapRowBytes); |
| 454 if (SkMask::kBW_Format == maskFormat || SkMask::kLCD16_Format == mas kFormat) { | 454 if (SkMask::kBW_Format == maskFormat || SkMask::kLCD16_Format == mas kFormat) { |
| 455 dstBitmap.allocPixels(); | 455 dstBitmap.allocPixels(); |
| 456 } else { | 456 } else { |
| 457 dstBitmap.setPixels(glyph.fImage); | 457 dstBitmap.setPixels(glyph.fImage); |
| 458 } | 458 } |
| 459 | 459 |
| 460 // Scale unscaledBitmap into dstBitmap. | 460 // Scale unscaledBitmap into dstBitmap. |
| 461 SkCanvas canvas(dstBitmap); | 461 SkCanvas canvas(dstBitmap); |
| 462 #ifdef SK_SHOW_TEXT_BLIT_COVERAGE | |
| 463 canvas.clear(0x33FF0000); | |
| 464 #else | |
| 462 canvas.clear(SK_ColorTRANSPARENT); | 465 canvas.clear(SK_ColorTRANSPARENT); |
| 463 canvas.scale(SkIntToScalar(glyph.fWidth) / SkIntToScalar(face->glyph ->bitmap.width), | 466 #endif |
| 464 SkIntToScalar(glyph.fHeight) / SkIntToScalar(face->glyp h->bitmap.rows)); | 467 canvas.translate(-glyph.fLeft, -glyph.fTop); |
| 468 canvas.concat(bitmapTransform); | |
|
bungeman-skia
2016/07/11 22:18:42
For the no-skew case everything is the same except
| |
| 469 canvas.translate(face->glyph->bitmap_left, -face->glyph->bitmap_top) ; | |
| 470 | |
| 465 SkPaint paint; | 471 SkPaint paint; |
| 466 paint.setFilterQuality(kMedium_SkFilterQuality); | 472 paint.setFilterQuality(kMedium_SkFilterQuality); |
| 467 canvas.drawBitmap(unscaledBitmap, 0, 0, &paint); | 473 canvas.drawBitmap(unscaledBitmap, 0, 0, &paint); |
| 468 | 474 |
| 469 // If the destination is BW or LCD, convert from A8. | 475 // If the destination is BW or LCD, convert from A8. |
| 470 if (SkMask::kBW_Format == maskFormat) { | 476 if (SkMask::kBW_Format == maskFormat) { |
| 471 // Copy the A8 dstBitmap into the A1 glyph.fImage. | 477 // Copy the A8 dstBitmap into the A1 glyph.fImage. |
| 472 SkMask dstMask; | 478 SkMask dstMask; |
| 473 glyph.toMask(&dstMask); | 479 glyph.toMask(&dstMask); |
| 474 packA8ToA1(dstMask, dstBitmap.getAddr8(0, 0), dstBitmap.rowBytes ()); | 480 packA8ToA1(dstMask, dstBitmap.getAddr8(0, 0), dstBitmap.rowBytes ()); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 | 562 |
| 557 FT_Error err = FT_Outline_Decompose(&face->glyph->outline, &funcs, path); | 563 FT_Error err = FT_Outline_Decompose(&face->glyph->outline, &funcs, path); |
| 558 | 564 |
| 559 if (err != 0) { | 565 if (err != 0) { |
| 560 path->reset(); | 566 path->reset(); |
| 561 return; | 567 return; |
| 562 } | 568 } |
| 563 | 569 |
| 564 path->close(); | 570 path->close(); |
| 565 } | 571 } |
| OLD | NEW |