Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(845)

Side by Side Diff: src/ports/SkFontHost_win.cpp

Issue 1737693006: Change type of SkGlyph::fAdvance[XY] to float. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Should be float, not SkScalar. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ports/SkFontHost_mac.cpp ('k') | src/ports/SkScalerContext_win_dw.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkTypes.h" 8 #include "SkTypes.h"
9 #if defined(SK_BUILD_FOR_WIN32) 9 #if defined(SK_BUILD_FOR_WIN32)
10 10
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 enum Type { 577 enum Type {
578 kTrueType_Type, kBitmap_Type, kLine_Type 578 kTrueType_Type, kBitmap_Type, kLine_Type
579 } fType; 579 } fType;
580 TEXTMETRIC fTM; 580 TEXTMETRIC fTM;
581 }; 581 };
582 582
583 static FIXED float2FIXED(float x) { 583 static FIXED float2FIXED(float x) {
584 return SkFixedToFIXED(SkFloatToFixed(x)); 584 return SkFixedToFIXED(SkFloatToFixed(x));
585 } 585 }
586 586
587 static inline float FIXED2float(FIXED x) {
588 return SkFixedToFloat(SkFIXEDToFixed(x));
589 }
590
587 static BYTE compute_quality(const SkScalerContext::Rec& rec) { 591 static BYTE compute_quality(const SkScalerContext::Rec& rec) {
588 switch (rec.fMaskFormat) { 592 switch (rec.fMaskFormat) {
589 case SkMask::kBW_Format: 593 case SkMask::kBW_Format:
590 return NONANTIALIASED_QUALITY; 594 return NONANTIALIASED_QUALITY;
591 case SkMask::kLCD16_Format: 595 case SkMask::kLCD16_Format:
592 return CLEARTYPE_QUALITY; 596 return CLEARTYPE_QUALITY;
593 default: 597 default:
594 if (rec.fFlags & SkScalerContext::kGenA8FromLCD_Flag) { 598 if (rec.fFlags & SkScalerContext::kGenA8FromLCD_Flag) {
595 return CLEARTYPE_QUALITY; 599 return CLEARTYPE_QUALITY;
596 } else { 600 } else {
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 glyph->fWidth = SkToS16(fTM.tmMaxCharWidth); 853 glyph->fWidth = SkToS16(fTM.tmMaxCharWidth);
850 } else { 854 } else {
851 glyph->fWidth = SkToS16(size.cx); 855 glyph->fWidth = SkToS16(size.cx);
852 } 856 }
853 glyph->fHeight = SkToS16(size.cy); 857 glyph->fHeight = SkToS16(size.cy);
854 858
855 glyph->fTop = SkToS16(-fTM.tmAscent); 859 glyph->fTop = SkToS16(-fTM.tmAscent);
856 // Bitmap FON cannot underhang, but vector FON may. 860 // Bitmap FON cannot underhang, but vector FON may.
857 // There appears no means of determining underhang of vector FON. 861 // There appears no means of determining underhang of vector FON.
858 glyph->fLeft = SkToS16(0); 862 glyph->fLeft = SkToS16(0);
859 glyph->fAdvanceX = SkIntToFixed(glyph->fWidth); 863 glyph->fAdvanceX = glyph->fWidth;
860 glyph->fAdvanceY = 0; 864 glyph->fAdvanceY = 0;
861 865
862 // Vector FON will transform nicely, but bitmap FON do not. 866 // Vector FON will transform nicely, but bitmap FON do not.
863 if (fType == SkScalerContext_GDI::kLine_Type) { 867 if (fType == SkScalerContext_GDI::kLine_Type) {
864 SkRect bounds = SkRect::MakeXYWH(glyph->fLeft, glyph->fTop, 868 SkRect bounds = SkRect::MakeXYWH(glyph->fLeft, glyph->fTop,
865 glyph->fWidth, glyph->fHeight); 869 glyph->fWidth, glyph->fHeight);
866 SkMatrix m; 870 SkMatrix m;
867 m.setAll(SkFIXEDToScalar(fMat22.eM11), -SkFIXEDToScalar(fMat22.eM21) , 0, 871 m.setAll(SkFIXEDToScalar(fMat22.eM11), -SkFIXEDToScalar(fMat22.eM21) , 0,
868 -SkFIXEDToScalar(fMat22.eM12), SkFIXEDToScalar(fMat22.eM22) , 0, 872 -SkFIXEDToScalar(fMat22.eM12), SkFIXEDToScalar(fMat22.eM22) , 0,
869 0, 0, 1); 873 0, 0, 1);
870 m.mapRect(&bounds); 874 m.mapRect(&bounds);
871 bounds.roundOut(&bounds); 875 bounds.roundOut(&bounds);
872 glyph->fLeft = SkScalarTruncToInt(bounds.fLeft); 876 glyph->fLeft = SkScalarTruncToInt(bounds.fLeft);
873 glyph->fTop = SkScalarTruncToInt(bounds.fTop); 877 glyph->fTop = SkScalarTruncToInt(bounds.fTop);
874 glyph->fWidth = SkScalarTruncToInt(bounds.width()); 878 glyph->fWidth = SkScalarTruncToInt(bounds.width());
875 glyph->fHeight = SkScalarTruncToInt(bounds.height()); 879 glyph->fHeight = SkScalarTruncToInt(bounds.height());
876 } 880 }
877 881
878 // Apply matrix to advance. 882 // Apply matrix to advance.
879 glyph->fAdvanceY = SkFixedMul(-SkFIXEDToFixed(fMat22.eM12), glyph->fAdva nceX); 883 glyph->fAdvanceY = -FIXED2float(fMat22.eM12) * glyph->fAdvanceX;
880 glyph->fAdvanceX = SkFixedMul(SkFIXEDToFixed(fMat22.eM11), glyph->fAdvan ceX); 884 glyph->fAdvanceX *= FIXED2float(fMat22.eM11);
881 885
882 return; 886 return;
883 } 887 }
884 888
885 UINT glyphId = glyph->getGlyphID(); 889 UINT glyphId = glyph->getGlyphID();
886 890
887 GLYPHMETRICS gm; 891 GLYPHMETRICS gm;
888 sk_bzero(&gm, sizeof(gm)); 892 sk_bzero(&gm, sizeof(gm));
889 893
890 DWORD status = GetGlyphOutlineW(fDDC, glyphId, GGO_METRICS | GGO_GLYPH_INDEX , &gm, 0, nullptr, &fMat22); 894 DWORD status = GetGlyphOutlineW(fDDC, glyphId, GGO_METRICS | GGO_GLYPH_INDEX , &gm, 0, nullptr, &fMat22);
(...skipping 24 matching lines...) Expand all
915 } else { 919 } else {
916 // Outset, since the image may bleed out of the black box. 920 // Outset, since the image may bleed out of the black box.
917 // For embedded bitmaps the black box should be exact. 921 // For embedded bitmaps the black box should be exact.
918 // For outlines we need to outset by 1 in all directions for bleed. 922 // For outlines we need to outset by 1 in all directions for bleed.
919 // For ClearType we need to outset by 2 for bleed. 923 // For ClearType we need to outset by 2 for bleed.
920 glyph->fWidth = gm.gmBlackBoxX + 4; 924 glyph->fWidth = gm.gmBlackBoxX + 4;
921 glyph->fHeight = gm.gmBlackBoxY + 4; 925 glyph->fHeight = gm.gmBlackBoxY + 4;
922 glyph->fTop -= 2; 926 glyph->fTop -= 2;
923 glyph->fLeft -= 2; 927 glyph->fLeft -= 2;
924 } 928 }
925 glyph->fAdvanceX = SkIntToFixed(gm.gmCellIncX); 929 // TODO(benjaminwagner): What is the type of gm.gmCellInc[XY]?
926 glyph->fAdvanceY = SkIntToFixed(gm.gmCellIncY); 930 glyph->fAdvanceX = (float)((int)gm.gmCellIncX);
931 glyph->fAdvanceY = (float)((int)gm.gmCellIncY);
927 glyph->fRsbDelta = 0; 932 glyph->fRsbDelta = 0;
928 glyph->fLsbDelta = 0; 933 glyph->fLsbDelta = 0;
929 934
930 if (this->isSubpixel()) { 935 if (this->isSubpixel()) {
931 sk_bzero(&gm, sizeof(gm)); 936 sk_bzero(&gm, sizeof(gm));
932 status = GetGlyphOutlineW(fDDC, glyphId, GGO_METRICS | GGO_GLYPH_INDEX, &gm, 0, nullptr, &fHighResMat22); 937 status = GetGlyphOutlineW(fDDC, glyphId, GGO_METRICS | GGO_GLYPH_INDEX, &gm, 0, nullptr, &fHighResMat22);
933 if (GDI_ERROR != status) { 938 if (GDI_ERROR != status) {
934 SkPoint advance; 939 SkPoint advance;
935 fHiResMatrix.mapXY(SkIntToScalar(gm.gmCellIncX), SkIntToScalar(gm.gm CellIncY), &advance); 940 fHiResMatrix.mapXY(SkIntToScalar(gm.gmCellIncX), SkIntToScalar(gm.gm CellIncY), &advance);
936 glyph->fAdvanceX = SkScalarToFixed(advance.fX); 941 glyph->fAdvanceX = SkScalarToFloat(advance.fX);
937 glyph->fAdvanceY = SkScalarToFixed(advance.fY); 942 glyph->fAdvanceY = SkScalarToFloat(advance.fY);
938 } 943 }
939 } else if (!isAxisAligned(this->fRec)) { 944 } else if (!isAxisAligned(this->fRec)) {
940 status = GetGlyphOutlineW(fDDC, glyphId, GGO_METRICS | GGO_GLYPH_INDEX, &gm, 0, nullptr, &fGsA); 945 status = GetGlyphOutlineW(fDDC, glyphId, GGO_METRICS | GGO_GLYPH_INDEX, &gm, 0, nullptr, &fGsA);
941 if (GDI_ERROR != status) { 946 if (GDI_ERROR != status) {
942 SkPoint advance; 947 SkPoint advance;
943 fG_inv.mapXY(SkIntToScalar(gm.gmCellIncX), SkIntToScalar(gm.gmCellIn cY), &advance); 948 fG_inv.mapXY(SkIntToScalar(gm.gmCellIncX), SkIntToScalar(gm.gmCellIn cY), &advance);
944 glyph->fAdvanceX = SkScalarToFixed(advance.fX); 949 glyph->fAdvanceX = SkScalarToFloat(advance.fX);
945 glyph->fAdvanceY = SkScalarToFixed(advance.fY); 950 glyph->fAdvanceY = SkScalarToFloat(advance.fY);
946 } 951 }
947 } 952 }
948 } 953 }
949 954
950 static const MAT2 gMat2Identity = {{0, 1}, {0, 0}, {0, 0}, {0, 1}}; 955 static const MAT2 gMat2Identity = {{0, 1}, {0, 0}, {0, 0}, {0, 1}};
951 void SkScalerContext_GDI::generateFontMetrics(SkPaint::FontMetrics* metrics) { 956 void SkScalerContext_GDI::generateFontMetrics(SkPaint::FontMetrics* metrics) {
952 if (nullptr == metrics) { 957 if (nullptr == metrics) {
953 return; 958 return;
954 } 959 }
955 sk_bzero(metrics, sizeof(*metrics)); 960 sk_bzero(metrics, sizeof(*metrics));
(...skipping 1553 matching lines...) Expand 10 before | Expand all | Expand 10 after
2509 2514
2510 private: 2515 private:
2511 SkTDArray<ENUMLOGFONTEX> fLogFontArray; 2516 SkTDArray<ENUMLOGFONTEX> fLogFontArray;
2512 }; 2517 };
2513 2518
2514 /////////////////////////////////////////////////////////////////////////////// 2519 ///////////////////////////////////////////////////////////////////////////////
2515 2520
2516 SkFontMgr* SkFontMgr_New_GDI() { return new SkFontMgrGDI; } 2521 SkFontMgr* SkFontMgr_New_GDI() { return new SkFontMgrGDI; }
2517 2522
2518 #endif//defined(SK_BUILD_FOR_WIN32) 2523 #endif//defined(SK_BUILD_FOR_WIN32)
OLDNEW
« no previous file with comments | « src/ports/SkFontHost_mac.cpp ('k') | src/ports/SkScalerContext_win_dw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698