HtexConnectionShape.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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, string timingId)
  13. {
  14. base.sid = timingId;
  15. base.slide = slide;
  16. this.rot = rot;
  17. this.connectionShape = connectionShape;
  18. base.id = id;
  19. base.top = top;
  20. base.left = left;
  21. base.width = width;
  22. base.height = height;
  23. base.invisible = invisible;
  24. base.animatable = animatable;
  25. base.index = index;
  26. base.type = "CxnSp";
  27. base.partForm = partForm;
  28. }
  29. public override List<Item> DrawElement()
  30. {
  31. //var xfrm = connectionShape.element.GetTextByPath("//p:spPr/a:xfrm");
  32. //var flipV = xfrm.Attribute("flipV");
  33. //var flipH = xfrm.Attribute("flipH");
  34. Position position = new Position { x = top, y = left, cx = width, cy = height, rot =rot};
  35. //if (flipV != null) {
  36. // position.flipV = int.Parse(flipV.Value);
  37. //}
  38. //if (flipH!= null)
  39. //{
  40. // position.flipH = int.Parse(flipH.Value);
  41. //}
  42. position.flipV = connectionShape.element.ShapeProperties.Transform2D.VerticalFlip!=null && connectionShape.element.ShapeProperties.Transform2D.VerticalFlip.Value?1:0;
  43. position.flipH = connectionShape.element.ShapeProperties.Transform2D.HorizontalFlip!=null && connectionShape.element.ShapeProperties.Transform2D.HorizontalFlip.Value ? 1 : 0;
  44. /*
  45. <xsd:enumeration value="none"/> 无
  46. <xsd:enumeration value="triangle"/> 三角形-▶
  47. <xsd:enumeration value="stealth"/> →
  48. <xsd:enumeration value="diamond"/> 菱形◆
  49. <xsd:enumeration value="oval"/> 圆点●
  50. <xsd:enumeration value="arrow"/> ->⇱
  51. */
  52. var shapeTypeNode = connectionShape.element.ShapeProperties.GetFirstChild<PresetGeometry>();
  53. var shapeType= shapeTypeNode.Preset.InnerText;
  54. var otl = connectionShape.element.ShapeProperties.GetFirstChild<Outline>();
  55. var shapeBorder = PPTXHelper.DoOutline(otl, slide,type);
  56. //从ShapeProperties 获取 p:spPr
  57. //再从 ShapeStyle 获取 p:spPr
  58. if (shapeBorder.color == null|| shapeBorder.color.type == null || shapeBorder.color.type == -1) {
  59. SlideColor slideColor = PPTXHelper.DoShapeStyle(connectionShape.element.ShapeStyle, slide,type);
  60. if (slideColor != null) {
  61. shapeBorder.color.solidFill = slideColor.LineColor;
  62. shapeBorder.color.type = 2;
  63. }
  64. }
  65. Svg svg = PPTXSvg.GenShapeSvg(connectionShape.element, index, shapeType, position, shapeBorder);
  66. // position = position ,mediaType = "image",type = type,index = index,animatable = animatable ,invisible = invisible
  67. Connector item = new Connector { sid =sid, type =type,cxnType=shapeType, invisible = invisible, animatable = animatable, index = index, id = id, svg = svg };
  68. item.style.position = position;
  69. item.style.border = shapeBorder;
  70. item.uid = connectionShape.suid;
  71. return new List<Item>() { item };
  72. }
  73. }
  74. }