Nikolay Sivov : dwrite: Allow for a weight difference in GetFirstMatchingFont().
Alexandre Julliard
julliard at wine.codeweavers.com
Wed Oct 29 07:36:58 CDT 2014
Module: wine
Branch: master
Commit: 5a5a6bdd92aa83b73fd54db8dddaf8329a9df813
URL: http://source.winehq.org/git/wine.git/?a=commit;h=5a5a6bdd92aa83b73fd54db8dddaf8329a9df813
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Mon Oct 27 14:53:59 2014 +0300
dwrite: Allow for a weight difference in GetFirstMatchingFont().
---
dlls/dwrite/font.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c
index b271e93..5112d24 100644
--- a/dlls/dwrite/font.c
+++ b/dlls/dwrite/font.c
@@ -1233,17 +1233,21 @@ static HRESULT WINAPI dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily *i
}
else
{
- int i;
- for (i = 0; i < This->data->font_count; i++)
- {
- if (style == This->data->fonts[i]->style &&
- weight == This->data->fonts[i]->weight &&
- stretch == This->data->fonts[i]->stretch)
- {
- return create_font_from_data(This->data->fonts[i], iface, font);
+ UINT32 min_weight_diff = ~0u;
+ 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) {
+ DWRITE_FONT_WEIGHT font_weight = This->data->fonts[i]->weight;
+ UINT32 weight_diff = abs(font_weight - weight);
+ 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;
}
}
More information about the wine-cvs
mailing list