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

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

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

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

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

            case HtmlElement.HtmlElementType.SPAN:
            case HtmlElement.HtmlElementType.FONT:
                flag = true;
                break;
            }
            if (!flag || m_currentHtmlElement.IsEmptyElement || !m_currentHtmlElement.HasAttributes)
            {
                return;
            }
            if (m_currentHtmlElement.ElementType == HtmlElement.HtmlElementType.FONT)
            {
                if (m_currentHtmlElement.Attributes.TryGetValue("size", out string value))
                {
                    if (RichTextStyleTranslator.TranslateHtmlFontSize(value, out string translatedSize))
                    {
                        m_currentStyle.FontSize = new ReportSize(translatedSize);
                    }
                    else
                    {
                        m_richTextLogger.RegisterInvalidSizeWarning("size", value, m_currentHtmlElement.CharacterPosition);
                    }
                }
                if (m_currentHtmlElement.Attributes.TryGetValue("face", out value))
                {
                    m_currentStyle.FontFamily = value;
                }
                if (m_currentHtmlElement.Attributes.TryGetValue("color", out value))
                {
                    if (ReportColor.TryParse(RichTextStyleTranslator.TranslateHtmlColor(value), out ReportColor reportColor))
                    {
                        m_currentStyle.Color = reportColor;
                    }
                    else
                    {
                        m_richTextLogger.RegisterInvalidColorWarning("color", value, m_currentHtmlElement.CharacterPosition);
                    }
                }
            }
            else if (m_currentHtmlElement.ElementType == HtmlElement.HtmlElementType.SPAN)
            {
                SetStyleValues(isParagraph: false);
            }
        }
        private void SetStyleValues(bool isParagraph)
        {
            if (m_currentHtmlElement.CssStyle == null)
            {
                return;
            }
            string     value;
            ReportSize reportSize;

            if (isParagraph && m_allowMultipleParagraphs)
            {
                if (m_currentHtmlElement.CssStyle.TryGetValue("text-align", out value))
                {
                    if (RichTextStyleTranslator.TranslateTextAlign(value, out TextAlignments textAlignment))
                    {
                        m_currentStyle.TextAlign = textAlignment;
                    }
                    else
                    {
                        m_richTextLogger.RegisterInvalidValueWarning("text-align", value, m_currentHtmlElement.CharacterPosition);
                    }
                }
                if (m_currentHtmlElement.CssStyle.TryGetValue("text-indent", out value))
                {
                    if (ReportSize.TryParse(value, allowNegative: true, out reportSize))
                    {
                        m_currentParagraph.HangingIndent = reportSize;
                    }
                    else
                    {
                        m_richTextLogger.RegisterInvalidSizeWarning("text-indent", value, m_currentHtmlElement.CharacterPosition);
                    }
                }
                ReportSize generalPadding = null;
                if (m_currentHtmlElement.CssStyle.TryGetValue("padding", out value))
                {
                    if (ReportSize.TryParse(value, out reportSize))
                    {
                        generalPadding = reportSize;
                    }
                    else
                    {
                        m_richTextLogger.RegisterInvalidSizeWarning("padding", value, m_currentHtmlElement.CharacterPosition);
                    }
                }
                if (HasPaddingValue("padding-top", generalPadding, out ReportSize effectivePadding))
                {
                    m_currentParagraph.AddSpaceBefore(effectivePadding);
                }
                if (HasPaddingValue("padding-bottom", generalPadding, out effectivePadding))
                {
                    m_currentParagraph.AddSpaceAfter(effectivePadding);
                }
                if (HasPaddingValue("padding-left", generalPadding, out effectivePadding))
                {
                    m_currentParagraph.AddLeftIndent(effectivePadding);
                }
                if (HasPaddingValue("padding-right", generalPadding, out effectivePadding))
                {
                    m_currentParagraph.AddRightIndent(effectivePadding);
                }
            }
            if (m_currentHtmlElement.CssStyle.TryGetValue("font-family", out value))
            {
                m_currentStyle.FontFamily = value;
            }
            if (m_currentHtmlElement.CssStyle.TryGetValue("font-size", out value))
            {
                if (ReportSize.TryParse(value, out reportSize))
                {
                    m_currentStyle.FontSize = reportSize;
                }
                else
                {
                    m_richTextLogger.RegisterInvalidSizeWarning("font-size", value, m_currentHtmlElement.CharacterPosition);
                }
            }
            if (m_currentHtmlElement.CssStyle.TryGetValue("font-weight", out value))
            {
                if (RichTextStyleTranslator.TranslateFontWeight(value, out FontWeights fontWieght))
                {
                    m_currentStyle.FontWeight = fontWieght;
                }
                else
                {
                    m_richTextLogger.RegisterInvalidValueWarning("font-weight", value, m_currentHtmlElement.CharacterPosition);
                }
            }
            if (m_currentHtmlElement.CssStyle.TryGetValue("color", out value))
            {
                if (ReportColor.TryParse(RichTextStyleTranslator.TranslateHtmlColor(value), out ReportColor reportColor))
                {
                    m_currentStyle.Color = reportColor;
                }
                else
                {
                    m_richTextLogger.RegisterInvalidColorWarning("color", value, m_currentHtmlElement.CharacterPosition);
                }
            }
        }
        private void ParseParagraphElement(HtmlElement.HtmlElementType elementType, FunctionalList <ListStyle> listStyles)
        {
            CloseParagraph();
            if (m_currentParagraph.ElementType == HtmlElement.HtmlElementType.P)
            {
                m_currentParagraph = m_currentParagraph.RemoveParagraph(HtmlElement.HtmlElementType.P);
                m_currentStyle     = m_currentStyle.RemoveStyle(HtmlElement.HtmlElementType.P);
            }
            if (elementType == HtmlElement.HtmlElementType.LI)
            {
                FlushPendingLI();
                if (listStyles.Count > 0)
                {
                    m_currentParagraph.ListStyle = listStyles.First;
                }
                else
                {
                    m_currentParagraph.ListStyle = ListStyle.Bulleted;
                }
            }
            else
            {
                m_currentStyle     = m_currentStyle.CreateChildStyle(elementType);
                m_currentParagraph = m_currentParagraph.CreateChildParagraph(elementType);
                switch (elementType)
                {
                case HtmlElement.HtmlElementType.H1:
                    m_currentStyle.FontSize   = StyleDefaults.H1FontSize;
                    m_currentStyle.FontWeight = FontWeights.Bold;
                    SetMarginTopAndBottom(StyleDefaults.H1Margin);
                    break;

                case HtmlElement.HtmlElementType.H2:
                    m_currentStyle.FontSize   = StyleDefaults.H2FontSize;
                    m_currentStyle.FontWeight = FontWeights.Bold;
                    SetMarginTopAndBottom(StyleDefaults.H2Margin);
                    break;

                case HtmlElement.HtmlElementType.H3:
                    m_currentStyle.FontSize   = StyleDefaults.H3FontSize;
                    m_currentStyle.FontWeight = FontWeights.Bold;
                    SetMarginTopAndBottom(StyleDefaults.H3Margin);
                    break;

                case HtmlElement.HtmlElementType.H4:
                    m_currentStyle.FontSize   = StyleDefaults.H4FontSize;
                    m_currentStyle.FontWeight = FontWeights.Bold;
                    SetMarginTopAndBottom(StyleDefaults.H4Margin);
                    break;

                case HtmlElement.HtmlElementType.H5:
                    m_currentStyle.FontSize   = StyleDefaults.H5FontSize;
                    m_currentStyle.FontWeight = FontWeights.Bold;
                    SetMarginTopAndBottom(StyleDefaults.H5Margin);
                    break;

                case HtmlElement.HtmlElementType.H6:
                    m_currentStyle.FontSize   = StyleDefaults.H6FontSize;
                    m_currentStyle.FontWeight = FontWeights.Bold;
                    SetMarginTopAndBottom(StyleDefaults.H6Margin);
                    break;

                case HtmlElement.HtmlElementType.P:
                    SetMarginTopAndBottom(StyleDefaults.PMargin);
                    break;
                }
                if (!m_currentHtmlElement.IsEmptyElement && m_currentHtmlElement.HasAttributes && m_allowMultipleParagraphs && m_currentHtmlElement.Attributes.TryGetValue("align", out string value))
                {
                    if (RichTextStyleTranslator.TranslateTextAlign(value, out TextAlignments textAlignment))
                    {
                        m_currentStyle.TextAlign = textAlignment;
                    }
                    else
                    {
                        m_richTextLogger.RegisterInvalidValueWarning("align", value, m_currentHtmlElement.CharacterPosition);
                    }
                }
            }
            SetStyleValues(isParagraph: true);
        }