dwrite: Set oblique simulation in GetFirstMatchingFont() when appropriate.
This commit is contained in:
parent
901a65ae42
commit
1d2993940a
|
@ -1213,6 +1213,17 @@ static HRESULT WINAPI dwritefontfamily_GetFamilyNames(IDWriteFontFamily *iface,
|
|||
return clone_localizedstring(This->data->familyname, names);
|
||||
}
|
||||
|
||||
static inline BOOL is_matching_font_style(DWRITE_FONT_STYLE style, DWRITE_FONT_STYLE font_style)
|
||||
{
|
||||
if (style == font_style)
|
||||
return TRUE;
|
||||
|
||||
if (((style == DWRITE_FONT_STYLE_ITALIC) || (style == DWRITE_FONT_STYLE_OBLIQUE)) && font_style == DWRITE_FONT_STYLE_NORMAL)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily *iface, DWRITE_FONT_WEIGHT weight,
|
||||
DWRITE_FONT_STRETCH stretch, DWRITE_FONT_STYLE style, IDWriteFont **font)
|
||||
{
|
||||
|
@ -1237,7 +1248,7 @@ static HRESULT WINAPI dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily *i
|
|||
int found = -1, i;
|
||||
|
||||
for (i = 0; i < This->data->font_count; i++) {
|
||||
if (style == This->data->fonts[i]->style && stretch == This->data->fonts[i]->stretch) {
|
||||
if (is_matching_font_style(style, This->data->fonts[i]->style) && stretch == This->data->fonts[i]->stretch) {
|
||||
DWRITE_FONT_WEIGHT font_weight = This->data->fonts[i]->weight;
|
||||
UINT32 weight_diff = abs(font_weight - weight);
|
||||
if (weight_diff < min_weight_diff) {
|
||||
|
@ -1247,7 +1258,19 @@ static HRESULT WINAPI dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily *i
|
|||
}
|
||||
}
|
||||
|
||||
return found != -1 ? create_font_from_data(This->data->fonts[found], iface, DWRITE_FONT_SIMULATIONS_NONE, font) : DWRITE_E_NOFONT;
|
||||
if (found != -1) {
|
||||
DWRITE_FONT_SIMULATIONS simulations = DWRITE_FONT_SIMULATIONS_NONE;
|
||||
|
||||
if (((style == DWRITE_FONT_STYLE_ITALIC) || (style == DWRITE_FONT_STYLE_OBLIQUE)) &&
|
||||
This->data->fonts[found]->style == DWRITE_FONT_STYLE_ITALIC) {
|
||||
simulations = DWRITE_FONT_SIMULATIONS_OBLIQUE;
|
||||
}
|
||||
return create_font_from_data(This->data->fonts[found], iface, simulations, font);
|
||||
}
|
||||
else {
|
||||
*font = NULL;
|
||||
return DWRITE_E_NOFONT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1475,10 +1475,13 @@ if (font3)
|
|||
|
||||
static void test_GetFirstMatchingFont(void)
|
||||
{
|
||||
DWRITE_FONT_SIMULATIONS simulations;
|
||||
IDWriteFontCollection *collection;
|
||||
IDWriteFont *font, *font2;
|
||||
IDWriteFontFamily *family;
|
||||
IDWriteFactory *factory;
|
||||
UINT32 index;
|
||||
BOOL exists;
|
||||
HRESULT hr;
|
||||
|
||||
factory = create_factory();
|
||||
|
@ -1486,7 +1489,13 @@ static void test_GetFirstMatchingFont(void)
|
|||
hr = IDWriteFactory_GetSystemFontCollection(factory, &collection, FALSE);
|
||||
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||
|
||||
hr = IDWriteFontCollection_GetFontFamily(collection, 0, &family);
|
||||
index = ~0;
|
||||
exists = FALSE;
|
||||
hr = IDWriteFontCollection_FindFamilyName(collection, tahomaW, &index, &exists);
|
||||
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||
ok(exists, "got %d\n", exists);
|
||||
|
||||
hr = IDWriteFontCollection_GetFontFamily(collection, index, &family);
|
||||
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||
|
||||
hr = IDWriteFontFamily_GetFirstMatchingFont(family, DWRITE_FONT_WEIGHT_NORMAL,
|
||||
|
@ -1497,6 +1506,15 @@ static void test_GetFirstMatchingFont(void)
|
|||
DWRITE_FONT_STRETCH_NORMAL, DWRITE_FONT_STYLE_NORMAL, &font2);
|
||||
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||
ok(font != font2, "got %p, %p\n", font, font2);
|
||||
IDWriteFont_Release(font);
|
||||
|
||||
hr = IDWriteFontFamily_GetFirstMatchingFont(family, DWRITE_FONT_WEIGHT_NORMAL,
|
||||
DWRITE_FONT_STRETCH_NORMAL, DWRITE_FONT_STYLE_ITALIC, &font);
|
||||
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||
|
||||
simulations = IDWriteFont_GetSimulations(font);
|
||||
todo_wine
|
||||
ok(simulations == DWRITE_FONT_SIMULATIONS_OBLIQUE, "%d\n", simulations);
|
||||
|
||||
IDWriteFont_Release(font);
|
||||
IDWriteFont_Release(font2);
|
||||
|
|
Loading…
Reference in New Issue