public void InsertParagraph(BlockCollection block, InlineCollection inlineCollection, IEnumerable <RichTextItem> items)
 {
     foreach (var item in items)
     {
         if (item.TextType == RichTextType.Text)
         {
             inlineCollection.Add(new Run(item.Text)
             {
                 Foreground = new SolidColorBrush(item.Foreground)
             });
         }
         else if (item.TextType == RichTextType.Hyperlink)
         {
             var hyperlink = new Hyperlink()
             {
                 NavigateUri = new Uri(item.Link)
             };
             InsertParagraph(block, hyperlink.Inlines, item.Children);
             inlineCollection.Add(hyperlink);
         }
         else
         {
             var paragraph = new Paragraph()
             {
                 Margin = new Thickness(0, 3, 0, 3)
             };
             InsertParagraph(block, paragraph.Inlines, item.Children);
             block.Add(paragraph);
         }
     }
 }
        public void AddInlines(InlineCollection inlines)
        {
            if (this.Parts == null)
            {
                this.CreateParts();
            }

            foreach (EmojiStringPart part in this.Parts)
            {
                switch (part)
                {
                case EmojiPart emoji:
                    Image image = new Image
                    {
                        Source = new BitmapImage(new Uri(emoji.FileName)),
                        Height = 16,
                        Width  = 16,
                        Margin = new Thickness(0)
                    };
                    RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.HighQuality);
                    inlines.Add(image);
                    break;

                case TextPart text:
                    inlines.Add(new Run(text.Content));
                    break;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Loops through children of an <see cref="INode"/> and appends as <see cref="Inline"/> to given <see cref="InlineCollection"/>.
        /// </summary>
        /// <param name="node">The parent <see cref="INode"/>.</param>
        /// <param name="inlines">The <see cref="InlineCollection"/> collection to add inlines to.</param>
        protected void AddInlineChildren(INode node, InlineCollection inlines)
        {
            bool isInDiv = false;

            if (node.NodeName == "DIV")
            {
                isInDiv = true;
            }
            if (isInDiv)
            {
                inlines.Add(new LineBreak());
            }
            foreach (var child in node.ChildNodes)
            {
                var inline = GenerateInlineForNode(child, inlines);

                try
                {
                    if (inlines.LastOrDefault() != inline)
                    {
                        inlines.Add(inline);
                    }
                }
                catch (ArgumentException exception)
                {
                    System.Diagnostics.Debug.WriteLine(exception.Message);
                }
            }
            if (isInDiv)
            {
                inlines.Add(new LineBreak());
            }
        }
Exemple #4
0
        Span RenderBlockContent(InlineCollection inlines, ListContext list, XElement e, int blockType)
        {
            if (inlines.LastInline != null && inlines.LastInline is LineBreak == false)
            {
                inlines.AppendLineWithMargin();
            }
            if (blockType == BLOCK_ITEM)
            {
                PopulateListNumber(inlines, list);
            }
            else
            {
                ParagraphCount++;
            }
            var span = new Span();

            if (_isCode > 0)
            {
                span.FontFamily = GetCodeFont();
            }
            if (blockType == BLOCK_TITLE)
            {
                span.FontWeight = System.Windows.FontWeights.Bold;
            }
            inlines.Add(span);
            InternalRender(e, span.Inlines, list);
            if (blockType != BLOCK_ITEM && e.NextNode != null &&
                IsInlineElementName((e.NextNode as XElement)?.Name.LocalName) == false)
            {
                inlines.Add(new LineBreak());
            }
            return(span);
        }
Exemple #5
0
        static void AddParameterModifier(SymbolFormatter formatter, InlineCollection inlines, IParameterSymbol p)
        {
            switch (p.RefKind)
            {
            case RefKind.Ref:
                inlines.Add(new Run("ref ")
                {
                    Foreground = formatter.Keyword
                });
                return;

            case RefKind.Out:
                inlines.Add(new Run("out ")
                {
                    Foreground = formatter.Keyword
                });
                return;

            case RefKind.In:
                inlines.Add(new Run("in ")
                {
                    Foreground = formatter.Keyword
                });
                return;
            }
            if (p.IsParams)
            {
                inlines.Add(new Run("params ")
                {
                    Foreground = formatter.Keyword
                });
            }
        }
Exemple #6
0
        private static void PutDate(InlineCollection inline, DateTime time)
        {
            Run text = new Run(time.ToString("M/d"));

            inline.Add(text);
            inline.Add(new LineBreak());
        }
        public static void Format(string message, InlineCollection collection)
        {
            UrlMatch urlMatch;
            int cur = 0;

            while (UrlMatcher.TryGetMatch(message, cur, out urlMatch))
            {
                string before = message.Substring(cur, urlMatch.Offset - cur);
                if (before.Length > 0)
                    collection.Add(new Run(before));

                var matchRun = new Run(urlMatch.Text);
                try
                {
                    Hyperlink link = new Hyperlink(matchRun);
                    link.NavigateUri = new Uri(urlMatch.Text);
                    link.RequestNavigate += hlink_RequestNavigate;
                    collection.Add(link);
                }
                catch
                {
                    collection.Add(matchRun);
                }

                cur = urlMatch.Offset + urlMatch.Text.Length;
            }

            string ending = message.Substring(cur);
            if (ending.Length > 0)
                collection.Add(new Run(ending));
        }
Exemple #8
0
        private void ContentToTextBlock(string str, InlineCollection inlines)
        {
            //<p>タグ部を改行タグ<br/>に置き換え
            var    ms     = reg_p.Matches(str);
            string result = ms[0].Value;

            for (int i = 1; i < ms.Count; i++)
            {
                result += "<br />" + ms[i].Value;
            }

            //文章全体を対象に<a>タグを検索し、リンクを作成する
            Match  m;
            string after = result;

            while ((m = reg_a.Match(after)).Success)
            {
                inlines.Add(reg_br.Replace(m.Groups[1].Value, "\n"));
                XElement xlink = XDocument.Parse(m.Groups[2].Value).Element("a");
                string   uri   = xlink.Attribute("href").Value;

                string text = "";

                if (xlink.Attribute("rel").Value == "tag")
                {
                    text = xlink.Value;
                }
                else
                {
                    foreach (XElement span in xlink.Elements("span"))
                    {
                        bool b = true;
                        foreach (XAttribute att in span.Attributes())
                        {
                            b = !(att.Name == "class" && att.Value == "invisible");
                        }
                        if (b)
                        {
                            text += span.Value;
                        }
                    }
                }

                var link = new Hyperlink()
                {
                    NavigateUri = new Uri(uri)
                };
                link.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler((obj, e) =>
                {
                    System.Diagnostics.Process.Start(e.Uri.AbsoluteUri);
                });
                link.Inlines.Add(text);
                inlines.Add(link);

                after = m.Groups[3].Value;
            }
            inlines.Add(reg_br.Replace(after, "\n"));
        }
Exemple #9
0
 public static InlineCollection AppendLineWithMargin(this InlineCollection inlines)
 {
     inlines.Add(new LineBreak());
     inlines.Add(new InlineUIContainer(new Border {
         Width = 1, Height = 3
     }));
     inlines.Add(new LineBreak());
     return(inlines);
 }
Exemple #10
0
 internal static void Analyse(HtmlNode node, InlineCollection container, ParsingStyle style)
 {
     if (node == null)
         return;
     foreach (var item in node.ChildNodes)
     {
         switch (item.Name)
         {
             //文本
             case "#text":
                 container.Add(new Run() { Text = item.InnerText });
                 continue;
             case "strong":
                 style = style | ParsingStyle.Bold;
                 break;
             //链接
             case "a":
                 var link = new Hyperlink();
                 ParseRelativeUrl(item.GetAttributeValue("href", ""), link, App.Current.NavigationService);
                 Analyse(item, link.Inlines, style);
                 container.Add(link);
                 continue;
             //图片
             case "img":
                 var image = new Image() { Source = new BitmapImage(new Uri(item.GetAttributeValue("src", ""))) };
                 var cont = new InlineUIContainer();
                 cont.Child = image;
                 container.Add(cont);
                 continue;
             //换行
             case "br":
                 container.Add(new LineBreak());
                 continue;
             //容器
             case "span":
             case "div":
             case "p":
                 break;
             case "b":
                 //TODO: 设置属性,是否要加红搜索显示结果
                 if(node.GetAttributeValue("class","") == "key_red")
                 {
                     Span p = new Span();
                     p.Foreground = new SolidColorBrush(Colors.Red);
                     Analyse(item, container, style);
                     continue;
                 }
                 else break;
             //非文本
             case "button":
                 continue;
             default:
                 continue;
         }
         Analyse(item, container, style);
     }
 }
Exemple #11
0
 void replaceInlines(InlineCollection ic)
 {
     ic.Clear(); dualFontSize(ic, fsz, PrgPosition); ic.Add((new Run()
     {
         Text = " · "
     })); dualFontSize(ic, fsz, PrgDuration - PrgPosition); ic.Add((new Run()
     {
         Text = "\n", FontSize = 1
     })); dualFontSize(ic, fsz, PrgDuration);
 }
Exemple #12
0
        internal void RenderXmlDocSymbol(string symbol, InlineCollection inlines, SymbolKind symbolKind)
        {
            switch (symbolKind)
            {
            case SymbolKind.Parameter:
                inlines.Add(symbol.Render(false, _SymbolFormatter.Parameter == null, _SymbolFormatter.Parameter));
                return;

            case SymbolKind.TypeParameter:
                inlines.Add(symbol.Render(_SymbolFormatter.TypeParameter == null, false, _SymbolFormatter.TypeParameter));
                return;

            case SymbolKind.DynamicType:
                // highlight keywords
                inlines.Add(symbol.Render(_SymbolFormatter.Keyword));
                return;
            }
            var s = DocumentationCommentId.GetFirstSymbolForDeclarationId(symbol, _Compilation);

            if (s != null)
            {
                _SymbolFormatter.Format(inlines, s, null, false);
                return;
            }
            if (symbol.Length > 2 && symbol[1] == ':')
            {
                switch (symbol[0])
                {
                case 'T':
                    inlines.Add(symbol.Substring(2).Render(false, true, _SymbolFormatter.Class));
                    return;

                case 'M':
                    inlines.Add(symbol.Substring(2).Render(false, true, _SymbolFormatter.Method));
                    return;

                case 'P':
                    inlines.Add(symbol.Substring(2).Render(false, true, _SymbolFormatter.Property));
                    return;

                case 'F':
                    inlines.Add(symbol.Substring(2).Render(false, true, _SymbolFormatter.Field));
                    return;

                case 'E':
                    inlines.Add(symbol.Substring(2).Render(false, true, _SymbolFormatter.Delegate));
                    return;

                case '!':
                    inlines.Add(symbol.Substring(2).Render(true, true, null));
                    return;
                }
            }
            inlines.Add(symbol);
        }
        public void CreateTweetBody(string text, InlineCollection inlines)
        {
            Match            m      = TwitterStatusViewer.TweetRegex.Match(text);
            int              last   = 0;
            List <Hyperlink> images = null;

            while (m.Success)
            {
                inlines.Add(text.Substring(last, m.Index - last));
                if (m.Success)
                {
                    Hyperlink link = CreateHyperlink(m.Value, m.Value, TwitterStatusViewer.LinkForegroundProperty, this.FontWeight, Hyperlink_Click);
                    inlines.Add(link);

                    foreach (IInlineImageUrlHandler handler in InlineImageSites)
                    {
                        string picurl = handler.Process(m.Value);
                        if (picurl == null)
                        {
                            continue;
                        }
                        Hyperlink imgLink = new Hyperlink {
                            Tag = m.Value
                        };
                        imgLink.Click += Hyperlink_Click;
                        imgLink.Inlines.Add(new Image {
                            Source    = new BitmapImage(new Uri(picurl)),
                            Stretch   = Stretch.Uniform,
                            MaxWidth  = 50,
                            MaxHeight = 50
                        });
                        if (images == null)
                        {
                            images = new List <Hyperlink> ();
                        }
                        images.Add(imgLink);
                        break;
                    }
                }

                last = m.Index + m.Length;
                m    = m.NextMatch();
            }
            inlines.Add(text.Substring(last));

            if (images != null)
            {
                inlines.Add(Environment.NewLine);
                for (int i = 0; i < images.Count; i++)
                {
                    inlines.Add(images[i]);
                }
            }
        }
Exemple #14
0
        private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InlineCollection inlines = GetInlines(d);

            if (inlines == null)
            {
                return;
            }

            inlines.Clear();

            string            plainText            = GetPlainText(d) ?? string.Empty;
            IEnumerable <int> matchedCharPositions = GetMatchedCharPositions(d) ?? Enumerable.Empty <int>();
            Style             matchedCharStyle     = GetMatchedCharStyle(d);

            int nextPos       = 0;
            int matchRunStart = 0;

            foreach (int matchPos in matchedCharPositions.OrderBy(p => p).Where(p => p < plainText.Length))
            {
                if (matchPos != nextPos)
                {
                    AddMatchRun();

                    var nonMatchRun = new Run(plainText.Substring(nextPos, matchPos - nextPos));
                    inlines.Add(nonMatchRun);

                    matchRunStart = matchPos;
                }

                nextPos = matchPos + 1;
            }

            AddMatchRun();

            if (nextPos < plainText.Length)
            {
                var nonMatchRun = new Run(plainText.Substring(nextPos));
                inlines.Add(nonMatchRun);
            }

            void AddMatchRun()
            {
                if (matchRunStart < nextPos)
                {
                    var matchRun = new Run(plainText.Substring(matchRunStart, nextPos - matchRunStart))
                    {
                        Style = matchedCharStyle
                    };
                    inlines.Add(matchRun);
                }
            }
        }
Exemple #15
0
 void AddTypeArguments(InlineCollection text, ImmutableArray <ITypeParameterSymbol> arguments)
 {
     text.Add("<");
     for (int i = 0; i < arguments.Length; i++)
     {
         if (i > 0)
         {
             text.Add(", ");
         }
         text.Add(arguments[i].Name.Render(TypeParameter));
     }
     text.Add(">");
 }
Exemple #16
0
 void AddTypeArguments(InlineCollection text, ImmutableArray <ITypeSymbol> arguments)
 {
     text.Add("<");
     for (int i = 0; i < arguments.Length; i++)
     {
         if (i > 0)
         {
             text.Add(", ");
         }
         Format(text, arguments[i], null, false);
     }
     text.Add(">");
 }
Exemple #17
0
 void dualFontSize(InlineCollection ic, int fsz, TimeSpan ts)
 {
     if (ts.TotalMinutes > 60)
     {
         ic.Add((new Run($@"{ts:h\:mm}")));
     }
     else
     {
         ic.Add((new Run($@" {ts.Minutes}")));
     }
     ic.Add((new Run()
     {
         Text = $".{ts:ss}", FontSize = fsz
     }));
 }
Exemple #18
0
 static void AddPadding(InlineCollection inlines, int padding)
 {
     if (padding != 0)
     {
         inlines.Add(CreatePadding(padding));
     }
 }
        private static void InlinesSourcePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            InlineCollection inlines = null;

            if (obj is TextBlock)
            {
                inlines = ((TextBlock)obj).Inlines;
            }
            else if (obj is Paragraph)
            {
                inlines = ((Paragraph)obj).Inlines;
            }
#if NETFX_CORE || SILVERLIGHT
            else if (obj is RichTextBlock)
            {
                var paragraph = new Paragraph();
                inlines = paragraph.Inlines;
                var richTextBlock = (RichTextBlock)obj;
                richTextBlock.Blocks.Clear();
                richTextBlock.Blocks.Add(paragraph);
            }
#endif
            if (inlines != null)
            {
                inlines.Clear();

                foreach (var inline in TextToInlines((string)e.NewValue))
                {
                    inlines.Add(inline);
                }
            }
        }
Exemple #20
0
        /// <summary>
        /// Renders a bold run element.
        /// </summary>
        /// <param name="inlineCollection"> The list to add to. </param>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="context"> Persistent state. </param>
        private void RenderBoldRun(InlineCollection inlineCollection, BoldTextInline element, RenderContext context)
        {
            // Create the text run
            FontWeight weight = FontWeights.Bold;

            if (_halfopacity)
            {
                weight = FontWeights.SemiBold;
            }

            Span boldSpan = new Span
            {
                FontWeight = weight,
                Foreground = BoldForeground,
            };

            // Render the children into the bold inline.
            var newcontext = context.Clone();

            newcontext.Foreground = BoldForeground;
            RenderInlineChildren(boldSpan.Inlines, element.Inlines, boldSpan, newcontext);

            // Add it to the current inlines
            inlineCollection.Add(boldSpan);
        }
        void AddUpdatedImage(InlineCollection inlines)
        {
            var image = new Image()
            {
                Margin = new System.Windows.Thickness(0),
                Width  = 10,
                Height = 10
            };

            image.Source = ImageFactory.Instance.Load(new Uri("pack://application:,,,/Images/msg-edit.png", UriKind.Absolute));

            var container = new BlockUIContainer(image)
            {
                Margin  = new System.Windows.Thickness(0),
                Padding = new System.Windows.Thickness(0)
            };

            var floater = new Floater(container)
            {
                Width = 20,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
                BaselineAlignment   = System.Windows.BaselineAlignment.Top,
                Margin  = new System.Windows.Thickness(0),
                Padding = new System.Windows.Thickness(0)
            };

            inlines.Add(floater);
        }
Exemple #22
0
        /// <summary>
        /// Renders a superscript element.
        /// </summary>
        /// <param name="inlineCollection"> The list to add to. </param>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="parent"> The container element. </param>
        /// <param name="context"> Persistent state. </param>
        private void RenderSuperscriptRun(InlineCollection inlineCollection, SuperscriptTextInline element, TextElement parent, RenderContext context)
        {
            // Le <sigh>, InlineUIContainers are not allowed within hyperlinks.
            if (context.WithinHyperlink)
            {
                RenderInlineChildren(inlineCollection, element.Inlines, parent, context);
                return;
            }

            var paragraph = new Paragraph();

            paragraph.FontSize   = parent.FontSize * 0.8;
            paragraph.FontFamily = parent.FontFamily;
            paragraph.FontStyle  = parent.FontStyle;
            paragraph.FontWeight = parent.FontWeight;
            RenderInlineChildren(paragraph.Inlines, element.Inlines, paragraph, context);

            var richTextBlock = CreateOrReuseRichTextBlock(null, context);

            richTextBlock.Blocks.Add(paragraph);

            var border = new Border();

            border.Padding = new Thickness(0, 0, 0, paragraph.FontSize * 0.2);
            border.Child   = richTextBlock;

            var inlineUIContainer = new InlineUIContainer();

            inlineUIContainer.Child = border;

            // Add it to the current inlines
            inlineCollection.Add(inlineUIContainer);
        }
Exemple #23
0
        /// <summary>
        /// Renders a link element
        /// </summary>
        /// <param name="inlineCollection"> The list to add to. </param>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="parent"> The container element. </param>
        /// <param name="context"> Persistent state. </param>
        private void RenderMarkdownLink(InlineCollection inlineCollection, MarkdownLinkInline element, TextElement parent, RenderContext context)
        {
            // Avoid crash when link text is empty.
            if (element.Inlines.Count == 0)
            {
                return;
            }

            // Attempt to resolve references.
            element.ResolveReference(_document);
            if (element.Url == null)
            {
                // The element couldn't be resolved, just render it as text.
                RenderInlineChildren(inlineCollection, element.Inlines, parent, context);
                return;
            }

            // HACK: Superscript is not allowed within a hyperlink.  But if we switch it around, so
            // that the superscript is outside the hyperlink, then it will render correctly.
            // This assumes that the entire hyperlink is to be rendered as superscript.
            if (AllTextIsSuperscript(element) == false)
            {
                // Regular ol' hyperlink.
                var link = new Hyperlink();

                // Register the link
                _linkRegister.RegisterNewHyperLink(link, element.Url);

                // Remove superscripts.
                RemoveSuperscriptRuns(element, insertCaret: true);

                // Render the children into the link inline.
                var childContext = context.Clone();
                childContext.WithinHyperlink = true;
                RenderInlineChildren(link.Inlines, element.Inlines, link, childContext);
                context.TrimLeadingWhitespace = childContext.TrimLeadingWhitespace;

                // Add it to the current inlines
                inlineCollection.Add(link);
            }
            else
            {
                // THE HACK IS ON!

                // Create a fake superscript element.
                var fakeSuperscript = new SuperscriptTextInline
                {
                    Inlines = new List <MarkdownInline>
                    {
                        element
                    }
                };

                // Remove superscripts.
                RemoveSuperscriptRuns(element, insertCaret: false);

                // Now render it.
                RenderSuperscriptRun(inlineCollection, fakeSuperscript, parent, context);
            }
        }
Exemple #24
0
        /// <summary>
        /// Renders a strikethrough element.
        /// </summary>
        /// <param name="inlineCollection"> The list to add to. </param>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="context"> Persistent state. </param>
        private void RenderStrikethroughRun(InlineCollection inlineCollection, StrikethroughTextInline element, RenderContext context)
        {
            Span span = new Span
            {
                FontFamily = new FontFamily("Consolas")
            };

            // Render the children into the inline.
            RenderInlineChildren(span.Inlines, element.Inlines, span, context);

            AlterChildRuns(span, (parentSpan, run) =>
            {
                var text    = run.Text;
                var builder = new StringBuilder(text.Length * 2);
                foreach (var c in text)
                {
                    builder.Append((char)0x0336);
                    builder.Append(c);
                }
                run.Text = builder.ToString();
            });

            // Add it to the current inlines
            inlineCollection.Add(span);
        }
 private void AddElementToCollection(Inline elm, InlineCollection coll)
 {
     if (elm is InlineParaGraph)
     {
         //coll.Add(new LineBreak());
         coll.Add(new LineBreak());
     }
     else if (elm is Table)
     {
         coll.Add(new LineBreak());
     }
     else
     {
         coll.Add(elm);
     }
 }
        private void InnerWrite(FlowDocumentScrollViewer rtb, Paragraph p, string text, ConsoleColor foreground)
        {
            InlineCollection list = p.Inlines;

            // 满1000行删除500行
            if (list.Count > 1000)
            {
                int delLines = 500;
                while (delLines-- > 0)
                {
                    ((IList)list).RemoveAt(0);
                }
            }
            Run run = new Run(text)
            {
                Foreground = new SolidColorBrush(foreground.ToMediaColor())
            };

            list.Add(run);

            if (ChkbIsConsoleAutoScrollToEnd.IsChecked.HasValue && ChkbIsConsoleAutoScrollToEnd.IsChecked.Value)
            {
                ScrollViewer(rtb)?.ScrollToEnd();
            }
        }
Exemple #27
0
        void replace3Inlines(InlineCollection ic)
        {
            ic.Clear();

            dualFontSize(ic, fsz, TimeSpan.FromSeconds(PrgPositSec));
            ic.Add((new Run()
            {
                Text = " · "
            }));
            dualFontSize(ic, fsz, TimeSpan.FromSeconds(PrgDuratSec) - TimeSpan.FromSeconds(PrgPositSec));
            ic.Add((new Run()
            {
                Text = "\n", FontSize = 1
            }));
            dualFontSize(ic, fsz, TimeSpan.FromSeconds(PrgDuratSec));
        }
Exemple #28
0
        /// <summary>
        /// Fill stop tip
        /// </summary>
        /// <param name="inlines">Inlines to fill</param>
        /// <param name="location">Source stop</param>
        private static void _FillStop(InlineCollection inlines, Stop stop)
        {
            if (stop.StopType == StopType.Lunch)
            {
                Inline inline = new Run((string)App.Current.FindResource("LunchString"));
                inlines.Add(inline);
                return;
            }

            _AddName(inlines, stop);

            if (stop.AssociatedObject is Order)
            {
                _AddPriorityIfNeeded(stop.AssociatedObject as Order, inlines);
            }

            _AddArriveTime(stop.ArriveTime, inlines);

            // Add stop's time window(s).
            _AddStopTimeWindows(inlines, stop);

            foreach (TipProperty tipProperty in App.Current.MapDisplay.StopTitlesSelected)
            {
                _AddBindableProperty(inlines, tipProperty, stop);
            }
        }
Exemple #29
0
 private static void Fill(InlineCollection inlines, ElementToken token, Hint hint)
 {
     foreach (var t in token.Tokens)
     {
         inlines.Add(GetInline(t, hint));
     }
 }
Exemple #30
0
        private static bool AddLineBreakIfNeeded(InlineCollection inlines)
        {
            if (inlines.Count <= 0)
            {
                return(false);
            }

            Inline lastInline = inlines[inlines.Count - 1];

            while ((lastInline is Span))
            {
                var span = (Span)lastInline;
                if (span.Inlines.Count > 0)
                {
                    lastInline = span.Inlines[span.Inlines.Count - 1];
                }
            }

            if (lastInline is LineBreak)
            {
                return(false);
            }

            inlines.Add(new LineBreak());
            return(true);
        }
Exemple #31
0
        /// <summary>
        /// Renders an image element.
        /// </summary>
        /// <param name="inlineCollection"> The list to add to. </param>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="context"> Persistent state. </param>
        private void RenderImage(InlineCollection inlineCollection, ImageInline element, RenderContext context)
        {
            var image          = new Image();
            var imageContainer = new InlineUIContainer()
            {
                Child = image
            };

            // if url is not absolute we have to return as local images are not supported
            if (!element.Url.StartsWith("http") && !element.Url.StartsWith("ms-app"))
            {
                RenderTextRun(inlineCollection, new TextRunInline {
                    Text = element.Text, Type = MarkdownInlineType.TextRun
                }, context);
                return;
            }

            image.Source = new BitmapImage(new Uri(element.Url));
            image.HorizontalAlignment = HorizontalAlignment.Left;
            image.VerticalAlignment   = VerticalAlignment.Top;
            image.Stretch             = ImageStretch;

            ToolTipService.SetToolTip(image, element.Tooltip);

            // Try to add it to the current inlines
            // Could fail because some containers like Hyperlink cannot have inlined images
            try
            {
                inlineCollection.Add(imageContainer);
            }
            catch
            {
                // Ignore error
            }
        }
        static bool AddLineBreakIfNeeded(InlineCollection inlines)
        {
            if (inlines.Count <= 0)
            {
                return(false);
            }

            var lastInline = inlines[inlines.Count - 1];

            while ((lastInline is Windows.UI.Xaml.Documents.Span))
            {
                var span = (Windows.UI.Xaml.Documents.Span)lastInline;
                if (span.Inlines.Count > 0)
                {
                    lastInline = span.Inlines[span.Inlines.Count - 1];
                }
            }

            if (lastInline is LineBreak)
            {
                return(false);
            }

            inlines.Add(new LineBreak());
            return(true);
        }
Exemple #33
0
 // Methods
 public static void AddLinkText(InlineCollection inlines, string text, HyperLinkObj obj)
 {
     Hyperlink item = new Hyperlink(new Run(text))
     {
         Tag = obj
     };
     inlines.Add(item);
 }
 private void AddComparisonToOptimal(InlineCollection inlines, double current, double optimal, bool smallIsGood)
 {
     double difference = current - optimal;
     Color color = new Color();
     if (difference < 0)
     {
         color = smallIsGood ? Colors.Green : Colors.Red;
     }
     else
     {
         color = smallIsGood ? Colors.Red : Colors.Green;
     }
     if (Math.Abs(difference) > 0.004)
     {
         inlines.Add(new Run() { Text = " (" });
         inlines.Add(new Run() { Text = difference.ToString("+0.##;-0.##"), Foreground = new SolidColorBrush(color) });
         inlines.Add(new Run() { Text = ")" });
     }
 }
 public void FillInlines(string text, InlineCollection collection)
 {
     text = text.Replace("\r", "");
     var codeLexem = new CodeLexem(text);
     var list = codeLexem.Parse(CodeLanguage);
     foreach (CodeLexem current in list)
     {
         collection.Add(current.ToInline(CodeLanguage));
     }
 }
Exemple #36
0
        private static void PutWeekDay(InlineCollection inline, DateTime time)
        {
            SolidColorBrush color = Brushes.White;
            if (time.DayOfWeek == DayOfWeek.Saturday)
            {
                color = Brushes.Blue;
            }
            else if (time.DayOfWeek == DayOfWeek.Sunday)
            {
                color = Brushes.Red;
            }

            Run weekday = new Run(time.ToString("ddd"));
            weekday.Foreground = color;
            weekday.FontWeight = FontWeights.Bold;
            inline.Add(new Run("("));
            inline.Add(weekday);
            inline.Add(new Run(")"));
            inline.Add(new LineBreak());
        }
        /// <summary>
        /// Renders a bold run element.
        /// </summary>
        /// <param name="inlineCollection"> The list to add to. </param>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="parent"> The container element. </param>
        /// <param name="context"> Persistent state. </param>
        private void RenderBoldRun(InlineCollection inlineCollection, BoldTextInline element, TextElement parent, RenderContext context)
        {
            // Create the text run
            Span boldSpan = new Span();
            boldSpan.FontWeight = FontWeights.Bold;

            // Render the children into the bold inline.
            RenderInlineChildren(boldSpan.Inlines, element.Inlines, boldSpan, context);

            // Add it to the current inlines
            inlineCollection.Add(boldSpan);
        }
        public void CreateTweetBody(string text, InlineCollection inlines)
        {
            Match m = TwitterStatusViewer.TweetRegex.Match (text);
            int last = 0;
            List<Hyperlink> images = null;
            while (m.Success) {
                inlines.Add (text.Substring (last, m.Index - last));
                if (m.Success) {
                    Hyperlink link = CreateHyperlink (m.Value, m.Value, TwitterStatusViewer.LinkForegroundProperty, this.FontWeight, Hyperlink_Click);
                    inlines.Add (link);

                    foreach (IInlineImageUrlHandler handler in InlineImageSites) {
                        string picurl = handler.Process (m.Value);
                        if (picurl == null)
                            continue;
                        Hyperlink imgLink = new Hyperlink {Tag = m.Value};
                        imgLink.Click += Hyperlink_Click;
                        imgLink.Inlines.Add (new Image {
                            Source = IconCache.CreateBitmapImageIgnoreColorProfile (new Uri (picurl)),
                            Stretch = Stretch.Uniform,
                            MaxWidth = 50,
                            MaxHeight = 50
                        });
                        if (images == null) images = new List<Hyperlink> ();
                        images.Add (imgLink);
                        break;
                    }
                }

                last = m.Index + m.Length;
                m = m.NextMatch ();
            }
            inlines.Add (text.Substring (last));

            if (images != null) {
                inlines.Add (Environment.NewLine);
                for (int i = 0; i < images.Count; i ++)
                    inlines.Add (images[i]);
            }
        }
        /// <summary>
        /// Renders a strikethrough element.
        /// </summary>
        /// <param name="inlineCollection"> The list to add to. </param>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="parent"> The container element. </param>
        /// <param name="context"> Persistent state. </param>
        private void RenderStrikethroughRun(InlineCollection inlineCollection, StrikethroughTextInline element, TextElement parent, RenderContext context)
        {
            Span span = new Span();
            span.FontFamily = new FontFamily("Consolas");

            // Render the children into the inline.
            RenderInlineChildren(span.Inlines, element.Inlines, span, context);

            AlterChildRuns(span, (parentSpan, run) =>
            {
                var text = run.Text;
                var builder = new StringBuilder(text.Length * 2);
                foreach (var c in text)
                {
                    builder.Append((char)0x0336);
                    builder.Append(c);
                }
                run.Text = builder.ToString();
            });

            // Add it to the current inlines
            inlineCollection.Add(span);
        }
Exemple #40
0
 private static void Fill(InlineCollection inlines, ElementToken token, Hint hint)
 {
     foreach (var t in token.Tokens)
     {
         inlines.Add(GetInline(t, hint));
     }
 }
 private void AddElementToCollection(Inline elm, InlineCollection coll)
 {
     if (elm is InlineParaGraph)
     {
         //coll.Add(new LineBreak());
         coll.Add(new LineBreak());
     }
     else if (elm is Table)
     {
         coll.Add(new LineBreak());
     }
     else
         coll.Add(elm);
 }
        public static void CreateBooleanTable(
            InlineCollection Table,
            bool[] NewValues,
            bool[] OldValues,
            string IndexTitle,
            string ValueTitle,
            string TrueValue,
            string FalseValue
            )
        {
            Table.Clear();

            for (var i = 0; i < NewValues.Length; i += 1)
            {
                var line = new Span();
                var block = new Run();
                block.Text = (i + 1).ToString("###");
                line.Inlines.Add(block);

                block = new Run();
                block.Text = "    ";
                line.Inlines.Add(block);

                block = new Run();
                block.Text = NewValues[i] ? TrueValue : FalseValue;

                if ((OldValues != null) && (OldValues[i] != NewValues[i]))
                {
                    var bold = new Bold();
                    bold.Inlines.Add(block);
                    line.Inlines.Add(bold);
                }
                else
                {
                    line.Inlines.Add(block);
                }

                line.Inlines.Add(new LineBreak());

                Table.Add(line);
            }
        }
 private void DisplayImpossibleDrinks(InlineCollection playerInlines, InlineCollection dealerInlines)
 {
     playerInlines.Clear();
     playerInlines.Add(new Run()
     {
         Text = "-"
     });
     dealerInlines.Clear();
     dealerInlines.Add(new Run()
     {
         Text = "-"
     });
 }
Exemple #44
0
        public void AddInlines(InlineCollection inlineCollection, IEnumerable<ColorTextPair> pairs, bool allowHyperlinks)
        {
            Run run;
            foreach (ColorTextPair pair in pairs)
            {
                bool hasHyperlinks = false;
                if (allowHyperlinks)
                {
                    if (!string.IsNullOrEmpty(pair.Text))
                    {
                        MatchCollection matches = new Regex(ZChat.Options.HyperlinkPattern).Matches(pair.Text);
                        if (matches.Count > 0)
                        {
                            hasHyperlinks = true;
                            string linkText;
                            int linkStart = 0, linkLength = 0;
                            int curPos = 0;
                            foreach (Match match in matches)
                            {
                                if (match.Value.StartsWith(" "))
                                {
                                    linkStart = match.Index + 1;
                                    linkLength = match.Length - 1;
                                }
                                else
                                {
                                    linkStart = match.Index;
                                    linkLength = match.Length;
                                }
                                linkText = pair.Text.Substring(linkStart, linkLength);

                                Hyperlink link = new Hyperlink(new Run(linkText));
                                link.Foreground = ZChat.Options.LinkFore;
                                link.SetValue(KeyboardNavigation.IsTabStopProperty, false);
                                //if (link.FontStyle) link.TextDecorations.Add(TextDecorations.Underline);
                                link.Click += new RoutedEventHandler(link_Click);
                                link.Tag = linkText;
                                run = new Run(pair.Text.Substring(curPos, linkStart - curPos));
                                run.Foreground = pair.Color;
                                if (linkStart > 0) inlineCollection.Add(run);
                                curPos = linkStart + linkLength;
                                inlineCollection.Add(link);
                            }
                            if (curPos < pair.Text.Length)
                            {
                                run = new Run(pair.Text.Substring(curPos, pair.Text.Length - curPos));
                                run.Foreground = pair.Color;
                                inlineCollection.Add(run);
                            }
                        }
                    }
                }
                if (hasHyperlinks == false)
                {
                    AddNonHyperlinkText(inlineCollection, pair.Text, pair.Color);
                    //run = new Run(pair.Text);
                    //run.Foreground = pair.Color;
                    //inlineCollection.Add(run);
                }
            }
        }
        private static void CreateElement(InlineCollection parent, Node node, RichTextBlockStatus status)
        {
            switch (node)
            {
                case Element element:
                    switch (element.TagName.ToLower())
                    {
                        case "a":
                            {
                                // We want to change BaseUri easily, so we use `GetAttribute("href")` instead of `HtmlAnchorElement.Href`
                                var href = element.GetAttribute("href");

                                if (!status.TryCreateUri(href, out var uri))
                                    break;

                                parent.Add(new Run() { Text = " " });

                                var hyperlink = new Hyperlink()
                                {
                                    NavigateUri = uri,
                                    Foreground = status.Foreground
                                };

                                foreach (var child in element.ChildNodes)
                                {
                                    switch (child)
                                    {
                                        case HtmlImageElement childElement:
                                            if (CreateImage(element, status) is Image image)
                                            {
                                                if (hyperlink.Inlines.Count != 0)
                                                {
                                                    hyperlink.SetUri(href);
                                                    status.Hyperlinks.Add(hyperlink);
                                                    parent.Add(hyperlink);
                                                }

                                                var button = new HyperlinkButton()
                                                {
                                                    NavigateUri = uri,
                                                    Content = image,
                                                    RequestedTheme = status.RequestedTheme
                                                };
                                                button.SetUri(href);
                                                status.HyperlinkButtons.Add(button);
                                                parent.Add(new InlineUIContainer() { Child = button });

                                                hyperlink = new Hyperlink()
                                                {
                                                    NavigateUri = uri,
                                                    Foreground = status.Foreground
                                                };
                                            }
                                            break;
                                        default:
                                            CreateElement(hyperlink.Inlines, child, status);
                                            break;
                                    }
                                    break;
                                }

                                if (hyperlink.Inlines.Count != 0)
                                {
                                    hyperlink.SetUri(href);
                                    status.Hyperlinks.Add(hyperlink);
                                    parent.Add(hyperlink);
                                }

                                parent.Add(new Run() { Text = " " });
                            }
                            break;
                        case "img":
                            {
                                if (CreateImage(element, status) is Image image)
                                    parent.Add(new InlineUIContainer() { Child = image });
                            }
                            break;
                        case "strong":
                        case "b":
                            {
                                var span = new Span() { FontWeight = FontWeights.Bold };
                                CreateChildren(span.Inlines, element, status);
                                parent.Add(span);
                            }
                            break;
                        case "div":
                        case "font":
                        case "p":
                        case "span":
                            {
                                var span = new Span();
                                foreach (var s in ParseStyle(element.GetAttribute("style")))
                                    switch (s.Key)
                                    {
                                        case "font-size":
                                            {
                                                var value = s.Value;

                                                double fontSize;
                                                if (value.EndsWith("px"))
                                                    fontSize = double.Parse(value.Remove(value.Length - 2));
                                                else if (value.EndsWith("%"))
                                                    fontSize = 14 * double.Parse(value.Remove(value.Length - 1)) / 100;
                                                else
                                                    fontSize = 14 * double.Parse(value);

                                                span.FontSize = fontSize;
                                            }
                                            break;
                                        case "font-weight":
                                            switch (s.Value)
                                            {
                                                case "bold":
                                                    span.FontWeight = FontWeights.Bold;
                                                    break;
                                            }
                                            break;
                                    }

                                CreateChildren(span.Inlines, element, status);
                                parent.Add(span);
                            }
                            break;
                        case "br":
                            if (element.NextSibling is Text nextText &&
                                nextText.Data.StartsWith("\n"))
                                break;

                            parent.Add(new LineBreak());
                            break;
                        case "hr":
                            parent.Add(new LineBreak());

                            var line = new Border()
                            {
                                BorderThickness = new Thickness(0, 1, 0, 0),
                                BorderBrush = status.Foreground,
                                Margin = new Thickness(8, 0, 8, 0),
                                Height = 1,
                            };

                            if (status.ActualWidth > 16)
                                line.Width = status.ActualWidth - 16;

                            status.Lines.Add(line);
                            parent.Add(new InlineUIContainer() { Child = line });

                            parent.Add(new LineBreak());
                            break;
                        case "iframe": // Ignore
                        case "script":
                        case "noscript":
                            break;
#if DEBUG
                        default:
                            Debug.WriteLine($"Ignore unknown tag {element.TagName}");
                            break;
#endif

                    }
                    break;
                case Text text:
                    parent.Add(new Run() { Text = text.Data });
                    break;
            }
        }
        /// <summary>
        /// Renders a text run element.
        /// </summary>
        /// <param name="inlineCollection"> The list to add to. </param>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="parent"> The container element. </param>
        /// <param name="context"> Persistent state. </param>
        private void RenderTextRun(InlineCollection inlineCollection, TextRunInline element, TextElement parent, RenderContext context)
        {
            // Create the text run
            Run textRun = new Run();
            textRun.Text = CollapseWhitespace(context, element.Text);

            // Add it
            inlineCollection.Add(textRun);
        }
 private void CreateInlines(WebVTTCue cue, IWebVTTInternalNode node, InlineCollection inlines, Brush brush)
 {
     foreach (var child in node.Nodes)
     {
         var inline = CreateInline(child, brush);
         if (inline != null)
         {
             inlines.Add(inline);
             if (inline is Span && child is IWebVTTInternalNode)
             {
                 CreateInlines(cue, (IWebVTTInternalNode)child, ((Span)inline).Inlines, brush);
             }
             if (NodeRendering != null) NodeRendering(this, new NodeRenderingEventArgs(cue, child, inline));
         }
     }
 }
        /// <summary>
        /// Renders a raw link element.
        /// </summary>
        /// <param name="inlineCollection"> The list to add to. </param>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="parent"> The container element. </param>
        /// <param name="context"> Persistent state. </param>
        private void RenderHyperlink(InlineCollection inlineCollection, HyperlinkInline element, TextElement parent, RenderContext context)
        {
            var link = new Hyperlink();

            // Register the link
            this.linkRegister.RegisterNewHyperLink(link, element.Url);

            // Make a text block for the link
            Run linkText = new Run();
            linkText.Text = CollapseWhitespace(context, element.Text);
            link.Inlines.Add(linkText);

            // Add it to the current inlines
            inlineCollection.Add(link);
        }
Exemple #49
0
 private static void PutTime(InlineCollection inline, string HourMod)
 {
     Run text = new Run(HourMod);
     text.FontSize = 13;
     text.FontWeight = FontWeights.Bold;
     inline.Add(text);
 }
        /// <summary>
        /// Renders a text run element.
        /// </summary>
        /// <param name="inlineCollection"> The list to add to. </param>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="parent"> The container element. </param>
        /// <param name="context"> Persistent state. </param>
        private void RenderItalicRun(InlineCollection inlineCollection, ItalicTextInline element, TextElement parent, RenderContext context)
        {
            // Create the text run
            Span italicSpan = new Span();
            italicSpan.FontStyle = FontStyle.Italic;

            // Render the children into the italic inline.
            RenderInlineChildren(italicSpan.Inlines, element.Inlines, italicSpan, context);

            // Add it to the current inlines
            inlineCollection.Add(italicSpan);
        }
Exemple #51
0
 private static void PutDate(InlineCollection inline, DateTime time)
 {
     Run text = new Run(time.ToString("M/d"));
     inline.Add(text);
     inline.Add(new LineBreak());
 }
Exemple #52
0
 public static void AddNormalText(InlineCollection inlines, string text)
 {
     inlines.Add(new Run(text));
 }
        private void DisplayExpectedDrinks(InlineCollection playerInlines, InlineCollection dealerInlines,
            double currentUserDrinks, double currentDealerDrinks,
            double unconstrainedUserDrinks, double unconstrainedDealerDrinks)
        {
            playerInlines.Clear();
            playerInlines.Add(new Run()
            {
                Text = String.Format("{0:0.##}", currentUserDrinks)
            });
            dealerInlines.Clear();
            dealerInlines.Add(new Run()
            {
                Text = String.Format("{0:0.##}", currentDealerDrinks)
            });

            if (!currentConstraint.IsSatisfiedBy(currentUnconstrainedStrategy))
            {
                AddComparisonToOptimal(playerInlines, currentUserDrinks,
                    unconstrainedUserDrinks, true);
                AddComparisonToOptimal(dealerInlines, currentDealerDrinks,
                    unconstrainedDealerDrinks, false);
            }
        }
        /// <summary>
        /// Clears and populates the provided table with rows that have the following syntax:
        /// [row #]    [state of new value]
        ///
        /// If the state of a value has changed, the value will be bolded.
        /// </summary>
        /// <param name="table">Table will be cleared and new rows will populate this table.</param>
        /// <param name="newValues">The new boolean values</param>
        /// <param name="oldValues">The boolean values that the new ones are being compared to</param>
        /// <param name="trueValue">Text if the new value is TRUE</param>
        /// <param name="falseValue">Text if the new vlaue is FALSE</param>
        public static Boolean CreateBooleanChartInTable(
            InlineCollection table,
            List<Boolean> newValues,
            List<Boolean> oldValues,
            String trueValue,
            String falseValue)
        {
            Boolean isBooleanChartCreated = false;

            // Make sure there are at least newValues to check or that there are the same number of old values as new values
            if ((newValues != null) && ((oldValues == null) || (newValues.Count == oldValues.Count)))
            {
                table.Clear();

                // Each new value has it's own row
                for (int i = 0; i < (int)newValues.Count; i += 1)
                {
                    var line = new Span();

                    // Row #
                    var block = new Run();
                    block.Text = (i + 1).ToString("D", NumberFormatInfo.InvariantInfo);
                    line.Inlines.Add(block);

                    // Space between row # and the value (simulates a column)
                    block = new Run();
                    block.Text = "    ";
                    line.Inlines.Add(block);

                    // Print the textual form of TRUE/FALSE values
                    block = new Run();
                    block.Text = newValues[i] ? trueValue : falseValue;

                    // Bold values that have changed
                    if ((oldValues != null) && (oldValues[i] != newValues[i]))
                    {
                        var bold = new Bold();
                        bold.Inlines.Add(block);
                        line.Inlines.Add(bold);
                    }
                    else
                    {
                        line.Inlines.Add(block);
                    }

                    line.Inlines.Add(new LineBreak());

                    table.Add(line);
                }

                isBooleanChartCreated = true;
            }

            return isBooleanChartCreated;
        }
        /// <summary>
        /// Renders a superscript element.
        /// </summary>
        /// <param name="inlineCollection"> The list to add to. </param>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="parent"> The container element. </param>
        /// <param name="context"> Persistent state. </param>
        private void RenderSuperscriptRun(InlineCollection inlineCollection, SuperscriptTextInline element, TextElement parent, RenderContext context)
        {
            // Le <sigh>, InlineUIContainers are not allowed within hyperlinks.
            if (context.WithinHyperlink)
            {
                RenderInlineChildren(inlineCollection, element.Inlines, parent, context);
                return;
            }

            var paragraph = new Paragraph();
            paragraph.FontSize = parent.FontSize * 0.8;
            paragraph.FontFamily = parent.FontFamily;
            paragraph.FontStyle = parent.FontStyle;
            paragraph.FontWeight = parent.FontWeight;
            RenderInlineChildren(paragraph.Inlines, element.Inlines, paragraph, context);

            var richTextBlock = CreateOrReuseRichTextBlock(null, context);
            richTextBlock.Blocks.Add(paragraph);

            var border = new Border();
            border.Padding = new Thickness(0, 0, 0, paragraph.FontSize * 0.2);
            border.Child = richTextBlock;

            var inlineUIContainer = new InlineUIContainer();
            inlineUIContainer.Child = border;

            // Add it to the current inlines
            inlineCollection.Add(inlineUIContainer);
        }
        /// <summary>
        /// Renders a link element
        /// </summary>
        /// <param name="inlineCollection"> The list to add to. </param>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="parent"> The container element. </param>
        /// <param name="context"> Persistent state. </param>
        private void RenderMarkdownLink(InlineCollection inlineCollection, MarkdownLinkInline element, TextElement parent, RenderContext context)
        {
            // Avoid crash when link text is empty.
            if (element.Inlines.Count == 0)
                return;

            // Attempt to resolve references.
            element.ResolveReference(this.document);
            if (element.Url == null)
            {
                // The element couldn't be resolved, just render it as text.
                RenderInlineChildren(inlineCollection, element.Inlines, parent, context);
                return;
            }

            // HACK: Superscript is not allowed within a hyperlink.  But if we switch it around, so
            // that the superscript is outside the hyperlink, then it will render correctly.
            // This assumes that the entire hyperlink is to be rendered as superscript.
            if (AllTextIsSuperscript(element) == false)
            {
                // Regular ol' hyperlink.
                var link = new Hyperlink();

                // Register the link
                this.linkRegister.RegisterNewHyperLink(link, element.Url);

                // Remove superscripts.
                RemoveSuperscriptRuns(element, insertCaret: true);

                // Render the children into the link inline.
                var childContext = context.Clone();
                childContext.WithinHyperlink = true;
                RenderInlineChildren(link.Inlines, element.Inlines, link, childContext);
                context.TrimLeadingWhitespace = childContext.TrimLeadingWhitespace;

                // Add it to the current inlines
                inlineCollection.Add(link);
            }
            else
            {
                // THE HACK IS ON!

                // Create a fake superscript element.
                var fakeSuperscript = new SuperscriptTextInline();
                fakeSuperscript.Inlines = new List<MarkdownInline> { element };

                // Remove superscripts.
                RemoveSuperscriptRuns(element, insertCaret: false);

                // Now render it.
                RenderSuperscriptRun(inlineCollection, fakeSuperscript, parent, context);

            }
        }
 private void DocTreeToTextElement(DocTree tree, InlineCollection coll)
 {
     if (tree.Element is Table)
     {
         coll.Add(new LineBreak());
         AddElementToCollection(CreateGrid(tree), coll);
     }
     else
     {
         AddElementToCollection(tree.Element, coll);
         if (!tree.HasChildren)
             return;
         foreach (var child in tree.Children)
         {
             DocTreeToTextElement(child, coll);
         }
     }
 }
        /// <summary>
        /// Fill stop tip
        /// </summary>
        /// <param name="inlines">Inlines to fill</param>
        /// <param name="location">Source stop</param>
        private static void _FillStop(InlineCollection inlines, Stop stop)
        {
            if (stop.StopType == StopType.Lunch)
            {
                Inline inline = new Run((string)App.Current.FindResource("LunchString"));
                inlines.Add(inline);
                return;
            }

            _AddName(inlines, stop);

            if (stop.AssociatedObject is Order)
            {
                _AddPriorityIfNeeded(stop.AssociatedObject as Order, inlines);
            }

            _AddArriveTime(stop.ArriveTime, inlines);

            // Add stop's time window(s).
            _AddStopTimeWindows(inlines, stop);

            foreach (TipProperty tipProperty in App.Current.MapDisplay.StopTitlesSelected)
            {
                _AddBindableProperty(inlines, tipProperty, stop);
            }
        }
        /// <summary>
        /// Renders a code element
        /// </summary>
        /// <param name="inlineCollection"> The list to add to. </param>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="parent"> The container element. </param>
        /// <param name="context"> Persistent state. </param>
        private void RenderCodeRun(InlineCollection inlineCollection, CodeInline element, TextElement parent, RenderContext context)
        {
            var run = new Run();
            run.FontFamily = CodeFontFamily ?? FontFamily;
            run.Text = CollapseWhitespace(context, element.Text);

            // Add it to the current inlines
            inlineCollection.Add(run);
        }
Exemple #60
0
        private void AddBoldOrRun(InlineCollection inlines, string text, SolidColorBrush brush, bool bold)
        {
            Run r = new Run(text);
            r.Foreground = brush;

            if (bold)
                inlines.Add(new Bold(r));
            else
                inlines.Add(r);
        }