} // RtfVisualVisitorBase // ---------------------------------------------------------------------- public void VisitText( IRtfVisualText visualText ) { if ( visualText != null ) { DoVisitText( visualText ); } } // VisitText
} // Convert // ---------------------------------------------------------------------- protected override void DoVisitText( IRtfVisualText visualText ) { // suppress hidden text if ( visualText.Format.IsHidden && this.settings.IsShowHiddenText == false ) { return; } WriteStartElement( "rtfVisualText" ); WriteStartElement( "format" ); WriteElementString( "fontSize", visualText.Format.FontSize.ToString() ); WriteColor( "backgroundColor", visualText.Format.BackgroundColor ); WriteColor( "foregroundColor", visualText.Format.ForegroundColor ); WriteElementString( "alignment", visualText.Format.Alignment.ToString() ); WriteElementString( "superScript", visualText.Format.SuperScript.ToString() ); WriteElementString( "isBold", visualText.Format.IsBold.ToString() ); WriteElementString( "isItalic", visualText.Format.IsItalic.ToString() ); WriteElementString( "isStrikeThrough", visualText.Format.IsStrikeThrough.ToString() ); WriteElementString( "isUnderline", visualText.Format.IsUnderline.ToString() ); WriteEndElement(); WriteStartElement( "font" ); WriteElementString( "id", visualText.Format.Font.Id ); WriteElementString( "kind", visualText.Format.Font.Kind.ToString() ); WriteElementString( "name", visualText.Format.Font.Name ); WriteElementString( "charSet", visualText.Format.Font.CharSet.ToString() ); WriteElementString( "codePage", visualText.Format.Font.CodePage.ToString() ); WriteElementString( "pitch", visualText.Format.Font.Pitch.ToString() ); WriteEndElement(); WriteElementString( "text", visualText.Text ); WriteEndElement(); } // DoVisitText
// ---------------------------------------------------------------------- public virtual IRtfHtmlStyle TextToHtml( IRtfVisualText visualText ) { if ( visualText == null ) { throw new ArgumentNullException( "visualText" ); } RtfHtmlStyle htmlStyle = new RtfHtmlStyle(); IRtfTextFormat textFormat = visualText.Format; // background color Color backgroundColor = textFormat.BackgroundColor.AsDrawingColor; if ( backgroundColor.R != 0 || backgroundColor.G != 0 || backgroundColor.B != 0 ) { htmlStyle.BackgroundColor = ColorTranslator.ToHtml( backgroundColor ); } // foreground color Color foregroundColor = textFormat.ForegroundColor.AsDrawingColor; if ( foregroundColor.R != 0 || foregroundColor.G != 0 || foregroundColor.B != 0 ) { htmlStyle.ForegroundColor = ColorTranslator.ToHtml( foregroundColor ); } // font htmlStyle.FontFamily = textFormat.Font.Name; if ( textFormat.FontSize > 0 ) { htmlStyle.FontSize = (textFormat.FontSize /2) + "pt"; } return htmlStyle; }
} // VisitText // ---------------------------------------------------------------------- protected virtual void DoVisitText( IRtfVisualText visualText ) { } // DoVisitText
// ---------------------------------------------------------------------- protected override void DoVisitText( IRtfVisualText visualText ) { if ( !EnterVisual( visualText ) ) { return; } // suppress hidden text if ( visualText.Format.IsHidden && settings.IsShowHiddenText == false ) { return; } IRtfTextFormat textFormat = visualText.Format; switch ( textFormat.Alignment ) { case RtfTextAlignment.Left: //Writer.AddAttribute( HtmlTextWriterAttribute.Align, "left", false ); break; case RtfTextAlignment.Center: Writer.AddAttribute( HtmlTextWriterAttribute.Align, "center", false ); break; case RtfTextAlignment.Right: Writer.AddAttribute( HtmlTextWriterAttribute.Align, "right", false ); break; case RtfTextAlignment.Justify: Writer.AddAttribute( HtmlTextWriterAttribute.Align, "justify", false ); break; } if ( !IsInListItem ) { BeginParagraph(); } // format tags if ( textFormat.IsBold ) { RenderBTag(); } if ( textFormat.IsItalic ) { RenderITag(); } if ( textFormat.IsUnderline ) { RenderUTag(); } if ( textFormat.IsStrikeThrough ) { RenderSTag(); } // span with style IRtfHtmlStyle htmlStyle = GetHtmlStyle( visualText ); if ( !htmlStyle.IsEmpty ) { if ( !string.IsNullOrEmpty( htmlStyle.ForegroundColor ) ) { Writer.AddStyleAttribute( HtmlTextWriterStyle.Color, htmlStyle.ForegroundColor ); } if ( !string.IsNullOrEmpty( htmlStyle.BackgroundColor ) ) { Writer.AddStyleAttribute( HtmlTextWriterStyle.BackgroundColor, htmlStyle.BackgroundColor ); } if ( !string.IsNullOrEmpty( htmlStyle.FontFamily ) ) { Writer.AddStyleAttribute( HtmlTextWriterStyle.FontFamily, htmlStyle.FontFamily ); } if ( !string.IsNullOrEmpty( htmlStyle.FontSize ) ) { Writer.AddStyleAttribute( HtmlTextWriterStyle.FontSize, htmlStyle.FontSize ); } RenderSpanTag(); } // visual hyperlink bool isHyperlink = false; if ( settings.ConvertVisualHyperlinks ) { string href = ConvertVisualHyperlink( visualText.Text ); if ( !string.IsNullOrEmpty( href ) ) { isHyperlink = true; Writer.AddAttribute( HtmlTextWriterAttribute.Href, href ); RenderATag(); } } string htmlText = FormatHtmlText( visualText.Text ); Writer.Write( htmlText ); // visual hyperlink if ( isHyperlink ) { RenderEndTag(); // a } // span with style if ( !htmlStyle.IsEmpty ) { RenderEndTag(); } // format tags if ( textFormat.IsStrikeThrough ) { RenderEndTag(); // s } if ( textFormat.IsUnderline ) { RenderEndTag(); // u } if ( textFormat.IsItalic ) { RenderEndTag(); // i } if ( textFormat.IsBold ) { RenderEndTag(); // b } LeaveVisual( visualText ); }
// ---------------------------------------------------------------------- public virtual IRtfHtmlStyle TextToHtml( IRtfVisualText visualText ) { return RtfHtmlStyle.Empty; }