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 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 // G is the Given's Matrix for A (rotational matrix such that GA[0][1] == 0)
. | 656 // G is the Given's Matrix for A (rotational matrix such that GA[0][1] == 0)
. |
657 SkMatrix G; | 657 SkMatrix G; |
658 G.setAll(c, -s, 0, | 658 G.setAll(c, -s, 0, |
659 s, c, 0, | 659 s, c, 0, |
660 0, 0, SkScalarToPersp(SK_Scalar1)); | 660 0, 0, SkScalarToPersp(SK_Scalar1)); |
661 | 661 |
662 // GA is the matrix A with rotation removed. | 662 // GA is the matrix A with rotation removed. |
663 SkMatrix GA(G); | 663 SkMatrix GA(G); |
664 GA.preConcat(A); | 664 GA.preConcat(A); |
665 | 665 |
666 // textSize is the actual device size we want (as opposed to the size the us
er requested). | 666 // realTextSize is the actual device size we want (as opposed to the size th
e user requested). |
| 667 // gdiTextSizde is the size we request from GDI. |
667 // If the scale is negative, this means the matrix will do the flip anyway. | 668 // If the scale is negative, this means the matrix will do the flip anyway. |
668 SkScalar textSize = SkScalarAbs(SkScalarRoundToScalar(GA.get(SkMatrix::kMSca
leY))); | 669 SkScalar realTextSize = SkScalarAbs(GA.get(SkMatrix::kMScaleY)); |
669 if (textSize == 0) { | 670 SkScalar gdiTextSize = SkScalarRoundToScalar(realTextSize); |
670 textSize = SK_Scalar1; | 671 if (gdiTextSize == 0) { |
| 672 gdiTextSize = SK_Scalar1; |
671 } | 673 } |
672 | 674 |
| 675 // When not hinting, remove only the gdiTextSize scale which will be applied
by GDI. |
| 676 // When GDI hinting, remove the entire Y scale to prevent 'subpixel' metrics
. |
| 677 SkScalar scale = (fRec.getHinting() == SkPaint::kNo_Hinting || |
| 678 fRec.getHinting() == SkPaint::kSlight_Hinting) |
| 679 ? SkScalarInvert(gdiTextSize) |
| 680 : SkScalarInvert(realTextSize); |
| 681 |
673 // sA is the total matrix A without the textSize (so GDI knows the text size
separately). | 682 // sA is the total matrix A without the textSize (so GDI knows the text size
separately). |
674 // When this matrix is used with GetGlyphOutline, no further processing is n
eeded. | 683 // When this matrix is used with GetGlyphOutline, no further processing is n
eeded. |
675 SkMatrix sA(A); | 684 SkMatrix sA(A); |
676 SkScalar scale = SkScalarInvert(textSize); | |
677 sA.preScale(scale, scale); //remove text size | 685 sA.preScale(scale, scale); //remove text size |
678 | 686 |
679 // GsA is the non-rotational part of A without the text height scale. | 687 // GsA is the non-rotational part of A without the text height scale. |
680 // This is what is used to find the magnitude of advances. | 688 // This is what is used to find the magnitude of advances. |
681 SkMatrix GsA(GA); | 689 SkMatrix GsA(GA); |
682 GsA.preScale(scale, scale); //remove text size, G is rotational so reorders
with the scale. | 690 GsA.preScale(scale, scale); //remove text size, G is rotational so reorders
with the scale. |
683 | 691 |
684 fGsA.eM11 = SkScalarToFIXED(GsA.get(SkMatrix::kMScaleX)); | 692 fGsA.eM11 = SkScalarToFIXED(GsA.get(SkMatrix::kMScaleX)); |
685 fGsA.eM12 = SkScalarToFIXED(-GsA.get(SkMatrix::kMSkewY)); // This should be
~0. | 693 fGsA.eM12 = SkScalarToFIXED(-GsA.get(SkMatrix::kMSkewY)); // This should be
~0. |
686 fGsA.eM21 = SkScalarToFIXED(-GsA.get(SkMatrix::kMSkewX)); | 694 fGsA.eM21 = SkScalarToFIXED(-GsA.get(SkMatrix::kMSkewX)); |
687 fGsA.eM22 = SkScalarToFIXED(GsA.get(SkMatrix::kMScaleY)); | 695 fGsA.eM22 = SkScalarToFIXED(GsA.get(SkMatrix::kMScaleY)); |
688 | 696 |
689 // fG_inv is G inverse, which is fairly simple since G is 2x2 rotational. | 697 // fG_inv is G inverse, which is fairly simple since G is 2x2 rotational. |
690 fG_inv.setAll(G.get(SkMatrix::kMScaleX), -G.get(SkMatrix::kMSkewX), G.get(Sk
Matrix::kMTransX), | 698 fG_inv.setAll(G.get(SkMatrix::kMScaleX), -G.get(SkMatrix::kMSkewX), G.get(Sk
Matrix::kMTransX), |
691 -G.get(SkMatrix::kMSkewY), G.get(SkMatrix::kMScaleY), G.get(Sk
Matrix::kMTransY), | 699 -G.get(SkMatrix::kMSkewY), G.get(SkMatrix::kMScaleY), G.get(Sk
Matrix::kMTransY), |
692 G.get(SkMatrix::kMPersp0), G.get(SkMatrix::kMPersp1), G.get(Sk
Matrix::kMPersp2)); | 700 G.get(SkMatrix::kMPersp0), G.get(SkMatrix::kMPersp1), G.get(Sk
Matrix::kMPersp2)); |
693 | 701 |
694 LOGFONT lf = typeface->fLogFont; | 702 LOGFONT lf = typeface->fLogFont; |
695 lf.lfHeight = -SkScalarTruncToInt(textSize); | 703 lf.lfHeight = -SkScalarTruncToInt(gdiTextSize); |
696 lf.lfQuality = compute_quality(fRec); | 704 lf.lfQuality = compute_quality(fRec); |
697 fFont = CreateFontIndirect(&lf); | 705 fFont = CreateFontIndirect(&lf); |
698 if (!fFont) { | 706 if (!fFont) { |
699 return; | 707 return; |
700 } | 708 } |
701 | 709 |
702 fSavefont = (HFONT)SelectObject(fDDC, fFont); | 710 fSavefont = (HFONT)SelectObject(fDDC, fFont); |
703 | 711 |
704 if (0 == GetTextMetrics(fDDC, &fTM)) { | 712 if (0 == GetTextMetrics(fDDC, &fTM)) { |
705 call_ensure_accessible(lf); | 713 call_ensure_accessible(lf); |
(...skipping 29 matching lines...) Expand all Loading... |
735 // MAT2 is row major, right handed (y up). | 743 // MAT2 is row major, right handed (y up). |
736 fMat22.eM11 = float2FIXED(xform.eM11); | 744 fMat22.eM11 = float2FIXED(xform.eM11); |
737 fMat22.eM12 = float2FIXED(-xform.eM12); | 745 fMat22.eM12 = float2FIXED(-xform.eM12); |
738 fMat22.eM21 = float2FIXED(-xform.eM21); | 746 fMat22.eM21 = float2FIXED(-xform.eM21); |
739 fMat22.eM22 = float2FIXED(xform.eM22); | 747 fMat22.eM22 = float2FIXED(xform.eM22); |
740 | 748 |
741 if (needToRenderWithSkia(fRec)) { | 749 if (needToRenderWithSkia(fRec)) { |
742 this->forceGenerateImageFromPath(); | 750 this->forceGenerateImageFromPath(); |
743 } | 751 } |
744 | 752 |
745 // Create a hires font if we need linear metrics. | 753 // Create a hires matrix if we need linear metrics. |
746 if (this->isSubpixel()) { | 754 if (this->isSubpixel()) { |
747 OUTLINETEXTMETRIC otm; | 755 OUTLINETEXTMETRIC otm; |
748 UINT success = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm); | 756 UINT success = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm); |
749 if (0 == success) { | 757 if (0 == success) { |
750 call_ensure_accessible(lf); | 758 call_ensure_accessible(lf); |
751 success = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm); | 759 success = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm); |
752 } | 760 } |
753 if (0 != success) { | 761 if (0 != success) { |
754 SkScalar scale = SkIntToScalar(otm.otmEMSquare); | 762 SkScalar upem = SkIntToScalar(otm.otmEMSquare); |
755 | 763 |
756 SkScalar textScale = scale / textSize; | 764 SkScalar gdiTextSizeToEMScale = upem / gdiTextSize; |
757 fHighResMat22.eM11 = float2FIXED(textScale); | 765 fHighResMat22.eM11 = float2FIXED(gdiTextSizeToEMScale); |
758 fHighResMat22.eM12 = float2FIXED(0); | 766 fHighResMat22.eM12 = float2FIXED(0); |
759 fHighResMat22.eM21 = float2FIXED(0); | 767 fHighResMat22.eM21 = float2FIXED(0); |
760 fHighResMat22.eM22 = float2FIXED(textScale); | 768 fHighResMat22.eM22 = float2FIXED(gdiTextSizeToEMScale); |
761 | 769 |
762 SkScalar invScale = SkScalarInvert(scale); | 770 SkScalar removeEMScale = SkScalarInvert(upem); |
763 fHiResMatrix = A; | 771 fHiResMatrix = A; |
764 fHiResMatrix.preScale(invScale, invScale); | 772 fHiResMatrix.preScale(removeEMScale, removeEMScale); |
765 } | 773 } |
766 } | 774 } |
767 | 775 |
768 } else { | 776 } else { |
769 // Assume bitmap | 777 // Assume bitmap |
770 fType = SkScalerContext_GDI::kBitmap_Type; | 778 fType = SkScalerContext_GDI::kBitmap_Type; |
771 | 779 |
772 xform.eM11 = 1.0f; | 780 xform.eM11 = 1.0f; |
773 xform.eM12 = 0.0f; | 781 xform.eM12 = 0.0f; |
774 xform.eM21 = 0.0f; | 782 xform.eM21 = 0.0f; |
(...skipping 1632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2407 | 2415 |
2408 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { | 2416 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { |
2409 return create_from_stream(stream); | 2417 return create_from_stream(stream); |
2410 } | 2418 } |
2411 | 2419 |
2412 #endif | 2420 #endif |
2413 | 2421 |
2414 SkFontMgr* SkFontMgr_New_GDI() { | 2422 SkFontMgr* SkFontMgr_New_GDI() { |
2415 return SkNEW(SkFontMgrGDI); | 2423 return SkNEW(SkFontMgrGDI); |
2416 } | 2424 } |
OLD | NEW |