ShapeHelper.cs 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  1. using TEAMModelOS.Service.Model.PowerPoint;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Xml;
  7. using TEAMModelOS.SDK.Helper.Common.ColorHelper;
  8. using TEAMModelOS.Service.Models.PowerPoint.Inner;
  9. namespace TEAMModelOS.Service.Services.PowerPoint.Implement
  10. {
  11. public static class ShapeHelper
  12. {
  13. private const int degree = 4;
  14. private const double px96 = 96.00, px72 = 72.00, px914400 = 914400.00, px12700 = 12700.00;
  15. private const double rot60000 = 60000.00;
  16. public static XmlNamespaceManager xmlnsManager;
  17. public static XmlNode GetTextByPath(this XmlDocument document, string expression)
  18. {
  19. return document.SelectSingleNode(expression, xmlnsManager);
  20. }
  21. public static XmlNode GetTextByPath(this XmlNode node, string expression)
  22. {
  23. return node.SelectSingleNode(expression, xmlnsManager);
  24. }
  25. public static XmlNodeList GetTextByPathList(this XmlDocument document, string expression)
  26. {
  27. return document.SelectNodes(expression, xmlnsManager);
  28. }
  29. public static XmlNodeList GetTextByPathList(this XmlNode node, string expression)
  30. {
  31. return node.SelectNodes(expression, xmlnsManager);
  32. }
  33. static ShapeHelper()
  34. {
  35. xmlnsManager = new XmlNamespaceManager(new NameTable());
  36. xmlnsManager.AddNamespace("p", "http://schemas.openxmlformats.org/presentationml/2006/main");
  37. xmlnsManager.AddNamespace("a", "http://schemas.openxmlformats.org/drawingml/2006/main");
  38. xmlnsManager.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
  39. xmlnsManager.AddNamespace("fo", "http://www.w3.org/1999/XSL/Format");
  40. xmlnsManager.AddNamespace("app", "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties");
  41. xmlnsManager.AddNamespace("cp", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
  42. xmlnsManager.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");
  43. xmlnsManager.AddNamespace("dcterms", "http://purl.org/dc/terms/");
  44. xmlnsManager.AddNamespace("dcmitype", "http://purl.org/dc/dcmitype/");
  45. xmlnsManager.AddNamespace("rel", "http://schemas.openxmlformats.org/package/2006/relationships");
  46. xmlnsManager.AddNamespace("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
  47. xmlnsManager.AddNamespace("cus", "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties");
  48. xmlnsManager.AddNamespace("vt", "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");
  49. xmlnsManager.AddNamespace("pic", "http://schemas.openxmlformats.org/drawingml/2006/picture");
  50. xmlnsManager.AddNamespace("dsp", "http://schemas.microsoft.com/office/drawing/2008/diagram");
  51. xmlnsManager.AddNamespace("dgm", "http://schemas.openxmlformats.org/drawingml/2006/diagram");
  52. xmlnsManager.AddNamespace("a14", "http://schemas.microsoft.com/office/drawing/2010/main");
  53. xmlnsManager.AddNamespace("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
  54. xmlnsManager.AddNamespace("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
  55. xmlnsManager.AddNamespace("p14", "http://schemas.microsoft.com/office/powerpoint/2010/main");
  56. xmlnsManager.AddNamespace("pkg", "http://schemas.microsoft.com/office/2006/xmlPackage");
  57. xmlnsManager.AddNamespace("p15", "http://schemas.microsoft.com/office/powerpoint/2012/main");
  58. xmlnsManager.AddNamespace("a16", "http://schemas.microsoft.com/office/drawing/2014/main");
  59. xmlnsManager.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
  60. xmlnsManager.AddNamespace("c", "http://schemas.openxmlformats.org/drawingml/2006/chart");
  61. xmlnsManager.AddNamespace("c14", "http://schemas.microsoft.com/office/drawing/2007/8/2/chart");
  62. xmlnsManager.AddNamespace("c16", "http://schemas.microsoft.com/office/drawing/2014/chart");
  63. xmlnsManager.AddNamespace("cs", "http://schemas.microsoft.com/office/drawing/2012/chartStyle");
  64. xmlnsManager.AddNamespace("thm15", "http://schemas.microsoft.com/office/thememl/2012/main");
  65. xmlnsManager.AddNamespace("fn", "http://www.w3.org/2005/xpath-functions");
  66. }
  67. /// <summary>
  68. /// 调色补充 Shade Tint LumMod LumOff 等
  69. /// </summary>
  70. /// <param name="nodeXml"></param>
  71. /// <param name="colorHex"></param>
  72. /// <returns></returns>
  73. public static string ColorToning(string nodeXml, string colorHex)
  74. {
  75. if (string.IsNullOrEmpty(colorHex)) { return null; }
  76. TEAMModelOS.SDK.Helper.Common.ColorHelper.ColorConverter converter = new TEAMModelOS.SDK.Helper.Common.ColorHelper.ColorConverter();
  77. XmlDocument doc = new XmlDocument();
  78. doc.LoadXml(nodeXml);
  79. XmlNode tint = doc.SelectSingleNode("//a:tint/@val", xmlnsManager);
  80. if (tint != null)
  81. {
  82. colorHex = converter.SetTint(colorHex, double.Parse(tint.Value));
  83. }
  84. XmlNode hueMod = doc.SelectSingleNode("//a:hueMod/@val", xmlnsManager);
  85. if (hueMod != null)
  86. {
  87. colorHex = converter.SetHueMod(colorHex, double.Parse(hueMod.Value));
  88. }
  89. XmlNode satMod = doc.SelectSingleNode("//a:satMod/@val", xmlnsManager);
  90. if (satMod != null)
  91. {
  92. colorHex = converter.SetSaturationMod(colorHex, double.Parse(satMod.Value));
  93. }
  94. XmlNode satOff = doc.SelectSingleNode("//a:satOff/@val", xmlnsManager);
  95. if (satOff != null)
  96. {
  97. colorHex = converter.SetSaturationOff(colorHex, double.Parse(satOff.Value));
  98. }
  99. XmlNode lumMod = doc.SelectSingleNode("//a:lumMod/@val", xmlnsManager);
  100. if (lumMod != null)
  101. {
  102. colorHex = converter.SetLuminanceMod(colorHex, double.Parse(lumMod.Value));
  103. }
  104. XmlNode lumOff = doc.SelectSingleNode("//a:lumOff/@val", xmlnsManager);
  105. if (lumOff != null)
  106. {
  107. colorHex = converter.SetLuminanceOff(colorHex, double.Parse(lumOff.Value));
  108. }
  109. XmlNode hueOff = doc.SelectSingleNode("//a:hueOff/@val", xmlnsManager);
  110. if (hueOff != null)
  111. {
  112. colorHex = converter.SetHueOff(colorHex, double.Parse(hueOff.Value));
  113. }
  114. XmlNode alphaOff = doc.SelectSingleNode("//a:alphaOff/@val", xmlnsManager);
  115. if (alphaOff != null)
  116. {
  117. // Color color= ColorTranslator.FromHtml("#" + colorHex);
  118. // color = Color.FromArgb(byte.Parse(int.Parse(alpha.Value)/100000+""),color.R,color.G,color.B);
  119. }
  120. XmlNode shade = doc.SelectSingleNode("//a:shade/@val", xmlnsManager);
  121. if (shade != null)
  122. {
  123. colorHex = converter.SetShade(colorHex, double.Parse(shade.Value));
  124. }
  125. XmlNode alpha = doc.SelectSingleNode("//a:alpha/@val", xmlnsManager);
  126. if (alpha != null)
  127. {
  128. // Color color= ColorTranslator.FromHtml("#" + colorHex);
  129. // color = Color.FromArgb(byte.Parse(int.Parse(alpha.Value)/100000+""),color.R,color.G,color.B);
  130. }
  131. return colorHex;
  132. }
  133. public static Border GetBorder(XmlNode node, bool isSvgMode, string bType, Dictionary<string, string> slideLayoutClrOvride, XmlNode slideMasterContent , XmlNode themeContent)
  134. {
  135. var borderWidth = 0.0;
  136. if (node.Name.Equals("p:cxnSp"))
  137. {
  138. borderWidth = 0.75;
  139. }
  140. Border border = new Border() { width = borderWidth };
  141. XmlNode lineNode = null;
  142. if (bType == "shape")
  143. {
  144. // cssText = "border: ";
  145. lineNode = node.GetTextByPath("p:spPr/a:ln");// node["p:spPr"]["a:ln"];
  146. }
  147. else if (bType == "text")
  148. {
  149. // cssText = "";
  150. lineNode = ShapeHelper.GetTextByPath(node, "a:rPr/a:ln");// node["a:rPr"]["a:ln"];
  151. }
  152. if (lineNode != null)
  153. {
  154. XmlNode wnode = lineNode.GetTextByPath("@w");
  155. if (wnode != null)
  156. {
  157. border.width = double.Parse(wnode.Value) / px12700;
  158. }
  159. // Border width: 1pt = 12700, default = 0.75pt
  160. // borderWidth = double.Parse(ShapeHelper.GetTextByPath(lineNode, "@w").Value) / px12700;
  161. //if (wnode != null || borderWidth < 1)
  162. //{
  163. // cssText += "0pt ";
  164. //}
  165. //else
  166. //{
  167. // borderWidth=
  168. // cssText += borderWidth + "pt ";
  169. //}
  170. }
  171. // Border type
  172. if (lineNode != null)
  173. {
  174. var borderType = ShapeHelper.GetTextByPath(lineNode, "a:prstDash/@val");
  175. if (borderType != null)
  176. {
  177. switch (borderType.Value)
  178. {
  179. case "solid":
  180. border.type = "solid";
  181. border.stroke = "0";
  182. break;
  183. case "dash":
  184. border.type += "dashed";
  185. border.stroke = "5";
  186. break;
  187. case "dashDot":
  188. border.type = "dashed";
  189. border.stroke = "5, 5, 1, 5";
  190. break;
  191. case "dot":
  192. border.type = "dotted";
  193. border.stroke = "1, 5";
  194. break;
  195. case "lgDash":
  196. border.type = "dashed";
  197. border.stroke = "10, 5";
  198. break;
  199. case "lgDashDotDot":
  200. border.type = "dashed";
  201. border.stroke = "10, 5, 1, 5, 1, 5";
  202. break;
  203. case "sysDash":
  204. border.type = "dashed";
  205. border.stroke = "5, 2";
  206. break;
  207. case "sysDashDot":
  208. border.type = "dashed";
  209. border.stroke = "5, 2, 1, 5";
  210. break;
  211. case "sysDashDotDot":
  212. border.type = "dashed";
  213. border.stroke = "5, 2, 1, 5, 1, 5";
  214. break;
  215. case "sysDot":
  216. border.type = "dotted";
  217. border.stroke = "2, 5";
  218. break;
  219. case null:
  220. //console.log(borderType);
  221. default:
  222. border.type = "solid";
  223. border.stroke = "0";
  224. break;
  225. }
  226. }
  227. }
  228. else {
  229. border.type = "solid";
  230. border.stroke = "0";
  231. }
  232. // Border color
  233. string borderColorstr = "";
  234. if (lineNode != null) {
  235. //var borderColor = ShapeHelper.GetTextByPath(lineNode, "a:solidFill/a:srgbClr/@val");
  236. //if (borderColor == null)
  237. //{
  238. // var schemeClrNode = ShapeHelper.GetTextByPathList(lineNode, "a:solidFill/a:schemeClr");
  239. // if (schemeClrNode != null)
  240. // {
  241. // var schemeClr = ShapeHelper.GetTextByPath(lineNode, "a:solidFill/a:schemeClr/@val");
  242. // borderColorstr = GetSchemeColorFromTheme(schemeClr.Value, null, slideLayoutClrOvride, themeContent);
  243. // borderColorstr = ShapeHelper.ColorToning(lineNode.OuterXml, borderColorstr);
  244. // }
  245. //}
  246. borderColorstr= GetSolidFill(lineNode, slideLayoutClrOvride, slideMasterContent, themeContent);
  247. borderColorstr = ShapeHelper.ColorToning(lineNode.OuterXml, borderColorstr);
  248. }
  249. // 2. drawingML namespace
  250. if (string.IsNullOrEmpty(borderColorstr))
  251. {
  252. XmlNode lnRefNode = ShapeHelper.GetTextByPath(node, "p:style/a:lnRef");
  253. if (lnRefNode != null) {
  254. borderColorstr = GetSolidFill(lnRefNode, slideLayoutClrOvride, slideMasterContent, themeContent);
  255. borderColorstr = ShapeHelper.ColorToning(lnRefNode.OuterXml, borderColorstr);
  256. }
  257. //var schemeClrNode = ShapeHelper.GetTextByPathList(node, "p:style/a:lnRef/a:schemeClr");
  258. //if (schemeClrNode != null)
  259. //{
  260. // var schemeClr = ShapeHelper.GetTextByPath(node, "p:style/a:lnRef/a:schemeClr/@val");
  261. // if (schemeClr != null)
  262. // {
  263. // borderColorstr = GetSchemeColorFromTheme(schemeClr.Value, null, slideLayoutClrOvride, themeContent);
  264. // }
  265. //}
  266. //if (borderColor != null)
  267. //{
  268. // var shade = ShapeHelper.GetTextByPath(node, "p:style/a:lnRef/a:schemeClr/a:shade/@val");
  269. // if (shade != null)
  270. // {
  271. // double shaded = double.Parse(shade.Value) / 100000.0;
  272. // var color = ColorTranslator.FromHtml("#" + borderColor);
  273. // ColorHSL colorHSL = ColorHelper.RgbToHsl(new ColorRGB(color.R, color.G, color.B));
  274. // colorHSL.L = colorHSL.L * shaded;
  275. // ColorRGB colorRGB = colorHSL.HslToRgb();
  276. // borderColorstr = ColorTranslator.ToHtml(Color.FromArgb(colorRGB.R, colorRGB.G, colorRGB.B));
  277. // // borderColor = color.hex.replace("#", "");
  278. // }
  279. //}
  280. }
  281. if (!string.IsNullOrEmpty(borderColorstr)) {
  282. border.color = borderColorstr;
  283. if (border.width == 0.0) {
  284. border.width = 1;
  285. }
  286. }
  287. return border;
  288. //if (borderColor == null)
  289. //{
  290. // if (isSvgMode)
  291. // {
  292. // borderColorstr = "none";
  293. // }
  294. // else
  295. // {
  296. // borderColorstr = "#000";
  297. // }
  298. //}
  299. //else
  300. //{
  301. // borderColorstr = "#" + borderColorstr;
  302. //}
  303. //cssText += " " + borderColor + " ";
  304. //if (borderType != null)
  305. //{
  306. // if (isSvgMode)
  307. // {
  308. // return new Border { Color = borderColorstr, Width = (int)borderWidth, Type = borderType.Value, Stroke = strokeDasharray };
  309. // }
  310. // else
  311. // {
  312. // return border;
  313. // }
  314. //}
  315. //else
  316. //{
  317. // if (isSvgMode)
  318. // {
  319. // return new Border { Color = borderColorstr, Width = (int)borderWidth, Type = "", Stroke = strokeDasharray };
  320. // }
  321. // else
  322. // {
  323. // return border;
  324. // }
  325. //}
  326. }
  327. public static string GetSchemeColorFromTheme(string schemeClr, XmlNode sldMasterNode, Dictionary<string, string> slideLayoutClrOvride, XmlNode themeContent)
  328. {
  329. //<p:clrMap ...> in slide master
  330. // e.g. tx2="dk2" bg2="lt2" tx1="dk1" bg1="lt1" slideLayoutClrOvride
  331. if (slideLayoutClrOvride == null || slideLayoutClrOvride.Count <= 0)
  332. {
  333. if (sldMasterNode != null)
  334. {
  335. var sldLayoutClrOvr = ShapeHelper.GetTextByPath(sldMasterNode, "p:sldMaster/p:clrMap");
  336. if (sldLayoutClrOvr != null)
  337. {
  338. //获取 overrideClrMapping所有属性节点 检查测试 是否slideLayoutClrOvride 需要被覆盖
  339. slideLayoutClrOvride = new Dictionary<string, string>() {
  340. { "accent1", sldLayoutClrOvr.GetTextByPath("@accent1").Value},
  341. { "accent2", sldLayoutClrOvr.GetTextByPath("@accent2").Value},
  342. { "accent3", sldLayoutClrOvr.GetTextByPath("@accent3").Value},
  343. { "accent4", sldLayoutClrOvr.GetTextByPath("@accent4").Value},
  344. { "accent5", sldLayoutClrOvr.GetTextByPath("@accent5").Value},
  345. { "accent6", sldLayoutClrOvr.GetTextByPath("@accent6").Value},
  346. { "bg1", sldLayoutClrOvr.GetTextByPath("@bg1").Value},
  347. { "bg2", sldLayoutClrOvr.GetTextByPath("@bg2").Value},
  348. { "folHlink", sldLayoutClrOvr.GetTextByPath("@folHlink").Value},
  349. { "hlink", sldLayoutClrOvr.GetTextByPath("@hlink").Value},
  350. { "tx1", sldLayoutClrOvr.GetTextByPath("@tx1").Value},
  351. { "tx2", sldLayoutClrOvr.GetTextByPath("@tx2").Value}
  352. };
  353. }
  354. }
  355. }
  356. if (!schemeClr.StartsWith("a:"))
  357. {
  358. schemeClr = "a:" + schemeClr;
  359. }
  360. //console.log(slideLayoutClrOvride);
  361. var schmClrName = schemeClr.Replace("a:", "");
  362. if (slideLayoutClrOvride != null)
  363. {
  364. switch (schmClrName)
  365. {
  366. case "tx1":
  367. case "tx2":
  368. case "bg1":
  369. case "bg2":
  370. schemeClr = "a:" + slideLayoutClrOvride[schmClrName];
  371. //schemeClr = "a:" + slideLayoutClrOvride[schmClrName];
  372. //console.log(schmClrName+ "=> "+schemeClr);
  373. break;
  374. }
  375. }
  376. else
  377. {
  378. switch (schmClrName)
  379. {
  380. case "tx1":
  381. schemeClr = "a:dk1";
  382. break;
  383. case "tx2":
  384. schemeClr = "a:dk2";
  385. break;
  386. case "bg1":
  387. schemeClr = "a:lt1";
  388. break;
  389. case "bg2":
  390. schemeClr = "a:lt2";
  391. break;
  392. }
  393. }
  394. //var refNode = ShapeHelper.GetTextByPathList(themeContent, "a:theme/a:themeElements/a:clrScheme/"+ schemeClr.Value);
  395. var color = ShapeHelper.GetTextByPath(themeContent, "pkg:xmlData/a:theme/a:themeElements/a:clrScheme/" + schemeClr + "/a:srgbClr/@val");
  396. if (color == null)//&& refNode != null
  397. {
  398. color = ShapeHelper.GetTextByPath(themeContent, "pkg:xmlData/a:theme/a:themeElements/a:clrScheme/" + schemeClr + "/a:sysClr/@lastClr");
  399. }
  400. //console.log(color)
  401. return color.Value;
  402. }
  403. public static string GetSvgImagePattern(string fillColor, int shpId)
  404. {
  405. var ptrn = "<pattern id=\"imgPtrn_" + shpId + "\"patternContentUnits=\"objectBoundingBox\" width=\"1\" height=\"1\">";// '<pattern id="imgPtrn_' + shpId + '" patternContentUnits="objectBoundingBox" width="1" height="1">';
  406. ptrn += "<image xlink:href=\"" + fillColor + "\"preserveAspectRatio=\"none\" width=\"1\" height=\"1\"></image>";// '<image xlink:href="' + fillColor + '" preserveAspectRatio="none" width="1" height="1"></image>';
  407. ptrn += "</pattern>";// '';
  408. return ptrn;
  409. }
  410. public static string GetSvgGradient(double w, double h, double angl, List<string> color_arry, int shpId, Dictionary<string, string> slideLayoutClrOvride, XmlNode themeContent)
  411. {
  412. var stopsArray = GetMiddleStops(color_arry.Count - 2);
  413. var svgAngle = "";
  414. double svgHeight = h;
  415. double svgWidth = w;
  416. string svg = "";
  417. List<double> xy_ary = SVGangle(angl, svgHeight, svgWidth, slideLayoutClrOvride, themeContent);
  418. double x1 = xy_ary[0];
  419. double y1 = xy_ary[1];
  420. double x2 = xy_ary[2];
  421. double y2 = xy_ary[3];
  422. var sal = stopsArray.Count;
  423. double sr = sal < 20 ? 100 : 1000;
  424. svgAngle = " gradientUnits=\"userSpaceOnUse\" x1=\"" + x1 + "%\" y1=\"" + y1 + "%\" x2=\"" + x2 + "%\" y2=\"" + y2 + "%\"";
  425. svgAngle = "<linearGradient id=\"linGrd_" + shpId + "\"" + svgAngle + ">\n";
  426. svg += svgAngle;
  427. for (var i = 0; i < sal; i++)
  428. {
  429. svg += "<stop offset=\"" + (System.Math.Round(double.Parse(stopsArray[i].Replace("%", ""))) / 100 * sr) / sr + "\" stop-color=\"" + color_arry[i] + "\"";
  430. svg += "/>\n";
  431. }
  432. svg += "</linearGradient>\n" + "";
  433. return svg;
  434. }
  435. public static List<string> GetMiddleStops(int s)
  436. {
  437. var sArry = new List<string> { "0%" };
  438. if (s == 0)
  439. {
  440. return sArry;
  441. }
  442. else
  443. {
  444. for (int i = s; i < 0; i--)
  445. {
  446. var middleStop = 100 - ((100 / (s + 1)) * (i + 1)); // AM: Ex - For 3 middle stops, progression will be 25%, 50%, and 75%, plus 0% and 100% at the ends.
  447. var middleStopString = middleStop + "%";
  448. sArry.Add(middleStopString);
  449. // sArry.splice(-1, 0, middleStopString);
  450. }
  451. // AM: add into stopsArray before 100%
  452. }
  453. sArry.Add("100%");
  454. return sArry;
  455. }
  456. public static List<double> SVGangle(double deg, double svgHeight, double svgWidth, Dictionary<string, string> slideLayoutClrOvride, XmlNode themeContent)
  457. {
  458. double w = svgWidth;
  459. double h = svgHeight;
  460. double ang = deg;
  461. double o = 2;
  462. double n = 2;
  463. double wc = w / 2;
  464. double hc = h / 2;
  465. double tx1 = 2;
  466. double ty1 = 2;
  467. double tx2 = 2;
  468. double ty2 = 2;
  469. double k = (((ang % 360) + 360) % 360);
  470. double j = (360 - k) * System.Math.PI / 180;
  471. double i = System.Math.Tan(j);
  472. double l = hc - i * wc;
  473. if (k == 0)
  474. {
  475. tx1 = w;
  476. ty1 = hc;
  477. tx2 = 0;
  478. ty2 = hc;
  479. }
  480. else if (k < 90)
  481. {
  482. n = w;
  483. o = 0;
  484. }
  485. else if (k == 90)
  486. {
  487. tx1 = wc;
  488. ty1 = 0;
  489. tx2 = wc;
  490. ty2 = h;
  491. }
  492. else if (k < 180)
  493. {
  494. n = 0;
  495. o = 0;
  496. }
  497. else if (k == 180)
  498. {
  499. tx1 = 0;
  500. ty1 = hc;
  501. tx2 = w;
  502. ty2 = hc;
  503. }
  504. else if (k < 270)
  505. {
  506. n = 0;
  507. o = h;
  508. }
  509. else if (k == 270)
  510. {
  511. tx1 = wc;
  512. ty1 = h;
  513. tx2 = wc;
  514. ty2 = 0;
  515. }
  516. else
  517. {
  518. n = w;
  519. o = h;
  520. }
  521. // AM: I could not quite figure out what m, n, and o are supposed to represent from the original code on visualcsstools.com.
  522. var m = o + (n / i);
  523. tx1 = tx1 == 2 ? i * (m - l) / (System.Math.Pow(i, 2) + 1) : tx1;
  524. ty1 = ty1 == 2 ? i * tx1 + l : ty1;
  525. tx2 = tx2 == 2 ? w - tx1 : tx2;
  526. ty2 = ty2 == 2 ? h - ty1 : ty2;
  527. double x1 = System.Math.Round(tx2 / w * 100 * 100) / 100.0;
  528. double y1 = System.Math.Round(ty2 / h * 100 * 100) / 100.0;
  529. double x2 = System.Math.Round(tx1 / w * 100 * 100) / 100.0;
  530. double y2 = System.Math.Round(ty1 / h * 100 * 100) / 100.0;
  531. return new List<double> { x1, y1, x2, y2 };
  532. }
  533. public static Fill GetPatternFill(XmlNode node, Dictionary<string, string> slideLayoutClrOvride, XmlNode slideMasterContent, XmlNode themeContent)
  534. {
  535. Fill fill = new Fill { type = 4 };
  536. //处理前景色
  537. var fgClr = node.GetTextByPath("a:fgClr");
  538. string fgclr = GetSolidFill(fgClr, slideLayoutClrOvride, slideMasterContent, themeContent);
  539. if (fgClr != null) {
  540. fgclr = ShapeHelper.ColorToning(fgClr.OuterXml, fgclr);
  541. }
  542. fill.grad.Add(fgclr);
  543. // 处理背景色
  544. var bgClr = node.GetTextByPath("a:bgClr");
  545. string bgclr = GetSolidFill(bgClr, slideLayoutClrOvride, slideMasterContent, themeContent);
  546. if (bgClr != null) {
  547. bgclr = ShapeHelper.ColorToning(bgClr.OuterXml, bgclr);
  548. }
  549. //处理内置图案属性
  550. var prst = node.GetTextByPath("@prst");
  551. if (prst != null)
  552. {
  553. fill.patt = prst.Value;
  554. }
  555. fill.grad.Add(bgclr);
  556. return fill;
  557. }
  558. public static dynamic GetSlideSize(XmlDocument xdoc)
  559. {
  560. var sldSzNode = xdoc.GetTextByPath("//pkg:part[@pkg:name='/ppt/presentation.xml']/pkg:xmlData/p:presentation/p:sldSz");
  561. double width = double.Parse(sldSzNode.GetTextByPath("@cx").Value) * px96 / px914400;
  562. double height = double.Parse(sldSzNode.GetTextByPath("@cy").Value) * px96 / px914400;
  563. return new { width, height };
  564. }
  565. public static Fill GetGradientFill(XmlNode node, Dictionary<string, string> slideLayoutClrOvride, XmlNode slideMasterContent, XmlNode themeContent)
  566. {
  567. XmlNodeList gsLst = ShapeHelper.GetTextByPathList(node, "a:gsLst/a:gs");// node["a:gsLst"]["a:gs"];
  568. //get start color
  569. var color_ary = new List<string>();
  570. for (int i = 0; i < gsLst.Count; i++)
  571. {
  572. var lo_color = GetSolidFill(gsLst[i], slideLayoutClrOvride, slideMasterContent, themeContent);
  573. lo_color = ShapeHelper.ColorToning(gsLst[i].OuterXml, lo_color);
  574. color_ary.Add(lo_color);
  575. }
  576. //get rot
  577. var lin = ShapeHelper.GetTextByPathList(node, "a:lin");// node["a:lin"];
  578. double rot = 0;
  579. if (lin != null)
  580. {
  581. rot = AngleToDegrees(ShapeHelper.GetTextByPath(node, "a:lin/@ang")) + 90;
  582. }
  583. return new Fill()
  584. {
  585. type = 2,
  586. grad = color_ary,
  587. rot = rot
  588. };
  589. }
  590. public static Position GetPosition(XmlNode slideXfrmNode, XmlNode slideLayoutXfrmNode, XmlNode slideMasterXfrmNode)
  591. {
  592. XmlNode off = null;
  593. XmlNode ext = null;
  594. double x, y, w, h;
  595. //ext
  596. if (slideXfrmNode != null)
  597. {
  598. ext = ShapeHelper.GetTextByPath(slideXfrmNode, "a:ext");
  599. }
  600. else if (slideLayoutXfrmNode != null && ext == null)
  601. {
  602. ext = ShapeHelper.GetTextByPath(slideLayoutXfrmNode, "a:ext");
  603. }
  604. else if (slideMasterXfrmNode != null && ext == null)
  605. {
  606. ext = ShapeHelper.GetTextByPath(slideMasterXfrmNode, "a:ext");
  607. }
  608. //off
  609. if (slideXfrmNode != null)
  610. {
  611. off = ShapeHelper.GetTextByPath(slideXfrmNode, "a:off");
  612. }
  613. else if (slideLayoutXfrmNode != null && off == null)
  614. {
  615. off = ShapeHelper.GetTextByPath(slideLayoutXfrmNode, "a:off");
  616. }
  617. else if (slideMasterXfrmNode != null && off == null)
  618. {
  619. off = ShapeHelper.GetTextByPath(slideMasterXfrmNode, "a:off");
  620. }
  621. x = System.Math.Round(double.Parse(off.GetTextByPath("@x").Value) * px96 / px914400, degree);
  622. y = System.Math.Round(double.Parse(off.GetTextByPath("@y").Value) * px96 / px914400, degree);
  623. w = System.Math.Round(double.Parse(ext.GetTextByPath("@cx").Value) * px96 / px914400, degree);
  624. h = System.Math.Round(double.Parse(ext.GetTextByPath("@cy").Value) * px96 / px914400, degree);
  625. return new Position()
  626. {
  627. cx = w,
  628. cy = h,
  629. x = x,
  630. y = y
  631. };
  632. }
  633. public static NodesTable IndexNodes(XmlNode content)
  634. {
  635. var idTable = new Dictionary<string, XmlNode>();
  636. var idxTable = new Dictionary<string, XmlNode>();
  637. var typeTable = new Dictionary<string, XmlNode>();
  638. var spTreeNode = content.GetTextByPath("p:cSld/p:spTree");
  639. // Dictionary<string, Dictionary<string, string>> slideResObj = new Dictionary<string, Dictionary<string, string>>();
  640. var spTreeNodeChildren = spTreeNode.ChildNodes;
  641. foreach (XmlNode child in spTreeNodeChildren)
  642. {
  643. if (child.Name.Equals("p:nvGrpSpPr") || child.Name.Equals("p:grpSpPr"))
  644. {
  645. continue;
  646. }
  647. //var targetNode = child.ChildNodes;
  648. var targetNode = child.GetTextByPath("p:nvSpPr");
  649. // < p:cNvCxnSpPr >
  650. // < a:cxnSpLocks /> ///这个是什么意思
  651. // </ p:cNvCxnSpPr >
  652. if (targetNode == null)
  653. {
  654. targetNode = child.GetTextByPath("p:nvCxnSpPr");
  655. }
  656. XmlNode id = null, idx = null, type = null;
  657. if (targetNode != null) {
  658. id = targetNode.GetTextByPath("p:cNvPr/@id");
  659. idx = targetNode.GetTextByPath("p:nvPr/p:ph/@idx");
  660. type = targetNode.GetTextByPath("p:nvPr/p:ph/@type");
  661. }
  662. // Dictionary<string, XmlNode> node = new Dictionary<string, XmlNode>();
  663. //if (child.ChildNodes != null)
  664. //{
  665. // foreach (XmlNode xmlNode in child.ChildNodes)
  666. // {
  667. // node.TryAdd(xmlNode.Name, xmlNode);
  668. // }
  669. //}
  670. if (id != null)
  671. {
  672. idTable[id.Value] = child;
  673. }
  674. if (idx != null)
  675. {
  676. idxTable[idx.Value] = child;
  677. }
  678. if (type != null)
  679. {
  680. //会出现相同Key
  681. typeTable[type.Value] = child;
  682. }
  683. }
  684. return new NodesTable { idTable = idTable, idxTable = idxTable, typeTable = typeTable };
  685. }
  686. public static double AngleToDegrees(XmlNode angle)
  687. {
  688. if (angle == null)
  689. {
  690. return 0;
  691. }
  692. return double.Parse(angle.Value) / rot60000;
  693. }
  694. public static XmlNode GetNodesTable(XmlNode id, XmlNode idx, XmlNode type, WarpObj warpObj, string LayoutOrMaster)
  695. {
  696. XmlNode resNode = null;
  697. if (resNode == null)
  698. {
  699. if (id != null)
  700. {
  701. if (LayoutOrMaster.Equals("Layout"))
  702. {
  703. if (warpObj.slideLayoutTables.idTable.TryGetValue(id.Value, out XmlNode LayoutNode))
  704. {
  705. // LayoutNode.TryGetValue(id.Value, out XmlNode node);
  706. resNode = LayoutNode;
  707. };
  708. }
  709. if (LayoutOrMaster.Equals("Master"))
  710. {
  711. if (warpObj.slideMasterTables.idTable.TryGetValue(id.Value, out XmlNode MasterNode))
  712. {
  713. // LayoutNode.TryGetValue(id.Value, out XmlNode node);
  714. resNode = MasterNode;
  715. };
  716. }
  717. }
  718. }
  719. if (resNode == null)
  720. {
  721. if (idx != null)
  722. {
  723. if (LayoutOrMaster.Equals("Layout"))
  724. {
  725. if (warpObj.slideLayoutTables.idxTable.TryGetValue(idx.Value, out XmlNode LayoutNode))
  726. {
  727. //LayoutNode.TryGetValue(idx.Value, out XmlNode node);
  728. resNode = LayoutNode;
  729. };
  730. }
  731. if (LayoutOrMaster.Equals("Master"))
  732. {
  733. if (warpObj.slideMasterTables.idxTable.TryGetValue(idx.Value, out XmlNode MasterNode))
  734. {
  735. // LayoutNode.TryGetValue(idx.Value, out XmlNode node);
  736. resNode = MasterNode;
  737. };
  738. }
  739. }
  740. }
  741. if (resNode == null)
  742. {
  743. if (type != null)
  744. {
  745. if (LayoutOrMaster.Equals("Layout"))
  746. {
  747. if (warpObj.slideLayoutTables.typeTable.TryGetValue(type.Value, out XmlNode LayoutNode))
  748. {
  749. // LayoutNode.TryGetValue(type.Value, out XmlNode node);
  750. resNode = LayoutNode;
  751. };
  752. }
  753. if (LayoutOrMaster.Equals("Master"))
  754. {
  755. if (warpObj.slideMasterTables.typeTable.TryGetValue(type.Value, out XmlNode MasterNode))
  756. {
  757. // MasterNode.TryGetValue(type.Value, out XmlNode node);
  758. resNode = MasterNode;
  759. };
  760. }
  761. }
  762. }
  763. return resNode;
  764. }
  765. public static string HexToRgbNew(string bgColor)
  766. {
  767. //var arrBuff = new ArrayBuffer(4);
  768. //var vw = new DataView(arrBuff);
  769. //vw.setUint32(0, parseInt(hex, 16), false);
  770. //var arrByte = new Uint8Array(arrBuff);
  771. int r = Convert.ToInt32("0x" + bgColor.Substring(0, 2), 16);
  772. int g = Convert.ToInt32("0x" + bgColor.Substring(2, 2), 16);
  773. int b = Convert.ToInt32("0x" + bgColor.Substring(4, 2), 16);
  774. return r + "," + g + "," + b;
  775. }
  776. public static double GetColorOpacity(XmlNode solidFill)
  777. {
  778. double opcity = 1;
  779. if (solidFill == null)
  780. {
  781. return opcity;
  782. }
  783. if (solidFill.GetTextByPath("a:srgbClr") != null)
  784. {
  785. var tint = solidFill.GetTextByPath("a:srgbClr/a:tint/@val");
  786. if (tint != null)
  787. {
  788. opcity = double.Parse(tint.Value) / 100000.0;
  789. }
  790. }
  791. else if (solidFill.GetTextByPath("a:schemeClr") != null)
  792. {
  793. var tint = solidFill.GetTextByPath("a:schemeClr/a:tint/@val");
  794. if (tint != null)
  795. {
  796. opcity = double.Parse(tint.Value) / 100000.0;
  797. }
  798. }
  799. else if (solidFill.GetTextByPath("a:scrgbClr") != null)
  800. {
  801. var tint = solidFill.GetTextByPath("a:scrgbClr/a:tint/@val");
  802. if (tint != null)
  803. {
  804. opcity = double.Parse(tint.Value) / 100000.0;
  805. }
  806. }
  807. else if (solidFill.GetTextByPath("a:prstClr") != null)
  808. {
  809. var tint = solidFill.GetTextByPath("a:prstClr/a:tint/@val");
  810. if (tint != null)
  811. {
  812. opcity = double.Parse(tint.Value) / 100000.0;
  813. }
  814. }
  815. else if (solidFill.GetTextByPath("a:hslClr") != null)
  816. {
  817. var tint = solidFill.GetTextByPath("a:hslClr/a:tint/@val");
  818. if (tint != null)
  819. {
  820. opcity = double.Parse(tint.Value) / 100000.0;
  821. }
  822. }
  823. else if (solidFill.GetTextByPath("a:sysClr") != null)
  824. {
  825. var tint = solidFill.GetTextByPath("a:sysClr/a:tint/@val");
  826. if (tint != null)
  827. {
  828. opcity = double.Parse(tint.Value) / 100000.0;
  829. }
  830. }
  831. return opcity;
  832. }
  833. public static Fill GetBgGradientFill(XmlNode bgPr, string phClr, Dictionary<string, string> slideLayoutClrOvride, XmlNode slideMasterContent, XmlNode themeContent)
  834. {
  835. if (bgPr != null)
  836. {
  837. var grdFill = bgPr.GetTextByPath("a:gradFill");
  838. return GetGradientFill(grdFill, slideLayoutClrOvride, slideMasterContent, themeContent);
  839. }
  840. else
  841. {
  842. if (phClr == null)
  843. {
  844. return new Fill { type = 1, color = phClr };
  845. }
  846. }
  847. return null;
  848. }
  849. public static string GetSolidFill(XmlNode node, Dictionary<string, string> slideLayoutClrOvride, XmlNode slideMasterContent, XmlNode themeContent)
  850. {
  851. if (node == null)
  852. {
  853. return null;
  854. }
  855. string Color =null;
  856. // Fill fill = new Fill() { Color = "FFF", Type = 1 };
  857. var srgbClrval = node.GetTextByPath("a:srgbClr/@val");
  858. var schemeClrval = node.GetTextByPath("a:schemeClr/@val");
  859. if (srgbClrval != null)
  860. {
  861. Color = srgbClrval.Value; //#...
  862. }
  863. else if (schemeClrval != null)//node["a:schemeClr"] != null)
  864. {
  865. //a:schemeClr
  866. // var schemeClr = ShapeHelper.GetTextByPath(node, "a:schemeClr/@val");
  867. //console.log(schemeClr)
  868. Color = ShapeHelper.GetSchemeColorFromTheme(schemeClrval.Value, slideMasterContent, slideLayoutClrOvride, themeContent); //#...
  869. }
  870. else if (ShapeHelper.GetTextByPath(node, "a:scrgbClr") != null)
  871. {
  872. //<a:scrgbClr r="50%" g="50%" b="50%"/> //Need to test/////////////////////////////////////////////
  873. var defBultColorValsR = ShapeHelper.GetTextByPath(node, "a:scrgbClr/@r");
  874. var defBultColorValsG = ShapeHelper.GetTextByPath(node, "a:scrgbClr/@g");
  875. var defBultColorValsB = ShapeHelper.GetTextByPath(node, "a:scrgbClr/@b");
  876. var red = (defBultColorValsR.Value.IndexOf("%") != -1) ? defBultColorValsR.Value.Split("%").First() : defBultColorValsR.Value;
  877. var green = (defBultColorValsG.Value.IndexOf("%") != -1) ? defBultColorValsG.Value.Split("%").First() : defBultColorValsG.Value;
  878. var blue = (defBultColorValsB.Value.IndexOf("%") != -1) ? defBultColorValsB.Value.Split("%").First() : defBultColorValsB.Value;
  879. var scrgbClr = red + "," + green + "," + blue;
  880. Color = ToHex(255 * (int.Parse(red) / 100)) + ToHex(255 * (int.Parse(green) / 100)) + ToHex(255 * (int.Parse(blue) / 100));
  881. //console.log("scrgbClr: " + scrgbClr);
  882. }
  883. else if (ShapeHelper.GetTextByPath(node, "a:prstClr") != null)
  884. {
  885. //<a:prstClr val="black"/> //Need to test/////////////////////////////////////////////
  886. var prstClr = ShapeHelper.GetTextByPath(node, "a:prstClr/@val");// node["a:prstClr"]["attrs"]["val"];
  887. Color = GetColorName2Hex(prstClr.Value);
  888. //console.log("prstClr: " + prstClr+" => hexClr: "+color);
  889. }
  890. else if (ShapeHelper.GetTextByPath(node, "a:hslClr") != null)
  891. {
  892. //<a:hslClr hue="14400000" sat="100%" lum="50%"/> //Need to test/////////////////////////////////////////////
  893. var defBultColorVals = ShapeHelper.GetTextByPath(node, "a:hslClr");//["attrs"];
  894. var defBultColorVals_hue = ShapeHelper.GetTextByPath(defBultColorVals, "@hue");
  895. var defBultColorVals_sat = ShapeHelper.GetTextByPath(defBultColorVals, "@sat");
  896. var defBultColorVals_lum = ShapeHelper.GetTextByPath(defBultColorVals, "@lum");
  897. var hue = int.Parse(defBultColorVals_hue.Value) / 100000;
  898. var sat = int.Parse((defBultColorVals_sat.Value.IndexOf("%") != -1) ? defBultColorVals_sat.Value.Split("%").First() : defBultColorVals_sat.Value) / 100;
  899. var lum = int.Parse((defBultColorVals_lum.Value.IndexOf("%") != -1) ? defBultColorVals_lum.Value.Split("%").First() : defBultColorVals_lum.Value) / 100;
  900. var hslClr = defBultColorVals_hue.Value.ToString() + "," + defBultColorVals_sat.Value.ToString() + "," + defBultColorVals_lum.Value.ToString();
  901. var hsl2rgb = HslToRgb(hue, sat, lum);
  902. Color = ToHex(hsl2rgb.r) + ToHex(hsl2rgb.g) + ToHex(hsl2rgb.b);
  903. //defBultColor = cnvrtHslColor2Hex(hslClr); //TODO
  904. // console.log("hslClr: " + hslClr);
  905. }
  906. else if (ShapeHelper.GetTextByPath(node, "a:sysClr") != null)
  907. {
  908. //<a:sysClr val="windowText" lastClr="000000"/> //Need to test/////////////////////////////////////////////
  909. var sysClr = ShapeHelper.GetTextByPath(node, "a:sysClr/@lastClr").Value;
  910. if (sysClr != null)
  911. {
  912. Color = sysClr;
  913. }
  914. }
  915. return Color;
  916. }
  917. public static string ToHex(int n)
  918. {
  919. string hex= Convert.ToString(n, 16);
  920. while (hex.Length < 2) { hex = "0" + hex; }
  921. return hex;
  922. }
  923. public static dynamic HslToRgb(int hue, int sat, int light)
  924. {
  925. int t1, t2, r, g, b;
  926. hue /= 60;
  927. if (light <= 0.5)
  928. {
  929. t2 = light * (sat + 1);
  930. }
  931. else
  932. {
  933. t2 = light + sat - (light * sat);
  934. }
  935. t1 = light * 2 - t2;
  936. r = HueToRgb(t1, t2, hue + 2) * 255;
  937. g = HueToRgb(t1, t2, hue) * 255;
  938. b = HueToRgb(t1, t2, hue - 2) * 255;
  939. return new { r, g, b };
  940. }
  941. public static int HueToRgb(int t1, int t2, int hue)
  942. {
  943. if (hue < 0) hue += 6;
  944. if (hue >= 6) hue -= 6;
  945. if (hue < 1) return (t2 - t1) * hue + t1;
  946. else if (hue < 3) return t2;
  947. else if (hue < 4) return (t2 - t1) * (4 - hue) + t1;
  948. else return t1;
  949. }
  950. public static string GetColorName2Hex(string name)
  951. {
  952. var hex = "";
  953. var colorName = new List<string> { "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige", "Bisque", "Black", "BlanchedAlmond", "Blue", "BlueViolet", "Brown", "BurlyWood", "CadetBlue", "Chartreuse", "Chocolate", "Coral", "CornflowerBlue", "Cornsilk", "Crimson", "Cyan", "DarkBlue", "DarkCyan", "DarkGoldenRod", "DarkGray", "DarkGrey", "DarkGreen", "DarkKhaki", "DarkMagenta", "DarkOliveGreen", "DarkOrange", "DarkOrchid", "DarkRed", "DarkSalmon", "DarkSeaGreen", "DarkSlateBlue", "DarkSlateGray", "DarkSlateGrey", "DarkTurquoise", "DarkViolet", "DeepPink", "DeepSkyBlue", "DimGray", "DimGrey", "DodgerBlue", "FireBrick", "FloralWhite", "ForestGreen", "Fuchsia", "Gainsboro", "GhostWhite", "Gold", "GoldenRod", "Gray", "Grey", "Green", "GreenYellow", "HoneyDew", "HotPink", "IndianRed", "Indigo", "Ivory", "Khaki", "Lavender", "LavenderBlush", "LawnGreen", "LemonChiffon", "LightBlue", "LightCoral", "LightCyan", "LightGoldenRodYellow", "LightGray", "LightGrey", "LightGreen", "LightPink", "LightSalmon", "LightSeaGreen", "LightSkyBlue", "LightSlateGray", "LightSlateGrey", "LightSteelBlue", "LightYellow", "Lime", "LimeGreen", "Linen", "Magenta", "Maroon", "MediumAquaMarine", "MediumBlue", "MediumOrchid", "MediumPurple", "MediumSeaGreen", "MediumSlateBlue", "MediumSpringGreen", "MediumTurquoise", "MediumVioletRed", "MidnightBlue", "MintCream", "MistyRose", "Moccasin", "NavajoWhite", "Navy", "OldLace", "Olive", "OliveDrab", "Orange", "OrangeRed", "Orchid", "PaleGoldenRod", "PaleGreen", "PaleTurquoise", "PaleVioletRed", "PapayaWhip", "PeachPuff", "Peru", "Pink", "Plum", "PowderBlue", "Purple", "RebeccaPurple", "Red", "RosyBrown", "RoyalBlue", "SaddleBrown", "Salmon", "SandyBrown", "SeaGreen", "SeaShell", "Sienna", "Silver", "SkyBlue", "SlateBlue", "SlateGray", "SlateGrey", "Snow", "SpringGreen", "SteelBlue", "Tan", "Teal", "Thistle", "Tomato", "Turquoise", "Violet", "Wheat", "White", "WhiteSmoke", "Yellow", "YellowGreen" };
  954. var colorHex = new List<string> { "f0f8ff", "faebd7", "00ffff", "7fffd4", "f0ffff", "f5f5dc", "ffe4c4", "000000", "ffebcd", "0000ff", "8a2be2", "a52a2a", "deb887", "5f9ea0", "7fff00", "d2691e", "ff7f50", "6495ed", "fff8dc", "dc143c", "00ffff", "00008b", "008b8b", "b8860b", "a9a9a9", "a9a9a9", "006400", "bdb76b", "8b008b", "556b2f", "ff8c00", "9932cc", "8b0000", "e9967a", "8fbc8f", "483d8b", "2f4f4f", "2f4f4f", "00ced1", "9400d3", "ff1493", "00bfff", "696969", "696969", "1e90ff", "b22222", "fffaf0", "228b22", "ff00ff", "dcdcdc", "f8f8ff", "ffd700", "daa520", "808080", "808080", "008000", "adff2f", "f0fff0", "ff69b4", "cd5c5c", "4b0082", "fffff0", "f0e68c", "e6e6fa", "fff0f5", "7cfc00", "fffacd", "add8e6", "f08080", "e0ffff", "fafad2", "d3d3d3", "d3d3d3", "90ee90", "ffb6c1", "ffa07a", "20b2aa", "87cefa", "778899", "778899", "b0c4de", "ffffe0", "00ff00", "32cd32", "faf0e6", "ff00ff", "800000", "66cdaa", "0000cd", "ba55d3", "9370db", "3cb371", "7b68ee", "00fa9a", "48d1cc", "c71585", "191970", "f5fffa", "ffe4e1", "ffe4b5", "ffdead", "000080", "fdf5e6", "808000", "6b8e23", "ffa500", "ff4500", "da70d6", "eee8aa", "98fb98", "afeeee", "db7093", "ffefd5", "ffdab9", "cd853f", "ffc0cb", "dda0dd", "b0e0e6", "800080", "663399", "ff0000", "bc8f8f", "4169e1", "8b4513", "fa8072", "f4a460", "2e8b57", "fff5ee", "a0522d", "c0c0c0", "87ceeb", "6a5acd", "708090", "708090", "fffafa", "00ff7f", "4682b4", "d2b48c", "008080", "d8bfd8", "ff6347", "40e0d0", "ee82ee", "f5deb3", "ffffff", "f5f5f5", "ffff00", "9acd32" };
  955. var findIndx = colorName.IndexOf(name);
  956. if (findIndx != -1)
  957. {
  958. hex = colorHex[findIndx];
  959. }
  960. return hex;
  961. }
  962. public static string GetFillType(XmlNode node)
  963. {
  964. //Need to test/////////////////////////////////////////////
  965. //SOLID_FILL
  966. //PIC_FILL
  967. //GRADIENT_FILL
  968. //PATTERN_FILL
  969. //NO_FILL
  970. var fillType = "";
  971. if (node.GetTextByPath("a:noFill") != null)
  972. {
  973. fillType = "NO_FILL";
  974. }
  975. if (node.GetTextByPath("a:solidFill") != null)
  976. {
  977. fillType = "SOLID_FILL";
  978. }
  979. if (node.GetTextByPath("a:gradFill") != null)
  980. {
  981. fillType = "GRADIENT_FILL";
  982. }
  983. if (node.GetTextByPath("a:pattFill") != null)
  984. {
  985. fillType = "PATTERN_FILL";
  986. }
  987. if (node.GetTextByPath("a:blipFill") != null)
  988. {
  989. fillType = "PIC_FILL";
  990. }
  991. if (fillType == "")
  992. {
  993. var clrName = node.GetTextByPath("p:style/a:fillRef");
  994. if (clrName != null)
  995. {
  996. fillType = "SOLID_FILL";
  997. }
  998. }
  999. return fillType;
  1000. }
  1001. }
  1002. }