HtexImage.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using DocumentFormat.OpenXml.Drawing;
  2. using HTEXLib.Helpers.ShapeHelpers;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. namespace HTEXLib.Models.HTEX
  8. {
  9. public class HtexImage : HtexElement
  10. {
  11. public string HyperLink { get; set; }
  12. public string FileExtension { get; set; }
  13. public HtexImage(string id, double rot, double width, double height,
  14. double top, double left, bool invisible,
  15. bool animatable, string extension,int index, Inner.PPTImage image, PPTSlide slide, string partForm)
  16. {
  17. base.slide = slide;
  18. this.rot = rot;
  19. this.image = image;
  20. base.id = id;
  21. base.top = top;
  22. base.left = left;
  23. base.width = width;
  24. base.height = height;
  25. base.invisible = invisible;
  26. base.animatable = animatable;
  27. this.FileExtension = extension;
  28. base.index = index;
  29. base.type = "Media";
  30. base.partForm = partForm;
  31. }
  32. public Inner.PPTImage image { get; set; }
  33. public override List<Item> DrawElement()
  34. {
  35. Position position = new Position { cx = width, cy = height, x = left, y = top, rot = rot };
  36. var ShapeStyle = PPTXHelper.DoShapeProperties(image.element.ShapeProperties, slide,type,partForm);
  37. Media media = new Media() { position = position ,mediaType= "image",type=type,index=index,animatable=animatable ,invisible=invisible};
  38. /*
  39. * cNvPicPr (非可视图片绘图属性) §19.3.1.11
  40. cNvPr (非可视绘图属性) §19.3.1.12
  41. nvPr (非可视属性) §19.3.1.33
  42. */
  43. var WaveAudioFile = image.element.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.GetFirstChild<WaveAudioFile>();
  44. var AudioFromFile = image.element.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.GetFirstChild<AudioFromFile>();
  45. var VideoFromFile = image.element.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.GetFirstChild<VideoFromFile>();
  46. if (WaveAudioFile != null) {
  47. }
  48. if (AudioFromFile != null) {
  49. string url = AudioFromFile.Link;
  50. var part = slide.SlidePart.DataPartReferenceRelationships.Where(x => x.Id == url).FirstOrDefault();
  51. if (part != null) {
  52. url = part.Uri.ToString().Replace("../", "/ppt/");
  53. HtexBlipFill file = new HtexBlipFill { url = url, urlType = "link" };
  54. var thumbnail = slide.Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
  55. if (thumbnail != null) {
  56. var contentType = thumbnail.Attribute("{http://schemas.microsoft.com/office/2006/xmlPackage}contentType").Value;
  57. file.contentType = contentType;
  58. }
  59. media.file = file;
  60. }
  61. }
  62. if (VideoFromFile != null) {
  63. string url = VideoFromFile.Link;
  64. var part = slide.SlidePart.DataPartReferenceRelationships.Where(x => x.Id == url).FirstOrDefault();
  65. if (part != null)
  66. {
  67. url = part.Uri.ToString().Replace("../", "/ppt/");
  68. HtexBlipFill file = new HtexBlipFill { url = url, urlType = "link" };
  69. var thumbnail = slide.Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
  70. if (thumbnail != null)
  71. {
  72. var contentType = thumbnail.Attribute("{http://schemas.microsoft.com/office/2006/xmlPackage}contentType").Value;
  73. file.contentType = contentType;
  74. }
  75. media.file = file;
  76. }
  77. }
  78. SlideColor slideColor = PPTXHelper.DoShapeStyle(image.element.ShapeStyle, slide,type);
  79. //从ShapeProperties 获取 p:spPr
  80. //再从 ShapeStyle 获取 p:spPr
  81. if (ShapeStyle.border == null || ShapeStyle.border.color == null || ShapeStyle.border.color.type == -1)
  82. {
  83. if (slideColor != null)
  84. {
  85. media.border.color.solidFill = slideColor.LineColor;
  86. media.border.color.type = 2;
  87. }
  88. }
  89. else
  90. {
  91. media.border = ShapeStyle.border;
  92. }
  93. if (ShapeStyle.fill == null || ShapeStyle.fill.type == -1)
  94. {
  95. if (slideColor != null)
  96. {
  97. media.fill.solidFill = slideColor.FillColor;
  98. media.fill.type = 2;
  99. }
  100. }
  101. else
  102. {
  103. media.fill = ShapeStyle.fill;
  104. }
  105. HtexBlipFill htexBlipFill = PPTXHelper.DoBlipFill(image.element.BlipFill, slide,partForm);
  106. media.image = htexBlipFill;
  107. //TODO 处理公式图片
  108. return new List<Item>() { media };
  109. }
  110. }
  111. }