Added a test showing how GDI scales bitmap font metrics.
This commit is contained in:
parent
26e6168440
commit
3aab64dee5
|
@ -2,6 +2,7 @@
|
||||||
* Unit test suite for GDI objects
|
* Unit test suite for GDI objects
|
||||||
*
|
*
|
||||||
* Copyright 2002 Mike McCormack
|
* Copyright 2002 Mike McCormack
|
||||||
|
* Copyright 2004 Dmitry Timoshkov
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
@ -72,7 +73,140 @@ static void test_logfont(void)
|
||||||
DeleteObject(hfont);
|
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 */
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_font_metrics(HDC hdc, HFONT hfont, const char *test_str,
|
||||||
|
INT test_str_len, const TEXTMETRICA *tm_orig,
|
||||||
|
const SIZE *size_orig, INT width_orig,
|
||||||
|
INT scale_x, INT scale_y)
|
||||||
|
{
|
||||||
|
HFONT old_hfont;
|
||||||
|
TEXTMETRICA tm;
|
||||||
|
SIZE size;
|
||||||
|
INT width;
|
||||||
|
|
||||||
|
old_hfont = SelectObject(hdc, hfont);
|
||||||
|
|
||||||
|
GetTextMetricsA(hdc, &tm);
|
||||||
|
|
||||||
|
ok(tm.tmHeight == tm_orig->tmHeight * scale_y, "%ld != %ld\n", tm.tmHeight, tm_orig->tmHeight * scale_y);
|
||||||
|
ok(tm.tmAscent == tm_orig->tmAscent * scale_y, "%ld != %ld\n", tm.tmAscent, tm_orig->tmAscent * scale_y);
|
||||||
|
ok(tm.tmDescent == tm_orig->tmDescent * scale_y, "%ld != %ld\n", tm.tmDescent, tm_orig->tmDescent * scale_y);
|
||||||
|
ok(tm.tmAveCharWidth == tm_orig->tmAveCharWidth * scale_x, "%ld != %ld\n", tm.tmAveCharWidth, tm_orig->tmAveCharWidth * scale_x);
|
||||||
|
|
||||||
|
GetTextExtentPoint32A(hdc, test_str, test_str_len, &size);
|
||||||
|
|
||||||
|
ok(size.cx == size_orig->cx * scale_x, "%ld != %ld\n", size.cx, size_orig->cx * scale_x);
|
||||||
|
ok(size.cy == size_orig->cy * scale_y, "%ld != %ld\n", size.cy, size_orig->cy * scale_y);
|
||||||
|
|
||||||
|
GetCharWidthA(hdc, 'A', 'A', &width);
|
||||||
|
|
||||||
|
ok(width == width_orig * scale_x, "%d != %d\n", width, width_orig * scale_x);
|
||||||
|
|
||||||
|
SelectObject(hdc, old_hfont);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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_orig;
|
||||||
|
SIZE size_orig;
|
||||||
|
INT ret, i, width_orig, height_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);
|
||||||
|
|
||||||
|
height_orig = 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);
|
||||||
|
|
||||||
|
/* test fractional scaling */
|
||||||
|
for (i = 1; i < height_orig; 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, FIELD_OFFSET(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);
|
||||||
|
|
||||||
|
test_font_metrics(hdc, hfont, test_str, sizeof(test_str), &tm_orig, &size_orig, width_orig, 1, 1);
|
||||||
|
DeleteObject(hfont);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* test integer scaling 3x2 */
|
||||||
|
bitmap_lf.lfHeight = height_orig * 2;
|
||||||
|
bitmap_lf.lfWidth *= 3;
|
||||||
|
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, FIELD_OFFSET(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);
|
||||||
|
todo_wine
|
||||||
|
{
|
||||||
|
test_font_metrics(hdc, hfont, test_str, sizeof(test_str), &tm_orig, &size_orig, width_orig, 3, 2);
|
||||||
|
}
|
||||||
|
DeleteObject(hfont);
|
||||||
|
|
||||||
|
/* test integer scaling 3x3 */
|
||||||
|
bitmap_lf.lfHeight = height_orig * 3;
|
||||||
|
bitmap_lf.lfWidth = 0;
|
||||||
|
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, FIELD_OFFSET(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);
|
||||||
|
todo_wine
|
||||||
|
{
|
||||||
|
test_font_metrics(hdc, hfont, test_str, sizeof(test_str), &tm_orig, &size_orig, width_orig, 3, 3);
|
||||||
|
}
|
||||||
|
DeleteObject(hfont);
|
||||||
|
|
||||||
|
ReleaseDC(0, hdc);
|
||||||
|
}
|
||||||
|
|
||||||
START_TEST(gdiobj)
|
START_TEST(gdiobj)
|
||||||
{
|
{
|
||||||
test_logfont();
|
test_logfont();
|
||||||
|
test_bitmap_font();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue