HtexImage.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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() { mediaType= "image",type=type,index=index,animatable=animatable ,invisible=invisible};
  38. media.style.position = position;
  39. /*
  40. * cNvPicPr (非可视图片绘图属性) §19.3.1.11
  41. cNvPr (非可视绘图属性) §19.3.1.12
  42. nvPr (非可视属性) §19.3.1.33
  43. */
  44. var WaveAudioFile = image.element.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.GetFirstChild<WaveAudioFile>();
  45. var AudioFromFile = image.element.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.GetFirstChild<AudioFromFile>();
  46. var VideoFromFile = image.element.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.GetFirstChild<VideoFromFile>();
  47. if (WaveAudioFile != null) {
  48. }
  49. if (AudioFromFile != null) {
  50. string url = AudioFromFile.Link;
  51. var part = slide.SlidePart.DataPartReferenceRelationships.Where(x => x.Id == url).FirstOrDefault();
  52. if (part != null) {
  53. url = part.Uri.ToString().Replace("../", "/ppt/");
  54. HtexBlipFill file = new HtexBlipFill { url = url };
  55. var thumbnail = slide.Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
  56. if (thumbnail != null) {
  57. var contentType = thumbnail.Attribute("{http://schemas.microsoft.com/office/2006/xmlPackage}contentType").Value;
  58. //file.contentType = contentType;
  59. }
  60. media.file = file;
  61. }
  62. }
  63. if (VideoFromFile != null) {
  64. string url = VideoFromFile.Link;
  65. var part = slide.SlidePart.DataPartReferenceRelationships.Where(x => x.Id == url).FirstOrDefault();
  66. if (part != null)
  67. {
  68. url = part.Uri.ToString().Replace("../", "/ppt/");
  69. HtexBlipFill file = new HtexBlipFill { url = url };
  70. var thumbnail = slide.Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
  71. if (thumbnail != null)
  72. {
  73. var contentType = thumbnail.Attribute("{http://schemas.microsoft.com/office/2006/xmlPackage}contentType").Value;
  74. // file.contentType = contentType;
  75. }
  76. media.file = file;
  77. }
  78. }
  79. SlideColor slideColor = PPTXHelper.DoShapeStyle(image.element.ShapeStyle, slide,type);
  80. //从ShapeProperties 获取 p:spPr
  81. //再从 ShapeStyle 获取 p:spPr
  82. if (ShapeStyle.border == null || ShapeStyle.border.color == null || ShapeStyle.border.color.type == -1)
  83. {
  84. if (slideColor != null)
  85. {
  86. media.style.border.color.solidFill = slideColor.LineColor;
  87. media.style.border.color.type = 2;
  88. }
  89. }
  90. else
  91. {
  92. media.style.border = ShapeStyle.border;
  93. }
  94. if (ShapeStyle.fill == null || ShapeStyle.fill.type == -1)
  95. {
  96. if (slideColor != null)
  97. {
  98. media.style.fill.solidFill = slideColor.FillColor;
  99. media.style.fill.type = 2;
  100. }
  101. }
  102. else
  103. {
  104. media.style.fill = ShapeStyle.fill;
  105. }
  106. HtexBlipFill htexBlipFill = PPTXHelper.DoBlipFill(image.element.BlipFill, slide,partForm);
  107. media.image = htexBlipFill;
  108. //TODO 处理公式图片
  109. return new List<Item>() { media };
  110. }
  111. }
  112. }