Inheritance: Span, IBold
Exemplo n.º 1
0
        public static Xaml.Bold Control(this Domain.Bold item, bool isThumbnail = false)
        {
            var control = new Xaml.Bold();

            if (isThumbnail)
            {
                control.FontSize = ThumbnailFontSize;
            }

            if (item.CharacterSpacing > 0)
            {
                control.CharacterSpacing = item.CharacterSpacing;
            }
            if (item.FontSize > 0 && !isThumbnail)
            {
                control.FontSize = item.FontSize;
            }
            if (!string.IsNullOrEmpty(item.FontStretch))
            {
                control.FontStretch = Helpers.ParseEnum <FontStretch>(item.FontStretch);
            }
            if (!string.IsNullOrEmpty(item.FontStyle))
            {
                control.FontStyle = Helpers.ParseEnum <FontStyle>(item.FontStyle);
            }
            if (!string.IsNullOrEmpty(item.FontWeight))
            {
                control.FontWeight = Helpers.ParseEnum <FontWeight>(item.FontWeight);
            }
            if (!string.IsNullOrEmpty(item.Foreground))
            {
                control.Foreground = new SolidColorBrush(item.Foreground.GetColor());
            }
            var run = new Xaml.Run {
                Text = item.Value
            };

            if (isThumbnail)
            {
                run.FontSize = ThumbnailFontSize;
            }

            control.Inlines.Add(run);

            return(control);
        }
Exemplo n.º 2
0
 private static Span GenerateH3(HtmlNode node)
 {
     Span s = new Span();
     s.Inlines.Add(new LineBreak());
     Bold bold = new Bold();
     Run r = new Run() { Text = CleanText(node.InnerText) };
     bold.Inlines.Add(r);
     s.Inlines.Add(bold);
     s.Inlines.Add(new LineBreak());
     return s;
 }
Exemplo n.º 3
0
 private static Inline GenerateBold(HtmlNode node)
 {
     Bold b = new Bold();
     AddChildren(b, node);
     return b;
 }
        /// <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;
        }
        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 static Span GenerateH3(HtmlNode node)
 {
     Span s = new Span() { FontSize = (double)Application.Current.Resources["H3"] };
     s.Inlines.Add(new LineBreak());
     Bold bold = new Bold();
     Run r = new Run() { Text = CleanText(node.InnerText) };
     bold.Inlines.Add(r);
     s.Inlines.Add(bold);
     s.Inlines.Add(new LineBreak());
     return s;
 }
Exemplo n.º 7
0
 private static Span RenderTextContent(TextModel text)
 {
     if (text.TextType == TextType.Bold)
     {
         var span = new Bold();
         if (!string.IsNullOrWhiteSpace(text.Text))
             span.Inlines.Add(new Run()
             {
                 Text = text.Text
             });
         AddInlineChildren(span, text);
         foreach (var inline in span.Inlines)
         {
             inline.FontWeight = FontWeights.Bold;
         }
         return span;
     }
     if (text.TextType == TextType.Cursive)
     {
         var span = new Span();
         if (!string.IsNullOrWhiteSpace(text.Text))
             span.Inlines.Add(new Run()
             {
                 Text = text.Text
             });
         AddInlineChildren(span, text);
         foreach (var inline in span.Inlines)
         {
             inline.FontStyle = FontStyle.Italic;
         }
         return span;
     }
     if (text.TextType == TextType.Hyperlink)
     {
         var span = new Hyperlink()
         {
             NavigateUri = new Uri(text.Text)
         };
         AddInlineChildren(span, text);
         return span;
     }
     if (text.TextType == TextType.Underline)
     {
         var span = new Underline();
         if (!string.IsNullOrWhiteSpace(text.Text))
             span.Inlines.Add(new Run()
             {
                 Text = text.Text
             });
         AddInlineChildren(span, text);
         return span;
     }
     else//(text.TextType == TextType.Normal)
     {
         var span = new Span();
         span.Inlines.Add(
             new Run()
             {
                 Text = text.Text
             });
         AddInlineChildren(span, text);
         return span;
     }
 }
 private static Inline GenerateBold(HtmlNode node)
 {
     Bold b = new Bold();
     if (node?.InnerHtml != null) node.InnerHtml += " ";
     AddChildren(b, node);
     return b;
 }
 public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
 {
     var bold = new Bold();
     parent.Add(bold);
     context.RenderNode(element, new SpanContainer(bold));
 }
Exemplo n.º 10
0
        private static void ParseElement(XmlElement element, ITextContainer parent)
        {
            foreach (var child in element.ChildNodes)
            {
                var tagNameToUpper = (child as XmlElement)?.TagName?.ToUpper();

                if (!isInP
                    && !(child is XmlElement && (tagNameToUpper == "P" || tagNameToUpper == "SPAN" || tagNameToUpper == "DIV" || tagNameToUpper == "IMG")))
                {
                    var paragraph = new Paragraph();
                    parent.Add(paragraph);
                    isInP = true;
                    parent = new ParagraphTextContainer(parent, paragraph);
                }

                if (child is XmlText)
                {
                    var text = child.InnerText.Replace("\n", "").Trim();
                    if (string.IsNullOrEmpty(text))
                        continue;

                    text = text.Replace("</form>", "");
                    parent.Add(new Run { Text = System.Net.WebUtility.HtmlDecode(text), Foreground = new SolidColorBrush(Windows.UI.Colors.Black) });
                }
                else if (child is XmlElement)
                {
                    XmlElement e = (XmlElement)child;
                    switch (tagNameToUpper)
                    {
                        case "P":
                        case "DIV":
                        case "SPAN":
                            if(tagNameToUpper == "DIV")
                            {
                                var classVal = e.Attributes.FirstOrDefault(a => a.NodeName == "class")?.NodeValue?.ToString() ?? "";
                                
                                if(classVal.Contains("open-list-comments") ||
                                   classVal.Contains("open-list-footer") ||
                                   classVal.Contains("modal-body"))
                                {
                                    return;
                                }
                            }

                            if (isInP)
                            {
                                if (tagNameToUpper == "P")
                                    parent.Add(new LineBreak());
                                ParseElement(e, parent);
                            }
                            else
                            {
                                var paragraph = new Paragraph();
                                parent.Add(paragraph);
                                isInP = true;
                                ParseElement(e, new ParagraphTextContainer(parent, paragraph));
                                isInP = false;
                            }
                            break;
                        case "B":
                        case "STRONG":
                        case "H1":
                        case "H2":
                        case "H3":
                        case "H4":
                        case "H5":
                        case "H6":
                            var bold = new Bold();
                            parent.Add(bold);
                            ParseElement(e, new SpanTextContainer(parent, bold));
                            break;
                        case "I":
                        case "EM":
                            var italic = new Italic();
                            parent.Add(italic);
                            ParseElement(e, new SpanTextContainer(parent, italic));
                            break;
                        case "U":
                            var underline = new Underline();
                            parent.Add(underline);
                            ParseElement(e, new SpanTextContainer(parent, underline));
                            break;
                        case "A":
                            var url = e.Attributes.FirstOrDefault(a => a.NodeName == "href")?.NodeValue;
                            Uri uri;
                            if (url != null && Uri.TryCreate(url.ToString(), UriKind.Absolute, out uri))
                            {
                                var link = new Hyperlink();
                                link.NavigateUri = uri;
                                parent.Add(link);
                                ParseElement(e, new SpanTextContainer(parent, link));
                            }
                            else
                            {
                                ParseElement(e, parent);
                            }

                            break;
                        case "BR":
                            parent.Add(new LineBreak());
                            break;
                        case "IMG":
                            var src = e.Attributes.FirstOrDefault(a => a.NodeName == "src")?.NodeValue;
                            Uri srcUri;
                            if (src != null && Uri.TryCreate(src.ToString(), UriKind.Absolute, out srcUri))
                            {
                                var img = new InlineUIContainer
                                {
                                    Child = new Windows.UI.Xaml.Controls.Image()
                                    {
                                        Source = new BitmapImage(srcUri)
                                    }
                                };

                                parent.AddToParentParagraph(img);
                            }
                            break;
                    }
                }
            }
        }
        private static void ParseElement(XmlElement element, ITextContainer parent)
        {
            foreach (var child in element.ChildNodes)
            {
                if (child is Windows.Data.Xml.Dom.XmlText)
                {
                    if (string.IsNullOrEmpty(child.InnerText) ||
                        child.InnerText == "\n")
                    {
                        continue;
                    }

                    parent.Add(new Run { Text = child.InnerText });
                }
                else if (child is XmlElement)
                {
                    XmlElement e = (XmlElement)child;
                    switch (e.TagName.ToUpper())
                    {
                        case "P":
                            var paragraph = new Paragraph();
                            parent.Add(paragraph);
                            ParseElement(e, new ParagraphTextContainer(paragraph));
                            break;
                        case "STRONG":
                            var bold = new Bold();
                            parent.Add(bold);
                            ParseElement(e, new SpanTextContainer(bold));
                            break;
                        case "U":
                            var underline = new Underline();
                            parent.Add(underline);
                            ParseElement(e, new SpanTextContainer(underline));
                            break;
                        case "A":
                            ParseElement(e, parent);
                            break;
                        case "BR":
                            parent.Add(new LineBreak());
                            break;
                    }
                }

            }
        }
Exemplo n.º 12
0
        private static void ParseElement(XmlElement element, ITextContainer parent)
        {
            foreach (var child in element.ChildNodes)
            {
                if (child is Windows.Data.Xml.Dom.XmlText)
                {
                    if (string.IsNullOrEmpty(child.InnerText) ||
                        child.InnerText == "\n")
                    {
                        continue;
                    }

                    parent.Add(new Run { Text = child.InnerText.Trim(new char[] {'\n'}) });
                }
                else if (child is XmlElement)
                {
                    XmlElement e = (XmlElement)child;
                    switch (e.TagName.ToUpper())
                    {
                        case "P":
                            var paragraph = new Paragraph();
                            parent.Add(paragraph);
                            ParseElement(e, new ParagraphTextContainer(paragraph));
                            break;
                        case "STRONG":
                            var bold = new Bold();
                            parent.Add(bold);
                            ParseElement(e, new SpanTextContainer(bold));
                            break;
                        case "U":
                            var underline = new Underline();
                            parent.Add(underline);
                            ParseElement(e, new SpanTextContainer(underline));
                            break;
                        case "A":
                            var inlineElt = new InlineUIContainer();
                            var hyperlink = new HyperlinkButton();
                            inlineElt.Child = hyperlink;
                            hyperlink.Style = (Style)App.Current.Resources["HyperlinkButtonStyle"];
                            hyperlink.Content = e.InnerText;
                            hyperlink.Click += delegate(object sender, RoutedEventArgs eventArgs)
                            {
                                string uriString = e.GetAttribute("href");
                                Messenger.Default.Send<LinkClickedMessage>(new LinkClickedMessage()
                                {
                                    UriToNavigate = uriString
                                });
                            };
                            parent.Add(inlineElt);
                            //ParseElement(e, parent);
                            break;
                        case "BR":
                                parent.Add(new LineBreak());
                            break;
                    }
                }

            }
        }
Exemplo n.º 13
0
        private static void ParseElement(XmlElement element, ITextContainer parent)
        {
            foreach (var child in element.ChildNodes)
            {
                if (child is Windows.Data.Xml.Dom.XmlText)
                {
                    if (string.IsNullOrEmpty(child.InnerText) ||
                        child.InnerText == "\n")
                    {
                        continue;
                    }

                    parent.Add(new Run { Text = ((XmlText)child).InnerText });
                }
                else if (child is XmlElement)
                {
                    XmlElement e = (XmlElement)child;
                    switch (e.TagName.ToUpper())
                    {
                        case "DIV":
                            if (e.GetAttribute("class") == "p")
                            {
                                Paragraph paragraph = new Paragraph();
                                paragraph.Margin = new Thickness(0, 0, 0, 10);
                                //paragraph.LineHeight = 20;
                                parent.Add(paragraph);
                                ParseElement(e, new ParagraphTextContainer(paragraph));

                            }
                            else if (e.GetAttribute("class") == "label" && element.GetAttribute("class").Contains("chapter"))
                            {
                                Paragraph chapterLabel = new Paragraph();
                                chapterLabel.FontFamily = new FontFamily("Segoe UI");
                                chapterLabel.FontSize = 32;
                                chapterLabel.Inlines.Add(new Run { Text = "Chapter " + e.InnerText });
                                parent.Add(chapterLabel);

                            }
                            else
                            {
                                ParseElement(e, parent);
                            }
                            break;
                        case "SPAN":
                            //ParseElement(e, parent);

                            if (e.GetAttribute("class") == "heading")
                            {
                                Paragraph header = new Paragraph();
                                header.FontFamily = new FontFamily("Segoe UI");
                                header.FontSize = 20;
                                header.Margin = new Thickness(0, 10, 0, 5);
                                header.Inlines.Add(new Run { Text = e.InnerText });
                                parent.Add(header);
                            }
                            else if (e.GetAttribute("class") == "label" && element.GetAttribute("class").Contains("verse"))
                            {
                                Run run = new Run();
                                run.Text = e.InnerText;
                                run.FontSize = 8;
                                parent.Add(run);
                            }
                            else
                            {
                                ParseElement(e, parent);
                            }
                            //else
                            //{
                            //    Run run = new Run();
                            //    run.Text = e.InnerText;
                            //    parent.Add(run);
                            //}
                            break;
                        case "P":
                            var p = new Paragraph();
                            parent.Add(p);
                            ParseElement(e, new ParagraphTextContainer(p));
                            break;
                        case "STRONG":
                            var bold = new Bold();
                            parent.Add(bold);
                            ParseElement(e, new SpanTextContainer(bold));
                            break;
                        case "U":
                            var underline = new Underline();
                            parent.Add(underline);
                            ParseElement(e, new SpanTextContainer(underline));
                            break;
                        case "A":
                            ParseElement(e, parent);
                            break;
                        case "BR":
                            parent.Add(new LineBreak());
                            break;
                    }
                }

            }
        }
 private static Span GenerateH3(HtmlNode node)
 {
     Debug.WriteLine("Properties >>>>>> GenerateH3");
     Span s = new Span();
     //s.Inlines.Add(new LineBreak());
     Bold bold = new Bold();
     Run r = new Run() { Text = CleanText(node.InnerText) };
     bold.Inlines.Add(r);
     s.Inlines.Add(bold);
     s.Inlines.Add(new LineBreak());
     return s;
 }
 private static Inline GenerateBold(HtmlNode node)
 {
     Debug.WriteLine("Properties >>>>>> GenerateBold");
     Bold b = new Bold();
     AddChildren(b, node);
     return b;
 }
Exemplo n.º 16
0
        /// <summary>
        /// Converts an HTML node into an Inline.
        /// </summary>
        private static Inline ToInline( HtmlNode node )
        {
            switch ( node.Name )
            {
                case "br":
                    return new LineBreak();

                case "a":
                    string url = node.GetAttributeValue( "href", "" );
                    if ( string.IsNullOrWhiteSpace( url ) ) // happens sometimes... broken HTML...
                    {
                        break;
                    }

                    string text = node.InnerText;
                    if ( string.IsNullOrWhiteSpace( text ) )
                    {
                        text = url;
                    }

                    var link = new Hyperlink
                    {
                        Inlines = 
                        {
                            new Run 
                            {
                                Text = text,
                                Foreground = new SolidColorBrush( Colors.Blue )
                            } 
                        }
                    };
                    link.Click += ( _, __ ) => LauncherEx.Launch( new Uri( url, UriKind.Absolute ) );

                    return new Span
                    {
                        Inlines =
                        {
                            new Run { Text = " " },
                            link,
                            new Run { Text = " " },
                        }
                    };

                case "strong":
                case "b":
                    var bold = new Bold();
                    foreach ( var child in node.ChildNodes )
                    {
                        bold.Inlines.Add( ToInline( child ) );
                    }
                    return bold;

                case "em":
                case "i":
                    var italic = new Italic();
                    foreach ( var child in node.ChildNodes )
                    {
                        italic.Inlines.Add( ToInline( child ) );
                    }
                    return italic;

                case "ul":
                    var unorderedList = new Span();
                    foreach ( var child in node.ChildNodes )
                    {
                        var listElem = new Span();
                        listElem.Inlines.Add( new Run { Text = "● " } );
                        listElem.Inlines.Add( ToInline( child ) );
                        unorderedList.Inlines.Add( listElem );
                        unorderedList.Inlines.Add( new LineBreak() );
                    }
                    return unorderedList;

                case "ol":
                    var orderedList = new Span();
                    for ( int n = 0; n < node.ChildNodes.Count; n++ )
                    {
                        var listElem = new Span();
                        listElem.Inlines.Add( new Run { Text = n.ToString() + " " } );
                        listElem.Inlines.Add( ToInline( node.ChildNodes[n] ) );
                        orderedList.Inlines.Add( listElem );
                        orderedList.Inlines.Add( new LineBreak() );
                    }
                    return orderedList;

                case "h1":
                    return new Run
                    {
                        Text = node.InnerText + Environment.NewLine,
                        FontWeight = FontWeights.Bold,
                        FontSize = 32
                    };

                case "h2":
                    return new Run
                    {
                        Text = node.InnerText + Environment.NewLine,
                        FontWeight = FontWeights.SemiBold,
                        FontSize = 24
                    };

                case "h3":
                    return new Run
                    {
                        Text = node.InnerText + Environment.NewLine,
                        FontWeight = FontWeights.SemiBold,
                        FontSize = 19
                    };

                case "h4":
                    return new Run
                    {
                        Text = node.InnerText + Environment.NewLine,
                        FontWeight = FontWeights.Medium,
                        FontSize = 17
                    };

                case "h5":
                    return new Run
                    {
                        Text = node.InnerText + Environment.NewLine,
                        FontWeight = FontWeights.Medium,
                        FontSize = 16
                    };

                case "div":
                case "p":
                case "blockquote":
                    var container = new Span();
                    foreach ( var child in node.ChildNodes )
                    {
                        container.Inlines.Add( ToInline( child ) );
                    }
                    container.Inlines.Add( new LineBreak() );
                    container.Inlines.Add( new LineBreak() );
                    return container;
            }

            return new Run { Text = node.PreviousSibling == null ? node.InnerText.TrimStart() : node.InnerText };
        }