Add a test showing that GDI should not scale bitmap font metrics

Dmitry Timoshkov dmitry at baikal.ru
Wed Sep 1 04:49:14 CDT 2004


"Huw D M Davies" <h.davies1 at physics.ox.ac.uk> wrote:

> > I had a wild guess whether GDI actually scales or not metrics for
> > a bitmap font if a requested font size is not available and wrote
> > a test case for it. No, GDI *does not* scale bitmap font metrics.
> 
> Well it does do integer scaling.  So if you request System (whose
> normal size is 16) with 32 <= lfHeight < 48 you'll get a double sized
> font with all the metrics scaled by a factor of two.  Wine doesn't do
> this yet.  Your test shows that gdi doesn't do fractional scaling which
> is indeed correct.

Thanks for pointing this out. A quick addition to the submitted test
case (attached) confirms that win2k does integer scaling. But it does
it in a somewhat inconsistent manner. For instance GetTextExtentPoint32
scales only height but not width, and GetCharWidth does not scale width
either. I'm a bit confused, is that a bug or a feature?

-- 
Dmitry.
-------------- next part --------------
--- cvs/hq/wine/dlls/gdi/tests/gdiobj.c	Wed Sep 01 08:36:31 2004
+++ wine/dlls/gdi/tests/gdiobj.c	Wed Sep 01 09:42:51 2004
@@ -98,7 +98,7 @@ static void test_bitmap_font(void)
     HFONT hfont, old_hfont;
     TEXTMETRICA tm, tm_orig;
     SIZE size, size_orig;
-    INT ret, i, width, width_orig;
+    INT ret, i, width, width_orig, height_orig;
 
     hdc = GetDC(0);
 
@@ -113,6 +113,7 @@ static void test_bitmap_font(void)
 
     trace("found bitmap font %s, height %ld\n", bitmap_lf.lfFaceName, bitmap_lf.lfHeight);
 
+    height_orig = bitmap_lf.lfHeight;
     hfont = CreateFontIndirectA(&bitmap_lf);
     assert(hfont);
 
@@ -123,7 +124,8 @@ static void test_bitmap_font(void)
     SelectObject(hdc, old_hfont);
     DeleteObject(hfont);
 
-    for (i = 1; i < 20; i++)
+    /* test fractional scaling */
+    for (i = 1; i < height_orig; i++)
     {
 	bitmap_lf.lfHeight = i;
 	hfont = CreateFontIndirectA(&bitmap_lf);
@@ -155,6 +157,37 @@ static void test_bitmap_font(void)
 	SelectObject(hdc, old_hfont);
 	DeleteObject(hfont);
     }
+
+    /* test integer scaling */
+    bitmap_lf.lfHeight = height_orig * 2;
+    hfont = CreateFontIndirectA(&bitmap_lf);
+    assert(hfont);
+
+    ret = GetObject(hfont, sizeof(lf), &lf);
+    ok(ret == sizeof(lf), "GetObject failed: %d\n", ret);
+    ok(!memcmp(&bitmap_lf, &lf, STRUCTOFFSET(LOGFONTA, lfFaceName)), "fonts don't match\n");
+    ok(!lstrcmpA(bitmap_lf.lfFaceName, lf.lfFaceName),
+       "font names don't match: %s != %s\n", bitmap_lf.lfFaceName, lf.lfFaceName);
+
+    old_hfont = SelectObject(hdc, hfont);
+
+    ok(GetTextMetricsA(hdc, &tm), "GetTextMetricsA failed\n");
+
+    ok(tm.tmHeight == tm_orig.tmHeight*2, "%ld != %ld\n", tm.tmHeight, tm_orig.tmHeight*2);
+    ok(tm.tmAscent == tm_orig.tmAscent*2, "%ld != %ld\n", tm.tmAscent, tm_orig.tmAscent*2);
+    ok(tm.tmDescent == tm_orig.tmDescent*2, "%ld != %ld\n", tm.tmDescent, tm_orig.tmDescent*2);
+    ok(tm.tmInternalLeading == tm_orig.tmInternalLeading*2, "%ld != %ld\n", tm.tmInternalLeading, tm_orig.tmInternalLeading*2);
+    ok(tm.tmExternalLeading == tm_orig.tmExternalLeading*2, "%ld != %ld\n", tm.tmExternalLeading, tm_orig.tmExternalLeading*2);
+
+    ok(GetTextExtentPoint32A(hdc, test_str, sizeof(test_str), &size), "GetTextExtentPoint32A failed\n");
+    ok(size.cx == size_orig.cx, "%ld != %ld\n", size.cx, size_orig.cx);
+    ok(size.cy == size_orig.cy*2, "%ld != %ld\n", size.cy, size_orig.cy*2);
+
+    ok(GetCharWidthA(hdc, 'A', 'A', &width), "GetCharWidthA failed\n");
+    ok(width == width_orig, "%d != %d\n", width, width_orig);
+
+    SelectObject(hdc, old_hfont);
+    DeleteObject(hfont);
 
     ReleaseDC(0, hdc);
 }


More information about the wine-devel mailing list