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};
37 static const WCHAR LiberationSerif
[] = {'L','i','b','e','r','a','t','i','o','n',' ','S','e','r','i','f',0};
39 static void test_createfont(void)
41 GpFontFamily
* fontfamily
= NULL
, *fontfamily2
;
47 WCHAR familyname
[LF_FACESIZE
];
49 stat
= GdipCreateFontFamilyFromName(nonexistent
, NULL
, &fontfamily
);
50 expect (FontFamilyNotFound
, stat
);
51 stat
= GdipDeleteFont(font
);
52 expect (InvalidParameter
, stat
);
53 stat
= GdipCreateFontFamilyFromName(arial
, NULL
, &fontfamily
);
54 if(stat
== FontFamilyNotFound
)
56 skip("Arial not installed\n");
60 stat
= GdipCreateFont(fontfamily
, 12, FontStyleRegular
, UnitPoint
, &font
);
62 stat
= GdipGetFontUnit (font
, &unit
);
64 expect (UnitPoint
, unit
);
66 stat
= GdipGetFamily(font
, &fontfamily2
);
68 stat
= GdipGetFamilyName(fontfamily2
, familyname
, 0);
70 ok (lstrcmpiW(arial
, familyname
) == 0, "Expected arial, got %s\n",
71 wine_dbgstr_w(familyname
));
72 stat
= GdipDeleteFontFamily(fontfamily2
);
75 /* Test to see if returned size is based on unit (its not) */
76 GdipGetFontSize(font
, &size
);
77 ok (size
== 12, "Expected 12, got %f\n", size
);
80 /* Make sure everything is converted correctly for all Units */
81 for (i
= UnitWorld
; i
<=UnitMillimeter
; i
++)
83 if (i
== UnitDisplay
) continue; /* Crashes WindowsXP, wtf? */
84 GdipCreateFont(fontfamily
, 24, FontStyleRegular
, i
, &font
);
85 GdipGetFontSize (font
, &size
);
86 ok (size
== 24, "Expected 24, got %f (with unit: %d)\n", size
, i
);
87 GdipGetFontUnit (font
, &unit
);
92 GdipDeleteFontFamily(fontfamily
);
95 static void test_logfont(void)
100 GpGraphics
*graphics
;
104 GdipCreateFromHDC(hdc
, &graphics
);
105 memset(&lfa
, 0, sizeof(LOGFONTA
));
106 memset(&lfa2
, 0xff, sizeof(LOGFONTA
));
109 lfa
.lfFaceName
[0] = 0;
110 stat
= GdipCreateFontFromLogfontA(hdc
, &lfa
, &font
);
111 expect(NotTrueTypeFont
, stat
);
113 lstrcpyA(lfa
.lfFaceName
, "Arial");
115 stat
= GdipCreateFontFromLogfontA(hdc
, &lfa
, &font
);
116 if (stat
== FileNotFound
)
118 skip("Arial not installed.\n");
122 stat
= GdipGetLogFontA(font
, graphics
, &lfa2
);
125 ok(lfa2
.lfHeight
< 0, "Expected negative height\n");
126 expect(0, lfa2
.lfWidth
);
127 expect(0, lfa2
.lfEscapement
);
128 expect(0, lfa2
.lfOrientation
);
129 ok((lfa2
.lfWeight
>= 100) && (lfa2
.lfWeight
<= 900), "Expected weight to be set\n");
130 expect(0, lfa2
.lfItalic
);
131 expect(0, lfa2
.lfUnderline
);
132 expect(0, lfa2
.lfStrikeOut
);
133 ok(lfa2
.lfCharSet
== GetTextCharset(hdc
) || lfa2
.lfCharSet
== ANSI_CHARSET
,
134 "Expected %x or %x, got %x\n", GetTextCharset(hdc
), ANSI_CHARSET
, lfa2
.lfCharSet
);
135 expect(0, lfa2
.lfOutPrecision
);
136 expect(0, lfa2
.lfClipPrecision
);
137 expect(0, lfa2
.lfQuality
);
138 expect(0, lfa2
.lfPitchAndFamily
);
140 GdipDeleteFont(font
);
142 memset(&lfa
, 0, sizeof(LOGFONTA
));
145 lfa
.lfEscapement
= lfa
.lfOrientation
= 50;
146 lfa
.lfItalic
= lfa
.lfUnderline
= lfa
.lfStrikeOut
= TRUE
;
148 memset(&lfa2
, 0xff, sizeof(LOGFONTA
));
149 lstrcpyA(lfa
.lfFaceName
, "Arial");
151 stat
= GdipCreateFontFromLogfontA(hdc
, &lfa
, &font
);
153 stat
= GdipGetLogFontA(font
, graphics
, &lfa2
);
156 ok(lfa2
.lfHeight
< 0, "Expected negative height\n");
157 expect(0, lfa2
.lfWidth
);
158 expect(0, lfa2
.lfEscapement
);
159 expect(0, lfa2
.lfOrientation
);
160 ok((lfa2
.lfWeight
>= 100) && (lfa2
.lfWeight
<= 900), "Expected weight to be set\n");
161 expect(TRUE
, lfa2
.lfItalic
);
162 expect(TRUE
, lfa2
.lfUnderline
);
163 expect(TRUE
, lfa2
.lfStrikeOut
);
164 ok(lfa2
.lfCharSet
== GetTextCharset(hdc
) || lfa2
.lfCharSet
== ANSI_CHARSET
,
165 "Expected %x or %x, got %x\n", GetTextCharset(hdc
), ANSI_CHARSET
, lfa2
.lfCharSet
);
166 expect(0, lfa2
.lfOutPrecision
);
167 expect(0, lfa2
.lfClipPrecision
);
168 expect(0, lfa2
.lfQuality
);
169 expect(0, lfa2
.lfPitchAndFamily
);
171 stat
= GdipGetFontStyle(font
, &style
);
173 ok (style
== (FontStyleItalic
| FontStyleUnderline
| FontStyleStrikeout
),
174 "Expected , got %d\n", style
);
176 GdipDeleteFont(font
);
178 GdipDeleteGraphics(graphics
);
182 static void test_fontfamily (void)
184 GpFontFamily
*family
, *clonedFontFamily
;
185 WCHAR itsName
[LF_FACESIZE
];
188 /* FontFamily cannot be NULL */
189 stat
= GdipCreateFontFamilyFromName (arial
, NULL
, NULL
);
190 expect (InvalidParameter
, stat
);
192 /* FontFamily must be able to actually find the family.
193 * If it can't, any subsequent calls should fail.
195 stat
= GdipCreateFontFamilyFromName (nonexistent
, NULL
, &family
);
196 expect (FontFamilyNotFound
, stat
);
198 /* Bitmap fonts are not found */
199 stat
= GdipCreateFontFamilyFromName (MSSansSerif
, NULL
, &family
);
200 expect (FontFamilyNotFound
, stat
);
201 if(stat
== Ok
) GdipDeleteFontFamily(family
);
203 stat
= GdipCreateFontFamilyFromName (arial
, NULL
, &family
);
204 if(stat
== FontFamilyNotFound
)
206 skip("Arial not installed\n");
211 stat
= GdipGetFamilyName (family
, itsName
, LANG_NEUTRAL
);
213 expect (0, lstrcmpiW(itsName
, arial
));
217 /* Crashes on Windows XP SP2, Vista, and so Wine as well */
218 stat
= GdipGetFamilyName (family
, NULL
, LANG_NEUTRAL
);
222 /* Make sure we don't read old data */
223 ZeroMemory (itsName
, sizeof(itsName
));
224 stat
= GdipCloneFontFamily(family
, &clonedFontFamily
);
226 GdipDeleteFontFamily(family
);
227 stat
= GdipGetFamilyName(clonedFontFamily
, itsName
, LANG_NEUTRAL
);
229 expect(0, lstrcmpiW(itsName
, arial
));
231 GdipDeleteFontFamily(clonedFontFamily
);
234 static void test_fontfamily_properties (void)
236 GpFontFamily
* FontFamily
= NULL
;
240 stat
= GdipCreateFontFamilyFromName(arial
, NULL
, &FontFamily
);
241 if(stat
== FontFamilyNotFound
)
242 skip("Arial not installed\n");
245 stat
= GdipGetLineSpacing(FontFamily
, FontStyleRegular
, &result
);
247 ok (result
== 2355, "Expected 2355, got %d\n", result
);
249 stat
= GdipGetEmHeight(FontFamily
, FontStyleRegular
, &result
);
251 ok(result
== 2048, "Expected 2048, got %d\n", result
);
253 stat
= GdipGetCellAscent(FontFamily
, FontStyleRegular
, &result
);
255 ok(result
== 1854, "Expected 1854, got %d\n", result
);
257 stat
= GdipGetCellDescent(FontFamily
, FontStyleRegular
, &result
);
259 ok(result
== 434, "Expected 434, got %d\n", result
);
260 GdipDeleteFontFamily(FontFamily
);
263 stat
= GdipCreateFontFamilyFromName(TimesNewRoman
, NULL
, &FontFamily
);
264 if(stat
== FontFamilyNotFound
)
265 skip("Times New Roman not installed\n");
269 stat
= GdipGetLineSpacing(FontFamily
, FontStyleRegular
, &result
);
271 ok(result
== 2355, "Expected 2355, got %d\n", result
);
273 stat
= GdipGetEmHeight(FontFamily
, FontStyleRegular
, &result
);
275 ok(result
== 2048, "Expected 2048, got %d\n", result
);
277 stat
= GdipGetCellAscent(FontFamily
, FontStyleRegular
, &result
);
279 ok(result
== 1825, "Expected 1825, got %d\n", result
);
281 stat
= GdipGetCellDescent(FontFamily
, FontStyleRegular
, &result
);
283 ok(result
== 443, "Expected 443 got %d\n", result
);
284 GdipDeleteFontFamily(FontFamily
);
288 static void check_family(const char* context
, GpFontFamily
*family
, WCHAR
*name
)
294 stat
= GdipGetFamilyName(family
, name
, LANG_NEUTRAL
);
295 ok(stat
== Ok
, "could not get the %s family name: %.8x\n", context
, stat
);
297 stat
= GdipCreateFont(family
, 12, FontStyleRegular
, UnitPixel
, &font
);
298 ok(stat
== Ok
, "could not create a font for the %s family: %.8x\n", context
, stat
);
301 stat
= GdipDeleteFont(font
);
302 ok(stat
== Ok
, "could not delete the %s family font: %.8x\n", context
, stat
);
305 stat
= GdipDeleteFontFamily(family
);
306 ok(stat
== Ok
, "could not delete the %s family: %.8x\n", context
, stat
);
309 static void test_getgenerics (void)
312 GpFontFamily
*family
;
313 WCHAR sansname
[LF_FACESIZE
], serifname
[LF_FACESIZE
], mononame
[LF_FACESIZE
];
314 int missingfonts
= 0;
316 stat
= GdipGetGenericFontFamilySansSerif(&family
);
318 if (stat
== FontFamilyNotFound
)
321 check_family("Sans Serif", family
, sansname
);
323 stat
= GdipGetGenericFontFamilySerif(&family
);
325 if (stat
== FontFamilyNotFound
)
328 check_family("Serif", family
, serifname
);
330 stat
= GdipGetGenericFontFamilyMonospace(&family
);
332 if (stat
== FontFamilyNotFound
)
335 check_family("Monospace", family
, mononame
);
337 if (missingfonts
&& strcmp(winetest_platform
, "wine") == 0)
338 trace("You may need to install either the Microsoft Web Fonts or the Liberation Fonts\n");
340 /* Check that the family names are all different */
341 ok(lstrcmpiW(sansname
, serifname
) != 0, "Sans Serif and Serif families should be different: %s\n", wine_dbgstr_w(sansname
));
342 ok(lstrcmpiW(sansname
, mononame
) != 0, "Sans Serif and Monospace families should be different: %s\n", wine_dbgstr_w(sansname
));
343 ok(lstrcmpiW(serifname
, mononame
) != 0, "Serif and Monospace families should be different: %s\n", wine_dbgstr_w(serifname
));
346 static void test_installedfonts (void)
349 GpFontCollection
* collection
=NULL
;
351 stat
= GdipNewInstalledFontCollection(NULL
);
352 expect (InvalidParameter
, stat
);
354 stat
= GdipNewInstalledFontCollection(&collection
);
356 ok (collection
!= NULL
, "got NULL font collection\n");
359 static void test_heightgivendpi(void)
363 GpFontFamily
* fontfamily
= NULL
;
366 stat
= GdipCreateFontFamilyFromName(arial
, NULL
, &fontfamily
);
367 if(stat
== FontFamilyNotFound
)
369 skip("Arial not installed\n");
374 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitPixel
, &font
);
377 stat
= GdipGetFontHeightGivenDPI(NULL
, 96, &height
);
378 expect(InvalidParameter
, stat
);
380 stat
= GdipGetFontHeightGivenDPI(font
, 96, NULL
);
381 expect(InvalidParameter
, stat
);
383 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
385 expectf((REAL
)34.497070, height
);
386 GdipDeleteFont(font
);
389 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitWorld
, &font
);
391 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
393 expectf((REAL
)34.497070, height
);
394 GdipDeleteFont(font
);
397 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitPoint
, &font
);
399 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
401 expectf((REAL
)45.996094, height
);
402 GdipDeleteFont(font
);
405 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitInch
, &font
);
407 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
409 expectf((REAL
)3311.718750, height
);
410 GdipDeleteFont(font
);
413 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitDocument
, &font
);
415 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
417 expectf((REAL
)11.039062, height
);
418 GdipDeleteFont(font
);
421 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitMillimeter
, &font
);
423 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
425 expectf((REAL
)130.382614, height
);
426 GdipDeleteFont(font
);
428 GdipDeleteFontFamily(fontfamily
);
433 struct GdiplusStartupInput gdiplusStartupInput
;
434 ULONG_PTR gdiplusToken
;
436 gdiplusStartupInput
.GdiplusVersion
= 1;
437 gdiplusStartupInput
.DebugEventCallback
= NULL
;
438 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
439 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
441 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
446 test_fontfamily_properties();
448 test_installedfonts();
449 test_heightgivendpi();
451 GdiplusShutdown(gdiplusToken
);