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
25 #include "wine/test.h"
27 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
28 #define expectf(expected, got) ok(fabs(expected - got) < 0.0001, "Expected %.2f, got %.2f\n", expected, got)
30 static const WCHAR arial[] = {'A','r','i','a','l','\0'};
31 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'};
32 static const WCHAR MSSansSerif[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
33 static const WCHAR MicrosoftSansSerif[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
34 static const WCHAR TimesNewRoman[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
35 static const WCHAR CourierNew[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'};
36 static const WCHAR Tahoma[] = {'T','a','h','o','m','a',0};
38 static void test_createfont(void)
40 GpFontFamily* fontfamily = NULL, *fontfamily2;
46 WCHAR familyname[LF_FACESIZE];
48 stat = GdipCreateFontFamilyFromName(nonexistent, NULL, &fontfamily);
49 expect (FontFamilyNotFound, stat);
50 stat = GdipDeleteFont(font);
51 expect (InvalidParameter, stat);
52 stat = GdipCreateFontFamilyFromName(arial, NULL, &fontfamily);
53 if(stat == FontFamilyNotFound)
55 skip("Arial not installed\n");
59 stat = GdipCreateFont(fontfamily, 12, FontStyleRegular, UnitPoint, &font);
61 stat = GdipGetFontUnit (font, &unit);
63 expect (UnitPoint, unit);
65 stat = GdipGetFamily(font, &fontfamily2);
67 stat = GdipGetFamilyName(fontfamily2, familyname, 0);
69 ok (lstrcmpiW(arial, familyname) == 0, "Expected arial, got %s\n",
70 wine_dbgstr_w(familyname));
71 stat = GdipDeleteFontFamily(fontfamily2);
74 /* Test to see if returned size is based on unit (its not) */
75 GdipGetFontSize(font, &size);
76 ok (size == 12, "Expected 12, got %f\n", size);
79 /* Make sure everything is converted correctly for all Units */
80 for (i = UnitWorld; i <=UnitMillimeter; i++)
82 if (i == UnitDisplay) continue; /* Crashes WindowsXP, wtf? */
83 GdipCreateFont(fontfamily, 24, FontStyleRegular, i, &font);
84 GdipGetFontSize (font, &size);
85 ok (size == 24, "Expected 24, got %f (with unit: %d)\n", size, i);
86 GdipGetFontUnit (font, &unit);
91 GdipDeleteFontFamily(fontfamily);
94 static void test_logfont(void)
103 GdipCreateFromHDC(hdc, &graphics);
104 memset(&lfa, 0, sizeof(LOGFONTA));
105 memset(&lfa2, 0xff, sizeof(LOGFONTA));
108 lfa.lfFaceName[0] = 0;
109 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
110 expect(NotTrueTypeFont, stat);
112 lstrcpyA(lfa.lfFaceName, "Arial");
114 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
115 if (stat == FileNotFound)
117 skip("Arial not installed.\n");
121 stat = GdipGetLogFontA(font, graphics, &lfa2);
124 ok(lfa2.lfHeight < 0, "Expected negative height\n");
125 expect(0, lfa2.lfWidth);
126 expect(0, lfa2.lfEscapement);
127 expect(0, lfa2.lfOrientation);
128 ok((lfa2.lfWeight >= 100) && (lfa2.lfWeight <= 900), "Expected weight to be set\n");
129 expect(0, lfa2.lfItalic);
130 expect(0, lfa2.lfUnderline);
131 expect(0, lfa2.lfStrikeOut);
132 expect(GetTextCharset(hdc), lfa2.lfCharSet);
133 expect(0, lfa2.lfOutPrecision);
134 expect(0, lfa2.lfClipPrecision);
135 expect(0, lfa2.lfQuality);
136 expect(0, lfa2.lfPitchAndFamily);
138 GdipDeleteFont(font);
140 memset(&lfa, 0, sizeof(LOGFONTA));
143 lfa.lfEscapement = lfa.lfOrientation = 50;
144 lfa.lfItalic = lfa.lfUnderline = lfa.lfStrikeOut = TRUE;
146 memset(&lfa2, 0xff, sizeof(LOGFONTA));
147 lstrcpyA(lfa.lfFaceName, "Arial");
149 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
151 stat = GdipGetLogFontA(font, graphics, &lfa2);
154 ok(lfa2.lfHeight < 0, "Expected negative height\n");
155 expect(0, lfa2.lfWidth);
156 expect(0, lfa2.lfEscapement);
157 expect(0, lfa2.lfOrientation);
158 ok((lfa2.lfWeight >= 100) && (lfa2.lfWeight <= 900), "Expected weight to be set\n");
159 expect(TRUE, lfa2.lfItalic);
160 expect(TRUE, lfa2.lfUnderline);
161 expect(TRUE, lfa2.lfStrikeOut);
162 expect(GetTextCharset(hdc), lfa2.lfCharSet);
163 expect(0, lfa2.lfOutPrecision);
164 expect(0, lfa2.lfClipPrecision);
165 expect(0, lfa2.lfQuality);
166 expect(0, lfa2.lfPitchAndFamily);
168 stat = GdipGetFontStyle(font, &style);
170 ok (style == (FontStyleItalic | FontStyleUnderline | FontStyleStrikeout),
171 "Expected , got %d\n", style);
173 GdipDeleteFont(font);
175 GdipDeleteGraphics(graphics);
179 static void test_fontfamily (void)
181 GpFontFamily *family, *clonedFontFamily;
182 WCHAR itsName[LF_FACESIZE];
185 /* FontFamily cannot be NULL */
186 stat = GdipCreateFontFamilyFromName (arial , NULL, NULL);
187 expect (InvalidParameter, stat);
189 /* FontFamily must be able to actually find the family.
190 * If it can't, any subsequent calls should fail.
192 stat = GdipCreateFontFamilyFromName (nonexistent, NULL, &family);
193 expect (FontFamilyNotFound, stat);
195 /* Bitmap fonts are not found */
196 stat = GdipCreateFontFamilyFromName (MSSansSerif, NULL, &family);
197 expect (FontFamilyNotFound, stat);
198 if(stat == Ok) GdipDeleteFontFamily(family);
200 stat = GdipCreateFontFamilyFromName (arial, NULL, &family);
201 if(stat == FontFamilyNotFound)
203 skip("Arial not installed\n");
208 stat = GdipGetFamilyName (family, itsName, LANG_NEUTRAL);
210 expect (0, lstrcmpiW(itsName, arial));
214 /* Crashes on Windows XP SP2, Vista, and so Wine as well */
215 stat = GdipGetFamilyName (family, NULL, LANG_NEUTRAL);
219 /* Make sure we don't read old data */
220 ZeroMemory (itsName, sizeof(itsName));
221 stat = GdipCloneFontFamily(family, &clonedFontFamily);
223 GdipDeleteFontFamily(family);
224 stat = GdipGetFamilyName(clonedFontFamily, itsName, LANG_NEUTRAL);
226 expect(0, lstrcmpiW(itsName, arial));
228 GdipDeleteFontFamily(clonedFontFamily);
231 static void test_fontfamily_properties (void)
233 GpFontFamily* FontFamily = NULL;
237 stat = GdipCreateFontFamilyFromName(arial, NULL, &FontFamily);
238 if(stat == FontFamilyNotFound)
239 skip("Arial not installed\n");
242 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
244 ok (result == 2355, "Expected 2355, got %d\n", result);
246 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
248 ok(result == 2048, "Expected 2048, got %d\n", result);
250 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
252 ok(result == 1854, "Expected 1854, got %d\n", result);
254 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
255 ok(result == 434, "Expected 434, got %d\n", result);
256 GdipDeleteFontFamily(FontFamily);
259 stat = GdipCreateFontFamilyFromName(TimesNewRoman, NULL, &FontFamily);
260 if(stat == FontFamilyNotFound)
261 skip("Times New Roman not installed\n");
265 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
267 ok(result == 2355, "Expected 2355, got %d\n", result);
269 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
271 ok(result == 2048, "Expected 2048, got %d\n", result);
273 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
275 ok(result == 1825, "Expected 1825, got %d\n", result);
277 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
278 ok(result == 443, "Expected 443 got %d\n", result);
279 GdipDeleteFontFamily(FontFamily);
283 static void test_getgenerics (void)
286 GpFontFamily* family;
287 WCHAR familyName[LF_FACESIZE];
288 ZeroMemory(familyName, sizeof(familyName)/sizeof(WCHAR));
290 stat = GdipGetGenericFontFamilySansSerif (&family);
291 if (stat == FontFamilyNotFound)
293 skip("Microsoft Sans Serif not installed\n");
297 stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL);
299 if (!lstrcmpiW(familyName, Tahoma))
300 todo_wine ok ((lstrcmpiW(familyName, MicrosoftSansSerif) == 0),
301 "Expected Microsoft Sans Serif, got Tahoma\n");
303 ok ((lstrcmpiW(familyName, MicrosoftSansSerif) == 0),
304 "Expected Microsoft Sans Serif, got %s\n", wine_dbgstr_w(familyName));
305 stat = GdipDeleteFontFamily (family);
309 stat = GdipGetGenericFontFamilySerif (&family);
310 if (stat == FontFamilyNotFound)
312 skip("Times New Roman not installed\n");
316 stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL);
318 ok (lstrcmpiW(familyName, TimesNewRoman) == 0,
319 "Expected Times New Roman, got %s\n", wine_dbgstr_w(familyName));
320 stat = GdipDeleteFontFamily (family);
324 stat = GdipGetGenericFontFamilyMonospace (&family);
325 if (stat == FontFamilyNotFound)
327 skip("Courier New not installed\n");
331 stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL);
333 ok (lstrcmpiW(familyName, CourierNew) == 0,
334 "Expected Courier New, got %s\n", wine_dbgstr_w(familyName));
335 stat = GdipDeleteFontFamily (family);
339 static void test_installedfonts (void)
342 GpFontCollection* collection=NULL;
344 stat = GdipNewInstalledFontCollection(NULL);
345 expect (InvalidParameter, stat);
347 stat = GdipNewInstalledFontCollection(&collection);
349 ok (collection != NULL, "got NULL font collection\n");
352 static void test_heightgivendpi(void)
356 GpFontFamily* fontfamily = NULL;
359 stat = GdipCreateFontFamilyFromName(arial, NULL, &fontfamily);
360 if(stat == FontFamilyNotFound)
362 skip("Arial not installed\n");
367 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPixel, &font);
370 stat = GdipGetFontHeightGivenDPI(NULL, 96, &height);
371 expect(InvalidParameter, stat);
373 stat = GdipGetFontHeightGivenDPI(font, 96, NULL);
374 expect(InvalidParameter, stat);
376 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
378 expectf((REAL)34.497070, height);
379 GdipDeleteFont(font);
382 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitWorld, &font);
384 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
386 expectf((REAL)34.497070, height);
387 GdipDeleteFont(font);
390 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPoint, &font);
392 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
394 expectf((REAL)45.996094, height);
395 GdipDeleteFont(font);
398 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitInch, &font);
400 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
402 expectf((REAL)3311.718750, height);
403 GdipDeleteFont(font);
406 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitDocument, &font);
408 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
410 expectf((REAL)11.039062, height);
411 GdipDeleteFont(font);
414 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitMillimeter, &font);
416 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
418 expectf((REAL)130.382614, height);
419 GdipDeleteFont(font);
421 GdipDeleteFontFamily(fontfamily);
426 struct GdiplusStartupInput gdiplusStartupInput;
427 ULONG_PTR gdiplusToken;
429 gdiplusStartupInput.GdiplusVersion = 1;
430 gdiplusStartupInput.DebugEventCallback = NULL;
431 gdiplusStartupInput.SuppressBackgroundThread = 0;
432 gdiplusStartupInput.SuppressExternalCodecs = 0;
434 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
439 test_fontfamily_properties();
441 test_installedfonts();
442 test_heightgivendpi();
444 GdiplusShutdown(gdiplusToken);