| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 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 "SkAdvancedTypefaceMetrics.h" | 9 #include "SkAdvancedTypefaceMetrics.h" |
| 10 #include "SkBase64.h" | 10 #include "SkBase64.h" |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 { | 609 { |
| 610 LogFontTypeface* typeface = reinterpret_cast<LogFontTypeface*>(rawTypeface); | 610 LogFontTypeface* typeface = reinterpret_cast<LogFontTypeface*>(rawTypeface); |
| 611 | 611 |
| 612 fDDC = ::CreateCompatibleDC(NULL); | 612 fDDC = ::CreateCompatibleDC(NULL); |
| 613 if (!fDDC) { | 613 if (!fDDC) { |
| 614 return; | 614 return; |
| 615 } | 615 } |
| 616 SetGraphicsMode(fDDC, GM_ADVANCED); | 616 SetGraphicsMode(fDDC, GM_ADVANCED); |
| 617 SetBkMode(fDDC, TRANSPARENT); | 617 SetBkMode(fDDC, TRANSPARENT); |
| 618 | 618 |
| 619 // When GDI hinting, remove the entire Y scale to prevent 'subpixel' metrics
. | 619 // When GDI hinting, remove the entire Y scale from sA and GsA. (Prevents 'l
inear' metrics.) |
| 620 // When not hinting, remove only the gdiTextSize scale which will be applied
by GDI. | 620 // When not hinting, remove only the integer Y scale from sA and GsA. (Appli
ed by GDI.) |
| 621 SkScalerContextRec::PreMatrixScale scaleConstraints = | 621 SkScalerContextRec::PreMatrixScale scaleConstraints = |
| 622 (fRec.getHinting() == SkPaint::kNo_Hinting || fRec.getHinting() == SkPai
nt::kSlight_Hinting) | 622 (fRec.getHinting() == SkPaint::kNo_Hinting || fRec.getHinting() == SkPai
nt::kSlight_Hinting) |
| 623 ? SkScalerContextRec::kVerticalInteger_PreMatrixScale | 623 ? SkScalerContextRec::kVerticalInteger_PreMatrixScale |
| 624 : SkScalerContextRec::kVertical_PreMatrixScale; | 624 : SkScalerContextRec::kVertical_PreMatrixScale; |
| 625 SkVector scale; | 625 SkVector scale; |
| 626 SkMatrix sA; | 626 SkMatrix sA; |
| 627 SkMatrix GsA; | 627 SkMatrix GsA; |
| 628 SkMatrix A; | 628 SkMatrix A; |
| 629 fRec.computeMatrices(scaleConstraints, &scale, &sA, &GsA, &fG_inv, &A); | 629 fRec.computeMatrices(scaleConstraints, &scale, &sA, &GsA, &fG_inv, &A); |
| 630 | 630 |
| 631 fGsA.eM11 = SkScalarToFIXED(GsA.get(SkMatrix::kMScaleX)); | 631 fGsA.eM11 = SkScalarToFIXED(GsA.get(SkMatrix::kMScaleX)); |
| 632 fGsA.eM12 = SkScalarToFIXED(-GsA.get(SkMatrix::kMSkewY)); // This should be
~0. | 632 fGsA.eM12 = SkScalarToFIXED(-GsA.get(SkMatrix::kMSkewY)); // This should be
~0. |
| 633 fGsA.eM21 = SkScalarToFIXED(-GsA.get(SkMatrix::kMSkewX)); | 633 fGsA.eM21 = SkScalarToFIXED(-GsA.get(SkMatrix::kMSkewX)); |
| 634 fGsA.eM22 = SkScalarToFIXED(GsA.get(SkMatrix::kMScaleY)); | 634 fGsA.eM22 = SkScalarToFIXED(GsA.get(SkMatrix::kMScaleY)); |
| 635 | 635 |
| 636 SkScalar gdiTextSize = scale.fY; | 636 // When not hinting, scale was computed with kVerticalInteger, so is already
an integer. |
| 637 // The sA and GsA transforms will be used to create 'linear' metrics. |
| 638 |
| 639 // When hinting, scale was computed with kVertical, stating that our port ca
n handle |
| 640 // non-integer scales. This is done so that sA and GsA are computed without
any 'residual' |
| 641 // scale in them, preventing 'linear' metrics. However, GDI cannot actually
handle non-integer |
| 642 // scales so we need to round in this case. This is fine, since all of the s
cale has been |
| 643 // removed from sA and GsA, so GDI will be handling the scale completely. |
| 644 SkScalar gdiTextSize = SkScalarRoundToScalar(scale.fY); |
| 645 |
| 646 // GDI will not accept a size of zero, so round the range [0, 1] to 1. |
| 647 // If the size was non-zero, the scale factors will also be non-zero and 1px
tall text is drawn. |
| 648 // If the size actually was zero, the scale factors will also be zero, so GD
I will draw nothing. |
| 637 if (gdiTextSize == 0) { | 649 if (gdiTextSize == 0) { |
| 638 gdiTextSize = SK_Scalar1; | 650 gdiTextSize = SK_Scalar1; |
| 639 } | 651 } |
| 640 | 652 |
| 641 LOGFONT lf = typeface->fLogFont; | 653 LOGFONT lf = typeface->fLogFont; |
| 642 lf.lfHeight = -SkScalarTruncToInt(gdiTextSize); | 654 lf.lfHeight = -SkScalarTruncToInt(gdiTextSize); |
| 643 lf.lfQuality = compute_quality(fRec); | 655 lf.lfQuality = compute_quality(fRec); |
| 644 fFont = CreateFontIndirect(&lf); | 656 fFont = CreateFontIndirect(&lf); |
| 645 if (!fFont) { | 657 if (!fFont) { |
| 646 return; | 658 return; |
| (...skipping 1865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2512 | 2524 |
| 2513 private: | 2525 private: |
| 2514 SkTDArray<ENUMLOGFONTEX> fLogFontArray; | 2526 SkTDArray<ENUMLOGFONTEX> fLogFontArray; |
| 2515 }; | 2527 }; |
| 2516 | 2528 |
| 2517 /////////////////////////////////////////////////////////////////////////////// | 2529 /////////////////////////////////////////////////////////////////////////////// |
| 2518 | 2530 |
| 2519 SkFontMgr* SkFontMgr_New_GDI() { | 2531 SkFontMgr* SkFontMgr_New_GDI() { |
| 2520 return SkNEW(SkFontMgrGDI); | 2532 return SkNEW(SkFontMgrGDI); |
| 2521 } | 2533 } |
| OLD | NEW |