Explorar el Código

调整WarpObj 的 zip slideLayoutTables slideMasterTables slideMasterTextStyles

CrazyIter hace 5 años
padre
commit
ce0e324da7

+ 14 - 0
TEAMModelOS.Service/Models/PowerPoint/Inner/WarpObj.cs

@@ -1,10 +1,24 @@
 using System;
 using System.Collections.Generic;
 using System.Text;
+using System.Xml;
 
 namespace TEAMModelOS.Service.Models.PowerPoint.Inner
 {
     public class WarpObj
     {
+        public XmlDocument zip { get; set; }
+        public NodesTable slideLayoutTables { get; set; }
+        public NodesTable slideMasterTables { get; set; }
+        public XmlNode slideMasterTextStyles { get; set; }
+        public Dictionary<string, Dictionary<string, string>> slideResObj { get; set; }
+        public Dictionary<string, Dictionary<string, string>> layoutResObj { get; set; }
+        public Dictionary<string, Dictionary<string, string>> masterResObj { get; set; }
     }
+
+
+}public class NodesTable { 
+    public Dictionary<string, Dictionary<string, XmlNode>> idTable { get; set; }
+    public Dictionary<string, Dictionary<string, XmlNode>> idxTable { get; set; }
+    public Dictionary<string, Dictionary<string, XmlNode>> typeTable { get; set; }
 }

+ 114 - 28
TEAMModelOS.Service/Services/PowerPoint/Implement/ShapeGenerator.cs

@@ -20,6 +20,7 @@ using TEAMModelOS.SDK.Helper.Common.StringHelper;
 using TEAMModelOS.SDK.Helper.Security.ShaHash;
 using TEAMModelOS.SDK.Module.AzureBlob.Container;
 using TEAMModelOS.SDK.Module.AzureBlob.Interfaces;
+using TEAMModelOS.Service.Models.PowerPoint.Inner;
 using ColorMap = DocumentFormat.OpenXml.Presentation.ColorMap;
 using Fill = HiTeachCC.Model.PowerPoint.Fill;
 
@@ -171,7 +172,7 @@ namespace HiTeachCC.Service.PowerPoint.Implement
             }
             // Open slideLayoutXX.xml
             var slideLayoutContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + layoutFilename + "']");
-            dynamic slideLayoutTables = IndexNodes(slideLayoutContent.GetTextByPath("pkg:xmlData/p:sldLayout"));
+            NodesTable slideLayoutTables = IndexNodes(slideLayoutContent.GetTextByPath("pkg:xmlData/p:sldLayout"));
             ///ppt/slides/slide5.xml  也包含a:overrideClrMapping
             ////ppt/slideLayouts/slideLayout13.xml  也包含a:overrideClrMapping
             var sldLayoutClrOvr = slideLayoutContent.GetTextByPath("pkg:xmlData/p:sldLayout/p:clrMapOvr/a:overrideClrMapping");
@@ -256,28 +257,32 @@ namespace HiTeachCC.Service.PowerPoint.Implement
 
             // =====< Step 3 >=====
             var slideContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + sldFileName + "']");
-            var nodes = slideContent.GetTextByPath("p:sld/p:cSld/p:spTree").ChildNodes;
-            dynamic warpObj = new
+            var spTreeNode = slideContent.GetTextByPath("pkg:xmlData/p:sld/p:cSld/p:spTree");
+            WarpObj warpObj = new WarpObj
             {
                 zip = xdoc,
-                slideLayoutTables,
-                slideMasterTables,
-                slideResObj,
-                slideMasterTextStyles,
-                layoutResObj,
-                masterResObj
+                slideLayoutTables= slideLayoutTables,
+                slideMasterTables = slideLayoutTables,
+                slideMasterTextStyles= slideMasterTextStyles,
+                slideResObj= slideResObj,
+                layoutResObj= layoutResObj,
+                masterResObj= masterResObj
             };
             var bgColor = GetSlideBackgroundFill(slideContent, slideLayoutContent, slideMasterContent, warpObj);
             var result = "<div class='slide' style='width:" + slideSize.width + "px; height:" + slideSize.height + "px;" + bgColor + "'>";
             //result += "<div>"+getBackgroundShapes(slideContent, slideLayoutContent, slideMasterContent,warpObj) + "</div>" - TODO
-            foreach (XmlNode node in nodes)
-            {
-                result += ProcessNodesInSlide(node.Name, node, warpObj);
+            if (spTreeNode != null) {
+                var nodes = spTreeNode.ChildNodes;
+                foreach (XmlNode node in nodes)
+                {
+                    result += ProcessNodesInSlide(node.Name, node, warpObj);
+                }
             }
+            
             return "";
         }
 
-        private dynamic ProcessNodesInSlide(string nodeKey, XmlNode nodeValue, dynamic warpObj)
+        private dynamic ProcessNodesInSlide(string nodeKey, XmlNode nodeValue, WarpObj warpObj)
         {
             var result = "";
 
@@ -308,7 +313,7 @@ namespace HiTeachCC.Service.PowerPoint.Implement
             return result;
         }
 
-        private string ProcessGroupSpNode(XmlNode node, dynamic warpObj)
+        private string ProcessGroupSpNode(XmlNode node, WarpObj warpObj)
         {
             var factor =1.00* px96 / px914400;
 
@@ -336,27 +341,106 @@ namespace HiTeachCC.Service.PowerPoint.Implement
             return result;
         }
 
-        private string ProcessGraphicFrameNode(XmlNode nodeValue, dynamic warpObj)
+        private string ProcessGraphicFrameNode(XmlNode nodeValue, WarpObj warpObj)
         {
             throw new NotImplementedException();
         }
 
-        private string ProcessPicNode(XmlNode nodeValue, dynamic warpObj)
+        private string ProcessPicNode(XmlNode nodeValue, WarpObj warpObj)
         {
             throw new NotImplementedException();
         }
 
-        private string ProcessCxnSpNode(XmlNode nodeValue, dynamic warpObj)
+        private string ProcessCxnSpNode(XmlNode nodeValue, WarpObj warpObj)
         {
             throw new NotImplementedException();
         }
 
-        private string ProcessSpNode(XmlNode nodeValue, dynamic warpObj)
+        private string ProcessSpNode(XmlNode node , WarpObj warpObj)
         {
+
+            /*
+           *  958    <xsd:complexType name="CT_GvmlShape">
+           *  959   <xsd:sequence>
+           *  960     <xsd:element name="nvSpPr" type="CT_GvmlShapeNonVisual"     minOccurs="1" maxOccurs="1"/>
+           *  961     <xsd:element name="spPr"   type="CT_ShapeProperties"        minOccurs="1" maxOccurs="1"/>
+           *  962     <xsd:element name="txSp"   type="CT_GvmlTextShape"          minOccurs="0" maxOccurs="1"/>
+           *  963     <xsd:element name="style"  type="CT_ShapeStyle"             minOccurs="0" maxOccurs="1"/>
+           *  964     <xsd:element name="extLst" type="CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1"/>
+           *  965   </xsd:sequence>
+           *  966 </xsd:complexType>
+           */
+
+            var id =node.GetTextByPath("p:nvSpPr/p:cNvPr/@id");
+            var name = node.GetTextByPath("p:nvSpPr/p:cNvPr/@name");
+            var idx = node.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@idx") ;
+            var type = node.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@type") ;
+            var order = node.GetTextByPath("@order");
+
+            XmlNode slideLayoutSpNode = null;
+            XmlNode slideMasterSpNode = null;
+
+            if (type != null)
+            {
+                if (idx !=null)
+                {
+                    if (warpObj.slideLayoutTables.typeTable.TryGetValue(type.Value, out Dictionary<string,XmlNode> LayoutNode)) {
+                        slideLayoutSpNode = LayoutNode[type.Value];
+                    };
+                    if (warpObj.slideMasterTables.typeTable.TryGetValue(type.Value, out Dictionary<string, XmlNode> MasterNode))
+                    {
+                        slideMasterSpNode = MasterNode[type.Value];
+                    };
+                    
+                }
+                else
+                {
+                    if (warpObj.slideLayoutTables.typeTable.TryGetValue(type.Value, out Dictionary<string, XmlNode> LayoutNode))
+                    {
+                        slideLayoutSpNode = LayoutNode[type.Value];
+                    };
+                    if (warpObj.slideMasterTables.typeTable.TryGetValue(type.Value, out Dictionary<string, XmlNode> MasterNode))
+                    {
+                        slideMasterSpNode = MasterNode[type.Value];
+                    };
+                }
+            }
+            else
+            {
+                if (idx !=null)
+                {
+                    if (warpObj.slideLayoutTables.typeTable.TryGetValue(type.Value, out Dictionary<string, XmlNode> LayoutNode))
+                    {
+                        slideLayoutSpNode = LayoutNode[type.Value];
+                    };
+                    if (warpObj.slideMasterTables.typeTable.TryGetValue(type.Value, out Dictionary<string, XmlNode> MasterNode))
+                    {
+                        slideMasterSpNode = MasterNode[type.Value];
+                    };
+                }
+                else
+                {
+                    // Nothing
+                }
+            }
+
+            if (type == null)
+            {
+
+                if (slideLayoutSpNode != null) {
+                    type = slideLayoutSpNode.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@type");
+                }
+               // type = slideLayoutSpNode.TryGetValue"p:nvSpPr", "p:nvPr", "p:ph", "attrs", "type"]);
+                if (type ==null)
+                {
+                    type = slideMasterSpNode.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@type");
+                    // type = getTextByPathList(slideMasterSpNode, ["p:nvSpPr", "p:nvPr", "p:ph", "attrs", "type"]);
+                }
+            }
             throw new NotImplementedException();
         }
 
-        private Fill GetSlideBackgroundFill(XmlNode slideContent ,XmlNode slideLayoutContent  , XmlNode slideMasterContent , dynamic warpObj) {
+        private Fill GetSlideBackgroundFill(XmlNode slideContent ,XmlNode slideLayoutContent  , XmlNode slideMasterContent , WarpObj warpObj) {
             var bgPr = slideContent.GetTextByPath("p:sld/p:cSld/p:bg/p:bgPr");
             var bgRef = slideContent.GetTextByPath("p:sld/p:cSld/p:bg/p:bgRef");
             var bgcolor="";
@@ -391,7 +475,7 @@ namespace HiTeachCC.Service.PowerPoint.Implement
             }
             return null; 
         }
-        private   string getBgPicFill(XmlNode bgPr,  string sorce,dynamic warpObj)
+        private   string getBgPicFill(XmlNode bgPr,  string sorce, WarpObj warpObj)
         {
             var bgcolor="";
             var picFillBase64 = GetPicFill(sorce, bgPr.GetTextByPath("a:blipFill"), warpObj);
@@ -402,7 +486,7 @@ namespace HiTeachCC.Service.PowerPoint.Implement
             return bgcolor;
         }
 
-        private static Fill GetPicFill(string type, XmlNode node, dynamic warpObj)
+        private static Fill GetPicFill(string type, XmlNode node, WarpObj warpObj)
         {
 
             //Need to test/////////////////////////////////////////////
@@ -414,15 +498,17 @@ namespace HiTeachCC.Service.PowerPoint.Implement
             var imgPath = "";
             if (type == "slideBg")
             {
-                imgPath = PowerPointHelper.GetTextByPath(warpObj, "slideResObj/" + rId + "/target").Value;
+                imgPath = warpObj.slideResObj[rId.Value][rId.Value];
+
+               // imgPath = PowerPointHelper.GetTextByPath(warpObj, "slideResObj/" + rId + "/target").Value;
             }
             else if (type == "layoutBg")
             {
-                imgPath = PowerPointHelper.GetTextByPath(warpObj, "layoutResObj/" + rId + "/target").Value;
+                imgPath = warpObj.layoutResObj[rId.Value][rId.Value];
             }
             else if (type == "masterBg")
             {
-                imgPath = PowerPointHelper.GetTextByPath(warpObj, "masterResObj/" + rId + "/target").Value;
+                imgPath = warpObj.masterResObj[rId.Value][rId.Value];
             }
             if (imgPath == null)
             {
@@ -433,7 +519,7 @@ namespace HiTeachCC.Service.PowerPoint.Implement
             {
                 return null;
             }
-            var imgArrayBuffer = warpObj.zip.file(imgPath).asArrayBuffer();
+          //  var imgArrayBuffer = warpObj.zip.GetTextByPath(imgPath).Value.asArrayBuffer();
             //var imgMimeType = GetMimeType(imgExt);
             //img = "data:" + imgMimeType + ";base64," + base64ArrayBuffer(imgArrayBuffer);
             return   null;
@@ -826,13 +912,13 @@ namespace HiTeachCC.Service.PowerPoint.Implement
             return fillType;
         }
 
-        private dynamic IndexNodes(XmlNode content)
+        private NodesTable IndexNodes(XmlNode content)
         {
             var idTable = new Dictionary<string, Dictionary<string,XmlNode>>();
             var idxTable = new Dictionary<string, Dictionary<string, XmlNode>>();
             var typeTable = new Dictionary<string, Dictionary<string, XmlNode>>();
             var spTreeNode = content.GetTextByPath("p:cSld/p:spTree");
-            Dictionary<string, Dictionary<string, string>> slideResObj = new Dictionary<string, Dictionary<string, string>>();
+          //  Dictionary<string, Dictionary<string, string>> slideResObj = new Dictionary<string, Dictionary<string, string>>();
             var spTreeNodeChildren = spTreeNode.ChildNodes;
             foreach (XmlNode child in spTreeNodeChildren)
             {
@@ -871,7 +957,7 @@ namespace HiTeachCC.Service.PowerPoint.Implement
                     typeTable.Add(type.Value, node);
                 }
             }
-            return new { idTable, idxTable, typeTable };
+            return new NodesTable { idTable =idTable, idxTable=idxTable, typeTable= typeTable };
         }
         private dynamic GetSlideSize(XmlDocument xdoc)
         {