Browse Source

优化SVG的Path精度输出,Buchar的NUll数据减少json文档大小,PPT的Json结构调整。

CrazyIter 5 years ago
parent
commit
99be0ba92b

+ 1 - 1
TEAMModelOS.Service/Models/PowerPoint/Item.cs

@@ -9,7 +9,7 @@ namespace HiTeachCC.Model.PowerPoint
         // Sp  CxnSp Media Group
         public string Type { get; set; }
         public Position Position { get; set; }
-        public string Xml { get; set; }
+      //  public string Xml { get; set; }
         public int Index { get; set; }
         public Svg Svg { get; set; }
         //public Picture Picture { get; set; }

+ 52 - 22
TEAMModelOS.Service/Services/PowerPoint/Implement/ShapeGenerator.cs

@@ -32,7 +32,7 @@ namespace HiTeachCC.Service.PowerPoint.Implement
 
         private Dictionary<string, string> slideLayoutClrOvride { get; set; }
         //  private XmlNode themeContent { get; set; }
-
+        private const int degree = 3;
         private int chartID = 0;
         private int _order = 1;
         private int titleFontSize = 42;
@@ -93,45 +93,47 @@ namespace HiTeachCC.Service.PowerPoint.Implement
         /// </summary>
         /// <param name="presentationFile"></param>
         /// <returns></returns>
-        public async Task<List<Dictionary<string, object>>> ProcessPPTX(XmlDocument xdoc, string shaCode)
+        public async Task< Dictionary<string, object>> ProcessPPTX(XmlDocument xdoc, string shaCode)
         {
-            List<Dictionary<string, object>> post_ary = new List<Dictionary<string, object>>();
+          //  List<Dictionary<string, object>> post_ary = new List<Dictionary<string, object>>();
+            Dictionary<string, object> post_ary = new Dictionary<string, object>();
             var dateBefore = DateTimeOffset.Now.UtcTicks;
             AzureBlobModel thumbnailModel = await GetThumbnailModel(xdoc, shaCode);
-            post_ary.Add(new Dictionary<string, object> { { "pptx-thumb", thumbnailModel } });
+            post_ary.Add(   "pptx-thumb", thumbnailModel  );
             //获取全部的/ppt/slides/slide1.xml--->>/ppt/slides/slide(n).xml
             var slideNodes = xdoc.GetTextByPathList("//pkg:part[@pkg:contentType='application/vnd.openxmlformats-officedocument.presentationml.slide+xml']");
             //获取全部的/ppt/slideLayouts/slideLayout1.xml--->>/ppt/slideLayouts/slideLayout(n).xml
             var slideLayoutNodes = xdoc.GetTextByPathList("//pkg:part[@pkg:contentType='application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml']");
             //获取ppt的宽高
             var slideSize = ShapeHelper.GetSlideSize(xdoc);
-            post_ary.Add(new Dictionary<string, object> { { "slideSize", slideSize } });
+            post_ary.Add( "slideSize", slideSize  );
             //加载当前PPT使用到的PPT节点
             var themeContent = LoadTheme(xdoc);
             //获取所有的表格样式节点
             var tableStyles = xdoc.GetTextByPath("//pkg:part[@pkg:name='/ppt/tableStyles.xml']/pkg:xmlData/a:tblStyleLst");
             //处理slide1---slide(n)
             int numOfSlides = slideNodes.Count;
-
+            List<Slide> slides = new List<Slide>();
             for (int i = 0; i < numOfSlides; i++)
             {
                 string filename = slideNodes[i].GetTextByPath("@pkg:name").Value;
                 //处理当前页的幻灯片
-                Slide slideHtml = await ProcessSingleSlide(xdoc, slideNodes[i], filename, i, slideSize, themeContent);
-                post_ary.Add(new Dictionary<string, object> { { "slide", slideHtml } });
-                post_ary.Add(new Dictionary<string, object> { { "progress-update", (i + 1) * 100 / numOfSlides } });
+                Slide slide = await ProcessSingleSlide(xdoc, slideNodes[i], filename, i, slideSize, themeContent);
+                slides.Add(slide);
+              //  post_ary.Add(new Dictionary<string, object> { { "slide", slideHtml } });
+               // post_ary.Add(new Dictionary<string, object> { { "progress-update", (i + 1) * 100 / numOfSlides } });
 
             }
-            post_ary.Add(new Dictionary<string, object> { { "globalCSS", GenGlobalCSS() } });
+            post_ary.Add( "slide", slides );
+            //post_ary.Add(  "globalCSS", GenGlobalCSS()  );
             var dateAfter = DateTimeOffset.Now.UtcTicks;
-            post_ary.Add(new Dictionary<string, object> { { "ExecutionTime", dateAfter - dateBefore } });
+           // post_ary.Add(  "ExecutionTime", dateAfter - dateBefore );
             return post_ary;
         }
 
         public Dictionary<string, string> GenGlobalCSS()
         {
             Dictionary<string, string> cssText = new Dictionary<string, string>();
-
             foreach (var key in styleTable.Keys)
             {
                 // cssText += "div ." + styleTable[key]["name"] + "{" + styleTable[key]["text"] + "}\n"; //section > div
@@ -594,10 +596,18 @@ namespace HiTeachCC.Service.PowerPoint.Implement
             {
                 Svg svg = ShapeSvg.GenShapeSvg(node, order, shapeType, isFlipV, position, grndFillFlg, imgFillFlg, Fill, shapeBorder, headEndNodeAttrs, tailEndNodeAttrs);
                 shapeSvg.SvgShape = svg.SvgShape;
-                shapeSvg.SvgData = svg.SvgData;
+                //  shapeSvg.SvgData = svg.SvgData;
                 if (ShapeType.Equals("Sp"))
+
                 {
-                    Shape shape = new Shape { Border = shapeBorder, Fill = Fill, Svg = shapeSvg, Type = "Sp", Position = position, Index = order, ShapeType = shapeType.Value };
+                    Shape shape = new Shape { Border = shapeBorder,   Svg = shapeSvg, Type = "Sp", Position = position, Index = order, ShapeType = shapeType.Value };
+                    if (Fill.Type == 0)
+                    {
+                        shape.Fill = null;
+                    }
+                    else {
+                        shape.Fill = Fill;
+                    }
                     var txbody = node.GetTextByPath("p:txBody");
                     if (txbody != null)
                     {
@@ -631,8 +641,8 @@ namespace HiTeachCC.Service.PowerPoint.Implement
                 var spY = 96.0;
                 if (startPoint != null)
                 {
-                    spX = double.Parse(startPoint.GetTextByPath("@x").Value) * 96 / 914400;
-                    spY = double.Parse(startPoint.GetTextByPath("@y").Value) * 96 / 914400;
+                    spX = System.Math.Round(double.Parse(startPoint.GetTextByPath("@x").Value) * 96 / 914400,degree);
+                    spY = System.Math.Round(double.Parse(startPoint.GetTextByPath("@y").Value) * 96 / 914400,degree);
                 }
                 var d = "M" + spX + "," + spY;
                 // List<HiTeachCC.Model.PowerPoint.Path> Paths = new List<Model.PowerPoint.Path>();
@@ -649,7 +659,7 @@ namespace HiTeachCC.Service.PowerPoint.Implement
                         //    Lx = double.Parse(Lx.Value) * px96 / px914400,
                         //    Ly = double.Parse(Lx.Value) * px96 / px914400,
                         //});
-                        d += " L" + Lx + "," + Ly;
+                        d += " L" + System.Math.Round(Lx,degree) + "," + System.Math.Round(Ly,degree);
                     }
                     if (childNode.Name.Equals("a:cubicBezTo"))
                     {
@@ -673,7 +683,7 @@ namespace HiTeachCC.Service.PowerPoint.Implement
                         //     Cx3 = double.Parse(Cx3.Value) * px96 / px914400,
                         //     Cy3 = double.Parse(Cy3.Value) * px96 / px914400
                         // });
-                        d += " C" + Cx1 + "," + Cy1 + " " + Cx2 + "," + Cy2 + " " + Cx3 + "," + Cy3;
+                        d += " C" + System.Math.Round(Cx1,degree) + "," + System.Math.Round(Cy1,degree) + " " + System.Math.Round(Cx2,degree) + "," + System.Math.Round(Cy2,degree) + " " + System.Math.Round(Cx3,degree) + "," + System.Math.Round(Cy3,degree);
                     }
                     if (childNode.Name.Equals("a:quadBezTo"))
                     {
@@ -694,7 +704,7 @@ namespace HiTeachCC.Service.PowerPoint.Implement
                         //    Cx2 = double.Parse(Cx2.Value) * px96 / px914400,
                         //    Cy2 = double.Parse(Cy2.Value) * px96 / px914400
                         //});
-                        d += " Q" + Cx1 + "," + Cy1 + " " + Cx2 + "," + Cy2;
+                        d += " Q" + System.Math.Round(Cx1,degree) + "," + System.Math.Round(Cy1,degree) + " " + System.Math.Round(Cx2,degree) + "," + System.Math.Round(Cy2,degree);
                     }
                     if (childNode.Name.Equals("a:arcTo"))
                     {
@@ -734,8 +744,16 @@ namespace HiTeachCC.Service.PowerPoint.Implement
                     }
                 };
                 shapeSvg.SvgShape = shapes;
-                shapeSvg.SvgData = result;
-                Shape shape = new Shape { Border = shapeBorder, Fill = Fill, Svg = shapeSvg, Type = "Sp", Position = position, Index = order, ShapeType = "custom" };
+               // shapeSvg.SvgData = result;
+                Shape shape = new Shape { Border = shapeBorder,   Svg = shapeSvg, Type = "Sp", Position = position, Index = order, ShapeType = "custom" };
+                if (Fill.Type == 0)
+                {
+                    shape.Fill = null;
+                }
+                else
+                {
+                    shape.Fill = Fill;
+                }
                 var txbody = node.GetTextByPath("p:txBody");
                 if (txbody != null)
                 {
@@ -746,7 +764,15 @@ namespace HiTeachCC.Service.PowerPoint.Implement
             }
             else
             {
-                Shape shape = new Shape { Border = shapeBorder, Fill = Fill, Svg = shapeSvg, Type = "Sp", Position = position, Index = order, ShapeType = "rect" };
+                Shape shape = new Shape { Border = shapeBorder,   Svg = shapeSvg, Type = "Sp", Position = position, Index = order, ShapeType = "rect" };
+                if (Fill.Type == 0)
+                {
+                    shape.Fill = null;
+                }
+                else
+                {
+                    shape.Fill = Fill;
+                }
                 var txbody = node.GetTextByPath("p:txBody");
                 if (txbody != null)
                 {
@@ -769,6 +795,10 @@ namespace HiTeachCC.Service.PowerPoint.Implement
                 foreach (XmlNode pNode in ps)
                 {
                     BuChar buChar = await GenBuChar(pNode, spNode, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
+                    if (buChar != null && (buChar.Buchar == null || buChar.Buchar.Equals("TYPE_NONE"))) {
+                        buChar = null;
+                    }
+
                     string HorizontalAlign = GetHorizontalAlign(pNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles);
                     Paragraph paragraph = new Paragraph
                     {

+ 1 - 1
TEAMModelOS.Service/Services/PowerPoint/Implement/ShapeHelper.cs

@@ -171,7 +171,7 @@ namespace TEAMModelOS.Service.Services.PowerPoint.Implement
             }
             if (!string.IsNullOrEmpty(borderColorstr)) {
                 border.Color = borderColorstr;
-                if (border.Width == 0) {
+                if (border.Width == 0.0) {
                     border.Width = 1;
                 }
             }

+ 7 - 7
TEAMModelOS.Service/Services/PowerPoint/Implement/ShapeSvg.cs

@@ -1232,9 +1232,9 @@ namespace TEAMModelOS.Service.Services.PowerPoint.Implement
                     var y = cY + System.Math.Sin(radians) * rY;
                     if (angle == stAng)
                     {
-                        dData = " M" + x + " " + y;
+                        dData = " M" + System.Math.Round(x,degree) + " " + System.Math.Round(y,degree);
                     }
-                    dData += " L" + x + " " + y;
+                    dData += " L" + System.Math.Round(x,degree) + " " + System.Math.Round(y,degree);
                     angle++;
                 }
             }
@@ -1247,9 +1247,9 @@ namespace TEAMModelOS.Service.Services.PowerPoint.Implement
                     var y = cY + System.Math.Sin(radians) * rY;
                     if (angle == stAng)
                     {
-                        dData = " M " + x + " " + y;
+                        dData = " M " + System.Math.Round(x,degree) + " " + System.Math.Round(y,degree);
                     }
-                    dData += " L " + x + " " + y;
+                    dData += " L " + System.Math.Round(x,degree) + " " + System.Math.Round(y,degree);
                     angle--;
                 }
             }
@@ -4668,9 +4668,9 @@ namespace TEAMModelOS.Service.Services.PowerPoint.Implement
             if (adj1 < 0) a1 = 0;
             else if (adj1 > cnsVal1) a1 = cnsVal1;
             else a1 = adj1;
-            x1 = a1 * (System.Math.Min(w, h)) / cnsVal2;
-            x2 = w - x1;
-            y2 = h - x1;
+            x1 =System.Math.Round(a1 * (System.Math.Min(w, h)) / cnsVal2,degree);
+            x2 = System.Math.Round(w - x1,degree);
+            y2 = System.Math.Round(h - x1,degree);
 
             string d_val = "M0," + x1 +
                         ShapeArc(0, 0, x1, x1, 90, 0, false).Replace("M", "L") +