[PATCH 3/5 v2] riched20: Call ITextHost_TxGetCharFormat() for setting default charformat.
Huw Davies
huw at codeweavers.com
Wed May 23 03:36:32 CDT 2018
On Tue, May 22, 2018 at 04:32:16PM +0800, Jactry Zeng wrote:
> Superseded patch 146215.
>
> Signed-off-by: Jactry Zeng <jzeng at codeweavers.com>
> ---
> dlls/riched20/para.c | 12 ++++++++++++
> dlls/riched20/tests/txtsrv.c | 46 ++++++++++++++++++++++++++++++++++++++++----
> 2 files changed, 54 insertions(+), 4 deletions(-)
>
> diff --git a/dlls/riched20/para.c b/dlls/riched20/para.c
> index f2a70e5746..e5e1c4be3c 100644
> --- a/dlls/riched20/para.c
> +++ b/dlls/riched20/para.c
> @@ -36,6 +36,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
> {
> ME_Context c;
> CHARFORMAT2W cf;
> + const CHARFORMATW *host_cf;
> LOGFONTW lf;
> HFONT hf;
> ME_TextBuffer *text = editor->pBuffer;
> @@ -44,6 +45,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
> ME_Style *style;
> int eol_len;
> WCHAR cr_lf[] = {'\r','\n',0};
> + HRESULT hr;
>
> ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
>
> @@ -73,6 +75,16 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
> cf.bCharSet = lf.lfCharSet;
> cf.lcid = GetSystemDefaultLCID();
>
> + /* replace some default charformat setting with charformat from host */
> + hr = ITextHost_TxGetCharFormat(editor->texthost, (const CHARFORMATW **)&host_cf);
> + if (hr == S_OK)
> + {
> + if (host_cf->dwMask & CFM_FACE)
> + lstrcpyW(cf.szFaceName, host_cf->szFaceName);
> + if (host_cf->dwMask & CFM_SIZE)
> + cf.yHeight = host_cf->yHeight;
Does this really only use CFM_FACE and CFM_SIZE? I'd expect a full merge of
char formats.
> + }
> +
> style = ME_MakeStyle(&cf);
> text->pDefaultStyle = style;
>
> diff --git a/dlls/riched20/tests/txtsrv.c b/dlls/riched20/tests/txtsrv.c
> index 8893fa6bf5..d6c888629a 100644
> --- a/dlls/riched20/tests/txtsrv.c
> +++ b/dlls/riched20/tests/txtsrv.c
> @@ -85,6 +85,7 @@ typedef struct ITextHostTestImpl
> {
> ITextHost ITextHost_iface;
> LONG refCount;
> + CHARFORMATW char_format;
> } ITextHostTestImpl;
>
> static inline ITextHostTestImpl *impl_from_ITextHost(ITextHost *iface)
> @@ -330,7 +331,8 @@ static HRESULT WINAPI ITextHostImpl_TxGetCharFormat(ITextHost *iface,
> {
> ITextHostTestImpl *This = impl_from_ITextHost(iface);
> TRACECALL("Call to TxGetCharFormat(%p, ppCF=%p)\n", This, ppCF);
> - return E_NOTIMPL;
> + *ppCF = &This->char_format;
> + return S_OK;
> }
>
> static HRESULT WINAPI ITextHostImpl_TxGetParaFormat(ITextHost *iface,
> @@ -609,6 +611,8 @@ static BOOL init_texthost(ITextServices **txtserv, ITextHost **ret)
> ITextHostTestImpl *dummyTextHost;
> IUnknown *init;
> HRESULT result;
> + LOGFONTW lf;
> + HFONT hf;
>
> dummyTextHost = CoTaskMemAlloc(sizeof(*dummyTextHost));
> if (dummyTextHost == NULL) {
> @@ -617,6 +621,13 @@ static BOOL init_texthost(ITextServices **txtserv, ITextHost **ret)
> }
> dummyTextHost->ITextHost_iface.lpVtbl = &itextHostVtbl;
> dummyTextHost->refCount = 1;
> + memset(&dummyTextHost->char_format, 0, sizeof(dummyTextHost->char_format));
> + dummyTextHost->char_format.cbSize = sizeof(dummyTextHost->char_format);
> + dummyTextHost->char_format.dwMask = CFM_FACE | CFM_SIZE;
> + hf = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
> + GetObjectW(hf, sizeof(LOGFONTW), &lf);
> + lstrcpyW(dummyTextHost->char_format.szFaceName, lf.lfFaceName);
> + dummyTextHost->char_format.yHeight = MulDiv(abs(lf.lfHeight), 1440, GetDeviceCaps(GetDC(NULL), LOGPIXELSY));
>
> /* MSDN states that an IUnknown object is returned by
> CreateTextServices which is then queried to obtain a
> @@ -706,8 +717,7 @@ static void _check_txgetnaturalsize(HRESULT res, LONG width, LONG height, LONG m
> ok_(__FILE__,line)(width >= min_width && width <= max_width,
> "got wrong width: %d, expected: %d <= width <= %d.\n",
> width, min_width, max_width);
> - ok_(__FILE__,line)(height == expected_height ||
> - height == 18 /* Japanese win7 */, "got wrong height: %d, expected: %d.\n",
> + ok_(__FILE__,line)(height == expected_height, "got wrong height: %d, expected: %d.\n",
> height, expected_height);
> }
>
> @@ -752,7 +762,7 @@ static void test_TxGetNaturalSize(void)
> win_skip("ITextServices_TxGetNaturalSize isn't available on this platform.\n");
> goto cleanup;
> }
> - todo_wine CHECK_TXGETNATURALSIZE(result, width, height, 95, 74, 16);
> + todo_wine CHECK_TXGETNATURALSIZE(result, width, height, 83, 70, 13);
>
> cleanup:
> ReleaseDC(NULL,hdcDraw);
> @@ -935,6 +945,33 @@ static void test_QueryInterface(void)
> ITextHost_Release(host);
> }
>
> +static void test_default_format(void)
> +{
> + ITextServices *txtserv;
> + ITextHost *host;
> + HRESULT result;
> + LRESULT lresult;
> + CHARFORMAT2W cf2;
> + HFONT hf;
> + LOGFONTW lf;
> + LONG expected_height;
> +
> + if (!init_texthost(&txtserv, &host))
> + return;
> +
> + cf2.cbSize = sizeof(CHARFORMAT2W);
> + result = ITextServices_TxSendMessage(txtserv, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf2, &lresult);
> + ok(result == S_OK, "ITextServices_TxSendMessage failed: 0x%08x.\n", result);
> + hf = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
> + GetObjectW(hf, sizeof(LOGFONTW), &lf);
> + expected_height = MulDiv(abs(lf.lfHeight), 1440, GetDeviceCaps(GetDC(NULL), LOGPIXELSY));
> + ok(!lstrcmpW(lf.lfFaceName, cf2.szFaceName), "got wrong font name: %s.\n", wine_dbgstr_w(cf2.szFaceName));
> + ok(cf2.yHeight == expected_height, "got wrong yHeight: %d, expetced %d.\n", cf2.yHeight, expected_height);
> +
> + ITextServices_Release(txtserv);
> + ITextHost_Release(host);
> +}
> +
> START_TEST( txtsrv )
> {
> ITextServices *txtserv;
> @@ -965,6 +1002,7 @@ START_TEST( txtsrv )
> test_TxGetNaturalSize();
> test_TxDraw();
> test_QueryInterface();
> + test_default_format();
> }
> if (wrapperCodeMem) VirtualFree(wrapperCodeMem, 0, MEM_RELEASE);
> }
> --
> 2.15.1 (Apple Git-101)
>
>
>
>
More information about the wine-devel
mailing list