[3/3 v5] riched20: Call ITextHost_TxGetCharFormat() for setting default charformat.

Jactry Zeng jzeng at codeweavers.com
Fri Jul 13 04:11:42 CDT 2018


Signed-off-by: Jactry Zeng <jzeng at codeweavers.com>
---
 dlls/riched20/para.c         | 45 +++++++++++++++++++++---------------
 dlls/riched20/tests/txtsrv.c | 41 +++++++++++++++++++++++++++++++-
 2 files changed, 66 insertions(+), 20 deletions(-)

diff --git a/dlls/riched20/para.c b/dlls/riched20/para.c
index f2a70e5746..0327d1cf8d 100644
--- a/dlls/riched20/para.c
+++ b/dlls/riched20/para.c
@@ -36,8 +36,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
 {
   ME_Context c;
   CHARFORMAT2W cf;
-  LOGFONTW lf;
-  HFONT hf;
+  CHARFORMATW *host_cf;
   ME_TextBuffer *text = editor->pBuffer;
   ME_DisplayItem *para = make_para(editor);
   ME_DisplayItem *run;
@@ -47,31 +46,39 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
 
   ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
 
-  hf = GetStockObject(SYSTEM_FONT);
-  assert(hf);
-  GetObjectW(hf, sizeof(LOGFONTW), &lf);
   ZeroMemory(&cf, sizeof(cf));
   cf.cbSize = sizeof(cf);
+
+  if (ITextHost_TxGetCharFormat(editor->texthost, (const CHARFORMATW **)&host_cf) == S_OK)
+    cfany_to_cf2w(&cf, (CHARFORMAT2W *)host_cf);
+  else
+  {
+    HFONT hf;
+    LOGFONTW lf;
+
+    hf = GetStockObject(SYSTEM_FONT);
+    assert(hf);
+    GetObjectW(hf, sizeof(LOGFONTW), &lf);
+    lstrcpyW(cf.szFaceName, lf.lfFaceName);
+    /* Convert system font height from logical units to twips for cf.yHeight */
+    cf.yHeight = (lf.lfHeight * 72 * 1440) / (c.dpi.cy * c.dpi.cy);
+    if (lf.lfWeight > FW_NORMAL) cf.dwEffects |= CFE_BOLD;
+    cf.wWeight = lf.lfWeight;
+    if (lf.lfItalic) cf.dwEffects |= CFE_ITALIC;
+    if (lf.lfUnderline) cf.dwEffects |= CFE_UNDERLINE;
+    cf.bUnderlineType = CFU_UNDERLINE;
+    if (lf.lfStrikeOut) cf.dwEffects |= CFE_STRIKEOUT;
+    cf.bPitchAndFamily = lf.lfPitchAndFamily;
+    cf.bCharSet = lf.lfCharSet;
+    cf.lcid = GetSystemDefaultLCID();
+  }
   cf.dwMask = CFM_ANIMATION|CFM_BACKCOLOR|CFM_CHARSET|CFM_COLOR|CFM_FACE|CFM_KERNING|CFM_LCID|CFM_OFFSET;
   cf.dwMask |= CFM_REVAUTHOR|CFM_SIZE|CFM_SPACING|CFM_STYLE|CFM_UNDERLINETYPE|CFM_WEIGHT;
   cf.dwMask |= CFM_ALLCAPS|CFM_BOLD|CFM_DISABLED|CFM_EMBOSS|CFM_HIDDEN;
   cf.dwMask |= CFM_IMPRINT|CFM_ITALIC|CFM_LINK|CFM_OUTLINE|CFM_PROTECTED;
   cf.dwMask |= CFM_REVISED|CFM_SHADOW|CFM_SMALLCAPS|CFM_STRIKEOUT;
   cf.dwMask |= CFM_SUBSCRIPT|CFM_UNDERLINE;
-  
-  cf.dwEffects = CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR;
-  lstrcpyW(cf.szFaceName, lf.lfFaceName);
-  /* Convert system font height from logical units to twips for cf.yHeight */
-  cf.yHeight = (lf.lfHeight * 72 * 1440) / (c.dpi.cy * c.dpi.cy);
-  if (lf.lfWeight > FW_NORMAL) cf.dwEffects |= CFE_BOLD;
-  cf.wWeight = lf.lfWeight;
-  if (lf.lfItalic) cf.dwEffects |= CFE_ITALIC;
-  if (lf.lfUnderline) cf.dwEffects |= CFE_UNDERLINE;
-  cf.bUnderlineType = CFU_UNDERLINE;
-  if (lf.lfStrikeOut) cf.dwEffects |= CFE_STRIKEOUT;
-  cf.bPitchAndFamily = lf.lfPitchAndFamily;
-  cf.bCharSet = lf.lfCharSet;
-  cf.lcid = GetSystemDefaultLCID();
+  cf.dwEffects |= CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR;
 
   style = ME_MakeStyle(&cf);
   text->pDefaultStyle = style;
diff --git a/dlls/riched20/tests/txtsrv.c b/dlls/riched20/tests/txtsrv.c
index 5d312ca2cd..9d3fc361d6 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;
+    CHARFORMAT2W 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 = (CHARFORMATW *)&This->char_format;
+    return S_OK;
 }
 
 static HRESULT WINAPI ITextHostImpl_TxGetParaFormat(ITextHost *iface,
@@ -624,6 +626,7 @@ static BOOL init_texthost(ITextServices **txtserv, ITextHost **ret)
     ITextHostTestImpl *dummyTextHost;
     IUnknown *init;
     HRESULT result;
+    HFONT hf;
 
     dummyTextHost = CoTaskMemAlloc(sizeof(*dummyTextHost));
     if (dummyTextHost == NULL) {
@@ -632,6 +635,11 @@ 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_ALL2;
+    hf = GetStockObject(DEFAULT_GUI_FONT);
+    hf_to_cf(hf, &dummyTextHost->char_format);
 
     /* MSDN states that an IUnknown object is returned by
        CreateTextServices which is then queried to obtain a
@@ -952,6 +960,36 @@ static void test_QueryInterface(void)
     ITextHost_Release(host);
 }
 
+static void test_default_format(void)
+{
+    ITextServices *txtserv;
+    ITextHost *host;
+    HRESULT result;
+    LRESULT lresult;
+    CHARFORMAT2W cf2;
+    CHARFORMATW *host_cf;
+    DWORD expected_effects;
+
+    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);
+
+    ITextHostImpl_TxGetCharFormat(host, (const CHARFORMATW **)&host_cf);
+    ok(!lstrcmpW(host_cf->szFaceName, cf2.szFaceName), "got wrong font name: %s.\n", wine_dbgstr_w(cf2.szFaceName));
+    ok(cf2.yHeight == host_cf->yHeight, "got wrong yHeight: %d, expetced %d.\n", cf2.yHeight, host_cf->yHeight);
+    expected_effects = (cf2.dwEffects & ~(CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR));
+    ok(host_cf->dwEffects == expected_effects , "got wrong dwEffects: %x, expetced %x.\n", cf2.dwEffects, expected_effects);
+    ok(cf2.bPitchAndFamily == host_cf->bPitchAndFamily, "got wrong bPitchAndFamily: %x, expected %x.\n",
+       cf2.bPitchAndFamily, host_cf->bPitchAndFamily);
+    ok(cf2.bCharSet == host_cf->bCharSet, "got wrong bCharSet: %x, expected %x.\n", cf2.bCharSet, host_cf->bCharSet);
+
+    ITextServices_Release(txtserv);
+    ITextHost_Release(host);
+}
+
 START_TEST( txtsrv )
 {
     ITextServices *txtserv;
@@ -982,6 +1020,7 @@ START_TEST( txtsrv )
         test_TxGetNaturalSize();
         test_TxDraw();
         test_QueryInterface();
+        test_default_format();
     }
     if (wrapperCodeMem) VirtualFree(wrapperCodeMem, 0, MEM_RELEASE);
 }
-- 
2.18.0




More information about the wine-devel mailing list