Пример #1
0
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] HeadingBlock obj)
        {
            var paragraph = new Paragraph()
            {
                Tag = obj
            };

            switch (obj.Level)
            {
            case 1: renderer.Styles.ApplyHeading1Style(paragraph); break;

            case 2: renderer.Styles.ApplyHeading2Style(paragraph); break;

            case 3: renderer.Styles.ApplyHeading3Style(paragraph); break;

            case 4: renderer.Styles.ApplyHeading4Style(paragraph); break;

            case 5: renderer.Styles.ApplyHeading5Style(paragraph); break;

            case 6: renderer.Styles.ApplyHeading6Style(paragraph); break;
            }

            renderer.Push(paragraph);
            renderer.WriteLeafInline(obj);
            renderer.Pop();
        }
Пример #2
0
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] HeadingBlock obj)
        {
            var paragraph = new Paragraph();
            ComponentResourceKey styleKey = null;

            switch (obj.Level)
            {
            case 1: styleKey = Styles.Heading1StyleKey; break;

            case 2: styleKey = Styles.Heading2StyleKey; break;

            case 3: styleKey = Styles.Heading3StyleKey; break;

            case 4: styleKey = Styles.Heading4StyleKey; break;

            case 5: styleKey = Styles.Heading5StyleKey; break;

            case 6: styleKey = Styles.Heading6StyleKey; break;
            }

            if (styleKey != null)
            {
                paragraph.SetResourceReference(FrameworkContentElement.StyleProperty, styleKey);
            }

            renderer.Push(paragraph);
            renderer.WriteLeafInline(obj);
            renderer.Pop();
        }
Пример #3
0
        /// <inheritdoc/>
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] AutolinkInline link)
        {
            var url = link.Url;

            if (link.IsEmail)
            {
                url = "mailto:" + url;
            }

            if (!Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute))
            {
                url = "#";
            }

            var hyperlink = new Hyperlink
            {
                Command          = Commands.Hyperlink,
                CommandParameter = url,
                NavigateUri      = new Uri(url, UriKind.RelativeOrAbsolute),
                ToolTip          = link.Url,
            };

            hyperlink.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.HyperlinkStyleKey);

            renderer.Push(hyperlink);
            renderer.WriteText(link.Url);
            renderer.Pop();
        }
        /// <inheritdoc/>
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] LinkInline link)
        {
            var url = link.GetDynamicUrl != null?link.GetDynamicUrl() ?? link.Url : link.Url;

            if (!Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute))
            {
                url = "#";
            }

            if (link.IsImage)
            {
                var image = new Image
                {
                    Source = new BitmapImage(new Uri(url))
                };

                image.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.ImageStyleKey);

                renderer.WriteInline(new InlineUIContainer(image));
            }
            else
            {
                var hyperlink = new Hyperlink
                {
                    Command          = Commands.Hyperlink,
                    CommandParameter = url,
                    NavigateUri      = new Uri(url, UriKind.RelativeOrAbsolute),
                    ToolTip          = link.Title != string.Empty ? link.Title : null,
                };

                renderer.Push(hyperlink);
                renderer.WriteChildren(link);
                renderer.Pop();
            }
        }
Пример #5
0
        public static FlowDocument ToFlowDocument([NotNull] string markdown, MarkdownPipeline pipeline = null, WpfRenderer renderer = null)
        {
            if (markdown == null)
            {
                throw new ArgumentNullException(nameof(markdown));
            }
            pipeline = pipeline ?? new MarkdownPipelineBuilder().Build();

            // We override the renderer with our own writer
            var result = new FlowDocument();

            if (renderer == null)
            {
                renderer = new WpfRenderer(result);
            }
            else
            {
                renderer.LoadDocument(result);
            }

            pipeline.Setup(renderer);

            var document = Markdig.Markdown.Parse(markdown, pipeline);

            renderer.Render(document);

            return(result);
        }
Пример #6
0
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] CodeBlock obj)
        {
            var paragraph = new Paragraph()
            {
                Tag = obj
            };

            renderer.Styles.ApplyCodeBlockStyle(paragraph);
            renderer.Push(paragraph);

            if (obj.Inline != null)
            {
                // there was a post-processor which has already processed the lines in this code block
                renderer.WriteChildren(obj.Inline);
            }
            else // there was no post-processor - we have to do the writing of the code lines
            {
                // original code: renderer.WriteLeafRawLines(obj); // Expand this call directly here in order to be able to include tags
                var lines = obj.Lines;
                if (lines.Lines != null)
                {
                    var slices = lines.Lines;
                    for (var i = 0; i < lines.Count; i++)
                    {
                        renderer.WriteInline(new Run(slices[i].Slice.ToString()));
                        renderer.WriteInline(new LineBreak());
                    }
                }
            }

            renderer.Pop();
        }
 /// <inheritdoc/>
 protected override void Write([NotNull] WpfRenderer renderer, [NotNull] LineBreakInline obj)
 {
     if (obj.IsHard)
     {
         renderer.WriteInline(new LineBreak());
     }
 }
Пример #8
0
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] CodeInline obj)
        {
            var span = new Span()
            {
                Tag = obj
            };

            renderer.Styles.ApplyCodeStyle(span);

            var run = new Run("\x202F"); // Narrow fixed space

            run.FontStretch = FontStretches.UltraCondensed;
            span.Inlines.Add(run);

            run = new Run(obj.Content.Replace(" ", "\xA0"))
            {
                Tag = obj
            };                                                             // Replace Space with fixed space
            span.Inlines.Add(run);

            run             = new Run("\x202F");            // Narrow fixed space
            run.FontStretch = FontStretches.UltraCondensed; // has an effect only for non fixed space fonts
            span.Inlines.Add(run);

            renderer.WriteInline(span);
        }
Пример #9
0
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] ListBlock listBlock)
        {
            var list = new List();

            if (listBlock.IsOrdered)
            {
                list.MarkerStyle = TextMarkerStyle.Decimal;

                if (listBlock.OrderedStart != null && (listBlock.DefaultOrderedStart != listBlock.OrderedStart))
                {
                    list.StartIndex = int.Parse(listBlock.OrderedStart);
                }
            }
            else
            {
                list.MarkerStyle = TextMarkerStyle.Disc;
            }

            renderer.Push(list);

            foreach (var item in listBlock)
            {
                var listItemBlock = (ListItemBlock)item;
                var listItem      = new ListItem();
                renderer.Push(listItem);
                renderer.WriteChildren(listItemBlock);
                renderer.Pop();
            }

            renderer.Pop();
        }
Пример #10
0
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] CodeInline obj)
        {
            var run = new Run(obj.Content);

            run.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.CodeStyleKey);
            renderer.WriteInline(run);
        }
Пример #11
0
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] EmphasisInline obj)
        {
            Span span = null;

            switch (obj.DelimiterChar)
            {
            case '*':
            case '_':
                span = obj.IsDouble ? (Span) new Bold() : new Italic();
                break;

            case '~':
                span = new Span();
                if (obj.IsDouble)
                {
                    renderer.Styles.ApplyStrikeThroughStyle(span);
                }
                else
                {
                    renderer.Styles.ApplySubscriptStyle(span);
                    if (span.FontSize < 1)
                    {
                        span.FontSize = renderer.CurrentFontSize() * span.FontSize;
                    }
                }
                break;

            case '^':
                span = new Span();
                renderer.Styles.ApplySuperscriptStyle(span);
                if (span.FontSize < 1)
                {
                    span.FontSize = renderer.CurrentFontSize() * span.FontSize;
                }
                break;

            case '+':
                span = new Span();
                renderer.Styles.ApplyInsertedStyle(span);
                break;

            case '=':
                span = new Span();
                renderer.Styles.ApplyMarkedStyle(span);
                break;
            }

            if (span != null)
            {
                span.Tag = obj;
                renderer.Push(span);
                renderer.WriteChildren(obj);
                renderer.Pop();
            }
            else
            {
                renderer.WriteChildren(obj);
            }
        }
Пример #12
0
        /// <inheritdoc/>
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] ParagraphBlock obj)
        {
            var paragraph = new Paragraph();

            renderer.Push(paragraph);
            renderer.WriteLeafInline(obj);
            renderer.Pop();
        }
Пример #13
0
        /// <inheritdoc/>
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] QuoteBlock obj)
        {
            var section = new Section();

            renderer.Push(section);
            renderer.WriteChildren(obj);
            section.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.QuoteBlockStyleKey);
            renderer.Pop();
        }
Пример #14
0
        /// <inheritdoc/>
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] LiteralInline obj)
        {
            if (obj.Content.IsEmpty)
            {
                return;
            }

            renderer.WriteText(ref obj.Content);
        }
Пример #15
0
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] CodeBlock obj)
        {
            var paragraph = new Paragraph();

            paragraph.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.CodeBlockStyleKey);
            renderer.Push(paragraph);
            renderer.WriteLeafRawLines(obj);
            renderer.Pop();
        }
Пример #16
0
        protected override void Write([NotNull] WpfRenderer renderer, EmphasisInline obj)
        {
            var inline = GetInline(obj);

            // TODO: "render" the inline
            renderer.WriteChildren(obj);
            // TODO: add children to the inline
            // Note: could be a push/pop API with a stack. Pop automatically adds children into the inline and removes it from the stack.
        }
Пример #17
0
        /// <inheritdoc/>
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] ParagraphBlock obj)
        {
            var paragraph = new Paragraph();

            renderer.BeginBlock(paragraph);
            renderer.WriteLeafInline(obj);

            paragraph.Inlines.AddRange(renderer.Inlines);
            renderer.EndBlock();
        }
Пример #18
0
        public GameWindow()
        {
            InitializeComponent();
            this.InitializeComponent();
            var wpfRenderer = new WpfRenderer(this.GameCanvas);

            this.Engine = new GameEngine(wpfRenderer);
            this.Engine.InitGame();
            this.Engine.StartGame();
        }
Пример #19
0
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] Markdig.Extensions.Figures.FigureCaption obj)
        {
            Paragraph paragraph = new Paragraph()
            {
                Tag = obj
            };

            renderer.Push(paragraph);
            renderer.WriteLeafInline(obj);
            renderer.Pop();
        }
Пример #20
0
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] TaskList taskList)
        {
            var checkBox = new CheckBox
            {
                IsEnabled = false,
                IsChecked = taskList.Checked,
            };

            checkBox.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.TaskListStyleKey);
            renderer.WriteInline(new InlineUIContainer(checkBox));
        }
Пример #21
0
        /// <inheritdoc/>
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] LiteralInline obj)
        {
            if (obj.Content.IsEmpty)
            {
                return;
            }

            renderer.WriteInline(new Run(obj.Content.ToString())
            {
                Tag = obj
            });
        }
Пример #22
0
        /// <inheritdoc/>
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] HtmlEntityInline obj)
        {
            if (obj.Transcoded.IsEmpty)
            {
                return;
            }

            renderer.WriteInline(new Run(obj.Transcoded.ToString())
            {
                Tag = obj
            });
        }
Пример #23
0
 /// <inheritdoc/>
 protected override void Write([NotNull] WpfRenderer renderer, [NotNull] LineBreakInline obj)
 {
     if (obj.IsHard)
     {
         renderer.WriteInline(new LineBreak());
     }
     else
     {
         // Soft line break.
         renderer.WriteText(" ");
     }
 }
Пример #24
0
        /// <inheritdoc/>
        protected override void Write(WpfRenderer renderer, LinkInline link)
        {
            if (renderer == null)
            {
                throw new ArgumentNullException(nameof(renderer));
            }
            if (link == null)
            {
                throw new ArgumentNullException(nameof(link));
            }

            var url = link.GetDynamicUrl != null?link.GetDynamicUrl() ?? link.Url : link.Url;

            if (!Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute))
            {
                url = "#";
            }

            if (link.IsImage)
            {
                var template = new ControlTemplate();
                var image    = new FrameworkElementFactory(typeof(Image));
                image.SetValue(Image.SourceProperty, new BitmapImage(new Uri(url, UriKind.RelativeOrAbsolute)));
                image.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.ImageStyleKey);
                template.VisualTree = image;

                var btn = new Button()
                {
                    Template         = template,
                    Command          = Commands.Image,
                    CommandParameter = url
                };

                renderer.WriteInline(new InlineUIContainer(btn));
            }
            else
            {
                var hyperlink = new Hyperlink
                {
                    Command          = Commands.Hyperlink,
                    CommandParameter = url,
                    NavigateUri      = new Uri(url, UriKind.RelativeOrAbsolute),
                    ToolTip          = !string.IsNullOrEmpty(link.Title) ? link.Title : null,
                };

                hyperlink.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.HyperlinkStyleKey);

                renderer.Push(hyperlink);
                renderer.WriteChildren(link);
                renderer.Pop();
            }
        }
        protected override void Write(WpfRenderer renderer, EmphasisInline obj)
        {
            if (renderer == null)
            {
                throw new ArgumentNullException(nameof(renderer));
            }
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            Span?span = null;

            switch (obj.DelimiterChar)
            {
            case '*':
            case '_':
                span = obj.DelimiterCount == 2 ? (Span) new Bold() : new Italic();
                break;

            case '~':
                span = new Span();
                span.SetResourceReference(FrameworkContentElement.StyleProperty, obj.DelimiterCount == 2 ? Styles.StrikeThroughStyleKey : Styles.SubscriptStyleKey);
                break;

            case '^':
                span = new Span();
                span.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.SuperscriptStyleKey);
                break;

            case '+':
                span = new Span();
                span.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.InsertedStyleKey);
                break;

            case '=':
                span = new Span();
                span.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.MarkedStyleKey);
                break;
            }

            if (span != null)
            {
                renderer.Push(span);
                renderer.WriteChildren(obj);
                renderer.Pop();
            }
            else
            {
                renderer.WriteChildren(obj);
            }
        }
Пример #26
0
        /// <inheritdoc/>
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] QuoteBlock obj)
        {
            var section = new Section()
            {
                Tag = obj
            };

            renderer.Styles.ApplyQuoteBlockStyle(section);

            renderer.Push(section);
            renderer.WriteChildren(obj);
            renderer.Pop();
        }
Пример #27
0
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] TaskList taskList)
        {
            var checkBox = new CheckBox
            {
                IsEnabled = false,
                IsChecked = taskList.Checked
            };

            renderer.Styles.ApplyTaskListStyle(checkBox);
            renderer.WriteInline(new InlineUIContainer(checkBox)
            {
                Tag = taskList
            });
        }
Пример #28
0
        /// <inheritdoc/>
        protected override void Write(WpfRenderer renderer, DelimiterInline obj)
        {
            if (renderer == null)
            {
                throw new ArgumentNullException(nameof(renderer));
            }
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            renderer.WriteText(obj.ToLiteral());
            renderer.WriteChildren(obj);
        }
Пример #29
0
        protected override void Write(WpfRenderer renderer, CodeBlock obj)
        {
            if (renderer == null)
            {
                throw new ArgumentNullException(nameof(renderer));
            }

            var paragraph = new Paragraph();

            paragraph.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.CodeBlockStyleKey);
            renderer.Push(paragraph);
            renderer.WriteLeafRawLines(obj);
            renderer.Pop();
        }
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] ThematicBreakBlock obj)
        {
            var line = new System.Windows.Shapes.Line {
                X2 = 1
            };

            line.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.ThematicBreakStyleKey);

            var paragraph = new Paragraph
            {
                Inlines = { new InlineUIContainer(line) }
            };

            renderer.WriteBlock(paragraph);
        }
Пример #31
0
 public MainWindow(IRace selectedPlayerRace)
 {
     InitializeComponent();
     try
     {
         var renderer = new WpfRenderer(this.GameCanvas);
         var inputHandlerer = new WpfInputHandlerer(this.GameCanvas);
         this.Engine = new GameEngine(renderer, inputHandlerer);
         this.Engine.InitGame(selectedPlayerRace);
         this.Engine.StartGame();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Пример #32
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="containers"></param>
        public static void Show(IList<Container> containers)
        {
            var renderer = new WpfRenderer();
            renderer.State.DrawShapeState.Flags = ShapeStateFlags.Printable;

            var sw = new ScrollViewer()
            {
                HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                VerticalScrollBarVisibility = ScrollBarVisibility.Auto
            };

            var sp = new StackPanel()
            {
                Margin = new Thickness(5),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            sw.Content = sp;

            foreach (var container in containers)
            {
                var vb = ToViewbox(container, renderer);
                vb.Margin = new Thickness(5);
                sp.Children.Add(vb);
            }

            var window = new Window()
            {
                Title = "Core2D Viewer",
                Width = 900,
                Height = 680,
                WindowStartupLocation = WindowStartupLocation.CenterScreen,
                SnapsToDevicePixels = true,
                UseLayoutRounding = true
            };
            TextOptions.SetTextFormattingMode(window, TextFormattingMode.Display);

            window.Content = sw;
            window.ShowDialog();
        }