123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196 |
- 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.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 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 const int degree = 3;
- 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"))
- {
-
- return await ConvertPPTX(file, 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
- Dictionary<string, object> data = new Dictionary<string, object> { { "data",rslt_ary} };
- return data;
- }
- /// <summary>
- /// 加载PPTX文件
- /// </summary>
- /// <param name="presentationFile"></param>
- /// <returns></returns>
- public async Task< Dictionary<string, object>> ProcessPPTX(XmlDocument xdoc, string shaCode)
- {
- // List<Dictionary<string, object>> post_ary = new List<Dictionary<string, object>>();
- Dictionary<string, object> post_ary = new Dictionary<string, object>();
- var dateBefore = DateTimeOffset.Now.UtcTicks;
- AzureBlobModel thumbnailModel = await GetThumbnailModel(xdoc, shaCode);
- post_ary.Add( "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( "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<Slide> slides = new List<Slide>();
- for (int i = 0; i < numOfSlides; i++)
- {
- string filename = slideNodes[i].GetTextByPath("@pkg:name").Value;
- //处理当前页的幻灯片
- Slide slide = await ProcessSingleSlide(xdoc, slideNodes[i], filename, i, slideSize, themeContent);
- slides.Add(slide);
- // 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( "slide", slides );
- //post_ary.Add( "globalCSS", GenGlobalCSS() );
- var dateAfter = DateTimeOffset.Now.UtcTicks;
- // post_ary.Add( "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<Slide> 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 = await 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
- 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<Item> items = new List<Item>();
- 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<Item> 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
- 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");
- Item mcitem = await ProcessSpNode(mcFallbackNode, order, warpObj);
- if (mcitem != null)
- {
- items.Add(mcitem);
- }
- break;
- default:
- break;
- }
- }
- public async Task ProcessGroupSpNode(List<Item> 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 = "<div class='block group' style='z-index: " + order + "; top: " + (y - chy) + "px; left: " + (x - chx) + "px;" +
- " width: " + (cx - chcx) + "px; height: " + (cy - chcy) + "px;'>";
- Group group = new Group();
- group.Position = new Position { X = x - chx, Y = y - chy, Cx = cx - chcx, Cy = cy - chcy, Rot = rotate };
- group.Type = "Group";
- group.Index = order++;
- // Procsee all child nodes
- var nodes = node.ChildNodes;
- List<Item> gpIterm = new List<Item>();
- foreach (XmlNode nd in nodes)
- {
- await ProcessNodesInSlide(gpIterm, nd.Name, nd, order, warpObj);
- order += 1;
- }
- group.Shapes = gpIterm;
- items.Add(group);
- result += "</div>";
- //return result;
- }
- public string ProcessGraphicFrameNode(List<Item> 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":
- 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<Item> 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<Item> 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"]);
- }
- }
- Item item = await GenShape("Sp", node, slideLayoutSpNode, slideMasterSpNode, id, name, idx, type, order, warpObj);
- return item;
- }
- public async Task<Item> 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 = 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");
- 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("<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 (Fill.Type==2)//== "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);
- 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 = "<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>";
- shapeSvg.Defs = triangleMarker;
- result += triangleMarker;
- }
- result += "</defs>";
- }
- 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 (Fill.Type == 0)
- {
- shape.Fill = null;
- }
- else {
- shape.Fill = Fill;
- }
- var txbody = node.GetTextByPath("p:txBody");
- if (txbody != null)
- {
- List<Paragraph> paragraphs = await GenTextBody(txbody, node, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
- shape.Paragraph = paragraphs;
- }
- return shape;
- }
- else if (ShapeType.Equals("CxnSp"))
- {
- 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<HiTeachCC.Model.PowerPoint.Path> Paths = new List<Model.PowerPoint.Path>();
- 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"))
- {
- XmlNodeList nodeList = childNode.ChildNodes;
- var wR = double.Parse(nodeList.Item(0).GetTextByPath("@wR").Value) * px96 / px914400;
- var hR = double.Parse(nodeList.Item(0).GetTextByPath("@hR").Value) * px96 / px914400;
- var stAng = double.Parse(nodeList.Item(0).GetTextByPath("@stAng").Value) * px96 / px914400;
- var swAng = double.Parse(nodeList.Item(0).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 + ")' ";
- //}
- List<SvgShape> shapes = new List<SvgShape>() {
- 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,
- MarkerStart="url(#markerTriangle_" + order + ")",
- MarkerEnd="url(#markerTriangle_" + order + ")"
- }
- };
- shapeSvg.SvgShape = shapes;
- // shapeSvg.SvgData = result;
- Shape shape = new Shape { Border = shapeBorder, Svg = shapeSvg, Type = "Sp", Position = position, Index = order, ShapeType = "custom" };
- if (Fill.Type == 0)
- {
- shape.Fill = null;
- }
- else
- {
- shape.Fill = Fill;
- }
- var txbody = node.GetTextByPath("p:txBody");
- if (txbody != null)
- {
- List<Paragraph> 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 (Fill.Type == 0)
- {
- shape.Fill = null;
- }
- else
- {
- shape.Fill = Fill;
- }
- var txbody = node.GetTextByPath("p:txBody");
- if (txbody != null)
- {
- List<Paragraph> paragraphs = await GenTextBody(txbody, node, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
- shape.Paragraph = paragraphs;
- }
- return shape;
- }
-
- }
- private async Task<List<Paragraph>> GenTextBody(XmlNode textBodyNode, XmlNode spNode, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, WarpObj warpObj)
- {
- List<Paragraph> paragraphs = new List<Paragraph>();
- var slideMasterTextStyles = warpObj.slideMasterTextStyles;
- string vert = GetVerticalAlign(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 HorizontalAlign = GetHorizontalAlign(pNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles);
- Paragraph paragraph = new Paragraph
- {
- BuChar = buChar,
- ParagraphStyle = new ParagraphStyle
- {
- VertAlign = vert,
- HoriAlign = HorizontalAlign
- }
- };
- 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<Text> texts = new List<Text> { text };
- paragraph.Texts = texts;
- }
- else
- {
- List<Text> texts = new List<Text>();
- 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;
- int 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<string, string> css))
- {
- cssName = css["name"];
- }
- else
- {
- cssName = "_css_" + (styleTable.Keys.Count + 1);
- styleTable.TryAdd(styleText, new Dictionary<string, string> { { "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"];
- }
- return new Text
- {
- Content = text,
- Href = linkURL,
- 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
- }
- };
- }
- private string GetTextVerticalAlign(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles)
- {
- var baseline = node.GetTextByPath("a:rPr/@baseline");
- if (baseline != null)
- {
- return int.Parse(baseline.Value) / 1000 + "%";
- }
- 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<BuChar> 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;
- int 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;
- }
- int 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;
- //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,
- MarginLeft = marginLeft,
- MarginRiht = marginRight,
- FontSize = 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,
- MarginLeft = marginLeft,
- MarginRiht = marginRight,
- FontSize = 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,
- MarginLeft = marginLeft,
- MarginRiht = marginRight,
- FontSize = bultSize,
- Buchar = buImg,
- Float = Float,
- Direction = Direction,
- Type = "TYPE_NUMERIC"
- };
- }
- else
- {
- if (isRTL)
- {
- Float = "right";
- Direction = "rtl";
- }
- BuChar = new BuChar
- {
- Typeface = typeface,
- MarginLeft = 328600 * px96 / px914400 * lvl,
- MarginRiht = marginRight,
- FontSize = bultSize,
- Float = Float,
- Direction = Direction,
- Type = "TYPE_NONE"
- };
- }
- return BuChar;
- }
- private int GetFontSize(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, XmlNode slideMasterTextStyles)
- {
- int fontSize = 0;
- if (node.GetTextByPath("a:rPr/@sz") != null)
- {
- fontSize = int.Parse(node.GetTextByPath("a:rPr/@sz").Value) / 100;
- }
- 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;
- }
- }
-
- }
- 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;
- }
- }
- 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 = PowerPointHelper.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.gradColor.IsNotEmpty())
- {
- color = colorFill.gradColor[0];
- }
- else
- {
- color = "000000";
- }
- }
- else
- {
- var sPstyle = spNode.GetTextByPath("p:style/a:fontRef");
- if (sPstyle != null)
- {
- string colorstr = ShapeHelper.GetSolidFill(sPstyle, slideLayoutClrOvride, slideMasterContent, themeContent);
- color = PowerPointHelper.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 = txBrd.Width * (4 / 3) + "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 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";
- }
- /// <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);
- if (sldFill!=null) {
- 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);
- }
- if(nodeList[trueIdx - 1]!=null)
- {
- phClr = PowerPointHelper.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("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);
- if (sldFill!=null) {
- 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);
- }
- if (nodeList[trueIdx - 1] != null) {
- 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:
- 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")
- {
- /*
- *
- *<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");
- string color = ShapeHelper.GetSolidFill(clrName, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- if (clrName != null)
- {
- fillType = "SOLID_FILL";
- color = PowerPointHelper.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.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
- //{
- // 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 = "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);
- 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"];
-
- 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;
- }
- //////////////////////////////////////////////////////////////////////////
- //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)
- //{
- //}
- rtrnData += "</div>";
- return media;
- }
- }
- }
|