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 %d, got %d\n", expected, got)
28 #define expectf(expected, got) ok(fabs(expected - got) < 0.0001, "Expected %f, got %f\n", expected, got)
30 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'};
31 static const WCHAR MSSansSerif[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
32 static const WCHAR MicrosoftSansSerif[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
33 static const WCHAR TimesNewRoman[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
34 static const WCHAR CourierNew[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'};
35 static const WCHAR Tahoma[] = {'T','a','h','o','m','a',0};
36 static const WCHAR LiberationSerif[] = {'L','i','b','e','r','a','t','i','o','n',' ','S','e','r','i','f',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(Tahoma, NULL, &fontfamily);
54 stat = GdipCreateFont(fontfamily, 12, FontStyleRegular, UnitPoint, &font);
56 stat = GdipGetFontUnit (font, &unit);
58 expect (UnitPoint, unit);
60 stat = GdipGetFamily(font, &fontfamily2);
62 stat = GdipGetFamilyName(fontfamily2, familyname, 0);
64 ok (lstrcmpiW(Tahoma, familyname) == 0, "Expected Tahoma, got %s\n",
65 wine_dbgstr_w(familyname));
66 stat = GdipDeleteFontFamily(fontfamily2);
69 /* Test to see if returned size is based on unit (its not) */
70 GdipGetFontSize(font, &size);
71 ok (size == 12, "Expected 12, got %f\n", size);
74 /* Make sure everything is converted correctly for all Units */
75 for (i = UnitWorld; i <=UnitMillimeter; i++)
77 if (i == UnitDisplay) continue; /* Crashes WindowsXP, wtf? */
78 GdipCreateFont(fontfamily, 24, FontStyleRegular, i, &font);
79 GdipGetFontSize (font, &size);
80 ok (size == 24, "Expected 24, got %f (with unit: %d)\n", size, i);
81 GdipGetFontUnit (font, &unit);
86 GdipDeleteFontFamily(fontfamily);
89 static void test_logfont(void)
98 GdipCreateFromHDC(hdc, &graphics);
99 memset(&lfa, 0, sizeof(LOGFONTA));
100 memset(&lfa2, 0xff, sizeof(LOGFONTA));
103 lfa.lfFaceName[0] = 0;
104 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
105 expect(NotTrueTypeFont, stat);
107 lstrcpyA(lfa.lfFaceName, "Tahoma");
109 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
111 stat = GdipGetLogFontA(font, graphics, &lfa2);
114 ok(lfa2.lfHeight < 0, "Expected negative height\n");
115 expect(0, lfa2.lfWidth);
116 expect(0, lfa2.lfEscapement);
117 expect(0, lfa2.lfOrientation);
118 ok((lfa2.lfWeight >= 100) && (lfa2.lfWeight <= 900), "Expected weight to be set\n");
119 expect(0, lfa2.lfItalic);
120 expect(0, lfa2.lfUnderline);
121 expect(0, lfa2.lfStrikeOut);
122 ok(lfa2.lfCharSet == GetTextCharset(hdc) || lfa2.lfCharSet == ANSI_CHARSET,
123 "Expected %x or %x, got %x\n", GetTextCharset(hdc), ANSI_CHARSET, lfa2.lfCharSet);
124 expect(0, lfa2.lfOutPrecision);
125 expect(0, lfa2.lfClipPrecision);
126 expect(0, lfa2.lfQuality);
127 expect(0, lfa2.lfPitchAndFamily);
129 GdipDeleteFont(font);
131 memset(&lfa, 0, sizeof(LOGFONTA));
134 lfa.lfEscapement = lfa.lfOrientation = 50;
135 lfa.lfItalic = lfa.lfUnderline = lfa.lfStrikeOut = TRUE;
137 memset(&lfa2, 0xff, sizeof(LOGFONTA));
138 lstrcpyA(lfa.lfFaceName, "Tahoma");
140 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
142 stat = GdipGetLogFontA(font, graphics, &lfa2);
145 ok(lfa2.lfHeight < 0, "Expected negative height\n");
146 expect(0, lfa2.lfWidth);
147 expect(0, lfa2.lfEscapement);
148 expect(0, lfa2.lfOrientation);
149 ok((lfa2.lfWeight >= 100) && (lfa2.lfWeight <= 900), "Expected weight to be set\n");
150 expect(TRUE, lfa2.lfItalic);
151 expect(TRUE, lfa2.lfUnderline);
152 expect(TRUE, lfa2.lfStrikeOut);
153 ok(lfa2.lfCharSet == GetTextCharset(hdc) || lfa2.lfCharSet == ANSI_CHARSET,
154 "Expected %x or %x, got %x\n", GetTextCharset(hdc), ANSI_CHARSET, lfa2.lfCharSet);
155 expect(0, lfa2.lfOutPrecision);
156 expect(0, lfa2.lfClipPrecision);
157 expect(0, lfa2.lfQuality);
158 expect(0, lfa2.lfPitchAndFamily);
160 stat = GdipGetFontStyle(font, &style);
162 ok (style == (FontStyleItalic | FontStyleUnderline | FontStyleStrikeout),
163 "Expected , got %d\n", style);
165 GdipDeleteFont(font);
167 GdipDeleteGraphics(graphics);
171 static void test_fontfamily (void)
173 GpFontFamily *family, *clonedFontFamily;
174 WCHAR itsName[LF_FACESIZE];
177 /* FontFamily cannot be NULL */
178 stat = GdipCreateFontFamilyFromName (Tahoma , NULL, NULL);
179 expect (InvalidParameter, stat);
181 /* FontFamily must be able to actually find the family.
182 * If it can't, any subsequent calls should fail.
184 stat = GdipCreateFontFamilyFromName (nonexistent, NULL, &family);
185 expect (FontFamilyNotFound, stat);
187 /* Bitmap fonts are not found */
188 stat = GdipCreateFontFamilyFromName (MSSansSerif, NULL, &family);
189 expect (FontFamilyNotFound, stat);
190 if(stat == Ok) GdipDeleteFontFamily(family);
192 stat = GdipCreateFontFamilyFromName (Tahoma, NULL, &family);
195 stat = GdipGetFamilyName (family, itsName, LANG_NEUTRAL);
197 expect (0, lstrcmpiW(itsName, Tahoma));
201 /* Crashes on Windows XP SP2, Vista, and so Wine as well */
202 stat = GdipGetFamilyName (family, NULL, LANG_NEUTRAL);
206 /* Make sure we don't read old data */
207 ZeroMemory (itsName, sizeof(itsName));
208 stat = GdipCloneFontFamily(family, &clonedFontFamily);
210 GdipDeleteFontFamily(family);
211 stat = GdipGetFamilyName(clonedFontFamily, itsName, LANG_NEUTRAL);
213 expect(0, lstrcmpiW(itsName, Tahoma));
215 GdipDeleteFontFamily(clonedFontFamily);
218 static void test_fontfamily_properties (void)
220 GpFontFamily* FontFamily = NULL;
224 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &FontFamily);
227 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
229 ok (result == 2472, "Expected 2472, got %d\n", result);
231 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
233 ok(result == 2048, "Expected 2048, got %d\n", result);
235 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
237 ok(result == 2049, "Expected 2049, got %d\n", result);
239 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
241 ok(result == 423, "Expected 423, got %d\n", result);
242 GdipDeleteFontFamily(FontFamily);
244 stat = GdipCreateFontFamilyFromName(TimesNewRoman, NULL, &FontFamily);
245 if(stat == FontFamilyNotFound)
246 skip("Times New Roman not installed\n");
250 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
252 ok(result == 2355, "Expected 2355, got %d\n", result);
254 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
256 ok(result == 2048, "Expected 2048, got %d\n", result);
258 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
260 ok(result == 1825, "Expected 1825, got %d\n", result);
262 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
264 ok(result == 443, "Expected 443 got %d\n", result);
265 GdipDeleteFontFamily(FontFamily);
269 static void check_family(const char* context, GpFontFamily *family, WCHAR *name)
275 stat = GdipGetFamilyName(family, name, LANG_NEUTRAL);
276 ok(stat == Ok, "could not get the %s family name: %.8x\n", context, stat);
278 stat = GdipCreateFont(family, 12, FontStyleRegular, UnitPixel, &font);
279 ok(stat == Ok, "could not create a font for the %s family: %.8x\n", context, stat);
282 stat = GdipDeleteFont(font);
283 ok(stat == Ok, "could not delete the %s family font: %.8x\n", context, stat);
286 stat = GdipDeleteFontFamily(family);
287 ok(stat == Ok, "could not delete the %s family: %.8x\n", context, stat);
290 static void test_getgenerics (void)
293 GpFontFamily *family;
294 WCHAR sansname[LF_FACESIZE], serifname[LF_FACESIZE], mononame[LF_FACESIZE];
295 int missingfonts = 0;
297 stat = GdipGetGenericFontFamilySansSerif(&family);
299 if (stat == FontFamilyNotFound)
302 check_family("Sans Serif", family, sansname);
304 stat = GdipGetGenericFontFamilySerif(&family);
306 if (stat == FontFamilyNotFound)
309 check_family("Serif", family, serifname);
311 stat = GdipGetGenericFontFamilyMonospace(&family);
313 if (stat == FontFamilyNotFound)
316 check_family("Monospace", family, mononame);
318 if (missingfonts && strcmp(winetest_platform, "wine") == 0)
319 trace("You may need to install either the Microsoft Web Fonts or the Liberation Fonts\n");
321 /* Check that the family names are all different */
322 ok(lstrcmpiW(sansname, serifname) != 0, "Sans Serif and Serif families should be different: %s\n", wine_dbgstr_w(sansname));
323 ok(lstrcmpiW(sansname, mononame) != 0, "Sans Serif and Monospace families should be different: %s\n", wine_dbgstr_w(sansname));
324 ok(lstrcmpiW(serifname, mononame) != 0, "Serif and Monospace families should be different: %s\n", wine_dbgstr_w(serifname));
327 static void test_installedfonts (void)
330 GpFontCollection* collection=NULL;
332 stat = GdipNewInstalledFontCollection(NULL);
333 expect (InvalidParameter, stat);
335 stat = GdipNewInstalledFontCollection(&collection);
337 ok (collection != NULL, "got NULL font collection\n");
340 static void test_heightgivendpi(void)
344 GpFontFamily* fontfamily = NULL;
347 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &fontfamily);
350 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPixel, &font);
353 stat = GdipGetFontHeightGivenDPI(NULL, 96, &height);
354 expect(InvalidParameter, stat);
356 stat = GdipGetFontHeightGivenDPI(font, 96, NULL);
357 expect(InvalidParameter, stat);
359 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
361 expectf(36.210938, height);
362 GdipDeleteFont(font);
365 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitWorld, &font);
367 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
369 expectf(36.210938, height);
370 GdipDeleteFont(font);
373 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPoint, &font);
375 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
377 expectf(48.281250, height);
378 GdipDeleteFont(font);
381 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitInch, &font);
383 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
385 expectf(3476.250000, height);
386 GdipDeleteFont(font);
389 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitDocument, &font);
391 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
393 expectf(11.587500, height);
394 GdipDeleteFont(font);
397 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitMillimeter, &font);
399 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
401 expectf(136.860245, height);
402 GdipDeleteFont(font);
404 GdipDeleteFontFamily(fontfamily);
409 struct GdiplusStartupInput gdiplusStartupInput;
410 ULONG_PTR gdiplusToken;
412 gdiplusStartupInput.GdiplusVersion = 1;
413 gdiplusStartupInput.DebugEventCallback = NULL;
414 gdiplusStartupInput.SuppressBackgroundThread = 0;
415 gdiplusStartupInput.SuppressExternalCodecs = 0;
417 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
422 test_fontfamily_properties();
424 test_installedfonts();
425 test_heightgivendpi();
427 GdiplusShutdown(gdiplusToken);