Module: wine Branch: master Commit: de46f610fe61ed5f1ff99908682d33a32e8c9f82 URL: http://source.winehq.org/git/wine.git/?a=commit;h=de46f610fe61ed5f1ff9990868...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Mon Jul 6 09:05:10 2015 +0300
dwrite: Make it possible to set text alignment on created layout.
---
dlls/dwrite/layout.c | 22 ++++++++--------- dlls/dwrite/tests/layout.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 11 deletions(-)
diff --git a/dlls/dwrite/layout.c b/dlls/dwrite/layout.c index 693f046..13a9ce0 100644 --- a/dlls/dwrite/layout.c +++ b/dlls/dwrite/layout.c @@ -328,6 +328,14 @@ static inline const char *debugstr_run(const struct regular_layout_run *run) run->descr.stringLength); }
+static inline HRESULT format_set_textalignment(struct dwrite_textformat_data *format, DWRITE_TEXT_ALIGNMENT alignment) +{ + if ((UINT32)alignment > DWRITE_TEXT_ALIGNMENT_JUSTIFIED) + return E_INVALIDARG; + format->textalignment = alignment; + return S_OK; +} + static HRESULT get_fontfallback_from_format(const struct dwrite_textformat_data *format, IDWriteFontFallback **fallback) { *fallback = format->fallback; @@ -1955,7 +1963,6 @@ static ULONG WINAPI dwritetextlayout_Release(IDWriteTextLayout2 *iface) static HRESULT WINAPI dwritetextlayout_SetTextAlignment(IDWriteTextLayout2 *iface, DWRITE_TEXT_ALIGNMENT alignment) { struct dwrite_textlayout *This = impl_from_IDWriteTextLayout2(iface); - TRACE("(%p)->(%d)\n", This, alignment); return IDWriteTextFormat1_SetTextAlignment(&This->IDWriteTextFormat1_iface, alignment); }
@@ -2013,7 +2020,6 @@ static HRESULT WINAPI dwritetextlayout_SetLineSpacing(IDWriteTextLayout2 *iface, static DWRITE_TEXT_ALIGNMENT WINAPI dwritetextlayout_GetTextAlignment(IDWriteTextLayout2 *iface) { struct dwrite_textlayout *This = impl_from_IDWriteTextLayout2(iface); - TRACE("(%p)\n", This); return IDWriteTextFormat1_GetTextAlignment(&This->IDWriteTextFormat1_iface); }
@@ -2972,8 +2978,8 @@ static ULONG WINAPI dwritetextformat1_layout_Release(IDWriteTextFormat1 *iface) static HRESULT WINAPI dwritetextformat1_layout_SetTextAlignment(IDWriteTextFormat1 *iface, DWRITE_TEXT_ALIGNMENT alignment) { struct dwrite_textlayout *This = impl_layout_form_IDWriteTextFormat1(iface); - FIXME("(%p)->(%d): stub\n", This, alignment); - return E_NOTIMPL; + TRACE("(%p)->(%d)\n", This, alignment); + return format_set_textalignment(&This->format, alignment); }
static HRESULT WINAPI dwritetextformat1_layout_SetParagraphAlignment(IDWriteTextFormat1 *iface, DWRITE_PARAGRAPH_ALIGNMENT alignment) @@ -3846,14 +3852,8 @@ static ULONG WINAPI dwritetextformat_Release(IDWriteTextFormat1 *iface) static HRESULT WINAPI dwritetextformat_SetTextAlignment(IDWriteTextFormat1 *iface, DWRITE_TEXT_ALIGNMENT alignment) { struct dwrite_textformat *This = impl_from_IDWriteTextFormat1(iface); - TRACE("(%p)->(%d)\n", This, alignment); - - if ((UINT32)alignment > DWRITE_TEXT_ALIGNMENT_JUSTIFIED) - return E_INVALIDARG; - - This->format.textalignment = alignment; - return S_OK; + return format_set_textalignment(&This->format, alignment); }
static HRESULT WINAPI dwritetextformat_SetParagraphAlignment(IDWriteTextFormat1 *iface, DWRITE_PARAGRAPH_ALIGNMENT alignment) diff --git a/dlls/dwrite/tests/layout.c b/dlls/dwrite/tests/layout.c index eee86a9..57d3a34 100644 --- a/dlls/dwrite/tests/layout.c +++ b/dlls/dwrite/tests/layout.c @@ -2863,6 +2863,65 @@ todo_wine { IDWriteFactory_Release(factory); }
+static void test_SetTextAlignment(void) +{ + static const WCHAR strW[] = {'a','b','c','d',0}; + IDWriteTextFormat1 *format1; + IDWriteTextFormat *format; + IDWriteTextLayout *layout; + IDWriteFactory *factory; + DWRITE_TEXT_ALIGNMENT v; + HRESULT hr; + + factory = create_factory(); + + hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, + DWRITE_FONT_STRETCH_NORMAL, 12.0, enusW, &format); + ok(hr == S_OK, "got 0x%08x\n", hr); + + v = IDWriteTextFormat_GetTextAlignment(format); + ok(v == DWRITE_TEXT_ALIGNMENT_LEADING, "got %d\n", v); + + hr = IDWriteFactory_CreateTextLayout(factory, strW, 4, format, 300.0, 100.0, &layout); + ok(hr == S_OK, "got 0x%08x\n", hr); + + v = IDWriteTextLayout_GetTextAlignment(layout); + ok(v == DWRITE_TEXT_ALIGNMENT_LEADING, "got %d\n", v); + + hr = IDWriteTextLayout_SetTextAlignment(layout, DWRITE_TEXT_ALIGNMENT_TRAILING); + ok(hr == S_OK, "got 0x%08x\n", hr); + + v = IDWriteTextFormat_GetTextAlignment(format); + ok(v == DWRITE_TEXT_ALIGNMENT_LEADING, "got %d\n", v); + + v = IDWriteTextLayout_GetTextAlignment(layout); + ok(v == DWRITE_TEXT_ALIGNMENT_TRAILING, "got %d\n", v); + + hr = IDWriteTextLayout_QueryInterface(layout, &IID_IDWriteTextFormat1, (void**)&format1); + if (hr == S_OK) { + hr = IDWriteTextFormat1_SetTextAlignment(format1, DWRITE_TEXT_ALIGNMENT_CENTER); + ok(hr == S_OK, "got 0x%08x\n", hr); + + v = IDWriteTextFormat_GetTextAlignment(format); + ok(v == DWRITE_TEXT_ALIGNMENT_LEADING, "got %d\n", v); + + v = IDWriteTextLayout_GetTextAlignment(layout); + ok(v == DWRITE_TEXT_ALIGNMENT_CENTER, "got %d\n", v); + + v = IDWriteTextFormat1_GetTextAlignment(format1); + ok(v == DWRITE_TEXT_ALIGNMENT_CENTER, "got %d\n", v); + + IDWriteTextFormat1_Release(format1); + } + else + win_skip("IDWriteTextFormat1 is not supported\n"); + + + IDWriteTextLayout_Release(layout); + IDWriteTextFormat_Release(format); + IDWriteFactory_Release(factory); +} + START_TEST(layout) { static const WCHAR ctrlstrW[] = {0x202a,0}; @@ -2903,6 +2962,7 @@ START_TEST(layout) test_SetFlowDirection(); test_SetDrawingEffect(); test_GetLineMetrics(); + test_SetTextAlignment();
IDWriteFactory_Release(factory); }