[PATCH 2/4 v5] riched20: Call ITextHost_TxGetCharFormat() for setting default charformat.

Huw Davies huw at codeweavers.com
Thu Jun 7 04:29:22 CDT 2018


On Wed, Jun 06, 2018 at 05:24:22PM +0800, Jactry Zeng wrote:
> Superseded patch 146571.
> 
> ChangeLog:
> v5:
> - Remove an unnecessary newline.
>  
> Signed-off-by: Jactry Zeng <jzeng at codeweavers.com>
> ---
>  dlls/riched20/para.c         |  5 ++++
>  dlls/riched20/tests/txtsrv.c | 58 +++++++++++++++++++++++++++++++++++-
>  2 files changed, 62 insertions(+), 1 deletion(-)
> 
> diff --git a/dlls/riched20/para.c b/dlls/riched20/para.c
> index f2a70e5746..ffb017c123 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,9 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
>    cf.bCharSet = lf.lfCharSet;
>    cf.lcid = GetSystemDefaultLCID();
>  
> +  hr = ITextHost_TxGetCharFormat(editor->texthost, (const CHARFORMATW **)&host_cf);
> +  if (hr == S_OK && (host_cf->cbSize >= sizeof(CHARFORMATW)))
> +    ME_ToCF2W(&cf, (CHARFORMAT2W *)host_cf);

Hmm, you need to use the return value of ME_ToCF2W() is this case.

However, ME_ToCF2W() and ME_ToCFAny() should be cleaned up.  They
should both do the copy even if the from argument is of the
correct type (basically what ME_CopyToCFAny() does).

Something like:

BOOL cfany_to_cf2w(CHARFORMAT2W *dst, const *CHARFORMAT2W *src);
BOOL cf2w_to_cfany(CHARFORMAT2W *dst, const *CHARFORMAT2W *src);


>    style = ME_MakeStyle(&cf);
>    text->pDefaultStyle = style;
>  
> diff --git a/dlls/riched20/tests/txtsrv.c b/dlls/riched20/tests/txtsrv.c
> index 6e61392dc5..ac06aa868e 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,19 @@ 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 | CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT;
> +    hf = (HFONT)GetStockObject(DEFAULT_GUI_FONT);

No cast.

> +    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));
> +    if (lf.lfWeight > FW_NORMAL) dummyTextHost->char_format.dwEffects |= CFE_BOLD;
> +    if (lf.lfItalic) dummyTextHost->char_format.dwEffects |= CFE_ITALIC;
> +    if (lf.lfUnderline) dummyTextHost->char_format.dwEffects |= CFE_UNDERLINE;
> +    if (lf.lfStrikeOut) dummyTextHost->char_format.dwEffects |= CFE_SUBSCRIPT;
> +    dummyTextHost->char_format.bPitchAndFamily = lf.lfPitchAndFamily;
> +    dummyTextHost->char_format.bCharSet = lf.lfCharSet;
 
You do the same thing in the previous patch, so this should be a
helper function.

>      /* MSDN states that an IUnknown object is returned by
>         CreateTextServices which is then queried to obtain a
> @@ -947,6 +964,44 @@ 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);

Rather than getting the font here, why not call ITextHost_GetCharFormat() ?

> +    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);
> +    if (lf.lfWeight > FW_NORMAL)
> +        ok(cf2.dwEffects & CFE_BOLD, "got dwEffects without CFE_BOLD: %x.\n", cf2.dwEffects);
> +    if (lf.lfItalic)
> +        ok(cf2.dwEffects & CFE_ITALIC, "got dwEffects without CFE_ITALIC: %x.\n", cf2.dwEffects);
> +    if (lf.lfUnderline)
> +        ok(cf2.dwEffects & CFE_UNDERLINE, "got dwEffects without CFE_UNDERLINE: %x.\n", cf2.dwEffects);
> +    if (lf.lfStrikeOut)
> +        ok(cf2.dwEffects & CFE_STRIKEOUT, "got dwEffects without CFE_STRIKEOUT: %x.\n", cf2.dwEffects);
> +    ok(cf2.bPitchAndFamily == lf.lfPitchAndFamily, "got wrong bPitchAndFamily: %x, expected %x.\n",
> +       cf2.bPitchAndFamily, lf.lfPitchAndFamily);
> +    ok(cf2.bCharSet == lf.lfCharSet, "got wrong bCharSet: %x, expected %x.\n", cf2.bCharSet, lf.lfCharSet);
> +
> +    ITextServices_Release(txtserv);
> +    ITextHost_Release(host);
> +}
> +
>  START_TEST( txtsrv )
>  {
>      ITextServices *txtserv;
> @@ -977,6 +1032,7 @@ START_TEST( txtsrv )
>          test_TxGetNaturalSize();
>          test_TxDraw();
>          test_QueryInterface();
> +        test_default_format();
>      }
>      if (wrapperCodeMem) VirtualFree(wrapperCodeMem, 0, MEM_RELEASE);
>  }
> -- 
> 2.17.1
> 
> 
> 
> 



More information about the wine-devel mailing list