RtfPipe icon indicating copy to clipboard operation
RtfPipe copied to clipboard

colortbl Default Entry

Open pgodwin opened this issue 6 years ago • 1 comments

I have the following RTF with highlighting:

{\rtf1\ansi\deff0 {\fonttbl {\f0 Courier;}{\f1 ProFontWindows;}}
{\colortbl;\red0\green0\blue0;\red255\green0\blue0;\red255\green255\blue0;}
This line is font 0 which is courier\line
\f1
This line is font 1\line
\f0
This line is font 0 again\line
This line has a \cf2 red \cf1 word\line
\highlight3 while this line has a \cf2 red \cf1 word and is highlighted in yellow\highlight0\line
Finally, back to the default color.\line
}

In Wordpad renders it as follows: image However the HTML output renders the last line (\highlight0 with a black background: image

Reading http://latex2rtf.sourceforge.net/rtfspec_6.html#rtfspec_12 states that:

Each definition must be delimited by a semicolon, even if the definition is omitted. If a color definition is omitted, the RTF reader uses its default color. The example below defines the default color table used by Word. The first color is omitted, as shown by the semicolon following the \colortbl control word. The missing definition indicates that color 0 is the ''auto'' color.

It would appear that in this case, the default color should be white.

pgodwin avatar Nov 15 '18 05:11 pgodwin

@erdomke, I think this more to do with the ColorTable handling rather than highlighting specifically. Ie, when the first color table definition is not included it should the "auto" color.

diff --git a/RtfPipe/Parser.cs b/RtfPipe/Parser.cs
index 5285d78..f95f4e6 100644
--- a/RtfPipe/Parser.cs
+++ b/RtfPipe/Parser.cs
@@ -338,9 +338,11 @@ private IToken ConsumeToken(IToken token)
       {
         if (token is TextToken)
         {
+
           if (_context.Peek().TokenBuffer.Count != 3)
           {
-            _document.ColorTable.Add(new ColorValue(0, 0, 0));
+            _document.ColorTable.Add(ColorValue.White); // todo - can we make this configurable?
           }
           else
           {

pgodwin avatar Nov 22 '18 02:11 pgodwin