Nikolay Sivov : dwrite: Implement IDWriteTextFormat::GetFontCollection().

Alexandre Julliard julliard at winehq.org
Tue Oct 23 13:37:18 CDT 2012


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

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Sun Oct 21 23:49:27 2012 -0400

dwrite: Implement IDWriteTextFormat::GetFontCollection().

---

 dlls/dwrite/dwrite_private.h |    2 +-
 dlls/dwrite/layout.c         |   31 ++++++++++++++++++++++++++++---
 dlls/dwrite/main.c           |    6 +-----
 dlls/dwrite/tests/layout.c   |   30 +++++++++++++++++++++++++++++-
 4 files changed, 59 insertions(+), 10 deletions(-)

diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h
index e9d927a..7216393 100644
--- a/dlls/dwrite/dwrite_private.h
+++ b/dlls/dwrite/dwrite_private.h
@@ -68,7 +68,7 @@ static inline LPWSTR heap_strdupnW(const WCHAR *str, UINT32 len)
 }
 
 extern HRESULT create_font_from_logfont(const LOGFONTW*, IDWriteFont**) DECLSPEC_HIDDEN;
-extern HRESULT create_textformat(const WCHAR*,DWRITE_FONT_WEIGHT,DWRITE_FONT_STYLE,DWRITE_FONT_STRETCH,
+extern HRESULT create_textformat(const WCHAR*,IDWriteFontCollection*,DWRITE_FONT_WEIGHT,DWRITE_FONT_STYLE,DWRITE_FONT_STRETCH,
                                  FLOAT,const WCHAR*,IDWriteTextFormat**) DECLSPEC_HIDDEN;
 extern HRESULT create_textlayout(const WCHAR*,UINT32,IDWriteTextLayout**) DECLSPEC_HIDDEN;
 extern HRESULT create_gdiinterop(IDWriteGdiInterop**) DECLSPEC_HIDDEN;
diff --git a/dlls/dwrite/layout.c b/dlls/dwrite/layout.c
index 760ebb2..91360ee 100644
--- a/dlls/dwrite/layout.c
+++ b/dlls/dwrite/layout.c
@@ -51,6 +51,8 @@ struct dwrite_textformat {
     DWRITE_FONT_STRETCH stretch;
 
     FLOAT size;
+
+    IDWriteFontCollection *collection;
 };
 
 static inline struct dwrite_textlayout *impl_from_IDWriteTextLayout(IDWriteTextLayout *iface)
@@ -705,6 +707,7 @@ static ULONG WINAPI dwritetextformat_Release(IDWriteTextFormat *iface)
 
     if (!ref)
     {
+        if (This->collection) IDWriteFontCollection_Release(This->collection);
         heap_free(This->family_name);
         heap_free(This->locale);
         heap_free(This);
@@ -832,8 +835,13 @@ static HRESULT WINAPI dwritetextformat_GetLineSpacing(IDWriteTextFormat *iface,
 static HRESULT WINAPI dwritetextformat_GetFontCollection(IDWriteTextFormat *iface, IDWriteFontCollection **collection)
 {
     struct dwrite_textformat *This = impl_from_IDWriteTextFormat(iface);
-    FIXME("(%p)->(%p): stub\n", This, collection);
-    return E_NOTIMPL;
+
+    TRACE("(%p)->(%p)\n", This, collection);
+
+    *collection = This->collection;
+    IDWriteFontCollection_AddRef(*collection);
+
+    return S_OK;
 }
 
 static UINT32 WINAPI dwritetextformat_GetFontFamilyNameLength(IDWriteTextFormat *iface)
@@ -923,11 +931,13 @@ static const IDWriteTextFormatVtbl dwritetextformatvtbl = {
     dwritetextformat_GetLocaleName
 };
 
-HRESULT create_textformat(const WCHAR *family_name, DWRITE_FONT_WEIGHT weight, DWRITE_FONT_STYLE style,
+HRESULT create_textformat(const WCHAR *family_name, IDWriteFontCollection *collection, DWRITE_FONT_WEIGHT weight, DWRITE_FONT_STYLE style,
     DWRITE_FONT_STRETCH stretch, FLOAT size, const WCHAR *locale, IDWriteTextFormat **format)
 {
     struct dwrite_textformat *This;
 
+    *format = NULL;
+
     This = heap_alloc(sizeof(struct dwrite_textformat));
     if (!This) return E_OUTOFMEMORY;
 
@@ -939,6 +949,21 @@ HRESULT create_textformat(const WCHAR *family_name, DWRITE_FONT_WEIGHT weight, D
     This->style = style;
     This->size = size;
 
+    if (collection)
+    {
+        This->collection = collection;
+        IDWriteFontCollection_AddRef(collection);
+    }
+    else
+    {
+        HRESULT hr = get_system_fontcollection(&This->collection);
+        if (hr != S_OK)
+        {
+            IDWriteTextFormat_Release(&This->IDWriteTextFormat_iface);
+            return hr;
+        }
+    }
+
     *format = &This->IDWriteTextFormat_iface;
 
     return S_OK;
diff --git a/dlls/dwrite/main.c b/dlls/dwrite/main.c
index ea1bbce..09ed3f2 100644
--- a/dlls/dwrite/main.c
+++ b/dlls/dwrite/main.c
@@ -488,11 +488,7 @@ static HRESULT WINAPI dwritefactory_CreateTextFormat(IDWriteFactory *iface, WCHA
 {
     TRACE("(%s %p %d %d %d %f %s %p)\n", debugstr_w(family_name), collection, weight, style, stretch,
         size, debugstr_w(locale), format);
-
-    if (collection)
-        FIXME("font collection not supported\n");
-
-    return create_textformat(family_name, weight, style, stretch, size, locale, format);
+    return create_textformat(family_name, collection, weight, style, stretch, size, locale, format);
 }
 
 static HRESULT WINAPI dwritefactory_CreateTypography(IDWriteFactory *iface, IDWriteTypography **typography)
diff --git a/dlls/dwrite/tests/layout.c b/dlls/dwrite/tests/layout.c
index ab29c06..6b8dc62 100644
--- a/dlls/dwrite/tests/layout.c
+++ b/dlls/dwrite/tests/layout.c
@@ -28,6 +28,7 @@
 static IDWriteFactory *factory;
 
 static const WCHAR tahomaW[] = {'T','a','h','o','m','a',0};
+static const WCHAR enusW[] = {'e','n','-','u','s',0};
 
 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
@@ -62,7 +63,6 @@ static void test_CreateTextLayout(void)
 static void test_CreateGdiCompatibleTextLayout(void)
 {
     static const WCHAR strW[] = {'s','t','r','i','n','g',0};
-    static const WCHAR enusW[] = {'e','n','-','u','s',0};
     IDWriteTextLayout *layout;
     IDWriteTextFormat *format;
     HRESULT hr;
@@ -107,6 +107,33 @@ static void test_CreateGdiCompatibleTextLayout(void)
     IDWriteTextFormat_Release(format);
 }
 
+static void test_CreateTextFormat(void)
+{
+    IDWriteFontCollection *collection, *syscoll;
+    IDWriteTextFormat *format;
+    HRESULT hr;
+
+    hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
+        DWRITE_FONT_STRETCH_NORMAL, 10.0, enusW, &format);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+
+if (0) /* crashes on native */
+    hr = IDWriteTextFormat_GetFontCollection(format, NULL);
+
+    collection = NULL;
+    hr = IDWriteTextFormat_GetFontCollection(format, &collection);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    ok(collection != NULL, "got %p\n", collection);
+
+    hr = IDWriteFactory_GetSystemFontCollection(factory, &syscoll, FALSE);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    ok(collection == syscoll, "got %p, was %p\n", syscoll, collection);
+    IDWriteFontCollection_Release(syscoll);
+    IDWriteFontCollection_Release(collection);
+
+    IDWriteTextFormat_Release(format);
+}
+
 START_TEST(layout)
 {
     HRESULT hr;
@@ -121,6 +148,7 @@ START_TEST(layout)
 
     test_CreateTextLayout();
     test_CreateGdiCompatibleTextLayout();
+    test_CreateTextFormat();
 
     IDWriteFactory_Release(factory);
 }




More information about the wine-cvs mailing list