http://bugs.winehq.org/show_bug.cgi?id=60161 Bug ID: 60161 Summary: riched20: colour table entries using \ctint/\cshade or theme colour keywords are parsed as three entries, shifting all \cfN indices Product: Wine Version: 11.15 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: richedit Assignee: wine-bugs@list.winehq.org Reporter: wehrwolfmann@gmail.com Target Milestone: --- Distribution: --- Created attachment 81788 --> http://bugs.winehq.org/attachment.cgi?id=81788 inimal reproducer: three RTF colour tables that must render identically. Wine's RTF reader only accepts \red, \green and \blue inside \colortbl. Any other control word that the RTF specification allows in a colour table entry -- \ctint, \cshade and the theme colour keywords \cmaindarkone, \cmainlightone, \caccentone ... -- is not recognised, so ReadColorTbl() terminates the entry early, emits "err:richedit:ReadColorTbl malformed entry", and starts a *new* colour entry at the next token. Consequences: 1. One source entry turns into several colour table entries, so every \cfN in the document afterwards selects the wrong colour. 2. The bogus entries are created with rtfCRed/CGreen/CBlue = -1, i.e. "use the default colour", so the affected text ends up with CFE_AUTOCOLOR instead of the colour the document asked for. The relevant code is dlls/riched20/reader.c, ReadColorTbl(): if (!RTFCheckCM (info, rtfControl, rtfColorName)) cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = -1; else { ... do { switch (info->rtfMinor) { case rtfRed: ... case rtfGreen: ... case rtfBlue: ... } RTFGetToken (info); } while (RTFCheckCM (info, rtfControl, rtfColorName)); } if (info->rtfClass == rtfEOF) break; if (!RTFCheckCM (info, rtfText, ';')) ERR ("malformed entry\n"); The keyword table in the same file (lines 1847-1849 of current master) knows exactly three colour table keywords: { rtfColorName, rtfRed, "red", 0 }, { rtfColorName, rtfGreen, "green", 0 }, { rtfColorName, rtfBlue, "blue", 0 }, \ctint, \cshade and the theme colour keywords do not appear anywhere in reader.c, so they are classified as unknown control words and break the entry apart. This is not a corner case: it is the shape Word (2007 and newer) and WordPad write for any document that uses theme colours, and it is what Inno Setup installers ship as their licence text. It is the likely cause of the long-standing "err:richedit:ReadColorTbl malformed entry" messages, e.g. in bug 20482. STEPS TO REPRODUCE Build and run the attached riched_colortbl.c (x86_64-w64-mingw32-gcc riched_colortbl.c -o riched_colortbl.exe -lgdi32 -luser32). It streams three RTF documents into a RichEdit 2.0 control with EM_STREAMIN and then reads the effective text colour of the single character back with EM_GETCHARFORMAT. All three documents request the same colour -- pure red -- and per the RTF specification must render identically: A {\rtf1\ansi\deff0{\fonttbl{\f0 Arial;}} {\colortbl;\red255\green0\blue0;}\cf1 X\par} B {\rtf1\ansi\deff0{\fonttbl{\f0 Arial;}} {\colortbl;\ctint255\cshade255\red255\green0\blue0;}\cf1 X\par} C {\rtf1\ansi\deff0{\fonttbl{\f0 Arial;}} {\colortbl;\red0\green0\blue0; \cmaindarkone\ctint255\cshade255\red255\green0\blue0;}\cf2 X\par} CURRENT BEHAVIOUR (wine-11.15, 64-bit, clean prefix, no overrides) expected for every line: crTextColor=0x0000ff (R=255 G=0 B=0) A plain colortbl stream error=0 textlen=1 effects=0x04000001 crTextColor=0x0000ff (R=255 G=0 B=0) B \ctint\cshade stream error=0 textlen=1 effects=0x44000001 crTextColor=0x007fff (R=255 G=127 B=0) [CFE_AUTOCOLOR] C Word theme colour stream error=0 textlen=1 effects=0x44000001 crTextColor=0x007fff (R=255 G=127 B=0) [CFE_AUTOCOLOR] with WINEDEBUG=+richedit: err:richedit:ReadColorTbl malformed entry (5x for the three documents) EXPECTED BEHAVIOUR All three lines report crTextColor=0x0000ff without CFE_AUTOCOLOR, and no "malformed entry" message is printed: \ctint, \cshade and the theme colour keywords are part of a single colour table entry and do not create entries of their own. SUGGESTED FIX Add the missing colour table keywords to the keyword table in dlls/riched20/reader.c and skip them in ReadColorTbl() instead of terminating the entry: * \ctintN and \cshadeN (tint/shade applied to the following \red\green\blue) * the theme colour keywords \cmaindarkone, \cmainlightone, \cmaindarktwo, \cmainlighttwo, \caccentone ... \caccentsix, \chyperlink, \cfollowedhyperlink, \cbackgroundone, \cbackgroundtwo, \ctextone, \ctexttwo Only the following \red/\green/\blue values need to be stored; the tint/shade factors and the theme name do not change which colour the entry resolves to for the purposes of \cfN lookup. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.