|
@@ -9,6 +9,8 @@ using DocumentFormat.OpenXml.Presentation;
|
|
|
using DocumentFormat.OpenXml.Drawing;
|
|
|
using HTEXLib.Models;
|
|
|
using ColorType = DocumentFormat.OpenXml.Drawing.ColorType;
|
|
|
+using System.Linq;
|
|
|
+using DocumentFormat.OpenXml.Packaging;
|
|
|
|
|
|
namespace HTEXLib.Helpers.ShapeHelpers
|
|
|
{
|
|
@@ -19,6 +21,8 @@ namespace HTEXLib.Helpers.ShapeHelpers
|
|
|
public string EffectColor { get; set; }
|
|
|
public string FontColor { get; set; }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
public static class PPTXHelper
|
|
|
{
|
|
|
// StyleMatrixReferenceType
|
|
@@ -50,7 +54,10 @@ namespace HTEXLib.Helpers.ShapeHelpers
|
|
|
/// 处理 FontReference 字体 a:fontRef
|
|
|
/// </summary>
|
|
|
/// <param name="shapeStyle"></param>
|
|
|
- public static SlideColor DoShapeStyle(DocumentFormat.OpenXml.Presentation.ShapeStyle shapeStyle, PPTSlide slide) {
|
|
|
+ public static SlideColor DoShapeStyle(DocumentFormat.OpenXml.Presentation.ShapeStyle shapeStyle, PPTSlide slide, string type) {
|
|
|
+ if (shapeStyle == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
string LineColor = StyleMatrixReferenceColors(shapeStyle.LineReference, slide);
|
|
|
string FillColor = StyleMatrixReferenceColors(shapeStyle.FillReference, slide);
|
|
|
string EffectColor = StyleMatrixReferenceColors(shapeStyle.EffectReference, slide);
|
|
@@ -62,59 +69,70 @@ namespace HTEXLib.Helpers.ShapeHelpers
|
|
|
/// </summary>
|
|
|
/// <param name="shapeProperties"></param>
|
|
|
/// <param name="slide"></param>
|
|
|
- public static void DoShapeProperties(DocumentFormat.OpenXml.Presentation.ShapeProperties shapeProperties, PPTSlide slide) {
|
|
|
+ public static HTEXLib.Models.HTEX.ShapeStyle DoShapeProperties(DocumentFormat.OpenXml.Presentation.ShapeProperties shapeProperties, PPTSlide slide, string type) {
|
|
|
//Outline
|
|
|
- var lnNode = shapeProperties.GetTextByPath("//a:ln");
|
|
|
+ var lnNode = shapeProperties.GetFirstChild<Outline>();
|
|
|
+ Border border = null;
|
|
|
if (lnNode != null)
|
|
|
{
|
|
|
- Border border = DoLn(new Outline(lnNode.ToString()),slide);
|
|
|
+ border = DoLn(lnNode, slide,type);
|
|
|
}
|
|
|
Fill fill = new Fill() { type = -1 };
|
|
|
- var gradFill = shapeProperties.GetTextByPath("a:gradFill");
|
|
|
+ var gradFill = shapeProperties.GetFirstChild<GradientFill>();
|
|
|
if (gradFill != null)
|
|
|
{
|
|
|
fill.type = 2;
|
|
|
- fill.gradientFill = DoGradientFill(new GradientFill(gradFill.ToString()), slide);
|
|
|
+ fill.gradientFill = DoGradientFill(gradFill, slide);
|
|
|
}
|
|
|
- var noFill = shapeProperties.GetTextByPath("a:noFill");
|
|
|
+ var noFill = shapeProperties.GetFirstChild<NoFill>();
|
|
|
if (noFill != null)
|
|
|
{
|
|
|
fill.type = 0;
|
|
|
}
|
|
|
- var pattFill = shapeProperties.GetTextByPath("a:pattFill");
|
|
|
+ var pattFill = shapeProperties.GetFirstChild<PatternFill>();
|
|
|
if (pattFill != null)
|
|
|
{
|
|
|
|
|
|
- DocumentFormat.OpenXml.Drawing.PatternFill patternFill = new PatternFill(pattFill.ToString());
|
|
|
- HtexPattFill htexPattFill = DoPattFill(patternFill, slide);
|
|
|
+
|
|
|
+ HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
|
|
|
fill.type = 4;
|
|
|
fill.pattFill = htexPattFill;
|
|
|
}
|
|
|
- var solidFill = shapeProperties.GetTextByPath("a:solidFill");
|
|
|
+ var solidFill = shapeProperties.GetFirstChild<SolidFill>();
|
|
|
if (solidFill != null)
|
|
|
{
|
|
|
fill.type = 1;
|
|
|
- fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
|
|
|
+ fill.solidFill = ReadSolidFillColors(solidFill, slide);
|
|
|
}
|
|
|
- var groupFill = shapeProperties.GetTextByPath("a:groupFill");
|
|
|
+ var groupFill = shapeProperties.GetFirstChild<GroupFill>();
|
|
|
if (groupFill != null)
|
|
|
{
|
|
|
fill.type =5;
|
|
|
// fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
|
|
|
}
|
|
|
- var blipFill = shapeProperties.GetTextByPath("a:blipFill");
|
|
|
+ var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
|
|
|
if (blipFill != null)
|
|
|
{
|
|
|
fill.type = 3;
|
|
|
+ fill.blipFill = DoBlipFill(blipFill, slide);
|
|
|
// fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
|
|
|
}
|
|
|
-
|
|
|
+ var EffectList= shapeProperties.GetFirstChild<EffectList>();
|
|
|
+ var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
|
|
|
+ var Scene3DType = shapeProperties.GetFirstChild<Scene3DType>();
|
|
|
+ var Shape3DType = shapeProperties.GetFirstChild<Shape3DType>();
|
|
|
+ var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<ShapePropertiesExtensionList>();
|
|
|
+ return new HTEXLib.Models.HTEX.ShapeStyle {fill=fill,border= border };
|
|
|
}
|
|
|
- public static HtexBlipFill DoBlipFill(DocumentFormat.OpenXml.Drawing.BlipFill blipFill, Slide slide) {
|
|
|
+ public static HtexBlipFill DoBlipFill(DocumentFormat.OpenXml.Drawing.BlipFill blipFill, PPTSlide slide) {
|
|
|
HtexBlipFill htexBlipFill = new HtexBlipFill();
|
|
|
SourceRectangle source= blipFill.SourceRectangle; ///源矩形 srcRect可能无用
|
|
|
htexBlipFill.dip = blipFill.Dpi;
|
|
|
- htexBlipFill.rotWithShape = blipFill.RotateWithShape;
|
|
|
+ if (blipFill.RotateWithShape != null) {
|
|
|
+ htexBlipFill.rotWithShape = blipFill.RotateWithShape;
|
|
|
+ }
|
|
|
+ { htexBlipFill.rotWithShape =true; }
|
|
|
+
|
|
|
var fillRect = blipFill.GetTextByPath("a:stretch/a:fillRect");///拉伸
|
|
|
if (fillRect != null) {
|
|
|
htexBlipFill.fillRect = new Vector
|
|
@@ -134,7 +152,85 @@ namespace HTEXLib.Helpers.ShapeHelpers
|
|
|
Tile tile= blipFill.GetFirstChild <Tile>();
|
|
|
if (tile != null) {
|
|
|
///algn (Alignment) flip (Tile Flipping) sx (Horizontal Ratio) sy (Vertical Ratio) tx (Horizontal Offset) ty (Vertical Offset)
|
|
|
+ htexBlipFill.tile = new HtexTile { algn=tile.Alignment,flip=tile.Flip,sx=tile.HorizontalRatio,sy=tile.VerticalRatio,tx=tile.HorizontalOffset,ty=tile.VerticalOffset};
|
|
|
+ }
|
|
|
+ var Embed = blipFill.Blip.Embed;
|
|
|
+ var Link = blipFill.Blip.Link;
|
|
|
+ //slide.SlideLayoutPart
|
|
|
+ var part = slide.SlidePart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault() ;
|
|
|
+ if (part != null) {
|
|
|
+ var url= part.OpenXmlPart.Uri .ToString().Replace("../","/ppt/");
|
|
|
+ var thumbnail = slide.Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
|
|
|
+ if (thumbnail != null)
|
|
|
+ {
|
|
|
+ var contentType = thumbnail.Attribute("{http://schemas.microsoft.com/office/2006/xmlPackage}contentType").Value;
|
|
|
+ var data = thumbnail.Value;
|
|
|
+ url = "data:" + contentType + ";base64," + data;
|
|
|
+ url = url.Replace("\r\n", "");
|
|
|
+ htexBlipFill.url = url;
|
|
|
+ htexBlipFill.urlType = "base64";
|
|
|
+ htexBlipFill.contentType = contentType;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //TODO 图片元素的更多信息需要后期继续实现,如滤镜,裁剪,图片颜色,图片校正等
|
|
|
+ return htexBlipFill;
|
|
|
+ }
|
|
|
+ public static HtexBlipFill DoBlipFill(DocumentFormat.OpenXml.Presentation.BlipFill blipFill, PPTSlide slide)
|
|
|
+ {
|
|
|
+ HtexBlipFill htexBlipFill = new HtexBlipFill();
|
|
|
+ SourceRectangle source = blipFill.SourceRectangle; ///源矩形 srcRect可能无用
|
|
|
+ htexBlipFill.dip = blipFill.Dpi;
|
|
|
+ if (blipFill.RotateWithShape != null)
|
|
|
+ {
|
|
|
+ htexBlipFill.rotWithShape = blipFill.RotateWithShape;
|
|
|
+ }
|
|
|
+ { htexBlipFill.rotWithShape = true; }
|
|
|
+
|
|
|
+ var fillRect = blipFill.GetTextByPath("a:stretch/a:fillRect");///拉伸
|
|
|
+ if (fillRect != null)
|
|
|
+ {
|
|
|
+ htexBlipFill.fillRect = new Vector
|
|
|
+ {
|
|
|
+ t = fillRect.Attribute("t") != null ? int.Parse(fillRect.Attribute("t").Value) / 1000 : 0,
|
|
|
+ l = fillRect.Attribute("l") != null ? int.Parse(fillRect.Attribute("l").Value) / 1000 : 0,
|
|
|
+ r = fillRect.Attribute("r") != null ? int.Parse(fillRect.Attribute("r").Value) / 1000 : 0,
|
|
|
+ b = fillRect.Attribute("b") != null ? int.Parse(fillRect.Attribute("b").Value) / 1000 : 0
|
|
|
+ };
|
|
|
+ }
|
|
|
+ var alphaModFix = blipFill.Blip.GetTextByPath("a:alphaModFix");
|
|
|
+ if (alphaModFix != null)
|
|
|
+ {
|
|
|
+ if (alphaModFix.Attribute("amt") != null)
|
|
|
+ {
|
|
|
+ htexBlipFill.opacity = int.Parse(alphaModFix.Attribute("amt").Value) * 1.0 / 1000;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Tile tile = blipFill.GetFirstChild<Tile>();
|
|
|
+ if (tile != null)
|
|
|
+ {
|
|
|
+ ///algn (Alignment) flip (Tile Flipping) sx (Horizontal Ratio) sy (Vertical Ratio) tx (Horizontal Offset) ty (Vertical Offset)
|
|
|
+ }
|
|
|
+ var Embed = blipFill.Blip.Embed;
|
|
|
+ var Link = blipFill.Blip.Link;
|
|
|
+ //slide.SlideLayoutPart
|
|
|
+ var part = slide.SlidePart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
|
|
|
+ if (part != null)
|
|
|
+ {
|
|
|
+ var url = part.OpenXmlPart.Uri.ToString().Replace("../", "/ppt/");
|
|
|
+ var thumbnail = slide.Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
|
|
|
+ if (thumbnail != null)
|
|
|
+ {
|
|
|
+ var contentType = thumbnail.Attribute("{http://schemas.microsoft.com/office/2006/xmlPackage}contentType").Value;
|
|
|
+ var data = thumbnail.Value;
|
|
|
+ url = "data:" + contentType + ";base64," + data;
|
|
|
+ url = url.Replace("\r\n", "");
|
|
|
+ htexBlipFill.url = url;
|
|
|
+ htexBlipFill.urlType = "base64";
|
|
|
+ htexBlipFill.contentType = contentType;
|
|
|
+ }
|
|
|
}
|
|
|
+ //TODO 图片元素的更多信息需要后期继续实现,如滤镜,裁剪,图片颜色,图片校正等
|
|
|
return htexBlipFill;
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -142,12 +238,19 @@ namespace HTEXLib.Helpers.ShapeHelpers
|
|
|
/// </summary>
|
|
|
/// <param name="shapeProperties"></param>
|
|
|
/// <param name="slide"></param>
|
|
|
- public static Border DoLn(DocumentFormat.OpenXml.Drawing.Outline outline, PPTSlide slide) {
|
|
|
+ public static Border DoLn(DocumentFormat.OpenXml.Drawing.Outline outline, PPTSlide slide,string Shapetype) {
|
|
|
Border border = new Border() {color= new Fill { type=-1} };
|
|
|
//20.1.10.35 EMUs. 1 pt = 12700 EMUs.
|
|
|
double? Width = null;
|
|
|
- if (outline.Width != null) {
|
|
|
- Width= double.Parse(outline.Width) * 1.0 / Globals.px12700 ;
|
|
|
+ if (outline.Width != null)
|
|
|
+ {
|
|
|
+ Width = double.Parse(outline.Width) * 1.0 * Globals.px96 / Globals.px914400;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (Shapetype == "CxnSp") {
|
|
|
+ Width = 0.75;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
// Center = 0,
|
|
|
// Insert = 1
|
|
@@ -179,64 +282,67 @@ namespace HTEXLib.Helpers.ShapeHelpers
|
|
|
cap = Convert.ToInt32(outline.CapType);
|
|
|
}
|
|
|
border.outline = new HtexOutline { Width = Width, algn = algn, cmpd = cmpd, cap = cap };
|
|
|
- var gradFill = outline.GetTextByPath("//a:gradFill");
|
|
|
+ var gradFill = outline.GetFirstChild<GradientFill>();
|
|
|
if (gradFill != null)
|
|
|
{
|
|
|
border.color.type = 2;
|
|
|
- border.color.gradientFill = DoGradientFill(new GradientFill(gradFill.ToString()), slide);
|
|
|
+ border.color.gradientFill = DoGradientFill(gradFill, slide);
|
|
|
}
|
|
|
- var noFill = outline.GetTextByPath("//a:noFill");
|
|
|
+ var noFill = outline.GetFirstChild<NoFill>();
|
|
|
if (noFill != null)
|
|
|
{
|
|
|
border.color.type = 0;
|
|
|
}
|
|
|
- var pattFill = outline.GetTextByPath("//a:pattFill");
|
|
|
+ var pattFill = outline.GetFirstChild<PatternFill>();
|
|
|
if (pattFill != null)
|
|
|
{
|
|
|
|
|
|
- DocumentFormat.OpenXml.Drawing.PatternFill patternFill = new PatternFill(pattFill.ToString());
|
|
|
- HtexPattFill htexPattFill = DoPattFill(patternFill, slide);
|
|
|
+ HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
|
|
|
border.color.type = 4;
|
|
|
border.color.pattFill = htexPattFill;
|
|
|
}
|
|
|
- var solidFill = outline.GetTextByPath("//a:solidFill");
|
|
|
+ var solidFill = outline.GetFirstChild<SolidFill>();
|
|
|
if (solidFill != null)
|
|
|
{
|
|
|
border.color.type = 1;
|
|
|
- border.color.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
|
|
|
+ border.color.solidFill = ReadSolidFillColors(solidFill, slide);
|
|
|
+ }
|
|
|
+ if (Width!=null && Width > 0) {
|
|
|
+ border.type = "solid";
|
|
|
+ border.stroke = "0";
|
|
|
}
|
|
|
- var prstDash= outline.GetTextByPath("//a:prstDash"); //预设连接符
|
|
|
+ var prstDash= outline.GetFirstChild<PresetDash>(); //预设连接符
|
|
|
if (prstDash != null) {
|
|
|
// PresetDash
|
|
|
var (type, stroke) = DoPrstDash(prstDash);
|
|
|
border.type = type;
|
|
|
border.stroke = stroke;
|
|
|
}
|
|
|
- if (outline.GetTextByPath("//a:bevel") != null) {
|
|
|
+ if (outline.GetFirstChild<Bevel>() != null) {
|
|
|
// 棱台切角
|
|
|
border.corner = "bevel";
|
|
|
}
|
|
|
- if (outline.GetTextByPath("//a:round")!=null) {
|
|
|
+ if (outline.GetFirstChild<Round>()!=null) {
|
|
|
//圆角
|
|
|
border.corner = "round";
|
|
|
}
|
|
|
- if (outline.GetTextByPath("//a:miter") != null) {
|
|
|
+ if (outline.GetFirstChild<Miter>() != null) {
|
|
|
//斜角
|
|
|
border.corner = "miter";
|
|
|
}
|
|
|
- var headEndNodeAttrs = outline.GetTextByPath("//a:headEnd"); //连接符开始符号
|
|
|
+ var headEndNodeAttrs = outline.GetFirstChild<HeadEnd>(); //连接符开始符号
|
|
|
if (headEndNodeAttrs != null)
|
|
|
{
|
|
|
- border.headEnd = headEndNodeAttrs != null ? headEndNodeAttrs.Attribute("type").Value : null;
|
|
|
+ border.headEnd = headEndNodeAttrs.Type;
|
|
|
}
|
|
|
- var tailEndNodeAttrs = outline.GetTextByPath("//a:tailEnd");//末端连接符
|
|
|
- if (headEndNodeAttrs != null)
|
|
|
+ var tailEndNodeAttrs = outline.GetFirstChild<TailEnd>();//末端连接符
|
|
|
+ if (tailEndNodeAttrs != null)
|
|
|
{
|
|
|
- border.tailEnd = tailEndNodeAttrs != null ? tailEndNodeAttrs.Attribute("type").Value : null;
|
|
|
+ border.tailEnd = tailEndNodeAttrs.Type;
|
|
|
}
|
|
|
//TODO
|
|
|
//outline.GetTextByPath("//a:extLst");
|
|
|
- XElement custDash = outline.GetTextByPath("//a:custDash");//自定义连接线
|
|
|
+ var custDash = outline.GetFirstChild<CustomDash>();//自定义连接线
|
|
|
if (custDash != null) {
|
|
|
var(type, stroke) = DoCustDash(custDash);
|
|
|
border.type = type;
|
|
@@ -249,7 +355,7 @@ namespace HTEXLib.Helpers.ShapeHelpers
|
|
|
/// </summary>
|
|
|
/// <param name="custDash"></param>
|
|
|
/// <returns></returns>
|
|
|
- public static (string type, string stroke) DoCustDash(XElement custDash) {
|
|
|
+ public static (string type, string stroke) DoCustDash(CustomDash custDash) {
|
|
|
string type = "cust";
|
|
|
string stroke = "";
|
|
|
IEnumerable<XElement> elements= custDash.GetTextByPathList("ds");
|
|
@@ -278,13 +384,13 @@ namespace HTEXLib.Helpers.ShapeHelpers
|
|
|
/// </summary>
|
|
|
/// <param name="presetDash"></param>
|
|
|
/// <returns></returns>
|
|
|
- public static (string type, string stroke) DoPrstDash(XElement presetDash)
|
|
|
+ public static (string type, string stroke) DoPrstDash(PresetDash presetDash)
|
|
|
{
|
|
|
Border border = new Border();
|
|
|
string type = "solid";
|
|
|
string stroke = "0";
|
|
|
//PresetLineDashValues 枚举
|
|
|
- string val = presetDash.Attribute("val").Value;
|
|
|
+ string val = presetDash.Val;
|
|
|
switch (val)
|
|
|
{
|
|
|
case "solid":
|
|
@@ -371,17 +477,24 @@ namespace HTEXLib.Helpers.ShapeHelpers
|
|
|
///HorizontalAndVertical 水平和垂直。
|
|
|
///Vertical 垂直
|
|
|
///None 无
|
|
|
- string name = Enum.GetName(typeof(TileFlipValues), GradientFill.Flip);
|
|
|
+ string name = "None";
|
|
|
+ if (GradientFill.Flip != null) {
|
|
|
+ name = GradientFill.Flip.Value.ToString();
|
|
|
+ }
|
|
|
gradientFill.flip = name;
|
|
|
List<ColorPosition> colors = new List<ColorPosition>();
|
|
|
- bool RotateWithShape = GradientFill.RotateWithShape;
|
|
|
+ bool RotateWithShape = true;
|
|
|
+ if (GradientFill.RotateWithShape != null)
|
|
|
+ {
|
|
|
+ RotateWithShape = GradientFill.RotateWithShape;
|
|
|
+ }
|
|
|
gradientFill.RotateWithShape = RotateWithShape;
|
|
|
foreach (GradientStop gradientStop in GradientFill.GradientStopList)
|
|
|
{
|
|
|
colors.Add(new ColorPosition
|
|
|
{
|
|
|
Color = ColorTypeColors(gradientStop, slide),
|
|
|
- Position = gradientStop.Position/// 位置,色带的位置 百分比0-100
|
|
|
+ Position = gradientStop.Position *1.0/ 1000 /// 位置,色带的位置 百分比0-100
|
|
|
});
|
|
|
}
|
|
|
gradientFill.colors = colors;
|
|
@@ -712,6 +825,9 @@ namespace HTEXLib.Helpers.ShapeHelpers
|
|
|
}
|
|
|
public static string ReadThemeSchemeColor(SchemeColor schemeColor, PPTSlide slide)
|
|
|
{
|
|
|
+ var light1Color1= slide.SlideLayoutPart.SlideMasterPart.
|
|
|
+ ThemePart;
|
|
|
+
|
|
|
string FontColor = "";
|
|
|
if (schemeColor.Val == "bg1")
|
|
|
{
|
|
@@ -783,7 +899,9 @@ namespace HTEXLib.Helpers.ShapeHelpers
|
|
|
FontColor = "#" + folHyperLink.RgbColorModelHex.Val.Value;
|
|
|
}
|
|
|
}
|
|
|
- FontColor= ReadAccentSchemeColors(schemeColor,slide);
|
|
|
+ if (string.IsNullOrEmpty(FontColor)) {
|
|
|
+ FontColor = ReadAccentSchemeColors(schemeColor, slide);
|
|
|
+ }
|
|
|
return FontColor;
|
|
|
}
|
|
|
|