Nikolay Sivov : dwrite: Set oblique simulation in GetFirstMatchingFont() when appropriate.
Alexandre Julliard
julliard at wine.codeweavers.com
Wed Oct 29 07:36:58 CDT 2014
Module: wine
Branch: master
Commit: 1d2993940ae0d0c9a63141ea0e54061be356c4b7
URL: http://source.winehq.org/git/wine.git/?a=commit;h=1d2993940ae0d0c9a63141ea0e54061be356c4b7
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Mon Oct 27 19:01:48 2014 +0300
dwrite: Set oblique simulation in GetFirstMatchingFont() when appropriate.
---
dlls/dwrite/font.c | 27 +++++++++++++++++++++++++--
dlls/dwrite/tests/font.c | 20 +++++++++++++++++++-
2 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c
index dd46ee7..4ebe261 100644
--- a/dlls/dwrite/font.c
+++ b/dlls/dwrite/font.c
@@ -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;
+ }
}
}
diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c
index 9cad650..74aad58 100644
--- a/dlls/dwrite/tests/font.c
+++ b/dlls/dwrite/tests/font.c
@@ -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);
More information about the wine-cvs
mailing list