12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176 |
- 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;
- }
- }
- }
|