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 expectf_(expected, got, precision) ok(fabs((expected) - (got)) <= (precision), "Expected %f, got %f\n", (expected), (got))
30 #define expectf(expected, got) expectf_((expected), (got), 0.001)
32 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'};
33 static const WCHAR MSSansSerif[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
34 static const WCHAR MicrosoftSansSerif[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
35 static const WCHAR TimesNewRoman[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
36 static const WCHAR CourierNew[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'};
37 static const WCHAR Tahoma[] = {'T','a','h','o','m','a',0};
38 static const WCHAR LiberationSerif[] = {'L','i','b','e','r','a','t','i','o','n',' ','S','e','r','i','f',0};
40 static void set_rect_empty(RectF *rc)
48 static void test_createfont(void)
50 GpFontFamily* fontfamily = NULL, *fontfamily2;
56 WCHAR familyname[LF_FACESIZE];
58 stat = GdipCreateFontFamilyFromName(nonexistent, NULL, &fontfamily);
59 expect (FontFamilyNotFound, stat);
60 stat = GdipDeleteFont(font);
61 expect (InvalidParameter, stat);
62 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &fontfamily);
64 stat = GdipCreateFont(fontfamily, 12, FontStyleRegular, UnitPoint, &font);
66 stat = GdipGetFontUnit (font, &unit);
68 expect (UnitPoint, unit);
70 stat = GdipGetFamily(font, &fontfamily2);
72 stat = GdipGetFamilyName(fontfamily2, familyname, 0);
74 ok (lstrcmpiW(Tahoma, familyname) == 0, "Expected Tahoma, got %s\n",
75 wine_dbgstr_w(familyname));
76 stat = GdipDeleteFontFamily(fontfamily2);
79 /* Test to see if returned size is based on unit (its not) */
80 GdipGetFontSize(font, &size);
81 ok (size == 12, "Expected 12, got %f\n", size);
84 /* Make sure everything is converted correctly for all Units */
85 for (i = UnitWorld; i <=UnitMillimeter; i++)
87 if (i == UnitDisplay) continue; /* Crashes WindowsXP, wtf? */
88 GdipCreateFont(fontfamily, 24, FontStyleRegular, i, &font);
89 GdipGetFontSize (font, &size);
90 ok (size == 24, "Expected 24, got %f (with unit: %d)\n", size, i);
91 GdipGetFontUnit (font, &unit);
96 GdipDeleteFontFamily(fontfamily);
99 static void test_logfont(void)
103 GpFontFamily *family;
105 GpGraphics *graphics;
109 UINT16 em_height, line_spacing;
112 GdipCreateFromHDC(hdc, &graphics);
114 memset(&lfa, 0, sizeof(LOGFONTA));
115 memset(&lfa2, 0xff, sizeof(LOGFONTA));
116 lstrcpyA(lfa.lfFaceName, "Tahoma");
118 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
120 stat = GdipGetLogFontA(font, graphics, &lfa2);
123 ok(lfa2.lfHeight < 0, "Expected negative height\n");
124 expect(0, lfa2.lfWidth);
125 expect(0, lfa2.lfEscapement);
126 expect(0, lfa2.lfOrientation);
127 ok((lfa2.lfWeight >= 100) && (lfa2.lfWeight <= 900), "Expected weight to be set\n");
128 expect(0, lfa2.lfItalic);
129 expect(0, lfa2.lfUnderline);
130 expect(0, lfa2.lfStrikeOut);
131 ok(lfa2.lfCharSet == GetTextCharset(hdc) || lfa2.lfCharSet == ANSI_CHARSET,
132 "Expected %x or %x, got %x\n", GetTextCharset(hdc), ANSI_CHARSET, 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, "Tahoma");
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 ok(lfa2.lfCharSet == GetTextCharset(hdc) || lfa2.lfCharSet == ANSI_CHARSET,
163 "Expected %x or %x, got %x\n", GetTextCharset(hdc), ANSI_CHARSET, lfa2.lfCharSet);
164 expect(0, lfa2.lfOutPrecision);
165 expect(0, lfa2.lfClipPrecision);
166 expect(0, lfa2.lfQuality);
167 expect(0, lfa2.lfPitchAndFamily);
169 stat = GdipGetFontStyle(font, &style);
171 ok (style == (FontStyleItalic | FontStyleUnderline | FontStyleStrikeout),
172 "Expected , got %d\n", style);
174 stat = GdipGetFontUnit(font, &unit);
176 expect(UnitWorld, unit);
178 stat = GdipGetFontHeight(font, graphics, &rval);
180 expectf(25.347656, rval);
181 stat = GdipGetFontSize(font, &rval);
185 stat = GdipGetFamily(font, &family);
187 stat = GdipGetEmHeight(family, FontStyleRegular, &em_height);
189 expect(2048, em_height);
190 stat = GdipGetLineSpacing(family, FontStyleRegular, &line_spacing);
192 expect(2472, line_spacing);
193 GdipDeleteFontFamily(family);
195 GdipDeleteFont(font);
197 memset(&lfa, 0, sizeof(lfa));
199 lstrcpyA(lfa.lfFaceName, "Tahoma");
200 stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
202 memset(&lfa2, 0xff, sizeof(lfa2));
203 stat = GdipGetLogFontA(font, graphics, &lfa2);
205 expect(lfa.lfHeight, lfa2.lfHeight);
207 stat = GdipGetFontUnit(font, &unit);
209 expect(UnitWorld, unit);
211 stat = GdipGetFontHeight(font, graphics, &rval);
213 expectf(30.175781, rval);
214 stat = GdipGetFontSize(font, &rval);
218 stat = GdipGetFamily(font, &family);
220 stat = GdipGetEmHeight(family, FontStyleRegular, &em_height);
222 expect(2048, em_height);
223 stat = GdipGetLineSpacing(family, FontStyleRegular, &line_spacing);
225 expect(2472, line_spacing);
226 GdipDeleteFontFamily(family);
228 GdipDeleteFont(font);
230 GdipDeleteGraphics(graphics);
234 static void test_fontfamily (void)
236 GpFontFamily *family, *clonedFontFamily;
237 WCHAR itsName[LF_FACESIZE];
240 /* FontFamily cannot be NULL */
241 stat = GdipCreateFontFamilyFromName (Tahoma , NULL, NULL);
242 expect (InvalidParameter, stat);
244 /* FontFamily must be able to actually find the family.
245 * If it can't, any subsequent calls should fail.
247 stat = GdipCreateFontFamilyFromName (nonexistent, NULL, &family);
248 expect (FontFamilyNotFound, stat);
250 /* Bitmap fonts are not found */
251 stat = GdipCreateFontFamilyFromName (MSSansSerif, NULL, &family);
252 expect (FontFamilyNotFound, stat);
253 if(stat == Ok) GdipDeleteFontFamily(family);
255 stat = GdipCreateFontFamilyFromName (Tahoma, NULL, &family);
258 stat = GdipGetFamilyName (family, itsName, LANG_NEUTRAL);
260 expect (0, lstrcmpiW(itsName, Tahoma));
264 /* Crashes on Windows XP SP2, Vista, and so Wine as well */
265 stat = GdipGetFamilyName (family, NULL, LANG_NEUTRAL);
269 /* Make sure we don't read old data */
270 ZeroMemory (itsName, sizeof(itsName));
271 stat = GdipCloneFontFamily(family, &clonedFontFamily);
273 GdipDeleteFontFamily(family);
274 stat = GdipGetFamilyName(clonedFontFamily, itsName, LANG_NEUTRAL);
276 expect(0, lstrcmpiW(itsName, Tahoma));
278 GdipDeleteFontFamily(clonedFontFamily);
281 static void test_fontfamily_properties (void)
283 GpFontFamily* FontFamily = NULL;
287 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &FontFamily);
290 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
292 ok (result == 2472, "Expected 2472, got %d\n", result);
294 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
296 ok(result == 2048, "Expected 2048, got %d\n", result);
298 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
300 ok(result == 2049, "Expected 2049, got %d\n", result);
302 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
304 ok(result == 423, "Expected 423, got %d\n", result);
305 GdipDeleteFontFamily(FontFamily);
307 stat = GdipCreateFontFamilyFromName(TimesNewRoman, NULL, &FontFamily);
308 if(stat == FontFamilyNotFound)
309 skip("Times New Roman not installed\n");
313 stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result);
315 ok(result == 2355, "Expected 2355, got %d\n", result);
317 stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result);
319 ok(result == 2048, "Expected 2048, got %d\n", result);
321 stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result);
323 ok(result == 1825, "Expected 1825, got %d\n", result);
325 stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result);
327 ok(result == 443, "Expected 443 got %d\n", result);
328 GdipDeleteFontFamily(FontFamily);
332 static void check_family(const char* context, GpFontFamily *family, WCHAR *name)
338 stat = GdipGetFamilyName(family, name, LANG_NEUTRAL);
339 ok(stat == Ok, "could not get the %s family name: %.8x\n", context, stat);
341 stat = GdipCreateFont(family, 12, FontStyleRegular, UnitPixel, &font);
342 ok(stat == Ok, "could not create a font for the %s family: %.8x\n", context, stat);
345 stat = GdipDeleteFont(font);
346 ok(stat == Ok, "could not delete the %s family font: %.8x\n", context, stat);
349 stat = GdipDeleteFontFamily(family);
350 ok(stat == Ok, "could not delete the %s family: %.8x\n", context, stat);
353 static void test_getgenerics (void)
356 GpFontFamily *family;
357 WCHAR sansname[LF_FACESIZE], serifname[LF_FACESIZE], mononame[LF_FACESIZE];
358 int missingfonts = 0;
360 stat = GdipGetGenericFontFamilySansSerif(&family);
362 if (stat == FontFamilyNotFound)
365 check_family("Sans Serif", family, sansname);
367 stat = GdipGetGenericFontFamilySerif(&family);
369 if (stat == FontFamilyNotFound)
372 check_family("Serif", family, serifname);
374 stat = GdipGetGenericFontFamilyMonospace(&family);
376 if (stat == FontFamilyNotFound)
379 check_family("Monospace", family, mononame);
381 if (missingfonts && strcmp(winetest_platform, "wine") == 0)
382 trace("You may need to install either the Microsoft Web Fonts or the Liberation Fonts\n");
384 /* Check that the family names are all different */
385 ok(lstrcmpiW(sansname, serifname) != 0, "Sans Serif and Serif families should be different: %s\n", wine_dbgstr_w(sansname));
386 ok(lstrcmpiW(sansname, mononame) != 0, "Sans Serif and Monospace families should be different: %s\n", wine_dbgstr_w(sansname));
387 ok(lstrcmpiW(serifname, mononame) != 0, "Serif and Monospace families should be different: %s\n", wine_dbgstr_w(serifname));
390 static void test_installedfonts (void)
393 GpFontCollection* collection=NULL;
395 stat = GdipNewInstalledFontCollection(NULL);
396 expect (InvalidParameter, stat);
398 stat = GdipNewInstalledFontCollection(&collection);
400 ok (collection != NULL, "got NULL font collection\n");
403 static void test_heightgivendpi(void)
407 GpFontFamily* fontfamily = NULL;
411 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &fontfamily);
414 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPixel, &font);
417 stat = GdipGetFontHeightGivenDPI(NULL, 96, &height);
418 expect(InvalidParameter, stat);
420 stat = GdipGetFontHeightGivenDPI(font, 96, NULL);
421 expect(InvalidParameter, stat);
423 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
425 expectf(36.210938, height);
426 GdipDeleteFont(font);
429 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitWorld, &font);
432 stat = GdipGetFontUnit(font, &unit);
434 expect(UnitWorld, unit);
436 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
438 expectf(36.210938, height);
439 GdipDeleteFont(font);
442 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPoint, &font);
444 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
446 expectf(48.281250, height);
447 GdipDeleteFont(font);
450 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitInch, &font);
453 stat = GdipGetFontUnit(font, &unit);
455 expect(UnitInch, unit);
457 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
459 expectf(3476.250000, height);
460 GdipDeleteFont(font);
463 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitDocument, &font);
466 stat = GdipGetFontUnit(font, &unit);
468 expect(UnitDocument, unit);
470 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
472 expectf(11.587500, height);
473 GdipDeleteFont(font);
476 stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitMillimeter, &font);
479 stat = GdipGetFontUnit(font, &unit);
481 expect(UnitMillimeter, unit);
483 stat = GdipGetFontHeightGivenDPI(font, 96, &height);
485 expectf(136.860245, height);
486 GdipDeleteFont(font);
488 GdipDeleteFontFamily(fontfamily);
491 static int CALLBACK font_enum_proc(const LOGFONTW *lfe, const TEXTMETRICW *ntme,
492 DWORD type, LPARAM lparam)
494 NEWTEXTMETRICW *ntm = (NEWTEXTMETRICW *)lparam;
496 if (type != TRUETYPE_FONTTYPE) return 1;
498 *ntm = *(NEWTEXTMETRICW *)ntme;
504 UINT16 em_height, line_spacing, ascent, descent;
505 REAL font_height, font_size;
509 static void gdi_get_font_metrics(LOGFONTW *lf, struct font_metrics *fm)
514 OUTLINETEXTMETRICW otm;
517 hdc = CreateCompatibleDC(0);
519 /* it's the only way to get extended NEWTEXTMETRIC fields */
520 ret = EnumFontFamiliesExW(hdc, lf, font_enum_proc, (LPARAM)&ntm, 0);
521 ok(!ret, "EnumFontFamiliesExW failed to find %s\n", wine_dbgstr_w(lf->lfFaceName));
523 hfont = CreateFontIndirectW(lf);
524 SelectObject(hdc, hfont);
526 otm.otmSize = sizeof(otm);
527 ret = GetOutlineTextMetricsW(hdc, otm.otmSize, &otm);
528 ok(ret, "GetOutlineTextMetrics failed\n");
533 fm->lfHeight = -otm.otmTextMetrics.tmAscent;
534 fm->line_spacing = ntm.ntmCellHeight;
535 fm->font_size = (REAL)otm.otmTextMetrics.tmAscent;
536 fm->font_height = (REAL)fm->line_spacing * fm->font_size / (REAL)ntm.ntmSizeEM;
537 fm->em_height = ntm.ntmSizeEM;
538 fm->ascent = ntm.ntmSizeEM;
539 fm->descent = ntm.ntmCellHeight - ntm.ntmSizeEM;
542 static void gdip_get_font_metrics(GpFont *font, struct font_metrics *fm)
545 GpFontFamily *family;
548 stat = GdipGetFontStyle(font, &style);
551 stat = GdipGetFontHeight(font, NULL, &fm->font_height);
553 stat = GdipGetFontSize(font, &fm->font_size);
556 fm->lfHeight = (INT)(fm->font_size * -1.0);
558 stat = GdipGetFamily(font, &family);
561 stat = GdipGetEmHeight(family, style, &fm->em_height);
563 stat = GdipGetLineSpacing(family, style, &fm->line_spacing);
565 stat = GdipGetCellAscent(family, style, &fm->ascent);
567 stat = GdipGetCellDescent(family, style, &fm->descent);
570 GdipDeleteFontFamily(family);
573 static void cmp_font_metrics(struct font_metrics *fm1, struct font_metrics *fm2, int line)
575 ok_(__FILE__, line)(fm1->lfHeight == fm2->lfHeight, "lfHeight %d != %d\n", fm1->lfHeight, fm2->lfHeight);
576 ok_(__FILE__, line)(fm1->em_height == fm2->em_height, "em_height %u != %u\n", fm1->em_height, fm2->em_height);
577 ok_(__FILE__, line)(fm1->line_spacing == fm2->line_spacing, "line_spacing %u != %u\n", fm1->line_spacing, fm2->line_spacing);
578 ok_(__FILE__, line)(abs(fm1->ascent - fm2->ascent) <= 1, "ascent %u != %u\n", fm1->ascent, fm2->ascent);
579 ok_(__FILE__, line)(abs(fm1->descent - fm2->descent) <= 1, "descent %u != %u\n", fm1->descent, fm2->descent);
580 ok(fm1->font_height > 0.0, "fm1->font_height should be positive, got %f\n", fm1->font_height);
581 ok(fm2->font_height > 0.0, "fm2->font_height should be positive, got %f\n", fm2->font_height);
582 ok_(__FILE__, line)(fm1->font_height == fm2->font_height, "font_height %f != %f\n", fm1->font_height, fm2->font_height);
583 ok(fm1->font_size > 0.0, "fm1->font_size should be positive, got %f\n", fm1->font_size);
584 ok(fm2->font_size > 0.0, "fm2->font_size should be positive, got %f\n", fm2->font_size);
585 ok_(__FILE__, line)(fm1->font_size == fm2->font_size, "font_size %f != %f\n", fm1->font_size, fm2->font_size);
588 static void test_font_metrics(void)
592 GpFontFamily *family;
593 GpGraphics *graphics;
596 struct font_metrics fm_gdi, fm_gdip;
599 hdc = CreateCompatibleDC(0);
600 stat = GdipCreateFromHDC(hdc, &graphics);
603 memset(&lf, 0, sizeof(lf));
606 lstrcpyW(lf.lfFaceName, Tahoma);
608 stat = GdipCreateFontFromLogfontW(hdc, &lf, &font);
611 stat = GdipGetFontUnit(font, &unit);
613 expect(UnitWorld, unit);
615 gdip_get_font_metrics(font, &fm_gdip);
617 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
618 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
619 fm_gdip.em_height, fm_gdip.line_spacing, fm_gdip.ascent, fm_gdip.descent,
620 fm_gdip.font_height, fm_gdip.font_size);
622 gdi_get_font_metrics(&lf, &fm_gdi);
624 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
625 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
626 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
627 fm_gdi.font_height, fm_gdi.font_size);
629 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
631 stat = GdipGetLogFontW(font, graphics, &lf);
633 ok(lf.lfHeight < 0, "lf.lfHeight should be negative, got %d\n", lf.lfHeight);
634 gdi_get_font_metrics(&lf, &fm_gdi);
636 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
637 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
638 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
639 fm_gdi.font_height, fm_gdi.font_size);
640 ok((REAL)lf.lfHeight * -1.0 == fm_gdi.font_size, "expected %f, got %f\n", (REAL)lf.lfHeight * -1.0, fm_gdi.font_size);
642 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
644 GdipDeleteFont(font);
647 lstrcpyW(lf.lfFaceName, Tahoma);
649 stat = GdipCreateFontFromLogfontW(hdc, &lf, &font);
652 stat = GdipGetFontUnit(font, &unit);
654 expect(UnitWorld, unit);
656 gdip_get_font_metrics(font, &fm_gdip);
658 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
659 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
660 fm_gdip.em_height, fm_gdip.line_spacing, fm_gdip.ascent, fm_gdip.descent,
661 fm_gdip.font_height, fm_gdip.font_size);
663 gdi_get_font_metrics(&lf, &fm_gdi);
665 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
666 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
667 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
668 fm_gdi.font_height, fm_gdi.font_size);
670 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
672 stat = GdipGetLogFontW(font, graphics, &lf);
674 ok(lf.lfHeight < 0, "lf.lfHeight should be negative, got %d\n", lf.lfHeight);
675 gdi_get_font_metrics(&lf, &fm_gdi);
677 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
678 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
679 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
680 fm_gdi.font_height, fm_gdi.font_size);
681 ok((REAL)lf.lfHeight * -1.0 == fm_gdi.font_size, "expected %f, got %f\n", (REAL)lf.lfHeight * -1.0, fm_gdi.font_size);
683 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
685 GdipDeleteFont(font);
687 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &family);
691 stat = GdipCreateFont(family, 13.0, FontStyleRegular, UnitPixel, &font);
694 gdip_get_font_metrics(font, &fm_gdip);
696 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
697 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
698 fm_gdip.em_height, fm_gdip.line_spacing, fm_gdip.ascent, fm_gdip.descent,
699 fm_gdip.font_height, fm_gdip.font_size);
701 stat = GdipGetLogFontW(font, graphics, &lf);
703 ok(lf.lfHeight < 0, "lf.lfHeight should be negative, got %d\n", lf.lfHeight);
704 gdi_get_font_metrics(&lf, &fm_gdi);
706 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
707 wine_dbgstr_w(lf.lfFaceName), lf.lfHeight,
708 fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent,
709 fm_gdi.font_height, fm_gdi.font_size);
710 ok((REAL)lf.lfHeight * -1.0 == fm_gdi.font_size, "expected %f, got %f\n", (REAL)lf.lfHeight * -1.0, fm_gdi.font_size);
712 cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__);
714 stat = GdipGetLogFontW(font, NULL, &lf);
715 expect(InvalidParameter, stat);
717 GdipDeleteFont(font);
719 stat = GdipCreateFont(family, -13.0, FontStyleRegular, UnitPixel, &font);
720 expect(InvalidParameter, stat);
722 GdipDeleteFontFamily(family);
724 GdipDeleteGraphics(graphics);
728 static void test_font_substitution(void)
730 WCHAR ms_shell_dlg[LF_FACESIZE];
735 GpGraphics *graphics;
737 GpFontFamily *family;
740 hdc = CreateCompatibleDC(0);
741 status = GdipCreateFromHDC(hdc, &graphics);
744 hfont = GetStockObject(DEFAULT_GUI_FONT);
745 ok(hfont != 0, "GetStockObject(DEFAULT_GUI_FONT) failed\n");
747 memset(&lf, 0xfe, sizeof(lf));
748 ret = GetObject(hfont, sizeof(lf), &lf);
749 ok(ret == sizeof(lf), "GetObject failed\n");
750 ok(!lstrcmp(lf.lfFaceName, "MS Shell Dlg"), "wrong face name %s\n", lf.lfFaceName);
751 MultiByteToWideChar(CP_ACP, 0, lf.lfFaceName, -1, ms_shell_dlg, LF_FACESIZE);
753 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
755 memset(&lf, 0xfe, sizeof(lf));
756 status = GdipGetLogFontA(font, graphics, &lf);
758 ok(!lstrcmp(lf.lfFaceName, "Microsoft Sans Serif") ||
759 !lstrcmp(lf.lfFaceName, "Tahoma"), "wrong face name %s\n", lf.lfFaceName);
760 GdipDeleteFont(font);
762 status = GdipCreateFontFamilyFromName(ms_shell_dlg, NULL, &family);
764 status = GdipCreateFont(family, 12, FontStyleRegular, UnitPoint, &font);
766 memset(&lf, 0xfe, sizeof(lf));
767 status = GdipGetLogFontA(font, graphics, &lf);
769 ok(!lstrcmp(lf.lfFaceName, "Microsoft Sans Serif") ||
770 !lstrcmp(lf.lfFaceName, "Tahoma"), "wrong face name %s\n", lf.lfFaceName);
771 GdipDeleteFont(font);
772 GdipDeleteFontFamily(family);
774 status = GdipCreateFontFamilyFromName(nonexistent, NULL, &family);
775 ok(status == FontFamilyNotFound, "expected FontFamilyNotFound, got %d\n", status);
777 lstrcpy(lf.lfFaceName, "ThisFontShouldNotExist");
778 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
780 memset(&lf, 0xfe, sizeof(lf));
781 status = GdipGetLogFontA(font, graphics, &lf);
783 ok(!lstrcmp(lf.lfFaceName, "Arial"), "wrong face name %s\n", lf.lfFaceName);
784 GdipDeleteFont(font);
787 lf.lfFaceName[0] = 0;
788 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
790 memset(&lf, 0xfe, sizeof(lf));
791 status = GdipGetLogFontA(font, graphics, &lf);
793 ok(!lstrcmp(lf.lfFaceName, "Arial"), "wrong face name %s\n", lf.lfFaceName);
794 GdipDeleteFont(font);
796 /* zeroing out lfWeight and lfCharSet leads to font creation failure */
799 lstrcpy(lf.lfFaceName, "ThisFontShouldNotExist");
800 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
802 ok(status == NotTrueTypeFont || broken(status == FileNotFound), /* before XP */
803 "expected NotTrueTypeFont, got %d\n", status);
806 lf.lfFaceName[0] = 0;
807 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
809 ok(status == NotTrueTypeFont || broken(status == FileNotFound), /* before XP */
810 "expected NotTrueTypeFont, got %d\n", status);
812 GdipDeleteGraphics(graphics);
816 static void test_font_transform(void)
818 static const WCHAR string[] = { 'A',0 };
823 GpGraphics *graphics;
825 GpStringFormat *format, *typographic;
826 PointF pos[1] = { { 0,0 } };
827 REAL height, margin_y;
830 hdc = CreateCompatibleDC(0);
831 status = GdipCreateFromHDC(hdc, &graphics);
834 status = GdipSetPageUnit(graphics, UnitPixel);
837 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
839 status = GdipStringFormatGetGenericTypographic(&typographic);
842 memset(&lf, 0, sizeof(lf));
843 lstrcpy(lf.lfFaceName, "Tahoma");
846 status = GdipCreateFontFromLogfontA(hdc, &lf, &font);
849 margin_y = 100.0 / 8.0;
851 /* identity matrix */
852 status = GdipCreateMatrix(&matrix);
854 status = GdipSetWorldTransform(graphics, matrix);
856 status = GdipGetLogFontA(font, graphics, &lf);
858 expect(-100, lf.lfHeight);
859 expect(0, lf.lfWidth);
860 status = GdipGetFontHeight(font, graphics, &height);
862 expectf(120.703125, height);
863 set_rect_empty(&rect);
864 set_rect_empty(&bounds);
865 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
867 expectf(0.0, bounds.X);
868 expectf(0.0, bounds.Y);
870 expectf(height + margin_y, bounds.Height);
871 set_rect_empty(&rect);
872 set_rect_empty(&bounds);
873 status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL);
875 expectf(0.0, bounds.X);
876 expectf(0.0, bounds.Y);
878 expectf(height, bounds.Height);
879 set_rect_empty(&bounds);
880 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
881 DriverStringOptionsCmapLookup, NULL, &bounds);
883 expectf(0.0, bounds.X);
885 expectf_(-100.0, bounds.Y, 0.05);
887 expectf(height, bounds.Height);
888 set_rect_empty(&bounds);
889 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
890 DriverStringOptionsCmapLookup, matrix, &bounds);
892 expectf(0.0, bounds.X);
894 expectf_(-100.0, bounds.Y, 0.05);
896 expectf(height, bounds.Height);
899 status = GdipScaleMatrix(matrix, 2.0, 3.0, MatrixOrderAppend);
901 status = GdipSetWorldTransform(graphics, matrix);
903 status = GdipGetLogFontA(font, graphics, &lf);
906 expect(-300, lf.lfHeight);
907 expect(0, lf.lfWidth);
908 status = GdipGetFontHeight(font, graphics, &height);
910 expectf(120.703125, height);
911 set_rect_empty(&rect);
912 set_rect_empty(&bounds);
913 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
915 expectf(0.0, bounds.X);
916 expectf(0.0, bounds.Y);
918 expectf(height + margin_y, bounds.Height);
919 set_rect_empty(&rect);
920 set_rect_empty(&bounds);
921 status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL);
923 expectf(0.0, bounds.X);
924 expectf(0.0, bounds.Y);
926 expectf(height, bounds.Height);
927 set_rect_empty(&bounds);
928 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
929 DriverStringOptionsCmapLookup, NULL, &bounds);
931 expectf(0.0, bounds.X);
933 expectf_(-100.0, bounds.Y, 0.05);
935 expectf(height, bounds.Height);
936 set_rect_empty(&bounds);
937 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
938 DriverStringOptionsCmapLookup, matrix, &bounds);
940 expectf(0.0, bounds.X);
942 expectf_(-300.0, bounds.Y, 0.15);
944 expectf(height * 3.0, bounds.Height);
946 /* scale + ratate matrix */
947 status = GdipRotateMatrix(matrix, 45.0, MatrixOrderAppend);
949 status = GdipSetWorldTransform(graphics, matrix);
951 status = GdipGetLogFontA(font, graphics, &lf);
954 expect(-300, lf.lfHeight);
955 expect(0, lf.lfWidth);
956 status = GdipGetFontHeight(font, graphics, &height);
958 expectf(120.703125, height);
959 set_rect_empty(&rect);
960 set_rect_empty(&bounds);
961 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
963 expectf(0.0, bounds.X);
964 expectf(0.0, bounds.Y);
966 expectf(height + margin_y, bounds.Height);
967 set_rect_empty(&rect);
968 set_rect_empty(&bounds);
969 status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL);
971 expectf(0.0, bounds.X);
972 expectf(0.0, bounds.Y);
974 expectf(height, bounds.Height);
975 set_rect_empty(&bounds);
976 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
977 DriverStringOptionsCmapLookup, NULL, &bounds);
979 expectf(0.0, bounds.X);
981 expectf_(-100.0, bounds.Y, 0.05);
983 expectf(height, bounds.Height);
984 set_rect_empty(&bounds);
985 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
986 DriverStringOptionsCmapLookup, matrix, &bounds);
989 expectf_(-43.814377, bounds.X, 0.05);
991 expectf_(-212.235611, bounds.Y, 0.05);
993 expectf_(340.847534, bounds.Height, 0.05);
995 /* scale + ratate + shear matrix */
996 status = GdipShearMatrix(matrix, 4.0, 5.0, MatrixOrderAppend);
998 status = GdipSetWorldTransform(graphics, matrix);
1000 status = GdipGetLogFontA(font, graphics, &lf);
1003 expect(1032, lf.lfHeight);
1004 expect(0, lf.lfWidth);
1005 status = GdipGetFontHeight(font, graphics, &height);
1007 expectf(120.703125, height);
1008 set_rect_empty(&rect);
1009 set_rect_empty(&bounds);
1010 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
1012 expectf(0.0, bounds.X);
1013 expectf(0.0, bounds.Y);
1015 expectf(height + margin_y, bounds.Height);
1016 set_rect_empty(&rect);
1017 set_rect_empty(&bounds);
1018 status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL);
1020 expectf(0.0, bounds.X);
1021 expectf(0.0, bounds.Y);
1023 expectf(height, bounds.Height);
1024 set_rect_empty(&bounds);
1025 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
1026 DriverStringOptionsCmapLookup, NULL, &bounds);
1028 expectf(0.0, bounds.X);
1030 expectf_(-100.0, bounds.Y, 0.05);
1032 expectf(height, bounds.Height);
1033 set_rect_empty(&bounds);
1034 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
1035 DriverStringOptionsCmapLookup, matrix, &bounds);
1038 expectf_(-636.706848, bounds.X, 0.05);
1040 expectf_(-175.257523, bounds.Y, 0.05);
1042 expectf_(1532.984985, bounds.Height, 0.05);
1044 /* scale + ratate + shear + translate matrix */
1045 status = GdipTranslateMatrix(matrix, 10.0, 20.0, MatrixOrderAppend);
1047 status = GdipSetWorldTransform(graphics, matrix);
1049 status = GdipGetLogFontA(font, graphics, &lf);
1052 expect(1032, lf.lfHeight);
1053 expect(0, lf.lfWidth);
1054 status = GdipGetFontHeight(font, graphics, &height);
1056 expectf(120.703125, height);
1057 set_rect_empty(&rect);
1058 set_rect_empty(&bounds);
1059 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
1061 expectf(0.0, bounds.X);
1062 expectf(0.0, bounds.Y);
1064 expectf(height + margin_y, bounds.Height);
1065 set_rect_empty(&rect);
1066 set_rect_empty(&bounds);
1067 status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL);
1069 expectf(0.0, bounds.X);
1070 expectf(0.0, bounds.Y);
1072 expectf(height, bounds.Height);
1073 set_rect_empty(&bounds);
1074 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
1075 DriverStringOptionsCmapLookup, NULL, &bounds);
1077 expectf(0.0, bounds.X);
1079 expectf_(-100.0, bounds.Y, 0.05);
1081 expectf(height, bounds.Height);
1082 set_rect_empty(&bounds);
1083 status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos,
1084 DriverStringOptionsCmapLookup, matrix, &bounds);
1087 expectf_(-626.706848, bounds.X, 0.05);
1089 expectf_(-155.257523, bounds.Y, 0.05);
1091 expectf_(1532.984985, bounds.Height, 0.05);
1093 GdipDeleteMatrix(matrix);
1094 GdipDeleteFont(font);
1095 GdipDeleteGraphics(graphics);
1096 GdipDeleteStringFormat(typographic);
1097 GdipDeleteStringFormat(format);
1103 struct GdiplusStartupInput gdiplusStartupInput;
1104 ULONG_PTR gdiplusToken;
1106 gdiplusStartupInput.GdiplusVersion = 1;
1107 gdiplusStartupInput.DebugEventCallback = NULL;
1108 gdiplusStartupInput.SuppressBackgroundThread = 0;
1109 gdiplusStartupInput.SuppressExternalCodecs = 0;
1111 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1113 test_font_transform();
1114 test_font_substitution();
1115 test_font_metrics();
1119 test_fontfamily_properties();
1121 test_installedfonts();
1122 test_heightgivendpi();
1124 GdiplusShutdown(gdiplusToken);