Ejemplo n.º 1
0
        public void SetDTDLocation(string dtdLocation)
        {
            System.Xml.XmlDocument doc = (System.Xml.XmlDocument)Node;
            string publicId            = null;
            string internalSubset      = null;

            if (doc.DocumentElement == null)
            {
                throw new System.InvalidOperationException("SetDTDLocation requires a root element.");
            }
            if (doc.DocumentType != null)
            {
                publicId       = doc.DocumentType.PublicId;
                internalSubset = doc.DocumentType.InternalSubset;

                doc.RemoveChild(doc.DocumentType);
            }
            doc.InsertBefore(doc.DocumentElement, doc.CreateDocumentType(doc.DocumentElement.Name, publicId, dtdLocation, internalSubset));
        }
Ejemplo n.º 2
0
        CreatePlist()
        {
            var doc = new System.Xml.XmlDocument();

            // don't resolve any URLs, or if there is no internet, the process will pause for some time
            doc.XmlResolver = null;

            {
                var type = doc.CreateDocumentType("plist", "-//Apple Computer//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);
                doc.AppendChild(type);
            }
            var plistEl = doc.CreateElement("plist");
            {
                var versionAttr = doc.CreateAttribute("version");
                versionAttr.Value = "1.0";
                plistEl.Attributes.Append(versionAttr);
            }

            var dictEl = doc.CreateElement("dict");

            plistEl.AppendChild(dictEl);
            doc.AppendChild(plistEl);

#if true
            // TODO: this seems to be the only way to get the target settings working
            CreateKeyValuePair(doc, dictEl, "BuildLocationStyle", "UseTargetSettings");
#else
            // build and intermediate file locations
            CreateKeyValuePair(doc, dictEl, "BuildLocationStyle", "CustomLocation");
            CreateKeyValuePair(doc, dictEl, "CustomBuildIntermediatesPath", "XcodeIntermediates"); // where xxx.build folders are stored
            CreateKeyValuePair(doc, dictEl, "CustomBuildLocationType", "RelativeToWorkspace");
            CreateKeyValuePair(doc, dictEl, "CustomBuildProductsPath", ".");                       // has to be the workspace folder, in order to write files to expected locations

            // derived data
            CreateKeyValuePair(doc, dictEl, "DerivedDataCustomLocation", "XcodeDerivedData");
            CreateKeyValuePair(doc, dictEl, "DerivedDataLocationStyle", "WorkspaceRelativePath");
#endif

            this.Document = doc;
        }
Ejemplo n.º 3
0
        CreateManagementPlist()
        {
            var doc = new System.Xml.XmlDocument();

            // don't resolve any URLs, or if there is no internet, the process will pause for some time
            doc.XmlResolver = null;

            {
                var type = doc.CreateDocumentType("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);
                doc.AppendChild(type);
            }
            var plistEl = doc.CreateElement("plist");

            plistEl.SetAttribute("version", "1.0");

            var dictEl = doc.CreateElement("dict");

            plistEl.AppendChild(dictEl);
            doc.AppendChild(plistEl);

            {
                var key = doc.CreateElement("key");
                key.InnerText = "SchemeUserState";
                dictEl.AppendChild(key);

                var valueDict = doc.CreateElement("dict");
                dictEl.AppendChild(valueDict);

                foreach (var scheme in this.SchemeDocuments)
                {
                    var schemeKey = doc.CreateElement("key");
                    schemeKey.InnerText = System.IO.Path.GetFileName(scheme.Key);
                    valueDict.AppendChild(schemeKey);
                }
            }

            this.ManagementDocument = doc;
        }
Ejemplo n.º 4
0
        public void CreateSvg(string version)
        {
            this.SvgDocument = new System.Xml.XmlDocument();
            if (System.Environment.OSVersion.Platform != System.PlatformID.Unix)
            {
                this.SvgDocument.XmlResolver = null; // .NET Framework
            }
            //System.Xml.XmlDocumentType doctype = SvgDocument.CreateDocumentType("html", "-//W3C//DTD HTML 4.01//EN", "http://www.w3.org/TR/html4/strict.dtd", null);
            System.Xml.XmlDocumentType doctype = SvgDocument.CreateDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", null);
            SvgDocument.AppendChild(doctype);

            this.SvgElement = SvgDocument.CreateElement("svg", SVGnamespace);

            this.SvgElement.SetAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/");
            this.SvgElement.SetAttribute("xmlns:cc", "http://creativecommons.org/ns#");
            this.SvgElement.SetAttribute("xmlns:rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
            this.SvgElement.SetAttribute("xmlns:svg", SVGnamespace);

            // System.Xml.XmlAttribute attribute = svgDocument.CreateAttribute("version"); ;
            // attribute.Value = version;
            // this.SvgElement.Attributes.Append(attribute);

            this.SvgElement.SetAttribute("version", version);
            this.SvgElement.SetAttribute("width", "500");
            this.SvgElement.SetAttribute("height", "500");

            // http://tutorials.jenkov.com/svg/svg-viewport-view-box.html
            // svgElement.SetAttribute("viewBox", "0 0 500 500");
            this.SvgElement.SetAttribute("viewBox", "0 0 "
                                         + this.SvgElement.Attributes["width"].Value
                                         + " "
                                         + this.SvgElement.Attributes["height"].Value);

            // preserveAspectRatio="none"

            this.RootNode = SvgDocument.AppendChild(this.SvgElement);
        }
Ejemplo n.º 5
0
 bool svgconcat(List<string> files, string output, uint delay, uint loop) {
     if (controller_ != null) controller_.appendOutput("TeX2img: Making animation svg...");
     try {
         var outxml = new System.Xml.XmlDocument();
         outxml.XmlResolver = null;
         outxml.AppendChild(outxml.CreateXmlDeclaration("1.0", "utf-8", "no"));
         outxml.AppendChild(outxml.CreateDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", null));
         var svg = outxml.CreateElement("svg", "http://www.w3.org/2000/svg");
         var attr = outxml.CreateAttribute("xmlns:xlink");
         attr.Value = "http://www.w3.org/1999/xlink";
         svg.Attributes.Append(attr);
         attr = outxml.CreateAttribute("version");
         attr.Value = "1.1";
         svg.Attributes.Append(attr);
         outxml.AppendChild(svg);
         var defs = outxml.CreateElement("defs", "http://www.w3.org/2000/svg");
         svg.AppendChild(defs);
         var idreg = new System.Text.RegularExpressions.Regex(@"(?<!\&)#");
         foreach (var f in files) {
             var id = Path.GetFileNameWithoutExtension(f);
             var xml = new System.Xml.XmlDocument();
             xml.XmlResolver = null;
             xml.Load(Path.Combine(workingDir, f));
             foreach (System.Xml.XmlNode tag in xml.GetElementsByTagName("*")) {
                 foreach (System.Xml.XmlAttribute a in tag.Attributes) {
                     if (a.Name.ToLower() == "id") a.Value = id + "-" + a.Value;
                     else a.Value = idreg.Replace(a.Value, "#" + id + "-");
                 }
             }
             foreach (System.Xml.XmlNode tag in xml.GetElementsByTagName("svg")) {
                 var idattr = xml.CreateAttribute("id");
                 idattr.Value = id;
                 tag.Attributes.Append(idattr);
             }
             foreach (System.Xml.XmlNode n in xml.ChildNodes) {
                 if (n.NodeType != System.Xml.XmlNodeType.DocumentType && n.NodeType != System.Xml.XmlNodeType.XmlDeclaration) {
                     defs.AppendChild(outxml.ImportNode(n, true));
                 }
             }
         }
         var use = outxml.CreateElement("use", "http://www.w3.org/2000/svg");
         svg.AppendChild(use);
         var animate = outxml.CreateElement("animate", "http://www.w3.org/2000/svg");
         use.AppendChild(animate);
         attr = outxml.CreateAttribute("attributeName");
         attr.Value = "xlink:href"; animate.Attributes.Append(attr);
         attr = outxml.CreateAttribute("begin");
         attr.Value = "0s"; animate.Attributes.Append(attr);
         attr = outxml.CreateAttribute("dur");
         attr.Value = ((decimal)(delay * files.Count) / 100).ToString() + "s";
         animate.Attributes.Append(attr);
         attr = outxml.CreateAttribute("repeatCount");
         attr.Value = loop > 0 ? loop.ToString() : "indefinite";
         animate.Attributes.Append(attr);
         attr = outxml.CreateAttribute("values");
         attr.Value = String.Join(";", files.Select(d => "#" + Path.GetFileNameWithoutExtension(d)).ToArray());
         animate.Attributes.Append(attr);
         outxml.Save(Path.Combine(workingDir, output));
         if (controller_ != null) controller_.appendOutput(" done\n");
         return true;
     }
     catch (Exception) { return false; }
 }
Ejemplo n.º 6
0
        private void CreatePlist()
        {
            var doc = new System.Xml.XmlDocument();
            // don't resolve any URLs, or if there is no internet, the process will pause for some time
            doc.XmlResolver = null;

            {
                var type = doc.CreateDocumentType("plist", "-//Apple Computer//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);
                doc.AppendChild(type);
            }
            var plistEl = doc.CreateElement("plist");
            {
                var versionAttr = doc.CreateAttribute("version");
                versionAttr.Value = "1.0";
                plistEl.Attributes.Append(versionAttr);
            }

            var dictEl = doc.CreateElement("dict");
            plistEl.AppendChild(dictEl);
            doc.AppendChild(plistEl);

            #if true
            // TODO: this seems to be the only way to get the target settings working
            CreateKeyValuePair(doc, dictEl, "BuildLocationStyle", "UseTargetSettings");
            #else
            // build and intermediate file locations
            CreateKeyValuePair(doc, dictEl, "BuildLocationStyle", "CustomLocation");
            CreateKeyValuePair(doc, dictEl, "CustomBuildIntermediatesPath", "XcodeIntermediates"); // where xxx.build folders are stored
            CreateKeyValuePair(doc, dictEl, "CustomBuildLocationType", "RelativeToWorkspace");
            CreateKeyValuePair(doc, dictEl, "CustomBuildProductsPath", "."); // has to be the workspace folder, in order to write files to expected locations

            // derived data
            CreateKeyValuePair(doc, dictEl, "DerivedDataCustomLocation", "XcodeDerivedData");
            CreateKeyValuePair(doc, dictEl, "DerivedDataLocationStyle", "WorkspaceRelativePath");
            #endif

            this.Document = doc;
        }
        /// <summary>
        /// Very basic SVGfile creation routine to make on SVG the display s two circles and mesh.
        /// kept simple just for this sample; there much better SVG toolkits avalable that cloud.
        /// be used for general purpose routines.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="circle1"></param>
        /// <param name="circle2"></param>
        /// <param name="intersectionMeshes"></param>
        static void WriteSvgFiles(string path, Circle circle1, Circle circle2, Mesh[] intersectionMeshes)
        {
            var doc = new System.Xml.XmlDocument();

            doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", "no"));
            doc.XmlResolver = null;
            doc.AppendChild(doc.CreateDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", null));
            var svgroot = doc.CreateElement("svg");

            var bbox = circle1.BoundingBox;

            bbox.Union(circle2.BoundingBox);
            var length = (bbox.Max - bbox.Min).Length;

            bbox.Inflate(length * 0.05);

            AppendAttribute(doc, svgroot, "viewBox", $"{bbox.Min.X} {bbox.Min.Y} {bbox.Max.X - bbox.Min.X} {bbox.Max.Y - bbox.Min.Y}");
            AppendAttribute(doc, svgroot, "version", "1.1");
            AppendAttribute(doc, svgroot, "xmlns", "http://www.w3.org/2000/svg");
            doc.AppendChild(svgroot);

            if (intersectionMeshes != null)
            {
                foreach (var mesh in intersectionMeshes)
                {
                    foreach (var face in mesh.Faces)
                    {
                        var elem   = doc.CreateElement("polygon");
                        var attrib = doc.CreateAttribute("fill");
                        attrib.Value = "#008000"; // green
                        elem.Attributes.Append(attrib);
                        attrib       = doc.CreateAttribute("stroke");
                        attrib.Value = "#008000"; // green
                        elem.Attributes.Append(attrib);
                        attrib = doc.CreateAttribute("points");
                        StringBuilder sb     = new StringBuilder();
                        var           points = new List <Rhino.Geometry.Point3d>();
                        points.Add(mesh.Vertices[face.A]);
                        points.Add(mesh.Vertices[face.B]);
                        points.Add(mesh.Vertices[face.C]);
                        if (face.IsQuad)
                        {
                            points.Add(mesh.Vertices[face.D]);
                        }
                        for (int i = 0; i < points.Count; i++)
                        {
                            if (i > 0)
                            {
                                sb.Append(", ");
                            }
                            sb.Append($"{points[i].X}, {points[i].Y}");
                        }
                        attrib.Value = sb.ToString().Trim();
                        elem.Attributes.Append(attrib);
                        svgroot.AppendChild(elem);
                    }
                }
            }

            svgroot.AppendChild(SvgCircle(circle1, doc));
            svgroot.AppendChild(SvgCircle(circle2, doc));

            doc.Save(path);
        }
Ejemplo n.º 8
0
        private void CreateManagementPlist()
        {
            var doc = new System.Xml.XmlDocument();
            // don't resolve any URLs, or if there is no internet, the process will pause for some time
            doc.XmlResolver = null;

            {
                var type = doc.CreateDocumentType("plist", "-//Apple Computer//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);
                doc.AppendChild(type);
            }
            var plistEl = doc.CreateElement("plist");
            plistEl.SetAttribute("version", "1.0");

            var dictEl = doc.CreateElement("dict");
            plistEl.AppendChild(dictEl);
            doc.AppendChild(plistEl);

            {
                var key = doc.CreateElement("key");
                key.InnerText = "SchemeUserState";
                dictEl.AppendChild(key);

                var valueDict = doc.CreateElement("dict");
                dictEl.AppendChild(valueDict);

                foreach (var scheme in this.SchemeDocuments)
                {
                    var schemeKey = doc.CreateElement("key");
                    schemeKey.InnerText = System.IO.Path.GetFileName(scheme.Key);
                    valueDict.AppendChild(schemeKey);
                }
            }

            this.ManagementDocument = doc;
        }