public void TestKnownDomain() { SvgWindow wnd = new SvgWindow(75, 75, null); SvgDocument doc = new SvgDocument(wnd); doc.Load("http://www.shiny-donkey.com/shinyDonkey.svg"); Assert.AreEqual("www.shiny-donkey.com", doc.Domain); }
private void LoadLocalFont(string fontPath, SvgWindow ownedWindow) { if (string.IsNullOrWhiteSpace(fontPath) || !File.Exists(fontPath)) { return; } string fileExt = Path.GetExtension(fontPath); if (string.Equals(fileExt, ".svg", StringComparison.OrdinalIgnoreCase) || string.Equals(fileExt, ".svgz", StringComparison.OrdinalIgnoreCase)) { SvgDocument document = new SvgDocument(ownedWindow); document.Load(fontPath); var svgFonts = document.SvgFonts; if (svgFonts != null && svgFonts.Count != 0) { foreach (var svgFont in svgFonts) { var fontNode = this.ImportNode(svgFont, true); this.DocumentElement.AppendChild(fontNode); // this.SvgFonts.Add(svgFont); } } document = null; } else if (string.Equals(fileExt, ".ttf", StringComparison.OrdinalIgnoreCase) || string.Equals(fileExt, ".otf", StringComparison.OrdinalIgnoreCase)) { } }
public void SetUp() { if(doc == null) { SvgWindow wnd = new SvgWindow(75, 75, null); doc = new SvgDocument(wnd); doc.Load(@"Renderer.Gdi\cssSelectors.svg"); } }
public void SetUp() { if(doc == null) { SvgWindow wnd = new SvgWindow(100, 100, null); doc = new SvgDocument(wnd); doc.Load("events_01.svg"); rect = (SvgRectElement)doc.SelectSingleNode("//*[local-name()='rect']"); g = (SvgGElement)doc.SelectSingleNode("//*[local-name()='g']"); } eventStatus = 0; }
public XmlNode GetNodeByUri(string absoluteUrl) { absoluteUrl = absoluteUrl.Trim(); if (absoluteUrl.StartsWith("#") || absoluteUrl.StartsWith("\"#")) { absoluteUrl = absoluteUrl.Replace("#", "").Replace("\"", ""); return(GetElementById(absoluteUrl)); //return GetElementById(absoluteUrl.Substring(1)); } else { Uri docUri = ResolveUri(""); Uri absoluteUri = new Uri(absoluteUrl); string fragment = absoluteUri.Fragment; if (fragment.Length == 0) { // no fragment => return entire document if (docUri.AbsolutePath == absoluteUri.AbsolutePath) { return(this); } else { SvgDocument doc = new SvgDocument((SvgWindow)Window); XmlReaderSettings settings = this.GetXmlReaderSettings(); settings.CloseInput = true; //PrepareXmlResolver(settings); using (XmlReader reader = XmlReader.Create( GetResource(absoluteUri).GetResponseStream(), settings, absoluteUri.AbsolutePath)) { doc.Load(reader); } return(doc); } } else { // got a fragment => return XmlElement string noFragment = absoluteUri.AbsoluteUri.Replace(fragment, ""); SvgDocument doc = (SvgDocument)GetNodeByUri(new Uri(noFragment)); return(doc.GetElementById(fragment.Substring(1))); } } }
private void LoadLocalFont(string fontPath, SvgWindow ownedWindow, SvgFontFaceElement fontFace) { if (string.IsNullOrWhiteSpace(fontPath) || !File.Exists(fontPath)) { // Trace.WriteLine("Private font not found: " + fontPath); return; } string fileExt = Path.GetExtension(fontPath); if (string.Equals(fileExt, ".svg", StringComparison.OrdinalIgnoreCase) || string.Equals(fileExt, ".svgz", StringComparison.OrdinalIgnoreCase)) { SvgDocument document = new SvgDocument(ownedWindow); document.Load(fontPath); var svgFonts = document.SvgFonts; if (svgFonts != null && svgFonts.Count != 0) { foreach (var svgFont in svgFonts) { if (fontFace != null && fontFace.HasAttribute("unicode-range")) { svgFont.SetAttribute("unicode-range", fontFace.GetAttribute("unicode-range")); } var fontNode = this.ImportNode(svgFont, true); this.DocumentElement.AppendChild(fontNode); // this.SvgFonts.Add(svgFont); } } document = null; } else if (string.Equals(fileExt, ".ttf", StringComparison.OrdinalIgnoreCase) || string.Equals(fileExt, ".otf", StringComparison.OrdinalIgnoreCase)) { Debug.Assert(false, "Testing files with this format"); } else if (string.Equals(fileExt, ".woff", StringComparison.OrdinalIgnoreCase) || string.Equals(fileExt, ".woff2", StringComparison.OrdinalIgnoreCase)) { Debug.Assert(false, "Testing files with this format"); } }
public XmlNode GetNodeByUri(string absoluteUrl) { absoluteUrl = absoluteUrl.Trim(); if (absoluteUrl.StartsWith("#")) { return(GetElementById(absoluteUrl.Substring(1))); } else { Uri docUri = ResolveUri(""); Uri absoluteUri = new Uri(absoluteUrl); string fragment = absoluteUri.Fragment; if (fragment.Length == 0) { // no fragment => return entire document if (docUri.AbsolutePath == absoluteUri.AbsolutePath) { return(this); } else { SvgDocument doc = new SvgDocument((SvgWindow)Window); XmlTextReader xtr = new XmlTextReader(absoluteUri.AbsolutePath, GetResource(absoluteUri).GetResponseStream()); XmlValidatingReader vr = new XmlValidatingReader(xtr); vr.ValidationType = ValidationType.None; doc.Load(vr); return(doc); } } else { // got a fragment => return XmlElement string noFragment = absoluteUri.AbsoluteUri.Replace(fragment, ""); SvgDocument doc = (SvgDocument)GetNodeByUri(new Uri(noFragment, true)); return(doc.GetElementById(fragment.Substring(1))); } } }
public void LoadDocument(Stream documentStream) { if (documentStream == null) { return; } SvgDocument document = new SvgDocument(this); if (_settings != null) { document.CustomSettings = _settings; } document.Load(documentStream); this.Document = document; }
public void LoadDocument(XmlReader xmlReader) { if (xmlReader == null) { return; } SvgDocument document = new SvgDocument(this); if (_settings != null) { document.CustomSettings = _settings; } document.Load(xmlReader); this.Document = document; }
public XmlNode GetNodeByUri(string absoluteUrl) { if (string.IsNullOrWhiteSpace(absoluteUrl)) { return(null); } absoluteUrl = absoluteUrl.Trim().Trim(new char[] { '\"', '\'' }); if (absoluteUrl.StartsWith("#", StringComparison.OrdinalIgnoreCase)) { return(GetElementById(absoluteUrl.Substring(1))); } Uri docUri = ResolveUri(""); Uri absoluteUri = new Uri(absoluteUrl); if (absoluteUri.IsFile) { string localFile = absoluteUri.LocalPath; if (File.Exists(localFile) == false) { Trace.TraceError("GetNodeByUri: Locally referenced file not found: " + localFile); return(null); } string fileExt = Path.GetExtension(localFile); if (!string.Equals(fileExt, ".svg", StringComparison.OrdinalIgnoreCase) && !string.Equals(fileExt, ".svgz", StringComparison.OrdinalIgnoreCase)) { Trace.TraceError("GetNodeByUri: Locally referenced file not valid: " + localFile); return(null); } } if (string.Equals(absoluteUri.Scheme, "data", StringComparison.OrdinalIgnoreCase)) { Trace.TraceError("GetNodeByUri: The Uri Scheme is 'data' is not a valid XmlDode " + absoluteUri); return(null); } string fragment = absoluteUri.Fragment; if (fragment.Length == 0) { // no fragment => return entire document if (docUri != null && string.Equals(docUri.AbsolutePath, absoluteUri.AbsolutePath, StringComparison.OrdinalIgnoreCase)) { return(this); } SvgDocument doc = new SvgDocument((SvgWindow)Window); XmlReaderSettings settings = this.GetXmlReaderSettings(); settings.CloseInput = true; //PrepareXmlResolver(settings); using (XmlReader reader = XmlReader.Create(GetResource(absoluteUri).GetResponseStream(), settings, absoluteUri.AbsolutePath)) { doc.Load(reader); } return(doc); } else { // got a fragment => return XmlElement string noFragment = absoluteUri.AbsoluteUri.Replace(fragment, ""); SvgDocument doc = (SvgDocument)GetNodeByUri(new Uri(noFragment)); return(doc.GetElementById(fragment.Substring(1))); } }
public void LoadDocument(Uri documentUri) { if (documentUri == null || !documentUri.IsAbsoluteUri) { return; } SvgDocument document = new SvgDocument(this); if (_settings != null) { document.CustomSettings = _settings; } document.Load(documentUri.AbsoluteUri); this.Document = document; }
private int singleRun(string filePath, bool saveLocal, bool saveImage) { DateTime startTime = DateTime.Now; GdiRenderer gdiRenderer = new GdiRenderer(); SvgWindow wnd = new SvgWindow(300, 300, gdiRenderer); SvgDocument doc = new SvgDocument(wnd); wnd.Document = doc; doc.Load(filePath); //wnd.Render(); if(((GdiRenderer)wnd.Renderer).RasterImage == null) { Console.WriteLine("ERROR: no image rendered"); } DateTime endTime = DateTime.Now; TimeSpan diff = endTime - startTime; if(saveLocal) { doc.Save(localPath); } if(saveImage) { ((GdiRenderer)wnd.Renderer).RasterImage.Save(imgPath, System.Drawing.Imaging.ImageFormat.Png); Console.WriteLine("Reference image saved as :\n" + imgPath); } wnd.Renderer = null; wnd = null; doc = null; return (int)diff.TotalMilliseconds; }
private void LoadLocalFont(string fontPath, SvgWindow ownedWindow, SvgFontFaceElement fontFace) { if (string.IsNullOrWhiteSpace(fontPath) || !File.Exists(fontPath)) { // Trace.WriteLine("Private font not found: " + fontPath); return; } string fileExt = Path.GetExtension(fontPath); if (string.Equals(fileExt, ".svg", StringComparison.OrdinalIgnoreCase) || string.Equals(fileExt, ".svgz", StringComparison.OrdinalIgnoreCase)) { SvgDocument document = new SvgDocument(ownedWindow); document.Load(fontPath); var svgFonts = document.SvgFonts; if (svgFonts != null && svgFonts.Count != 0) { foreach (var svgFont in svgFonts) { if (fontFace != null && fontFace.HasAttribute("unicode-range")) { svgFont.SetAttribute("unicode-range", fontFace.GetAttribute("unicode-range")); } var fontNode = this.ImportNode(svgFont, true); this.DocumentElement.AppendChild(fontNode); // this.SvgFonts.Add(svgFont); } } document = null; } else if (string.Equals(fileExt, ".woff", StringComparison.OrdinalIgnoreCase) || string.Equals(fileExt, ".woff2", StringComparison.OrdinalIgnoreCase)) { if (_fontFamilies == null) { _fontFamilies = new List <SvgFontFamily>(); } var woffParser = new SvgWoffParser(); if (woffParser.Import(fontPath)) { string fontExportPath = woffParser.DefaultExportPath; if (File.Exists(fontExportPath)) { var fontFamily = new SvgFontFamily(true, fontExportPath, fontPath); _fontFamilies.Add(fontFamily); } else { fontExportPath = woffParser.GetExportPath(); if (woffParser.Export(fontExportPath)) { var fontFamily = new SvgFontFamily(true, fontExportPath, fontPath); _fontFamilies.Add(fontFamily); } } } } else if (string.Equals(fileExt, ".ttf", StringComparison.OrdinalIgnoreCase) || string.Equals(fileExt, ".otf", StringComparison.OrdinalIgnoreCase)) { if (_fontFamilies == null) { _fontFamilies = new List <SvgFontFamily>(); } var fontFamily = new SvgFontFamily(false, fontPath); _fontFamilies.Add(fontFamily); } else if (string.Equals(fileExt, ".ttc", StringComparison.OrdinalIgnoreCase) || string.Equals(fileExt, ".otc", StringComparison.OrdinalIgnoreCase)) { if (_fontFamilies == null) { _fontFamilies = new List <SvgFontFamily>(); } var fontFamily = new SvgFontFamily(false, fontPath); _fontFamilies.Add(fontFamily); } }
private bool CompareImages(string svgFile) { svgFile = Path.Combine(baseDir, svgFile); CompareUtil util = new CompareUtil(); SvgDocument doc = new SvgDocument(window); doc.Load(svgFile); return util.CompareImages(renderer.Render(doc), svgFile + ".png"); }
public void TestLocalGZip() { SvgWindow wnd = new SvgWindow(100, 100, null); SvgDocument doc = new SvgDocument(wnd); doc.Load("gzip-test.svgz"); }
public XmlNode GetNodeByUri(string absoluteUrl) { absoluteUrl = absoluteUrl.Trim(); if(absoluteUrl.StartsWith("#")) { return GetElementById(absoluteUrl.Substring(1)); } else { Uri docUri = ResolveUri(""); Uri absoluteUri = new Uri(absoluteUrl); string fragment = absoluteUri.Fragment; if(fragment.Length == 0) { // no fragment => return entire document if(docUri.AbsolutePath == absoluteUri.AbsolutePath) { return this; } else { SvgDocument doc = new SvgDocument((SvgWindow)Window); XmlTextReader xtr = new XmlTextReader(absoluteUri.AbsolutePath, GetResource(absoluteUri).GetResponseStream() ); XmlValidatingReader vr = new XmlValidatingReader(xtr); vr.ValidationType = ValidationType.None; doc.Load(vr); return doc; } } else { // got a fragment => return XmlElement string noFragment = absoluteUri.AbsoluteUri.Replace(fragment, ""); SvgDocument doc = (SvgDocument)GetNodeByUri(new Uri(noFragment, true)); return doc.GetElementById(fragment.Substring(1)); } } }
public XmlNode GetNodeByUri(string absoluteUrl) { absoluteUrl = absoluteUrl.Trim(); if (absoluteUrl.StartsWith("#")) { return GetElementById(absoluteUrl.Substring(1)); } else { Uri docUri = ResolveUri(""); Uri absoluteUri = new Uri(absoluteUrl); string fragment = absoluteUri.Fragment; if (fragment.Length == 0) { // no fragment => return entire document if (docUri.AbsolutePath == absoluteUri.AbsolutePath) { return this; } else { SvgDocument doc = new SvgDocument((SvgWindow)Window); XmlReaderSettings settings = this.GetXmlReaderSettings(); settings.CloseInput = true; //PrepareXmlResolver(settings); using (XmlReader reader = XmlReader.Create( GetResource(absoluteUri).GetResponseStream(), settings, absoluteUri.AbsolutePath)) { doc.Load(reader); } return doc; } } else { // got a fragment => return XmlElement string noFragment = absoluteUri.AbsoluteUri.Replace(fragment, ""); SvgDocument doc = (SvgDocument)GetNodeByUri(new Uri(noFragment)); return doc.GetElementById(fragment.Substring(1)); } } }
public void TestRemoteGZip() { SvgWindow wnd = new SvgWindow(100, 100, null); SvgDocument doc = new SvgDocument(wnd); doc.Load("http://www.sharpvectors.org/tests/gzip-test.svgz"); }