gdiplus: Use a better framework for filling out FontFamilies.
This commit is contained in:
parent
25e4fd7d3c
commit
c027f427ef
|
@ -95,7 +95,7 @@ GpStatus WINGDIPAPI GdipCreateFont(GDIPCONST GpFontFamily *fontFamily,
|
||||||
{
|
{
|
||||||
WCHAR facename[LF_FACESIZE];
|
WCHAR facename[LF_FACESIZE];
|
||||||
LOGFONTW* lfw;
|
LOGFONTW* lfw;
|
||||||
const TEXTMETRICW* tmw;
|
const NEWTEXTMETRICW* tmw;
|
||||||
GpStatus stat;
|
GpStatus stat;
|
||||||
|
|
||||||
if (!fontFamily || !fontFamily->FamilyName || !font)
|
if (!fontFamily || !fontFamily->FamilyName || !font)
|
||||||
|
@ -333,19 +333,31 @@ GpStatus WINGDIPAPI GdipGetFontHeightGivenDPI(GDIPCONST GpFont *font, REAL dpi,
|
||||||
return NotImplemented;
|
return NotImplemented;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Borrowed from GDI32 */
|
/***********************************************************************
|
||||||
|
* Borrowed from GDI32:
|
||||||
|
*
|
||||||
|
* Elf is really an ENUMLOGFONTEXW, and ntm is a NEWTEXTMETRICEXW.
|
||||||
|
* We have to use other types because of the FONTENUMPROCW definition.
|
||||||
|
*/
|
||||||
static INT CALLBACK is_font_installed_proc(const LOGFONTW *elf,
|
static INT CALLBACK is_font_installed_proc(const LOGFONTW *elf,
|
||||||
const TEXTMETRICW *ntm, DWORD type, LPARAM lParam)
|
const TEXTMETRICW *ntm, DWORD type, LPARAM lParam)
|
||||||
{
|
{
|
||||||
|
if (!ntm)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*(NEWTEXTMETRICW*)lParam = *(const NEWTEXTMETRICW*)ntm;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL is_font_installed(const WCHAR *name)
|
static BOOL find_installed_font(const WCHAR *name, NEWTEXTMETRICW *ntm)
|
||||||
{
|
{
|
||||||
HDC hdc = GetDC(0);
|
HDC hdc = GetDC(0);
|
||||||
BOOL ret = FALSE;
|
BOOL ret = FALSE;
|
||||||
|
|
||||||
if(!EnumFontFamiliesW(hdc, name, is_font_installed_proc, 0))
|
if(!EnumFontFamiliesW(hdc, name, is_font_installed_proc, (LPARAM)ntm))
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
|
|
||||||
ReleaseDC(0, hdc);
|
ReleaseDC(0, hdc);
|
||||||
|
@ -377,9 +389,7 @@ GpStatus WINGDIPAPI GdipCreateFontFamilyFromName(GDIPCONST WCHAR *name,
|
||||||
GpFontFamily **FontFamily)
|
GpFontFamily **FontFamily)
|
||||||
{
|
{
|
||||||
GpFontFamily* ffamily;
|
GpFontFamily* ffamily;
|
||||||
HDC hdc;
|
NEWTEXTMETRICW ntm;
|
||||||
HFONT hFont, hfont_old;
|
|
||||||
LOGFONTW lfw;
|
|
||||||
|
|
||||||
TRACE("%s, %p %p\n", debugstr_w(name), fontCollection, FontFamily);
|
TRACE("%s, %p %p\n", debugstr_w(name), fontCollection, FontFamily);
|
||||||
|
|
||||||
|
@ -387,35 +397,25 @@ GpStatus WINGDIPAPI GdipCreateFontFamilyFromName(GDIPCONST WCHAR *name,
|
||||||
return InvalidParameter;
|
return InvalidParameter;
|
||||||
if (fontCollection)
|
if (fontCollection)
|
||||||
FIXME("No support for FontCollections yet!\n");
|
FIXME("No support for FontCollections yet!\n");
|
||||||
if (!is_font_installed(name))
|
|
||||||
|
if (!find_installed_font(name, &ntm))
|
||||||
return FontFamilyNotFound;
|
return FontFamilyNotFound;
|
||||||
|
|
||||||
ffamily = GdipAlloc(sizeof (GpFontFamily));
|
ffamily = GdipAlloc(sizeof (GpFontFamily));
|
||||||
if (!ffamily) return OutOfMemory;
|
if (!ffamily) return OutOfMemory;
|
||||||
|
|
||||||
hdc = GetDC(0);
|
ffamily->tmw = ntm;
|
||||||
lstrcpynW(lfw.lfFaceName, name, sizeof(WCHAR) * LF_FACESIZE);
|
|
||||||
lfw.lfCharSet = DEFAULT_CHARSET;
|
|
||||||
lfw.lfEscapement = lfw.lfOrientation = 0;
|
|
||||||
|
|
||||||
hFont = CreateFontIndirectW (&lfw);
|
|
||||||
hfont_old = SelectObject(hdc, hFont);
|
|
||||||
|
|
||||||
GetTextMetricsW(hdc, &ffamily->tmw);
|
|
||||||
DeleteObject(SelectObject(hdc, hfont_old));
|
|
||||||
|
|
||||||
ffamily->FamilyName = GdipAlloc(LF_FACESIZE * sizeof (WCHAR));
|
ffamily->FamilyName = GdipAlloc(LF_FACESIZE * sizeof (WCHAR));
|
||||||
if (!ffamily->FamilyName)
|
if (!ffamily->FamilyName)
|
||||||
{
|
{
|
||||||
GdipFree(ffamily);
|
GdipFree(ffamily);
|
||||||
ReleaseDC(0, hdc);
|
|
||||||
return OutOfMemory;
|
return OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
lstrcpynW(ffamily->FamilyName, name, sizeof(WCHAR) * LF_FACESIZE);
|
lstrcpynW(ffamily->FamilyName, name, sizeof(WCHAR) * LF_FACESIZE);
|
||||||
|
|
||||||
*FontFamily = ffamily;
|
*FontFamily = ffamily;
|
||||||
ReleaseDC(0, hdc);
|
|
||||||
|
|
||||||
return Ok;
|
return Ok;
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,7 +192,7 @@ struct GpFontCollection{
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GpFontFamily{
|
struct GpFontFamily{
|
||||||
TEXTMETRICW tmw;
|
NEWTEXTMETRICW tmw;
|
||||||
WCHAR* FamilyName;
|
WCHAR* FamilyName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue