static void test_createfont(void) { GpFontFamily* fontfamily = NULL, *fontfamily2; GpFont* font = NULL; GpStatus stat; Unit unit; UINT i; REAL size; WCHAR familyname[LF_FACESIZE]; stat = GdipCreateFontFamilyFromName(nonexistent, NULL, &fontfamily); expect (FontFamilyNotFound, stat); stat = GdipDeleteFont(font); expect (InvalidParameter, stat); stat = GdipCreateFontFamilyFromName(arial, NULL, &fontfamily); if(stat == FontFamilyNotFound) { skip("Arial not installed\n"); return; } expect (Ok, stat); stat = GdipCreateFont(fontfamily, 12, FontStyleRegular, UnitPoint, &font); expect (Ok, stat); stat = GdipGetFontUnit (font, &unit); expect (Ok, stat); expect (UnitPoint, unit); stat = GdipGetFamily(font, &fontfamily2); expect(Ok, stat); stat = GdipGetFamilyName(fontfamily2, familyname, 0); expect(Ok, stat); ok (lstrcmpiW(arial, familyname) == 0, "Expected arial, got %s\n", debugstr_w(familyname)); stat = GdipDeleteFontFamily(fontfamily2); expect(Ok, stat); /* Test to see if returned size is based on unit (its not) */ GdipGetFontSize(font, &size); ok (size == 12, "Expected 12, got %f\n", size); GdipDeleteFont(font); /* Make sure everything is converted correctly for all Units */ for (i = UnitWorld; i <=UnitMillimeter; i++) { if (i == UnitDisplay) continue; /* Crashes WindowsXP, wtf? */ GdipCreateFont(fontfamily, 24, FontStyleRegular, i, &font); GdipGetFontSize (font, &size); ok (size == 24, "Expected 24, got %f (with unit: %d)\n", size, i); GdipGetFontUnit (font, &unit); expect (i, unit); GdipDeleteFont(font); } GdipDeleteFontFamily(fontfamily); }
static void test_fontfamily (void) { GpFontFamily *family, *clonedFontFamily; WCHAR itsName[LF_FACESIZE]; GpStatus stat; /* FontFamily cannot be NULL */ stat = GdipCreateFontFamilyFromName (arial , NULL, NULL); expect (InvalidParameter, stat); /* FontFamily must be able to actually find the family. * If it can't, any subsequent calls should fail. */ stat = GdipCreateFontFamilyFromName (nonexistent, NULL, &family); expect (FontFamilyNotFound, stat); /* Bitmap fonts are not found */ todo_wine { stat = GdipCreateFontFamilyFromName (MSSansSerif, NULL, &family); expect (FontFamilyNotFound, stat); } stat = GdipCreateFontFamilyFromName (arial, NULL, &family); if(stat == FontFamilyNotFound) { skip("Arial not installed\n"); return; } expect (Ok, stat); stat = GdipGetFamilyName (family, itsName, LANG_NEUTRAL); expect (Ok, stat); expect (0, lstrcmpiW(itsName, arial)); if (0) { /* Crashes on Windows XP SP2, Vista, and so Wine as well */ stat = GdipGetFamilyName (family, NULL, LANG_NEUTRAL); expect (Ok, stat); } /* Make sure we don't read old data */ ZeroMemory (itsName, sizeof(itsName)); stat = GdipCloneFontFamily(family, &clonedFontFamily); expect (Ok, stat); GdipDeleteFontFamily(family); stat = GdipGetFamilyName(clonedFontFamily, itsName, LANG_NEUTRAL); expect(Ok, stat); expect(0, lstrcmpiW(itsName, arial)); GdipDeleteFontFamily(clonedFontFamily); }
static void test_fontfamily_properties (void) { GpFontFamily* FontFamily = NULL; GpStatus stat; UINT16 result = 0; stat = GdipCreateFontFamilyFromName(arial, NULL, &FontFamily); if(stat == FontFamilyNotFound) skip("Arial not installed\n"); else { stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result); expect(Ok, stat); ok (result == 2355, "Expected 2355, got %d\n", result); result = 0; stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result); expect(Ok, stat); ok(result == 2048, "Expected 2048, got %d\n", result); result = 0; stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result); expect(Ok, stat); ok(result == 1854, "Expected 1854, got %d\n", result); result = 0; stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result); ok(result == 434, "Expected 434, got %d\n", result); GdipDeleteFontFamily(FontFamily); } stat = GdipCreateFontFamilyFromName(TimesNewRoman, NULL, &FontFamily); if(stat == FontFamilyNotFound) skip("Times New Roman not installed\n"); else { result = 0; stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result); expect(Ok, stat); ok(result == 2355, "Expected 2355, got %d\n", result); result = 0; stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result); expect(Ok, stat); ok(result == 2048, "Expected 2048, got %d\n", result); result = 0; stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result); expect(Ok, stat); ok(result == 1825, "Expected 1825, got %d\n", result); result = 0; stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result); ok(result == 443, "Expected 443 got %d\n", result); GdipDeleteFontFamily(FontFamily); } }
static INT CALLBACK add_font_proc(const LOGFONTW *lfw, const TEXTMETRICW *ntm, DWORD type, LPARAM lParam) { GpFontCollection* fonts = (GpFontCollection*)lParam; int i; /* skip duplicates */ for (i=0; i<fonts->count; i++) if (strcmpiW(lfw->lfFaceName, fonts->FontFamilies[i]->FamilyName) == 0) return 1; if (fonts->allocated == fonts->count) { INT new_alloc_count = fonts->allocated+50; GpFontFamily** new_family_list = HeapAlloc(GetProcessHeap(), 0, new_alloc_count*sizeof(void*)); if (!new_family_list) return 0; memcpy(new_family_list, fonts->FontFamilies, fonts->count*sizeof(void*)); HeapFree(GetProcessHeap(), 0, fonts->FontFamilies); fonts->FontFamilies = new_family_list; fonts->allocated = new_alloc_count; } if (GdipCreateFontFamilyFromName(lfw->lfFaceName, NULL, &fonts->FontFamilies[fonts->count]) == Ok) fonts->count++; else return 0; return 1; }
static GF_Err gdip_set_font(GF_FontReader *dr, const char *fontName, u32 styles) { WCHAR wcFontName[GDIP_MAX_STRING_SIZE]; FontPriv *ctx = (FontPriv *)dr->udta; if (ctx->font) GdipDeleteFontFamily(ctx->font); ctx->font = NULL; if (fontName && strlen(fontName) >= GDIP_MAX_STRING_SIZE) fontName = NULL; if (!fontName || !strlen(fontName) ) fontName = ctx->font_serif; else if (!stricmp(fontName, "SANS") || !stricmp(fontName, "sans-serif")) fontName = ctx->font_sans; else if (!stricmp(fontName, "SERIF")) fontName = ctx->font_serif; else if (!stricmp(fontName, "TYPEWRITER") || !stricmp(fontName, "monospace")) fontName = ctx->font_fixed; MultiByteToWideChar(CP_ACP, 0, fontName, strlen(fontName)+1, wcFontName, sizeof(wcFontName)/sizeof(wcFontName[0]) ); GdipCreateFontFamilyFromName(wcFontName, NULL, &ctx->font); if (!ctx->font) return GF_NOT_SUPPORTED; //setup styles ctx->font_style = 0; if (styles & GF_FONT_WEIGHT_BOLD ) ctx->font_style |= FontStyleBold; if (styles & GF_FONT_ITALIC) ctx->font_style |= FontStyleItalic; if (styles & GF_FONT_UNDERLINED) ctx->font_style |= FontStyleUnderline; if (styles & GF_FONT_STRIKEOUT) ctx->font_style |= FontStyleStrikeout; return GF_OK; }
/***************************************************************************** * GdipGetGenericFontFamilyMonospace [GDIPLUS.@] * * Obtains a serif family (Courier New on Windows) * * PARAMS * **nativeFamily [I] Where the font will be stored * * RETURNS * InvalidParameter if nativeFamily is NULL. * Ok otherwise. */ GpStatus WINGDIPAPI GdipGetGenericFontFamilyMonospace(GpFontFamily **nativeFamily) { static const WCHAR CourierNew[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'}; if (nativeFamily == NULL) return InvalidParameter; return GdipCreateFontFamilyFromName(CourierNew, NULL, nativeFamily); }
static void test_fontfamily (void) { GpFontFamily** family = NULL; WCHAR itsName[LF_FACESIZE]; GpStatus stat; /* FontFamily can not be NULL */ stat = GdipCreateFontFamilyFromName (arial , NULL, family); expect (InvalidParameter, stat); family = GdipAlloc (sizeof (GpFontFamily*)); /* FontFamily must be able to actually find the family. * If it can't, any subsequent calls should fail * * We currently fail (meaning we don't) because we don't actually * test to see if we can successfully get a family */ stat = GdipCreateFontFamilyFromName (nonexistant, NULL, family); expect (FontFamilyNotFound, stat); stat = GdipGetFamilyName (*family,itsName, LANG_NEUTRAL); expect (InvalidParameter, stat); ok ((lstrcmpiW(itsName,nonexistant) != 0), "Expected a non-zero value for nonexistant font!\n"); stat = GdipDeleteFontFamily(*family); expect (InvalidParameter, stat); stat = GdipCreateFontFamilyFromName (arial, NULL, family); expect (Ok, stat); stat = GdipGetFamilyName (*family, itsName, LANG_NEUTRAL); expect (Ok, stat); expect (0, lstrcmpiW(itsName,arial)); if (0) { /* Crashes on Windows XP SP2, Vista, and so Wine as well */ stat = GdipGetFamilyName (*family, NULL, LANG_NEUTRAL); expect (Ok, stat); } stat = GdipDeleteFontFamily(*family); expect (Ok, stat); if (family) GdipFree (family); }
/******************************************************************************* * GdipGetFamily [GDIPLUS.@] * * Returns the FontFamily for the specified Font * * PARAMS * font [I] Font to request from * family [O] Resulting FontFamily object * * RETURNS * SUCCESS: Ok * FAILURE: An element of GpStatus */ GpStatus WINGDIPAPI GdipGetFamily(GpFont *font, GpFontFamily **family) { TRACE("%p %p\n", font, family); if (!(font && family)) return InvalidParameter; return GdipCreateFontFamilyFromName(font->lfw.lfFaceName, NULL, family); }
/***************************************************************************** * GdipGetGenericFontFamilyMonospace [GDIPLUS.@] * * Obtains a serif family (Courier New on Windows) * * PARAMS * **nativeFamily [I] Where the font will be stored * * RETURNS * InvalidParameter if nativeFamily is NULL. * Ok otherwise. */ GpStatus WINGDIPAPI GdipGetGenericFontFamilyMonospace(GpFontFamily **nativeFamily) { static const WCHAR CourierNew[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'}; static const WCHAR LiberationMono[] = {'L','i','b','e','r','a','t','i','o','n',' ','M','o','n','o','\0'}; GpStatus stat; if (nativeFamily == NULL) return InvalidParameter; stat = GdipCreateFontFamilyFromName(CourierNew, NULL, nativeFamily); if (stat == FontFamilyNotFound) stat = GdipCreateFontFamilyFromName(LiberationMono, NULL, nativeFamily); if (stat == FontFamilyNotFound) ERR("Missing 'Courier New' font\n"); return stat; }
/***************************************************************************** * GdipGetGenericFontFamilySansSerif [GDIPLUS.@] * * Obtains a serif family (Microsoft Sans Serif on Windows) * * PARAMS * **nativeFamily [I] Where the font will be stored * * RETURNS * InvalidParameter if nativeFamily is NULL. * Ok otherwise. */ GpStatus WINGDIPAPI GdipGetGenericFontFamilySansSerif(GpFontFamily **nativeFamily) { GpStatus stat; static const WCHAR MicrosoftSansSerif[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'}; static const WCHAR Tahoma[] = {'T','a','h','o','m','a','\0'}; TRACE("(%p)\n", nativeFamily); if (nativeFamily == NULL) return InvalidParameter; stat = GdipCreateFontFamilyFromName(MicrosoftSansSerif, NULL, nativeFamily); if (stat == FontFamilyNotFound) /* FIXME: Microsoft Sans Serif is not installed on Wine. */ stat = GdipCreateFontFamilyFromName(Tahoma, NULL, nativeFamily); return stat; }
/***************************************************************************** * GdipGetGenericFontFamilySerif [GDIPLUS.@] * * Obtains a serif family (Times New Roman on Windows) * * PARAMS * **nativeFamily [I] Where the font will be stored * * RETURNS * InvalidParameter if nativeFamily is NULL. * Ok otherwise. */ GpStatus WINGDIPAPI GdipGetGenericFontFamilySerif(GpFontFamily **nativeFamily) { static const WCHAR TimesNewRoman[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'}; TRACE("(%p)\n", nativeFamily); if (nativeFamily == NULL) return InvalidParameter; return GdipCreateFontFamilyFromName(TimesNewRoman, NULL, nativeFamily); }
/***************************************************************************** * GdipGetGenericFontFamilySerif [GDIPLUS.@] * * Obtains a serif family (Times New Roman on Windows) * * PARAMS * **nativeFamily [I] Where the font will be stored * * RETURNS * InvalidParameter if nativeFamily is NULL. * Ok otherwise. */ GpStatus WINGDIPAPI GdipGetGenericFontFamilySerif(GpFontFamily **nativeFamily) { static const WCHAR TimesNewRoman[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'}; static const WCHAR LiberationSerif[] = {'L','i','b','e','r','a','t','i','o','n',' ','S','e','r','i','f','\0'}; GpStatus stat; TRACE("(%p)\n", nativeFamily); if (nativeFamily == NULL) return InvalidParameter; stat = GdipCreateFontFamilyFromName(TimesNewRoman, NULL, nativeFamily); if (stat == FontFamilyNotFound) stat = GdipCreateFontFamilyFromName(LiberationSerif, NULL, nativeFamily); if (stat == FontFamilyNotFound) ERR("Missing 'Times New Roman' font\n"); return stat; }
/***************************************************************************** * GdipGetGenericFontFamilySansSerif [GDIPLUS.@] * * Obtains a serif family (Microsoft Sans Serif on Windows) * * PARAMS * **nativeFamily [I] Where the font will be stored * * RETURNS * InvalidParameter if nativeFamily is NULL. * Ok otherwise. */ GpStatus WINGDIPAPI GdipGetGenericFontFamilySansSerif(GpFontFamily **nativeFamily) { /* FIXME: On Windows this is called Microsoft Sans Serif, this shouldn't * affect anything */ static const WCHAR MSSansSerif[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}; TRACE("(%p)\n", nativeFamily); if (nativeFamily == NULL) return InvalidParameter; return GdipCreateFontFamilyFromName(MSSansSerif, NULL, nativeFamily); }
static void test_createfont(void) { GpFontFamily* fontfamily = NULL; GpFont* font = NULL; GpStatus stat; Unit unit; UINT i; REAL size; stat = GdipCreateFontFamilyFromName(nonexistant, NULL, &fontfamily); expect (FontFamilyNotFound, stat); stat = GdipDeleteFont(font); expect (InvalidParameter, stat); stat = GdipCreateFontFamilyFromName(arial, NULL, &fontfamily); expect (Ok, stat); stat = GdipCreateFont(fontfamily, 12, FontStyleRegular, UnitPoint, &font); expect (Ok, stat); stat = GdipGetFontUnit (font, &unit); expect (Ok, stat); expect (UnitPoint, unit); /* Test to see if returned size is based on unit (its not) */ GdipGetFontSize(font, &size); ok (size == 12, "Expected 12, got %f\n", size); GdipDeleteFont(font); /* Make sure everything is converted correctly for all Units */ for (i = UnitWorld; i <=UnitMillimeter; i++) { if (i == UnitDisplay) continue; /* Crashes WindowsXP, wtf? */ GdipCreateFont(fontfamily, 24, FontStyleRegular, i, &font); GdipGetFontSize (font, &size); ok (size == 24, "Expected 24, got %f (with unit: %d)\n", size, i); GdipGetFontUnit (font, &unit); expect (i, unit); GdipDeleteFont(font); } }
/******************************************************************************* * GdipCreateFontFromLogfontW [GDIPLUS.@] */ GpStatus WINGDIPAPI GdipCreateFontFromLogfontW(HDC hdc, GDIPCONST LOGFONTW *logfont, GpFont **font) { HFONT hfont, oldfont; OUTLINETEXTMETRICW otm; GpStatus stat; int ret; TRACE("(%p, %p, %p)\n", hdc, logfont, font); if (!hdc || !logfont || !font) return InvalidParameter; hfont = CreateFontIndirectW(logfont); oldfont = SelectObject(hdc, hfont); otm.otmSize = sizeof(otm); ret = GetOutlineTextMetricsW(hdc, otm.otmSize, &otm); SelectObject(hdc, oldfont); DeleteObject(hfont); if (!ret) return NotTrueTypeFont; *font = GdipAlloc(sizeof(GpFont)); if (!*font) return OutOfMemory; (*font)->unit = UnitWorld; (*font)->emSize = otm.otmTextMetrics.tmAscent; (*font)->otm = otm; stat = GdipCreateFontFamilyFromName(logfont->lfFaceName, NULL, &(*font)->family); if (stat != Ok) { GdipFree(*font); return NotTrueTypeFont; } TRACE("<-- %p\n", *font); return Ok; }
static M4Err gdip_set_font(FontRaster *dr, const char *fontName, const char *styles) { WCHAR wcFontName[GDIP_MAX_STRING_SIZE]; FontPriv *ctx = (FontPriv *)dr->priv; if (ctx->font) GdipDeleteFontFamily(ctx->font); ctx->font = NULL; if (fontName && strlen(fontName) >= GDIP_MAX_STRING_SIZE) fontName = NULL; if (!fontName || !strlen(fontName) ) fontName = ctx->font_serif; else if (!strcmp(fontName, "SANS")) fontName = ctx->font_sans; else if (!strcmp(fontName, "SERIF")) fontName = ctx->font_serif; else if (!strcmp(fontName, "TYPEWRITER")) fontName = ctx->font_fixed; MultiByteToWideChar(CP_ACP, 0, fontName, strlen(fontName)+1, wcFontName, sizeof(wcFontName)/sizeof(wcFontName[0]) ); GdipCreateFontFamilyFromName(wcFontName, NULL, &ctx->font); if (!ctx->font) return M4NotSupported; //setup styles ctx->font_style = 0; if (styles) { if (strstr(styles, "BOLDITALIC")) ctx->font_style |= FontStyleBoldItalic; else if (strstr(styles, "BOLD")) ctx->font_style |= FontStyleBold; else if (strstr(styles, "ITALIC")) ctx->font_style |= FontStyleItalic; if (strstr(styles, "UNDERLINED")) { ctx->font_style |= FontStyleUnderline; } if (strstr(styles, "STRIKEOUT")) { ctx->font_style |= FontStyleStrikeout; } } return M4OK; }
static void test_heightgivendpi(void) { GpStatus stat; GpFont* font = NULL; GpFontFamily* fontfamily = NULL; REAL height; Unit unit; stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &fontfamily); expect(Ok, stat); stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPixel, &font); expect(Ok, stat); stat = GdipGetFontHeightGivenDPI(NULL, 96, &height); expect(InvalidParameter, stat); stat = GdipGetFontHeightGivenDPI(font, 96, NULL); expect(InvalidParameter, stat); stat = GdipGetFontHeightGivenDPI(font, 96, &height); expect(Ok, stat); expectf(36.210938, height); GdipDeleteFont(font); height = 12345; stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitWorld, &font); expect(Ok, stat); stat = GdipGetFontUnit(font, &unit); expect(Ok, stat); expect(UnitWorld, unit); stat = GdipGetFontHeightGivenDPI(font, 96, &height); expect(Ok, stat); expectf(36.210938, height); GdipDeleteFont(font); height = 12345; stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPoint, &font); expect(Ok, stat); stat = GdipGetFontHeightGivenDPI(font, 96, &height); expect(Ok, stat); expectf(48.281250, height); GdipDeleteFont(font); height = 12345; stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitInch, &font); expect(Ok, stat); stat = GdipGetFontUnit(font, &unit); expect(Ok, stat); expect(UnitInch, unit); stat = GdipGetFontHeightGivenDPI(font, 96, &height); expect(Ok, stat); expectf(3476.250000, height); GdipDeleteFont(font); height = 12345; stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitDocument, &font); expect(Ok, stat); stat = GdipGetFontUnit(font, &unit); expect(Ok, stat); expect(UnitDocument, unit); stat = GdipGetFontHeightGivenDPI(font, 96, &height); expect(Ok, stat); expectf(11.587500, height); GdipDeleteFont(font); height = 12345; stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitMillimeter, &font); expect(Ok, stat); stat = GdipGetFontUnit(font, &unit); expect(Ok, stat); expect(UnitMillimeter, unit); stat = GdipGetFontHeightGivenDPI(font, 96, &height); expect(Ok, stat); expectf(136.860245, height); GdipDeleteFont(font); GdipDeleteFontFamily(fontfamily); }
static void test_font_metrics(void) { LOGFONTW lf; GpFont *font; GpFontFamily *family; GpGraphics *graphics; GpStatus stat; Unit unit; struct font_metrics fm_gdi, fm_gdip; HDC hdc; hdc = CreateCompatibleDC(0); stat = GdipCreateFromHDC(hdc, &graphics); expect(Ok, stat); memset(&lf, 0, sizeof(lf)); /* Tahoma,-13 */ lstrcpyW(lf.lfFaceName, Tahoma); lf.lfHeight = -13; stat = GdipCreateFontFromLogfontW(hdc, &lf, &font); expect(Ok, stat); stat = GdipGetFontUnit(font, &unit); expect(Ok, stat); expect(UnitWorld, unit); gdip_get_font_metrics(font, &fm_gdip); trace("gdiplus:\n"); trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n", wine_dbgstr_w(lf.lfFaceName), lf.lfHeight, fm_gdip.em_height, fm_gdip.line_spacing, fm_gdip.ascent, fm_gdip.descent, fm_gdip.font_height, fm_gdip.font_size); gdi_get_font_metrics(&lf, &fm_gdi); trace("gdi:\n"); trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n", wine_dbgstr_w(lf.lfFaceName), lf.lfHeight, fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent, fm_gdi.font_height, fm_gdi.font_size); cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__); stat = GdipGetLogFontW(font, graphics, &lf); expect(Ok, stat); ok(lf.lfHeight < 0, "lf.lfHeight should be negative, got %d\n", lf.lfHeight); gdi_get_font_metrics(&lf, &fm_gdi); trace("gdi:\n"); trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n", wine_dbgstr_w(lf.lfFaceName), lf.lfHeight, fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent, fm_gdi.font_height, fm_gdi.font_size); ok((REAL)lf.lfHeight * -1.0 == fm_gdi.font_size, "expected %f, got %f\n", (REAL)lf.lfHeight * -1.0, fm_gdi.font_size); cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__); GdipDeleteFont(font); /* Tahoma,13 */ lstrcpyW(lf.lfFaceName, Tahoma); lf.lfHeight = 13; stat = GdipCreateFontFromLogfontW(hdc, &lf, &font); expect(Ok, stat); stat = GdipGetFontUnit(font, &unit); expect(Ok, stat); expect(UnitWorld, unit); gdip_get_font_metrics(font, &fm_gdip); trace("gdiplus:\n"); trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n", wine_dbgstr_w(lf.lfFaceName), lf.lfHeight, fm_gdip.em_height, fm_gdip.line_spacing, fm_gdip.ascent, fm_gdip.descent, fm_gdip.font_height, fm_gdip.font_size); gdi_get_font_metrics(&lf, &fm_gdi); trace("gdi:\n"); trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n", wine_dbgstr_w(lf.lfFaceName), lf.lfHeight, fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent, fm_gdi.font_height, fm_gdi.font_size); cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__); stat = GdipGetLogFontW(font, graphics, &lf); expect(Ok, stat); ok(lf.lfHeight < 0, "lf.lfHeight should be negative, got %d\n", lf.lfHeight); gdi_get_font_metrics(&lf, &fm_gdi); trace("gdi:\n"); trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n", wine_dbgstr_w(lf.lfFaceName), lf.lfHeight, fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent, fm_gdi.font_height, fm_gdi.font_size); ok((REAL)lf.lfHeight * -1.0 == fm_gdi.font_size, "expected %f, got %f\n", (REAL)lf.lfHeight * -1.0, fm_gdi.font_size); cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__); GdipDeleteFont(font); stat = GdipCreateFontFamilyFromName(Tahoma, NULL, &family); expect(Ok, stat); /* Tahoma,13 */ stat = GdipCreateFont(family, 13.0, FontStyleRegular, UnitPixel, &font); expect(Ok, stat); gdip_get_font_metrics(font, &fm_gdip); trace("gdiplus:\n"); trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n", wine_dbgstr_w(lf.lfFaceName), lf.lfHeight, fm_gdip.em_height, fm_gdip.line_spacing, fm_gdip.ascent, fm_gdip.descent, fm_gdip.font_height, fm_gdip.font_size); stat = GdipGetLogFontW(font, graphics, &lf); expect(Ok, stat); ok(lf.lfHeight < 0, "lf.lfHeight should be negative, got %d\n", lf.lfHeight); gdi_get_font_metrics(&lf, &fm_gdi); trace("gdi:\n"); trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n", wine_dbgstr_w(lf.lfFaceName), lf.lfHeight, fm_gdi.em_height, fm_gdi.line_spacing, fm_gdi.ascent, fm_gdi.descent, fm_gdi.font_height, fm_gdi.font_size); ok((REAL)lf.lfHeight * -1.0 == fm_gdi.font_size, "expected %f, got %f\n", (REAL)lf.lfHeight * -1.0, fm_gdi.font_size); cmp_font_metrics(&fm_gdip, &fm_gdi, __LINE__); stat = GdipGetLogFontW(font, NULL, &lf); expect(InvalidParameter, stat); GdipDeleteFont(font); stat = GdipCreateFont(family, -13.0, FontStyleRegular, UnitPixel, &font); expect(InvalidParameter, stat); GdipDeleteFontFamily(family); GdipDeleteGraphics(graphics); DeleteDC(hdc); }
static void test_font_substitution(void) { WCHAR ms_shell_dlg[LF_FACESIZE]; HDC hdc; HFONT hfont; LOGFONTA lf; GpStatus status; GpGraphics *graphics; GpFont *font; GpFontFamily *family; int ret; hdc = CreateCompatibleDC(0); status = GdipCreateFromHDC(hdc, &graphics); expect(Ok, status); hfont = GetStockObject(DEFAULT_GUI_FONT); ok(hfont != 0, "GetStockObject(DEFAULT_GUI_FONT) failed\n"); memset(&lf, 0xfe, sizeof(lf)); ret = GetObjectA(hfont, sizeof(lf), &lf); ok(ret == sizeof(lf), "GetObject failed\n"); ok(!lstrcmpA(lf.lfFaceName, "MS Shell Dlg"), "wrong face name %s\n", lf.lfFaceName); MultiByteToWideChar(CP_ACP, 0, lf.lfFaceName, -1, ms_shell_dlg, LF_FACESIZE); status = GdipCreateFontFromLogfontA(hdc, &lf, &font); expect(Ok, status); memset(&lf, 0xfe, sizeof(lf)); status = GdipGetLogFontA(font, graphics, &lf); expect(Ok, status); ok(!lstrcmpA(lf.lfFaceName, "Microsoft Sans Serif") || !lstrcmpA(lf.lfFaceName, "Tahoma"), "wrong face name %s\n", lf.lfFaceName); GdipDeleteFont(font); status = GdipCreateFontFamilyFromName(ms_shell_dlg, NULL, &family); expect(Ok, status); status = GdipCreateFont(family, 12, FontStyleRegular, UnitPoint, &font); expect(Ok, status); memset(&lf, 0xfe, sizeof(lf)); status = GdipGetLogFontA(font, graphics, &lf); expect(Ok, status); ok(!lstrcmpA(lf.lfFaceName, "Microsoft Sans Serif") || !lstrcmpA(lf.lfFaceName, "Tahoma"), "wrong face name %s\n", lf.lfFaceName); GdipDeleteFont(font); GdipDeleteFontFamily(family); status = GdipCreateFontFamilyFromName(nonexistent, NULL, &family); ok(status == FontFamilyNotFound, "expected FontFamilyNotFound, got %d\n", status); lstrcpyA(lf.lfFaceName, "ThisFontShouldNotExist"); status = GdipCreateFontFromLogfontA(hdc, &lf, &font); expect(Ok, status); memset(&lf, 0xfe, sizeof(lf)); status = GdipGetLogFontA(font, graphics, &lf); expect(Ok, status); ok(!lstrcmpA(lf.lfFaceName, "Arial"), "wrong face name %s\n", lf.lfFaceName); GdipDeleteFont(font); /* empty FaceName */ lf.lfFaceName[0] = 0; status = GdipCreateFontFromLogfontA(hdc, &lf, &font); expect(Ok, status); memset(&lf, 0xfe, sizeof(lf)); status = GdipGetLogFontA(font, graphics, &lf); expect(Ok, status); ok(!lstrcmpA(lf.lfFaceName, "Arial"), "wrong face name %s\n", lf.lfFaceName); GdipDeleteFont(font); /* zeroing out lfWeight and lfCharSet leads to font creation failure */ lf.lfWeight = 0; lf.lfCharSet = 0; lstrcpyA(lf.lfFaceName, "ThisFontShouldNotExist"); font = NULL; status = GdipCreateFontFromLogfontA(hdc, &lf, &font); todo_wine ok(status == NotTrueTypeFont || broken(status == FileNotFound), /* before XP */ "expected NotTrueTypeFont, got %d\n", status); /* FIXME: remove when wine is fixed */ if (font) GdipDeleteFont(font); /* empty FaceName */ lf.lfFaceName[0] = 0; font = NULL; status = GdipCreateFontFromLogfontA(hdc, &lf, &font); todo_wine ok(status == NotTrueTypeFont || broken(status == FileNotFound), /* before XP */ "expected NotTrueTypeFont, got %d\n", status); /* FIXME: remove when wine is fixed */ if (font) GdipDeleteFont(font); GdipDeleteGraphics(graphics); DeleteDC(hdc); }
static void test_heightgivendpi(void) { GpStatus stat; GpFont* font = NULL; GpFontFamily* fontfamily = NULL; REAL height; stat = GdipCreateFontFamilyFromName(arial, NULL, &fontfamily); if(stat == FontFamilyNotFound) { skip("Arial not installed\n"); return; } expect(Ok, stat); stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPixel, &font); expect(Ok, stat); stat = GdipGetFontHeightGivenDPI(NULL, 96, &height); expect(InvalidParameter, stat); stat = GdipGetFontHeightGivenDPI(font, 96, NULL); expect(InvalidParameter, stat); stat = GdipGetFontHeightGivenDPI(font, 96, &height); expect(Ok, stat); expectf((REAL)34.497070, height); GdipDeleteFont(font); height = 12345; stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitWorld, &font); expect(Ok, stat); stat = GdipGetFontHeightGivenDPI(font, 96, &height); expect(Ok, stat); expectf((REAL)34.497070, height); GdipDeleteFont(font); height = 12345; stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitPoint, &font); expect(Ok, stat); stat = GdipGetFontHeightGivenDPI(font, 96, &height); expect(Ok, stat); expectf((REAL)45.996094, height); GdipDeleteFont(font); height = 12345; stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitInch, &font); expect(Ok, stat); stat = GdipGetFontHeightGivenDPI(font, 96, &height); expect(Ok, stat); expectf((REAL)3311.718750, height); GdipDeleteFont(font); height = 12345; stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitDocument, &font); expect(Ok, stat); stat = GdipGetFontHeightGivenDPI(font, 96, &height); expect(Ok, stat); expectf((REAL)11.039062, height); GdipDeleteFont(font); height = 12345; stat = GdipCreateFont(fontfamily, 30, FontStyleRegular, UnitMillimeter, &font); expect(Ok, stat); stat = GdipGetFontHeightGivenDPI(font, 96, &height); expect(Ok, stat); expectf((REAL)130.382614, height); GdipDeleteFont(font); GdipDeleteFontFamily(fontfamily); }