123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using DocumentFormat.OpenXml;
- using DocumentFormat.OpenXml.Packaging;
- using DocumentFormat.OpenXml.Presentation;
- using HTEXLib.Models;
- using HTEXLib.Models.Inner;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace HTEXLib.Builders
- {
- internal class PPTContainerShapeBuilder
- {
- public PPTContainerShape GetPPTContainerShape(SlideLayoutPart slidePart, PPTSlide slide)
- {
- var pptContainerShape = new PPTContainerShape();
- pptContainerShape.Elements = new List<PPTShapeBase>();
- var objs = slidePart.SlideLayout.Descendants();
- foreach (object obj in objs)
- {
- if (typeof(DocumentFormat.OpenXml.Presentation.Shape).Equals(obj.GetType()))
- {
- //p:sp
- pptContainerShape.Elements.Add(new PPTShape(slidePart, (DocumentFormat.OpenXml.Presentation.Shape)obj, slide));
- }
- else if (typeof(Picture).Equals(obj.GetType()))
- {
- //p:pic
- pptContainerShape.Elements.Add(new PPTImage(slidePart, (Picture)obj));
- }
- else if (typeof(GraphicFrame).Equals(obj.GetType()))
- {
- //p:graphicFrame Chart, Diagram, Table
- pptContainerShape.Elements.Add(new PPTGraphicFrame(slidePart, (GraphicFrame)obj));
- }
- else if (typeof(GroupShape).Equals(obj.GetType()))
- {
- //p:grpSp
- pptContainerShape.Elements.Add(new PPTGroupShape(slidePart, (GroupShape)obj,slide));
- }
- else if (typeof(ConnectionShape).Equals(obj.GetType()))
- {
- //p:cxnSp
- pptContainerShape.Elements.Add(new PPTConnectionShape(slidePart, (ConnectionShape)obj));
- }
- else if (typeof(AlternateContent).Equals(obj.GetType()))
- {
- ///Equations and formulas as Image 处理公式 方程等
- AlternateContent alternateContent = (AlternateContent)obj;
- var element = alternateContent.ChildElements.Where(x => typeof(AlternateContentFallback).Equals(x.GetType())).FirstOrDefault();
- if (element != null)
- {
- AlternateContentFallback alternateContentFallback = (AlternateContentFallback)element;
- if (alternateContentFallback.ChildElements.First() is DocumentFormat.OpenXml.Presentation.Shape shapea)
- {
- pptContainerShape.Elements.Add(new PPTShape(slidePart, shapea, slide));
- }
- else if (alternateContentFallback.ChildElements.First() is DocumentFormat.OpenXml.Presentation.Picture Picturea)
- {
- pptContainerShape.Elements.Add(new PPTImage(slidePart, Picturea));
- }
- }
- //MathML
- // pptContainerShape.Elements.Add(new PPTAlternateContent(slidePart, (AlternateContent)obj, slide));
- /// 处理公式 方程等
- }
- }
- return pptContainerShape;
- }
- public PPTContainerShape GetPPTContainerShape(SlidePart slidePart, PPTSlide slide)
- {
- var pptContainerShape = new PPTContainerShape();
- pptContainerShape.Elements = new List<PPTShapeBase>();
- var objs = slidePart.Slide.Descendants();
- foreach (object obj in objs)
- {
-
- if (typeof(DocumentFormat.OpenXml.Presentation.Shape).Equals(obj.GetType()))
- {
- //p:sp
- pptContainerShape.Elements.Add(new PPTShape(slidePart, (DocumentFormat.OpenXml.Presentation.Shape)obj, slide));
- }
- else if (typeof(Picture).Equals(obj.GetType()))
- {
- //p:pic
- pptContainerShape.Elements.Add(new PPTImage(slidePart, (Picture)obj));
- }
- else if (typeof(GraphicFrame).Equals(obj.GetType()))
- {
- //p:graphicFrame Chart, Diagram, Table
- pptContainerShape.Elements.Add(new PPTGraphicFrame(slidePart, (GraphicFrame)obj));
- }
- else if (typeof(GroupShape).Equals(obj.GetType()))
- {
- //p:grpSp
- pptContainerShape.Elements.Add(new PPTGroupShape(slidePart, (GroupShape)obj,slide));
- }
- else if (typeof(ConnectionShape).Equals(obj.GetType()))
- {
- //p:cxnSp
- pptContainerShape.Elements.Add(new PPTConnectionShape(slidePart, (ConnectionShape)obj));
- }
- else if (typeof(AlternateContent).Equals(obj.GetType())) {
- ///Equations and formulas as Image 处理公式 方程等
- AlternateContent alternateContent = (AlternateContent)obj;
- var element = alternateContent.ChildElements.Where(x =>typeof(AlternateContentFallback).Equals(x.GetType())).FirstOrDefault();
- if (element != null) {
- AlternateContentFallback alternateContentFallback = (AlternateContentFallback)element;
- if (alternateContentFallback.ChildElements.First() is DocumentFormat.OpenXml.Presentation.Shape shapea)
- {
- pptContainerShape.Elements.Add(new PPTShape(slidePart, shapea, slide));
- }
- else if (alternateContentFallback.ChildElements.First() is DocumentFormat.OpenXml.Presentation.Picture Picturea)
- {
- pptContainerShape.Elements.Add(new PPTImage(slidePart, Picturea));
- }
- }
- //MathML
- // pptContainerShape.Elements.Add(new PPTAlternateContent(slidePart, (AlternateContent)obj, slide));
- /// 处理公式 方程等
- }
- }
- return pptContainerShape;
- }
- }
- }
|