1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175 |
- using DocumentFormat.OpenXml.Packaging;
- using TEAMModelOS.Service.Model.PowerPoint;
- using Microsoft.AspNetCore.Http;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml;
- using System.Xml.Linq;
- using TEAMModelOS.SDK.Context.Constant;
- using TEAMModelOS.SDK.Context.Constant.Common;
- using TEAMModelOS.SDK.Context.Exception;
- using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
- using TEAMModelOS.SDK.Helper.Security.ShaHash;
- using TEAMModelOS.SDK.Module.AzureBlob.Container;
- using TEAMModelOS.SDK.Module.AzureBlob.Interfaces;
- using TEAMModelOS.Service.Models.PowerPoint.Inner;
- using Fill = TEAMModelOS.Service.Model.PowerPoint.Fill;
- using Media = TEAMModelOS.Service.Model.PowerPoint.Media;
- using Position = TEAMModelOS.Service.Model.PowerPoint.Position;
- using TEAMModelOS.Service.Services.PowerPoint.Interface;
- using TEAMModelOS.Service.Models.Exam.Models;
- using TEAMModelOS.Service.Services.Exam.Interfaces;
- using TEAMModelOS.SDK.Helper.Common.JsonHelper;
- namespace TEAMModelOS.Service.Services.PowerPoint.Implement
- {
- public class HtexService : IHtexService
- {
- private string fileShaCode { get; set; }
- private Dictionary<string, string> slideLayoutClrOvride { get; set; }
- private const int degree = 4;
- //private Dictionary<string, Dictionary<string, string>> styleTable = new Dictionary<string, Dictionary<string, string>>();
- private const double px96 = 96.00, px72 = 72.00, px914400 = 914400.00, px12700 = 12700.00;
- private const double rot60000 = 60000.00;
- public readonly IAzureBlobDBRepository azureBlobDBRepository;
- public readonly IHtmlAnalyzeService htmlAnalyzeService;
- public HtexService(IAzureBlobDBRepository _azureBlobDBRepository, IHtmlAnalyzeService _htmlAnalyzeService)
- {
- azureBlobDBRepository = _azureBlobDBRepository;
- htmlAnalyzeService = _htmlAnalyzeService;
- }
- public async Task<Htex> AnalyzeHtmlToHtex(string htmlString, string Lang)
- {
- Htex htex = new Htex();
- List<ExamItem> items = htmlAnalyzeService.AnalyzeWordAsync(htmlString, Lang);
- string sha= ShaHashHelper.GetSHA1(htmlString);
- int index = 0;
- foreach (ExamItem item in items)
- {
- Slide slide = new Slide { exercise = item, index = index, source = 2, flag = 2 };
- index++;
- AzureBlobModel model= await azureBlobDBRepository.UploadTextByFolder(slide.ToJson(), sha, index+".json","htex",false);
- htex.slides.Add(model.BlobUrl);
- }
- htex.page = items.Count;
- return htex;
- }
- public async Task<Dictionary<string, object>> LoadDoc(IFormFile file)
- {
- Dictionary<string, object> resdict = new Dictionary<string, object>();
- if (FileType.GetExtention(file.FileName).ToLower().Equals("pptx"))
- {
-
- return await ConvertPPTX(file, resdict);
- }
- else if (FileType.GetExtention(file.FileName).ToLower().Equals("pdf"))
- {
- // await ProcessPDF(file, resdict);
- return resdict;
- }
- else if (FileType.GetExtention(file.FileName).ToLower().Equals("xml"))
- {
- XmlDocument xmlDocument = new XmlDocument();
- StreamReader sr = new StreamReader(file.OpenReadStream(), System.Text.Encoding.UTF8);
- string line;
- StringBuilder builder = new StringBuilder();
- while ((line = sr.ReadLine()) != null)
- {
- builder.Append(line.ToString());
- }
- sr.Close();
- xmlDocument.LoadXml(builder.ToString());
- string shaCode = fileShaCode = ShaHashHelper.GetSHA1(file.OpenReadStream());
- var rslt_ary = await ProcessPPTX(xmlDocument, shaCode);
- //TODO
- Dictionary<string, object> data = new Dictionary<string, object> { { "htexl", rslt_ary } };
- return data;
- }
- else
- {
- throw new BizException("file type does not support!", 500);
- }
- }
- public async Task<Dictionary<string, object>> ConvertPPTX(IFormFile file, Dictionary<string, object> resdict)
- {
- string shaCode = fileShaCode = ShaHashHelper.GetSHA1(file.OpenReadStream());
- PresentationDocument presentationDocument = PresentationDocument.Open(file.OpenReadStream(), false);
- if (presentationDocument == null)
- {
- throw new ArgumentNullException("presentationDocument");
- }
- XDocument xdoc = presentationDocument.ToFlatOpcDocument();
- XmlDocument xmlDocument = new XmlDocument();
- xmlDocument.LoadXml(xdoc.ToString());
- var rslt_ary = await ProcessPPTX(xmlDocument, shaCode);
- //TODO
- Dictionary<string, object> data = new Dictionary<string, object> { { "pptx",rslt_ary} };
- return data;
- }
- /// <summary>
- /// 加载PPTX文件
- /// </summary>
- /// <param name="presentationFile"></param>
- /// <returns></returns>
- public async Task<Htex> ProcessPPTX(XmlDocument xdoc, string shaCode)
- {
- Htex pptx = new Htex();
- // List<Dictionary<string, object>> post_ary = new List<Dictionary<string, object>>();
- Dictionary<string, object> post_ary = new Dictionary<string, object>();
- var dateBefore = DateTimeOffset.Now.UtcTicks;
- AzureBlobModel thumbnailModel = await GetThumbnailModel(xdoc, shaCode);
- // post_ary.Add( "pptx-thumb", thumbnailModel );
- pptx.thumbnail = thumbnailModel != null ? thumbnailModel.BlobUrl : "";
- //获取全部的/ppt/slides/slide1.xml--->>/ppt/slides/slide(n).xml
- var slideNodes = xdoc.GetTextByPathList("//pkg:part[@pkg:contentType='application/vnd.openxmlformats-officedocument.presentationml.slide+xml']");
- //获取全部的/ppt/slideLayouts/slideLayout1.xml--->>/ppt/slideLayouts/slideLayout(n).xml
- var slideLayoutNodes = xdoc.GetTextByPathList("//pkg:part[@pkg:contentType='application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml']");
- //获取ppt的宽高
- var slideSize = ShapeHelper.GetSlideSize(xdoc);
- pptx.size = new HtexSize { width = slideSize.width, height = slideSize.height };
- // post_ary.Add( "slideSize", slideSize );
- //加载当前PPT使用到的PPT节点
- var themeContent = LoadTheme(xdoc);
- //获取所有的表格样式节点
- var tableStyles = xdoc.GetTextByPath("//pkg:part[@pkg:name='/ppt/tableStyles.xml']/pkg:xmlData/a:tblStyleLst");
- //处理slide1---slide(n)
- int numOfSlides = slideNodes.Count;
- List<Slide> slides = new List<Slide>();
- for (int i = 0; i < numOfSlides; i++)
- {
-
- var node = xdoc.GetTextByPath("//pkg:part[@pkg:name='/ppt/slides/slide" + (i + 1) + ".xml']");
- string filename = node.GetTextByPath("@pkg:name").Value;
- //处理当前页的幻灯片
- Slide slide = await ProcessSingleSlide(xdoc, node, filename, i, slideSize, themeContent, tableStyles, pptx);
-
- slide.source = 1;
- slide.flag = 1;
- AzureBlobModel model = await azureBlobDBRepository.UploadTextByFolder(slide.ToJson(), shaCode, (i + 1) + ".json", "htex", false);
- pptx.slides.Add(model.BlobUrl);
- slides.Add(slide);
- // post_ary.Add(new Dictionary<string, object> { { "slide", slideHtml } });
- // post_ary.Add(new Dictionary<string, object> { { "progress-update", (i + 1) * 100 / numOfSlides } });
- }
- // pptx.Sha1Code = shaCode;
- pptx.page = slides.Count;
- //post_ary.Add( "slide", slides );
- //post_ary.Add( "globalCSS", GenGlobalCSS() );
- // var dateAfter = DateTimeOffset.Now.UtcTicks;
- // post_ary.Add( "ExecutionTime", dateAfter - dateBefore );
- return pptx;
- }
- //public Dictionary<string, string> GenGlobalCSS()
- //{
- // Dictionary<string, string> cssText = new Dictionary<string, string>();
- // foreach (var key in styleTable.Keys)
- // {
- // // cssText += "div ." + styleTable[key]["name"] + "{" + styleTable[key]["text"] + "}\n"; //section > div
- // var cssTextKey = styleTable[key]["name"];
- // var cssTextValue = styleTable[key]["text"];
- // cssText.Add(cssTextKey, cssTextValue);
- // }
- // return cssText;
- //}
- public async Task<Slide> ProcessSingleSlide(XmlDocument xdoc, XmlNode xnode, string sldFileName, int index, dynamic slideSize, XmlNode themeContent, XmlNode tableStyles,Htex pptx)
- {
- var resName = sldFileName.Replace("slides/slide", "slides/_rels/slide") + ".rels";
- var RelationshipArray = xdoc.GetTextByPathList("//pkg:part[@pkg:name='" + resName + "']/pkg:xmlData/rel:Relationships/rel:Relationship");
- Dictionary<string, Dictionary<string, string>> slideResObj = new Dictionary<string, Dictionary<string, string>>();
- var layoutFilename = "";
- foreach (XmlNode Relationship in RelationshipArray)
- {
- var RelationshipType = Relationship.GetTextByPath("@Type");
- if (RelationshipType.Value.Equals("http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout"))
- {
- layoutFilename = Relationship.GetTextByPath("@Target").Value.Replace("../", "/ppt/");
- }
- else
- {
- //case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide":
- //case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image":
- //case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart":
- //case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink":
- Dictionary<string, string> dict = new Dictionary<string, string>();
- string Type = Relationship.GetTextByPath("@Type").Value.Replace("http://schemas.openxmlformats.org/officeDocument/2006/relationships/", "");
- string Target = Relationship.GetTextByPath("@Target").Value.Replace("../", "/ppt/");
- string Id = Relationship.GetTextByPath("@Id").Value;
- dict.Add("type", Type);
- dict.Add("target", Target);
- slideResObj.Add(Id, dict);
- }
- }
- // Open slideLayoutXX.xml
- var slideLayoutContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + layoutFilename + "']");
- NodesTable slideLayoutTables = ShapeHelper.IndexNodes(slideLayoutContent.GetTextByPath("pkg:xmlData/p:sldLayout"));
- ///ppt/slides/slide5.xml 也包含a:overrideClrMapping
- ////ppt/slideLayouts/slideLayout13.xml 也包含a:overrideClrMapping
- var sldLayoutClrOvr = slideLayoutContent.GetTextByPath("pkg:xmlData/p:sldLayout/p:clrMapOvr/a:overrideClrMapping");
- if (sldLayoutClrOvr != null)
- {
- //获取 overrideClrMapping所有属性节点
- slideLayoutClrOvride = new Dictionary<string, string>() {
- { "accent1", sldLayoutClrOvr.GetTextByPath("@accent1").Value},
- { "accent2", sldLayoutClrOvr.GetTextByPath("@accent2").Value},
- { "accent3", sldLayoutClrOvr.GetTextByPath("@accent3").Value},
- { "accent4", sldLayoutClrOvr.GetTextByPath("@accent4").Value},
- { "accent5", sldLayoutClrOvr.GetTextByPath("@accent5").Value},
- { "accent6", sldLayoutClrOvr.GetTextByPath("@accent6").Value},
- { "bg1", sldLayoutClrOvr.GetTextByPath("@bg1").Value},
- { "bg2", sldLayoutClrOvr.GetTextByPath("@bg2").Value},
- { "folHlink", sldLayoutClrOvr.GetTextByPath("@folHlink").Value},
- { "hlink", sldLayoutClrOvr.GetTextByPath("@hlink").Value},
- { "tx1", sldLayoutClrOvr.GetTextByPath("@tx1").Value},
- { "tx2", sldLayoutClrOvr.GetTextByPath("@tx2").Value}
- };
- }
- // =====< Step 2 >=====
- // Read slide master filename of the slidelayout (Get slideMasterXX.xml)
- // @resName: ppt/slideLayouts/slideLayout1.xml
- // @masterName: ppt/slideLayouts/_rels/slideLayout1.xml.rels
- var slideLayoutResFilename = layoutFilename.Replace("slideLayouts/slideLayout", "slideLayouts/_rels/slideLayout") + ".rels";
- var slideLayoutResContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + slideLayoutResFilename + "']");
- ///查看js 是替换之前 还是添加
- RelationshipArray = slideLayoutResContent.GetTextByPathList("pkg:xmlData/rel:Relationships/rel:Relationship");
- var masterFilename = "";
- Dictionary<string, Dictionary<string, string>> layoutResObj = new Dictionary<string, Dictionary<string, string>>();
- for (int i = 0; i < RelationshipArray.Count; i++)
- {
- if (RelationshipArray[i].GetTextByPath("@Type").Value.Equals("http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster"))
- {
- masterFilename = RelationshipArray[i].GetTextByPath("@Target").Value.Replace("../", "/ppt/");
- }
- else
- {
- Dictionary<string, string> dict = new Dictionary<string, string>();
- string Type = RelationshipArray[i].GetTextByPath("@Type").Value.Replace("http://schemas.openxmlformats.org/officeDocument/2006/relationships/", "");
- string Target = RelationshipArray[i].GetTextByPath("@Target").Value.Replace("../", "/ppt/");
- string Id = RelationshipArray[i].GetTextByPath("@Id").Value;
- dict.Add("type", Type);
- dict.Add("target", Target);
- layoutResObj.Add(Id, dict);
- }
- }
- // Open slideMasterXX.xml
- var slideMasterContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + masterFilename + "']");
- var slideMasterTextStyles = slideMasterContent.GetTextByPath("pkg:xmlData/p:sldMaster/p:txStyles");
- var slideMasterTables = ShapeHelper.IndexNodes(slideMasterContent.GetTextByPath("pkg:xmlData/p:sldMaster"));
- /////////////////Amir/////////////
- //Open slideMasterXX.xml.rels
- var slideMasterResFilename = masterFilename.Replace("slideMasters/slideMaster", "slideMasters/_rels/slideMaster") + ".rels";
- var slideMasterResContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + slideMasterResFilename + "']");
- RelationshipArray = slideMasterResContent.GetTextByPathList("pkg:xmlData/rel:Relationships/rel:Relationship");
- var themeFilename = "";
- Dictionary<string, Dictionary<string, string>> masterResObj = new Dictionary<string, Dictionary<string, string>>();
- for (int i = 0; i < RelationshipArray.Count; i++)
- {
- if (RelationshipArray[i].GetTextByPath("@Type").Value.Equals("http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"))
- {
- themeFilename = RelationshipArray[i].GetTextByPath("@Target").Value.Replace("../", "/ppt/");
- }
- else
- {
- Dictionary<string, string> dict = new Dictionary<string, string>();
- string Type = RelationshipArray[i].GetTextByPath("@Type").Value.Replace("http://schemas.openxmlformats.org/officeDocument/2006/relationships/", "");
- string Target = RelationshipArray[i].GetTextByPath("@Target").Value.Replace("../", "/ppt/");
- string Id = RelationshipArray[i].GetTextByPath("@Id").Value;
- dict.Add("type", Type);
- dict.Add("target", Target);
- masterResObj.Add(Id, dict);
- }
- }
- //Load Theme file
- if (!string.IsNullOrEmpty(themeFilename))
- {
- themeContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + themeFilename + "']");
- }
- // =====< Step 3 >===== throw new NotImplementedException();
- var slideContent = xdoc.GetTextByPath("//pkg:part[@pkg:name='" + sldFileName + "']");
- var spTreeNode = slideContent.GetTextByPath("pkg:xmlData/p:sld/p:cSld/p:spTree");
- WarpObj warpObj = new WarpObj
- {
- zip = xdoc,
- slideLayoutTables = slideLayoutTables,
- slideMasterTables = slideMasterTables,
- slideMasterTextStyles = slideMasterTextStyles,
- slideResObj = slideResObj,
- layoutResObj = layoutResObj,
- masterResObj = masterResObj,
- slideLayoutContent = slideLayoutContent,
- slideMasterContent = slideMasterContent,
- themeContent = themeContent,
- tableStyles = tableStyles,
- htex = pptx
- };
- var bgColor = await GetSlideBackgroundFill(slideContent, index, warpObj);
- //string sha = null;
- //if (bgColor != null) {
- // sha = ShaHashHelper.GetSHA1(bgColor.ToJson());
- // warpObj.pptx.Fills.TryAdd(sha, bgColor);
- //}
- // string result = "<div class='slide' style='width:" + slideSize.width + "px; height:" + slideSize.height + "px;" + bgColor + "'>";
- //result += "<div>"+getBackgroundShapes(slideContent, slideLayoutContent, slideMasterContent,warpObj) + "</div>" - TODO
- Slide slide = new Slide { fill=bgColor ,width= slideSize .width ,height= slideSize .height ,index=index };
- if (spTreeNode != null)
- {
- var nodes = spTreeNode.ChildNodes;
- int order = 1;
- List<Item> items = new List<Item>();
- foreach (XmlNode node in nodes)
- {
- await ProcessNodesInSlide(items, node.Name, node, order, warpObj);
- order += 1;
- }
- slide.item = items;
- }
- return slide;
- }
- public async Task ProcessNodesInSlide(List<Item> items, string nodeKey, XmlNode node, int order, WarpObj warpObj)
- {
- // string result = "";
- switch (nodeKey)
- {
- case "p:sp": // Shape, Text
- Item spitem= await ProcessSpNode(node, order, warpObj);
- if (spitem != null) {
- items.Add(spitem);
- }
- break;
- case "p:cxnSp": // Shape, Text (with connection)
- Item cxnitem = await ProcessCxnSpNode(node, order, warpObj);
- if (cxnitem != null)
- {
- items.Add(cxnitem);
- }
- break;
- case "p:pic": // Picture
- Item picitem = await ProcessPicNode(node, order, warpObj);
- if (picitem != null) {
- items.Add(picitem);
- }
- break;
- case "p:graphicFrame": // Chart, Diagram, Table
- await ProcessGraphicFrameNode(items, node, order, warpObj);
- break;
- case "p:grpSp":
- await ProcessGroupSpNode(items, node, order, warpObj);
- break;
- case "mc:AlternateContent": //Equations and formulas as Image 处理公式 方程等
- var mcFallbackNode = node.GetTextByPath("mc:Fallback/p:sp");
- if (mcFallbackNode != null)
- {
- Item mcitem = await ProcessSpNode(mcFallbackNode, order, warpObj);
- if (mcitem != null)
- {
- items.Add(mcitem);
- }
- }
- else {
- mcFallbackNode = node.GetTextByPath("mc:Fallback/p:pic");
- if (mcFallbackNode != null) {
- Item mcPicitem = await ProcessPicNode(mcFallbackNode, order, warpObj);
- if (mcPicitem != null)
- {
- items.Add(mcPicitem);
- }
- }
- }
- break;
- default:
- break;
- }
- }
- public async Task ProcessGroupSpNode(List<Item> items, XmlNode node, int order, WarpObj warpObj)
- {
- var factor = 1.00 * px96 / px914400;
- var xfrmNode = node.GetTextByPath("p:grpSpPr/a:xfrm");
- var x = int.Parse(xfrmNode.GetTextByPath("a:off/@x").Value) * factor;
- var y = int.Parse(xfrmNode.GetTextByPath("a:off/@y").Value) * factor;
- var chx = int.Parse(xfrmNode.GetTextByPath("a:chOff/@x").Value) * factor;
- var chy = int.Parse(xfrmNode.GetTextByPath("a:chOff/@y").Value) * factor;
- var cx = int.Parse(xfrmNode.GetTextByPath("a:ext/@cx").Value) * factor;
- var cy = int.Parse(xfrmNode.GetTextByPath("a:ext/@cy").Value) * factor;
- var chcx = int.Parse(xfrmNode.GetTextByPath("a:chExt/@cx").Value) * factor;
- var chcy = int.Parse(xfrmNode.GetTextByPath("a:chExt/@cy").Value) * factor;
- var rotate = ShapeHelper.AngleToDegrees(xfrmNode.GetTextByPath("@rot"));
- // string result = "<div class='block group' style='z-index: " + order + "; top: " + (y - chy) + "px; left: " + (x - chx) + "px;" +
- // " width: " + (cx - chcx) + "px; height: " + (cy - chcy) + "px;'>";
- Group group = new Group
- {
- 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) },
- type = "Group",
- index = order++
- };
- // Procsee all child nodes
- var nodes = node.ChildNodes;
- List<Item> gpIterm = new List<Item>();
- foreach (XmlNode nd in nodes)
- {
- await ProcessNodesInSlide(gpIterm, nd.Name, nd, order, warpObj);
- order += 1;
- }
- group.shapes = gpIterm;
- items.Add(group);
- // result += "</div>";
- //return result;
- }
- public async Task ProcessGraphicFrameNode(List<Item> items, XmlNode node, int order, WarpObj warpObj)
- {
- // var result = "";
- var graphicTypeUri = node.GetTextByPath("a:graphic/a:graphicData/@uri");
- if (graphicTypeUri != null)
- {
- switch (graphicTypeUri.Value)
- {
- case "http://schemas.openxmlformats.org/drawingml/2006/table":
- Table table= await GenTable(node, order, warpObj);
- items.Add(table);
- break;
- case "http://schemas.openxmlformats.org/drawingml/2006/chart":
- items.Add(GenChart(node, order, warpObj));
- break;
- case "http://schemas.openxmlformats.org/drawingml/2006/diagram":
- await GenDiagram(items, node, order, warpObj);
- break;
- default:
- break;
- }
- }
- //return result;
- }
- public async Task GenDiagram(List<Item> items, XmlNode node, int order, WarpObj warpObj)
- {
- var xfrmNode = node.GetTextByPath("p:xfrm");
- var dgmRelIds = node.GetTextByPath("a:graphic/a:graphicData/dgm:relIds");
- var dgmClrFileId = dgmRelIds.GetTextByPath("@r:cs");
- var dgmDataFileId = dgmRelIds.GetTextByPath("@r:dm");
- var dgmLayoutFileId = dgmRelIds.GetTextByPath("@r:lo");
- var dgmQuickStyleFileId = dgmRelIds.GetTextByPath("@r:qs");
- var dgmClrFileName = warpObj.slideResObj[dgmClrFileId.Value]["target"];
- var dgmDataFileName = warpObj.slideResObj[dgmDataFileId.Value]["target"];
- var dgmLayoutFileName = warpObj.slideResObj[dgmLayoutFileId.Value]["target"];
- var dgmQuickStyleFileName = warpObj.slideResObj[dgmQuickStyleFileId.Value]["target"];
- var dgmClr = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + dgmClrFileName + "']");
- var dgmData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + dgmDataFileName + "']");
- var dgmLayout = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + dgmLayoutFileName + "']");
- var dgmQuickStyle = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + dgmQuickStyleFileName + "']");
- var dgmDrwFileName = "";
- var dataModelExt = dgmData.GetTextByPath("pkg:xmlData/dgm:dataModel/dgm:extLst/a:ext/dsp:dataModelExt");
- if (dataModelExt != null) {
- var dgmDrwFileId = dataModelExt.GetTextByPath("@relId");
- dgmDrwFileName = warpObj.slideResObj[dgmDrwFileId.Value]["target"];
- }
- XmlNode dgmDrwFile=null ;
- if (dgmDrwFileName != "")
- {
- dgmDrwFile = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + dgmDrwFileName + "']");
- }
- var dgmDrwSpArray = dgmDrwFile.GetTextByPathList("pkg:xmlData/dsp:drawing/dsp:spTree/dsp:sp");
- if (dgmDrwSpArray !=null)
- {
- Diagram diagram = new Diagram();
- diagram.position = ShapeHelper.GetPosition(xfrmNode, null, null);
- diagram.type = "Diagram";
- diagram.index = order++;
- // Procsee all child nodes
- List<Item> gpIterm = new List<Item>();
- XmlDocument nodeDoc = new XmlDocument();
- var dgmDrwSpArrayLen = dgmDrwSpArray.Count;
- for (var i = 0; i < dgmDrwSpArrayLen; i++)
- {
- var dspSp = dgmDrwSpArray.Item(i);
- 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\"");
- nodeDoc.LoadXml(pSpStr);
- //await ProcessSpNode(nodeDoc,order,warpObj);
- await ProcessNodesInSlide(gpIterm, nodeDoc.FirstChild.Name, nodeDoc.FirstChild, order, warpObj);
- }
- diagram.shapes = gpIterm;
- items.Add(diagram);
- }
- }
- public Chart GenChart(XmlNode node,int order , WarpObj warpObj)
- {
- Chart chart = new Chart { index=order,type= "Chart" };
- var slideXfrmNode = node.GetTextByPath("p:xfrm");
- Position position = ShapeHelper.GetPosition(slideXfrmNode, null, null);
- chart.position = position;
- var rid = node.GetTextByPath("a:graphic/a:graphicData/c:chart/@r:id");
- List<Paragraph> paragraphs = new List<Paragraph>() ;
- if (rid != null) {
- var refName= warpObj.slideResObj[rid.Value]["target"];
- var content = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + refName + "']");
- var plotArea = content.GetTextByPath("pkg:xmlData/c:chartSpace/c:chart/c:plotArea");
- var chartPnode = content.GetTextByPathList("pkg:xmlData/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p");
- var anchor = content.GetTextByPath("pkg:xmlData/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:bodyPr/@anchor");
- var vert = content.GetTextByPath("pkg:xmlData/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:bodyPr/@vert");
- string VertAlign = "v-up";
- string WritingMode = "horz";
- if (anchor != null)
- {
- VertAlign = anchor.Value.Equals("ctr") ? "v-mid" : anchor.Value.Equals("b") ? "v-down" : "v-up";
- }
- if (vert != null) {
- WritingMode = vert.Value;
- }
-
- foreach (XmlNode pNode in chartPnode) {
- string HoriAlign= GetHorizontalAlign(pNode, null, null, null, null);
- // string sha = null;
- ParagraphStyle paragraphStyle = new ParagraphStyle
- {
- hori = HoriAlign,
- writing = WritingMode,
- vert = VertAlign
- };
- //sha = ShaHashHelper.GetSHA1(paragraphStyle.ToJson());
- //warpObj.pptx.ParagraphStyles.TryAdd(sha, paragraphStyle);
- Paragraph paragraph = new Paragraph
- {
- style = paragraphStyle,
- // StyleSha=sha
- };
- double defFontSize = 0;
- string defFontColor = "none";
- var defsz= pNode.GetTextByPath("a:pPr/a:defRPr/@sz");
- if (defsz != null) {
- defFontSize = int.Parse(defsz.Value) / 100.0;
- }
- var solidFillNode = pNode.GetTextByPath("a:pPr/a:defRPr/a:solidFill");
- string colorstr = ShapeHelper.GetSolidFill(solidFillNode, slideLayoutClrOvride,warpObj. slideMasterContent,warpObj. themeContent);
- if (solidFillNode != null)
- {
- defFontColor = ShapeHelper.ColorToning(solidFillNode.OuterXml, colorstr);
- }
- var rNodes = pNode.GetTextByPathList("a:r");
- List<Text> texts = new List<Text>();
- foreach (XmlNode rNode in rNodes)
- {
- Text text = GenSpanElement(rNode, null, null, null, null, warpObj);
- if (pNode.GetTextByPath("a:br") != null)
- {
- text.isbr = true;
- }
- if (text.style.size == 0) {
- text.style.size = defFontSize;
- }
- if (text.style.color.Equals("000000"))
- {
- text.style.color = defFontColor;
- }
- //string styleSha = ShaHashHelper.GetSHA1(text.FontStyle.ToJson());
- //warpObj.pptx.FontStyles.TryAdd(styleSha, text.FontStyle);
- //text.StyleSha = styleSha;
- texts.Add(text);
- }
- paragraph.texts = texts;
- paragraphs.Add(paragraph);
- }
- chart.title = paragraphs;
- var ps = plotArea.ChildNodes;
- List<CommonChart> charts = new List<CommonChart>();
-
- foreach (XmlNode nodeChild in ps) {
- string key = nodeChild.Name.Replace("c:","");
- XmlNodeList serNodes = null;
- switch (key)
- {
- //break块中不可以随意更换,此条件用于归类不同从Chart
- case "pieChart":
- case "ofPieChart":
- case "pie3DChart":
- case "doughnutChart":
- PieChart pieChart = new PieChart { chartType="pie"};
- if (key.Equals("pie3DChart")) {
- pieChart.is3D = true;
- }
- pieChart.pieType = key;
- if (key.Equals("ofPieChart")) {
- var ofPieType = nodeChild.GetTextByPath("c:ofPieType/@val");
- if (ofPieType != null) {
- //ofPieChart-pie ofPieChart-bar 子母饼图
- pieChart.pieType += "-"+ ofPieType.Value;
- }
- }
- serNodes = nodeChild.GetTextByPathList("c:ser");
- pieChart.datas= ExtractChartData(serNodes);
- charts.Add(pieChart);
- break;
- case "lineChart":
- case "line3DChart":
- LineChart lineChart = new LineChart { chartType = "line" };
- if (key.Equals("line3DChart"))
- {
- lineChart.is3D = true;
- }
- lineChart.lineType = key;
- var LineGrouping = nodeChild.GetTextByPath("c:grouping/@val");
- if (LineGrouping != null)
- {
- //standard stacked percentStacked
- lineChart.lineType += "-" + LineGrouping.Value;
- }
- serNodes = nodeChild.GetTextByPathList("c:ser");
- lineChart.datas = ExtractChartData(serNodes);
- charts.Add(lineChart);
- break;
- case "barChart":
- case "bar3DChart":
- var barDir = nodeChild.GetTextByPath("c:barDir/@val");
- if (barDir != null)
- {
- if (barDir.Value.Equals("bar"))
- {
- BarChart barChart = new BarChart { chartType = "bar" };
- charts.Add(barChart);
- if (key.Equals("bar3DChart"))
- {
- barChart.is3D = true;
- }
- barChart.barType = key;
- var BarGrouping = nodeChild.GetTextByPath("c:grouping/@val");
- if (BarGrouping != null)
- {
- //standard stacked percentStacked
- barChart.barType += "-" + BarGrouping.Value;
- }
- serNodes = nodeChild.GetTextByPathList("c:ser");
- barChart.datas = ExtractChartData(serNodes);
- charts.Add(barChart);
- }
- else if(barDir.Value.Equals("col")){
- ColChart colChart = new ColChart { chartType = "col" };
- if (key.Equals("bar3DChart"))
- {
- colChart.is3D = true;
- }
- colChart.colType = key.Replace("bar","col");
- var ColGrouping = nodeChild.GetTextByPath("c:grouping/@val");
- if (ColGrouping != null)
- {
- //standard stacked percentStacked
- colChart.colType += "-" + ColGrouping.Value;
- }
- serNodes = nodeChild.GetTextByPathList("c:ser");
- colChart.datas = ExtractChartData(serNodes);
- charts.Add(colChart);
- }
- }
- break;
- case "areaChart":
- case "area3DChart":
- AreaChart areaChart = new AreaChart { chartType = "area" };
- if (key.Equals("area3DChart"))
- {
- areaChart.is3D = true;
- }
- areaChart.areaType = key;
- var AreaGrouping = nodeChild.GetTextByPath("c:grouping/@val");
- if (AreaGrouping != null)
- {
- //standard stacked percentStacked
- areaChart.areaType += "-" + AreaGrouping.Value;
- }
- serNodes = nodeChild.GetTextByPathList("c:ser");
- areaChart.datas = ExtractChartData(serNodes);
- charts.Add(areaChart);
- break;
- case "scatterChart":
- case "bubbleChart":
- ScatterChart scatterChart = new ScatterChart { chartType = "scatter" };
- scatterChart.scatterType = key;
- if (key.Equals("scatterChart")) {
- var ScatterStyle = nodeChild.GetTextByPath("c:scatterStyle/@val");
- if (ScatterStyle != null)
- {
- scatterChart.scatterType += "-" + ScatterStyle.Value.Replace("Marker","");
- }
- }
- serNodes = nodeChild.GetTextByPathList("c:ser");
- scatterChart.datas = ExtractChartData(serNodes);
- charts.Add(scatterChart);
- break;
- case "radarChart":
- RadarChart radarChart = new RadarChart { chartType = "radar" };
- radarChart.radarType = key;
- var RadarStyle = nodeChild.GetTextByPath("c:radarStyle/@val");
- if (RadarStyle != null)
- {
- radarChart.radarType += "-" + RadarStyle.Value;
- }
- serNodes = nodeChild.GetTextByPathList("c:ser");
- radarChart.datas = ExtractChartData(serNodes);
- charts.Add(radarChart);
- break;
- case "plotAreaRegion":
- PlotAreaChart plotAreaChart = new PlotAreaChart { chartType = "plotArea" };
- plotAreaChart.plotAreaType = key;
- var PlotSeries = nodeChild.GetTextByPath("cx:series/@layoutId");
- if (PlotSeries != null)
- {
- plotAreaChart.plotAreaType += "-" + PlotSeries.Value;
- }
- serNodes = nodeChild.GetTextByPathList("c:ser");
- plotAreaChart.datas = ExtractChartData(serNodes);
- charts.Add(plotAreaChart);
- break;
- case "stockChart":
- StockChart stockChart = new StockChart { chartType = "stock" };
- stockChart.stockType = key;
- serNodes = nodeChild.GetTextByPathList("c:ser");
- stockChart.datas = ExtractChartData(serNodes);
- charts.Add(stockChart);
- break;
- case "surfaceChart":
- case "surface3DChart":
- SurfaceChart surfaceChart = new SurfaceChart { chartType = "surface" };
- if (key.Equals("surface3DChart"))
- {
- surfaceChart.is3D = true;
- }
- surfaceChart.surfaceType = key;
- var Wireframe = nodeChild.GetTextByPath("c:wireframe/@val");
- if (Wireframe != null)
- {
- surfaceChart.surfaceType += "-" + Wireframe.Value;
- }
- serNodes = nodeChild.GetTextByPathList("c:ser");
- surfaceChart.datas = ExtractChartData(serNodes);
- charts.Add(surfaceChart);
- break;
- }
- }
- chart.charts = charts;
- }
- return chart;
- }
- public List<Dictionary<string,object>> ExtractChartData(XmlNodeList nodes) {
- if (nodes != null) {
- List<Dictionary<string, object>> listDict = new List<Dictionary<string, object>>();
- foreach(XmlNode node in nodes)
- {
-
- if (node.GetTextByPath("c:xVal") != null)
- {
- Dictionary<string, object> dict = new Dictionary<string, object>();
- var xCvNodes = node.GetTextByPathList("c:xVal/c:numRef/c:numCache/c:pt/c:v");
- if (xCvNodes != null)
- {
- List<string> list = new List<string>();
- foreach (XmlNode cvNode in xCvNodes)
- {
- list.Add(cvNode.InnerText);
- }
- dict.Add("xAxis", list);
- }
- var yCvNodes = node.GetTextByPathList("c:yVal/c:numRef/c:numCache/c:pt/c:v");
- if (yCvNodes != null)
- {
- List<string> list = new List<string>();
- foreach (XmlNode cvNode in yCvNodes)
- {
- list.Add(cvNode.InnerText);
- }
- dict.Add("yAxis", list);
- }
- dict.Add("colName", "-");
- listDict.Add(dict);
- }
- else
- {
- Dictionary<string, object> dict = new Dictionary<string, object>();
- var colNameNode = node.GetTextByPath("c:tx/c:strRef/c:strCache/c:pt/c:v");
- if (colNameNode != null) {
- dict.Add("colName", colNameNode.InnerText);
- }
- //name
- var catNodes = node.GetTextByPathList("c:cat/c:strRef/c:strCache/c:pt/c:v");
- if (catNodes == null) {
- catNodes = node.GetTextByPathList("c:cat/c:numRef/c:numCache/c:pt/c:v");
- }
- if (catNodes != null) {
- List<string> list = new List<string>();
- foreach (XmlNode cvNode in catNodes)
- {
- list.Add(cvNode.InnerText);
- }
- dict.Add("xAxis", list);
- }
- //value
- var valNodes = node.GetTextByPathList("c:val/c:numRef/c:numCache/c:pt/c:v");
- if (valNodes != null) {
- List<string> list = new List<string>();
- foreach (XmlNode cvNode in valNodes)
- {
- list.Add(cvNode.InnerText);
- }
- dict.Add("yAxis", list);
- }
- listDict.Add(dict);
- }
- }
- return listDict;
- }
- return null;
- }
- public async Task<Table> GenTable(XmlNode node, int order, WarpObj warpObj)
- {
- Table table = new Table();
- table.index = order;
- var slideXfrmNode= node.GetTextByPath("p:xfrm");
- Position position = ShapeHelper.GetPosition(slideXfrmNode, null, null);
- var tableNode = node.GetTextByPath("a:graphic/a:graphicData/a:tbl");
- var getTblPr = tableNode.GetTextByPath("a:tblPr");
- var getColsGrid = tableNode.GetTextByPath("a:tblGrid/a:gridCol");
- var tblDir = "ltr";
- XmlNode firstRowAttr = null , bandRowAttr =null ;
- if (getTblPr != null) {
- var isRTL = getTblPr.GetTextByPath("@rtl");
- tblDir = isRTL!=null && isRTL.Value.Equals("1") ? "rtl" : "ltr";
- firstRowAttr = getTblPr.GetTextByPath("@firstRow"); //associated element <a:firstRow> in the table styles
- var firstColAttr = getTblPr.GetTextByPath("@firstCol"); //associated element <a:firstCol> in the table styles
- var lastRowAttr = getTblPr.GetTextByPath("@lastRow");//associated element <a:lastRow> in the table styles
- var lastColAttr = getTblPr.GetTextByPath("@lastCol"); //associated element <a:lastCol> in the table styles
- bandRowAttr = getTblPr.GetTextByPath("@bandRow"); //associated element <a:band1H>, <a:band2H> in the table styles
- var bandColAttr = getTblPr.GetTextByPath("@bandCol"); //associated element <a:band1V>, <a:band2V> in the table styles
- }
- table.dir = tblDir;
- table.position = position;
- table.type = "Table";
- var trNodes = tableNode.GetTextByPathList("a:tr");
- if (trNodes != null) {
- int trSize = trNodes.Count;
- for (int i = 0; i < trSize; i++)
- {
- Tr tr = new Tr();
- var rowHeightParam = trNodes.Item(i).GetTextByPath("@h");
- double rowHeight = 0;
- //var rowsStyl = "";
- if (rowHeightParam != null) {
- rowHeight = int.Parse(rowHeightParam.Value) * px96 / px914400;
- }
- tr.height = rowHeight;
- XmlNode thisTblStyle=null;
- var tbleStyleId = getTblPr.GetTextByPath("a:tableStyleId");
- if (tbleStyleId != null)
- {
- var tbleStylList = warpObj.tableStyles.GetTextByPathList("a:tblStyleLst/a:tblStyle");
- foreach (XmlNode tbleStyle in tbleStylList)
- {
- if (tbleStyle.GetTextByPath("@styleId").Value.Equals(tbleStyleId.Value))
- {
- thisTblStyle = tbleStyle;
- }
- }
- }
- if (i == 0 && firstRowAttr != null && thisTblStyle != null)
- {
- var fillColor = "fff";
- // var colorOpacity = 1;
- if (thisTblStyle.GetTextByPath("a:firstRow") != null)
- {
- //处理纯色填充
- var bgFillschemeClr = thisTblStyle.GetTextByPath("a:firstRow/a:tcStyle/a:fill/a:solidFill");
- if (bgFillschemeClr != null)
- {
- fillColor = ShapeHelper.GetSolidFill(bgFillschemeClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- fillColor = ShapeHelper.ColorToning(bgFillschemeClr.OuterXml, fillColor);
- Fill f = new Fill { color = fillColor, type = 1 };
- //string sha = null;
- //sha = ShaHashHelper.GetSHA1(f.ToJson());
- //warpObj.pptx.Fills.TryAdd(sha, f);
- //tr.FillSha = sha;
- tr.fill = f;
- }
- //其他填充 todo
- var fill = thisTblStyle.GetTextByPath("a:firstRow/a:tcStyle/a:fill");
- string fillType = ShapeHelper.GetFillType(fill);
- var borderStyl = thisTblStyle.GetTextByPath("a:firstRow/a:tcStyle/a:tcBdr");
- if (borderStyl != null)
- {
- List<Border> borders = GetTableBorders(borderStyl, warpObj);
- tr.borders = borders;
- }
- //Text Style - TODO
- //var rowTxtStyl = getTextByPathList(thisTblStyle,["a:firstRow", "a:tcTxStyle"]);
- //if (rowTxtStyl !== undefined)
- //{
- /*
- var fontClrPr = getFontColorPr(node, spNode, type, slideMasterTextStyles);
- var styleText =
- "color:" + fontClrPr[0] + ";" +
- "text-shadow:" + fontClrPr[1] + ";" +
- "font-size:" + getFontSize(node, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles) + ";" +
- "font-family:" + getFontType(node, type, slideMasterTextStyles) + ";" +
- "font-weight:" + getFontBold(node, type, slideMasterTextStyles) + ";" +
- "font-style:" + getFontItalic(node, type, slideMasterTextStyles) + ";" +
- "text-decoration:" + getFontDecoration(node, type, slideMasterTextStyles) + ";" +
- "text-align:" + getTextHorizontalAlign(node, type, slideMasterTextStyles) + ";" +
- "vertical-align:" + getTextVerticalAlign(node, type, slideMasterTextStyles) + ";";
- */
- //}
- }
- }
- else if (i > 0 && bandRowAttr != null && thisTblStyle != null)
- {
- var fillColor = "fff";
- // var colorOpacity = 1;
- if ((i % 2) == 0)
- {
- if (thisTblStyle.GetTextByPath("a:band2H") != null)
- {
- //处理纯色填充
- var bgFillschemeClr = thisTblStyle.GetTextByPath("a:band2H/a:tcStyle/a:fill/a:solidFill");
- if (bgFillschemeClr != null)
- {
- fillColor = ShapeHelper.GetSolidFill(bgFillschemeClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- fillColor = ShapeHelper.ColorToning(bgFillschemeClr.OuterXml, fillColor);
- Fill f = new Fill { color = fillColor, type = 1 };
- //string sha = null;
- //sha = ShaHashHelper.GetSHA1(f.ToJson());
- //warpObj.pptx.Fills.TryAdd(sha, f);
- //tr.FillSha = sha;
-
- tr.fill = f;
- }
- //其他填充 todo
- var fill = thisTblStyle.GetTextByPath("a:band2H/a:tcStyle/a:fill");
- string fillType = ShapeHelper.GetFillType(fill);
- var borderStyl = thisTblStyle.GetTextByPath("a:band2H/a:tcStyle/a:tcBdr");
- if (borderStyl != null)
- {
- List<Border> borders = GetTableBorders(borderStyl, warpObj);
- tr.borders = borders;
- }
- //Text Style - TODO
- //var rowTxtStyl = getTextByPathList(thisTblStyle,["a:band2H", "a:tcTxStyle"]);
- //if (rowTxtStyl !== undefined)
- //{
- //}
- }
- else
- {
- //处理纯色填充
- var bgFillschemeClr = thisTblStyle.GetTextByPath("a:wholeTbl/a:tcStyle/a:fill/a:solidFill");
- if (bgFillschemeClr != null)
- {
- fillColor = ShapeHelper.GetSolidFill(bgFillschemeClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- fillColor = ShapeHelper.ColorToning(bgFillschemeClr.OuterXml, fillColor);
- Fill f = new Fill { color = fillColor, type = 1 };
- //string sha = null;
- //sha = ShaHashHelper.GetSHA1(f.ToJson());
- //warpObj.pptx.Fills.TryAdd(sha, f);
- //tr.FillSha = sha;
- tr.fill = f;
-
- }
- //其他填充 todo
- var fill = thisTblStyle.GetTextByPath("a:wholeTbl/a:tcStyle/a:fill");
- string fillType = ShapeHelper.GetFillType(fill);
- var borderStyl = thisTblStyle.GetTextByPath("a:wholeTbl/a:tcStyle/a:tcBdr");
- if (borderStyl != null)
- {
- List<Border> borders = GetTableBorders(borderStyl, warpObj);
- tr.borders = borders;
- }
- //Text Style - TODO
- //var rowTxtStyl = thisTblStyle["a:wholeTbl"]["a:tcTxStyle"];
- //if (rowTxtStyl !== undefined)
- //{
- //}
- }
- }
- else {
- if (thisTblStyle.GetTextByPath("a:band1H") != null)
- {
- //处理纯色填充
- var bgFillschemeClr = thisTblStyle.GetTextByPath("a:band1H/a:tcStyle/a:fill/a:solidFill");
- if (bgFillschemeClr != null)
- {
- fillColor = ShapeHelper.GetSolidFill(bgFillschemeClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- fillColor = ShapeHelper.ColorToning(bgFillschemeClr.OuterXml, fillColor);
- Fill f = new Fill { color = fillColor, type = 1 };
- //string sha = null;
- //sha = ShaHashHelper.GetSHA1(f.ToJson());
- //warpObj.pptx.Fills.TryAdd(sha, f);
- //tr.FillSha = sha;
- tr.fill = f;
- }
- //其他填充 todo
- var fill = thisTblStyle.GetTextByPath("a:band1H/a:tcStyle/a:fill");
- string fillType = ShapeHelper.GetFillType(fill);
- var borderStyl = thisTblStyle.GetTextByPath("a:band1H/a:tcStyle/a:tcBdr");
- if (borderStyl != null)
- {
- List<Border> borders = GetTableBorders(borderStyl, warpObj);
- tr.borders = borders;
- }
- //Text Style - TODO
- //var rowTxtStyl = getTextByPathList(thisTblStyle,["a:band1H", "a:tcTxStyle"]);
- //if (rowTxtStyl !== undefined)
- //{
- //}
- }
- }
- }
- var tcNodes= trNodes.Item(i).GetTextByPathList("a:tc");
- if (tcNodes != null) {
- int tcSize = tcNodes.Count;
- for (int j = 0; j < tcSize; j++) {
- Td td = new Td();
- List<Paragraph> paragraphs= await GenTextBody(tcNodes.Item(j).GetTextByPath("a:txBody"),node,null,null,null,warpObj);
- var rowSpan = tcNodes.Item(j).GetTextByPath( "@rowSpan");
- var colSpan = tcNodes.Item(j).GetTextByPath("@gridSpan");
- var vMerge = tcNodes.Item(j).GetTextByPath("@vMerge");
- var hMerge = tcNodes.Item(j).GetTextByPath("@hMerge");
- var colWidthParam = getColsGrid.GetTextByPath("@w");
- if (colWidthParam != null) {
- td.width = int.Parse(colWidthParam.Value) * px96 / px914400;
- }
- var getFill = tcNodes.Item(j).GetTextByPath("a:tcPr/a:solidFill");
- string fillColor = "";
- if (getFill != null)
- {
- fillColor = ShapeHelper.GetSolidFill(getFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- fillColor = ShapeHelper.ColorToning(getFill.OuterXml, fillColor);
- Fill f = new Fill { color = fillColor, type = 1 };
- //string sha = null;
- //sha = ShaHashHelper.GetSHA1(f.ToJson());
- //warpObj.pptx.Fills.TryAdd(sha, f);
- //tr.FillSha = sha;
- td.fill = f;
- }
- else {
- //get from Theme (tableStyles.xml) TODO
- //get tableStyleId = a:tbl => a:tblPr => a:tableStyleId
- //var tbleStyleId = getTblPr["a:tableStyleId"];
- //if (tbleStyleId !== undefined)
- //{
- // //get Style from tableStyles.xml by {var tbleStyleId}
- // //table style object : tableStyles
- // var tbleStylList = tableStyles["a:tblStyleLst"]["a:tblStyle"];
- // for (var k = 0; k < tbleStylList.length; k++)
- // {
- // if (tbleStylList[k]["attrs"]["styleId"] == tbleStyleId)
- // {
- // //console.log(tbleStylList[k]);
- // }
- // }
- //}
- }
- //其他填充 todo
- if (rowSpan != null) {
- td.rowspan = int.Parse(rowSpan.Value);
- }
- if (colSpan != null)
- {
- td.colspan = int.Parse(colSpan.Value);
- }
- //
- if (vMerge != null)
- {
- td.vmerge = int.Parse(vMerge.Value);
- }
- if (colSpan != null)
- {
- td.hmerge = int.Parse(colSpan.Value);
- }
- if (rowSpan == null && colSpan == null && vMerge == null && hMerge == null) {
- td.rowspan = 0;
- td.colspan = 0;
- td.hmerge = 0;
- td.vmerge = 0;
- }
- td.paragraphs = paragraphs;
- tr.td.Add(td);
- }
- }
- table.tr.Add(tr);
- }
- }
- return table;
- }
- private List<Border> GetTableBorders(XmlNode node, WarpObj warpObj) {
- List<Border> borders = new List<Border>();
- if (node.GetTextByPath("a:bottom") != null) {
- string xml= "<p:spPr><a:ln>"+ node.GetTextByPath("a:bottom/a:ln").InnerXml + "</p:spPr></a:ln>";
- XmlDocument nodeDoc = new XmlDocument();
- nodeDoc.LoadXml(xml);
- Border border= ShapeHelper.GetBorder(nodeDoc, false, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- border.dir = "bottom";
- //string sha = ShaHashHelper.GetSHA1(border.ToJson());
- //warpObj.pptx.Borders.TryAdd(sha, border);
- borders.Add(border);
- }
- if (node.GetTextByPath("a:top") != null)
- {
- string xml = "<p:spPr><a:ln>" + node.GetTextByPath("a:top/a:ln").InnerXml + "</p:spPr></a:ln>";
- XmlDocument nodeDoc = new XmlDocument();
- nodeDoc.LoadXml(xml);
- Border border = ShapeHelper.GetBorder(nodeDoc, false, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- border.dir = "top";
- //string sha = ShaHashHelper.GetSHA1(border.ToJson());
- //warpObj.pptx.Borders.TryAdd(sha, border);
- borders.Add(border);
- }
- if (node.GetTextByPath("a:right") != null)
- {
- string xml = "<p:spPr><a:ln>" + node.GetTextByPath("a:right/a:ln").InnerXml + "</p:spPr></a:ln>";
- XmlDocument nodeDoc = new XmlDocument();
- nodeDoc.LoadXml(xml);
- Border border = ShapeHelper.GetBorder(nodeDoc, false, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- border.dir = "right";
- //string sha = ShaHashHelper.GetSHA1(border.ToJson());
- //warpObj.pptx.Borders.TryAdd(sha, border);
- borders.Add(border);
- }
- if (node.GetTextByPath("a:left") != null)
- {
- string xml = "<p:spPr><a:ln>" + node.GetTextByPath("a:left/a:ln").InnerXml + "</p:spPr></a:ln>";
- XmlDocument nodeDoc = new XmlDocument();
- nodeDoc.LoadXml(xml);
- Border border = ShapeHelper.GetBorder(nodeDoc, false, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- border.dir = "left";
- //string sha = ShaHashHelper.GetSHA1(border.ToJson());
- //warpObj.pptx.Borders.TryAdd(sha, border);
- borders.Add(border);
- }
- return borders;
- }
- public async Task<Item> ProcessCxnSpNode(XmlNode node, int order, WarpObj warpObj)
- {
- var id = node.GetTextByPath("p:nvCxnSpPr/p:cNvPr/@id");
- var name = node.GetTextByPath("p:nvCxnSpPr/p:cNvPr/@name");
- return await GenShape("CxnSp", node, null, null, id, name, null, null, order, warpObj);
- }
- public async Task<Item> ProcessSpNode(XmlNode node, int order, WarpObj warpObj)
- {
- /*
- * 958 <xsd:complexType name="CT_GvmlShape">
- * 959 <xsd:sequence>
- * 960 <xsd:element name="nvSpPr" type="CT_GvmlShapeNonVisual" minOccurs="1" maxOccurs="1"/>
- * 961 <xsd:element name="spPr" type="CT_ShapeProperties" minOccurs="1" maxOccurs="1"/>
- * 962 <xsd:element name="txSp" type="CT_GvmlTextShape" minOccurs="0" maxOccurs="1"/>
- * 963 <xsd:element name="style" type="CT_ShapeStyle" minOccurs="0" maxOccurs="1"/>
- * 964 <xsd:element name="extLst" type="CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1"/>
- * 965 </xsd:sequence>
- * 966 </xsd:complexType>
- */
- var id = node.GetTextByPath("p:nvSpPr/p:cNvPr/@id");
- var name = node.GetTextByPath("p:nvSpPr/p:cNvPr/@name");
- var idx = node.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@idx");
- var type = node.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@type");
- XmlNode slideLayoutSpNode = ShapeHelper.GetNodesTable(id, idx, type, warpObj, "Layout");
- XmlNode slideMasterSpNode = ShapeHelper.GetNodesTable(id, idx, type, warpObj, "Master");
- if (type == null)
- {
- if (slideLayoutSpNode != null)
- {
- type = slideLayoutSpNode.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@type");
- }
- // type = slideLayoutSpNode.TryGetValue"p:nvSpPr", "p:nvPr", "p:ph", "attrs", "type"]);
- if (type == null)
- {
- if (slideMasterSpNode != null)
- {
- type = slideMasterSpNode.GetTextByPath("p:nvSpPr/p:nvPr/p:ph/@type");
- }
- // type = getTextByPathList(slideMasterSpNode, ["p:nvSpPr", "p:nvPr", "p:ph", "attrs", "type"]);
- }
- }
- Item item = await GenShape("Sp", node, slideLayoutSpNode, slideMasterSpNode, id, name, idx, type, order, warpObj);
- return item;
- }
- public async Task<Item> GenShape(string ShapeType, XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode id, XmlNode name, XmlNode idx, XmlNode type, int order, WarpObj warpObj)
- {
- var xfrmList = "p:spPr/a:xfrm";
- var slideXfrmNode = node.GetTextByPath(xfrmList);
- XmlNode slideLayoutXfrmNode = null;
- if (slideLayoutSpNode != null)
- {
- slideLayoutXfrmNode = slideLayoutSpNode.GetTextByPath(xfrmList);
- }
- XmlNode slideMasterXfrmNode = null;
- if (slideMasterSpNode != null)
- {
- slideMasterXfrmNode = slideMasterSpNode.GetTextByPath(xfrmList);
- }
- if (slideXfrmNode == null)
- {
- slideXfrmNode = slideLayoutXfrmNode;
- }
- if (slideXfrmNode == null)
- {
- slideXfrmNode = slideMasterXfrmNode;
- }
- // var result = "";
- var shapeType = node.GetTextByPath("p:spPr/a:prstGeom/@prst");
- var custShapType = node.GetTextByPath("p:spPr/a:custGeom");
- var isFlipV = 0;
- var isFlipH = 0;
- if (slideXfrmNode.GetTextByPath("@flipV") != null && slideXfrmNode.GetTextByPath("@flipV").Value == "1")
- {// if ( getTextByPathList(slideXfrmNode, ["attrs", "flipV"]) === "1" || getTextByPathList(slideXfrmNode, ["attrs", "flipH"]) === "1")
- isFlipV = 1;
- }
- if (slideXfrmNode.GetTextByPath("@flipH") != null && slideXfrmNode.GetTextByPath("@flipH").Value == "1")
- {
- isFlipH = 1;
- }
- //rotate
- var rotate = ShapeHelper.AngleToDegrees(slideXfrmNode.GetTextByPath("@rot"));
- double txtRotate;
- var txtXframeNode = node.GetTextByPath("p:txXfrm/@rot");
- if (txtXframeNode != null)
- {
- txtRotate = ShapeHelper.AngleToDegrees(txtXframeNode) + 90;
- }
- else
- {
- txtRotate = rotate;
- }
- Position position = ShapeHelper.GetPosition(slideXfrmNode, slideLayoutXfrmNode, slideMasterXfrmNode);
- position.rot = System.Math.Round(rotate,degree);
- position.flipH = isFlipH;
- position.flipV = isFlipV;
- var grndFillFlg = false;
- var imgFillFlg = false;
- var Fill = await GetShapeFill(node, warpObj);
- // Border Color
- var shapeBorder = ShapeHelper.GetBorder(node, true, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- var headEndNodeAttrs = node.GetTextByPath("p:spPr/a:ln/a:headEnd");
- var tailEndNodeAttrs = node.GetTextByPath("p:spPr/a:ln/a:tailEnd");
- Svg shapeSvg = new Svg { id = order + "", /*Width = position.Cx + "", Height = position.Cy + "", Top = position.X + "", Left = position.Y + "", Transform = "rotate(" + position.Rot + "deg)"*/};
- // StringBuilder svgPath = new StringBuilder("<svg class='drawing' _id='" + order + id + "' _idx='" + order + idx + "' _type='" + order + type + "' _name='" + order + name + "'");
- // svgPath.Append(" style='top:" + position.Y + "px;left:" + position.X + "px;width:" + position.Cx + "px;height" + position.Cy + "px;'");
- if (shapeType != null || custShapType != null)
- {
- //result += "<svg class='drawing' _id='" + id + "' _idx='" + idx + "' _type='" + type + "' _name='" + name +
- // "' style='" +
- // getPosition(slideXfrmNode, null, null) +
- // getSize(slideXfrmNode, null, null) +
- // " z-index: " + order + ";" +
- // "transform: rotate(" + rotate + "deg);" +
- // "'>";
- //result += "<defs>";
- // Fill Color
- var clrFillType = ShapeHelper.GetFillType(node.GetTextByPath("p:spPr"));
- /////////////////////////////////////////
- if (Fill.type==2)//== "GRADIENT_FILL"
- {
- grndFillFlg = true;
- var color_arry = Fill.grad;
- var angl = Fill.rot;
- // var svgGrdnt = ShapeHelper.GetSvgGradient(position.Cx, position.Cy, angl, color_arry, order, slideLayoutClrOvride, warpObj.themeContent);
- // shapeSvg.Defs = svgGrdnt;
- //fill="url(#linGrd)"
- // Fill.SvgText = svgGrdnt;
- // result += svgGrdnt;
- }
- else if (Fill.type == 3) //(clrFillType == "PIC_FILL")
- {
- imgFillFlg = true;
- // var svgBgImg = ShapeHelper.GetSvgImagePattern(Fill.Image, order);
- // shapeSvg.Defs = svgBgImg;
- //fill="url(#imgPtrn)"
- // Fill.SvgText = svgBgImg;
- // result += svgBgImg;
- }
- else
- {
- // if (clrFillType != null && clrFillType != "SOLID_FILL" && clrFillType != "PATTERN_FILL")
- if (shapeType != null)
- {
- if (Fill.type != 1 && Fill.type != 4 &&(shapeType.Value == "arc" ||
- shapeType.Value == "bracketPair" ||
- shapeType.Value == "bracePair" ||
- shapeType.Value == "leftBracket" ||
- shapeType.Value == "leftBrace" ||
- shapeType.Value == "rightBrace" ||
- shapeType.Value == "rightBracket"))
- {
- //Fill.HtmlText = "none";
- Fill.color = "none";
- }
- }
- }
- // type: none, triangle, stealth, diamond, oval, arrow
- if ((headEndNodeAttrs != null && (headEndNodeAttrs.GetTextByPath("@type").Value == "triangle" || (headEndNodeAttrs.GetTextByPath("@type").Value == "arrow")) ||
- (tailEndNodeAttrs != null && (tailEndNodeAttrs.GetTextByPath("@type").Value == "triangle" || (tailEndNodeAttrs.GetTextByPath("@type").Value == "arrow")))))
- {
- // var triangleMarker = "<marker id='markerTriangle_" + order + "' viewBox='0 0 10 10' refX='1' refY='5' markerWidth='5' markerHeight='5' stroke='" + shapeBorder.Color + "' fill='" + shapeBorder.Color +
- // "' orient='auto-start-reverse' markerUnits='strokeWidth'><path d='M 0 0 L 10 5 L 0 10 z' /></marker>";
- // shapeSvg.Defs = triangleMarker;
- // result += triangleMarker;
- }
- // result += "</defs>";
- }
- if (shapeType != null && custShapType == null)
- {
- Svg svg = ShapeSvg.GenShapeSvg(node, order, shapeType, isFlipV, position, grndFillFlg, imgFillFlg, Fill, shapeBorder, headEndNodeAttrs, tailEndNodeAttrs);
- shapeSvg.svgShape = svg.svgShape;
- // shapeSvg.SvgData = svg.SvgData;
- if (ShapeType.Equals("Sp"))
- {
- Shape shape = new Shape { border = shapeBorder, svg = shapeSvg, type = "Sp", position = position, index = order, shapeType = shapeType.Value };
- //if (shapeBorder != null&& shapeBorder.Type!=null)
- //{
-
- // shape.BorderSha = ShaHashHelper.GetSHA1(shapeBorder.ToJson());
- // warpObj.pptx.Borders.TryAdd(shape.BorderSha, shapeBorder);
- //}
- if (Fill.type == 0)
- {
- shape.fill = null;
- }
- else {
- //string sha = null;
- //sha = ShaHashHelper.GetSHA1(Fill.ToJson());
- //warpObj.pptx.Fills.TryAdd(sha, Fill);
- //shape.FillSha = sha;
- shape.fill = Fill;
- }
- var txbody = node.GetTextByPath("p:txBody");
- if (txbody != null)
- {
- List<Paragraph> paragraphs = await GenTextBody(txbody, node, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
- shape.paragraph = paragraphs;
- }
- return shape;
- }
- else if (ShapeType.Equals("CxnSp"))
- {
- string bdsha = null;
- //if (shapeBorder != null && shapeBorder.Type != null)
- //{
- // bdsha = ShaHashHelper.GetSHA1(shapeBorder.ToJson());
- // warpObj.pptx.Borders.TryAdd(bdsha, shapeBorder);
- //}
- return new Connector { border = shapeBorder, svg = shapeSvg, type = "CxnSp", position = position, index = order, cxnType = shapeType.Value };
- }
- else {
- return null;
- }
- }
- else if (custShapType != null)
- {
- XmlNode pathLstNode = custShapType.GetTextByPath("a:pathLst");
- //XmlNode pathNode = pathLstNode.GetTextByPath("a:path");
- //var maxX = 0.0;
- //var maxY = 0.0;
- //if (pathLstNode != null)
- //{
- // maxX = double.Parse(pathNode.GetTextByPath("@w").Value) * px96 / px914400;
- // maxY = double.Parse(pathNode.GetTextByPath("@h").Value) * px96 / px914400;
- //}
- var closeNode = pathLstNode.GetTextByPath("a:path/a:close");
- var startPoint = pathLstNode.GetTextByPath("a:path/a:moveTo/a:pt");
- var spX = 96.0;
- var spY = 96.0;
- if (startPoint != null)
- {
- spX = System.Math.Round(double.Parse(startPoint.GetTextByPath("@x").Value) * 96 / 914400,degree);
- spY = System.Math.Round(double.Parse(startPoint.GetTextByPath("@y").Value) * 96 / 914400,degree);
- }
- var d = "M" + spX + "," + spY;
- // List<TEAMModelOS.Service.Model.PowerPoint.Path> Paths = new List<Model.PowerPoint.Path>();
- XmlNodeList pathChildNodes = pathLstNode.GetTextByPath("a:path").ChildNodes;
- foreach (XmlNode childNode in pathChildNodes)
- {
- if (childNode.Name.Equals("a:lnTo"))
- {
- XmlNodeList nodeList = childNode.ChildNodes;
- var Lx = double.Parse(nodeList.Item(0).GetTextByPath("@x").Value) * px96 / px914400;
- var Ly = double.Parse(nodeList.Item(0).GetTextByPath("@y").Value) * px96 / px914400;
- //Paths.Add(new LineToPath
- //{
- // Lx = double.Parse(Lx.Value) * px96 / px914400,
- // Ly = double.Parse(Lx.Value) * px96 / px914400,
- //});
- d += " L" + System.Math.Round(Lx,degree) + "," + System.Math.Round(Ly,degree);
- }
- if (childNode.Name.Equals("a:cubicBezTo"))
- {
- XmlNodeList nodeList = childNode.ChildNodes;
- var Cx1 = double.Parse(nodeList.Item(0).GetTextByPath("@x").Value) * px96 / px914400;
- var Cy1 = double.Parse(nodeList.Item(0).GetTextByPath("@y").Value) * px96 / px914400;
- var Cx2 = double.Parse(nodeList.Item(1).GetTextByPath("@x").Value) * px96 / px914400;
- var Cy2 = double.Parse(nodeList.Item(1).GetTextByPath("@y").Value) * px96 / px914400;
- var Cx3 = double.Parse(nodeList.Item(2).GetTextByPath("@x").Value) * px96 / px914400;
- var Cy3 = double.Parse(nodeList.Item(2).GetTextByPath("@y").Value) * px96 / px914400;
- //Paths.Add( new CubicBezPath
- // {
- // Cx1 = double.Parse(Cx1.Value) * px96 / px914400,
- // Cy1 = double.Parse(Cy1.Value) * px96 / px914400,
- // Cx2 = double.Parse(Cx2.Value) * px96 / px914400,
- // Cy2 = double.Parse(Cy2.Value) * px96 / px914400,
- // Cx3 = double.Parse(Cx3.Value) * px96 / px914400,
- // Cy3 = double.Parse(Cy3.Value) * px96 / px914400
- // });
- d += " C" + System.Math.Round(Cx1,degree) + "," + System.Math.Round(Cy1,degree) + " " + System.Math.Round(Cx2,degree) + "," + System.Math.Round(Cy2,degree) + " " + System.Math.Round(Cx3,degree) + "," + System.Math.Round(Cy3,degree);
- }
- if (childNode.Name.Equals("a:quadBezTo"))
- {
- //http://cw.hubwiz.com/card/c/5636b7041bc20c980538e995/1/4/4/
- XmlNodeList nodeList = childNode.ChildNodes;
- var Cx1 = double.Parse(nodeList.Item(0).GetTextByPath("@x").Value) * px96 / px914400;
- var Cy1 = double.Parse(nodeList.Item(0).GetTextByPath("@y").Value) * px96 / px914400;
- var Cx2 = double.Parse(nodeList.Item(1).GetTextByPath("@x").Value) * px96 / px914400;
- var Cy2 = double.Parse(nodeList.Item(1).GetTextByPath("@y").Value) * px96 / px914400;
- //Paths.Add(new QuadBezPath
- //{
- // Cx1 = double.Parse(Cx1.Value) * px96 / px914400,
- // Cy1 = double.Parse(Cy1.Value) * px96 / px914400,
- // Cx2 = double.Parse(Cx2.Value) * px96 / px914400,
- // Cy2 = double.Parse(Cy2.Value) * px96 / px914400
- //});
- d += " Q" + System.Math.Round(Cx1,degree) + "," + System.Math.Round(Cy1,degree) + " " + System.Math.Round(Cx2,degree) + "," + System.Math.Round(Cy2,degree);
- }
- if (childNode.Name.Equals("a:arcTo"))
- {
-
-
- var wR = double.Parse(childNode.GetTextByPath("@wR").Value) * px96 / px914400;
- var hR = double.Parse(childNode.GetTextByPath("@hR").Value) * px96 / px914400;
- var stAng = double.Parse(childNode.GetTextByPath("@stAng").Value) * px96 / px914400;
- var swAng = double.Parse(childNode.GetTextByPath("@swAng").Value) * px96 / px914400;
- var endAng = stAng + swAng;
- d += ShapeSvg.ShapeArc(wR, hR, wR, hR, stAng, endAng, false);
- //Paths.Add(new ArcToPath() {
- // WidthRadius = double.Parse(wR.Value) * px96 / px914400,
- // HeightRadius = double.Parse(hR.Value) * px96 / px914400,
- // StartAngle = double.Parse(stAng.Value) * px96 / px914400,
- // SwingAngle = double.Parse(swAng.Value) * px96 / px914400
- //});
- }
- }
- //if (headEndNodeAttrs != null && (headEndNodeAttrs.GetTextByPath("@type").Value == "triangle" || headEndNodeAttrs.GetTextByPath("@type").Value == "arrow"))
- //{
- // result += "marker-start='url(#markerTriangle_" + order + ")' ";
- //}
- //if (tailEndNodeAttrs != null && (tailEndNodeAttrs.GetTextByPath("@type").Value == "triangle" || tailEndNodeAttrs.GetTextByPath("@type").Value == "arrow"))
- //{
- // result += "marker-end='url(#markerTriangle_" + order + ")' ";
- //}
- //是否关闭svg
- if (closeNode != null) {
- d += " z";
- }
- List<SvgShape> shapes = new List<SvgShape>() {
- new SvgPath {
- type = "path",
- // Fill = (!imgFillFlg ? (grndFillFlg ? "url(#linGrd_" + order + ")" : Fill.Color) : "url(#imgPtrn_" + order + ")"),
- //Stroke = "#" + shapeBorder.Color,
- //StrokeWidth = shapeBorder.Width + "",
- //StrokeDasharray = shapeBorder.Stroke,
- d=d,
- start=headEndNodeAttrs!=null?headEndNodeAttrs.GetTextByPath("@type").Value:null,
- end=tailEndNodeAttrs!=null?tailEndNodeAttrs.GetTextByPath("@type").Value:null,
- }
- };
- shapeSvg.svgShape = shapes;
- // shapeSvg.SvgData = result;
- Shape shape = new Shape { border = shapeBorder, svg = shapeSvg, type = "Sp", position = position, index = order, shapeType = "custom" };
- //if (shapeBorder != null && shapeBorder.Type != null)
- //{
- // shape.BorderSha = ShaHashHelper.GetSHA1(shapeBorder.ToJson());
- // warpObj.pptx.Borders.TryAdd(shape.BorderSha, shapeBorder);
- //}
- if (Fill.type == 0)
- {
- shape.fill = null;
- }
- else
- {
- //string sha = null;
- //sha = ShaHashHelper.GetSHA1(Fill.ToJson());
- //warpObj.pptx.Fills.TryAdd(sha, Fill);
- //shape.FillSha = sha;
- shape.fill = Fill;
- }
- var txbody = node.GetTextByPath("p:txBody");
- if (txbody != null)
- {
- List<Paragraph> paragraphs = await GenTextBody(txbody, node, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
- shape.paragraph = paragraphs;
- }
- return shape;
- }
- else
- {
-
- Shape shape = new Shape { border = shapeBorder, svg = shapeSvg, type = "Sp", position = position, index = order, shapeType = "rect" };
- //if (shapeBorder != null && shapeBorder.Type != null)
- //{
- // shape.BorderSha = ShaHashHelper.GetSHA1(shapeBorder.ToJson());
- // warpObj.pptx.Borders.TryAdd(shape.BorderSha, shapeBorder);
- //}
- if (Fill.type == 0)
- {
- shape.fill = null;
- }
- else
- {
- //string sha = null;
- //sha = ShaHashHelper.GetSHA1(Fill.ToJson());
- //warpObj.pptx.Fills.TryAdd(sha, Fill);
- //shape.FillSha = sha;
-
- shape.fill = Fill;
- }
- var txbody = node.GetTextByPath("p:txBody");
- if (txbody != null)
- {
- List<Paragraph> paragraphs = await GenTextBody(txbody, node, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
- shape.paragraph = paragraphs;
- }
- return shape;
- }
-
- }
- private async Task<List<Paragraph>> GenTextBody(XmlNode textBodyNode, XmlNode spNode, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, WarpObj warpObj)
- {
- List<Paragraph> paragraphs = new List<Paragraph>();
- var slideMasterTextStyles = warpObj.slideMasterTextStyles;
- string VertAlign = GetVerticalAlign(spNode, slideLayoutSpNode, slideMasterSpNode);
- string WritingMode = GetWritingMode(spNode, slideLayoutSpNode, slideMasterSpNode);
- var ps = textBodyNode.GetTextByPathList("a:p");
- if (ps != null)
- {
- foreach (XmlNode pNode in ps)
- {
- BuChar buChar = await GenBuChar(pNode, spNode, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
- if (buChar != null && (buChar.buchar == null || buChar.buchar.Equals("TYPE_NONE"))) {
- buChar = null;
- }
- //string bucharsha = null;
- //if (buChar != null) {
- // bucharsha = ShaHashHelper.GetSHA1(buChar.ToJson());
- // warpObj.pptx.BuChars.TryAdd(bucharsha, buChar);
- //}
- string HoriAlign = GetHorizontalAlign(pNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles);
-
- ParagraphStyle paragraphStyle = new ParagraphStyle
- {
- hori= HoriAlign,
- writing = WritingMode,
- vert = VertAlign
- };
- //sha = ShaHashHelper.GetSHA1(paragraphStyle.ToJson());
- //warpObj.pptx.ParagraphStyles.TryAdd(sha, paragraphStyle);
- Paragraph paragraph = new Paragraph
- {
- buChar = buChar,
- style = paragraphStyle,
- //StyleSha = sha,
- //BuCharSha= bucharsha
- };
- var rNode = pNode.GetTextByPathList("a:r");
- if (rNode == null)
- {
- Text text = GenSpanElement(pNode, spNode, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
- if (pNode.GetTextByPath("a:br") != null)
- {
- text.isbr = true;
- }
- List<Text> texts = new List<Text> { text };
- paragraph.texts = texts;
- }
- else
- {
- List<Text> texts = new List<Text>();
- foreach (XmlNode node in rNode)
- {
- Text text = GenSpanElement(node, spNode, slideLayoutSpNode, slideMasterSpNode, type, warpObj);
- if (pNode.GetTextByPath("a:br") != null)
- {
- text.isbr = true;
- }
- texts.Add(text);
- }
- paragraph.texts = texts;
- }
- paragraphs.Add(paragraph);
- }
- }
- return paragraphs;
- }
- private Text GenSpanElement(XmlNode node, XmlNode spNode, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, WarpObj warpObj)
- {
- string text;
- var slideMasterTextStyles = warpObj.slideMasterTextStyles;
- var textNode = node.GetTextByPath("a:t");
- if (textNode == null)
- {
- textNode = node.GetTextByPath("a:fld/a:t");
- if (textNode == null)
- {
- text = " ";
- }
- else
- {
- text = textNode.InnerText;
- }
- }
- else
- {
- text = textNode.InnerText;
- }
- var fontClrPr = GetFontColorPr(node, spNode, type, slideMasterTextStyles, warpObj.slideMasterContent, warpObj.themeContent);
- string color = fontClrPr.color;
- string text_shadow = fontClrPr.textBordr;
- double font_size = GetFontSize(node, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles);
- string font_family = GetFontType(node, type, slideMasterTextStyles, warpObj.themeContent);
- string font_weight = GetFontBold(node, type, slideMasterTextStyles);
- string font_style = GetFontItalic(node, type, slideMasterTextStyles);
- string text_decoration = GetFontDecoration(node, type, slideMasterTextStyles);
- string text_align = GetTextHorizontalAlign(node, type, slideMasterTextStyles);
- string vertical_align = GetTextVerticalAlign(node, type, slideMasterTextStyles);
- //var styleText =
- // "color:" + color + ";" +
- // "text-shadow:" + text_shadow + ";" +
- // "font-size:" + font_size + ";" +
- // "font-family:" + font_family + ";" +
- // "font-weight:" + font_weight + ";" +
- // "font-style:" + font_style + ";" +
- // "text-decoration:" + text_decoration + ";" +
- // "text-align:" + text_align + ";" +
- // "vertical-align:" + vertical_align + ";";
- //string cssName = "";
- //if (styleTable.TryGetValue(styleText, out Dictionary<string, string> css))
- //{
- // cssName = css["name"];
- //}
- //else
- //{
- // cssName = "_css_" + (styleTable.Keys.Count + 1);
- // styleTable.TryAdd(styleText, new Dictionary<string, string> { { "name", cssName }, { "text", styleText } });
- //}
- var linkID = node.GetTextByPath("a:rPr/a:hlinkClick/@r:id");
- string linkURL = null;
- if (linkID != null)
- {
- linkURL = warpObj.slideResObj[linkID.Value]["target"];
- }
- FontStyle fontStyle = new FontStyle
- {
- color = color,
- size = font_size,
- family = font_family,
- weight = font_weight,
- style = font_style,
- decoration = text_decoration,
- vertAlign = vertical_align,
- align = text_align,
- shadow = text_shadow
- };
- //string styleSha = ShaHashHelper.GetSHA1(fontStyle.ToJson());
- //warpObj.pptx.FontStyles.TryAdd(styleSha, fontStyle);
- return new Text
- {
- content = text,
- href = linkURL,
- style=fontStyle
- //StyleSha = styleSha
- };
- }
- private string GetTextVerticalAlign(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles)
- {
- var baseline = node.GetTextByPath("a:rPr/@baseline");
- if (baseline != null)
- {
- return double.Parse(baseline.Value) / 1000.0 + "%";
- }
- else
- {
- return "baseline";
- }
- }
- private string GetTextHorizontalAlign(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles)
- {
- var getAlgn = node.GetTextByPath("a:pPr/@algn");
- var align = "initial";
- if (getAlgn != null)
- {
- switch (getAlgn.Value)
- {
- case "l":
- align = "left";
- break;
- case "r":
- align = "right";
- break;
- case "ctr":
- align = "center";
- break;
- case "just":
- align = "justify";
- break;
- case "dist":
- align = "justify";
- break;
- default:
- align = "initial";
- break;
- }
- }
- return align;
- }
- private string GetFontDecoration(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles)
- {
- if (node.GetTextByPath("a:rPr") != null)
- {
- var FontDecor = node.GetTextByPath("a:rPr/@u");
- var underLine = FontDecor != null ? FontDecor.Value : "none";
- var FontStrik = node.GetTextByPath("a:rPr/@strike");
- var strikethrough = FontStrik != null ? FontStrik.Value : "noStrike";
- if (underLine != "none" && strikethrough == "noStrike")
- {
- return "underline";
- }
- else if (underLine == "none" && strikethrough != "noStrike")
- {
- return "line-through";
- }
- else if (underLine != "none" && strikethrough != "noStrike")
- {
- return "underline line-through";
- }
- else
- {
- return "initial";
- }
- }
- else
- {
- return "initial";
- }
- }
- private string GetFontItalic(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles)
- {
- var FontBold = node.GetTextByPath("a:rPr/@i");
- if (FontBold != null)
- {
- if (FontBold.Value.Equals("1"))
- {
- return "italic";
- }
- else
- {
- return "normal";
- }
- }
- else
- {
- return "normal";
- }
- }
- private string GetFontBold(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles)
- {
- var FontBold = node.GetTextByPath("a:rPr/@b");
- if (FontBold != null)
- {
- if (FontBold.Value.Equals("1"))
- {
- return "bold";
- }
- else
- {
- return "initial";
- }
- }
- else
- {
- return "initial";
- }
- }
- private string GetFontType(XmlNode node, XmlNode type, XmlNode slideMasterTextStyles, XmlNode themeContent)
- {
- string typeface = "inherit";
- XmlNode typefaceNode = node.GetTextByPath("a:rPr/a:latin/@typeface");
- if (typefaceNode == null)
- {
- var fontSchemeNode = themeContent.GetTextByPath("a:theme/a:themeElements/a:fontScheme");
- if (type != null && fontSchemeNode != null && (type.Value == "title" || type.Value == "subTitle" || type.Value == "ctrTitle"))
- {
- typefaceNode = fontSchemeNode.GetTextByPath("a:majorFont/a:latin/@typeface");
- }
- else if (type != null && fontSchemeNode != null && type.Value == "body")
- {
- typefaceNode = fontSchemeNode.GetTextByPath("a:minorFont/a:latin/@typeface");
- }
- else if(fontSchemeNode!=null)
- {
- typefaceNode = fontSchemeNode.GetTextByPath("a:minorFont/a:latin/@typeface");
- }
- }
- if (typefaceNode != null)
- {
- typeface = typefaceNode.Value;
- }
- return typeface;
- }
- private async Task<BuChar> GenBuChar(XmlNode node, XmlNode spNode, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, WarpObj warpObj)
- {
- var sldMstrTxtStyles = warpObj.slideMasterTextStyles;
- var slideMasterContent = warpObj.slideMasterContent;
- var themeContent = warpObj.themeContent;
- var rNodes = node.GetTextByPathList("a:r");
- XmlNode rNode = null;
- if (rNodes != null)
- {
- rNode = rNodes[0];
- }
- dynamic dfltBultColor;
- double dfltBultSize;
- if (rNode != null)
- {
- dfltBultColor = GetFontColorPr(rNode, spNode, type, sldMstrTxtStyles, slideMasterContent, themeContent);
- dfltBultSize = GetFontSize(rNode, slideLayoutSpNode, slideMasterSpNode, type, sldMstrTxtStyles);
- }
- else
- {
- dfltBultColor = GetFontColorPr(node, spNode, type, sldMstrTxtStyles, slideMasterContent, themeContent);
- dfltBultSize = GetFontSize(node, slideLayoutSpNode, slideMasterSpNode, type, sldMstrTxtStyles);
- }
- var bullet = "";
- var pPrNode = node.GetTextByPath("a:pPr");
- var getRtlVal = node.GetTextByPath("a:pPr/@rtl");
- var isRTL = false;
- if (getRtlVal != null && getRtlVal.Equals("1"))
- {
- isRTL = true;
- }
- int lvl = 0;
- if (node.GetTextByPath("a:pPr/@lvl") != null)
- {
- lvl = int.Parse(node.GetTextByPath("a:pPr/@lvl").Value);
- }
- XmlNode buNum = null;
- XmlNode buPic = null;
- XmlNode buCharNode = null;
- XmlNode buClrNode = null;
- if (pPrNode != null) {
- buCharNode = pPrNode.GetTextByPath("a:buChar/@char");
- buNum = pPrNode.GetTextByPath("a:buAutoNum/@type");
- buPic = pPrNode.GetTextByPath("a:buBlip");
- buClrNode= pPrNode.GetTextByPath("a:buClr");
- }
- string buChar = "";
- var buType = "TYPE_NONE";
- if (buCharNode != null)
- {
- buChar = buCharNode.Value;
- buType = "TYPE_BULLET";
- }
- if (buNum != null)
- {
- buType = "TYPE_NUMERIC";
- }
- if (buPic != null)
- {
- buType = "TYPE_BULPIC";
- }
- XmlNode buFontAttrs = null;
- if (buType != "TYPE_NONE" && pPrNode!=null)
- {
- buFontAttrs = pPrNode.GetTextByPath("a:buFont");
- }
-
- var defBultColor = "NoNe";
- string bultColor;
- if (buClrNode != null)
- {
- defBultColor = ShapeHelper.GetSolidFill(buClrNode, slideLayoutClrOvride, slideMasterContent, themeContent);
- }
- else
- {
- }
- if (defBultColor == "NoNe")
- {
- bultColor = dfltBultColor.color;
- }
- else
- {
- bultColor = "#" + defBultColor;
- }
- double bultSize;
- XmlNode buVal=null;
- if (pPrNode != null) {
- buVal = pPrNode.GetTextByPath("a:buSzPts/@val"); //pt
- }
-
- if (buVal != null)
- {
- bultSize = int.Parse(buVal.Value) / 100;
- }
- else
- {
- if (pPrNode != null)
- {
- buVal = pPrNode.GetTextByPath("a:buSzPct/@val");
- }
- if (buVal != null)
- {
- var prcnt = int.Parse(buVal.Value) / 100000.0;
- //dfltBultSize = XXpt
- var dfltBultSizeNoPt = dfltBultSize;
- //pt
- bultSize = prcnt * (dfltBultSizeNoPt);
- }
- else
- {
- bultSize = dfltBultSize;
- }
- }
- double marginLeft = 0;
- double marginRight = 0;
- string typeface = "";
- string Float = "left";
- string Direction = "inherit";
- BuChar BuChar = null;
- if (buType == "TYPE_BULLET")
- {
- if (buFontAttrs != null)
- {
- XmlNode marl = null;
- if (pPrNode != null)
- {
- marl = pPrNode.GetTextByPath("@marL");
- }
-
- if (marl != null)
- {
- marginLeft = int.Parse(marl.Value) * px96 / px914400;
- if (buFontAttrs.GetTextByPath("@pitchFamily") != null)
- {
- marginRight = int.Parse(buFontAttrs.GetTextByPath("@pitchFamily").Value);
- }
- if (marginLeft == 0)
- {
- marginLeft = 328600 * px96 / px914400;
- }
- var typefaceNode = buFontAttrs.GetTextByPath("@typeface");
- if (typefaceNode != null)
- {
- typeface = typefaceNode.Value;
- }
- if (isRTL)
- {
- Float = "right";
- Direction = "rtl";
- }
- marginLeft = marginLeft * lvl;
- }
- }
- else
- {
- marginLeft = 328600 * px96 / px914400 * lvl;
- }
- BuChar = new BuChar
- {
- typeface = typeface,
- left = marginLeft,
- riht = marginRight,
- size = bultSize,
- buchar = buChar,
- @float = Float,
- direction = Direction,
- type = "TYPE_BULLET"
- };
- }
- else if (buType == "TYPE_NUMERIC")
- {
- if (buFontAttrs != null)
- {
- XmlNode marl = null;
- if (pPrNode != null)
- {
- marl = pPrNode.GetTextByPath("@marL");
- }
- if (marl != null)
- {
- marginLeft = int.Parse(marl.Value) * px96 / px914400;
- if (buFontAttrs.GetTextByPath("@pitchFamily") != null)
- {
- marginRight = int.Parse(buFontAttrs.GetTextByPath("@pitchFamily").Value);
- }
- if (marginLeft == 0)
- {
- marginLeft = 328600 * px96 / px914400;
- }
- var typefaceNode = buFontAttrs.GetTextByPath("@typeface");
- if (typefaceNode != null)
- {
- typeface = typefaceNode.Value;
- }
- else
- {
- typeface = "inherit";
- }
- if (isRTL)
- {
- Float = "right";
- Direction = "rtl";
- }
- else
- {
- Float = "left";
- Direction = "ltr";
- }
- marginLeft = marginLeft * lvl;
- }
- }
- else
- {
- marginLeft = 328600 * 96 / 914400 * lvl;
- if (isRTL)
- {
- Float = "right";
- Direction = "rtl";
- }
- else
- {
- Float = "left";
- Direction = "ltr";
- }
- BuChar = new BuChar
- {
- typeface = typeface,
- left = marginLeft,
- riht = marginRight,
- size = bultSize,
- buchar = buChar,
- @float = Float,
- direction = Direction,
- type = "TYPE_NUMERIC"
- };
- }
- }
- else if (buType == "TYPE_BULPIC")
- {
- XmlNode marl = null;
- if (pPrNode != null)
- {
- marl = pPrNode.GetTextByPath("@marL");
- }
-
- if (marl != null)
- {
- marginLeft = int.Parse(marl.Value) * px96 / px914400;
- }
- else
- {
- marginLeft = 328600 * px96 / px914400;
- }
- XmlNode marR = null;
- if (pPrNode != null)
- {
- marR = pPrNode.GetTextByPath("@marR");
- }
-
- if (marR != null)
- {
- marginRight = int.Parse(marR.Value) * px96 / px914400;
- }
- var buPicId = buPic.GetTextByPath("a:blip/@r:embed");
- var buImg = "";
- if (buPicId != null)
- {
- var imgPath = warpObj.slideResObj[buPicId.Value];
- var imgData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + imgPath["target"] + "']");
- if (imgData != null)
- {
- var imgFileExt = imgData.GetTextByPath("@pkg:contentType");
- AzureBlobModel imgModel = await SaveBase64ToBolob(imgData.InnerText, imgFileExt.Value, fileShaCode + "/imgs", "");
- buImg = imgModel.BlobUrl;
- }
- }
- else
- {
- buImg = "‣";
- }
- if (isRTL)
- {
- Float = "right";
- Direction = "rtl";
- }
- marginLeft = marginLeft * lvl;
- BuChar = new BuChar
- {
- typeface = typeface,
- left = marginLeft,
- riht = marginRight,
- size = bultSize,
- buchar = buImg,
- @float = Float,
- direction = Direction,
- type = "TYPE_NUMERIC"
- };
- }
- else
- {
- if (isRTL)
- {
- Float = "right";
- Direction = "rtl";
- }
- BuChar = new BuChar
- {
- typeface = typeface,
- left = 328600 * px96 / px914400 * lvl,
- riht = marginRight,
- size = bultSize,
- @float = Float,
- direction = Direction,
- type = "TYPE_NONE"
- };
- }
- return BuChar;
- }
- private double GetFontSize(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode, XmlNode type, XmlNode slideMasterTextStyles)
- {
- double fontSize = 0;
- if (node.GetTextByPath("a:rPr/@sz") != null)
- {
- fontSize = int.Parse(node.GetTextByPath("a:rPr/@sz").Value) / 100.0;
- }
- if (fontSize == 0)
- {
- if (slideLayoutSpNode != null) {
- var sz = slideLayoutSpNode.GetTextByPath("p:txBody/a:lstStyle/a:lvl1pPr/a:defRPr/@sz");
- if (sz != null)
- {
- fontSize = int.Parse(sz.Value) / 100.0;
- }
- }
-
- }
- XmlNode size = null;
- if (fontSize == 0)
- {
- if (type == null) {
- size = slideMasterTextStyles.GetTextByPath("p:otherStyle/a:lvl1pPr/a:defRPr/@sz");
- }
- else if (type.Value.Equals("title") || type.Value.Equals("subTitle") || type.Value.Equals("ctrTitle"))
- {
- size = slideMasterTextStyles.GetTextByPath("p:titleStyle/a:lvl1pPr/a:defRPr/@sz");
- }
- else if (type.Value.Equals("body"))
- {
- size = slideMasterTextStyles.GetTextByPath("p:bodyStyle/a:lvl1pPr/a:defRPr/@sz");
- }
- else if (type.Value.Equals("dt") || type.Value.Equals("sldNum"))
- {
- fontSize = 12;
- }
- if (size != null)
- {
- fontSize = int.Parse(size.Value) / 100.0;
- }
- }
- var baseline = node.GetTextByPath("a:rPr/@baseline");
- if (baseline != null && fontSize != 0)
- {
- fontSize -= 10;
- }
- //return isNaN(fontSize) ? "inherit" : (fontSize + "pt");
- //如果fontSize为0 则 使用inherit 继承方式
- return fontSize;
- }
- private dynamic GetFontColorPr(XmlNode node, XmlNode spNode, XmlNode type, XmlNode sldMstrTxtStyles, XmlNode slideMasterContent, XmlNode themeContent)
- {
- var rPrNode = node.GetTextByPath("a:rPr");
- string filTyp, textBordr;
- string color = null;
- if (rPrNode != null)
- {
- filTyp = ShapeHelper.GetFillType(rPrNode);
- if (filTyp == "SOLID_FILL")
- {
- var solidFillNode = node.GetTextByPath("a:rPr/a:solidFill");
- string colorstr = ShapeHelper.GetSolidFill(solidFillNode, slideLayoutClrOvride, slideMasterContent, themeContent);
- if (solidFillNode!=null) {
- color = ShapeHelper.ColorToning(solidFillNode.OuterXml, colorstr);
- }
- }
- else if (filTyp == "PATTERN_FILL")
- {
- var pattFill = node.GetTextByPath("a:rPr/a:pattFill");
- Fill colorFill = ShapeHelper.GetPatternFill(pattFill, slideLayoutClrOvride, slideMasterContent, themeContent);
- if (colorFill != null && colorFill.grad.IsNotEmpty())
- {
- color = colorFill.grad[0];
- }
- else
- {
- color = "000000";
- }
- }
- else
- {
- if (spNode != null) {
- var sPstyle = spNode.GetTextByPath("p:style/a:fontRef");
- if (sPstyle != null)
- {
- string colorstr = ShapeHelper.GetSolidFill(sPstyle, slideLayoutClrOvride, slideMasterContent, themeContent);
- color = ShapeHelper.ColorToning(sPstyle.OuterXml, colorstr);
- }
- }
- }
- }
- if (color == null)
- {
- color = "000000";
- }
- var txtBrdrNode = node.GetTextByPath("a:rPr/a:ln");
- if (txtBrdrNode != null)
- {
- var txBrd = ShapeHelper.GetBorder(node, true, "text", slideLayoutClrOvride, slideMasterContent, themeContent);
- var brdSize = System.Math.Round(txBrd.width * (4 / 3.00),degree) + "px";
- var brdClr = txBrd.color;
- textBordr = "-" + brdSize + " 0 " + brdClr + ", 0 " + brdSize + " " + brdClr + ", " + brdSize + " 0 " + brdClr + ", 0 -" + brdSize + " " + brdClr + ";";
- }
- else
- {
- textBordr = "none";
- }
- return new { color, textBordr };
- }
- public string GetVerticalAlign(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode)
- {
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(node.OuterXml);
- XmlNode anchor = doc.GetTextByPath("//p:txBody/a:bodyPr/@anchor");
- if (anchor == null)
- {
- if (slideLayoutSpNode != null)
- {
- doc.LoadXml(slideLayoutSpNode.OuterXml);
- anchor = doc.GetTextByPath("//p:txBody/a:bodyPr/@anchor");
- }
- if (anchor == null && slideMasterSpNode != null)
- {
- doc.LoadXml(slideMasterSpNode.OuterXml);
- anchor = doc.GetTextByPath("//p:txBody/a:bodyPr/@anchor");
- }
- }
- if (anchor != null)
- {
- return anchor.Value.Equals("ctr") ? "v-mid" : anchor.Value.Equals("b") ? "v-down" : "v-up";
- }
- else
- {
- return "v-up";
- }
- }
- public string GetWritingMode(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode)
- {
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(node.OuterXml);
- XmlNode vert = doc.GetTextByPath("//p:txBody/a:bodyPr/@vert");
- if (vert == null)
- {
- if (slideLayoutSpNode != null)
- {
- doc.LoadXml(slideLayoutSpNode.OuterXml);
- vert = doc.GetTextByPath("//p:txBody/a:bodyPr/@vert");
- }
- if (vert == null && slideMasterSpNode != null)
- {
- doc.LoadXml(slideMasterSpNode.OuterXml);
- vert = doc.GetTextByPath("//p:txBody/a:bodyPr/@vert");
- }
- }
- if (vert != null)
- {
- return vert.Value;
- }
- else
- {
- return "horz";
- }
- }
-
- public string GetHorizontalAlign(XmlNode node, XmlNode slideLayoutSpNode, XmlNode slideMasterSpNode,
- XmlNode typeNode, XmlNode slideMasterTextStyles)
- {
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(node.OuterXml);
- XmlNode algn = doc.GetTextByPath("//a:pPr/@algn");
- if (algn == null)
- {
- if (slideLayoutSpNode != null)
- {
- doc.LoadXml(slideLayoutSpNode.OuterXml);
- algn = doc.GetTextByPath("//p:txBody/a:p/a:pPr/@algn");
- }
- if (algn == null && slideMasterSpNode != null)
- {
- doc.LoadXml(slideMasterSpNode.OuterXml);
- algn = doc.GetTextByPath("//p:txBody/a:p/a:pPr/@algn");
- }
- if (algn == null && typeNode != null)
- {
- switch (typeNode.Value)
- {
- case "title":
- case "subTitle":
- case "ctrTitle":
- //doc.LoadXml(slideMasterStyle.TypeTable.OuterXml);
- doc.LoadXml(slideMasterTextStyles.OuterXml);
- algn = doc.GetTextByPath("//p:titleStyle/a:lvl1pPr/@algn");
- break;
- case "body":
- doc.LoadXml(slideMasterTextStyles.OuterXml);
- algn = doc.GetTextByPath("//p:bodyStyle/a:lvl1pPr/@algn");
- break;
- default:
- // doc.LoadXml(slideMasterStyle.TypeTable.OuterXml);
- doc.LoadXml(slideMasterTextStyles.OuterXml);
- algn = doc.GetTextByPath("//p:otherStyle/a:lvl1pPr/@algn");
- break;
- }
- }
- }
- if (algn == null)
- {
- if (typeNode == null)
- {
- return "h-left";
- }
- if (typeNode.Value.Equals("title") || typeNode.Value.Equals("subTitle") || typeNode.Value.Equals("ctrTitle"))
- {
- return "h-mid";
- }
- else if (typeNode.Value == "sldNum")
- {
- return "h-right";
- }
- else if (typeNode.Value.Equals("body")) { return "h-left"; }
- }
- return algn.Value.Equals("ctr") ? "h-mid" : algn.Value.Equals("r") ? "h-right" : "h-left";
- }
- /// <summary>
- /// 幻灯片 背景色填充
- /// </summary>
- /// <param name="slideContent"></param>
- /// <param name="slideLayoutContent"></param>
- /// <param name="slideMasterContent"></param>
- /// <param name="index"></param>
- /// <param name="warpObj"></param>
- /// <returns></returns>
- public async Task<Fill> GetSlideBackgroundFill(XmlNode slideContent, int index, WarpObj warpObj)
- {
- var bgPr = slideContent.GetTextByPath("pkg:xmlData/p:sld/p:cSld/p:bg/p:bgPr");
- var bgRef = slideContent.GetTextByPath("pkg:xmlData/p:sld/p:cSld/p:bg/p:bgRef");
- if (bgPr != null)
- {
- var bgFillTyp = ShapeHelper.GetFillType(bgPr);
- if (bgFillTyp == "SOLID_FILL")
- {
- var sldFill = bgPr.GetTextByPath("a:solidFill");
- var bgColor = ShapeHelper.GetSolidFill(sldFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- if (sldFill!=null) {
- bgColor = ShapeHelper.ColorToning(sldFill.OuterXml, bgColor);
- }
- return new Fill { type = 1, color = bgColor };
- }
- else if (bgFillTyp == "GRADIENT_FILL")
- {
- return ShapeHelper.GetBgGradientFill(bgPr, null, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- else if (bgFillTyp == "PIC_FILL")
- {
- return await GetPicFill("slideBg", bgPr.GetTextByPath("a:blipFill"), warpObj);
- }
- }
- else if (bgRef != null)
- {
- string phClr = ShapeHelper.GetSolidFill(bgRef, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- phClr = ShapeHelper.ColorToning(bgRef.OuterXml, phClr);
- var idx = bgRef.GetTextByPath("@idx");
- if (idx != null)
- {
- int value = int.Parse(idx.Value);
- if (value == 0 || value == 1000)
- {
- return new Fill { type = 0 };
- //no background
- }
- else if (value > 0 && value < 1000)
- {
- //fillStyleLst in themeContent
- //themeContent["a:fmtScheme"]["a:fillStyleLst"]
- //bgcolor = "background: red;";
- }
- else if (value > 1000)
- {
- var trueIdx = value - 1000;
- var bgFillLst = warpObj.themeContent.GetTextByPath("a:theme/a:themeElements/a:fmtScheme/a:bgFillStyleLst");
- if (bgFillLst != null)
- {
- XmlNodeList nodeList = bgFillLst.ChildNodes;
- if (trueIdx < nodeList.Count)
- {
- string type = ShapeHelper.GetFillType(nodeList[trueIdx - 1]);
- if (type.Equals("SOLID_FILL"))
- {
- if (string.IsNullOrEmpty(phClr))
- {
- phClr = ShapeHelper.GetSolidFill(nodeList[trueIdx - 1], slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- if(nodeList[trueIdx - 1]!=null)
- {
- phClr = ShapeHelper.ColorToning(nodeList[trueIdx - 1].OuterXml, phClr);
- }
-
- return new Fill { type = 1, color = phClr };
- }
- else if (type.Equals("GRADIENT_FILL"))
- {
- return ShapeHelper.GetBgGradientFill(nodeList[trueIdx - 1], phClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- else if (type.Equals("PIC_FILL"))
- {
- return await GetPicFill("slideBg", nodeList[trueIdx - 1].GetTextByPath("a:blipFill"), warpObj);
- }
- else
- {
- return new Fill { type = 0 };
- }
- }
- }
- }
- }
- //var node = bgRef.GetTextByPath("");
- //if (bgRef["a:srgbClr"] !== undefined)
- //{
- // phClr = getTextByPathList(bgRef,["a:srgbClr", "attrs", "val"]); //#...
- //}
- //else if (bgRef["a:schemeClr"] !== undefined)
- //{ //a:schemeClr
- // var schemeClr = getTextByPathList(bgRef,["a:schemeClr", "attrs", "val"]);
- // phClr = getSchemeColorFromTheme("a:" + schemeClr, slideMasterContent); //#...
- //}
- }
- else
- {
- bgPr = warpObj.slideLayoutContent.GetTextByPath("pkg:xmlData/p:sldLayout/p:cSld/p:bg/p:bgPr");
- bgRef = warpObj.slideLayoutContent.GetTextByPath("pkg:xmlData/p:sldLayout/p:cSld/p:bg/p:bgRef");
- if (bgPr != null)
- {
- var bgFillTyp = ShapeHelper.GetFillType(bgPr);
- if (bgFillTyp == "SOLID_FILL")
- {
- var sldFill = bgPr.GetTextByPath("a:solidFill");
- var bgColor = ShapeHelper.GetSolidFill(sldFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- if (sldFill != null)
- {
- bgColor = ShapeHelper.ColorToning(sldFill.OuterXml, bgColor);
- }
- return new Fill { type = 1, color = bgColor };
- }
- else if (bgFillTyp == "GRADIENT_FILL")
- {
- return ShapeHelper.GetBgGradientFill(bgPr, null, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- else if (bgFillTyp == "PIC_FILL")
- {
- return await GetPicFill("layoutBg", bgPr.GetTextByPath("a:blipFill"), warpObj);
- }
- }
- else if (bgRef != null)
- {
- string phClr = ShapeHelper.GetSolidFill(bgRef, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- phClr = ShapeHelper.ColorToning(bgRef.OuterXml, phClr);
- var idx = bgRef.GetTextByPath("@idx");
- if (idx != null)
- {
- int value = int.Parse(idx.Value);
- if (value == 0 || value == 1000)
- {
- return new Fill { type = 0 };
- //no background
- }
- else if (value > 0 && value < 1000)
- {
- //fillStyleLst in themeContent
- //themeContent["a:fmtScheme"]["a:fillStyleLst"]
- //bgcolor = "background: red;";
- }
- else if (value > 1000)
- {
- var trueIdx = value - 1000;
- var bgFillLst = warpObj.themeContent.GetTextByPath("a:theme/a:themeElements/a:fmtScheme/a:bgFillStyleLst");
- if (bgFillLst != null)
- {
- XmlNodeList nodeList = bgFillLst.ChildNodes;
- if (trueIdx < nodeList.Count)
- {
- string type = ShapeHelper.GetFillType(nodeList[trueIdx - 1]);
- if (type.Equals("SOLID_FILL"))
- {
- if (string.IsNullOrEmpty(phClr))
- {
- phClr = ShapeHelper.GetSolidFill(nodeList[trueIdx - 1], slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- if (nodeList[trueIdx - 1] != null)
- {
- phClr = ShapeHelper.ColorToning(nodeList[trueIdx - 1].Value, phClr);
- }
- return new Fill { type = 1, color = phClr };
- }
- else if (type.Equals("GRADIENT_FILL"))
- {
- return ShapeHelper.GetBgGradientFill(nodeList[trueIdx - 1], phClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- else if (type.Equals("PIC_FILL"))
- {
- return await GetPicFill("slideBg", nodeList[trueIdx - 1].GetTextByPath("a:blipFill"), warpObj);
- }
- else
- {
- return new Fill { type = 0 };
- }
- }
- }
- }
- }
- }
- else
- {
- bgPr = warpObj.slideMasterContent.GetTextByPath("pkg:xmlData/p:sldMaster/p:cSld/p:bg/p:bgPr");
- bgRef = warpObj.slideMasterContent.GetTextByPath("pkg:xmlData/p:sldMaster/p:cSld/p:bg/p:bgRef");
- if (bgPr != null)
- {
- var bgFillTyp = ShapeHelper.GetFillType(bgPr);
- if (bgFillTyp == "SOLID_FILL")
- {
- var sldFill = bgPr.GetTextByPath("a:solidFill");
- var bgColor = ShapeHelper.GetSolidFill(sldFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- if (sldFill != null)
- {
- bgColor = ShapeHelper.ColorToning(sldFill.OuterXml, bgColor);
- }
- return new Fill { type = 1, color = bgColor };
- }
- else if (bgFillTyp == "GRADIENT_FILL")
- {
- return ShapeHelper.GetBgGradientFill(bgPr, null, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- else if (bgFillTyp == "PIC_FILL")
- {
- return await GetPicFill("masterBg", bgPr.GetTextByPath("a:blipFill"), warpObj);
- }
- }
- else if (bgRef != null)
- {
- string phClr = ShapeHelper.GetSolidFill(bgRef, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- phClr = ShapeHelper.ColorToning(bgRef.OuterXml, phClr);
- var idx = bgRef.GetTextByPath("@idx");
- if (idx != null)
- {
- int value = int.Parse(idx.Value);
- if (value == 0 || value == 1000)
- {
- return new Fill { type = 0 };
- //no background
- }
- else if (value > 0 && value < 1000)
- {
- //fillStyleLst in themeContent
- //themeContent["a:fmtScheme"]["a:fillStyleLst"]
- //bgcolor = "background: red;";
- }
- else if (value > 1000)
- {
- var trueIdx = value - 1000;
- var bgFillLst = warpObj.themeContent.GetTextByPath("a:theme/a:themeElements/a:fmtScheme/a:bgFillStyleLst");
- if (bgFillLst != null)
- {
- XmlNodeList nodeList = bgFillLst.ChildNodes;
- if (trueIdx < nodeList.Count)
- {
- string type = ShapeHelper.GetFillType(nodeList[trueIdx - 1]);
- if (type.Equals("SOLID_FILL"))
- {
- if (string.IsNullOrEmpty(phClr))
- {
- phClr = ShapeHelper.GetSolidFill(nodeList[trueIdx - 1], slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- if (nodeList[trueIdx - 1] != null)
- {
- phClr = ShapeHelper.ColorToning(nodeList[trueIdx - 1].Value, phClr);
- }
- return new Fill { type = 1, color = phClr };
- }
- else if (type.Equals("GRADIENT_FILL"))
- {
- return ShapeHelper.GetBgGradientFill(nodeList[trueIdx - 1], phClr, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- else if (type.Equals("PIC_FILL"))
- {
- return await GetPicFill("slideBg", nodeList[trueIdx - 1].GetTextByPath("a:blipFill"), warpObj);
- }
- else
- {
- return new Fill { type = 0 };
- }
- }
- }
- }
- }
- }
- }
- }
- return null;
- }
- public async Task<Fill> GetPicFill(string type, XmlNode node, WarpObj warpObj)
- {
- //Need to test/////////////////////////////////////////////
- //rId
- //TODO - Image Properties - Tile, Stretch, or Display Portion of Image
- //(http://officeopenxml.com/drwPic-tile.php)
- // var img = "";
- var rId = node.GetTextByPath("a:blip/@r:embed");//node["a:blip"]["attrs"]["r:embed"];
- Dictionary<string, string> imgPath = new Dictionary<string, string>();
- if (type == "slideBg")
- {
- imgPath = warpObj.slideResObj[rId.Value];
- }
- else if (type == "layoutBg")
- {
- imgPath = warpObj.layoutResObj[rId.Value];
- }
- else if (type == "masterBg")
- {
- imgPath = warpObj.masterResObj[rId.Value];
- }
- if (imgPath == null)
- {
- return null;
- }
-
- //var imgExt = imgPath["type"];
- //if (imgExt == "xml")
- //{
- // return null;
- //}
- var imgData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + imgPath["target"] + "']");
- if (imgData != null)
- {
- AzureBlobModel model = await SaveBase64ToBolob(imgData.InnerText, imgData.GetTextByPath("@pkg:contentType").Value,
- fileShaCode + "/imgs", null);
- XmlNode fillRect_node = node.GetTextByPath("a:stretch/a:fillRect");
- Fill fill = new Fill { type = 3, image = model.BlobUrl };
- if (fillRect_node != null)
- {
- FillStyle fillStyle = new FillStyle();
- XmlNode left = node.GetTextByPath("a:stretch/a:fillRect/@l");
- XmlNode top = node.GetTextByPath("a:stretch/a:fillRect/@t");
- XmlNode right = node.GetTextByPath("a:stretch/a:fillRect/@r");
- XmlNode bottom = node.GetTextByPath("a:stretch/a:fillRect/@b");
- if (left != null) {
- fillStyle.left = int.Parse(left.Value);
- }
- if (top != null)
- {
- fillStyle.top = int.Parse(top.Value);
- }
- if (right != null)
- {
- fillStyle.right = int.Parse(right.Value);
- }
- if (bottom != null)
- {
- fillStyle.bottom = int.Parse(bottom.Value);
- }
- fill.style = fillStyle;
- }
- return fill;
- }
- else { return null; }
- // var imgArrayBuffer = warpObj.zip.GetTextByPath(imgPath).Value.asArrayBuffer();
- //var imgMimeType = GetMimeType(imgExt);
- //img = "data:" + imgMimeType + ";base64," + base64ArrayBuffer(imgArrayBuffer);
- }
- public async Task<Fill> GetShapeFill(XmlNode node, WarpObj warpObj)
- {
- // 1. presentationML
- // p:spPr/ [a:noFill, solidFill, gradFill, blipFill, pattFill, grpFill]
- // From slide
- //Fill Type:
- var fillType = ShapeHelper.GetFillType(node.GetTextByPath("p:spPr"));
- Fill fill = null;
- //0
- if (fillType == "NO_FILL")
- {
- fill = new Fill
- {
- type = 0,
- //HtmlText = "background-color: initial;",
- //SvgText = "none"
- };
- //return isSvgMode ? "none" : "background-color: initial;";
- }
- //1纯色填充
- else if (fillType == "SOLID_FILL")
- {
- XmlNode shpFill = node.GetTextByPath("p:spPr/a:solidFill");// node["p:spPr"]["a:solidFill"];
- string color = ShapeHelper.GetSolidFill(shpFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- fill = new Fill
- {
- type = 1,
- color = color,
- };
- }
- //2渐变色填充
- else if (fillType == "GRADIENT_FILL")
- {
- var shpFill = node.GetTextByPath("p:spPr/a:gradFill");// node["p:spPr"]["a:gradFill"];
- // fillColor = GetSolidFill(shpFill);
- fill = ShapeHelper.GetGradientFill(shpFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }//3图片 纹理填充
- else if (fillType == "PIC_FILL")
- {
- var shpFill = node.GetTextByPath("p:spPr/a:blipFill"); //node["p:spPr"]["a:blipFill"];
- fill = await GetPicFill("slideBg", shpFill, warpObj);
- }//4 图案填充
- else if (fillType == "PATTERN_FILL")
- {
- /*
- *
- *<a:pattFill prst="ltDnDiag">
- <a:fgClr>
- <a:schemeClr val="dk1">
- <a:lumMod val="15000"/>
- <a:lumOff val="85000"/>
- </a:schemeClr>
- </a:fgClr>
- <a:bgClr>
- <a:schemeClr val="lt1"/>
- </a:bgClr>
- </a:pattFill>
- */
- var shpFill = node.GetTextByPath("p:spPr/a:pattFill");// node["p:spPr"]["a:pattFill"];
- fill = ShapeHelper.GetPatternFill(shpFill, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- }
- // 2. drawingML namespace
- if (fill == null)
- {
- var clrName = node.GetTextByPath("p:style/a:fillRef");
- string color = ShapeHelper.GetSolidFill(clrName, slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- if (clrName != null)
- {
- fillType = "SOLID_FILL";
- color = ShapeHelper.ColorToning(clrName.OuterXml, color);
- fill = new Fill
- {
- type = 1,
- color = color,
- };
- }
- }
- if (fill != null)
- {
- if (fillType == "GRADIENT_FILL")
- {
- //if (isSvgMode)
- //{
- // return fill;
- //}
- //else
- //{
- // var colorAry = fill.grad;
- // var rot = fill.Rot;
- //var bgcolor = "background: linear-gradient(" + rot + "deg,";
- //for (var i = 0; i < colorAry.Count; i++)
- //{
- // if (i == colorAry.Count - 1)
- // {
- // bgcolor += colorAry[i] + ");";
- // }
- // else
- // {
- // bgcolor += colorAry[i] + ", ";
- // }
- //}
- //fill.HtmlText = bgcolor;
- return fill;
- // }
- }
- else if (fillType == "PIC_FILL")
- {
- //if (isSvgMode)
- //{
- // return fill;
- //}
- //else
- //{
- // fill.HtmlText = "background-image:url(" + fill.Image + ");";
- return fill;
- // }
- }
- else
- {
-
- //if (isSvgMode)
- //{
- // var color = new colz.Color(fill);
- // fill = color.rgb.toString();
- //fill.HtmlText = "background-color: #" + fill.Color + ";";
- return fill;
- //}
- //else
- //{
- // return fill;
- //}
- }
- }
- else
- {
- //if (isSvgMode)
- //{
- // return fill;
- //}
- //else
- //{
- fill = new Fill { type = 0 };
- //fill.SvgText = "none";
- //fill.HtmlText = "background-color: initial;";
- return fill;
- // }
- }
- }
- public async Task<AzureBlobModel> GetThumbnailModel(XmlDocument xdoc, string shaCode)
- {
- var thumbnailNode = xdoc.GetTextByPath("//pkg:part[@pkg:name='/docProps/thumbnail.jpeg']");
- if (thumbnailNode != null)
- {
- var contentType = thumbnailNode.GetTextByPath("@pkg:contentType");
- var thumbnail = thumbnailNode.InnerText;
- return await SaveBase64ToBolob(thumbnail, contentType.Value, shaCode + "/imgs", "thumbnail");
- }
- return null;
- }
- public XmlNode LoadTheme(XmlDocument xdoc)
- {
- var themeRelationship = xdoc.GetTextByPath("//pkg:part[@pkg:name='/ppt/_rels/presentation.xml.rels']/pkg:xmlData/rel:Relationships/rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme']/@Target");
- // "/ppt/theme/theme1.xml"
- string themeURI = "/ppt/" + themeRelationship.Value;
- return xdoc.GetTextByPath("//pkg:part[@pkg:name='" + themeURI + "']");
- }
- public async Task<AzureBlobModel> SaveBase64ToBolob(string data, string contentType, string FolderName, string fileName)
- {
- string fileExt;
- if (ContentTypeDict.extdict.TryGetValue(contentType, out string ext))
- {
- fileExt = ext;
- }
- else
- {
- //解决多种扩展名不能获取的
- string[] sp = contentType.Split("/");
- fileExt = sp[sp.Length - 1];
- sp = fileExt.Split("+");
- fileExt = "." + sp[sp.Length - 1];
- }
- //data:image/jpeg;base64,
- if (string.IsNullOrEmpty(fileName))
- {
- Stream stream = new MemoryStream(Convert.FromBase64String(data));
- string shaCode = ShaHashHelper.GetSHA1(stream);
- fileName = shaCode + fileExt;
- }
- else
- {
- if (fileName.Split(".").Length == 1)
- {
- fileName += fileExt;
- }
- }
- Stream streamBlob = new MemoryStream(Convert.FromBase64String(data));
- AzureBlobModel model = await azureBlobDBRepository.UploadFileByFolder(streamBlob, FolderName, fileName, "pptx", false);
- return model;
- }
- public async Task<Media> ProcessPicNode(XmlNode node, int order, WarpObj warpObj)
- {
- var xfrmList = "p:spPr/a:xfrm";
- var xfrmNode = node.GetTextByPath(xfrmList);
- Media media = new Media() { type = "Media" };
- var id = node.GetTextByPath("p:nvPicPr/p:cNvPr/@id");
- XmlNode slideLayoutSpNode = ShapeHelper.GetNodesTable(id, null, null, warpObj, "Layout");
- XmlNode slideMasterSpNode = ShapeHelper.GetNodesTable(id, null, null, warpObj, "Master");
- XmlNode slideLayoutXfrmNode = null;
- if (slideLayoutSpNode != null)
- {
- slideLayoutXfrmNode = slideLayoutSpNode.GetTextByPath(xfrmList);
- }
- XmlNode slideMasterXfrmNode = null;
- if (slideMasterSpNode != null)
- {
- slideMasterXfrmNode = slideMasterSpNode.GetTextByPath(xfrmList);
- }
- double rotate = 0;
- var rotateNode = node.GetTextByPath("p:spPr/a:xfrm/@rot");
- if (rotateNode != null)
- {
- rotate = ShapeHelper.AngleToDegrees(rotateNode);
- }
- Fill fill = await GetShapeFill(node, warpObj);
- //string sha = null;
- //if (fill != null && fill.Type!=0) {
- // sha = ShaHashHelper.GetSHA1(fill.ToJson());
- // warpObj.pptx.Fills.TryAdd(sha, fill);
-
- //}
- // media.FillSha = sha;
- media.fill = fill;
- Border border = ShapeHelper.GetBorder(node, true, "shape", slideLayoutClrOvride, warpObj.slideMasterContent, warpObj.themeContent);
- //if (border != null && border.Type!=null) {
- // media.BorderSha =ShaHashHelper.GetSHA1(border.ToJson());
- // warpObj.pptx.Borders.TryAdd(media.BorderSha, border);
- //}
- media.border = border;
- Position position = ShapeHelper.GetPosition(xfrmNode, slideLayoutXfrmNode, slideMasterXfrmNode);
- media.position = position;
- position.rot = System.Math.Round(rotate,degree);
- //var rtrnData = "";
- //image
- var rid = node.GetTextByPath("p:blipFill/a:blip/@r:embed");
- if (rid != null)
- {
- var imgName = warpObj.slideResObj[rid.Value]["target"];
-
- if (!string.IsNullOrEmpty(imgName))
- {
- var imgData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + imgName + "']");
- var imgFileExt = imgData.GetTextByPath("@pkg:contentType");
- AzureBlobModel imgModel = await SaveBase64ToBolob(imgData.InnerText, imgFileExt.Value, fileShaCode + "/imgs", "");
- media.image = imgModel.BlobUrl;
- media.mediaType = "image";
- media.index = order;
- }
- }
- ///////////////////////////////////////Amir//////////////////////////////
- //video
- var vdoNode = node.GetTextByPath("p:nvPicPr/p:nvPr/a:videoFile/@r:link");
- if (vdoNode != null)
- {
- string vdoFile = warpObj.slideResObj[vdoNode.Value]["target"];
- if (!string.IsNullOrEmpty(vdoFile))
- {
- var videoData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + vdoFile + "']");
- var contentType = videoData.GetTextByPath("@pkg:contentType");
- AzureBlobModel vdoModel = await SaveBase64ToBolob(videoData.InnerText, contentType.Value, fileShaCode + "/media", "");
- media.url = vdoModel.BlobUrl;
- media.mediaType = "video";
- media.index = order;
- }
- /// 处理为AzureBlob 上传
- // vdoMimeType = getMimeType(vdoFileExt);
- // blob = new Blob([uInt8Array], {
- // type: vdoMimeType
- // });
- // vdoBlob = URL.createObjectURL(blob);
- }
- //audio
- var audioNode = node.GetTextByPath("p:nvPicPr/p:nvPr/a:audioFile/@r:link");
- // var audioObjc;
- if (audioNode != null)
- {
- string audioFile = warpObj.slideResObj[audioNode.Value]["target"];
- if (!string.IsNullOrEmpty(audioFile))
- {
- var audioData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + audioFile + "']");
- var contentType = audioData.GetTextByPath("@pkg:contentType");
- AzureBlobModel adoModel = await SaveBase64ToBolob(audioData.InnerText, contentType.Value, fileShaCode + "/media", "");
- media.url = adoModel.BlobUrl;
- media.mediaType = "audio";
- media.index = order;
- }
- //uInt8ArrayAudio = zip.file(audioFile).asArrayBuffer();
- //blobAudio = new Blob([uInt8ArrayAudio]);
- //audioBlob = URL.createObjectURL(blobAudio);
- //var cx = parseInt(xfrmNode["a:ext"]["attrs"]["cx"]) * 20;
- //var cy = xfrmNode["a:ext"]["attrs"]["cy"];
- //var x = parseInt(xfrmNode["a:off"]["attrs"]["x"]) / 2.5;
- //var y = xfrmNode["a:off"]["attrs"]["y"];
- //audioObjc = {
- // "a:ext" : {
- // "attrs":{
- // "cx":cx,
- // "cy":cy
- // }
- // },
- // "a:off":{
- // "attrs":{
- // "x":x,
- // "y":y
- // }
- // }
- //}
- // mediaSupportFlag = true;
- }
- //////////////////////////////////////////////////////////////////////////
- //mimeType = imgFileExt;
- //rtrnData = "<div class='block content' style='" +
- // (( audioPlayerFlag) ? GetPosition(audioObjc, null, null) : GetPosition(xfrmNode, null, null)) +
- // (( audioPlayerFlag) ? GetSize(audioObjc, null, null) :GetSize(xfrmNode, null, null)) +
- // " z-index: " + order + ";" +
- // "transform: rotate(" + rotate + "deg);'>";
- //if ((vdoNode ==null && audioNode ==null) || !mediaSupportFlag)
- //{
- // rtrnData += "<img src='data:" + mimeType + ";base64," + base64ArrayBuffer(imgArrayBuffer) + "' style='width: 100%; height: 100%'/>";
- //}
- //else if ((vdoNode !=null || audioNode !=null) && mediaSupportFlag)
- //{
- // if (vdoNode !=null)
- // {
- // rtrnData += "<video src='" + vdoBlob + "' controls style='width: 100%; height: 100%'>Your browser does not support the video tag.</video>";
- // }
- // if (audioNode !=null)
- // {
- // rtrnData += "<audio id='audio_player' controls ><source src='" + audioBlob + "'></audio>";
- // }
- //}
- //rtrnData += "<span style='color:red;font-size:40px;position: absolute;'>This media file Not supported by HTML5</span>";
- //if ((vdoNode != null || audioNode != null) && mediaSupportFlag)
- //{
- //}
- // rtrnData += "</div>";
- return media;
- }
- }
- }
|