PPTXHelper.cs 79 KB

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