Created
April 9, 2020 06:53
-
-
Save juanpaexpedite/54fe45c2a468e7e25a3a83491fee0ac2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Documents; | |
using System.Windows.Input; | |
using System.Windows.Media; | |
using System.Windows.Media.Imaging; | |
using System.Windows.Navigation; | |
using System.Windows.Shapes; | |
using System.Xml; | |
using System.Xml.XPath; | |
namespace SKIASVGExampleWPFNETFr | |
{ | |
/// <summary> | |
/// Interaction logic for MainWindow.xaml | |
/// </summary> | |
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
this.Loaded += MainWindow_Loaded; | |
} | |
SkiaSharp.Extended.Svg.SKSvg sksvg = new SkiaSharp.Extended.Svg.SKSvg(); | |
private void MainWindow_Loaded(object sender, RoutedEventArgs e) | |
{ | |
var document = new XmlDocument(); | |
document.Load("Assets/Firefox.75.0.svg"); | |
XmlNode svg = null; | |
foreach (XmlNode svgchild in document.ChildNodes) | |
{ | |
if (svgchild.Name is "svg") | |
{ | |
svg = svgchild; | |
break; | |
} | |
} | |
if (svg != null) | |
{ | |
foreach (XmlNode child in svg.ChildNodes) | |
{ | |
if (child.Name is "path") // or another to add here | |
{ | |
if (child.Attributes["fill"] != null) | |
{ | |
//Trying to solve Firefox.75.0.svg | |
var fillattrib = child.Attributes["fill"]; | |
var fill = fillattrib.Value; | |
XmlAttribute style = document.CreateAttribute("style"); | |
//style.Value = $"fill:{fill}"; | |
style.Value = $"fill:#ff00ff"; | |
child.Attributes.Append(style); | |
child.Attributes.Remove(fillattrib); | |
} | |
if (child.Attributes["d"] != null) | |
{ | |
////Trying to break wikipedia.svg | |
var dattrib = child.Attributes["d"]; | |
var d = dattrib.Value; | |
d = d.Replace(",", " "); | |
child.Attributes["d"].Value = d; | |
} | |
} | |
} | |
} | |
using (var reader = new XmlNodeReader(document)) | |
{ | |
sksvg.Load(reader); | |
} | |
SkiaCanvas.InvalidateVisual(); | |
} | |
private void SkiaCanvas_PaintSurface(object sender, SkiaSharp.Views.Desktop.SKPaintSurfaceEventArgs e) | |
{ | |
if (sksvg != null && sksvg.Picture != null) | |
{ | |
e.Surface.Canvas.DrawPicture(sksvg.Picture); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment