static void test_getgenerics (void) { GpStatus stat; GpFontFamily* family; WCHAR familyName[LF_FACESIZE]; ZeroMemory(familyName, sizeof(familyName)/sizeof(WCHAR)); stat = GdipGetGenericFontFamilySansSerif (&family); if (stat == FontFamilyNotFound) { skip("Microsoft Sans Serif not installed\n"); goto serif; } expect (Ok, stat); stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL); expect (Ok, stat); if (!lstrcmpiW(familyName, Tahoma)) todo_wine ok ((lstrcmpiW(familyName, MicrosoftSansSerif) == 0), "Expected Microsoft Sans Serif, got Tahoma\n"); else ok ((lstrcmpiW(familyName, MicrosoftSansSerif) == 0), "Expected Microsoft Sans Serif, got %s\n", wine_dbgstr_w(familyName)); stat = GdipDeleteFontFamily (family); expect (Ok, stat); serif: stat = GdipGetGenericFontFamilySerif (&family); if (stat == FontFamilyNotFound) { skip("Times New Roman not installed\n"); goto monospace; } expect (Ok, stat); stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL); expect (Ok, stat); ok (lstrcmpiW(familyName, TimesNewRoman) == 0, "Expected Times New Roman, got %s\n", wine_dbgstr_w(familyName)); stat = GdipDeleteFontFamily (family); expect (Ok, stat); monospace: stat = GdipGetGenericFontFamilyMonospace (&family); if (stat == FontFamilyNotFound) { skip("Courier New not installed\n"); return; } expect (Ok, stat); stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL); expect (Ok, stat); ok (lstrcmpiW(familyName, CourierNew) == 0, "Expected Courier New, got %s\n", wine_dbgstr_w(familyName)); stat = GdipDeleteFontFamily (family); expect (Ok, stat); }
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 (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); }
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); }
/******************************************************************************* * GdipCreateFont [GDIPLUS.@] * * Create a new font based off of a FontFamily * * PARAMS * *fontFamily [I] Family to base the font off of * emSize [I] Size of the font * style [I] Bitwise OR of FontStyle enumeration * unit [I] Unit emSize is measured in * **font [I] the resulting Font object * * RETURNS * SUCCESS: Ok * FAILURE: InvalidParameter if fontfamily or font is NULL. * FAILURE: FontFamilyNotFound if an invalid FontFamily is given * * NOTES * UnitDisplay is unsupported. * emSize is stored separately from lfHeight, to hold the fraction. */ GpStatus WINGDIPAPI GdipCreateFont(GDIPCONST GpFontFamily *fontFamily, REAL emSize, INT style, Unit unit, GpFont **font) { HFONT hfont; OUTLINETEXTMETRICW otm; LOGFONTW lfw; HDC hdc; GpStatus stat; int ret; if (!fontFamily || !font || emSize < 0.0) return InvalidParameter; TRACE("%p (%s), %f, %d, %d, %p\n", fontFamily, debugstr_w(fontFamily->FamilyName), emSize, style, unit, font); memset(&lfw, 0, sizeof(lfw)); stat = GdipGetFamilyName(fontFamily, lfw.lfFaceName, LANG_NEUTRAL); if (stat != Ok) return stat; lfw.lfHeight = -units_to_pixels(emSize, unit, fontFamily->dpi); lfw.lfWeight = style & FontStyleBold ? FW_BOLD : FW_REGULAR; lfw.lfItalic = style & FontStyleItalic; lfw.lfUnderline = style & FontStyleUnderline; lfw.lfStrikeOut = style & FontStyleStrikeout; hfont = CreateFontIndirectW(&lfw); hdc = CreateCompatibleDC(0); SelectObject(hdc, hfont); otm.otmSize = sizeof(otm); ret = GetOutlineTextMetricsW(hdc, otm.otmSize, &otm); DeleteDC(hdc); DeleteObject(hfont); if (!ret) return NotTrueTypeFont; *font = GdipAlloc(sizeof(GpFont)); if (!*font) return OutOfMemory; (*font)->unit = unit; (*font)->emSize = emSize; (*font)->otm = otm; stat = clone_font_family(fontFamily, &(*font)->family); if (stat != Ok) { GdipFree(*font); return stat; } TRACE("<-- %p\n", *font); return Ok; }
static void test_getgenerics (void) { GpStatus stat; GpFontFamily** family; WCHAR familyName[LF_FACESIZE]; ZeroMemory(familyName, sizeof(familyName)/sizeof(WCHAR)); family = GdipAlloc (sizeof (GpFontFamily*)); stat = GdipGetGenericFontFamilySansSerif (family); expect (Ok, stat); stat = GdipGetFamilyName (*family, familyName, LANG_NEUTRAL); expect (Ok, stat); ok ((lstrcmpiW(familyName, MicrosoftSansSerif) == 0) || (lstrcmpiW(familyName,MSSansSerif) == 0), "Expected Microsoft Sans Serif or MS Sans Serif, got %s\n", debugstr_w(familyName)); stat = GdipDeleteFontFamily (*family); expect (Ok, stat); stat = GdipGetGenericFontFamilySerif (family); expect (Ok, stat); stat = GdipGetFamilyName (*family, familyName, LANG_NEUTRAL); expect (Ok, stat); ok (lstrcmpiW(familyName, TimesNewRoman) == 0, "Expected Times New Roman, got %s\n", debugstr_w(familyName)); stat = GdipDeleteFontFamily (*family); expect (Ok, stat); stat = GdipGetGenericFontFamilyMonospace (family); expect (Ok, stat); stat = GdipGetFamilyName (*family, familyName, LANG_NEUTRAL); expect (Ok, stat); ok (lstrcmpiW(familyName, CourierNew) == 0, "Expected Courier New, got %s\n", debugstr_w(familyName)); stat = GdipDeleteFontFamily (*family); expect (Ok, stat); GdipFree (family); }
static void check_family(const char* context, GpFontFamily *family, WCHAR *name) { GpStatus stat; GpFont* font; *name = 0; stat = GdipGetFamilyName(family, name, LANG_NEUTRAL); ok(stat == Ok, "could not get the %s family name: %.8x\n", context, stat); stat = GdipCreateFont(family, 12, FontStyleRegular, UnitPixel, &font); ok(stat == Ok, "could not create a font for the %s family: %.8x\n", context, stat); if (stat == Ok) { stat = GdipDeleteFont(font); ok(stat == Ok, "could not delete the %s family font: %.8x\n", context, stat); } stat = GdipDeleteFontFamily(family); ok(stat == Ok, "could not delete the %s family: %.8x\n", context, stat); }
/******************************************************************************* * GdipCreateFont [GDIPLUS.@] * * Create a new font based off of a FontFamily * * PARAMS * *fontFamily [I] Family to base the font off of * emSize [I] Size of the font * style [I] Bitwise OR of FontStyle enumeration * unit [I] Unit emSize is measured in * **font [I] the resulting Font object * * RETURNS * SUCCESS: Ok * FAILURE: InvalidParameter if fontfamily or font is NULL. * FAILURE: FontFamilyNotFound if an invalid FontFamily is given * * NOTES * UnitDisplay is unsupported. * emSize is stored separately from lfHeight, to hold the fraction. */ GpStatus WINGDIPAPI GdipCreateFont(GDIPCONST GpFontFamily *fontFamily, REAL emSize, INT style, Unit unit, GpFont **font) { WCHAR facename[LF_FACESIZE]; LOGFONTW* lfw; const NEWTEXTMETRICW* tmw; GpStatus stat; if (!fontFamily || !font) return InvalidParameter; TRACE("%p (%s), %f, %d, %d, %p\n", fontFamily, debugstr_w(fontFamily->FamilyName), emSize, style, unit, font); stat = GdipGetFamilyName (fontFamily, facename, 0); if (stat != Ok) return stat; *font = GdipAlloc(sizeof(GpFont)); tmw = &fontFamily->tmw; lfw = &((*font)->lfw); ZeroMemory(&(*lfw), sizeof(*lfw)); lfw->lfWeight = tmw->tmWeight; lfw->lfItalic = tmw->tmItalic; lfw->lfUnderline = tmw->tmUnderlined; lfw->lfStrikeOut = tmw->tmStruckOut; lfw->lfCharSet = tmw->tmCharSet; lfw->lfPitchAndFamily = tmw->tmPitchAndFamily; lstrcpynW(lfw->lfFaceName, facename, LF_FACESIZE); switch (unit) { case UnitWorld: /* FIXME: Figure out when World != Pixel */ lfw->lfHeight = emSize; break; case UnitDisplay: FIXME("Unknown behavior for UnitDisplay! Please report!\n"); /* FIXME: Figure out how this works... * MSDN says that if "DISPLAY" is a monitor, then pixel should be * used. That's not what I got. Tests on Windows revealed no output, * and the tests in tests/font crash windows */ lfw->lfHeight = 0; break; case UnitPixel: lfw->lfHeight = emSize; break; case UnitPoint: lfw->lfHeight = point_to_pixel(emSize); break; case UnitInch: lfw->lfHeight = inch_to_pixel(emSize); break; case UnitDocument: lfw->lfHeight = document_to_pixel(emSize); break; case UnitMillimeter: lfw->lfHeight = mm_to_pixel(emSize); break; } lfw->lfHeight *= -1; lfw->lfWeight = style & FontStyleBold ? 700 : 400; lfw->lfItalic = style & FontStyleItalic; lfw->lfUnderline = style & FontStyleUnderline; lfw->lfStrikeOut = style & FontStyleStrikeout; (*font)->unit = unit; (*font)->emSize = emSize; (*font)->height = tmw->ntmSizeEM; (*font)->line_spacing = tmw->tmAscent + tmw->tmDescent + tmw->tmExternalLeading; TRACE("<-- %p\n", *font); return Ok; }