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 #if CORE_6660_IS_FIXED
101 static void test_logfont(void)
105 GpFontFamily
*family
;
107 GpGraphics
*graphics
;
111 UINT16 em_height
, line_spacing
;
114 GdipCreateFromHDC(hdc
, &graphics
);
116 memset(&lfa
, 0, sizeof(LOGFONTA
));
117 memset(&lfa2
, 0xff, sizeof(LOGFONTA
));
118 lstrcpyA(lfa
.lfFaceName
, "Tahoma");
120 stat
= GdipCreateFontFromLogfontA(hdc
, &lfa
, &font
);
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
, "Tahoma");
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 stat
= GdipGetFontUnit(font
, &unit
);
178 expect(UnitWorld
, unit
);
180 stat
= GdipGetFontHeight(font
, graphics
, &rval
);
182 expectf(25.347656, rval
);
183 stat
= GdipGetFontSize(font
, &rval
);
187 stat
= GdipGetFamily(font
, &family
);
189 stat
= GdipGetEmHeight(family
, FontStyleRegular
, &em_height
);
191 expect(2048, em_height
);
192 stat
= GdipGetLineSpacing(family
, FontStyleRegular
, &line_spacing
);
194 expect(2472, line_spacing
);
195 GdipDeleteFontFamily(family
);
197 GdipDeleteFont(font
);
199 memset(&lfa
, 0, sizeof(lfa
));
201 lstrcpyA(lfa
.lfFaceName
, "Tahoma");
202 stat
= GdipCreateFontFromLogfontA(hdc
, &lfa
, &font
);
204 memset(&lfa2
, 0xff, sizeof(lfa2
));
205 stat
= GdipGetLogFontA(font
, graphics
, &lfa2
);
207 expect(lfa
.lfHeight
, lfa2
.lfHeight
);
209 stat
= GdipGetFontUnit(font
, &unit
);
211 expect(UnitWorld
, unit
);
213 stat
= GdipGetFontHeight(font
, graphics
, &rval
);
215 expectf(30.175781, rval
);
216 stat
= GdipGetFontSize(font
, &rval
);
220 stat
= GdipGetFamily(font
, &family
);
222 stat
= GdipGetEmHeight(family
, FontStyleRegular
, &em_height
);
224 expect(2048, em_height
);
225 stat
= GdipGetLineSpacing(family
, FontStyleRegular
, &line_spacing
);
227 expect(2472, line_spacing
);
228 GdipDeleteFontFamily(family
);
230 GdipDeleteFont(font
);
232 GdipDeleteGraphics(graphics
);
236 static void test_fontfamily (void)
238 GpFontFamily
*family
, *clonedFontFamily
;
239 WCHAR itsName
[LF_FACESIZE
];
242 /* FontFamily cannot be NULL */
243 stat
= GdipCreateFontFamilyFromName (Tahoma
, NULL
, NULL
);
244 expect (InvalidParameter
, stat
);
246 /* FontFamily must be able to actually find the family.
247 * If it can't, any subsequent calls should fail.
249 stat
= GdipCreateFontFamilyFromName (nonexistent
, NULL
, &family
);
250 expect (FontFamilyNotFound
, stat
);
252 /* Bitmap fonts are not found */
253 stat
= GdipCreateFontFamilyFromName (MSSansSerif
, NULL
, &family
);
254 expect (FontFamilyNotFound
, stat
);
255 if(stat
== Ok
) GdipDeleteFontFamily(family
);
257 stat
= GdipCreateFontFamilyFromName (Tahoma
, NULL
, &family
);
260 stat
= GdipGetFamilyName (family
, itsName
, LANG_NEUTRAL
);
262 expect (0, lstrcmpiW(itsName
, Tahoma
));
266 /* Crashes on Windows XP SP2, Vista, and so Wine as well */
267 stat
= GdipGetFamilyName (family
, NULL
, LANG_NEUTRAL
);
271 /* Make sure we don't read old data */
272 ZeroMemory (itsName
, sizeof(itsName
));
273 stat
= GdipCloneFontFamily(family
, &clonedFontFamily
);
275 GdipDeleteFontFamily(family
);
276 stat
= GdipGetFamilyName(clonedFontFamily
, itsName
, LANG_NEUTRAL
);
278 expect(0, lstrcmpiW(itsName
, Tahoma
));
280 GdipDeleteFontFamily(clonedFontFamily
);
282 #endif // CORE_6660_IS_FIXED
284 static void test_fontfamily_properties (void)
286 GpFontFamily
* FontFamily
= NULL
;
290 stat
= GdipCreateFontFamilyFromName(Tahoma
, NULL
, &FontFamily
);
293 stat
= GdipGetLineSpacing(FontFamily
, FontStyleRegular
, &result
);
295 ok (result
== 2472, "Expected 2472, got %d\n", result
);
297 stat
= GdipGetEmHeight(FontFamily
, FontStyleRegular
, &result
);
299 ok(result
== 2048, "Expected 2048, got %d\n", result
);
301 stat
= GdipGetCellAscent(FontFamily
, FontStyleRegular
, &result
);
303 ok(result
== 2049, "Expected 2049, got %d\n", result
);
305 stat
= GdipGetCellDescent(FontFamily
, FontStyleRegular
, &result
);
307 ok(result
== 423, "Expected 423, got %d\n", result
);
308 GdipDeleteFontFamily(FontFamily
);
310 stat
= GdipCreateFontFamilyFromName(TimesNewRoman
, NULL
, &FontFamily
);
311 if(stat
== FontFamilyNotFound
)
312 skip("Times New Roman not installed\n");
316 stat
= GdipGetLineSpacing(FontFamily
, FontStyleRegular
, &result
);
318 ok(result
== 2355, "Expected 2355, got %d\n", result
);
320 stat
= GdipGetEmHeight(FontFamily
, FontStyleRegular
, &result
);
322 ok(result
== 2048, "Expected 2048, got %d\n", result
);
324 stat
= GdipGetCellAscent(FontFamily
, FontStyleRegular
, &result
);
326 ok(result
== 1825, "Expected 1825, got %d\n", result
);
328 stat
= GdipGetCellDescent(FontFamily
, FontStyleRegular
, &result
);
330 ok(result
== 443, "Expected 443 got %d\n", result
);
331 GdipDeleteFontFamily(FontFamily
);
335 static void check_family(const char* context
, GpFontFamily
*family
, WCHAR
*name
)
341 stat
= GdipGetFamilyName(family
, name
, LANG_NEUTRAL
);
342 ok(stat
== Ok
, "could not get the %s family name: %.8x\n", context
, stat
);
344 stat
= GdipCreateFont(family
, 12, FontStyleRegular
, UnitPixel
, &font
);
345 ok(stat
== Ok
, "could not create a font for the %s family: %.8x\n", context
, stat
);
348 stat
= GdipDeleteFont(font
);
349 ok(stat
== Ok
, "could not delete the %s family font: %.8x\n", context
, stat
);
352 stat
= GdipDeleteFontFamily(family
);
353 ok(stat
== Ok
, "could not delete the %s family: %.8x\n", context
, stat
);
356 static void test_getgenerics (void)
359 GpFontFamily
*family
;
360 WCHAR sansname
[LF_FACESIZE
], serifname
[LF_FACESIZE
], mononame
[LF_FACESIZE
];
361 int missingfonts
= 0;
363 stat
= GdipGetGenericFontFamilySansSerif(&family
);
365 if (stat
== FontFamilyNotFound
)
368 check_family("Sans Serif", family
, sansname
);
370 stat
= GdipGetGenericFontFamilySerif(&family
);
372 if (stat
== FontFamilyNotFound
)
375 check_family("Serif", family
, serifname
);
377 stat
= GdipGetGenericFontFamilyMonospace(&family
);
379 if (stat
== FontFamilyNotFound
)
382 check_family("Monospace", family
, mononame
);
384 if (missingfonts
&& strcmp(winetest_platform
, "wine") == 0)
385 trace("You may need to install either the Microsoft Web Fonts or the Liberation Fonts\n");
387 /* Check that the family names are all different */
388 ok(lstrcmpiW(sansname
, serifname
) != 0, "Sans Serif and Serif families should be different: %s\n", wine_dbgstr_w(sansname
));
389 ok(lstrcmpiW(sansname
, mononame
) != 0, "Sans Serif and Monospace families should be different: %s\n", wine_dbgstr_w(sansname
));
390 ok(lstrcmpiW(serifname
, mononame
) != 0, "Serif and Monospace families should be different: %s\n", wine_dbgstr_w(serifname
));
393 static void test_installedfonts (void)
396 GpFontCollection
* collection
=NULL
;
398 stat
= GdipNewInstalledFontCollection(NULL
);
399 expect (InvalidParameter
, stat
);
401 stat
= GdipNewInstalledFontCollection(&collection
);
403 ok (collection
!= NULL
, "got NULL font collection\n");
406 static void test_heightgivendpi(void)
410 GpFontFamily
* fontfamily
= NULL
;
414 stat
= GdipCreateFontFamilyFromName(Tahoma
, NULL
, &fontfamily
);
417 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitPixel
, &font
);
420 stat
= GdipGetFontHeightGivenDPI(NULL
, 96, &height
);
421 expect(InvalidParameter
, stat
);
423 stat
= GdipGetFontHeightGivenDPI(font
, 96, NULL
);
424 expect(InvalidParameter
, stat
);
426 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
428 expectf(36.210938, height
);
429 GdipDeleteFont(font
);
432 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitWorld
, &font
);
435 stat
= GdipGetFontUnit(font
, &unit
);
437 expect(UnitWorld
, unit
);
439 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
441 expectf(36.210938, height
);
442 GdipDeleteFont(font
);
445 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitPoint
, &font
);
447 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
449 expectf(48.281250, height
);
450 GdipDeleteFont(font
);
453 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitInch
, &font
);
456 stat
= GdipGetFontUnit(font
, &unit
);
458 expect(UnitInch
, unit
);
460 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
462 expectf(3476.250000, height
);
463 GdipDeleteFont(font
);
466 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitDocument
, &font
);
469 stat
= GdipGetFontUnit(font
, &unit
);
471 expect(UnitDocument
, unit
);
473 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
475 expectf(11.587500, height
);
476 GdipDeleteFont(font
);
479 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitMillimeter
, &font
);
482 stat
= GdipGetFontUnit(font
, &unit
);
484 expect(UnitMillimeter
, unit
);
486 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
488 expectf(136.860245, height
);
489 GdipDeleteFont(font
);
491 GdipDeleteFontFamily(fontfamily
);
494 #if CORE_6660_IS_FIXED
495 static int CALLBACK
font_enum_proc(const LOGFONTW
*lfe
, const TEXTMETRICW
*ntme
,
496 DWORD type
, LPARAM lparam
)
498 NEWTEXTMETRICW
*ntm
= (NEWTEXTMETRICW
*)lparam
;
500 if (type
!= TRUETYPE_FONTTYPE
) return 1;
502 *ntm
= *(NEWTEXTMETRICW
*)ntme
;
508 UINT16 em_height
, line_spacing
, ascent
, descent
;
509 REAL font_height
, font_size
;
513 static void gdi_get_font_metrics(LOGFONTW
*lf
, struct font_metrics
*fm
)
518 OUTLINETEXTMETRICW otm
;
521 hdc
= CreateCompatibleDC(0);
523 /* it's the only way to get extended NEWTEXTMETRIC fields */
524 ret
= EnumFontFamiliesExW(hdc
, lf
, font_enum_proc
, (LPARAM
)&ntm
, 0);
525 ok(!ret
, "EnumFontFamiliesExW failed to find %s\n", wine_dbgstr_w(lf
->lfFaceName
));
527 hfont
= CreateFontIndirectW(lf
);
528 SelectObject(hdc
, hfont
);
530 otm
.otmSize
= sizeof(otm
);
531 ret
= GetOutlineTextMetricsW(hdc
, otm
.otmSize
, &otm
);
532 ok(ret
, "GetOutlineTextMetrics failed\n");
537 fm
->lfHeight
= -otm
.otmTextMetrics
.tmAscent
;
538 fm
->line_spacing
= ntm
.ntmCellHeight
;
539 fm
->font_size
= (REAL
)otm
.otmTextMetrics
.tmAscent
;
540 fm
->font_height
= (REAL
)fm
->line_spacing
* fm
->font_size
/ (REAL
)ntm
.ntmSizeEM
;
541 fm
->em_height
= ntm
.ntmSizeEM
;
542 fm
->ascent
= ntm
.ntmSizeEM
;
543 fm
->descent
= ntm
.ntmCellHeight
- ntm
.ntmSizeEM
;
546 static void gdip_get_font_metrics(GpFont
*font
, struct font_metrics
*fm
)
549 GpFontFamily
*family
;
552 stat
= GdipGetFontStyle(font
, &style
);
555 stat
= GdipGetFontHeight(font
, NULL
, &fm
->font_height
);
557 stat
= GdipGetFontSize(font
, &fm
->font_size
);
560 fm
->lfHeight
= (INT
)(fm
->font_size
* -1.0);
562 stat
= GdipGetFamily(font
, &family
);
565 stat
= GdipGetEmHeight(family
, style
, &fm
->em_height
);
567 stat
= GdipGetLineSpacing(family
, style
, &fm
->line_spacing
);
569 stat
= GdipGetCellAscent(family
, style
, &fm
->ascent
);
571 stat
= GdipGetCellDescent(family
, style
, &fm
->descent
);
574 GdipDeleteFontFamily(family
);
577 static void cmp_font_metrics(struct font_metrics
*fm1
, struct font_metrics
*fm2
, int line
)
579 ok_(__FILE__
, line
)(fm1
->lfHeight
== fm2
->lfHeight
, "lfHeight %d != %d\n", fm1
->lfHeight
, fm2
->lfHeight
);
580 ok_(__FILE__
, line
)(fm1
->em_height
== fm2
->em_height
, "em_height %u != %u\n", fm1
->em_height
, fm2
->em_height
);
581 ok_(__FILE__
, line
)(fm1
->line_spacing
== fm2
->line_spacing
, "line_spacing %u != %u\n", fm1
->line_spacing
, fm2
->line_spacing
);
582 ok_(__FILE__
, line
)(abs(fm1
->ascent
- fm2
->ascent
) <= 1, "ascent %u != %u\n", fm1
->ascent
, fm2
->ascent
);
583 ok_(__FILE__
, line
)(abs(fm1
->descent
- fm2
->descent
) <= 1, "descent %u != %u\n", fm1
->descent
, fm2
->descent
);
584 ok(fm1
->font_height
> 0.0, "fm1->font_height should be positive, got %f\n", fm1
->font_height
);
585 ok(fm2
->font_height
> 0.0, "fm2->font_height should be positive, got %f\n", fm2
->font_height
);
586 ok_(__FILE__
, line
)(fm1
->font_height
== fm2
->font_height
, "font_height %f != %f\n", fm1
->font_height
, fm2
->font_height
);
587 ok(fm1
->font_size
> 0.0, "fm1->font_size should be positive, got %f\n", fm1
->font_size
);
588 ok(fm2
->font_size
> 0.0, "fm2->font_size should be positive, got %f\n", fm2
->font_size
);
589 ok_(__FILE__
, line
)(fm1
->font_size
== fm2
->font_size
, "font_size %f != %f\n", fm1
->font_size
, fm2
->font_size
);
592 static void test_font_metrics(void)
596 GpFontFamily
*family
;
597 GpGraphics
*graphics
;
600 struct font_metrics fm_gdi
, fm_gdip
;
603 hdc
= CreateCompatibleDC(0);
604 stat
= GdipCreateFromHDC(hdc
, &graphics
);
607 memset(&lf
, 0, sizeof(lf
));
610 lstrcpyW(lf
.lfFaceName
, Tahoma
);
612 stat
= GdipCreateFontFromLogfontW(hdc
, &lf
, &font
);
615 stat
= GdipGetFontUnit(font
, &unit
);
617 expect(UnitWorld
, unit
);
619 gdip_get_font_metrics(font
, &fm_gdip
);
621 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
622 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
623 fm_gdip
.em_height
, fm_gdip
.line_spacing
, fm_gdip
.ascent
, fm_gdip
.descent
,
624 fm_gdip
.font_height
, fm_gdip
.font_size
);
626 gdi_get_font_metrics(&lf
, &fm_gdi
);
628 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
629 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
630 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
631 fm_gdi
.font_height
, fm_gdi
.font_size
);
633 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
635 stat
= GdipGetLogFontW(font
, graphics
, &lf
);
637 ok(lf
.lfHeight
< 0, "lf.lfHeight should be negative, got %d\n", lf
.lfHeight
);
638 gdi_get_font_metrics(&lf
, &fm_gdi
);
640 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
641 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
642 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
643 fm_gdi
.font_height
, fm_gdi
.font_size
);
644 ok((REAL
)lf
.lfHeight
* -1.0 == fm_gdi
.font_size
, "expected %f, got %f\n", (REAL
)lf
.lfHeight
* -1.0, fm_gdi
.font_size
);
646 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
648 GdipDeleteFont(font
);
651 lstrcpyW(lf
.lfFaceName
, Tahoma
);
653 stat
= GdipCreateFontFromLogfontW(hdc
, &lf
, &font
);
656 stat
= GdipGetFontUnit(font
, &unit
);
658 expect(UnitWorld
, unit
);
660 gdip_get_font_metrics(font
, &fm_gdip
);
662 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
663 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
664 fm_gdip
.em_height
, fm_gdip
.line_spacing
, fm_gdip
.ascent
, fm_gdip
.descent
,
665 fm_gdip
.font_height
, fm_gdip
.font_size
);
667 gdi_get_font_metrics(&lf
, &fm_gdi
);
669 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
670 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
671 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
672 fm_gdi
.font_height
, fm_gdi
.font_size
);
674 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
676 stat
= GdipGetLogFontW(font
, graphics
, &lf
);
678 ok(lf
.lfHeight
< 0, "lf.lfHeight should be negative, got %d\n", lf
.lfHeight
);
679 gdi_get_font_metrics(&lf
, &fm_gdi
);
681 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
682 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
683 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
684 fm_gdi
.font_height
, fm_gdi
.font_size
);
685 ok((REAL
)lf
.lfHeight
* -1.0 == fm_gdi
.font_size
, "expected %f, got %f\n", (REAL
)lf
.lfHeight
* -1.0, fm_gdi
.font_size
);
687 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
689 GdipDeleteFont(font
);
691 stat
= GdipCreateFontFamilyFromName(Tahoma
, NULL
, &family
);
695 stat
= GdipCreateFont(family
, 13.0, FontStyleRegular
, UnitPixel
, &font
);
698 gdip_get_font_metrics(font
, &fm_gdip
);
700 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
701 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
702 fm_gdip
.em_height
, fm_gdip
.line_spacing
, fm_gdip
.ascent
, fm_gdip
.descent
,
703 fm_gdip
.font_height
, fm_gdip
.font_size
);
705 stat
= GdipGetLogFontW(font
, graphics
, &lf
);
707 ok(lf
.lfHeight
< 0, "lf.lfHeight should be negative, got %d\n", lf
.lfHeight
);
708 gdi_get_font_metrics(&lf
, &fm_gdi
);
710 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
711 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
712 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
713 fm_gdi
.font_height
, fm_gdi
.font_size
);
714 ok((REAL
)lf
.lfHeight
* -1.0 == fm_gdi
.font_size
, "expected %f, got %f\n", (REAL
)lf
.lfHeight
* -1.0, fm_gdi
.font_size
);
716 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
718 stat
= GdipGetLogFontW(font
, NULL
, &lf
);
719 expect(InvalidParameter
, stat
);
721 GdipDeleteFont(font
);
723 stat
= GdipCreateFont(family
, -13.0, FontStyleRegular
, UnitPixel
, &font
);
724 expect(InvalidParameter
, stat
);
726 GdipDeleteFontFamily(family
);
728 GdipDeleteGraphics(graphics
);
731 #endif // CORE_6660_IS_FIXED
733 static void test_font_substitution(void)
735 WCHAR ms_shell_dlg
[LF_FACESIZE
];
740 GpGraphics
*graphics
;
742 GpFontFamily
*family
;
745 hdc
= CreateCompatibleDC(0);
746 status
= GdipCreateFromHDC(hdc
, &graphics
);
749 hfont
= GetStockObject(DEFAULT_GUI_FONT
);
750 ok(hfont
!= 0, "GetStockObject(DEFAULT_GUI_FONT) failed\n");
752 memset(&lf
, 0xfe, sizeof(lf
));
753 ret
= GetObject(hfont
, sizeof(lf
), &lf
);
754 ok(ret
== sizeof(lf
), "GetObject failed\n");
755 ok(!lstrcmp(lf
.lfFaceName
, "MS Shell Dlg"), "wrong face name %s\n", lf
.lfFaceName
);
756 MultiByteToWideChar(CP_ACP
, 0, lf
.lfFaceName
, -1, ms_shell_dlg
, LF_FACESIZE
);
758 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
760 memset(&lf
, 0xfe, sizeof(lf
));
761 status
= GdipGetLogFontA(font
, graphics
, &lf
);
763 ok(!lstrcmp(lf
.lfFaceName
, "Microsoft Sans Serif") ||
764 !lstrcmp(lf
.lfFaceName
, "Tahoma"), "wrong face name %s\n", lf
.lfFaceName
);
765 GdipDeleteFont(font
);
767 status
= GdipCreateFontFamilyFromName(ms_shell_dlg
, NULL
, &family
);
769 status
= GdipCreateFont(family
, 12, FontStyleRegular
, UnitPoint
, &font
);
771 memset(&lf
, 0xfe, sizeof(lf
));
772 status
= GdipGetLogFontA(font
, graphics
, &lf
);
774 ok(!lstrcmp(lf
.lfFaceName
, "Microsoft Sans Serif") ||
775 !lstrcmp(lf
.lfFaceName
, "Tahoma"), "wrong face name %s\n", lf
.lfFaceName
);
776 GdipDeleteFont(font
);
777 GdipDeleteFontFamily(family
);
779 status
= GdipCreateFontFamilyFromName(nonexistent
, NULL
, &family
);
780 ok(status
== FontFamilyNotFound
, "expected FontFamilyNotFound, got %d\n", status
);
782 lstrcpy(lf
.lfFaceName
, "ThisFontShouldNotExist");
783 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
785 memset(&lf
, 0xfe, sizeof(lf
));
786 status
= GdipGetLogFontA(font
, graphics
, &lf
);
788 ok(!lstrcmp(lf
.lfFaceName
, "Arial"), "wrong face name %s\n", lf
.lfFaceName
);
789 GdipDeleteFont(font
);
792 lf
.lfFaceName
[0] = 0;
793 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
795 memset(&lf
, 0xfe, sizeof(lf
));
796 status
= GdipGetLogFontA(font
, graphics
, &lf
);
798 ok(!lstrcmp(lf
.lfFaceName
, "Arial"), "wrong face name %s\n", lf
.lfFaceName
);
799 GdipDeleteFont(font
);
801 /* zeroing out lfWeight and lfCharSet leads to font creation failure */
804 lstrcpy(lf
.lfFaceName
, "ThisFontShouldNotExist");
805 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
807 ok(status
== NotTrueTypeFont
|| broken(status
== FileNotFound
), /* before XP */
808 "expected NotTrueTypeFont, got %d\n", status
);
811 lf
.lfFaceName
[0] = 0;
812 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
814 ok(status
== NotTrueTypeFont
|| broken(status
== FileNotFound
), /* before XP */
815 "expected NotTrueTypeFont, got %d\n", status
);
817 GdipDeleteGraphics(graphics
);
821 static void test_font_transform(void)
823 static const WCHAR string
[] = { 'A',0 };
828 GpGraphics
*graphics
;
830 GpStringFormat
*format
, *typographic
;
831 PointF pos
[1] = { { 0,0 } };
832 REAL height
, margin_y
;
835 hdc
= CreateCompatibleDC(0);
836 status
= GdipCreateFromHDC(hdc
, &graphics
);
839 status
= GdipSetPageUnit(graphics
, UnitPixel
);
842 status
= GdipCreateStringFormat(0, LANG_NEUTRAL
, &format
);
844 status
= GdipStringFormatGetGenericTypographic(&typographic
);
847 memset(&lf
, 0, sizeof(lf
));
848 lstrcpy(lf
.lfFaceName
, "Tahoma");
851 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
854 margin_y
= 100.0 / 8.0;
856 /* identity matrix */
857 status
= GdipCreateMatrix(&matrix
);
859 status
= GdipSetWorldTransform(graphics
, matrix
);
861 status
= GdipGetLogFontA(font
, graphics
, &lf
);
863 expect(-100, lf
.lfHeight
);
864 expect(0, lf
.lfWidth
);
865 expect(0, lf
.lfEscapement
);
866 expect(0, lf
.lfOrientation
);
867 status
= GdipGetFontHeight(font
, graphics
, &height
);
869 expectf(120.703125, height
);
870 set_rect_empty(&rect
);
871 set_rect_empty(&bounds
);
872 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
874 expectf(0.0, bounds
.X
);
875 expectf(0.0, bounds
.Y
);
877 expectf(height
+ margin_y
, bounds
.Height
);
878 set_rect_empty(&rect
);
879 set_rect_empty(&bounds
);
880 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
882 expectf(0.0, bounds
.X
);
883 expectf(0.0, bounds
.Y
);
885 expectf(height
, bounds
.Height
);
886 set_rect_empty(&bounds
);
887 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
888 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
890 expectf(0.0, bounds
.X
);
892 expectf_(-100.0, bounds
.Y
, 0.05);
894 expectf(height
, bounds
.Height
);
895 set_rect_empty(&bounds
);
896 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
897 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
899 expectf(0.0, bounds
.X
);
901 expectf_(-100.0, bounds
.Y
, 0.05);
903 expectf(height
, bounds
.Height
);
906 status
= GdipScaleMatrix(matrix
, 2.0, 3.0, MatrixOrderAppend
);
908 status
= GdipSetWorldTransform(graphics
, matrix
);
910 status
= GdipGetLogFontA(font
, graphics
, &lf
);
912 expect(-300, lf
.lfHeight
);
913 expect(0, lf
.lfWidth
);
914 expect(0, lf
.lfEscapement
);
915 expect(0, lf
.lfOrientation
);
916 status
= GdipGetFontHeight(font
, graphics
, &height
);
918 expectf(120.703125, height
);
919 set_rect_empty(&rect
);
920 set_rect_empty(&bounds
);
921 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
923 expectf(0.0, bounds
.X
);
924 expectf(0.0, bounds
.Y
);
926 expectf(height
+ margin_y
, bounds
.Height
);
927 set_rect_empty(&rect
);
928 set_rect_empty(&bounds
);
929 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
931 expectf(0.0, bounds
.X
);
932 expectf(0.0, bounds
.Y
);
934 expectf(height
, bounds
.Height
);
935 set_rect_empty(&bounds
);
936 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
937 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
939 expectf(0.0, bounds
.X
);
941 expectf_(-100.0, bounds
.Y
, 0.05);
943 expectf(height
, bounds
.Height
);
944 set_rect_empty(&bounds
);
945 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
946 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
948 expectf(0.0, bounds
.X
);
950 expectf_(-300.0, bounds
.Y
, 0.15);
952 expectf(height
* 3.0, bounds
.Height
);
954 /* scale + ratate matrix */
955 status
= GdipRotateMatrix(matrix
, 45.0, MatrixOrderAppend
);
957 status
= GdipSetWorldTransform(graphics
, matrix
);
959 status
= GdipGetLogFontA(font
, graphics
, &lf
);
961 expect(-300, lf
.lfHeight
);
962 expect(0, lf
.lfWidth
);
963 expect_(3151, lf
.lfEscapement
, 1);
964 expect_(3151, lf
.lfOrientation
, 1);
965 status
= GdipGetFontHeight(font
, graphics
, &height
);
967 expectf(120.703125, height
);
968 set_rect_empty(&rect
);
969 set_rect_empty(&bounds
);
970 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
972 expectf(0.0, bounds
.X
);
973 expectf(0.0, bounds
.Y
);
975 expectf(height
+ margin_y
, bounds
.Height
);
976 set_rect_empty(&rect
);
977 set_rect_empty(&bounds
);
978 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
980 expectf(0.0, bounds
.X
);
981 expectf(0.0, bounds
.Y
);
983 expectf(height
, bounds
.Height
);
984 set_rect_empty(&bounds
);
985 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
986 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
988 expectf(0.0, bounds
.X
);
990 expectf_(-100.0, bounds
.Y
, 0.05);
992 expectf(height
, bounds
.Height
);
993 set_rect_empty(&bounds
);
994 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
995 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
998 expectf_(-43.814377, bounds
.X
, 0.05);
1000 expectf_(-212.235611, bounds
.Y
, 0.05);
1002 expectf_(340.847534, bounds
.Height
, 0.05);
1004 /* scale + ratate + shear matrix */
1005 status
= GdipShearMatrix(matrix
, 4.0, 5.0, MatrixOrderAppend
);
1007 status
= GdipSetWorldTransform(graphics
, matrix
);
1009 status
= GdipGetLogFontA(font
, graphics
, &lf
);
1012 expect(1032, lf
.lfHeight
);
1013 expect(0, lf
.lfWidth
);
1014 expect_(3099, lf
.lfEscapement
, 1);
1015 expect_(3099, lf
.lfOrientation
, 1);
1016 status
= GdipGetFontHeight(font
, graphics
, &height
);
1018 expectf(120.703125, height
);
1019 set_rect_empty(&rect
);
1020 set_rect_empty(&bounds
);
1021 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
1023 expectf(0.0, bounds
.X
);
1024 expectf(0.0, bounds
.Y
);
1026 expectf(height
+ margin_y
, bounds
.Height
);
1027 set_rect_empty(&rect
);
1028 set_rect_empty(&bounds
);
1029 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
1031 expectf(0.0, bounds
.X
);
1032 expectf(0.0, bounds
.Y
);
1034 expectf(height
, bounds
.Height
);
1035 set_rect_empty(&bounds
);
1036 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1037 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
1039 expectf(0.0, bounds
.X
);
1041 expectf_(-100.0, bounds
.Y
, 0.05);
1043 expectf(height
, bounds
.Height
);
1044 set_rect_empty(&bounds
);
1045 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1046 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
1049 expectf_(-636.706848, bounds
.X
, 0.05);
1051 expectf_(-175.257523, bounds
.Y
, 0.05);
1053 expectf_(1532.984985, bounds
.Height
, 0.05);
1055 /* scale + ratate + shear + translate matrix */
1056 status
= GdipTranslateMatrix(matrix
, 10.0, 20.0, MatrixOrderAppend
);
1058 status
= GdipSetWorldTransform(graphics
, matrix
);
1060 status
= GdipGetLogFontA(font
, graphics
, &lf
);
1063 expect(1032, lf
.lfHeight
);
1064 expect(0, lf
.lfWidth
);
1065 expect_(3099, lf
.lfEscapement
, 1);
1066 expect_(3099, lf
.lfOrientation
, 1);
1067 status
= GdipGetFontHeight(font
, graphics
, &height
);
1069 expectf(120.703125, height
);
1070 set_rect_empty(&rect
);
1071 set_rect_empty(&bounds
);
1072 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
1074 expectf(0.0, bounds
.X
);
1075 expectf(0.0, bounds
.Y
);
1077 expectf(height
+ margin_y
, bounds
.Height
);
1078 set_rect_empty(&rect
);
1079 set_rect_empty(&bounds
);
1080 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
1082 expectf(0.0, bounds
.X
);
1083 expectf(0.0, bounds
.Y
);
1085 expectf(height
, bounds
.Height
);
1086 set_rect_empty(&bounds
);
1087 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1088 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
1090 expectf(0.0, bounds
.X
);
1092 expectf_(-100.0, bounds
.Y
, 0.05);
1094 expectf(height
, bounds
.Height
);
1095 set_rect_empty(&bounds
);
1096 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1097 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
1100 expectf_(-626.706848, bounds
.X
, 0.05);
1102 expectf_(-155.257523, bounds
.Y
, 0.05);
1104 expectf_(1532.984985, bounds
.Height
, 0.05);
1106 GdipDeleteMatrix(matrix
);
1107 GdipDeleteFont(font
);
1108 GdipDeleteGraphics(graphics
);
1109 GdipDeleteStringFormat(typographic
);
1110 GdipDeleteStringFormat(format
);
1116 struct GdiplusStartupInput gdiplusStartupInput
;
1117 ULONG_PTR gdiplusToken
;
1119 gdiplusStartupInput
.GdiplusVersion
= 1;
1120 gdiplusStartupInput
.DebugEventCallback
= NULL
;
1121 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
1122 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
1124 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
1126 test_font_transform();
1127 test_font_substitution();
1128 #if CORE_6660_IS_FIXED
1129 test_font_metrics();
1132 #if CORE_6660_IS_FIXED
1136 test_fontfamily_properties();
1138 test_installedfonts();
1139 test_heightgivendpi();
1141 GdiplusShutdown(gdiplusToken
);