PPTXHelper.cs 97 KB

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