Nikolay Sivov : dwrite: Implement GetPaletteEntries().

Alexandre Julliard julliard at wine.codeweavers.com
Fri Aug 7 10:57:42 CDT 2015


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

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Thu Aug  6 19:44:27 2015 +0300

dwrite: Implement GetPaletteEntries().

---

 dlls/dwrite/dwrite_private.h |  1 +
 dlls/dwrite/font.c           |  4 ++--
 dlls/dwrite/opentype.c       | 38 ++++++++++++++++++++++++++++++++++++++
 dlls/dwrite/tests/font.c     |  6 ------
 4 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h
index a849406..48078d9 100644
--- a/dlls/dwrite/dwrite_private.h
+++ b/dlls/dwrite/dwrite_private.h
@@ -155,6 +155,7 @@ extern HRESULT opentype_get_typographic_features(IDWriteFontFace*,UINT32,UINT32,
 extern BOOL opentype_get_vdmx_size(const void*,INT,UINT16*,UINT16*) DECLSPEC_HIDDEN;
 extern UINT32 opentype_get_cpal_palettecount(const void*) DECLSPEC_HIDDEN;
 extern UINT32 opentype_get_cpal_paletteentrycount(const void*) DECLSPEC_HIDDEN;
+extern HRESULT opentype_get_cpal_entries(const void*,UINT32,UINT32,UINT32,DWRITE_COLOR_F*) DECLSPEC_HIDDEN;
 
 enum gasp_flags {
     GASP_GRIDFIT             = 0x0001,
diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c
index 266f7ef..80a209f 100644
--- a/dlls/dwrite/font.c
+++ b/dlls/dwrite/font.c
@@ -972,8 +972,8 @@ static HRESULT WINAPI dwritefontface2_GetPaletteEntries(IDWriteFontFace2 *iface,
     UINT32 first_entry_index, UINT32 entry_count, DWRITE_COLOR_F *entries)
 {
     struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
-    FIXME("(%p)->(%u %u %u %p): stub\n", This, palette_index, first_entry_index, entry_count, entries);
-    return E_NOTIMPL;
+    TRACE("(%p)->(%u %u %u %p)\n", This, palette_index, first_entry_index, entry_count, entries);
+    return opentype_get_cpal_entries(get_fontface_cpal(This), palette_index, first_entry_index, entry_count, entries);
 }
 
 static HRESULT WINAPI dwritefontface2_GetRecommendedRenderingMode(IDWriteFontFace2 *iface, FLOAT emSize,
diff --git a/dlls/dwrite/opentype.c b/dlls/dwrite/opentype.c
index 7be9df3..f8c66fc 100644
--- a/dlls/dwrite/opentype.c
+++ b/dlls/dwrite/opentype.c
@@ -687,6 +687,14 @@ struct CPAL_SubHeader_1
     ULONG  offsetPaletteEntryLabelArray;
 };
 
+struct CPAL_ColorRecord
+{
+    BYTE blue;
+    BYTE green;
+    BYTE red;
+    BYTE alpha;
+};
+
 BOOL is_face_type_supported(DWRITE_FONT_FACE_TYPE type)
 {
     return (type == DWRITE_FONT_FACE_TYPE_CFF) ||
@@ -1434,3 +1442,33 @@ UINT32 opentype_get_cpal_paletteentrycount(const void *cpal)
     const struct CPAL_Header_0 *header = (const struct CPAL_Header_0*)cpal;
     return header ? GET_BE_WORD(header->numPaletteEntries) : 0;
 }
+
+HRESULT opentype_get_cpal_entries(const void *cpal, UINT32 palette, UINT32 first_entry_index, UINT32 entry_count,
+    DWRITE_COLOR_F *entries)
+{
+    const struct CPAL_Header_0 *header = (const struct CPAL_Header_0*)cpal;
+    const struct CPAL_ColorRecord *records;
+    UINT32 palettecount, entrycount, i;
+
+    if (!header) return DWRITE_E_NOCOLOR;
+
+    palettecount = GET_BE_WORD(header->numPalette);
+    if (palette >= palettecount)
+        return DWRITE_E_NOCOLOR;
+
+    entrycount = GET_BE_WORD(header->numPaletteEntries);
+    if (first_entry_index + entry_count > entrycount)
+        return E_INVALIDARG;
+
+    records = (const struct CPAL_ColorRecord*)((BYTE*)cpal + GET_BE_DWORD(header->offsetFirstColorRecord));
+    first_entry_index += GET_BE_WORD(header->colorRecordIndices[palette]);
+
+    for (i = 0; i < entry_count; i++) {
+        entries[i].r = records[first_entry_index + i].red   / 255.0f;
+        entries[i].g = records[first_entry_index + i].green / 255.0f;
+        entries[i].b = records[first_entry_index + i].blue  / 255.0f;
+        entries[i].a = records[first_entry_index + i].alpha / 255.0f;
+    }
+
+    return S_OK;
+}
diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c
index 6c5cb82..0664a9a 100644
--- a/dlls/dwrite/tests/font.c
+++ b/dlls/dwrite/tests/font.c
@@ -4792,7 +4792,6 @@ static void test_GetPaletteEntries(void)
     }
 
     hr = IDWriteFontFace2_GetPaletteEntries(fontface2, 0, 0, 1, &color);
-todo_wine
     ok(hr == DWRITE_E_NOCOLOR, "got 0x%08x\n", hr);
     IDWriteFontFace2_Release(fontface2);
 
@@ -4827,7 +4826,6 @@ todo_wine
     /* invalid palette index */
     color.r = color.g = color.b = color.a = 123.0;
     hr = IDWriteFontFace2_GetPaletteEntries(fontface2, palettecount, 0, 1, &color);
-todo_wine
     ok(hr == DWRITE_E_NOCOLOR, "got 0x%08x\n", hr);
     ok(color.r == 123.0 && color.g == 123.0 && color.b == 123.0 && color.a == 123.0,
         "got wrong color %.2fx%.2fx%.2fx%.2f\n", color.r, color.g, color.b, color.a);
@@ -4835,23 +4833,19 @@ todo_wine
     /* invalid entry index */
     color.r = color.g = color.b = color.a = 123.0;
     hr = IDWriteFontFace2_GetPaletteEntries(fontface2, 0, entrycount, 1, &color);
-todo_wine
     ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
     ok(color.r == 123.0 && color.g == 123.0 && color.b == 123.0 && color.a == 123.0,
         "got wrong color %.2fx%.2fx%.2fx%.2f\n", color.r, color.g, color.b, color.a);
 
     color.r = color.g = color.b = color.a = 123.0;
     hr = IDWriteFontFace2_GetPaletteEntries(fontface2, 0, entrycount - 1, 1, &color);
-todo_wine {
     ok(hr == S_OK, "got 0x%08x\n", hr);
     ok(color.r != 123.0 && color.g != 123.0 && color.b != 123.0 && color.a != 123.0,
         "got wrong color %.2fx%.2fx%.2fx%.2f\n", color.r, color.g, color.b, color.a);
-}
 
     /* zero return length */
     color.r = color.g = color.b = color.a = 123.0;
     hr = IDWriteFontFace2_GetPaletteEntries(fontface2, 0, 0, 0, &color);
-todo_wine
     ok(hr == S_OK, "got 0x%08x\n", hr);
     ok(color.r == 123.0 && color.g == 123.0 && color.b == 123.0 && color.a == 123.0,
         "got wrong color %.2fx%.2fx%.2fx%.2f\n", color.r, color.g, color.b, color.a);




More information about the wine-cvs mailing list