HtexService.cs 152 KB

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