HtexConnectionShape.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using DocumentFormat.OpenXml.Drawing;
  2. using HTEXLib.Helpers.ShapeHelpers;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace HTEXLib.Models.HTEX
  7. {
  8. public class HtexConnectionShape : HtexElement
  9. {
  10. public Inner.PPTConnectionShape connectionShape { get; set; }
  11. public HtexConnectionShape(string id, double rot, double width, double height,
  12. double top, double left, bool invisible, bool animatable, int index, Inner.PPTConnectionShape connectionShape, PPTSlide slide, string partForm)
  13. {
  14. base.slide = slide;
  15. this.rot = rot;
  16. this.connectionShape = connectionShape;
  17. base.id = id;
  18. base.top = top;
  19. base.left = left;
  20. base.width = width;
  21. base.height = height;
  22. base.invisible = invisible;
  23. base.animatable = animatable;
  24. base.index = index;
  25. base.type = "CxnSp";
  26. base.partForm = partForm;
  27. }
  28. public override List<Item> DrawElement()
  29. {
  30. //var xfrm = connectionShape.element.GetTextByPath("//p:spPr/a:xfrm");
  31. //var flipV = xfrm.Attribute("flipV");
  32. //var flipH = xfrm.Attribute("flipH");
  33. Position position = new Position { x = top, y = left, cx = width, cy = height, rot =rot};
  34. //if (flipV != null) {
  35. // position.flipV = int.Parse(flipV.Value);
  36. //}
  37. //if (flipH!= null)
  38. //{
  39. // position.flipH = int.Parse(flipH.Value);
  40. //}
  41. position.flipV = connectionShape.element.ShapeProperties.Transform2D.VerticalFlip!=null && connectionShape.element.ShapeProperties.Transform2D.VerticalFlip.Value?1:0;
  42. position.flipH = connectionShape.element.ShapeProperties.Transform2D.HorizontalFlip!=null && connectionShape.element.ShapeProperties.Transform2D.HorizontalFlip.Value ? 1 : 0;
  43. /*
  44. <xsd:enumeration value="none"/> 无
  45. <xsd:enumeration value="triangle"/> 三角形-▶
  46. <xsd:enumeration value="stealth"/> →
  47. <xsd:enumeration value="diamond"/> 菱形◆
  48. <xsd:enumeration value="oval"/> 圆点●
  49. <xsd:enumeration value="arrow"/> ->⇱
  50. */
  51. var shapeTypeNode = connectionShape.element.ShapeProperties.GetFirstChild<PresetGeometry>();
  52. var shapeType= shapeTypeNode.Preset.InnerText;
  53. var otl = connectionShape.element.ShapeProperties.GetFirstChild<Outline>();
  54. var shapeBorder = PPTXHelper.DoOutline(otl, slide,type);
  55. //从ShapeProperties 获取 p:spPr
  56. //再从 ShapeStyle 获取 p:spPr
  57. if (shapeBorder.color == null|| shapeBorder.color.type==-1) {
  58. SlideColor slideColor = PPTXHelper.DoShapeStyle(connectionShape.element.ShapeStyle, slide,type);
  59. if (slideColor != null) {
  60. shapeBorder.color.solidFill = slideColor.LineColor;
  61. shapeBorder.color.type = 2;
  62. }
  63. }
  64. Svg svg = PPTXSvg.GenShapeSvg(connectionShape.element, index, shapeType, position, shapeBorder);
  65. // position = position ,mediaType = "image",type = type,index = index,animatable = animatable ,invisible = invisible
  66. Item item= new Connector { position = position,type=type,cxnType=shapeType, invisible = invisible, animatable = animatable, index = index, id = id, svg = svg, border = shapeBorder };
  67. return new List<Item>() { item };
  68. }
  69. }
  70. }