PowerPointService.cs 150 KB

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