123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898 |
- using HiTeachCC.Model.PowerPoint;
- using HiTeachCC.Service.PowerPoint.Implement;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Xml;
- using TEAMModelOS.SDK.Helper.Common.ColorHelper;
- using TEAMModelOS.Service.Models.PowerPoint.Inner;
- namespace TEAMModelOS.Service.Services.PowerPoint.Implement
- {
- public static class ShapeHelper
- {
- private const double px96 = 96.00, px72 = 72.00, px914400 = 914400.00, px12700 = 12700.00;
- private const double rot60000 = 60000.00;
- public static Border GetBorder(XmlNode node, bool isSvgMode, string bType, Dictionary<string, string> slideLayoutClrOvride, XmlNode themeContent)
- {
- Border border = new Border();
-
- string cssText = "";
- XmlNode lineNode = null;
- if (bType == "shape")
- {
- cssText = "border: ";
- lineNode = node.GetTextByPath( "p:spPr/a:ln");// node["p:spPr"]["a:ln"];
- }
- else if (bType == "text")
- {
- cssText = "";
- lineNode = PowerPointHelper.GetTextByPath(node, "a:rPr/a:ln");// node["a:rPr"]["a:ln"];
- }
- if (lineNode == null)
- {
- return null;
- }
- var borderWidth = 0.0;
- XmlNode wnode = lineNode.GetTextByPath("@w");
- if (wnode != null)
- {
- borderWidth = double.Parse(wnode.Value) / px12700;
- }
- // Border width: 1pt = 12700, default = 0.75pt
- // borderWidth = double.Parse(PowerPointHelper.GetTextByPath(lineNode, "@w").Value) / px12700;
- if (wnode != null || borderWidth < 1)
- {
- cssText += "0pt ";
- }
- else
- {
- cssText += borderWidth + "pt ";
- }
- // Border type
- var borderType = PowerPointHelper.GetTextByPath(lineNode, "a:prstDash/@val");
- var strokeDasharray = "0";
- if (borderType != null) {
- switch (borderType.Value)
- {
- case "solid":
- cssText += "solid";
- strokeDasharray = "0";
- break;
- case "dash":
- cssText += "dashed";
- strokeDasharray = "5";
- break;
- case "dashDot":
- cssText += "dashed";
- strokeDasharray = "5, 5, 1, 5";
- break;
- case "dot":
- cssText += "dotted";
- strokeDasharray = "1, 5";
- break;
- case "lgDash":
- cssText += "dashed";
- strokeDasharray = "10, 5";
- break;
- case "lgDashDotDot":
- cssText += "dashed";
- strokeDasharray = "10, 5, 1, 5, 1, 5";
- break;
- case "sysDash":
- cssText += "dashed";
- strokeDasharray = "5, 2";
- break;
- case "sysDashDot":
- cssText += "dashed";
- strokeDasharray = "5, 2, 1, 5";
- break;
- case "sysDashDotDot":
- cssText += "dashed";
- strokeDasharray = "5, 2, 1, 5, 1, 5";
- break;
- case "sysDot":
- cssText += "dotted";
- strokeDasharray = "2, 5";
- break;
- case null:
- //console.log(borderType);
- default:
- cssText += "solid";
- strokeDasharray = "0";
- break;
- }
- }
- // Border color
- string borderColorstr = "";
- var borderColor = PowerPointHelper.GetTextByPath(lineNode, "a:solidFill/a:srgbClr/@val");
- if (borderColor == null)
- {
- var schemeClrNode = PowerPointHelper.GetTextByPathList(lineNode, "a:solidFill/a:schemeClr");
- if (schemeClrNode != null)
- {
- var schemeClr = PowerPointHelper.GetTextByPath(lineNode, "a:solidFill/a:schemeClr/@val");
- borderColorstr = GetSchemeColorFromTheme(schemeClr.Value, null ,slideLayoutClrOvride,themeContent);
- }
- }
- // 2. drawingML namespace
- if (borderColor == null)
- {
- var schemeClrNode = PowerPointHelper.GetTextByPathList(node, "p:style/a:lnRef/a:schemeClr");
- if (schemeClrNode != null)
- {
- var schemeClr = PowerPointHelper.GetTextByPath(node, "p:style/a:lnRef/a:schemeClr/@val");
- if (schemeClr != null) {
- borderColorstr = GetSchemeColorFromTheme(schemeClr.Value, null, slideLayoutClrOvride, themeContent);
- }
- }
- if (borderColor != null)
- {
- var shade = PowerPointHelper.GetTextByPath(node, "p:style/a:lnRef/a:schemeClr/a:shade/@val");
- if (shade != null)
- {
- double shaded = double.Parse(shade.Value) / 100000.0;
- var color = ColorTranslator.FromHtml("#" + borderColor);
- ColorHSL colorHSL = ColorHelper.RgbToHsl(new ColorRGB(color.R, color.G, color.B));
- colorHSL.L = colorHSL.L * shaded;
- ColorRGB colorRGB = colorHSL.HslToRgb();
- borderColorstr = ColorTranslator.ToHtml(Color.FromArgb(colorRGB.R, colorRGB.G, colorRGB.B));
- // borderColor = color.hex.replace("#", "");
- }
- }
- }
- if (borderColor == null)
- {
- if (isSvgMode)
- {
- borderColorstr = "none";
- }
- else
- {
- borderColorstr = "#000";
- }
- }
- else
- {
- borderColorstr = "#" + borderColorstr;
- }
- cssText += " " + borderColor + " ";
- if (borderType != null)
- {
- if (isSvgMode)
- {
- return new Border { Color = borderColorstr, Width = (int)borderWidth, Type = borderType.Value, Stroke = strokeDasharray };
- }
- else
- {
- return border;
- }
- }
- else {
- if (isSvgMode)
- {
- return new Border { Color = borderColorstr, Width = (int)borderWidth, Type ="", Stroke = strokeDasharray };
- }
- else
- {
- return border;
- }
- }
-
-
- }
- public static string GetSchemeColorFromTheme(string schemeClr, XmlNode sldMasterNode , Dictionary<string ,string > slideLayoutClrOvride ,XmlNode themeContent)
- {
- //<p:clrMap ...> in slide master
- // e.g. tx2="dk2" bg2="lt2" tx1="dk1" bg1="lt1" slideLayoutClrOvride
- if (slideLayoutClrOvride == null || slideLayoutClrOvride.Count <= 0)
- {
- if (sldMasterNode != null)
- {
- var sldLayoutClrOvr = PowerPointHelper.GetTextByPath(sldMasterNode, "p:sldMaster/p:clrMap");
- if (sldLayoutClrOvr != null)
- {
- //获取 overrideClrMapping所有属性节点 检查测试 是否slideLayoutClrOvride 需要被覆盖
- slideLayoutClrOvride = new Dictionary<string, string>() {
- { "accent1", sldLayoutClrOvr.GetTextByPath("@accent1").Value},
- { "accent2", sldLayoutClrOvr.GetTextByPath("@accent2").Value},
- { "accent3", sldLayoutClrOvr.GetTextByPath("@accent3").Value},
- { "accent4", sldLayoutClrOvr.GetTextByPath("@accent4").Value},
- { "accent5", sldLayoutClrOvr.GetTextByPath("@accent5").Value},
- { "accent6", sldLayoutClrOvr.GetTextByPath("@accent6").Value},
- { "bg1", sldLayoutClrOvr.GetTextByPath("@bg1").Value},
- { "bg2", sldLayoutClrOvr.GetTextByPath("@bg2").Value},
- { "folHlink", sldLayoutClrOvr.GetTextByPath("@folHlink").Value},
- { "hlink", sldLayoutClrOvr.GetTextByPath("@hlink").Value},
- { "tx1", sldLayoutClrOvr.GetTextByPath("@tx1").Value},
- { "tx2", sldLayoutClrOvr.GetTextByPath("@tx2").Value}
- };
- }
- }
- }
- if (!schemeClr.StartsWith("a:"))
- {
- schemeClr = "a:" + schemeClr;
- }
- //console.log(slideLayoutClrOvride);
- var schmClrName = schemeClr.Replace("a:", "");
- if (slideLayoutClrOvride != null)
- {
- switch (schmClrName)
- {
- case "tx1":
- case "tx2":
- case "bg1":
- case "bg2":
- schemeClr = "a:" + slideLayoutClrOvride[schmClrName];
- //schemeClr = "a:" + slideLayoutClrOvride[schmClrName];
- //console.log(schmClrName+ "=> "+schemeClr);
- break;
- }
- }
- else
- {
- switch (schmClrName)
- {
- case "tx1":
- schemeClr = "a:dk1";
- break;
- case "tx2":
- schemeClr = "a:dk2";
- break;
- case "bg1":
- schemeClr = "a:lt1";
- break;
- case "bg2":
- schemeClr = "a:lt2";
- break;
- }
- }
- //var refNode = PowerPointHelper.GetTextByPathList(themeContent, "a:theme/a:themeElements/a:clrScheme/"+ schemeClr.Value);
- var color = PowerPointHelper.GetTextByPath(themeContent, "pkg:xmlData/a:theme/a:themeElements/a:clrScheme/" + schemeClr + "/a:srgbClr/@val");
- if (color == null)//&& refNode != null
- {
- color = PowerPointHelper.GetTextByPath(themeContent, "pkg:xmlData/a:theme/a:themeElements/a:clrScheme/" + schemeClr + "/a:sysClr/@lastClr");
- }
- //console.log(color)
- return color.Value;
- }
- public static string GetSvgImagePattern(string fillColor, int shpId)
- {
- var ptrn = "<pattern id=\"imgPtrn_" + shpId + "\"patternContentUnits=\"objectBoundingBox\" width=\"1\" height=\"1\">";// '<pattern id="imgPtrn_' + shpId + '" patternContentUnits="objectBoundingBox" width="1" height="1">';
- ptrn += "<image xlink:href=\"" + fillColor + "\"preserveAspectRatio=\"none\" width=\"1\" height=\"1\"></image>";// '<image xlink:href="' + fillColor + '" preserveAspectRatio="none" width="1" height="1"></image>';
- ptrn += "</pattern>";// '';
- return ptrn;
- }
- public static string GetSvgGradient(double w, double h, double angl, List<string> color_arry, int shpId, Dictionary<string, string> slideLayoutClrOvride, XmlNode themeContent)
- {
- var stopsArray = GetMiddleStops(color_arry.Count - 2);
- var svgAngle = "";
- double svgHeight = h;
- double svgWidth = w;
- string svg = "";
- List<double> xy_ary = SVGangle(angl, svgHeight, svgWidth, slideLayoutClrOvride, themeContent);
- double x1 = xy_ary[0];
- double y1 = xy_ary[1];
- double x2 = xy_ary[2];
- double y2 = xy_ary[3];
- var sal = stopsArray.Count;
- double sr = sal < 20 ? 100 : 1000;
- svgAngle = " gradientUnits=\"userSpaceOnUse\" x1=\"" + x1 + "%\" y1=\"" + y1 + "%\" x2=\"" + x2 + "%\" y2=\"" + y2 + "%\"";
- svgAngle = "<linearGradient id=\"linGrd_" + shpId + "\"" + svgAngle + ">\n";
- svg += svgAngle;
- for (var i = 0; i < sal; i++)
- {
- svg += "<stop offset=\"" + (System.Math.Round(double.Parse(stopsArray[i].Replace("%",""))) / 100 * sr) / sr + "\" stop-color=\"" + color_arry[i] + "\"";
- svg += "/>\n";
- }
- svg += "</linearGradient>\n" + "";
- return svg;
- }
- public static List<string> GetMiddleStops(int s)
- {
- var sArry = new List<string> { "0%" };
- if (s == 0)
- {
- return sArry;
- }
- else
- {
- for (int i = s; i < 0; i--)
- {
- 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.
- var middleStopString = middleStop + "%";
- sArry.Add(middleStopString);
- // sArry.splice(-1, 0, middleStopString);
- }
- // AM: add into stopsArray before 100%
- }
- sArry.Add("100%");
- return sArry;
- }
- public static List<double> SVGangle(double deg, double svgHeight, double svgWidth , Dictionary<string, string> slideLayoutClrOvride, XmlNode themeContent)
- {
- double w = svgWidth;
- double h = svgHeight;
- double ang = deg;
- double o = 2;
- double n = 2;
- double wc = w / 2;
- double hc = h / 2;
- double tx1 = 2;
- double ty1 = 2;
- double tx2 = 2;
- double ty2 = 2;
- double k = (((ang % 360) + 360) % 360);
- double j = (360 - k) * System.Math.PI / 180;
- double i = System.Math.Tan(j);
- double l = hc - i * wc;
- if (k == 0)
- {
- tx1 = w;
- ty1 = hc;
- tx2 = 0;
- ty2 = hc;
- }
- else if (k < 90)
- {
- n = w;
- o = 0;
- }
- else if (k == 90)
- {
- tx1 = wc;
- ty1 = 0;
- tx2 = wc;
- ty2 = h;
- }
- else if (k < 180)
- {
- n = 0;
- o = 0;
- }
- else if (k == 180)
- {
- tx1 = 0;
- ty1 = hc;
- tx2 = w;
- ty2 = hc;
- }
- else if (k < 270)
- {
- n = 0;
- o = h;
- }
- else if (k == 270)
- {
- tx1 = wc;
- ty1 = h;
- tx2 = wc;
- ty2 = 0;
- }
- else
- {
- n = w;
- o = h;
- }
- // AM: I could not quite figure out what m, n, and o are supposed to represent from the original code on visualcsstools.com.
- var m = o + (n / i);
- tx1 = tx1 == 2 ? i * (m - l) / (System.Math.Pow(i, 2) + 1) : tx1;
- ty1 = ty1 == 2 ? i * tx1 + l : ty1;
- tx2 = tx2 == 2 ? w - tx1 : tx2;
- ty2 = ty2 == 2 ? h - ty1 : ty2;
- double x1 = System.Math.Round(tx2 / w * 100 * 100) / 100;
- double y1 = System.Math.Round(ty2 / h * 100 * 100) / 100;
- double x2 = System.Math.Round(tx1 / w * 100 * 100) / 100;
- double y2 = System.Math.Round(ty1 / h * 100 * 100) / 100;
- return new List<double> { x1, y1, x2, y2 };
- }
- public static Fill GetPatternFill(XmlNode node ,Dictionary<string, string> slideLayoutClrOvride, XmlNode slideMasterContent, XmlNode themeContent)
- {
- Fill fill = new Fill { Type = 4 };
- //处理前景色
- var fgClr = node.GetTextByPath( "a:fgClr");
- string fgclr = GetSolidFill(fgClr, slideLayoutClrOvride, slideMasterContent, themeContent);
- fgclr =PowerPointHelper.ColorToning(fgClr.OuterXml, fgclr);
- fill.gradColor.Add(fgclr);
- // 处理背景色
- var bgClr = node.GetTextByPath( "a:bgClr");
- string bgclr = GetSolidFill(bgClr, slideLayoutClrOvride, slideMasterContent, themeContent);
- bgclr = PowerPointHelper.ColorToning(bgClr.OuterXml, bgclr);
- //处理内置图案属性
- var prst = node.GetTextByPath("@prst");
- if (prst != null) {
- fill.pattPrst = prst.Value;
- }
- fill.gradColor.Add(bgclr);
- return fill;
- }
- public static dynamic GetSlideSize(XmlDocument xdoc)
- {
- var sldSzNode = xdoc.GetTextByPath("//pkg:part[@pkg:name='/ppt/presentation.xml']/pkg:xmlData/p:presentation/p:sldSz");
- double width = double.Parse(sldSzNode.GetTextByPath("@cx").Value) * px96 / px914400;
- double height = double.Parse(sldSzNode.GetTextByPath("@cy").Value) * px96 / px914400;
- return new { width, height };
- }
- public static Fill GetGradientFill(XmlNode node, Dictionary<string, string> slideLayoutClrOvride,XmlNode slideMasterContent, XmlNode themeContent)
- {
- XmlNodeList gsLst = PowerPointHelper.GetTextByPathList(node, "a:gsLst/a:gs");// node["a:gsLst"]["a:gs"];
- //get start color
- var color_ary = new List<string>();
- for (int i = 0; i < gsLst.Count; i++)
- {
- var lo_color = GetSolidFill(gsLst[i] , slideLayoutClrOvride, slideMasterContent, themeContent);
- lo_color = PowerPointHelper.ColorToning(gsLst[i].OuterXml, lo_color);
- color_ary.Add(lo_color);
- }
- //get rot
- var lin = PowerPointHelper.GetTextByPathList(node, "a:lin");// node["a:lin"];
- double rot = 0;
- if (lin != null)
- {
- rot = AngleToDegrees(PowerPointHelper.GetTextByPath(node, "a:lin/@ang")) + 90;
- }
- return new Fill()
- {
- Type = 2,
- gradColor = color_ary,
- Rot = rot
- };
- }
-
- public static Position GetPosition(XmlNode slideXfrmNode, XmlNode slideLayoutXfrmNode, XmlNode slideMasterXfrmNode)
- {
- XmlNode off = null;
- XmlNode ext = null;
- double x, y,w,h;
- //ext
- if(slideXfrmNode != null)
- {
- ext = PowerPointHelper.GetTextByPath(slideXfrmNode, "a:ext");
- }
- else if (slideLayoutXfrmNode != null && ext == null)
- {
- ext = PowerPointHelper.GetTextByPath(slideLayoutXfrmNode, "a:ext");
- }
- else if (slideMasterXfrmNode != null && ext == null)
- {
- ext = PowerPointHelper.GetTextByPath(slideMasterXfrmNode, "a:ext");
- }
- //off
- if (slideXfrmNode != null)
- {
- off = PowerPointHelper.GetTextByPath(slideXfrmNode, "a:off");
- }
- else if (slideLayoutXfrmNode != null && off==null)
- {
- off = PowerPointHelper.GetTextByPath(slideLayoutXfrmNode, "a:off");
- }
- else if (slideMasterXfrmNode != null && off == null)
- {
- off = PowerPointHelper.GetTextByPath(slideMasterXfrmNode, "a:off");
- }
- x = double.Parse(off.GetTextByPath( "@x").Value) * px96 / px914400;
- y = double.Parse(off.GetTextByPath( "@y").Value) * px96 / px914400;
- w = double.Parse(ext.GetTextByPath("@cx").Value) * px96 / px914400;
- h = double.Parse(ext.GetTextByPath("@cy").Value) * px96 / px914400;
- return new Position()
- {
- Cx=w,
- Cy=h,
- X = x,
- Y = y
- };
- }
- public static NodesTable IndexNodes(XmlNode content)
- {
- var idTable = new Dictionary<string, XmlNode>();
- var idxTable = new Dictionary<string, XmlNode>();
- var typeTable = new Dictionary<string, XmlNode>();
- var spTreeNode = content.GetTextByPath("p:cSld/p:spTree");
- // Dictionary<string, Dictionary<string, string>> slideResObj = new Dictionary<string, Dictionary<string, string>>();
- var spTreeNodeChildren = spTreeNode.ChildNodes;
- foreach (XmlNode child in spTreeNodeChildren)
- {
- if (child.Name.Equals("p:nvGrpSpPr") || child.Name.Equals("p:grpSpPr"))
- {
- continue;
- }
- //var targetNode = child.ChildNodes;
- var targetNode = child.GetTextByPath("p:nvSpPr");
- // < p:cNvCxnSpPr >
- // < a:cxnSpLocks /> ///这个是什么意思
- // </ p:cNvCxnSpPr >
- if (targetNode == null)
- {
- targetNode = child.GetTextByPath("p:nvCxnSpPr");
- }
- var id = targetNode.GetTextByPath("p:cNvPr/@id");
- var idx = targetNode.GetTextByPath("p:nvPr/p:ph/@idx");
- var type = targetNode.GetTextByPath("p:nvPr/p:ph/@type");
- // Dictionary<string, XmlNode> node = new Dictionary<string, XmlNode>();
- //if (child.ChildNodes != null)
- //{
- // foreach (XmlNode xmlNode in child.ChildNodes)
- // {
- // node.TryAdd(xmlNode.Name, xmlNode);
- // }
- //}
- if (id != null)
- {
- idTable[id.Value] = child;
- }
- if (idx != null)
- {
- idxTable[idx.Value] = child;
- }
- if (type != null)
- {
- ///会出现相同Key
- typeTable[type.Value] = child;
- }
- }
- return new NodesTable { idTable = idTable, idxTable = idxTable, typeTable = typeTable };
- }
- public static double AngleToDegrees(XmlNode angle)
- {
- if (angle == null)
- {
- return 0;
- }
- return double.Parse(angle.Value) / 60000.00;
- }
- public static XmlNode GetNodesTable(XmlNode id, XmlNode idx, XmlNode type, WarpObj warpObj, string LayoutOrMaster)
- {
- XmlNode resNode = null;
- if (resNode == null)
- {
- if (id != null)
- {
- if (LayoutOrMaster.Equals("Layout"))
- {
- if (warpObj.slideLayoutTables.idTable.TryGetValue(id.Value, out XmlNode LayoutNode))
- {
- // LayoutNode.TryGetValue(id.Value, out XmlNode node);
- resNode = LayoutNode;
- };
- }
- if (LayoutOrMaster.Equals("Master"))
- {
- if (warpObj.slideMasterTables.idTable.TryGetValue(id.Value, out XmlNode MasterNode))
- {
- // LayoutNode.TryGetValue(id.Value, out XmlNode node);
- resNode = MasterNode;
- };
- }
- }
- }
- if (resNode == null)
- {
- if (idx != null)
- {
- if (LayoutOrMaster.Equals("Layout"))
- {
- if (warpObj.slideLayoutTables.idxTable.TryGetValue(idx.Value, out XmlNode LayoutNode))
- {
- //LayoutNode.TryGetValue(idx.Value, out XmlNode node);
- resNode = LayoutNode;
- };
- }
- if (LayoutOrMaster.Equals("Master"))
- {
- if (warpObj.slideMasterTables.idxTable.TryGetValue(idx.Value, out XmlNode MasterNode))
- {
- // LayoutNode.TryGetValue(idx.Value, out XmlNode node);
- resNode = MasterNode;
- };
- }
- }
- }
- if (resNode == null)
- {
- if (type != null)
- {
- if (LayoutOrMaster.Equals("Layout"))
- {
- if (warpObj.slideLayoutTables.typeTable.TryGetValue(type.Value, out XmlNode LayoutNode))
- {
- // LayoutNode.TryGetValue(type.Value, out XmlNode node);
- resNode = LayoutNode;
- };
- }
- if (LayoutOrMaster.Equals("Master"))
- {
- if (warpObj.slideMasterTables.typeTable.TryGetValue(type.Value, out XmlNode MasterNode))
- {
- // MasterNode.TryGetValue(type.Value, out XmlNode node);
- resNode = MasterNode;
- };
- }
- }
- }
- return resNode;
- }
- public static string HexToRgbNew(string bgColor)
- {
- //var arrBuff = new ArrayBuffer(4);
- //var vw = new DataView(arrBuff);
- //vw.setUint32(0, parseInt(hex, 16), false);
- //var arrByte = new Uint8Array(arrBuff);
- int r = Convert.ToInt32("0x" + bgColor.Substring(0, 2), 16);
- int g = Convert.ToInt32("0x" + bgColor.Substring(2, 2), 16);
- int b = Convert.ToInt32("0x" + bgColor.Substring(4, 2), 16);
- return r + "," + g + "," + b;
- }
- public static double GetColorOpacity(XmlNode solidFill)
- {
- double opcity = 1;
- if (solidFill == null)
- {
- return opcity;
- }
- if (solidFill.GetTextByPath("a:srgbClr") != null)
- {
- var tint = solidFill.GetTextByPath("a:srgbClr/a:tint/@val");
- if (tint != null)
- {
- opcity = double.Parse(tint.Value) / 100000;
- }
- }
- else if (solidFill.GetTextByPath("a:schemeClr") != null)
- {
- var tint = solidFill.GetTextByPath("a:schemeClr/a:tint/@val");
- if (tint != null)
- {
- opcity = double.Parse(tint.Value) / 100000;
- }
- }
- else if (solidFill.GetTextByPath("a:scrgbClr") != null)
- {
- var tint = solidFill.GetTextByPath("a:scrgbClr/a:tint/@val");
- if (tint != null)
- {
- opcity = double.Parse(tint.Value) / 100000;
- }
- }
- else if (solidFill.GetTextByPath("a:prstClr") != null)
- {
- var tint = solidFill.GetTextByPath("a:prstClr/a:tint/@val");
- if (tint != null)
- {
- opcity = double.Parse(tint.Value) / 100000;
- }
- }
- else if (solidFill.GetTextByPath("a:hslClr") != null)
- {
- var tint = solidFill.GetTextByPath("a:hslClr/a:tint/@val");
- if (tint != null)
- {
- opcity = double.Parse(tint.Value) / 100000;
- }
- }
- else if (solidFill.GetTextByPath("a:sysClr") != null)
- {
- var tint = solidFill.GetTextByPath("a:sysClr/a:tint/@val");
- if (tint != null)
- {
- opcity = double.Parse(tint.Value) / 100000;
- }
- }
- return opcity;
- }
- public static Fill GetBgGradientFill(XmlNode bgPr, string phClr, Dictionary<string ,string > slideLayoutClrOvride, XmlNode slideMasterContent, XmlNode themeContent)
- {
- if (bgPr != null)
- {
- var grdFill = bgPr.GetTextByPath("a:gradFill");
- return GetGradientFill(grdFill, slideLayoutClrOvride, slideMasterContent, themeContent);
- }
- else
- {
- if (phClr == null)
- {
- return new Fill { Type = 1, Color = phClr };
- }
- }
- return null;
- }
- public static string GetSolidFill(XmlNode node, Dictionary<string, string> slideLayoutClrOvride, XmlNode slideMasterContent, XmlNode themeContent)
- {
- if (node == null)
- {
- return null;
- }
- string Color = "FFF";
- // Fill fill = new Fill() { Color = "FFF", Type = 1 };
- var srgbClrval = node.GetTextByPath("a:srgbClr/@val");
- var schemeClrval = node.GetTextByPath("a:schemeClr/@val");
- if (srgbClrval != null)
- {
- Color = srgbClrval.Value; //#...
- }
- else if (schemeClrval != null)//node["a:schemeClr"] != null)
- {
- //a:schemeClr
- // var schemeClr = PowerPointHelper.GetTextByPath(node, "a:schemeClr/@val");
- //console.log(schemeClr)
- Color = ShapeHelper.GetSchemeColorFromTheme(schemeClrval.Value, slideMasterContent, slideLayoutClrOvride, themeContent); //#...
- }
- else if (PowerPointHelper.GetTextByPath(node, "a:scrgbClr") != null)
- {
- //<a:scrgbClr r="50%" g="50%" b="50%"/> //Need to test/////////////////////////////////////////////
- var defBultColorValsR = PowerPointHelper.GetTextByPath(node, "a:scrgbClr/@r");
- var defBultColorValsG = PowerPointHelper.GetTextByPath(node, "a:scrgbClr/@g");
- var defBultColorValsB = PowerPointHelper.GetTextByPath(node, "a:scrgbClr/@b");
- var red = (defBultColorValsR.Value.IndexOf("%") != -1) ? defBultColorValsR.Value.Split("%").First() : defBultColorValsR.Value;
- var green = (defBultColorValsG.Value.IndexOf("%") != -1) ? defBultColorValsG.Value.Split("%").First() : defBultColorValsG.Value;
- var blue = (defBultColorValsB.Value.IndexOf("%") != -1) ? defBultColorValsB.Value.Split("%").First() : defBultColorValsB.Value;
- var scrgbClr = red + "," + green + "," + blue;
- Color = ToHex(255 * (double.Parse(red) / 100)) + ToHex(255 * (double.Parse(green) / 100)) + ToHex(255 * (double.Parse(blue) / 100));
- //console.log("scrgbClr: " + scrgbClr);
- }
- else if (PowerPointHelper.GetTextByPath(node, "a:prstClr") != null)
- {
- //<a:prstClr val="black"/> //Need to test/////////////////////////////////////////////
- var prstClr = PowerPointHelper.GetTextByPath(node, "a:prstClr/@val");// node["a:prstClr"]["attrs"]["val"];
- Color = GetColorName2Hex(prstClr.Value);
- //console.log("prstClr: " + prstClr+" => hexClr: "+color);
- }
- else if (PowerPointHelper.GetTextByPath(node, "a:hslClr") != null)
- {
- //<a:hslClr hue="14400000" sat="100%" lum="50%"/> //Need to test/////////////////////////////////////////////
- var defBultColorVals = PowerPointHelper.GetTextByPath(node, "a:hslClr");//["attrs"];
- var defBultColorVals_hue = PowerPointHelper.GetTextByPath(defBultColorVals, "@hue");
- var defBultColorVals_sat = PowerPointHelper.GetTextByPath(defBultColorVals, "@sat");
- var defBultColorVals_lum = PowerPointHelper.GetTextByPath(defBultColorVals, "@lum");
- var hue = double.Parse(defBultColorVals_hue.Value) / 100000;
- var sat = double.Parse((defBultColorVals_sat.Value.IndexOf("%") != -1) ? defBultColorVals_sat.Value.Split("%").First() : defBultColorVals_sat.Value) / 100;
- var lum = double.Parse((defBultColorVals_lum.Value.IndexOf("%") != -1) ? defBultColorVals_lum.Value.Split("%").First() : defBultColorVals_lum.Value) / 100;
- var hslClr = defBultColorVals_hue.Value.ToString() + "," + defBultColorVals_sat.Value.ToString() + "," + defBultColorVals_lum.Value.ToString();
- var hsl2rgb = HslToRgb(hue, sat, lum);
- Color = ToHex(hsl2rgb.r) + ToHex(hsl2rgb.g) + ToHex(hsl2rgb.b);
- //defBultColor = cnvrtHslColor2Hex(hslClr); //TODO
- // console.log("hslClr: " + hslClr);
- }
- else if (PowerPointHelper.GetTextByPath(node, "a:sysClr") != null)
- {
- //<a:sysClr val="windowText" lastClr="000000"/> //Need to test/////////////////////////////////////////////
- var sysClr = PowerPointHelper.GetTextByPath(node, "a:sysClr/@lastClr").Value;
- if (sysClr != null)
- {
- Color = sysClr;
- }
- }
- return Color;
- }
- public static string ToHex(dynamic n)
- {
- string hex = n.toString(16);
- while (hex.Length < 2) { hex = "0" + hex; }
- return hex;
- }
- public static dynamic HslToRgb(double hue, double sat, double light)
- {
- double t1, t2, r, g, b;
- hue /= 60;
- if (light <= 0.5)
- {
- t2 = light * (sat + 1);
- }
- else
- {
- t2 = light + sat - (light * sat);
- }
- t1 = light * 2 - t2;
- r = HueToRgb(t1, t2, hue + 2) * 255;
- g = HueToRgb(t1, t2, hue) * 255;
- b = HueToRgb(t1, t2, hue - 2) * 255;
- return new { r, g, b };
- }
- public static double HueToRgb(double t1, double t2, double hue)
- {
- if (hue < 0) hue += 6;
- if (hue >= 6) hue -= 6;
- if (hue < 1) return (t2 - t1) * hue + t1;
- else if (hue < 3) return t2;
- else if (hue < 4) return (t2 - t1) * (4 - hue) + t1;
- else return t1;
- }
- public static string GetColorName2Hex(string name)
- {
- var hex = "";
- 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" };
- 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" };
- var findIndx = colorName.IndexOf(name);
- if (findIndx != -1)
- {
- hex = colorHex[findIndx];
- }
- return hex;
- }
- public static string GetFillType(XmlNode node)
- {
- //Need to test/////////////////////////////////////////////
- //SOLID_FILL
- //PIC_FILL
- //GRADIENT_FILL
- //PATTERN_FILL
- //NO_FILL
- var fillType = "";
- if (node.GetTextByPath("a:noFill") != null)
- {
- fillType = "NO_FILL";
- }
- if (node.GetTextByPath("a:solidFill") != null)
- {
- fillType = "SOLID_FILL";
- }
- if (node.GetTextByPath("a:gradFill") != null)
- {
- fillType = "GRADIENT_FILL";
- }
- if (node.GetTextByPath("a:pattFill") != null)
- {
- fillType = "PATTERN_FILL";
- }
- if (node.GetTextByPath("a:blipFill") != null)
- {
- fillType = "PIC_FILL";
- }
- return fillType;
- }
- }
- }
|