RTF KeyNotFoundException when there is whitespace between the opening RTF header and the color.

17 views
Skip to first unread message

MKB

unread,
Nov 28, 2013, 12:02:10 PM11/28/13
to dot-net-...@googlegroups.com
I've found that if there is any whitespace between the opening RTF declaration (\rtf...) and the color ({\color...), then Siberix will throw a KeyNotFoundException in the TextReader.GetBrush method.  You can see this yourself by editing the Example.rtf that comes with the Evaluation samples.  Just add a couple of spaces after the initial line:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1033{\fonttbl{\f0\fnil\fcharset0 Verdana;}} 

MKB

unread,
Nov 28, 2013, 12:30:03 PM11/28/13
to dot-net-...@googlegroups.com
There's another bug where if you add multiple RTF text sections in succession, it will retain the color from the first section used.  
For example, you can modify the "RichParagraph" example to load RTF from not one, but two files, say "Example.rtf" and "Example2.rtf".  If "Example.rtf" has text in green and "Example2.rtf" has text in blue, both sections will show in blue.

siberix

unread,
Nov 28, 2013, 3:40:35 PM11/28/13
to dot-net-...@googlegroups.com
Hi MKB,

Thank your for your feedback!

Please be cautious while adding white-spaces into RTF documents as they are not ignored (as in XML documents) and could be treated as part of the command keywords (breaking the structure of the markup) or appear as a part of the document content. In your case adding a space before the color definition adds it to the content of the document and since no color was assigned yet (to render this white-space) it generates an error. I made an update to the ReportWriter (it will be available with the next release) that handles this situation and draws the text in Black if no colors were yet assigned.

Thank You,
Victor

siberix

unread,
Nov 28, 2013, 4:52:13 PM11/28/13
to dot-net-...@googlegroups.com
Hi MKB,

This is indeed a bug and i've just fixed it. Could you please contact me at (in...@siberix.com), so i could send you an updated evaluation version of the Report Writer that contains the fixes.

Thank You,
Victor
Reply all
Reply to author
Forward
0 new messages