Commit c22b2192 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

dwrite: Improve ConvertFontFaceToLOGFONT using same logic IDWriteFont uses.

parent bf23b8a5
...@@ -163,7 +163,6 @@ struct fontface_desc ...@@ -163,7 +163,6 @@ struct fontface_desc
struct dwrite_font_data *font_data; /* could be NULL when face is created directly with IDWriteFactory::CreateFontFace() */ struct dwrite_font_data *font_data; /* could be NULL when face is created directly with IDWriteFactory::CreateFontFace() */
}; };
extern HRESULT convert_fontface_to_logfont(IDWriteFontFace*, LOGFONTW*) DECLSPEC_HIDDEN;
extern HRESULT create_numbersubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD,const WCHAR *locale,BOOL,IDWriteNumberSubstitution**) DECLSPEC_HIDDEN; extern HRESULT create_numbersubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD,const WCHAR *locale,BOOL,IDWriteNumberSubstitution**) DECLSPEC_HIDDEN;
extern HRESULT create_textformat(const WCHAR*,IDWriteFontCollection*,DWRITE_FONT_WEIGHT,DWRITE_FONT_STYLE,DWRITE_FONT_STRETCH, extern HRESULT create_textformat(const WCHAR*,IDWriteFontCollection*,DWRITE_FONT_WEIGHT,DWRITE_FONT_STYLE,DWRITE_FONT_STRETCH,
FLOAT,const WCHAR*,IDWriteTextFormat**) DECLSPEC_HIDDEN; FLOAT,const WCHAR*,IDWriteTextFormat**) DECLSPEC_HIDDEN;
...@@ -201,6 +200,7 @@ extern HRESULT factory_get_cached_fontface(IDWriteFactory4*,IDWriteFontFile*cons ...@@ -201,6 +200,7 @@ extern HRESULT factory_get_cached_fontface(IDWriteFactory4*,IDWriteFontFile*cons
struct list**) DECLSPEC_HIDDEN; struct list**) DECLSPEC_HIDDEN;
extern void factory_cache_fontface(struct list*,IDWriteFontFace4*) DECLSPEC_HIDDEN; extern void factory_cache_fontface(struct list*,IDWriteFontFace4*) DECLSPEC_HIDDEN;
extern void get_logfont_from_font(IDWriteFont*,LOGFONTW*) DECLSPEC_HIDDEN; extern void get_logfont_from_font(IDWriteFont*,LOGFONTW*) DECLSPEC_HIDDEN;
extern void get_logfont_from_fontface(IDWriteFontFace*,LOGFONTW*) DECLSPEC_HIDDEN;
/* Opentype font table functions */ /* Opentype font table functions */
struct dwrite_font_props { struct dwrite_font_props {
......
...@@ -243,6 +243,8 @@ struct dwrite_fontface { ...@@ -243,6 +243,8 @@ struct dwrite_fontface {
DWRITE_FONT_STRETCH stretch; DWRITE_FONT_STRETCH stretch;
DWRITE_FONT_WEIGHT weight; DWRITE_FONT_WEIGHT weight;
DWRITE_PANOSE panose; DWRITE_PANOSE panose;
LOGFONTW lf;
}; };
struct dwrite_fontfile { struct dwrite_fontfile {
...@@ -1685,12 +1687,26 @@ static struct dwrite_font *unsafe_impl_from_IDWriteFont(IDWriteFont *iface) ...@@ -1685,12 +1687,26 @@ static struct dwrite_font *unsafe_impl_from_IDWriteFont(IDWriteFont *iface)
return CONTAINING_RECORD(iface, struct dwrite_font, IDWriteFont3_iface); return CONTAINING_RECORD(iface, struct dwrite_font, IDWriteFont3_iface);
} }
static struct dwrite_fontface *unsafe_impl_from_IDWriteFontFace(IDWriteFontFace *iface)
{
if (!iface)
return NULL;
assert(iface->lpVtbl = (IDWriteFontFaceVtbl*)&dwritefontfacevtbl);
return CONTAINING_RECORD(iface, struct dwrite_fontface, IDWriteFontFace4_iface);
}
void get_logfont_from_font(IDWriteFont *iface, LOGFONTW *lf) void get_logfont_from_font(IDWriteFont *iface, LOGFONTW *lf)
{ {
struct dwrite_font *font = unsafe_impl_from_IDWriteFont(iface); struct dwrite_font *font = unsafe_impl_from_IDWriteFont(iface);
*lf = font->data->lf; *lf = font->data->lf;
} }
void get_logfont_from_fontface(IDWriteFontFace *iface, LOGFONTW *lf)
{
struct dwrite_fontface *fontface = unsafe_impl_from_IDWriteFontFace(iface);
*lf = fontface->lf;
}
static HRESULT create_font(struct dwrite_font_data *data, IDWriteFontFamily1 *family, IDWriteFont3 **font) static HRESULT create_font(struct dwrite_font_data *data, IDWriteFontFamily1 *family, IDWriteFont3 **font)
{ {
struct dwrite_font *This; struct dwrite_font *This;
...@@ -4284,6 +4300,7 @@ HRESULT create_fontface(const struct fontface_desc *desc, IDWriteFontFace4 **ret ...@@ -4284,6 +4300,7 @@ HRESULT create_fontface(const struct fontface_desc *desc, IDWriteFontFace4 **ret
fontface->style = desc->font_data->style; fontface->style = desc->font_data->style;
fontface->stretch = desc->font_data->stretch; fontface->stretch = desc->font_data->stretch;
fontface->panose = desc->font_data->panose; fontface->panose = desc->font_data->panose;
fontface->lf = desc->font_data->lf;
} }
else { else {
IDWriteLocalizedStrings *names; IDWriteLocalizedStrings *names;
...@@ -4299,6 +4316,7 @@ HRESULT create_fontface(const struct fontface_desc *desc, IDWriteFontFace4 **ret ...@@ -4299,6 +4316,7 @@ HRESULT create_fontface(const struct fontface_desc *desc, IDWriteFontFace4 **ret
fontface->style = data->style; fontface->style = data->style;
fontface->stretch = data->stretch; fontface->stretch = data->stretch;
fontface->panose = data->panose; fontface->panose = data->panose;
fontface->lf = data->lf;
IDWriteLocalizedStrings_Release(names); IDWriteLocalizedStrings_Release(names);
release_font_data(data); release_font_data(data);
......
...@@ -658,67 +658,20 @@ static HRESULT WINAPI gdiinterop_ConvertFontToLOGFONT(IDWriteGdiInterop1 *iface, ...@@ -658,67 +658,20 @@ static HRESULT WINAPI gdiinterop_ConvertFontToLOGFONT(IDWriteGdiInterop1 *iface,
static HRESULT WINAPI gdiinterop_ConvertFontFaceToLOGFONT(IDWriteGdiInterop1 *iface, static HRESULT WINAPI gdiinterop_ConvertFontFaceToLOGFONT(IDWriteGdiInterop1 *iface,
IDWriteFontFace *fontface, LOGFONTW *logfont) IDWriteFontFace *fontface, LOGFONTW *logfont)
{ {
static const WCHAR enusW[] = {'e','n','-','u','s',0};
struct gdiinterop *This = impl_from_IDWriteGdiInterop1(iface); struct gdiinterop *This = impl_from_IDWriteGdiInterop1(iface);
IDWriteLocalizedStrings *familynames;
DWRITE_FONT_SIMULATIONS simulations;
struct file_stream_desc stream_desc;
struct dwrite_font_props props;
IDWriteFontFileStream *stream;
IDWriteFontFile *file = NULL;
UINT32 index;
BOOL exists;
HRESULT hr;
TRACE("(%p)->(%p %p)\n", This, fontface, logfont); TRACE("(%p)->(%p %p)\n", This, fontface, logfont);
memset(logfont, 0, sizeof(*logfont)); memset(logfont, 0, sizeof(*logfont));
index = 1; if (!fontface)
hr = IDWriteFontFace_GetFiles(fontface, &index, &file); return E_INVALIDARG;
if (FAILED(hr) || !file)
return hr;
hr = get_filestream_from_file(file, &stream);
if (FAILED(hr)) {
IDWriteFontFile_Release(file);
return hr;
}
stream_desc.stream = stream;
stream_desc.face_type = IDWriteFontFace_GetType(fontface);
stream_desc.face_index = IDWriteFontFace_GetIndex(fontface);
opentype_get_font_properties(&stream_desc, &props);
hr = opentype_get_font_familyname(&stream_desc, &familynames);
IDWriteFontFile_Release(file);
IDWriteFontFileStream_Release(stream);
if (FAILED(hr))
return hr;
simulations = IDWriteFontFace_GetSimulations(fontface);
get_logfont_from_fontface(fontface, logfont);
logfont->lfCharSet = DEFAULT_CHARSET; logfont->lfCharSet = DEFAULT_CHARSET;
logfont->lfWeight = props.weight;
logfont->lfItalic = props.style == DWRITE_FONT_STYLE_ITALIC || (simulations & DWRITE_FONT_SIMULATIONS_OBLIQUE);
logfont->lfOutPrecision = OUT_OUTLINE_PRECIS; logfont->lfOutPrecision = OUT_OUTLINE_PRECIS;
logfont->lfFaceName[0] = 0;
exists = FALSE;
hr = IDWriteLocalizedStrings_FindLocaleName(familynames, enusW, &index, &exists);
if (FAILED(hr) || !exists) {
/* fallback to 0 index */
if (IDWriteLocalizedStrings_GetCount(familynames) > 0)
index = 0;
else {
IDWriteLocalizedStrings_Release(familynames);
return E_FAIL;
}
}
hr = IDWriteLocalizedStrings_GetString(familynames, index, logfont->lfFaceName, sizeof(logfont->lfFaceName)/sizeof(WCHAR)); return S_OK;
IDWriteLocalizedStrings_Release(familynames);
return hr;
} }
struct font_realization_info { struct font_realization_info {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment