2 * Unit test suite for GDI objects
4 * Copyright 2002 Mike McCormack
5 * Copyright 2004 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "wine/test.h"
32 static void test_logfont(void)
37 memset(&lf, 0, sizeof lf);
39 lf.lfCharSet = ANSI_CHARSET;
40 lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
41 lf.lfWeight = FW_DONTCARE;
44 lf.lfQuality = DEFAULT_QUALITY;
45 lstrcpyA(lf.lfFaceName, "Arial");
47 hfont = CreateFontIndirectA(&lf);
48 ok(hfont != 0, "CreateFontIndirect failed\n");
50 ok(GetObjectA(hfont, sizeof(lfout), &lfout) == sizeof(lfout),
51 "GetObject returned wrong size\n");
53 ok(!memcmp(&lfout, &lf, FIELD_OFFSET(LOGFONTA, lfFaceName)), "fonts don't match\n");
54 ok(!lstrcmpA(lfout.lfFaceName, lf.lfFaceName),
55 "font names don't match: %s != %s\n", lfout.lfFaceName, lf.lfFaceName);
59 memset(&lf, 'A', sizeof(lf));
60 hfont = CreateFontIndirectA(&lf);
61 ok(hfont != 0, "CreateFontIndirectA with strange LOGFONT failed\n");
63 ok(GetObjectA(hfont, sizeof(lfout), NULL) == sizeof(lfout),
64 "GetObjectA with NULL failed\n");
66 ok(GetObjectA(hfont, sizeof(lfout), &lfout) == sizeof(lfout),
67 "GetObjectA failed\n");
68 ok(!memcmp(&lfout, &lf, FIELD_OFFSET(LOGFONTA, lfFaceName)), "fonts don't match\n");
69 lf.lfFaceName[LF_FACESIZE - 1] = 0;
70 ok(!lstrcmpA(lfout.lfFaceName, lf.lfFaceName),
71 "font names don't match: %s != %s\n", lfout.lfFaceName, lf.lfFaceName);
76 static INT CALLBACK font_enum_proc(const LOGFONT *elf, const TEXTMETRIC *ntm, DWORD type, LPARAM lParam)
78 if (type & RASTER_FONTTYPE)
80 LOGFONT *lf = (LOGFONT *)lParam;
82 return 0; /* stop enumeration */
85 return 1; /* continue enumeration */
88 static void test_font_metrics(HDC hdc, HFONT hfont, const char *test_str,
89 INT test_str_len, const TEXTMETRICA *tm_orig,
90 const SIZE *size_orig, INT width_orig,
91 INT scale_x, INT scale_y)
98 old_hfont = SelectObject(hdc, hfont);
100 GetTextMetricsA(hdc, &tm);
102 ok(tm.tmHeight == tm_orig->tmHeight * scale_y, "%ld != %ld\n", tm.tmHeight, tm_orig->tmHeight * scale_y);
103 ok(tm.tmAscent == tm_orig->tmAscent * scale_y, "%ld != %ld\n", tm.tmAscent, tm_orig->tmAscent * scale_y);
104 ok(tm.tmDescent == tm_orig->tmDescent * scale_y, "%ld != %ld\n", tm.tmDescent, tm_orig->tmDescent * scale_y);
105 ok(tm.tmAveCharWidth == tm_orig->tmAveCharWidth * scale_x, "%ld != %ld\n", tm.tmAveCharWidth, tm_orig->tmAveCharWidth * scale_x);
107 GetTextExtentPoint32A(hdc, test_str, test_str_len, &size);
109 ok(size.cx == size_orig->cx * scale_x, "%ld != %ld\n", size.cx, size_orig->cx * scale_x);
110 ok(size.cy == size_orig->cy * scale_y, "%ld != %ld\n", size.cy, size_orig->cy * scale_y);
112 GetCharWidthA(hdc, 'A', 'A', &width);
114 ok(width == width_orig * scale_x, "%d != %d\n", width, width_orig * scale_x);
116 SelectObject(hdc, old_hfont);
119 /* see whether GDI scales bitmap font metrics */
120 static void test_bitmap_font(void)
122 static const char test_str[11] = "Test String";
124 LOGFONTA bitmap_lf, lf;
125 HFONT hfont, old_hfont;
128 INT ret, i, width_orig, height_orig;
132 /* "System" has only 1 pixel size defined, otherwise the test breaks */
133 ret = EnumFontFamiliesA(hdc, "System", font_enum_proc, (LPARAM)&bitmap_lf);
137 trace("no bitmap fonts were found, skipping the test\n");
141 trace("found bitmap font %s, height %ld\n", bitmap_lf.lfFaceName, bitmap_lf.lfHeight);
143 height_orig = bitmap_lf.lfHeight;
144 hfont = CreateFontIndirectA(&bitmap_lf);
147 old_hfont = SelectObject(hdc, hfont);
148 ok(GetTextMetricsA(hdc, &tm_orig), "GetTextMetricsA failed\n");
149 ok(GetTextExtentPoint32A(hdc, test_str, sizeof(test_str), &size_orig), "GetTextExtentPoint32A failed\n");
150 ok(GetCharWidthA(hdc, 'A', 'A', &width_orig), "GetCharWidthA failed\n");
151 SelectObject(hdc, old_hfont);
154 /* test fractional scaling */
155 for (i = 1; i < height_orig; i++)
157 bitmap_lf.lfHeight = i;
158 hfont = CreateFontIndirectA(&bitmap_lf);
161 ret = GetObject(hfont, sizeof(lf), &lf);
162 ok(ret == sizeof(lf), "GetObject failed: %d\n", ret);
163 ok(!memcmp(&bitmap_lf, &lf, FIELD_OFFSET(LOGFONTA, lfFaceName)), "fonts don't match\n");
164 ok(!lstrcmpA(bitmap_lf.lfFaceName, lf.lfFaceName),
165 "font names don't match: %s != %s\n", bitmap_lf.lfFaceName, lf.lfFaceName);
167 test_font_metrics(hdc, hfont, test_str, sizeof(test_str), &tm_orig, &size_orig, width_orig, 1, 1);
171 /* test integer scaling 3x2 */
172 bitmap_lf.lfHeight = height_orig * 2;
173 bitmap_lf.lfWidth *= 3;
174 hfont = CreateFontIndirectA(&bitmap_lf);
177 ret = GetObject(hfont, sizeof(lf), &lf);
178 ok(ret == sizeof(lf), "GetObject failed: %d\n", ret);
179 ok(!memcmp(&bitmap_lf, &lf, FIELD_OFFSET(LOGFONTA, lfFaceName)), "fonts don't match\n");
180 ok(!lstrcmpA(bitmap_lf.lfFaceName, lf.lfFaceName),
181 "font names don't match: %s != %s\n", bitmap_lf.lfFaceName, lf.lfFaceName);
184 test_font_metrics(hdc, hfont, test_str, sizeof(test_str), &tm_orig, &size_orig, width_orig, 3, 2);
188 /* test integer scaling 3x3 */
189 bitmap_lf.lfHeight = height_orig * 3;
190 bitmap_lf.lfWidth = 0;
191 hfont = CreateFontIndirectA(&bitmap_lf);
194 ret = GetObject(hfont, sizeof(lf), &lf);
195 ok(ret == sizeof(lf), "GetObject failed: %d\n", ret);
196 ok(!memcmp(&bitmap_lf, &lf, FIELD_OFFSET(LOGFONTA, lfFaceName)), "fonts don't match\n");
197 ok(!lstrcmpA(bitmap_lf.lfFaceName, lf.lfFaceName),
198 "font names don't match: %s != %s\n", bitmap_lf.lfFaceName, lf.lfFaceName);
201 test_font_metrics(hdc, hfont, test_str, sizeof(test_str), &tm_orig, &size_orig, width_orig, 3, 3);