PPTXHelper.cs 116 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613
  1. using DocumentFormat.OpenXml;
  2. using HTEXLib.Models.Inner;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using System.Xml;
  7. using System.Xml.Linq;
  8. using DocumentFormat.OpenXml.Presentation;
  9. using DocumentFormat.OpenXml.Drawing;
  10. using HTEXLib.Models;
  11. using ColorType = DocumentFormat.OpenXml.Drawing.ColorType;
  12. using System.Linq;
  13. using DocumentFormat.OpenXml.Packaging;
  14. using DocumentFormat.OpenXml.Drawing.Charts;
  15. using System.Drawing;
  16. using HTEXLib.Helpers.ColorHelpers;
  17. using System.IO;
  18. namespace HTEXLib.Helpers.ShapeHelpers
  19. {
  20. public class SlideColor
  21. {
  22. public string LineColor { get; set; }
  23. public string FillColor { get; set; }
  24. public string EffectColor { get; set; }
  25. public string FontColor { get; set; }
  26. }
  27. public static class PPTXHelper
  28. {
  29. // StyleMatrixReferenceType
  30. ///处理边框
  31. //
  32. // 摘要:
  33. // LineReference.
  34. // Represents the following element tag in the schema: a:lnRef.
  35. //public LineReference LineReference { get; set; }
  36. //
  37. // 摘要:
  38. // FillReference.
  39. // Represents the following element tag in the schema: a:fillRef.
  40. // public FillReference FillReference { get; set; }
  41. //
  42. // 摘要:
  43. // EffectReference.
  44. // Represents the following element tag in the schema: a:effectRef.
  45. //
  46. // 摘要:
  47. // Font Reference.
  48. // Represents the following element tag in the schema: a:fontRef.
  49. // public FontReference FontReference { get; set; }
  50. /// <summary>
  51. /// 处理 LineReference 轮廓 a:lnRef
  52. /// 处理 FillReference 填充 a:fillRef
  53. /// 处理 EffectReference 效果 a:effectRef
  54. /// 处理 FontReference 字体 a:fontRef
  55. /// </summary>
  56. /// <param name="shapeStyle"></param>
  57. public static SlideColor DoShapeStyle(DocumentFormat.OpenXml.Presentation.ShapeStyle shapeStyle, PPTSlide slide, string type) {
  58. if (shapeStyle == null) {
  59. return null;
  60. }
  61. string LineColor = DoMatrixReferenceColors(shapeStyle.LineReference, slide);
  62. string FillColor = DoMatrixReferenceColors(shapeStyle.FillReference, slide);
  63. string EffectColor = DoMatrixReferenceColors(shapeStyle.EffectReference, slide);
  64. string FontColor = FontReferenceColors(shapeStyle.FontReference, slide);
  65. return new SlideColor { LineColor = LineColor, FillColor = FillColor, EffectColor = EffectColor, FontColor = FontColor };
  66. }
  67. public static SlideColor DoShapeStyle(DocumentFormat.OpenXml.Office.Drawing.ShapeStyle shapeStyle, PPTSlide slide, string type)
  68. {
  69. if (shapeStyle == null)
  70. {
  71. return null;
  72. }
  73. string LineColor = DoMatrixReferenceColors(shapeStyle.LineReference, slide);
  74. string FillColor = DoMatrixReferenceColors(shapeStyle.FillReference, slide);
  75. string EffectColor = DoMatrixReferenceColors(shapeStyle.EffectReference, slide);
  76. string FontColor = FontReferenceColors(shapeStyle.FontReference, slide);
  77. return new SlideColor { LineColor = LineColor, FillColor = FillColor, EffectColor = EffectColor, FontColor = FontColor };
  78. }
  79. public static HTEXLib.PPTX.Models.HyperLink DoHyperlinkType(HyperlinkType hyperlink,PPTSlide slide ,string partForm) {
  80. if (hyperlink == null) {
  81. return null;
  82. }
  83. string linkType = hyperlink.LocalName;
  84. HyperlinkRelationship hyperlinksp = null;
  85. if (partForm == "slide")
  86. {
  87. hyperlinksp = slide.SlidePart.HyperlinkRelationships.Where(x => x.Id == hyperlink.Id).FirstOrDefault();
  88. }
  89. if (partForm == "layout")
  90. {
  91. hyperlinksp = slide.SlideLayoutPart.HyperlinkRelationships.Where(x => x.Id == hyperlink.Id).FirstOrDefault();
  92. }
  93. if (partForm == "master")
  94. {
  95. hyperlinksp = slide.slideMasterPart.HyperlinkRelationships.Where(x => x.Id == hyperlink.Id).FirstOrDefault();
  96. }
  97. if (partForm == "drawing")
  98. {
  99. hyperlinksp = slide.diagramDataPart.HyperlinkRelationships.Where(x => x.Id == hyperlink.Id).FirstOrDefault();
  100. }
  101. if (partForm == "chart")
  102. {
  103. hyperlinksp = slide.chartPart.HyperlinkRelationships.Where(x => x.Id == hyperlink.Id).FirstOrDefault();
  104. }
  105. HTEXLib.PPTX.Models.HyperLink hyper = new HTEXLib.PPTX.Models.HyperLink
  106. {
  107. linkType = linkType,
  108. // history = hyperlink.History != null ? hyperlink.History.Value.ToString() : null,
  109. // invalidUrl = hyperlink.InvalidUrl != null ? hyperlink.InvalidUrl.Value.ToString() : null,
  110. //tgtFrame = hyperlink.TargetFrame != null ? hyperlink.TargetFrame.Value.ToString() : null,
  111. // tooltip = hyperlink.Tooltip!=null ? hyperlink.Tooltip.Value.ToString():null,
  112. // id = hyperlink.Id!=null ? hyperlink.Id.Value.ToString():null,
  113. action = hyperlink.Action!=null?hyperlink.Action.Value.ToString():null,
  114. highlightClick = hyperlink.HighlightClick!=null ? hyperlink.HighlightClick.Value:false,
  115. // endSnd = hyperlink.EndSound!=null? hyperlink.EndSound.Value:false
  116. };
  117. if (hyperlink.HyperlinkSound != null)
  118. {
  119. hyper.sndName = hyperlink.HyperlinkSound.Name;
  120. DataPartReferenceRelationship snd = null;
  121. if (partForm == "slide")
  122. {
  123. snd = slide.SlidePart.DataPartReferenceRelationships.Where(x => x.Id == hyperlink.HyperlinkSound.Embed).FirstOrDefault();
  124. }
  125. if (partForm == "layout")
  126. {
  127. snd = slide.SlideLayoutPart.DataPartReferenceRelationships.Where(x => x.Id == hyperlink.HyperlinkSound.Embed).FirstOrDefault();
  128. }
  129. if (partForm == "master")
  130. {
  131. snd = slide.slideMasterPart.DataPartReferenceRelationships.Where(x => x.Id == hyperlink.HyperlinkSound.Embed).FirstOrDefault();
  132. }
  133. if (partForm == "drawing")
  134. {
  135. snd = slide.diagramDataPart.DataPartReferenceRelationships.Where(x => x.Id == hyperlink.HyperlinkSound.Embed).FirstOrDefault();
  136. }
  137. if (partForm == "chart")
  138. {
  139. snd = slide.chartPart.DataPartReferenceRelationships.Where(x => x.Id == hyperlink.HyperlinkSound.Embed).FirstOrDefault();
  140. }
  141. if (snd != null) {
  142. var url = snd.Uri.ToString().Replace("../", "/ppt/");
  143. var name = url.Replace("/", "");
  144. var thumbnail = slide.Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
  145. hyper.sndUrl = name;
  146. }
  147. }
  148. if (hyperlinksp != null) {
  149. var url= hyperlinksp.Uri.IsAbsoluteUri? hyperlinksp.Uri.AbsoluteUri : hyperlinksp.Uri.OriginalString;
  150. hyper.url = url;
  151. var strs= hyperlinksp.RelationshipType.Split('/');
  152. //hyper.type = strs[strs.Length-1];
  153. //var type = hyperlinksp.RelationshipType;
  154. //string[] s = type.Split('/');
  155. //linkType = s[s.Length - 1];
  156. //link = hyperlinksp.Uri.ToString();
  157. //if (hyperlink.Action != null && (hyperlink.Action.Value.StartsWith("ppaction://hlinkpres") || hyperlink.Action.Value.StartsWith("ppaction://hlinkfile")
  158. // || hyperlink.Action.Value.StartsWith("ppaction://hlinksldjump")
  159. // || hyperlink.Action.Value.StartsWith("ppaction://hlinkshowjump")))
  160. //{
  161. // linkType = "file";
  162. // slide.lazyFiles.Add(link);
  163. //}
  164. }
  165. return hyper;
  166. }
  167. public static Shape DoCustomGeometry(CustomGeometry shapeTypeCustom, Shape shape) {
  168. if (shapeTypeCustom != null)
  169. {
  170. var pathlist = shapeTypeCustom.GetFirstChild<PathList>();
  171. var path = pathlist.GetFirstChild<DocumentFormat.OpenXml.Drawing.Path>();
  172. var Width = 1.0;
  173. if (path.Width != null) {
  174. Width= shape.style.position.cx / path.Width.Value / 96.0 * 914400;
  175. }
  176. var Height = 1.0;
  177. if (path.Height != null) {
  178. Height = shape.style.position.cy / path.Height.Value / 96.0 * 914400;
  179. }
  180. var pathChildren = path.ChildElements;
  181. if (pathChildren != null)
  182. {
  183. var start = pathChildren.Where(x => x is MoveTo).FirstOrDefault();
  184. var close = pathChildren.Where(x => x is CloseShapePath).FirstOrDefault();
  185. var spX = 96.0;
  186. var spY = 96.0;
  187. if (start != null)
  188. {
  189. var point = start.GetFirstChild<DocumentFormat.OpenXml.Drawing.Point>();
  190. spX = double.Parse(point.X.Value) * Globals.px96 / Globals.px914400 * Width;
  191. spY = double.Parse(point.Y.Value) * Globals.px96 / Globals.px914400* Height;
  192. }
  193. var d = "M" + spX + "," + spY;
  194. foreach (var child in pathChildren)
  195. {
  196. if (child is LineTo lineTo)
  197. {
  198. var elm = lineTo.GetFirstChild<DocumentFormat.OpenXml.Drawing.Point>();
  199. if (elm != null)
  200. {
  201. var Lx = double.Parse(elm.X.Value) * Globals.px96 / Globals.px914400 * Width;
  202. var Ly = double.Parse(elm.Y.Value) * Globals.px96 / Globals.px914400 * Height;
  203. d += " L" + Lx + "," + Ly;
  204. }
  205. }
  206. if (child is ArcTo arcTo)
  207. {
  208. var WidthRadius = arcTo.WidthRadius ;
  209. var HeightRadius = arcTo.HeightRadius ;
  210. var StartAngle = arcTo.StartAngle;
  211. var SwingAngle = arcTo.SwingAngle;
  212. var wR = double.Parse(WidthRadius.Value) * Globals.px96 / Globals.px914400 * Width;
  213. var hR = double.Parse(HeightRadius.Value) * Globals.px96 / Globals.px914400 * Height;
  214. var stAng = double.Parse(StartAngle.Value) * Globals.px96 / Globals.px914400;
  215. var swAng = double.Parse(SwingAngle.Value) * Globals.px96 / Globals.px914400;
  216. var endAng = stAng + swAng;
  217. d += SvgHelper.ShapeArc(wR, hR, wR, hR, stAng, endAng, false);
  218. }
  219. if (child is QuadraticBezierCurveTo quadraticBezierCurveTo)
  220. {
  221. var elms = quadraticBezierCurveTo.Elements<DocumentFormat.OpenXml.Drawing.Point>();
  222. if (elms != null)
  223. {
  224. var list = elms.ToList();
  225. var Cx1 = double.Parse(list[0].X.Value) * Globals.px96 / Globals.px914400 * Width;
  226. var Cy1 = double.Parse(list[0].Y.Value) * Globals.px96 / Globals.px914400 * Height;
  227. var Cx2 = double.Parse(list[1].X.Value) * Globals.px96 / Globals.px914400 * Width;
  228. var Cy2 = double.Parse(list[1].Y.Value) * Globals.px96 / Globals.px914400 * Height;
  229. var Cx3 = double.Parse(list[2].X.Value) * Globals.px96 / Globals.px914400 * Width;
  230. var Cy3 = double.Parse(list[2].Y.Value) * Globals.px96 / Globals.px914400 * Height;
  231. d += " C" + Cx1 + "," + Cy1 + " " + Cx2 + "," + Cy2 + " " + Cx3 + "," + Cy3;
  232. }
  233. }
  234. if (child is CubicBezierCurveTo cubicBezierCurveTo)
  235. {
  236. var elms = cubicBezierCurveTo.Elements<DocumentFormat.OpenXml.Drawing.Point>();
  237. if (elms != null)
  238. {
  239. var list = elms.ToList();
  240. var Cx1 = double.Parse(list[0].X.Value) * Globals.px96 / Globals.px914400 * Width;
  241. var Cy1 = double.Parse(list[0].Y.Value) * Globals.px96 / Globals.px914400 * Height;
  242. var Cx2 = double.Parse(list[1].X.Value) * Globals.px96 / Globals.px914400 * Width;
  243. var Cy2 = double.Parse(list[1].Y.Value) * Globals.px96 / Globals.px914400 * Height;
  244. var Cx3 = double.Parse(list[2].X.Value) * Globals.px96 / Globals.px914400 * Width;
  245. var Cy3 = double.Parse(list[2].Y.Value) * Globals.px96 / Globals.px914400 * Height;
  246. d += " C" + Cx1 + "," + Cy1 + " " + Cx2 + "," + Cy2 + " " + Cx3 + "," + Cy3;
  247. }
  248. }
  249. }
  250. //是否关闭svg
  251. if (close != null)
  252. {
  253. d += " z";
  254. }
  255. d = d.Replace(",", " ");
  256. Svg shapes =
  257. new Svg {
  258. type = "path",
  259. // Fill = (!imgFillFlg ? (grndFillFlg ? "url(#linGrd_" + order + ")" : Fill.Color) : "url(#imgPtrn_" + order + ")"),
  260. //Stroke = "#" + shapeBorder.Color,
  261. //StrokeWidth = shapeBorder.Width + "",
  262. //StrokeDasharray = shapeBorder.Stroke,
  263. d=d,
  264. close = close!=null? true:false,
  265. start =shape.style.border.headEnd!=null?shape.style.border.headEnd:null,
  266. end=shape.style.border.tailEnd!=null?shape.style.border.tailEnd:null,
  267. };
  268. shape.svg = shapes;
  269. shape.shapeType = "custom";
  270. }
  271. }
  272. return shape;
  273. }
  274. public static HTEXLib.Models.HTEX.ShapeStyle DoBackground(DocumentFormat.OpenXml.Drawing.Diagrams.Background shapeProperties, PPTSlide slide, string partForm)
  275. {
  276. if (shapeProperties == null)
  277. {
  278. return null;
  279. }
  280. Fill fill = new Fill() { type = -1 };
  281. var gradFill = shapeProperties.GetFirstChild<GradientFill>();
  282. if (gradFill != null)
  283. {
  284. fill.type = 2;
  285. fill.gradientFill = DoGradientFill(gradFill, slide);
  286. }
  287. var noFill = shapeProperties.GetFirstChild<NoFill>();
  288. if (noFill != null)
  289. {
  290. fill.type = 0;
  291. }
  292. var pattFill = shapeProperties.GetFirstChild<PatternFill>();
  293. if (pattFill != null)
  294. {
  295. HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
  296. fill.type = 4;
  297. fill.pattFill = htexPattFill;
  298. }
  299. var solidFill = shapeProperties.GetFirstChild<SolidFill>();
  300. if (solidFill != null)
  301. {
  302. fill.type = 1;
  303. fill.solidFill = DoSolidFill(solidFill, slide);
  304. }
  305. var groupFill = shapeProperties.GetFirstChild<GroupFill>();
  306. if (groupFill != null)
  307. {
  308. fill.type = 5;
  309. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  310. }
  311. var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
  312. if (blipFill != null)
  313. {
  314. fill.type = 3;
  315. fill.blipFill = DoBlipFill(blipFill, slide, partForm);
  316. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  317. }
  318. var EffectList = shapeProperties.GetFirstChild<EffectList>();
  319. var effect = doEffect(EffectList, slide, partForm);
  320. var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
  321. var Scene3DType = shapeProperties.GetFirstChild<Scene3DType>();
  322. var Shape3DType = shapeProperties.GetFirstChild<Shape3DType>();
  323. var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<ShapePropertiesExtensionList>();
  324. return new HTEXLib.Models.HTEX.ShapeStyle { fill = fill, effect = effect };
  325. }
  326. public static Border DoWhole(DocumentFormat.OpenXml.Drawing.Diagrams.Whole shapeProperties, PPTSlide slide, string type, string partForm)
  327. {
  328. if (shapeProperties == null)
  329. {
  330. return null;
  331. }
  332. //Outline
  333. var lnNode = shapeProperties.GetFirstChild<Outline>();
  334. Border border = null;
  335. if (lnNode != null)
  336. {
  337. border = DoOutline(lnNode, slide, type);
  338. }
  339. //var EffectList = shapeProperties.GetFirstChild<EffectList>();
  340. //var effect = doEffect(EffectList, slide, partForm);
  341. //var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
  342. //var Scene3DType = shapeProperties.GetFirstChild<Scene3DType>();
  343. //var Shape3DType = shapeProperties.GetFirstChild<Shape3DType>();
  344. //var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<ShapePropertiesExtensionList>();
  345. return border;
  346. }
  347. public static HTEXLib.Models.HTEX.ShapeStyle DoShapeProperties(DocumentFormat.OpenXml.Office.Drawing.ShapeProperties shapeProperties, PPTSlide slide, string type, string partForm)
  348. {
  349. if (shapeProperties == null)
  350. {
  351. return null;
  352. }
  353. //Outline
  354. var lnNode = shapeProperties.GetFirstChild<Outline>();
  355. Border border = null;
  356. if (lnNode != null)
  357. {
  358. border = DoOutline(lnNode, slide, type);
  359. }
  360. Fill fill = new Fill() { type = -1 };
  361. var gradFill = shapeProperties.GetFirstChild<GradientFill>();
  362. if (gradFill != null)
  363. {
  364. fill.type = 2;
  365. fill.gradientFill = DoGradientFill(gradFill, slide);
  366. }
  367. var noFill = shapeProperties.GetFirstChild<NoFill>();
  368. if (noFill != null)
  369. {
  370. fill.type = 0;
  371. }
  372. var pattFill = shapeProperties.GetFirstChild<PatternFill>();
  373. if (pattFill != null)
  374. {
  375. HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
  376. fill.type = 4;
  377. fill.pattFill = htexPattFill;
  378. }
  379. var solidFill = shapeProperties.GetFirstChild<SolidFill>();
  380. if (solidFill != null)
  381. {
  382. fill.type = 1;
  383. fill.solidFill = DoSolidFill(solidFill, slide);
  384. }
  385. var groupFill = shapeProperties.GetFirstChild<GroupFill>();
  386. if (groupFill != null)
  387. {
  388. fill.type = 5;
  389. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  390. }
  391. var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
  392. if (blipFill != null)
  393. {
  394. fill.type = 3;
  395. fill.blipFill = DoBlipFill(blipFill, slide, partForm);
  396. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  397. }
  398. var EffectList = shapeProperties.GetFirstChild<EffectList>();
  399. var effect = doEffect(EffectList, slide, partForm);
  400. var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
  401. var Scene3DType = shapeProperties.GetFirstChild<Scene3DType>();
  402. var Shape3DType = shapeProperties.GetFirstChild<Shape3DType>();
  403. var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<ShapePropertiesExtensionList>();
  404. return new HTEXLib.Models.HTEX.ShapeStyle { fill = fill, border = border, effect = effect };
  405. }
  406. public static HTEXLib.Models.HTEX.RunStyle DoRunProperties(TextCharacterPropertiesType shapeProperties, PPTSlide slide, string type, string partForm) {
  407. if (shapeProperties == null)
  408. {
  409. return null;
  410. }
  411. //Outline
  412. var lnNode = shapeProperties.GetFirstChild<Outline>();
  413. Border border = null;
  414. if (lnNode != null)
  415. {
  416. border = DoOutline(lnNode, slide, type);
  417. }
  418. Fill fill = new Fill() { type = -1 };
  419. var gradFill = shapeProperties.GetFirstChild<GradientFill>();
  420. if (gradFill != null)
  421. {
  422. fill.type = 2;
  423. fill.gradientFill = DoGradientFill(gradFill, slide);
  424. }
  425. var noFill = shapeProperties.GetFirstChild<NoFill>();
  426. if (noFill != null)
  427. {
  428. fill.type = 0;
  429. }
  430. var pattFill = shapeProperties.GetFirstChild<PatternFill>();
  431. if (pattFill != null)
  432. {
  433. HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
  434. fill.type = 4;
  435. fill.pattFill = htexPattFill;
  436. }
  437. var solidFill = shapeProperties.GetFirstChild<SolidFill>();
  438. if (solidFill != null)
  439. {
  440. fill.type = 1;
  441. fill.solidFill = DoSolidFill(solidFill, slide);
  442. }
  443. var groupFill = shapeProperties.GetFirstChild<GroupFill>();
  444. if (groupFill != null)
  445. {
  446. fill.type = 5;
  447. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  448. }
  449. var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
  450. if (blipFill != null)
  451. {
  452. fill.type = 3;
  453. fill.blipFill = DoBlipFill(blipFill, slide, partForm);
  454. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  455. }
  456. var EffectList = shapeProperties.GetFirstChild<EffectList>();
  457. var effect = doEffect(EffectList, slide, partForm);
  458. var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
  459. var Scene3DType = shapeProperties.GetFirstChild<Scene3DType>();
  460. var Shape3DType = shapeProperties.GetFirstChild<Shape3DType>();
  461. var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<ShapePropertiesExtensionList>();
  462. return new HTEXLib.Models.HTEX.RunStyle { fill = fill, border = border,effect=effect };
  463. }
  464. public static HTEXLib.Models.HTEX.Effect doEffect(EffectList effectList, PPTSlide slide, string partForm) {
  465. if (effectList == null) {
  466. return null;
  467. }
  468. HTEXLib.Models.HTEX.Effect effect = new Models.HTEX.Effect();
  469. if (effectList.Blur != null) {
  470. effect.blur = new Models.HTEX.Blur
  471. {
  472. radius = effectList.Blur.Radius!=null? effectList.Blur.Radius.Value * 1.0 / Globals.px12700 : 0,
  473. grow = effectList.Blur.Grow!=null?effectList.Blur.Grow.Value:false
  474. };
  475. }
  476. if (effectList.FillOverlay != null)
  477. {
  478. Fill fill = DoFillOverlay(effectList.FillOverlay, slide, partForm);
  479. if (fill == null || fill.type == -1 || fill.type == 0) {
  480. fill = null;
  481. }
  482. effect.fillOverlay = new Models.HTEX.FillOverlay
  483. {
  484. fill = fill,
  485. blend = effectList.FillOverlay.Blend != null ? effectList.FillOverlay.Blend.Value.ToString() : null
  486. };
  487. }
  488. if (effectList.Glow != null)
  489. {
  490. string color = DoEffectColor(slide, effectList.Glow);
  491. effect.glow = new Models.HTEX.Glow
  492. {
  493. color = color,
  494. rad= effectList.Glow.Radius!=null?effectList.Glow.Radius.Value * 1.0 / Globals.px12700 : 0
  495. };
  496. }
  497. if (effectList.InnerShadow != null)
  498. {
  499. string color = DoEffectColor(slide, effectList.InnerShadow);
  500. effect.innerShadow = new Models.HTEX.InnerShadow
  501. {
  502. color = color,
  503. blurRad = effectList.InnerShadow.BlurRadius!=null?effectList.InnerShadow.BlurRadius.Value * 1.0 / Globals.px12700 : 0,
  504. dir= effectList.InnerShadow.Direction!=null?effectList.InnerShadow.Direction.Value* 1.0 / 60000 : 0,
  505. dist= effectList.InnerShadow.Distance!=null?effectList.InnerShadow.Distance.Value*1.0/Globals.px12700:0
  506. };
  507. }
  508. if (effectList.OuterShadow != null)
  509. {
  510. string color = DoEffectColor(slide, effectList.OuterShadow);
  511. effect.outerShadow = new Models.HTEX.OuterShadow
  512. {
  513. color = color,
  514. blurRad = effectList.OuterShadow.BlurRadius!=null? effectList.OuterShadow.BlurRadius.Value*1.0/ Globals.px12700 : 0,
  515. dir = effectList.OuterShadow.Direction!=null?effectList.OuterShadow.Direction.Value * 1.0 / 60000 : 0,
  516. dist = effectList.OuterShadow.Distance!=null?effectList.OuterShadow.Distance.Value * 1.0 / Globals.px12700 : 0,
  517. rotWithShape= effectList.OuterShadow.RotateWithShape!=null?effectList.OuterShadow.RotateWithShape.Value:true,
  518. algn= effectList.OuterShadow.Alignment!=null? effectList.OuterShadow.Alignment.Value.ToString():null,
  519. ky= effectList.OuterShadow.VerticalSkew!=null? effectList.OuterShadow.VerticalSkew.Value:0,
  520. sy = effectList.OuterShadow.VerticalRatio!=null? effectList.OuterShadow.VerticalRatio.Value:0,
  521. sx= effectList.OuterShadow.HorizontalRatio!=null? effectList.OuterShadow.HorizontalRatio.Value:0,
  522. kx= effectList.OuterShadow.HorizontalSkew!=null? effectList.OuterShadow.HorizontalSkew.Value:0,
  523. };
  524. }
  525. if (effectList.PresetShadow != null)
  526. {
  527. string color = DoEffectColor(slide, effectList.PresetShadow);
  528. effect.presetShadow = new Models.HTEX.PresetShadow
  529. {
  530. color = color,
  531. dir = effectList.PresetShadow.Direction!=null? effectList.PresetShadow.Direction.Value * 1.0 / 60000 : 0,
  532. dist = effectList.PresetShadow.Distance!=null?effectList.PresetShadow.Distance.Value * 1.0 / Globals.px12700 : 0,
  533. prst = effectList.PresetShadow.Preset!=null? effectList.PresetShadow.Preset.Value.ToString():null
  534. };
  535. }
  536. if (effectList.Reflection != null)
  537. {
  538. effect.reflection = new Models.HTEX.Reflection
  539. {
  540. dir = effectList.Reflection.Direction!=null ? effectList.Reflection.Direction.Value*1.0/ 60000 : 0,
  541. dist = effectList.Reflection.Distance!=null?effectList.Reflection.Distance.Value*1.0/Globals.px12700:0,
  542. blurRad = effectList.Reflection.BlurRadius!=null? effectList.Reflection.BlurRadius.Value * 1.0 / Globals.px12700 : 0,
  543. rotWithShape = effectList.Reflection.RotateWithShape!=null? effectList.Reflection.RotateWithShape.Value:true,
  544. algn = effectList.Reflection.Alignment!=null? effectList.Reflection.Alignment.Value.ToString():null,
  545. ky = effectList.Reflection.VerticalSkew!=null?effectList.Reflection.VerticalSkew.Value:0,
  546. sy = effectList.Reflection.VerticalRatio!=null? effectList.Reflection.VerticalRatio.Value:0,
  547. sx = effectList.Reflection.HorizontalRatio!=null? effectList.Reflection.HorizontalRatio.Value:0,
  548. kx = effectList.Reflection.HorizontalSkew!=null? effectList.Reflection.HorizontalSkew.Value:0,
  549. stA= effectList.Reflection.StartOpacity!=null?effectList.Reflection.StartOpacity.Value * 1.0 / 100000 : 1,
  550. stPos = effectList.Reflection.StartPosition!=null?effectList.Reflection.StartPosition.Value : 0,
  551. endA = effectList.Reflection.EndAlpha!=null?effectList.Reflection.EndAlpha.Value:0,
  552. endPos = effectList.Reflection.EndPosition!=null?effectList.Reflection.EndPosition.Value*1.0/100000:1,
  553. fadeDir = effectList.Reflection.FadeDirection!=null?effectList.Reflection.FadeDirection.Value:0,
  554. };
  555. }
  556. if (effectList.SoftEdge != null)
  557. {
  558. effect.softEdge = new Models.HTEX.SoftEdge
  559. {
  560. //12700
  561. rad = effectList.SoftEdge.Radius!=null? effectList.SoftEdge.Radius.Value*1.0/Globals.px12700:0,
  562. };
  563. }
  564. return effect;
  565. }
  566. private static string DoEffectColor(PPTSlide slide, PresetShadow FillReference)
  567. {
  568. string color = null;
  569. if (FillReference != null)
  570. {
  571. if (FillReference.RgbColorModelPercentage != null)
  572. {
  573. color = ReadColor(FillReference.RgbColorModelPercentage);
  574. }
  575. if (FillReference.RgbColorModelHex != null)
  576. {
  577. color = ReadColor(FillReference.RgbColorModelHex);
  578. }
  579. if (FillReference.HslColor != null)
  580. {
  581. color = ReadColor(FillReference.HslColor);
  582. }
  583. if (FillReference.SystemColor != null)
  584. {
  585. color = ReadColor(FillReference.SystemColor, slide);
  586. }
  587. if (FillReference.SchemeColor != null)
  588. {
  589. color = ReadColor(FillReference.SchemeColor, slide);
  590. }
  591. if (FillReference.PresetColor != null)
  592. {
  593. color = ReadColor(FillReference.PresetColor);
  594. }
  595. }
  596. return color;
  597. }
  598. private static string DoEffectColor(PPTSlide slide, OuterShadow FillReference)
  599. {
  600. string color = null;
  601. if (FillReference != null)
  602. {
  603. if (FillReference.RgbColorModelPercentage != null)
  604. {
  605. color = ReadColor(FillReference.RgbColorModelPercentage);
  606. }
  607. if (FillReference.RgbColorModelHex != null)
  608. {
  609. color = ReadColor(FillReference.RgbColorModelHex);
  610. }
  611. if (FillReference.HslColor != null)
  612. {
  613. color = ReadColor(FillReference.HslColor);
  614. }
  615. if (FillReference.SystemColor != null)
  616. {
  617. color = ReadColor(FillReference.SystemColor, slide);
  618. }
  619. if (FillReference.SchemeColor != null)
  620. {
  621. color = ReadColor(FillReference.SchemeColor, slide);
  622. }
  623. if (FillReference.PresetColor != null)
  624. {
  625. color = ReadColor(FillReference.PresetColor);
  626. }
  627. }
  628. return color;
  629. }
  630. private static string DoEffectColor(PPTSlide slide, InnerShadow FillReference)
  631. {
  632. string color = null;
  633. if (FillReference != null)
  634. {
  635. if (FillReference.RgbColorModelPercentage != null)
  636. {
  637. color = ReadColor(FillReference.RgbColorModelPercentage);
  638. }
  639. if (FillReference.RgbColorModelHex != null)
  640. {
  641. color = ReadColor(FillReference.RgbColorModelHex);
  642. }
  643. if (FillReference.HslColor != null)
  644. {
  645. color = ReadColor(FillReference.HslColor);
  646. }
  647. if (FillReference.SystemColor != null)
  648. {
  649. color = ReadColor(FillReference.SystemColor, slide);
  650. }
  651. if (FillReference.SchemeColor != null)
  652. {
  653. color = ReadColor(FillReference.SchemeColor, slide);
  654. }
  655. if (FillReference.PresetColor != null)
  656. {
  657. color = ReadColor(FillReference.PresetColor);
  658. }
  659. }
  660. return color;
  661. }
  662. private static string DoEffectColor(PPTSlide slide, Glow FillReference)
  663. {
  664. string color = null;
  665. if (FillReference != null)
  666. {
  667. if (FillReference.RgbColorModelPercentage != null)
  668. {
  669. color = ReadColor(FillReference.RgbColorModelPercentage);
  670. }
  671. if (FillReference.RgbColorModelHex != null)
  672. {
  673. color = ReadColor(FillReference.RgbColorModelHex);
  674. }
  675. if (FillReference.HslColor != null)
  676. {
  677. color = ReadColor(FillReference.HslColor);
  678. }
  679. if (FillReference.SystemColor != null)
  680. {
  681. color = ReadColor(FillReference.SystemColor, slide);
  682. }
  683. if (FillReference.SchemeColor != null)
  684. {
  685. color = ReadColor(FillReference.SchemeColor, slide);
  686. }
  687. if (FillReference.PresetColor != null)
  688. {
  689. color = ReadColor(FillReference.PresetColor);
  690. }
  691. }
  692. return color;
  693. }
  694. public static Fill DoFillOverlay(FillOverlay fillOverlay, PPTSlide slide, string partForm) {
  695. Fill fill = new Fill() { type = -1 };
  696. var gradFill = fillOverlay.GradientFill;
  697. if (gradFill != null)
  698. {
  699. fill.type = 2;
  700. fill.gradientFill = DoGradientFill(gradFill, slide);
  701. }
  702. var noFill = fillOverlay.NoFill;
  703. if (noFill != null)
  704. {
  705. fill.type = 0;
  706. }
  707. var pattFill = fillOverlay.PatternFill;
  708. if (pattFill != null)
  709. {
  710. HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
  711. fill.type = 4;
  712. fill.pattFill = htexPattFill;
  713. }
  714. var solidFill = fillOverlay.SolidFill;
  715. if (solidFill != null)
  716. {
  717. fill.type = 1;
  718. fill.solidFill = DoSolidFill(solidFill, slide);
  719. }
  720. var groupFill = fillOverlay.GroupFill;
  721. if (groupFill != null)
  722. {
  723. fill.type = 5;
  724. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  725. }
  726. var blipFill = fillOverlay.BlipFill;
  727. if (blipFill != null)
  728. {
  729. fill.type = 3;
  730. fill.blipFill = DoBlipFill(blipFill, slide, partForm);
  731. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  732. }
  733. return fill;
  734. }
  735. public static HTEXLib.Models.HTEX.ShapeStyle DoShapeProperties(DocumentFormat.OpenXml.Drawing.Charts.ShapeProperties shapeProperties, PPTSlide slide, string type, string partForm)
  736. {
  737. if (shapeProperties == null) {
  738. return null;
  739. }
  740. //Outline
  741. var lnNode = shapeProperties.GetFirstChild<Outline>();
  742. Border border = null;
  743. if (lnNode != null)
  744. {
  745. border = DoOutline(lnNode, slide, type);
  746. }
  747. Fill fill = new Fill() { type = -1 };
  748. var gradFill = shapeProperties.GetFirstChild<GradientFill>();
  749. if (gradFill != null)
  750. {
  751. fill.type = 2;
  752. fill.gradientFill = DoGradientFill(gradFill, slide);
  753. }
  754. var noFill = shapeProperties.GetFirstChild<NoFill>();
  755. if (noFill != null)
  756. {
  757. fill.type = 0;
  758. }
  759. var pattFill = shapeProperties.GetFirstChild<PatternFill>();
  760. if (pattFill != null)
  761. {
  762. HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
  763. fill.type = 4;
  764. fill.pattFill = htexPattFill;
  765. }
  766. var solidFill = shapeProperties.GetFirstChild<SolidFill>();
  767. if (solidFill != null)
  768. {
  769. fill.type = 1;
  770. fill.solidFill = DoSolidFill(solidFill, slide);
  771. }
  772. var groupFill = shapeProperties.GetFirstChild<GroupFill>();
  773. if (groupFill != null)
  774. {
  775. fill.type = 5;
  776. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  777. }
  778. var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
  779. if (blipFill != null)
  780. {
  781. fill.type = 3;
  782. fill.blipFill = DoBlipFill(blipFill, slide, partForm);
  783. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  784. }
  785. var EffectList = shapeProperties.GetFirstChild<EffectList>();
  786. var effect = doEffect(EffectList, slide,partForm);
  787. var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
  788. var Scene3DType = shapeProperties.GetFirstChild<Scene3DType>();
  789. var Shape3DType = shapeProperties.GetFirstChild<Shape3DType>();
  790. var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<ShapePropertiesExtensionList>();
  791. // CustomGeometry PresetGeometry TODO
  792. return new HTEXLib.Models.HTEX.ShapeStyle { fill = fill, border = border, effect=effect };
  793. }
  794. public static HTEXLib.Models.HTEX.ShapeStyle DoShapeProperties(ChartShapeProperties shapeProperties, PPTSlide slide, string type, string partForm,ChartPart chartPart)
  795. {
  796. if (chartPart != null) {
  797. slide.chartPart = chartPart;
  798. }
  799. //Outline
  800. var lnNode = shapeProperties.GetFirstChild<Outline>();
  801. Border border = null;
  802. if (lnNode != null)
  803. {
  804. border = DoOutline(lnNode, slide, type);
  805. }
  806. Fill fill = new Fill() { type = -1 };
  807. var gradFill = shapeProperties.GetFirstChild<GradientFill>();
  808. if (gradFill != null)
  809. {
  810. fill.type = 2;
  811. fill.gradientFill = DoGradientFill(gradFill, slide);
  812. }
  813. var noFill = shapeProperties.GetFirstChild<NoFill>();
  814. if (noFill != null)
  815. {
  816. fill.type = 0;
  817. }
  818. var pattFill = shapeProperties.GetFirstChild<PatternFill>();
  819. if (pattFill != null)
  820. {
  821. HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
  822. fill.type = 4;
  823. fill.pattFill = htexPattFill;
  824. }
  825. var solidFill = shapeProperties.GetFirstChild<SolidFill>();
  826. if (solidFill != null)
  827. {
  828. fill.type = 1;
  829. fill.solidFill = DoSolidFill(solidFill, slide);
  830. }
  831. var groupFill = shapeProperties.GetFirstChild<GroupFill>();
  832. if (groupFill != null)
  833. {
  834. fill.type = 5;
  835. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  836. }
  837. var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
  838. if (blipFill != null)
  839. {
  840. fill.type = 3;
  841. partForm = "chartPart";
  842. fill.blipFill = DoBlipFill(blipFill, slide, partForm);
  843. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  844. }
  845. var EffectList = shapeProperties.GetFirstChild<EffectList>();
  846. Models.HTEX. Effect effect= doEffect(EffectList, slide, partForm);
  847. var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
  848. var Scene3DType = shapeProperties.GetFirstChild<Scene3DType>();
  849. var Shape3DType = shapeProperties.GetFirstChild<Shape3DType>();
  850. var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<ShapePropertiesExtensionList>();
  851. // CustomGeometry PresetGeometry TODO
  852. return new HTEXLib.Models.HTEX.ShapeStyle { fill = fill, border = border ,effect= effect };
  853. }
  854. public static HTEXLib.Models.HTEX.ShapeStyle DoShapeProperties(GroupShapeProperties shapeProperties, PPTSlide slide, string type, string partForm)
  855. {
  856. //Outline
  857. var lnNode = shapeProperties.GetFirstChild<Outline>();
  858. Border border = null;
  859. if (lnNode != null)
  860. {
  861. border = DoOutline(lnNode, slide, type);
  862. }
  863. Fill fill = new Fill() { type = -1 };
  864. var gradFill = shapeProperties.GetFirstChild<GradientFill>();
  865. if (gradFill != null)
  866. {
  867. fill.type = 2;
  868. fill.gradientFill = DoGradientFill(gradFill, slide);
  869. }
  870. var noFill = shapeProperties.GetFirstChild<NoFill>();
  871. if (noFill != null)
  872. {
  873. fill.type = 0;
  874. }
  875. var pattFill = shapeProperties.GetFirstChild<PatternFill>();
  876. if (pattFill != null)
  877. {
  878. HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
  879. fill.type = 4;
  880. fill.pattFill = htexPattFill;
  881. }
  882. var solidFill = shapeProperties.GetFirstChild<SolidFill>();
  883. if (solidFill != null)
  884. {
  885. fill.type = 1;
  886. fill.solidFill = DoSolidFill(solidFill, slide);
  887. }
  888. var groupFill = shapeProperties.GetFirstChild<GroupFill>();
  889. if (groupFill != null)
  890. {
  891. fill.type = 5;
  892. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  893. }
  894. var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
  895. if (blipFill != null)
  896. {
  897. fill.type = 3;
  898. fill.blipFill = DoBlipFill(blipFill, slide, partForm);
  899. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  900. }
  901. var EffectList = shapeProperties.GetFirstChild<EffectList>();
  902. Models.HTEX.Effect effect = doEffect(EffectList, slide, partForm);
  903. var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
  904. var Scene3DType = shapeProperties.GetFirstChild<Scene3DType>();
  905. var Shape3DType = shapeProperties.GetFirstChild<Shape3DType>();
  906. var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<ShapePropertiesExtensionList>();
  907. return new HTEXLib.Models.HTEX.ShapeStyle { fill = fill, border = border ,effect=effect};
  908. }
  909. public static (HTEXLib.Models.HTEX.ShapeStyle,TbStyle) DoTableProperties(TableProperties shapeProperties, PPTSlide slide, string type, string partForm)
  910. {
  911. Fill fill = new Fill() { type = -1 };
  912. var gradFill = shapeProperties.GetFirstChild<GradientFill>();
  913. if (gradFill != null)
  914. {
  915. fill.type = 2;
  916. fill.gradientFill = DoGradientFill(gradFill, slide);
  917. }
  918. var noFill = shapeProperties.GetFirstChild<NoFill>();
  919. if (noFill != null)
  920. {
  921. fill.type = 0;
  922. }
  923. var pattFill = shapeProperties.GetFirstChild<PatternFill>();
  924. if (pattFill != null)
  925. {
  926. HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
  927. fill.type = 4;
  928. fill.pattFill = htexPattFill;
  929. }
  930. var solidFill = shapeProperties.GetFirstChild<SolidFill>();
  931. if (solidFill != null)
  932. {
  933. fill.type = 1;
  934. fill.solidFill = DoSolidFill(solidFill, slide);
  935. }
  936. var groupFill = shapeProperties.GetFirstChild<GroupFill>();
  937. if (groupFill != null)
  938. {
  939. fill.type = 5;
  940. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  941. }
  942. var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
  943. if (blipFill != null)
  944. {
  945. fill.type = 3;
  946. fill.blipFill = DoBlipFill(blipFill, slide, partForm);
  947. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  948. }
  949. TableStyleType TableStyle = shapeProperties.GetFirstChild<TableStyle>();
  950. if (TableStyle == null)
  951. {
  952. var TableStyleId = shapeProperties.GetFirstChild<TableStyleId>();
  953. if (TableStyleId != null) {
  954. var TableStyleEntrys = slide.tableStylesPart.TableStyleList.Elements<TableStyleEntry>();
  955. foreach (var TableStyleEntry in TableStyleEntrys)
  956. {
  957. if (TableStyleEntry.StyleId == TableStyleId.InnerText)
  958. {
  959. TableStyle = TableStyleEntry;
  960. }
  961. }
  962. }
  963. }
  964. (TbStyle tbStyle,Fill fillbg) = DoTableStyle(TableStyle,slide,type,partForm);
  965. var shapeStyle = new HTEXLib.Models.HTEX.ShapeStyle() ;
  966. if (fill != null)
  967. {
  968. shapeStyle.fill = fill;
  969. }
  970. else {
  971. shapeStyle.fill = fillbg;
  972. }
  973. if (shapeStyle.fill.type == -1)
  974. {
  975. shapeStyle.fill = null;
  976. }
  977. //TODO
  978. var EffectList = shapeProperties.GetFirstChild<EffectList>();
  979. var effect= doEffect(EffectList, slide, partForm);
  980. var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
  981. var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.ExtensionList>();
  982. tbStyle.rightToLeft = shapeProperties.RightToLeft != null? shapeProperties.RightToLeft.Value:false;
  983. tbStyle.firstRow = shapeProperties.FirstRow != null ? shapeProperties.FirstRow.Value : false;
  984. tbStyle.firstColumn = shapeProperties.FirstColumn != null ? shapeProperties.FirstColumn.Value : false;
  985. tbStyle.lastRow = shapeProperties.LastRow != null ? shapeProperties.LastRow.Value : false;
  986. tbStyle.lastColumn = shapeProperties.LastColumn != null ? shapeProperties.LastColumn.Value : false;
  987. tbStyle.bandRow = shapeProperties.BandRow != null ? shapeProperties.BandRow.Value : false;
  988. tbStyle.bandColumn = shapeProperties.BandColumn != null ? shapeProperties.BandColumn.Value : false;
  989. shapeStyle.effect = effect;
  990. return (shapeStyle,tbStyle);
  991. }
  992. public static (TbStyle, Fill) DoTableStyle(TableStyleType tableStyle, PPTSlide slide, string type, string partForm) {
  993. TbStyle tbStyle = new TbStyle();
  994. if (tableStyle == null) {
  995. return (tbStyle,null);
  996. }
  997. var TableBackground = tableStyle.TableBackground;
  998. Fill fill = null;
  999. if (TableBackground != null)
  1000. {
  1001. var shapeProperties = TableBackground.GetFirstChild<FillProperties>();
  1002. fill = DoFillProperties(shapeProperties , partForm,slide );
  1003. var FillReference = TableBackground.GetFirstChild<FillReference>();
  1004. fill= DoFillReference(slide, fill, FillReference);
  1005. if (fill.type == -1)
  1006. {
  1007. fill = null;
  1008. }
  1009. //TODO
  1010. TableBackground.GetFirstChild<EffectPropertiesType>();
  1011. string EffectColor = DoMatrixReferenceColors(TableBackground.GetFirstChild<EffectReference>(), slide);
  1012. }
  1013. //TablePartStyleType
  1014. List<CellStyle> cellStyles = new List<CellStyle>();
  1015. var WholeTable = tableStyle.WholeTable;
  1016. if (WholeTable != null) {
  1017. var style= DoTablePartStyleType(WholeTable, slide, type, partForm);
  1018. if (style != null) {
  1019. cellStyles.Add(style);
  1020. }
  1021. }
  1022. var Band1Horizontal = tableStyle.Band1Horizontal;
  1023. if (Band1Horizontal != null)
  1024. {
  1025. var style= DoTablePartStyleType(Band1Horizontal, slide, type, partForm);
  1026. if (style != null)
  1027. {
  1028. cellStyles.Add(style);
  1029. }
  1030. }
  1031. var Band2Horizontal = tableStyle.Band2Horizontal;
  1032. if (Band2Horizontal != null)
  1033. {
  1034. var style= DoTablePartStyleType(Band2Horizontal, slide, type, partForm);
  1035. if (style != null)
  1036. {
  1037. cellStyles.Add(style);
  1038. }
  1039. }
  1040. var Band1Vertical = tableStyle.Band1Vertical;
  1041. if (Band1Vertical != null)
  1042. {
  1043. var style= DoTablePartStyleType(Band1Vertical, slide, type, partForm);
  1044. if (style != null)
  1045. {
  1046. cellStyles.Add(style);
  1047. }
  1048. }
  1049. var Band2Vertical = tableStyle.Band2Vertical;
  1050. if (Band2Vertical != null)
  1051. {
  1052. var style= DoTablePartStyleType(Band2Vertical, slide, type, partForm);
  1053. if (style != null)
  1054. {
  1055. cellStyles.Add(style);
  1056. }
  1057. }
  1058. var LastColumn = tableStyle.LastColumn;
  1059. if (LastColumn != null)
  1060. {
  1061. var style= DoTablePartStyleType(LastColumn, slide, type, partForm);
  1062. if (style != null)
  1063. {
  1064. cellStyles.Add(style);
  1065. }
  1066. }
  1067. var FirstColumn = tableStyle.FirstColumn;
  1068. if (FirstColumn != null)
  1069. {
  1070. var style= DoTablePartStyleType(FirstColumn, slide, type, partForm);
  1071. if (style != null)
  1072. {
  1073. cellStyles.Add(style);
  1074. }
  1075. }
  1076. var FirstRow = tableStyle.FirstRow;
  1077. if (FirstRow != null)
  1078. {
  1079. var style= DoTablePartStyleType(FirstRow, slide, type, partForm);
  1080. if (style != null)
  1081. {
  1082. cellStyles.Add(style);
  1083. }
  1084. }
  1085. var LastRow = tableStyle.LastRow;
  1086. if (LastRow != null)
  1087. {
  1088. var style= DoTablePartStyleType(LastRow, slide, type, partForm);
  1089. if (style != null)
  1090. {
  1091. cellStyles.Add(style);
  1092. }
  1093. }
  1094. var SoutheastCell = tableStyle.SoutheastCell;
  1095. if (SoutheastCell != null)
  1096. {
  1097. var style= DoTablePartStyleType(SoutheastCell, slide, type, partForm);
  1098. if (style != null)
  1099. {
  1100. cellStyles.Add(style);
  1101. }
  1102. }
  1103. var SouthwestCell = tableStyle.SouthwestCell;
  1104. if (SouthwestCell != null)
  1105. {
  1106. var style= DoTablePartStyleType(SouthwestCell, slide, type, partForm);
  1107. if (style != null)
  1108. {
  1109. cellStyles.Add(style);
  1110. }
  1111. }
  1112. var NortheastCell = tableStyle.NortheastCell;
  1113. if (NortheastCell != null)
  1114. {
  1115. var style= DoTablePartStyleType(NortheastCell, slide, type, partForm);
  1116. if (style != null)
  1117. {
  1118. cellStyles.Add(style);
  1119. }
  1120. }
  1121. var NorthwestCell = tableStyle.NorthwestCell;
  1122. if (NorthwestCell != null)
  1123. {
  1124. var style= DoTablePartStyleType(NorthwestCell, slide, type, partForm);
  1125. if (style != null)
  1126. {
  1127. cellStyles.Add(style);
  1128. }
  1129. }
  1130. tbStyle.cellStyles = cellStyles;
  1131. var ExtensionList = tableStyle.ExtensionList;
  1132. return (tbStyle,fill);
  1133. }
  1134. private static Fill DoFillReference(PPTSlide slide, Fill fill, FillReference FillReference)
  1135. {
  1136. if (FillReference != null)
  1137. {
  1138. if (fill.type == -1)
  1139. {
  1140. string color = null;
  1141. if (FillReference.RgbColorModelPercentage != null)
  1142. {
  1143. color = ReadColor(FillReference.RgbColorModelPercentage);
  1144. }
  1145. if (FillReference.RgbColorModelHex != null)
  1146. {
  1147. color = ReadColor(FillReference.RgbColorModelHex);
  1148. }
  1149. if (FillReference.HslColor != null)
  1150. {
  1151. color = ReadColor(FillReference.HslColor);
  1152. }
  1153. if (FillReference.SystemColor != null)
  1154. {
  1155. color = ReadColor(FillReference.SystemColor, slide);
  1156. }
  1157. if (FillReference.SchemeColor != null)
  1158. {
  1159. color = ReadColor(FillReference.SchemeColor, slide);
  1160. }
  1161. if (FillReference.PresetColor != null)
  1162. {
  1163. color = ReadColor(FillReference.PresetColor);
  1164. }
  1165. fill.solidFill = color;
  1166. fill.type = 2;
  1167. }
  1168. }
  1169. return fill;
  1170. }
  1171. private static Fill DoFillProperties(FillProperties shapeProperties , string partForm, PPTSlide slide)
  1172. {
  1173. Fill fill = new Fill() { type = -1 };
  1174. if (shapeProperties != null)
  1175. {
  1176. var gradFill = shapeProperties.GetFirstChild<GradientFill>();
  1177. if (gradFill != null)
  1178. {
  1179. fill.type = 2;
  1180. fill.gradientFill = DoGradientFill(gradFill, slide);
  1181. }
  1182. var noFill = shapeProperties.GetFirstChild<NoFill>();
  1183. if (noFill != null)
  1184. {
  1185. fill.type = 0;
  1186. }
  1187. var pattFill = shapeProperties.GetFirstChild<PatternFill>();
  1188. if (pattFill != null)
  1189. {
  1190. HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
  1191. fill.type = 4;
  1192. fill.pattFill = htexPattFill;
  1193. }
  1194. var solidFill = shapeProperties.GetFirstChild<SolidFill>();
  1195. if (solidFill != null)
  1196. {
  1197. fill.type = 1;
  1198. fill.solidFill = DoSolidFill(solidFill, slide);
  1199. }
  1200. var groupFill = shapeProperties.GetFirstChild<GroupFill>();
  1201. if (groupFill != null)
  1202. {
  1203. fill.type = 5;
  1204. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  1205. }
  1206. var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
  1207. if (blipFill != null)
  1208. {
  1209. fill.type = 3;
  1210. fill.blipFill = DoBlipFill(blipFill, slide, partForm);
  1211. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  1212. }
  1213. }
  1214. return fill;
  1215. }
  1216. /// <summary>
  1217. /// 单元格样式表
  1218. /// </summary>
  1219. /// <param name="tablePartStyleType"></param>
  1220. /// <param name="slide"></param>
  1221. /// <param name="type"></param>
  1222. /// <param name="partForm"></param>
  1223. public static CellStyle DoTablePartStyleType(TablePartStyleType tablePartStyleType, PPTSlide slide, string type, string partForm) {
  1224. //表格单元格文本样式。
  1225. CellStyle cellStyle = new CellStyle() { type= tablePartStyleType.LocalName};
  1226. var TableCellTextStyle = tablePartStyleType.GetFirstChild<TableCellTextStyle>();
  1227. if (TableCellTextStyle != null) {
  1228. FontStyle fontStyle = new FontStyle { };
  1229. //字体加粗以及斜体
  1230. if (TableCellTextStyle.Bold != null && TableCellTextStyle.Bold.Value == BooleanStyleValues.On)
  1231. {
  1232. fontStyle.bold = true;
  1233. }
  1234. else {
  1235. fontStyle.bold = false;
  1236. }
  1237. if (TableCellTextStyle.Italic != null && TableCellTextStyle.Italic.Value == BooleanStyleValues.On)
  1238. {
  1239. fontStyle.italic = true;
  1240. }
  1241. //字体颜色
  1242. string color = null;
  1243. var RgbColorModelPercentage = TableCellTextStyle.GetFirstChild<RgbColorModelPercentage>();
  1244. if (RgbColorModelPercentage != null)
  1245. {
  1246. color = ReadColor(RgbColorModelPercentage);
  1247. }
  1248. var RgbColorModelHex = TableCellTextStyle.GetFirstChild<RgbColorModelHex>();
  1249. if (RgbColorModelHex != null)
  1250. {
  1251. color = ReadColor(RgbColorModelHex);
  1252. }
  1253. var HslColor = TableCellTextStyle.GetFirstChild<DocumentFormat.OpenXml.Drawing.HslColor>();
  1254. if (HslColor != null)
  1255. {
  1256. color = ReadColor(HslColor);
  1257. }
  1258. var SystemColor = TableCellTextStyle.GetFirstChild<SystemColor>();
  1259. if (SystemColor != null)
  1260. {
  1261. color = ReadColor(SystemColor, slide);
  1262. }
  1263. var SchemeColor = TableCellTextStyle.GetFirstChild<SchemeColor>();
  1264. if (SchemeColor != null)
  1265. {
  1266. color = ReadColor(SchemeColor, slide);
  1267. }
  1268. var PresetColor = TableCellTextStyle.GetFirstChild<PresetColor>();
  1269. if (PresetColor != null)
  1270. {
  1271. color = ReadColor(PresetColor);
  1272. }
  1273. fontStyle.color = color;
  1274. var FontReference = TableCellTextStyle.GetFirstChild<DocumentFormat.OpenXml.Drawing.FontReference>();
  1275. if (color == null && FontReference != null)
  1276. {
  1277. if (FontReference.RgbColorModelPercentage != null)
  1278. {
  1279. color = ReadColor(FontReference.RgbColorModelPercentage);
  1280. }
  1281. if (FontReference.RgbColorModelHex != null)
  1282. {
  1283. color = ReadColor(FontReference.RgbColorModelHex);
  1284. }
  1285. if (FontReference.HslColor != null)
  1286. {
  1287. color = ReadColor(FontReference.HslColor);
  1288. }
  1289. if (FontReference.SystemColor != null)
  1290. {
  1291. color = ReadColor(FontReference.SystemColor, slide);
  1292. }
  1293. if (FontReference.SchemeColor != null)
  1294. {
  1295. color = ReadColor(FontReference.SchemeColor, slide);
  1296. }
  1297. if (FontReference.PresetColor != null)
  1298. {
  1299. color = ReadColor(FontReference.PresetColor);
  1300. }
  1301. fontStyle.color = color;
  1302. }
  1303. //字体属性
  1304. var font = TableCellTextStyle.GetFirstChild<DocumentFormat.OpenXml.Drawing.Fonts>();
  1305. if (font != null) {
  1306. var LatinFont = font.LatinFont;
  1307. var EastAsianFont = font.EastAsianFont;
  1308. var ComplexScriptFont = font.ComplexScriptFont;
  1309. if (EastAsianFont != null)
  1310. {
  1311. fontStyle.family = DoTextFontType(EastAsianFont, slide);
  1312. }
  1313. if (ComplexScriptFont != null)
  1314. {
  1315. fontStyle.family = DoTextFontType(ComplexScriptFont, slide);
  1316. }
  1317. if (LatinFont != null)
  1318. {
  1319. fontStyle.family = DoTextFontType(LatinFont, slide);
  1320. }
  1321. var SupplementalFont = font.GetFirstChild<SupplementalFont>();
  1322. if (SupplementalFont != null)
  1323. {
  1324. fontStyle.family = SupplementalFont.Typeface;
  1325. }
  1326. cellStyle.fontStyle = fontStyle;
  1327. }
  1328. }
  1329. //表格单元格样式。
  1330. var TableCellStyle = tablePartStyleType.GetFirstChild<TableCellStyle>();
  1331. if (TableCellStyle != null)
  1332. {
  1333. List<CellBorder> cellBorders = new List<CellBorder>();
  1334. var TableCellBorders= TableCellStyle.TableCellBorders;
  1335. if (TableCellBorders != null) {
  1336. var LeftBorder = TableCellBorders.LeftBorder;
  1337. if (LeftBorder != null) {
  1338. Border border= DoOutline(LeftBorder.Outline, slide, type);
  1339. if (LeftBorder.LineReference!= null && (border.color.type == null || border.color.type == -1))
  1340. {
  1341. border.color.solidFill=DoMatrixReferenceColors(LeftBorder.LineReference, slide);
  1342. border.color.type = 2;
  1343. }
  1344. cellBorders.Add(new CellBorder() { border = border, type = "Left" });
  1345. }
  1346. var RightBorder = TableCellBorders.RightBorder;
  1347. if (RightBorder != null)
  1348. {
  1349. Border border = DoOutline(RightBorder.Outline, slide, type);
  1350. if (RightBorder.LineReference != null && (border.color.type == null || border.color.type == -1))
  1351. {
  1352. border.color.solidFill = DoMatrixReferenceColors(RightBorder.LineReference, slide);
  1353. border.color.type = 2;
  1354. }
  1355. cellBorders.Add(new CellBorder() { border = border, type = "Right" });
  1356. }
  1357. var TopBorder = TableCellBorders.TopBorder;
  1358. if (TopBorder != null)
  1359. {
  1360. Border border = DoOutline(TopBorder.Outline, slide, type);
  1361. if (TopBorder.LineReference != null && (border.color.type == null || border.color.type == -1))
  1362. {
  1363. border.color.solidFill = DoMatrixReferenceColors(TopBorder.LineReference, slide);
  1364. border.color.type = 2;
  1365. }
  1366. cellBorders.Add(new CellBorder() { border = border, type = "Top" });
  1367. }
  1368. var BottomBorder = TableCellBorders.BottomBorder;
  1369. if (BottomBorder != null)
  1370. {
  1371. Border border = DoOutline(BottomBorder.Outline, slide, type);
  1372. if (BottomBorder.LineReference != null && (border.color.type == null || border.color.type == -1))
  1373. {
  1374. border.color.solidFill = DoMatrixReferenceColors(BottomBorder.LineReference, slide);
  1375. border.color.type = 2;
  1376. }
  1377. cellBorders.Add(new CellBorder() { border = border, type = "Bottom" });
  1378. }
  1379. var InsideHorizontalBorder = TableCellBorders.InsideHorizontalBorder;
  1380. if (InsideHorizontalBorder != null)
  1381. {
  1382. Border border = DoOutline(InsideHorizontalBorder.Outline, slide, type);
  1383. if (InsideHorizontalBorder.LineReference != null && (border.color.type == null || border.color.type == -1))
  1384. {
  1385. border.color.solidFill = DoMatrixReferenceColors(InsideHorizontalBorder.LineReference, slide);
  1386. border.color.type = 2;
  1387. }
  1388. cellBorders.Add(new CellBorder() { border = border, type = "InHor" });
  1389. }
  1390. var InsideVerticalBorder = TableCellBorders.InsideVerticalBorder;
  1391. if (InsideVerticalBorder != null)
  1392. {
  1393. Border border = DoOutline(InsideVerticalBorder.Outline, slide, type);
  1394. if (InsideVerticalBorder.LineReference != null && (border.color.type == null || border.color.type == -1))
  1395. {
  1396. border.color.solidFill = DoMatrixReferenceColors(InsideVerticalBorder.LineReference, slide);
  1397. border.color.type = 2;
  1398. }
  1399. cellBorders.Add(new CellBorder() { border = border, type = "InVer" });
  1400. }
  1401. var TopLeftToBottomRightBorder = TableCellBorders.TopLeftToBottomRightBorder;
  1402. if (TopLeftToBottomRightBorder != null)
  1403. {
  1404. Border border = DoOutline(TopLeftToBottomRightBorder.Outline, slide, type);
  1405. if (TopLeftToBottomRightBorder.LineReference != null && (border.color.type == null || border.color.type == -1))
  1406. {
  1407. border.color.solidFill = DoMatrixReferenceColors(TopLeftToBottomRightBorder.LineReference, slide);
  1408. border.color.type = 2;
  1409. }
  1410. cellBorders.Add(new CellBorder() { border = border, type = "Tl2br" });
  1411. }
  1412. var TopRightToBottomLeftBorder = TableCellBorders.TopRightToBottomLeftBorder;
  1413. if (TopRightToBottomLeftBorder != null)
  1414. {
  1415. Border border = DoOutline(TopRightToBottomLeftBorder.Outline, slide, type);
  1416. if (TopRightToBottomLeftBorder.LineReference != null && (border.color.type == null || border.color.type == -1))
  1417. {
  1418. border.color.solidFill = DoMatrixReferenceColors(TopRightToBottomLeftBorder.LineReference, slide);
  1419. border.color.type = 2;
  1420. }
  1421. cellBorders.Add(new CellBorder() { border = border, type = "Tr2bl" });
  1422. }
  1423. }
  1424. cellStyle.cellBorders = cellBorders;
  1425. var FillProperties = TableCellStyle.GetFirstChild<FillProperties>();
  1426. Fill fill = DoFillProperties(FillProperties, partForm, slide);
  1427. var FillReference = TableCellStyle.GetFirstChild<FillReference>();
  1428. fill= DoFillReference(slide, fill, FillReference);
  1429. cellStyle.fill = fill;
  1430. if (cellStyle.fill.type == -1)
  1431. {
  1432. cellStyle.fill = null;
  1433. }
  1434. //TODO
  1435. var Cell3DProperties = TableCellStyle.GetFirstChild<Cell3DProperties>();
  1436. }
  1437. return cellStyle;
  1438. }
  1439. public static CellStyle DoTableCellProperties(TableCellProperties shapeProperties, PPTSlide slide ,string type ,string partForm) {
  1440. CellStyle cellStyle = new CellStyle();
  1441. //TODO
  1442. var Cell3DProperties = shapeProperties.GetFirstChild<Cell3DProperties>();
  1443. Fill fill = new Fill() { type = -1 };
  1444. var gradFill = shapeProperties.GetFirstChild<GradientFill>();
  1445. if (gradFill != null)
  1446. {
  1447. fill.type = 2;
  1448. fill.gradientFill = DoGradientFill(gradFill, slide);
  1449. }
  1450. var noFill = shapeProperties.GetFirstChild<NoFill>();
  1451. if (noFill != null)
  1452. {
  1453. fill.type = 0;
  1454. }
  1455. var pattFill = shapeProperties.GetFirstChild<PatternFill>();
  1456. if (pattFill != null)
  1457. {
  1458. HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
  1459. fill.type = 4;
  1460. fill.pattFill = htexPattFill;
  1461. }
  1462. var solidFill = shapeProperties.GetFirstChild<SolidFill>();
  1463. if (solidFill != null)
  1464. {
  1465. fill.type = 1;
  1466. fill.solidFill = DoSolidFill(solidFill, slide);
  1467. }
  1468. var groupFill = shapeProperties.GetFirstChild<GroupFill>();
  1469. if (groupFill != null)
  1470. {
  1471. fill.type = 5;
  1472. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  1473. }
  1474. var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
  1475. if (blipFill != null)
  1476. {
  1477. fill.type = 3;
  1478. fill.blipFill = DoBlipFill(blipFill, slide, partForm);
  1479. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  1480. }
  1481. cellStyle.fill = fill;
  1482. if (cellStyle.fill.type == -1)
  1483. {
  1484. cellStyle.fill = null;
  1485. }
  1486. List<CellBorder> cellBorders = new List<CellBorder>();
  1487. var LeftBorder = shapeProperties.LeftBorderLineProperties;
  1488. if (LeftBorder != null)
  1489. {
  1490. Border border = DoOutline(LeftBorder, slide, type);
  1491. cellBorders.Add(new CellBorder() { border = border, type = "Left" });
  1492. }
  1493. var RightBorder = shapeProperties.RightBorderLineProperties;
  1494. if (RightBorder != null)
  1495. {
  1496. Border border = DoOutline(RightBorder, slide, type);
  1497. cellBorders.Add(new CellBorder() { border = border, type = "Right" });
  1498. }
  1499. var TopBorderLineProperties = shapeProperties.TopBorderLineProperties;
  1500. if (TopBorderLineProperties != null)
  1501. {
  1502. Border border = DoOutline(TopBorderLineProperties, slide, type);
  1503. cellBorders.Add(new CellBorder() { border = border, type = "Top" });
  1504. }
  1505. var BottomBorderLineProperties = shapeProperties.BottomBorderLineProperties;
  1506. if (BottomBorderLineProperties != null)
  1507. {
  1508. Border border = DoOutline(BottomBorderLineProperties, slide, type);
  1509. cellBorders.Add(new CellBorder() { border = border, type = "Bottom" });
  1510. }
  1511. var TopLeftToBottomRightBorderLineProperties = shapeProperties.TopLeftToBottomRightBorderLineProperties;
  1512. if (TopLeftToBottomRightBorderLineProperties != null)
  1513. {
  1514. // \
  1515. Border border = DoOutline(TopLeftToBottomRightBorderLineProperties, slide, type);
  1516. cellBorders.Add(new CellBorder() { border = border, type = "Tl2br" });
  1517. }
  1518. var BottomLeftToTopRightBorderLineProperties = shapeProperties.BottomLeftToTopRightBorderLineProperties;
  1519. if (BottomLeftToTopRightBorderLineProperties != null)
  1520. { // /
  1521. Border border = DoOutline(BottomLeftToTopRightBorderLineProperties, slide, type);
  1522. cellBorders.Add(new CellBorder() { border = border, type = "Tr2bl" });
  1523. }
  1524. cellStyle.cellBorders = cellBorders;
  1525. return cellStyle;
  1526. }
  1527. /// <summary>
  1528. ///
  1529. /// </summary>
  1530. /// <param name="shapeProperties"></param>
  1531. /// <param name="slide"></param>
  1532. public static HTEXLib.Models.HTEX.ShapeStyle DoShapeProperties(DocumentFormat.OpenXml.Presentation.ShapeProperties shapeProperties, PPTSlide slide, string type, string partForm) {
  1533. //Outline
  1534. var lnNode = shapeProperties.GetFirstChild<Outline>();
  1535. Border border = null;
  1536. if (lnNode != null)
  1537. {
  1538. border = DoOutline(lnNode, slide,type);
  1539. }
  1540. Fill fill = new Fill() { type = -1 };
  1541. var gradFill = shapeProperties.GetFirstChild<GradientFill>();
  1542. if (gradFill != null)
  1543. {
  1544. fill.type = 2;
  1545. fill.gradientFill = DoGradientFill(gradFill, slide);
  1546. }
  1547. var noFill = shapeProperties.GetFirstChild<NoFill>();
  1548. if (noFill != null)
  1549. {
  1550. fill.type = 0;
  1551. }
  1552. var pattFill = shapeProperties.GetFirstChild<PatternFill>();
  1553. if (pattFill != null)
  1554. {
  1555. HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
  1556. fill.type = 4;
  1557. fill.pattFill = htexPattFill;
  1558. }
  1559. var solidFill = shapeProperties.GetFirstChild<SolidFill>();
  1560. if (solidFill != null)
  1561. {
  1562. fill.type = 1;
  1563. fill.solidFill = DoSolidFill(solidFill, slide);
  1564. }
  1565. var groupFill = shapeProperties.GetFirstChild<GroupFill>();
  1566. if (groupFill != null)
  1567. {
  1568. fill.type =5;
  1569. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  1570. }
  1571. var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
  1572. if (blipFill != null)
  1573. {
  1574. fill.type = 3;
  1575. fill.blipFill = DoBlipFill(blipFill, slide,partForm);
  1576. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  1577. }
  1578. var EffectList= shapeProperties.GetFirstChild<EffectList>();
  1579. var effect= doEffect(EffectList, slide, partForm);
  1580. var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
  1581. var Scene3DType = shapeProperties.GetFirstChild<Scene3DType>();
  1582. var Shape3DType = shapeProperties.GetFirstChild<Shape3DType>();
  1583. var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<ShapePropertiesExtensionList>();
  1584. return new HTEXLib.Models.HTEX.ShapeStyle {fill=fill,border= border ,effect= effect };
  1585. }
  1586. public static Fill DoBackgroundProperties(DocumentFormat.OpenXml.Presentation.BackgroundProperties shapeProperties, PPTSlide slide, string partForm)
  1587. {
  1588. Fill fill = new Fill() { type = -1 };
  1589. if (shapeProperties == null) {
  1590. return fill;
  1591. }
  1592. var gradFill = shapeProperties.GetFirstChild<GradientFill>();
  1593. if (gradFill != null)
  1594. {
  1595. fill.type = 2;
  1596. fill.gradientFill = DoGradientFill(gradFill, slide);
  1597. }
  1598. var noFill = shapeProperties.GetFirstChild<NoFill>();
  1599. if (noFill != null)
  1600. {
  1601. fill.type = 0;
  1602. }
  1603. var pattFill = shapeProperties.GetFirstChild<PatternFill>();
  1604. if (pattFill != null)
  1605. {
  1606. HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
  1607. fill.type = 4;
  1608. fill.pattFill = htexPattFill;
  1609. }
  1610. var solidFill = shapeProperties.GetFirstChild<SolidFill>();
  1611. if (solidFill != null)
  1612. {
  1613. fill.type = 1;
  1614. fill.solidFill = DoSolidFill(solidFill, slide);
  1615. }
  1616. var groupFill = shapeProperties.GetFirstChild<GroupFill>();
  1617. if (groupFill != null)
  1618. {
  1619. fill.type = 5;
  1620. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  1621. }
  1622. var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
  1623. if (blipFill != null)
  1624. {
  1625. fill.type = 3;
  1626. fill.blipFill = DoBlipFill(blipFill, slide,partForm);
  1627. // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
  1628. }
  1629. var EffectList = shapeProperties.GetFirstChild<EffectList>();
  1630. var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
  1631. //var Scene3DType = shapeProperties.GetFirstChild<Scene3DType>();
  1632. //var Shape3DType = shapeProperties.GetFirstChild<Shape3DType>();
  1633. //var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<ShapePropertiesExtensionList>();
  1634. return fill;
  1635. }
  1636. public static HtexBlipFill DoBlipFill(DocumentFormat.OpenXml.Drawing.BlipFill blipFill, PPTSlide slide,string partForm) {
  1637. HtexBlipFill htexBlipFill = new HtexBlipFill();
  1638. SourceRectangle source= blipFill.SourceRectangle; ///源矩形 srcRect可能无用
  1639. htexBlipFill.dip = blipFill.Dpi;
  1640. if (blipFill.RotateWithShape != null) {
  1641. htexBlipFill.rotWithShape = blipFill.RotateWithShape;
  1642. }
  1643. { htexBlipFill.rotWithShape =true; }
  1644. var fillRect = blipFill.GetPPTXNodeByPath("a:stretch/a:fillRect");///拉伸
  1645. if (fillRect != null) {
  1646. htexBlipFill.fillRect = new Vector
  1647. {
  1648. t = fillRect.Attribute("t") != null ? int.Parse(fillRect.Attribute("t").Value) / 1000 : 0,
  1649. l = fillRect.Attribute("l") != null ? int.Parse(fillRect.Attribute("l").Value) / 1000 : 0,
  1650. r = fillRect.Attribute("r") != null ? int.Parse(fillRect.Attribute("r").Value) / 1000 : 0,
  1651. b = fillRect.Attribute("b") != null ? int.Parse(fillRect.Attribute("b").Value) / 1000 : 0
  1652. };
  1653. }
  1654. var alphaModFix = blipFill.Blip.GetPPTXNodeByPath("a:alphaModFix");
  1655. if (alphaModFix != null) {
  1656. if (alphaModFix.Attribute("amt") != null) {
  1657. htexBlipFill.opacity = int.Parse(alphaModFix.Attribute("amt").Value) * 1.0 / 1000;
  1658. }
  1659. }
  1660. Tile tile= blipFill.GetFirstChild <Tile>();
  1661. if (tile != null) {
  1662. ///algn (Alignment) flip (Tile Flipping) sx (Horizontal Ratio) sy (Vertical Ratio) tx (Horizontal Offset) ty (Vertical Offset)
  1663. htexBlipFill.tile = new HtexTile { algn=tile.Alignment,flip=tile.Flip,sx=tile.HorizontalRatio,sy=tile.VerticalRatio,tx=tile.HorizontalOffset,ty=tile.VerticalOffset};
  1664. }
  1665. var Embed = blipFill.Blip.Embed;
  1666. var Link = blipFill.Blip.Link;
  1667. //slide.SlideLayoutPart
  1668. IdPartPair part = null;
  1669. if (partForm == "slide")
  1670. {
  1671. part = slide.SlidePart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
  1672. }
  1673. if (partForm == "layout")
  1674. {
  1675. part = slide.SlideLayoutPart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
  1676. }
  1677. if (partForm == "master")
  1678. {
  1679. part = slide.slideMasterPart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
  1680. }
  1681. if (partForm == "chartPart") {
  1682. part = slide.chartPart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
  1683. }
  1684. if (partForm == "drawing")
  1685. {
  1686. part = slide.diagramDataPart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
  1687. }
  1688. if (part != null) {
  1689. var url= part.OpenXmlPart.Uri .ToString().Replace("../","/ppt/");
  1690. var name = url.Replace("/", "");
  1691. var thumbnail = slide.Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
  1692. if (thumbnail != null)
  1693. {
  1694. var contentType = thumbnail.Attribute("{http://schemas.microsoft.com/office/2006/xmlPackage}contentType").Value;
  1695. //var data = thumbnail.Value;
  1696. //url = "data:" + contentType + ";base64," + data;
  1697. //url = url.Replace("\r\n", "");
  1698. htexBlipFill.url = name;
  1699. // htexBlipFill.urlType = "base64";
  1700. // htexBlipFill.contentType = contentType;
  1701. }
  1702. }
  1703. //TODO 图片元素的更多信息需要后期继续实现,如滤镜,裁剪,图片颜色,图片校正等
  1704. return htexBlipFill;
  1705. }
  1706. public static HtexBlipFill DoBlipFill(DocumentFormat.OpenXml.Presentation.BlipFill blipFill, PPTSlide slide, string partForm)
  1707. {
  1708. HtexBlipFill htexBlipFill = new HtexBlipFill();
  1709. SourceRectangle source = blipFill.SourceRectangle; ///源矩形 srcRect可能无用
  1710. htexBlipFill.dip = blipFill.Dpi;
  1711. if (blipFill.RotateWithShape != null)
  1712. {
  1713. htexBlipFill.rotWithShape = blipFill.RotateWithShape;
  1714. }
  1715. { htexBlipFill.rotWithShape = true; }
  1716. var fillRect = blipFill.GetPPTXNodeByPath("a:stretch/a:fillRect");///拉伸
  1717. if (fillRect != null)
  1718. {
  1719. htexBlipFill.fillRect = new Vector
  1720. {
  1721. t = fillRect.Attribute("t") != null ? int.Parse(fillRect.Attribute("t").Value) / 1000 : 0,
  1722. l = fillRect.Attribute("l") != null ? int.Parse(fillRect.Attribute("l").Value) / 1000 : 0,
  1723. r = fillRect.Attribute("r") != null ? int.Parse(fillRect.Attribute("r").Value) / 1000 : 0,
  1724. b = fillRect.Attribute("b") != null ? int.Parse(fillRect.Attribute("b").Value) / 1000 : 0
  1725. };
  1726. }
  1727. var alphaModFix = blipFill.Blip.GetPPTXNodeByPath("a:alphaModFix");
  1728. if (alphaModFix != null)
  1729. {
  1730. if (alphaModFix.Attribute("amt") != null)
  1731. {
  1732. htexBlipFill.opacity = int.Parse(alphaModFix.Attribute("amt").Value) * 1.0 / 1000;
  1733. }
  1734. }
  1735. Tile tile = blipFill.GetFirstChild<Tile>();
  1736. if (tile != null)
  1737. {
  1738. ///algn (Alignment) flip (Tile Flipping) sx (Horizontal Ratio) sy (Vertical Ratio) tx (Horizontal Offset) ty (Vertical Offset)
  1739. }
  1740. var Embed = blipFill.Blip.Embed;
  1741. var Link = blipFill.Blip.Link;
  1742. //slide.SlideLayoutPart
  1743. IdPartPair part = null;
  1744. if (partForm == "slide") {
  1745. part = slide.SlidePart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
  1746. }
  1747. if (partForm == "layout")
  1748. {
  1749. part = slide.SlideLayoutPart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
  1750. }
  1751. if (partForm == "master")
  1752. {
  1753. part = slide.slideMasterPart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
  1754. }
  1755. if (part != null)
  1756. {
  1757. var url = part.OpenXmlPart.Uri.ToString().Replace("../", "/ppt/");
  1758. var name = url.Replace("/", "");
  1759. var thumbnail = slide.Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
  1760. if (thumbnail != null)
  1761. {
  1762. //var contentType = thumbnail.Attribute("{http://schemas.microsoft.com/office/2006/xmlPackage}contentType").Value;
  1763. //var data = thumbnail.Value;
  1764. //url = "data:" + contentType + ";base64," + data;
  1765. //url = url.Replace("\r\n", "");
  1766. htexBlipFill.url = name;
  1767. // htexBlipFill.urlType = "base64";
  1768. // htexBlipFill.contentType = contentType;
  1769. }
  1770. }
  1771. //TODO 图片元素的更多信息需要后期继续实现,如滤镜,裁剪,图片颜色,图片校正等
  1772. return htexBlipFill;
  1773. }
  1774. /// <summary>
  1775. /// a:ln 图形的外边
  1776. /// </summary>
  1777. /// <param name="shapeProperties"></param>
  1778. /// <param name="slide"></param>
  1779. public static Border DoOutline(DocumentFormat.OpenXml.Drawing.LinePropertiesType outline, PPTSlide slide,string Shapetype) {
  1780. Border border = new Border() {color= new Fill { type=-1},type="none" };
  1781. //20.1.10.35 EMUs. 1 pt = 12700 EMUs.
  1782. double? Width = null;
  1783. if (outline == null && Shapetype== "CxnSp") {
  1784. return new Border { outline =new HtexOutline { width=0.5} ,type= "solid",stroke="0" };
  1785. }
  1786. if (outline.Width != null)
  1787. {
  1788. Width = double.Parse(outline.Width) * 1.0 * Globals.px96 / Globals.px914400;
  1789. }
  1790. else {
  1791. if (Shapetype == "CxnSp") {
  1792. Width = 0.75;
  1793. }
  1794. }
  1795. // Center = 0,Insert = 1
  1796. //
  1797. //20.1.10.39
  1798. string algn = null;
  1799. if (outline.Alignment != null) {
  1800. algn = outline.Alignment;
  1801. }
  1802. /* 20.1.10.15 复合类型
  1803. Single = 0, 单线 默认
  1804. Double = 1, 双细线
  1805. ThickThin = 2, 粗到细
  1806. ThinThick = 3, 细到粗
  1807. Triple = 4 三线
  1808. */
  1809. string cmpd = null ;
  1810. if (outline.CompoundLineType!=null) {
  1811. cmpd = outline.CompoundLineType;
  1812. }
  1813. /* 20.1.10.31 线端类型
  1814. Round = 0, 方
  1815. Square = 1,圆
  1816. Flat = 2 平
  1817. */
  1818. string cap =null;
  1819. if (outline.CapType != null) {
  1820. cap = outline.CapType;
  1821. }
  1822. border.outline = new HtexOutline { width = Width, algn = algn, cmpd = cmpd, cap = cap };
  1823. var gradFill = outline.GetFirstChild<GradientFill>();
  1824. if (gradFill != null)
  1825. {
  1826. border.color.type = 2;
  1827. border.color.gradientFill = DoGradientFill(gradFill, slide);
  1828. }
  1829. var noFill = outline.GetFirstChild<NoFill>();
  1830. if (noFill != null)
  1831. {
  1832. border.color.type = 0;
  1833. }
  1834. var pattFill = outline.GetFirstChild<PatternFill>();
  1835. if (pattFill != null)
  1836. {
  1837. HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
  1838. border.color.type = 4;
  1839. border.color.pattFill = htexPattFill;
  1840. }
  1841. var solidFill = outline.GetFirstChild<SolidFill>();
  1842. if (solidFill != null)
  1843. {
  1844. border.color.type = 1;
  1845. border.color.solidFill = DoSolidFill(solidFill, slide);
  1846. }
  1847. if (Width!=null && Width > 0) {
  1848. border.type = "solid";
  1849. border.stroke = "0";
  1850. }
  1851. var prstDash= outline.GetFirstChild<PresetDash>(); //预设连接符
  1852. if (prstDash != null) {
  1853. // PresetDash
  1854. var (type, stroke) = DoPrstDash(prstDash);
  1855. border.type = type;
  1856. border.stroke = stroke;
  1857. }
  1858. if (outline.GetFirstChild<Bevel>() != null) {
  1859. // 棱台切角
  1860. border.corner = "bevel";
  1861. }
  1862. if (outline.GetFirstChild<Round>()!=null) {
  1863. //圆角
  1864. border.corner = "round";
  1865. }
  1866. if (outline.GetFirstChild<Miter>() != null) {
  1867. //斜角
  1868. border.corner = "miter";
  1869. }
  1870. var headEndNodeAttrs = outline.GetFirstChild<HeadEnd>(); //连接符开始符号
  1871. if (headEndNodeAttrs != null)
  1872. {
  1873. border.headEnd = headEndNodeAttrs.Type;
  1874. }
  1875. var tailEndNodeAttrs = outline.GetFirstChild<TailEnd>();//末端连接符
  1876. if (tailEndNodeAttrs != null)
  1877. {
  1878. border.tailEnd = tailEndNodeAttrs.Type;
  1879. }
  1880. //TODO
  1881. //outline.GetTextByPath("//a:extLst");
  1882. var custDash = outline.GetFirstChild<CustomDash>();//自定义连接线
  1883. if (custDash != null) {
  1884. var(type, stroke) = DoCustDash(custDash);
  1885. border.type = type;
  1886. border.stroke = stroke;
  1887. }
  1888. if (border.color != null && (border.color.type !=null || border.color.type !=1) && border.outline.width==null) {
  1889. border.outline.width = 1;
  1890. if (border.type == "none"|| border.type==null) {
  1891. border.type = "solid";
  1892. border.stroke = "0";
  1893. }
  1894. }
  1895. return border;
  1896. }
  1897. /// <summary>
  1898. ///自定义连线符
  1899. /// </summary>
  1900. /// <param name="custDash"></param>
  1901. /// <returns></returns>
  1902. public static (string type, string stroke) DoCustDash(CustomDash custDash) {
  1903. string type = "cust";
  1904. string stroke = "0";
  1905. IEnumerable<XElement> elements= custDash.GetPPTXNodeListByPath("ds");
  1906. if (elements != null) {
  1907. foreach (XElement element in elements) {
  1908. var d= element.Attribute("d");//线段长度
  1909. if (d != null) {
  1910. stroke =stroke+ d.Value + ",";
  1911. }
  1912. var sp= element.Attribute("sp");//空白间距长度
  1913. if (sp != null) {
  1914. stroke =stroke+ sp.Value + ",";
  1915. }
  1916. }
  1917. }
  1918. if (string.IsNullOrEmpty(stroke)) {
  1919. stroke = "0";
  1920. }
  1921. if (stroke.EndsWith(",")) {
  1922. stroke.Substring(0, stroke.Length - 1);
  1923. }
  1924. return (type,stroke);
  1925. }
  1926. /// <summary>
  1927. /// 预设连线符
  1928. /// </summary>
  1929. /// <param name="presetDash"></param>
  1930. /// <returns></returns>
  1931. public static (string type, string stroke) DoPrstDash(PresetDash presetDash)
  1932. {
  1933. Border border = new Border() { type= "solid",stroke="0"
  1934. };
  1935. //PresetLineDashValues 枚举
  1936. string val = presetDash.Val;
  1937. switch (val)
  1938. {
  1939. case "solid":
  1940. border.type = "solid";
  1941. border.stroke = "0";
  1942. break;
  1943. case "dash":
  1944. border.type += "dashed";
  1945. border.stroke = "5";
  1946. break;
  1947. case "dashDot":
  1948. border.type = "dashed";
  1949. border.stroke = "5, 5, 1, 5";
  1950. break;
  1951. case "dot":
  1952. border.type = "dotted";
  1953. border.stroke = "1, 5";
  1954. break;
  1955. case "lgDash":
  1956. border.type = "dashed";
  1957. border.stroke = "10, 5";
  1958. break;
  1959. case "lgDashDotDot":
  1960. border.type = "dashed";
  1961. border.stroke = "10, 5, 1, 5, 1, 5";
  1962. break;
  1963. case "sysDash":
  1964. border.type = "dashed";
  1965. border.stroke = "5, 2";
  1966. break;
  1967. case "sysDashDot":
  1968. border.type = "dashed";
  1969. border.stroke = "5, 2, 1, 5";
  1970. break;
  1971. case "sysDashDotDot":
  1972. border.type = "dashed";
  1973. border.stroke = "5, 2, 1, 5, 1, 5";
  1974. break;
  1975. case "sysDot":
  1976. border.type = "dotted";
  1977. border.stroke = "2, 5";
  1978. break;
  1979. case null:
  1980. //console.log(borderType);
  1981. default:
  1982. border.type = "solid";
  1983. border.stroke = "0";
  1984. break;
  1985. }
  1986. return (border.type, border.stroke);
  1987. }
  1988. public static HtexPattFill DoPattFill(DocumentFormat.OpenXml.Drawing.PatternFill patternFill , PPTSlide slide) {
  1989. HtexPattFill htexPattFill = new HtexPattFill();
  1990. Color FgClr = Color.Empty;
  1991. Color BgClr = Color.Empty;
  1992. if (patternFill.ForegroundColor != null)
  1993. {
  1994. var fgClr = ColorTypeColors(patternFill.ForegroundColor, slide);
  1995. htexPattFill.fgClr = fgClr;
  1996. FgClr= ColorTranslator.FromHtml(fgClr);
  1997. }
  1998. if (patternFill.BackgroundColor != null)
  1999. {
  2000. var bgClr = ColorTypeColors(patternFill.BackgroundColor, slide);
  2001. htexPattFill.bgClr = bgClr;
  2002. BgClr= ColorTranslator.FromHtml(bgClr);
  2003. }
  2004. htexPattFill.prst = patternFill.Preset.ToString();
  2005. MemoryStream ms = new MemoryStream();
  2006. System.Drawing.Bitmap bm = PatternFillHelper.GetVmlPatternFill(patternFill.Preset, FgClr, BgClr);
  2007. Graphics graphics = Graphics.FromImage(bm);
  2008. graphics.Save();
  2009. graphics.Dispose();
  2010. bm.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  2011. byte[] arr = new byte[ms.Length];
  2012. ms.Position = 0;
  2013. ms.Read(arr, 0, (int)ms.Length);
  2014. ms.Close();
  2015. bm.Dispose();
  2016. string sImageData = "data:image/png;base64,"+ Convert.ToBase64String(arr);
  2017. htexPattFill.base64 = sImageData;
  2018. return htexPattFill;
  2019. }
  2020. /// <summary>
  2021. /// 渐变颜色
  2022. /// GradientStopList (渐变停止列表)(默认)
  2023. /// LinearGradientFill(线性渐变填充)
  2024. /// PathGradientFill (路径渐变)根据具体形状描边式
  2025. /// TileRectangle (平铺矩形) 右下角是一个举行
  2026. /// </summary>
  2027. /// <param name="GradientFill"></param>
  2028. /// <returns></returns>
  2029. public static HtexGradientFill DoGradientFill(DocumentFormat.OpenXml.Drawing.GradientFill GradientFill, PPTSlide slide)
  2030. {
  2031. HtexGradientFill gradientFill = new HtexGradientFill();
  2032. ///右下角弧形模式
  2033. string type = "";
  2034. ///平铺翻转模式
  2035. ///Horizontal 水平
  2036. ///HorizontalAndVertical 水平和垂直。
  2037. ///Vertical 垂直
  2038. ///None 无
  2039. string name = "None";
  2040. if (GradientFill.Flip != null) {
  2041. name = GradientFill.Flip.Value.ToString();
  2042. }
  2043. gradientFill.flip = name;
  2044. List<ColorPosition> colors = new List<ColorPosition>();
  2045. bool RotateWithShape = true;
  2046. if (GradientFill.RotateWithShape != null)
  2047. {
  2048. RotateWithShape = GradientFill.RotateWithShape;
  2049. }
  2050. gradientFill.RotateWithShape = RotateWithShape;
  2051. foreach (GradientStop gradientStop in GradientFill.GradientStopList)
  2052. {
  2053. colors.Add(new ColorPosition
  2054. {
  2055. color = ColorTypeColors(gradientStop, slide),
  2056. position = gradientStop.Position *1.0/ 1000 /// 位置,色带的位置 百分比0-100
  2057. });
  2058. }
  2059. gradientFill.colors = colors;
  2060. var lin = GradientFill.GetPPTXNodeByPath("//a:lin");
  2061. double? rot = null;
  2062. string scaled = "";
  2063. //线性模式
  2064. if (lin != null) {
  2065. rot = 90;
  2066. type = "line";
  2067. var ang = lin.Attribute("ang");
  2068. var scaledNode = lin.Attribute("scaled");
  2069. if (ang != null) {
  2070. rot= ShapeHelper.AngleToDegrees(ang.Value);
  2071. }
  2072. if (scaledNode != null) {
  2073. scaled = scaledNode.Value;
  2074. }
  2075. gradientFill.line = new LineFill { rot = rot, scaled = scaled };
  2076. }
  2077. var path = GradientFill.GetPPTXNodeByPath("//a:path");
  2078. if (path != null) {
  2079. type = "path";
  2080. ///circle
  2081. ///rect
  2082. ///shape
  2083. var pathType= path.Attribute("path").Value;
  2084. var fillToRect=path.GetPPTXNodeByPath("//a:fillToRect");
  2085. if (fillToRect != null) {
  2086. Vector vector= new Vector();
  2087. var bnode = fillToRect.Attribute("b");
  2088. var lnode = fillToRect.Attribute("l");
  2089. var rnode = fillToRect.Attribute("r");
  2090. var tnode = fillToRect.Attribute("t");
  2091. if (bnode != null)
  2092. {
  2093. vector.b= int.Parse(bnode.Value) / 1000;
  2094. }
  2095. if (lnode != null)
  2096. {
  2097. vector.l = int.Parse(lnode.Value) / 1000;
  2098. }
  2099. if (rnode != null)
  2100. {
  2101. vector.r = int.Parse(rnode.Value) / 1000;
  2102. }
  2103. if (tnode != null)
  2104. {
  2105. vector.t = int.Parse(tnode.Value) / 1000;
  2106. }
  2107. gradientFill.path =new PathFill {fillToRect= vector,pathType= pathType } ;
  2108. }
  2109. }
  2110. var tileRect = GradientFill.GetPPTXNodeByPath("//a:tileRect");
  2111. if (tileRect != null) {
  2112. ///四个方向的偏移量,矩形的下边缘。例如50000/1000= 50% ,辐射百分比
  2113. Vector vector = new Vector();
  2114. var bnode = tileRect.Attribute("b");
  2115. var lnode = tileRect.Attribute("l");
  2116. var rnode = tileRect.Attribute("r");
  2117. var tnode = tileRect.Attribute("t");
  2118. if (bnode != null)
  2119. {
  2120. vector.b = int.Parse(bnode.Value) / 1000;
  2121. }
  2122. if (lnode != null)
  2123. {
  2124. vector.l = int.Parse(lnode.Value) / 1000;
  2125. }
  2126. if (rnode != null)
  2127. {
  2128. vector.r = int.Parse(rnode.Value) / 1000;
  2129. }
  2130. if (tnode != null)
  2131. {
  2132. vector.t = int.Parse(tnode.Value) / 1000;
  2133. }
  2134. gradientFill.tileRect = vector;
  2135. }
  2136. gradientFill.type = type;
  2137. return gradientFill;
  2138. }
  2139. public static string ColorTypeColors(GradientStop Color, PPTSlide slide)
  2140. {
  2141. string FontColor = "";
  2142. if (Color.RgbColorModelHex != null)
  2143. {
  2144. FontColor = ReadColor(Color.RgbColorModelHex);
  2145. }
  2146. else if (Color.RgbColorModelPercentage != null)
  2147. {
  2148. FontColor = ReadColor(Color.RgbColorModelPercentage);
  2149. }
  2150. else if (Color.SystemColor != null)
  2151. {
  2152. FontColor = ReadColor(Color.SystemColor, slide);
  2153. }
  2154. if (Color.SchemeColor != null)
  2155. {
  2156. FontColor = ReadColor(Color.SchemeColor, slide);
  2157. }
  2158. if (Color.HslColor != null)
  2159. {
  2160. FontColor = ReadColor(Color.HslColor);
  2161. }
  2162. if (Color.PresetColor != null)
  2163. {
  2164. FontColor = ReadColor(Color.PresetColor);
  2165. }
  2166. return FontColor;
  2167. }
  2168. public static string ColorTypeColors(ColorType Color, PPTSlide slide)
  2169. {
  2170. string FontColor = "";
  2171. if (Color.RgbColorModelHex != null)
  2172. {
  2173. FontColor = ReadColor(Color.RgbColorModelHex);
  2174. }
  2175. else if (Color.RgbColorModelPercentage != null)
  2176. {
  2177. FontColor = ReadColor(Color.RgbColorModelPercentage);
  2178. }
  2179. else if (Color.SystemColor != null)
  2180. {
  2181. FontColor = ReadColor(Color.SystemColor, slide);
  2182. }
  2183. if (Color.SchemeColor != null)
  2184. {
  2185. FontColor = ReadColor(Color.SchemeColor, slide);
  2186. }
  2187. if (Color.HslColor != null)
  2188. {
  2189. FontColor = ReadColor(Color.HslColor);
  2190. }
  2191. if (Color.PresetColor != null)
  2192. {
  2193. FontColor = ReadColor(Color.PresetColor);
  2194. }
  2195. return FontColor;
  2196. }
  2197. public static string FontReferenceColors(FontReference Color, PPTSlide slide)
  2198. {
  2199. string FontColor = "";
  2200. if (Color.RgbColorModelHex != null)
  2201. {
  2202. FontColor = ReadColor(Color.RgbColorModelHex);
  2203. }
  2204. else if (Color.RgbColorModelPercentage != null)
  2205. {
  2206. FontColor = ReadColor(Color.RgbColorModelPercentage);
  2207. }
  2208. else if (Color.SystemColor != null)
  2209. {
  2210. FontColor = ReadColor(Color.SystemColor, slide);
  2211. }
  2212. if (Color.SchemeColor != null)
  2213. {
  2214. FontColor = ReadColor(Color.SchemeColor, slide);
  2215. }
  2216. if (Color.HslColor != null)
  2217. {
  2218. FontColor = ReadColor(Color.HslColor);
  2219. }
  2220. if (Color.PresetColor != null)
  2221. {
  2222. FontColor = ReadColor(Color.PresetColor);
  2223. }
  2224. return FontColor;
  2225. }
  2226. public static string DoMatrixReferenceColors(StyleMatrixReferenceType Color, PPTSlide slide) {
  2227. string FontColor = "";
  2228. if (Color == null) {
  2229. return FontColor;
  2230. }
  2231. if (Color.RgbColorModelHex != null)
  2232. {
  2233. FontColor = ReadColor(Color.RgbColorModelHex);
  2234. }
  2235. else if (Color.RgbColorModelPercentage != null)
  2236. {
  2237. FontColor = ReadColor(Color.RgbColorModelPercentage);
  2238. }
  2239. else if (Color.SystemColor != null)
  2240. {
  2241. FontColor = ReadColor(Color.SystemColor, slide);
  2242. }
  2243. if (Color.SchemeColor != null)
  2244. {
  2245. FontColor = ReadColor(Color.SchemeColor, slide);
  2246. }
  2247. if (Color.HslColor != null)
  2248. {
  2249. FontColor = ReadColor(Color.HslColor);
  2250. }
  2251. if (Color.PresetColor != null)
  2252. {
  2253. FontColor = ReadColor(Color.PresetColor);
  2254. }
  2255. return FontColor;
  2256. }
  2257. public static string DoSolidFill(SolidFill Color, PPTSlide slide)
  2258. {
  2259. string FontColor = "";
  2260. if (Color.RgbColorModelHex != null)
  2261. {
  2262. FontColor = ReadColor(Color.RgbColorModelHex);
  2263. }
  2264. else if (Color.RgbColorModelPercentage != null)
  2265. {
  2266. FontColor = ReadColor(Color.RgbColorModelPercentage);
  2267. }
  2268. else if (Color.SystemColor != null)
  2269. {
  2270. FontColor = ReadColor(Color.SystemColor, slide);
  2271. }
  2272. if (Color.SchemeColor != null)
  2273. {
  2274. FontColor = ReadColor(Color.SchemeColor, slide);
  2275. }
  2276. if (Color.HslColor != null)
  2277. {
  2278. FontColor = ReadColor(Color.HslColor);
  2279. }
  2280. if (Color.PresetColor != null)
  2281. {
  2282. FontColor= ReadColor(Color.PresetColor);
  2283. }
  2284. return FontColor;
  2285. }
  2286. public static string ReadColor(DocumentFormat.OpenXml.Drawing.RgbColorModelHex RgbColorModelHex)
  2287. {
  2288. string FontColor = "";
  2289. FontColor = "#" + RgbColorModelHex.Val;
  2290. FontColor = "#" + ShapeHelper.ColorToning(RgbColorModelHex.OuterXml, FontColor.Replace("#", "")).Replace("#","");
  2291. return FontColor;
  2292. }
  2293. public static string ReadColor(DocumentFormat.OpenXml.Drawing.RgbColorModelPercentage RgbColorModelPercentage)
  2294. {
  2295. string FontColor = "";
  2296. int red =RgbColorModelPercentage.RedPortion.Value;
  2297. int green = RgbColorModelPercentage.GreenPortion.Value;
  2298. int blue = RgbColorModelPercentage.BluePortion.Value;
  2299. var colorFromRGB = System.Drawing.Color.FromArgb(red, green, blue);
  2300. string fontcolor = System.Drawing.ColorTranslator.ToHtml(colorFromRGB);
  2301. FontColor = fontcolor;
  2302. FontColor = "#" + ShapeHelper.ColorToning(RgbColorModelPercentage.OuterXml, FontColor.Replace("#", "")).Replace("#", "");
  2303. return FontColor;
  2304. }
  2305. public static string ReadColor(DocumentFormat.OpenXml.Drawing.SystemColor SystemColor, PPTSlide slide)
  2306. {
  2307. string FontColor = "";
  2308. FontColor = "#" + SystemColor.LastColor.Value;
  2309. FontColor = "#" + ShapeHelper.ColorToning(SystemColor.OuterXml, FontColor.Replace("#", "")).Replace("#", "");
  2310. return FontColor;
  2311. }
  2312. public static string ReadColor(DocumentFormat.OpenXml.Drawing.SchemeColor SchemeColor,PPTSlide slide) {
  2313. string FontColor = "";
  2314. FontColor = DoSchemeColor(SchemeColor, slide);
  2315. FontColor = "#" + ShapeHelper.ColorToning(SchemeColor.OuterXml, FontColor.Replace("#", "")).Replace("#", "");
  2316. return FontColor;
  2317. }
  2318. public static string ReadColor(DocumentFormat.OpenXml.Drawing.HslColor HslColor)
  2319. {
  2320. string FontColor = "";
  2321. var hue =HslColor.HueValue / 100000;
  2322. var sat = HslColor.SatValue / 100;
  2323. var lum =HslColor.LumValue / 100;
  2324. var hsl2rgb = ShapeHelper.HslToRgb(hue, sat, lum);
  2325. FontColor = "#" + ShapeHelper.ToHex(hsl2rgb.r) + ShapeHelper.ToHex(hsl2rgb.g) + ShapeHelper.ToHex(hsl2rgb.b);
  2326. FontColor = "#" + ShapeHelper.ColorToning(HslColor.OuterXml, FontColor.Replace("#", "")).Replace("#", "");
  2327. return FontColor;
  2328. }
  2329. public static string ReadColor(PresetColor PresetColor) {
  2330. string FontColor = "";
  2331. //https://m.fontke.com/tool/rgb/0000ff/
  2332. //判断是否是拿到名字 还是值
  2333. FontColor = ShapeHelper.GetColorName2Hex(PresetColor.Val);
  2334. FontColor = "#" + ShapeHelper.ColorToning(PresetColor.OuterXml, FontColor.Replace("#", "")).Replace("#", "");
  2335. //TODO
  2336. return FontColor;
  2337. }
  2338. public static string DoTextFontType(TextFontType latinFonts, PPTSlide slide)
  2339. {
  2340. string FontFamily = "";
  2341. FontScheme allSchemeFonts =
  2342. slide.SlideLayoutPart.SlideMasterPart.ThemePart.Theme
  2343. .ThemeElements.FontScheme;
  2344. var minorFont = allSchemeFonts.GetFirstChild<MinorFont>();
  2345. var majorFont = allSchemeFonts.GetFirstChild<MajorFont>();
  2346. if (latinFonts != null)
  2347. {
  2348. FontFamily = latinFonts.Typeface.Value;
  2349. if (latinFonts.Typeface.Value.Equals("+mj-lt"))
  2350. {
  2351. FontFamily = majorFont.LatinFont.Typeface.Value;
  2352. }
  2353. else if (latinFonts.Typeface.Value.Equals("+mj-cs"))
  2354. {
  2355. FontFamily = majorFont.ComplexScriptFont.Typeface.Value;
  2356. }
  2357. else if (latinFonts.Typeface.Value.Equals("+mj-ea"))
  2358. {
  2359. FontFamily = majorFont.EastAsianFont.Typeface.Value;
  2360. }
  2361. else if (latinFonts.Typeface.Value.Equals("+mn-lt"))
  2362. {
  2363. FontFamily = minorFont.LatinFont.Typeface.Value;
  2364. }
  2365. else if (latinFonts.Typeface.Value.Equals("+mn-cs"))
  2366. {
  2367. FontFamily = minorFont.ComplexScriptFont.Typeface.Value;
  2368. }
  2369. else if (latinFonts.Typeface.Value.Equals("+mn-ea"))
  2370. {
  2371. FontFamily = minorFont.EastAsianFont.Typeface.Value;
  2372. }
  2373. }
  2374. return FontFamily;
  2375. }
  2376. public static string DoSchemeColor(SchemeColor schemeColor, PPTSlide slide)
  2377. {
  2378. //var light1Color1= slide.SlideLayoutPart.SlideMasterPart.
  2379. // ThemePart;
  2380. string FontColor = "";
  2381. if (schemeColor.Val == "bg1")
  2382. {
  2383. Light1Color light1Color = slide.SlideLayoutPart.SlideMasterPart.
  2384. ThemePart.Theme.ThemeElements.ColorScheme.Light1Color;
  2385. if (light1Color.RgbColorModelHex != null)
  2386. {
  2387. FontColor = "#" + light1Color.RgbColorModelHex.Val.Value;
  2388. }
  2389. else if (light1Color.SystemColor != null)
  2390. {
  2391. FontColor = "#" + light1Color.SystemColor.LastColor.Value;
  2392. }
  2393. }
  2394. else if (schemeColor.Val == "bg2")
  2395. {
  2396. Light2Color light2Color = slide.SlideLayoutPart.SlideMasterPart.
  2397. ThemePart.Theme.ThemeElements.ColorScheme.Light2Color;
  2398. if (light2Color.RgbColorModelHex != null)
  2399. {
  2400. FontColor = "#" + light2Color.RgbColorModelHex.Val.Value;
  2401. }
  2402. else if (light2Color.SystemColor != null)
  2403. {
  2404. FontColor = "#" + light2Color.SystemColor.LastColor.Value;
  2405. }
  2406. }
  2407. else if (schemeColor.Val == "tx1")
  2408. {
  2409. Dark1Color dark1Color = slide.SlideLayoutPart.SlideMasterPart.
  2410. ThemePart.Theme.ThemeElements.ColorScheme.Dark1Color;
  2411. if (dark1Color.RgbColorModelHex != null)
  2412. {
  2413. FontColor = "#" + dark1Color.RgbColorModelHex.Val.Value;
  2414. }
  2415. else if (dark1Color.SystemColor != null)
  2416. {
  2417. FontColor = "#" + dark1Color.SystemColor.LastColor.Value;
  2418. }
  2419. }
  2420. else if (schemeColor.Val == "tx2")
  2421. {
  2422. Dark2Color dark2Color = slide.SlideLayoutPart.SlideMasterPart.
  2423. ThemePart.Theme.ThemeElements.ColorScheme.Dark2Color;
  2424. if (dark2Color.RgbColorModelHex != null)
  2425. {
  2426. FontColor = "#" + dark2Color.RgbColorModelHex.Val.Value;
  2427. }
  2428. else if (dark2Color.SystemColor != null)
  2429. {
  2430. FontColor = "#" + dark2Color.SystemColor.LastColor.Value;
  2431. }
  2432. }
  2433. else if (schemeColor.Val == "hlink")
  2434. {
  2435. Hyperlink HyperLink = slide.SlideLayoutPart.SlideMasterPart.
  2436. ThemePart.Theme.ThemeElements.ColorScheme.Hyperlink;
  2437. if (HyperLink.RgbColorModelHex != null)
  2438. {
  2439. FontColor = "#" + HyperLink.RgbColorModelHex.Val.Value;
  2440. }
  2441. }
  2442. else if (schemeColor.Val == "folHlink")
  2443. {
  2444. FollowedHyperlinkColor folHyperLink = slide.SlideLayoutPart.SlideMasterPart.
  2445. ThemePart.Theme.ThemeElements.ColorScheme.FollowedHyperlinkColor;
  2446. if (folHyperLink.RgbColorModelHex != null)
  2447. {
  2448. FontColor = "#" + folHyperLink.RgbColorModelHex.Val.Value;
  2449. }
  2450. }
  2451. if (string.IsNullOrEmpty(FontColor)) {
  2452. FontColor = ReadAccentSchemeColors(schemeColor, slide);
  2453. }
  2454. if (FontColor.Replace("#", "") == "") {
  2455. var chren= slide.SlideLayoutPart.SlideMasterPart.ThemePart.Theme.ThemeElements.ColorScheme.ChildElements;
  2456. foreach(var cl in chren) {
  2457. if (schemeColor.Val == cl.LocalName) {
  2458. if (schemeColor.Val == "dk1" || schemeColor.Val == "lt1")
  2459. {
  2460. if (cl.GetFirstChild<SystemColor>() != null)
  2461. {
  2462. FontColor = "#" + cl.GetFirstChild<SystemColor>().LastColor;
  2463. }
  2464. else {
  2465. FontColor = "#" + cl.GetFirstChild<RgbColorModelHex>().Val.Value; ;
  2466. }
  2467. }
  2468. else {
  2469. FontColor ="#"+cl.GetFirstChild<RgbColorModelHex>().Val.Value; ;
  2470. }
  2471. }
  2472. }
  2473. }
  2474. return FontColor;
  2475. }
  2476. public static string ReadAccentSchemeColors(SchemeColor schemeColor, PPTSlide slide)
  2477. {
  2478. string FontColor = "";
  2479. for (int i = 1; i <= 6; i++)
  2480. {
  2481. if (schemeColor.Val == "accent" + i)
  2482. {
  2483. switch (i)
  2484. {
  2485. case 1:
  2486. {
  2487. Accent1Color c = slide.SlideLayoutPart.SlideMasterPart.
  2488. ThemePart.Theme.ThemeElements.ColorScheme.Accent1Color;
  2489. if (c.RgbColorModelHex != null)
  2490. FontColor = "#" + c.RgbColorModelHex.Val.Value;
  2491. }
  2492. break;
  2493. case 2:
  2494. {
  2495. Accent2Color c = slide.SlideLayoutPart.SlideMasterPart.
  2496. ThemePart.Theme.ThemeElements.ColorScheme.Accent2Color;
  2497. if (c.RgbColorModelHex != null)
  2498. FontColor = "#" + c.RgbColorModelHex.Val.Value;
  2499. }
  2500. break;
  2501. case 3:
  2502. {
  2503. Accent3Color c = slide.SlideLayoutPart.SlideMasterPart.
  2504. ThemePart.Theme.ThemeElements.ColorScheme.Accent3Color;
  2505. if (c.RgbColorModelHex != null)
  2506. FontColor = "#" + c.RgbColorModelHex.Val.Value;
  2507. }
  2508. break;
  2509. case 4:
  2510. {
  2511. Accent4Color c = slide.SlideLayoutPart.SlideMasterPart.
  2512. ThemePart.Theme.ThemeElements.ColorScheme.Accent4Color;
  2513. if (c.RgbColorModelHex != null)
  2514. FontColor = "#" + c.RgbColorModelHex.Val.Value;
  2515. }
  2516. break;
  2517. case 5:
  2518. {
  2519. Accent5Color c = slide.SlideLayoutPart.SlideMasterPart.
  2520. ThemePart.Theme.ThemeElements.ColorScheme.Accent5Color;
  2521. if (c.RgbColorModelHex != null)
  2522. FontColor = "#" + c.RgbColorModelHex.Val.Value;
  2523. }
  2524. break;
  2525. case 6:
  2526. {
  2527. Accent6Color c = slide.SlideLayoutPart.SlideMasterPart.
  2528. ThemePart.Theme.ThemeElements.ColorScheme.Accent6Color;
  2529. if (c.RgbColorModelHex != null)
  2530. FontColor = "#" + c.RgbColorModelHex.Val.Value;
  2531. }
  2532. break;
  2533. default: { } break;
  2534. }
  2535. }
  2536. }
  2537. return FontColor;
  2538. }
  2539. }
  2540. }