dwrite: Allow for a weight difference in GetFirstMatchingFont().

This commit is contained in:
Nikolay Sivov 2014-10-27 14:53:59 +03:00 committed by Alexandre Julliard
parent 6706ada9f8
commit 5a5a6bdd92
1 changed files with 13 additions and 9 deletions

View File

@ -1233,17 +1233,21 @@ static HRESULT WINAPI dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily *i
} }
else else
{ {
int i; UINT32 min_weight_diff = ~0u;
for (i = 0; i < This->data->font_count; i++) int found = -1, i;
{
if (style == This->data->fonts[i]->style && for (i = 0; i < This->data->font_count; i++) {
weight == This->data->fonts[i]->weight && if (style == This->data->fonts[i]->style && stretch == This->data->fonts[i]->stretch) {
stretch == This->data->fonts[i]->stretch) DWRITE_FONT_WEIGHT font_weight = This->data->fonts[i]->weight;
{ UINT32 weight_diff = abs(font_weight - weight);
return create_font_from_data(This->data->fonts[i], iface, font); if (weight_diff < min_weight_diff) {
min_weight_diff = weight_diff;
found = i;
}
} }
} }
return DWRITE_E_NOFONT;
return found != -1 ? create_font_from_data(This->data->fonts[found], iface, font) : DWRITE_E_NOFONT;
} }
} }