[PATCH 1/2] riched20: Add a helper for merging two CHARFORMAT2W.

Jactry Zeng jzeng at codeweavers.com
Tue Jul 17 07:42:26 CDT 2018


Signed-off-by: Jactry Zeng <jzeng at codeweavers.com>
---
 dlls/riched20/editor.h |  1 +
 dlls/riched20/style.c  | 69 +++++++++++++++++++++++-------------------
 2 files changed, 39 insertions(+), 31 deletions(-)

diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 141c63aca9..35168bcdfb 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -61,6 +61,7 @@ void ME_SaveTempStyle(ME_TextEditor *editor, ME_Style *style) DECLSPEC_HIDDEN;
 void ME_ClearTempStyle(ME_TextEditor *editor) DECLSPEC_HIDDEN;
 void ME_DumpStyleToBuf(CHARFORMAT2W *pFmt, char buf[2048]) DECLSPEC_HIDDEN;
 void ME_DumpStyle(ME_Style *s) DECLSPEC_HIDDEN;
+void merge_cf2w(CHARFORMAT2W *to, const CHARFORMAT2W *from) DECLSPEC_HIDDEN;
 BOOL cfany_to_cf2w(CHARFORMAT2W *to, const CHARFORMAT2W *from) DECLSPEC_HIDDEN;
 BOOL cf2w_to_cfany(CHARFORMAT2W *to, const CHARFORMAT2W *from) DECLSPEC_HIDDEN;
 void ME_CopyCharFormat(CHARFORMAT2W *pDest, const CHARFORMAT2W *pSrc) DECLSPEC_HIDDEN; /* only works with 2W structs */
diff --git a/dlls/riched20/style.c b/dlls/riched20/style.c
index 97e98a7a14..43c12c53e5 100644
--- a/dlls/riched20/style.c
+++ b/dlls/riched20/style.c
@@ -132,15 +132,15 @@ ME_Style *ME_MakeStyle(CHARFORMAT2W *style)
 }
 
 #define COPY_STYLE_ITEM(mask, member) \
-  if (mod->dwMask & mask) { \
-    fmt.dwMask |= mask;\
-    fmt.member = mod->member;\
+  if (from->dwMask & mask) { \
+    to->dwMask |= mask; \
+    to->member = from->member; \
   }
 
 #define COPY_STYLE_ITEM_MEMCPY(mask, member) \
-  if (mod->dwMask & mask) { \
-    fmt.dwMask |= mask;\
-    CopyMemory(fmt.member, mod->member, sizeof(mod->member));\
+  if (from->dwMask & mask) { \
+    to->dwMask |= mask; \
+    CopyMemory(to->member, from->member, sizeof(from->member)); \
   }
 
 void ME_InitCharFormat2W(CHARFORMAT2W *pFmt)
@@ -149,12 +149,11 @@ void ME_InitCharFormat2W(CHARFORMAT2W *pFmt)
   pFmt->cbSize = sizeof(CHARFORMAT2W);
 }
 
-ME_Style *ME_ApplyStyle(ME_TextEditor *editor, ME_Style *sSrc, CHARFORMAT2W *mod)
+void merge_cf2w(CHARFORMAT2W *to, const CHARFORMAT2W *from)
 {
-  CHARFORMAT2W fmt = sSrc->fmt;
-  ME_Style *s;
+  assert(to->cbSize == sizeof(CHARFORMAT2W));
+  assert(from->cbSize == sizeof(CHARFORMAT2W));
 
-  assert(mod->cbSize == sizeof(CHARFORMAT2W));
   COPY_STYLE_ITEM(CFM_ANIMATION, bAnimation);
   COPY_STYLE_ITEM(CFM_BACKCOLOR, crBackColor);
   COPY_STYLE_ITEM(CFM_CHARSET, bCharSet);
@@ -164,9 +163,9 @@ ME_Style *ME_ApplyStyle(ME_TextEditor *editor, ME_Style *sSrc, CHARFORMAT2W *mod
   COPY_STYLE_ITEM(CFM_LCID, lcid);
   COPY_STYLE_ITEM(CFM_OFFSET, yOffset);
   COPY_STYLE_ITEM(CFM_REVAUTHOR, bRevAuthor);
-  if (mod->dwMask & CFM_SIZE) {
-    fmt.dwMask |= CFM_SIZE;
-    fmt.yHeight = min(mod->yHeight, yHeightCharPtsMost * 20);
+  if (from->dwMask & CFM_SIZE) {
+    to->dwMask |= CFM_SIZE;
+    to->yHeight = min(from->yHeight, yHeightCharPtsMost * 20);
   }
   COPY_STYLE_ITEM(CFM_SPACING, sSpacing);
   COPY_STYLE_ITEM(CFM_STYLE, sStyle);
@@ -174,37 +173,45 @@ ME_Style *ME_ApplyStyle(ME_TextEditor *editor, ME_Style *sSrc, CHARFORMAT2W *mod
   /* FIXME: this is not documented this way, but that's the more logical */
   COPY_STYLE_ITEM(CFM_FACE, bPitchAndFamily);
 
-  fmt.dwEffects &= ~(mod->dwMask);
-  fmt.dwEffects |= mod->dwEffects & mod->dwMask;
-  fmt.dwMask |= mod->dwMask;
-  if (mod->dwMask & CFM_COLOR)
+  to->dwEffects &= ~(from->dwMask);
+  to->dwEffects |= from->dwEffects & from->dwMask;
+  to->dwMask |= from->dwMask;
+  if (from->dwMask & CFM_COLOR)
   {
-    if (mod->dwEffects & CFE_AUTOCOLOR)
-      fmt.dwEffects |= CFE_AUTOCOLOR;
+    if (from->dwEffects & CFE_AUTOCOLOR)
+      to->dwEffects |= CFE_AUTOCOLOR;
     else
-      fmt.dwEffects &= ~CFE_AUTOCOLOR;
+      to->dwEffects &= ~CFE_AUTOCOLOR;
   }
 
   COPY_STYLE_ITEM(CFM_UNDERLINETYPE, bUnderlineType);
   /* If the CFM_UNDERLINE effect is not specified, set it appropriately */
-  if ((mod->dwMask & CFM_UNDERLINETYPE) && !(mod->dwMask & CFM_UNDERLINE))
+  if ((from->dwMask & CFM_UNDERLINETYPE) && !(from->dwMask & CFM_UNDERLINE))
   {
-      fmt.dwMask |= CFM_UNDERLINE;
-      if (mod->bUnderlineType == CFU_UNDERLINENONE)
-          fmt.dwEffects &= ~CFE_UNDERLINE;
+      to->dwMask |= CFM_UNDERLINE;
+      if (from->bUnderlineType == CFU_UNDERLINENONE)
+          to->dwEffects &= ~CFE_UNDERLINE;
       else
-          fmt.dwEffects |= CFE_UNDERLINE;
+          to->dwEffects |= CFE_UNDERLINE;
   }
 
-  if (mod->dwMask & CFM_BOLD && !(mod->dwMask & CFM_WEIGHT))
+  if (from->dwMask & CFM_BOLD && !(from->dwMask & CFM_WEIGHT))
   {
-      fmt.wWeight = (mod->dwEffects & CFE_BOLD) ? FW_BOLD : FW_NORMAL;
-  } else if (mod->dwMask & CFM_WEIGHT && !(mod->dwMask & CFM_BOLD)) {
-      if (mod->wWeight > FW_NORMAL)
-          fmt.dwEffects |= CFE_BOLD;
+      to->wWeight = (from->dwEffects & CFE_BOLD) ? FW_BOLD : FW_NORMAL;
+  } else if (from->dwMask & CFM_WEIGHT && !(from->dwMask & CFM_BOLD)) {
+      if (from->wWeight > FW_NORMAL)
+          to->dwEffects |= CFE_BOLD;
       else
-          fmt.dwEffects &= ~CFE_BOLD;
+          to->dwEffects &= ~CFE_BOLD;
   }
+}
+
+ME_Style *ME_ApplyStyle(ME_TextEditor *editor, ME_Style *sSrc, CHARFORMAT2W *mod)
+{
+  CHARFORMAT2W fmt = sSrc->fmt;
+  ME_Style *s;
+
+  merge_cf2w(&fmt, mod);
 
   LIST_FOR_EACH_ENTRY(s, &editor->style_list, ME_Style, entry)
   {
-- 
2.18.0





More information about the wine-devel mailing list