123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using DocumentFormat.OpenXml.Drawing;
- using HTEXLib.Helpers.ShapeHelpers;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace HTEXLib.Models.HTEX
- {
- public class HtexImage : HtexElement
- {
- public string HyperLink { get; set; }
- public string FileExtension { get; set; }
- public HtexImage(string id, double rot, double width, double height,
- double top, double left, bool invisible,
- bool animatable, string extension,int index, Inner.PPTImage image, PPTSlide slide, string partForm, string timingId)
- {
- base.sid = timingId;
- base.slide = slide;
- this.rot = rot;
- this.image = image;
- base.id = id;
- base.top = top;
- base.left = left;
- base.width = width;
- base.height = height;
- base.invisible = invisible;
- base.animatable = animatable;
- this.FileExtension = extension;
- base.index = index;
- base.type = "Media";
- base.partForm = partForm;
- }
- public Inner.PPTImage image { get; set; }
- public override List<Item> DrawElement()
- {
- Position position = new Position { cx = width, cy = height, x = left, y = top, rot = rot };
- var ShapeStyle = PPTXHelper.DoShapeProperties(image.element.ShapeProperties, slide,type,partForm);
- Media media = new Media() { sid = sid, id = this.id, mediaType = "image",type=type,index=index/*,animatable=animatable ,invisible=invisible*/};
- media.style.position = position;
- media.style.effect = ShapeStyle.effect;
- /*
- * cNvPicPr (非可视图片绘图属性) §19.3.1.11
- cNvPr (非可视绘图属性) §19.3.1.12
- nvPr (非可视属性) §19.3.1.33
- */
- var WaveAudioFile = image.element.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.GetFirstChild<WaveAudioFile>();
- var AudioFromFile = image.element.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.GetFirstChild<AudioFromFile>();
- var VideoFromFile = image.element.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.GetFirstChild<VideoFromFile>();
- if (WaveAudioFile != null) {
-
- }
- if (AudioFromFile != null) {
- string url = AudioFromFile.Link;
- var part = slide.SlidePart.DataPartReferenceRelationships.Where(x => x.Id == url).FirstOrDefault();
- if (part != null) {
- url = part.Uri.ToString().Replace("../", "/ppt/");
- HtexBlipFill file = new HtexBlipFill { url = url };
- 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;
- //file.contentType = contentType;
- }
- media.mediaType = "audio";
- media.file = file;
- }
- }
- if (VideoFromFile != null) {
- string url = VideoFromFile.Link;
- var part = slide.SlidePart.DataPartReferenceRelationships.Where(x => x.Id == url).FirstOrDefault();
- if (part != null)
- {
- url = part.Uri.ToString().Replace("../", "/ppt/");
- HtexBlipFill file = new HtexBlipFill { url = url };
- 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;
- // file.contentType = contentType;
- }
- media.mediaType = "video";
- media.file = file;
- }
- }
- SlideColor slideColor = PPTXHelper.DoShapeStyle(image.element.ShapeStyle, slide,type);
- //从ShapeProperties 获取 p:spPr
- //再从 ShapeStyle 获取 p:spPr
- if (ShapeStyle.border == null || ShapeStyle.border.color == null || ShapeStyle.border.color.type == -1)
- {
- if (slideColor != null)
- {
- media.style.border.color.solidFill = slideColor.LineColor;
- media.style.border.color.type = 2;
- }
- }
- else
- {
- media.style.border = ShapeStyle.border;
- }
- if (ShapeStyle.fill == null || ShapeStyle.fill.type == -1)
- {
- if (slideColor != null)
- {
- media.style.fill.solidFill = slideColor.FillColor;
- media.style.fill.type = 2;
- }
- }
- else
- {
- media.style.fill = ShapeStyle.fill;
- }
- HtexBlipFill htexBlipFill = PPTXHelper.DoBlipFill(image.element.BlipFill, slide,partForm);
- media.image = htexBlipFill;
- media.uid = image.suid;
- if (media.style.fill.type == -1|| media.style.fill.type == 0) {
- media.style.fill = null;
- }
- if (media.style.border != null && (media.style.border.color.type == -1|| media.style.border.color.type == 0))
- {
- media.style.border.color = null;
- }
- if (media.style.border != null && media.style.border.type == "none")
- {
- media.style.border = null;
- }
- //TODO 处理公式图片
- return new List<Item>() { media };
- }
- }
- }
|