Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/layout.c | 53 +++++++++++++++------- dlls/dwrite/tests/layout.c | 91 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+), 15 deletions(-)
diff --git a/dlls/dwrite/layout.c b/dlls/dwrite/layout.c index b9321157a91..25d3bcb4ad0 100644 --- a/dlls/dwrite/layout.c +++ b/dlls/dwrite/layout.c @@ -32,7 +32,8 @@
WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
-struct dwrite_textformat_data { +struct dwrite_textformat_data +{ WCHAR *family_name; UINT32 family_len; WCHAR *locale; @@ -51,6 +52,7 @@ struct dwrite_textformat_data { DWRITE_VERTICAL_GLYPH_ORIENTATION vertical_orientation; DWRITE_OPTICAL_ALIGNMENT optical_alignment; DWRITE_LINE_SPACING spacing; + DWRITE_AUTOMATIC_FONT_AXES automatic_axes;
FLOAT fontsize; FLOAT tabstop; @@ -4144,17 +4146,25 @@ static HRESULT WINAPI dwritetextlayout4_GetFontAxisValues(IDWriteTextLayout4 *if
static DWRITE_AUTOMATIC_FONT_AXES WINAPI dwritetextlayout4_GetAutomaticFontAxes(IDWriteTextLayout4 *iface) { - FIXME("%p.\n", iface); + struct dwrite_textlayout *layout = impl_from_IDWriteTextLayout4(iface); + + TRACE("%p.\n", iface);
- return DWRITE_AUTOMATIC_FONT_AXES_NONE; + return layout->format.automatic_axes; }
static HRESULT WINAPI dwritetextlayout4_SetAutomaticFontAxes(IDWriteTextLayout4 *iface, DWRITE_AUTOMATIC_FONT_AXES axes) { - FIXME("%p, %d.\n", iface, axes); + struct dwrite_textlayout *layout = impl_from_IDWriteTextLayout4(iface);
- return E_NOTIMPL; + TRACE("%p, %d.\n", iface, axes); + + if ((unsigned int)axes > DWRITE_AUTOMATIC_FONT_AXES_OPTICAL_SIZE) + return E_INVALIDARG; + + layout->format.automatic_axes = axes; + return S_OK; }
static const IDWriteTextLayout4Vtbl dwritetextlayoutvtbl = @@ -4702,17 +4712,15 @@ static HRESULT WINAPI dwritetextformat3_layout_GetFontAxisValues(IDWriteTextForm
static DWRITE_AUTOMATIC_FONT_AXES WINAPI dwritetextformat3_layout_GetAutomaticFontAxes(IDWriteTextFormat3 *iface) { - FIXME("%p.\n", iface); - - return DWRITE_AUTOMATIC_FONT_AXES_NONE; + struct dwrite_textlayout *layout = impl_layout_from_IDWriteTextFormat3(iface); + return IDWriteTextLayout4_GetAutomaticFontAxes(&layout->IDWriteTextLayout4_iface); }
static HRESULT WINAPI dwritetextformat3_layout_SetAutomaticFontAxes(IDWriteTextFormat3 *iface, DWRITE_AUTOMATIC_FONT_AXES axes) { - FIXME("%p, %d.\n", iface, axes); - - return E_NOTIMPL; + struct dwrite_textlayout *layout = impl_layout_from_IDWriteTextFormat3(iface); + return IDWriteTextLayout4_SetAutomaticFontAxes(&layout->IDWriteTextLayout4_iface, axes); }
static const IDWriteTextFormat3Vtbl dwritetextformat3_layout_vtbl = @@ -5036,6 +5044,7 @@ static HRESULT layout_format_from_textformat(struct dwrite_textlayout *layout, I { struct dwrite_textformat *textformat; IDWriteTextFormat1 *format1; + IDWriteTextFormat3 *format3; UINT32 len; HRESULT hr;
@@ -5125,6 +5134,13 @@ static HRESULT layout_format_from_textformat(struct dwrite_textlayout *layout, I layout->format.optical_alignment = DWRITE_OPTICAL_ALIGNMENT_NONE; }
+ hr = IDWriteTextFormat_QueryInterface(format, &IID_IDWriteTextFormat3, (void **)&format3); + if (hr == S_OK) + { + layout->format.automatic_axes = IDWriteTextFormat3_GetAutomaticFontAxes(format3); + IDWriteTextFormat3_Release(format3); + } + return IDWriteTextFormat_GetFontCollection(format, &layout->format.collection); }
@@ -5833,16 +5849,22 @@ static HRESULT WINAPI dwritetextformat3_GetFontAxisValues(IDWriteTextFormat3 *if
static DWRITE_AUTOMATIC_FONT_AXES WINAPI dwritetextformat3_GetAutomaticFontAxes(IDWriteTextFormat3 *iface) { - FIXME("%p.\n", iface); + struct dwrite_textformat *format = impl_from_IDWriteTextFormat3(iface);
- return DWRITE_AUTOMATIC_FONT_AXES_NONE; + TRACE("%p.\n", iface); + + return format->format.automatic_axes; }
static HRESULT WINAPI dwritetextformat3_SetAutomaticFontAxes(IDWriteTextFormat3 *iface, DWRITE_AUTOMATIC_FONT_AXES axes) { - FIXME("%p, %d.\n", iface, axes); + struct dwrite_textformat *format = impl_from_IDWriteTextFormat3(iface);
- return E_NOTIMPL; + TRACE("%p, %d.\n", iface, axes); + + format->format.automatic_axes = axes; + + return S_OK; }
static const IDWriteTextFormat3Vtbl dwritetextformatvtbl = @@ -5948,6 +5970,7 @@ HRESULT create_textformat(const WCHAR *family_name, IDWriteFontCollection *colle This->format.trimmingsign = NULL; This->format.collection = collection; This->format.fallback = NULL; + This->format.automatic_axes = DWRITE_AUTOMATIC_FONT_AXES_NONE; IDWriteFontCollection_AddRef(collection);
*format = (IDWriteTextFormat *)&This->IDWriteTextFormat3_iface; diff --git a/dlls/dwrite/tests/layout.c b/dlls/dwrite/tests/layout.c index 2e309f14b73..beb09f400f9 100644 --- a/dlls/dwrite/tests/layout.c +++ b/dlls/dwrite/tests/layout.c @@ -5732,6 +5732,96 @@ todo_wine { IDWriteFactory_Release(factory); }
+static void test_automatic_font_axes(void) +{ + DWRITE_AUTOMATIC_FONT_AXES axes; + IDWriteTextLayout4 *layout4 = NULL; + IDWriteTextFormat3 *format3; + IDWriteTextLayout *layout; + IDWriteTextFormat *format; + IDWriteFactory *factory; + HRESULT hr; + + factory = create_factory(); + + hr = IDWriteFactory_CreateTextFormat(factory, L"Tahoma", NULL, DWRITE_FONT_WEIGHT_NORMAL, + DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, 16.0f, L"en-us", &format); + ok(hr == S_OK, "Failed to create text format, hr %#x.\n", hr); + + hr = IDWriteFactory_CreateTextLayout(factory, L"a", 1, format, 1000.0f, 1000.0f, &layout); + ok(hr == S_OK, "Failed to create text layout, hr %x.\n", hr); + + IDWriteTextLayout_QueryInterface(layout, &IID_IDWriteTextLayout4, (void **)&layout4); + + IDWriteTextLayout_Release(layout); + + if (!layout4) + { + win_skip("Text layout does not support variable fonts.\n"); + IDWriteFactory_Release(factory); + IDWriteTextFormat_Release(format); + return; + } + + hr = IDWriteTextFormat_QueryInterface(format, &IID_IDWriteTextFormat3, (void **)&format3); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + axes = IDWriteTextFormat3_GetAutomaticFontAxes(format3); + ok(axes == DWRITE_AUTOMATIC_FONT_AXES_NONE, "Unexpected automatic axes %u.\n", axes); + + hr = IDWriteTextFormat3_SetAutomaticFontAxes(format3, DWRITE_AUTOMATIC_FONT_AXES_OPTICAL_SIZE); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IDWriteTextFormat3_SetAutomaticFontAxes(format3, DWRITE_AUTOMATIC_FONT_AXES_OPTICAL_SIZE + 1); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + IDWriteTextFormat3_Release(format3); + + axes = IDWriteTextLayout4_GetAutomaticFontAxes(layout4); + ok(axes == DWRITE_AUTOMATIC_FONT_AXES_NONE, "Unexpected automatic axes %u.\n", axes); + + hr = IDWriteTextLayout4_SetAutomaticFontAxes(layout4, DWRITE_AUTOMATIC_FONT_AXES_OPTICAL_SIZE + 1); + ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr); + + hr = IDWriteTextLayout4_SetAutomaticFontAxes(layout4, DWRITE_AUTOMATIC_FONT_AXES_OPTICAL_SIZE); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + IDWriteTextLayout4_Release(layout4); + + /* Out of range values allow for formats, but not for layouts. */ + hr = IDWriteFactory_CreateTextLayout(factory, L"a", 1, format, 1000.0f, 1000.0f, &layout); + ok(hr == S_OK, "Failed to create text layout, hr %x.\n", hr); + + hr = IDWriteTextLayout_QueryInterface(layout, &IID_IDWriteTextLayout4, (void **)&layout4); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + axes = IDWriteTextLayout4_GetAutomaticFontAxes(layout4); + ok(axes == DWRITE_AUTOMATIC_FONT_AXES_OPTICAL_SIZE + 1, "Unexpected automatic axes %u.\n", axes); + + hr = IDWriteTextLayout4_QueryInterface(layout4, &IID_IDWriteTextFormat3, (void **)&format3); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + axes = IDWriteTextFormat3_GetAutomaticFontAxes(format3); + ok(axes == DWRITE_AUTOMATIC_FONT_AXES_OPTICAL_SIZE + 1, "Unexpected automatic axes %u.\n", axes); + + hr = IDWriteTextLayout4_SetAutomaticFontAxes(layout4, DWRITE_AUTOMATIC_FONT_AXES_OPTICAL_SIZE); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + axes = IDWriteTextFormat3_GetAutomaticFontAxes(format3); + ok(axes == DWRITE_AUTOMATIC_FONT_AXES_OPTICAL_SIZE, "Unexpected automatic axes %u.\n", axes); + + hr = IDWriteTextFormat3_SetAutomaticFontAxes(format3, DWRITE_AUTOMATIC_FONT_AXES_OPTICAL_SIZE + 1); + ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr); + + IDWriteTextFormat3_Release(format3); + + IDWriteTextLayout_Release(layout); + + IDWriteTextLayout4_Release(layout4); + IDWriteTextFormat_Release(format); + IDWriteFactory_Release(factory); +} + START_TEST(layout) { IDWriteFactory *factory; @@ -5783,6 +5873,7 @@ START_TEST(layout) test_line_spacing(); test_GetOverhangMetrics(); test_tab_stops(); + test_automatic_font_axes();
IDWriteFactory_Release(factory); }