// ---------------------------------------------------------------------- public void VisitText(IRtfVisualText visualText) { if (visualText != null) { DoVisitText(visualText); } } // VisitText
// ---------------------------------------------------------------------- public virtual IRtfHtmlStyle TextToHtml(IRtfVisualText visualText) { if (visualText == null) { throw new ArgumentNullException("visualText"); } RtfHtmlStyle htmlStyle = new RtfHtmlStyle(); IRtfTextFormat textFormat = visualText.Format; // background color var color = textFormat.BackgroundColor; if (color.Red != 255 || color.Green != 255 || color.Blue != 255) { htmlStyle.BackgroundColor = ToHtmlColor(color); } // foreground color color = textFormat.ForegroundColor; if (color.Red != 0 || color.Green != 0 || color.Blue != 0) { htmlStyle.ForegroundColor = ToHtmlColor(color); } // font htmlStyle.FontFamily = textFormat.Font.Name; if (textFormat.FontSize > 0) { htmlStyle.FontSize = (textFormat.FontSize / 2) + "pt"; } return(htmlStyle); } // TextToHtml
} // Convert // ---------------------------------------------------------------------- protected override void DoVisitText(IRtfVisualText visualText) { // suppress hidden text if (visualText.Format.IsHidden && settings.IsShowHiddenText == false) { return; } WriteStartElement("rtfVisualText"); WriteStartElement("format"); WriteElementString("fontSize", visualText.Format.FontSize.ToString(CultureInfo.InvariantCulture)); WriteColor("backgroundColor", visualText.Format.BackgroundColor); WriteColor("foregroundColor", visualText.Format.ForegroundColor); WriteElementString("alignment", visualText.Format.Alignment.ToString()); WriteElementString("superScript", visualText.Format.SuperScript.ToString(CultureInfo.InvariantCulture)); WriteElementString("isBold", visualText.Format.IsBold.ToString(CultureInfo.InvariantCulture)); WriteElementString("isItalic", visualText.Format.IsItalic.ToString(CultureInfo.InvariantCulture)); WriteElementString("isStrikeThrough", visualText.Format.IsStrikeThrough.ToString(CultureInfo.InvariantCulture)); WriteElementString("isUnderline", visualText.Format.IsUnderline.ToString(CultureInfo.InvariantCulture)); 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(CultureInfo.InvariantCulture)); WriteElementString("codePage", visualText.Format.Font.CodePage.ToString(CultureInfo.InvariantCulture)); WriteElementString("pitch", visualText.Format.Font.Pitch.ToString()); WriteEndElement(); WriteElementString("text", visualText.Text); WriteEndElement(); } // DoVisitText
} // 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
} // LeaveVisual // ---------------------------------------------------------------------- // returns true if visual is in list private bool EnsureOpenList(IRtfVisual rtfVisual) { IRtfVisualText visualText = rtfVisual as IRtfVisualText; if (visualText == null || !isInParagraphNumber) { return(false); } if (!IsInList) { bool unsortedList = unsortedListValue.Equals(visualText.Text); if (unsortedList) { RenderUlTag(); // unsorted list } else { RenderOlTag(); // ordered list } } RenderLiTag(); return(true); } // EnsureOpenList
// ---------------------------------------------------------------------- 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; }
// ---------------------------------------------------------------------- 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); } // TextToHtml
} // VisitText // ---------------------------------------------------------------------- protected virtual void DoVisitText(IRtfVisualText visualText) { } // DoVisitText
} // 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; }
} // FormatHtmlText #endregion // HtmlFormat #region RtfVisuals // ---------------------------------------------------------------------- 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.AddStyleAttribute( HtmlTextWriterStyle.TextAlign, "left" ); break; case RtfTextAlignment.Center: Writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "center"); break; case RtfTextAlignment.Right: Writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "right"); break; case RtfTextAlignment.Justify: Writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "justify"); 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(); } } // subscript and superscript if (textFormat.SuperScript < 0) { RenderSubTag(); } else if (textFormat.SuperScript > 0) { RenderSupTag(); } string htmlText = FormatHtmlText(visualText.Text); Writer.Write(htmlText); // subscript and superscript if (textFormat.SuperScript < 0) { RenderEndTag(); // sub } else if (textFormat.SuperScript > 0) { RenderEndTag(); // sup } // 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); } // DoVisitText
// ---------------------------------------------------------------------- public virtual IRtfHtmlStyle TextToHtml(IRtfVisualText visualText) { return(RtfHtmlStyle.Empty); } // TextToHtml
} // GetHtmlStyle #endregion // HtmlFormat #region RtfVisuals // ---------------------------------------------------------------------- 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; if (!IsInListItem && BeginParagraph()) { switch (textFormat.Alignment) { case RtfTextAlignment.Left: //Writer.AddStyleAttribute( HtmlTextWriterStyle.TextAlign, "left" ); break; case RtfTextAlignment.Center: Writer.WriteAttributeString("style", "text-align:center"); break; case RtfTextAlignment.Right: Writer.WriteAttributeString("style", "text-align:right"); break; case RtfTextAlignment.Justify: Writer.WriteAttributeString("style", "text-align:justify"); break; } } // 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) { RenderSpanTag(); var styles = new Dictionary <string, string>(); if (!string.IsNullOrEmpty(htmlStyle.ForegroundColor)) { styles["color"] = htmlStyle.ForegroundColor; } if (!string.IsNullOrEmpty(htmlStyle.BackgroundColor)) { styles["background-color"] = htmlStyle.BackgroundColor; } if (!string.IsNullOrEmpty(htmlStyle.FontFamily)) { styles["font-family"] = htmlStyle.FontFamily; } if (!string.IsNullOrEmpty(htmlStyle.FontSize)) { styles["font-size"] = htmlStyle.FontSize; } if (styles.Count > 0) { _writer.WriteStartAttribute("style"); var first = true; foreach (var kvp in styles) { if (!first) { _writer.WriteString(";"); } _writer.WriteString(kvp.Key); _writer.WriteString(":"); _writer.WriteString(kvp.Value); first = false; } _writer.WriteEndAttribute(); } } // visual hyperlink bool isHyperlink = false; if (_settings.ConvertVisualHyperlinks) { string href = ConvertVisualHyperlink(visualText.Text); if (!string.IsNullOrEmpty(href)) { isHyperlink = true; RenderATag(); Writer.WriteAttributeString("href", href); } } // subscript and superscript if (textFormat.SuperScript < 0) { RenderSubTag(); } else if (textFormat.SuperScript > 0) { RenderSupTag(); } Writer.WriteString(visualText.Text); // subscript and superscript if (textFormat.SuperScript < 0) { RenderEndTag(); // sub } else if (textFormat.SuperScript > 0) { RenderEndTag(); // sup } // 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); } // DoVisitText