Parcourir la source

Group位置修订

CrazyIter_Bin il y a 4 ans
Parent
commit
454dd681c8

+ 13 - 13
HTEXLib/PPTX/Models/HTEX/HtexGroupShape.cs

@@ -33,8 +33,8 @@ namespace HTEXLib.Models.HTEX
         public List<Item> shapes { get; set; } = new List<Item>();
         public override List<Item> DrawElement()
         {
-            var ChildExtents = groupShape.VisualShapeProp.ChildExtents;
-            var ChildOffset = groupShape.VisualShapeProp.ChildOffset;
+           // var ChildExtents = groupShape.VisualShapeProp.ChildExtents;
+           // var ChildOffset = groupShape.VisualShapeProp.ChildOffset;
             Position position = new Position { cx = width, cy = height, x = left, y = top, rot = rot };
             var ShapeStyle = PPTXHelper.DoShapeProperties(groupShape.element.GroupShapeProperties, slide, type, partForm);
             Group group = new Group() { sid = sid, type = type, index = index, uid = groupShape.suid, subName = groupShape.NonVisualShapeProp.SubName };
@@ -48,17 +48,17 @@ namespace HTEXLib.Models.HTEX
                 
                 FromGroup = true
             };
-            htexSlide.ContainerShape.ChildExtents = ChildExtents;
-            htexSlide.ContainerShape.ChildOffset = ChildOffset;
-            htexSlide.ContainerShape.GroupOffset = groupShape.VisualShapeProp.Offset;
-            htexSlide.ContainerShape.GroupExtents = groupShape.VisualShapeProp.Extents;
-            foreach (PPTShapeBase baseShape in htexSlide.ContainerShape.Elements)
-            {
-                baseShape.VisualShapeProp.ChildExtents =  ChildExtents;
-                baseShape.VisualShapeProp.ChildOffset =  ChildOffset;
-                baseShape.VisualShapeProp.GroupExtents = groupShape.VisualShapeProp.Extents;
-                baseShape.VisualShapeProp.GroupOffset = groupShape.VisualShapeProp.Offset;
-            }
+           // htexSlide.ContainerShape.ChildExtents = ChildExtents;
+            //htexSlide.ContainerShape.ChildOffset = ChildOffset;
+            //htexSlide.ContainerShape.GroupOffset = groupShape.VisualShapeProp.Offset;
+           // htexSlide.ContainerShape.GroupExtents = groupShape.VisualShapeProp.Extents;
+            //foreach (PPTShapeBase baseShape in htexSlide.ContainerShape.Elements)
+            //{
+            //    baseShape.VisualShapeProp.ChildExtents =  ChildExtents;
+            //    baseShape.VisualShapeProp.ChildOffset =  ChildOffset;
+            //    baseShape.VisualShapeProp.GroupExtents = groupShape.VisualShapeProp.Extents;
+            //    baseShape.VisualShapeProp.GroupOffset = groupShape.VisualShapeProp.Offset;
+            //}
             var elements = htexSlide.DrawElement();
             if (elements != null)
             {

+ 114 - 99
HTEXLib/PPTX/Models/HTEX/HtexSlide.cs

@@ -70,82 +70,19 @@ namespace HTEXLib.Models.HTEX
         }
 
 
-        /**
-         * 
-        <a:xfrm> 
-            <a:off y = "1940518" x="2952779" /> 
-            <a:ext cy = "2209679" cx="1219680" /> 
-            <a:choff y = "1052" x="1972" /> 
-            <a:chext cy = "1116" cx="616" /> 
-        </a:xfrm> 
-        <a:xfrm> 
-             <a:off y = "1160" x="2161" /> 
-             <a:ext cy = "287" cx="288" /> 
-        </a:xfrm>
-        scale_factor_y = ext_cy / chext_cy 
-               = 2209679 / 1116 
-               ≈ 1980
-        scale_factor_x = ext_cx / chext_cx 
-                = 1219680 / 616
-                ≈ 1980
-        off_y = (not_scaled_off_y - choff_y) * scale_factor_y + group_off_y
-              = (1160  - 1052) * 1980 + 1940518
-              = 2154358
-        off_x = (not_scaled_off_x - choff_x) * scale_factor_x + group_off_x
-              = (2161  - 1972) * 1980 + 2952779
-              = 3326999
-        ext_cy = not_scaled_ext_cy * scale_factor_y
-               = 287 * 1980
-               = 568260
-        ext_cx = not_scaled_ext_cx * scale_factor_x
-               = 288 * 1980
-               = 570240
-         **/
+      
         private List<Item> DrawShapeHtex( PPTShapeBase baseShape,int index)
         {
-            double left =0;
-            double width = 0;
-            double top =0;
-            double height = 0;
-            if (FromGroup) {
-                if (baseShape.VisualShapeProp.ChildExtents != null && baseShape.VisualShapeProp.GroupExtents != null) {
-                    //具体算法
-                    //https://stackoverflow.com/questions/60770606/how-to-get-the-absolute-position-of-child-shapes-by-using-apache-poi
-                    double scale_factor_y = 1;
-                    double scale_factor_x = 1;
-                    if (baseShape.VisualShapeProp.ChildExtents.Cy > 0)
-                    {
-                        scale_factor_y = baseShape.VisualShapeProp.GroupExtents.Cy * 1.0 / baseShape.VisualShapeProp.ChildExtents.Cy;
-                        var off_y = (baseShape.VisualShapeProp.Offset.Y - baseShape.VisualShapeProp.ChildOffset.Y) * scale_factor_y + baseShape.VisualShapeProp.GroupOffset.Y;
-                        top = off_y * 1.0 * Globals.px96 / Globals.px914400;
-                        var ext_cy = baseShape.VisualShapeProp.Extents.Cy * scale_factor_y;
-                        height = ext_cy * 1.0 * Globals.px96 / Globals.px914400;
-
-                    }
-                    else
-                    {
-                        top = baseShape.VisualShapeProp.Top();
-                        height = baseShape.VisualShapeProp.PixelHeight();
-                    }
-                    if (baseShape.VisualShapeProp.ChildExtents.Cx > 0)
-                    {
-                        scale_factor_x = baseShape.VisualShapeProp.GroupExtents.Cx * 1.0 / baseShape.VisualShapeProp.ChildExtents.Cx;
-                        var off_x = (baseShape.VisualShapeProp.Offset.X - baseShape.VisualShapeProp.ChildOffset.X) * scale_factor_x + baseShape.VisualShapeProp.GroupOffset.X;
-                        left = off_x * 1.0 * Globals.px96 / Globals.px914400;
-                        var ext_cx = baseShape.VisualShapeProp.Extents.Cx * scale_factor_x;
-                        width = ext_cx * 1.0 * Globals.px96 / Globals.px914400;
-                    }
-                    else {
-                        left = baseShape.VisualShapeProp.Left();
-                        width = baseShape.VisualShapeProp.PixelWidth();
-                    }
-                }
-            } else {
-                left = baseShape.VisualShapeProp.Left();
-                width = baseShape.VisualShapeProp.PixelWidth();
-                top = baseShape.VisualShapeProp.Top();
-                height = baseShape.VisualShapeProp.PixelHeight();
+            if (baseShape.NonVisualShapeProp.SubName.Equals("矩形 34")) {
+                Console.WriteLine(1);
             }
+           
+
+            double left = baseShape.VisualShapeProp.Left();
+            double width = baseShape.VisualShapeProp.PixelWidth();
+            double top = baseShape.VisualShapeProp.Top();
+            double height = baseShape.VisualShapeProp.PixelHeight();
+          
             slide.hyperlinks = baseShape.hyperlinks;
             
             double rot = baseShape.VisualShapeProp.Rotate;
@@ -167,12 +104,12 @@ namespace HTEXLib.Models.HTEX
             List<Item> items = null;
             if (baseShape is PPTGraphicFrame graphicFrame)
             {
-                if (graphicFrame.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
+                if (graphicFrame.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape groupGF)
                 {
                     if (FromGroup)
                     {
-                        HtexGraphicFrame htmlSmartArt = new HtexGraphicFrame(Id, rot, width, height, top,
-                                                               left, invisible, animatable, index, graphicFrame, slide, baseShape.PartForm, TimingId);
+                        (double t,double l , double w,double h) =  FormGroup(groupGF, graphicFrame.VisualShapeProp.Offset, graphicFrame.VisualShapeProp.Extents, left, top, width, height);
+                        HtexGraphicFrame htmlSmartArt = new HtexGraphicFrame(Id, rot, w, h, t, l, invisible, animatable, index, graphicFrame, slide, baseShape.PartForm, TimingId);
                         items = htmlSmartArt.DrawElement();
                     }
                 }
@@ -186,12 +123,12 @@ namespace HTEXLib.Models.HTEX
             }
             else if (baseShape is PPTGroupShape groupShape)
             {
-                if (groupShape.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
+                if (groupShape.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape  groupGp)
                 {
                     if (FromGroup)
                     {
-                        HtexGroupShape htmlShape = new HtexGroupShape(Id, rot, width, height, top,
-                                                                left, invisible, animatable, index, groupShape, slide,  baseShape.PartForm, TimingId);
+                        (double t, double l, double w, double h) = FormGroup(groupGp, groupShape.VisualShapeProp.Offset, groupShape.VisualShapeProp.Extents, left, top, width, height);
+                        HtexGroupShape htmlShape = new HtexGroupShape(Id, rot, w, h, t, l, invisible, animatable, index, groupShape, slide,  baseShape.PartForm, TimingId);
                         items = htmlShape.DrawElement();
                     }
                 }
@@ -204,13 +141,13 @@ namespace HTEXLib.Models.HTEX
             }
             else if (baseShape is PPTConnectionShape connectionShape)
             {
-                if (connectionShape.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
+                if (connectionShape.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape  groupCs)
                 {
                     if (FromGroup)
                     {
+                        (double t, double l, double w, double h) = FormGroup(groupCs, connectionShape.VisualShapeProp.Offset, connectionShape.VisualShapeProp.Extents, left, top, width, height);
                         HtexConnectionShape htmlShape =
-                      new HtexConnectionShape(Id, rot, width, height, top,
-                                              left, invisible, animatable, index, connectionShape, slide,  baseShape.PartForm, TimingId);
+                      new HtexConnectionShape(Id, rot, w, h, t, l, invisible, animatable, index, connectionShape, slide,  baseShape.PartForm, TimingId);
                         items = htmlShape.DrawElement();
                     }
                 }
@@ -225,12 +162,12 @@ namespace HTEXLib.Models.HTEX
             }
             else if (baseShape is PPTShape shape)
             {
-                if (shape.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
+                if (shape.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape  groupSp)
                 {
                     if (FromGroup)
                     {
-                        HtexShape htmlShape = new HtexShape(Id, rot, width, height, top,
-                                                            left, invisible, animatable, slideIndex, index, shape, slide, baseShape.PartForm, TimingId)
+                        (double t, double l, double w, double h) = FormGroup(groupSp, shape.VisualShapeProp.Offset, shape.VisualShapeProp.Extents, left, top, width, height);
+                        HtexShape htmlShape = new HtexShape(Id, rot, w, h, t, l, invisible, animatable, slideIndex, index, shape, slide, baseShape.PartForm, TimingId)
                         {
                             Shape = shape,
                             //rot = baseShape.VisualShapeProp.Rotate,
@@ -254,12 +191,12 @@ namespace HTEXLib.Models.HTEX
             }
             else if (baseShape is PPTImage image)
             {
-                if (image.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
+                if (image.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape groupIm)
                 {
                     if (FromGroup)
                     {
-                        HtexImage htmlImage = new HtexImage(Id, rot, width, height,
-                                                     top, left, invisible, animatable, image.FileExtension, index, image, slide,  baseShape.PartForm, TimingId)
+                        (double t, double l, double w, double h) = FormGroup(groupIm, image.VisualShapeProp.Offset, image.VisualShapeProp.Extents, left, top, width, height);
+                        HtexImage htmlImage = new HtexImage(Id, rot, w, h, t, l, invisible, animatable, image.FileExtension, index, image, slide,  baseShape.PartForm, TimingId)
                         {
                             HyperLink = clickLinkUrl
                         };
@@ -280,12 +217,12 @@ namespace HTEXLib.Models.HTEX
             else if (baseShape is PPTMath math)
             {
 
-                if (math.element.Parent.Parent.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
+                if (math.element.Parent.Parent.Parent is DocumentFormat.OpenXml.Presentation.GroupShape groupMh)
                 {
                     if (FromGroup)
                     {
-                        HtexMath htexMath = new HtexMath(Id, rot, width, height, top,
-                                                          left, invisible, animatable, slideIndex, index, math, slide,  baseShape.PartForm, TimingId)
+                        (double t, double l, double w, double h) = FormGroup(groupMh, math.VisualShapeProp.Offset, math.VisualShapeProp.Extents, left, top, width, height);
+                        HtexMath htexMath = new HtexMath(Id, rot, w, h, t, l, invisible, animatable, slideIndex, index, math, slide,  baseShape.PartForm, TimingId)
                         {
                             pptMath = math,
                             HyperLink = clickLinkUrl
@@ -305,14 +242,13 @@ namespace HTEXLib.Models.HTEX
                 }
             }
             else if(baseShape is PPTTable table){
-                if (table.element.Parent.Parent.Parent.Parent.Parent.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
+                if (table.element.Parent.Parent.Parent.Parent.Parent.Parent is DocumentFormat.OpenXml.Presentation.GroupShape groupTb)
                 {
                     if (FromGroup)
                     {
-                        HtexTable HtexTable = new HtexTable(Id, rot, width, height, top, left, invisible, animatable, index, table, slide,  baseShape.PartForm, TimingId);
-                       
+                        (double t, double l, double w, double h) = FormGroup(groupTb, table.VisualShapeProp.Offset, table.VisualShapeProp.Extents, left, top, width, height);
+                        HtexTable HtexTable = new HtexTable(Id, rot, w, h, t, l, invisible, animatable, index, table, slide,  baseShape.PartForm, TimingId);
                         items = HtexTable.DrawElement();
-                        
                     }
                 }
                 else
@@ -324,11 +260,12 @@ namespace HTEXLib.Models.HTEX
             }
             else if (baseShape is PPTChart Chart)
             {
-                if (Chart.element.Parent.Parent.Parent.Parent.Parent.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
+                if (Chart.element.Parent.Parent.Parent.Parent.Parent.Parent is DocumentFormat.OpenXml.Presentation.GroupShape groupCh)
                 {
                     if (FromGroup)
                     {
-                        HtexChart HtexChart = new HtexChart(Id, rot, width, height, top, left, invisible, animatable, index, Chart, slide,  baseShape.PartForm, TimingId);
+                        (double t, double l, double w, double h) = FormGroup(groupCh, Chart.VisualShapeProp.Offset, Chart.VisualShapeProp.Extents, left, top, width, height);
+                        HtexChart HtexChart = new HtexChart(Id, rot, w, h, t, l, invisible, animatable, index, Chart, slide,  baseShape.PartForm, TimingId);
                         items = HtexChart.DrawElement();
                     }
                 }
@@ -341,11 +278,12 @@ namespace HTEXLib.Models.HTEX
             }
             else if (baseShape is PPTDiagram Diagram)
             {
-                if (Diagram.element.Parent.Parent.Parent.Parent.Parent.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
+                if (Diagram.element.Parent.Parent.Parent.Parent.Parent.Parent is DocumentFormat.OpenXml.Presentation.GroupShape groupDi)
                 {
                     if (FromGroup)
                     {
-                        HtexDiagram HtexChart = new HtexDiagram(Id, rot, width, height, top, left, invisible, animatable, index, Diagram, slide,  baseShape.PartForm, TimingId);
+                        (double t, double l, double w, double h) = FormGroup(groupDi, Diagram.VisualShapeProp.Offset, Diagram.VisualShapeProp.Extents,left,top,width,height);
+                        HtexDiagram HtexChart = new HtexDiagram(Id, rot, w, h, t, l, invisible, animatable, index, Diagram, slide,  baseShape.PartForm, TimingId);
                         items = HtexChart.DrawElement();
                     }
                 }
@@ -359,6 +297,83 @@ namespace HTEXLib.Models.HTEX
             return items;
         }
 
+
+        /**
+       * 
+      <a:xfrm> 
+          <a:off y = "1940518" x="2952779" /> 
+          <a:ext cy = "2209679" cx="1219680" /> 
+          <a:choff y = "1052" x="1972" /> 
+          <a:chext cy = "1116" cx="616" /> 
+      </a:xfrm> 
+      <a:xfrm> 
+           <a:off y = "1160" x="2161" /> 
+           <a:ext cy = "287" cx="288" /> 
+      </a:xfrm>
+      scale_factor_y = ext_cy / chext_cy 
+             = 2209679 / 1116 
+             ≈ 1980
+      scale_factor_x = ext_cx / chext_cx 
+              = 1219680 / 616
+              ≈ 1980
+      off_y = (not_scaled_off_y - choff_y) * scale_factor_y + group_off_y
+            = (1160  - 1052) * 1980 + 1940518
+            = 2154358
+      off_x = (not_scaled_off_x - choff_x) * scale_factor_x + group_off_x
+            = (2161  - 1972) * 1980 + 2952779
+            = 3326999
+      ext_cy = not_scaled_ext_cy * scale_factor_y
+             = 287 * 1980
+             = 568260
+      ext_cx = not_scaled_ext_cx * scale_factor_x
+             = 288 * 1980
+             = 570240
+       **/
+        public (double top , double left, double width, double height) FormGroup(DocumentFormat.OpenXml.Presentation.GroupShape Parent, Offset childOffset, Extents childExtents,
+             double left = 0, double width = 0, double top = 0, double height = 0
+            ) 
+        {
+
+            //double left = 0;
+            //double width = 0;
+            //double top = 0;
+            //double height = 0;
+            if (Parent.GroupShapeProperties.TransformGroup.ChildExtents != null && Parent.GroupShapeProperties.TransformGroup.Extents != null)
+            {
+                //具体算法
+                //https://stackoverflow.com/questions/60770606/how-to-get-the-absolute-position-of-child-shapes-by-using-apache-poi
+                double scale_factor_y = 1;
+                double scale_factor_x = 1;
+                if (Parent.GroupShapeProperties.TransformGroup.ChildExtents.Cy > 0)
+                {
+                    scale_factor_y = Parent.GroupShapeProperties.TransformGroup.Extents.Cy * 1.0 / Parent.GroupShapeProperties.TransformGroup.ChildExtents.Cy;
+                    var off_y = (childOffset.Y - Parent.GroupShapeProperties.TransformGroup.ChildOffset.Y) * scale_factor_y + Parent.GroupShapeProperties.TransformGroup.Offset.Y;
+                    top = off_y * 1.0 * Globals.px96 / Globals.px914400;
+                    var ext_cy = childExtents.Cy * scale_factor_y;
+                    height = ext_cy * 1.0 * Globals.px96 / Globals.px914400;
+
+                }
+                else
+                {
+                    top = childOffset.Y * 1.0 * Globals.px96 / Globals.px914400;
+                    height = childExtents.Cy * 1.0 * Globals.px96 / Globals.px914400;
+                }
+                if (Parent.GroupShapeProperties.TransformGroup.ChildExtents.Cx > 0)
+                {
+                    scale_factor_x = Parent.GroupShapeProperties.TransformGroup.Extents.Cx * 1.0 / Parent.GroupShapeProperties.TransformGroup.ChildExtents.Cx;
+                    var off_x = (childOffset.X- Parent.GroupShapeProperties.TransformGroup.ChildOffset.X) * scale_factor_y + Parent.GroupShapeProperties.TransformGroup.Offset.X; 
+                    left = off_x * 1.0 * Globals.px96 / Globals.px914400;
+                    var ext_cx = childExtents.Cx * scale_factor_x;
+                    width = ext_cx * 1.0 * Globals.px96 / Globals.px914400;
+                }
+                else
+                {
+                    left = childOffset.X* 1.0 * Globals.px96 / Globals.px914400;
+                    width = childExtents.Cx * 1.0 * Globals.px96 / Globals.px914400;
+                }
+            }
+            return (top, left, width, height);
+        }
         public override string ToString()
         {
 

+ 4 - 4
HTEXLib/PPTX/Models/PPTX/PPTContainerShape.cs

@@ -8,10 +8,10 @@ namespace HTEXLib.Models.Inner
    public class PPTContainerShape
     {
         public List<PPTShapeBase> Elements { get; set; } = new List<PPTShapeBase>();
-        public ChildExtents ChildExtents { get; set; }
-        public ChildOffset ChildOffset { get; set; }
-        public Offset GroupOffset { get; set; }
-        public Extents GroupExtents { get; set; }
+        //public ChildExtents ChildExtents { get; set; }
+        //public ChildOffset ChildOffset { get; set; }
+        //public Offset GroupOffset { get; set; }
+        //public Extents GroupExtents { get; set; }
         public PPTContainerShape()
         {
         }

+ 4 - 4
HTEXLib/PPTX/Models/PPTX/PPTGroupShape.cs

@@ -204,8 +204,8 @@ namespace HTEXLib.Models.Inner
             {
                 base.VisualShapeProp.Extents = groupShape.GroupShapeProperties.TransformGroup.Extents;
                 base.VisualShapeProp.Offset = groupShape.GroupShapeProperties.TransformGroup.Offset;
-                base.VisualShapeProp.ChildExtents= groupShape.GroupShapeProperties.TransformGroup.ChildExtents;
-                base.VisualShapeProp.ChildOffset = groupShape.GroupShapeProperties.TransformGroup.ChildOffset;
+                //base.VisualShapeProp.ChildExtents= groupShape.GroupShapeProperties.TransformGroup.ChildExtents;
+                //base.VisualShapeProp.ChildOffset = groupShape.GroupShapeProperties.TransformGroup.ChildOffset;
             }
             else
             {
@@ -229,8 +229,8 @@ namespace HTEXLib.Models.Inner
                     {
                         base.VisualShapeProp.Extents = layoutShape.GroupShapeProperties.TransformGroup.Extents;
                         base.VisualShapeProp.Offset = layoutShape.GroupShapeProperties.TransformGroup.Offset;
-                        base.VisualShapeProp.ChildExtents = groupShape.GroupShapeProperties.TransformGroup.ChildExtents;
-                        base.VisualShapeProp.ChildOffset = groupShape.GroupShapeProperties.TransformGroup.ChildOffset;
+                       // base.VisualShapeProp.ChildExtents = groupShape.GroupShapeProperties.TransformGroup.ChildExtents;
+                       // base.VisualShapeProp.ChildOffset = groupShape.GroupShapeProperties.TransformGroup.ChildOffset;
                     }
                 }
             }

+ 25 - 25
HTEXLib/PPTX/Models/PPTX/PPTVisualPPTShapeProp.cs

@@ -8,31 +8,31 @@ namespace HTEXLib.Models.Inner
     public class PPTVisualPPTShapeProp
     {
 
-        public ChildExtents ChildExtents
-        {
-            get;
-            set;
-
-        }
-
-        public ChildOffset ChildOffset
-        {
-            get;
-            set;
-        }
-
-        public Offset GroupOffset
-        {
-            get;
-            set;
-
-        }
-
-        public Extents GroupExtents
-        {
-            get;
-            set;
-        }
+        //public ChildExtents ChildExtents
+        //{
+        //    get;
+        //    set;
+
+        //}
+
+        //public ChildOffset ChildOffset
+        //{
+        //    get;
+        //    set;
+        //}
+
+        //public Offset GroupOffset
+        //{
+        //    get;
+        //    set;
+
+        //}
+
+        //public Extents GroupExtents
+        //{
+        //    get;
+        //    set;
+        //}
 
         public Offset Offset
         {