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

Unified Diff: src/ports/SkFontHost_win.cpp

Issue 21047008: Fix subpixel metrics with GDI. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Move global now that there is one fewer user. Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontHost_win.cpp
===================================================================
--- src/ports/SkFontHost_win.cpp (revision 10422)
+++ src/ports/SkFontHost_win.cpp (working copy)
@@ -550,14 +550,17 @@
* Used to find the magnitude of advances.
*/
MAT2 fGsA;
+ /** The total matrix without the textSize. */
MAT2 fMat22;
+ /** Scales font to EM size. */
+ MAT2 fHighResMat22;
HDC fDDC;
HFONT fSavefont;
HFONT fFont;
- HFONT fHiResFont;
SCRIPT_CACHE fSC;
int fGlyphCount;
+ /** The total matrix which also removes EM scale. */
SkMatrix fHiResMatrix;
/** fG_inv is the inverse of the rotational part of the total matrix.
* Used to set the direction of advances.
@@ -595,7 +598,6 @@
, fDDC(0)
, fSavefont(0)
, fFont(0)
- , fHiResFont(0)
, fSC(0)
, fGlyphCount(-1)
{
@@ -735,16 +737,17 @@
success = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm);
}
if (0 != success) {
- lf.lfHeight = -SkToS32(otm.otmEMSquare);
- fHiResFont = CreateFontIndirect(&lf);
- if (!fHiResFont) {
- return;
- }
+ SkScalar scale = SkIntToScalar(otm.otmEMSquare);
- // construct a matrix to go from HIRES logical units to our device units
- fRec.getSingleMatrix(&fHiResMatrix);
- SkScalar scale = SkScalarInvert(SkIntToScalar(otm.otmEMSquare));
- fHiResMatrix.preScale(scale, scale);
+ SkScalar textScale = scale / textSize;
+ fHighResMat22.eM11 = float2FIXED(textScale);
+ fHighResMat22.eM12 = float2FIXED(0);
+ fHighResMat22.eM21 = float2FIXED(0);
+ fHighResMat22.eM22 = float2FIXED(textScale);
+
+ SkScalar invScale = SkScalarInvert(scale);
+ fHiResMatrix = A;
+ fHiResMatrix.preScale(invScale, invScale);
}
}
@@ -778,9 +781,6 @@
if (fFont) {
::DeleteObject(fFont);
}
- if (fHiResFont) {
- ::DeleteObject(fHiResFont);
- }
if (fSC) {
::ScriptFreeCache(&fSC);
}
@@ -827,7 +827,6 @@
this->generateMetrics(glyph);
}
-static const MAT2 gMat2Identity = {{0, 1}, {0, 0}, {0, 0}, {0, 1}};
void SkScalerContext_Windows::generateMetrics(SkGlyph* glyph) {
SkASSERT(fDDC);
@@ -898,17 +897,15 @@
glyph->fRsbDelta = 0;
glyph->fLsbDelta = 0;
- if (fHiResFont) {
- SelectObject(fDDC, fHiResFont);
+ if (this->isSubpixel()) {
sk_bzero(&gm, sizeof(gm));
- status = GetGlyphOutlineW(fDDC, glyphId, GGO_METRICS | GGO_GLYPH_INDEX, &gm, 0, NULL, &gMat2Identity);
+ status = GetGlyphOutlineW(fDDC, glyphId, GGO_METRICS | GGO_GLYPH_INDEX, &gm, 0, NULL, &fHighResMat22);
if (GDI_ERROR != status) {
SkPoint advance;
fHiResMatrix.mapXY(SkIntToScalar(gm.gmCellIncX), SkIntToScalar(gm.gmCellIncY), &advance);
glyph->fAdvanceX = SkScalarToFixed(advance.fX);
glyph->fAdvanceY = SkScalarToFixed(advance.fY);
}
- SelectObject(fDDC, fFont);
} else if (!isAxisAligned(this->fRec)) {
status = GetGlyphOutlineW(fDDC, glyphId, GGO_METRICS | GGO_GLYPH_INDEX, &gm, 0, NULL, &fGsA);
if (GDI_ERROR != status) {
@@ -920,6 +917,7 @@
}
}
+static const MAT2 gMat2Identity = {{0, 1}, {0, 0}, {0, 0}, {0, 1}};
void SkScalerContext_Windows::generateFontMetrics(SkPaint::FontMetrics* mx, SkPaint::FontMetrics* my) {
if (!(mx || my)) {
return;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698