push decde5eed3d79f9d889b4d757f73e86ce6ff9241
[wine/hacks.git] / dlls / gdiplus / tests / font.c
blobab0f814fa6289d4a5e86f491627d73f2e7b17144
1 /*
2 * Unit test suite for fonts
4 * Copyright (C) 2007 Google (Evan Stade)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "windows.h"
22 #include "gdiplus.h"
23 #include "wine/test.h"
25 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
27 static const WCHAR arial[] = {'A','r','i','a','l','\0'};
28 static const WCHAR nonexistent[] = {'T','h','i','s','F','o','n','t','s','h','o','u','l','d','N','o','t','E','x','i','s','t','\0'};
29 static const WCHAR MSSansSerif[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
30 static const WCHAR MicrosoftSansSerif[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
31 static const WCHAR TimesNewRoman[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
32 static const WCHAR CourierNew[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'};
34 static const char *debugstr_w(LPCWSTR str)
36 static char buf[1024];
37 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
38 return buf;
42 static void test_createfont(void)
44 GpFontFamily* fontfamily = NULL;
45 GpFont* font = NULL;
46 GpStatus stat;
47 Unit unit;
48 UINT i;
49 REAL size;
51 stat = GdipCreateFontFamilyFromName(nonexistent, NULL, &fontfamily);
52 expect (FontFamilyNotFound, stat);
53 stat = GdipDeleteFont(font);
54 expect (InvalidParameter, stat);
55 stat = GdipCreateFontFamilyFromName(arial, NULL, &fontfamily);
56 if(stat == FontFamilyNotFound)
58 skip("Arial not installed\n");
59 return;
61 expect (Ok, stat);
62 stat = GdipCreateFont(fontfamily, 12, FontStyleRegular, UnitPoint, &font);
63 expect (Ok, stat);
64 stat = GdipGetFontUnit (font, &unit);
65 expect (Ok, stat);
66 expect (UnitPoint, unit);
68 /* Test to see if returned size is based on unit (its not) */
69 GdipGetFontSize(font, &size);
70 ok (size == 12, "Expected 12, got %f\n", size);
71 GdipDeleteFont(font);
73 /* Make sure everything is converted correctly for all Units */
74 for (i = UnitWorld; i <=UnitMillimeter; i++)
76 if (i == UnitDisplay) continue; /* Crashes WindowsXP, wtf? */
77 GdipCreateFont(fontfamily, 24, FontStyleRegular, i, &font);
78 GdipGetFontSize (font, &size);
79 ok (size == 24, "Expected 24, got %f (with unit: %d)\n", size, i);
80 GdipGetFontUnit (font, &unit);
81 expect (i, unit);
82 GdipDeleteFont(font);
85 GdipDeleteFontFamily(fontfamily);
88 static void test_logfont(void)
90 LOGFONTW lfw, lfw2;
91 GpFont *font;
92 GpStatus stat;
93 GpGraphics *graphics;
94 HDC hdc = GetDC(0);
96 GdipCreateFromHDC(hdc, &graphics);
97 memset(&lfw, 0, sizeof(LOGFONTW));
98 memset(&lfw2, 0xff, sizeof(LOGFONTW));
99 memcpy(&lfw.lfFaceName, arial, 6 * sizeof(WCHAR));
101 stat = GdipCreateFontFromLogfontW(hdc, &lfw, &font);
102 expect(Ok, stat);
103 stat = GdipGetLogFontW(font, graphics, &lfw2);
104 expect(Ok, stat);
106 ok(lfw2.lfHeight < 0, "Expected negative height\n");
107 expect(0, lfw2.lfWidth);
108 expect(0, lfw2.lfEscapement);
109 expect(0, lfw2.lfOrientation);
110 ok((lfw2.lfWeight >= 100) && (lfw2.lfWeight <= 900), "Expected weight to be set\n");
111 expect(0, lfw2.lfItalic);
112 expect(0, lfw2.lfUnderline);
113 expect(0, lfw2.lfStrikeOut);
114 expect(0, lfw2.lfCharSet);
115 expect(0, lfw2.lfOutPrecision);
116 expect(0, lfw2.lfClipPrecision);
117 expect(0, lfw2.lfQuality);
118 expect(0, lfw2.lfPitchAndFamily);
120 GdipDeleteFont(font);
122 memset(&lfw, 0, sizeof(LOGFONTW));
123 lfw.lfHeight = 25;
124 lfw.lfWidth = 25;
125 lfw.lfEscapement = lfw.lfOrientation = 50;
126 lfw.lfItalic = lfw.lfUnderline = lfw.lfStrikeOut = TRUE;
128 memset(&lfw2, 0xff, sizeof(LOGFONTW));
129 memcpy(&lfw.lfFaceName, arial, 6 * sizeof(WCHAR));
131 stat = GdipCreateFontFromLogfontW(hdc, &lfw, &font);
132 expect(Ok, stat);
133 stat = GdipGetLogFontW(font, graphics, &lfw2);
134 expect(Ok, stat);
136 ok(lfw2.lfHeight < 0, "Expected negative height\n");
137 expect(0, lfw2.lfWidth);
138 expect(0, lfw2.lfEscapement);
139 expect(0, lfw2.lfOrientation);
140 ok((lfw2.lfWeight >= 100) && (lfw2.lfWeight <= 900), "Expected weight to be set\n");
141 expect(TRUE, lfw2.lfItalic);
142 expect(TRUE, lfw2.lfUnderline);
143 expect(TRUE, lfw2.lfStrikeOut);
144 expect(0, lfw2.lfCharSet);
145 expect(0, lfw2.lfOutPrecision);
146 expect(0, lfw2.lfClipPrecision);
147 expect(0, lfw2.lfQuality);
148 expect(0, lfw2.lfPitchAndFamily);
150 GdipDeleteFont(font);
152 GdipDeleteGraphics(graphics);
153 ReleaseDC(0, hdc);
156 static void test_fontfamily (void)
158 GpFontFamily *family, *clonedFontFamily;
159 WCHAR itsName[LF_FACESIZE];
160 GpStatus stat;
162 /* FontFamily cannot be NULL */
163 stat = GdipCreateFontFamilyFromName (arial , NULL, NULL);
164 expect (InvalidParameter, stat);
166 /* FontFamily must be able to actually find the family.
167 * If it can't, any subsequent calls should fail.
169 stat = GdipCreateFontFamilyFromName (nonexistent, NULL, &family);
170 expect (FontFamilyNotFound, stat);
172 /* Bitmap fonts are not found */
173 todo_wine
175 stat = GdipCreateFontFamilyFromName (MSSansSerif, NULL, &family);
176 expect (FontFamilyNotFound, stat);
179 stat = GdipCreateFontFamilyFromName (arial, NULL, &family);
180 if(stat == FontFamilyNotFound)
182 skip("Arial not installed\n");
183 return;
185 expect (Ok, stat);
187 stat = GdipGetFamilyName (family, itsName, LANG_NEUTRAL);
188 expect (Ok, stat);
189 expect (0, lstrcmpiW(itsName, arial));
191 if (0)
193 /* Crashes on Windows XP SP2, Vista, and so Wine as well */
194 stat = GdipGetFamilyName (family, NULL, LANG_NEUTRAL);
195 expect (Ok, stat);
198 /* Make sure we don't read old data */
199 ZeroMemory (itsName, sizeof(itsName));
200 stat = GdipCloneFontFamily(family, &clonedFontFamily);
201 expect (Ok, stat);
202 GdipDeleteFontFamily(family);
203 stat = GdipGetFamilyName(clonedFontFamily, itsName, LANG_NEUTRAL);
204 expect(Ok, stat);
205 expect(0, lstrcmpiW(itsName, arial));
207 GdipDeleteFontFamily(clonedFontFamily);
210 static void test_fontfamily_properties (void)
212 GpFontFamily* FontFamily = NULL;
213 GpStatus stat;
214 UINT16 result = 0;
216 stat = GdipCreateFontFamilyFromName(arial, NULL, &FontFamily);
217 if(stat == FontFamilyNotFound)
218 skip("Arial not installed\n");
219 else
221 todo_wine
223 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
224 expect(Ok, stat);
225 ok (result == 2355, "Expected 2355, got %d\n", result);
227 result = 0;
228 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
229 expect(Ok, stat);
230 ok(result == 2048, "Expected 2048, got %d\n", result);
231 result = 0;
232 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
233 expect(Ok, stat);
234 ok(result == 1854, "Expected 1854, got %d\n", result);
235 result = 0;
236 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
237 ok(result == 434, "Expected 434, got %d\n", result);
238 GdipDeleteFontFamily(FontFamily);
241 stat = GdipCreateFontFamilyFromName(TimesNewRoman, NULL, &FontFamily);
242 if(stat == FontFamilyNotFound)
243 skip("Times New Roman not installed\n");
244 else
246 result = 0;
247 todo_wine
249 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
250 expect(Ok, stat);
251 ok(result == 2355, "Expected 2355, got %d\n", result);
253 result = 0;
254 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
255 expect(Ok, stat);
256 ok(result == 2048, "Expected 2048, got %d\n", result);
257 result = 0;
258 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
259 expect(Ok, stat);
260 ok(result == 1825, "Expected 1825, got %d\n", result);
261 result = 0;
262 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
263 ok(result == 443, "Expected 443 got %d\n", result);
264 GdipDeleteFontFamily(FontFamily);
268 static void test_getgenerics (void)
270 GpStatus stat;
271 GpFontFamily* family;
272 WCHAR familyName[LF_FACESIZE];
273 ZeroMemory(familyName, sizeof(familyName)/sizeof(WCHAR));
275 stat = GdipGetGenericFontFamilySansSerif (&family);
276 expect (Ok, stat);
277 stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL);
278 expect (Ok, stat);
279 ok ((lstrcmpiW(familyName, MicrosoftSansSerif) == 0) ||
280 (lstrcmpiW(familyName,MSSansSerif) == 0),
281 "Expected Microsoft Sans Serif or MS Sans Serif, got %s\n",
282 debugstr_w(familyName));
283 stat = GdipDeleteFontFamily (family);
284 expect (Ok, stat);
286 stat = GdipGetGenericFontFamilySerif (&family);
287 expect (Ok, stat);
288 stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL);
289 expect (Ok, stat);
290 ok (lstrcmpiW(familyName, TimesNewRoman) == 0,
291 "Expected Times New Roman, got %s\n", debugstr_w(familyName));
292 stat = GdipDeleteFontFamily (family);
293 expect (Ok, stat);
295 stat = GdipGetGenericFontFamilyMonospace (&family);
296 expect (Ok, stat);
297 stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL);
298 expect (Ok, stat);
299 ok (lstrcmpiW(familyName, CourierNew) == 0,
300 "Expected Courier New, got %s\n", debugstr_w(familyName));
301 stat = GdipDeleteFontFamily (family);
302 expect (Ok, stat);
305 START_TEST(font)
307 struct GdiplusStartupInput gdiplusStartupInput;
308 ULONG_PTR gdiplusToken;
310 gdiplusStartupInput.GdiplusVersion = 1;
311 gdiplusStartupInput.DebugEventCallback = NULL;
312 gdiplusStartupInput.SuppressBackgroundThread = 0;
313 gdiplusStartupInput.SuppressExternalCodecs = 0;
315 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
317 test_createfont();
318 test_logfont();
319 test_fontfamily();
320 test_fontfamily_properties();
321 test_getgenerics();
323 GdiplusShutdown(gdiplusToken);