|
@@ -1,4 +1,5 @@
|
|
|
using DocumentFormat.OpenXml;
|
|
|
+using DocumentFormat.OpenXml.Drawing;
|
|
|
using DocumentFormat.OpenXml.Packaging;
|
|
|
using DocumentFormat.OpenXml.Presentation;
|
|
|
using HiTeachCC.Model.PowerPoint;
|
|
@@ -13,7 +14,7 @@ using Theme = DocumentFormat.OpenXml.Drawing.Theme;
|
|
|
|
|
|
namespace HiTeachCC.Service.PowerPoint.Implement
|
|
|
{
|
|
|
- public class PowerPointService : BaseService, IPowerPointService
|
|
|
+ public class PowerPointService : BaseService, IPowerPointService
|
|
|
{
|
|
|
const double inchpixel = 96.00, inchpt = 72.00, pxBase = 914400.00, ptBase = 12700;
|
|
|
const double rotBase = 60000.00;
|
|
@@ -52,6 +53,7 @@ namespace HiTeachCC.Service.PowerPoint.Implement
|
|
|
int pageSize = 0;
|
|
|
var slideMasterParts = presentationPart.SlideMasterParts;
|
|
|
ColorMap colorMap = null;
|
|
|
+ SlideMaster slideMaster = null;
|
|
|
Theme theme = null;
|
|
|
foreach (var slideMasterPart in slideMasterParts)
|
|
|
{
|
|
@@ -59,10 +61,11 @@ namespace HiTeachCC.Service.PowerPoint.Implement
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
+ slideMaster = slideMasterPart.SlideMaster;
|
|
|
colorMap = slideMasterPart.SlideMaster.ColorMap;
|
|
|
theme = slideMasterPart.ThemePart.Theme;
|
|
|
}
|
|
|
- Dictionary<string,string> colors= DoColorMap(colorMap, theme);
|
|
|
+ Dictionary<string, string> colors = DoColorMap(colorMap, theme);
|
|
|
//获取PPT 一页大小
|
|
|
double x = presentation.SlideSize.Cx * inchpixel / pxBase;
|
|
|
double y = presentation.SlideSize.Cy * inchpixel / pxBase;
|
|
@@ -70,7 +73,7 @@ namespace HiTeachCC.Service.PowerPoint.Implement
|
|
|
if (presentation.SlideIdList != null)
|
|
|
{
|
|
|
|
|
|
- // presentation.SlideIdList.OrderBy(x=>x.);
|
|
|
+ // presentation.SlideIdList.OrderBy(x=>x.);
|
|
|
// Get the title of each slide in the slide order.
|
|
|
// 获取的是几页PPT数量
|
|
|
foreach (var slideId in presentation.SlideIdList.Elements<SlideId>())
|
|
@@ -82,6 +85,7 @@ namespace HiTeachCC.Service.PowerPoint.Implement
|
|
|
//获取当前页 PPT 的所有元素
|
|
|
// slide.Items = GetSlideElement(slidePart, theme, colorMap);
|
|
|
//slide.Xml = slidePart.Slide.OuterXml;
|
|
|
+ GetSlideElement(slidePart, colors);
|
|
|
slides.Add(slide);
|
|
|
pageSize++;
|
|
|
}
|
|
@@ -92,25 +96,43 @@ namespace HiTeachCC.Service.PowerPoint.Implement
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
- public HiTeachCC.Model.PowerPoint.Slide GetSlideElement(SlidePart slidePart, Dictionary<string, string> colors) {
|
|
|
+ public HiTeachCC.Model.PowerPoint.Slide GetSlideElement(SlidePart slidePart, Dictionary<string, string> colors)
|
|
|
+ {
|
|
|
+ //slidePart.SlideLayoutPart;
|
|
|
+
|
|
|
var shapeTrees = from shap in slidePart.Slide.Descendants<ShapeTree>() select shap;
|
|
|
if (shapeTrees.Count() > 0 && shapeTrees.First().ChildElements.Count > 0)
|
|
|
{
|
|
|
OpenXmlElementList openXmlElements = shapeTrees.First().ChildElements;
|
|
|
+ TransformGroup transformGroup = shapeTrees.First().GroupShapeProperties.TransformGroup;
|
|
|
+ HiTeachCC.Model.PowerPoint.Position position = new
|
|
|
+ HiTeachCC.Model.PowerPoint.Position();
|
|
|
+ position.Rot = transformGroup.Rotation == null ? 0 : transformGroup.Rotation.Value;
|
|
|
+ position.FlipH = transformGroup.HorizontalFlip == null ? false : transformGroup.HorizontalFlip.Value;
|
|
|
+ position.FlipV = transformGroup.VerticalFlip == null ? false : transformGroup.VerticalFlip.Value;
|
|
|
+ position.X = transformGroup.Offset.X == null ? 0 : transformGroup.Offset.X.Value;
|
|
|
+ position.Y = transformGroup.Offset.Y == null ? 0 : transformGroup.Offset.Y.Value;
|
|
|
+ position.Cx = transformGroup.Extents.Cx == null ? 0 : transformGroup.Extents.Cx.Value;
|
|
|
+ position.Cy = transformGroup.Extents.Cy == null ? 0 : transformGroup.Extents.Cy.Value;
|
|
|
+ position.ChX = transformGroup.ChildOffset.X == null ? 0 : transformGroup.ChildOffset.X.Value;
|
|
|
+ position.ChY = transformGroup.ChildOffset.Y == null ? 0 : transformGroup.ChildOffset.Y.Value;
|
|
|
+ position.ChCX = transformGroup.ChildExtents.Cx == null ? 0 : transformGroup.ChildExtents.Cx.Value;
|
|
|
+ position.ChCY = transformGroup.ChildExtents.Cy == null ? 0 : transformGroup.ChildExtents.Cy.Value;
|
|
|
int index = 0;
|
|
|
foreach (OpenXmlElement element in openXmlElements)
|
|
|
{
|
|
|
- ProcessNodesInSlide(element ,slidePart, colors, index);
|
|
|
+ ProcessNodesInSlide(element, slidePart, colors, index);
|
|
|
index++;
|
|
|
}
|
|
|
}
|
|
|
- return null;
|
|
|
+ return null;
|
|
|
}
|
|
|
- public string ProcessNodesInSlide(OpenXmlElement element, SlidePart slidePart, Dictionary<string, string> colors, int index ) {
|
|
|
+ public string ProcessNodesInSlide(OpenXmlElement element, SlidePart slidePart, Dictionary<string, string> colors, int index)
|
|
|
+ {
|
|
|
if (element is DocumentFormat.OpenXml.Presentation.Shape sp)//p:sp
|
|
|
{
|
|
|
// pptElement = ShapeConvert(shape, theme, colorMap, index);
|
|
|
- ProcessSpNode(sp, slidePart,colors, index);
|
|
|
+ ProcessSpNode(sp, slidePart, colors, index);
|
|
|
}
|
|
|
else if (element is DocumentFormat.OpenXml.Presentation.Picture pic)//p:pic
|
|
|
{
|
|
@@ -122,12 +144,12 @@ namespace HiTeachCC.Service.PowerPoint.Implement
|
|
|
ProcessMcNode(mc, slidePart, colors, index);
|
|
|
/// pptElement = AlternateContentConvert(content, theme, colorMap, slidePart, index);
|
|
|
}
|
|
|
- else if(element is DocumentFormat.OpenXml.Presentation.GraphicFrame graphicFrame)//p:graphicFrame
|
|
|
+ else if (element is DocumentFormat.OpenXml.Presentation.GraphicFrame graphicFrame)//p:graphicFrame
|
|
|
{
|
|
|
ProcessGraphicFrameNode(graphicFrame, slidePart, colors, index);
|
|
|
/// pptElement = GraphicFrameConvert(graphicFrame, theme, colorMap, index);
|
|
|
}
|
|
|
- else if (element is DocumentFormat.OpenXml.Presentation.GroupShape grpSp)//p:grpSp
|
|
|
+ else if (element is DocumentFormat.OpenXml.Presentation.GroupShape grpSp)//p:grpSp
|
|
|
{
|
|
|
ProcessGrpSpNode(grpSp, slidePart, colors, index);
|
|
|
/// pptElement = GroupShapeConvert(groupShape, theme, colorMap, index);
|
|
@@ -137,44 +159,51 @@ namespace HiTeachCC.Service.PowerPoint.Implement
|
|
|
ProcessCxnSpNode(cxnSp, slidePart, colors, index);
|
|
|
/// pptElement = ConnectionShapeConvert(connectionShape, theme, colorMap, index);
|
|
|
}
|
|
|
- return null;
|
|
|
+ return null;
|
|
|
}
|
|
|
- public string ProcessSpNode(OpenXmlElement element, SlidePart slidePart, Dictionary<string, string> colors, int index) {
|
|
|
+ public string ProcessSpNode(DocumentFormat.OpenXml.Presentation.Shape element, SlidePart slidePart, Dictionary<string, string> colors, int index)
|
|
|
+ {
|
|
|
+ HiTeachCC.Model.PowerPoint.Shape shape = new HiTeachCC.Model.PowerPoint.Shape();
|
|
|
+ HiTeachCC.Model.PowerPoint.Position position = new HiTeachCC.Model.PowerPoint.Position();
|
|
|
+ //element.ShapeProperties
|
|
|
return null;
|
|
|
}
|
|
|
- public string ProcessPicNode(OpenXmlElement element, SlidePart slidePart, Dictionary<string, string> colors, int index)
|
|
|
+ public string ProcessPicNode(DocumentFormat.OpenXml.Presentation.Picture element, SlidePart slidePart, Dictionary<string, string> colors, int index)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
- public string ProcessMcNode(OpenXmlElement element, SlidePart slidePart, Dictionary<string, string> colors, int index)
|
|
|
+ public string ProcessMcNode(DocumentFormat.OpenXml.AlternateContent element, SlidePart slidePart, Dictionary<string, string> colors, int index)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
- public string ProcessGraphicFrameNode(OpenXmlElement element, SlidePart slidePart, Dictionary<string, string> colors, int index)
|
|
|
+ public string ProcessGraphicFrameNode(DocumentFormat.OpenXml.Presentation.GraphicFrame element, SlidePart slidePart, Dictionary<string, string> colors, int index)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
- public string ProcessGrpSpNode(OpenXmlElement element, SlidePart slidePart, Dictionary<string, string> colors, int index)
|
|
|
+ public string ProcessGrpSpNode(DocumentFormat.OpenXml.Presentation.GroupShape element, SlidePart slidePart, Dictionary<string, string> colors, int index)
|
|
|
{
|
|
|
var shapes = from shap in element.Descendants<DocumentFormat.OpenXml.Presentation.Shape>() select shap;
|
|
|
- foreach (var shape in shapes) {
|
|
|
- string s = ProcessNodesInSlide(shape, slidePart, colors, index);
|
|
|
+ foreach (var shape in shapes)
|
|
|
+ {
|
|
|
+ string s = ProcessNodesInSlide(shape, slidePart, colors, index);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
- public string ProcessCxnSpNode(OpenXmlElement element, SlidePart slidePart, Dictionary<string, string> colors, int index)
|
|
|
+ public string ProcessCxnSpNode(DocumentFormat.OpenXml.Presentation.ConnectionShape element, SlidePart slidePart, Dictionary<string, string> colors, int index)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
- public Dictionary<string, string> DoColorMap(ColorMap colorMap , Theme theme) {
|
|
|
+ public Dictionary<string, string> DoColorMap(ColorMap colorMap, Theme theme)
|
|
|
+ {
|
|
|
string[] colors = { "accent1", "accent2", "accent3", "accent4", "accent5", "accent6",
|
|
|
"lt1", "lt2", "tx1", "tx2", "dk1","dk2","hlink","folHlink" };
|
|
|
DocumentFormat.OpenXml.Drawing.ColorScheme colorScheme = theme.ThemeElements.ColorScheme;
|
|
|
Dictionary<string, string> pairs = new Dictionary<string, string>();
|
|
|
- foreach (var col in colors) {
|
|
|
+ foreach (var col in colors)
|
|
|
+ {
|
|
|
pairs.Add(col, PowerPointHelper.ColorForThemeClr(col, colorScheme, colorMap));
|
|
|
}
|
|
|
- return pairs;
|
|
|
+ return pairs;
|
|
|
}
|
|
|
}
|
|
|
}
|