Exemple #1
0
        //==========================================================================
        /// <summary>
        ///   Loads an SVG document and renders it into a
        ///   <see cref="DrawingImage"/>.
        /// </summary>
        /// <param name="reader">
        ///   A <see cref="XmlReader"/> to read the XML structure of the SVG
        ///   document.
        /// </param>
        /// <param name="options">
        ///   <see cref="SvgReaderOptions"/> to use for parsing respectively
        ///   rendering the SVG document.
        /// </param>
        /// <returns>
        ///   A <see cref="DrawingImage"/> containing the rendered SVG document.
        /// </returns>
        public static DrawingImage Load(XmlReader reader, SvgReaderOptions options)
        {
            options ??= new SvgReaderOptions();

            var document = XDocument.Load(reader);

            if (document.Root.Name.NamespaceName != "http://www.w3.org/2000/svg")
            {
                throw new XmlException("Root element is not in namespace 'http://www.w3.org/2000/svg'.");
            }
            return(document.Root.Name.LocalName == "svg"
                ? new SvgDocument(document.Root, options).Draw()
                : throw new XmlException("Root element is not an <svg> element."));
        }
Exemple #2
0
 //==========================================================================
 public SvgDocument(XElement root, SvgReaderOptions options)
 {
     Root    = new SvgSVGElement(this, null, root);
     Options = options;
 }
Exemple #3
0
 //==========================================================================
 /// <summary>
 ///   Loads an SVG document and renders it into a
 ///   <see cref="DrawingImage"/>.
 /// </summary>
 /// <param name="stream">
 ///   A <see cref="Stream"/> to read the XML structure of the SVG
 ///   document.
 /// </param>
 /// <param name="options">
 ///   <see cref="SvgReaderOptions"/> to use for parsing respectively
 ///   rendering the SVG document.
 /// </param>
 /// <returns>
 ///   A <see cref="DrawingImage"/> containing the rendered SVG document.
 /// </returns>
 public static DrawingImage Load(Stream stream, SvgReaderOptions options)
 {
     using var reader = XmlReader.Create(stream, new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore });
     return(Load(reader, options));
 }