/// <summary>
        /// Renders the <see cref="SvgDocument">SvgDocument</see>.
        /// </summary>
        /// <param name="node">
        /// The <see cref="SvgDocument">SvgDocument</see> node to be
        /// rendered
        /// </param>
        /// <returns>
        /// The bitmap on which the rendering was performed.
        /// </returns>
        public void Render(ISvgDocument node)
        {
            SvgRectF updatedRect;

            if (invalidRect != SvgRectF.Empty)
            {
                updatedRect = new SvgRectF(invalidRect.X, invalidRect.Y,
                                           invalidRect.Width, invalidRect.Height);
            }
            else
            {
                updatedRect = SvgRectF.Empty;
            }

            RendererBeforeRender();

            if (graphics != null && graphics.Graphics != null)
            {
                _svgRenderer.Render(node);
            }

            RendererAfterRender();

            if (onRender != null)
            {
                OnRender(updatedRect);
            }
        }
        private async Task RenderSvgSource(string svgSource)
        {
            if (string.IsNullOrWhiteSpace(svgSource))
            {
                return;
            }

            try
            {
                this.Cursor = Cursors.WaitCursor;
                await svgPictureBox.LoadAsync(svgSource);

                // JR Test event
                ISvgDocument doc = svgPictureBox.Window.Document;
                if (doc != null && doc.RootElement != null)
                {
                    doc.RootElement.AddEventListener("click", new EventListener(OnSvgElementClicked), false);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), MainForm.AppErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
示例#3
0
        private void Load(string svgFile)
        {
            string fullPath = new FileInfo(baseDir + svgFile).FullName;

            window.Src = fullPath;
            document   = window.Document;
        }
示例#4
0
        public void Render(ISvgDocument docElement)
        {
            SvgSvgElement root = docElement.RootElement as SvgSvgElement;

            var baseUrl = root.BaseURI;

            var context = _renderer.Context;

            if (!string.IsNullOrWhiteSpace(baseUrl) && context != null)
            {
                context.AddUrl(baseUrl);

                var window = docElement.Window;
                if (window != null && window.BaseUrls == null)
                {
                    window.BaseUrls = context.BaseUrls;
                }
            }

            if (root != null)
            {
                this.Render(root);
            }

            if (!string.IsNullOrWhiteSpace(baseUrl) && context != null)
            {
                context.RemoveUrl(baseUrl);
            }
        }
示例#5
0
        public void TestOwnerDocument()
        {
            SvgElement   elm = Util.GetXmlElement("<" + localName + " xmlns='http://www.w3.org/2000/svg' />", "", localName) as SvgElement;
            ISvgDocument doc = elm.OwnerDocument as ISvgDocument;

            Assert.IsNotNull(doc);
        }
        public void Render(ISvgDocument node)
        {
            //SvgRectF updatedRect;
            //if (invalidRect != SvgRectF.Empty)
            //    updatedRect = new SvgRectF(invalidRect.X, invalidRect.Y,
            //        invalidRect.Width, invalidRect.Height);
            //else
            //    updatedRect = SvgRectF.Empty;

            //RendererBeforeRender();

            //_renderingContext = new WpfDrawingContext(new DrawingGroup());
            if (_svgRenderer == null)
            {
                _svgRenderer = new WpfRenderingHelper(this);
            }

            _context = new WpfDrawingContext(_isEmbedded, _settings);

            _context.Initialize(_linkVisitor, _fontFamilyVisitor, _imageVisitor);

            _context.BeginDrawing(_drawingDocument);

            _svgRenderer.Render(node);

            _context.EndDrawing();

            //RendererAfterRender();

            //if (onRender != null)
            //    OnRender(updatedRect);
        }
        public void Render(ISvgDocument docElement)
        {
            SvgSvgElement root = docElement.RootElement as SvgSvgElement;

            if (root != null)
            {
                this.Render(root);
            }
        }
        public void Render(ISvgDocument docElement)
        {
            SvgSvgElement root = docElement.RootElement as SvgSvgElement;

            if (root != null)
            {
                this.Render(root);
            }
        }
示例#9
0
        public void Render(ISvgDocument node)
        {
            //SvgRectF updatedRect;
            //if (invalidRect != SvgRectF.Empty)
            //    updatedRect = new SvgRectF(invalidRect.X, invalidRect.Y,
            //        invalidRect.Width, invalidRect.Height);
            //else
            //    updatedRect = SvgRectF.Empty;

            //RendererBeforeRender();

            //_renderingContext = new WpfDrawingContext(new DrawingGroup());
            if (_svgRenderer == null)
            {
                _svgRenderer = new WpfRenderingHelper(this);
            }

            var isStatic = node.Static;

            node.Static = true;

            _context = new WpfDrawingContext(_isEmbedded, _settings);

            _context.Initialize(_linkVisitor, _fontFamilyVisitor, _imageVisitor);

            if (!_isEmbedded)
            {
                if (_svgWindow != null && _svgWindow.BaseUrls == null)
                {
                    _svgWindow.BaseUrls = _context.BaseUrls;
                }
            }

            _context.BeginDrawing(_drawingDocument);

            _svgRenderer.Render(node);

            _context.EndDrawing();

            if (!_isEmbedded)
            {
                if (_svgWindow != null && _svgWindow.BaseUrls != null && _svgWindow.BaseUrls.Count != 0)
                {
                    _svgWindow.BaseUrls.Clear();
                }

                node.Static = isStatic;
            }

            //RendererAfterRender();

            //if (onRender != null)
            //    OnRender(updatedRect);
        }
示例#10
0
        private DrawingImage LoadSvg(Stream svgStream)
        {
            if (svgStream == null)
            {
                return(null);
            }

            // Read the SVG file
            DrawingGroup drawing = _converter.Read(svgStream);

            if (drawing != null)
            {
                DomDocument = _converter.DomDocument;
                ISvgSvgElement root        = DomDocument.RootElement;
                Color?         fillColor   = GetColor(root, @"fill");
                Color?         strokeColor = GetColor(root, @"stroke");
                if (fillColor != null)
                {
                    _BackgroundColor.ARGB = CommonFunction.CovertColorToInt(fillColor.Value);
                    _bSupportBackground   = true;
                    FirePropertyChanged("vBackgroundColor");
                }

                if (strokeColor != null)
                {
                    _StrokeColor.ARGB = CommonFunction.CovertColorToInt(strokeColor.Value);
                    _bSupportBorder   = true;
                    FirePropertyChanged("vBorderLineColor");
                }


                string ratio = root.GetAttribute("preserveAspectRatio");
                if (string.IsNullOrEmpty(ratio))
                {
                    root.SetAttribute("preserveAspectRatio", "none");
                    GetApectRatio(root.GetAttribute("viewBox"));
                }

                MemoryStream stream = new MemoryStream();
                (DomDocument as SvgDocument).Save(stream);
                (_model as SVGModel).SVGUpdateStream = stream;
                return(new DrawingImage(drawing));
            }
            else
            {
                DomDocument         = null;
                _bSupportBackground = false;
                _bSupportBorder     = false;
                FirePropertyChanged("vBackgroundColor");
                FirePropertyChanged("vBorderLineColor");
                return(null);
            }
        }
示例#11
0
        private async Task OpenSvgSource(string svgSource)
        {
            if (string.IsNullOrWhiteSpace(svgSource))
            {
                return;
            }

            try
            {
                this.Cursor = Cursors.WaitCursor;
                await svgPictureBox.LoadAsync(svgSource);

                // JR Test event
                ISvgDocument doc = svgPictureBox.Window.Document;
                if (doc != null && doc.RootElement != null)
                {
                    doc.RootElement.AddEventListener("click", new EventListener(OnSvgElementClicked), false);
                }

                if (File.Exists(svgSource))
                {
                    this.Text = _titleBase + " - " + Path.GetFileName(svgSource);
                }
                else
                {
                    var uriSource = TryGetUri(svgSource);
                    if (uriSource != null)
                    {
                        this.Text = _titleBase + " - " + uriSource.AbsoluteUri;
                    }
                    else
                    {
                        this.Text = _titleBase + " - " + svgSource;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
示例#12
0
        private void loadUrl(
            string url)
        {
            if (url.StartsWith("http://www.w3.org/Graphics/SVG/Test/20021112/svggen/"))
            {
                // SVG test suite file
                svgPictureBox.Size      = new System.Drawing.Size(480, 360);
                this.svgPictureBox.Dock = System.Windows.Forms.DockStyle.None;
                this.pbRefImage.Visible = miTestShowRefImage.Checked;
            }
            else
            {
                //this.svgPictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
                this.pbRefImage.Visible = false;
            }

            // JR simple timing
            DateTime started = DateTime.Now;

            svgPictureBox.SourceURL = url;

            string title = svgPictureBox.Window.Document.Title;

            if (title.Length > 0)
            {
                this.Text = this.title + " - " + title;
            }
            else
            {
                this.Text = this.title;
            }

            // JR simple timing
            TimeSpan duration = DateTime.Now - started;

            statusBar.Text = "Done (" + duration + ")";

            // JR Test event
            ISvgDocument doc = svgPictureBox.Window.Document;

            doc.RootElement.AddEventListener("click", new EventListener(ClickMe), false);
        }
示例#13
0
        private void OpenSvgFile(string fileName)
        {
            if (string.IsNullOrWhiteSpace(fileName) || !File.Exists(fileName))
            {
                return;
            }
            string fileExt = Path.GetExtension(fileName);

            if (string.IsNullOrWhiteSpace(fileExt))
            {
                return;
            }
            if (!string.Equals(fileExt, ".svgz", StringComparison.OrdinalIgnoreCase) &&
                !string.Equals(fileExt, ".svg", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            try
            {
                this.Cursor = Cursors.WaitCursor;
                svgPictureBox.Load(fileName);

                // JR Test event
                ISvgDocument doc = svgPictureBox.Window.Document;
                if (doc != null && doc.RootElement != null)
                {
                    doc.RootElement.AddEventListener("click", new EventListener(OnSvgElementClicked), false);
                }

                this.Text = _titleBase + " - " + Path.GetFileName(fileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
示例#14
0
        /// <summary>
        /// Renders the <see cref="SvgDocument">SvgDocument</see>.
        /// </summary>
        /// <param name="node">
        /// The <see cref="SvgDocument">SvgDocument</see> node to be
        /// rendered
        /// </param>
        /// <returns>
        /// The bitmap on which the rendering was performed.
        /// </returns>
        public Bitmap Render(
            ISvgDocument node)
        {
            RectangleF updatedRect;

            if (invalidRect != RectangleF.Empty)
            {
                updatedRect = new RectangleF(invalidRect.X, invalidRect.Y, invalidRect.Width, invalidRect.Height);
            }
            else
            {
                updatedRect = RectangleF.Empty;
            }
            RendererBeforeRender();
            ((SvgDocument)node).Render(this);
            RendererAfterRender();
            if (onRender != null)
            {
                OnRender(updatedRect);
            }
            return(rasterImage);
        }
示例#15
0
 public void Render(ISvgDocument node)
 {
     RenderElement(node.RootElement);
 }
        /// <summary>
        /// Renders the <see cref="SvgDocument">SvgDocument</see>.
        /// </summary>
        /// <param name="node">
        /// The <see cref="SvgDocument">SvgDocument</see> node to be
        /// rendered
        /// </param>
        /// <returns>
        /// The bitmap on which the rendering was performed.
        /// </returns>
        public void Render(ISvgDocument node)
        {
            SvgRectF updatedRect;
            if (invalidRect != SvgRectF.Empty)
                updatedRect = new SvgRectF(invalidRect.X, invalidRect.Y,
                    invalidRect.Width, invalidRect.Height);
            else
                updatedRect = SvgRectF.Empty;

            RendererBeforeRender();

            if (graphics != null && graphics.Graphics != null)
            {
                _svgRenderer.Render(node);
            }

            RendererAfterRender();

            if (onRender != null)
                OnRender(updatedRect);
        }
示例#17
0
 private void Load(string svgFile)
 {
     string fullPath = new FileInfo(baseDir+svgFile).FullName;
     window.Src = fullPath;
     document = window.Document;
 }
        public void Render(ISvgDocument node)
        {
            //SvgRectF updatedRect;
            //if (invalidRect != SvgRectF.Empty)
            //    updatedRect = new SvgRectF(invalidRect.X, invalidRect.Y,
            //        invalidRect.Width, invalidRect.Height);
            //else
            //    updatedRect = SvgRectF.Empty;

            //RendererBeforeRender();

            //_renderingContext = new WpfDrawingContext(new DrawingGroup());
            _renderingContext = new WpfDrawingContext(false,
                _renderingSettings);

            _renderingContext.Initialize(_linkVisitor, _fontFamilyVisitor, _imageVisitor);

            _renderingContext.BeginDrawing();

            _svgRenderer.Render(node);

            _renderingContext.EndDrawing();

            //RendererAfterRender();

            //if (onRender != null)
            //    OnRender(updatedRect);
        }
示例#19
0
 public ExampleCreateBox(ISvgDocument document)
 {
     _document = document;
 }
示例#20
0
 /// <summary>
 /// Renders the <see cref="SvgDocument">SvgDocument</see>.
 /// </summary>
 /// <param name="node">
 /// The <see cref="SvgDocument">SvgDocument</see> node to be
 /// rendered
 /// </param>
 /// <returns>
 /// The bitmap on which the rendering was performed.
 /// </returns>
 public Bitmap Render(
 ISvgDocument node)
 {
     RectangleF updatedRect;
     if (invalidRect != RectangleF.Empty)
     updatedRect = new RectangleF(invalidRect.X, invalidRect.Y, invalidRect.Width, invalidRect.Height);
     else
     updatedRect = RectangleF.Empty;
     RendererBeforeRender();
     ((SvgDocument)node).Render(this);
     RendererAfterRender();
     if (onRender != null)
     OnRender(updatedRect);
     return rasterImage;
 }