/******************************************************************************* * GdipCreateFontFromLogfontA [GDIPLUS.@] */ GpStatus WINGDIPAPI GdipCreateFontFromLogfontA(HDC hdc, GDIPCONST LOGFONTA *lfa, GpFont **font) { LOGFONTW lfw; TRACE("(%p, %p, %p)\n", hdc, lfa, font); if(!lfa || !font) return InvalidParameter; memcpy(&lfw, lfa, FIELD_OFFSET(LOGFONTA,lfFaceName) ); if(!MultiByteToWideChar(CP_ACP, 0, lfa->lfFaceName, -1, lfw.lfFaceName, LF_FACESIZE)) return GenericError; return GdipCreateFontFromLogfontW(hdc, &lfw, font); }
/******************************************************************************* * GdipCreateFontFromDC [GDIPLUS.@] */ GpStatus WINGDIPAPI GdipCreateFontFromDC(HDC hdc, GpFont **font) { HFONT hfont; LOGFONTW lfw; TRACE("(%p, %p)\n", hdc, font); if(!font) return InvalidParameter; hfont = GetCurrentObject(hdc, OBJ_FONT); if(!hfont) return GenericError; if(!GetObjectW(hfont, sizeof(LOGFONTW), &lfw)) return GenericError; return GdipCreateFontFromLogfontW(hdc, &lfw, font); }
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_logfont(void) { LOGFONTW lfw, lfw2; GpFont *font; GpStatus stat; GpGraphics *graphics; HDC hdc = GetDC(0); INT style; GdipCreateFromHDC(hdc, &graphics); memset(&lfw, 0, sizeof(LOGFONTW)); memset(&lfw2, 0xff, sizeof(LOGFONTW)); /* empty FaceName */ lfw.lfFaceName[0] = 0; stat = GdipCreateFontFromLogfontW(hdc, &lfw, &font); expect(NotTrueTypeFont, stat); memcpy(&lfw.lfFaceName, arial, 6 * sizeof(WCHAR)); stat = GdipCreateFontFromLogfontW(hdc, &lfw, &font); if (stat == FileNotFound) { skip("Arial not installed.\n"); return; } expect(Ok, stat); stat = GdipGetLogFontW(font, graphics, &lfw2); expect(Ok, stat); ok(lfw2.lfHeight < 0, "Expected negative height\n"); expect(0, lfw2.lfWidth); expect(0, lfw2.lfEscapement); expect(0, lfw2.lfOrientation); ok((lfw2.lfWeight >= 100) && (lfw2.lfWeight <= 900), "Expected weight to be set\n"); expect(0, lfw2.lfItalic); expect(0, lfw2.lfUnderline); expect(0, lfw2.lfStrikeOut); expect(GetTextCharset(hdc), lfw2.lfCharSet); expect(0, lfw2.lfOutPrecision); expect(0, lfw2.lfClipPrecision); expect(0, lfw2.lfQuality); expect(0, lfw2.lfPitchAndFamily); GdipDeleteFont(font); memset(&lfw, 0, sizeof(LOGFONTW)); lfw.lfHeight = 25; lfw.lfWidth = 25; lfw.lfEscapement = lfw.lfOrientation = 50; lfw.lfItalic = lfw.lfUnderline = lfw.lfStrikeOut = TRUE; memset(&lfw2, 0xff, sizeof(LOGFONTW)); memcpy(&lfw.lfFaceName, arial, 6 * sizeof(WCHAR)); stat = GdipCreateFontFromLogfontW(hdc, &lfw, &font); expect(Ok, stat); stat = GdipGetLogFontW(font, graphics, &lfw2); expect(Ok, stat); ok(lfw2.lfHeight < 0, "Expected negative height\n"); expect(0, lfw2.lfWidth); expect(0, lfw2.lfEscapement); expect(0, lfw2.lfOrientation); ok((lfw2.lfWeight >= 100) && (lfw2.lfWeight <= 900), "Expected weight to be set\n"); expect(TRUE, lfw2.lfItalic); expect(TRUE, lfw2.lfUnderline); expect(TRUE, lfw2.lfStrikeOut); expect(GetTextCharset(hdc), lfw2.lfCharSet); expect(0, lfw2.lfOutPrecision); expect(0, lfw2.lfClipPrecision); expect(0, lfw2.lfQuality); expect(0, lfw2.lfPitchAndFamily); stat = GdipGetFontStyle(font, &style); expect(Ok, stat); ok (style == (FontStyleItalic | FontStyleUnderline | FontStyleStrikeout), "Expected , got %d\n", style); GdipDeleteFont(font); GdipDeleteGraphics(graphics); ReleaseDC(0, hdc); }
static void test_logfont(void) { LOGFONTW lfw, lfw2; GpFont *font; GpStatus stat; GpGraphics *graphics; HDC hdc = GetDC(0); GdipCreateFromHDC(hdc, &graphics); memset(&lfw, 0, sizeof(LOGFONTW)); memset(&lfw2, 0xff, sizeof(LOGFONTW)); memcpy(&lfw.lfFaceName, arial, 6 * sizeof(WCHAR)); stat = GdipCreateFontFromLogfontW(hdc, &lfw, &font); expect(Ok, stat); stat = GdipGetLogFontW(font, graphics, &lfw2); expect(Ok, stat); ok(lfw2.lfHeight < 0, "Expected negative height\n"); expect(0, lfw2.lfWidth); expect(0, lfw2.lfEscapement); expect(0, lfw2.lfOrientation); ok((lfw2.lfWeight >= 100) && (lfw2.lfWeight <= 900), "Expected weight to be set\n"); expect(0, lfw2.lfItalic); expect(0, lfw2.lfUnderline); expect(0, lfw2.lfStrikeOut); expect(0, lfw2.lfCharSet); expect(0, lfw2.lfOutPrecision); expect(0, lfw2.lfClipPrecision); expect(0, lfw2.lfQuality); expect(0, lfw2.lfPitchAndFamily); GdipDeleteFont(font); memset(&lfw, 0, sizeof(LOGFONTW)); lfw.lfHeight = 25; lfw.lfWidth = 25; lfw.lfEscapement = lfw.lfOrientation = 50; lfw.lfItalic = lfw.lfUnderline = lfw.lfStrikeOut = TRUE; memset(&lfw2, 0xff, sizeof(LOGFONTW)); memcpy(&lfw.lfFaceName, arial, 6 * sizeof(WCHAR)); stat = GdipCreateFontFromLogfontW(hdc, &lfw, &font); expect(Ok, stat); stat = GdipGetLogFontW(font, graphics, &lfw2); expect(Ok, stat); ok(lfw2.lfHeight < 0, "Expected negative height\n"); expect(0, lfw2.lfWidth); expect(0, lfw2.lfEscapement); expect(0, lfw2.lfOrientation); ok((lfw2.lfWeight >= 100) && (lfw2.lfWeight <= 900), "Expected weight to be set\n"); expect(TRUE, lfw2.lfItalic); expect(TRUE, lfw2.lfUnderline); expect(TRUE, lfw2.lfStrikeOut); expect(0, lfw2.lfCharSet); expect(0, lfw2.lfOutPrecision); expect(0, lfw2.lfClipPrecision); expect(0, lfw2.lfQuality); expect(0, lfw2.lfPitchAndFamily); GdipDeleteFont(font); GdipDeleteGraphics(graphics); ReleaseDC(0, hdc); }