Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2989_MovingPeaksBenchmark/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/EPPlus-4.0.3/Style/XmlAccess/ExcelGradientFillXml.cs @ 17717

Last change on this file since 17717 was 12074, checked in by sraggl, 10 years ago

#2341: Added EPPlus-4.0.3 to ExtLibs

File size: 7.8 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-10-01
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.Globalization;
37namespace OfficeOpenXml.Style.XmlAccess
38{
39    /// <summary>
40    /// Xml access class for gradient fillsde
41    /// </summary>
42    public sealed class ExcelGradientFillXml : ExcelFillXml
43    {
44        internal ExcelGradientFillXml(XmlNamespaceManager nameSpaceManager)
45            : base(nameSpaceManager)
46        {
47            GradientColor1 = new ExcelColorXml(nameSpaceManager);
48            GradientColor2 = new ExcelColorXml(nameSpaceManager);
49        }
50        internal ExcelGradientFillXml(XmlNamespaceManager nsm, XmlNode topNode) :
51            base(nsm, topNode)
52        {
53            Degree = GetXmlNodeDouble(_degreePath);
54            Type = GetXmlNodeString(_typePath)=="path" ? ExcelFillGradientType.Path : ExcelFillGradientType.Linear;
55            GradientColor1 = new ExcelColorXml(nsm, topNode.SelectSingleNode(_gradientColor1Path, nsm));
56            GradientColor2 = new ExcelColorXml(nsm, topNode.SelectSingleNode(_gradientColor2Path, nsm));
57           
58            Top = GetXmlNodeDouble(_topPath);
59            Bottom = GetXmlNodeDouble(_bottomPath);
60            Left = GetXmlNodeDouble(_leftPath);
61            Right = GetXmlNodeDouble(_rightPath);
62        }
63        const string _typePath = "d:gradientFill/@type";
64        /// <summary>
65        /// Type of gradient fill.
66        /// </summary>
67        public ExcelFillGradientType Type
68        {
69            get;
70            internal set;
71        }
72        const string _degreePath = "d:gradientFill/@degree";
73        /// <summary>
74        /// Angle of the linear gradient
75        /// </summary>
76        public double Degree
77        {
78            get;
79            internal set;
80        }
81        const string _gradientColor1Path = "d:gradientFill/d:stop[@position=\"0\"]/d:color";
82        /// <summary>
83        /// Gradient color 1
84        /// </summary>
85        public ExcelColorXml GradientColor1
86        {
87            get;
88            private set;
89        }
90        const string _gradientColor2Path = "d:gradientFill/d:stop[@position=\"1\"]/d:color";
91        /// <summary>
92        /// Gradient color 2
93        /// </summary>
94        public ExcelColorXml GradientColor2
95        {
96            get;
97            private set;
98        }
99        const string _bottomPath = "d:gradientFill/@bottom";
100        /// <summary>
101        /// Percentage format bottom
102        /// </summary>
103        public double Bottom
104        {
105            get;
106            internal set;
107        }
108        const string _topPath = "d:gradientFill/@top";
109        /// <summary>
110        /// Percentage format top
111        /// </summary>
112        public double Top
113        {
114            get;
115            internal set;
116        }
117        const string _leftPath = "d:gradientFill/@left";
118        /// <summary>
119        /// Percentage format left
120        /// </summary>
121        public double Left
122        {
123            get;
124            internal set;
125        }
126        const string _rightPath = "d:gradientFill/@right";
127        /// <summary>
128        /// Percentage format right
129        /// </summary>
130        public double Right
131        {
132            get;
133            internal set;
134        }
135        internal override string Id
136        {
137            get
138            {
139                return base.Id + Degree.ToString() + GradientColor1.Id + GradientColor2.Id + Type + Left.ToString() + Right.ToString() + Bottom.ToString() + Top.ToString();
140            }
141        }
142
143        #region Public Properties
144        #endregion
145        internal override ExcelFillXml Copy()
146        {
147            ExcelGradientFillXml newFill = new ExcelGradientFillXml(NameSpaceManager);
148            newFill.PatternType = base._fillPatternType;
149            newFill.BackgroundColor = _backgroundColor.Copy();
150            newFill.PatternColor = _patternColor.Copy();
151
152            newFill.GradientColor1 = GradientColor1.Copy();
153            newFill.GradientColor2 = GradientColor2.Copy();
154            newFill.Type = Type;
155            newFill.Degree = Degree;
156            newFill.Top = Top;
157            newFill.Bottom = Bottom;
158            newFill.Left = Left;
159            newFill.Right = Right;
160           
161            return newFill;
162        }
163
164        internal override XmlNode CreateXmlNode(XmlNode topNode)
165        {
166            TopNode = topNode;
167            CreateNode("d:gradientFill");
168            if(Type==ExcelFillGradientType.Path) SetXmlNodeString(_typePath, "path");
169            if(!double.IsNaN(Degree)) SetXmlNodeString(_degreePath, Degree.ToString(CultureInfo.InvariantCulture));
170            if (GradientColor1!=null)
171            {
172                /*** Gradient color node 1***/
173                var node = TopNode.SelectSingleNode("d:gradientFill", NameSpaceManager);
174                var stopNode = node.OwnerDocument.CreateElement("stop", ExcelPackage.schemaMain);
175                stopNode.SetAttribute("position", "0");
176                node.AppendChild(stopNode);
177                var colorNode = node.OwnerDocument.CreateElement("color", ExcelPackage.schemaMain);
178                stopNode.AppendChild(colorNode);
179                GradientColor1.CreateXmlNode(colorNode);
180
181                /*** Gradient color node 2***/
182                stopNode = node.OwnerDocument.CreateElement("stop", ExcelPackage.schemaMain);
183                stopNode.SetAttribute("position", "1");
184                node.AppendChild(stopNode);
185                colorNode = node.OwnerDocument.CreateElement("color", ExcelPackage.schemaMain);
186                stopNode.AppendChild(colorNode);
187
188                GradientColor2.CreateXmlNode(colorNode);
189            }
190            if (!double.IsNaN(Top)) SetXmlNodeString(_topPath, Top.ToString("F5",CultureInfo.InvariantCulture));
191            if (!double.IsNaN(Bottom)) SetXmlNodeString(_bottomPath, Bottom.ToString("F5", CultureInfo.InvariantCulture));
192            if (!double.IsNaN(Left)) SetXmlNodeString(_leftPath, Left.ToString("F5", CultureInfo.InvariantCulture));
193            if (!double.IsNaN(Right)) SetXmlNodeString(_rightPath, Right.ToString("F5", CultureInfo.InvariantCulture));
194
195            return topNode;
196        }
197    }
198}
Note: See TracBrowser for help on using the repository browser.