Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ExportSymbolicDataAnalysisSolutions/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/3.1.3/EPPlus-3.1.3/Drawing/ExcelDrawingFill.cs @ 9580

Last change on this file since 9580 was 9580, checked in by sforsten, 11 years ago

#1730:

  • added SymbolicDataAnalysisExpressionExcelFormatter
  • changed modifiers in SymbolicExpressionTreeChart of methods SaveImageAsBitmap and SaveImageAsEmf to public
  • added menu item ExportSymbolicSolutionToExcelMenuItem to export a symbolic solution to an excel file
  • added EPPlus-3.1.3 to ExtLibs
File size: 7.6 KB
Line 
1/*******************************************************************************
2 * You may amend and distribute as you like, but don't remove this header!
3 *
4 * EPPlus provides server-side generation of Excel 2007/2010 spreadsheets.
5 * See http://www.codeplex.com/EPPlus for details.
6 *
7 * Copyright (C) 2011  Jan Källman
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
17 * See the GNU Lesser General Public License for more details.
18 *
19 * The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php
20 * If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html
21 *
22 * All code and executables are provided "as is" with no warranty either express or implied.
23 * The author accepts no liability for any damage or loss of business that this product may cause.
24 *
25 * Code change notes:
26 *
27 * Author             Change            Date
28 * ******************************************************************************
29 * Jan Källman                    Initial Release           2009-12-22
30 * Jan Källman    License changed GPL-->LGPL 2011-12-16
31 *******************************************************************************/
32using System;
33using System.Collections.Generic;
34using System.Text;
35using System.Xml;
36using System.Drawing;
37
38namespace OfficeOpenXml.Drawing
39{
40    /// <summary>
41    /// Fill properties for drawing objects
42    /// </summary>
43    public sealed class ExcelDrawingFill : XmlHelper
44    {
45        //ExcelShape _shp;               
46        string _fillPath;
47        XmlNode _fillNode;
48        internal ExcelDrawingFill(XmlNamespaceManager nameSpaceManager, XmlNode topNode, string fillPath) :
49            base(nameSpaceManager, topNode)
50        {
51          //  _shp=shp;
52            _fillPath = fillPath;
53            _fillNode = topNode.SelectSingleNode(_fillPath, NameSpaceManager);
54            SchemaNodeOrder = new string[] { "tickLblPos", "spPr", "txPr","dLblPos", "crossAx", "printSettings", "showVal", "prstGeom", "noFill", "solidFill", "blipFill", "gradFill", "noFill", "pattFill", "ln", "prstDash" };
55            //Setfill node
56            if (_fillNode != null)
57            {
58                _fillTypeNode = topNode.SelectSingleNode("solidFill");
59                if (_fillTypeNode == null) _fillTypeNode = topNode.SelectSingleNode("noFill");
60                if (_fillTypeNode == null) _fillTypeNode = topNode.SelectSingleNode("blipFill");
61                if (_fillTypeNode == null) _fillTypeNode = topNode.SelectSingleNode("gradFill");
62                if (_fillTypeNode == null) _fillTypeNode = topNode.SelectSingleNode("pattFill");
63            }
64        }
65        eFillStyle _style;
66        XmlNode _fillTypeNode = null;
67        /// <summary>
68        /// Fill style
69        /// </summary>
70        public eFillStyle Style
71        {
72            get
73            {
74                if (_fillTypeNode == null)
75                {
76                    return eFillStyle.SolidFill;
77                }
78                else
79                {
80                    _style=GetStyleEnum(_fillTypeNode.Name);
81                }
82                return _style;
83            }
84            set
85            {
86                if (value == eFillStyle.NoFill || value == eFillStyle.SolidFill)
87                {
88                    _style = value;
89                    CreateFillTopNode(value);
90                }
91                else
92                {
93                    throw new NotImplementedException("Fillstyle not implemented");
94                }
95            }
96        }
97
98        private void CreateFillTopNode(eFillStyle value)
99        {
100            if (_fillTypeNode != null)
101            {
102                TopNode.RemoveChild(_fillTypeNode);
103            }
104            CreateNode(_fillPath + "/a:" + GetStyleText(value), false);
105            _fillNode=TopNode.SelectSingleNode(_fillPath + "/a:" + GetStyleText(value), NameSpaceManager);
106        }
107
108        private eFillStyle GetStyleEnum(string name)
109        {
110            switch(name)
111            {
112                case "noFill":
113                    return eFillStyle.NoFill;
114                case "blipFill":
115                    return eFillStyle.BlipFill;
116                case "gradFill":
117                    return eFillStyle.GradientFill;
118                case "grpFill":
119                    return eFillStyle.GroupFill;
120                case "pattFill":
121                    return eFillStyle.PatternFill;
122                default:
123                    return eFillStyle.SolidFill;
124            }
125        }
126
127        private string GetStyleText(eFillStyle style)
128        {
129            switch (style)
130            {
131                case eFillStyle.BlipFill:
132                    return "blipFill";
133                case eFillStyle.GradientFill:
134                    return "gradFill";
135                case eFillStyle.GroupFill:
136                    return "grpFill";
137                case eFillStyle.NoFill:
138                    return "noFill";               
139                case eFillStyle.PatternFill:
140                    return "pattFill";
141                default:
142                    return "solidFill";
143            }
144        }
145
146        const string ColorPath = "/a:solidFill/a:srgbClr/@val";
147        /// <summary>
148        /// Fill color for solid fills
149        /// </summary>
150        public Color Color
151        {
152            get
153            {
154                string col = GetXmlNodeString(_fillPath + ColorPath);
155                if (col == "")
156                {
157                    return Color.FromArgb(79, 129, 189);
158                }
159                else
160                {
161                    return Color.FromArgb(int.Parse(col,System.Globalization.NumberStyles.AllowHexSpecifier));
162                }
163            }
164            set
165            {
166                if (_fillTypeNode == null)
167                {
168                    _style = eFillStyle.SolidFill;
169                }
170                else if (_style != eFillStyle.SolidFill)
171                {
172                    throw new Exception("FillStyle must be set to SolidFill");
173                }
174                CreateNode(_fillPath, false);
175                SetXmlNodeString(_fillPath + ColorPath, value.ToArgb().ToString("X").Substring(2, 6));
176            }
177        }
178        const string alphaPath = "/a:solidFill/a:srgbClr/a:alpha/@val";
179        /// <summary>
180        /// Transparancy in percent
181        /// </summary>
182        public int Transparancy
183        {
184            get
185            {
186                return 100 - (GetXmlNodeInt(_fillPath + alphaPath) / 1000);
187            }
188            set
189            {
190                if (_fillTypeNode == null)
191                {
192                    _style = eFillStyle.SolidFill;
193                    Color = Color.FromArgb(79, 129, 189);   //Set a Default color
194                }
195                else if (_style != eFillStyle.SolidFill)
196                {
197                    throw new Exception("FillStyle must be set to SolidFill");
198                }
199                //CreateNode(_fillPath, false);
200                SetXmlNodeString(_fillPath + alphaPath, ((100 - value) * 1000).ToString());
201            }
202        }
203    }
204}
Note: See TracBrowser for help on using the repository browser.