Browse Source

PPT解析优化

CrazyIter 4 years ago
parent
commit
f9234fe0c9

+ 6 - 6
HTEXLib/Builders/PPTContainerShapeBuilder.cs

@@ -50,12 +50,12 @@ namespace HTEXLib.Builders
                 else if (typeof(Picture).Equals(obj.GetType()))
                 else if (typeof(Picture).Equals(obj.GetType()))
                 {
                 {
                     //p:pic
                     //p:pic
-                    shape =new PPTImage(slidePart, (Picture)obj);
+                    shape =new PPTImage(slidePart, (Picture)obj, slide);
                 }
                 }
                 else if (typeof(GraphicFrame).Equals(obj.GetType()))
                 else if (typeof(GraphicFrame).Equals(obj.GetType()))
                 {
                 {
                     //p:graphicFrame  Chart, Diagram, Table
                     //p:graphicFrame  Chart, Diagram, Table
-                    shape =new PPTGraphicFrame(slidePart, (GraphicFrame)obj);
+                    shape =new PPTGraphicFrame(slidePart, (GraphicFrame)obj, slide);
                 }
                 }
                 else if (typeof(GroupShape).Equals(obj.GetType()))
                 else if (typeof(GroupShape).Equals(obj.GetType()))
                 {
                 {
@@ -65,7 +65,7 @@ namespace HTEXLib.Builders
                 else if (typeof(ConnectionShape).Equals(obj.GetType()))
                 else if (typeof(ConnectionShape).Equals(obj.GetType()))
                 {
                 {
                     //p:cxnSp
                     //p:cxnSp
-                    shape =new PPTConnectionShape(slidePart, (ConnectionShape)obj);
+                    shape =new PPTConnectionShape(slidePart, (ConnectionShape)obj, slide);
                 }
                 }
                 else if (typeof(AlternateContent).Equals(obj.GetType()))
                 else if (typeof(AlternateContent).Equals(obj.GetType()))
                 {
                 {
@@ -145,12 +145,12 @@ namespace HTEXLib.Builders
                 else if (typeof(Picture).Equals(obj.GetType()))
                 else if (typeof(Picture).Equals(obj.GetType()))
                 {
                 {
                     //p:pic
                     //p:pic
-                    shape =new PPTImage(slidePart, (Picture)obj);
+                    shape =new PPTImage(slidePart, (Picture)obj,slide);
                 }
                 }
                 else if (typeof(GraphicFrame).Equals(obj.GetType()))
                 else if (typeof(GraphicFrame).Equals(obj.GetType()))
                 {
                 {
                     //p:graphicFrame  Chart, Diagram, Table
                     //p:graphicFrame  Chart, Diagram, Table
-                    shape =new PPTGraphicFrame(slidePart, (GraphicFrame)obj);
+                    shape =new PPTGraphicFrame(slidePart, (GraphicFrame)obj, slide);
                 }
                 }
                 else if (typeof(GroupShape).Equals(obj.GetType()))
                 else if (typeof(GroupShape).Equals(obj.GetType()))
                 {
                 {
@@ -160,7 +160,7 @@ namespace HTEXLib.Builders
                 else if (typeof(ConnectionShape).Equals(obj.GetType()))
                 else if (typeof(ConnectionShape).Equals(obj.GetType()))
                 {
                 {
                     //p:cxnSp
                     //p:cxnSp
-                    shape =new PPTConnectionShape(slidePart, (ConnectionShape)obj);
+                    shape =new PPTConnectionShape(slidePart, (ConnectionShape)obj, slide);
                 }
                 }
                 else if (typeof(AlternateContent).Equals(obj.GetType())) {
                 else if (typeof(AlternateContent).Equals(obj.GetType())) {
                     ///Equations and formulas as Image  处理公式 方程等
                     ///Equations and formulas as Image  处理公式 方程等

+ 3 - 0
HTEXLib/HTEXLib.csproj

@@ -4,6 +4,9 @@
     <Description>PPT解析</Description>
     <Description>PPT解析</Description>
     <PackageReleaseNotes>PPT解析</PackageReleaseNotes>
     <PackageReleaseNotes>PPT解析</PackageReleaseNotes>
     <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
     <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
+    <Version>1.0.1</Version>
+    <AssemblyVersion>1.0.1.1</AssemblyVersion>
+    <FileVersion>1.0.1.1</FileVersion>
   </PropertyGroup>
   </PropertyGroup>
   <ItemGroup>
   <ItemGroup>
     <PackageReference Include="DocumentFormat.OpenXml" Version="2.11.3" />
     <PackageReference Include="DocumentFormat.OpenXml" Version="2.11.3" />

+ 3 - 3
HTEXLib/Models/FontStyle.cs

@@ -16,10 +16,10 @@ namespace HTEXLib
         //inherit  继承父级
         //inherit  继承父级
         public string family { get; set; }
         public string family { get; set; }
 
 
-        public string weight { get; set; }
-        public string style { get; set; }
+        //public string weight { get; set; }
+        //public string style { get; set; }
         public string underline { get; set; }
         public string underline { get; set; }
-        public string vertAlign { get; set; }
+       // public string vertAlign { get; set; }
         public string align { get; set; }
         public string align { get; set; }
         /// <summary>
         /// <summary>
         /// 阴影
         /// 阴影

+ 1 - 0
HTEXLib/Models/HTEX/HtexConnectionShape.cs

@@ -68,6 +68,7 @@ namespace HTEXLib.Models.HTEX
             Connector item = new Connector { type=type,cxnType=shapeType, invisible = invisible, animatable = animatable, index = index, id = id, svg = svg };
             Connector item = new Connector { type=type,cxnType=shapeType, invisible = invisible, animatable = animatable, index = index, id = id, svg = svg };
             item.style.position = position;
             item.style.position = position;
             item.style.border = shapeBorder;
             item.style.border = shapeBorder;
+            item.uid = connectionShape.suid;
             return new List<Item>() { item }; 
             return new List<Item>() { item }; 
         }
         }
     }
     }

+ 13 - 6
HTEXLib/Models/HTEX/HtexGraphicFrame.cs

@@ -38,25 +38,32 @@ namespace HTEXLib.Models.HTEX
 
 
         public override List<Item> DrawElement()
         public override List<Item> DrawElement()
         {
         {
-            var GraphicDataChildren = graphicFrame.element.Graphic.GraphicData.ChildElements;
-            
+            List < Item > items= null;
+           var GraphicDataChildren = graphicFrame.element.Graphic.GraphicData.ChildElements;
+          
             foreach (var clild in GraphicDataChildren) {
             foreach (var clild in GraphicDataChildren) {
                 if (clild is DocumentFormat.OpenXml.Drawing.Table Table) {
                 if (clild is DocumentFormat.OpenXml.Drawing.Table Table) {
                     HtexTable table = new HtexTable(id,rot,width,height,top,left,invisible,animatable,index,Table,slide,partForm);
                     HtexTable table = new HtexTable(id,rot,width,height,top,left,invisible,animatable,index,Table,slide,partForm);
-                    return table.DrawElement();
+                    items= table.DrawElement();
                 }
                 }
                 if (clild is DocumentFormat.OpenXml.Drawing.Charts.ChartReference Chart)
                 if (clild is DocumentFormat.OpenXml.Drawing.Charts.ChartReference Chart)
                 {
                 {
                     HtexChart chart = new HtexChart(id, rot, width, height, top, left, invisible, animatable, index, Chart, slide, partForm);
                     HtexChart chart = new HtexChart(id, rot, width, height, top, left, invisible, animatable, index, Chart, slide, partForm);
-                    return chart.DrawElement();
+                    items = chart.DrawElement();
                 }
                 }
                 if (clild is DocumentFormat.OpenXml.Drawing.Diagrams.RelationshipIds Diagram)
                 if (clild is DocumentFormat.OpenXml.Drawing.Diagrams.RelationshipIds Diagram)
                 {
                 {
                     HtexDiagram diagram = new HtexDiagram(id, rot, width, height, top, left, invisible, animatable, index, Diagram, slide, partForm);
                     HtexDiagram diagram = new HtexDiagram(id, rot, width, height, top, left, invisible, animatable, index, Diagram, slide, partForm);
-                    return diagram.DrawElement();
+                    items = diagram.DrawElement();
+                  
+                }
+                if (items != null&& items.Count > 0)
+                {
+                    items[0].uid = graphicFrame.suid;
+
                 }
                 }
             }
             }
-            return null; 
+            return items; 
         }
         }
         
         
 
 

+ 1 - 0
HTEXLib/Models/HTEX/HtexGroupShape.cs

@@ -34,6 +34,7 @@ namespace HTEXLib.Models.HTEX
             group.style.border = ShapeStyle.border;
             group.style.border = ShapeStyle.border;
             group.style.fill = ShapeStyle.fill;
             group.style.fill = ShapeStyle.fill;
             group.style.position = position;
             group.style.position = position;
+            group.uid = groupShape.suid;
             //SlideColor slideColor = PPTXHelper.DoShapeStyle(groupShape.element.ShapeStyle, slide, type);
             //SlideColor slideColor = PPTXHelper.DoShapeStyle(groupShape.element.ShapeStyle, slide, type);
             HtexSlide htexSlide = new HtexSlide(slide, slide.slideIndex)
             HtexSlide htexSlide = new HtexSlide(slide, slide.slideIndex)
             {
             {

+ 1 - 0
HTEXLib/Models/HTEX/HtexImage.cs

@@ -107,6 +107,7 @@ namespace HTEXLib.Models.HTEX
             }
             }
             HtexBlipFill htexBlipFill = PPTXHelper.DoBlipFill(image.element.BlipFill, slide,partForm);
             HtexBlipFill htexBlipFill = PPTXHelper.DoBlipFill(image.element.BlipFill, slide,partForm);
             media.image = htexBlipFill;
             media.image = htexBlipFill;
+            media.uid = image.suid;
             //TODO  处理公式图片
             //TODO  处理公式图片
             return new List<Item>() { media }; 
             return new List<Item>() { media }; 
         }
         }

+ 1 - 0
HTEXLib/Models/HTEX/HtexMath.cs

@@ -159,6 +159,7 @@ namespace HTEXLib.Models.HTEX
                     math.back = elmt[0];
                     math.back = elmt[0];
                 }
                 }
             }
             }
+            math.uid = pptMath.suid;
             return new List<Item> { math };
             return new List<Item> { math };
         }
         }
         /// <summary>
         /// <summary>

+ 1 - 0
HTEXLib/Models/HTEX/HtexShape.cs

@@ -195,6 +195,7 @@ namespace HTEXLib.Models.HTEX
                 }
                 }
             }
             }
             var elmt = new List<Item> ();
             var elmt = new List<Item> ();
+            shape.uid = Shape.suid;
             elmt.Add(shape);
             elmt.Add(shape);
             return elmt;
             return elmt;
         }
         }

+ 3 - 1
HTEXLib/Models/HTEX/HtexText.cs

@@ -82,7 +82,9 @@ namespace HTEXLib.Models.HTEX
                     }
                     }
                 }
                 }
             }
             }
-            return new List<Item>() { new Text() };
+
+            return null;
+          // return new List<Item>() { new Text() };
           
           
         }
         }
         public bool sameProps(HtexText other)
         public bool sameProps(HtexText other)

+ 1 - 1
HTEXLib/Models/PPTX/PPTAlternateContent.cs

@@ -24,7 +24,7 @@ namespace HTEXLib.Models.Inner
             }
             }
             base.slide = slide;
             base.slide = slide;
             element = alternateContent;
             element = alternateContent;
-            suid = ShaHashHelper.GetSHA1((alternateContent.GetType().Name + alternateContent.OuterXml).Trim().ToLower());
+            suid =slide.slideIndex+"-" +ShaHashHelper.GetSHA1((alternateContent.GetType().Name + alternateContent.OuterXml).Trim().ToLower());
             SetAlternateContentVisualProperties(openXmlPart, alternateContent);
             SetAlternateContentVisualProperties(openXmlPart, alternateContent);
             SetAlternateContentNonVisualProperties(openXmlPart, alternateContent);
             SetAlternateContentNonVisualProperties(openXmlPart, alternateContent);
             SetChild(openXmlPart, alternateContent);
             SetChild(openXmlPart, alternateContent);

+ 3 - 2
HTEXLib/Models/PPTX/PPTConnectionShape.cs

@@ -11,9 +11,10 @@ namespace HTEXLib.Models.Inner
 {
 {
     public class PPTConnectionShape : PPTShapeBase
     public class PPTConnectionShape : PPTShapeBase
     {
     {
-        public PPTConnectionShape(OpenXmlPart openXmlPart, ConnectionShape connectionShape)
+        public PPTConnectionShape(OpenXmlPart openXmlPart, ConnectionShape connectionShape, PPTSlide slide)
         {
         {
-            suid = ShaHashHelper.GetSHA1((connectionShape.GetType().Name + connectionShape.OuterXml).Trim().ToLower());
+            this.slide = slide;
+            suid = slide.slideIndex+"-" +ShaHashHelper.GetSHA1((connectionShape.GetType().Name + connectionShape.OuterXml).Trim().ToLower());
             if (openXmlPart is SlidePart slidePart)
             if (openXmlPart is SlidePart slidePart)
             {
             {
                 PartForm = "slide";
                 PartForm = "slide";

+ 3 - 2
HTEXLib/Models/PPTX/PPTGraphicFrame.cs

@@ -7,9 +7,10 @@ namespace HTEXLib.Models.Inner
     public class PPTGraphicFrame : PPTShapeBase
     public class PPTGraphicFrame : PPTShapeBase
     {
     {
         public DocumentFormat.OpenXml.Presentation.GraphicFrame element { get; set; }
         public DocumentFormat.OpenXml.Presentation.GraphicFrame element { get; set; }
-        public PPTGraphicFrame(OpenXmlPart openXmlPart, GraphicFrame gfarame)
+        public PPTGraphicFrame(OpenXmlPart openXmlPart, GraphicFrame gfarame, PPTSlide slide)
         {
         {
-            suid = ShaHashHelper.GetSHA1((gfarame.GetType().Name + gfarame.OuterXml).Trim().ToLower());
+            this.slide = slide;
+            suid = slide.slideIndex + "-" + ShaHashHelper.GetSHA1((gfarame.GetType().Name + gfarame.OuterXml).Trim().ToLower());
             if (openXmlPart is SlidePart slidePart)
             if (openXmlPart is SlidePart slidePart)
             {
             {
                 PartForm = "slide";
                 PartForm = "slide";

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

@@ -15,7 +15,7 @@ namespace HTEXLib.Models.Inner
     {
     {
         public PPTGroupShape(OpenXmlPart openXmlPart, DocumentFormat.OpenXml.Presentation.GroupShape groupShape ,PPTSlide slide)
         public PPTGroupShape(OpenXmlPart openXmlPart, DocumentFormat.OpenXml.Presentation.GroupShape groupShape ,PPTSlide slide)
         {
         {
-            suid = ShaHashHelper.GetSHA1((groupShape.GetType().Name + groupShape.OuterXml).Trim().ToLower());
+            suid = slide.slideIndex + "-" + ShaHashHelper.GetSHA1((groupShape.GetType().Name + groupShape.OuterXml).Trim().ToLower());
             if (openXmlPart is SlidePart slidePart)
             if (openXmlPart is SlidePart slidePart)
             {
             {
                 PartForm = "slide";
                 PartForm = "slide";
@@ -44,12 +44,12 @@ namespace HTEXLib.Models.Inner
             foreach (var shap in children) {
             foreach (var shap in children) {
                 if (shap is DocumentFormat.OpenXml.Presentation.ConnectionShape ConnectionShape) {
                 if (shap is DocumentFormat.OpenXml.Presentation.ConnectionShape ConnectionShape) {
                     //p:cxnSp
                     //p:cxnSp
-                    pptContainerShape.Elements.Add(new PPTConnectionShape(openXmlPart, ConnectionShape));
+                    pptContainerShape.Elements.Add(new PPTConnectionShape(openXmlPart, ConnectionShape,slide));
                 }
                 }
                 if (shap is DocumentFormat.OpenXml.Presentation.GraphicFrame GraphicFrame)
                 if (shap is DocumentFormat.OpenXml.Presentation.GraphicFrame GraphicFrame)
                 {
                 {
                     //p:graphicFrame  Chart, Diagram, Table
                     //p:graphicFrame  Chart, Diagram, Table
-                    pptContainerShape.Elements.Add(new PPTGraphicFrame(openXmlPart, GraphicFrame));
+                    pptContainerShape.Elements.Add(new PPTGraphicFrame(openXmlPart, GraphicFrame,slide));
                 }
                 }
                 if (shap is DocumentFormat.OpenXml.AlternateContent alternateContent)
                 if (shap is DocumentFormat.OpenXml.AlternateContent alternateContent)
                 {
                 {
@@ -65,7 +65,7 @@ namespace HTEXLib.Models.Inner
                         }
                         }
                         else if (alternateContentFallback.ChildElements.First() is DocumentFormat.OpenXml.Presentation.Picture Picturea)
                         else if (alternateContentFallback.ChildElements.First() is DocumentFormat.OpenXml.Presentation.Picture Picturea)
                         {
                         {
-                            pptContainerShape.Elements.Add(new PPTImage(openXmlPart, Picturea));
+                            pptContainerShape.Elements.Add(new PPTImage(openXmlPart, Picturea,slide));
                         }
                         }
                     }
                     }
                     //MathML
                     //MathML
@@ -81,7 +81,7 @@ namespace HTEXLib.Models.Inner
                 if (shap is DocumentFormat.OpenXml.Presentation.Picture Picture)
                 if (shap is DocumentFormat.OpenXml.Presentation.Picture Picture)
                 {
                 {
                     //p:pic
                     //p:pic
-                    pptContainerShape.Elements.Add(new PPTImage(openXmlPart, Picture));
+                    pptContainerShape.Elements.Add(new PPTImage(openXmlPart, Picture,slide));
                 }
                 }
                 if (shap is DocumentFormat.OpenXml.Presentation.Shape Shape)
                 if (shap is DocumentFormat.OpenXml.Presentation.Shape Shape)
                 {
                 {

+ 3 - 2
HTEXLib/Models/PPTX/PPTImage.cs

@@ -6,9 +6,10 @@ namespace HTEXLib.Models.Inner
 {
 {
     public class PPTImage : PPTShapeBase
     public class PPTImage : PPTShapeBase
     {
     {
-        public PPTImage(OpenXmlPart openXmlPart, Picture picture)
+        public PPTImage(OpenXmlPart openXmlPart, Picture picture, PPTSlide slide)
         {
         {
-            suid = ShaHashHelper.GetSHA1((picture.GetType().Name + picture.OuterXml).Trim().ToLower());
+            this.slide = slide;
+            suid = slide.slideIndex + "-" + ShaHashHelper.GetSHA1((picture.GetType().Name + picture.OuterXml).Trim().ToLower());
             if (openXmlPart is SlidePart slidePart)
             if (openXmlPart is SlidePart slidePart)
             {
             {
                 PartForm = "slide";
                 PartForm = "slide";

+ 1 - 1
HTEXLib/Models/PPTX/PPTMath.cs

@@ -26,7 +26,7 @@ namespace HTEXLib.Models.PPTX
             base.slide = slide;
             base.slide = slide;
             this.AlternateContentChoice = AlternateContentChoice;
             this.AlternateContentChoice = AlternateContentChoice;
             this.AlternateContentFallback = AlternateContentFallback;
             this.AlternateContentFallback = AlternateContentFallback;
-            suid = ShaHashHelper.GetSHA1((AlternateContentChoice.GetType().Name + AlternateContentChoice.OuterXml).Trim().ToLower());
+            suid = slide.slideIndex + "-" +  ShaHashHelper.GetSHA1((AlternateContentChoice.GetType().Name + AlternateContentChoice.OuterXml).Trim().ToLower());
             SetMathNonVisualProperties(openXmlPart, AlternateContentChoice, AlternateContentFallback);
             SetMathNonVisualProperties(openXmlPart, AlternateContentChoice, AlternateContentFallback);
             SetMathVisualProperties(openXmlPart, AlternateContentChoice, AlternateContentFallback);
             SetMathVisualProperties(openXmlPart, AlternateContentChoice, AlternateContentFallback);
         }
         }

+ 1 - 1
HTEXLib/Models/PPTX/PPTShape.cs

@@ -37,7 +37,7 @@ namespace HTEXLib.Models.Inner
 
 
         public PPTShape(OpenXmlPart openXmlPart, DocumentFormat.OpenXml.Presentation.Shape shape, PPTSlide slide) : base()
         public PPTShape(OpenXmlPart openXmlPart, DocumentFormat.OpenXml.Presentation.Shape shape, PPTSlide slide) : base()
         {
         {
-            suid =ShaHashHelper.GetSHA1((shape.GetType().Name + shape.OuterXml).Trim().ToLower());
+            suid = slide.slideIndex + "-" +  ShaHashHelper.GetSHA1((shape.GetType().Name + shape.OuterXml).Trim().ToLower());
             if (openXmlPart is SlidePart slidePart)
             if (openXmlPart is SlidePart slidePart)
             {
             {
                 PartForm = "slide";
                 PartForm = "slide";

+ 1 - 0
HTEXLib/Models/PPTX/PPTShapeBase.cs

@@ -11,6 +11,7 @@ namespace HTEXLib.Models.Inner
 {
 {
     public class PPTShapeBase
     public class PPTShapeBase
     {
     {
+
         public string suid { get; set; }
         public string suid { get; set; }
         public PPTVisualPPTShapeProp VisualShapeProp { get; set; }
         public PPTVisualPPTShapeProp VisualShapeProp { get; set; }
         public PPTNonVisualShapeProp NonVisualShapeProp { get; set; }
         public PPTNonVisualShapeProp NonVisualShapeProp { get; set; }

+ 1 - 1
HTEXLib/Models/Paragraph.cs

@@ -27,7 +27,7 @@ namespace HTEXLib
         /// </summary>
         /// </summary>
         public bool invisible { get; set; }
         public bool invisible { get; set; }
     }
     }
-    public class Text :Item
+    public class Text //:Item
     {
     {
       //  public string StyleSha { get; set; }
       //  public string StyleSha { get; set; }
         public string content { get; set; }
         public string content { get; set; }