[12074] | 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 | *******************************************************************************/
|
---|
| 32 | using System;
|
---|
| 33 | using System.Collections.Generic;
|
---|
| 34 | using System.Globalization;
|
---|
| 35 | using System.Text;
|
---|
| 36 | using System.Xml;
|
---|
| 37 | using System.Drawing;
|
---|
| 38 |
|
---|
| 39 | namespace OfficeOpenXml.Drawing
|
---|
| 40 | {
|
---|
| 41 | /// <summary>
|
---|
| 42 | /// Type of Line cap
|
---|
| 43 | /// </summary>
|
---|
| 44 | public enum eLineCap
|
---|
| 45 | {
|
---|
| 46 | Flat, //flat
|
---|
| 47 | Round, //rnd
|
---|
| 48 | Square //Sq
|
---|
| 49 | }
|
---|
| 50 | /// <summary>
|
---|
| 51 | /// Line style.
|
---|
| 52 | /// </summary>
|
---|
| 53 | public enum eLineStyle
|
---|
| 54 | {
|
---|
| 55 | Dash,
|
---|
| 56 | DashDot,
|
---|
| 57 | Dot,
|
---|
| 58 | LongDash,
|
---|
| 59 | LongDashDot,
|
---|
| 60 | LongDashDotDot,
|
---|
| 61 | Solid,
|
---|
| 62 | SystemDash,
|
---|
| 63 | SystemDashDot,
|
---|
| 64 | SystemDashDotDot,
|
---|
| 65 | SystemDot
|
---|
| 66 | }
|
---|
| 67 | /// <summary>
|
---|
| 68 | /// Border for drawings
|
---|
| 69 | /// </summary>
|
---|
| 70 | public sealed class ExcelDrawingBorder : XmlHelper
|
---|
| 71 | {
|
---|
| 72 | string _linePath;
|
---|
| 73 | internal ExcelDrawingBorder(XmlNamespaceManager nameSpaceManager, XmlNode topNode, string linePath) :
|
---|
| 74 | base(nameSpaceManager, topNode)
|
---|
| 75 | {
|
---|
| 76 | SchemaNodeOrder = new string[] { "chart","tickLblPos", "spPr", "txPr","crossAx", "printSettings", "showVal", "showCatName", "showSerName", "showPercent", "separator", "showLeaderLines", "noFill", "solidFill", "blipFill", "gradFill", "noFill", "pattFill", "prstDash" };
|
---|
| 77 | _linePath = linePath;
|
---|
| 78 | _lineStylePath = string.Format(_lineStylePath, linePath);
|
---|
| 79 | _lineCapPath = string.Format(_lineCapPath, linePath);
|
---|
| 80 | _lineWidth = string.Format(_lineWidth, linePath);
|
---|
| 81 | }
|
---|
| 82 | #region "Public properties"
|
---|
| 83 | ExcelDrawingFill _fill = null;
|
---|
| 84 | /// <summary>
|
---|
| 85 | /// Fill
|
---|
| 86 | /// </summary>
|
---|
| 87 | public ExcelDrawingFill Fill
|
---|
| 88 | {
|
---|
| 89 | get
|
---|
| 90 | {
|
---|
| 91 | if (_fill == null)
|
---|
| 92 | {
|
---|
| 93 | _fill = new ExcelDrawingFill(NameSpaceManager, TopNode, _linePath);
|
---|
| 94 | }
|
---|
| 95 | return _fill;
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | string _lineStylePath = "{0}/a:prstDash/@val";
|
---|
| 99 | /// <summary>
|
---|
| 100 | /// Linestyle
|
---|
| 101 | /// </summary>
|
---|
| 102 | public eLineStyle LineStyle
|
---|
| 103 | {
|
---|
| 104 | get
|
---|
| 105 | {
|
---|
| 106 | return TranslateLineStyle(GetXmlNodeString(_lineStylePath));
|
---|
| 107 | }
|
---|
| 108 | set
|
---|
| 109 | {
|
---|
| 110 | CreateNode(_linePath, false);
|
---|
| 111 | SetXmlNodeString(_lineStylePath, TranslateLineStyleText(value));
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 | string _lineCapPath = "{0}/@cap";
|
---|
| 115 | /// <summary>
|
---|
| 116 | /// Linecap
|
---|
| 117 | /// </summary>
|
---|
| 118 | public eLineCap LineCap
|
---|
| 119 | {
|
---|
| 120 | get
|
---|
| 121 | {
|
---|
| 122 | return TranslateLineCap(GetXmlNodeString(_lineCapPath));
|
---|
| 123 | }
|
---|
| 124 | set
|
---|
| 125 | {
|
---|
| 126 | CreateNode(_linePath, false);
|
---|
| 127 | SetXmlNodeString(_lineCapPath, TranslateLineCapText(value));
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 | string _lineWidth = "{0}/@w";
|
---|
| 131 | /// <summary>
|
---|
| 132 | /// Width in pixels
|
---|
| 133 | /// </summary>
|
---|
| 134 | public int Width
|
---|
| 135 | {
|
---|
| 136 | get
|
---|
| 137 | {
|
---|
| 138 | return GetXmlNodeInt(_lineWidth) / 12700;
|
---|
| 139 | }
|
---|
| 140 | set
|
---|
| 141 | {
|
---|
| 142 | SetXmlNodeString(_lineWidth, (value * 12700).ToString());
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 | #endregion
|
---|
| 146 | #region "Translate Enum functions"
|
---|
| 147 | private string TranslateLineStyleText(eLineStyle value)
|
---|
| 148 | {
|
---|
| 149 | string text=value.ToString();
|
---|
| 150 | switch (value)
|
---|
| 151 | {
|
---|
| 152 | case eLineStyle.Dash:
|
---|
| 153 | case eLineStyle.Dot:
|
---|
| 154 | case eLineStyle.DashDot:
|
---|
| 155 | case eLineStyle.Solid:
|
---|
| 156 | return text.Substring(0,1).ToLower(CultureInfo.InvariantCulture) + text.Substring(1,text.Length-1); //First to Lower case.
|
---|
| 157 | case eLineStyle.LongDash:
|
---|
| 158 | case eLineStyle.LongDashDot:
|
---|
| 159 | case eLineStyle.LongDashDotDot:
|
---|
| 160 | return "lg" + text.Substring(4, text.Length - 4);
|
---|
| 161 | case eLineStyle.SystemDash:
|
---|
| 162 | case eLineStyle.SystemDashDot:
|
---|
| 163 | case eLineStyle.SystemDashDotDot:
|
---|
| 164 | case eLineStyle.SystemDot:
|
---|
| 165 | return "sys" + text.Substring(6, text.Length - 6);
|
---|
| 166 | default:
|
---|
| 167 | throw(new Exception("Invalid Linestyle"));
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
| 170 | private eLineStyle TranslateLineStyle(string text)
|
---|
| 171 | {
|
---|
| 172 | switch (text)
|
---|
| 173 | {
|
---|
| 174 | case "dash":
|
---|
| 175 | case "dot":
|
---|
| 176 | case "dashDot":
|
---|
| 177 | case "solid":
|
---|
| 178 | return (eLineStyle)Enum.Parse(typeof(eLineStyle), text, true);
|
---|
| 179 | case "lgDash":
|
---|
| 180 | case "lgDashDot":
|
---|
| 181 | case "lgDashDotDot":
|
---|
| 182 | return (eLineStyle)Enum.Parse(typeof(eLineStyle), "Long" + text.Substring(2, text.Length - 2));
|
---|
| 183 | case "sysDash":
|
---|
| 184 | case "sysDashDot":
|
---|
| 185 | case "sysDashDotDot":
|
---|
| 186 | case "sysDot":
|
---|
| 187 | return (eLineStyle)Enum.Parse(typeof(eLineStyle), "System" + text.Substring(3, text.Length - 3));
|
---|
| 188 | default:
|
---|
| 189 | throw (new Exception("Invalid Linestyle"));
|
---|
| 190 | }
|
---|
| 191 | }
|
---|
| 192 | private string TranslateLineCapText(eLineCap value)
|
---|
| 193 | {
|
---|
| 194 | switch (value)
|
---|
| 195 | {
|
---|
| 196 | case eLineCap.Round:
|
---|
| 197 | return "rnd";
|
---|
| 198 | case eLineCap.Square:
|
---|
| 199 | return "sq";
|
---|
| 200 | default:
|
---|
| 201 | return "flat";
|
---|
| 202 | }
|
---|
| 203 | }
|
---|
| 204 | private eLineCap TranslateLineCap(string text)
|
---|
| 205 | {
|
---|
| 206 | switch (text)
|
---|
| 207 | {
|
---|
| 208 | case "rnd":
|
---|
| 209 | return eLineCap.Round;
|
---|
| 210 | case "sq":
|
---|
| 211 | return eLineCap.Square;
|
---|
| 212 | default:
|
---|
| 213 | return eLineCap.Flat;
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 | #endregion
|
---|
| 217 |
|
---|
| 218 |
|
---|
| 219 | //public ExcelDrawingFont Font
|
---|
| 220 | //{
|
---|
| 221 | // get
|
---|
| 222 | // {
|
---|
| 223 |
|
---|
| 224 | // }
|
---|
| 225 | //}
|
---|
| 226 | }
|
---|
| 227 | }
|
---|