Exemple #1
0
        private static Viewbox CreateImage(HtmlNode node, string src)
        {
            var viewbox = new Viewbox
            {
                StretchDirection = StretchDirection.DownOnly
            };

            var imgHeight = node.Attributes.GetValueInt("height");
            var width = node.Attributes.GetValueInt("width");

            if (imgHeight > 0)
            {
                viewbox.MaxHeight = imgHeight;
            }
            if (width > 0)
            {
                viewbox.MaxWidth = width;
            }

            viewbox.Child = new ImageEx
            {
                Source = src,
                Stretch = Stretch.Uniform,
                Background = new SolidColorBrush(Colors.Transparent),
                Foreground = new SolidColorBrush(Colors.Transparent),
                AnimateGif = true
            };
            return viewbox;
        }
Exemple #2
0
        internal HtmlNode AddNode(HtmlTag tag)
        {
            var node = new HtmlNode(tag);
            Fragments.Add(node);

            return node;
        }
Exemple #3
0
 private static int GetSpan(HtmlNode node, string name)
 {
     if (node != null)
     {
         return node.Attributes.GetValueInt(name);
     }
     return 0;
 }
Exemple #4
0
        private static int? GetTableBorder(HtmlNode node)
        {
            var table = node?.Ascendant("table") as HtmlNode;

            if (table != null && !string.IsNullOrEmpty(table.Attributes.GetValue("border")))
            {
                return table.Attributes.GetValueInt("border");
            }

            return null;
        }
Exemple #5
0
 private static string GetImageSrc(HtmlNode node)
 {
     var regex = new Regex(@"(?:http(?:s?)://www\.youtube\.com/embed/)(?<videoid>[\w_-]*)(?:\??)(?:/?)(?:\.*)");
     var src = GetIframeSrc(node);
     if (!string.IsNullOrEmpty(src))
     {
         var match = regex.Match(src);
         if (match.Success)
         {
             return $"https://i.ytimg.com/vi/{match.Groups["videoid"].Value}/maxresdefault.jpg";
         }
     }
     return null;
 }
Exemple #6
0
 protected abstract void SetScreenshot(ImageEx img, HtmlNode node);
Exemple #7
0
 protected override void SetScreenshot(ImageEx img, HtmlNode node)
 {
     img.Source = GetEmbebedImage("AppStudio.Uwp.Controls.HtmlBlock.channel9-screen.png");
     img.Background = new SolidColorBrush(Color.FromArgb(255, 249, 203, 66));
 }
Exemple #8
0
        private static string GetImageSrc(HtmlNode img)
        {
            if (!string.IsNullOrEmpty(img.Attributes.GetValue("src")))
            {
                return img.Attributes.GetValue("src");
            }
            else if (!string.IsNullOrEmpty(img.Attributes.GetValue("srcset")))
            {
                var regex = new Regex(@"(?:(?<src>[^\""'\s,]+)\s*(?:\s+\d+[wx])(?:,\s*)?)");
                var matches = regex.Matches(img.Attributes.GetValue("srcset"));

                if (matches.Count > 0)
                {
                    var m = matches[matches.Count - 1];
                    return m?.Groups["src"].Value;
                }
            }

            return null;
        }
Exemple #9
0
 protected override void SetScreenshot(ImageEx img, HtmlNode node)
 {
     img.Source = GetImageSrc(node);
 }