Example #1
0
        }          // OnLeaveVisual

        #endregion // HtmlStructure

        #region HtmlFormat

        // ----------------------------------------------------------------------
        protected virtual IRtfHtmlStyle GetHtmlStyle(IRtfVisual rtfVisual)
        {
            IRtfHtmlStyle htmlStyle = RtfHtmlStyle.Empty;

            switch (rtfVisual.Kind)
            {
            case RtfVisualKind.Text:
                htmlStyle = styleConverter.TextToHtml(rtfVisual as IRtfVisualText);
                break;
            }

            return(htmlStyle);
        }         // GetHtmlStyle
Example #2
0
        }          // 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
Example #3
0
        } // 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