Nikolay Sivov : dwrite: Simplify collection_find_family().

Alexandre Julliard julliard at wine.codeweavers.com
Wed Feb 4 10:51:17 CST 2015


Module: wine
Branch: master
Commit: 77189de8b7bb9b19ec6ce90571d890826bbb9d1d
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=77189de8b7bb9b19ec6ce90571d890826bbb9d1d

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Wed Feb  4 15:28:48 2015 +0300

dwrite: Simplify collection_find_family().

---

 dlls/dwrite/font.c | 43 +++++++++++++++++--------------------------
 1 file changed, 17 insertions(+), 26 deletions(-)

diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c
index ca586ea..3dc5738 100644
--- a/dlls/dwrite/font.c
+++ b/dlls/dwrite/font.c
@@ -1424,40 +1424,33 @@ static HRESULT WINAPI dwritefontcollection_GetFontFamily(IDWriteFontCollection *
     return create_fontfamily(This->family_data[index], iface, family);
 }
 
-static HRESULT collection_find_family(struct dwrite_fontcollection *collection, const WCHAR *name, UINT32 *index, BOOL *exists)
+static UINT32 collection_find_family(struct dwrite_fontcollection *collection, const WCHAR *name)
 {
     UINT32 i;
 
-    if (collection->family_count) {
-        for (i = 0; i < collection->family_count; i++) {
-            IDWriteLocalizedStrings *family_name = collection->family_data[i]->familyname;
-            HRESULT hr;
-            int j;
-
-            for (j = 0; j < IDWriteLocalizedStrings_GetCount(family_name); j++) {
-                WCHAR buffer[255];
-                hr = IDWriteLocalizedStrings_GetString(family_name, j, buffer, 255);
-                if (SUCCEEDED(hr)) {
-                    if (!strcmpW(buffer, name)) {
-                        *index = i;
-                        *exists = TRUE;
-                        return S_OK;
-                    }
-                }
-            }
+    for (i = 0; i < collection->family_count; i++) {
+        IDWriteLocalizedStrings *family_name = collection->family_data[i]->familyname;
+        HRESULT hr;
+        int j;
+
+        for (j = 0; j < IDWriteLocalizedStrings_GetCount(family_name); j++) {
+            WCHAR buffer[255];
+            hr = IDWriteLocalizedStrings_GetString(family_name, j, buffer, 255);
+            if (SUCCEEDED(hr) && !strcmpW(buffer, name))
+                return i;
         }
-        *index = (UINT32)-1;
-        *exists = FALSE;
     }
 
-    return S_OK;
+    return ~0u;
 }
 
 static HRESULT WINAPI dwritefontcollection_FindFamilyName(IDWriteFontCollection *iface, const WCHAR *name, UINT32 *index, BOOL *exists)
 {
     struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection(iface);
     TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(name), index, exists);
-    return collection_find_family(This, name, index, exists);
+    *index = collection_find_family(This, name);
+    *exists = *index != ~0u;
+    return S_OK;
 }
 
 static BOOL is_same_fontfile(IDWriteFontFile *left, IDWriteFontFile *right)
@@ -1728,7 +1721,6 @@ HRESULT create_font_collection(IDWriteFactory2* factory, IDWriteFontFileEnumerat
             IDWriteFontFileStream *stream;
             WCHAR buffer[255];
             UINT32 index;
-            BOOL exists;
 
             /* alloc and init new font data structure */
             font_data = heap_alloc_zero(sizeof(struct dwrite_font_data));
@@ -1755,9 +1747,8 @@ HRESULT create_font_collection(IDWriteFactory2* factory, IDWriteFontFileEnumerat
             buffer[0] = 0;
             IDWriteLocalizedStrings_GetString(family_name, 0, buffer, sizeof(buffer)/sizeof(WCHAR));
 
-            exists = FALSE;
-            hr = collection_find_family(collection, buffer, &index, &exists);
-            if (exists)
+            index = collection_find_family(collection, buffer);
+            if (index != ~0u)
                 fontfamily_add_font(collection->family_data[index], font_data);
             else {
                 struct dwrite_fontfamily_data *family_data;




More information about the wine-cvs mailing list