HtexService.cs 151 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176
  1. using DocumentFormat.OpenXml.Packaging;
  2. using TEAMModelOS.Service.Model.PowerPoint;
  3. using Microsoft.AspNetCore.Http;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Xml;
  10. using System.Xml.Linq;
  11. using TEAMModelOS.SDK.Context.Constant;
  12. using TEAMModelOS.SDK.Context.Constant.Common;
  13. using TEAMModelOS.SDK.Context.Exception;
  14. using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
  15. using TEAMModelOS.SDK.Helper.Security.ShaHash;
  16. using TEAMModelOS.SDK.Module.AzureBlob.Container;
  17. using TEAMModelOS.SDK.Module.AzureBlob.Interfaces;
  18. using TEAMModelOS.Service.Models.PowerPoint.Inner;
  19. using Fill = TEAMModelOS.Service.Model.PowerPoint.Fill;
  20. using Media = TEAMModelOS.Service.Model.PowerPoint.Media;
  21. using Position = TEAMModelOS.Service.Model.PowerPoint.Position;
  22. using TEAMModelOS.Service.Services.PowerPoint.Interface;
  23. using TEAMModelOS.Service.Models.Exam.Models;
  24. using TEAMModelOS.Service.Services.Exam.Interfaces;
  25. using TEAMModelOS.SDK.Helper.Common.JsonHelper;
  26. namespace TEAMModelOS.Service.Services.PowerPoint.Implement
  27. {
  28. public class HtexService : IHtexService
  29. {
  30. private string fileShaCode { get; set; }
  31. private Dictionary<string, string> slideLayoutClrOvride { get; set; }
  32. private const int degree = 4;
  33. //private Dictionary<string, Dictionary<string, string>> styleTable = new Dictionary<string, Dictionary<string, string>>();
  34. private const double px96 = 96.00, px72 = 72.00, px914400 = 914400.00, px12700 = 12700.00;
  35. private const double rot60000 = 60000.00;
  36. public readonly IAzureBlobDBRepository azureBlobDBRepository;
  37. public readonly IHtmlAnalyzeService htmlAnalyzeService;
  38. public HtexService(IAzureBlobDBRepository _azureBlobDBRepository, IHtmlAnalyzeService _htmlAnalyzeService)
  39. {
  40. azureBlobDBRepository = _azureBlobDBRepository;
  41. htmlAnalyzeService = _htmlAnalyzeService;
  42. }
  43. public async Task<Htex> AnalyzeHtmlToHtex(string htmlString, string Lang)
  44. {
  45. Htex htex = new Htex();
  46. List<ExamItem> items = htmlAnalyzeService.AnalyzeWordAsync(htmlString, Lang);
  47. string sha= ShaHashHelper.GetSHA1(htmlString);
  48. int index = 0;
  49. foreach (ExamItem item in items)
  50. {
  51. Slide slide = new Slide { exercise = item, index = index, source = 2, flag = 2 };
  52. index++;
  53. AzureBlobModel model= await azureBlobDBRepository.UploadTextByFolder(slide.ToJson(), sha, index+".json","htex",false);
  54. htex.slides.Add(model.BlobUrl);
  55. }
  56. htex.page = items.Count;
  57. return htex;
  58. }
  59. public async Task<Dictionary<string, object>> LoadDoc(IFormFile file)
  60. {
  61. Dictionary<string, object> resdict = new Dictionary<string, object>();
  62. if (FileType.GetExtention(file.FileName).ToLower().Equals("pptx"))
  63. {
  64. return await ConvertPPTX(file, resdict);
  65. }
  66. else if (FileType.GetExtention(file.FileName).ToLower().Equals("pdf"))
  67. {
  68. // await ProcessPDF(file, resdict);
  69. return resdict;
  70. }
  71. else if (FileType.GetExtention(file.FileName).ToLower().Equals("xml"))
  72. {
  73. XmlDocument xmlDocument = new XmlDocument();
  74. StreamReader sr = new StreamReader(file.OpenReadStream(), System.Text.Encoding.UTF8);
  75. string line;
  76. StringBuilder builder = new StringBuilder();
  77. while ((line = sr.ReadLine()) != null)
  78. {
  79. builder.Append(line.ToString());
  80. }
  81. sr.Close();
  82. xmlDocument.LoadXml(builder.ToString());
  83. string shaCode = fileShaCode = ShaHashHelper.GetSHA1(file.OpenReadStream());
  84. var rslt_ary = await ProcessPPTX(xmlDocument, shaCode);
  85. //TODO
  86. Dictionary<string, object> data = new Dictionary<string, object> { { "htexl", rslt_ary } };
  87. return data;
  88. }
  89. else
  90. {
  91. throw new BizException("file type does not support!", 500);
  92. }
  93. }
  94. public async Task<Dictionary<string, object>> ConvertPPTX(IFormFile file, Dictionary<string, object> resdict)
  95. {
  96. string shaCode = fileShaCode = ShaHashHelper.GetSHA1(file.OpenReadStream());
  97. PresentationDocument presentationDocument = PresentationDocument.Open(file.OpenReadStream(), false);
  98. if (presentationDocument == null)
  99. {
  100. throw new ArgumentNullException("presentationDocument");
  101. }
  102. XDocument xdoc = presentationDocument.ToFlatOpcDocument();
  103. XmlDocument xmlDocument = new XmlDocument();
  104. xmlDocument.LoadXml(xdoc.ToString());
  105. var rslt_ary = await ProcessPPTX(xmlDocument, shaCode);
  106. //TODO
  107. Dictionary<string, object> data = new Dictionary<string, object> { { "pptx",rslt_ary} };
  108. return data;
  109. }
  110. /// <summary>
  111. /// 加载PPTX文件
  112. /// </summary>
  113. /// <param name="presentationFile"></param>
  114. /// <returns></returns>
  115. public async Task<Htex> ProcessPPTX(XmlDocument xdoc, string shaCode)
  116. {
  117. Htex pptx = new Htex();
  118. // List<Dictionary<string, object>> post_ary = new List<Dictionary<string, object>>();
  119. Dictionary<string, object> post_ary = new Dictionary<string, object>();
  120. var dateBefore = DateTimeOffset.Now.UtcTicks;
  121. AzureBlobModel thumbnailModel = await GetThumbnailModel(xdoc, shaCode);
  122. // post_ary.Add( "pptx-thumb", thumbnailModel );
  123. pptx.thumbnail = thumbnailModel != null ? thumbnailModel.BlobUrl : "";
  124. //获取全部的/ppt/slides/slide1.xml--->>/ppt/slides/slide(n).xml
  125. var slideNodes = xdoc.GetTextByPathList("//pkg:part[@pkg:contentType='application/vnd.openxmlformats-officedocument.presentationml.slide+xml']");
  126. //获取全部的/ppt/slideLayouts/slideLayout1.xml--->>/ppt/slideLayouts/slideLayout(n).xml
  127. var slideLayoutNodes = xdoc.GetTextByPathList("//pkg:part[@pkg:contentType='application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml']");
  128. //获取ppt的宽高
  129. var slideSize = ShapeHelper.GetSlideSize(xdoc);
  130. pptx.size = new HtexSize { width = slideSize.width, height = slideSize.height };
  131. // post_ary.Add( "slideSize", slideSize );
  132. //加载当前PPT使用到的PPT节点
  133. var themeContent = LoadTheme(xdoc);
  134. //获取所有的表格样式节点
  135. var tableStyles = xdoc.GetTextByPath("//pkg:part[@pkg:name='/ppt/tableStyles.xml']/pkg:xmlData/a:tblStyleLst");
  136. //处理slide1---slide(n)
  137. int numOfSlides = slideNodes.Count;
  138. List<Slide> slides = new List<Slide>();
  139. for (int i = 0; i < numOfSlides; i++)
  140. {
  141. var node = xdoc.GetTextByPath("//pkg:part[@pkg:name='/ppt/slides/slide" + (i + 1) + ".xml']");
  142. string filename = node.GetTextByPath("@pkg:name").Value;
  143. //处理当前页的幻灯片
  144. Slide slide = await ProcessSingleSlide(xdoc, node, filename, i, slideSize, themeContent, tableStyles, pptx);
  145. slide.source = 1;
  146. slide.flag = 1;
  147. AzureBlobModel model = await azureBlobDBRepository.UploadTextByFolder(slide.ToJson(), shaCode, (i + 1) + ".json", "htex", false);
  148. pptx.slides.Add(model.BlobUrl);
  149. slides.Add(slide);
  150. // post_ary.Add(new Dictionary<string, object> { { "slide", slideHtml } });
  151. // post_ary.Add(new Dictionary<string, object> { { "progress-update", (i + 1) * 100 / numOfSlides } });
  152. }
  153. // pptx.Sha1Code = shaCode;
  154. pptx.page = slides.Count;
  155. //post_ary.Add( "slide", slides );
  156. //post_ary.Add( "globalCSS", GenGlobalCSS() );
  157. // var dateAfter = DateTimeOffset.Now.UtcTicks;
  158. // post_ary.Add( "ExecutionTime", dateAfter - dateBefore );
  159. return pptx;
  160. }
  161. //public Dictionary<string, string> GenGlobalCSS()
  162. //{
  163. // Dictionary<string, string> cssText = new Dictionary<string, string>();
  164. // foreach (var key in styleTable.Keys)
  165. // {
  166. // // cssText += "div ." + styleTable[key]["name"] + "{" + styleTable[key]["text"] + "}\n"; //section > div
  167. // var cssTextKey = styleTable[key]["name"];
  168. // var cssTextValue = styleTable[key]["text"];
  169. // cssText.Add(cssTextKey, cssTextValue);
  170. // }
  171. // return cssText;
  172. //}
  173. public async Task<Slide> ProcessSingleSlide(XmlDocument xdoc, XmlNode xnode, string sldFileName, int index, dynamic slideSize, XmlNode themeContent, XmlNode tableStyles,Htex pptx)
  174. {
  175. var resName = sldFileName.Replace("slides/slide", "slides/_rels/slide") + ".rels";
  176. var RelationshipArray = xdoc.GetTextByPathList("//pkg:part[@pkg:name='" + resName + "']/pkg:xmlData/rel:Relationships/rel:Relationship");
  177. Dictionary<string, Dictionary<string, string>> slideResObj = new Dictionary<string, Dictionary<string, string>>();
  178. var layoutFilename = "";
  179. foreach (XmlNode Relationship in RelationshipArray)
  180. {
  181. var RelationshipType = Relationship.GetTextByPath("@Type");
  182. if (RelationshipType.Value.Equals("http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout"))
  183. {
  184. layoutFilename = Relationship.GetTextByPath("@Target").Value.Replace("../", "/ppt/");
  185. }
  186. else
  187. {
  188. //case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide":
  189. //case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image":
  190. //case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart":
  191. //case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink":
  192. Dictionary<string, string> dict = new Dictionary<string, string>();
  193. string Type = Relationship.GetTextByPath("@Type").Value.Replace("http://schemas.openxmlformats.org/officeDocument/2006/relationships/", "");
  194. string Target = Relationship.GetTextByPath("@Target").Value.Replace("../", "/ppt/");
  195. string Id = Relationship.GetTextByPath("@Id").Value;
  196. dict.Add("type", Type);
  197. dict.Add("target", Target);
  198. slideResObj.Add(Id, dict);
  199. }
  200. }
  201. // Open slideLayoutXX.xml
  202. var slideLayoutContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + layoutFilename + "']");
  203. NodesTable slideLayoutTables = ShapeHelper.IndexNodes(slideLayoutContent.GetTextByPath("pkg:xmlData/p:sldLayout"));
  204. ///ppt/slides/slide5.xml 也包含a:overrideClrMapping
  205. ////ppt/slideLayouts/slideLayout13.xml 也包含a:overrideClrMapping
  206. var sldLayoutClrOvr = slideLayoutContent.GetTextByPath("pkg:xmlData/p:sldLayout/p:clrMapOvr/a:overrideClrMapping");
  207. if (sldLayoutClrOvr != null)
  208. {
  209. //获取 overrideClrMapping所有属性节点
  210. slideLayoutClrOvride = new Dictionary<string, string>() {
  211. { "accent1", sldLayoutClrOvr.GetTextByPath("@accent1").Value},
  212. { "accent2", sldLayoutClrOvr.GetTextByPath("@accent2").Value},
  213. { "accent3", sldLayoutClrOvr.GetTextByPath("@accent3").Value},
  214. { "accent4", sldLayoutClrOvr.GetTextByPath("@accent4").Value},
  215. { "accent5", sldLayoutClrOvr.GetTextByPath("@accent5").Value},
  216. { "accent6", sldLayoutClrOvr.GetTextByPath("@accent6").Value},
  217. { "bg1", sldLayoutClrOvr.GetTextByPath("@bg1").Value},
  218. { "bg2", sldLayoutClrOvr.GetTextByPath("@bg2").Value},
  219. { "folHlink", sldLayoutClrOvr.GetTextByPath("@folHlink").Value},
  220. { "hlink", sldLayoutClrOvr.GetTextByPath("@hlink").Value},
  221. { "tx1", sldLayoutClrOvr.GetTextByPath("@tx1").Value},
  222. { "tx2", sldLayoutClrOvr.GetTextByPath("@tx2").Value}
  223. };
  224. }
  225. // =====< Step 2 >=====
  226. // Read slide master filename of the slidelayout (Get slideMasterXX.xml)
  227. // @resName: ppt/slideLayouts/slideLayout1.xml
  228. // @masterName: ppt/slideLayouts/_rels/slideLayout1.xml.rels
  229. var slideLayoutResFilename = layoutFilename.Replace("slideLayouts/slideLayout", "slideLayouts/_rels/slideLayout") + ".rels";
  230. var slideLayoutResContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + slideLayoutResFilename + "']");
  231. ///查看js 是替换之前 还是添加
  232. RelationshipArray = slideLayoutResContent.GetTextByPathList("pkg:xmlData/rel:Relationships/rel:Relationship");
  233. var masterFilename = "";
  234. Dictionary<string, Dictionary<string, string>> layoutResObj = new Dictionary<string, Dictionary<string, string>>();
  235. for (int i = 0; i < RelationshipArray.Count; i++)
  236. {
  237. if (RelationshipArray[i].GetTextByPath("@Type").Value.Equals("http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster"))
  238. {
  239. masterFilename = RelationshipArray[i].GetTextByPath("@Target").Value.Replace("../", "/ppt/");
  240. }
  241. else
  242. {
  243. Dictionary<string, string> dict = new Dictionary<string, string>();
  244. string Type = RelationshipArray[i].GetTextByPath("@Type").Value.Replace("http://schemas.openxmlformats.org/officeDocument/2006/relationships/", "");
  245. string Target = RelationshipArray[i].GetTextByPath("@Target").Value.Replace("../", "/ppt/");
  246. string Id = RelationshipArray[i].GetTextByPath("@Id").Value;
  247. dict.Add("type", Type);
  248. dict.Add("target", Target);
  249. layoutResObj.Add(Id, dict);
  250. }
  251. }
  252. // Open slideMasterXX.xml
  253. var slideMasterContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + masterFilename + "']");
  254. var slideMasterTextStyles = slideMasterContent.GetTextByPath("pkg:xmlData/p:sldMaster/p:txStyles");
  255. var slideMasterTables = ShapeHelper.IndexNodes(slideMasterContent.GetTextByPath("pkg:xmlData/p:sldMaster"));
  256. /////////////////Amir/////////////
  257. //Open slideMasterXX.xml.rels
  258. var slideMasterResFilename = masterFilename.Replace("slideMasters/slideMaster", "slideMasters/_rels/slideMaster") + ".rels";
  259. var slideMasterResContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + slideMasterResFilename + "']");
  260. RelationshipArray = slideMasterResContent.GetTextByPathList("pkg:xmlData/rel:Relationships/rel:Relationship");
  261. var themeFilename = "";
  262. Dictionary<string, Dictionary<string, string>> masterResObj = new Dictionary<string, Dictionary<string, string>>();
  263. for (int i = 0; i < RelationshipArray.Count; i++)
  264. {
  265. if (RelationshipArray[i].GetTextByPath("@Type").Value.Equals("http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"))
  266. {
  267. themeFilename = RelationshipArray[i].GetTextByPath("@Target").Value.Replace("../", "/ppt/");
  268. }
  269. else
  270. {
  271. Dictionary<string, string> dict = new Dictionary<string, string>();
  272. string Type = RelationshipArray[i].GetTextByPath("@Type").Value.Replace("http://schemas.openxmlformats.org/officeDocument/2006/relationships/", "");
  273. string Target = RelationshipArray[i].GetTextByPath("@Target").Value.Replace("../", "/ppt/");
  274. string Id = RelationshipArray[i].GetTextByPath("@Id").Value;
  275. dict.Add("type", Type);
  276. dict.Add("target", Target);
  277. masterResObj.Add(Id, dict);
  278. }
  279. }
  280. //Load Theme file
  281. if (!string.IsNullOrEmpty(themeFilename))
  282. {
  283. themeContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + themeFilename + "']");
  284. }
  285. // =====< Step 3 >===== throw new NotImplementedException();
  286. var slideContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + sldFileName + "']");
  287. var spTreeNode = slideContent.GetTextByPath("pkg:xmlData/p:sld/p:cSld/p:spTree");
  288. WarpObj warpObj = new WarpObj
  289. {
  290. zip = xdoc,
  291. slideLayoutTables = slideLayoutTables,
  292. slideMasterTables = slideMasterTables,
  293. slideMasterTextStyles = slideMasterTextStyles,
  294. slideResObj = slideResObj,
  295. layoutResObj = layoutResObj,
  296. masterResObj = masterResObj,
  297. slideLayoutContent = slideLayoutContent,
  298. slideMasterContent = slideMasterContent,
  299. themeContent = themeContent,
  300. tableStyles = tableStyles,
  301. htex = pptx
  302. };
  303. var bgColor = await GetSlideBackgroundFill(slideContent, index, warpObj);
  304. //string sha = null;
  305. //if (bgColor != null) {
  306. // sha = ShaHashHelper.GetSHA1(bgColor.ToJson());
  307. // warpObj.pptx.Fills.TryAdd(sha, bgColor);
  308. //}
  309. // string result = "<div class='slide' style='width:" + slideSize.width + "px; height:" + slideSize.height + "px;" + bgColor + "'>";
  310. //result += "<div>"+getBackgroundShapes(slideContent, slideLayoutContent, slideMasterContent,warpObj) + "</div>" - TODO
  311. Slide slide = new Slide { fill=bgColor ,width= slideSize .width ,height= slideSize .height ,index=index };
  312. if (spTreeNode != null)
  313. {
  314. var nodes = spTreeNode.ChildNodes;
  315. int order = 1;
  316. List<Item> items = new List<Item>();
  317. foreach (XmlNode node in nodes)
  318. {
  319. await ProcessNodesInSlide(items, node.Name, node, order, warpObj);
  320. order += 1;
  321. }
  322. slide.item = items;
  323. }
  324. return slide;
  325. }
  326. public async Task ProcessNodesInSlide(List<Item> items, string nodeKey, XmlNode node, int order, WarpObj warpObj)
  327. {
  328. // string result = "";
  329. switch (nodeKey)
  330. {
  331. case "p:sp": // Shape, Text
  332. Item spitem= await ProcessSpNode(node, order, warpObj);
  333. if (spitem != null) {
  334. items.Add(spitem);
  335. }
  336. break;
  337. case "p:cxnSp": // Shape, Text (with connection)
  338. Item cxnitem = await ProcessCxnSpNode(node, order, warpObj);
  339. if (cxnitem != null)
  340. {
  341. items.Add(cxnitem);
  342. }
  343. break;
  344. case "p:pic": // Picture
  345. Item picitem = await ProcessPicNode(node, order, warpObj);
  346. if (picitem != null) {
  347. items.Add(picitem);
  348. }
  349. break;
  350. case "p:graphicFrame": // Chart, Diagram, Table
  351. await ProcessGraphicFrameNode(items, node, order, warpObj);
  352. break;
  353. case "p:grpSp":
  354. await ProcessGroupSpNode(items, node, order, warpObj);
  355. break;
  356. case "mc:AlternateContent": //Equations and formulas as Image 处理公式 方程等
  357. var mcFallbackNode = node.GetTextByPath("mc:Fallback/p:sp");
  358. if (mcFallbackNode != null)
  359. {
  360. Item mcitem = await ProcessSpNode(mcFallbackNode, order, warpObj);
  361. if (mcitem != null)
  362. {
  363. items.Add(mcitem);
  364. }
  365. }
  366. else {
  367. mcFallbackNode = node.GetTextByPath("mc:Fallback/p:pic");
  368. if (mcFallbackNode != null) {
  369. Item mcPicitem = await ProcessPicNode(mcFallbackNode, order, warpObj);
  370. if (mcPicitem != null)
  371. {
  372. items.Add(mcPicitem);
  373. }
  374. }
  375. }
  376. break;
  377. default:
  378. break;
  379. }
  380. }
  381. public async Task ProcessGroupSpNode(List<Item> items, XmlNode node, int order, WarpObj warpObj)
  382. {
  383. var factor = 1.00 * px96 / px914400;
  384. var xfrmNode = node.GetTextByPath("p:grpSpPr/a:xfrm");
  385. var x = int.Parse(xfrmNode.GetTextByPath("a:off/@x").Value) * factor;
  386. var y = int.Parse(xfrmNode.GetTextByPath("a:off/@y").Value) * factor;
  387. var chx = int.Parse(xfrmNode.GetTextByPath("a:chOff/@x").Value) * factor;
  388. var chy = int.Parse(xfrmNode.GetTextByPath("a:chOff/@y").Value) * factor;
  389. var cx = int.Parse(xfrmNode.GetTextByPath("a:ext/@cx").Value) * factor;
  390. var cy = int.Parse(xfrmNode.GetTextByPath("a:ext/@cy").Value) * factor;
  391. var chcx = int.Parse(xfrmNode.GetTextByPath("a:chExt/@cx").Value) * factor;
  392. var chcy = int.Parse(xfrmNode.GetTextByPath("a:chExt/@cy").Value) * factor;
  393. var rotate = ShapeHelper.AngleToDegrees(xfrmNode.GetTextByPath("@rot"));
  394. // string result = "<div class='block group' style='z-index: " + order + "; top: " + (y - chy) + "px; left: " + (x - chx) + "px;" +
  395. // " width: " + (cx - chcx) + "px; height: " + (cy - chcy) + "px;'>";
  396. Group group = new Group
  397. {
  398. position = new Position { x = System.Math.Round(x - chx, degree), y = System.Math.Round(y - chy, degree), cx = System.Math.Round(cx - chcx, degree), cy = System.Math.Round(cy - chcy, degree), rot = System.Math.Round(rotate, degree) },
  399. type = "Group",
  400. index = order++
  401. };
  402. // Procsee all child nodes
  403. var nodes = node.ChildNodes;
  404. List<Item> gpIterm = new List<Item>();
  405. foreach (XmlNode nd in nodes)
  406. {
  407. await ProcessNodesInSlide(gpIterm, nd.Name, nd, order, warpObj);
  408. order += 1;
  409. }
  410. group.shapes = gpIterm;
  411. items.Add(group);
  412. // result += "</div>";
  413. //return result;
  414. }
  415. public async Task ProcessGraphicFrameNode(List<Item> items, XmlNode node, int order, WarpObj warpObj)
  416. {
  417. // var result = "";
  418. var graphicTypeUri = node.GetTextByPath("a:graphic/a:graphicData/@uri");
  419. if (graphicTypeUri != null)
  420. {
  421. switch (graphicTypeUri.Value)
  422. {
  423. case "http://schemas.openxmlformats.org/drawingml/2006/table":
  424. Table table= await GenTable(node, order, warpObj);
  425. items.Add(table);
  426. break;
  427. case "http://schemas.openxmlformats.org/drawingml/2006/chart":
  428. items.Add(GenChart(node, order, warpObj));
  429. break;
  430. case "http://schemas.openxmlformats.org/drawingml/2006/diagram":
  431. await GenDiagram(items, node, order, warpObj);
  432. break;
  433. default:
  434. break;
  435. }
  436. }
  437. //return result;
  438. }
  439. public async Task GenDiagram(List<Item> items, XmlNode node, int order, WarpObj warpObj)
  440. {
  441. var xfrmNode = node.GetTextByPath("p:xfrm");
  442. var dgmRelIds = node.GetTextByPath("a:graphic/a:graphicData/dgm:relIds");
  443. var dgmClrFileId = dgmRelIds.GetTextByPath("@r:cs");
  444. var dgmDataFileId = dgmRelIds.GetTextByPath("@r:dm");
  445. var dgmLayoutFileId = dgmRelIds.GetTextByPath("@r:lo");
  446. var dgmQuickStyleFileId = dgmRelIds.GetTextByPath("@r:qs");
  447. var dgmClrFileName = warpObj.slideResObj[dgmClrFileId.Value]["target"];
  448. var dgmDataFileName = warpObj.slideResObj[dgmDataFileId.Value]["target"];
  449. var dgmLayoutFileName = warpObj.slideResObj[dgmLayoutFileId.Value]["target"];
  450. var dgmQuickStyleFileName = warpObj.slideResObj[dgmQuickStyleFileId.Value]["target"];
  451. var dgmClr = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + dgmClrFileName + "']");
  452. var dgmData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + dgmDataFileName + "']");
  453. var dgmLayout = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + dgmLayoutFileName + "']");
  454. var dgmQuickStyle = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + dgmQuickStyleFileName + "']");
  455. var dgmDrwFileName = "";
  456. var dataModelExt = dgmData.GetTextByPath("pkg:xmlData/dgm:dataModel/dgm:extLst/a:ext/dsp:dataModelExt");
  457. if (dataModelExt != null) {
  458. var dgmDrwFileId = dataModelExt.GetTextByPath("@relId");
  459. dgmDrwFileName = warpObj.slideResObj[dgmDrwFileId.Value]["target"];
  460. }
  461. XmlNode dgmDrwFile=null ;
  462. if (dgmDrwFileName != "")
  463. {
  464. dgmDrwFile = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + dgmDrwFileName + "']");
  465. }
  466. var dgmDrwSpArray = dgmDrwFile.GetTextByPathList("pkg:xmlData/dsp:drawing/dsp:spTree/dsp:sp");
  467. if (dgmDrwSpArray !=null)
  468. {
  469. Diagram diagram = new Diagram();
  470. diagram.position = ShapeHelper.GetPosition(xfrmNode, null, null);
  471. diagram.type = "Diagram";
  472. diagram.index = order++;
  473. // Procsee all child nodes
  474. List<Item> gpIterm = new List<Item>();
  475. XmlDocument nodeDoc = new XmlDocument();
  476. var dgmDrwSpArrayLen = dgmDrwSpArray.Count;
  477. for (var i = 0; i < dgmDrwSpArrayLen; i++)
  478. {
  479. var dspSp = dgmDrwSpArray.Item(i);
  480. var pSpStr = dspSp.OuterXml.Replace("dsp:", "p:").Replace("xmlns:dsp=\"http://schemas.microsoft.com/office/drawing/2008/diagram\"", "xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\"");
  481. nodeDoc.LoadXml(pSpStr);
  482. //await ProcessSpNode(nodeDoc,order,warpObj);
  483. await ProcessNodesInSlide(gpIterm, nodeDoc.FirstChild.Name, nodeDoc.FirstChild, order, warpObj);
  484. }
  485. diagram.shapes = gpIterm;
  486. items.Add(diagram);
  487. }
  488. }
  489. public Chart GenChart(XmlNode node,int order , WarpObj warpObj)
  490. {
  491. Chart chart = new Chart { index=order,type= "Chart" };
  492. var slideXfrmNode = node.GetTextByPath("p:xfrm");
  493. Position position = ShapeHelper.GetPosition(slideXfrmNode, null, null);
  494. chart.position = position;
  495. var rid = node.GetTextByPath("a:graphic/a:graphicData/c:chart/@r:id");
  496. List<Paragraph> paragraphs = new List<Paragraph>() ;
  497. if (rid != null) {
  498. var refName= warpObj.slideResObj[rid.Value]["target"];
  499. var content = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + refName + "']");
  500. var plotArea = content.GetTextByPath("pkg:xmlData/c:chartSpace/c:chart/c:plotArea");
  501. var chartPnode = content.GetTextByPathList("pkg:xmlData/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p");
  502. var anchor = content.GetTextByPath("pkg:xmlData/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:bodyPr/@anchor");
  503. var vert = content.GetTextByPath("pkg:xmlData/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:bodyPr/@vert");
  504. string VertAlign = "v-up";
  505. string WritingMode = "horz";
  506. if (anchor != null)
  507. {
  508. VertAlign = anchor.Value.Equals("ctr") ? "v-mid" : anchor.Value.Equals("b") ? "v-down" : "v-up";
  509. }
  510. if (vert != null) {
  511. WritingMode = vert.Value;
  512. }
  513. foreach (XmlNode pNode in chartPnode) {
  514. string HoriAlign= GetHorizontalAlign(pNode, null, null, null, null);
  515. // string sha = null;
  516. ParagraphStyle paragraphStyle = new ParagraphStyle
  517. {
  518. hori = HoriAlign,
  519. writing = WritingMode,
  520. vert = VertAlign
  521. };
  522. //sha = ShaHashHelper.GetSHA1(paragraphStyle.ToJson());
  523. //warpObj.pptx.ParagraphStyles.TryAdd(sha, paragraphStyle);
  524. Paragraph paragraph = new Paragraph
  525. {
  526. style = paragraphStyle,
  527. // StyleSha=sha
  528. };
  529. double defFontSize = 0;
  530. string defFontColor = "none";
  531. var defsz= pNode.GetTextByPath("a:pPr/a:defRPr/@sz");
  532. if (defsz != null) {
  533. defFontSize = int.Parse(defsz.Value) / 100.0;
  534. }
  535. var solidFillNode = pNode.GetTextByPath("a:pPr/a:defRPr/a:solidFill");
  536. string colorstr = ShapeHelper.GetSolidFill(solidFillNode, slideLayoutClrOvride,warpObj. slideMasterContent,warpObj. themeContent);
  537. if (solidFillNode != null)
  538. {
  539. defFontColor = ShapeHelper.ColorToning(solidFillNode.OuterXml, colorstr);
  540. }
  541. var rNodes = pNode.GetTextByPathList("a:r");
  542. List<Text> texts = new List<Text>();
  543. foreach (XmlNode rNode in rNodes)
  544. {
  545. Text text = GenSpanElement(rNode, null, null, null, null, warpObj);
  546. if (pNode.GetTextByPath("a:br") != null)
  547. {
  548. text.isbr = true;
  549. }
  550. if (text.style.size == 0) {
  551. text.style.size = defFontSize;
  552. }
  553. if (text.style.color.Equals("000000"))
  554. {
  555. text.style.color = defFontColor;
  556. }
  557. //string styleSha = ShaHashHelper.GetSHA1(text.FontStyle.ToJson());
  558. //warpObj.pptx.FontStyles.TryAdd(styleSha, text.FontStyle);
  559. //text.StyleSha = styleSha;
  560. texts.Add(text);
  561. }
  562. paragraph.texts = texts;
  563. paragraphs.Add(paragraph);
  564. }
  565. chart.title = paragraphs;
  566. var ps = plotArea.ChildNodes;
  567. List<CommonChart> charts = new List<CommonChart>();
  568. foreach (XmlNode nodeChild in ps) {
  569. string key = nodeChild.Name.Replace("c:","");
  570. XmlNodeList serNodes = null;
  571. switch (key)
  572. {
  573. //break块中不可以随意更换,此条件用于归类不同从Chart
  574. case "pieChart":
  575. case "ofPieChart":
  576. case "pie3DChart":
  577. case "doughnutChart":
  578. PieChart pieChart = new PieChart { chartType="pie"};
  579. if (key.Equals("pie3DChart")) {
  580. pieChart.is3D = true;
  581. }
  582. pieChart.pieType = key;
  583. if (key.Equals("ofPieChart")) {
  584. var ofPieType = nodeChild.GetTextByPath("c:ofPieType/@val");
  585. if (ofPieType != null) {
  586. //ofPieChart-pie ofPieChart-bar 子母饼图
  587. pieChart.pieType += "-"+ ofPieType.Value;
  588. }
  589. }
  590. serNodes = nodeChild.GetTextByPathList("c:ser");
  591. pieChart.datas= ExtractChartData(serNodes);
  592. charts.Add(pieChart);
  593. break;
  594. case "lineChart":
  595. case "line3DChart":
  596. LineChart lineChart = new LineChart { chartType = "line" };
  597. if (key.Equals("line3DChart"))
  598. {
  599. lineChart.is3D = true;
  600. }
  601. lineChart.lineType = key;
  602. var LineGrouping = nodeChild.GetTextByPath("c:grouping/@val");
  603. if (LineGrouping != null)
  604. {
  605. //standard stacked percentStacked
  606. lineChart.lineType += "-" + LineGrouping.Value;
  607. }
  608. serNodes = nodeChild.GetTextByPathList("c:ser");
  609. lineChart.datas = ExtractChartData(serNodes);
  610. charts.Add(lineChart);
  611. break;
  612. case "barChart":
  613. case "bar3DChart":
  614. var barDir = nodeChild.GetTextByPath("c:barDir/@val");
  615. if (barDir != null)
  616. {
  617. if (barDir.Value.Equals("bar"))
  618. {
  619. BarChart barChart = new BarChart { chartType = "bar" };
  620. charts.Add(barChart);
  621. if (key.Equals("bar3DChart"))
  622. {
  623. barChart.is3D = true;
  624. }
  625. barChart.barType = key;
  626. var BarGrouping = nodeChild.GetTextByPath("c:grouping/@val");
  627. if (BarGrouping != null)
  628. {
  629. //standard stacked percentStacked
  630. barChart.barType += "-" + BarGrouping.Value;
  631. }
  632. serNodes = nodeChild.GetTextByPathList("c:ser");
  633. barChart.datas = ExtractChartData(serNodes);
  634. charts.Add(barChart);
  635. }
  636. else if(barDir.Value.Equals("col")){
  637. ColChart colChart = new ColChart { chartType = "col" };
  638. if (key.Equals("bar3DChart"))
  639. {
  640. colChart.is3D = true;
  641. }
  642. colChart.colType = key.Replace("bar","col");
  643. var ColGrouping = nodeChild.GetTextByPath("c:grouping/@val");
  644. if (ColGrouping != null)
  645. {
  646. //standard stacked percentStacked
  647. colChart.colType += "-" + ColGrouping.Value;
  648. }
  649. serNodes = nodeChild.GetTextByPathList("c:ser");
  650. colChart.datas = ExtractChartData(serNodes);
  651. charts.Add(colChart);
  652. }
  653. }
  654. break;
  655. case "areaChart":
  656. case "area3DChart":
  657. AreaChart areaChart = new AreaChart { chartType = "area" };
  658. if (key.Equals("area3DChart"))
  659. {
  660. areaChart.is3D = true;
  661. }
  662. areaChart.areaType = key;
  663. var AreaGrouping = nodeChild.GetTextByPath("c:grouping/@val");
  664. if (AreaGrouping != null)
  665. {
  666. //standard stacked percentStacked
  667. areaChart.areaType += "-" + AreaGrouping.Value;
  668. }
  669. serNodes = nodeChild.GetTextByPathList("c:ser");
  670. areaChart.datas = ExtractChartData(serNodes);
  671. charts.Add(areaChart);
  672. break;
  673. case "scatterChart":
  674. case "bubbleChart":
  675. ScatterChart scatterChart = new ScatterChart { chartType = "scatter" };
  676. scatterChart.scatterType = key;
  677. if (key.Equals("scatterChart")) {
  678. var ScatterStyle = nodeChild.GetTextByPath("c:scatterStyle/@val");
  679. if (ScatterStyle != null)
  680. {
  681. scatterChart.scatterType += "-" + ScatterStyle.Value.Replace("Marker","");
  682. }
  683. }
  684. serNodes = nodeChild.GetTextByPathList("c:ser");
  685. scatterChart.datas = ExtractChartData(serNodes);
  686. charts.Add(scatterChart);
  687. break;
  688. case "radarChart":
  689. RadarChart radarChart = new RadarChart { chartType = "radar" };
  690. radarChart.radarType = key;
  691. var RadarStyle = nodeChild.GetTextByPath("c:radarStyle/@val");
  692. if (RadarStyle != null)
  693. {
  694. radarChart.radarType += "-" + RadarStyle.Value;
  695. }
  696. serNodes = nodeChild.GetTextByPathList("c:ser");
  697. radarChart.datas = ExtractChartData(serNodes);
  698. charts.Add(radarChart);
  699. break;
  700. case "plotAreaRegion":
  701. PlotAreaChart plotAreaChart = new PlotAreaChart { chartType = "plotArea" };
  702. plotAreaChart.plotAreaType = key;
  703. var PlotSeries = nodeChild.GetTextByPath("cx:series/@layoutId");
  704. if (PlotSeries != null)
  705. {
  706. plotAreaChart.plotAreaType += "-" + PlotSeries.Value;
  707. }
  708. serNodes = nodeChild.GetTextByPathList("c:ser");
  709. plotAreaChart.datas = ExtractChartData(serNodes);
  710. charts.Add(plotAreaChart);
  711. break;
  712. case "stockChart":
  713. StockChart stockChart = new StockChart { chartType = "stock" };
  714. stockChart.stockType = key;
  715. serNodes = nodeChild.GetTextByPathList("c:ser");
  716. stockChart.datas = ExtractChartData(serNodes);
  717. charts.Add(stockChart);
  718. break;
  719. case "surfaceChart":
  720. case "surface3DChart":
  721. SurfaceChart surfaceChart = new SurfaceChart { chartType = "surface" };
  722. if (key.Equals("surface3DChart"))
  723. {
  724. surfaceChart.is3D = true;
  725. }
  726. surfaceChart.surfaceType = key;
  727. var Wireframe = nodeChild.GetTextByPath("c:wireframe/@val");
  728. if (Wireframe != null)
  729. {
  730. surfaceChart.surfaceType += "-" + Wireframe.Value;
  731. }
  732. serNodes = nodeChild.GetTextByPathList("c:ser");
  733. surfaceChart.datas = ExtractChartData(serNodes);
  734. charts.Add(surfaceChart);
  735. break;
  736. }
  737. }
  738. chart.charts = charts;
  739. }
  740. return chart;
  741. }
  742. public List<Dictionary<string,object>> ExtractChartData(XmlNodeList nodes) {
  743. if (nodes != null) {
  744. List<Dictionary<string, object>> listDict = new List<Dictionary<string, object>>();
  745. foreach(XmlNode node in nodes)
  746. {
  747. if (node.GetTextByPath("c:xVal") != null)
  748. {
  749. Dictionary<string, object> dict = new Dictionary<string, object>();
  750. var xCvNodes = node.GetTextByPathList("c:xVal/c:numRef/c:numCache/c:pt/c:v");
  751. if (xCvNodes != null)
  752. {
  753. List<string> list = new List<string>();
  754. foreach (XmlNode cvNode in xCvNodes)
  755. {
  756. list.Add(cvNode.InnerText);
  757. }
  758. dict.Add("xAxis", list);
  759. }
  760. var yCvNodes = node.GetTextByPathList("c:yVal/c:numRef/c:numCache/c:pt/c:v");
  761. if (yCvNodes != null)
  762. {
  763. List<string> list = new List<string>();
  764. foreach (XmlNode cvNode in yCvNodes)
  765. {
  766. list.Add(cvNode.InnerText);
  767. }
  768. dict.Add("yAxis", list);
  769. }
  770. dict.Add("colName", "-");
  771. listDict.Add(dict);
  772. }
  773. else
  774. {
  775. Dictionary<string, object> dict = new Dictionary<string, object>();
  776. var colNameNode = node.GetTextByPath("c:tx/c:strRef/c:strCache/c:pt/c:v");
  777. if (colNameNode != null) {
  778. dict.Add("colName", colNameNode.InnerText);
  779. }
  780. //name
  781. var catNodes = node.GetTextByPathList("c:cat/c:strRef/c:strCache/c:pt/c:v");
  782. if (catNodes == null) {
  783. catNodes = node.GetTextByPathList("c:cat/c:numRef/c:numCache/c:pt/c:v");
  784. }
  785. if (catNodes != null) {
  786. List<string> list = new List<string>();
  787. foreach (XmlNode cvNode in catNodes)
  788. {
  789. list.Add(cvNode.InnerText);
  790. }
  791. dict.Add("xAxis", list);
  792. }
  793. //value
  794. var valNodes = node.GetTextByPathList("c:val/c:numRef/c:numCache/c:pt/c:v");
  795. if (valNodes != null) {
  796. List<string> list = new List<string>();
  797. foreach (XmlNode cvNode in valNodes)
  798. {
  799. list.Add(cvNode.InnerText);
  800. }
  801. dict.Add("yAxis", list);
  802. }
  803. listDict.Add(dict);
  804. }
  805. }
  806. return listDict;
  807. }
  808. return null;
  809. }
  810. public async Task<Table> GenTable(XmlNode node, int order, WarpObj warpObj)
  811. {
  812. Table table = new Table();
  813. table.index = order;
  814. var slideXfrmNode= node.GetTextByPath("p:xfrm");
  815. Position position = ShapeHelper.GetPosition(slideXfrmNode, null, null);
  816. var tableNode = node.GetTextByPath("a:graphic/a:graphicData/a:tbl");
  817. var getTblPr = tableNode.GetTextByPath("a:tblPr");
  818. var getColsGrid = tableNode.GetTextByPath("a:tblGrid/a:gridCol");
  819. var tblDir = "ltr";
  820. XmlNode firstRowAttr = null , bandRowAttr =null ;
  821. if (getTblPr != null) {
  822. var isRTL = getTblPr.GetTextByPath("@rtl");
  823. tblDir = isRTL!=null && isRTL.Value.Equals("1") ? "rtl" : "ltr";
  824. firstRowAttr = getTblPr.GetTextByPath("@firstRow"); //associated element <a:firstRow> in the table styles
  825. var firstColAttr = getTblPr.GetTextByPath("@firstCol"); //associated element <a:firstCol> in the table styles
  826. var lastRowAttr = getTblPr.GetTextByPath("@lastRow");//associated element <a:lastRow> in the table styles
  827. var lastColAttr = getTblPr.GetTextByPath("@lastCol"); //associated element <a:lastCol> in the table styles
  828. bandRowAttr = getTblPr.GetTextByPath("@bandRow"); //associated element <a:band1H>, <a:band2H> in the table styles
  829. var bandColAttr = getTblPr.GetTextByPath("@bandCol"); //associated element <a:band1V>, <a:band2V> in the table styles
  830. }
  831. table.dir = tblDir;
  832. table.position = position;
  833. table.type = "Table";
  834. var trNodes = tableNode.GetTextByPathList("a:tr");
  835. if (trNodes != null) {
  836. int trSize = trNodes.Count;
  837. for (int i = 0; i < trSize; i++)
  838. {
  839. Tr tr = new Tr();
  840. var rowHeightParam = trNodes.Item(i).GetTextByPath("@h");
  841. double rowHeight = 0;
  842. //var rowsStyl = "";
  843. if (rowHeightParam != null) {
  844. rowHeight = int.Parse(rowHeightParam.Value) * px96 / px914400;
  845. }
  846. tr.height = rowHeight;
  847. XmlNode thisTblStyle=null;
  848. var tbleStyleId = getTblPr.GetTextByPath("a:tableStyleId");
  849. if (tbleStyleId != null)
  850. {
  851. var tbleStylList = warpObj.tableStyles.GetTextByPathList("a:tblStyleLst/a:tblStyle");
  852. foreach (XmlNode tbleStyle in tbleStylList)
  853. {
  854. if (tbleStyle.GetTextByPath("@styleId").Value.Equals(tbleStyleId.Value))
  855. {
  856. thisTblStyle = tbleStyle;
  857. }
  858. }
  859. }
  860. if (i == 0 && firstRowAttr != null && thisTblStyle != null)
  861. {
  862. var fillColor = "fff";
  863. // var colorOpacity = 1;
  864. if (thisTblStyle.GetTextByPath("a:firstRow") != null)
  865. {
  866. //处理纯色填充
  867. var bgFillschemeClr = thisTblStyle.GetTextByPath("a:firstRow/a:tcStyle/a:fill/a:solidFill");
  868. if (bgFillschemeClr != null)
  869. {
  870. fillColor = ShapeHelper.GetSolidFill(bgFillschemeClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  871. fillColor = ShapeHelper.ColorToning(bgFillschemeClr.OuterXml, fillColor);
  872. Fill f = new Fill { color = fillColor, type = 1 };
  873. //string sha = null;
  874. //sha = ShaHashHelper.GetSHA1(f.ToJson());
  875. //warpObj.pptx.Fills.TryAdd(sha, f);
  876. //tr.FillSha = sha;
  877. tr.fill = f;
  878. }
  879. //其他填充 todo
  880. var fill = thisTblStyle.GetTextByPath("a:firstRow/a:tcStyle/a:fill");
  881. string fillType = ShapeHelper.GetFillType(fill);
  882. var borderStyl = thisTblStyle.GetTextByPath("a:firstRow/a:tcStyle/a:tcBdr");
  883. if (borderStyl != null)
  884. {
  885. List<Border> borders = GetTableBorders(borderStyl, warpObj);
  886. tr.borders = borders;
  887. }
  888. //Text Style - TODO
  889. //var rowTxtStyl = getTextByPathList(thisTblStyle,["a:firstRow", "a:tcTxStyle"]);
  890. //if (rowTxtStyl !== undefined)
  891. //{
  892. /*
  893. var fontClrPr = getFontColorPr(node, spNode, type, slideMasterTextStyles);
  894. var styleText =
  895. "color:" + fontClrPr[0] + ";" +
  896. "text-shadow:" + fontClrPr[1] + ";" +
  897. "font-size:" + getFontSize(node, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles) + ";" +
  898. "font-family:" + getFontType(node, type, slideMasterTextStyles) + ";" +
  899. "font-weight:" + getFontBold(node, type, slideMasterTextStyles) + ";" +
  900. "font-style:" + getFontItalic(node, type, slideMasterTextStyles) + ";" +
  901. "text-decoration:" + getFontDecoration(node, type, slideMasterTextStyles) + ";" +
  902. "text-align:" + getTextHorizontalAlign(node, type, slideMasterTextStyles) + ";" +
  903. "vertical-align:" + getTextVerticalAlign(node, type, slideMasterTextStyles) + ";";
  904. */
  905. //}
  906. }
  907. }
  908. else if (i > 0 && bandRowAttr != null && thisTblStyle != null)
  909. {
  910. var fillColor = "fff";
  911. // var colorOpacity = 1;
  912. if ((i % 2) == 0)
  913. {
  914. if (thisTblStyle.GetTextByPath("a:band2H") != null)
  915. {
  916. //处理纯色填充
  917. var bgFillschemeClr = thisTblStyle.GetTextByPath("a:band2H/a:tcStyle/a:fill/a:solidFill");
  918. if (bgFillschemeClr != null)
  919. {
  920. fillColor = ShapeHelper.GetSolidFill(bgFillschemeClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  921. fillColor = ShapeHelper.ColorToning(bgFillschemeClr.OuterXml, fillColor);
  922. Fill f = new Fill { color = fillColor, type = 1 };
  923. //string sha = null;
  924. //sha = ShaHashHelper.GetSHA1(f.ToJson());
  925. //warpObj.pptx.Fills.TryAdd(sha, f);
  926. //tr.FillSha = sha;
  927. tr.fill = f;
  928. }
  929. //其他填充 todo
  930. var fill = thisTblStyle.GetTextByPath("a:band2H/a:tcStyle/a:fill");
  931. string fillType = ShapeHelper.GetFillType(fill);
  932. var borderStyl = thisTblStyle.GetTextByPath("a:band2H/a:tcStyle/a:tcBdr");
  933. if (borderStyl != null)
  934. {
  935. List<Border> borders = GetTableBorders(borderStyl, warpObj);
  936. tr.borders = borders;
  937. }
  938. //Text Style - TODO
  939. //var rowTxtStyl = getTextByPathList(thisTblStyle,["a:band2H", "a:tcTxStyle"]);
  940. //if (rowTxtStyl !== undefined)
  941. //{
  942. //}
  943. }
  944. else
  945. {
  946. //处理纯色填充
  947. var bgFillschemeClr = thisTblStyle.GetTextByPath("a:wholeTbl/a:tcStyle/a:fill/a:solidFill");
  948. if (bgFillschemeClr != null)
  949. {
  950. fillColor = ShapeHelper.GetSolidFill(bgFillschemeClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  951. fillColor = ShapeHelper.ColorToning(bgFillschemeClr.OuterXml, fillColor);
  952. Fill f = new Fill { color = fillColor, type = 1 };
  953. //string sha = null;
  954. //sha = ShaHashHelper.GetSHA1(f.ToJson());
  955. //warpObj.pptx.Fills.TryAdd(sha, f);
  956. //tr.FillSha = sha;
  957. tr.fill = f;
  958. }
  959. //其他填充 todo
  960. var fill = thisTblStyle.GetTextByPath("a:wholeTbl/a:tcStyle/a:fill");
  961. string fillType = ShapeHelper.GetFillType(fill);
  962. var borderStyl = thisTblStyle.GetTextByPath("a:wholeTbl/a:tcStyle/a:tcBdr");
  963. if (borderStyl != null)
  964. {
  965. List<Border> borders = GetTableBorders(borderStyl, warpObj);
  966. tr.borders = borders;
  967. }
  968. //Text Style - TODO
  969. //var rowTxtStyl = thisTblStyle["a:wholeTbl"]["a:tcTxStyle"];
  970. //if (rowTxtStyl !== undefined)
  971. //{
  972. //}
  973. }
  974. }
  975. else {
  976. if (thisTblStyle.GetTextByPath("a:band1H") != null)
  977. {
  978. //处理纯色填充
  979. var bgFillschemeClr = thisTblStyle.GetTextByPath("a:band1H/a:tcStyle/a:fill/a:solidFill");
  980. if (bgFillschemeClr != null)
  981. {
  982. fillColor = ShapeHelper.GetSolidFill(bgFillschemeClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  983. fillColor = ShapeHelper.ColorToning(bgFillschemeClr.OuterXml, fillColor);
  984. Fill f = new Fill { color = fillColor, type = 1 };
  985. //string sha = null;
  986. //sha = ShaHashHelper.GetSHA1(f.ToJson());
  987. //warpObj.pptx.Fills.TryAdd(sha, f);
  988. //tr.FillSha = sha;
  989. tr.fill = f;
  990. }
  991. //其他填充 todo
  992. var fill = thisTblStyle.GetTextByPath("a:band1H/a:tcStyle/a:fill");
  993. string fillType = ShapeHelper.GetFillType(fill);
  994. var borderStyl = thisTblStyle.GetTextByPath("a:band1H/a:tcStyle/a:tcBdr");
  995. if (borderStyl != null)
  996. {
  997. List<Border> borders = GetTableBorders(borderStyl, warpObj);
  998. tr.borders = borders;
  999. }
  1000. //Text Style - TODO
  1001. //var rowTxtStyl = getTextByPathList(thisTblStyle,["a:band1H", "a:tcTxStyle"]);
  1002. //if (rowTxtStyl !== undefined)
  1003. //{
  1004. //}
  1005. }
  1006. }
  1007. }
  1008. var tcNodes= trNodes.Item(i).GetTextByPathList("a:tc");
  1009. if (tcNodes != null) {
  1010. int tcSize = tcNodes.Count;
  1011. for (int j = 0; j < tcSize; j++) {
  1012. Td td = new Td();
  1013. List<Paragraph> paragraphs= await GenTextBody(tcNodes.Item(j).GetTextByPath("a:txBody"),node,null,null,null,warpObj);
  1014. var rowSpan = tcNodes.Item(j).GetTextByPath( "@rowSpan");
  1015. var colSpan = tcNodes.Item(j).GetTextByPath("@gridSpan");
  1016. var vMerge = tcNodes.Item(j).GetTextByPath("@vMerge");
  1017. var hMerge = tcNodes.Item(j).GetTextByPath("@hMerge");
  1018. var colWidthParam = getColsGrid.GetTextByPath("@w");
  1019. if (colWidthParam != null) {
  1020. td.width = int.Parse(colWidthParam.Value) * px96 / px914400;
  1021. }
  1022. var getFill = tcNodes.Item(j).GetTextByPath("a:tcPr/a:solidFill");
  1023. string fillColor = "";
  1024. if (getFill != null)
  1025. {
  1026. fillColor = ShapeHelper.GetSolidFill(getFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1027. fillColor = ShapeHelper.ColorToning(getFill.OuterXml, fillColor);
  1028. Fill f = new Fill { color = fillColor, type = 1 };
  1029. //string sha = null;
  1030. //sha = ShaHashHelper.GetSHA1(f.ToJson());
  1031. //warpObj.pptx.Fills.TryAdd(sha, f);
  1032. //tr.FillSha = sha;
  1033. td.fill = f;
  1034. }
  1035. else {
  1036. //get from Theme (tableStyles.xml) TODO
  1037. //get tableStyleId = a:tbl => a:tblPr => a:tableStyleId
  1038. //var tbleStyleId = getTblPr["a:tableStyleId"];
  1039. //if (tbleStyleId !== undefined)
  1040. //{
  1041. // //get Style from tableStyles.xml by {var tbleStyleId}
  1042. // //table style object : tableStyles
  1043. // var tbleStylList = tableStyles["a:tblStyleLst"]["a:tblStyle"];
  1044. // for (var k = 0; k < tbleStylList.length; k++)
  1045. // {
  1046. // if (tbleStylList[k]["attrs"]["styleId"] == tbleStyleId)
  1047. // {
  1048. // //console.log(tbleStylList[k]);
  1049. // }
  1050. // }
  1051. //}
  1052. }
  1053. //其他填充 todo
  1054. if (rowSpan != null) {
  1055. td.rowspan = int.Parse(rowSpan.Value);
  1056. }
  1057. if (colSpan != null)
  1058. {
  1059. td.colspan = int.Parse(colSpan.Value);
  1060. }
  1061. //
  1062. if (vMerge != null)
  1063. {
  1064. td.vmerge = int.Parse(vMerge.Value);
  1065. }
  1066. if (colSpan != null)
  1067. {
  1068. td.hmerge = int.Parse(colSpan.Value);
  1069. }
  1070. if (rowSpan == null && colSpan == null && vMerge == null && hMerge == null) {
  1071. td.rowspan = 0;
  1072. td.colspan = 0;
  1073. td.hmerge = 0;
  1074. td.vmerge = 0;
  1075. }
  1076. td.paragraphs = paragraphs;
  1077. tr.td.Add(td);
  1078. }
  1079. }
  1080. table.tr.Add(tr);
  1081. }
  1082. }
  1083. return table;
  1084. }
  1085. private List<Border> GetTableBorders(XmlNode node, WarpObj warpObj) {
  1086. List<Border> borders = new List<Border>();
  1087. if (node.GetTextByPath("a:bottom") != null) {
  1088. string xml= "<p:spPr><a:ln>"+ node.GetTextByPath("a:bottom/a:ln").InnerXml + "</p:spPr></a:ln>";
  1089. XmlDocument nodeDoc = new XmlDocument();
  1090. nodeDoc.LoadXml(xml);
  1091. Border border= ShapeHelper.GetBorder(nodeDoc, false, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1092. border.dir = "bottom";
  1093. //string sha = ShaHashHelper.GetSHA1(border.ToJson());
  1094. //warpObj.pptx.Borders.TryAdd(sha, border);
  1095. borders.Add(border);
  1096. }
  1097. if (node.GetTextByPath("a:top") != null)
  1098. {
  1099. string xml = "<p:spPr><a:ln>" + node.GetTextByPath("a:top/a:ln").InnerXml + "</p:spPr></a:ln>";
  1100. XmlDocument nodeDoc = new XmlDocument();
  1101. nodeDoc.LoadXml(xml);
  1102. Border border = ShapeHelper.GetBorder(nodeDoc, false, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1103. border.dir = "top";
  1104. //string sha = ShaHashHelper.GetSHA1(border.ToJson());
  1105. //warpObj.pptx.Borders.TryAdd(sha, border);
  1106. borders.Add(border);
  1107. }
  1108. if (node.GetTextByPath("a:right") != null)
  1109. {
  1110. string xml = "<p:spPr><a:ln>" + node.GetTextByPath("a:right/a:ln").InnerXml + "</p:spPr></a:ln>";
  1111. XmlDocument nodeDoc = new XmlDocument();
  1112. nodeDoc.LoadXml(xml);
  1113. Border border = ShapeHelper.GetBorder(nodeDoc, false, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1114. border.dir = "right";
  1115. //string sha = ShaHashHelper.GetSHA1(border.ToJson());
  1116. //warpObj.pptx.Borders.TryAdd(sha, border);
  1117. borders.Add(border);
  1118. }
  1119. if (node.GetTextByPath("a:left") != null)
  1120. {
  1121. string xml = "<p:spPr><a:ln>" + node.GetTextByPath("a:left/a:ln").InnerXml + "</p:spPr></a:ln>";
  1122. XmlDocument nodeDoc = new XmlDocument();
  1123. nodeDoc.LoadXml(xml);
  1124. Border border = ShapeHelper.GetBorder(nodeDoc, false, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1125. border.dir = "left";
  1126. //string sha = ShaHashHelper.GetSHA1(border.ToJson());
  1127. //warpObj.pptx.Borders.TryAdd(sha, border);
  1128. borders.Add(border);
  1129. }
  1130. return borders;
  1131. }
  1132. public async Task<Item> ProcessCxnSpNode(XmlNode node, int order, WarpObj warpObj)
  1133. {
  1134. var id = node.GetTextByPath("p:nvCxnSpPr/p:cNvPr/@id");
  1135. var name = node.GetTextByPath("p:nvCxnSpPr/p:cNvPr/@name");
  1136. return await GenShape("CxnSp", node, null, null, id, name, null, null, order, warpObj);
  1137. }
  1138. public async Task<Item> ProcessSpNode(XmlNode node, int order, WarpObj warpObj)
  1139. {
  1140. /*
  1141. * 958 <xsd:complexType name="CT_GvmlShape">
  1142. * 959 <xsd:sequence>
  1143. * 960 <xsd:element name="nvSpPr" type="CT_GvmlShapeNonVisual" minOccurs="1" maxOccurs="1"/>
  1144. * 961 <xsd:element name="spPr" type="CT_ShapeProperties" minOccurs="1" maxOccurs="1"/>
  1145. * 962 <xsd:element name="txSp" type="CT_GvmlTextShape" minOccurs="0" maxOccurs="1"/>
  1146. * 963 <xsd:element name="style" type="CT_ShapeStyle" minOccurs="0" maxOccurs="1"/>
  1147. * 964 <xsd:element name="extLst" type="CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1"/>
  1148. * 965 </xsd:sequence>
  1149. * 966 </xsd:complexType>
  1150. */
  1151. var id = node.GetTextByPath("p:nvSpPr/p:cNvPr/@id");
  1152. var name = node.GetTextByPath("p:nvSpPr/p:cNvPr/@name");
  1153. var idx = node.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@idx");
  1154. var type = node.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@type");
  1155. XmlNode slideLayoutSpNode = ShapeHelper.GetNodesTable(id, idx, type, warpObj, "Layout");
  1156. XmlNode slideMasterSpNode = ShapeHelper.GetNodesTable(id, idx, type, warpObj, "Master");
  1157. if (type == null)
  1158. {
  1159. if (slideLayoutSpNode != null)
  1160. {
  1161. type = slideLayoutSpNode.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@type");
  1162. }
  1163. // type = slideLayoutSpNode.TryGetValue"p:nvSpPr", "p:nvPr", "p:ph", "attrs", "type"]);
  1164. if (type == null)
  1165. {
  1166. if (slideMasterSpNode != null)
  1167. {
  1168. type = slideMasterSpNode.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@type");
  1169. }
  1170. // type = getTextByPathList(slideMasterSpNode, ["p:nvSpPr", "p:nvPr", "p:ph", "attrs", "type"]);
  1171. }
  1172. }
  1173. Item item = await GenShape("Sp", node, slideLayoutSpNode, slideMasterSpNode, id, name, idx, type, order, warpObj);
  1174. return item;
  1175. }
  1176. 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)
  1177. {
  1178. var xfrmList = "p:spPr/a:xfrm";
  1179. var slideXfrmNode = node.GetTextByPath(xfrmList);
  1180. XmlNode slideLayoutXfrmNode = null;
  1181. if (slideLayoutSpNode != null)
  1182. {
  1183. slideLayoutXfrmNode = slideLayoutSpNode.GetTextByPath(xfrmList);
  1184. }
  1185. XmlNode slideMasterXfrmNode = null;
  1186. if (slideMasterSpNode != null)
  1187. {
  1188. slideMasterXfrmNode = slideMasterSpNode.GetTextByPath(xfrmList);
  1189. }
  1190. if (slideXfrmNode == null)
  1191. {
  1192. slideXfrmNode = slideLayoutXfrmNode;
  1193. }
  1194. if (slideXfrmNode == null)
  1195. {
  1196. slideXfrmNode = slideMasterXfrmNode;
  1197. }
  1198. // var result = "";
  1199. var shapeType = node.GetTextByPath("p:spPr/a:prstGeom/@prst");
  1200. var custShapType = node.GetTextByPath("p:spPr/a:custGeom");
  1201. var isFlipV = 0;
  1202. var isFlipH = 0;
  1203. if (slideXfrmNode.GetTextByPath("@flipV") != null && slideXfrmNode.GetTextByPath("@flipV").Value == "1")
  1204. {// if ( getTextByPathList(slideXfrmNode, ["attrs", "flipV"]) === "1" || getTextByPathList(slideXfrmNode, ["attrs", "flipH"]) === "1")
  1205. isFlipV = 1;
  1206. }
  1207. if (slideXfrmNode.GetTextByPath("@flipH") != null && slideXfrmNode.GetTextByPath("@flipH").Value == "1")
  1208. {
  1209. isFlipH = 1;
  1210. }
  1211. //rotate
  1212. var rotate = ShapeHelper.AngleToDegrees(slideXfrmNode.GetTextByPath("@rot"));
  1213. double txtRotate;
  1214. var txtXframeNode = node.GetTextByPath("p:txXfrm/@rot");
  1215. if (txtXframeNode != null)
  1216. {
  1217. txtRotate = ShapeHelper.AngleToDegrees(txtXframeNode) + 90;
  1218. }
  1219. else
  1220. {
  1221. txtRotate = rotate;
  1222. }
  1223. Position position = ShapeHelper.GetPosition(slideXfrmNode, slideLayoutXfrmNode, slideMasterXfrmNode);
  1224. position.rot = System.Math.Round(rotate,degree);
  1225. position.flipH = isFlipH;
  1226. position.flipV = isFlipV;
  1227. var grndFillFlg = false;
  1228. var imgFillFlg = false;
  1229. var Fill = await GetShapeFill(node, warpObj);
  1230. // Border Color
  1231. var shapeBorder = ShapeHelper.GetBorder(node, true, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  1232. var headEndNodeAttrs = node.GetTextByPath("p:spPr/a:ln/a:headEnd");
  1233. var tailEndNodeAttrs = node.GetTextByPath("p:spPr/a:ln/a:tailEnd");
  1234. Svg shapeSvg = new Svg { id = order + "", /*Width = position.Cx + "", Height = position.Cy + "", Top = position.X + "", Left = position.Y + "", Transform = "rotate(" + position.Rot + "deg)"*/};
  1235. // StringBuilder svgPath = new StringBuilder("<svg class='drawing' _id='" + order + id + "' _idx='" + order + idx + "' _type='" + order + type + "' _name='" + order + name + "'");
  1236. // svgPath.Append(" style='top:" + position.Y + "px;left:" + position.X + "px;width:" + position.Cx + "px;height" + position.Cy + "px;'");
  1237. if (shapeType != null || custShapType != null)
  1238. {
  1239. //result += "<svg class='drawing' _id='" + id + "' _idx='" + idx + "' _type='" + type + "' _name='" + name +
  1240. // "' style='" +
  1241. // getPosition(slideXfrmNode, null, null) +
  1242. // getSize(slideXfrmNode, null, null) +
  1243. // " z-index: " + order + ";" +
  1244. // "transform: rotate(" + rotate + "deg);" +
  1245. // "'>";
  1246. //result += "<defs>";
  1247. // Fill Color
  1248. var clrFillType = ShapeHelper.GetFillType(node.GetTextByPath("p:spPr"));
  1249. /////////////////////////////////////////
  1250. if (Fill.type==2)//== "GRADIENT_FILL"
  1251. {
  1252. grndFillFlg = true;
  1253. var color_arry = Fill.grad;
  1254. var angl = Fill.rot;
  1255. // var svgGrdnt = ShapeHelper.GetSvgGradient(position.Cx, position.Cy, angl, color_arry, order, slideLayoutClrOvride, warpObj.themeContent);
  1256. // shapeSvg.Defs = svgGrdnt;
  1257. //fill="url(#linGrd)"
  1258. // Fill.SvgText = svgGrdnt;
  1259. // result += svgGrdnt;
  1260. }
  1261. else if (Fill.type == 3) //(clrFillType == "PIC_FILL")
  1262. {
  1263. imgFillFlg = true;
  1264. // var svgBgImg = ShapeHelper.GetSvgImagePattern(Fill.Image, order);
  1265. // shapeSvg.Defs = svgBgImg;
  1266. //fill="url(#imgPtrn)"
  1267. // Fill.SvgText = svgBgImg;
  1268. // result += svgBgImg;
  1269. }
  1270. else
  1271. {
  1272. // if (clrFillType != null && clrFillType != "SOLID_FILL" && clrFillType != "PATTERN_FILL")
  1273. if (shapeType != null)
  1274. {
  1275. if (Fill.type != 1 && Fill.type != 4 &&(shapeType.Value == "arc" ||
  1276. shapeType.Value == "bracketPair" ||
  1277. shapeType.Value == "bracePair" ||
  1278. shapeType.Value == "leftBracket" ||
  1279. shapeType.Value == "leftBrace" ||
  1280. shapeType.Value == "rightBrace" ||
  1281. shapeType.Value == "rightBracket"))
  1282. {
  1283. //Fill.HtmlText = "none";
  1284. Fill.color = "none";
  1285. }
  1286. }
  1287. }
  1288. // type: none, triangle, stealth, diamond, oval, arrow
  1289. if ((headEndNodeAttrs != null && (headEndNodeAttrs.GetTextByPath("@type").Value == "triangle" || (headEndNodeAttrs.GetTextByPath("@type").Value == "arrow")) ||
  1290. (tailEndNodeAttrs != null && (tailEndNodeAttrs.GetTextByPath("@type").Value == "triangle" || (tailEndNodeAttrs.GetTextByPath("@type").Value == "arrow")))))
  1291. {
  1292. // 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 +
  1293. // "' orient='auto-start-reverse' markerUnits='strokeWidth'><path d='M 0 0 L 10 5 L 0 10 z' /></marker>";
  1294. // shapeSvg.Defs = triangleMarker;
  1295. // result += triangleMarker;
  1296. }
  1297. // result += "</defs>";
  1298. }
  1299. if (shapeType != null && custShapType == null)
  1300. {
  1301. Svg svg = ShapeSvg.GenShapeSvg(node, order, shapeType, isFlipV, position, grndFillFlg, imgFillFlg, Fill, shapeBorder, headEndNodeAttrs, tailEndNodeAttrs);
  1302. shapeSvg.svgShape = svg.svgShape;
  1303. // shapeSvg.SvgData = svg.SvgData;
  1304. if (ShapeType.Equals("Sp"))
  1305. {
  1306. Shape shape = new Shape { border = shapeBorder, svg = shapeSvg, type = "Sp", position = position, index = order, shapeType = shapeType.Value };
  1307. //if (shapeBorder != null&& shapeBorder.Type!=null)
  1308. //{
  1309. // shape.BorderSha = ShaHashHelper.GetSHA1(shapeBorder.ToJson());
  1310. // warpObj.pptx.Borders.TryAdd(shape.BorderSha, shapeBorder);
  1311. //}
  1312. if (Fill.type == 0)
  1313. {
  1314. shape.fill = null;
  1315. }
  1316. else {
  1317. //string sha = null;
  1318. //sha = ShaHashHelper.GetSHA1(Fill.ToJson());
  1319. //warpObj.pptx.Fills.TryAdd(sha, Fill);
  1320. //shape.FillSha = sha;
  1321. shape.fill = Fill;
  1322. }
  1323. var txbody = node.GetTextByPath("p:txBody");
  1324. if (txbody != null)
  1325. {
  1326. List<Paragraph> paragraphs = await GenTextBody(txbody, node, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
  1327. shape.paragraph = paragraphs;
  1328. }
  1329. return shape;
  1330. }
  1331. else if (ShapeType.Equals("CxnSp"))
  1332. {
  1333. //string bdsha = null;
  1334. //if (shapeBorder != null && shapeBorder.Type != null)
  1335. //{
  1336. // bdsha = ShaHashHelper.GetSHA1(shapeBorder.ToJson());
  1337. // warpObj.pptx.Borders.TryAdd(bdsha, shapeBorder);
  1338. //}
  1339. return new Connector { border = shapeBorder, svg = shapeSvg, type = "CxnSp", position = position, index = order, cxnType = shapeType.Value };
  1340. }
  1341. else {
  1342. return null;
  1343. }
  1344. }
  1345. else if (custShapType != null)
  1346. {
  1347. XmlNode pathLstNode = custShapType.GetTextByPath("a:pathLst");
  1348. //XmlNode pathNode = pathLstNode.GetTextByPath("a:path");
  1349. //var maxX = 0.0;
  1350. //var maxY = 0.0;
  1351. //if (pathLstNode != null)
  1352. //{
  1353. // maxX = double.Parse(pathNode.GetTextByPath("@w").Value) * px96 / px914400;
  1354. // maxY = double.Parse(pathNode.GetTextByPath("@h").Value) * px96 / px914400;
  1355. //}
  1356. var closeNode = pathLstNode.GetTextByPath("a:path/a:close");
  1357. var startPoint = pathLstNode.GetTextByPath("a:path/a:moveTo/a:pt");
  1358. var spX = 96.0;
  1359. var spY = 96.0;
  1360. if (startPoint != null)
  1361. {
  1362. spX = System.Math.Round(double.Parse(startPoint.GetTextByPath("@x").Value) * 96 / 914400,degree);
  1363. spY = System.Math.Round(double.Parse(startPoint.GetTextByPath("@y").Value) * 96 / 914400,degree);
  1364. }
  1365. var d = "M" + spX + "," + spY;
  1366. // List<TEAMModelOS.Service.Model.PowerPoint.Path> Paths = new List<Model.PowerPoint.Path>();
  1367. XmlNodeList pathChildNodes = pathLstNode.GetTextByPath("a:path").ChildNodes;
  1368. foreach (XmlNode childNode in pathChildNodes)
  1369. {
  1370. if (childNode.Name.Equals("a:lnTo"))
  1371. {
  1372. XmlNodeList nodeList = childNode.ChildNodes;
  1373. var Lx = double.Parse(nodeList.Item(0).GetTextByPath("@x").Value) * px96 / px914400;
  1374. var Ly = double.Parse(nodeList.Item(0).GetTextByPath("@y").Value) * px96 / px914400;
  1375. //Paths.Add(new LineToPath
  1376. //{
  1377. // Lx = double.Parse(Lx.Value) * px96 / px914400,
  1378. // Ly = double.Parse(Lx.Value) * px96 / px914400,
  1379. //});
  1380. d += " L" + System.Math.Round(Lx,degree) + "," + System.Math.Round(Ly,degree);
  1381. }
  1382. if (childNode.Name.Equals("a:cubicBezTo"))
  1383. {
  1384. XmlNodeList nodeList = childNode.ChildNodes;
  1385. var Cx1 = double.Parse(nodeList.Item(0).GetTextByPath("@x").Value) * px96 / px914400;
  1386. var Cy1 = double.Parse(nodeList.Item(0).GetTextByPath("@y").Value) * px96 / px914400;
  1387. var Cx2 = double.Parse(nodeList.Item(1).GetTextByPath("@x").Value) * px96 / px914400;
  1388. var Cy2 = double.Parse(nodeList.Item(1).GetTextByPath("@y").Value) * px96 / px914400;
  1389. var Cx3 = double.Parse(nodeList.Item(2).GetTextByPath("@x").Value) * px96 / px914400;
  1390. var Cy3 = double.Parse(nodeList.Item(2).GetTextByPath("@y").Value) * px96 / px914400;
  1391. //Paths.Add( new CubicBezPath
  1392. // {
  1393. // Cx1 = double.Parse(Cx1.Value) * px96 / px914400,
  1394. // Cy1 = double.Parse(Cy1.Value) * px96 / px914400,
  1395. // Cx2 = double.Parse(Cx2.Value) * px96 / px914400,
  1396. // Cy2 = double.Parse(Cy2.Value) * px96 / px914400,
  1397. // Cx3 = double.Parse(Cx3.Value) * px96 / px914400,
  1398. // Cy3 = double.Parse(Cy3.Value) * px96 / px914400
  1399. // });
  1400. 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);
  1401. }
  1402. if (childNode.Name.Equals("a:quadBezTo"))
  1403. {
  1404. //http://cw.hubwiz.com/card/c/5636b7041bc20c980538e995/1/4/4/
  1405. XmlNodeList nodeList = childNode.ChildNodes;
  1406. var Cx1 = double.Parse(nodeList.Item(0).GetTextByPath("@x").Value) * px96 / px914400;
  1407. var Cy1 = double.Parse(nodeList.Item(0).GetTextByPath("@y").Value) * px96 / px914400;
  1408. var Cx2 = double.Parse(nodeList.Item(1).GetTextByPath("@x").Value) * px96 / px914400;
  1409. var Cy2 = double.Parse(nodeList.Item(1).GetTextByPath("@y").Value) * px96 / px914400;
  1410. //Paths.Add(new QuadBezPath
  1411. //{
  1412. // Cx1 = double.Parse(Cx1.Value) * px96 / px914400,
  1413. // Cy1 = double.Parse(Cy1.Value) * px96 / px914400,
  1414. // Cx2 = double.Parse(Cx2.Value) * px96 / px914400,
  1415. // Cy2 = double.Parse(Cy2.Value) * px96 / px914400
  1416. //});
  1417. d += " Q" + System.Math.Round(Cx1,degree) + "," + System.Math.Round(Cy1,degree) + " " + System.Math.Round(Cx2,degree) + "," + System.Math.Round(Cy2,degree);
  1418. }
  1419. if (childNode.Name.Equals("a:arcTo"))
  1420. {
  1421. var wR = double.Parse(childNode.GetTextByPath("@wR").Value) * px96 / px914400;
  1422. var hR = double.Parse(childNode.GetTextByPath("@hR").Value) * px96 / px914400;
  1423. var stAng = double.Parse(childNode.GetTextByPath("@stAng").Value) * px96 / px914400;
  1424. var swAng = double.Parse(childNode.GetTextByPath("@swAng").Value) * px96 / px914400;
  1425. var endAng = stAng + swAng;
  1426. d += ShapeSvg.ShapeArc(wR, hR, wR, hR, stAng, endAng, false);
  1427. //Paths.Add(new ArcToPath() {
  1428. // WidthRadius = double.Parse(wR.Value) * px96 / px914400,
  1429. // HeightRadius = double.Parse(hR.Value) * px96 / px914400,
  1430. // StartAngle = double.Parse(stAng.Value) * px96 / px914400,
  1431. // SwingAngle = double.Parse(swAng.Value) * px96 / px914400
  1432. //});
  1433. }
  1434. }
  1435. //if (headEndNodeAttrs != null && (headEndNodeAttrs.GetTextByPath("@type").Value == "triangle" || headEndNodeAttrs.GetTextByPath("@type").Value == "arrow"))
  1436. //{
  1437. // result += "marker-start='url(#markerTriangle_" + order + ")' ";
  1438. //}
  1439. //if (tailEndNodeAttrs != null && (tailEndNodeAttrs.GetTextByPath("@type").Value == "triangle" || tailEndNodeAttrs.GetTextByPath("@type").Value == "arrow"))
  1440. //{
  1441. // result += "marker-end='url(#markerTriangle_" + order + ")' ";
  1442. //}
  1443. //是否关闭svg
  1444. if (closeNode != null) {
  1445. d += " z";
  1446. }
  1447. List<SvgShape> shapes = new List<SvgShape>() {
  1448. new SvgPath {
  1449. type = "path",
  1450. // Fill = (!imgFillFlg ? (grndFillFlg ? "url(#linGrd_" + order + ")" : Fill.Color) : "url(#imgPtrn_" + order + ")"),
  1451. //Stroke = "#" + shapeBorder.Color,
  1452. //StrokeWidth = shapeBorder.Width + "",
  1453. //StrokeDasharray = shapeBorder.Stroke,
  1454. d=d,
  1455. start=headEndNodeAttrs!=null?headEndNodeAttrs.GetTextByPath("@type").Value:null,
  1456. end=tailEndNodeAttrs!=null?tailEndNodeAttrs.GetTextByPath("@type").Value:null,
  1457. }
  1458. };
  1459. shapeSvg.svgShape = shapes;
  1460. // shapeSvg.SvgData = result;
  1461. Shape shape = new Shape { border = shapeBorder, svg = shapeSvg, type = "Sp", position = position, index = order, shapeType = "custom" };
  1462. //if (shapeBorder != null && shapeBorder.Type != null)
  1463. //{
  1464. // shape.BorderSha = ShaHashHelper.GetSHA1(shapeBorder.ToJson());
  1465. // warpObj.pptx.Borders.TryAdd(shape.BorderSha, shapeBorder);
  1466. //}
  1467. if (Fill.type == 0)
  1468. {
  1469. shape.fill = null;
  1470. }
  1471. else
  1472. {
  1473. //string sha = null;
  1474. //sha = ShaHashHelper.GetSHA1(Fill.ToJson());
  1475. //warpObj.pptx.Fills.TryAdd(sha, Fill);
  1476. //shape.FillSha = sha;
  1477. shape.fill = Fill;
  1478. }
  1479. var txbody = node.GetTextByPath("p:txBody");
  1480. if (txbody != null)
  1481. {
  1482. List<Paragraph> paragraphs = await GenTextBody(txbody, node, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
  1483. shape.paragraph = paragraphs;
  1484. }
  1485. return shape;
  1486. }
  1487. else
  1488. {
  1489. Shape shape = new Shape { border = shapeBorder, svg = shapeSvg, type = "Sp", position = position, index = order, shapeType = "rect" };
  1490. //if (shapeBorder != null && shapeBorder.Type != null)
  1491. //{
  1492. // shape.BorderSha = ShaHashHelper.GetSHA1(shapeBorder.ToJson());
  1493. // warpObj.pptx.Borders.TryAdd(shape.BorderSha, shapeBorder);
  1494. //}
  1495. if (Fill.type == 0)
  1496. {
  1497. shape.fill = null;
  1498. }
  1499. else
  1500. {
  1501. //string sha = null;
  1502. //sha = ShaHashHelper.GetSHA1(Fill.ToJson());
  1503. //warpObj.pptx.Fills.TryAdd(sha, Fill);
  1504. //shape.FillSha = sha;
  1505. shape.fill = Fill;
  1506. }
  1507. var txbody = node.GetTextByPath("p:txBody");
  1508. if (txbody != null)
  1509. {
  1510. List<Paragraph> paragraphs = await GenTextBody(txbody, node, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
  1511. shape.paragraph = paragraphs;
  1512. }
  1513. return shape;
  1514. }
  1515. }
  1516. private async Task<List<Paragraph>> GenTextBody(XmlNode textBodyNode, XmlNode spNode, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, WarpObj warpObj)
  1517. {
  1518. List<Paragraph> paragraphs = new List<Paragraph>();
  1519. var slideMasterTextStyles = warpObj.slideMasterTextStyles;
  1520. string VertAlign = GetVerticalAlign(spNode, slideLayoutSpNode, slideMasterSpNode);
  1521. string WritingMode = GetWritingMode(spNode, slideLayoutSpNode, slideMasterSpNode);
  1522. var ps = textBodyNode.GetTextByPathList("a:p");
  1523. if (ps != null)
  1524. {
  1525. foreach (XmlNode pNode in ps)
  1526. {
  1527. BuChar buChar = await GenBuChar(pNode, spNode, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
  1528. if (buChar != null && (buChar.buchar == null || buChar.buchar.Equals("TYPE_NONE"))) {
  1529. buChar = null;
  1530. }
  1531. //string bucharsha = null;
  1532. //if (buChar != null) {
  1533. // bucharsha = ShaHashHelper.GetSHA1(buChar.ToJson());
  1534. // warpObj.pptx.BuChars.TryAdd(bucharsha, buChar);
  1535. //}
  1536. string HoriAlign = GetHorizontalAlign(pNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles);
  1537. ParagraphStyle paragraphStyle = new ParagraphStyle
  1538. {
  1539. hori= HoriAlign,
  1540. writing = WritingMode,
  1541. vert = VertAlign
  1542. };
  1543. //sha = ShaHashHelper.GetSHA1(paragraphStyle.ToJson());
  1544. //warpObj.pptx.ParagraphStyles.TryAdd(sha, paragraphStyle);
  1545. Paragraph paragraph = new Paragraph
  1546. {
  1547. buChar = buChar,
  1548. style = paragraphStyle,
  1549. //StyleSha = sha,
  1550. //BuCharSha= bucharsha
  1551. };
  1552. var rNode = pNode.GetTextByPathList("a:r");
  1553. if (rNode == null)
  1554. {
  1555. Text text = GenSpanElement(pNode, spNode, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
  1556. if (pNode.GetTextByPath("a:br") != null)
  1557. {
  1558. text.isbr = true;
  1559. }
  1560. List<Text> texts = new List<Text> { text };
  1561. paragraph.texts = texts;
  1562. }
  1563. else
  1564. {
  1565. List<Text> texts = new List<Text>();
  1566. foreach (XmlNode node in rNode)
  1567. {
  1568. Text text = GenSpanElement(node, spNode, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
  1569. if (pNode.GetTextByPath("a:br") != null)
  1570. {
  1571. text.isbr = true;
  1572. }
  1573. texts.Add(text);
  1574. }
  1575. paragraph.texts = texts;
  1576. }
  1577. paragraphs.Add(paragraph);
  1578. }
  1579. }
  1580. return paragraphs;
  1581. }
  1582. private Text GenSpanElement(XmlNode node, XmlNode spNode, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, WarpObj warpObj)
  1583. {
  1584. string text;
  1585. var slideMasterTextStyles = warpObj.slideMasterTextStyles;
  1586. var textNode = node.GetTextByPath("a:t");
  1587. if (textNode == null)
  1588. {
  1589. textNode = node.GetTextByPath("a:fld/a:t");
  1590. if (textNode == null)
  1591. {
  1592. text = "&nbsp;";
  1593. }
  1594. else
  1595. {
  1596. text = textNode.InnerText;
  1597. }
  1598. }
  1599. else
  1600. {
  1601. text = textNode.InnerText;
  1602. }
  1603. var fontClrPr = GetFontColorPr(node, spNode, type, slideMasterTextStyles, warpObj.slideMasterContent, warpObj.themeContent);
  1604. string color = fontClrPr.color;
  1605. string text_shadow = fontClrPr.textBordr;
  1606. double font_size = GetFontSize(node, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles);
  1607. string font_family = GetFontType(node, type, slideMasterTextStyles, warpObj.themeContent);
  1608. string font_weight = GetFontBold(node, type, slideMasterTextStyles);
  1609. string font_style = GetFontItalic(node, type, slideMasterTextStyles);
  1610. string text_decoration = GetFontDecoration(node, type, slideMasterTextStyles);
  1611. string text_align = GetTextHorizontalAlign(node, type, slideMasterTextStyles);
  1612. string vertical_align = GetTextVerticalAlign(node, type, slideMasterTextStyles);
  1613. //var styleText =
  1614. // "color:" + color + ";" +
  1615. // "text-shadow:" + text_shadow + ";" +
  1616. // "font-size:" + font_size + ";" +
  1617. // "font-family:" + font_family + ";" +
  1618. // "font-weight:" + font_weight + ";" +
  1619. // "font-style:" + font_style + ";" +
  1620. // "text-decoration:" + text_decoration + ";" +
  1621. // "text-align:" + text_align + ";" +
  1622. // "vertical-align:" + vertical_align + ";";
  1623. //string cssName = "";
  1624. //if (styleTable.TryGetValue(styleText, out Dictionary<string, string> css))
  1625. //{
  1626. // cssName = css["name"];
  1627. //}
  1628. //else
  1629. //{
  1630. // cssName = "_css_" + (styleTable.Keys.Count + 1);
  1631. // styleTable.TryAdd(styleText, new Dictionary<string, string> { { "name", cssName }, { "text", styleText } });
  1632. //}
  1633. var linkID = node.GetTextByPath("a:rPr/a:hlinkClick/@r:id");
  1634. string linkURL = null;
  1635. if (linkID != null)
  1636. {
  1637. linkURL = warpObj.slideResObj[linkID.Value]["target"];
  1638. }
  1639. FontStyle fontStyle = new FontStyle
  1640. {
  1641. color = color,
  1642. size = font_size,
  1643. family = font_family,
  1644. weight = font_weight,
  1645. style = font_style,
  1646. decoration = text_decoration,
  1647. vertAlign = vertical_align,
  1648. align = text_align,
  1649. shadow = text_shadow
  1650. };
  1651. //string styleSha = ShaHashHelper.GetSHA1(fontStyle.ToJson());
  1652. //warpObj.pptx.FontStyles.TryAdd(styleSha, fontStyle);
  1653. return new Text
  1654. {
  1655. content = text,
  1656. href = linkURL,
  1657. style=fontStyle
  1658. //StyleSha = styleSha
  1659. };
  1660. }
  1661. private string GetTextVerticalAlign(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles)
  1662. {
  1663. var baseline = node.GetTextByPath("a:rPr/@baseline");
  1664. if (baseline != null)
  1665. {
  1666. return double.Parse(baseline.Value) / 1000.0 + "%";
  1667. }
  1668. else
  1669. {
  1670. return "baseline";
  1671. }
  1672. }
  1673. private string GetTextHorizontalAlign(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles)
  1674. {
  1675. var getAlgn = node.GetTextByPath("a:pPr/@algn");
  1676. var align = "initial";
  1677. if (getAlgn != null)
  1678. {
  1679. switch (getAlgn.Value)
  1680. {
  1681. case "l":
  1682. align = "left";
  1683. break;
  1684. case "r":
  1685. align = "right";
  1686. break;
  1687. case "ctr":
  1688. align = "center";
  1689. break;
  1690. case "just":
  1691. align = "justify";
  1692. break;
  1693. case "dist":
  1694. align = "justify";
  1695. break;
  1696. default:
  1697. align = "initial";
  1698. break;
  1699. }
  1700. }
  1701. return align;
  1702. }
  1703. private string GetFontDecoration(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles)
  1704. {
  1705. if (node.GetTextByPath("a:rPr") != null)
  1706. {
  1707. var FontDecor = node.GetTextByPath("a:rPr/@u");
  1708. var underLine = FontDecor != null ? FontDecor.Value : "none";
  1709. var FontStrik = node.GetTextByPath("a:rPr/@strike");
  1710. var strikethrough = FontStrik != null ? FontStrik.Value : "noStrike";
  1711. if (underLine != "none" && strikethrough == "noStrike")
  1712. {
  1713. return "underline";
  1714. }
  1715. else if (underLine == "none" && strikethrough != "noStrike")
  1716. {
  1717. return "line-through";
  1718. }
  1719. else if (underLine != "none" && strikethrough != "noStrike")
  1720. {
  1721. return "underline line-through";
  1722. }
  1723. else
  1724. {
  1725. return "initial";
  1726. }
  1727. }
  1728. else
  1729. {
  1730. return "initial";
  1731. }
  1732. }
  1733. private string GetFontItalic(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles)
  1734. {
  1735. var FontBold = node.GetTextByPath("a:rPr/@i");
  1736. if (FontBold != null)
  1737. {
  1738. if (FontBold.Value.Equals("1"))
  1739. {
  1740. return "italic";
  1741. }
  1742. else
  1743. {
  1744. return "normal";
  1745. }
  1746. }
  1747. else
  1748. {
  1749. return "normal";
  1750. }
  1751. }
  1752. private string GetFontBold(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles)
  1753. {
  1754. var FontBold = node.GetTextByPath("a:rPr/@b");
  1755. if (FontBold != null)
  1756. {
  1757. if (FontBold.Value.Equals("1"))
  1758. {
  1759. return "bold";
  1760. }
  1761. else
  1762. {
  1763. return "initial";
  1764. }
  1765. }
  1766. else
  1767. {
  1768. return "initial";
  1769. }
  1770. }
  1771. private string GetFontType(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles, XmlNode themeContent)
  1772. {
  1773. string typeface = "inherit";
  1774. XmlNode typefaceNode = node.GetTextByPath("a:rPr/a:latin/@typeface");
  1775. if (typefaceNode == null)
  1776. {
  1777. var fontSchemeNode = themeContent.GetTextByPath("a:theme/a:themeElements/a:fontScheme");
  1778. if (type != null && fontSchemeNode != null && (type.Value == "title" || type.Value == "subTitle" || type.Value == "ctrTitle"))
  1779. {
  1780. typefaceNode = fontSchemeNode.GetTextByPath("a:majorFont/a:latin/@typeface");
  1781. }
  1782. else if (type != null && fontSchemeNode != null && type.Value == "body")
  1783. {
  1784. typefaceNode = fontSchemeNode.GetTextByPath("a:minorFont/a:latin/@typeface");
  1785. }
  1786. else if(fontSchemeNode!=null)
  1787. {
  1788. typefaceNode = fontSchemeNode.GetTextByPath("a:minorFont/a:latin/@typeface");
  1789. }
  1790. }
  1791. if (typefaceNode != null)
  1792. {
  1793. typeface = typefaceNode.Value;
  1794. }
  1795. return typeface;
  1796. }
  1797. private async Task<BuChar> GenBuChar(XmlNode node, XmlNode spNode, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, WarpObj warpObj)
  1798. {
  1799. var sldMstrTxtStyles = warpObj.slideMasterTextStyles;
  1800. var slideMasterContent = warpObj.slideMasterContent;
  1801. var themeContent = warpObj.themeContent;
  1802. var rNodes = node.GetTextByPathList("a:r");
  1803. XmlNode rNode = null;
  1804. if (rNodes != null)
  1805. {
  1806. rNode = rNodes[0];
  1807. }
  1808. dynamic dfltBultColor;
  1809. double dfltBultSize;
  1810. if (rNode != null)
  1811. {
  1812. dfltBultColor = GetFontColorPr(rNode, spNode, type, sldMstrTxtStyles, slideMasterContent, themeContent);
  1813. dfltBultSize = GetFontSize(rNode, slideLayoutSpNode, slideMasterSpNode, type, sldMstrTxtStyles);
  1814. }
  1815. else
  1816. {
  1817. dfltBultColor = GetFontColorPr(node, spNode, type, sldMstrTxtStyles, slideMasterContent, themeContent);
  1818. dfltBultSize = GetFontSize(node, slideLayoutSpNode, slideMasterSpNode, type, sldMstrTxtStyles);
  1819. }
  1820. //var bullet = "";
  1821. var pPrNode = node.GetTextByPath("a:pPr");
  1822. var getRtlVal = node.GetTextByPath("a:pPr/@rtl");
  1823. var isRTL = false;
  1824. if (getRtlVal != null && getRtlVal.Equals("1"))
  1825. {
  1826. isRTL = true;
  1827. }
  1828. int lvl = 0;
  1829. if (node.GetTextByPath("a:pPr/@lvl") != null)
  1830. {
  1831. lvl = int.Parse(node.GetTextByPath("a:pPr/@lvl").Value);
  1832. }
  1833. XmlNode buNum = null;
  1834. XmlNode buPic = null;
  1835. XmlNode buCharNode = null;
  1836. XmlNode buClrNode = null;
  1837. if (pPrNode != null) {
  1838. buCharNode = pPrNode.GetTextByPath("a:buChar/@char");
  1839. buNum = pPrNode.GetTextByPath("a:buAutoNum/@type");
  1840. buPic = pPrNode.GetTextByPath("a:buBlip");
  1841. buClrNode= pPrNode.GetTextByPath("a:buClr");
  1842. }
  1843. string buChar = "";
  1844. var buType = "TYPE_NONE";
  1845. if (buCharNode != null)
  1846. {
  1847. buChar = buCharNode.Value;
  1848. buType = "TYPE_BULLET";
  1849. }
  1850. if (buNum != null)
  1851. {
  1852. buType = "TYPE_NUMERIC";
  1853. }
  1854. if (buPic != null)
  1855. {
  1856. buType = "TYPE_BULPIC";
  1857. }
  1858. XmlNode buFontAttrs = null;
  1859. if (buType != "TYPE_NONE" && pPrNode!=null)
  1860. {
  1861. buFontAttrs = pPrNode.GetTextByPath("a:buFont");
  1862. }
  1863. var defBultColor = "NoNe";
  1864. string bultColor;
  1865. if (buClrNode != null)
  1866. {
  1867. defBultColor = ShapeHelper.GetSolidFill(buClrNode, slideLayoutClrOvride, slideMasterContent, themeContent);
  1868. }
  1869. else
  1870. {
  1871. }
  1872. if (defBultColor == "NoNe")
  1873. {
  1874. bultColor = dfltBultColor.color;
  1875. }
  1876. else
  1877. {
  1878. bultColor = "#" + defBultColor;
  1879. }
  1880. double bultSize;
  1881. XmlNode buVal=null;
  1882. if (pPrNode != null) {
  1883. buVal = pPrNode.GetTextByPath("a:buSzPts/@val"); //pt
  1884. }
  1885. if (buVal != null)
  1886. {
  1887. bultSize = int.Parse(buVal.Value) / 100;
  1888. }
  1889. else
  1890. {
  1891. if (pPrNode != null)
  1892. {
  1893. buVal = pPrNode.GetTextByPath("a:buSzPct/@val");
  1894. }
  1895. if (buVal != null)
  1896. {
  1897. var prcnt = int.Parse(buVal.Value) / 100000.0;
  1898. //dfltBultSize = XXpt
  1899. var dfltBultSizeNoPt = dfltBultSize;
  1900. //pt
  1901. bultSize = prcnt * (dfltBultSizeNoPt);
  1902. }
  1903. else
  1904. {
  1905. bultSize = dfltBultSize;
  1906. }
  1907. }
  1908. double marginLeft = 0;
  1909. double marginRight = 0;
  1910. string typeface = "";
  1911. string Float = "left";
  1912. string Direction = "inherit";
  1913. BuChar BuChar = null;
  1914. if (buType == "TYPE_BULLET")
  1915. {
  1916. if (buFontAttrs != null)
  1917. {
  1918. XmlNode marl = null;
  1919. if (pPrNode != null)
  1920. {
  1921. marl = pPrNode.GetTextByPath("@marL");
  1922. }
  1923. if (marl != null)
  1924. {
  1925. marginLeft = int.Parse(marl.Value) * px96 / px914400;
  1926. if (buFontAttrs.GetTextByPath("@pitchFamily") != null)
  1927. {
  1928. marginRight = int.Parse(buFontAttrs.GetTextByPath("@pitchFamily").Value);
  1929. }
  1930. if (marginLeft == 0)
  1931. {
  1932. marginLeft = 328600 * px96 / px914400;
  1933. }
  1934. var typefaceNode = buFontAttrs.GetTextByPath("@typeface");
  1935. if (typefaceNode != null)
  1936. {
  1937. typeface = typefaceNode.Value;
  1938. }
  1939. if (isRTL)
  1940. {
  1941. Float = "right";
  1942. Direction = "rtl";
  1943. }
  1944. marginLeft = marginLeft * lvl;
  1945. }
  1946. }
  1947. else
  1948. {
  1949. marginLeft = 328600 * px96 / px914400 * lvl;
  1950. }
  1951. BuChar = new BuChar
  1952. {
  1953. typeface = typeface,
  1954. left = marginLeft,
  1955. riht = marginRight,
  1956. size = bultSize,
  1957. buchar = buChar,
  1958. @float = Float,
  1959. direction = Direction,
  1960. type = "TYPE_BULLET"
  1961. };
  1962. }
  1963. else if (buType == "TYPE_NUMERIC")
  1964. {
  1965. if (buFontAttrs != null)
  1966. {
  1967. XmlNode marl = null;
  1968. if (pPrNode != null)
  1969. {
  1970. marl = pPrNode.GetTextByPath("@marL");
  1971. }
  1972. if (marl != null)
  1973. {
  1974. marginLeft = int.Parse(marl.Value) * px96 / px914400;
  1975. if (buFontAttrs.GetTextByPath("@pitchFamily") != null)
  1976. {
  1977. marginRight = int.Parse(buFontAttrs.GetTextByPath("@pitchFamily").Value);
  1978. }
  1979. if (marginLeft == 0)
  1980. {
  1981. marginLeft = 328600 * px96 / px914400;
  1982. }
  1983. var typefaceNode = buFontAttrs.GetTextByPath("@typeface");
  1984. if (typefaceNode != null)
  1985. {
  1986. typeface = typefaceNode.Value;
  1987. }
  1988. else
  1989. {
  1990. typeface = "inherit";
  1991. }
  1992. if (isRTL)
  1993. {
  1994. Float = "right";
  1995. Direction = "rtl";
  1996. }
  1997. else
  1998. {
  1999. Float = "left";
  2000. Direction = "ltr";
  2001. }
  2002. marginLeft = marginLeft * lvl;
  2003. }
  2004. }
  2005. else
  2006. {
  2007. marginLeft = 328600 * 96 / 914400 * lvl;
  2008. if (isRTL)
  2009. {
  2010. Float = "right";
  2011. Direction = "rtl";
  2012. }
  2013. else
  2014. {
  2015. Float = "left";
  2016. Direction = "ltr";
  2017. }
  2018. BuChar = new BuChar
  2019. {
  2020. typeface = typeface,
  2021. left = marginLeft,
  2022. riht = marginRight,
  2023. size = bultSize,
  2024. buchar = buChar,
  2025. @float = Float,
  2026. direction = Direction,
  2027. type = "TYPE_NUMERIC"
  2028. };
  2029. }
  2030. }
  2031. else if (buType == "TYPE_BULPIC")
  2032. {
  2033. XmlNode marl = null;
  2034. if (pPrNode != null)
  2035. {
  2036. marl = pPrNode.GetTextByPath("@marL");
  2037. }
  2038. if (marl != null)
  2039. {
  2040. marginLeft = int.Parse(marl.Value) * px96 / px914400;
  2041. }
  2042. else
  2043. {
  2044. marginLeft = 328600 * px96 / px914400;
  2045. }
  2046. XmlNode marR = null;
  2047. if (pPrNode != null)
  2048. {
  2049. marR = pPrNode.GetTextByPath("@marR");
  2050. }
  2051. if (marR != null)
  2052. {
  2053. marginRight = int.Parse(marR.Value) * px96 / px914400;
  2054. }
  2055. var buPicId = buPic.GetTextByPath("a:blip/@r:embed");
  2056. var buImg = "";
  2057. if (buPicId != null)
  2058. {
  2059. var imgPath = warpObj.slideResObj[buPicId.Value];
  2060. var imgData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + imgPath["target"] + "']");
  2061. if (imgData != null)
  2062. {
  2063. var imgFileExt = imgData.GetTextByPath("@pkg:contentType");
  2064. AzureBlobModel imgModel = await SaveBase64ToBolob(imgData.InnerText, imgFileExt.Value, fileShaCode + "/imgs", "");
  2065. buImg = imgModel.BlobUrl;
  2066. }
  2067. }
  2068. else
  2069. {
  2070. buImg = "&#8227;";
  2071. }
  2072. if (isRTL)
  2073. {
  2074. Float = "right";
  2075. Direction = "rtl";
  2076. }
  2077. marginLeft = marginLeft * lvl;
  2078. BuChar = new BuChar
  2079. {
  2080. typeface = typeface,
  2081. left = marginLeft,
  2082. riht = marginRight,
  2083. size = bultSize,
  2084. buchar = buImg,
  2085. @float = Float,
  2086. direction = Direction,
  2087. type = "TYPE_NUMERIC"
  2088. };
  2089. }
  2090. else
  2091. {
  2092. if (isRTL)
  2093. {
  2094. Float = "right";
  2095. Direction = "rtl";
  2096. }
  2097. BuChar = new BuChar
  2098. {
  2099. typeface = typeface,
  2100. left = 328600 * px96 / px914400 * lvl,
  2101. riht = marginRight,
  2102. size = bultSize,
  2103. @float = Float,
  2104. direction = Direction,
  2105. type = "TYPE_NONE"
  2106. };
  2107. }
  2108. return BuChar;
  2109. }
  2110. private double GetFontSize(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, XmlNode slideMasterTextStyles)
  2111. {
  2112. double fontSize = 0;
  2113. if (node.GetTextByPath("a:rPr/@sz") != null)
  2114. {
  2115. fontSize = int.Parse(node.GetTextByPath("a:rPr/@sz").Value) / 100.0;
  2116. }
  2117. if (fontSize == 0)
  2118. {
  2119. if (slideLayoutSpNode != null) {
  2120. var sz = slideLayoutSpNode.GetTextByPath("p:txBody/a:lstStyle/a:lvl1pPr/a:defRPr/@sz");
  2121. if (sz != null)
  2122. {
  2123. fontSize = int.Parse(sz.Value) / 100.0;
  2124. }
  2125. }
  2126. }
  2127. XmlNode size = null;
  2128. if (fontSize == 0)
  2129. {
  2130. if (type == null) {
  2131. size = slideMasterTextStyles.GetTextByPath("p:otherStyle/a:lvl1pPr/a:defRPr/@sz");
  2132. }
  2133. else if (type.Value.Equals("title") || type.Value.Equals("subTitle") || type.Value.Equals("ctrTitle"))
  2134. {
  2135. size = slideMasterTextStyles.GetTextByPath("p:titleStyle/a:lvl1pPr/a:defRPr/@sz");
  2136. }
  2137. else if (type.Value.Equals("body"))
  2138. {
  2139. size = slideMasterTextStyles.GetTextByPath("p:bodyStyle/a:lvl1pPr/a:defRPr/@sz");
  2140. }
  2141. else if (type.Value.Equals("dt") || type.Value.Equals("sldNum"))
  2142. {
  2143. fontSize = 12;
  2144. }
  2145. if (size != null)
  2146. {
  2147. fontSize = int.Parse(size.Value) / 100.0;
  2148. }
  2149. }
  2150. var baseline = node.GetTextByPath("a:rPr/@baseline");
  2151. if (baseline != null && fontSize != 0)
  2152. {
  2153. fontSize -= 10;
  2154. }
  2155. //return isNaN(fontSize) ? "inherit" : (fontSize + "pt");
  2156. //如果fontSize为0 则 使用inherit 继承方式
  2157. return fontSize;
  2158. }
  2159. private dynamic GetFontColorPr(XmlNode node, XmlNode spNode, XmlNode type, XmlNode sldMstrTxtStyles, XmlNode slideMasterContent, XmlNode themeContent)
  2160. {
  2161. var rPrNode = node.GetTextByPath("a:rPr");
  2162. string filTyp, textBordr;
  2163. string color = null;
  2164. if (rPrNode != null)
  2165. {
  2166. filTyp = ShapeHelper.GetFillType(rPrNode);
  2167. if (filTyp == "SOLID_FILL")
  2168. {
  2169. var solidFillNode = node.GetTextByPath("a:rPr/a:solidFill");
  2170. string colorstr = ShapeHelper.GetSolidFill(solidFillNode, slideLayoutClrOvride, slideMasterContent, themeContent);
  2171. if (solidFillNode!=null) {
  2172. color = ShapeHelper.ColorToning(solidFillNode.OuterXml, colorstr);
  2173. }
  2174. }
  2175. else if (filTyp == "PATTERN_FILL")
  2176. {
  2177. var pattFill = node.GetTextByPath("a:rPr/a:pattFill");
  2178. Fill colorFill = ShapeHelper.GetPatternFill(pattFill, slideLayoutClrOvride, slideMasterContent, themeContent);
  2179. if (colorFill != null && colorFill.grad.IsNotEmpty())
  2180. {
  2181. color = colorFill.grad[0];
  2182. }
  2183. else
  2184. {
  2185. color = "000000";
  2186. }
  2187. }
  2188. else
  2189. {
  2190. if (spNode != null) {
  2191. var sPstyle = spNode.GetTextByPath("p:style/a:fontRef");
  2192. if (sPstyle != null)
  2193. {
  2194. string colorstr = ShapeHelper.GetSolidFill(sPstyle, slideLayoutClrOvride, slideMasterContent, themeContent);
  2195. color = ShapeHelper.ColorToning(sPstyle.OuterXml, colorstr);
  2196. }
  2197. }
  2198. }
  2199. }
  2200. if (color == null)
  2201. {
  2202. color = "000000";
  2203. }
  2204. var txtBrdrNode = node.GetTextByPath("a:rPr/a:ln");
  2205. if (txtBrdrNode != null)
  2206. {
  2207. var txBrd = ShapeHelper.GetBorder(node, true, "text", slideLayoutClrOvride, slideMasterContent, themeContent);
  2208. var brdSize = System.Math.Round(txBrd.width * (4 / 3.00),degree) + "px";
  2209. var brdClr = txBrd.color;
  2210. textBordr = "-" + brdSize + " 0 " + brdClr + ", 0 " + brdSize + " " + brdClr + ", " + brdSize + " 0 " + brdClr + ", 0 -" + brdSize + " " + brdClr + ";";
  2211. }
  2212. else
  2213. {
  2214. textBordr = "none";
  2215. }
  2216. return new { color, textBordr };
  2217. }
  2218. public string GetVerticalAlign(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode)
  2219. {
  2220. XmlDocument doc = new XmlDocument();
  2221. doc.LoadXml(node.OuterXml);
  2222. XmlNode anchor = doc.GetTextByPath("//p:txBody/a:bodyPr/@anchor");
  2223. if (anchor == null)
  2224. {
  2225. if (slideLayoutSpNode != null)
  2226. {
  2227. doc.LoadXml(slideLayoutSpNode.OuterXml);
  2228. anchor = doc.GetTextByPath("//p:txBody/a:bodyPr/@anchor");
  2229. }
  2230. if (anchor == null && slideMasterSpNode != null)
  2231. {
  2232. doc.LoadXml(slideMasterSpNode.OuterXml);
  2233. anchor = doc.GetTextByPath("//p:txBody/a:bodyPr/@anchor");
  2234. }
  2235. }
  2236. if (anchor != null)
  2237. {
  2238. return anchor.Value.Equals("ctr") ? "v-mid" : anchor.Value.Equals("b") ? "v-down" : "v-up";
  2239. }
  2240. else
  2241. {
  2242. return "v-up";
  2243. }
  2244. }
  2245. public string GetWritingMode(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode)
  2246. {
  2247. XmlDocument doc = new XmlDocument();
  2248. doc.LoadXml(node.OuterXml);
  2249. XmlNode vert = doc.GetTextByPath("//p:txBody/a:bodyPr/@vert");
  2250. if (vert == null)
  2251. {
  2252. if (slideLayoutSpNode != null)
  2253. {
  2254. doc.LoadXml(slideLayoutSpNode.OuterXml);
  2255. vert = doc.GetTextByPath("//p:txBody/a:bodyPr/@vert");
  2256. }
  2257. if (vert == null && slideMasterSpNode != null)
  2258. {
  2259. doc.LoadXml(slideMasterSpNode.OuterXml);
  2260. vert = doc.GetTextByPath("//p:txBody/a:bodyPr/@vert");
  2261. }
  2262. }
  2263. if (vert != null)
  2264. {
  2265. return vert.Value;
  2266. }
  2267. else
  2268. {
  2269. return "horz";
  2270. }
  2271. }
  2272. public string GetHorizontalAlign(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode,
  2273. XmlNode typeNode, XmlNode slideMasterTextStyles)
  2274. {
  2275. XmlDocument doc = new XmlDocument();
  2276. doc.LoadXml(node.OuterXml);
  2277. XmlNode algn = doc.GetTextByPath("//a:pPr/@algn");
  2278. if (algn == null)
  2279. {
  2280. if (slideLayoutSpNode != null)
  2281. {
  2282. doc.LoadXml(slideLayoutSpNode.OuterXml);
  2283. algn = doc.GetTextByPath("//p:txBody/a:p/a:pPr/@algn");
  2284. }
  2285. if (algn == null && slideMasterSpNode != null)
  2286. {
  2287. doc.LoadXml(slideMasterSpNode.OuterXml);
  2288. algn = doc.GetTextByPath("//p:txBody/a:p/a:pPr/@algn");
  2289. }
  2290. if (algn == null && typeNode != null)
  2291. {
  2292. switch (typeNode.Value)
  2293. {
  2294. case "title":
  2295. case "subTitle":
  2296. case "ctrTitle":
  2297. //doc.LoadXml(slideMasterStyle.TypeTable.OuterXml);
  2298. doc.LoadXml(slideMasterTextStyles.OuterXml);
  2299. algn = doc.GetTextByPath("//p:titleStyle/a:lvl1pPr/@algn");
  2300. break;
  2301. case "body":
  2302. doc.LoadXml(slideMasterTextStyles.OuterXml);
  2303. algn = doc.GetTextByPath("//p:bodyStyle/a:lvl1pPr/@algn");
  2304. break;
  2305. default:
  2306. // doc.LoadXml(slideMasterStyle.TypeTable.OuterXml);
  2307. doc.LoadXml(slideMasterTextStyles.OuterXml);
  2308. algn = doc.GetTextByPath("//p:otherStyle/a:lvl1pPr/@algn");
  2309. break;
  2310. }
  2311. }
  2312. }
  2313. if (algn == null)
  2314. {
  2315. if (typeNode == null)
  2316. {
  2317. return "h-left";
  2318. }
  2319. if (typeNode.Value.Equals("title") || typeNode.Value.Equals("subTitle") || typeNode.Value.Equals("ctrTitle"))
  2320. {
  2321. return "h-mid";
  2322. }
  2323. else if (typeNode.Value == "sldNum")
  2324. {
  2325. return "h-right";
  2326. }
  2327. else if (typeNode.Value.Equals("body")) { return "h-left"; }
  2328. }
  2329. return algn.Value.Equals("ctr") ? "h-mid" : algn.Value.Equals("r") ? "h-right" : "h-left";
  2330. }
  2331. /// <summary>
  2332. /// 幻灯片 背景色填充
  2333. /// </summary>
  2334. /// <param name="slideContent"></param>
  2335. /// <param name="slideLayoutContent"></param>
  2336. /// <param name="slideMasterContent"></param>
  2337. /// <param name="index"></param>
  2338. /// <param name="warpObj"></param>
  2339. /// <returns></returns>
  2340. public async Task<Fill> GetSlideBackgroundFill(XmlNode slideContent, int index, WarpObj warpObj)
  2341. {
  2342. var bgPr = slideContent.GetTextByPath("pkg:xmlData/p:sld/p:cSld/p:bg/p:bgPr");
  2343. var bgRef = slideContent.GetTextByPath("pkg:xmlData/p:sld/p:cSld/p:bg/p:bgRef");
  2344. if (bgPr != null)
  2345. {
  2346. var bgFillTyp = ShapeHelper.GetFillType(bgPr);
  2347. if (bgFillTyp == "SOLID_FILL")
  2348. {
  2349. var sldFill = bgPr.GetTextByPath("a:solidFill");
  2350. var bgColor = ShapeHelper.GetSolidFill(sldFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2351. if (sldFill!=null) {
  2352. bgColor = ShapeHelper.ColorToning(sldFill.OuterXml, bgColor);
  2353. }
  2354. return new Fill { type = 1, color = bgColor };
  2355. }
  2356. else if (bgFillTyp == "GRADIENT_FILL")
  2357. {
  2358. return ShapeHelper.GetBgGradientFill(bgPr, null, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2359. }
  2360. else if (bgFillTyp == "PIC_FILL")
  2361. {
  2362. return await GetPicFill("slideBg", bgPr.GetTextByPath("a:blipFill"), warpObj);
  2363. }
  2364. }
  2365. else if (bgRef != null)
  2366. {
  2367. string phClr = ShapeHelper.GetSolidFill(bgRef, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2368. phClr = ShapeHelper.ColorToning(bgRef.OuterXml, phClr);
  2369. var idx = bgRef.GetTextByPath("@idx");
  2370. if (idx != null)
  2371. {
  2372. int value = int.Parse(idx.Value);
  2373. if (value == 0 || value == 1000)
  2374. {
  2375. return new Fill { type = 0 };
  2376. //no background
  2377. }
  2378. else if (value > 0 && value < 1000)
  2379. {
  2380. //fillStyleLst in themeContent
  2381. //themeContent["a:fmtScheme"]["a:fillStyleLst"]
  2382. //bgcolor = "background: red;";
  2383. }
  2384. else if (value > 1000)
  2385. {
  2386. var trueIdx = value - 1000;
  2387. var bgFillLst = warpObj.themeContent.GetTextByPath("a:theme/a:themeElements/a:fmtScheme/a:bgFillStyleLst");
  2388. if (bgFillLst != null)
  2389. {
  2390. XmlNodeList nodeList = bgFillLst.ChildNodes;
  2391. if (trueIdx < nodeList.Count)
  2392. {
  2393. string type = ShapeHelper.GetFillType(nodeList[trueIdx - 1]);
  2394. if (type.Equals("SOLID_FILL"))
  2395. {
  2396. if (string.IsNullOrEmpty(phClr))
  2397. {
  2398. phClr = ShapeHelper.GetSolidFill(nodeList[trueIdx - 1], slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2399. }
  2400. if(nodeList[trueIdx - 1]!=null)
  2401. {
  2402. phClr = ShapeHelper.ColorToning(nodeList[trueIdx - 1].OuterXml, phClr);
  2403. }
  2404. return new Fill { type = 1, color = phClr };
  2405. }
  2406. else if (type.Equals("GRADIENT_FILL"))
  2407. {
  2408. return ShapeHelper.GetBgGradientFill(nodeList[trueIdx - 1], phClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2409. }
  2410. else if (type.Equals("PIC_FILL"))
  2411. {
  2412. return await GetPicFill("slideBg", nodeList[trueIdx - 1].GetTextByPath("a:blipFill"), warpObj);
  2413. }
  2414. else
  2415. {
  2416. return new Fill { type = 0 };
  2417. }
  2418. }
  2419. }
  2420. }
  2421. }
  2422. //var node = bgRef.GetTextByPath("");
  2423. //if (bgRef["a:srgbClr"] !== undefined)
  2424. //{
  2425. // phClr = getTextByPathList(bgRef,["a:srgbClr", "attrs", "val"]); //#...
  2426. //}
  2427. //else if (bgRef["a:schemeClr"] !== undefined)
  2428. //{ //a:schemeClr
  2429. // var schemeClr = getTextByPathList(bgRef,["a:schemeClr", "attrs", "val"]);
  2430. // phClr = getSchemeColorFromTheme("a:" + schemeClr, slideMasterContent); //#...
  2431. //}
  2432. }
  2433. else
  2434. {
  2435. bgPr = warpObj.slideLayoutContent.GetTextByPath("pkg:xmlData/p:sldLayout/p:cSld/p:bg/p:bgPr");
  2436. bgRef = warpObj.slideLayoutContent.GetTextByPath("pkg:xmlData/p:sldLayout/p:cSld/p:bg/p:bgRef");
  2437. if (bgPr != null)
  2438. {
  2439. var bgFillTyp = ShapeHelper.GetFillType(bgPr);
  2440. if (bgFillTyp == "SOLID_FILL")
  2441. {
  2442. var sldFill = bgPr.GetTextByPath("a:solidFill");
  2443. var bgColor = ShapeHelper.GetSolidFill(sldFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2444. if (sldFill != null)
  2445. {
  2446. bgColor = ShapeHelper.ColorToning(sldFill.OuterXml, bgColor);
  2447. }
  2448. return new Fill { type = 1, color = bgColor };
  2449. }
  2450. else if (bgFillTyp == "GRADIENT_FILL")
  2451. {
  2452. return ShapeHelper.GetBgGradientFill(bgPr, null, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2453. }
  2454. else if (bgFillTyp == "PIC_FILL")
  2455. {
  2456. return await GetPicFill("layoutBg", bgPr.GetTextByPath("a:blipFill"), warpObj);
  2457. }
  2458. }
  2459. else if (bgRef != null)
  2460. {
  2461. string phClr = ShapeHelper.GetSolidFill(bgRef, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2462. phClr = ShapeHelper.ColorToning(bgRef.OuterXml, phClr);
  2463. var idx = bgRef.GetTextByPath("@idx");
  2464. if (idx != null)
  2465. {
  2466. int value = int.Parse(idx.Value);
  2467. if (value == 0 || value == 1000)
  2468. {
  2469. return new Fill { type = 0 };
  2470. //no background
  2471. }
  2472. else if (value > 0 && value < 1000)
  2473. {
  2474. //fillStyleLst in themeContent
  2475. //themeContent["a:fmtScheme"]["a:fillStyleLst"]
  2476. //bgcolor = "background: red;";
  2477. }
  2478. else if (value > 1000)
  2479. {
  2480. var trueIdx = value - 1000;
  2481. var bgFillLst = warpObj.themeContent.GetTextByPath("a:theme/a:themeElements/a:fmtScheme/a:bgFillStyleLst");
  2482. if (bgFillLst != null)
  2483. {
  2484. XmlNodeList nodeList = bgFillLst.ChildNodes;
  2485. if (trueIdx < nodeList.Count)
  2486. {
  2487. string type = ShapeHelper.GetFillType(nodeList[trueIdx - 1]);
  2488. if (type.Equals("SOLID_FILL"))
  2489. {
  2490. if (string.IsNullOrEmpty(phClr))
  2491. {
  2492. phClr = ShapeHelper.GetSolidFill(nodeList[trueIdx - 1], slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2493. }
  2494. if (nodeList[trueIdx - 1] != null)
  2495. {
  2496. phClr = ShapeHelper.ColorToning(nodeList[trueIdx - 1].Value, phClr);
  2497. }
  2498. return new Fill { type = 1, color = phClr };
  2499. }
  2500. else if (type.Equals("GRADIENT_FILL"))
  2501. {
  2502. return ShapeHelper.GetBgGradientFill(nodeList[trueIdx - 1], phClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2503. }
  2504. else if (type.Equals("PIC_FILL"))
  2505. {
  2506. return await GetPicFill("slideBg", nodeList[trueIdx - 1].GetTextByPath("a:blipFill"), warpObj);
  2507. }
  2508. else
  2509. {
  2510. return new Fill { type = 0 };
  2511. }
  2512. }
  2513. }
  2514. }
  2515. }
  2516. }
  2517. else
  2518. {
  2519. bgPr = warpObj.slideMasterContent.GetTextByPath("pkg:xmlData/p:sldMaster/p:cSld/p:bg/p:bgPr");
  2520. bgRef = warpObj.slideMasterContent.GetTextByPath("pkg:xmlData/p:sldMaster/p:cSld/p:bg/p:bgRef");
  2521. if (bgPr != null)
  2522. {
  2523. var bgFillTyp = ShapeHelper.GetFillType(bgPr);
  2524. if (bgFillTyp == "SOLID_FILL")
  2525. {
  2526. var sldFill = bgPr.GetTextByPath("a:solidFill");
  2527. var bgColor = ShapeHelper.GetSolidFill(sldFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2528. if (sldFill != null)
  2529. {
  2530. bgColor = ShapeHelper.ColorToning(sldFill.OuterXml, bgColor);
  2531. }
  2532. return new Fill { type = 1, color = bgColor };
  2533. }
  2534. else if (bgFillTyp == "GRADIENT_FILL")
  2535. {
  2536. return ShapeHelper.GetBgGradientFill(bgPr, null, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2537. }
  2538. else if (bgFillTyp == "PIC_FILL")
  2539. {
  2540. return await GetPicFill("masterBg", bgPr.GetTextByPath("a:blipFill"), warpObj);
  2541. }
  2542. }
  2543. else if (bgRef != null)
  2544. {
  2545. string phClr = ShapeHelper.GetSolidFill(bgRef, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2546. phClr = ShapeHelper.ColorToning(bgRef.OuterXml, phClr);
  2547. var idx = bgRef.GetTextByPath("@idx");
  2548. if (idx != null)
  2549. {
  2550. int value = int.Parse(idx.Value);
  2551. if (value == 0 || value == 1000)
  2552. {
  2553. return new Fill { type = 0 };
  2554. //no background
  2555. }
  2556. else if (value > 0 && value < 1000)
  2557. {
  2558. //fillStyleLst in themeContent
  2559. //themeContent["a:fmtScheme"]["a:fillStyleLst"]
  2560. //bgcolor = "background: red;";
  2561. }
  2562. else if (value > 1000)
  2563. {
  2564. var trueIdx = value - 1000;
  2565. var bgFillLst = warpObj.themeContent.GetTextByPath("a:theme/a:themeElements/a:fmtScheme/a:bgFillStyleLst");
  2566. if (bgFillLst != null)
  2567. {
  2568. XmlNodeList nodeList = bgFillLst.ChildNodes;
  2569. if (trueIdx < nodeList.Count)
  2570. {
  2571. string type = ShapeHelper.GetFillType(nodeList[trueIdx - 1]);
  2572. if (type.Equals("SOLID_FILL"))
  2573. {
  2574. if (string.IsNullOrEmpty(phClr))
  2575. {
  2576. phClr = ShapeHelper.GetSolidFill(nodeList[trueIdx - 1], slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2577. }
  2578. if (nodeList[trueIdx - 1] != null)
  2579. {
  2580. phClr = ShapeHelper.ColorToning(nodeList[trueIdx - 1].Value, phClr);
  2581. }
  2582. return new Fill { type = 1, color = phClr };
  2583. }
  2584. else if (type.Equals("GRADIENT_FILL"))
  2585. {
  2586. return ShapeHelper.GetBgGradientFill(nodeList[trueIdx - 1], phClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2587. }
  2588. else if (type.Equals("PIC_FILL"))
  2589. {
  2590. return await GetPicFill("slideBg", nodeList[trueIdx - 1].GetTextByPath("a:blipFill"), warpObj);
  2591. }
  2592. else
  2593. {
  2594. return new Fill { type = 0 };
  2595. }
  2596. }
  2597. }
  2598. }
  2599. }
  2600. }
  2601. }
  2602. }
  2603. return null;
  2604. }
  2605. public async Task<Fill> GetPicFill(string type, XmlNode node, WarpObj warpObj)
  2606. {
  2607. //Need to test/////////////////////////////////////////////
  2608. //rId
  2609. //TODO - Image Properties - Tile, Stretch, or Display Portion of Image
  2610. //(http://officeopenxml.com/drwPic-tile.php)
  2611. // var img = "";
  2612. var rId = node.GetTextByPath("a:blip/@r:embed");//node["a:blip"]["attrs"]["r:embed"];
  2613. Dictionary<string, string> imgPath = new Dictionary<string, string>();
  2614. if (type == "slideBg")
  2615. {
  2616. imgPath = warpObj.slideResObj[rId.Value];
  2617. }
  2618. else if (type == "layoutBg")
  2619. {
  2620. imgPath = warpObj.layoutResObj[rId.Value];
  2621. }
  2622. else if (type == "masterBg")
  2623. {
  2624. imgPath = warpObj.masterResObj[rId.Value];
  2625. }
  2626. if (imgPath == null)
  2627. {
  2628. return null;
  2629. }
  2630. //var imgExt = imgPath["type"];
  2631. //if (imgExt == "xml")
  2632. //{
  2633. // return null;
  2634. //}
  2635. var imgData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + imgPath["target"] + "']");
  2636. if (imgData != null)
  2637. {
  2638. AzureBlobModel model = await SaveBase64ToBolob(imgData.InnerText, imgData.GetTextByPath("@pkg:contentType").Value,
  2639. fileShaCode + "/imgs", null);
  2640. XmlNode fillRect_node = node.GetTextByPath("a:stretch/a:fillRect");
  2641. Fill fill = new Fill { type = 3, image = model.BlobUrl };
  2642. if (fillRect_node != null)
  2643. {
  2644. FillStyle fillStyle = new FillStyle();
  2645. XmlNode left = node.GetTextByPath("a:stretch/a:fillRect/@l");
  2646. XmlNode top = node.GetTextByPath("a:stretch/a:fillRect/@t");
  2647. XmlNode right = node.GetTextByPath("a:stretch/a:fillRect/@r");
  2648. XmlNode bottom = node.GetTextByPath("a:stretch/a:fillRect/@b");
  2649. if (left != null) {
  2650. fillStyle.left = int.Parse(left.Value);
  2651. }
  2652. if (top != null)
  2653. {
  2654. fillStyle.top = int.Parse(top.Value);
  2655. }
  2656. if (right != null)
  2657. {
  2658. fillStyle.right = int.Parse(right.Value);
  2659. }
  2660. if (bottom != null)
  2661. {
  2662. fillStyle.bottom = int.Parse(bottom.Value);
  2663. }
  2664. fill.style = fillStyle;
  2665. }
  2666. return fill;
  2667. }
  2668. else { return null; }
  2669. // var imgArrayBuffer = warpObj.zip.GetTextByPath(imgPath).Value.asArrayBuffer();
  2670. //var imgMimeType = GetMimeType(imgExt);
  2671. //img = "data:" + imgMimeType + ";base64," + base64ArrayBuffer(imgArrayBuffer);
  2672. }
  2673. public async Task<Fill> GetShapeFill(XmlNode node, WarpObj warpObj)
  2674. {
  2675. // 1. presentationML
  2676. // p:spPr/ [a:noFill, solidFill, gradFill, blipFill, pattFill, grpFill]
  2677. // From slide
  2678. //Fill Type:
  2679. var fillType = ShapeHelper.GetFillType(node.GetTextByPath("p:spPr"));
  2680. Fill fill = null;
  2681. //0
  2682. if (fillType == "NO_FILL")
  2683. {
  2684. fill = new Fill
  2685. {
  2686. type = 0,
  2687. //HtmlText = "background-color: initial;",
  2688. //SvgText = "none"
  2689. };
  2690. //return isSvgMode ? "none" : "background-color: initial;";
  2691. }
  2692. //1纯色填充
  2693. else if (fillType == "SOLID_FILL")
  2694. {
  2695. XmlNode shpFill = node.GetTextByPath("p:spPr/a:solidFill");// node["p:spPr"]["a:solidFill"];
  2696. string color = ShapeHelper.GetSolidFill(shpFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2697. fill = new Fill
  2698. {
  2699. type = 1,
  2700. color = color,
  2701. };
  2702. }
  2703. //2渐变色填充
  2704. else if (fillType == "GRADIENT_FILL")
  2705. {
  2706. var shpFill = node.GetTextByPath("p:spPr/a:gradFill");// node["p:spPr"]["a:gradFill"];
  2707. // fillColor = GetSolidFill(shpFill);
  2708. fill = ShapeHelper.GetGradientFill(shpFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2709. }//3图片 纹理填充
  2710. else if (fillType == "PIC_FILL")
  2711. {
  2712. var shpFill = node.GetTextByPath("p:spPr/a:blipFill"); //node["p:spPr"]["a:blipFill"];
  2713. fill = await GetPicFill("slideBg", shpFill, warpObj);
  2714. }//4 图案填充
  2715. else if (fillType == "PATTERN_FILL")
  2716. {
  2717. /*
  2718. *
  2719. *<a:pattFill prst="ltDnDiag">
  2720. <a:fgClr>
  2721. <a:schemeClr val="dk1">
  2722. <a:lumMod val="15000"/>
  2723. <a:lumOff val="85000"/>
  2724. </a:schemeClr>
  2725. </a:fgClr>
  2726. <a:bgClr>
  2727. <a:schemeClr val="lt1"/>
  2728. </a:bgClr>
  2729. </a:pattFill>
  2730. */
  2731. var shpFill = node.GetTextByPath("p:spPr/a:pattFill");// node["p:spPr"]["a:pattFill"];
  2732. fill = ShapeHelper.GetPatternFill(shpFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2733. }
  2734. // 2. drawingML namespace
  2735. if (fill == null)
  2736. {
  2737. var clrName = node.GetTextByPath("p:style/a:fillRef");
  2738. string color = ShapeHelper.GetSolidFill(clrName, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2739. if (clrName != null)
  2740. {
  2741. fillType = "SOLID_FILL";
  2742. color = ShapeHelper.ColorToning(clrName.OuterXml, color);
  2743. fill = new Fill
  2744. {
  2745. type = 1,
  2746. color = color,
  2747. };
  2748. }
  2749. }
  2750. if (fill != null)
  2751. {
  2752. if (fillType == "GRADIENT_FILL")
  2753. {
  2754. //if (isSvgMode)
  2755. //{
  2756. // return fill;
  2757. //}
  2758. //else
  2759. //{
  2760. // var colorAry = fill.grad;
  2761. // var rot = fill.Rot;
  2762. //var bgcolor = "background: linear-gradient(" + rot + "deg,";
  2763. //for (var i = 0; i < colorAry.Count; i++)
  2764. //{
  2765. // if (i == colorAry.Count - 1)
  2766. // {
  2767. // bgcolor += colorAry[i] + ");";
  2768. // }
  2769. // else
  2770. // {
  2771. // bgcolor += colorAry[i] + ", ";
  2772. // }
  2773. //}
  2774. //fill.HtmlText = bgcolor;
  2775. return fill;
  2776. // }
  2777. }
  2778. else if (fillType == "PIC_FILL")
  2779. {
  2780. //if (isSvgMode)
  2781. //{
  2782. // return fill;
  2783. //}
  2784. //else
  2785. //{
  2786. // fill.HtmlText = "background-image:url(" + fill.Image + ");";
  2787. return fill;
  2788. // }
  2789. }
  2790. else
  2791. {
  2792. //if (isSvgMode)
  2793. //{
  2794. // var color = new colz.Color(fill);
  2795. // fill = color.rgb.toString();
  2796. //fill.HtmlText = "background-color: #" + fill.Color + ";";
  2797. return fill;
  2798. //}
  2799. //else
  2800. //{
  2801. // return fill;
  2802. //}
  2803. }
  2804. }
  2805. else
  2806. {
  2807. //if (isSvgMode)
  2808. //{
  2809. // return fill;
  2810. //}
  2811. //else
  2812. //{
  2813. fill = new Fill { type = 0 };
  2814. //fill.SvgText = "none";
  2815. //fill.HtmlText = "background-color: initial;";
  2816. return fill;
  2817. // }
  2818. }
  2819. }
  2820. public async Task<AzureBlobModel> GetThumbnailModel(XmlDocument xdoc, string shaCode)
  2821. {
  2822. var thumbnailNode = xdoc.GetTextByPath("//pkg:part[@pkg:name='/docProps/thumbnail.jpeg']");
  2823. if (thumbnailNode != null)
  2824. {
  2825. var contentType = thumbnailNode.GetTextByPath("@pkg:contentType");
  2826. var thumbnail = thumbnailNode.InnerText;
  2827. return await SaveBase64ToBolob(thumbnail, contentType.Value, shaCode + "/imgs", "thumbnail");
  2828. }
  2829. return null;
  2830. }
  2831. public XmlNode LoadTheme(XmlDocument xdoc)
  2832. {
  2833. 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");
  2834. // "/ppt/theme/theme1.xml"
  2835. string themeURI = "/ppt/" + themeRelationship.Value;
  2836. return xdoc.GetTextByPath("//pkg:part[@pkg:name='" + themeURI + "']");
  2837. }
  2838. public async Task<AzureBlobModel> SaveBase64ToBolob(string data, string contentType, string FolderName, string fileName)
  2839. {
  2840. string fileExt;
  2841. if (ContentTypeDict.extdict.TryGetValue(contentType, out string ext))
  2842. {
  2843. fileExt = ext;
  2844. }
  2845. else
  2846. {
  2847. //解决多种扩展名不能获取的
  2848. string[] sp = contentType.Split("/");
  2849. fileExt = sp[sp.Length - 1];
  2850. sp = fileExt.Split("+");
  2851. fileExt = "." + sp[sp.Length - 1];
  2852. }
  2853. //data:image/jpeg;base64,
  2854. if (string.IsNullOrEmpty(fileName))
  2855. {
  2856. Stream stream = new MemoryStream(Convert.FromBase64String(data));
  2857. string shaCode = ShaHashHelper.GetSHA1(stream);
  2858. fileName = shaCode + fileExt;
  2859. }
  2860. else
  2861. {
  2862. if (fileName.Split(".").Length == 1)
  2863. {
  2864. fileName += fileExt;
  2865. }
  2866. }
  2867. Stream streamBlob = new MemoryStream(Convert.FromBase64String(data));
  2868. AzureBlobModel model = await azureBlobDBRepository.UploadFileByFolder(streamBlob, FolderName, fileName, "pptx", false);
  2869. return model;
  2870. }
  2871. public async Task<Media> ProcessPicNode(XmlNode node, int order, WarpObj warpObj)
  2872. {
  2873. var xfrmList = "p:spPr/a:xfrm";
  2874. var xfrmNode = node.GetTextByPath(xfrmList);
  2875. Media media = new Media() { type = "Media" };
  2876. var id = node.GetTextByPath("p:nvPicPr/p:cNvPr/@id");
  2877. XmlNode slideLayoutSpNode = ShapeHelper.GetNodesTable(id, null, null, warpObj, "Layout");
  2878. XmlNode slideMasterSpNode = ShapeHelper.GetNodesTable(id, null, null, warpObj, "Master");
  2879. XmlNode slideLayoutXfrmNode = null;
  2880. if (slideLayoutSpNode != null)
  2881. {
  2882. slideLayoutXfrmNode = slideLayoutSpNode.GetTextByPath(xfrmList);
  2883. }
  2884. XmlNode slideMasterXfrmNode = null;
  2885. if (slideMasterSpNode != null)
  2886. {
  2887. slideMasterXfrmNode = slideMasterSpNode.GetTextByPath(xfrmList);
  2888. }
  2889. double rotate = 0;
  2890. var rotateNode = node.GetTextByPath("p:spPr/a:xfrm/@rot");
  2891. if (rotateNode != null)
  2892. {
  2893. rotate = ShapeHelper.AngleToDegrees(rotateNode);
  2894. }
  2895. Fill fill = await GetShapeFill(node, warpObj);
  2896. //string sha = null;
  2897. //if (fill != null && fill.Type!=0) {
  2898. // sha = ShaHashHelper.GetSHA1(fill.ToJson());
  2899. // warpObj.pptx.Fills.TryAdd(sha, fill);
  2900. //}
  2901. // media.FillSha = sha;
  2902. media.fill = fill;
  2903. Border border = ShapeHelper.GetBorder(node, true, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
  2904. //if (border != null && border.Type!=null) {
  2905. // media.BorderSha =ShaHashHelper.GetSHA1(border.ToJson());
  2906. // warpObj.pptx.Borders.TryAdd(media.BorderSha, border);
  2907. //}
  2908. media.border = border;
  2909. Position position = ShapeHelper.GetPosition(xfrmNode, slideLayoutXfrmNode, slideMasterXfrmNode);
  2910. media.position = position;
  2911. position.rot = System.Math.Round(rotate,degree);
  2912. //var rtrnData = "";
  2913. //image
  2914. var rid = node.GetTextByPath("p:blipFill/a:blip/@r:embed");
  2915. if (rid != null)
  2916. {
  2917. var imgName = warpObj.slideResObj[rid.Value]["target"];
  2918. if (!string.IsNullOrEmpty(imgName))
  2919. {
  2920. var imgData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + imgName + "']");
  2921. var imgFileExt = imgData.GetTextByPath("@pkg:contentType");
  2922. AzureBlobModel imgModel = await SaveBase64ToBolob(imgData.InnerText, imgFileExt.Value, fileShaCode + "/imgs", "");
  2923. media.image = imgModel.BlobUrl;
  2924. media.mediaType = "image";
  2925. media.index = order;
  2926. }
  2927. }
  2928. ///////////////////////////////////////Amir//////////////////////////////
  2929. //video
  2930. var vdoNode = node.GetTextByPath("p:nvPicPr/p:nvPr/a:videoFile/@r:link");
  2931. if (vdoNode != null)
  2932. {
  2933. string vdoFile = warpObj.slideResObj[vdoNode.Value]["target"];
  2934. if (!string.IsNullOrEmpty(vdoFile))
  2935. {
  2936. var videoData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + vdoFile + "']");
  2937. var contentType = videoData.GetTextByPath("@pkg:contentType");
  2938. AzureBlobModel vdoModel = await SaveBase64ToBolob(videoData.InnerText, contentType.Value, fileShaCode + "/media", "");
  2939. media.url = vdoModel.BlobUrl;
  2940. media.mediaType = "video";
  2941. media.index = order;
  2942. }
  2943. /// 处理为AzureBlob 上传
  2944. // vdoMimeType = getMimeType(vdoFileExt);
  2945. // blob = new Blob([uInt8Array], {
  2946. // type: vdoMimeType
  2947. // });
  2948. // vdoBlob = URL.createObjectURL(blob);
  2949. }
  2950. //audio
  2951. var audioNode = node.GetTextByPath("p:nvPicPr/p:nvPr/a:audioFile/@r:link");
  2952. // var audioObjc;
  2953. if (audioNode != null)
  2954. {
  2955. string audioFile = warpObj.slideResObj[audioNode.Value]["target"];
  2956. if (!string.IsNullOrEmpty(audioFile))
  2957. {
  2958. var audioData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + audioFile + "']");
  2959. var contentType = audioData.GetTextByPath("@pkg:contentType");
  2960. AzureBlobModel adoModel = await SaveBase64ToBolob(audioData.InnerText, contentType.Value, fileShaCode + "/media", "");
  2961. media.url = adoModel.BlobUrl;
  2962. media.mediaType = "audio";
  2963. media.index = order;
  2964. }
  2965. //uInt8ArrayAudio = zip.file(audioFile).asArrayBuffer();
  2966. //blobAudio = new Blob([uInt8ArrayAudio]);
  2967. //audioBlob = URL.createObjectURL(blobAudio);
  2968. //var cx = parseInt(xfrmNode["a:ext"]["attrs"]["cx"]) * 20;
  2969. //var cy = xfrmNode["a:ext"]["attrs"]["cy"];
  2970. //var x = parseInt(xfrmNode["a:off"]["attrs"]["x"]) / 2.5;
  2971. //var y = xfrmNode["a:off"]["attrs"]["y"];
  2972. //audioObjc = {
  2973. // "a:ext" : {
  2974. // "attrs":{
  2975. // "cx":cx,
  2976. // "cy":cy
  2977. // }
  2978. // },
  2979. // "a:off":{
  2980. // "attrs":{
  2981. // "x":x,
  2982. // "y":y
  2983. // }
  2984. // }
  2985. //}
  2986. // mediaSupportFlag = true;
  2987. }
  2988. //////////////////////////////////////////////////////////////////////////
  2989. //mimeType = imgFileExt;
  2990. //rtrnData = "<div class='block content' style='" +
  2991. // (( audioPlayerFlag) ? GetPosition(audioObjc, null, null) : GetPosition(xfrmNode, null, null)) +
  2992. // (( audioPlayerFlag) ? GetSize(audioObjc, null, null) :GetSize(xfrmNode, null, null)) +
  2993. // " z-index: " + order + ";" +
  2994. // "transform: rotate(" + rotate + "deg);'>";
  2995. //if ((vdoNode ==null && audioNode ==null) || !mediaSupportFlag)
  2996. //{
  2997. // rtrnData += "<img src='data:" + mimeType + ";base64," + base64ArrayBuffer(imgArrayBuffer) + "' style='width: 100%; height: 100%'/>";
  2998. //}
  2999. //else if ((vdoNode !=null || audioNode !=null) && mediaSupportFlag)
  3000. //{
  3001. // if (vdoNode !=null)
  3002. // {
  3003. // rtrnData += "<video src='" + vdoBlob + "' controls style='width: 100%; height: 100%'>Your browser does not support the video tag.</video>";
  3004. // }
  3005. // if (audioNode !=null)
  3006. // {
  3007. // rtrnData += "<audio id='audio_player' controls ><source src='" + audioBlob + "'></audio>";
  3008. // }
  3009. //}
  3010. //rtrnData += "<span style='color:red;font-size:40px;position: absolute;'>This media file Not supported by HTML5</span>";
  3011. //if ((vdoNode != null || audioNode != null) && mediaSupportFlag)
  3012. //{
  3013. //}
  3014. // rtrnData += "</div>";
  3015. return media;
  3016. }
  3017. }
  3018. }