2 * Unit test suite for fonts
4 * Copyright (C) 2007 Google (Evan Stade)
5 * Copyright (C) 2012 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
28 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
29 #define expect_(expected, got, precision) ok(abs((expected) - (got)) <= (precision), "Expected %d, got %d\n", (expected), (got))
30 #define expectf_(expected, got, precision) ok(fabs((expected) - (got)) <= (precision), "Expected %f, got %f\n", (expected), (got))
31 #define expectf(expected, got) expectf_((expected), (got), 0.001)
33 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'};
34 static const WCHAR MSSansSerif[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
35 static const WCHAR MicrosoftSansSerif[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
36 static const WCHAR TimesNewRoman[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
37 static const WCHAR CourierNew[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'};
38 static const WCHAR Tahoma[] = {'T','a','h','o','m','a',0};
39 static const WCHAR LiberationSerif[] = {'L','i','b','e','r','a','t','i','o','n',' ','S','e','r','i','f',0};
41 static void set_rect_empty(RectF *rc)
49 static void test_createfont(void)
51 GpFontFamily* fontfamily = NULL, *fontfamily2;
57 WCHAR familyname[LF_FACESIZE];
59 stat = GdipCreateFontFamilyFromName(nonexistent, NULL, &fontfamily);
60 expect (FontFamilyNotFound, stat);
61 stat = GdipDeleteFont(font);
62 expect (InvalidParameter, stat);
63 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &fontfamily);
65 stat = GdipCreateFont(fontfamily, 12, FontStyleRegular, UnitPoint, &font);
67 stat = GdipGetFontUnit (font, &unit);
69 expect (UnitPoint, unit);
71 stat = GdipGetFamily(font, &fontfamily2);
73 stat = GdipGetFamilyName(fontfamily2, familyname, 0);
75 ok (lstrcmpiW(Tahoma, familyname) == 0, "Expected Tahoma, got %s\n",
76 wine_dbgstr_w(familyname));
77 stat = GdipDeleteFontFamily(fontfamily2);
80 /* Test to see if returned size is based on unit (its not) */
81 GdipGetFontSize(font, &size);
82 ok (size == 12, "Expected 12, got %f\n", size);
85 /* Make sure everything is converted correctly for all Units */
86 for (i = UnitWorld; i <=UnitMillimeter; i++)
88 if (i == UnitDisplay) continue; /* Crashes WindowsXP, wtf? */
89 GdipCreateFont(fontfamily, 24, FontStyleRegular, i, &font);
90 GdipGetFontSize (font, &size);
91 ok (size == 24, "Expected 24, got %f (with unit: %d)\n", size, i);
92 GdipGetFontUnit (font, &unit);
97 GdipDeleteFontFamily(fontfamily);
100 static void test_logfont(void)
104 GpFontFamily *family;
106 GpGraphics *graphics;
110 UINT16 em_height, line_spacing;
113 GdipCreateFromHDC(hdc, &graphics);
115 memset(&lfa, 0, sizeof(LOGFONTA));
116 memset(&lfa2, 0xff, sizeof(LOGFONTA));
117 lstrcpyA(lfa.lfFaceName, "Tahoma");
119 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
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 ok(lfa2.lfCharSet == GetTextCharset(hdc) || lfa2.lfCharSet == ANSI_CHARSET,
133 "Expected %x or %x, got %x\n", GetTextCharset(hdc), ANSI_CHARSET, lfa2.lfCharSet);
134 expect(0, lfa2.lfOutPrecision);
135 expect(0, lfa2.lfClipPrecision);
136 expect(0, lfa2.lfQuality);
137 expect(0, lfa2.lfPitchAndFamily);
139 GdipDeleteFont(font);
141 memset(&lfa, 0, sizeof(LOGFONTA));
144 lfa.lfEscapement = lfa.lfOrientation = 50;
145 lfa.lfItalic = lfa.lfUnderline = lfa.lfStrikeOut = TRUE;
147 memset(&lfa2, 0xff, sizeof(LOGFONTA));
148 lstrcpyA(lfa.lfFaceName, "Tahoma");
150 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
152 stat = GdipGetLogFontA(font, graphics, &lfa2);
155 ok(lfa2.lfHeight < 0, "Expected negative height\n");
156 expect(0, lfa2.lfWidth);
157 expect(0, lfa2.lfEscapement);
158 expect(0, lfa2.lfOrientation);
159 ok((lfa2.lfWeight >= 100) && (lfa2.lfWeight <= 900), "Expected weight to be set\n");
160 expect(TRUE, lfa2.lfItalic);
161 expect(TRUE, lfa2.lfUnderline);
162 expect(TRUE, lfa2.lfStrikeOut);
163 ok(lfa2.lfCharSet == GetTextCharset(hdc) || lfa2.lfCharSet == ANSI_CHARSET,
164 "Expected %x or %x, got %x\n", GetTextCharset(hdc), ANSI_CHARSET, lfa2.lfCharSet);
165 expect(0, lfa2.lfOutPrecision);
166 expect(0, lfa2.lfClipPrecision);
167 expect(0, lfa2.lfQuality);
168 expect(0, lfa2.lfPitchAndFamily);
170 stat = GdipGetFontStyle(font, &style);
172 ok (style == (FontStyleItalic | FontStyleUnderline | FontStyleStrikeout),
173 "Expected , got %d\n", style);
175 stat = GdipGetFontUnit(font, &unit);
177 expect(UnitWorld, unit);
179 stat = GdipGetFontHeight(font, graphics, &rval);
181 expectf(25.347656, rval);
182 stat = GdipGetFontSize(font, &rval);
186 stat = GdipGetFamily(font, &family);
188 stat = GdipGetEmHeight(family, FontStyleRegular, &em_height);
190 expect(2048, em_height);
191 stat = GdipGetLineSpacing(family, FontStyleRegular, &line_spacing);
193 expect(2472, line_spacing);
194 GdipDeleteFontFamily(family);
196 GdipDeleteFont(font);
198 memset(&lfa, 0, sizeof(lfa));
200 lstrcpyA(lfa.lfFaceName, "Tahoma");
201 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
203 memset(&lfa2, 0xff, sizeof(lfa2));
204 stat = GdipGetLogFontA(font, graphics, &lfa2);
206 expect(lfa.lfHeight, lfa2.lfHeight);
208 stat = GdipGetFontUnit(font, &unit);
210 expect(UnitWorld, unit);
212 stat = GdipGetFontHeight(font, graphics, &rval);
214 expectf(30.175781, rval);
215 stat = GdipGetFontSize(font, &rval);
219 stat = GdipGetFamily(font, &family);
221 stat = GdipGetEmHeight(family, FontStyleRegular, &em_height);
223 expect(2048, em_height);
224 stat = GdipGetLineSpacing(family, FontStyleRegular, &line_spacing);
226 expect(2472, line_spacing);
227 GdipDeleteFontFamily(family);
229 GdipDeleteFont(font);
231 GdipDeleteGraphics(graphics);
235 static void test_fontfamily (void)
237 GpFontFamily *family, *clonedFontFamily;
238 WCHAR itsName[LF_FACESIZE];
241 /* FontFamily cannot be NULL */
242 stat = GdipCreateFontFamilyFromName (Tahoma , NULL, NULL);
243 expect (InvalidParameter, stat);
245 /* FontFamily must be able to actually find the family.
246 * If it can't, any subsequent calls should fail.
248 stat = GdipCreateFontFamilyFromName (nonexistent, NULL, &family);
249 expect (FontFamilyNotFound, stat);
251 /* Bitmap fonts are not found */
252 stat = GdipCreateFontFamilyFromName (MSSansSerif, NULL, &family);
253 expect (FontFamilyNotFound, stat);
254 if(stat == Ok) GdipDeleteFontFamily(family);
256 stat = GdipCreateFontFamilyFromName (Tahoma, NULL, &family);
259 stat = GdipGetFamilyName (family, itsName, LANG_NEUTRAL);
261 expect (0, lstrcmpiW(itsName, Tahoma));
265 /* Crashes on Windows XP SP2, Vista, and so Wine as well */
266 stat = GdipGetFamilyName (family, NULL, LANG_NEUTRAL);
270 /* Make sure we don't read old data */
271 ZeroMemory (itsName, sizeof(itsName));
272 stat = GdipCloneFontFamily(family, &clonedFontFamily);
274 GdipDeleteFontFamily(family);
275 stat = GdipGetFamilyName(clonedFontFamily, itsName, LANG_NEUTRAL);
277 expect(0, lstrcmpiW(itsName, Tahoma));
279 GdipDeleteFontFamily(clonedFontFamily);
282 static void test_fontfamily_properties (void)
284 GpFontFamily* FontFamily = NULL;
288 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &FontFamily);
291 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
293 ok (result == 2472, "Expected 2472, got %d\n", result);
295 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
297 ok(result == 2048, "Expected 2048, got %d\n", result);
299 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
301 ok(result == 2049, "Expected 2049, got %d\n", result);
303 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
305 ok(result == 423, "Expected 423, got %d\n", result);
306 GdipDeleteFontFamily(FontFamily);
308 stat = GdipCreateFontFamilyFromName(TimesNewRoman, NULL, &FontFamily);
309 if(stat == FontFamilyNotFound)
310 skip("Times New Roman not installed\n");
314 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
316 ok(result == 2355, "Expected 2355, got %d\n", result);
318 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
320 ok(result == 2048, "Expected 2048, got %d\n", result);
322 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
324 ok(result == 1825, "Expected 1825, got %d\n", result);
326 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
328 ok(result == 443, "Expected 443 got %d\n", result);
329 GdipDeleteFontFamily(FontFamily);
333 static void check_family(const char* context, GpFontFamily *family, WCHAR *name)
339 stat = GdipGetFamilyName(family, name, LANG_NEUTRAL);
340 ok(stat == Ok, "could not get the %s family name: %.8x\n", context, stat);
342 stat = GdipCreateFont(family, 12, FontStyleRegular, UnitPixel, &font);
343 ok(stat == Ok, "could not create a font for the %s family: %.8x\n", context, stat);
346 stat = GdipDeleteFont(font);
347 ok(stat == Ok, "could not delete the %s family font: %.8x\n", context, stat);
350 stat = GdipDeleteFontFamily(family);
351 ok(stat == Ok, "could not delete the %s family: %.8x\n", context, stat);
354 static void test_getgenerics (void)
357 GpFontFamily *family;
358 WCHAR sansname[LF_FACESIZE], serifname[LF_FACESIZE], mononame[LF_FACESIZE];
359 int missingfonts = 0;
361 stat = GdipGetGenericFontFamilySansSerif(&family);
363 if (stat == FontFamilyNotFound)
366 check_family("Sans Serif", family, sansname);
368 stat = GdipGetGenericFontFamilySerif(&family);
370 if (stat == FontFamilyNotFound)
373 check_family("Serif", family, serifname);
375 stat = GdipGetGenericFontFamilyMonospace(&family);
377 if (stat == FontFamilyNotFound)
380 check_family("Monospace", family, mononame);
382 if (missingfonts && strcmp(winetest_platform, "wine") == 0)
383 trace("You may need to install either the Microsoft Web Fonts or the Liberation Fonts\n");
385 /* Check that the family names are all different */
386 ok(lstrcmpiW(sansname, serifname) != 0, "Sans Serif and Serif families should be different: %s\n", wine_dbgstr_w(sansname));
387 ok(lstrcmpiW(sansname, mononame) != 0, "Sans Serif and Monospace families should be different: %s\n", wine_dbgstr_w(sansname));
388 ok(lstrcmpiW(serifname, mononame) != 0, "Serif and Monospace families should be different: %s\n", wine_dbgstr_w(serifname));
391 static void test_installedfonts (void)
394 GpFontCollection* collection=NULL;
396 stat = GdipNewInstalledFontCollection(NULL);
397 expect (InvalidParameter, stat);
399 stat = GdipNewInstalledFontCollection(&collection);
401 ok (collection != NULL, "got NULL font collection\n");
404 static void test_heightgivendpi(void)
408 GpFontFamily* fontfamily = NULL;
412 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &fontfamily);
415 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPixel, &font);
418 stat = GdipGetFontHeightGivenDPI(NULL, 96, &height);
419 expect(InvalidParameter, stat);
421 stat = GdipGetFontHeightGivenDPI(font, 96, NULL);
422 expect(InvalidParameter, stat);
424 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
426 expectf(36.210938, height);
427 GdipDeleteFont(font);
430 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitWorld, &font);
433 stat = GdipGetFontUnit(font, &unit);
435 expect(UnitWorld, unit);
437 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
439 expectf(36.210938, height);
440 GdipDeleteFont(font);
443 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPoint, &font);
445 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
447 expectf(48.281250, height);
448 GdipDeleteFont(font);
451 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitInch, &font);
454 stat = GdipGetFontUnit(font, &unit);
456 expect(UnitInch, unit);
458 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
460 expectf(3476.250000, height);
461 GdipDeleteFont(font);
464 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitDocument, &font);
467 stat = GdipGetFontUnit(font, &unit);
469 expect(UnitDocument, unit);
471 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
473 expectf(11.587500, height);
474 GdipDeleteFont(font);
477 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitMillimeter, &font);
480 stat = GdipGetFontUnit(font, &unit);
482 expect(UnitMillimeter, unit);
484 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
486 expectf(136.860245, height);
487 GdipDeleteFont(font);
489 GdipDeleteFontFamily(fontfamily);
492 static int CALLBACK font_enum_proc(const LOGFONTW *lfe, const TEXTMETRICW *ntme,
493 DWORD type, LPARAM lparam)
495 NEWTEXTMETRICW *ntm = (NEWTEXTMETRICW *)lparam;
497 if (type != TRUETYPE_FONTTYPE) return 1;
499 *ntm = *(NEWTEXTMETRICW *)ntme;
505 UINT16 em_height, line_spacing, ascent, descent;
506 REAL font_height, font_size;
510 static void gdi_get_font_metrics(LOGFONTW *lf, struct font_metrics *fm)
515 OUTLINETEXTMETRICW otm;
518 hdc = CreateCompatibleDC(0);
520 /* it's the only way to get extended NEWTEXTMETRIC fields */
521 ret = EnumFontFamiliesExW(hdc, lf, font_enum_proc, (LPARAM)&ntm, 0);
522 ok(!ret, "EnumFontFamiliesExW failed to find %s\n", wine_dbgstr_w(lf->lfFaceName));
524 hfont = CreateFontIndirectW(lf);
525 SelectObject(hdc, hfont);
527 otm.otmSize = sizeof(otm);
528 ret = GetOutlineTextMetricsW(hdc, otm.otmSize, &otm);
529 ok(ret, "GetOutlineTextMetrics failed\n");
534 fm->lfHeight = -otm.otmTextMetrics.tmAscent;
535 fm->line_spacing = ntm.ntmCellHeight;
536 fm->font_size = (REAL)otm.otmTextMetrics.tmAscent;
537 fm->font_height = (REAL)fm->line_spacing * fm->font_size / (REAL)ntm.ntmSizeEM;
538 fm->em_height = ntm.ntmSizeEM;
539 fm->ascent = ntm.ntmSizeEM;
540 fm->descent = ntm.ntmCellHeight - ntm.ntmSizeEM;
543 static void gdip_get_font_metrics(GpFont *font, struct font_metrics *fm)
546 GpFontFamily *family;
549 stat = GdipGetFontStyle(font, &style);
552 stat = GdipGetFontHeight(font, NULL, &fm->font_height);
554 stat = GdipGetFontSize(font, &fm->font_size);
557 fm->lfHeight = (INT)(fm->font_size * -1.0);
559 stat = GdipGetFamily(font, &family);
562 stat = GdipGetEmHeight(family, style, &fm->em_height);
564 stat = GdipGetLineSpacing(family, style, &fm->line_spacing);
566 stat = GdipGetCellAscent(family, style, &fm->ascent);
568 stat = GdipGetCellDescent(family, style, &fm->descent);
571 GdipDeleteFontFamily(family);
574 static void cmp_font_metrics(struct font_metrics *fm1, struct font_metrics *fm2, int line)
576 ok_(__FILE__, line)(fm1->lfHeight == fm2->lfHeight, "lfHeight %d != %d\n", fm1->lfHeight, fm2->lfHeight);
577 ok_(__FILE__, line)(fm1->em_height == fm2->em_height, "em_height %u != %u\n", fm1->em_height, fm2->em_height);
578 ok_(__FILE__, line)(fm1->line_spacing == fm2->line_spacing, "line_spacing %u != %u\n", fm1->line_spacing, fm2->line_spacing);
579 ok_(__FILE__, line)(abs(fm1->ascent - fm2->ascent) <= 1, "ascent %u != %u\n", fm1->ascent, fm2->ascent);
580 ok_(__FILE__, line)(abs(fm1->descent - fm2->descent) <= 1, "descent %u != %u\n", fm1->descent, fm2->descent);
581 ok(fm1->font_height > 0.0, "fm1->font_height should be positive, got %f\n", fm1->font_height);
582 ok(fm2->font_height > 0.0, "fm2->font_height should be positive, got %f\n", fm2->font_height);
583 ok_(__FILE__, line)(fm1->font_height == fm2->font_height, "font_height %f != %f\n", fm1->font_height, fm2->font_height);
584 ok(fm1->font_size > 0.0, "fm1->font_size should be positive, got %f\n", fm1->font_size);
585 ok(fm2->font_size > 0.0, "fm2->font_size should be positive, got %f\n", fm2->font_size);
586 ok_(__FILE__, line)(fm1->font_size == fm2->font_size, "font_size %f != %f\n", fm1->font_size, fm2->font_size);
589 static void test_font_metrics(void)
593 GpFontFamily *family;
594 GpGraphics *graphics;
597 struct font_metrics fm_gdi, fm_gdip;
600 hdc = CreateCompatibleDC(0);
601 stat = GdipCreateFromHDC(hdc, &graphics);
604 memset(&lf, 0, sizeof(lf));
607 lstrcpyW(lf.lfFaceName, Tahoma);
609 stat = GdipCreateFontFromLogfontW(hdc, &lf, &font);
612 stat = GdipGetFontUnit(font, &unit);
614 expect(UnitWorld, unit);
616 gdip_get_font_metrics(font, &fm_gdip);
618 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
619 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
620 fm_gdip.em_height, fm_gdip.line_spacing, fm_gdip.ascent, fm_gdip.descent,
621 fm_gdip.font_height, fm_gdip.font_size);
623 gdi_get_font_metrics(&lf, &fm_gdi);
625 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
626 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
627 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
628 fm_gdi.font_height, fm_gdi.font_size);
630 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
632 stat = GdipGetLogFontW(font, graphics, &lf);
634 ok(lf.lfHeight < 0, "lf.lfHeight should be negative, got %d\n", lf.lfHeight);
635 gdi_get_font_metrics(&lf, &fm_gdi);
637 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
638 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
639 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
640 fm_gdi.font_height, fm_gdi.font_size);
641 ok((REAL)lf.lfHeight * -1.0 == fm_gdi.font_size, "expected %f, got %f\n", (REAL)lf.lfHeight * -1.0, fm_gdi.font_size);
643 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
645 GdipDeleteFont(font);
648 lstrcpyW(lf.lfFaceName, Tahoma);
650 stat = GdipCreateFontFromLogfontW(hdc, &lf, &font);
653 stat = GdipGetFontUnit(font, &unit);
655 expect(UnitWorld, unit);
657 gdip_get_font_metrics(font, &fm_gdip);
659 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
660 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
661 fm_gdip.em_height, fm_gdip.line_spacing, fm_gdip.ascent, fm_gdip.descent,
662 fm_gdip.font_height, fm_gdip.font_size);
664 gdi_get_font_metrics(&lf, &fm_gdi);
666 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
667 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
668 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
669 fm_gdi.font_height, fm_gdi.font_size);
671 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
673 stat = GdipGetLogFontW(font, graphics, &lf);
675 ok(lf.lfHeight < 0, "lf.lfHeight should be negative, got %d\n", lf.lfHeight);
676 gdi_get_font_metrics(&lf, &fm_gdi);
678 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
679 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
680 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
681 fm_gdi.font_height, fm_gdi.font_size);
682 ok((REAL)lf.lfHeight * -1.0 == fm_gdi.font_size, "expected %f, got %f\n", (REAL)lf.lfHeight * -1.0, fm_gdi.font_size);
684 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
686 GdipDeleteFont(font);
688 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &family);
692 stat = GdipCreateFont(family, 13.0, FontStyleRegular, UnitPixel, &font);
695 gdip_get_font_metrics(font, &fm_gdip);
697 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
698 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
699 fm_gdip.em_height, fm_gdip.line_spacing, fm_gdip.ascent, fm_gdip.descent,
700 fm_gdip.font_height, fm_gdip.font_size);
702 stat = GdipGetLogFontW(font, graphics, &lf);
704 ok(lf.lfHeight < 0, "lf.lfHeight should be negative, got %d\n", lf.lfHeight);
705 gdi_get_font_metrics(&lf, &fm_gdi);
707 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
708 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
709 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
710 fm_gdi.font_height, fm_gdi.font_size);
711 ok((REAL)lf.lfHeight * -1.0 == fm_gdi.font_size, "expected %f, got %f\n", (REAL)lf.lfHeight * -1.0, fm_gdi.font_size);
713 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
715 stat = GdipGetLogFontW(font, NULL, &lf);
716 expect(InvalidParameter, stat);
718 GdipDeleteFont(font);
720 stat = GdipCreateFont(family, -13.0, FontStyleRegular, UnitPixel, &font);
721 expect(InvalidParameter, stat);
723 GdipDeleteFontFamily(family);
725 GdipDeleteGraphics(graphics);
729 static void test_font_substitution(void)
731 WCHAR ms_shell_dlg[LF_FACESIZE];
736 GpGraphics *graphics;
738 GpFontFamily *family;
741 hdc = CreateCompatibleDC(0);
742 status = GdipCreateFromHDC(hdc, &graphics);
745 hfont = GetStockObject(DEFAULT_GUI_FONT);
746 ok(hfont != 0, "GetStockObject(DEFAULT_GUI_FONT) failed\n");
748 memset(&lf, 0xfe, sizeof(lf));
749 ret = GetObject(hfont, sizeof(lf), &lf);
750 ok(ret == sizeof(lf), "GetObject failed\n");
751 ok(!lstrcmp(lf.lfFaceName, "MS Shell Dlg"), "wrong face name %s\n", lf.lfFaceName);
752 MultiByteToWideChar(CP_ACP, 0, lf.lfFaceName, -1, ms_shell_dlg, LF_FACESIZE);
754 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
756 memset(&lf, 0xfe, sizeof(lf));
757 status = GdipGetLogFontA(font, graphics, &lf);
759 ok(!lstrcmp(lf.lfFaceName, "Microsoft Sans Serif") ||
760 !lstrcmp(lf.lfFaceName, "Tahoma"), "wrong face name %s\n", lf.lfFaceName);
761 GdipDeleteFont(font);
763 status = GdipCreateFontFamilyFromName(ms_shell_dlg, NULL, &family);
765 status = GdipCreateFont(family, 12, FontStyleRegular, UnitPoint, &font);
767 memset(&lf, 0xfe, sizeof(lf));
768 status = GdipGetLogFontA(font, graphics, &lf);
770 ok(!lstrcmp(lf.lfFaceName, "Microsoft Sans Serif") ||
771 !lstrcmp(lf.lfFaceName, "Tahoma"), "wrong face name %s\n", lf.lfFaceName);
772 GdipDeleteFont(font);
773 GdipDeleteFontFamily(family);
775 status = GdipCreateFontFamilyFromName(nonexistent, NULL, &family);
776 ok(status == FontFamilyNotFound, "expected FontFamilyNotFound, got %d\n", status);
778 lstrcpy(lf.lfFaceName, "ThisFontShouldNotExist");
779 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
781 memset(&lf, 0xfe, sizeof(lf));
782 status = GdipGetLogFontA(font, graphics, &lf);
784 ok(!lstrcmp(lf.lfFaceName, "Arial"), "wrong face name %s\n", lf.lfFaceName);
785 GdipDeleteFont(font);
788 lf.lfFaceName[0] = 0;
789 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
791 memset(&lf, 0xfe, sizeof(lf));
792 status = GdipGetLogFontA(font, graphics, &lf);
794 ok(!lstrcmp(lf.lfFaceName, "Arial"), "wrong face name %s\n", lf.lfFaceName);
795 GdipDeleteFont(font);
797 /* zeroing out lfWeight and lfCharSet leads to font creation failure */
800 lstrcpy(lf.lfFaceName, "ThisFontShouldNotExist");
801 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
803 ok(status == NotTrueTypeFont || broken(status == FileNotFound), /* before XP */
804 "expected NotTrueTypeFont, got %d\n", status);
807 lf.lfFaceName[0] = 0;
808 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
810 ok(status == NotTrueTypeFont || broken(status == FileNotFound), /* before XP */
811 "expected NotTrueTypeFont, got %d\n", status);
813 GdipDeleteGraphics(graphics);
817 static void test_font_transform(void)
819 static const WCHAR string[] = { 'A',0 };
824 GpGraphics *graphics;
826 GpStringFormat *format, *typographic;
827 PointF pos[1] = { { 0,0 } };
828 REAL height, margin_y;
831 hdc = CreateCompatibleDC(0);
832 status = GdipCreateFromHDC(hdc, &graphics);
835 status = GdipSetPageUnit(graphics, UnitPixel);
838 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
840 status = GdipStringFormatGetGenericTypographic(&typographic);
843 memset(&lf, 0, sizeof(lf));
844 lstrcpy(lf.lfFaceName, "Tahoma");
847 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
850 margin_y = 100.0 / 8.0;
852 /* identity matrix */
853 status = GdipCreateMatrix(&matrix);
855 status = GdipSetWorldTransform(graphics, matrix);
857 status = GdipGetLogFontA(font, graphics, &lf);
859 expect(-100, lf.lfHeight);
860 expect(0, lf.lfWidth);
861 expect(0, lf.lfEscapement);
862 expect(0, lf.lfOrientation);
863 status = GdipGetFontHeight(font, graphics, &height);
865 expectf(120.703125, height);
866 set_rect_empty(&rect);
867 set_rect_empty(&bounds);
868 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
870 expectf(0.0, bounds.X);
871 expectf(0.0, bounds.Y);
873 expectf(height + margin_y, bounds.Height);
874 set_rect_empty(&rect);
875 set_rect_empty(&bounds);
876 status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL);
878 expectf(0.0, bounds.X);
879 expectf(0.0, bounds.Y);
881 expectf(height, bounds.Height);
882 set_rect_empty(&bounds);
883 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
884 DriverStringOptionsCmapLookup, NULL, &bounds);
886 expectf(0.0, bounds.X);
888 expectf_(-100.0, bounds.Y, 0.05);
890 expectf(height, bounds.Height);
891 set_rect_empty(&bounds);
892 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
893 DriverStringOptionsCmapLookup, matrix, &bounds);
895 expectf(0.0, bounds.X);
897 expectf_(-100.0, bounds.Y, 0.05);
899 expectf(height, bounds.Height);
902 status = GdipScaleMatrix(matrix, 2.0, 3.0, MatrixOrderAppend);
904 status = GdipSetWorldTransform(graphics, matrix);
906 status = GdipGetLogFontA(font, graphics, &lf);
908 expect(-300, lf.lfHeight);
909 expect(0, lf.lfWidth);
910 expect(0, lf.lfEscapement);
911 expect(0, lf.lfOrientation);
912 status = GdipGetFontHeight(font, graphics, &height);
914 expectf(120.703125, height);
915 set_rect_empty(&rect);
916 set_rect_empty(&bounds);
917 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
919 expectf(0.0, bounds.X);
920 expectf(0.0, bounds.Y);
922 expectf(height + margin_y, bounds.Height);
923 set_rect_empty(&rect);
924 set_rect_empty(&bounds);
925 status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL);
927 expectf(0.0, bounds.X);
928 expectf(0.0, bounds.Y);
930 expectf(height, bounds.Height);
931 set_rect_empty(&bounds);
932 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
933 DriverStringOptionsCmapLookup, NULL, &bounds);
935 expectf(0.0, bounds.X);
937 expectf_(-100.0, bounds.Y, 0.05);
939 expectf(height, bounds.Height);
940 set_rect_empty(&bounds);
941 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
942 DriverStringOptionsCmapLookup, matrix, &bounds);
944 expectf(0.0, bounds.X);
946 expectf_(-300.0, bounds.Y, 0.15);
948 expectf(height * 3.0, bounds.Height);
950 /* scale + ratate matrix */
951 status = GdipRotateMatrix(matrix, 45.0, MatrixOrderAppend);
953 status = GdipSetWorldTransform(graphics, matrix);
955 status = GdipGetLogFontA(font, graphics, &lf);
957 expect(-300, lf.lfHeight);
958 expect(0, lf.lfWidth);
959 expect_(3151, lf.lfEscapement, 1);
960 expect_(3151, lf.lfOrientation, 1);
961 status = GdipGetFontHeight(font, graphics, &height);
963 expectf(120.703125, height);
964 set_rect_empty(&rect);
965 set_rect_empty(&bounds);
966 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
968 expectf(0.0, bounds.X);
969 expectf(0.0, bounds.Y);
971 expectf(height + margin_y, bounds.Height);
972 set_rect_empty(&rect);
973 set_rect_empty(&bounds);
974 status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL);
976 expectf(0.0, bounds.X);
977 expectf(0.0, bounds.Y);
979 expectf(height, bounds.Height);
980 set_rect_empty(&bounds);
981 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
982 DriverStringOptionsCmapLookup, NULL, &bounds);
984 expectf(0.0, bounds.X);
986 expectf_(-100.0, bounds.Y, 0.05);
988 expectf(height, bounds.Height);
989 set_rect_empty(&bounds);
990 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
991 DriverStringOptionsCmapLookup, matrix, &bounds);
994 expectf_(-43.814377, bounds.X, 0.05);
996 expectf_(-212.235611, bounds.Y, 0.05);
998 expectf_(340.847534, bounds.Height, 0.05);
1000 /* scale + ratate + shear matrix */
1001 status = GdipShearMatrix(matrix, 4.0, 5.0, MatrixOrderAppend);
1003 status = GdipSetWorldTransform(graphics, matrix);
1005 status = GdipGetLogFontA(font, graphics, &lf);
1008 expect(1032, lf.lfHeight);
1009 expect(0, lf.lfWidth);
1010 expect_(3099, lf.lfEscapement, 1);
1011 expect_(3099, lf.lfOrientation, 1);
1012 status = GdipGetFontHeight(font, graphics, &height);
1014 expectf(120.703125, height);
1015 set_rect_empty(&rect);
1016 set_rect_empty(&bounds);
1017 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
1019 expectf(0.0, bounds.X);
1020 expectf(0.0, bounds.Y);
1022 expectf(height + margin_y, bounds.Height);
1023 set_rect_empty(&rect);
1024 set_rect_empty(&bounds);
1025 status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL);
1027 expectf(0.0, bounds.X);
1028 expectf(0.0, bounds.Y);
1030 expectf(height, bounds.Height);
1031 set_rect_empty(&bounds);
1032 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
1033 DriverStringOptionsCmapLookup, NULL, &bounds);
1035 expectf(0.0, bounds.X);
1037 expectf_(-100.0, bounds.Y, 0.05);
1039 expectf(height, bounds.Height);
1040 set_rect_empty(&bounds);
1041 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
1042 DriverStringOptionsCmapLookup, matrix, &bounds);
1045 expectf_(-636.706848, bounds.X, 0.05);
1047 expectf_(-175.257523, bounds.Y, 0.05);
1049 expectf_(1532.984985, bounds.Height, 0.05);
1051 /* scale + ratate + shear + translate matrix */
1052 status = GdipTranslateMatrix(matrix, 10.0, 20.0, MatrixOrderAppend);
1054 status = GdipSetWorldTransform(graphics, matrix);
1056 status = GdipGetLogFontA(font, graphics, &lf);
1059 expect(1032, lf.lfHeight);
1060 expect(0, lf.lfWidth);
1061 expect_(3099, lf.lfEscapement, 1);
1062 expect_(3099, lf.lfOrientation, 1);
1063 status = GdipGetFontHeight(font, graphics, &height);
1065 expectf(120.703125, height);
1066 set_rect_empty(&rect);
1067 set_rect_empty(&bounds);
1068 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
1070 expectf(0.0, bounds.X);
1071 expectf(0.0, bounds.Y);
1073 expectf(height + margin_y, bounds.Height);
1074 set_rect_empty(&rect);
1075 set_rect_empty(&bounds);
1076 status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL);
1078 expectf(0.0, bounds.X);
1079 expectf(0.0, bounds.Y);
1081 expectf(height, bounds.Height);
1082 set_rect_empty(&bounds);
1083 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
1084 DriverStringOptionsCmapLookup, NULL, &bounds);
1086 expectf(0.0, bounds.X);
1088 expectf_(-100.0, bounds.Y, 0.05);
1090 expectf(height, bounds.Height);
1091 set_rect_empty(&bounds);
1092 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
1093 DriverStringOptionsCmapLookup, matrix, &bounds);
1096 expectf_(-626.706848, bounds.X, 0.05);
1098 expectf_(-155.257523, bounds.Y, 0.05);
1100 expectf_(1532.984985, bounds.Height, 0.05);
1102 GdipDeleteMatrix(matrix);
1103 GdipDeleteFont(font);
1104 GdipDeleteGraphics(graphics);
1105 GdipDeleteStringFormat(typographic);
1106 GdipDeleteStringFormat(format);
1112 struct GdiplusStartupInput gdiplusStartupInput;
1113 ULONG_PTR gdiplusToken;
1115 gdiplusStartupInput.GdiplusVersion = 1;
1116 gdiplusStartupInput.DebugEventCallback = NULL;
1117 gdiplusStartupInput.SuppressBackgroundThread = 0;
1118 gdiplusStartupInput.SuppressExternalCodecs = 0;
1120 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1122 test_font_transform();
1123 test_font_substitution();
1124 test_font_metrics();
1128 test_fontfamily_properties();
1130 test_installedfonts();
1131 test_heightgivendpi();
1133 GdiplusShutdown(gdiplusToken);