Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] MathInline obj)
        {
            var text = obj.Content.Text.Substring(obj.Content.Start, obj.Content.Length);

            TexFormula formula = null;

            try
            {
                formula = formulaParser.Parse(text);
            }
            catch (Exception)
            {
                renderer.WriteInline(new Run("[!!FORMULA PARSE ERROR!!]")
                {
                    Tag = obj
                });
                return;
            }

            var fontSize        = renderer.CurrentFontSize();
            var formulaRenderer = formula.GetRenderer(TexStyle.Display, fontSize, "Arial");
            var geo             = formulaRenderer.RenderToGeometry(0, 0);
            var geoD            = new System.Windows.Media.GeometryDrawing(Brushes.Black, null, geo);
            var di      = new DrawingImage(geoD);
            var uiImage = new System.Windows.Controls.Image()
            {
                Source = di
            };

            uiImage.Height = formulaRenderer.RenderSize.Height;                                                                         // size image to match rendersize -> get a zoom of 100%
            uiImage.Margin = new System.Windows.Thickness(0, 0, 0, -formulaRenderer.RenderSize.Height * formulaRenderer.RelativeDepth); // Move image so that baseline matches that of text
            var uiInline = new System.Windows.Documents.InlineUIContainer()
            {
                Child             = uiImage,
                Background        = Brushes.Yellow,
                BaselineAlignment = System.Windows.BaselineAlignment.Baseline,
                Tag = obj,
            };

            renderer.WriteInline(uiInline);
        }
Esempio n. 3
0
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] MathBlock obj)
        {
            string text = string.Empty; // obj.Content.Text.Substring(obj.Content.Start, obj.Content.Length);

            for (int i = 0; i < obj.Lines.Count; ++i)
            {
                var l = obj.Lines.Lines[i];
                text += l.Slice.Text.Substring(l.Slice.Start, l.Slice.Length);
            }

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            TexFormula formula = null;

            try
            {
                formula = formulaParser.Parse(text);
            }
            catch (Exception)
            {
                var paragraph = new Paragraph()
                {
                    Tag = obj
                };
                renderer.Push(paragraph);
                renderer.WriteInline(new Run("[!!FORMULA PARSE ERROR!!]")
                {
                    Tag = obj
                });
                renderer.Pop();
                return;
            }

            var fontSize = renderer.CurrentFontSize();

            if (fontSize <= 0)
            {
                throw new InvalidProgramException();
            }

            var formulaRenderer = formula.GetRenderer(TexStyle.Display, fontSize, "Arial");
            var geo             = formulaRenderer.RenderToGeometry(0, 0);
            var geoD            = new System.Windows.Media.GeometryDrawing(Brushes.Black, null, geo);
            var di      = new DrawingImage(geoD);
            var uiImage = new System.Windows.Controls.Image()
            {
                Source = di
            };

            uiImage.Height = formulaRenderer.RenderSize.Height; // size image to match rendersize -> get a zoom of 100%
            // uiImage.Margin = new System.Windows.Thickness(0, 0, 0, -formulaRenderer.RenderSize.Height * formulaRenderer.RelativeDepth); // Move image so that baseline matches that of text
            var uiBlock = new System.Windows.Documents.BlockUIContainer()
            {
                Child = uiImage,
                Tag   = obj,
            };

            renderer.WriteBlock(uiBlock);
        }