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 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); }
public void SetUp() { SvgWindow wnd = new SvgWindow(100, 100, new GdiRenderer()); SvgDocument doc = wnd.CreateEmptySvgDocument(); doc.LoadXml("<svg xmlns='" + SvgDocument.SvgNamespace + "'><rect /></svg>"); elm = (SvgStyleableElement)doc.SelectSingleNode("//*[local-name()='rect']"); }
public override void TestTypeFromCreateElement() { SvgWindow wnd = new SvgWindow(100, 100, null); SvgDocument doc = new SvgDocument(wnd); XmlElement elm = doc.CreateElement("", localName, "http://www.w3.org/2000/svg"); Assert.AreEqual(elmType, elm.GetType()); }
protected override void OnLoaded() { base.OnLoaded(); if (_window == null || _window.LoadFonts == false) { return; } IList <string> fontUrls = this.GetFontUrls(); if (fontUrls == null || fontUrls.Count == 0) { return; } //TODO: Trying a background run... Task.Factory.StartNew(() => { SvgWindow ownedWindow = _window.CreateOwnedWindow(); ownedWindow.LoadFonts = false; for (int i = 0; i < fontUrls.Count; i++) { var fontUrl = fontUrls[i]; try { // remove any hash (won't work for local files) int hashStart = fontUrl.IndexOf("#", StringComparison.OrdinalIgnoreCase); if (hashStart > -1) { fontUrl = fontUrl.Substring(0, hashStart); } Uri fileUrl = this.ResolveUri(fontUrl); if (fileUrl == null || fileUrl.IsAbsoluteUri == false) { continue; } string scheme = fileUrl.Scheme; if (string.Equals(scheme, "file", StringComparison.OrdinalIgnoreCase)) { this.LoadLocalFont(fileUrl.LocalPath, ownedWindow); } else { //TODO } } catch (Exception ex) { Trace.TraceError(ex.ToString()); //Ignore the exception } } }); }
public void SetUp() { // create a BitmapComparator comparator = new BitmapComparator(); // create an SVGWindow and an associated GdiRenderer renderer = new GdiRenderer(); window = new SvgWindow(75,75, renderer); }
public SvgDocument(SvgWindow window) : this() { _window = window; _window.Document = this; // set up CSS properties this.AddStyleElement(SvgDocument.SvgNamespace, "style"); this.CssPropertyProfile = CssPropertyProfile.SvgProfile; }
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 SvgDocument GetImageDocument() { SvgWindow window = this.SvgWindow; if (window == null) { return(null); } else { return((SvgDocument)window.Document); } }
public static SvgDocument GetXmlDoc(string content, string style) { SvgWindow wnd = new SvgWindow(100, 100, null); SvgDocument doc = new SvgDocument(wnd); string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"; xml += "<svg xmlns='" + SvgDocument.SvgNamespace + "' xmlns:xlink='" + SvgDocument.XLinkNamespace + "'>"; xml += "<style type='text/css'>" + style + "</style>"; xml += content; xml += "</svg>"; doc.LoadXml(xml); return doc; }
public SvgDocument(SvgWindow window) { this.window = window; this.window.Document = this; // set up CSS properties AddStyleElement(SvgDocument.SvgNamespace, "style"); CssPropertyProfile = CssPropertyProfile.SvgProfile; //this.XmlResolver = new CachingXmlUrlResolver(); // build tagName to type dictionary buildTypeDictionary(); }
public SvgPictureBox() { InitializeComponent(); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); scriptEngineByMimeType = new TypeDictionary(); SetMimeTypeEngineType("application/ecmascript", typeof(JScriptEngine)); renderer = new GdiRenderer(); renderer.OnRender = new RenderEvent(this.OnRender); window = new SvgWindow(this, renderer); }
public void TestDataImage() { string testData = "<?xml version='1.0'?>\n<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'><image id='theImage' width='50' height='50' xlink:href='data:image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSpa/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJlZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uisF81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PHhhx4dbgYKAAA7'/></svg>"; SvgWindow wnd = new SvgWindow(50, 50, null); SvgDocument doc = new SvgDocument(wnd); doc.LoadXml(testData); SvgImageElement imgElm = doc.GetElementById("theImage") as SvgImageElement; Assert.IsNotNull(imgElm); Assert.IsTrue(!imgElm.IsSvgImage, "IsSvgImage"); Bitmap bmp = imgElm.Bitmap; Assert.AreEqual(48, bmp.Width); Assert.AreEqual(48, bmp.Height); }
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 SvgImageWidget() { //scriptEngineByMimeType = new TypeDictionary(); //SetMimeTypeEngineType("application/ecmascript", //typeof(JScriptEngine)); this.Events = this.Events | Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask | Gdk.EventMask.EnterNotifyMask | Gdk.EventMask.LeaveNotifyMask | Gdk.EventMask.ScrollMask; this.CanFocus = true; renderer = new GdiRenderer(); renderer.OnRender += OnRender; window = new SvgWindow(this.Allocation.Width, this.Allocation.Height, renderer); }
protected SvgWindow(SvgWindow parentWindow, long innerWidth, long innerHeight) : this(innerWidth, innerHeight, parentWindow.CreateSvgRenderer()) { _parentWindow = parentWindow; _baseUrls = parentWindow.BaseUrls; }
private SvgDocument LoadXml(string content) { SvgWindow wnd = new SvgWindow(200, 300, null); SvgDocument doc = new SvgDocument(wnd); string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\">"; xml += content; xml += "</svg>"; doc.LoadXml(xml); return doc; }
public SvgPictureBoxWindow(SvgWindow parentWindow, long innerWidth, long innerHeight) : base(parentWindow, innerWidth, innerHeight) { }
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; }
protected SvgWindow(SvgWindow parentWindow, long innerWidth, long innerHeight) : this(innerWidth, innerHeight, parentWindow.Renderer) { _parentWindow = parentWindow; }
public SvgWindow(SvgWindow parentWindow, long innerWidth, long innerHeight) : this(innerWidth, innerHeight, parentWindow.Renderer) { this.parentWindow = parentWindow; }
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); } }
public void SetUp() { renderer = new GdiRenderer(); wnd = new SvgWindow(75, 75, renderer); doc = new SvgDocument(wnd); }
public void TestLength() { SvgWindow wnd = new SvgWindow(100, 100, null); SvgDocument doc = new SvgDocument(wnd); Assert.AreEqual(61, doc.CssPropertyProfile.Length); }
protected override void OnLoaded() { base.OnLoaded(); if (_window == null || _window.LoadFonts == false) { return; } IList <Tuple <string, SvgFontFaceElement> > fontUrls = this.GetFontUrls(); if (fontUrls == null || fontUrls.Count == 0) { return; } _isFontsLoaded = false; //TODO: Trying a background run... var loadTask = Task.Factory.StartNew(() => { SvgWindow ownedWindow = _window.CreateOwnedWindow(); ownedWindow.LoadFonts = false; for (int i = 0; i < fontUrls.Count; i++) { var fontUrl = fontUrls[i].Item1; var fontFace = fontUrls[i].Item2; try { // remove any hash (won't work for local files) int hashStart = fontUrl.IndexOf("#", StringComparison.OrdinalIgnoreCase); if (hashStart > -1) { fontUrl = fontUrl.Substring(0, hashStart); } Uri fileUrl = this.ResolveUri(fontUrl); if (fileUrl == null || fileUrl.IsAbsoluteUri == false) { continue; } string scheme = fileUrl.Scheme; if (string.Equals(scheme, "file", StringComparison.OrdinalIgnoreCase)) { this.LoadLocalFont(fileUrl.LocalPath, ownedWindow, fontFace); } else { throw new NotSupportedException("Loading fonts from a remote source is not supported."); } } catch (Exception ex) { Trace.TraceError(ex.ToString()); //Ignore the exception } } _isFontsLoaded = true; }); _window.AddTask("SvgDocument", loadTask); }
private SvgPathElement getPathElement() { SvgWindow wnd = new SvgWindow(100, 100, null); SvgDocument doc = new SvgDocument(wnd); return (SvgPathElement)doc.CreateElement("", "path", SvgDocument.SvgNamespace); }
public SvgDocument(SvgWindow window) : this() { this._window = window; this._window.Document = this; // set up CSS properties AddStyleElement(SvgDocument.SvgNamespace, "style"); CssPropertyProfile = CssPropertyProfile.SvgProfile; }
/// <summary> /// The following code will load the SVGDOM, render to a emf, and /// place the EMF on the clipboard. Kt seems more complicated than it should /// see http://www.dotnet247.com/247reference/msgs/23/118514.aspx /// for why the straight forward solution does not work. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void miCopy_Click( object sender, System.EventArgs e) { if (svgUrlCombo.Text.Length > 0) { int width = 500; int height = 500; // make SVG document with associated window so we can render it. SvgWindow window = new SvgWindow(width, height, null); GdiRenderer renderer = new GdiRenderer(); renderer.Window = window; window.Renderer = renderer; window.Src = svgUrlCombo.Text; // copy and paste code taken from // http://www.dotnet247.com/247reference/msgs/23/117611.aspx // putting a plain MetaFile on the clipboard does not work. // .Net's metafile format is not recognised by most programs. Graphics g = CreateGraphics(); IntPtr hdc = g.GetHdc(); Metafile m = new Metafile(hdc, EmfType.EmfOnly); g.ReleaseHdc(hdc); g.Dispose(); g = Graphics.FromImage(m); // draw the SVG here // NOTE: the graphics object is automatically Disposed by the // GdiRenderer. renderer.Graphics = g; renderer.Render(window.Document as SvgDocument); //window.Render(); // put meta file on the clipboard. IntPtr hwnd = this.Handle; if (Win32.OpenClipboard(hwnd)) { Win32.EmptyClipboard(); IntPtr hemf = m.GetHenhmetafile(); Win32.SetClipboardData(14, hemf); //CF_ENHMETAFILE=14 Win32.CloseClipboard(); } } }
public WpfSvgWindow(SvgWindow parentWindow, long innerWidth, long innerHeight) : base(parentWindow, innerWidth, innerHeight) { }
public void TestLocalGZip() { SvgWindow wnd = new SvgWindow(100, 100, null); SvgDocument doc = new SvgDocument(wnd); doc.Load("gzip-test.svgz"); }
protected SvgWindow(SvgWindow parentWindow, long innerWidth, long innerHeight) : this(innerWidth, innerHeight, parentWindow.Renderer) { this.parentWindow = parentWindow; }
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"); }