dwrite: Properly implement CreateFontFaceFromHdc().
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
parent
2be56fdc95
commit
f2b830ec76
|
@ -777,31 +777,85 @@ static HRESULT WINAPI gdiinterop_ConvertFontFaceToLOGFONT(IDWriteGdiInterop *ifa
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct font_realization_info {
|
||||||
|
DWORD size;
|
||||||
|
DWORD flags;
|
||||||
|
DWORD cache_num;
|
||||||
|
DWORD instance_id;
|
||||||
|
DWORD unk;
|
||||||
|
DWORD face_index;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct font_fileinfo {
|
||||||
|
FILETIME writetime;
|
||||||
|
LARGE_INTEGER size;
|
||||||
|
WCHAR path[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Undocumented gdi32 exports, used to access actually selected font information */
|
||||||
|
extern BOOL WINAPI GetFontRealizationInfo(HDC hdc, struct font_realization_info *info);
|
||||||
|
extern BOOL WINAPI GetFontFileInfo(DWORD instance_id, DWORD unknown, struct font_fileinfo *info, DWORD size, DWORD *needed);
|
||||||
|
|
||||||
static HRESULT WINAPI gdiinterop_CreateFontFaceFromHdc(IDWriteGdiInterop *iface,
|
static HRESULT WINAPI gdiinterop_CreateFontFaceFromHdc(IDWriteGdiInterop *iface,
|
||||||
HDC hdc, IDWriteFontFace **fontface)
|
HDC hdc, IDWriteFontFace **fontface)
|
||||||
{
|
{
|
||||||
struct gdiinterop *This = impl_from_IDWriteGdiInterop(iface);
|
struct gdiinterop *This = impl_from_IDWriteGdiInterop(iface);
|
||||||
IDWriteFont *font;
|
struct font_realization_info info;
|
||||||
LOGFONTW logfont;
|
struct font_fileinfo *fileinfo;
|
||||||
HFONT hfont;
|
DWRITE_FONT_FILE_TYPE filetype;
|
||||||
|
DWRITE_FONT_FACE_TYPE facetype;
|
||||||
|
IDWriteFontFile *file;
|
||||||
|
BOOL is_supported;
|
||||||
|
UINT32 facenum;
|
||||||
|
DWORD needed;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
TRACE("(%p)->(%p %p)\n", This, hdc, fontface);
|
TRACE("(%p)->(%p %p)\n", This, hdc, fontface);
|
||||||
|
|
||||||
*fontface = NULL;
|
*fontface = NULL;
|
||||||
|
|
||||||
hfont = GetCurrentObject(hdc, OBJ_FONT);
|
if (!hdc)
|
||||||
if (!hfont)
|
|
||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
GetObjectW(hfont, sizeof(logfont), &logfont);
|
|
||||||
|
|
||||||
hr = IDWriteGdiInterop_CreateFontFromLOGFONT(iface, &logfont, &font);
|
/* get selected font id */
|
||||||
|
info.size = sizeof(info);
|
||||||
|
if (!GetFontRealizationInfo(hdc, &info)) {
|
||||||
|
WARN("failed to get selected font id\n");
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
needed = 0;
|
||||||
|
GetFontFileInfo(info.instance_id, 0, NULL, 0, &needed);
|
||||||
|
if (needed == 0) {
|
||||||
|
WARN("failed to get font file info size\n");
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
fileinfo = heap_alloc(needed);
|
||||||
|
if (!fileinfo)
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
|
if (!GetFontFileInfo(info.instance_id, 0, fileinfo, needed, &needed)) {
|
||||||
|
heap_free(fileinfo);
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = IDWriteFactory2_CreateFontFileReference(This->factory, fileinfo->path, &fileinfo->writetime,
|
||||||
|
&file);
|
||||||
|
heap_free(fileinfo);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
hr = IDWriteFont_CreateFontFace(font, fontface);
|
is_supported = FALSE;
|
||||||
IDWriteFont_Release(font);
|
hr = IDWriteFontFile_Analyze(file, &is_supported, &filetype, &facetype, &facenum);
|
||||||
|
if (FAILED(hr) || !is_supported) {
|
||||||
|
IDWriteFontFile_Release(file);
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = IDWriteFactory2_CreateFontFace(This->factory, facetype, 1, &file, info.face_index, DWRITE_FONT_SIMULATIONS_NONE,
|
||||||
|
fontface);
|
||||||
|
IDWriteFontFile_Release(file);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue