Browse Source

修复自定义图形缩放比例

CrazyIter_Bin 4 years ago
parent
commit
13d32558da

+ 3 - 3
HTEXLib/HTEXLib.csproj

@@ -4,9 +4,9 @@
     <Description>模板解析类型</Description>
     <PackageReleaseNotes>模板解析类型</PackageReleaseNotes>
     <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
-    <Version>2.1.6</Version>
-    <AssemblyVersion>2.1.6.6</AssemblyVersion>
-    <FileVersion>2.1.6.6</FileVersion>
+    <Version>2.2.2</Version>
+    <AssemblyVersion>2.2.2.2</AssemblyVersion>
+    <FileVersion>2.2.2.2</FileVersion>
   </PropertyGroup>
   <ItemGroup>
     <PackageReference Include="DocumentFormat.OpenXml" Version="2.11.3" />

+ 10 - 3
HTEXLib/PPTX/Helpers/ShapeHelpers/AnimtimeHelper.cs

@@ -137,8 +137,12 @@ namespace HTEXLib.Helpers.ShapeHelpers
                 spid = spTgt.First().Attribute("spid").Value;
             }
             var obj_uid = spid.ToString().PadRight(3, '0') + stNum.ToString().PadLeft(3, '0');
-            var item = items.Where(x => x.sid == spid).First();
-            if (!dict.ContainsKey(obj_uid))
+            var itema = items.Where(x => x.sid == spid);
+            Item item = null;
+            if (itema == null) {
+                 item = itema.First();
+            }
+            if (!dict.ContainsKey(obj_uid)&& item!=null)
             {
                 //是否包含文字部分
                 if (stNum == 0 && item.haspar)
@@ -198,7 +202,10 @@ namespace HTEXLib.Helpers.ShapeHelpers
             }
             else
             {
-                innerDict.Add(new KeyValuePair<string, AnimtimeData>(obj_uid, dict[obj_uid]));
+                if(dict.TryGetValue(obj_uid, out AnimtimeData animtimeData))
+                {
+                    innerDict.Add(new KeyValuePair<string, AnimtimeData>(obj_uid, dict[obj_uid]));
+                }
             }
             return (innerDict,spid ,item);
         }

+ 28 - 22
HTEXLib/PPTX/Helpers/ShapeHelpers/PPTXHelper.cs

@@ -178,6 +178,9 @@ namespace HTEXLib.Helpers.ShapeHelpers
             {
                 var pathlist = shapeTypeCustom.GetFirstChild<PathList>();
                 var path = pathlist.GetFirstChild<DocumentFormat.OpenXml.Drawing.Path>();
+                var Width = shape.style.position.cx/path.Width.Value / 96.0 * 914400 ;
+                var Height = shape.style.position.cy/ path.Height.Value / 96.0 * 914400;
+
                 var pathChildren = path.ChildElements;
                 if (pathChildren != null)
                 {
@@ -188,8 +191,8 @@ namespace HTEXLib.Helpers.ShapeHelpers
                     if (start != null)
                     {
                         var point = start.GetFirstChild<DocumentFormat.OpenXml.Drawing.Point>();
-                        spX = System.Math.Round(double.Parse(point.X.Value) * Globals.px96 * 1.0 / Globals.px914400, Globals.degree);
-                        spY = System.Math.Round(double.Parse(point.Y.Value) * Globals.px96 * 1.0 / Globals.px914400, Globals.degree);
+                        spX = double.Parse(point.X.Value) * Globals.px96 / Globals.px914400 * Width;
+                        spY = double.Parse(point.Y.Value) * Globals.px96 / Globals.px914400* Height;
                     }
                     var d = "M" + spX + "," + spY;
                     foreach (var child in pathChildren)
@@ -199,21 +202,21 @@ namespace HTEXLib.Helpers.ShapeHelpers
                             var elm = lineTo.GetFirstChild<DocumentFormat.OpenXml.Drawing.Point>();
                             if (elm != null)
                             {
-                                var Lx = System.Math.Round(double.Parse(elm.X.Value) * Globals.px96 * 1.0 / Globals.px914400, Globals.degree);
-                                var Ly = System.Math.Round(double.Parse(elm.Y.Value) * Globals.px96 * 1.0 / Globals.px914400, Globals.degree);
+                                var Lx = double.Parse(elm.X.Value) * Globals.px96  / Globals.px914400 * Width;
+                                var Ly = double.Parse(elm.Y.Value) * Globals.px96 / Globals.px914400 * Height;
                                 d += " L" + Lx + "," + Ly;
                             }
                         }
                         if (child is ArcTo arcTo)
                         {
-                            var WidthRadius = arcTo.WidthRadius;
-                            var HeightRadius = arcTo.HeightRadius;
+                            var WidthRadius = arcTo.WidthRadius ;
+                            var HeightRadius = arcTo.HeightRadius ;
                             var StartAngle = arcTo.StartAngle;
                             var SwingAngle = arcTo.SwingAngle;
-                            var wR = System.Math.Round(double.Parse(WidthRadius.Value) * Globals.px96 * 1.0 / Globals.px914400, Globals.degree);
-                            var hR = System.Math.Round(double.Parse(HeightRadius.Value) * Globals.px96 * 1.0 / Globals.px914400, Globals.degree);
-                            var stAng = System.Math.Round(double.Parse(StartAngle.Value) * Globals.px96 * 1.0 / Globals.px914400, Globals.degree);
-                            var swAng = System.Math.Round(double.Parse(SwingAngle.Value) * Globals.px96 * 1.0 / Globals.px914400, Globals.degree);
+                            var wR = double.Parse(WidthRadius.Value) * Globals.px96  / Globals.px914400 * Width;
+                            var hR = double.Parse(HeightRadius.Value) * Globals.px96 / Globals.px914400 * Height;
+                            var stAng = double.Parse(StartAngle.Value) * Globals.px96 / Globals.px914400;
+                            var swAng = double.Parse(SwingAngle.Value) * Globals.px96  / Globals.px914400;
                             var endAng = stAng + swAng;
                             d += SvgHelper.ShapeArc(wR, hR, wR, hR, stAng, endAng, false);
                         }
@@ -223,15 +226,15 @@ namespace HTEXLib.Helpers.ShapeHelpers
                             if (elms != null)
                             {
                                 var list = elms.ToList();
-                                var Cx1 = double.Parse(list[0].X.Value) * Globals.px96 * 1.0 / Globals.px914400;
-                                var Cy1 = double.Parse(list[0].Y.Value) * Globals.px96 * 1.0 / Globals.px914400;
+                                var Cx1 = double.Parse(list[0].X.Value) * Globals.px96 / Globals.px914400 * Width;
+                                var Cy1 = double.Parse(list[0].Y.Value) * Globals.px96  / Globals.px914400 * Height;
 
-                                var Cx2 = double.Parse(list[1].X.Value) * Globals.px96 * 1.0 / Globals.px914400;
-                                var Cy2 = double.Parse(list[1].Y.Value) * Globals.px96 * 1.0 / Globals.px914400;
+                                var Cx2 = double.Parse(list[1].X.Value) * Globals.px96 / Globals.px914400 * Width;
+                                var Cy2 = double.Parse(list[1].Y.Value) * Globals.px96  / Globals.px914400 * Height;
 
-                                var Cx3 = double.Parse(list[2].X.Value) * Globals.px96 * 1.0 / Globals.px914400;
-                                var Cy3 = double.Parse(list[2].Y.Value) * Globals.px96 * 1.0 / Globals.px914400;
-                                d += " C" + System.Math.Round(Cx1, Globals.degree) + "," + System.Math.Round(Cy1, Globals.degree) + " " + System.Math.Round(Cx2, Globals.degree) + "," + System.Math.Round(Cy2, Globals.degree) + " " + System.Math.Round(Cx3, Globals.degree) + "," + System.Math.Round(Cy3, Globals.degree);
+                                var Cx3 = double.Parse(list[2].X.Value) * Globals.px96  / Globals.px914400 * Width;
+                                var Cy3 = double.Parse(list[2].Y.Value) * Globals.px96 / Globals.px914400 * Height;
+                                d += " C" + Cx1 + "," + Cy1 + " " + Cx2 + "," + Cy2 + " " + Cx3 + "," + Cy3;
                             }
                         }
                         if (child is CubicBezierCurveTo cubicBezierCurveTo)
@@ -240,12 +243,15 @@ namespace HTEXLib.Helpers.ShapeHelpers
                             if (elms != null)
                             {
                                 var list = elms.ToList();
-                                var Cx1 = double.Parse(list[0].X.Value) * Globals.px96 * 1.0 / Globals.px914400;
-                                var Cy1 = double.Parse(list[0].Y.Value) * Globals.px96 * 1.0 / Globals.px914400;
+                                var Cx1 = double.Parse(list[0].X.Value) * Globals.px96   / Globals.px914400 * Width;
+                                var Cy1 = double.Parse(list[0].Y.Value) * Globals.px96  / Globals.px914400 * Height;
+
+                                var Cx2 = double.Parse(list[1].X.Value) * Globals.px96   / Globals.px914400 * Width;
+                                var Cy2 = double.Parse(list[1].Y.Value) * Globals.px96  / Globals.px914400 * Height;
 
-                                var Cx2 = double.Parse(list[1].X.Value) * Globals.px96 * 1.0 / Globals.px914400;
-                                var Cy2 = double.Parse(list[1].Y.Value) * Globals.px96 * 1.0 / Globals.px914400;
-                                d += " Q" + System.Math.Round(Cx1, Globals.degree) + "," + System.Math.Round(Cy1, Globals.degree) + " " + System.Math.Round(Cx2, Globals.degree) + "," + System.Math.Round(Cy2, Globals.degree);
+                                var Cx3 = double.Parse(list[2].X.Value) * Globals.px96 / Globals.px914400 * Width;
+                                var Cy3 = double.Parse(list[2].Y.Value) * Globals.px96 / Globals.px914400 * Height;
+                                d += " C" + Cx1 + "," + Cy1 + " " + Cx2 + "," + Cy2 + " " + Cx3 + "," + Cy3;
                             }
                         }
                     }

+ 1 - 1
HTEXLib/PPTX/Helpers/ShapeHelpers/SvgHelper.cs

@@ -10131,7 +10131,7 @@ namespace HTEXLib.Helpers
                 //    type = "path",
                 //    d = " M" +h * (1.0  / 8.0) + ",L" + w + " " + h * (1.0  / 8.0),
                 //});
-                ds = ds + " M" + h * (1.0 / 8.0) + ",L" + w + " " + h * (1.0 / 8.0);
+                ds = ds + " M0 " + h * (1.0 / 8.0) + ",L" + w + " " + h * (1.0 / 8.0);
             }
             shapes = new Svg
             {