static HRESULT WINAPI gdiinterop_CreateFontFaceFromHdc(IDWriteGdiInterop *iface, HDC hdc, IDWriteFontFace **fontface) { struct gdiinterop *This = impl_from_IDWriteGdiInterop(iface); IDWriteFont *font; LOGFONTW logfont; HFONT hfont; HRESULT hr; TRACE("(%p)->(%p %p)\n", This, hdc, fontface); *fontface = NULL; hfont = GetCurrentObject(hdc, OBJ_FONT); if (!hfont) return E_INVALIDARG; GetObjectW(hfont, sizeof(logfont), &logfont); hr = IDWriteGdiInterop_CreateFontFromLOGFONT(iface, &logfont, &font); if (FAILED(hr)) return hr; hr = IDWriteFont_CreateFontFace(font, fontface); IDWriteFont_Release(font); return hr; }
static void test_CreateFontFace(void) { IDWriteFontFace *fontface, *fontface2; IDWriteGdiInterop *interop; IDWriteFont *font; LOGFONTW logfont; HRESULT hr; hr = IDWriteFactory_GetGdiInterop(factory, &interop); EXPECT_HR(hr, S_OK); memset(&logfont, 0, sizeof(logfont)); logfont.lfHeight = 12; logfont.lfWidth = 12; logfont.lfWeight = FW_NORMAL; logfont.lfItalic = 1; lstrcpyW(logfont.lfFaceName, tahomaW); hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IDWriteFont_QueryInterface(font, &IID_IDWriteFontFace, (void**)&fontface); ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr); if (0) /* crashes on native */ hr = IDWriteFont_CreateFontFace(font, NULL); hr = IDWriteFont_CreateFontFace(font, &fontface); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IDWriteFont_CreateFontFace(font, &fontface2); ok(hr == S_OK, "got 0x%08x\n", hr); ok(fontface == fontface2, "got %p, was %p\n", fontface2, fontface); /* the fontface refcount is increased here */ IDWriteFontFace_Release(fontface); IDWriteFontFace_Release(fontface); IDWriteFont_Release(font); IDWriteGdiInterop_Release(interop); }
static void test_ConvertFontFaceToLOGFONT(void) { IDWriteGdiInterop *interop; IDWriteFontFace *fontface; IDWriteFont *font; LOGFONTW logfont; HRESULT hr; hr = IDWriteFactory_GetGdiInterop(factory, &interop); ok(hr == S_OK, "got 0x%08x\n", hr); memset(&logfont, 0, sizeof(logfont)); logfont.lfHeight = 12; logfont.lfWidth = 12; logfont.lfEscapement = 100; logfont.lfWeight = FW_NORMAL; logfont.lfItalic = 1; logfont.lfUnderline = 1; logfont.lfStrikeOut = 1; lstrcpyW(logfont.lfFaceName, tahomaW); hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IDWriteFont_CreateFontFace(font, &fontface); ok(hr == S_OK, "got 0x%08x\n", hr); IDWriteFont_Release(font); if (0) /* crashes on native */ { hr = IDWriteGdiInterop_ConvertFontFaceToLOGFONT(interop, NULL, NULL); hr = IDWriteGdiInterop_ConvertFontFaceToLOGFONT(interop, fontface, NULL); } memset(&logfont, 0xa, sizeof(logfont)); logfont.lfFaceName[0] = 0; hr = IDWriteGdiInterop_ConvertFontFaceToLOGFONT(interop, fontface, &logfont); ok(hr == S_OK, "got 0x%08x\n", hr); ok(logfont.lfHeight == 0, "got %d\n", logfont.lfHeight); ok(logfont.lfWidth == 0, "got %d\n", logfont.lfWidth); ok(logfont.lfWeight == FW_NORMAL, "got %d\n", logfont.lfWeight); ok(logfont.lfEscapement == 0, "got %d\n", logfont.lfEscapement); ok(logfont.lfItalic == 1, "got %d\n", logfont.lfItalic); ok(logfont.lfUnderline == 0, "got %d\n", logfont.lfUnderline); ok(logfont.lfStrikeOut == 0, "got %d\n", logfont.lfStrikeOut); ok(!lstrcmpW(logfont.lfFaceName, tahomaW), "got %s\n", wine_dbgstr_w(logfont.lfFaceName)); IDWriteGdiInterop_Release(interop); IDWriteFontFace_Release(fontface); }