ShapeGenerator.cs 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196
  1. using DocumentFormat.OpenXml.Packaging;
  2. using HiTeachCC.Model.PowerPoint;
  3. using HiTeachCC.Service.PowerPoint.Interface;
  4. using Microsoft.AspNetCore.Http;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Xml;
  11. using System.Xml.Linq;
  12. using TEAMModelOS.SDK.Context.Constant;
  13. using TEAMModelOS.SDK.Context.Constant.Common;
  14. using TEAMModelOS.SDK.Context.Exception;
  15. using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
  16. using TEAMModelOS.SDK.Helper.Security.ShaHash;
  17. using TEAMModelOS.SDK.Module.AzureBlob.Container;
  18. using TEAMModelOS.SDK.Module.AzureBlob.Interfaces;
  19. using TEAMModelOS.Service.Models.PowerPoint.Inner;
  20. using TEAMModelOS.Service.Services.PowerPoint.Implement;
  21. using Fill = HiTeachCC.Model.PowerPoint.Fill;
  22. using Media = HiTeachCC.Model.PowerPoint.Media;
  23. using Position = HiTeachCC.Model.PowerPoint.Position;
  24. namespace HiTeachCC.Service.PowerPoint.Implement
  25. {
  26. public class ShapeGenerator : IShapeGenerator
  27. {
  28. private string fileShaCode { get; set; }
  29. private bool isDone = false;
  30. private List<object> MsgQueue = new List<object>();
  31. private Dictionary<string, string> slideLayoutClrOvride { get; set; }
  32. // private XmlNode themeContent { get; set; }
  33. private const int degree = 3;
  34. private int chartID = 0;
  35. private int _order = 1;
  36. private int titleFontSize = 42;
  37. private int bodyFontSize = 20;
  38. private int otherFontSize = 16;
  39. private bool isSlideMode = false;
  40. private Dictionary<string, Dictionary<string, string>> styleTable = new Dictionary<string, Dictionary<string, string>>();
  41. private const double px96 = 96.00, px72 = 72.00, px914400 = 914400.00, px12700 = 12700.00;
  42. private const double rot60000 = 60000.00;
  43. public readonly IAzureBlobDBRepository azureBlobDBRepository;
  44. public ShapeGenerator(IAzureBlobDBRepository _azureBlobDBRepository)
  45. {
  46. azureBlobDBRepository = _azureBlobDBRepository;
  47. }
  48. public async Task<Dictionary<string, object>> LoadPresentation(IFormFile file)
  49. {
  50. Dictionary<string, object> resdict = new Dictionary<string, object>();
  51. if (FileType.GetExtention(file.FileName).ToLower().Equals("pptx"))
  52. {
  53. return await ConvertPPTX(file, resdict);
  54. }
  55. else if (FileType.GetExtention(file.FileName).ToLower().Equals("pdf"))
  56. {
  57. // await ProcessPDF(file, resdict);
  58. return resdict;
  59. }
  60. else
  61. {
  62. throw new BizException("file type does not support!", 500);
  63. }
  64. }
  65. public async Task<Dictionary<string, object>> ConvertPPTX(IFormFile file, Dictionary<string, object> resdict)
  66. {
  67. string shaCode = fileShaCode = ShaHashHelper.GetSHA1(file.OpenReadStream());
  68. PresentationDocument presentationDocument = PresentationDocument.Open(file.OpenReadStream(), false);
  69. if (presentationDocument == null)
  70. {
  71. throw new ArgumentNullException("presentationDocument");
  72. }
  73. XDocument xdoc = presentationDocument.ToFlatOpcDocument();
  74. XmlDocument xmlDocument = new XmlDocument();
  75. xmlDocument.LoadXml(xdoc.ToString());
  76. var rslt_ary = await ProcessPPTX(xmlDocument, shaCode);
  77. //TODO
  78. Dictionary<string, object> data = new Dictionary<string, object> { { "data",rslt_ary} };
  79. return data;
  80. }
  81. /// <summary>
  82. /// 加载PPTX文件
  83. /// </summary>
  84. /// <param name="presentationFile"></param>
  85. /// <returns></returns>
  86. public async Task< Dictionary<string, object>> ProcessPPTX(XmlDocument xdoc, string shaCode)
  87. {
  88. // List<Dictionary<string, object>> post_ary = new List<Dictionary<string, object>>();
  89. Dictionary<string, object> post_ary = new Dictionary<string, object>();
  90. var dateBefore = DateTimeOffset.Now.UtcTicks;
  91. AzureBlobModel thumbnailModel = await GetThumbnailModel(xdoc, shaCode);
  92. post_ary.Add( "pptx-thumb", thumbnailModel );
  93. //获取全部的/ppt/slides/slide1.xml--->>/ppt/slides/slide(n).xml
  94. var slideNodes = xdoc.GetTextByPathList("//pkg:part[@pkg:contentType='application/vnd.openxmlformats-officedocument.presentationml.slide+xml']");
  95. //获取全部的/ppt/slideLayouts/slideLayout1.xml--->>/ppt/slideLayouts/slideLayout(n).xml
  96. var slideLayoutNodes = xdoc.GetTextByPathList("//pkg:part[@pkg:contentType='application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml']");
  97. //获取ppt的宽高
  98. var slideSize = ShapeHelper.GetSlideSize(xdoc);
  99. post_ary.Add( "slideSize", slideSize );
  100. //加载当前PPT使用到的PPT节点
  101. var themeContent = LoadTheme(xdoc);
  102. //获取所有的表格样式节点
  103. var tableStyles = xdoc.GetTextByPath("//pkg:part[@pkg:name='/ppt/tableStyles.xml']/pkg:xmlData/a:tblStyleLst");
  104. //处理slide1---slide(n)
  105. int numOfSlides = slideNodes.Count;
  106. List<Slide> slides = new List<Slide>();
  107. for (int i = 0; i < numOfSlides; i++)
  108. {
  109. string filename = slideNodes[i].GetTextByPath("@pkg:name").Value;
  110. //处理当前页的幻灯片
  111. Slide slide = await ProcessSingleSlide(xdoc, slideNodes[i], filename, i, slideSize, themeContent);
  112. slides.Add(slide);
  113. // post_ary.Add(new Dictionary<string, object> { { "slide", slideHtml } });
  114. // post_ary.Add(new Dictionary<string, object> { { "progress-update", (i + 1) * 100 / numOfSlides } });
  115. }
  116. post_ary.Add( "slide", slides );
  117. //post_ary.Add( "globalCSS", GenGlobalCSS() );
  118. var dateAfter = DateTimeOffset.Now.UtcTicks;
  119. // post_ary.Add( "ExecutionTime", dateAfter - dateBefore );
  120. return post_ary;
  121. }
  122. public Dictionary<string, string> GenGlobalCSS()
  123. {
  124. Dictionary<string, string> cssText = new Dictionary<string, string>();
  125. foreach (var key in styleTable.Keys)
  126. {
  127. // cssText += "div ." + styleTable[key]["name"] + "{" + styleTable[key]["text"] + "}\n"; //section > div
  128. var cssTextKey = styleTable[key]["name"];
  129. var cssTextValue = styleTable[key]["text"];
  130. cssText.Add(cssTextKey, cssTextValue);
  131. }
  132. return cssText;
  133. }
  134. public async Task<Slide> ProcessSingleSlide(XmlDocument xdoc, XmlNode xnode, string sldFileName, int index, dynamic slideSize, XmlNode themeContent)
  135. {
  136. var resName = sldFileName.Replace("slides/slide", "slides/_rels/slide") + ".rels";
  137. var RelationshipArray = xdoc.GetTextByPathList("//pkg:part[@pkg:name='" + resName + "']/pkg:xmlData/rel:Relationships/rel:Relationship");
  138. Dictionary<string, Dictionary<string, string>> slideResObj = new Dictionary<string, Dictionary<string, string>>();
  139. var layoutFilename = "";
  140. foreach (XmlNode Relationship in RelationshipArray)
  141. {
  142. var RelationshipType = Relationship.GetTextByPath("@Type");
  143. if (RelationshipType.Value.Equals("http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout"))
  144. {
  145. layoutFilename = Relationship.GetTextByPath("@Target").Value.Replace("../", "/ppt/");
  146. }
  147. else
  148. {
  149. //case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide":
  150. //case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image":
  151. //case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart":
  152. //case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink":
  153. Dictionary<string, string> dict = new Dictionary<string, string>();
  154. string Type = Relationship.GetTextByPath("@Type").Value.Replace("http://schemas.openxmlformats.org/officeDocument/2006/relationships/", "");
  155. string Target = Relationship.GetTextByPath("@Target").Value.Replace("../", "/ppt/");
  156. string Id = Relationship.GetTextByPath("@Id").Value;
  157. dict.Add("type", Type);
  158. dict.Add("target", Target);
  159. slideResObj.Add(Id, dict);
  160. }
  161. }
  162. // Open slideLayoutXX.xml
  163. var slideLayoutContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + layoutFilename + "']");
  164. NodesTable slideLayoutTables = ShapeHelper.IndexNodes(slideLayoutContent.GetTextByPath("pkg:xmlData/p:sldLayout"));
  165. ///ppt/slides/slide5.xml 也包含a:overrideClrMapping
  166. ////ppt/slideLayouts/slideLayout13.xml 也包含a:overrideClrMapping
  167. var sldLayoutClrOvr = slideLayoutContent.GetTextByPath("pkg:xmlData/p:sldLayout/p:clrMapOvr/a:overrideClrMapping");
  168. if (sldLayoutClrOvr != null)
  169. {
  170. //获取 overrideClrMapping所有属性节点
  171. slideLayoutClrOvride = new Dictionary<string, string>() {
  172. { "accent1", sldLayoutClrOvr.GetTextByPath("@accent1").Value},
  173. { "accent2", sldLayoutClrOvr.GetTextByPath("@accent2").Value},
  174. { "accent3", sldLayoutClrOvr.GetTextByPath("@accent3").Value},
  175. { "accent4", sldLayoutClrOvr.GetTextByPath("@accent4").Value},
  176. { "accent5", sldLayoutClrOvr.GetTextByPath("@accent5").Value},
  177. { "accent6", sldLayoutClrOvr.GetTextByPath("@accent6").Value},
  178. { "bg1", sldLayoutClrOvr.GetTextByPath("@bg1").Value},
  179. { "bg2", sldLayoutClrOvr.GetTextByPath("@bg2").Value},
  180. { "folHlink", sldLayoutClrOvr.GetTextByPath("@folHlink").Value},
  181. { "hlink", sldLayoutClrOvr.GetTextByPath("@hlink").Value},
  182. { "tx1", sldLayoutClrOvr.GetTextByPath("@tx1").Value},
  183. { "tx2", sldLayoutClrOvr.GetTextByPath("@tx2").Value}
  184. };
  185. }
  186. // =====< Step 2 >=====
  187. // Read slide master filename of the slidelayout (Get slideMasterXX.xml)
  188. // @resName: ppt/slideLayouts/slideLayout1.xml
  189. // @masterName: ppt/slideLayouts/_rels/slideLayout1.xml.rels
  190. var slideLayoutResFilename = layoutFilename.Replace("slideLayouts/slideLayout", "slideLayouts/_rels/slideLayout") + ".rels";
  191. var slideLayoutResContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + slideLayoutResFilename + "']");
  192. ///查看js 是替换之前 还是添加
  193. RelationshipArray = slideLayoutResContent.GetTextByPathList("pkg:xmlData/rel:Relationships/rel:Relationship");
  194. var masterFilename = "";
  195. Dictionary<string, Dictionary<string, string>> layoutResObj = new Dictionary<string, Dictionary<string, string>>();
  196. for (int i = 0; i < RelationshipArray.Count; i++)
  197. {
  198. if (RelationshipArray[i].GetTextByPath("@Type").Value.Equals("http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster"))
  199. {
  200. masterFilename = RelationshipArray[i].GetTextByPath("@Target").Value.Replace("../", "/ppt/");
  201. }
  202. else
  203. {
  204. Dictionary<string, string> dict = new Dictionary<string, string>();
  205. string Type = RelationshipArray[i].GetTextByPath("@Type").Value.Replace("http://schemas.openxmlformats.org/officeDocument/2006/relationships/", "");
  206. string Target = RelationshipArray[i].GetTextByPath("@Target").Value.Replace("../", "/ppt/");
  207. string Id = RelationshipArray[i].GetTextByPath("@Id").Value;
  208. dict.Add("type", Type);
  209. dict.Add("target", Target);
  210. layoutResObj.Add(Id, dict);
  211. }
  212. }
  213. // Open slideMasterXX.xml
  214. var slideMasterContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + masterFilename + "']");
  215. var slideMasterTextStyles = slideMasterContent.GetTextByPath("pkg:xmlData/p:sldMaster/p:txStyles");
  216. var slideMasterTables = ShapeHelper.IndexNodes(slideMasterContent.GetTextByPath("pkg:xmlData/p:sldMaster"));
  217. /////////////////Amir/////////////
  218. //Open slideMasterXX.xml.rels
  219. var slideMasterResFilename = masterFilename.Replace("slideMasters/slideMaster", "slideMasters/_rels/slideMaster") + ".rels";
  220. var slideMasterResContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + slideMasterResFilename + "']");
  221. RelationshipArray = slideMasterResContent.GetTextByPathList("pkg:xmlData/rel:Relationships/rel:Relationship");
  222. var themeFilename = "";
  223. Dictionary<string, Dictionary<string, string>> masterResObj = new Dictionary<string, Dictionary<string, string>>();
  224. for (int i = 0; i < RelationshipArray.Count; i++)
  225. {
  226. if (RelationshipArray[i].GetTextByPath("@Type").Value.Equals("http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"))
  227. {
  228. themeFilename = RelationshipArray[i].GetTextByPath("@Target").Value.Replace("../", "/ppt/");
  229. }
  230. else
  231. {
  232. Dictionary<string, string> dict = new Dictionary<string, string>();
  233. string Type = RelationshipArray[i].GetTextByPath("@Type").Value.Replace("http://schemas.openxmlformats.org/officeDocument/2006/relationships/", "");
  234. string Target = RelationshipArray[i].GetTextByPath("@Target").Value.Replace("../", "/ppt/");
  235. string Id = RelationshipArray[i].GetTextByPath("@Id").Value;
  236. dict.Add("type", Type);
  237. dict.Add("target", Target);
  238. masterResObj.Add(Id, dict);
  239. }
  240. }
  241. //Load Theme file
  242. if (!string.IsNullOrEmpty(themeFilename))
  243. {
  244. themeContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + themeFilename + "']");
  245. }
  246. // =====< Step 3 >===== throw new NotImplementedException();
  247. var slideContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + sldFileName + "']");
  248. var spTreeNode = slideContent.GetTextByPath("pkg:xmlData/p:sld/p:cSld/p:spTree");
  249. WarpObj warpObj = new WarpObj
  250. {
  251. zip = xdoc,
  252. slideLayoutTables = slideLayoutTables,
  253. slideMasterTables = slideMasterTables,
  254. slideMasterTextStyles = slideMasterTextStyles,
  255. slideResObj = slideResObj,
  256. layoutResObj = layoutResObj,
  257. masterResObj = masterResObj,
  258. slideLayoutContent = slideLayoutContent,
  259. slideMasterContent = slideMasterContent,
  260. themeContent = themeContent
  261. };
  262. var bgColor = await GetSlideBackgroundFill(slideContent, index, warpObj);
  263. string result = "<div class='slide' style='width:" + slideSize.width + "px; height:" + slideSize.height + "px;" + bgColor + "'>";
  264. //result += "<div>"+getBackgroundShapes(slideContent, slideLayoutContent, slideMasterContent,warpObj) + "</div>" - TODO
  265. Slide slide = new Slide { Fill=bgColor ,Width= slideSize .width ,Height= slideSize .height ,Index=index};
  266. if (spTreeNode != null)
  267. {
  268. var nodes = spTreeNode.ChildNodes;
  269. int order = 1;
  270. List<Item> items = new List<Item>();
  271. foreach (XmlNode node in nodes)
  272. {
  273. await ProcessNodesInSlide(items, node.Name, node, order, warpObj);
  274. order += 1;
  275. }
  276. slide.Item = items;
  277. }
  278. return slide;
  279. }
  280. public async Task ProcessNodesInSlide(List<Item> items, string nodeKey, XmlNode node, int order, WarpObj warpObj)
  281. {
  282. // string result = "";
  283. switch (nodeKey)
  284. {
  285. case "p:sp": // Shape, Text
  286. Item spitem= await ProcessSpNode(node, order, warpObj);
  287. if (spitem != null) {
  288. items.Add(spitem);
  289. }
  290. break;
  291. case "p:cxnSp": // Shape, Text (with connection)
  292. Item cxnitem = await ProcessCxnSpNode(node, order, warpObj);
  293. if (cxnitem != null)
  294. {
  295. items.Add(cxnitem);
  296. }
  297. break;
  298. case "p:pic": // Picture
  299. Item picitem = await ProcessPicNode(node, order, warpObj);
  300. if (picitem != null) {
  301. items.Add(picitem);
  302. }
  303. break;
  304. case "p:graphicFrame": // Chart, Diagram, Table
  305. ProcessGraphicFrameNode(items, node, order, warpObj);
  306. break;
  307. case "p:grpSp":
  308. await ProcessGroupSpNode(items, node, order, warpObj);
  309. break;
  310. case "mc:AlternateContent": //Equations and formulas as Image 处理公式 方程等
  311. var mcFallbackNode = node.GetTextByPath("mc:Fallback/p:sp");
  312. Item mcitem = await ProcessSpNode(mcFallbackNode, order, warpObj);
  313. if (mcitem != null)
  314. {
  315. items.Add(mcitem);
  316. }
  317. break;
  318. default:
  319. break;
  320. }
  321. }
  322. public async Task ProcessGroupSpNode(List<Item> items, XmlNode node, int order, WarpObj warpObj)
  323. {
  324. var factor = 1.00 * px96 / px914400;
  325. var xfrmNode = node.GetTextByPath("p:grpSpPr/a:xfrm");
  326. var x = int.Parse(xfrmNode.GetTextByPath("a:off/@x").Value) * factor;
  327. var y = int.Parse(xfrmNode.GetTextByPath("a:off/@y").Value) * factor;
  328. var chx = int.Parse(xfrmNode.GetTextByPath("a:chOff/@x").Value) * factor;
  329. var chy = int.Parse(xfrmNode.GetTextByPath("a:chOff/@y").Value) * factor;
  330. var cx = int.Parse(xfrmNode.GetTextByPath("a:ext/@cx").Value) * factor;
  331. var cy = int.Parse(xfrmNode.GetTextByPath("a:ext/@cy").Value) * factor;
  332. var chcx = int.Parse(xfrmNode.GetTextByPath("a:chExt/@cx").Value) * factor;
  333. var chcy = int.Parse(xfrmNode.GetTextByPath("a:chExt/@cy").Value) * factor;
  334. var rotate = ShapeHelper.AngleToDegrees(xfrmNode.GetTextByPath("@rot"));
  335. string result = "<div class='block group' style='z-index: " + order + "; top: " + (y - chy) + "px; left: " + (x - chx) + "px;" +
  336. " width: " + (cx - chcx) + "px; height: " + (cy - chcy) + "px;'>";
  337. Group group = new Group();
  338. group.Position = new Position { X = x - chx, Y = y - chy, Cx = cx - chcx, Cy = cy - chcy, Rot = rotate };
  339. group.Type = "Group";
  340. group.Index = order++;
  341. // Procsee all child nodes
  342. var nodes = node.ChildNodes;
  343. List<Item> gpIterm = new List<Item>();
  344. foreach (XmlNode nd in nodes)
  345. {
  346. await ProcessNodesInSlide(gpIterm, nd.Name, nd, order, warpObj);
  347. order += 1;
  348. }
  349. group.Shapes = gpIterm;
  350. items.Add(group);
  351. result += "</div>";
  352. //return result;
  353. }
  354. public string ProcessGraphicFrameNode(List<Item> items, XmlNode node, int order, WarpObj warpObj)
  355. {
  356. var result = "";
  357. var graphicTypeUri = node.GetTextByPath("a:graphic/a:graphicData/uri");
  358. if (graphicTypeUri != null)
  359. {
  360. switch (graphicTypeUri.Value)
  361. {
  362. case "http://schemas.openxmlformats.org/drawingml/2006/table":
  363. result = GenTable(node, warpObj);
  364. break;
  365. case "http://schemas.openxmlformats.org/drawingml/2006/chart":
  366. result = GenChart(node, warpObj);
  367. break;
  368. case "http://schemas.openxmlformats.org/drawingml/2006/diagram":
  369. result = GenDiagram(node, warpObj);
  370. break;
  371. default:
  372. break;
  373. }
  374. }
  375. return result;
  376. }
  377. public string GenDiagram(XmlNode node, WarpObj warpObj)
  378. {
  379. return "";
  380. }
  381. public string GenChart(XmlNode node, WarpObj warpObj)
  382. {
  383. return "";
  384. }
  385. public string GenTable(XmlNode node, WarpObj warpObj)
  386. {
  387. return "";
  388. }
  389. public async Task<Item> ProcessCxnSpNode(XmlNode node, int order, WarpObj warpObj)
  390. {
  391. var id = node.GetTextByPath("p:nvCxnSpPr/p:cNvPr/@id");
  392. var name = node.GetTextByPath("p:nvCxnSpPr/p:cNvPr/@name");
  393. return await GenShape("CxnSp", node, null, null, id, name, null, null, order, warpObj);
  394. }
  395. public async Task<Item> ProcessSpNode(XmlNode node, int order, WarpObj warpObj)
  396. {
  397. /*
  398. * 958 <xsd:complexType name="CT_GvmlShape">
  399. * 959 <xsd:sequence>
  400. * 960 <xsd:element name="nvSpPr" type="CT_GvmlShapeNonVisual" minOccurs="1" maxOccurs="1"/>
  401. * 961 <xsd:element name="spPr" type="CT_ShapeProperties" minOccurs="1" maxOccurs="1"/>
  402. * 962 <xsd:element name="txSp" type="CT_GvmlTextShape" minOccurs="0" maxOccurs="1"/>
  403. * 963 <xsd:element name="style" type="CT_ShapeStyle" minOccurs="0" maxOccurs="1"/>
  404. * 964 <xsd:element name="extLst" type="CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1"/>
  405. * 965 </xsd:sequence>
  406. * 966 </xsd:complexType>
  407. */
  408. var id = node.GetTextByPath("p:nvSpPr/p:cNvPr/@id");
  409. var name = node.GetTextByPath("p:nvSpPr/p:cNvPr/@name");
  410. var idx = node.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@idx");
  411. var type = node.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@type");
  412. XmlNode slideLayoutSpNode = ShapeHelper.GetNodesTable(id, idx, type, warpObj, "Layout");
  413. XmlNode slideMasterSpNode = ShapeHelper.GetNodesTable(id, idx, type, warpObj, "Master");
  414. if (type == null)
  415. {
  416. if (slideLayoutSpNode != null)
  417. {
  418. type = slideLayoutSpNode.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@type");
  419. }
  420. // type = slideLayoutSpNode.TryGetValue"p:nvSpPr", "p:nvPr", "p:ph", "attrs", "type"]);
  421. if (type == null)
  422. {
  423. if (slideMasterSpNode != null)
  424. {
  425. type = slideMasterSpNode.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@type");
  426. }
  427. // type = getTextByPathList(slideMasterSpNode, ["p:nvSpPr", "p:nvPr", "p:ph", "attrs", "type"]);
  428. }
  429. }
  430. Item item = await GenShape("Sp", node, slideLayoutSpNode, slideMasterSpNode, id, name, idx, type, order, warpObj);
  431. return item;
  432. }
  433. 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)
  434. {
  435. var xfrmList = "p:spPr/a:xfrm";
  436. var slideXfrmNode = node.GetTextByPath(xfrmList);
  437. XmlNode slideLayoutXfrmNode = null;
  438. if (slideLayoutSpNode != null)
  439. {
  440. slideLayoutXfrmNode = slideLayoutSpNode.GetTextByPath(xfrmList);
  441. }
  442. XmlNode slideMasterXfrmNode = null;
  443. if (slideMasterSpNode != null)
  444. {
  445. slideMasterXfrmNode = slideMasterSpNode.GetTextByPath(xfrmList);
  446. }
  447. if (slideXfrmNode == null)
  448. {
  449. slideXfrmNode = slideLayoutXfrmNode;
  450. }
  451. if (slideXfrmNode == null)
  452. {
  453. slideXfrmNode = slideMasterXfrmNode;
  454. }
  455. var result = "";
  456. var shapeType = node.GetTextByPath("p:spPr/a:prstGeom/@prst");
  457. var custShapType = node.GetTextByPath("p:spPr/a:custGeom");
  458. var isFlipV = 0;
  459. var isFlipH = 0;
  460. if (slideXfrmNode.GetTextByPath("@flipV") != null && slideXfrmNode.GetTextByPath("@flipV").Value == "1")
  461. {// if ( getTextByPathList(slideXfrmNode, ["attrs", "flipV"]) === "1" || getTextByPathList(slideXfrmNode, ["attrs", "flipH"]) === "1")
  462. isFlipV = 1;
  463. }
  464. if (slideXfrmNode.GetTextByPath("@flipH") != null && slideXfrmNode.GetTextByPath("@flipH").Value == "1")
  465. {
  466. isFlipH = 1;
  467. }
  468. //rotate
  469. var rotate = ShapeHelper.AngleToDegrees(slideXfrmNode.GetTextByPath("@rot"));
  470. double txtRotate;
  471. var txtXframeNode = node.GetTextByPath("p:txXfrm/@rot");
  472. if (txtXframeNode != null)
  473. {
  474. txtRotate = ShapeHelper.AngleToDegrees(txtXframeNode) + 90;
  475. }
  476. else
  477. {
  478. txtRotate = rotate;
  479. }
  480. Position position = ShapeHelper.GetPosition(slideXfrmNode, slideLayoutXfrmNode, slideMasterXfrmNode);
  481. position.Rot = rotate;
  482. position.FlipH = isFlipH;
  483. position.FlipV = isFlipV;
  484. var grndFillFlg = false;
  485. var imgFillFlg = false;
  486. var Fill = await GetShapeFill(node, warpObj);
  487. // Border Color
  488. var shapeBorder = ShapeHelper.GetBorder(node, true, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  489. var headEndNodeAttrs = node.GetTextByPath("p:spPr/a:ln/a:headEnd");
  490. var tailEndNodeAttrs = node.GetTextByPath("p:spPr/a:ln/a:tailEnd");
  491. Svg shapeSvg = new Svg { Id = order + "", Width = position.Cx + "", Height = position.Cy + "", Top = position.X + "", Left = position.Y + "", Transform = "rotate(" + position.Rot + "deg)" };
  492. StringBuilder svgPath = new StringBuilder("<svg class='drawing' _id='" + order + id + "' _idx='" + order + idx + "' _type='" + order + type + "' _name='" + order + name + "'");
  493. svgPath.Append(" style='top:" + position.Y + "px;left:" + position.X + "px;width:" + position.Cx + "px;height" + position.Cy + "px;'");
  494. if (shapeType != null || custShapType != null)
  495. {
  496. //result += "<svg class='drawing' _id='" + id + "' _idx='" + idx + "' _type='" + type + "' _name='" + name +
  497. // "' style='" +
  498. // getPosition(slideXfrmNode, null, null) +
  499. // getSize(slideXfrmNode, null, null) +
  500. // " z-index: " + order + ";" +
  501. // "transform: rotate(" + rotate + "deg);" +
  502. // "'>";
  503. //result += "<defs>";
  504. // Fill Color
  505. var clrFillType = ShapeHelper.GetFillType(node.GetTextByPath("p:spPr"));
  506. /////////////////////////////////////////
  507. if (Fill.Type==2)//== "GRADIENT_FILL"
  508. {
  509. grndFillFlg = true;
  510. var color_arry = Fill.gradColor;
  511. var angl = Fill.Rot;
  512. var svgGrdnt = ShapeHelper.GetSvgGradient(position.Cx, position.Cy, angl, color_arry, order, slideLayoutClrOvride, warpObj.themeContent);
  513. shapeSvg.Defs = svgGrdnt;
  514. //fill="url(#linGrd)"
  515. Fill.SvgText = svgGrdnt;
  516. result += svgGrdnt;
  517. }
  518. else if (Fill.Type == 3) //(clrFillType == "PIC_FILL")
  519. {
  520. imgFillFlg = true;
  521. var svgBgImg = ShapeHelper.GetSvgImagePattern(Fill.Image, order);
  522. shapeSvg.Defs = svgBgImg;
  523. //fill="url(#imgPtrn)"
  524. Fill.SvgText = svgBgImg;
  525. result += svgBgImg;
  526. }
  527. else
  528. {
  529. // if (clrFillType != null && clrFillType != "SOLID_FILL" && clrFillType != "PATTERN_FILL")
  530. if (shapeType != null)
  531. {
  532. if (Fill.Type != 1 && Fill.Type != 4 &&(shapeType.Value == "arc" ||
  533. shapeType.Value == "bracketPair" ||
  534. shapeType.Value == "bracePair" ||
  535. shapeType.Value == "leftBracket" ||
  536. shapeType.Value == "leftBrace" ||
  537. shapeType.Value == "rightBrace" ||
  538. shapeType.Value == "rightBracket"))
  539. {
  540. Fill.HtmlText = "none";
  541. Fill.Color = "none";
  542. }
  543. }
  544. }
  545. // type: none, triangle, stealth, diamond, oval, arrow
  546. if ((headEndNodeAttrs != null && (headEndNodeAttrs.GetTextByPath("@type").Value == "triangle" || (headEndNodeAttrs.GetTextByPath("@type").Value == "arrow")) ||
  547. (tailEndNodeAttrs != null && (tailEndNodeAttrs.GetTextByPath("@type").Value == "triangle" || (tailEndNodeAttrs.GetTextByPath("@type").Value == "arrow")))))
  548. {
  549. 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 +
  550. "' orient='auto-start-reverse' markerUnits='strokeWidth'><path d='M 0 0 L 10 5 L 0 10 z' /></marker>";
  551. shapeSvg.Defs = triangleMarker;
  552. result += triangleMarker;
  553. }
  554. result += "</defs>";
  555. }
  556. if (shapeType != null && custShapType == null)
  557. {
  558. Svg svg = ShapeSvg.GenShapeSvg(node, order, shapeType, isFlipV, position, grndFillFlg, imgFillFlg, Fill, shapeBorder, headEndNodeAttrs, tailEndNodeAttrs);
  559. shapeSvg.SvgShape = svg.SvgShape;
  560. // shapeSvg.SvgData = svg.SvgData;
  561. if (ShapeType.Equals("Sp"))
  562. {
  563. Shape shape = new Shape { Border = shapeBorder, Svg = shapeSvg, Type = "Sp", Position = position, Index = order, ShapeType = shapeType.Value };
  564. if (Fill.Type == 0)
  565. {
  566. shape.Fill = null;
  567. }
  568. else {
  569. shape.Fill = Fill;
  570. }
  571. var txbody = node.GetTextByPath("p:txBody");
  572. if (txbody != null)
  573. {
  574. List<Paragraph> paragraphs = await GenTextBody(txbody, node, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
  575. shape.Paragraph = paragraphs;
  576. }
  577. return shape;
  578. }
  579. else if (ShapeType.Equals("CxnSp"))
  580. {
  581. return new Connector { Border = shapeBorder, Svg = shapeSvg, Type = "CxnSp", Position = position, Index = order, CxnType = shapeType.Value };
  582. }
  583. else {
  584. return null;
  585. }
  586. }
  587. else if (custShapType != null)
  588. {
  589. XmlNode pathLstNode = custShapType.GetTextByPath("a:pathLst");
  590. XmlNode pathNode = pathLstNode.GetTextByPath("a:path");
  591. var maxX = 0.0;
  592. var maxY = 0.0;
  593. if (pathLstNode != null)
  594. {
  595. maxX = double.Parse(pathNode.GetTextByPath("@w").Value) * px96 / px914400;
  596. maxY = double.Parse(pathNode.GetTextByPath("@h").Value) * px96 / px914400;
  597. }
  598. var closeNode = pathLstNode.GetTextByPath("a:path/a:close");
  599. var startPoint = pathLstNode.GetTextByPath("a:path/a:moveTo/a:pt");
  600. var spX = 96.0;
  601. var spY = 96.0;
  602. if (startPoint != null)
  603. {
  604. spX = System.Math.Round(double.Parse(startPoint.GetTextByPath("@x").Value) * 96 / 914400,degree);
  605. spY = System.Math.Round(double.Parse(startPoint.GetTextByPath("@y").Value) * 96 / 914400,degree);
  606. }
  607. var d = "M" + spX + "," + spY;
  608. // List<HiTeachCC.Model.PowerPoint.Path> Paths = new List<Model.PowerPoint.Path>();
  609. XmlNodeList pathChildNodes = pathLstNode.GetTextByPath("a:path").ChildNodes;
  610. foreach (XmlNode childNode in pathChildNodes)
  611. {
  612. if (childNode.Name.Equals("a:lnTo"))
  613. {
  614. XmlNodeList nodeList = childNode.ChildNodes;
  615. var Lx = double.Parse(nodeList.Item(0).GetTextByPath("@x").Value) * px96 / px914400;
  616. var Ly = double.Parse(nodeList.Item(0).GetTextByPath("@y").Value) * px96 / px914400;
  617. //Paths.Add(new LineToPath
  618. //{
  619. // Lx = double.Parse(Lx.Value) * px96 / px914400,
  620. // Ly = double.Parse(Lx.Value) * px96 / px914400,
  621. //});
  622. d += " L" + System.Math.Round(Lx,degree) + "," + System.Math.Round(Ly,degree);
  623. }
  624. if (childNode.Name.Equals("a:cubicBezTo"))
  625. {
  626. XmlNodeList nodeList = childNode.ChildNodes;
  627. var Cx1 = double.Parse(nodeList.Item(0).GetTextByPath("@x").Value) * px96 / px914400;
  628. var Cy1 = double.Parse(nodeList.Item(0).GetTextByPath("@y").Value) * px96 / px914400;
  629. var Cx2 = double.Parse(nodeList.Item(1).GetTextByPath("@x").Value) * px96 / px914400;
  630. var Cy2 = double.Parse(nodeList.Item(1).GetTextByPath("@y").Value) * px96 / px914400;
  631. var Cx3 = double.Parse(nodeList.Item(2).GetTextByPath("@x").Value) * px96 / px914400;
  632. var Cy3 = double.Parse(nodeList.Item(2).GetTextByPath("@y").Value) * px96 / px914400;
  633. //Paths.Add( new CubicBezPath
  634. // {
  635. // Cx1 = double.Parse(Cx1.Value) * px96 / px914400,
  636. // Cy1 = double.Parse(Cy1.Value) * px96 / px914400,
  637. // Cx2 = double.Parse(Cx2.Value) * px96 / px914400,
  638. // Cy2 = double.Parse(Cy2.Value) * px96 / px914400,
  639. // Cx3 = double.Parse(Cx3.Value) * px96 / px914400,
  640. // Cy3 = double.Parse(Cy3.Value) * px96 / px914400
  641. // });
  642. 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);
  643. }
  644. if (childNode.Name.Equals("a:quadBezTo"))
  645. {
  646. //http://cw.hubwiz.com/card/c/5636b7041bc20c980538e995/1/4/4/
  647. XmlNodeList nodeList = childNode.ChildNodes;
  648. var Cx1 = double.Parse(nodeList.Item(0).GetTextByPath("@x").Value) * px96 / px914400;
  649. var Cy1 = double.Parse(nodeList.Item(0).GetTextByPath("@y").Value) * px96 / px914400;
  650. var Cx2 = double.Parse(nodeList.Item(1).GetTextByPath("@x").Value) * px96 / px914400;
  651. var Cy2 = double.Parse(nodeList.Item(1).GetTextByPath("@y").Value) * px96 / px914400;
  652. //Paths.Add(new QuadBezPath
  653. //{
  654. // Cx1 = double.Parse(Cx1.Value) * px96 / px914400,
  655. // Cy1 = double.Parse(Cy1.Value) * px96 / px914400,
  656. // Cx2 = double.Parse(Cx2.Value) * px96 / px914400,
  657. // Cy2 = double.Parse(Cy2.Value) * px96 / px914400
  658. //});
  659. d += " Q" + System.Math.Round(Cx1,degree) + "," + System.Math.Round(Cy1,degree) + " " + System.Math.Round(Cx2,degree) + "," + System.Math.Round(Cy2,degree);
  660. }
  661. if (childNode.Name.Equals("a:arcTo"))
  662. {
  663. XmlNodeList nodeList = childNode.ChildNodes;
  664. var wR = double.Parse(nodeList.Item(0).GetTextByPath("@wR").Value) * px96 / px914400;
  665. var hR = double.Parse(nodeList.Item(0).GetTextByPath("@hR").Value) * px96 / px914400;
  666. var stAng = double.Parse(nodeList.Item(0).GetTextByPath("@stAng").Value) * px96 / px914400;
  667. var swAng = double.Parse(nodeList.Item(0).GetTextByPath("@swAng").Value) * px96 / px914400;
  668. var endAng = stAng + swAng;
  669. d += ShapeSvg.ShapeArc(wR, hR, wR, hR, stAng, endAng, false);
  670. //Paths.Add(new ArcToPath() {
  671. // WidthRadius = double.Parse(wR.Value) * px96 / px914400,
  672. // HeightRadius = double.Parse(hR.Value) * px96 / px914400,
  673. // StartAngle = double.Parse(stAng.Value) * px96 / px914400,
  674. // SwingAngle = double.Parse(swAng.Value) * px96 / px914400
  675. //});
  676. }
  677. }
  678. //if (headEndNodeAttrs != null && (headEndNodeAttrs.GetTextByPath("@type").Value == "triangle" || headEndNodeAttrs.GetTextByPath("@type").Value == "arrow"))
  679. //{
  680. // result += "marker-start='url(#markerTriangle_" + order + ")' ";
  681. //}
  682. //if (tailEndNodeAttrs != null && (tailEndNodeAttrs.GetTextByPath("@type").Value == "triangle" || tailEndNodeAttrs.GetTextByPath("@type").Value == "arrow"))
  683. //{
  684. // result += "marker-end='url(#markerTriangle_" + order + ")' ";
  685. //}
  686. List<SvgShape> shapes = new List<SvgShape>() {
  687. new SvgPath {
  688. Type = "path",
  689. Fill = (!imgFillFlg ? (grndFillFlg ? "url(#linGrd_" + order + ")" : Fill.Color) : "url(#imgPtrn_" + order + ")"),
  690. Stroke = "#" + shapeBorder.Color,
  691. StrokeWidth = shapeBorder.Width + "",
  692. StrokeDasharray = shapeBorder.Stroke,
  693. D=d,
  694. MarkerStart="url(#markerTriangle_" + order + ")",
  695. MarkerEnd="url(#markerTriangle_" + order + ")"
  696. }
  697. };
  698. shapeSvg.SvgShape = shapes;
  699. // shapeSvg.SvgData = result;
  700. Shape shape = new Shape { Border = shapeBorder, Svg = shapeSvg, Type = "Sp", Position = position, Index = order, ShapeType = "custom" };
  701. if (Fill.Type == 0)
  702. {
  703. shape.Fill = null;
  704. }
  705. else
  706. {
  707. shape.Fill = Fill;
  708. }
  709. var txbody = node.GetTextByPath("p:txBody");
  710. if (txbody != null)
  711. {
  712. List<Paragraph> paragraphs = await GenTextBody(txbody, node, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
  713. shape.Paragraph = paragraphs;
  714. }
  715. return shape;
  716. }
  717. else
  718. {
  719. Shape shape = new Shape { Border = shapeBorder, Svg = shapeSvg, Type = "Sp", Position = position, Index = order, ShapeType = "rect" };
  720. if (Fill.Type == 0)
  721. {
  722. shape.Fill = null;
  723. }
  724. else
  725. {
  726. shape.Fill = Fill;
  727. }
  728. var txbody = node.GetTextByPath("p:txBody");
  729. if (txbody != null)
  730. {
  731. List<Paragraph> paragraphs = await GenTextBody(txbody, node, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
  732. shape.Paragraph = paragraphs;
  733. }
  734. return shape;
  735. }
  736. }
  737. private async Task<List<Paragraph>> GenTextBody(XmlNode textBodyNode, XmlNode spNode, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, WarpObj warpObj)
  738. {
  739. List<Paragraph> paragraphs = new List<Paragraph>();
  740. var slideMasterTextStyles = warpObj.slideMasterTextStyles;
  741. string vert = GetVerticalAlign(spNode, slideLayoutSpNode, slideMasterSpNode);
  742. var ps = textBodyNode.GetTextByPathList("a:p");
  743. if (ps != null)
  744. {
  745. foreach (XmlNode pNode in ps)
  746. {
  747. BuChar buChar = await GenBuChar(pNode, spNode, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
  748. if (buChar != null && (buChar.Buchar == null || buChar.Buchar.Equals("TYPE_NONE"))) {
  749. buChar = null;
  750. }
  751. string HorizontalAlign = GetHorizontalAlign(pNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles);
  752. Paragraph paragraph = new Paragraph
  753. {
  754. BuChar = buChar,
  755. ParagraphStyle = new ParagraphStyle
  756. {
  757. VertAlign = vert,
  758. HoriAlign = HorizontalAlign
  759. }
  760. };
  761. var rNode = pNode.GetTextByPathList("a:r");
  762. if (rNode == null)
  763. {
  764. Text text = GenSpanElement(pNode, spNode, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
  765. if (pNode.GetTextByPath("a:br") != null)
  766. {
  767. text.isbr = true;
  768. }
  769. List<Text> texts = new List<Text> { text };
  770. paragraph.Texts = texts;
  771. }
  772. else
  773. {
  774. List<Text> texts = new List<Text>();
  775. foreach (XmlNode node in rNode)
  776. {
  777. Text text = GenSpanElement(node, spNode, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
  778. if (pNode.GetTextByPath("a:br") != null)
  779. {
  780. text.isbr = true;
  781. }
  782. texts.Add(text);
  783. }
  784. paragraph.Texts = texts;
  785. }
  786. paragraphs.Add(paragraph);
  787. }
  788. }
  789. return paragraphs;
  790. }
  791. private Text GenSpanElement(XmlNode node, XmlNode spNode, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, WarpObj warpObj)
  792. {
  793. string text;
  794. var slideMasterTextStyles = warpObj.slideMasterTextStyles;
  795. var textNode = node.GetTextByPath("a:t");
  796. if (textNode == null)
  797. {
  798. textNode = node.GetTextByPath("a:fld/a:t");
  799. if (textNode == null)
  800. {
  801. text = "&nbsp;";
  802. }
  803. else
  804. {
  805. text = textNode.InnerText;
  806. }
  807. }
  808. else
  809. {
  810. text = textNode.InnerText;
  811. }
  812. var fontClrPr = GetFontColorPr(node, spNode, type, slideMasterTextStyles, warpObj.slideMasterContent, warpObj.themeContent);
  813. string color = fontClrPr.color;
  814. string text_shadow = fontClrPr.textBordr;
  815. int font_size = GetFontSize(node, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles);
  816. string font_family = GetFontType(node, type, slideMasterTextStyles, warpObj.themeContent);
  817. string font_weight = GetFontBold(node, type, slideMasterTextStyles);
  818. string font_style = GetFontItalic(node, type, slideMasterTextStyles);
  819. string text_decoration = GetFontDecoration(node, type, slideMasterTextStyles);
  820. string text_align = GetTextHorizontalAlign(node, type, slideMasterTextStyles);
  821. string vertical_align = GetTextVerticalAlign(node, type, slideMasterTextStyles);
  822. var styleText =
  823. "color:" + color + ";" +
  824. "text-shadow:" + text_shadow + ";" +
  825. "font-size:" + font_size + ";" +
  826. "font-family:" + font_family + ";" +
  827. "font-weight:" + font_weight + ";" +
  828. "font-style:" + font_style + ";" +
  829. "text-decoration:" + text_decoration + ";" +
  830. "text-align:" + text_align + ";" +
  831. "vertical-align:" + vertical_align + ";";
  832. string cssName = "";
  833. if (styleTable.TryGetValue(styleText, out Dictionary<string, string> css))
  834. {
  835. cssName = css["name"];
  836. }
  837. else
  838. {
  839. cssName = "_css_" + (styleTable.Keys.Count + 1);
  840. styleTable.TryAdd(styleText, new Dictionary<string, string> { { "name", cssName }, { "text", styleText } });
  841. }
  842. var linkID = node.GetTextByPath("a:rPr/a:hlinkClick/@r:id");
  843. string linkURL = null;
  844. if (linkID != null)
  845. {
  846. linkURL = warpObj.slideResObj[linkID.Value]["target"];
  847. }
  848. return new Text
  849. {
  850. Content = text,
  851. Href = linkURL,
  852. FontStyle = new FontStyle
  853. {
  854. Color = color,
  855. Size = font_size,
  856. Family = font_family,
  857. Weight = font_weight,
  858. Style = font_style,
  859. Decoration = text_decoration,
  860. VertAlign = vertical_align,
  861. Align = text_align,
  862. Shadow = text_shadow
  863. }
  864. };
  865. }
  866. private string GetTextVerticalAlign(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles)
  867. {
  868. var baseline = node.GetTextByPath("a:rPr/@baseline");
  869. if (baseline != null)
  870. {
  871. return int.Parse(baseline.Value) / 1000 + "%";
  872. }
  873. else
  874. {
  875. return "baseline";
  876. }
  877. }
  878. private string GetTextHorizontalAlign(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles)
  879. {
  880. var getAlgn = node.GetTextByPath("a:pPr/@algn");
  881. var align = "initial";
  882. if (getAlgn != null)
  883. {
  884. switch (getAlgn.Value)
  885. {
  886. case "l":
  887. align = "left";
  888. break;
  889. case "r":
  890. align = "right";
  891. break;
  892. case "ctr":
  893. align = "center";
  894. break;
  895. case "just":
  896. align = "justify";
  897. break;
  898. case "dist":
  899. align = "justify";
  900. break;
  901. default:
  902. align = "initial";
  903. break;
  904. }
  905. }
  906. return align;
  907. }
  908. private string GetFontDecoration(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles)
  909. {
  910. if (node.GetTextByPath("a:rPr") != null)
  911. {
  912. var FontDecor = node.GetTextByPath("a:rPr/@u");
  913. var underLine = FontDecor != null ? FontDecor.Value : "none";
  914. var FontStrik = node.GetTextByPath("a:rPr/@strike");
  915. var strikethrough = FontStrik != null ? FontStrik.Value : "noStrike";
  916. if (underLine != "none" && strikethrough == "noStrike")
  917. {
  918. return "underline";
  919. }
  920. else if (underLine == "none" && strikethrough != "noStrike")
  921. {
  922. return "line-through";
  923. }
  924. else if (underLine != "none" && strikethrough != "noStrike")
  925. {
  926. return "underline line-through";
  927. }
  928. else
  929. {
  930. return "initial";
  931. }
  932. }
  933. else
  934. {
  935. return "initial";
  936. }
  937. }
  938. private string GetFontItalic(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles)
  939. {
  940. var FontBold = node.GetTextByPath("a:rPr/@i");
  941. if (FontBold != null)
  942. {
  943. if (FontBold.Value.Equals("1"))
  944. {
  945. return "italic";
  946. }
  947. else
  948. {
  949. return "normal";
  950. }
  951. }
  952. else
  953. {
  954. return "normal";
  955. }
  956. }
  957. private string GetFontBold(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles)
  958. {
  959. var FontBold = node.GetTextByPath("a:rPr/@b");
  960. if (FontBold != null)
  961. {
  962. if (FontBold.Value.Equals("1"))
  963. {
  964. return "bold";
  965. }
  966. else
  967. {
  968. return "initial";
  969. }
  970. }
  971. else
  972. {
  973. return "initial";
  974. }
  975. }
  976. private string GetFontType(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles, XmlNode themeContent)
  977. {
  978. string typeface = "inherit";
  979. XmlNode typefaceNode = node.GetTextByPath("a:rPr/a:latin/@typeface");
  980. if (typefaceNode == null)
  981. {
  982. var fontSchemeNode = themeContent.GetTextByPath("a:theme/a:themeElements/a:fontScheme");
  983. if (type != null && fontSchemeNode != null && (type.Value == "title" || type.Value == "subTitle" || type.Value == "ctrTitle"))
  984. {
  985. typefaceNode = fontSchemeNode.GetTextByPath("a:majorFont/a:latin/@typeface");
  986. }
  987. else if (type != null && fontSchemeNode != null && type.Value == "body")
  988. {
  989. typefaceNode = fontSchemeNode.GetTextByPath("a:minorFont/a:latin/@typeface");
  990. }
  991. else if(fontSchemeNode!=null)
  992. {
  993. typefaceNode = fontSchemeNode.GetTextByPath("a:minorFont/a:latin/@typeface");
  994. }
  995. }
  996. if (typefaceNode != null)
  997. {
  998. typeface = typefaceNode.Value;
  999. }
  1000. return typeface;
  1001. }
  1002. private async Task<BuChar> GenBuChar(XmlNode node, XmlNode spNode, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, WarpObj warpObj)
  1003. {
  1004. var sldMstrTxtStyles = warpObj.slideMasterTextStyles;
  1005. var slideMasterContent = warpObj.slideMasterContent;
  1006. var themeContent = warpObj.themeContent;
  1007. var rNodes = node.GetTextByPathList("a:r");
  1008. XmlNode rNode = null;
  1009. if (rNodes != null)
  1010. {
  1011. rNode = rNodes[0];
  1012. }
  1013. dynamic dfltBultColor;
  1014. int dfltBultSize;
  1015. if (rNode != null)
  1016. {
  1017. dfltBultColor = GetFontColorPr(rNode, spNode, type, sldMstrTxtStyles, slideMasterContent, themeContent);
  1018. dfltBultSize = GetFontSize(rNode, slideLayoutSpNode, slideMasterSpNode, type, sldMstrTxtStyles);
  1019. }
  1020. else
  1021. {
  1022. dfltBultColor = GetFontColorPr(node, spNode, type, sldMstrTxtStyles, slideMasterContent, themeContent);
  1023. dfltBultSize = GetFontSize(node, slideLayoutSpNode, slideMasterSpNode, type, sldMstrTxtStyles);
  1024. }
  1025. var bullet = "";
  1026. var pPrNode = node.GetTextByPath("a:pPr");
  1027. var getRtlVal = node.GetTextByPath("a:pPr/@rtl");
  1028. var isRTL = false;
  1029. if (getRtlVal != null && getRtlVal.Equals("1"))
  1030. {
  1031. isRTL = true;
  1032. }
  1033. int lvl = 0;
  1034. if (node.GetTextByPath("a:pPr/@lvl") != null)
  1035. {
  1036. lvl = int.Parse(node.GetTextByPath("a:pPr/@lvl").Value);
  1037. }
  1038. XmlNode buNum = null;
  1039. XmlNode buPic = null;
  1040. XmlNode buCharNode = null;
  1041. XmlNode buClrNode = null;
  1042. if (pPrNode != null) {
  1043. buCharNode = pPrNode.GetTextByPath("a:buChar/@char");
  1044. buNum = pPrNode.GetTextByPath("a:buAutoNum/@type");
  1045. buPic = pPrNode.GetTextByPath("a:buBlip");
  1046. buClrNode= pPrNode.GetTextByPath("a:buClr");
  1047. }
  1048. string buChar = "";
  1049. var buType = "TYPE_NONE";
  1050. if (buCharNode != null)
  1051. {
  1052. buChar = buCharNode.Value;
  1053. buType = "TYPE_BULLET";
  1054. }
  1055. if (buNum != null)
  1056. {
  1057. buType = "TYPE_NUMERIC";
  1058. }
  1059. if (buPic != null)
  1060. {
  1061. buType = "TYPE_BULPIC";
  1062. }
  1063. XmlNode buFontAttrs = null;
  1064. if (buType != "TYPE_NONE" && pPrNode!=null)
  1065. {
  1066. buFontAttrs = pPrNode.GetTextByPath("a:buFont");
  1067. }
  1068. var defBultColor = "NoNe";
  1069. string bultColor;
  1070. if (buClrNode != null)
  1071. {
  1072. defBultColor = ShapeHelper.GetSolidFill(buClrNode, slideLayoutClrOvride, slideMasterContent, themeContent);
  1073. }
  1074. else
  1075. {
  1076. }
  1077. if (defBultColor == "NoNe")
  1078. {
  1079. bultColor = dfltBultColor.color;
  1080. }
  1081. else
  1082. {
  1083. bultColor = "#" + defBultColor;
  1084. }
  1085. int bultSize;
  1086. XmlNode buVal=null;
  1087. if (pPrNode != null) {
  1088. buVal = pPrNode.GetTextByPath("a:buSzPts/@val"); //pt
  1089. }
  1090. if (buVal != null)
  1091. {
  1092. bultSize = int.Parse(buVal.Value) / 100;
  1093. }
  1094. else
  1095. {
  1096. if (pPrNode != null)
  1097. {
  1098. buVal = pPrNode.GetTextByPath("a:buSzPct/@val");
  1099. }
  1100. if (buVal != null)
  1101. {
  1102. var prcnt = int.Parse(buVal.Value) / 100000;
  1103. //dfltBultSize = XXpt
  1104. var dfltBultSizeNoPt = dfltBultSize;
  1105. //pt
  1106. bultSize = prcnt * (dfltBultSizeNoPt);
  1107. }
  1108. else
  1109. {
  1110. bultSize = dfltBultSize;
  1111. }
  1112. }
  1113. double marginLeft = 0;
  1114. double marginRight = 0;
  1115. string typeface = "";
  1116. string Float = "left";
  1117. string Direction = "inherit";
  1118. BuChar BuChar = null;
  1119. if (buType == "TYPE_BULLET")
  1120. {
  1121. if (buFontAttrs != null)
  1122. {
  1123. XmlNode marl = null;
  1124. if (pPrNode != null)
  1125. {
  1126. marl = pPrNode.GetTextByPath("@marL");
  1127. }
  1128. if (marl != null)
  1129. {
  1130. marginLeft = int.Parse(marl.Value) * px96 / px914400;
  1131. if (buFontAttrs.GetTextByPath("@pitchFamily") != null)
  1132. {
  1133. marginRight = int.Parse(buFontAttrs.GetTextByPath("@pitchFamily").Value);
  1134. }
  1135. if (marginLeft == 0)
  1136. {
  1137. marginLeft = 328600 * px96 / px914400;
  1138. }
  1139. var typefaceNode = buFontAttrs.GetTextByPath("@typeface");
  1140. if (typefaceNode != null)
  1141. {
  1142. typeface = typefaceNode.Value;
  1143. }
  1144. if (isRTL)
  1145. {
  1146. Float = "right";
  1147. Direction = "rtl";
  1148. }
  1149. marginLeft = marginLeft * lvl;
  1150. }
  1151. }
  1152. else
  1153. {
  1154. marginLeft = 328600 * px96 / px914400 * lvl;
  1155. }
  1156. BuChar = new BuChar
  1157. {
  1158. Typeface = typeface,
  1159. MarginLeft = marginLeft,
  1160. MarginRiht = marginRight,
  1161. FontSize = bultSize,
  1162. Buchar = buChar,
  1163. Float = Float,
  1164. Direction = Direction,
  1165. Type = "TYPE_BULLET"
  1166. };
  1167. }
  1168. else if (buType == "TYPE_NUMERIC")
  1169. {
  1170. if (buFontAttrs != null)
  1171. {
  1172. XmlNode marl = null;
  1173. if (pPrNode != null)
  1174. {
  1175. marl = pPrNode.GetTextByPath("@marL");
  1176. }
  1177. if (marl != null)
  1178. {
  1179. marginLeft = int.Parse(marl.Value) * px96 / px914400;
  1180. if (buFontAttrs.GetTextByPath("@pitchFamily") != null)
  1181. {
  1182. marginRight = int.Parse(buFontAttrs.GetTextByPath("@pitchFamily").Value);
  1183. }
  1184. if (marginLeft == 0)
  1185. {
  1186. marginLeft = 328600 * px96 / px914400;
  1187. }
  1188. var typefaceNode = buFontAttrs.GetTextByPath("@typeface");
  1189. if (typefaceNode != null)
  1190. {
  1191. typeface = typefaceNode.Value;
  1192. }
  1193. else
  1194. {
  1195. typeface = "inherit";
  1196. }
  1197. if (isRTL)
  1198. {
  1199. Float = "right";
  1200. Direction = "rtl";
  1201. }
  1202. else
  1203. {
  1204. Float = "left";
  1205. Direction = "ltr";
  1206. }
  1207. marginLeft = marginLeft * lvl;
  1208. }
  1209. }
  1210. else
  1211. {
  1212. marginLeft = 328600 * 96 / 914400 * lvl;
  1213. if (isRTL)
  1214. {
  1215. Float = "right";
  1216. Direction = "rtl";
  1217. }
  1218. else
  1219. {
  1220. Float = "left";
  1221. Direction = "ltr";
  1222. }
  1223. BuChar = new BuChar
  1224. {
  1225. Typeface = typeface,
  1226. MarginLeft = marginLeft,
  1227. MarginRiht = marginRight,
  1228. FontSize = bultSize,
  1229. Buchar = buChar,
  1230. Float = Float,
  1231. Direction = Direction,
  1232. Type = "TYPE_NUMERIC"
  1233. };
  1234. }
  1235. }
  1236. else if (buType == "TYPE_BULPIC")
  1237. {
  1238. XmlNode marl = null;
  1239. if (pPrNode != null)
  1240. {
  1241. marl = pPrNode.GetTextByPath("@marL");
  1242. }
  1243. if (marl != null)
  1244. {
  1245. marginLeft = int.Parse(marl.Value) * px96 / px914400;
  1246. }
  1247. else
  1248. {
  1249. marginLeft = 328600 * px96 / px914400;
  1250. }
  1251. XmlNode marR = null;
  1252. if (pPrNode != null)
  1253. {
  1254. marR = pPrNode.GetTextByPath("@marR");
  1255. }
  1256. if (marR != null)
  1257. {
  1258. marginRight = int.Parse(marR.Value) * px96 / px914400;
  1259. }
  1260. var buPicId = buPic.GetTextByPath("a:blip/@r:embed");
  1261. var buImg = "";
  1262. if (buPicId != null)
  1263. {
  1264. var imgPath = warpObj.slideResObj[buPicId.Value];
  1265. var imgData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + imgPath["target"] + "']");
  1266. if (imgData != null)
  1267. {
  1268. var imgFileExt = imgData.GetTextByPath("@pkg:contentType");
  1269. AzureBlobModel imgModel = await SaveBase64ToBolob(imgData.InnerText, imgFileExt.Value, fileShaCode + "/imgs", "");
  1270. buImg = imgModel.BlobUrl;
  1271. }
  1272. }
  1273. else
  1274. {
  1275. buImg = "&#8227;";
  1276. }
  1277. if (isRTL)
  1278. {
  1279. Float = "right";
  1280. Direction = "rtl";
  1281. }
  1282. marginLeft = marginLeft * lvl;
  1283. BuChar = new BuChar
  1284. {
  1285. Typeface = typeface,
  1286. MarginLeft = marginLeft,
  1287. MarginRiht = marginRight,
  1288. FontSize = bultSize,
  1289. Buchar = buImg,
  1290. Float = Float,
  1291. Direction = Direction,
  1292. Type = "TYPE_NUMERIC"
  1293. };
  1294. }
  1295. else
  1296. {
  1297. if (isRTL)
  1298. {
  1299. Float = "right";
  1300. Direction = "rtl";
  1301. }
  1302. BuChar = new BuChar
  1303. {
  1304. Typeface = typeface,
  1305. MarginLeft = 328600 * px96 / px914400 * lvl,
  1306. MarginRiht = marginRight,
  1307. FontSize = bultSize,
  1308. Float = Float,
  1309. Direction = Direction,
  1310. Type = "TYPE_NONE"
  1311. };
  1312. }
  1313. return BuChar;
  1314. }
  1315. private int GetFontSize(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, XmlNode slideMasterTextStyles)
  1316. {
  1317. int fontSize = 0;
  1318. if (node.GetTextByPath("a:rPr/@sz") != null)
  1319. {
  1320. fontSize = int.Parse(node.GetTextByPath("a:rPr/@sz").Value) / 100;
  1321. }
  1322. if (fontSize == 0)
  1323. {
  1324. if (slideLayoutSpNode != null) {
  1325. var sz = slideLayoutSpNode.GetTextByPath("p:txBody/a:lstStyle/a:lvl1pPr/a:defRPr/@sz");
  1326. if (sz != null)
  1327. {
  1328. fontSize = int.Parse(sz.Value) / 100;
  1329. }
  1330. }
  1331. }
  1332. XmlNode size = null;
  1333. if (fontSize == 0)
  1334. {
  1335. if (type == null) {
  1336. size = slideMasterTextStyles.GetTextByPath("p:otherStyle/a:lvl1pPr/a:defRPr/@sz");
  1337. }
  1338. else if (type.Value.Equals("title") || type.Value.Equals("subTitle") || type.Value.Equals("ctrTitle"))
  1339. {
  1340. size = slideMasterTextStyles.GetTextByPath("p:titleStyle/a:lvl1pPr/a:defRPr/@sz");
  1341. }
  1342. else if (type.Value.Equals("body"))
  1343. {
  1344. size = slideMasterTextStyles.GetTextByPath("p:bodyStyle/a:lvl1pPr/a:defRPr/@sz");
  1345. }
  1346. else if (type.Value.Equals("dt") || type.Value.Equals("sldNum"))
  1347. {
  1348. fontSize = 12;
  1349. }
  1350. if (size != null)
  1351. {
  1352. fontSize = int.Parse(size.Value) / 100;
  1353. }
  1354. }
  1355. var baseline = node.GetTextByPath("a:rPr/@baseline");
  1356. if (baseline != null && fontSize != 0)
  1357. {
  1358. fontSize -= 10;
  1359. }
  1360. //return isNaN(fontSize) ? "inherit" : (fontSize + "pt");
  1361. //如果fontSize为0 则 使用inherit 继承方式
  1362. return fontSize;
  1363. }
  1364. private dynamic GetFontColorPr(XmlNode node, XmlNode spNode, XmlNode type, XmlNode sldMstrTxtStyles, XmlNode slideMasterContent, XmlNode themeContent)
  1365. {
  1366. var rPrNode = node.GetTextByPath("a:rPr");
  1367. string filTyp, textBordr;
  1368. string color = null;
  1369. if (rPrNode != null)
  1370. {
  1371. filTyp = ShapeHelper.GetFillType(rPrNode);
  1372. if (filTyp == "SOLID_FILL")
  1373. {
  1374. var solidFillNode = node.GetTextByPath("a:rPr/a:solidFill");
  1375. string colorstr = ShapeHelper.GetSolidFill(solidFillNode, slideLayoutClrOvride, slideMasterContent, themeContent);
  1376. if (solidFillNode!=null) {
  1377. color = PowerPointHelper.ColorToning(solidFillNode.OuterXml, colorstr);
  1378. }
  1379. }
  1380. else if (filTyp == "PATTERN_FILL")
  1381. {
  1382. var pattFill = node.GetTextByPath("a:rPr/a:pattFill");
  1383. Fill colorFill = ShapeHelper.GetPatternFill(pattFill, slideLayoutClrOvride, slideMasterContent, themeContent);
  1384. if (colorFill != null && colorFill.gradColor.IsNotEmpty())
  1385. {
  1386. color = colorFill.gradColor[0];
  1387. }
  1388. else
  1389. {
  1390. color = "000000";
  1391. }
  1392. }
  1393. else
  1394. {
  1395. var sPstyle = spNode.GetTextByPath("p:style/a:fontRef");
  1396. if (sPstyle != null)
  1397. {
  1398. string colorstr = ShapeHelper.GetSolidFill(sPstyle, slideLayoutClrOvride, slideMasterContent, themeContent);
  1399. color = PowerPointHelper.ColorToning(sPstyle.OuterXml, colorstr);
  1400. }
  1401. }
  1402. }
  1403. if (color == null)
  1404. {
  1405. color = "000000";
  1406. }
  1407. var txtBrdrNode = node.GetTextByPath("a:rPr/a:ln");
  1408. if (txtBrdrNode != null)
  1409. {
  1410. var txBrd = ShapeHelper.GetBorder(node, true, "text", slideLayoutClrOvride, slideMasterContent, themeContent);
  1411. var brdSize = txBrd.Width * (4 / 3) + "px";
  1412. var brdClr = txBrd.Color;
  1413. textBordr = "-" + brdSize + " 0 " + brdClr + ", 0 " + brdSize + " " + brdClr + ", " + brdSize + " 0 " + brdClr + ", 0 -" + brdSize + " " + brdClr + ";";
  1414. }
  1415. else
  1416. {
  1417. textBordr = "none";
  1418. }
  1419. return new { color, textBordr };
  1420. }
  1421. public string GetVerticalAlign(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode)
  1422. {
  1423. XmlDocument doc = new XmlDocument();
  1424. doc.LoadXml(node.OuterXml);
  1425. XmlNode anchor = doc.GetTextByPath("//p:txBody/a:bodyPr/@anchor");
  1426. if (anchor == null)
  1427. {
  1428. if (slideLayoutSpNode != null)
  1429. {
  1430. doc.LoadXml(slideLayoutSpNode.OuterXml);
  1431. anchor = doc.GetTextByPath("//p:txBody/a:bodyPr/@anchor");
  1432. }
  1433. if (anchor == null && slideMasterSpNode != null)
  1434. {
  1435. doc.LoadXml(slideMasterSpNode.OuterXml);
  1436. anchor = doc.GetTextByPath("//p:txBody/a:bodyPr/@anchor");
  1437. }
  1438. }
  1439. if (anchor != null)
  1440. {
  1441. return anchor.Value.Equals("ctr") ? "v-mid" : anchor.Value.Equals("b") ? "v-down" : "v-up";
  1442. }
  1443. else
  1444. {
  1445. return "v-up";
  1446. }
  1447. }
  1448. public string GetHorizontalAlign(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode,
  1449. XmlNode typeNode, XmlNode slideMasterTextStyles)
  1450. {
  1451. XmlDocument doc = new XmlDocument();
  1452. doc.LoadXml(node.OuterXml);
  1453. XmlNode algn = doc.GetTextByPath("//a:pPr/@algn");
  1454. if (algn == null)
  1455. {
  1456. if (slideLayoutSpNode != null)
  1457. {
  1458. doc.LoadXml(slideLayoutSpNode.OuterXml);
  1459. algn = doc.GetTextByPath("//p:txBody/a:p/a:pPr/@algn");
  1460. }
  1461. if (algn == null && slideMasterSpNode != null)
  1462. {
  1463. doc.LoadXml(slideMasterSpNode.OuterXml);
  1464. algn = doc.GetTextByPath("//p:txBody/a:p/a:pPr/@algn");
  1465. }
  1466. if (algn == null && typeNode != null)
  1467. {
  1468. switch (typeNode.Value)
  1469. {
  1470. case "title":
  1471. case "subTitle":
  1472. case "ctrTitle":
  1473. //doc.LoadXml(slideMasterStyle.TypeTable.OuterXml);
  1474. doc.LoadXml(slideMasterTextStyles.OuterXml);
  1475. algn = doc.GetTextByPath("//p:titleStyle/a:lvl1pPr/@algn");
  1476. break;
  1477. case "body":
  1478. doc.LoadXml(slideMasterTextStyles.OuterXml);
  1479. algn = doc.GetTextByPath("//p:bodyStyle/a:lvl1pPr/@algn");
  1480. break;
  1481. default:
  1482. // doc.LoadXml(slideMasterStyle.TypeTable.OuterXml);
  1483. doc.LoadXml(slideMasterTextStyles.OuterXml);
  1484. algn = doc.GetTextByPath("//p:otherStyle/a:lvl1pPr/@algn");
  1485. break;
  1486. }
  1487. }
  1488. }
  1489. if (algn == null)
  1490. {
  1491. if (typeNode == null)
  1492. {
  1493. return "h-left";
  1494. }
  1495. if (typeNode.Value.Equals("title") || typeNode.Value.Equals("subTitle") || typeNode.Value.Equals("ctrTitle"))
  1496. {
  1497. return "h-mid";
  1498. }
  1499. else if (typeNode.Value == "sldNum")
  1500. {
  1501. return "h-right";
  1502. }
  1503. else if (typeNode.Value.Equals("body")) { return "h-left"; }
  1504. }
  1505. return algn.Value.Equals("ctr") ? "h-mid" : algn.Value.Equals("r") ? "h-right" : "h-left";
  1506. }
  1507. /// <summary>
  1508. /// 幻灯片 背景色填充
  1509. /// </summary>
  1510. /// <param name="slideContent"></param>
  1511. /// <param name="slideLayoutContent"></param>
  1512. /// <param name="slideMasterContent"></param>
  1513. /// <param name="index"></param>
  1514. /// <param name="warpObj"></param>
  1515. /// <returns></returns>
  1516. public async Task<Fill> GetSlideBackgroundFill(XmlNode slideContent, int index, WarpObj warpObj)
  1517. {
  1518. var bgPr = slideContent.GetTextByPath("p:sld/p:cSld/p:bg/p:bgPr");
  1519. var bgRef = slideContent.GetTextByPath("p:sld/p:cSld/p:bg/p:bgRef");
  1520. if (bgPr != null)
  1521. {
  1522. var bgFillTyp = ShapeHelper.GetFillType(bgPr);
  1523. if (bgFillTyp == "SOLID_FILL")
  1524. {
  1525. var sldFill = bgPr.GetTextByPath("a:solidFill");
  1526. var bgColor = ShapeHelper.GetSolidFill(sldFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1527. if (sldFill!=null) {
  1528. bgColor = PowerPointHelper.ColorToning(sldFill.OuterXml, bgColor);
  1529. }
  1530. return new Fill { Type = 1, Color = bgColor };
  1531. }
  1532. else if (bgFillTyp == "GRADIENT_FILL")
  1533. {
  1534. return ShapeHelper.GetBgGradientFill(bgPr, null, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1535. }
  1536. else if (bgFillTyp == "PIC_FILL")
  1537. {
  1538. return await GetPicFill("slideBg", bgPr.GetTextByPath("a:blipFill"), warpObj);
  1539. }
  1540. }
  1541. else if (bgRef != null)
  1542. {
  1543. string phClr = ShapeHelper.GetSolidFill(bgRef, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1544. phClr = PowerPointHelper.ColorToning(bgRef.OuterXml, phClr);
  1545. var idx = bgRef.GetTextByPath("@idx");
  1546. if (idx != null)
  1547. {
  1548. int value = int.Parse(idx.Value);
  1549. if (value == 0 || value == 1000)
  1550. {
  1551. return new Fill { Type = 0 };
  1552. //no background
  1553. }
  1554. else if (value > 0 && value < 1000)
  1555. {
  1556. //fillStyleLst in themeContent
  1557. //themeContent["a:fmtScheme"]["a:fillStyleLst"]
  1558. //bgcolor = "background: red;";
  1559. }
  1560. else if (value > 1000)
  1561. {
  1562. var trueIdx = value - 1000;
  1563. var bgFillLst = warpObj.themeContent.GetTextByPath("a:theme/a:themeElements/a:fmtScheme/a:bgFillStyleLst");
  1564. if (bgFillLst != null)
  1565. {
  1566. XmlNodeList nodeList = bgFillLst.ChildNodes;
  1567. if (trueIdx < nodeList.Count)
  1568. {
  1569. string type = ShapeHelper.GetFillType(nodeList[trueIdx - 1]);
  1570. if (type.Equals("SOLID_FILL"))
  1571. {
  1572. if (string.IsNullOrEmpty(phClr))
  1573. {
  1574. phClr = ShapeHelper.GetSolidFill(nodeList[trueIdx - 1], slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1575. }
  1576. if(nodeList[trueIdx - 1]!=null)
  1577. {
  1578. phClr = PowerPointHelper.ColorToning(nodeList[trueIdx - 1].OuterXml, phClr);
  1579. }
  1580. return new Fill { Type = 1, Color = phClr };
  1581. }
  1582. else if (type.Equals("GRADIENT_FILL"))
  1583. {
  1584. return ShapeHelper.GetBgGradientFill(nodeList[trueIdx - 1], phClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1585. }
  1586. else if (type.Equals("PIC_FILL"))
  1587. {
  1588. return await GetPicFill("slideBg", nodeList[trueIdx - 1].GetTextByPath("a:blipFill"), warpObj);
  1589. }
  1590. else
  1591. {
  1592. return new Fill { Type = 0 };
  1593. }
  1594. }
  1595. }
  1596. }
  1597. }
  1598. //var node = bgRef.GetTextByPath("");
  1599. //if (bgRef["a:srgbClr"] !== undefined)
  1600. //{
  1601. // phClr = getTextByPathList(bgRef,["a:srgbClr", "attrs", "val"]); //#...
  1602. //}
  1603. //else if (bgRef["a:schemeClr"] !== undefined)
  1604. //{ //a:schemeClr
  1605. // var schemeClr = getTextByPathList(bgRef,["a:schemeClr", "attrs", "val"]);
  1606. // phClr = getSchemeColorFromTheme("a:" + schemeClr, slideMasterContent); //#...
  1607. //}
  1608. }
  1609. else
  1610. {
  1611. bgPr = warpObj.slideLayoutContent.GetTextByPath("p:sldLayout/p:cSld/p:bg/p:bgPr");
  1612. bgRef = warpObj.slideLayoutContent.GetTextByPath("p:sldLayout/p:cSld/p:bg/p:bgRef");
  1613. if (bgPr != null)
  1614. {
  1615. var bgFillTyp = ShapeHelper.GetFillType(bgPr);
  1616. if (bgFillTyp == "SOLID_FILL")
  1617. {
  1618. var sldFill = bgPr.GetTextByPath("a:solidFill");
  1619. var bgColor = ShapeHelper.GetSolidFill(sldFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1620. if (sldFill!=null) {
  1621. bgColor = PowerPointHelper.ColorToning(sldFill.OuterXml, bgColor);
  1622. }
  1623. return new Fill { Type = 1, Color = bgColor };
  1624. }
  1625. else if (bgFillTyp == "GRADIENT_FILL")
  1626. {
  1627. return ShapeHelper.GetBgGradientFill(bgPr, null, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1628. }
  1629. else if (bgFillTyp == "PIC_FILL")
  1630. {
  1631. return await GetPicFill("slideBg", bgPr.GetTextByPath("a:blipFill"), warpObj);
  1632. }
  1633. }
  1634. else if (bgRef != null)
  1635. {
  1636. string phClr = ShapeHelper.GetSolidFill(bgRef, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1637. phClr = PowerPointHelper.ColorToning(bgRef.OuterXml, phClr);
  1638. var idx = bgRef.GetTextByPath("@idx");
  1639. if (idx != null)
  1640. {
  1641. int value = int.Parse(idx.Value);
  1642. if (value == 0 || value == 1000)
  1643. {
  1644. return new Fill { Type = 0 };
  1645. //no background
  1646. }
  1647. else if (value > 0 && value < 1000)
  1648. {
  1649. //fillStyleLst in themeContent
  1650. //themeContent["a:fmtScheme"]["a:fillStyleLst"]
  1651. //bgcolor = "background: red;";
  1652. }
  1653. else if (value > 1000)
  1654. {
  1655. var trueIdx = value - 1000;
  1656. var bgFillLst = warpObj.themeContent.GetTextByPath("a:theme/a:themeElements/a:fmtScheme/a:bgFillStyleLst");
  1657. if (bgFillLst != null)
  1658. {
  1659. XmlNodeList nodeList = bgFillLst.ChildNodes;
  1660. if (trueIdx < nodeList.Count)
  1661. {
  1662. string type = ShapeHelper.GetFillType(nodeList[trueIdx - 1]);
  1663. if (type.Equals("SOLID_FILL"))
  1664. {
  1665. if (string.IsNullOrEmpty(phClr))
  1666. {
  1667. phClr = ShapeHelper.GetSolidFill(nodeList[trueIdx - 1], slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1668. }
  1669. if (nodeList[trueIdx - 1] != null) {
  1670. phClr = PowerPointHelper.ColorToning(nodeList[trueIdx - 1].Value, phClr);
  1671. }
  1672. return new Fill { Type = 1, Color = phClr };
  1673. }
  1674. else if (type.Equals("GRADIENT_FILL"))
  1675. {
  1676. return ShapeHelper.GetBgGradientFill(nodeList[trueIdx - 1], phClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1677. }
  1678. else if (type.Equals("PIC_FILL"))
  1679. {
  1680. return await GetPicFill("slideBg", nodeList[trueIdx - 1].GetTextByPath("a:blipFill"), warpObj);
  1681. }
  1682. else
  1683. {
  1684. return new Fill { Type = 0 };
  1685. }
  1686. }
  1687. }
  1688. }
  1689. }
  1690. }
  1691. }
  1692. return null;
  1693. }
  1694. public async Task<Fill> GetPicFill(string type, XmlNode node, WarpObj warpObj)
  1695. {
  1696. //Need to test/////////////////////////////////////////////
  1697. //rId
  1698. //TODO - Image Properties - Tile, Stretch, or Display Portion of Image
  1699. //(http://officeopenxml.com/drwPic-tile.php)
  1700. // var img = "";
  1701. var rId = node.GetTextByPath("a:blip/@r:embed");//node["a:blip"]["attrs"]["r:embed"];
  1702. Dictionary<string, string> imgPath = new Dictionary<string, string>();
  1703. if (type == "slideBg")
  1704. {
  1705. imgPath = warpObj.slideResObj[rId.Value];
  1706. }
  1707. else if (type == "layoutBg")
  1708. {
  1709. imgPath = warpObj.layoutResObj[rId.Value];
  1710. }
  1711. else if (type == "masterBg")
  1712. {
  1713. imgPath = warpObj.masterResObj[rId.Value];
  1714. }
  1715. if (imgPath == null)
  1716. {
  1717. return null;
  1718. }
  1719. //var imgExt = imgPath["type"];
  1720. //if (imgExt == "xml")
  1721. //{
  1722. // return null;
  1723. //}
  1724. var imgData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + imgPath["target"] + "']");
  1725. if (imgData != null)
  1726. {
  1727. AzureBlobModel model = await SaveBase64ToBolob(imgData.InnerText, imgData.GetTextByPath("@pkg:contentType").Value,
  1728. fileShaCode + "/imgs", null);
  1729. return new Fill { Type = 3, Image = model.BlobUrl };
  1730. }
  1731. else { return null; }
  1732. // var imgArrayBuffer = warpObj.zip.GetTextByPath(imgPath).Value.asArrayBuffer();
  1733. //var imgMimeType = GetMimeType(imgExt);
  1734. //img = "data:" + imgMimeType + ";base64," + base64ArrayBuffer(imgArrayBuffer);
  1735. }
  1736. public async Task<Fill> GetShapeFill(XmlNode node, WarpObj warpObj)
  1737. {
  1738. // 1. presentationML
  1739. // p:spPr/ [a:noFill, solidFill, gradFill, blipFill, pattFill, grpFill]
  1740. // From slide
  1741. //Fill Type:
  1742. var fillType = ShapeHelper.GetFillType(node.GetTextByPath("p:spPr"));
  1743. Fill fill = null;
  1744. //0
  1745. if (fillType == "NO_FILL")
  1746. {
  1747. fill = new Fill
  1748. {
  1749. Type = 0,
  1750. HtmlText = "background-color: initial;",
  1751. SvgText = "none"
  1752. };
  1753. //return isSvgMode ? "none" : "background-color: initial;";
  1754. }
  1755. //1纯色填充
  1756. else if (fillType == "SOLID_FILL")
  1757. {
  1758. XmlNode shpFill = node.GetTextByPath("p:spPr/a:solidFill");// node["p:spPr"]["a:solidFill"];
  1759. string color = ShapeHelper.GetSolidFill(shpFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1760. fill = new Fill
  1761. {
  1762. Type = 1,
  1763. Color = color,
  1764. };
  1765. }
  1766. //2渐变色填充
  1767. else if (fillType == "GRADIENT_FILL")
  1768. {
  1769. var shpFill = node.GetTextByPath("p:spPr/a:gradFill");// node["p:spPr"]["a:gradFill"];
  1770. // fillColor = GetSolidFill(shpFill);
  1771. fill = ShapeHelper.GetGradientFill(shpFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1772. }//3图片 纹理填充
  1773. else if (fillType == "PIC_FILL")
  1774. {
  1775. var shpFill = node.GetTextByPath("p:spPr/a:blipFill"); //node["p:spPr"]["a:blipFill"];
  1776. fill = await GetPicFill("slideBg", shpFill, warpObj);
  1777. }//4 图案填充
  1778. else if (fillType == "PATTERN_FILL")
  1779. {
  1780. /*
  1781. *
  1782. *<a:pattFill prst="ltDnDiag">
  1783. <a:fgClr>
  1784. <a:schemeClr val="dk1">
  1785. <a:lumMod val="15000"/>
  1786. <a:lumOff val="85000"/>
  1787. </a:schemeClr>
  1788. </a:fgClr>
  1789. <a:bgClr>
  1790. <a:schemeClr val="lt1"/>
  1791. </a:bgClr>
  1792. </a:pattFill>
  1793. */
  1794. var shpFill = node.GetTextByPath("p:spPr/a:pattFill");// node["p:spPr"]["a:pattFill"];
  1795. fill = ShapeHelper.GetPatternFill(shpFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1796. }
  1797. // 2. drawingML namespace
  1798. if (fill == null)
  1799. {
  1800. var clrName = node.GetTextByPath("p:style/a:fillRef");
  1801. string color = ShapeHelper.GetSolidFill(clrName, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1802. if (clrName != null)
  1803. {
  1804. fillType = "SOLID_FILL";
  1805. color = PowerPointHelper.ColorToning(clrName.OuterXml, color);
  1806. }
  1807. fill = new Fill
  1808. {
  1809. Type = 1,
  1810. Color = color,
  1811. };
  1812. }
  1813. if (fill != null)
  1814. {
  1815. if (fillType == "GRADIENT_FILL")
  1816. {
  1817. //if (isSvgMode)
  1818. //{
  1819. // return fill;
  1820. //}
  1821. //else
  1822. //{
  1823. var colorAry = fill.gradColor;
  1824. var rot = fill.Rot;
  1825. var bgcolor = "background: linear-gradient(" + rot + "deg,";
  1826. for (var i = 0; i < colorAry.Count; i++)
  1827. {
  1828. if (i == colorAry.Count - 1)
  1829. {
  1830. bgcolor += colorAry[i] + ");";
  1831. }
  1832. else
  1833. {
  1834. bgcolor += colorAry[i] + ", ";
  1835. }
  1836. }
  1837. fill.HtmlText = bgcolor;
  1838. return fill;
  1839. // }
  1840. }
  1841. else if (fillType == "PIC_FILL")
  1842. {
  1843. //if (isSvgMode)
  1844. //{
  1845. // return fill;
  1846. //}
  1847. //else
  1848. //{
  1849. fill.HtmlText = "background-image:url(" + fill.Image + ");";
  1850. return fill;
  1851. // }
  1852. }
  1853. else
  1854. {
  1855. Console.WriteLine("#" + fill.Color);
  1856. //if (isSvgMode)
  1857. //{
  1858. // var color = new colz.Color(fill);
  1859. // fill = color.rgb.toString();
  1860. fill.HtmlText = "background-color: #" + fill.Color + ";";
  1861. return fill;
  1862. //}
  1863. //else
  1864. //{
  1865. // return fill;
  1866. //}
  1867. }
  1868. }
  1869. else
  1870. {
  1871. //if (isSvgMode)
  1872. //{
  1873. // return fill;
  1874. //}
  1875. //else
  1876. //{
  1877. fill.SvgText = "none";
  1878. fill.HtmlText = "background-color: initial;";
  1879. return fill;
  1880. // }
  1881. }
  1882. }
  1883. public async Task<AzureBlobModel> GetThumbnailModel(XmlDocument xdoc, string shaCode)
  1884. {
  1885. var thumbnailNode = xdoc.GetTextByPath("//pkg:part[@pkg:name='/docProps/thumbnail.jpeg']");
  1886. if (thumbnailNode != null)
  1887. {
  1888. var contentType = thumbnailNode.GetTextByPath("@pkg:contentType");
  1889. var thumbnail = thumbnailNode.InnerText;
  1890. return await SaveBase64ToBolob(thumbnail, contentType.Value, shaCode + "/imgs", "thumbnail");
  1891. }
  1892. return null;
  1893. }
  1894. public XmlNode LoadTheme(XmlDocument xdoc)
  1895. {
  1896. 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");
  1897. // "/ppt/theme/theme1.xml"
  1898. string themeURI = "/ppt/" + themeRelationship.Value;
  1899. return xdoc.GetTextByPath("//pkg:part[@pkg:name='" + themeURI + "']");
  1900. }
  1901. public async Task<AzureBlobModel> SaveBase64ToBolob(string data, string contentType, string FolderName, string fileName)
  1902. {
  1903. string fileExt;
  1904. if (ContentTypeDict.extdict.TryGetValue(contentType, out string ext))
  1905. {
  1906. fileExt = ext;
  1907. }
  1908. else
  1909. {
  1910. //解决多种扩展名不能获取的
  1911. string[] sp = contentType.Split("/");
  1912. fileExt = sp[sp.Length - 1];
  1913. sp = fileExt.Split("+");
  1914. fileExt = "." + sp[sp.Length - 1];
  1915. }
  1916. //data:image/jpeg;base64,
  1917. if (string.IsNullOrEmpty(fileName))
  1918. {
  1919. Stream stream = new MemoryStream(Convert.FromBase64String(data));
  1920. string shaCode = ShaHashHelper.GetSHA1(stream);
  1921. fileName = shaCode + fileExt;
  1922. }
  1923. else
  1924. {
  1925. if (fileName.Split(".").Length == 1)
  1926. {
  1927. fileName += fileExt;
  1928. }
  1929. }
  1930. Stream streamBlob = new MemoryStream(Convert.FromBase64String(data));
  1931. AzureBlobModel model = await azureBlobDBRepository.UploadFileByFolder(streamBlob, FolderName, fileName, "pptx", false);
  1932. return model;
  1933. }
  1934. public async Task<Media> ProcessPicNode(XmlNode node, int order, WarpObj warpObj)
  1935. {
  1936. var xfrmList = "p:spPr/a:xfrm";
  1937. var xfrmNode = node.GetTextByPath(xfrmList);
  1938. Media media = new Media() { Type = "Media" };
  1939. var id = node.GetTextByPath("p:nvPicPr/p:cNvPr/@id");
  1940. XmlNode slideLayoutSpNode = ShapeHelper.GetNodesTable(id, null, null, warpObj, "Layout");
  1941. XmlNode slideMasterSpNode = ShapeHelper.GetNodesTable(id, null, null, warpObj, "Master");
  1942. XmlNode slideLayoutXfrmNode = null;
  1943. if (slideLayoutSpNode != null)
  1944. {
  1945. slideLayoutXfrmNode = slideLayoutSpNode.GetTextByPath(xfrmList);
  1946. }
  1947. XmlNode slideMasterXfrmNode = null;
  1948. if (slideMasterSpNode != null)
  1949. {
  1950. slideMasterXfrmNode = slideMasterSpNode.GetTextByPath(xfrmList);
  1951. }
  1952. double rotate = 0;
  1953. var rotateNode = node.GetTextByPath("p:spPr/a:xfrm/@rot");
  1954. if (rotateNode != null)
  1955. {
  1956. rotate = ShapeHelper.AngleToDegrees(rotateNode);
  1957. }
  1958. Fill fill = await GetShapeFill(node, warpObj);
  1959. media.Fill = fill;
  1960. Border border = ShapeHelper.GetBorder(node, true, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1961. media.Border = border;
  1962. Position position = ShapeHelper.GetPosition(xfrmNode, slideLayoutXfrmNode, slideMasterXfrmNode);
  1963. media.Position = position;
  1964. position.Rot = rotate;
  1965. var rtrnData = "";
  1966. //image
  1967. var rid = node.GetTextByPath("p:blipFill/a:blip/@r:embed");
  1968. if (rid != null)
  1969. {
  1970. var imgName = warpObj.slideResObj[rid.Value]["target"];
  1971. if (!string.IsNullOrEmpty(imgName))
  1972. {
  1973. var imgData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + imgName + "']");
  1974. var imgFileExt = imgData.GetTextByPath("@pkg:contentType");
  1975. AzureBlobModel imgModel = await SaveBase64ToBolob(imgData.InnerText, imgFileExt.Value, fileShaCode + "/imgs", "");
  1976. media.Image = imgModel.BlobUrl;
  1977. media.MediaType = "image";
  1978. }
  1979. }
  1980. ///////////////////////////////////////Amir//////////////////////////////
  1981. //video
  1982. var vdoNode = node.GetTextByPath("p:nvPicPr/p:nvPr/a:videoFile/@r:link");
  1983. if (vdoNode != null)
  1984. {
  1985. string vdoFile = warpObj.slideResObj[vdoNode.Value]["target"];
  1986. if (!string.IsNullOrEmpty(vdoFile))
  1987. {
  1988. var videoData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + vdoFile + "']");
  1989. var contentType = videoData.GetTextByPath("@pkg:contentType");
  1990. AzureBlobModel vdoModel = await SaveBase64ToBolob(videoData.InnerText, contentType.Value, fileShaCode + "/media", "");
  1991. media.Url = vdoModel.BlobUrl;
  1992. media.MediaType = "video";
  1993. }
  1994. /// 处理为AzureBlob 上传
  1995. // vdoMimeType = getMimeType(vdoFileExt);
  1996. // blob = new Blob([uInt8Array], {
  1997. // type: vdoMimeType
  1998. // });
  1999. // vdoBlob = URL.createObjectURL(blob);
  2000. }
  2001. //audio
  2002. var audioNode = node.GetTextByPath("p:nvPicPr/p:nvPr/a:audioFile/@r:link");
  2003. // var audioObjc;
  2004. if (audioNode != null)
  2005. {
  2006. string audioFile = warpObj.slideResObj[audioNode.Value]["target"];
  2007. if (!string.IsNullOrEmpty(audioFile))
  2008. {
  2009. var audioData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + audioFile + "']");
  2010. var contentType = audioData.GetTextByPath("@pkg:contentType");
  2011. AzureBlobModel adoModel = await SaveBase64ToBolob(audioData.InnerText, contentType.Value, fileShaCode + "/media", "");
  2012. media.Url = adoModel.BlobUrl;
  2013. media.MediaType = "audio";
  2014. }
  2015. //uInt8ArrayAudio = zip.file(audioFile).asArrayBuffer();
  2016. //blobAudio = new Blob([uInt8ArrayAudio]);
  2017. //audioBlob = URL.createObjectURL(blobAudio);
  2018. //var cx = parseInt(xfrmNode["a:ext"]["attrs"]["cx"]) * 20;
  2019. //var cy = xfrmNode["a:ext"]["attrs"]["cy"];
  2020. //var x = parseInt(xfrmNode["a:off"]["attrs"]["x"]) / 2.5;
  2021. //var y = xfrmNode["a:off"]["attrs"]["y"];
  2022. //audioObjc = {
  2023. // "a:ext" : {
  2024. // "attrs":{
  2025. // "cx":cx,
  2026. // "cy":cy
  2027. // }
  2028. // },
  2029. // "a:off":{
  2030. // "attrs":{
  2031. // "x":x,
  2032. // "y":y
  2033. // }
  2034. // }
  2035. //}
  2036. // mediaSupportFlag = true;
  2037. }
  2038. //////////////////////////////////////////////////////////////////////////
  2039. //mimeType = imgFileExt;
  2040. //rtrnData = "<div class='block content' style='" +
  2041. // (( audioPlayerFlag) ? GetPosition(audioObjc, null, null) : GetPosition(xfrmNode, null, null)) +
  2042. // (( audioPlayerFlag) ? GetSize(audioObjc, null, null) :GetSize(xfrmNode, null, null)) +
  2043. // " z-index: " + order + ";" +
  2044. // "transform: rotate(" + rotate + "deg);'>";
  2045. //if ((vdoNode ==null && audioNode ==null) || !mediaSupportFlag)
  2046. //{
  2047. // rtrnData += "<img src='data:" + mimeType + ";base64," + base64ArrayBuffer(imgArrayBuffer) + "' style='width: 100%; height: 100%'/>";
  2048. //}
  2049. //else if ((vdoNode !=null || audioNode !=null) && mediaSupportFlag)
  2050. //{
  2051. // if (vdoNode !=null)
  2052. // {
  2053. // rtrnData += "<video src='" + vdoBlob + "' controls style='width: 100%; height: 100%'>Your browser does not support the video tag.</video>";
  2054. // }
  2055. // if (audioNode !=null)
  2056. // {
  2057. // rtrnData += "<audio id='audio_player' controls ><source src='" + audioBlob + "'></audio>";
  2058. // }
  2059. //}
  2060. rtrnData += "<span style='color:red;font-size:40px;position: absolute;'>This media file Not supported by HTML5</span>";
  2061. //if ((vdoNode != null || audioNode != null) && mediaSupportFlag)
  2062. //{
  2063. //}
  2064. rtrnData += "</div>";
  2065. return media;
  2066. }
  2067. }
  2068. }