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

dwrite: Improve lfWeight values returned by ConvertFontToLOGFONT().

parent a7fd13c2
...@@ -3401,6 +3401,7 @@ static void fontfamily_add_bold_simulated_face(struct dwrite_fontfamily_data *fa ...@@ -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) { if (init_font_data_from_font(family->fonts[heaviest], DWRITE_FONT_SIMULATIONS_BOLD, facenameW, &boldface) == S_OK) {
boldface->bold_sim_tested = 1; boldface->bold_sim_tested = 1;
boldface->lf.lfWeight += (FW_BOLD - FW_REGULAR) / 2 + 1;
fontfamily_add_font(family, boldface); fontfamily_add_font(family, boldface);
} }
} }
......
...@@ -654,7 +654,6 @@ static HRESULT WINAPI gdiinterop_ConvertFontToLOGFONT(IDWriteGdiInterop1 *iface, ...@@ -654,7 +654,6 @@ static HRESULT WINAPI gdiinterop_ConvertFontToLOGFONT(IDWriteGdiInterop1 *iface,
get_logfont_from_font(font, logfont); get_logfont_from_font(font, logfont);
logfont->lfCharSet = DEFAULT_CHARSET; logfont->lfCharSet = DEFAULT_CHARSET;
logfont->lfWeight = IDWriteFont_GetWeight(font);
logfont->lfOutPrecision = OUT_OUTLINE_PRECIS; logfont->lfOutPrecision = OUT_OUTLINE_PRECIS;
logfont->lfFaceName[0] = 0; logfont->lfFaceName[0] = 0;
......
...@@ -1307,10 +1307,9 @@ void opentype_get_font_properties(struct file_stream_desc *stream_desc, struct d ...@@ -1307,10 +1307,9 @@ void opentype_get_font_properties(struct file_stream_desc *stream_desc, struct d
if (version >= 4 && (fsSelection & OS2_FSSELECTION_OBLIQUE)) if (version >= 4 && (fsSelection & OS2_FSSELECTION_OBLIQUE))
props->style = DWRITE_FONT_STYLE_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->style = DWRITE_FONT_STYLE_ITALIC;
props->lf.lfItalic = 1;
}
memcpy(&props->panose, &tt_os2->panose, sizeof(props->panose)); memcpy(&props->panose, &tt_os2->panose, sizeof(props->panose));
} }
else if (tt_head) { else if (tt_head) {
...@@ -1324,12 +1323,13 @@ void opentype_get_font_properties(struct file_stream_desc *stream_desc, struct d ...@@ -1324,12 +1323,13 @@ void opentype_get_font_properties(struct file_stream_desc *stream_desc, struct d
if (macStyle & TT_HEAD_MACSTYLE_BOLD) if (macStyle & TT_HEAD_MACSTYLE_BOLD)
props->weight = DWRITE_FONT_WEIGHT_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->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); TRACE("stretch=%d, weight=%d, style %d\n", props->stretch, props->weight, props->style);
if (tt_os2) if (tt_os2)
......
...@@ -3458,7 +3458,16 @@ static void test_TryGetFontTable(void) ...@@ -3458,7 +3458,16 @@ static void test_TryGetFontTable(void)
static void get_logfont_from_font(IDWriteFont *font, LOGFONTW *logfont) 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; DWRITE_FONT_STYLE style;
const TT_HEAD *tt_head;
LONG weight;
UINT32 size;
BOOL exists;
HRESULT hr;
/* These are rendering time properties. */ /* These are rendering time properties. */
logfont->lfHeight = 0; logfont->lfHeight = 0;
...@@ -3468,32 +3477,50 @@ static void get_logfont_from_font(IDWriteFont *font, LOGFONTW *logfont) ...@@ -3468,32 +3477,50 @@ static void get_logfont_from_font(IDWriteFont *font, LOGFONTW *logfont)
logfont->lfUnderline = 0; logfont->lfUnderline = 0;
logfont->lfStrikeOut = 0; logfont->lfStrikeOut = 0;
logfont->lfWeight = 0;
logfont->lfItalic = 0; logfont->lfItalic = 0;
if (IDWriteFont_GetSimulations(font) & DWRITE_FONT_SIMULATIONS_OBLIQUE) hr = IDWriteFont_CreateFontFace(font, &fontface);
logfont->lfItalic = 1; ok(hr == S_OK, "Failed to create font face, %#x\n", hr);
style = IDWriteFont_GetStyle(font); hr = IDWriteFontFace_TryGetFontTable(fontface, MS_0S2_TAG, (const void **)&tt_os2, &size,
if (!logfont->lfItalic && ((style == DWRITE_FONT_STYLE_ITALIC) || (style == DWRITE_FONT_STYLE_OBLIQUE))) { &os2_context, &exists);
void *os2_context, *head_context; ok(hr == S_OK, "Failed to get OS/2 table, %#x\n", hr);
IDWriteFontFace *fontface;
const TT_OS2_V2 *tt_os2;
const TT_HEAD *tt_head;
UINT32 size;
BOOL exists;
HRESULT hr;
hr = IDWriteFont_CreateFontFace(font, &fontface); hr = IDWriteFontFace_TryGetFontTable(fontface, MS_HEAD_TAG, (const void **)&tt_head, &size,
ok(hr == S_OK, "Failed to create font face, %#x\n", hr); &head_context, &exists);
ok(hr == S_OK, "Failed to get head table, %#x\n", hr);
sim = IDWriteFont_GetSimulations(font);
hr = IDWriteFontFace_TryGetFontTable(fontface, MS_0S2_TAG, (const void **)&tt_os2, &size, /* lfWeight */
&os2_context, &exists); weight = FW_REGULAR;
ok(hr == S_OK, "Failed to get OS/2 table, %#x\n", hr); if (tt_os2) {
USHORT usWeightClass = GET_BE_WORD(tt_os2->usWeightClass);
hr = IDWriteFontFace_TryGetFontTable(fontface, MS_HEAD_TAG, (const void **)&tt_head, &size, if (usWeightClass >= 1 && usWeightClass <= 9)
&head_context, &exists); usWeightClass *= 100;
ok(hr == S_OK, "Failed to get head table, %#x\n", hr);
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))) {
if (tt_os2) { if (tt_os2) {
USHORT fsSelection = GET_BE_WORD(tt_os2->fsSelection); USHORT fsSelection = GET_BE_WORD(tt_os2->fsSelection);
logfont->lfItalic = !!(fsSelection & OS2_FSSELECTION_ITALIC); logfont->lfItalic = !!(fsSelection & OS2_FSSELECTION_ITALIC);
...@@ -3502,13 +3529,13 @@ static void get_logfont_from_font(IDWriteFont *font, LOGFONTW *logfont) ...@@ -3502,13 +3529,13 @@ static void get_logfont_from_font(IDWriteFont *font, LOGFONTW *logfont)
USHORT macStyle = GET_BE_WORD(tt_head->macStyle); USHORT macStyle = GET_BE_WORD(tt_head->macStyle);
logfont->lfItalic = !!(macStyle & TT_HEAD_MACSTYLE_ITALIC); 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) static void test_ConvertFontToLOGFONT(void)
...@@ -3599,10 +3626,12 @@ if (0) { /* crashes on native */ ...@@ -3599,10 +3626,12 @@ if (0) { /* crashes on native */
sim = IDWriteFont_GetSimulations(font); sim = IDWriteFont_GetSimulations(font);
get_logfont_from_font(font, &lf); 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", 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"); 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.lfOutPrecision == OUT_OUTLINE_PRECIS, "got %d\n", logfont.lfOutPrecision);
ok(logfont.lfClipPrecision == 0, "got %d\n", logfont.lfClipPrecision); ok(logfont.lfClipPrecision == 0, "got %d\n", logfont.lfClipPrecision);
ok(logfont.lfQuality == 0, "got %d\n", logfont.lfQuality); ok(logfont.lfQuality == 0, "got %d\n", logfont.lfQuality);
......
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