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

Jactry Zeng jzeng at codeweavers.com
Mon May 28 23:12:17 CDT 2018


Signed-off-by: Jactry Zeng <jzeng at codeweavers.com>
---
 dlls/riched20/para.c         |  5 ++++
 dlls/riched20/tests/txtsrv.c | 59 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/dlls/riched20/para.c b/dlls/riched20/para.c
index f2a70e5746..2a702a869a 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)
+    ME_ToCF2W(&cf, (CHARFORMAT2W *)host_cf);
   style = ME_MakeStyle(&cf);
   text->pDefaultStyle = style;
 
diff --git a/dlls/riched20/tests/txtsrv.c b/dlls/riched20/tests/txtsrv.c
index 76b4eb34f6..f97cd39d18 100644
--- a/dlls/riched20/tests/txtsrv.c
+++ b/dlls/riched20/tests/txtsrv.c
@@ -86,6 +86,7 @@ typedef struct ITextHostTestImpl
 {
     ITextHost ITextHost_iface;
     LONG refCount;
+    CHARFORMATW char_format;
 } ITextHostTestImpl;
 
 static inline ITextHostTestImpl *impl_from_ITextHost(ITextHost *iface)
@@ -331,7 +332,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,
@@ -610,6 +612,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) {
@@ -618,6 +622,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);
+    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;
 
     /* MSDN states that an IUnknown object is returned by
        CreateTextServices which is then queried to obtain a
@@ -1011,6 +1028,45 @@ 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);
+    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;
@@ -1041,6 +1097,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