Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
2.20/5 (5 votes)
See more:
Hi,

In case you would be interested...

I think I found an issue with the class Itenso.Rtf.Interpreter, method VisitTag. If I am parsing hidden text, for example an Xml style comment inserted in the middle of an Rtf document, you parser hides the text but still adds \par and \tab in the plain text output. I implemented a fix around line 291 in RtfInterpreter.cs


C#
case RtfSpec.TagParagraph:
    if(!Context.WritableCurrentTextFormat.IsHidden)//My fix
        NotifyInsertBreak( RtfVisualBreakKind.Paragraph );
    break;
case RtfSpec.TagLine:
    NotifyInsertBreak( RtfVisualBreakKind.Line );
    break;
case RtfSpec.TagPage:
    NotifyInsertBreak( RtfVisualBreakKind.Page );
    break;
case RtfSpec.TagTabulator:
    if (!Context.WritableCurrentTextFormat.IsHidden) //My fix
        NotifyInsertSpecialChar(RtfVisualSpecialCharKind.Tabulator);
    break;

Sample Rtf:

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\froman\fcharset0 Times New Roman;}{\f1\fnil Tahoma;}{\f2\fnil MS Sans Serif;}}
{\colortbl ;\red255\green0\blue0;\red0\green0\blue255;}
\viewkind4\uc1\pard\sb100\sa100\lang3084\f0\fs24 Mer 12 janvier 2011, 9h 02min 20s \par
This text should appear just before... \par
\par
\cf1\v <!--\par
\par
_filtered \{font-family:Calibri;panose-1:2 15 5 2 2 2 4 3 2 4;\}\par
_filtered \{font-family:Tahoma;panose-1:2 11 6 4 3 5 4 4 2 4;\}\par
_filtered \{font-family:"Wingdings 2";panose-1:5 2 1 2 1 5 7 7 7 7;\}\par
\par
p.MsoNormal, li.MsoNormal, div.MsoNormal\par
\tab\{margin:0cm;margin-bottom:.0001pt;font-size:12.0pt;font-family:"serif";\}\par
a:link, span.MsoHyperlink\par
\tab\{font-family:"sans-serif";\}\par
.MsoChpDefault\par
\tab\{font-family:"sans-serif";\}\par
_filtered \{margin:72.0pt 90.0pt 72.0pt 90.0pt;\}\par
div.WordSection1\par
\tab\{\}\par
-->\cf0\v0 ...that text, without extra linefeed or spaces
}

==================
Also the Microsoft RichTextbox control renders plain text differently from your library because it adds a line break when it hits a \row tag in the Rtf source. I was able to fix this with a 'patch' since your library doesn't seem to fully implement support for \intbl and \trow . The patch is;

Class RtfSpec:
C#
public const string TagRow = "row";


Method RtfInterpreter.VisitTag:
C#
case RtfSpec.TagRow: //My fix
case RtfSpec.TagParagraph:
    if(!Context.WritableCurrentTextFormat.IsHidden)
        NotifyInsertBreak( RtfVisualBreakKind.Paragraph );
    break;

...and it works fine.

Thanks.

Sylvain
Posted
Comments
[no name] 19-Apr-12 15:59pm    
And your question is what exactly?
R. Giskard Reventlov 19-Apr-12 16:07pm    
Entirely the wrong lace to post an answer. Didn't you read anything before posting. This would be better as a blog post or trick/tip.
Nelek 19-Apr-12 18:19pm    
Agree with mark merrens. You should post it as tip/trick. Please have a look to http://www.codeproject.com/script/Articles/Submit.aspx[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900