예제 #1
0
        public string WriteSVGString(bool compressAttributes)
        {
            string         internalSubset = "";
            XmlDocument    xmlDocument    = new XmlDocument();
            XmlDeclaration xmlDeclaration = xmlDocument.CreateXmlDeclaration("1.0", null, "yes");

            xmlDocument.AppendChild(xmlDeclaration);
            this.WriteXmlElements(xmlDocument, null);
            xmlDocument.DocumentElement.SetAttribute("xmlns", "http://www.w3.org/2000/svg");
            if (compressAttributes)
            {
                internalSubset = SvgFactory.CompressXML(xmlDocument, xmlDocument.DocumentElement);
            }
            xmlDocument.XmlResolver = new SvgElement.DummyXmlResolver();
            xmlDocument.InsertAfter(xmlDocument.CreateDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", internalSubset), xmlDeclaration);
            MemoryStream  memoryStream  = new MemoryStream();
            XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, new UTF8Encoding());

            xmlTextWriter.Formatting = Formatting.None;
            xmlDocument.Save(xmlTextWriter);
            byte[] array   = memoryStream.ToArray();
            string @string = Encoding.UTF8.GetString(array, 0, array.Length);

            xmlTextWriter.Close();
            return(@string);
        }
예제 #2
0
        /// <summary>
        /// Get a string that contains a complete SVG document.  XML version, DOCTYPE etc are included.
        /// </summary>
        /// <returns></returns>
        /// <param name="compressAttributes">Should usually be set true.  Causes the XML output to be optimized so that
        /// long attributes like styles and transformations are represented with entities.</param>
        public string WriteSVGString(bool compressAttributes)
        {
            string s;
            string ents = "";

            XmlDocument doc = new XmlDocument();

            //write out our SVG tree to the new XmlDocument
            WriteXmlElements(doc, null);

            if (compressAttributes)
            {
                ents = SvgFactory.CompressXML(doc, doc.DocumentElement);
            }

            //This complicated business of writing to a memory stream and then reading back out to a string
            //is necessary in order to specify UTF8 -- for some reason the default is UTF16 (which makes most renderers
            //give up)

            MemoryStream  ms = new MemoryStream();
            XmlTextWriter wr = new XmlTextWriter(ms, new UTF8Encoding());

            wr.Formatting = Formatting.Indented;
            wr.WriteStartDocument(true);
            wr.WriteDocType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", ents);
            doc.Save(wr);

            byte[] buf = ms.ToArray();
            s = Encoding.UTF8.GetString(buf, 0, buf.Length);

            wr.Close();

            return(s);
        }
예제 #3
0
        /// <summary>
        /// Get a string that contains a complete SVG document.  XML version, DOCTYPE etc are included.
        /// </summary>
        /// <returns></returns>
        /// <param name="compressAttributes">Should usually be set true.  Causes the XML output to be optimized so that
        /// long attributes like styles and transformations are represented with entities.</param>
        public string WriteSVGString(bool compressAttributes)
        {
            var doc = new XmlDocument();

            var declaration = doc.CreateXmlDeclaration("1.0", null, "yes");

            doc.AppendChild(declaration);

            //write out our SVG tree to the new XmlDocument
            WriteXmlElements(doc, null);

            doc.DocumentElement.SetAttribute("xmlns", "http://www.w3.org/2000/svg");

            var ents = string.Empty;

            if (compressAttributes)
            {
                ents = SvgFactory.CompressXML(doc, doc.DocumentElement);
            }

            doc.XmlResolver = new DummyXmlResolver();
            doc.InsertAfter(
                doc.CreateDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", ents),
                declaration
                );

            return(ToXmlString(doc));
        }
예제 #4
0
        private XmlDocument GetXmlDocument(bool compressAttributes, out string ents)
        {
            ents = "";

            XmlDocument doc = new XmlDocument();

            //write out our SVG tree to the new XmlDocument
            WriteXmlElements(doc, null);

            if (compressAttributes)
            {
                ents = SvgFactory.CompressXML(doc, doc.DocumentElement);
            }
            return(doc);
        }
예제 #5
0
        /// <summary>
        /// Get a string that contains a complete SVG document.  XML version, DOCTYPE etc are included.
        /// </summary>
        /// <returns></returns>
        /// <param name="compressAttributes">Should usually be set true.  Causes the XML output to be optimized so that
        /// long attributes like styles and transformations are represented with entities.</param>
        public string WriteSVGString(bool compressAttributes)
        {
            string s;
            string ents = "";

            XmlDocument doc = new XmlDocument();

            var declaration = doc.CreateXmlDeclaration("1.0", null, "yes");

            doc.AppendChild(declaration);

            //write out our SVG tree to the new XmlDocument
            WriteXmlElements(doc, null);

            doc.DocumentElement.SetAttribute("xmlns", "http://www.w3.org/2000/svg");

            if (compressAttributes)
            {
                ents = SvgFactory.CompressXML(doc, doc.DocumentElement);
            }

            doc.XmlResolver = new DummyXmlResolver();
            doc.InsertAfter(
                doc.CreateDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", ents),
                declaration
                );

            //This complicated business of writing to a memory stream and then reading back out to a string
            //is necessary in order to specify UTF8 -- for some reason the default is UTF16 (which makes most renderers
            //give up)

            MemoryStream  ms = new MemoryStream();
            XmlTextWriter wr = new XmlTextWriter(ms, new UTF8Encoding());

            wr.Formatting = Formatting.None;             // Indented formatting would be nice for debugging but causes unwanted trailing white spaces between <text> and <tspan> elements in Internet Explorer
            doc.Save(wr);

            byte[] buf = ms.ToArray();
            s = Encoding.UTF8.GetString(buf, 0, buf.Length);

            wr.Close();

            return(s);
        }