using DocumentFormat.OpenXml.Packaging; using TEAMModelOS.Service.Model.PowerPoint; 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.Common.CollectionHelper; 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 Fill = TEAMModelOS.Service.Model.PowerPoint.Fill; using Media = TEAMModelOS.Service.Model.PowerPoint.Media; using Position = TEAMModelOS.Service.Model.PowerPoint.Position; using TEAMModelOS.Service.Services.PowerPoint.Interface; using TEAMModelOS.Service.Models.Exam.Models; using TEAMModelOS.Service.Services.Exam.Interfaces; using TEAMModelOS.SDK.Helper.Common.JsonHelper; namespace TEAMModelOS.Service.Services.PowerPoint.Implement { public class HtexService : IHtexService { private string fileShaCode { get; set; } private Dictionary slideLayoutClrOvride { get; set; } private const int degree = 4; //private Dictionary> styleTable = new Dictionary>(); 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 readonly IHtmlAnalyzeService htmlAnalyzeService; public HtexService(IAzureBlobDBRepository _azureBlobDBRepository, IHtmlAnalyzeService _htmlAnalyzeService) { azureBlobDBRepository = _azureBlobDBRepository; htmlAnalyzeService = _htmlAnalyzeService; } public async Task AnalyzeHtmlToHtex(string htmlString, string Lang) { Htex htex = new Htex(); List items = htmlAnalyzeService.AnalyzeWordAsync(htmlString, Lang); string sha= ShaHashHelper.GetSHA1(htmlString); int index = 0; foreach (ExamItem item in items) { Slide slide = new Slide { exercise = item, index = index, source = 2, flag = 2 }; index++; AzureBlobModel model= await azureBlobDBRepository.UploadTextByFolder(slide.ToJson(), sha, index+".json","htex",false); htex.slides.Add(model.BlobUrl); } htex.page = items.Count; return htex; } public async Task> LoadDoc(IFormFile file) { Dictionary resdict = new Dictionary(); if (FileType.GetExtention(file.FileName).ToLower().Equals("pptx")) { return await ConvertPPTX(file, resdict); } else if (FileType.GetExtention(file.FileName).ToLower().Equals("pdf")) { // await ProcessPDF(file, resdict); return resdict; } else if (FileType.GetExtention(file.FileName).ToLower().Equals("xml")) { XmlDocument xmlDocument = new XmlDocument(); StreamReader sr = new StreamReader(file.OpenReadStream(), System.Text.Encoding.UTF8); string line; StringBuilder builder = new StringBuilder(); while ((line = sr.ReadLine()) != null) { builder.Append(line.ToString()); } sr.Close(); xmlDocument.LoadXml(builder.ToString()); string shaCode = fileShaCode = ShaHashHelper.GetSHA1(file.OpenReadStream()); var rslt_ary = await ProcessPPTX(xmlDocument, shaCode); //TODO Dictionary data = new Dictionary { { "htexl", rslt_ary } }; return data; } else { throw new BizException("file type does not support!", 500); } } public async Task> ConvertPPTX(IFormFile file, Dictionary 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 Dictionary data = new Dictionary { { "pptx",rslt_ary} }; return data; } /// /// 加载PPTX文件 /// /// /// public async Task ProcessPPTX(XmlDocument xdoc, string shaCode) { Htex pptx = new Htex(); // List> post_ary = new List>(); Dictionary post_ary = new Dictionary(); var dateBefore = DateTimeOffset.Now.UtcTicks; AzureBlobModel thumbnailModel = await GetThumbnailModel(xdoc, shaCode); // post_ary.Add( "pptx-thumb", thumbnailModel ); pptx.thumbnail = thumbnailModel != null ? thumbnailModel.BlobUrl : ""; //获取全部的/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); pptx.size = new HtexSize { width = slideSize.width, height = slideSize.height }; // post_ary.Add( "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; List slides = new List(); for (int i = 0; i < numOfSlides; i++) { var node = xdoc.GetTextByPath("//pkg:part[@pkg:name='/ppt/slides/slide" + (i + 1) + ".xml']"); string filename = node.GetTextByPath("@pkg:name").Value; //处理当前页的幻灯片 Slide slide = await ProcessSingleSlide(xdoc, node, filename, i, slideSize, themeContent, tableStyles, pptx); slide.source = 1; slide.flag = 1; AzureBlobModel model = await azureBlobDBRepository.UploadTextByFolder(slide.ToJson(), shaCode, (i + 1) + ".json", "htex", false); pptx.slides.Add(model.BlobUrl); slides.Add(slide); // post_ary.Add(new Dictionary { { "slide", slideHtml } }); // post_ary.Add(new Dictionary { { "progress-update", (i + 1) * 100 / numOfSlides } }); } // pptx.Sha1Code = shaCode; pptx.page = slides.Count; //post_ary.Add( "slide", slides ); //post_ary.Add( "globalCSS", GenGlobalCSS() ); // var dateAfter = DateTimeOffset.Now.UtcTicks; // post_ary.Add( "ExecutionTime", dateAfter - dateBefore ); return pptx; } //public Dictionary GenGlobalCSS() //{ // Dictionary cssText = new Dictionary(); // 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 ProcessSingleSlide(XmlDocument xdoc, XmlNode xnode, string sldFileName, int index, dynamic slideSize, XmlNode themeContent, XmlNode tableStyles,Htex pptx) { 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> slideResObj = new Dictionary>(); 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 dict = new Dictionary(); 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() { { "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> layoutResObj = new Dictionary>(); 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 dict = new Dictionary(); 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> masterResObj = new Dictionary>(); 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 dict = new Dictionary(); 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, tableStyles = tableStyles, htex = pptx }; var bgColor = await GetSlideBackgroundFill(slideContent, index, warpObj); //string sha = null; //if (bgColor != null) { // sha = ShaHashHelper.GetSHA1(bgColor.ToJson()); // warpObj.pptx.Fills.TryAdd(sha, bgColor); //} // string result = "
"; //result += "
"+getBackgroundShapes(slideContent, slideLayoutContent, slideMasterContent,warpObj) + "
" - TODO Slide slide = new Slide { fill=bgColor ,width= slideSize .width ,height= slideSize .height ,index=index }; if (spTreeNode != null) { var nodes = spTreeNode.ChildNodes; int order = 1; List items = new List(); foreach (XmlNode node in nodes) { await ProcessNodesInSlide(items, node.Name, node, order, warpObj); order += 1; } slide.item = items; } return slide; } public async Task ProcessNodesInSlide(List items, string nodeKey, XmlNode node, int order, WarpObj warpObj) { // string result = ""; switch (nodeKey) { case "p:sp": // Shape, Text Item spitem= await ProcessSpNode(node, order, warpObj); if (spitem != null) { items.Add(spitem); } break; case "p:cxnSp": // Shape, Text (with connection) Item cxnitem = await ProcessCxnSpNode(node, order, warpObj); if (cxnitem != null) { items.Add(cxnitem); } break; case "p:pic": // Picture Item picitem = await ProcessPicNode(node, order, warpObj); if (picitem != null) { items.Add(picitem); } break; case "p:graphicFrame": // Chart, Diagram, Table await ProcessGraphicFrameNode(items, node, order, warpObj); break; case "p:grpSp": await ProcessGroupSpNode(items, node, order, warpObj); break; case "mc:AlternateContent": //Equations and formulas as Image 处理公式 方程等 var mcFallbackNode = node.GetTextByPath("mc:Fallback/p:sp"); if (mcFallbackNode != null) { Item mcitem = await ProcessSpNode(mcFallbackNode, order, warpObj); if (mcitem != null) { items.Add(mcitem); } } else { mcFallbackNode = node.GetTextByPath("mc:Fallback/p:pic"); if (mcFallbackNode != null) { Item mcPicitem = await ProcessPicNode(mcFallbackNode, order, warpObj); if (mcPicitem != null) { items.Add(mcPicitem); } } } break; default: break; } } public async Task ProcessGroupSpNode(List items, 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; var rotate = ShapeHelper.AngleToDegrees(xfrmNode.GetTextByPath("@rot")); // string result = "
"; Group group = new Group { position = new Position { x = System.Math.Round(x - chx, degree), y = System.Math.Round(y - chy, degree), cx = System.Math.Round(cx - chcx, degree), cy = System.Math.Round(cy - chcy, degree), rot = System.Math.Round(rotate, degree) }, type = "Group", index = order++ }; // Procsee all child nodes var nodes = node.ChildNodes; List gpIterm = new List(); foreach (XmlNode nd in nodes) { await ProcessNodesInSlide(gpIterm, nd.Name, nd, order, warpObj); order += 1; } group.shapes = gpIterm; items.Add(group); // result += "
"; //return result; } public async Task ProcessGraphicFrameNode(List items, 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": Table table= await GenTable(node, order, warpObj); items.Add(table); break; case "http://schemas.openxmlformats.org/drawingml/2006/chart": items.Add(GenChart(node, order, warpObj)); break; case "http://schemas.openxmlformats.org/drawingml/2006/diagram": await GenDiagram(items, node, order, warpObj); break; default: break; } } //return result; } public async Task GenDiagram(List items, XmlNode node, int order, WarpObj warpObj) { var xfrmNode = node.GetTextByPath("p:xfrm"); var dgmRelIds = node.GetTextByPath("a:graphic/a:graphicData/dgm:relIds"); var dgmClrFileId = dgmRelIds.GetTextByPath("@r:cs"); var dgmDataFileId = dgmRelIds.GetTextByPath("@r:dm"); var dgmLayoutFileId = dgmRelIds.GetTextByPath("@r:lo"); var dgmQuickStyleFileId = dgmRelIds.GetTextByPath("@r:qs"); var dgmClrFileName = warpObj.slideResObj[dgmClrFileId.Value]["target"]; var dgmDataFileName = warpObj.slideResObj[dgmDataFileId.Value]["target"]; var dgmLayoutFileName = warpObj.slideResObj[dgmLayoutFileId.Value]["target"]; var dgmQuickStyleFileName = warpObj.slideResObj[dgmQuickStyleFileId.Value]["target"]; var dgmClr = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + dgmClrFileName + "']"); var dgmData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + dgmDataFileName + "']"); var dgmLayout = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + dgmLayoutFileName + "']"); var dgmQuickStyle = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + dgmQuickStyleFileName + "']"); var dgmDrwFileName = ""; var dataModelExt = dgmData.GetTextByPath("pkg:xmlData/dgm:dataModel/dgm:extLst/a:ext/dsp:dataModelExt"); if (dataModelExt != null) { var dgmDrwFileId = dataModelExt.GetTextByPath("@relId"); dgmDrwFileName = warpObj.slideResObj[dgmDrwFileId.Value]["target"]; } XmlNode dgmDrwFile=null ; if (dgmDrwFileName != "") { dgmDrwFile = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + dgmDrwFileName + "']"); } var dgmDrwSpArray = dgmDrwFile.GetTextByPathList("pkg:xmlData/dsp:drawing/dsp:spTree/dsp:sp"); if (dgmDrwSpArray !=null) { Diagram diagram = new Diagram(); diagram.position = ShapeHelper.GetPosition(xfrmNode, null, null); diagram.type = "Diagram"; diagram.index = order++; // Procsee all child nodes List gpIterm = new List(); XmlDocument nodeDoc = new XmlDocument(); var dgmDrwSpArrayLen = dgmDrwSpArray.Count; for (var i = 0; i < dgmDrwSpArrayLen; i++) { var dspSp = dgmDrwSpArray.Item(i); var pSpStr = dspSp.OuterXml.Replace("dsp:", "p:").Replace("xmlns:dsp=\"http://schemas.microsoft.com/office/drawing/2008/diagram\"", "xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\""); nodeDoc.LoadXml(pSpStr); //await ProcessSpNode(nodeDoc,order,warpObj); await ProcessNodesInSlide(gpIterm, nodeDoc.FirstChild.Name, nodeDoc.FirstChild, order, warpObj); } diagram.shapes = gpIterm; items.Add(diagram); } } public Chart GenChart(XmlNode node,int order , WarpObj warpObj) { Chart chart = new Chart { index=order,type= "Chart" }; var slideXfrmNode = node.GetTextByPath("p:xfrm"); Position position = ShapeHelper.GetPosition(slideXfrmNode, null, null); chart.position = position; var rid = node.GetTextByPath("a:graphic/a:graphicData/c:chart/@r:id"); List paragraphs = new List() ; if (rid != null) { var refName= warpObj.slideResObj[rid.Value]["target"]; var content = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + refName + "']"); var plotArea = content.GetTextByPath("pkg:xmlData/c:chartSpace/c:chart/c:plotArea"); var chartPnode = content.GetTextByPathList("pkg:xmlData/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p"); var anchor = content.GetTextByPath("pkg:xmlData/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:bodyPr/@anchor"); var vert = content.GetTextByPath("pkg:xmlData/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:bodyPr/@vert"); string VertAlign = "v-up"; string WritingMode = "horz"; if (anchor != null) { VertAlign = anchor.Value.Equals("ctr") ? "v-mid" : anchor.Value.Equals("b") ? "v-down" : "v-up"; } if (vert != null) { WritingMode = vert.Value; } foreach (XmlNode pNode in chartPnode) { string HoriAlign= GetHorizontalAlign(pNode, null, null, null, null); // string sha = null; ParagraphStyle paragraphStyle = new ParagraphStyle { hori = HoriAlign, writing = WritingMode, vert = VertAlign }; //sha = ShaHashHelper.GetSHA1(paragraphStyle.ToJson()); //warpObj.pptx.ParagraphStyles.TryAdd(sha, paragraphStyle); Paragraph paragraph = new Paragraph { style = paragraphStyle, // StyleSha=sha }; double defFontSize = 0; string defFontColor = "none"; var defsz= pNode.GetTextByPath("a:pPr/a:defRPr/@sz"); if (defsz != null) { defFontSize = int.Parse(defsz.Value) / 100.0; } var solidFillNode = pNode.GetTextByPath("a:pPr/a:defRPr/a:solidFill"); string colorstr = ShapeHelper.GetSolidFill(solidFillNode, slideLayoutClrOvride,warpObj. slideMasterContent,warpObj. themeContent); if (solidFillNode != null) { defFontColor = ShapeHelper.ColorToning(solidFillNode.OuterXml, colorstr); } var rNodes = pNode.GetTextByPathList("a:r"); List texts = new List(); foreach (XmlNode rNode in rNodes) { Text text = GenSpanElement(rNode, null, null, null, null, warpObj); if (pNode.GetTextByPath("a:br") != null) { text.isbr = true; } if (text.style.size == 0) { text.style.size = defFontSize; } if (text.style.color.Equals("000000")) { text.style.color = defFontColor; } //string styleSha = ShaHashHelper.GetSHA1(text.FontStyle.ToJson()); //warpObj.pptx.FontStyles.TryAdd(styleSha, text.FontStyle); //text.StyleSha = styleSha; texts.Add(text); } paragraph.texts = texts; paragraphs.Add(paragraph); } chart.title = paragraphs; var ps = plotArea.ChildNodes; List charts = new List(); foreach (XmlNode nodeChild in ps) { string key = nodeChild.Name.Replace("c:",""); XmlNodeList serNodes = null; switch (key) { //break块中不可以随意更换,此条件用于归类不同从Chart case "pieChart": case "ofPieChart": case "pie3DChart": case "doughnutChart": PieChart pieChart = new PieChart { chartType="pie"}; if (key.Equals("pie3DChart")) { pieChart.is3D = true; } pieChart.pieType = key; if (key.Equals("ofPieChart")) { var ofPieType = nodeChild.GetTextByPath("c:ofPieType/@val"); if (ofPieType != null) { //ofPieChart-pie ofPieChart-bar 子母饼图 pieChart.pieType += "-"+ ofPieType.Value; } } serNodes = nodeChild.GetTextByPathList("c:ser"); pieChart.datas= ExtractChartData(serNodes); charts.Add(pieChart); break; case "lineChart": case "line3DChart": LineChart lineChart = new LineChart { chartType = "line" }; if (key.Equals("line3DChart")) { lineChart.is3D = true; } lineChart.lineType = key; var LineGrouping = nodeChild.GetTextByPath("c:grouping/@val"); if (LineGrouping != null) { //standard stacked percentStacked lineChart.lineType += "-" + LineGrouping.Value; } serNodes = nodeChild.GetTextByPathList("c:ser"); lineChart.datas = ExtractChartData(serNodes); charts.Add(lineChart); break; case "barChart": case "bar3DChart": var barDir = nodeChild.GetTextByPath("c:barDir/@val"); if (barDir != null) { if (barDir.Value.Equals("bar")) { BarChart barChart = new BarChart { chartType = "bar" }; charts.Add(barChart); if (key.Equals("bar3DChart")) { barChart.is3D = true; } barChart.barType = key; var BarGrouping = nodeChild.GetTextByPath("c:grouping/@val"); if (BarGrouping != null) { //standard stacked percentStacked barChart.barType += "-" + BarGrouping.Value; } serNodes = nodeChild.GetTextByPathList("c:ser"); barChart.datas = ExtractChartData(serNodes); charts.Add(barChart); } else if(barDir.Value.Equals("col")){ ColChart colChart = new ColChart { chartType = "col" }; if (key.Equals("bar3DChart")) { colChart.is3D = true; } colChart.colType = key.Replace("bar","col"); var ColGrouping = nodeChild.GetTextByPath("c:grouping/@val"); if (ColGrouping != null) { //standard stacked percentStacked colChart.colType += "-" + ColGrouping.Value; } serNodes = nodeChild.GetTextByPathList("c:ser"); colChart.datas = ExtractChartData(serNodes); charts.Add(colChart); } } break; case "areaChart": case "area3DChart": AreaChart areaChart = new AreaChart { chartType = "area" }; if (key.Equals("area3DChart")) { areaChart.is3D = true; } areaChart.areaType = key; var AreaGrouping = nodeChild.GetTextByPath("c:grouping/@val"); if (AreaGrouping != null) { //standard stacked percentStacked areaChart.areaType += "-" + AreaGrouping.Value; } serNodes = nodeChild.GetTextByPathList("c:ser"); areaChart.datas = ExtractChartData(serNodes); charts.Add(areaChart); break; case "scatterChart": case "bubbleChart": ScatterChart scatterChart = new ScatterChart { chartType = "scatter" }; scatterChart.scatterType = key; if (key.Equals("scatterChart")) { var ScatterStyle = nodeChild.GetTextByPath("c:scatterStyle/@val"); if (ScatterStyle != null) { scatterChart.scatterType += "-" + ScatterStyle.Value.Replace("Marker",""); } } serNodes = nodeChild.GetTextByPathList("c:ser"); scatterChart.datas = ExtractChartData(serNodes); charts.Add(scatterChart); break; case "radarChart": RadarChart radarChart = new RadarChart { chartType = "radar" }; radarChart.radarType = key; var RadarStyle = nodeChild.GetTextByPath("c:radarStyle/@val"); if (RadarStyle != null) { radarChart.radarType += "-" + RadarStyle.Value; } serNodes = nodeChild.GetTextByPathList("c:ser"); radarChart.datas = ExtractChartData(serNodes); charts.Add(radarChart); break; case "plotAreaRegion": PlotAreaChart plotAreaChart = new PlotAreaChart { chartType = "plotArea" }; plotAreaChart.plotAreaType = key; var PlotSeries = nodeChild.GetTextByPath("cx:series/@layoutId"); if (PlotSeries != null) { plotAreaChart.plotAreaType += "-" + PlotSeries.Value; } serNodes = nodeChild.GetTextByPathList("c:ser"); plotAreaChart.datas = ExtractChartData(serNodes); charts.Add(plotAreaChart); break; case "stockChart": StockChart stockChart = new StockChart { chartType = "stock" }; stockChart.stockType = key; serNodes = nodeChild.GetTextByPathList("c:ser"); stockChart.datas = ExtractChartData(serNodes); charts.Add(stockChart); break; case "surfaceChart": case "surface3DChart": SurfaceChart surfaceChart = new SurfaceChart { chartType = "surface" }; if (key.Equals("surface3DChart")) { surfaceChart.is3D = true; } surfaceChart.surfaceType = key; var Wireframe = nodeChild.GetTextByPath("c:wireframe/@val"); if (Wireframe != null) { surfaceChart.surfaceType += "-" + Wireframe.Value; } serNodes = nodeChild.GetTextByPathList("c:ser"); surfaceChart.datas = ExtractChartData(serNodes); charts.Add(surfaceChart); break; } } chart.charts = charts; } return chart; } public List> ExtractChartData(XmlNodeList nodes) { if (nodes != null) { List> listDict = new List>(); foreach(XmlNode node in nodes) { if (node.GetTextByPath("c:xVal") != null) { Dictionary dict = new Dictionary(); var xCvNodes = node.GetTextByPathList("c:xVal/c:numRef/c:numCache/c:pt/c:v"); if (xCvNodes != null) { List list = new List(); foreach (XmlNode cvNode in xCvNodes) { list.Add(cvNode.InnerText); } dict.Add("xAxis", list); } var yCvNodes = node.GetTextByPathList("c:yVal/c:numRef/c:numCache/c:pt/c:v"); if (yCvNodes != null) { List list = new List(); foreach (XmlNode cvNode in yCvNodes) { list.Add(cvNode.InnerText); } dict.Add("yAxis", list); } dict.Add("colName", "-"); listDict.Add(dict); } else { Dictionary dict = new Dictionary(); var colNameNode = node.GetTextByPath("c:tx/c:strRef/c:strCache/c:pt/c:v"); if (colNameNode != null) { dict.Add("colName", colNameNode.InnerText); } //name var catNodes = node.GetTextByPathList("c:cat/c:strRef/c:strCache/c:pt/c:v"); if (catNodes == null) { catNodes = node.GetTextByPathList("c:cat/c:numRef/c:numCache/c:pt/c:v"); } if (catNodes != null) { List list = new List(); foreach (XmlNode cvNode in catNodes) { list.Add(cvNode.InnerText); } dict.Add("xAxis", list); } //value var valNodes = node.GetTextByPathList("c:val/c:numRef/c:numCache/c:pt/c:v"); if (valNodes != null) { List list = new List(); foreach (XmlNode cvNode in valNodes) { list.Add(cvNode.InnerText); } dict.Add("yAxis", list); } listDict.Add(dict); } } return listDict; } return null; } public async Task GenTable(XmlNode node, int order, WarpObj warpObj) { Table table = new Table(); table.index = order; var slideXfrmNode= node.GetTextByPath("p:xfrm"); Position position = ShapeHelper.GetPosition(slideXfrmNode, null, null); var tableNode = node.GetTextByPath("a:graphic/a:graphicData/a:tbl"); var getTblPr = tableNode.GetTextByPath("a:tblPr"); var getColsGrid = tableNode.GetTextByPath("a:tblGrid/a:gridCol"); var tblDir = "ltr"; XmlNode firstRowAttr = null , bandRowAttr =null ; if (getTblPr != null) { var isRTL = getTblPr.GetTextByPath("@rtl"); tblDir = isRTL!=null && isRTL.Value.Equals("1") ? "rtl" : "ltr"; firstRowAttr = getTblPr.GetTextByPath("@firstRow"); //associated element in the table styles var firstColAttr = getTblPr.GetTextByPath("@firstCol"); //associated element in the table styles var lastRowAttr = getTblPr.GetTextByPath("@lastRow");//associated element in the table styles var lastColAttr = getTblPr.GetTextByPath("@lastCol"); //associated element in the table styles bandRowAttr = getTblPr.GetTextByPath("@bandRow"); //associated element , in the table styles var bandColAttr = getTblPr.GetTextByPath("@bandCol"); //associated element , in the table styles } table.dir = tblDir; table.position = position; table.type = "Table"; var trNodes = tableNode.GetTextByPathList("a:tr"); if (trNodes != null) { int trSize = trNodes.Count; for (int i = 0; i < trSize; i++) { Tr tr = new Tr(); var rowHeightParam = trNodes.Item(i).GetTextByPath("@h"); double rowHeight = 0; //var rowsStyl = ""; if (rowHeightParam != null) { rowHeight = int.Parse(rowHeightParam.Value) * px96 / px914400; } tr.height = rowHeight; XmlNode thisTblStyle=null; var tbleStyleId = getTblPr.GetTextByPath("a:tableStyleId"); if (tbleStyleId != null) { var tbleStylList = warpObj.tableStyles.GetTextByPathList("a:tblStyleLst/a:tblStyle"); foreach (XmlNode tbleStyle in tbleStylList) { if (tbleStyle.GetTextByPath("@styleId").Value.Equals(tbleStyleId.Value)) { thisTblStyle = tbleStyle; } } } if (i == 0 && firstRowAttr != null && thisTblStyle != null) { var fillColor = "fff"; // var colorOpacity = 1; if (thisTblStyle.GetTextByPath("a:firstRow") != null) { //处理纯色填充 var bgFillschemeClr = thisTblStyle.GetTextByPath("a:firstRow/a:tcStyle/a:fill/a:solidFill"); if (bgFillschemeClr != null) { fillColor = ShapeHelper.GetSolidFill(bgFillschemeClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent); fillColor = ShapeHelper.ColorToning(bgFillschemeClr.OuterXml, fillColor); Fill f = new Fill { color = fillColor, type = 1 }; //string sha = null; //sha = ShaHashHelper.GetSHA1(f.ToJson()); //warpObj.pptx.Fills.TryAdd(sha, f); //tr.FillSha = sha; tr.fill = f; } //其他填充 todo var fill = thisTblStyle.GetTextByPath("a:firstRow/a:tcStyle/a:fill"); string fillType = ShapeHelper.GetFillType(fill); var borderStyl = thisTblStyle.GetTextByPath("a:firstRow/a:tcStyle/a:tcBdr"); if (borderStyl != null) { List borders = GetTableBorders(borderStyl, warpObj); tr.borders = borders; } //Text Style - TODO //var rowTxtStyl = getTextByPathList(thisTblStyle,["a:firstRow", "a:tcTxStyle"]); //if (rowTxtStyl !== undefined) //{ /* var fontClrPr = getFontColorPr(node, spNode, type, slideMasterTextStyles); var styleText = "color:" + fontClrPr[0] + ";" + "text-shadow:" + fontClrPr[1] + ";" + "font-size:" + getFontSize(node, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles) + ";" + "font-family:" + getFontType(node, type, slideMasterTextStyles) + ";" + "font-weight:" + getFontBold(node, type, slideMasterTextStyles) + ";" + "font-style:" + getFontItalic(node, type, slideMasterTextStyles) + ";" + "text-decoration:" + getFontDecoration(node, type, slideMasterTextStyles) + ";" + "text-align:" + getTextHorizontalAlign(node, type, slideMasterTextStyles) + ";" + "vertical-align:" + getTextVerticalAlign(node, type, slideMasterTextStyles) + ";"; */ //} } } else if (i > 0 && bandRowAttr != null && thisTblStyle != null) { var fillColor = "fff"; // var colorOpacity = 1; if ((i % 2) == 0) { if (thisTblStyle.GetTextByPath("a:band2H") != null) { //处理纯色填充 var bgFillschemeClr = thisTblStyle.GetTextByPath("a:band2H/a:tcStyle/a:fill/a:solidFill"); if (bgFillschemeClr != null) { fillColor = ShapeHelper.GetSolidFill(bgFillschemeClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent); fillColor = ShapeHelper.ColorToning(bgFillschemeClr.OuterXml, fillColor); Fill f = new Fill { color = fillColor, type = 1 }; //string sha = null; //sha = ShaHashHelper.GetSHA1(f.ToJson()); //warpObj.pptx.Fills.TryAdd(sha, f); //tr.FillSha = sha; tr.fill = f; } //其他填充 todo var fill = thisTblStyle.GetTextByPath("a:band2H/a:tcStyle/a:fill"); string fillType = ShapeHelper.GetFillType(fill); var borderStyl = thisTblStyle.GetTextByPath("a:band2H/a:tcStyle/a:tcBdr"); if (borderStyl != null) { List borders = GetTableBorders(borderStyl, warpObj); tr.borders = borders; } //Text Style - TODO //var rowTxtStyl = getTextByPathList(thisTblStyle,["a:band2H", "a:tcTxStyle"]); //if (rowTxtStyl !== undefined) //{ //} } else { //处理纯色填充 var bgFillschemeClr = thisTblStyle.GetTextByPath("a:wholeTbl/a:tcStyle/a:fill/a:solidFill"); if (bgFillschemeClr != null) { fillColor = ShapeHelper.GetSolidFill(bgFillschemeClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent); fillColor = ShapeHelper.ColorToning(bgFillschemeClr.OuterXml, fillColor); Fill f = new Fill { color = fillColor, type = 1 }; //string sha = null; //sha = ShaHashHelper.GetSHA1(f.ToJson()); //warpObj.pptx.Fills.TryAdd(sha, f); //tr.FillSha = sha; tr.fill = f; } //其他填充 todo var fill = thisTblStyle.GetTextByPath("a:wholeTbl/a:tcStyle/a:fill"); string fillType = ShapeHelper.GetFillType(fill); var borderStyl = thisTblStyle.GetTextByPath("a:wholeTbl/a:tcStyle/a:tcBdr"); if (borderStyl != null) { List borders = GetTableBorders(borderStyl, warpObj); tr.borders = borders; } //Text Style - TODO //var rowTxtStyl = thisTblStyle["a:wholeTbl"]["a:tcTxStyle"]; //if (rowTxtStyl !== undefined) //{ //} } } else { if (thisTblStyle.GetTextByPath("a:band1H") != null) { //处理纯色填充 var bgFillschemeClr = thisTblStyle.GetTextByPath("a:band1H/a:tcStyle/a:fill/a:solidFill"); if (bgFillschemeClr != null) { fillColor = ShapeHelper.GetSolidFill(bgFillschemeClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent); fillColor = ShapeHelper.ColorToning(bgFillschemeClr.OuterXml, fillColor); Fill f = new Fill { color = fillColor, type = 1 }; //string sha = null; //sha = ShaHashHelper.GetSHA1(f.ToJson()); //warpObj.pptx.Fills.TryAdd(sha, f); //tr.FillSha = sha; tr.fill = f; } //其他填充 todo var fill = thisTblStyle.GetTextByPath("a:band1H/a:tcStyle/a:fill"); string fillType = ShapeHelper.GetFillType(fill); var borderStyl = thisTblStyle.GetTextByPath("a:band1H/a:tcStyle/a:tcBdr"); if (borderStyl != null) { List borders = GetTableBorders(borderStyl, warpObj); tr.borders = borders; } //Text Style - TODO //var rowTxtStyl = getTextByPathList(thisTblStyle,["a:band1H", "a:tcTxStyle"]); //if (rowTxtStyl !== undefined) //{ //} } } } var tcNodes= trNodes.Item(i).GetTextByPathList("a:tc"); if (tcNodes != null) { int tcSize = tcNodes.Count; for (int j = 0; j < tcSize; j++) { Td td = new Td(); List paragraphs= await GenTextBody(tcNodes.Item(j).GetTextByPath("a:txBody"),node,null,null,null,warpObj); var rowSpan = tcNodes.Item(j).GetTextByPath( "@rowSpan"); var colSpan = tcNodes.Item(j).GetTextByPath("@gridSpan"); var vMerge = tcNodes.Item(j).GetTextByPath("@vMerge"); var hMerge = tcNodes.Item(j).GetTextByPath("@hMerge"); var colWidthParam = getColsGrid.GetTextByPath("@w"); if (colWidthParam != null) { td.width = int.Parse(colWidthParam.Value) * px96 / px914400; } var getFill = tcNodes.Item(j).GetTextByPath("a:tcPr/a:solidFill"); string fillColor = ""; if (getFill != null) { fillColor = ShapeHelper.GetSolidFill(getFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent); fillColor = ShapeHelper.ColorToning(getFill.OuterXml, fillColor); Fill f = new Fill { color = fillColor, type = 1 }; //string sha = null; //sha = ShaHashHelper.GetSHA1(f.ToJson()); //warpObj.pptx.Fills.TryAdd(sha, f); //tr.FillSha = sha; td.fill = f; } else { //get from Theme (tableStyles.xml) TODO //get tableStyleId = a:tbl => a:tblPr => a:tableStyleId //var tbleStyleId = getTblPr["a:tableStyleId"]; //if (tbleStyleId !== undefined) //{ // //get Style from tableStyles.xml by {var tbleStyleId} // //table style object : tableStyles // var tbleStylList = tableStyles["a:tblStyleLst"]["a:tblStyle"]; // for (var k = 0; k < tbleStylList.length; k++) // { // if (tbleStylList[k]["attrs"]["styleId"] == tbleStyleId) // { // //console.log(tbleStylList[k]); // } // } //} } //其他填充 todo if (rowSpan != null) { td.rowspan = int.Parse(rowSpan.Value); } if (colSpan != null) { td.colspan = int.Parse(colSpan.Value); } // if (vMerge != null) { td.vmerge = int.Parse(vMerge.Value); } if (colSpan != null) { td.hmerge = int.Parse(colSpan.Value); } if (rowSpan == null && colSpan == null && vMerge == null && hMerge == null) { td.rowspan = 0; td.colspan = 0; td.hmerge = 0; td.vmerge = 0; } td.paragraphs = paragraphs; tr.td.Add(td); } } table.tr.Add(tr); } } return table; } private List GetTableBorders(XmlNode node, WarpObj warpObj) { List borders = new List(); if (node.GetTextByPath("a:bottom") != null) { string xml= ""+ node.GetTextByPath("a:bottom/a:ln").InnerXml + ""; XmlDocument nodeDoc = new XmlDocument(); nodeDoc.LoadXml(xml); Border border= ShapeHelper.GetBorder(nodeDoc, false, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent); border.dir = "bottom"; //string sha = ShaHashHelper.GetSHA1(border.ToJson()); //warpObj.pptx.Borders.TryAdd(sha, border); borders.Add(border); } if (node.GetTextByPath("a:top") != null) { string xml = "" + node.GetTextByPath("a:top/a:ln").InnerXml + ""; XmlDocument nodeDoc = new XmlDocument(); nodeDoc.LoadXml(xml); Border border = ShapeHelper.GetBorder(nodeDoc, false, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent); border.dir = "top"; //string sha = ShaHashHelper.GetSHA1(border.ToJson()); //warpObj.pptx.Borders.TryAdd(sha, border); borders.Add(border); } if (node.GetTextByPath("a:right") != null) { string xml = "" + node.GetTextByPath("a:right/a:ln").InnerXml + ""; XmlDocument nodeDoc = new XmlDocument(); nodeDoc.LoadXml(xml); Border border = ShapeHelper.GetBorder(nodeDoc, false, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent); border.dir = "right"; //string sha = ShaHashHelper.GetSHA1(border.ToJson()); //warpObj.pptx.Borders.TryAdd(sha, border); borders.Add(border); } if (node.GetTextByPath("a:left") != null) { string xml = "" + node.GetTextByPath("a:left/a:ln").InnerXml + ""; XmlDocument nodeDoc = new XmlDocument(); nodeDoc.LoadXml(xml); Border border = ShapeHelper.GetBorder(nodeDoc, false, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent); border.dir = "left"; //string sha = ShaHashHelper.GetSHA1(border.ToJson()); //warpObj.pptx.Borders.TryAdd(sha, border); borders.Add(border); } return borders; } public async Task 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("CxnSp", node, null, null, id, name, null, null, order, warpObj); } public async Task ProcessSpNode(XmlNode node, int order, WarpObj warpObj) { /* * 958 * 959 * 960 * 961 * 962 * 963 * 964 * 965 * 966 */ 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"]); } } Item item = await GenShape("Sp", node, slideLayoutSpNode, slideMasterSpNode, id, name, idx, type, order, warpObj); return item; } public async Task GenShape(string ShapeType, 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")); 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 = System.Math.Round(rotate,degree); 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"); Svg shapeSvg = new Svg { id = order + "", /*Width = position.Cx + "", Height = position.Cy + "", Top = position.X + "", Left = position.Y + "", Transform = "rotate(" + position.Rot + "deg)"*/}; // StringBuilder svgPath = new StringBuilder(""; //result += ""; // Fill Color var clrFillType = ShapeHelper.GetFillType(node.GetTextByPath("p:spPr")); ///////////////////////////////////////// if (Fill.type==2)//== "GRADIENT_FILL" { grndFillFlg = true; var color_arry = Fill.grad; var angl = Fill.rot; // var svgGrdnt = ShapeHelper.GetSvgGradient(position.Cx, position.Cy, angl, color_arry, order, slideLayoutClrOvride, warpObj.themeContent); // shapeSvg.Defs = svgGrdnt; //fill="url(#linGrd)" // Fill.SvgText = svgGrdnt; // result += svgGrdnt; } else if (Fill.type == 3) //(clrFillType == "PIC_FILL") { imgFillFlg = true; // var svgBgImg = ShapeHelper.GetSvgImagePattern(Fill.Image, order); // shapeSvg.Defs = svgBgImg; //fill="url(#imgPtrn)" // Fill.SvgText = svgBgImg; // result += svgBgImg; } else { // if (clrFillType != null && clrFillType != "SOLID_FILL" && clrFillType != "PATTERN_FILL") if (shapeType != null) { if (Fill.type != 1 && Fill.type != 4 &&(shapeType.Value == "arc" || shapeType.Value == "bracketPair" || shapeType.Value == "bracePair" || shapeType.Value == "leftBracket" || shapeType.Value == "leftBrace" || shapeType.Value == "rightBrace" || shapeType.Value == "rightBracket")) { //Fill.HtmlText = "none"; Fill.color = "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 = ""; // shapeSvg.Defs = triangleMarker; // result += triangleMarker; } // result += ""; } if (shapeType != null && custShapType == null) { Svg svg = ShapeSvg.GenShapeSvg(node, order, shapeType, isFlipV, position, grndFillFlg, imgFillFlg, Fill, shapeBorder, headEndNodeAttrs, tailEndNodeAttrs); shapeSvg.svgShape = svg.svgShape; // shapeSvg.SvgData = svg.SvgData; if (ShapeType.Equals("Sp")) { Shape shape = new Shape { border = shapeBorder, svg = shapeSvg, type = "Sp", position = position, index = order, shapeType = shapeType.Value }; //if (shapeBorder != null&& shapeBorder.Type!=null) //{ // shape.BorderSha = ShaHashHelper.GetSHA1(shapeBorder.ToJson()); // warpObj.pptx.Borders.TryAdd(shape.BorderSha, shapeBorder); //} if (Fill.type == 0) { shape.fill = null; } else { //string sha = null; //sha = ShaHashHelper.GetSHA1(Fill.ToJson()); //warpObj.pptx.Fills.TryAdd(sha, Fill); //shape.FillSha = sha; shape.fill = Fill; } var txbody = node.GetTextByPath("p:txBody"); if (txbody != null) { List paragraphs = await GenTextBody(txbody, node, slideLayoutSpNode, slideMasterSpNode, type, warpObj); shape.paragraph = paragraphs; } return shape; } else if (ShapeType.Equals("CxnSp")) { //string bdsha = null; //if (shapeBorder != null && shapeBorder.Type != null) //{ // bdsha = ShaHashHelper.GetSHA1(shapeBorder.ToJson()); // warpObj.pptx.Borders.TryAdd(bdsha, shapeBorder); //} return new Connector { border = shapeBorder, svg = shapeSvg, type = "CxnSp", position = position, index = order, cxnType = shapeType.Value }; } else { return null; } } else if (custShapType != null) { XmlNode pathLstNode = custShapType.GetTextByPath("a:pathLst"); //XmlNode pathNode = pathLstNode.GetTextByPath("a:path"); //var maxX = 0.0; //var maxY = 0.0; //if (pathLstNode != null) //{ // maxX = double.Parse(pathNode.GetTextByPath("@w").Value) * px96 / px914400; // maxY = double.Parse(pathNode.GetTextByPath("@h").Value) * px96 / px914400; //} var closeNode = pathLstNode.GetTextByPath("a:path/a:close"); var startPoint = pathLstNode.GetTextByPath("a:path/a:moveTo/a:pt"); var spX = 96.0; var spY = 96.0; if (startPoint != null) { spX = System.Math.Round(double.Parse(startPoint.GetTextByPath("@x").Value) * 96 / 914400,degree); spY = System.Math.Round(double.Parse(startPoint.GetTextByPath("@y").Value) * 96 / 914400,degree); } var d = "M" + spX + "," + spY; // List Paths = new List(); XmlNodeList pathChildNodes = pathLstNode.GetTextByPath("a:path").ChildNodes; foreach (XmlNode childNode in pathChildNodes) { if (childNode.Name.Equals("a:lnTo")) { XmlNodeList nodeList = childNode.ChildNodes; var Lx = double.Parse(nodeList.Item(0).GetTextByPath("@x").Value) * px96 / px914400; var Ly = double.Parse(nodeList.Item(0).GetTextByPath("@y").Value) * px96 / px914400; //Paths.Add(new LineToPath //{ // Lx = double.Parse(Lx.Value) * px96 / px914400, // Ly = double.Parse(Lx.Value) * px96 / px914400, //}); d += " L" + System.Math.Round(Lx,degree) + "," + System.Math.Round(Ly,degree); } if (childNode.Name.Equals("a:cubicBezTo")) { XmlNodeList nodeList = childNode.ChildNodes; var Cx1 = double.Parse(nodeList.Item(0).GetTextByPath("@x").Value) * px96 / px914400; var Cy1 = double.Parse(nodeList.Item(0).GetTextByPath("@y").Value) * px96 / px914400; var Cx2 = double.Parse(nodeList.Item(1).GetTextByPath("@x").Value) * px96 / px914400; var Cy2 = double.Parse(nodeList.Item(1).GetTextByPath("@y").Value) * px96 / px914400; var Cx3 = double.Parse(nodeList.Item(2).GetTextByPath("@x").Value) * px96 / px914400; var Cy3 = double.Parse(nodeList.Item(2).GetTextByPath("@y").Value) * px96 / px914400; //Paths.Add( new CubicBezPath // { // Cx1 = double.Parse(Cx1.Value) * px96 / px914400, // Cy1 = double.Parse(Cy1.Value) * px96 / px914400, // Cx2 = double.Parse(Cx2.Value) * px96 / px914400, // Cy2 = double.Parse(Cy2.Value) * px96 / px914400, // Cx3 = double.Parse(Cx3.Value) * px96 / px914400, // Cy3 = double.Parse(Cy3.Value) * px96 / px914400 // }); d += " C" + System.Math.Round(Cx1,degree) + "," + System.Math.Round(Cy1,degree) + " " + System.Math.Round(Cx2,degree) + "," + System.Math.Round(Cy2,degree) + " " + System.Math.Round(Cx3,degree) + "," + System.Math.Round(Cy3,degree); } if (childNode.Name.Equals("a:quadBezTo")) { //http://cw.hubwiz.com/card/c/5636b7041bc20c980538e995/1/4/4/ XmlNodeList nodeList = childNode.ChildNodes; var Cx1 = double.Parse(nodeList.Item(0).GetTextByPath("@x").Value) * px96 / px914400; var Cy1 = double.Parse(nodeList.Item(0).GetTextByPath("@y").Value) * px96 / px914400; var Cx2 = double.Parse(nodeList.Item(1).GetTextByPath("@x").Value) * px96 / px914400; var Cy2 = double.Parse(nodeList.Item(1).GetTextByPath("@y").Value) * px96 / px914400; //Paths.Add(new QuadBezPath //{ // Cx1 = double.Parse(Cx1.Value) * px96 / px914400, // Cy1 = double.Parse(Cy1.Value) * px96 / px914400, // Cx2 = double.Parse(Cx2.Value) * px96 / px914400, // Cy2 = double.Parse(Cy2.Value) * px96 / px914400 //}); d += " Q" + System.Math.Round(Cx1,degree) + "," + System.Math.Round(Cy1,degree) + " " + System.Math.Round(Cx2,degree) + "," + System.Math.Round(Cy2,degree); } if (childNode.Name.Equals("a:arcTo")) { var wR = double.Parse(childNode.GetTextByPath("@wR").Value) * px96 / px914400; var hR = double.Parse(childNode.GetTextByPath("@hR").Value) * px96 / px914400; var stAng = double.Parse(childNode.GetTextByPath("@stAng").Value) * px96 / px914400; var swAng = double.Parse(childNode.GetTextByPath("@swAng").Value) * px96 / px914400; var endAng = stAng + swAng; d += ShapeSvg.ShapeArc(wR, hR, wR, hR, stAng, endAng, false); //Paths.Add(new ArcToPath() { // WidthRadius = double.Parse(wR.Value) * px96 / px914400, // HeightRadius = double.Parse(hR.Value) * px96 / px914400, // StartAngle = double.Parse(stAng.Value) * px96 / px914400, // SwingAngle = double.Parse(swAng.Value) * px96 / px914400 //}); } } //if (headEndNodeAttrs != null && (headEndNodeAttrs.GetTextByPath("@type").Value == "triangle" || headEndNodeAttrs.GetTextByPath("@type").Value == "arrow")) //{ // result += "marker-start='url(#markerTriangle_" + order + ")' "; //} //if (tailEndNodeAttrs != null && (tailEndNodeAttrs.GetTextByPath("@type").Value == "triangle" || tailEndNodeAttrs.GetTextByPath("@type").Value == "arrow")) //{ // result += "marker-end='url(#markerTriangle_" + order + ")' "; //} //是否关闭svg if (closeNode != null) { d += " z"; } List shapes = new List() { new SvgPath { type = "path", // Fill = (!imgFillFlg ? (grndFillFlg ? "url(#linGrd_" + order + ")" : Fill.Color) : "url(#imgPtrn_" + order + ")"), //Stroke = "#" + shapeBorder.Color, //StrokeWidth = shapeBorder.Width + "", //StrokeDasharray = shapeBorder.Stroke, d=d, start=headEndNodeAttrs!=null?headEndNodeAttrs.GetTextByPath("@type").Value:null, end=tailEndNodeAttrs!=null?tailEndNodeAttrs.GetTextByPath("@type").Value:null, } }; shapeSvg.svgShape = shapes; // shapeSvg.SvgData = result; Shape shape = new Shape { border = shapeBorder, svg = shapeSvg, type = "Sp", position = position, index = order, shapeType = "custom" }; //if (shapeBorder != null && shapeBorder.Type != null) //{ // shape.BorderSha = ShaHashHelper.GetSHA1(shapeBorder.ToJson()); // warpObj.pptx.Borders.TryAdd(shape.BorderSha, shapeBorder); //} if (Fill.type == 0) { shape.fill = null; } else { //string sha = null; //sha = ShaHashHelper.GetSHA1(Fill.ToJson()); //warpObj.pptx.Fills.TryAdd(sha, Fill); //shape.FillSha = sha; shape.fill = Fill; } var txbody = node.GetTextByPath("p:txBody"); if (txbody != null) { List paragraphs = await GenTextBody(txbody, node, slideLayoutSpNode, slideMasterSpNode, type, warpObj); shape.paragraph = paragraphs; } return shape; } else { Shape shape = new Shape { border = shapeBorder, svg = shapeSvg, type = "Sp", position = position, index = order, shapeType = "rect" }; //if (shapeBorder != null && shapeBorder.Type != null) //{ // shape.BorderSha = ShaHashHelper.GetSHA1(shapeBorder.ToJson()); // warpObj.pptx.Borders.TryAdd(shape.BorderSha, shapeBorder); //} if (Fill.type == 0) { shape.fill = null; } else { //string sha = null; //sha = ShaHashHelper.GetSHA1(Fill.ToJson()); //warpObj.pptx.Fills.TryAdd(sha, Fill); //shape.FillSha = sha; shape.fill = Fill; } var txbody = node.GetTextByPath("p:txBody"); if (txbody != null) { List paragraphs = await GenTextBody(txbody, node, slideLayoutSpNode, slideMasterSpNode, type, warpObj); shape.paragraph = paragraphs; } return shape; } } private async Task> GenTextBody(XmlNode textBodyNode, XmlNode spNode, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, WarpObj warpObj) { List paragraphs = new List(); var slideMasterTextStyles = warpObj.slideMasterTextStyles; string VertAlign = GetVerticalAlign(spNode, slideLayoutSpNode, slideMasterSpNode); string WritingMode = GetWritingMode(spNode, slideLayoutSpNode, slideMasterSpNode); var ps = textBodyNode.GetTextByPathList("a:p"); if (ps != null) { foreach (XmlNode pNode in ps) { BuChar buChar = await GenBuChar(pNode, spNode, slideLayoutSpNode, slideMasterSpNode, type, warpObj); if (buChar != null && (buChar.buchar == null || buChar.buchar.Equals("TYPE_NONE"))) { buChar = null; } //string bucharsha = null; //if (buChar != null) { // bucharsha = ShaHashHelper.GetSHA1(buChar.ToJson()); // warpObj.pptx.BuChars.TryAdd(bucharsha, buChar); //} string HoriAlign = GetHorizontalAlign(pNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles); ParagraphStyle paragraphStyle = new ParagraphStyle { hori= HoriAlign, writing = WritingMode, vert = VertAlign }; //sha = ShaHashHelper.GetSHA1(paragraphStyle.ToJson()); //warpObj.pptx.ParagraphStyles.TryAdd(sha, paragraphStyle); Paragraph paragraph = new Paragraph { buChar = buChar, style = paragraphStyle, //StyleSha = sha, //BuCharSha= bucharsha }; var rNode = pNode.GetTextByPathList("a:r"); if (rNode == null) { Text text = GenSpanElement(pNode, spNode, slideLayoutSpNode, slideMasterSpNode, type, warpObj); if (pNode.GetTextByPath("a:br") != null) { text.isbr = true; } List texts = new List { text }; paragraph.texts = texts; } else { List texts = new List(); foreach (XmlNode node in rNode) { Text text = GenSpanElement(node, spNode, slideLayoutSpNode, slideMasterSpNode, type, warpObj); if (pNode.GetTextByPath("a:br") != null) { text.isbr = true; } texts.Add(text); } paragraph.texts = texts; } paragraphs.Add(paragraph); } } return paragraphs; } private Text GenSpanElement(XmlNode node, XmlNode spNode, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, WarpObj warpObj) { string text; var slideMasterTextStyles = warpObj.slideMasterTextStyles; var textNode = node.GetTextByPath("a:t"); if (textNode == null) { textNode = node.GetTextByPath("a:fld/a:t"); if (textNode == null) { text = " "; } else { text = textNode.InnerText; } } else { text = textNode.InnerText; } var fontClrPr = GetFontColorPr(node, spNode, type, slideMasterTextStyles, warpObj.slideMasterContent, warpObj.themeContent); string color = fontClrPr.color; string text_shadow = fontClrPr.textBordr; double font_size = GetFontSize(node, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles); string font_family = GetFontType(node, type, slideMasterTextStyles, warpObj.themeContent); string font_weight = GetFontBold(node, type, slideMasterTextStyles); string font_style = GetFontItalic(node, type, slideMasterTextStyles); string text_decoration = GetFontDecoration(node, type, slideMasterTextStyles); string text_align = GetTextHorizontalAlign(node, type, slideMasterTextStyles); string vertical_align = GetTextVerticalAlign(node, type, slideMasterTextStyles); //var styleText = // "color:" + color + ";" + // "text-shadow:" + text_shadow + ";" + // "font-size:" + font_size + ";" + // "font-family:" + font_family + ";" + // "font-weight:" + font_weight + ";" + // "font-style:" + font_style + ";" + // "text-decoration:" + text_decoration + ";" + // "text-align:" + text_align + ";" + // "vertical-align:" + vertical_align + ";"; //string cssName = ""; //if (styleTable.TryGetValue(styleText, out Dictionary css)) //{ // cssName = css["name"]; //} //else //{ // cssName = "_css_" + (styleTable.Keys.Count + 1); // styleTable.TryAdd(styleText, new Dictionary { { "name", cssName }, { "text", styleText } }); //} var linkID = node.GetTextByPath("a:rPr/a:hlinkClick/@r:id"); string linkURL = null; if (linkID != null) { linkURL = warpObj.slideResObj[linkID.Value]["target"]; } FontStyle fontStyle = new FontStyle { color = color, size = font_size, family = font_family, weight = font_weight, style = font_style, decoration = text_decoration, vertAlign = vertical_align, align = text_align, shadow = text_shadow }; //string styleSha = ShaHashHelper.GetSHA1(fontStyle.ToJson()); //warpObj.pptx.FontStyles.TryAdd(styleSha, fontStyle); return new Text { content = text, href = linkURL, style=fontStyle //StyleSha = styleSha }; } private string GetTextVerticalAlign(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles) { var baseline = node.GetTextByPath("a:rPr/@baseline"); if (baseline != null) { return double.Parse(baseline.Value) / 1000.0 + "%"; } else { return "baseline"; } } private string GetTextHorizontalAlign(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles) { var getAlgn = node.GetTextByPath("a:pPr/@algn"); var align = "initial"; if (getAlgn != null) { switch (getAlgn.Value) { case "l": align = "left"; break; case "r": align = "right"; break; case "ctr": align = "center"; break; case "just": align = "justify"; break; case "dist": align = "justify"; break; default: align = "initial"; break; } } return align; } private string GetFontDecoration(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles) { if (node.GetTextByPath("a:rPr") != null) { var FontDecor = node.GetTextByPath("a:rPr/@u"); var underLine = FontDecor != null ? FontDecor.Value : "none"; var FontStrik = node.GetTextByPath("a:rPr/@strike"); var strikethrough = FontStrik != null ? FontStrik.Value : "noStrike"; if (underLine != "none" && strikethrough == "noStrike") { return "underline"; } else if (underLine == "none" && strikethrough != "noStrike") { return "line-through"; } else if (underLine != "none" && strikethrough != "noStrike") { return "underline line-through"; } else { return "initial"; } } else { return "initial"; } } private string GetFontItalic(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles) { var FontBold = node.GetTextByPath("a:rPr/@i"); if (FontBold != null) { if (FontBold.Value.Equals("1")) { return "italic"; } else { return "normal"; } } else { return "normal"; } } private string GetFontBold(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles) { var FontBold = node.GetTextByPath("a:rPr/@b"); if (FontBold != null) { if (FontBold.Value.Equals("1")) { return "bold"; } else { return "initial"; } } else { return "initial"; } } private string GetFontType(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles, XmlNode themeContent) { string typeface = "inherit"; XmlNode typefaceNode = node.GetTextByPath("a:rPr/a:latin/@typeface"); if (typefaceNode == null) { var fontSchemeNode = themeContent.GetTextByPath("a:theme/a:themeElements/a:fontScheme"); if (type != null && fontSchemeNode != null && (type.Value == "title" || type.Value == "subTitle" || type.Value == "ctrTitle")) { typefaceNode = fontSchemeNode.GetTextByPath("a:majorFont/a:latin/@typeface"); } else if (type != null && fontSchemeNode != null && type.Value == "body") { typefaceNode = fontSchemeNode.GetTextByPath("a:minorFont/a:latin/@typeface"); } else if(fontSchemeNode!=null) { typefaceNode = fontSchemeNode.GetTextByPath("a:minorFont/a:latin/@typeface"); } } if (typefaceNode != null) { typeface = typefaceNode.Value; } return typeface; } private async Task GenBuChar(XmlNode node, XmlNode spNode, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, WarpObj warpObj) { var sldMstrTxtStyles = warpObj.slideMasterTextStyles; var slideMasterContent = warpObj.slideMasterContent; var themeContent = warpObj.themeContent; var rNodes = node.GetTextByPathList("a:r"); XmlNode rNode = null; if (rNodes != null) { rNode = rNodes[0]; } dynamic dfltBultColor; double dfltBultSize; if (rNode != null) { dfltBultColor = GetFontColorPr(rNode, spNode, type, sldMstrTxtStyles, slideMasterContent, themeContent); dfltBultSize = GetFontSize(rNode, slideLayoutSpNode, slideMasterSpNode, type, sldMstrTxtStyles); } else { dfltBultColor = GetFontColorPr(node, spNode, type, sldMstrTxtStyles, slideMasterContent, themeContent); dfltBultSize = GetFontSize(node, slideLayoutSpNode, slideMasterSpNode, type, sldMstrTxtStyles); } //var bullet = ""; var pPrNode = node.GetTextByPath("a:pPr"); var getRtlVal = node.GetTextByPath("a:pPr/@rtl"); var isRTL = false; if (getRtlVal != null && getRtlVal.Equals("1")) { isRTL = true; } int lvl = 0; if (node.GetTextByPath("a:pPr/@lvl") != null) { lvl = int.Parse(node.GetTextByPath("a:pPr/@lvl").Value); } XmlNode buNum = null; XmlNode buPic = null; XmlNode buCharNode = null; XmlNode buClrNode = null; if (pPrNode != null) { buCharNode = pPrNode.GetTextByPath("a:buChar/@char"); buNum = pPrNode.GetTextByPath("a:buAutoNum/@type"); buPic = pPrNode.GetTextByPath("a:buBlip"); buClrNode= pPrNode.GetTextByPath("a:buClr"); } string buChar = ""; var buType = "TYPE_NONE"; if (buCharNode != null) { buChar = buCharNode.Value; buType = "TYPE_BULLET"; } if (buNum != null) { buType = "TYPE_NUMERIC"; } if (buPic != null) { buType = "TYPE_BULPIC"; } XmlNode buFontAttrs = null; if (buType != "TYPE_NONE" && pPrNode!=null) { buFontAttrs = pPrNode.GetTextByPath("a:buFont"); } var defBultColor = "NoNe"; string bultColor; if (buClrNode != null) { defBultColor = ShapeHelper.GetSolidFill(buClrNode, slideLayoutClrOvride, slideMasterContent, themeContent); } else { } if (defBultColor == "NoNe") { bultColor = dfltBultColor.color; } else { bultColor = "#" + defBultColor; } double bultSize; XmlNode buVal=null; if (pPrNode != null) { buVal = pPrNode.GetTextByPath("a:buSzPts/@val"); //pt } if (buVal != null) { bultSize = int.Parse(buVal.Value) / 100; } else { if (pPrNode != null) { buVal = pPrNode.GetTextByPath("a:buSzPct/@val"); } if (buVal != null) { var prcnt = int.Parse(buVal.Value) / 100000.0; //dfltBultSize = XXpt var dfltBultSizeNoPt = dfltBultSize; //pt bultSize = prcnt * (dfltBultSizeNoPt); } else { bultSize = dfltBultSize; } } double marginLeft = 0; double marginRight = 0; string typeface = ""; string Float = "left"; string Direction = "inherit"; BuChar BuChar = null; if (buType == "TYPE_BULLET") { if (buFontAttrs != null) { XmlNode marl = null; if (pPrNode != null) { marl = pPrNode.GetTextByPath("@marL"); } if (marl != null) { marginLeft = int.Parse(marl.Value) * px96 / px914400; if (buFontAttrs.GetTextByPath("@pitchFamily") != null) { marginRight = int.Parse(buFontAttrs.GetTextByPath("@pitchFamily").Value); } if (marginLeft == 0) { marginLeft = 328600 * px96 / px914400; } var typefaceNode = buFontAttrs.GetTextByPath("@typeface"); if (typefaceNode != null) { typeface = typefaceNode.Value; } if (isRTL) { Float = "right"; Direction = "rtl"; } marginLeft = marginLeft * lvl; } } else { marginLeft = 328600 * px96 / px914400 * lvl; } BuChar = new BuChar { typeface = typeface, left = marginLeft, riht = marginRight, size = bultSize, buchar = buChar, @float = Float, direction = Direction, type = "TYPE_BULLET" }; } else if (buType == "TYPE_NUMERIC") { if (buFontAttrs != null) { XmlNode marl = null; if (pPrNode != null) { marl = pPrNode.GetTextByPath("@marL"); } if (marl != null) { marginLeft = int.Parse(marl.Value) * px96 / px914400; if (buFontAttrs.GetTextByPath("@pitchFamily") != null) { marginRight = int.Parse(buFontAttrs.GetTextByPath("@pitchFamily").Value); } if (marginLeft == 0) { marginLeft = 328600 * px96 / px914400; } var typefaceNode = buFontAttrs.GetTextByPath("@typeface"); if (typefaceNode != null) { typeface = typefaceNode.Value; } else { typeface = "inherit"; } if (isRTL) { Float = "right"; Direction = "rtl"; } else { Float = "left"; Direction = "ltr"; } marginLeft = marginLeft * lvl; } } else { marginLeft = 328600 * 96 / 914400 * lvl; if (isRTL) { Float = "right"; Direction = "rtl"; } else { Float = "left"; Direction = "ltr"; } BuChar = new BuChar { typeface = typeface, left = marginLeft, riht = marginRight, size = bultSize, buchar = buChar, @float = Float, direction = Direction, type = "TYPE_NUMERIC" }; } } else if (buType == "TYPE_BULPIC") { XmlNode marl = null; if (pPrNode != null) { marl = pPrNode.GetTextByPath("@marL"); } if (marl != null) { marginLeft = int.Parse(marl.Value) * px96 / px914400; } else { marginLeft = 328600 * px96 / px914400; } XmlNode marR = null; if (pPrNode != null) { marR = pPrNode.GetTextByPath("@marR"); } if (marR != null) { marginRight = int.Parse(marR.Value) * px96 / px914400; } var buPicId = buPic.GetTextByPath("a:blip/@r:embed"); var buImg = ""; if (buPicId != null) { var imgPath = warpObj.slideResObj[buPicId.Value]; var imgData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + imgPath["target"] + "']"); if (imgData != null) { var imgFileExt = imgData.GetTextByPath("@pkg:contentType"); AzureBlobModel imgModel = await SaveBase64ToBolob(imgData.InnerText, imgFileExt.Value, fileShaCode + "/imgs", ""); buImg = imgModel.BlobUrl; } } else { buImg = "‣"; } if (isRTL) { Float = "right"; Direction = "rtl"; } marginLeft = marginLeft * lvl; BuChar = new BuChar { typeface = typeface, left = marginLeft, riht = marginRight, size = bultSize, buchar = buImg, @float = Float, direction = Direction, type = "TYPE_NUMERIC" }; } else { if (isRTL) { Float = "right"; Direction = "rtl"; } BuChar = new BuChar { typeface = typeface, left = 328600 * px96 / px914400 * lvl, riht = marginRight, size = bultSize, @float = Float, direction = Direction, type = "TYPE_NONE" }; } return BuChar; } private double GetFontSize(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, XmlNode slideMasterTextStyles) { double fontSize = 0; if (node.GetTextByPath("a:rPr/@sz") != null) { fontSize = int.Parse(node.GetTextByPath("a:rPr/@sz").Value) / 100.0; } if (fontSize == 0) { if (slideLayoutSpNode != null) { var sz = slideLayoutSpNode.GetTextByPath("p:txBody/a:lstStyle/a:lvl1pPr/a:defRPr/@sz"); if (sz != null) { fontSize = int.Parse(sz.Value) / 100.0; } } } XmlNode size = null; if (fontSize == 0) { if (type == null) { size = slideMasterTextStyles.GetTextByPath("p:otherStyle/a:lvl1pPr/a:defRPr/@sz"); } else if (type.Value.Equals("title") || type.Value.Equals("subTitle") || type.Value.Equals("ctrTitle")) { size = slideMasterTextStyles.GetTextByPath("p:titleStyle/a:lvl1pPr/a:defRPr/@sz"); } else if (type.Value.Equals("body")) { size = slideMasterTextStyles.GetTextByPath("p:bodyStyle/a:lvl1pPr/a:defRPr/@sz"); } else if (type.Value.Equals("dt") || type.Value.Equals("sldNum")) { fontSize = 12; } if (size != null) { fontSize = int.Parse(size.Value) / 100.0; } } var baseline = node.GetTextByPath("a:rPr/@baseline"); if (baseline != null && fontSize != 0) { fontSize -= 10; } //return isNaN(fontSize) ? "inherit" : (fontSize + "pt"); //如果fontSize为0 则 使用inherit 继承方式 return fontSize; } private dynamic GetFontColorPr(XmlNode node, XmlNode spNode, XmlNode type, XmlNode sldMstrTxtStyles, XmlNode slideMasterContent, XmlNode themeContent) { var rPrNode = node.GetTextByPath("a:rPr"); string filTyp, textBordr; string color = null; if (rPrNode != null) { filTyp = ShapeHelper.GetFillType(rPrNode); if (filTyp == "SOLID_FILL") { var solidFillNode = node.GetTextByPath("a:rPr/a:solidFill"); string colorstr = ShapeHelper.GetSolidFill(solidFillNode, slideLayoutClrOvride, slideMasterContent, themeContent); if (solidFillNode!=null) { color = ShapeHelper.ColorToning(solidFillNode.OuterXml, colorstr); } } else if (filTyp == "PATTERN_FILL") { var pattFill = node.GetTextByPath("a:rPr/a:pattFill"); Fill colorFill = ShapeHelper.GetPatternFill(pattFill, slideLayoutClrOvride, slideMasterContent, themeContent); if (colorFill != null && colorFill.grad.IsNotEmpty()) { color = colorFill.grad[0]; } else { color = "000000"; } } else { if (spNode != null) { var sPstyle = spNode.GetTextByPath("p:style/a:fontRef"); if (sPstyle != null) { string colorstr = ShapeHelper.GetSolidFill(sPstyle, slideLayoutClrOvride, slideMasterContent, themeContent); color = ShapeHelper.ColorToning(sPstyle.OuterXml, colorstr); } } } } if (color == null) { color = "000000"; } var txtBrdrNode = node.GetTextByPath("a:rPr/a:ln"); if (txtBrdrNode != null) { var txBrd = ShapeHelper.GetBorder(node, true, "text", slideLayoutClrOvride, slideMasterContent, themeContent); var brdSize = System.Math.Round(txBrd.width * (4 / 3.00),degree) + "px"; var brdClr = txBrd.color; textBordr = "-" + brdSize + " 0 " + brdClr + ", 0 " + brdSize + " " + brdClr + ", " + brdSize + " 0 " + brdClr + ", 0 -" + brdSize + " " + brdClr + ";"; } else { textBordr = "none"; } return new { color, textBordr }; } public string GetVerticalAlign(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode) { XmlDocument doc = new XmlDocument(); doc.LoadXml(node.OuterXml); XmlNode anchor = doc.GetTextByPath("//p:txBody/a:bodyPr/@anchor"); if (anchor == null) { if (slideLayoutSpNode != null) { doc.LoadXml(slideLayoutSpNode.OuterXml); anchor = doc.GetTextByPath("//p:txBody/a:bodyPr/@anchor"); } if (anchor == null && slideMasterSpNode != null) { doc.LoadXml(slideMasterSpNode.OuterXml); anchor = doc.GetTextByPath("//p:txBody/a:bodyPr/@anchor"); } } if (anchor != null) { return anchor.Value.Equals("ctr") ? "v-mid" : anchor.Value.Equals("b") ? "v-down" : "v-up"; } else { return "v-up"; } } public string GetWritingMode(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode) { XmlDocument doc = new XmlDocument(); doc.LoadXml(node.OuterXml); XmlNode vert = doc.GetTextByPath("//p:txBody/a:bodyPr/@vert"); if (vert == null) { if (slideLayoutSpNode != null) { doc.LoadXml(slideLayoutSpNode.OuterXml); vert = doc.GetTextByPath("//p:txBody/a:bodyPr/@vert"); } if (vert == null && slideMasterSpNode != null) { doc.LoadXml(slideMasterSpNode.OuterXml); vert = doc.GetTextByPath("//p:txBody/a:bodyPr/@vert"); } } if (vert != null) { return vert.Value; } else { return "horz"; } } public string GetHorizontalAlign(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode typeNode, XmlNode slideMasterTextStyles) { XmlDocument doc = new XmlDocument(); doc.LoadXml(node.OuterXml); XmlNode algn = doc.GetTextByPath("//a:pPr/@algn"); if (algn == null) { if (slideLayoutSpNode != null) { doc.LoadXml(slideLayoutSpNode.OuterXml); algn = doc.GetTextByPath("//p:txBody/a:p/a:pPr/@algn"); } if (algn == null && slideMasterSpNode != null) { doc.LoadXml(slideMasterSpNode.OuterXml); algn = doc.GetTextByPath("//p:txBody/a:p/a:pPr/@algn"); } if (algn == null && typeNode != null) { switch (typeNode.Value) { case "title": case "subTitle": case "ctrTitle": //doc.LoadXml(slideMasterStyle.TypeTable.OuterXml); doc.LoadXml(slideMasterTextStyles.OuterXml); algn = doc.GetTextByPath("//p:titleStyle/a:lvl1pPr/@algn"); break; case "body": doc.LoadXml(slideMasterTextStyles.OuterXml); algn = doc.GetTextByPath("//p:bodyStyle/a:lvl1pPr/@algn"); break; default: // doc.LoadXml(slideMasterStyle.TypeTable.OuterXml); doc.LoadXml(slideMasterTextStyles.OuterXml); algn = doc.GetTextByPath("//p:otherStyle/a:lvl1pPr/@algn"); break; } } } if (algn == null) { if (typeNode == null) { return "h-left"; } if (typeNode.Value.Equals("title") || typeNode.Value.Equals("subTitle") || typeNode.Value.Equals("ctrTitle")) { return "h-mid"; } else if (typeNode.Value == "sldNum") { return "h-right"; } else if (typeNode.Value.Equals("body")) { return "h-left"; } } return algn.Value.Equals("ctr") ? "h-mid" : algn.Value.Equals("r") ? "h-right" : "h-left"; } /// /// 幻灯片 背景色填充 /// /// /// /// /// /// /// public async Task GetSlideBackgroundFill(XmlNode slideContent, int index, WarpObj warpObj) { var bgPr = slideContent.GetTextByPath("pkg:xmlData/p:sld/p:cSld/p:bg/p:bgPr"); var bgRef = slideContent.GetTextByPath("pkg:xmlData/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); if (sldFill!=null) { bgColor = ShapeHelper.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 = ShapeHelper.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); } if(nodeList[trueIdx - 1]!=null) { phClr = ShapeHelper.ColorToning(nodeList[trueIdx - 1].OuterXml, 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); //#... //} } else { bgPr = warpObj.slideLayoutContent.GetTextByPath("pkg:xmlData/p:sldLayout/p:cSld/p:bg/p:bgPr"); bgRef = warpObj.slideLayoutContent.GetTextByPath("pkg:xmlData/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); if (sldFill != null) { bgColor = ShapeHelper.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("layoutBg", bgPr.GetTextByPath("a:blipFill"), warpObj); } } else if (bgRef != null) { string phClr = ShapeHelper.GetSolidFill(bgRef, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent); phClr = ShapeHelper.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); } if (nodeList[trueIdx - 1] != null) { phClr = ShapeHelper.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 }; } } } } } } else { bgPr = warpObj.slideMasterContent.GetTextByPath("pkg:xmlData/p:sldMaster/p:cSld/p:bg/p:bgPr"); bgRef = warpObj.slideMasterContent.GetTextByPath("pkg:xmlData/p:sldMaster/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); if (sldFill != null) { bgColor = ShapeHelper.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("masterBg", bgPr.GetTextByPath("a:blipFill"), warpObj); } } else if (bgRef != null) { string phClr = ShapeHelper.GetSolidFill(bgRef, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent); phClr = ShapeHelper.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); } if (nodeList[trueIdx - 1] != null) { phClr = ShapeHelper.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 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 imgPath = new Dictionary(); 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); XmlNode fillRect_node = node.GetTextByPath("a:stretch/a:fillRect"); Fill fill = new Fill { type = 3, image = model.BlobUrl }; if (fillRect_node != null) { FillStyle fillStyle = new FillStyle(); XmlNode left = node.GetTextByPath("a:stretch/a:fillRect/@l"); XmlNode top = node.GetTextByPath("a:stretch/a:fillRect/@t"); XmlNode right = node.GetTextByPath("a:stretch/a:fillRect/@r"); XmlNode bottom = node.GetTextByPath("a:stretch/a:fillRect/@b"); if (left != null) { fillStyle.left = int.Parse(left.Value); } if (top != null) { fillStyle.top = int.Parse(top.Value); } if (right != null) { fillStyle.right = int.Parse(right.Value); } if (bottom != null) { fillStyle.bottom = int.Parse(bottom.Value); } fill.style = fillStyle; } return fill; } else { return null; } // var imgArrayBuffer = warpObj.zip.GetTextByPath(imgPath).Value.asArrayBuffer(); //var imgMimeType = GetMimeType(imgExt); //img = "data:" + imgMimeType + ";base64," + base64ArrayBuffer(imgArrayBuffer); } public async Task GetShapeFill(XmlNode node, WarpObj warpObj) { // 1. presentationML // p:spPr/ [a:noFill, solidFill, gradFill, blipFill, pattFill, grpFill] // From slide //Fill Type: 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 = "none" }; //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); }//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") { /* * * */ 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"); string color = ShapeHelper.GetSolidFill(clrName, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent); if (clrName != null) { fillType = "SOLID_FILL"; color = ShapeHelper.ColorToning(clrName.OuterXml, color); fill = new Fill { type = 1, color = color, }; } } if (fill != null) { if (fillType == "GRADIENT_FILL") { //if (isSvgMode) //{ // return fill; //} //else //{ // var colorAry = fill.grad; // 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 { //if (isSvgMode) //{ // var color = new colz.Color(fill); // fill = color.rgb.toString(); //fill.HtmlText = "background-color: #" + fill.Color + ";"; return fill; //} //else //{ // return fill; //} } } else { //if (isSvgMode) //{ // return fill; //} //else //{ fill = new Fill { type = 0 }; //fill.SvgText = "none"; //fill.HtmlText = "background-color: initial;"; return fill; // } } } public async Task 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 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 ProcessPicNode(XmlNode node, int order, WarpObj warpObj) { var xfrmList = "p:spPr/a:xfrm"; var xfrmNode = node.GetTextByPath(xfrmList); Media media = new Media() { type = "Media" }; 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); //string sha = null; //if (fill != null && fill.Type!=0) { // sha = ShaHashHelper.GetSHA1(fill.ToJson()); // warpObj.pptx.Fills.TryAdd(sha, fill); //} // media.FillSha = sha; media.fill = fill; Border border = ShapeHelper.GetBorder(node, true, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent); //if (border != null && border.Type!=null) { // media.BorderSha =ShaHashHelper.GetSHA1(border.ToJson()); // warpObj.pptx.Borders.TryAdd(media.BorderSha, border); //} media.border = border; Position position = ShapeHelper.GetPosition(xfrmNode, slideLayoutXfrmNode, slideMasterXfrmNode); media.position = position; position.rot = System.Math.Round(rotate,degree); //var rtrnData = ""; //image var rid = node.GetTextByPath("p:blipFill/a:blip/@r:embed"); if (rid != null) { var imgName = warpObj.slideResObj[rid.Value]["target"]; 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"; media.index = order; } } ///////////////////////////////////////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"; media.index = order; } /// 处理为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"; media.index = order; } //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; } ////////////////////////////////////////////////////////////////////////// //mimeType = imgFileExt; //rtrnData = "
"; //if ((vdoNode ==null && audioNode ==null) || !mediaSupportFlag) //{ // rtrnData += ""; //} //else if ((vdoNode !=null || audioNode !=null) && mediaSupportFlag) //{ // if (vdoNode !=null) // { // rtrnData += ""; // } // if (audioNode !=null) // { // rtrnData += ""; // } //} //rtrnData += "This media file Not supported by HTML5"; //if ((vdoNode != null || audioNode != null) && mediaSupportFlag) //{ //} // rtrnData += "
"; return media; } } }