Huw Davies : riched20: Add a helper to add a colour to the colour table.

Alexandre Julliard julliard at winehq.org
Tue Oct 11 15:21:10 CDT 2016


Module: wine
Branch: master
Commit: b8e55779fe26846bebd034744a5a02fa40b98ca7
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=b8e55779fe26846bebd034744a5a02fa40b98ca7

Author: Huw Davies <huw at codeweavers.com>
Date:   Tue Oct 11 13:04:03 2016 +0100

riched20: Add a helper to add a colour to the colour table.

Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/riched20/writer.c | 54 +++++++++++++++++++-------------------------------
 1 file changed, 20 insertions(+), 34 deletions(-)

diff --git a/dlls/riched20/writer.c b/dlls/riched20/writer.c
index b448f43..e79aacf 100644
--- a/dlls/riched20/writer.c
+++ b/dlls/riched20/writer.c
@@ -237,6 +237,21 @@ static void add_font_to_fonttbl( ME_OutStream *stream, ME_Style *style )
     }
 }
 
+static void add_color_to_colortbl( ME_OutStream *stream, COLORREF color )
+{
+    int i;
+
+    for (i = 1; i < stream->nColorTblLen; i++)
+        if (stream->colortbl[i] == color)
+            break;
+
+    if (i == stream->nColorTblLen && i < STREAMOUT_COLORTBL_SIZE)
+    {
+        stream->colortbl[i] = color;
+        stream->nColorTblLen++;
+    }
+}
+
 static BOOL
 ME_StreamOutRTFFontAndColorTbl(ME_OutStream *pStream, ME_DisplayItem *pFirstRun,
                                ME_DisplayItem *pLastRun)
@@ -249,30 +264,13 @@ ME_StreamOutRTFFontAndColorTbl(ME_OutStream *pStream, ME_DisplayItem *pFirstRun,
 
   do {
     CHARFORMAT2W *fmt = &item->member.run.style->fmt;
-    COLORREF crColor;
 
     add_font_to_fonttbl( pStream, item->member.run.style );
 
-    if (fmt->dwMask & CFM_COLOR && !(fmt->dwEffects & CFE_AUTOCOLOR)) {
-      crColor = fmt->crTextColor;
-      for (i = 1; i < pStream->nColorTblLen; i++)
-        if (pStream->colortbl[i] == crColor)
-          break;
-      if (i == pStream->nColorTblLen && i < STREAMOUT_COLORTBL_SIZE) {
-        pStream->colortbl[i] = crColor;
-        pStream->nColorTblLen++;
-      }
-    }
-    if (fmt->dwMask & CFM_BACKCOLOR && !(fmt->dwEffects & CFE_AUTOBACKCOLOR)) {
-      crColor = fmt->crBackColor;
-      for (i = 1; i < pStream->nColorTblLen; i++)
-        if (pStream->colortbl[i] == crColor)
-          break;
-      if (i == pStream->nColorTblLen && i < STREAMOUT_COLORTBL_SIZE) {
-        pStream->colortbl[i] = crColor;
-        pStream->nColorTblLen++;
-      }
-    }
+    if (fmt->dwMask & CFM_COLOR && !(fmt->dwEffects & CFE_AUTOCOLOR))
+      add_color_to_colortbl( pStream, fmt->crTextColor );
+    if (fmt->dwMask & CFM_BACKCOLOR && !(fmt->dwEffects & CFE_AUTOBACKCOLOR))
+      add_color_to_colortbl( pStream, fmt->crBackColor );
 
     if (item == pLastRun)
       break;
@@ -287,20 +285,8 @@ ME_StreamOutRTFFontAndColorTbl(ME_OutStream *pStream, ME_DisplayItem *pFirstRun,
                                   &pCell->member.cell.border.bottom,
                                   &pCell->member.cell.border.right };
         for (i = 0; i < 4; i++)
-        {
           if (borders[i]->width > 0)
-          {
-            unsigned int j;
-            COLORREF crColor = borders[i]->colorRef;
-            for (j = 1; j < pStream->nColorTblLen; j++)
-              if (pStream->colortbl[j] == crColor)
-                break;
-            if (j == pStream->nColorTblLen && j < STREAMOUT_COLORTBL_SIZE) {
-              pStream->colortbl[j] = crColor;
-              pStream->nColorTblLen++;
-            }
-          }
-        }
+            add_color_to_colortbl( pStream, borders[i]->colorRef );
     }
     if (item == pLastPara)
       break;




More information about the wine-cvs mailing list