Ejemplo n.º 1
0
        public static System.Xml.XmlNamespaceManager BuildNamespacesManagerForDoc(System.Xml.XmlDocument xmlDoc, string defaultNamespacePrefix)
        {
            System.Xml.XmlNodeList         nodes;
            System.Xml.XmlNamespaceManager nsmgrXML = new System.Xml.XmlNamespaceManager(xmlDoc.NameTable);
            nspaceLookup nSpace;

            System.Collections.Hashtable collection = new System.Collections.Hashtable();
            System.Diagnostics.Debug.WriteLine(DateTime.Now);
            nodes = xmlDoc.SelectNodes("//*");
            foreach (System.Xml.XmlNode node in nodes)
            {
                nSpace        = new nspaceLookup();
                nSpace.nspace = node.NamespaceURI;
                nSpace.prefix = node.Prefix;
                if (!collection.Contains(nSpace.prefix + ":" + nSpace.nspace))
                {
                    collection.Add(nSpace.prefix + ":" + nSpace.nspace, nSpace);
                }
            }
            System.Diagnostics.Debug.WriteLine(DateTime.Now);

            foreach (System.Collections.DictionaryEntry d in collection)
            {
                nSpace = ((nspaceLookup)(d.Value));
                if (nSpace.prefix.Trim().Length == 0)
                {
                    nSpace.prefix = defaultNamespacePrefix;
                }
                nsmgrXML.AddNamespace(nSpace.prefix, nSpace.nspace);
            }
            nsmgrXML.AddNamespace("kg", "http://kadgen.com/KADGenDriving.xsd");

            foreach (string prefix in nsmgrXML)
            {
                Console.WriteLine("Prefix={0}, Namespace={1}", prefix, nsmgrXML.LookupNamespace(prefix));
            }

            return(nsmgrXML);
        }
Ejemplo n.º 2
0
 public void LoadValidationHierarchy()
 {
     Arcs.Clear();
     Arcs.AddRange(this.VariableArcs);
     Arcs.AddRange(this.VariableFilterArcs);
     Arcs.AddRange(this.VariableSetFilterArcs); //.Where(i=>i.Complement=false));
     if (this.AssertionSet != null)
     {
         Identifiables.Add(this.AssertionSet);
     }
     Identifiables.AddRange(this.ValueAssertions);
     Identifiables.AddRange(this.DimensionFilters);
     Identifiables.AddRange(this.TupleFilters);
     Identifiables.AddRange(this.GeneralFilters);
     Identifiables.AddRange(this.ConceptFilters);
     Identifiables.AddRange(this.AspectFilters);
     Identifiables.AddRange(this.FactVariables);
     Identifiables.AddRange(this.Filters);
     foreach (var identifiable in Identifiables)
     {
         var df = identifiable as DimensionFilter;
         if (df != null)
         {
             var nsuri = NsManager.LookupNamespace(df.Dimension.QName.Domain);
             df.Dimension.QName.Domain = Taxonomy.FindNamespacePrefix(nsuri, df.Dimension.QName.Domain);
             var exdf = df as ExplicitDimensionFilter;
             if (exdf != null)
             {
                 foreach (var m in exdf.Members)
                 {
                     nsuri             = NsManager.LookupNamespace(m.QName.Domain);
                     m.QName.Domain    = Taxonomy.FindNamespacePrefix(nsuri, m.QName.Domain);
                     m.IsDefaultMember = Taxonomy.IsDefaultMember(m.QName);
                 }
             }
             var tydf = df as TypedDimensionFilter;
             if (tydf != null)
             {
                 //tydf.
             }
         }
         var cf = identifiable as ConceptFilter;
         if (cf != null)
         {
             var cfn = cf as ConceptNameFilter;
             if (cfn != null)
             {
                 foreach (var concept in cfn.Concepts)
                 {
                     var nsprefix = concept.QName.Domain;
                     var nsuri    = NsManager.LookupNamespace(nsprefix);
                     concept.QName.Domain = Taxonomy.FindNamespacePrefix(nsuri, nsprefix);
                 }
             }
         }
     }
     ValidationRoot = Hierarchy <XbrlIdentifiable> .GetHierarchy(Arcs, Identifiables,
                                                                 (i, a) => i.Item.LabelID == a.From, (i, a) => i.Item.LabelID == a.To,
                                                                 (i, a) => {
         if (i.Item is Filter && a is ComplementArc)
         {
             var filter        = i.Item as Filter;
             var arc           = a as ComplementArc;
             filter.Complement = arc.Complement;
         }
         if (a is VariableArc)
         {
             var varc      = a as VariableArc;
             var variable  = i.Item as Variable;
             variable.Name = varc.Name;
         }
         if (a is VariableFilterArc && i.Item is Filter)
         {
             var vfarc = a as VariableFilterArc;
             var ac    = i.Item as Filter;
             ac.Cover  = vfarc.Cover;
         }
     });
 }
Ejemplo n.º 3
0
        public static byte[] SvgToPdf(string svg, bool current_view)
        {
            if (string.IsNullOrEmpty(svg))
            {
                throw new System.ArgumentNullException("svg");
            }



            string styleTemplate = @"
path:not([fill]){fill: none}
path:not([stroke]){stroke: #000}
path:not([stroke-width]){stroke-width: 1}
";



            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

            doc.XmlResolver = null; // https://stackoverflow.com/questions/4445348/net-prevent-xmldocument-loadxml-from-retrieving-dtd
            doc.LoadXml(svg);



            System.Xml.XmlNamespaceManager nsmgr = XmlHelper.GetNamespaceManager(doc);
            string realDefaultNamespace          = nsmgr.LookupNamespace("dft");

            // System.Xml.XmlElement style = doc.CreateElement("", "style", realDefaultNamespace);
            System.Xml.XmlElement style = doc.CreateElement("style");
            style.SetAttribute("type", "text/css");
            style.SetAttribute("media", "all");
            style.InnerXml = styleTemplate;
            doc.DocumentElement.PrependChild(style);

            // string svgContent = doc.OuterXml.Replace("xmlns=\"\"", "");
            // doc.LoadXml(svgContent);
            // System.Console.WriteLine(doc.InnerXml);



            // data-height="967px" data-width="1324px"
            System.Xml.XmlAttribute dataWidth  = doc.DocumentElement.Attributes["data-width"];
            System.Xml.XmlAttribute dataHeight = doc.DocumentElement.Attributes["data-height"];



            string swidth  = "967px";
            string sheight = "967px";

            swidth  = dataWidth.Value;
            sheight = dataHeight.Value;



            if (string.IsNullOrEmpty(swidth))
            {
                throw new System.ArgumentNullException("swidth");
            }

            if (string.IsNullOrEmpty(sheight))
            {
                throw new System.ArgumentNullException("sheight");
            }

            swidth  = swidth.Trim();
            sheight = sheight.Trim();


            string templatePre  = @"<!doctype html>
<html>
<head>
<title></title>
<style>
html, body, div, svg { margin: 0px; padding: 0px; }

#SVG svg 
{
    -ms-transform: translate(-50%, -50%) translateZ(0);
    -ms-transform-origin: 50% 50% 0px;
    -webkit-transform: translate(-50%, -50%) translateZ(0);
    -webkit-transform-origin: 50% 50% 0px;
    background: #fff;
    fill: #ffffff;
    left: 50%;
    position: absolute;
    user-select: none;
    top: 50%;
    transform: translate(-50%, -50%);
    transform-origin: 50% 50% 0px;
}

</style>
</head>
<body>
<div id=""SVG"" style=""display: block; width: " + swidth + "; height: " + sheight + @"; position: relative; background-color: hotpink; overflow: hidden;"">
";
            string templatePost = @"
</div>
</body>
</html>
";

            svg = doc.DocumentElement.OuterXml;


            string html = templatePre + svg + templatePost;



            if (swidth.EndsWith("px", System.StringComparison.InvariantCultureIgnoreCase))
            {
                swidth = swidth.Substring(0, swidth.Length - 2);
            }

            if (sheight.EndsWith("px", System.StringComparison.InvariantCultureIgnoreCase))
            {
                sheight = sheight.Substring(0, sheight.Length - 2);
            }

            int width  = 1324;
            int height = 967;

            if (!int.TryParse(swidth, out width))
            {
                throw new System.ArgumentException("swidth");
            }

            if (!int.TryParse(sheight, out height))
            {
                throw new System.ArgumentException("sheight");
            }

            if (current_view)
            {
                return(Html2Pdf(html, width + 37, height + 37));
            }


            System.Xml.XmlAttribute attWidth   = doc.DocumentElement.Attributes["width"];
            System.Xml.XmlAttribute attHeight  = doc.DocumentElement.Attributes["height"];
            System.Xml.XmlAttribute attViewBox = doc.DocumentElement.Attributes["viewBox"];



            swidth  = attWidth.Value;
            sheight = attHeight.Value;
            string viewBox = attViewBox.Value;

            //System.Console.WriteLine(width);
            //System.Console.WriteLine(height);
            //System.Console.WriteLine(viewBox);
            string[] viewBoxValues = viewBox.Split(' ');

            string viewbox_width  = viewBoxValues[2];
            string viewbox_height = viewBoxValues[3];

            //System.Console.WriteLine(viewBoxValues);


            if (viewbox_width.EndsWith("px", System.StringComparison.InvariantCultureIgnoreCase))
            {
                viewbox_width = viewbox_width.Substring(0, viewbox_width.Length - 2);
            }

            if (viewbox_height.EndsWith("px", System.StringComparison.InvariantCultureIgnoreCase))
            {
                viewbox_height = viewbox_height.Substring(0, viewbox_height.Length - 2);
            }

            double viewbox_dblwidth  = 1324.0;
            double viewbox_dblHeight = 967.0;

            if (!double.TryParse(viewbox_width, out viewbox_dblwidth))
            {
                throw new System.ArgumentException("viewbox_width");
            }

            if (!double.TryParse(viewbox_height, out viewbox_dblHeight))
            {
                throw new System.ArgumentException("viewbox_height");
            }


            double r1 = 21.0 / viewbox_dblwidth;
            double r2 = 29.7 / viewbox_dblHeight;
            double r  = System.Math.Min(r1, r2);

            var w = viewbox_dblwidth * r;
            var h = viewbox_dblHeight * r;

            attWidth.Value  = w.ToString("N8", System.Globalization.CultureInfo.InvariantCulture) + "cm";
            attHeight.Value = h.ToString("N8", System.Globalization.CultureInfo.InvariantCulture) + "cm";

            w *= 0.393701 * 100;
            h *= 0.393701 * 100;

            System.IO.File.WriteAllText(@"d:\stefanlol.xml", doc.OuterXml, System.Text.Encoding.UTF8);


            svg = doc.DocumentElement.OuterXml;


            templatePre = @"<!doctype html>
<html>
<head>
<title></title>
<style>
html, body, div, svg { margin: 0px; padding: 0px; }
</style>
</head>
<body>
<div>
";

            html = templatePre + svg + templatePost;

            return(Html2Pdf(html, (int)System.Math.Ceiling(w), (int)System.Math.Ceiling(h)));
        }