gdiplus: Implement GdipGetFontStyle.
[wine.git] / dlls / gdiplus / tests / font.c
blobb3961419f07362f0fdc392e615b9584cf03f66a2
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, *fontfamily2;
45 GpFont* font = NULL;
46 GpStatus stat;
47 Unit unit;
48 UINT i;
49 REAL size;
50 WCHAR familyname[LF_FACESIZE];
52 stat = GdipCreateFontFamilyFromName(nonexistent, NULL, &fontfamily);
53 expect (FontFamilyNotFound, stat);
54 stat = GdipDeleteFont(font);
55 expect (InvalidParameter, stat);
56 stat = GdipCreateFontFamilyFromName(arial, NULL, &fontfamily);
57 if(stat == FontFamilyNotFound)
59 skip("Arial not installed\n");
60 return;
62 expect (Ok, stat);
63 stat = GdipCreateFont(fontfamily, 12, FontStyleRegular, UnitPoint, &font);
64 expect (Ok, stat);
65 stat = GdipGetFontUnit (font, &unit);
66 expect (Ok, stat);
67 expect (UnitPoint, unit);
69 stat = GdipGetFamily(font, &fontfamily2);
70 expect(Ok, stat);
71 stat = GdipGetFamilyName(fontfamily2, familyname, 0);
72 expect(Ok, stat);
73 ok (lstrcmpiW(arial, familyname) == 0, "Expected arial, got %s\n",
74 debugstr_w(familyname));
75 stat = GdipDeleteFontFamily(fontfamily2);
76 expect(Ok, stat);
78 /* Test to see if returned size is based on unit (its not) */
79 GdipGetFontSize(font, &size);
80 ok (size == 12, "Expected 12, got %f\n", size);
81 GdipDeleteFont(font);
83 /* Make sure everything is converted correctly for all Units */
84 for (i = UnitWorld; i <=UnitMillimeter; i++)
86 if (i == UnitDisplay) continue; /* Crashes WindowsXP, wtf? */
87 GdipCreateFont(fontfamily, 24, FontStyleRegular, i, &font);
88 GdipGetFontSize (font, &size);
89 ok (size == 24, "Expected 24, got %f (with unit: %d)\n", size, i);
90 GdipGetFontUnit (font, &unit);
91 expect (i, unit);
92 GdipDeleteFont(font);
95 GdipDeleteFontFamily(fontfamily);
98 static void test_logfont(void)
100 LOGFONTW lfw, lfw2;
101 GpFont *font;
102 GpStatus stat;
103 GpGraphics *graphics;
104 HDC hdc = GetDC(0);
105 INT style;
107 GdipCreateFromHDC(hdc, &graphics);
108 memset(&lfw, 0, sizeof(LOGFONTW));
109 memset(&lfw2, 0xff, sizeof(LOGFONTW));
111 /* empty FaceName */
112 lfw.lfFaceName[0] = 0;
113 stat = GdipCreateFontFromLogfontW(hdc, &lfw, &font);
115 todo_wine {
116 expect(NotTrueTypeFont, stat);
119 memcpy(&lfw.lfFaceName, arial, 6 * sizeof(WCHAR));
121 stat = GdipCreateFontFromLogfontW(hdc, &lfw, &font);
122 if (stat == FileNotFound)
124 skip("Arial not installed.\n");
125 return;
127 expect(Ok, stat);
128 stat = GdipGetLogFontW(font, graphics, &lfw2);
129 expect(Ok, stat);
131 ok(lfw2.lfHeight < 0, "Expected negative height\n");
132 expect(0, lfw2.lfWidth);
133 expect(0, lfw2.lfEscapement);
134 expect(0, lfw2.lfOrientation);
135 ok((lfw2.lfWeight >= 100) && (lfw2.lfWeight <= 900), "Expected weight to be set\n");
136 expect(0, lfw2.lfItalic);
137 expect(0, lfw2.lfUnderline);
138 expect(0, lfw2.lfStrikeOut);
139 expect(0, lfw2.lfCharSet);
140 expect(0, lfw2.lfOutPrecision);
141 expect(0, lfw2.lfClipPrecision);
142 expect(0, lfw2.lfQuality);
143 expect(0, lfw2.lfPitchAndFamily);
145 GdipDeleteFont(font);
147 memset(&lfw, 0, sizeof(LOGFONTW));
148 lfw.lfHeight = 25;
149 lfw.lfWidth = 25;
150 lfw.lfEscapement = lfw.lfOrientation = 50;
151 lfw.lfItalic = lfw.lfUnderline = lfw.lfStrikeOut = TRUE;
153 memset(&lfw2, 0xff, sizeof(LOGFONTW));
154 memcpy(&lfw.lfFaceName, arial, 6 * sizeof(WCHAR));
156 stat = GdipCreateFontFromLogfontW(hdc, &lfw, &font);
157 expect(Ok, stat);
158 stat = GdipGetLogFontW(font, graphics, &lfw2);
159 expect(Ok, stat);
161 ok(lfw2.lfHeight < 0, "Expected negative height\n");
162 expect(0, lfw2.lfWidth);
163 expect(0, lfw2.lfEscapement);
164 expect(0, lfw2.lfOrientation);
165 ok((lfw2.lfWeight >= 100) && (lfw2.lfWeight <= 900), "Expected weight to be set\n");
166 expect(TRUE, lfw2.lfItalic);
167 expect(TRUE, lfw2.lfUnderline);
168 expect(TRUE, lfw2.lfStrikeOut);
169 expect(0, lfw2.lfCharSet);
170 expect(0, lfw2.lfOutPrecision);
171 expect(0, lfw2.lfClipPrecision);
172 expect(0, lfw2.lfQuality);
173 expect(0, lfw2.lfPitchAndFamily);
175 stat = GdipGetFontStyle(font, &style);
176 expect(Ok, stat);
177 ok (style == (FontStyleItalic | FontStyleUnderline | FontStyleStrikeout),
178 "Expected , got %d\n", style);
180 GdipDeleteFont(font);
182 GdipDeleteGraphics(graphics);
183 ReleaseDC(0, hdc);
186 static void test_fontfamily (void)
188 GpFontFamily *family, *clonedFontFamily;
189 WCHAR itsName[LF_FACESIZE];
190 GpStatus stat;
192 /* FontFamily cannot be NULL */
193 stat = GdipCreateFontFamilyFromName (arial , NULL, NULL);
194 expect (InvalidParameter, stat);
196 /* FontFamily must be able to actually find the family.
197 * If it can't, any subsequent calls should fail.
199 stat = GdipCreateFontFamilyFromName (nonexistent, NULL, &family);
200 expect (FontFamilyNotFound, stat);
202 /* Bitmap fonts are not found */
203 todo_wine
205 stat = GdipCreateFontFamilyFromName (MSSansSerif, NULL, &family);
206 expect (FontFamilyNotFound, stat);
209 stat = GdipCreateFontFamilyFromName (arial, NULL, &family);
210 if(stat == FontFamilyNotFound)
212 skip("Arial not installed\n");
213 return;
215 expect (Ok, stat);
217 stat = GdipGetFamilyName (family, itsName, LANG_NEUTRAL);
218 expect (Ok, stat);
219 expect (0, lstrcmpiW(itsName, arial));
221 if (0)
223 /* Crashes on Windows XP SP2, Vista, and so Wine as well */
224 stat = GdipGetFamilyName (family, NULL, LANG_NEUTRAL);
225 expect (Ok, stat);
228 /* Make sure we don't read old data */
229 ZeroMemory (itsName, sizeof(itsName));
230 stat = GdipCloneFontFamily(family, &clonedFontFamily);
231 expect (Ok, stat);
232 GdipDeleteFontFamily(family);
233 stat = GdipGetFamilyName(clonedFontFamily, itsName, LANG_NEUTRAL);
234 expect(Ok, stat);
235 expect(0, lstrcmpiW(itsName, arial));
237 GdipDeleteFontFamily(clonedFontFamily);
240 static void test_fontfamily_properties (void)
242 GpFontFamily* FontFamily = NULL;
243 GpStatus stat;
244 UINT16 result = 0;
246 stat = GdipCreateFontFamilyFromName(arial, NULL, &FontFamily);
247 if(stat == FontFamilyNotFound)
248 skip("Arial not installed\n");
249 else
251 todo_wine
253 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
254 expect(Ok, stat);
255 ok (result == 2355, "Expected 2355, got %d\n", result);
257 result = 0;
258 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
259 expect(Ok, stat);
260 ok(result == 2048, "Expected 2048, got %d\n", result);
261 result = 0;
262 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
263 expect(Ok, stat);
264 ok(result == 1854, "Expected 1854, got %d\n", result);
265 result = 0;
266 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
267 ok(result == 434, "Expected 434, got %d\n", result);
268 GdipDeleteFontFamily(FontFamily);
271 stat = GdipCreateFontFamilyFromName(TimesNewRoman, NULL, &FontFamily);
272 if(stat == FontFamilyNotFound)
273 skip("Times New Roman not installed\n");
274 else
276 result = 0;
277 todo_wine
279 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
280 expect(Ok, stat);
281 ok(result == 2355, "Expected 2355, got %d\n", result);
283 result = 0;
284 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
285 expect(Ok, stat);
286 ok(result == 2048, "Expected 2048, got %d\n", result);
287 result = 0;
288 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
289 expect(Ok, stat);
290 ok(result == 1825, "Expected 1825, got %d\n", result);
291 result = 0;
292 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
293 ok(result == 443, "Expected 443 got %d\n", result);
294 GdipDeleteFontFamily(FontFamily);
298 static void test_getgenerics (void)
300 GpStatus stat;
301 GpFontFamily* family;
302 WCHAR familyName[LF_FACESIZE];
303 ZeroMemory(familyName, sizeof(familyName)/sizeof(WCHAR));
305 stat = GdipGetGenericFontFamilySansSerif (&family);
306 if (stat == FontFamilyNotFound)
308 skip("Microsoft Sans Serif not installed\n");
309 goto serif;
311 expect (Ok, stat);
312 stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL);
313 expect (Ok, stat);
314 ok ((lstrcmpiW(familyName, MicrosoftSansSerif) == 0) ||
315 (lstrcmpiW(familyName,MSSansSerif) == 0),
316 "Expected Microsoft Sans Serif or MS Sans Serif, got %s\n",
317 debugstr_w(familyName));
318 stat = GdipDeleteFontFamily (family);
319 expect (Ok, stat);
321 serif:
322 stat = GdipGetGenericFontFamilySerif (&family);
323 if (stat == FontFamilyNotFound)
325 skip("Times New Roman not installed\n");
326 goto monospace;
328 expect (Ok, stat);
329 stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL);
330 expect (Ok, stat);
331 ok (lstrcmpiW(familyName, TimesNewRoman) == 0,
332 "Expected Times New Roman, got %s\n", debugstr_w(familyName));
333 stat = GdipDeleteFontFamily (family);
334 expect (Ok, stat);
336 monospace:
337 stat = GdipGetGenericFontFamilyMonospace (&family);
338 if (stat == FontFamilyNotFound)
340 skip("Courier New not installed\n");
341 return;
343 expect (Ok, stat);
344 stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL);
345 expect (Ok, stat);
346 ok (lstrcmpiW(familyName, CourierNew) == 0,
347 "Expected Courier New, got %s\n", debugstr_w(familyName));
348 stat = GdipDeleteFontFamily (family);
349 expect (Ok, stat);
352 START_TEST(font)
354 struct GdiplusStartupInput gdiplusStartupInput;
355 ULONG_PTR gdiplusToken;
357 gdiplusStartupInput.GdiplusVersion = 1;
358 gdiplusStartupInput.DebugEventCallback = NULL;
359 gdiplusStartupInput.SuppressBackgroundThread = 0;
360 gdiplusStartupInput.SuppressExternalCodecs = 0;
362 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
364 test_createfont();
365 test_logfont();
366 test_fontfamily();
367 test_fontfamily_properties();
368 test_getgenerics();
370 GdiplusShutdown(gdiplusToken);