[PATCH 5/9] dwrite: Add newer CreateFontFaceReference() variant.

Nikolay Sivov nsivov at codeweavers.com
Thu Dec 5 02:56:01 CST 2019


Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
 dlls/dwrite/dwrite_private.h |  5 +++--
 dlls/dwrite/font.c           | 26 +++++++++++++++++++++-----
 dlls/dwrite/main.c           | 19 ++++++++++++-------
 dlls/dwrite/tests/font.c     | 25 +++++++++++++++++++------
 4 files changed, 55 insertions(+), 20 deletions(-)

diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h
index 1598bb6aee..9447c59663 100644
--- a/dlls/dwrite/dwrite_private.h
+++ b/dlls/dwrite/dwrite_private.h
@@ -262,8 +262,9 @@ extern void release_system_fontfallback(IDWriteFontFallback1 *fallback) DECLSPEC
 extern HRESULT create_fontfallback_builder(IDWriteFactory5*,IDWriteFontFallbackBuilder**) DECLSPEC_HIDDEN;
 extern HRESULT create_matching_font(IDWriteFontCollection*,const WCHAR*,DWRITE_FONT_WEIGHT,DWRITE_FONT_STYLE,DWRITE_FONT_STRETCH,
     IDWriteFont**) DECLSPEC_HIDDEN;
-extern HRESULT create_fontfacereference(IDWriteFactory5*,IDWriteFontFile*,UINT32,DWRITE_FONT_SIMULATIONS,
-    IDWriteFontFaceReference**) DECLSPEC_HIDDEN;
+extern HRESULT create_fontfacereference(IDWriteFactory5 *factory, IDWriteFontFile *file, UINT32 face_index,
+        DWRITE_FONT_SIMULATIONS simulations, DWRITE_FONT_AXIS_VALUE const *axis_values, UINT32 axis_values_count,
+        IDWriteFontFaceReference1 **reference) DECLSPEC_HIDDEN;
 extern HRESULT factory_get_cached_fontface(IDWriteFactory5*,IDWriteFontFile*const*,UINT32,DWRITE_FONT_SIMULATIONS,
         struct list**,REFIID,void**) DECLSPEC_HIDDEN;
 extern void factory_detach_fontcollection(IDWriteFactory5 *factory, IDWriteFontCollection3 *collection) DECLSPEC_HIDDEN;
diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c
index 8045bce870..c9f1e885d5 100644
--- a/dlls/dwrite/font.c
+++ b/dlls/dwrite/font.c
@@ -231,6 +231,8 @@ struct dwrite_fontfacereference
     IDWriteFontFile *file;
     UINT32 index;
     USHORT simulations;
+    DWRITE_FONT_AXIS_VALUE *axis_values;
+    UINT32 axis_values_count;
     IDWriteFactory5 *factory;
 };
 
@@ -6081,6 +6083,7 @@ static ULONG WINAPI fontfacereference_Release(IDWriteFontFaceReference1 *iface)
     {
         IDWriteFontFile_Release(reference->file);
         IDWriteFactory5_Release(reference->factory);
+        heap_free(reference->axis_values);
         heap_free(reference);
     }
 
@@ -6253,9 +6256,11 @@ static HRESULT WINAPI fontfacereference1_CreateFontFace(IDWriteFontFaceReference
 
 static UINT32 WINAPI fontfacereference1_GetFontAxisValueCount(IDWriteFontFaceReference1 *iface)
 {
-    FIXME("%p.\n", iface);
+    struct dwrite_fontfacereference *reference = impl_from_IDWriteFontFaceReference1(iface);
 
-    return 0;
+    TRACE("%p.\n", iface);
+
+    return reference->axis_values_count;
 }
 
 static HRESULT WINAPI fontfacereference1_GetFontAxisValues(IDWriteFontFaceReference1 *iface,
@@ -6291,7 +6296,8 @@ static const IDWriteFontFaceReference1Vtbl fontfacereferencevtbl =
 };
 
 HRESULT create_fontfacereference(IDWriteFactory5 *factory, IDWriteFontFile *file, UINT32 index,
-    DWRITE_FONT_SIMULATIONS simulations, IDWriteFontFaceReference **ret)
+        DWRITE_FONT_SIMULATIONS simulations, DWRITE_FONT_AXIS_VALUE const *axis_values, UINT32 axis_values_count,
+        IDWriteFontFaceReference1 **ret)
 {
     struct dwrite_fontfacereference *object;
 
@@ -6300,7 +6306,7 @@ HRESULT create_fontfacereference(IDWriteFactory5 *factory, IDWriteFontFile *file
     if (!is_simulation_valid(simulations))
         return E_INVALIDARG;
 
-    object = heap_alloc(sizeof(*object));
+    object = heap_alloc_zero(sizeof(*object));
     if (!object)
         return E_OUTOFMEMORY;
 
@@ -6313,8 +6319,18 @@ HRESULT create_fontfacereference(IDWriteFactory5 *factory, IDWriteFontFile *file
     IDWriteFontFile_AddRef(object->file);
     object->index = index;
     object->simulations = simulations;
+    if (axis_values_count)
+    {
+        if (!(object->axis_values = heap_alloc(axis_values_count * sizeof(*axis_values))))
+        {
+            IDWriteFontFaceReference1_Release(&object->IDWriteFontFaceReference1_iface);
+            return E_OUTOFMEMORY;
+        }
+        memcpy(object->axis_values, axis_values, axis_values_count * sizeof(*axis_values));
+        object->axis_values_count = axis_values_count;
+    }
 
-    *ret = (IDWriteFontFaceReference *)&object->IDWriteFontFaceReference1_iface;
+    *ret = &object->IDWriteFontFaceReference1_iface;
 
     return S_OK;
 }
diff --git a/dlls/dwrite/main.c b/dlls/dwrite/main.c
index e4b76823ff..5f30b8e4f4 100644
--- a/dlls/dwrite/main.c
+++ b/dlls/dwrite/main.c
@@ -1443,7 +1443,8 @@ static HRESULT WINAPI dwritefactory3_CreateFontFaceReference_(IDWriteFactory7 *i
 {
     TRACE("%p, %p, %u, %x, %p.\n", iface, file, index, simulations, reference);
 
-    return create_fontfacereference((IDWriteFactory5 *)iface, file, index, simulations, reference);
+    return create_fontfacereference((IDWriteFactory5 *)iface, file, index, simulations, NULL, 0,
+            (IDWriteFontFaceReference1 **)reference);
 }
 
 static HRESULT WINAPI dwritefactory3_CreateFontFaceReference(IDWriteFactory7 *iface, WCHAR const *path,
@@ -1455,13 +1456,15 @@ static HRESULT WINAPI dwritefactory3_CreateFontFaceReference(IDWriteFactory7 *if
 
     TRACE("%p, %s, %p, %u, %#x, %p.\n", iface, debugstr_w(path), writetime, index, simulations, reference);
 
-    hr = IDWriteFactory5_CreateFontFileReference((IDWriteFactory5 *)iface, path, writetime, &file);
-    if (FAILED(hr)) {
+    hr = IDWriteFactory7_CreateFontFileReference(iface, path, writetime, &file);
+    if (FAILED(hr))
+    {
         *reference = NULL;
         return hr;
     }
 
-    hr = IDWriteFactory5_CreateFontFaceReference_((IDWriteFactory5 *)iface, file, index, simulations, reference);
+    hr = create_fontfacereference((IDWriteFactory5 *)iface, file, index, simulations, NULL, 0,
+            (IDWriteFontFaceReference1 **)reference);
     IDWriteFontFile_Release(file);
     return hr;
 }
@@ -1656,11 +1659,13 @@ static HRESULT WINAPI dwritefactory5_UnpackFontFile(IDWriteFactory7 *iface, DWRI
 
 static HRESULT WINAPI dwritefactory6_CreateFontFaceReference(IDWriteFactory7 *iface, IDWriteFontFile *file,
         UINT32 face_index, DWRITE_FONT_SIMULATIONS simulations, DWRITE_FONT_AXIS_VALUE const *axis_values,
-        UINT32 num_axis, IDWriteFontFaceReference1 **ref)
+        UINT32 axis_values_count, IDWriteFontFaceReference1 **reference)
 {
-    FIXME("%p, %p, %u, %#x, %p, %u, %p.\n", iface, file, face_index, simulations, axis_values, num_axis, ref);
+    TRACE("%p, %p, %u, %#x, %p, %u, %p.\n", iface, file, face_index, simulations, axis_values, axis_values_count,
+            reference);
 
-    return E_NOTIMPL;
+    return create_fontfacereference((IDWriteFactory5 *)iface, file, face_index, simulations, axis_values,
+            axis_values_count, reference);
 }
 
 static HRESULT WINAPI dwritefactory6_CreateFontResource(IDWriteFactory7 *iface, IDWriteFontFile *file,
diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c
index 83d6be4449..5ab01465b7 100644
--- a/dlls/dwrite/tests/font.c
+++ b/dlls/dwrite/tests/font.c
@@ -9239,6 +9239,7 @@ static void test_font_resource(void)
     IDWriteFontFaceReference1 *reference, *reference2;
     IDWriteFontResource *resource, *resource2;
     IDWriteFontFile *fontfile, *fontfile2;
+    DWRITE_FONT_AXIS_VALUE axis_value;
     IDWriteFontFace5 *fontface5;
     IDWriteFontFace *fontface;
     IDWriteFactory6 *factory;
@@ -9274,22 +9275,34 @@ static void test_font_resource(void)
     index = IDWriteFontResource_GetFontFaceIndex(resource);
     ok(!index, "Unexpected index %u.\n", index);
 
+    /* Specify axis value, font has no variations. */
+    axis_value.axisTag = DWRITE_FONT_AXIS_TAG_WEIGHT;
+    axis_value.value = 400.0f;
+    hr = IDWriteFontResource_CreateFontFaceReference(resource, DWRITE_FONT_SIMULATIONS_NONE, &axis_value, 1, &reference);
+    ok(hr == S_OK, "Failed to create reference object, hr %#x.\n", hr);
+
+    count = IDWriteFontFaceReference1_GetFontAxisValueCount(reference);
+    ok(count == 1, "Unexpected axis value count.\n");
+
+    IDWriteFontFaceReference1_Release(reference);
+
+    hr = IDWriteFactory6_CreateFontFaceReference(factory, fontfile, 0, DWRITE_FONT_SIMULATIONS_NONE, &axis_value, 1,
+            &reference);
+    count = IDWriteFontFaceReference1_GetFontAxisValueCount(reference);
+    ok(count == 1, "Unexpected axis value count.\n");
+    IDWriteFontFaceReference1_Release(reference);
+
     EXPECT_REF(resource, 1);
     hr = IDWriteFontResource_CreateFontFaceReference(resource, DWRITE_FONT_SIMULATIONS_NONE, NULL, 0, &reference);
-todo_wine
     ok(hr == S_OK, "Failed to create reference object, hr %#x.\n", hr);
     EXPECT_REF(resource, 1);
 
     hr = IDWriteFontResource_CreateFontFaceReference(resource, DWRITE_FONT_SIMULATIONS_NONE, NULL, 0, &reference2);
-todo_wine
     ok(hr == S_OK, "Failed to create reference object, hr %#x.\n", hr);
-
-if (SUCCEEDED(hr))
-{
     ok(reference != reference2, "Unexpected reference instance.\n");
     IDWriteFontFaceReference1_Release(reference2);
     IDWriteFontFaceReference1_Release(reference);
-}
+
     hr = IDWriteFontFace_QueryInterface(fontface, &IID_IDWriteFontFace5, (void **)&fontface5);
     ok(hr == S_OK, "Failed to get interface, hr %#x.\n", hr);
 
-- 
2.24.0




More information about the wine-devel mailing list