public static bool TranslateTextAlign(string styleString, out TextAlignments textAlignment)
        {
            textAlignment = TextAlignments.General;
            if (!string.IsNullOrEmpty(styleString))
            {
                if (RichTextStyleTranslator.CompareWithInvariantCulture("General", styleString))
                {
                    textAlignment = TextAlignments.General;
                    goto IL_0067;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("Left", styleString))
                {
                    textAlignment = TextAlignments.Left;
                    goto IL_0067;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("Center", styleString))
                {
                    textAlignment = TextAlignments.Center;
                    goto IL_0067;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("Right", styleString))
                {
                    textAlignment = TextAlignments.Right;
                    goto IL_0067;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("Default", styleString))
                {
                    textAlignment = TextAlignments.General;
                    goto IL_0067;
                }
                return(false);
            }
            return(false);

IL_0067:
            return(true);
        }
        public static bool TranslateFontWeight(string styleString, out FontWeights fontWieght)
        {
            fontWieght = FontWeights.Normal;
            if (!string.IsNullOrEmpty(styleString))
            {
                if (RichTextStyleTranslator.CompareWithInvariantCulture("Normal", styleString))
                {
                    fontWieght = FontWeights.Normal;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("Bold", styleString))
                {
                    fontWieght = FontWeights.Bold;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("Bolder", styleString))
                {
                    fontWieght = FontWeights.Bold;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("100", styleString))
                {
                    fontWieght = FontWeights.Thin;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("200", styleString))
                {
                    fontWieght = FontWeights.ExtraLight;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("300", styleString))
                {
                    fontWieght = FontWeights.Light;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("400", styleString))
                {
                    fontWieght = FontWeights.Normal;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("500", styleString))
                {
                    fontWieght = FontWeights.Medium;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("600", styleString))
                {
                    fontWieght = FontWeights.SemiBold;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("700", styleString))
                {
                    fontWieght = FontWeights.Bold;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("800", styleString))
                {
                    fontWieght = FontWeights.ExtraBold;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("900", styleString))
                {
                    fontWieght = FontWeights.Heavy;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("Thin", styleString))
                {
                    fontWieght = FontWeights.Thin;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("ExtraLight", styleString))
                {
                    fontWieght = FontWeights.ExtraLight;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("Light", styleString))
                {
                    fontWieght = FontWeights.Light;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("Lighter", styleString))
                {
                    fontWieght = FontWeights.Light;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("Medium", styleString))
                {
                    fontWieght = FontWeights.Medium;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("SemiBold", styleString))
                {
                    fontWieght = FontWeights.SemiBold;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("ExtraBold", styleString))
                {
                    fontWieght = FontWeights.ExtraBold;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("Heavy", styleString))
                {
                    fontWieght = FontWeights.Heavy;
                    goto IL_01b6;
                }
                if (RichTextStyleTranslator.CompareWithInvariantCulture("Default", styleString))
                {
                    fontWieght = FontWeights.Normal;
                    goto IL_01b6;
                }
                return(false);
            }
            return(false);

IL_01b6:
            return(true);
        }
Exemplo n.º 3
0
        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);
                }
            }
        }
Exemplo n.º 4
0
 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);
             }
         }
     }
 }
Exemplo n.º 5
0
        private void ParseParagraphElement(HtmlElement.HtmlElementType elementType, FunctionalList <ListStyle> listStyles)
        {
            this.CloseParagraph();
            if (base.m_currentParagraph.ElementType == HtmlElement.HtmlElementType.P)
            {
                base.m_currentParagraph = base.m_currentParagraph.RemoveParagraph(HtmlElement.HtmlElementType.P);
                base.m_currentStyle     = base.m_currentStyle.RemoveStyle(HtmlElement.HtmlElementType.P);
            }
            if (elementType == HtmlElement.HtmlElementType.LI)
            {
                this.FlushPendingLI();
                if (listStyles.Count > 0)
                {
                    base.m_currentParagraph.ListStyle = listStyles.First;
                }
                else
                {
                    base.m_currentParagraph.ListStyle = ListStyle.Bulleted;
                }
            }
            else
            {
                base.m_currentStyle     = base.m_currentStyle.CreateChildStyle(elementType);
                base.m_currentParagraph = base.m_currentParagraph.CreateChildParagraph(elementType);
                switch (elementType)
                {
                case HtmlElement.HtmlElementType.H1:
                    base.m_currentStyle.FontSize   = StyleDefaults.H1FontSize;
                    base.m_currentStyle.FontWeight = FontWeights.Bold;
                    this.SetMarginTopAndBottom(StyleDefaults.H1Margin);
                    break;

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

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

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

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

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

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