Пример #1
0
        public static void FormatText(Md2MlEngine core, Paragraph paragraph, string markdown, FontProperties fontProperties)
        {
            var hasPattern = PatternMatcher.HasPatterns(markdown);

            while (hasPattern)
            {
                var s                 = PatternMatcher.GetPatternsAndNonPatternText(markdown);
                var count             = s.Value.Count();
                var NewFontProperties = new FontProperties();
                switch (s.Key)
                {
                case RunPattern.BoldAndItalic:
                    NewFontProperties.Bold   = true;
                    NewFontProperties.Italic = true;
                    FormatText(core, paragraph, s.Value[0], new FontProperties());
                    FormatText(core, paragraph, s.Value[1], NewFontProperties);
                    FormatText(core, paragraph, FramePendingString(s.Value, "***"), new FontProperties());
                    break;

                case RunPattern.Bold:
                    NewFontProperties.Bold = true;
                    FormatText(core, paragraph, s.Value[0], new FontProperties());
                    FormatText(core, paragraph, s.Value[1], NewFontProperties);
                    FormatText(core, paragraph, FramePendingString(s.Value, "**"), new FontProperties());
                    break;

                case RunPattern.Italic:
                    NewFontProperties.Italic = true;
                    FormatText(core, paragraph, s.Value[0], new FontProperties());
                    FormatText(core, paragraph, s.Value[1], NewFontProperties);
                    FormatText(core, paragraph, FramePendingString(s.Value, "*"), new FontProperties());
                    break;

                case RunPattern.MonospaceOrCode:
                    NewFontProperties.StyleName = "InlineCodeChar";
                    FormatText(core, paragraph, s.Value[0], new FontProperties());
                    FormatText(core, paragraph, s.Value[1], NewFontProperties);
                    FormatText(core, paragraph, FramePendingString(s.Value, "`"), new FontProperties());
                    break;

                case RunPattern.Strikethrough:
                    NewFontProperties.Strikeout = true;
                    FormatText(core, paragraph, s.Value[0], new FontProperties());
                    FormatText(core, paragraph, s.Value[1], NewFontProperties);
                    FormatText(core, paragraph, FramePendingString(s.Value, "~~"), new FontProperties());
                    break;

                case RunPattern.Underline:
                    NewFontProperties.Underline = UnderlineValues.Single;
                    FormatText(core, paragraph, s.Value[0], new FontProperties());
                    FormatText(core, paragraph, s.Value[1], NewFontProperties);
                    FormatText(core, paragraph, FramePendingString(s.Value, "__"), new FontProperties());
                    break;
                }
                return;
            }
            core.WriteText(paragraph, markdown, fontProperties);
        }
Пример #2
0
        public void WriteText(Paragraph paragraph, string text, FontProperties fontProperties)
        {
            Run           run = new Run();
            RunProperties rp  = new RunProperties();

            if (fontProperties.StyleName != null)
            {
                rp.Append(new RunStyle()
                {
                    Val = fontProperties.StyleName
                });
            }
            if (fontProperties.FontName != null)
            {
                rp.Append(new RunFonts()
                {
                    ComplexScript = fontProperties.FontName, Ascii = fontProperties.FontName, HighAnsi = fontProperties.FontName
                });
            }
            else if (fontProperties.UseTemplateHeadingFont)
            {
                rp.Append(new RunFonts()
                {
                    AsciiTheme = ThemeFontValues.MajorHighAnsi, HighAnsiTheme = ThemeFontValues.MajorHighAnsi, ComplexScriptTheme = ThemeFontValues.MajorHighAnsi
                });
            }
            if (fontProperties.FontSize != null)
            {
                rp.Append(new FontSize()
                {
                    Val = fontProperties.FontSize
                });
            }
            if (fontProperties.Bold)
            {
                rp.Append(new Bold());
            }
            if (fontProperties.Italic)
            {
                rp.Append(new Italic());
            }
            if (fontProperties.Underline != UnderlineValues.None)
            {
                rp.Append(new Underline()
                {
                    Val = fontProperties.Underline
                });
            }
            if (fontProperties.Strikeout)
            {
                rp.Append(new Strike());
            }
            if (fontProperties.WriteAs != VerticalPositionValues.Baseline)
            {
                rp.Append(new VerticalTextAlignment()
                {
                    Val = fontProperties.WriteAs
                });
            }
            if (fontProperties.UseThemeColor)
            {
                rp.Append(new DocumentFormat.OpenXml.Wordprocessing.Color()
                {
                    ThemeColor = fontProperties.ThemeColor
                });
            }
            else if (fontProperties.Color != null)
            {
                rp.Append(new DocumentFormat.OpenXml.Wordprocessing.Color()
                {
                    Val = string.Format("#{0:X2}{1:X2}{2:X2}", fontProperties.Color.Value.R, fontProperties.Color.Value.G, fontProperties.Color.Value.B)
                });
            }
            run.Append(rp);
            run.Append(new Text(text)
            {
                Space = SpaceProcessingModeValues.Preserve
            });
            paragraph.Append(run);
        }
Пример #3
0
 public void WriteText(string text, FontProperties fontProperties) => WriteText(CreateParagraph(), text, fontProperties);