private void ParseTextRunElement(HtmlElement.HtmlElementType elementType)
        {
            base.m_currentStyle = base.m_currentStyle.CreateChildStyle(elementType);
            bool flag = false;

            switch (this.m_currentHtmlElement.ElementType)
            {
            case HtmlElement.HtmlElementType.I:
            case HtmlElement.HtmlElementType.EM:
                base.m_currentStyle.FontStyle = FontStyles.Italic;
                break;

            case HtmlElement.HtmlElementType.U:
                base.m_currentStyle.TextDecoration = TextDecorations.Underline;
                break;

            case HtmlElement.HtmlElementType.STRONG:
            case HtmlElement.HtmlElementType.B:
                base.m_currentStyle.FontWeight = FontWeights.Bold;
                break;

            case HtmlElement.HtmlElementType.STRIKE:
            case HtmlElement.HtmlElementType.S:
                base.m_currentStyle.TextDecoration = TextDecorations.LineThrough;
                break;

            case HtmlElement.HtmlElementType.SPAN:
            case HtmlElement.HtmlElementType.FONT:
                flag = true;
                break;
            }
            if (flag && !this.m_currentHtmlElement.IsEmptyElement && this.m_currentHtmlElement.HasAttributes)
            {
                if (this.m_currentHtmlElement.ElementType == HtmlElement.HtmlElementType.FONT)
                {
                    string text = default(string);
                    if (this.m_currentHtmlElement.Attributes.TryGetValue("size", out text))
                    {
                        string size = default(string);
                        if (RichTextStyleTranslator.TranslateHtmlFontSize(text, out size))
                        {
                            base.m_currentStyle.FontSize = new ReportSize(size);
                        }
                        else
                        {
                            base.m_richTextLogger.RegisterInvalidSizeWarning("size", text, this.m_currentHtmlElement.CharacterPosition);
                        }
                    }
                    if (this.m_currentHtmlElement.Attributes.TryGetValue("face", out text))
                    {
                        base.m_currentStyle.FontFamily = text;
                    }
                    if (this.m_currentHtmlElement.Attributes.TryGetValue("color", out text))
                    {
                        ReportColor color = default(ReportColor);
                        if (ReportColor.TryParse(RichTextStyleTranslator.TranslateHtmlColor(text), out color))
                        {
                            base.m_currentStyle.Color = color;
                        }
                        else
                        {
                            base.m_richTextLogger.RegisterInvalidColorWarning("color", text, this.m_currentHtmlElement.CharacterPosition);
                        }
                    }
                }
                else if (this.m_currentHtmlElement.ElementType == HtmlElement.HtmlElementType.SPAN)
                {
                    this.SetStyleValues(false);
                }
            }
        }
 private void SetStyleValues(bool isParagraph)
 {
     if (this.m_currentHtmlElement.CssStyle != null)
     {
         string     text       = default(string);
         ReportSize reportSize = default(ReportSize);
         if (isParagraph && base.m_allowMultipleParagraphs)
         {
             if (this.m_currentHtmlElement.CssStyle.TryGetValue("text-align", out text))
             {
                 TextAlignments textAlign = default(TextAlignments);
                 if (RichTextStyleTranslator.TranslateTextAlign(text, out textAlign))
                 {
                     base.m_currentStyle.TextAlign = textAlign;
                 }
                 else
                 {
                     base.m_richTextLogger.RegisterInvalidValueWarning("text-align", text, this.m_currentHtmlElement.CharacterPosition);
                 }
             }
             if (this.m_currentHtmlElement.CssStyle.TryGetValue("text-indent", out text))
             {
                 if (ReportSize.TryParse(text, true, out reportSize))
                 {
                     base.m_currentParagraph.HangingIndent = reportSize;
                 }
                 else
                 {
                     base.m_richTextLogger.RegisterInvalidSizeWarning("text-indent", text, this.m_currentHtmlElement.CharacterPosition);
                 }
             }
             ReportSize generalPadding = null;
             if (this.m_currentHtmlElement.CssStyle.TryGetValue("padding", out text))
             {
                 if (ReportSize.TryParse(text, out reportSize))
                 {
                     generalPadding = reportSize;
                 }
                 else
                 {
                     base.m_richTextLogger.RegisterInvalidSizeWarning("padding", text, this.m_currentHtmlElement.CharacterPosition);
                 }
             }
             ReportSize size = default(ReportSize);
             if (this.HasPaddingValue("padding-top", generalPadding, out size))
             {
                 base.m_currentParagraph.AddSpaceBefore(size);
             }
             if (this.HasPaddingValue("padding-bottom", generalPadding, out size))
             {
                 base.m_currentParagraph.AddSpaceAfter(size);
             }
             if (this.HasPaddingValue("padding-left", generalPadding, out size))
             {
                 base.m_currentParagraph.AddLeftIndent(size);
             }
             if (this.HasPaddingValue("padding-right", generalPadding, out size))
             {
                 base.m_currentParagraph.AddRightIndent(size);
             }
         }
         if (this.m_currentHtmlElement.CssStyle.TryGetValue("font-family", out text))
         {
             base.m_currentStyle.FontFamily = text;
         }
         if (this.m_currentHtmlElement.CssStyle.TryGetValue("font-size", out text))
         {
             if (ReportSize.TryParse(text, out reportSize))
             {
                 base.m_currentStyle.FontSize = reportSize;
             }
             else
             {
                 base.m_richTextLogger.RegisterInvalidSizeWarning("font-size", text, this.m_currentHtmlElement.CharacterPosition);
             }
         }
         if (this.m_currentHtmlElement.CssStyle.TryGetValue("font-weight", out text))
         {
             FontWeights fontWeight = default(FontWeights);
             if (RichTextStyleTranslator.TranslateFontWeight(text, out fontWeight))
             {
                 base.m_currentStyle.FontWeight = fontWeight;
             }
             else
             {
                 base.m_richTextLogger.RegisterInvalidValueWarning("font-weight", text, this.m_currentHtmlElement.CharacterPosition);
             }
         }
         if (this.m_currentHtmlElement.CssStyle.TryGetValue("color", out text))
         {
             ReportColor color = default(ReportColor);
             if (ReportColor.TryParse(RichTextStyleTranslator.TranslateHtmlColor(text), out color))
             {
                 base.m_currentStyle.Color = color;
             }
             else
             {
                 base.m_richTextLogger.RegisterInvalidColorWarning("color", text, this.m_currentHtmlElement.CharacterPosition);
             }
         }
     }
 }
Example #3
0
 public static bool TryParse(string value, out ReportColor reportColor)
 {
     return(ReportColor.TryParse(value, false, out reportColor));
 }