Dylan Smith : richedit: Handle missing colours in rtf colour table.

Alexandre Julliard julliard at winehq.org
Fri Jul 17 09:03:46 CDT 2009


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

Author: Dylan Smith <dylan.ah.smith at gmail.com>
Date:   Fri Jul 17 09:17:20 2009 -0400

richedit: Handle missing colours in rtf colour table.

When a colour table entry is empty, then the default colour is used.
For an incomplete colour table entry 0 is used for the missing colours.

Previously the -1 value used internally for missing colours was being
converted into white, where it should be using the default colour that
is normally black.

This bug could be seen by loading the following rich text into wordpad:
{\rtf{\colortbl;;}\cf1 text}

---

 dlls/riched20/editor.c |   12 ++++++++----
 dlls/riched20/reader.c |   23 +++++++++++++----------
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 7ffb7cb..14a7246 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -422,7 +422,10 @@ void ME_RTFCharAttrHook(RTF_Info *info)
       else if (info->rtfParam != rtfNoParam)
       {
         RTFColor *c = RTFGetColor(info, info->rtfParam);
-        fmt.crTextColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed);
+        if (c && c->rtfCBlue >= 0)
+          fmt.crTextColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed);
+        else
+          fmt.dwEffects = CFE_AUTOBACKCOLOR;
       }
       break;
     case rtfForeColor:
@@ -433,10 +436,11 @@ void ME_RTFCharAttrHook(RTF_Info *info)
       else if (info->rtfParam != rtfNoParam)
       {
         RTFColor *c = RTFGetColor(info, info->rtfParam);
-        if (c)
+        if (c && c->rtfCBlue >= 0)
           fmt.crTextColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed);
-        else
-          fmt.crTextColor = 0;
+        else {
+          fmt.dwEffects = CFE_AUTOCOLOR;
+        }
       }
       break;
     case rtfFontNum:
diff --git a/dlls/riched20/reader.c b/dlls/riched20/reader.c
index b6a6f44..0462f71 100644
--- a/dlls/riched20/reader.c
+++ b/dlls/riched20/reader.c
@@ -990,18 +990,21 @@ static void ReadColorTbl(RTF_Info *info)
 			break;
 		}
 		cp->rtfCNum = cnum++;
-		cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = -1;
 		cp->rtfNextColor = info->colorList;
 		info->colorList = cp;
-		while (RTFCheckCM (info, rtfControl, rtfColorName))
-		{
-			switch (info->rtfMinor)
-			{
-			case rtfRed:	cp->rtfCRed = info->rtfParam; break;
-			case rtfGreen:	cp->rtfCGreen = info->rtfParam; break;
-			case rtfBlue:	cp->rtfCBlue = info->rtfParam; break;
-			}
-			RTFGetToken (info);
+		if (!RTFCheckCM (info, rtfControl, rtfColorName))
+			cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = -1;
+		else {
+			cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = 0;
+			do {
+				switch (info->rtfMinor)
+				{
+				case rtfRed:	cp->rtfCRed = info->rtfParam & 0xFF; break;
+				case rtfGreen:	cp->rtfCGreen = info->rtfParam & 0xFF; break;
+				case rtfBlue:	cp->rtfCBlue = info->rtfParam & 0xFF; break;
+				}
+				RTFGetToken (info);
+			} while (RTFCheckCM (info, rtfControl, rtfColorName));
 		}
 		if (info->rtfClass == rtfEOF)
 			break;




More information about the wine-cvs mailing list