1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174 |
- using DocumentFormat.OpenXml.Packaging;
- using HiTeachCC.Model.PowerPoint;
- using HiTeachCC.Service.PowerPoint.Interface;
- using Microsoft.AspNetCore.Http;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml;
- using System.Xml.Linq;
- using TEAMModelOS.SDK.Context.Constant;
- using TEAMModelOS.SDK.Context.Constant.Common;
- using TEAMModelOS.SDK.Context.Exception;
- using TEAMModelOS.SDK.Helper.Security.ShaHash;
- using TEAMModelOS.SDK.Module.AzureBlob.Container;
- using TEAMModelOS.SDK.Module.AzureBlob.Interfaces;
- using TEAMModelOS.Service.Models.PowerPoint.Inner;
- using TEAMModelOS.Service.Services.PowerPoint.Implement;
- using Fill = HiTeachCC.Model.PowerPoint.Fill;
- using Media = HiTeachCC.Model.PowerPoint.Media;
- using Position = HiTeachCC.Model.PowerPoint.Position;
- namespace HiTeachCC.Service.PowerPoint.Implement
- {
- public class ShapeGenerator : IShapeGenerator
- {
-
- private string fileShaCode { get; set; }
- private bool isDone = false;
- private List<object> MsgQueue = new List<object>();
- private Dictionary<string, string> slideLayoutClrOvride { get; set; }
- // private XmlNode themeContent { get; set; }
- private int chartID = 0;
- private int _order = 1;
- private int titleFontSize = 42;
- private int bodyFontSize = 20;
- private int otherFontSize = 16;
- private bool isSlideMode = false;
- private Dictionary<string, Dictionary<string, string>> styleTable = new Dictionary<string, Dictionary<string, string>>();
- private const double px96 = 96.00, px72 = 72.00, px914400 = 914400.00, px12700 = 12700.00;
- private const double rot60000 = 60000.00;
- public readonly IAzureBlobDBRepository azureBlobDBRepository;
- public ShapeGenerator(IAzureBlobDBRepository _azureBlobDBRepository)
- {
- azureBlobDBRepository = _azureBlobDBRepository;
- }
- public async Task<Dictionary<string, object>> LoadPresentation(IFormFile file)
- {
- Dictionary<string, object> resdict = new Dictionary<string, object>();
- if (FileType.GetExtention(file.FileName).ToLower().Equals("pptx"))
- {
- await ConvertPPTX(file, resdict);
- return resdict;
- }
- else if (FileType.GetExtention(file.FileName).ToLower().Equals("pdf"))
- {
- // await ProcessPDF(file, resdict);
- return resdict;
- }
- else
- {
- throw new BizException("file type does not support!", 500);
- }
- }
- public async Task<Dictionary<string, object>> ConvertPPTX(IFormFile file, Dictionary<string, object> resdict)
- {
- string shaCode = fileShaCode = ShaHashHelper.GetSHA1(file.OpenReadStream());
- PresentationDocument presentationDocument = PresentationDocument.Open(file.OpenReadStream(), false);
- if (presentationDocument == null)
- {
- throw new ArgumentNullException("presentationDocument");
- }
- XDocument xdoc = presentationDocument.ToFlatOpcDocument();
- XmlDocument xmlDocument = new XmlDocument();
- xmlDocument.LoadXml(xdoc.ToString());
- var rslt_ary = await ProcessPPTX(xmlDocument, shaCode);
- //TODO
- return null;
- }
- /// <summary>
- /// 加载PPTX文件
- /// </summary>
- /// <param name="presentationFile"></param>
- /// <returns></returns>
- public async Task<List<Dictionary<string, object>>> ProcessPPTX(XmlDocument xdoc, string shaCode)
- {
- List<Dictionary<string, object>> post_ary = new List<Dictionary<string, object>>();
- var dateBefore = DateTimeOffset.Now.UtcTicks;
- AzureBlobModel thumbnailModel = await GetThumbnailModel(xdoc, shaCode);
- post_ary.Add(new Dictionary<string, object> { { "pptx-thumb", thumbnailModel } });
- //获取全部的/ppt/slides/slide1.xml--->>/ppt/slides/slide(n).xml
- var slideNodes = xdoc.GetTextByPathList("//pkg:part[@pkg:contentType='application/vnd.openxmlformats-officedocument.presentationml.slide+xml']");
- //获取全部的/ppt/slideLayouts/slideLayout1.xml--->>/ppt/slideLayouts/slideLayout(n).xml
- var slideLayoutNodes = xdoc.GetTextByPathList("//pkg:part[@pkg:contentType='application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml']");
- //获取ppt的宽高
- var slideSize = ShapeHelper.GetSlideSize(xdoc);
- post_ary.Add(new Dictionary<string, object> { { "slideSize", slideSize } });
- //加载当前PPT使用到的PPT节点
- var themeContent = LoadTheme(xdoc);
- //获取所有的表格样式节点
- var tableStyles = xdoc.GetTextByPath("//pkg:part[@pkg:name='/ppt/tableStyles.xml']/pkg:xmlData/a:tblStyleLst");
- //处理slide1---slide(n)
- int numOfSlides = slideNodes.Count;
- for (int i = 0; i < numOfSlides; i++)
- {
- string filename = slideNodes[i].GetTextByPath("@pkg:name").Value;
- //处理当前页的幻灯片
- string slideHtml = await ProcessSingleSlide(xdoc, slideNodes[i], filename, i, slideSize, themeContent);
- post_ary.Add(new Dictionary<string, object> { { "slide", slideHtml } });
- post_ary.Add(new Dictionary<string, object> { { "progress-update", (i + 1) * 100 / numOfSlides } });
- }
- post_ary.Add(new Dictionary<string, object> { { "globalCSS", GenGlobalCSS() } });
- var dateAfter = DateTimeOffset.Now.UtcTicks;
- post_ary.Add(new Dictionary<string, object> { { "ExecutionTime", dateAfter - dateBefore } });
- return post_ary;
- }
- public Dictionary<string, string> GenGlobalCSS()
- {
- Dictionary<string, string> cssText = new Dictionary<string, string>();
- foreach (var key in styleTable.Keys)
- {
- // cssText += "div ." + styleTable[key]["name"] + "{" + styleTable[key]["text"] + "}\n"; //section > div
- var cssTextKey = styleTable[key]["name"];
- var cssTextValue = styleTable[key]["text"];
- cssText.Add(cssTextKey, cssTextValue);
- }
- return cssText;
- }
- public async Task<string> ProcessSingleSlide(XmlDocument xdoc, XmlNode xnode, string sldFileName, int index, dynamic slideSize, XmlNode themeContent)
- {
- var resName = sldFileName.Replace("slides/slide", "slides/_rels/slide") + ".rels";
- var RelationshipArray = xdoc.GetTextByPathList("//pkg:part[@pkg:name='" + resName + "']/pkg:xmlData/rel:Relationships/rel:Relationship");
- Dictionary<string, Dictionary<string, string>> slideResObj = new Dictionary<string, Dictionary<string, string>>();
- var layoutFilename = "";
- foreach (XmlNode Relationship in RelationshipArray)
- {
- var RelationshipType = Relationship.GetTextByPath("@Type");
- if (RelationshipType.Value.Equals("http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout"))
- {
- layoutFilename = Relationship.GetTextByPath("@Target").Value.Replace("../", "/ppt/");
- }
- else
- {
- //case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide":
- //case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image":
- //case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart":
- //case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink":
- Dictionary<string, string> dict = new Dictionary<string, string>();
- string Type = Relationship.GetTextByPath("@Type").Value.Replace("http://schemas.openxmlformats.org/officeDocument/2006/relationships/", "");
- string Target = Relationship.GetTextByPath("@Target").Value.Replace("../", "/ppt/");
- string Id = Relationship.GetTextByPath("@Id").Value;
- dict.Add("type", Type);
- dict.Add("target", Target);
- slideResObj.Add(Id, dict);
- }
- }
- // Open slideLayoutXX.xml
- var slideLayoutContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + layoutFilename + "']");
- NodesTable slideLayoutTables = ShapeHelper.IndexNodes(slideLayoutContent.GetTextByPath("pkg:xmlData/p:sldLayout"));
- ///ppt/slides/slide5.xml 也包含a:overrideClrMapping
- ////ppt/slideLayouts/slideLayout13.xml 也包含a:overrideClrMapping
- var sldLayoutClrOvr = slideLayoutContent.GetTextByPath("pkg:xmlData/p:sldLayout/p:clrMapOvr/a:overrideClrMapping");
- if (sldLayoutClrOvr != null)
- {
- //获取 overrideClrMapping所有属性节点
- slideLayoutClrOvride = new Dictionary<string, string>() {
- { "accent1", sldLayoutClrOvr.GetTextByPath("@accent1").Value},
- { "accent2", sldLayoutClrOvr.GetTextByPath("@accent2").Value},
- { "accent3", sldLayoutClrOvr.GetTextByPath("@accent3").Value},
- { "accent4", sldLayoutClrOvr.GetTextByPath("@accent4").Value},
- { "accent5", sldLayoutClrOvr.GetTextByPath("@accent5").Value},
- { "accent6", sldLayoutClrOvr.GetTextByPath("@accent6").Value},
- { "bg1", sldLayoutClrOvr.GetTextByPath("@bg1").Value},
- { "bg2", sldLayoutClrOvr.GetTextByPath("@bg2").Value},
- { "folHlink", sldLayoutClrOvr.GetTextByPath("@folHlink").Value},
- { "hlink", sldLayoutClrOvr.GetTextByPath("@hlink").Value},
- { "tx1", sldLayoutClrOvr.GetTextByPath("@tx1").Value},
- { "tx2", sldLayoutClrOvr.GetTextByPath("@tx2").Value}
- };
- }
- // =====< Step 2 >=====
- // Read slide master filename of the slidelayout (Get slideMasterXX.xml)
- // @resName: ppt/slideLayouts/slideLayout1.xml
- // @masterName: ppt/slideLayouts/_rels/slideLayout1.xml.rels
- var slideLayoutResFilename = layoutFilename.Replace("slideLayouts/slideLayout", "slideLayouts/_rels/slideLayout") + ".rels";
- var slideLayoutResContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + slideLayoutResFilename + "']");
- ///查看js 是替换之前 还是添加
- RelationshipArray = slideLayoutResContent.GetTextByPathList("pkg:xmlData/rel:Relationships/rel:Relationship");
- var masterFilename = "";
- Dictionary<string, Dictionary<string, string>> layoutResObj = new Dictionary<string, Dictionary<string, string>>();
- for (int i = 0; i < RelationshipArray.Count; i++)
- {
- if (RelationshipArray[i].GetTextByPath("@Type").Value.Equals("http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster"))
- {
- masterFilename = RelationshipArray[i].GetTextByPath("@Target").Value.Replace("../", "/ppt/");
- }
- else
- {
- Dictionary<string, string> dict = new Dictionary<string, string>();
- string Type = RelationshipArray[i].GetTextByPath("@Type").Value.Replace("http://schemas.openxmlformats.org/officeDocument/2006/relationships/", "");
- string Target = RelationshipArray[i].GetTextByPath("@Target").Value.Replace("../", "/ppt/");
- string Id = RelationshipArray[i].GetTextByPath("@Id").Value;
- dict.Add("type", Type);
- dict.Add("target", Target);
- layoutResObj.Add(Id, dict);
- }
- }
- // Open slideMasterXX.xml
- var slideMasterContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + masterFilename + "']");
- var slideMasterTextStyles = slideMasterContent.GetTextByPath("pkg:xmlData/p:sldMaster/p:txStyles");
- var slideMasterTables = ShapeHelper.IndexNodes(slideMasterContent.GetTextByPath("pkg:xmlData/p:sldMaster"));
- /////////////////Amir/////////////
- //Open slideMasterXX.xml.rels
- var slideMasterResFilename = masterFilename.Replace("slideMasters/slideMaster", "slideMasters/_rels/slideMaster") + ".rels";
- var slideMasterResContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + slideMasterResFilename + "']");
- RelationshipArray = slideMasterResContent.GetTextByPathList("pkg:xmlData/rel:Relationships/rel:Relationship");
- var themeFilename = "";
- Dictionary<string, Dictionary<string, string>> masterResObj = new Dictionary<string, Dictionary<string, string>>();
- for (int i = 0; i < RelationshipArray.Count; i++)
- {
- if (RelationshipArray[i].GetTextByPath("@Type").Value.Equals("http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"))
- {
- themeFilename = RelationshipArray[i].GetTextByPath("@Target").Value.Replace("../", "/ppt/");
- }
- else
- {
- Dictionary<string, string> dict = new Dictionary<string, string>();
- string Type = RelationshipArray[i].GetTextByPath("@Type").Value.Replace("http://schemas.openxmlformats.org/officeDocument/2006/relationships/", "");
- string Target = RelationshipArray[i].GetTextByPath("@Target").Value.Replace("../", "/ppt/");
- string Id = RelationshipArray[i].GetTextByPath("@Id").Value;
- dict.Add("type", Type);
- dict.Add("target", Target);
- masterResObj.Add(Id, dict);
- }
- }
- //Load Theme file
- if (!string.IsNullOrEmpty(themeFilename))
- {
- themeContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + themeFilename + "']");
- }
- // =====< Step 3 >===== throw new NotImplementedException();
- var slideContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + sldFileName + "']");
- var spTreeNode = slideContent.GetTextByPath("pkg:xmlData/p:sld/p:cSld/p:spTree");
- WarpObj warpObj = new WarpObj
- {
- zip = xdoc,
- slideLayoutTables = slideLayoutTables,
- slideMasterTables = slideMasterTables,
- slideMasterTextStyles = slideMasterTextStyles,
- slideResObj = slideResObj,
- layoutResObj = layoutResObj,
- masterResObj = masterResObj,
- slideLayoutContent = slideLayoutContent,
- slideMasterContent = slideMasterContent,
- themeContent = themeContent
- };
- var bgColor = GetSlideBackgroundFill(slideContent, index, warpObj);
- string result = "<div class='slide' style='width:" + slideSize.width + "px; height:" + slideSize.height + "px;" + bgColor + "'>";
- //result += "<div>"+getBackgroundShapes(slideContent, slideLayoutContent, slideMasterContent,warpObj) + "</div>" - TODO
- if (spTreeNode != null)
- {
- var nodes = spTreeNode.ChildNodes;
- int order = 1;
- foreach (XmlNode node in nodes)
- {
- result += await ProcessNodesInSlide(node.Name, node, order, warpObj);
- order += 1;
- }
- }
- return result;
- }
- public async Task<string> ProcessNodesInSlide(string nodeKey, XmlNode node, int order, WarpObj warpObj)
- {
- string result = "";
- switch (nodeKey)
- {
- case "p:sp": // Shape, Text
- result = await ProcessSpNode(node, order, warpObj);
- break;
- case "p:cxnSp": // Shape, Text (with connection)
- result = await ProcessCxnSpNode(node, order, warpObj);
- break;
- case "p:pic": // Picture
- await ProcessPicNode(node, order, warpObj);
- break;
- case "p:graphicFrame": // Chart, Diagram, Table
- result = ProcessGraphicFrameNode(node, order, warpObj);
- break;
- case "p:grpSp":
- await ProcessGroupSpNode(node, order, warpObj);
- break;
- case "mc:AlternateContent": //Equations and formulas as Image 处理公式 方程等
- var mcFallbackNode = node.GetTextByPath("mc:Fallback/p:sp");
- result = await ProcessSpNode(mcFallbackNode, order, warpObj);
- break;
- default:
- break;
- }
- return result;
- }
- public async Task<string> ProcessGroupSpNode(XmlNode node, int order, WarpObj warpObj)
- {
- var factor = 1.00 * px96 / px914400;
- var xfrmNode = node.GetTextByPath("p:grpSpPr/a:xfrm");
- var x = int.Parse(xfrmNode.GetTextByPath("a:off/@x").Value) * factor;
- var y = int.Parse(xfrmNode.GetTextByPath("a:off/@y").Value) * factor;
- var chx = int.Parse(xfrmNode.GetTextByPath("a:chOff/@x").Value) * factor;
- var chy = int.Parse(xfrmNode.GetTextByPath("a:chOff/@y").Value) * factor;
- var cx = int.Parse(xfrmNode.GetTextByPath("a:ext/@cx").Value) * factor;
- var cy = int.Parse(xfrmNode.GetTextByPath("a:ext/@cy").Value) * factor;
- var chcx = int.Parse(xfrmNode.GetTextByPath("a:chExt/@cx").Value) * factor;
- var chcy = int.Parse(xfrmNode.GetTextByPath("a:chExt/@cy").Value) * factor;
- string result = "<div class='block group' style='z-index: " + order + "; top: " + (y - chy) + "px; left: " + (x - chx) + "px; width: " + (cx - chcx) + "px; height: " + (cy - chcy) + "px;'>";
- // Procsee all child nodes
- var nodes = node.ChildNodes;
- foreach (XmlNode nd in nodes)
- {
- result += await ProcessNodesInSlide(nd.Name, nd, order, warpObj);
- order += 1;
- }
- result += "</div>";
- return result;
- }
- public string ProcessGraphicFrameNode(XmlNode node, int order, WarpObj warpObj)
- {
- var result = "";
- var graphicTypeUri = node.GetTextByPath("a:graphic/a:graphicData/uri");
- if (graphicTypeUri != null)
- {
- switch (graphicTypeUri.Value)
- {
- case "http://schemas.openxmlformats.org/drawingml/2006/table":
- result = GenTable(node, warpObj);
- break;
- case "http://schemas.openxmlformats.org/drawingml/2006/chart":
- result = GenChart(node, warpObj);
- break;
- case "http://schemas.openxmlformats.org/drawingml/2006/diagram":
- result = GenDiagram(node, warpObj);
- break;
- default:
- break;
- }
- }
- return result;
- }
- public string GenDiagram(XmlNode node, WarpObj warpObj)
- {
- return "";
- }
- public string GenChart(XmlNode node, WarpObj warpObj)
- {
- return "";
- }
- public string GenTable(XmlNode node, WarpObj warpObj)
- {
- return "";
- }
- public async Task<string> ProcessCxnSpNode(XmlNode node, int order, WarpObj warpObj)
- {
- var id = node.GetTextByPath("p:nvCxnSpPr/p:cNvPr/@id");
- var name = node.GetTextByPath("p:nvCxnSpPr/p:cNvPr/@name");
- return await GenShape(node, null, null, id, name, null, null, order, warpObj);
- }
- public async Task<string> ProcessSpNode(XmlNode node, int order, WarpObj warpObj)
- {
- /*
- * 958 <xsd:complexType name="CT_GvmlShape">
- * 959 <xsd:sequence>
- * 960 <xsd:element name="nvSpPr" type="CT_GvmlShapeNonVisual" minOccurs="1" maxOccurs="1"/>
- * 961 <xsd:element name="spPr" type="CT_ShapeProperties" minOccurs="1" maxOccurs="1"/>
- * 962 <xsd:element name="txSp" type="CT_GvmlTextShape" minOccurs="0" maxOccurs="1"/>
- * 963 <xsd:element name="style" type="CT_ShapeStyle" minOccurs="0" maxOccurs="1"/>
- * 964 <xsd:element name="extLst" type="CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1"/>
- * 965 </xsd:sequence>
- * 966 </xsd:complexType>
- */
- var id = node.GetTextByPath("p:nvSpPr/p:cNvPr/@id");
- var name = node.GetTextByPath("p:nvSpPr/p:cNvPr/@name");
- var idx = node.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@idx");
- var type = node.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@type");
- XmlNode slideLayoutSpNode = ShapeHelper.GetNodesTable(id, idx, type, warpObj, "Layout");
- XmlNode slideMasterSpNode = ShapeHelper.GetNodesTable(id, idx, type, warpObj, "Master");
- if (type == null)
- {
- if (slideLayoutSpNode != null)
- {
- type = slideLayoutSpNode.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@type");
- }
- // type = slideLayoutSpNode.TryGetValue"p:nvSpPr", "p:nvPr", "p:ph", "attrs", "type"]);
- if (type == null)
- {
- if (slideMasterSpNode != null)
- {
- type = slideMasterSpNode.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@type");
- }
- // type = getTextByPathList(slideMasterSpNode, ["p:nvSpPr", "p:nvPr", "p:ph", "attrs", "type"]);
- }
- }
- string s = await GenShape(node, slideLayoutSpNode, slideMasterSpNode, id, name, idx, type, order, warpObj);
- return "";
- }
- public async Task<string> GenShape(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode id, XmlNode name, XmlNode idx, XmlNode type, int order, WarpObj warpObj)
- {
- var xfrmList = "p:spPr/a:xfrm";
- var slideXfrmNode = node.GetTextByPath(xfrmList);
- XmlNode slideLayoutXfrmNode = null;
- if (slideLayoutSpNode != null)
- {
- slideLayoutXfrmNode = slideLayoutSpNode.GetTextByPath(xfrmList);
- }
- XmlNode slideMasterXfrmNode = null;
- if (slideMasterSpNode != null)
- {
- slideMasterXfrmNode = slideMasterSpNode.GetTextByPath(xfrmList);
- }
- if (slideXfrmNode == null)
- {
- slideXfrmNode = slideLayoutXfrmNode;
- }
- if (slideXfrmNode == null)
- {
- slideXfrmNode = slideMasterXfrmNode;
- }
- var result = "";
- var shapeType = node.GetTextByPath("p:spPr/a:prstGeom/@prst");
- var custShapType = node.GetTextByPath("p:spPr/a:custGeom");
- var isFlipV = 0;
- var isFlipH = 0;
- if (slideXfrmNode.GetTextByPath("@flipV") != null && slideXfrmNode.GetTextByPath("@flipV").Value == "1")
- {// if ( getTextByPathList(slideXfrmNode, ["attrs", "flipV"]) === "1" || getTextByPathList(slideXfrmNode, ["attrs", "flipH"]) === "1")
- isFlipV = 1;
- }
- if (slideXfrmNode.GetTextByPath("@flipH") != null && slideXfrmNode.GetTextByPath("@flipH").Value == "1")
- {
- isFlipH = 1;
- }
- //rotate
- var rotate = ShapeHelper.AngleToDegrees(slideXfrmNode.GetTextByPath("@rot"));
- //console.log("rotate: "+rotate);
- double txtRotate;
- var txtXframeNode = node.GetTextByPath("p:txXfrm/@rot");
- if (txtXframeNode != null)
- {
- txtRotate = ShapeHelper.AngleToDegrees(txtXframeNode) + 90;
- }
- else
- {
- txtRotate = rotate;
- }
- Position position = ShapeHelper.GetPosition(slideXfrmNode, slideLayoutXfrmNode, slideMasterXfrmNode);
- position.Rot = rotate;
- position.FlipH = isFlipH;
- position.FlipV = isFlipV;
- var grndFillFlg = false;
- var imgFillFlg = false;
- var Fill = await GetShapeFill(node, warpObj);
- // Border Color
- var shapeBorder = ShapeHelper.GetBorder(node, true, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- var headEndNodeAttrs = node.GetTextByPath("p:spPr/a:ln/a:headEnd");
- var tailEndNodeAttrs = node.GetTextByPath("p:spPr/a:ln/a:tailEnd");
- StringBuilder svgPath = new StringBuilder("<svg class='drawing' _id='" + order + id + "' _idx='" + order + idx + "' _type='" + order + type + "' _name='" + order + name+ "'");
- svgPath.Append(" style='top:"+position.Y+"px;left:"+position.X+ "px;width:"+position.Cx+ "px;height"+position.Cy+"px;'");
- if (shapeType != null || custShapType != null)
- {
- //result += "<svg class='drawing' _id='" + id + "' _idx='" + idx + "' _type='" + type + "' _name='" + name +
- // "' style='" +
- // getPosition(slideXfrmNode, null, null) +
- // getSize(slideXfrmNode, null, null) +
- // " z-index: " + order + ";" +
- // "transform: rotate(" + rotate + "deg);" +
- // "'>";
- //result += "<defs>";
- // Fill Color
-
-
- var clrFillType = ShapeHelper.GetFillType(node.GetTextByPath("p:spPr"));
- /////////////////////////////////////////
- if (clrFillType == "GRADIENT_FILL")
- {
- grndFillFlg = true;
- var color_arry = Fill.gradColor;
- var angl = Fill.Rot;
- var svgGrdnt = ShapeHelper.GetSvgGradient(position.Cx, position.Cy, angl, color_arry, order, slideLayoutClrOvride, warpObj.themeContent);
- //fill="url(#linGrd)"
- Fill.SvgText = svgGrdnt;
- result += svgGrdnt;
- }
- else if (clrFillType == "PIC_FILL")
- {
- imgFillFlg = true;
- var svgBgImg = ShapeHelper.GetSvgImagePattern(Fill.Image, order);
- //fill="url(#imgPtrn)"
- //console.log(svgBgImg)
- Fill.SvgText = svgBgImg;
- result += svgBgImg;
- }
- else
- {
- if (clrFillType != null && clrFillType != "SOLID_FILL" && clrFillType != "PATTERN_FILL")
- {
- Fill.HtmlText = "none";
- }
- if (shapeType != null)
- {
- if (shapeType.Value == "arc" ||
- shapeType.Value == "bracketPair" ||
- shapeType.Value == "bracePair" ||
- shapeType.Value == "leftBracket" ||
- shapeType.Value == "leftBrace" ||
- shapeType.Value == "rightBrace" ||
- shapeType.Value == "rightBracket")
- { //Temp. solution - TODO
- Fill.HtmlText = "none";
- }
- }
- }
-
- // type: none, triangle, stealth, diamond, oval, arrow
- if ((headEndNodeAttrs != null && (headEndNodeAttrs.GetTextByPath("@type").Value == "triangle" || (headEndNodeAttrs.GetTextByPath("@type").Value == "arrow")) ||
- (tailEndNodeAttrs != null && (tailEndNodeAttrs.GetTextByPath("@type").Value == "triangle" || (tailEndNodeAttrs.GetTextByPath("@type").Value == "arrow")))))
- {
- var triangleMarker = "<marker id='markerTriangle_" + order + "' viewBox='0 0 10 10' refX='1' refY='5' markerWidth='5' markerHeight='5' stroke='" + shapeBorder.Color + "' fill='" + shapeBorder.Color +
- "' orient='auto-start-reverse' markerUnits='strokeWidth'><path d='M 0 0 L 10 5 L 0 10 z' /></marker>";
- result += triangleMarker;
- }
- result += "</defs>";
- }
- if (shapeType != null && custShapType == null) {
- result+= ShapeSvg.GenShapeSvg(node, order, shapeType, isFlipV, position, grndFillFlg, imgFillFlg, Fill, shapeBorder, headEndNodeAttrs, tailEndNodeAttrs);
- }
- return result;
- }
- /// <summary>
- /// 幻灯片 背景色填充
- /// </summary>
- /// <param name="slideContent"></param>
- /// <param name="slideLayoutContent"></param>
- /// <param name="slideMasterContent"></param>
- /// <param name="index"></param>
- /// <param name="warpObj"></param>
- /// <returns></returns>
- public async Task<Fill> GetSlideBackgroundFill(XmlNode slideContent, int index, WarpObj warpObj)
- {
- var bgPr = slideContent.GetTextByPath("p:sld/p:cSld/p:bg/p:bgPr");
- var bgRef = slideContent.GetTextByPath("p:sld/p:cSld/p:bg/p:bgRef");
- if (bgPr != null)
- {
- var bgFillTyp = ShapeHelper.GetFillType(bgPr);
- if (bgFillTyp == "SOLID_FILL")
- {
- var sldFill = bgPr.GetTextByPath("a:solidFill");
- var bgColor = ShapeHelper.GetSolidFill(sldFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- bgColor = PowerPointHelper.ColorToning(sldFill.OuterXml, bgColor);
- return new Fill { Type = 1, Color = bgColor };
- }
- else if (bgFillTyp == "GRADIENT_FILL")
- {
- return ShapeHelper.GetBgGradientFill(bgPr, null, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- else if (bgFillTyp == "PIC_FILL")
- {
- return await GetPicFill("slideBg", bgPr.GetTextByPath("a:blipFill"), warpObj);
- }
- }
- else if (bgRef != null)
- {
- string phClr = ShapeHelper.GetSolidFill(bgRef, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- phClr = PowerPointHelper.ColorToning(bgRef.OuterXml, phClr);
- var idx = bgRef.GetTextByPath("@idx");
- if (idx != null)
- {
- int value = int.Parse(idx.Value);
- if (value == 0 || value == 1000)
- {
- return new Fill { Type = 0 };
- //no background
- }
- else if (value > 0 && value < 1000)
- {
- //fillStyleLst in themeContent
- //themeContent["a:fmtScheme"]["a:fillStyleLst"]
- //bgcolor = "background: red;";
- }
- else if (value > 1000)
- {
- var trueIdx = value - 1000;
- var bgFillLst = warpObj.themeContent.GetTextByPath("a:theme/a:themeElements/a:fmtScheme/a:bgFillStyleLst");
- if (bgFillLst != null) {
- XmlNodeList nodeList = bgFillLst.ChildNodes;
- if (trueIdx < nodeList.Count) {
- string type= ShapeHelper.GetFillType(nodeList[trueIdx - 1]);
- if (type.Equals("SOLID_FILL"))
- {
- if (string.IsNullOrEmpty(phClr))
- {
- phClr = ShapeHelper.GetSolidFill(nodeList[trueIdx - 1], slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- phClr = PowerPointHelper.ColorToning(nodeList[trueIdx - 1].Value, phClr);
- return new Fill { Type = 1, Color = phClr };
- }
- else if (type.Equals("GRADIENT_FILL"))
- {
- return ShapeHelper.GetBgGradientFill(nodeList[trueIdx - 1], phClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- else if (type.Equals("PIC_FILL"))
- {
- return await GetPicFill("slideBg", nodeList[trueIdx - 1].GetTextByPath("a:blipFill"), warpObj);
- }
- else {
- return new Fill { Type = 0 };
- }
- }
- }
- }
- }
- //var node = bgRef.GetTextByPath("");
- //if (bgRef["a:srgbClr"] !== undefined)
- //{
- // phClr = getTextByPathList(bgRef,["a:srgbClr", "attrs", "val"]); //#...
- //}
- //else if (bgRef["a:schemeClr"] !== undefined)
- //{ //a:schemeClr
- // var schemeClr = getTextByPathList(bgRef,["a:schemeClr", "attrs", "val"]);
- // phClr = getSchemeColorFromTheme("a:" + schemeClr, slideMasterContent); //#...
- // //console.log("schemeClr",schemeClr,"phClr=",phClr)
- //}
- }
- else
- {
- bgPr =warpObj. slideLayoutContent.GetTextByPath("p:sldLayout/p:cSld/p:bg/p:bgPr");
- bgRef = warpObj. slideLayoutContent.GetTextByPath("p:sldLayout/p:cSld/p:bg/p:bgRef");
- if (bgPr != null)
- {
- var bgFillTyp = ShapeHelper.GetFillType(bgPr);
- if (bgFillTyp == "SOLID_FILL")
- {
- var sldFill = bgPr.GetTextByPath("a:solidFill");
- var bgColor = ShapeHelper.GetSolidFill(sldFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- bgColor = PowerPointHelper.ColorToning(sldFill.OuterXml, bgColor);
- return new Fill { Type = 1, Color = bgColor };
- }
- else if (bgFillTyp == "GRADIENT_FILL")
- {
- return ShapeHelper.GetBgGradientFill(bgPr, null, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- else if (bgFillTyp == "PIC_FILL")
- {
- return await GetPicFill("slideBg", bgPr.GetTextByPath("a:blipFill"), warpObj);
- }
- }
- else if (bgRef != null)
- {
- string phClr = ShapeHelper.GetSolidFill(bgRef, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- phClr = PowerPointHelper.ColorToning(bgRef.OuterXml, phClr);
- var idx = bgRef.GetTextByPath("@idx");
- if (idx != null)
- {
- int value = int.Parse(idx.Value);
- if (value == 0 || value == 1000)
- {
- return new Fill { Type = 0 };
- //no background
- }
- else if (value > 0 && value < 1000)
- {
- //fillStyleLst in themeContent
- //themeContent["a:fmtScheme"]["a:fillStyleLst"]
- //bgcolor = "background: red;";
- }
- else if (value > 1000)
- {
- var trueIdx = value - 1000;
- var bgFillLst = warpObj.themeContent.GetTextByPath("a:theme/a:themeElements/a:fmtScheme/a:bgFillStyleLst");
- if (bgFillLst != null)
- {
- XmlNodeList nodeList = bgFillLst.ChildNodes;
- if (trueIdx < nodeList.Count)
- {
- string type = ShapeHelper.GetFillType(nodeList[trueIdx - 1]);
- if (type.Equals("SOLID_FILL"))
- {
- if (string.IsNullOrEmpty(phClr))
- {
- phClr = ShapeHelper.GetSolidFill(nodeList[trueIdx - 1], slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- phClr = PowerPointHelper.ColorToning(nodeList[trueIdx - 1].Value, phClr);
- return new Fill { Type = 1, Color = phClr };
- }
- else if (type.Equals("GRADIENT_FILL"))
- {
- return ShapeHelper.GetBgGradientFill(nodeList[trueIdx - 1], phClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- else if (type.Equals("PIC_FILL"))
- {
- return await GetPicFill("slideBg", nodeList[trueIdx - 1].GetTextByPath("a:blipFill"), warpObj);
- }
- else
- {
- return new Fill { Type = 0 };
- }
- }
- }
- }
- }
- }
- }
- return null;
- }
- public async Task<Fill> GetPicFill(string type, XmlNode node, WarpObj warpObj)
- {
- //Need to test/////////////////////////////////////////////
- //rId
- //TODO - Image Properties - Tile, Stretch, or Display Portion of Image
- //(http://officeopenxml.com/drwPic-tile.php)
- // var img = "";
- var rId = node.GetTextByPath("a:blip/@r:embed");//node["a:blip"]["attrs"]["r:embed"];
- Dictionary<string, string> imgPath = new Dictionary<string, string>();
- if (type == "slideBg")
- {
- imgPath = warpObj.slideResObj[rId.Value];
- }
- else if (type == "layoutBg")
- {
- imgPath = warpObj.layoutResObj[rId.Value];
- }
- else if (type == "masterBg")
- {
- imgPath = warpObj.masterResObj[rId.Value];
- }
- if (imgPath == null)
- {
- return null;
- }
- //var imgExt = imgPath["type"];
- //if (imgExt == "xml")
- //{
- // return null;
- //}
- var imgData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + imgPath["target"] + "']");
- if (imgData != null)
- {
- AzureBlobModel model = await SaveBase64ToBolob(imgData.InnerText, imgData.GetTextByPath("@pkg:contentType").Value,
- fileShaCode + "/imgs", null);
- return new Fill { Type = 3, Image = model.BlobUrl };
- }
- else { return null; }
- // var imgArrayBuffer = warpObj.zip.GetTextByPath(imgPath).Value.asArrayBuffer();
- //var imgMimeType = GetMimeType(imgExt);
- //img = "data:" + imgMimeType + ";base64," + base64ArrayBuffer(imgArrayBuffer);
- }
- public async Task<Fill> GetShapeFill(XmlNode node, WarpObj warpObj)
- {
- // 1. presentationML
- // p:spPr/ [a:noFill, solidFill, gradFill, blipFill, pattFill, grpFill]
- // From slide
- //Fill Type:
- //console.log("ShapeFill: ", node)
- var fillType = ShapeHelper.GetFillType(node.GetTextByPath("p:spPr"));
- Fill fill =null;
- //0
- if (fillType == "NO_FILL")
- {
- fill = new Fill
- {
- Type = 0,
- HtmlText = "background-color: initial;",
- SvgText = "node"
- };
- //return isSvgMode ? "none" : "background-color: initial;";
- }
- //1纯色填充
- else if (fillType == "SOLID_FILL")
- {
- XmlNode shpFill = node.GetTextByPath("p:spPr/a:solidFill");// node["p:spPr"]["a:solidFill"];
- string color = ShapeHelper.GetSolidFill(shpFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- fill = new Fill
- {
- Type = 1,
- Color = color,
- };
- }
- //2渐变色填充
- else if (fillType == "GRADIENT_FILL")
- {
- var shpFill = node.GetTextByPath("p:spPr/a:gradFill");// node["p:spPr"]["a:gradFill"];
- // fillColor = GetSolidFill(shpFill);
- fill = ShapeHelper.GetGradientFill(shpFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- //console.log("shpFill",shpFill,grndColor.color)
- }//3图片 纹理填充
- else if (fillType == "PIC_FILL")
- {
- var shpFill = node.GetTextByPath("p:spPr/a:blipFill"); //node["p:spPr"]["a:blipFill"];
- fill = await GetPicFill("slideBg", shpFill, warpObj);
- }//4 图案填充
- else if (fillType == "PATTERN_FILL")
- {
- /*
- *
- *<a:pattFill prst="ltDnDiag">
- <a:fgClr>
- <a:schemeClr val="dk1">
- <a:lumMod val="15000"/>
- <a:lumOff val="85000"/>
- </a:schemeClr>
- </a:fgClr>
- <a:bgClr>
- <a:schemeClr val="lt1"/>
- </a:bgClr>
- </a:pattFill>
- */
- var shpFill = node.GetTextByPath("p:spPr/a:pattFill");// node["p:spPr"]["a:pattFill"];
- fill = ShapeHelper.GetPatternFill(shpFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- // 2. drawingML namespace
- if (fill == null)
- {
- var clrName = node.GetTextByPath("p:style/a:fillRef");
- if (clrName != null) {
- fillType = "SOLID_FILL";
- }
- string color = ShapeHelper.GetSolidFill(clrName, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- color= PowerPointHelper.ColorToning(clrName.OuterXml,color);
- fill = new Fill
- {
- Type = 1,
- Color = color,
- };
- }
- if (fill != null)
- {
- if (fillType == "GRADIENT_FILL")
- {
- //if (isSvgMode)
- //{
- // // console.log("GRADIENT_FILL color", fillColor.color[0])
- // return fill;
- //}
- //else
- //{
- var colorAry = fill.gradColor;
- var rot = fill.Rot;
- var bgcolor = "background: linear-gradient(" + rot + "deg,";
-
- for (var i = 0; i < colorAry.Count; i++)
- {
- if (i == colorAry.Count - 1)
- {
- bgcolor += colorAry[i] + ");";
- }
- else
- {
- bgcolor += colorAry[i] + ", ";
- }
- }
- fill.HtmlText = bgcolor;
- return fill;
- // }
- }
- else if (fillType == "PIC_FILL")
- {
- //if (isSvgMode)
- //{
- // return fill;
- //}
- //else
- //{
- fill.HtmlText = "background-image:url(" + fill.Image + ");";
- return fill;
- // }
- }
- else
- {
- Console.WriteLine("#" + fill.Color);
- //if (isSvgMode)
- //{
- // var color = new colz.Color(fill);
- // fill = color.rgb.toString();
- fill.HtmlText = "background-color: #" + fill.Color + ";";
- return fill;
- //}
- //else
- //{
- // //console.log(node,"fillColor: ",fillColor,"fillType: ",fillType,"isSvgMode: ",isSvgMode)
- // return fill;
- //}
- }
- }
- else
- {
- //if (isSvgMode)
- //{
- // return fill;
- //}
- //else
- //{
- fill.SvgText = "none";
- fill.HtmlText = "background-color: initial;";
- return fill;
- // }
- }
- }
- public async Task<AzureBlobModel> GetThumbnailModel(XmlDocument xdoc, string shaCode)
- {
- var thumbnailNode = xdoc.GetTextByPath("//pkg:part[@pkg:name='/docProps/thumbnail.jpeg']");
- if (thumbnailNode != null)
- {
- var contentType = thumbnailNode.GetTextByPath("@pkg:contentType");
- var thumbnail = thumbnailNode.InnerText;
- return await SaveBase64ToBolob(thumbnail, contentType.Value, shaCode + "/imgs", "thumbnail");
- }
- return null;
- }
- public XmlNode LoadTheme(XmlDocument xdoc)
- {
- var themeRelationship = xdoc.GetTextByPath("//pkg:part[@pkg:name='/ppt/_rels/presentation.xml.rels']/pkg:xmlData/rel:Relationships/rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme']/@Target");
- // "/ppt/theme/theme1.xml"
- string themeURI = "/ppt/" + themeRelationship.Value;
- return xdoc.GetTextByPath("//pkg:part[@pkg:name='" + themeURI + "']");
- }
- public async Task<AzureBlobModel> SaveBase64ToBolob(string data, string contentType, string FolderName, string fileName)
- {
- string fileExt;
- if (ContentTypeDict.extdict.TryGetValue(contentType, out string ext))
- {
- fileExt = ext;
- }
- else
- {
- //解决多种扩展名不能获取的
- string[] sp = contentType.Split("/");
- fileExt = sp[sp.Length - 1];
- sp = fileExt.Split("+");
- fileExt = "." + sp[sp.Length - 1];
- }
- //data:image/jpeg;base64,
- if (string.IsNullOrEmpty(fileName))
- {
- Stream stream = new MemoryStream(Convert.FromBase64String(data));
- string shaCode = ShaHashHelper.GetSHA1(stream);
- fileName = shaCode + fileExt;
- }
- else
- {
- if (fileName.Split(".").Length == 1)
- {
- fileName += fileExt;
- }
- }
- Stream streamBlob = new MemoryStream(Convert.FromBase64String(data));
- AzureBlobModel model = await azureBlobDBRepository.UploadFileByFolder(streamBlob, FolderName, fileName, "pptx", false);
- return model;
- }
- public async Task<Media> ProcessPicNode(XmlNode node, int order, WarpObj warpObj)
- {
- var xfrmList = "p:spPr/a:xfrm";
- var xfrmNode = node.GetTextByPath(xfrmList);
- Media media = new Media() { Type = "Pic" };
- var id = node.GetTextByPath("p:nvPicPr/p:cNvPr/@id");
- XmlNode slideLayoutSpNode = ShapeHelper.GetNodesTable(id, null, null, warpObj, "Layout");
- XmlNode slideMasterSpNode = ShapeHelper.GetNodesTable(id, null, null, warpObj, "Master");
- XmlNode slideLayoutXfrmNode = null;
- if (slideLayoutSpNode != null)
- {
- slideLayoutXfrmNode = slideLayoutSpNode.GetTextByPath(xfrmList);
- }
- XmlNode slideMasterXfrmNode = null;
- if (slideMasterSpNode != null)
- {
- slideMasterXfrmNode = slideMasterSpNode.GetTextByPath(xfrmList);
- }
- double rotate = 0;
- var rotateNode = node.GetTextByPath("p:spPr/a:xfrm/@rot");
- if (rotateNode != null)
- {
- rotate = ShapeHelper.AngleToDegrees(rotateNode);
- }
- Fill fill = await GetShapeFill(node, warpObj);
- media.Fill = fill;
- Border border = ShapeHelper.GetBorder(node, true, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- media.Border = border;
- Position position = ShapeHelper.GetPosition(xfrmNode, slideLayoutXfrmNode, slideMasterXfrmNode);
- media.Position = position;
- position.Rot = rotate;
- var rtrnData = "";
- //image
- var rid = node.GetTextByPath("p:blipFill/a:blip/@r:embed");
- if (rid != null)
- {
- var imgName = warpObj.slideResObj[rid.Value]["target"];
- Console.WriteLine(imgName);
- if (!string.IsNullOrEmpty(imgName))
- {
- var imgData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + imgName + "']");
- var imgFileExt = imgData.GetTextByPath("@pkg:contentType");
- AzureBlobModel imgModel = await SaveBase64ToBolob(imgData.InnerText, imgFileExt.Value, fileShaCode + "/imgs", "");
- media.Image = imgModel.BlobUrl;
- media.MediaType = "image";
- }
- }
- ///////////////////////////////////////Amir//////////////////////////////
- //video
- var vdoNode = node.GetTextByPath("p:nvPicPr/p:nvPr/a:videoFile/@r:link");
- if (vdoNode != null)
- {
- string vdoFile = warpObj.slideResObj[vdoNode.Value]["target"];
- if (!string.IsNullOrEmpty(vdoFile))
- {
- var videoData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + vdoFile + "']");
- var contentType = videoData.GetTextByPath("@pkg:contentType");
- AzureBlobModel vdoModel = await SaveBase64ToBolob(videoData.InnerText, contentType.Value, fileShaCode + "/media", "");
- media.Url = vdoModel.BlobUrl;
- media.MediaType = "video";
- }
- /// 处理为AzureBlob 上传
- // vdoMimeType = getMimeType(vdoFileExt);
- // blob = new Blob([uInt8Array], {
- // type: vdoMimeType
- // });
- // vdoBlob = URL.createObjectURL(blob);
- }
- //audio
- var audioNode = node.GetTextByPath("p:nvPicPr/p:nvPr/a:audioFile/@r:link");
- // var audioObjc;
- if (audioNode != null)
- {
- string audioFile = warpObj.slideResObj[audioNode.Value]["target"];
- if (!string.IsNullOrEmpty(audioFile))
- {
- var audioData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + audioFile + "']");
- var contentType = audioData.GetTextByPath("@pkg:contentType");
- AzureBlobModel adoModel = await SaveBase64ToBolob(audioData.InnerText, contentType.Value, fileShaCode + "/media", "");
- media.Url = adoModel.BlobUrl;
- media.MediaType = "audio";
- }
- //uInt8ArrayAudio = zip.file(audioFile).asArrayBuffer();
- //blobAudio = new Blob([uInt8ArrayAudio]);
- //audioBlob = URL.createObjectURL(blobAudio);
- //var cx = parseInt(xfrmNode["a:ext"]["attrs"]["cx"]) * 20;
- //var cy = xfrmNode["a:ext"]["attrs"]["cy"];
- //var x = parseInt(xfrmNode["a:off"]["attrs"]["x"]) / 2.5;
- //var y = xfrmNode["a:off"]["attrs"]["y"];
- //audioObjc = {
- // "a:ext" : {
- // "attrs":{
- // "cx":cx,
- // "cy":cy
- // }
- // },
- // "a:off":{
- // "attrs":{
- // "x":x,
- // "y":y
- // }
- // }
- //}
- // mediaSupportFlag = true;
- }
- //console.log(node)
- //////////////////////////////////////////////////////////////////////////
- //mimeType = imgFileExt;
- //rtrnData = "<div class='block content' style='" +
- // (( audioPlayerFlag) ? GetPosition(audioObjc, null, null) : GetPosition(xfrmNode, null, null)) +
- // (( audioPlayerFlag) ? GetSize(audioObjc, null, null) :GetSize(xfrmNode, null, null)) +
- // " z-index: " + order + ";" +
- // "transform: rotate(" + rotate + "deg);'>";
- //if ((vdoNode ==null && audioNode ==null) || !mediaSupportFlag)
- //{
- // rtrnData += "<img src='data:" + mimeType + ";base64," + base64ArrayBuffer(imgArrayBuffer) + "' style='width: 100%; height: 100%'/>";
- //}
- //else if ((vdoNode !=null || audioNode !=null) && mediaSupportFlag)
- //{
- // if (vdoNode !=null)
- // {
- // rtrnData += "<video src='" + vdoBlob + "' controls style='width: 100%; height: 100%'>Your browser does not support the video tag.</video>";
- // }
- // if (audioNode !=null)
- // {
- // rtrnData += "<audio id='audio_player' controls ><source src='" + audioBlob + "'></audio>";
- // }
- //}
- rtrnData += "<span style='color:red;font-size:40px;position: absolute;'>This media file Not supported by HTML5</span>";
- //if ((vdoNode != null || audioNode != null) && mediaSupportFlag)
- //{
- // //console.log("Founded supported media file but media process disabled (mediaProcess=false)");
- //}
- rtrnData += "</div>";
- //console.log(rtrnData)
- return media;
- }
- }
- }
|