Add a test showing that GDI should not scale bitmap font metrics
Dmitry Timoshkov
dmitry at baikal.ru
Wed Sep 1 03:44:19 CDT 2004
Hello,
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.
The test passes under Wine.
Changelog:
Dmitry Timoshkov <dmitry at codeweavers.com>
Add a test showing that GDI should not scale bitmap font metrics.
diff -u cvs/hq/wine/dlls/gdi/gdiobj.c wine/dlls/gdi/gdiobj.c
--- cvs/hq/wine/dlls/gdi/gdiobj.c Wed Sep 1 17:25:07 2004
+++ wine/dlls/gdi/gdiobj.c Wed Sep 1 17:18:19 2004
@@ -2,6 +2,7 @@
* Unit test suite for GDI objects
*
* Copyright 2002 Mike McCormack
+ * Copyright 2004 Dmitry Timoshkov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -76,7 +77,90 @@ static void test_logfont(void)
DeleteObject(hfont);
}
+static INT CALLBACK font_enum_proc(const LOGFONT *elf, const TEXTMETRIC *ntm, DWORD type, LPARAM lParam)
+{
+ if (type & RASTER_FONTTYPE)
+ {
+ LOGFONT *lf = (LOGFONT *)lParam;
+ *lf = *elf;
+ return 0; /* stop enumeration */
+ }
+
+ return 1; /* continue enumeration */
+}
+
+/* see whether GDI scales bitmap font metrics */
+static void test_bitmap_font(void)
+{
+ static const char test_str[11] = "Test String";
+ HDC hdc;
+ LOGFONTA bitmap_lf, lf;
+ HFONT hfont, old_hfont;
+ TEXTMETRICA tm, tm_orig;
+ SIZE size, size_orig;
+ INT ret, i, width, width_orig;
+
+ hdc = GetDC(0);
+
+ /* "System" has only 1 pixel size defined, otherwise the test breaks */
+ ret = EnumFontFamiliesA(hdc, "System", font_enum_proc, (LPARAM)&bitmap_lf);
+ if (ret)
+ {
+ ReleaseDC(0, hdc);
+ trace("no bitmap fonts were found, skipping the test\n");
+ return;
+ }
+
+ trace("found bitmap font %s, height %ld\n", bitmap_lf.lfFaceName, bitmap_lf.lfHeight);
+
+ hfont = CreateFontIndirectA(&bitmap_lf);
+ assert(hfont);
+
+ old_hfont = SelectObject(hdc, hfont);
+ ok(GetTextMetricsA(hdc, &tm_orig), "GetTextMetricsA failed\n");
+ ok(GetTextExtentPoint32A(hdc, test_str, sizeof(test_str), &size_orig), "GetTextExtentPoint32A failed\n");
+ ok(GetCharWidthA(hdc, 'A', 'A', &width_orig), "GetCharWidthA failed\n");
+ SelectObject(hdc, old_hfont);
+ DeleteObject(hfont);
+
+ for (i = 1; i < 20; i++)
+ {
+ bitmap_lf.lfHeight = i;
+ 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, "%ld != %ld\n", tm.tmHeight, tm_orig.tmHeight);
+ ok(tm.tmAscent == tm_orig.tmAscent, "%ld != %ld\n", tm.tmAscent, tm_orig.tmAscent);
+ ok(tm.tmDescent == tm_orig.tmDescent, "%ld != %ld\n", tm.tmDescent, tm_orig.tmDescent);
+ ok(tm.tmInternalLeading == tm_orig.tmInternalLeading, "%ld != %ld\n", tm.tmInternalLeading, tm_orig.tmInternalLeading);
+ ok(tm.tmExternalLeading == tm_orig.tmExternalLeading, "%ld != %ld\n", tm.tmExternalLeading, tm_orig.tmExternalLeading);
+
+ 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, "%ld != %ld\n", size.cy, size_orig.cy);
+
+ 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);
+}
+
START_TEST(gdiobj)
{
test_logfont();
+ test_bitmap_font();
}
More information about the wine-patches
mailing list