dwrite: Improve lfWeight values returned by ConvertFontToLOGFONT().

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
oldstable
Nikolay Sivov 2016-12-04 19:22:14 +03:00 committed by Alexandre Julliard
parent a7fd13c244
commit da11bee6c7
4 changed files with 62 additions and 33 deletions

View File

@ -3401,6 +3401,7 @@ static void fontfamily_add_bold_simulated_face(struct dwrite_fontfamily_data *fa
if (init_font_data_from_font(family->fonts[heaviest], DWRITE_FONT_SIMULATIONS_BOLD, facenameW, &boldface) == S_OK) {
boldface->bold_sim_tested = 1;
boldface->lf.lfWeight += (FW_BOLD - FW_REGULAR) / 2 + 1;
fontfamily_add_font(family, boldface);
}
}

View File

@ -654,7 +654,6 @@ static HRESULT WINAPI gdiinterop_ConvertFontToLOGFONT(IDWriteGdiInterop1 *iface,
get_logfont_from_font(font, logfont);
logfont->lfCharSet = DEFAULT_CHARSET;
logfont->lfWeight = IDWriteFont_GetWeight(font);
logfont->lfOutPrecision = OUT_OUTLINE_PRECIS;
logfont->lfFaceName[0] = 0;

View File

@ -1307,10 +1307,9 @@ void opentype_get_font_properties(struct file_stream_desc *stream_desc, struct d
if (version >= 4 && (fsSelection & OS2_FSSELECTION_OBLIQUE))
props->style = DWRITE_FONT_STYLE_OBLIQUE;
else if (fsSelection & OS2_FSSELECTION_ITALIC) {
else if (fsSelection & OS2_FSSELECTION_ITALIC)
props->style = DWRITE_FONT_STYLE_ITALIC;
props->lf.lfItalic = 1;
}
memcpy(&props->panose, &tt_os2->panose, sizeof(props->panose));
}
else if (tt_head) {
@ -1324,12 +1323,13 @@ void opentype_get_font_properties(struct file_stream_desc *stream_desc, struct d
if (macStyle & TT_HEAD_MACSTYLE_BOLD)
props->weight = DWRITE_FONT_WEIGHT_BOLD;
if (macStyle & TT_HEAD_MACSTYLE_ITALIC) {
if (macStyle & TT_HEAD_MACSTYLE_ITALIC)
props->style = DWRITE_FONT_STYLE_ITALIC;
props->lf.lfItalic = 1;
}
}
props->lf.lfWeight = props->weight;
props->lf.lfItalic = props->style == DWRITE_FONT_STYLE_ITALIC;
TRACE("stretch=%d, weight=%d, style %d\n", props->stretch, props->weight, props->style);
if (tt_os2)

View File

@ -3458,7 +3458,16 @@ static void test_TryGetFontTable(void)
static void get_logfont_from_font(IDWriteFont *font, LOGFONTW *logfont)
{
void *os2_context, *head_context;
DWRITE_FONT_SIMULATIONS sim;
IDWriteFontFace *fontface;
const TT_OS2_V2 *tt_os2;
DWRITE_FONT_STYLE style;
const TT_HEAD *tt_head;
LONG weight;
UINT32 size;
BOOL exists;
HRESULT hr;
/* These are rendering time properties. */
logfont->lfHeight = 0;
@ -3468,32 +3477,50 @@ static void get_logfont_from_font(IDWriteFont *font, LOGFONTW *logfont)
logfont->lfUnderline = 0;
logfont->lfStrikeOut = 0;
logfont->lfWeight = 0;
logfont->lfItalic = 0;
hr = IDWriteFont_CreateFontFace(font, &fontface);
ok(hr == S_OK, "Failed to create font face, %#x\n", hr);
hr = IDWriteFontFace_TryGetFontTable(fontface, MS_0S2_TAG, (const void **)&tt_os2, &size,
&os2_context, &exists);
ok(hr == S_OK, "Failed to get OS/2 table, %#x\n", hr);
hr = IDWriteFontFace_TryGetFontTable(fontface, MS_HEAD_TAG, (const void **)&tt_head, &size,
&head_context, &exists);
ok(hr == S_OK, "Failed to get head table, %#x\n", hr);
sim = IDWriteFont_GetSimulations(font);
/* lfWeight */
weight = FW_REGULAR;
if (tt_os2) {
USHORT usWeightClass = GET_BE_WORD(tt_os2->usWeightClass);
if (usWeightClass >= 1 && usWeightClass <= 9)
usWeightClass *= 100;
if (usWeightClass > DWRITE_FONT_WEIGHT_ULTRA_BLACK)
weight = DWRITE_FONT_WEIGHT_ULTRA_BLACK;
else if (usWeightClass > 0)
weight = usWeightClass;
}
else if (tt_head) {
USHORT macStyle = GET_BE_WORD(tt_head->macStyle);
if (macStyle & TT_HEAD_MACSTYLE_BOLD)
weight = DWRITE_FONT_WEIGHT_BOLD;
}
if (sim & DWRITE_FONT_SIMULATIONS_BOLD)
weight += (FW_BOLD - FW_REGULAR) / 2 + 1;
logfont->lfWeight = weight;
/* lfItalic */
if (IDWriteFont_GetSimulations(font) & DWRITE_FONT_SIMULATIONS_OBLIQUE)
logfont->lfItalic = 1;
style = IDWriteFont_GetStyle(font);
if (!logfont->lfItalic && ((style == DWRITE_FONT_STYLE_ITALIC) || (style == DWRITE_FONT_STYLE_OBLIQUE))) {
void *os2_context, *head_context;
IDWriteFontFace *fontface;
const TT_OS2_V2 *tt_os2;
const TT_HEAD *tt_head;
UINT32 size;
BOOL exists;
HRESULT hr;
hr = IDWriteFont_CreateFontFace(font, &fontface);
ok(hr == S_OK, "Failed to create font face, %#x\n", hr);
hr = IDWriteFontFace_TryGetFontTable(fontface, MS_0S2_TAG, (const void **)&tt_os2, &size,
&os2_context, &exists);
ok(hr == S_OK, "Failed to get OS/2 table, %#x\n", hr);
hr = IDWriteFontFace_TryGetFontTable(fontface, MS_HEAD_TAG, (const void **)&tt_head, &size,
&head_context, &exists);
ok(hr == S_OK, "Failed to get head table, %#x\n", hr);
if (tt_os2) {
USHORT fsSelection = GET_BE_WORD(tt_os2->fsSelection);
logfont->lfItalic = !!(fsSelection & OS2_FSSELECTION_ITALIC);
@ -3502,13 +3529,13 @@ static void get_logfont_from_font(IDWriteFont *font, LOGFONTW *logfont)
USHORT macStyle = GET_BE_WORD(tt_head->macStyle);
logfont->lfItalic = !!(macStyle & TT_HEAD_MACSTYLE_ITALIC);
}
if (tt_os2)
IDWriteFontFace_ReleaseFontTable(fontface, os2_context);
if (tt_head)
IDWriteFontFace_ReleaseFontTable(fontface, head_context);
IDWriteFontFace_Release(fontface);
}
if (tt_os2)
IDWriteFontFace_ReleaseFontTable(fontface, os2_context);
if (tt_head)
IDWriteFontFace_ReleaseFontTable(fontface, head_context);
IDWriteFontFace_Release(fontface);
}
static void test_ConvertFontToLOGFONT(void)
@ -3599,10 +3626,12 @@ if (0) { /* crashes on native */
sim = IDWriteFont_GetSimulations(font);
get_logfont_from_font(font, &lf);
ok(logfont.lfWeight == lf.lfWeight, "%s: unexpected lfWeight %d, expected lfWeight %d, font weight %d, "
"bold simulation %s\n", wine_dbgstr_w(nameW), logfont.lfWeight, lf.lfWeight, IDWriteFont_GetWeight(font),
sim & DWRITE_FONT_SIMULATIONS_BOLD ? "yes" : "no");
ok(logfont.lfItalic == lf.lfItalic, "%s: unexpected italic flag %d, oblique simulation %s\n",
wine_dbgstr_w(nameW), logfont.lfItalic, sim & DWRITE_FONT_SIMULATIONS_OBLIQUE ? "yes" : "no");
ok(logfont.lfWeight > 0, "got %d\n", logfont.lfWeight);
ok(logfont.lfOutPrecision == OUT_OUTLINE_PRECIS, "got %d\n", logfont.lfOutPrecision);
ok(logfont.lfClipPrecision == 0, "got %d\n", logfont.lfClipPrecision);
ok(logfont.lfQuality == 0, "got %d\n", logfont.lfQuality);