1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Globalization;
|
---|
4 | using System.Linq;
|
---|
5 | using System.Text;
|
---|
6 | using System.Xml;
|
---|
7 |
|
---|
8 | namespace OfficeOpenXml.Style.Dxf
|
---|
9 | {
|
---|
10 | public abstract class DxfStyleBase<T>
|
---|
11 | {
|
---|
12 | protected ExcelStyles _styles;
|
---|
13 | internal DxfStyleBase(ExcelStyles styles)
|
---|
14 | {
|
---|
15 | _styles = styles;
|
---|
16 | AllowChange = false; //Don't touch this value in the styles.xml (by default). When Dxfs is fully implemented this can be removed.
|
---|
17 | }
|
---|
18 | protected internal abstract string Id { get; }
|
---|
19 | protected internal abstract bool HasValue{get;}
|
---|
20 | protected internal abstract void CreateNodes(XmlHelper helper, string path);
|
---|
21 | protected internal abstract T Clone();
|
---|
22 | protected void SetValueColor(XmlHelper helper,string path, ExcelDxfColor color)
|
---|
23 | {
|
---|
24 | if (color != null && color.HasValue)
|
---|
25 | {
|
---|
26 | if (color.Color != null)
|
---|
27 | {
|
---|
28 | SetValue(helper, path + "/@rgb", color.Color.Value.ToArgb().ToString("x"));
|
---|
29 | }
|
---|
30 | else if (color.Auto != null)
|
---|
31 | {
|
---|
32 | SetValueBool(helper, path + "/@auto", color.Auto);
|
---|
33 | }
|
---|
34 | else if (color.Theme != null)
|
---|
35 | {
|
---|
36 | SetValue(helper, path + "/@theme", color.Theme);
|
---|
37 | }
|
---|
38 | else if (color.Index != null)
|
---|
39 | {
|
---|
40 | SetValue(helper, path + "/@indexed", color.Index);
|
---|
41 | }
|
---|
42 | if (color.Tint != null)
|
---|
43 | {
|
---|
44 | SetValue(helper, path + "/@tint", color.Tint);
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|
48 | /// <summary>
|
---|
49 | /// Same as SetValue but will set first char to lower case.
|
---|
50 | /// </summary>
|
---|
51 | /// <param name="helper"></param>
|
---|
52 | /// <param name="path"></param>
|
---|
53 | /// <param name="v"></param>
|
---|
54 | protected void SetValueEnum(XmlHelper helper, string path, Enum v)
|
---|
55 | {
|
---|
56 | if (v == null)
|
---|
57 | {
|
---|
58 | helper.DeleteNode(path);
|
---|
59 | }
|
---|
60 | else
|
---|
61 | {
|
---|
62 | var s = v.ToString();
|
---|
63 | s = s.Substring(0, 1).ToLower(CultureInfo.InvariantCulture) + s.Substring(1);
|
---|
64 | helper.SetXmlNodeString(path, s);
|
---|
65 | }
|
---|
66 | }
|
---|
67 | protected void SetValue(XmlHelper helper, string path, object v)
|
---|
68 | {
|
---|
69 | if (v == null)
|
---|
70 | {
|
---|
71 | helper.DeleteNode(path);
|
---|
72 | }
|
---|
73 | else
|
---|
74 | {
|
---|
75 | helper.SetXmlNodeString(path, v.ToString());
|
---|
76 | }
|
---|
77 | }
|
---|
78 | protected void SetValueBool(XmlHelper helper, string path, bool? v)
|
---|
79 | {
|
---|
80 | if (v == null)
|
---|
81 | {
|
---|
82 | helper.DeleteNode(path);
|
---|
83 | }
|
---|
84 | else
|
---|
85 | {
|
---|
86 | helper.SetXmlNodeBool(path, (bool)v);
|
---|
87 | }
|
---|
88 | }
|
---|
89 | protected internal string GetAsString(object v)
|
---|
90 | {
|
---|
91 | return (v ?? "").ToString();
|
---|
92 | }
|
---|
93 | /// <summary>
|
---|
94 | /// Is this value allowed to be changed?
|
---|
95 | /// </summary>
|
---|
96 | protected internal bool AllowChange { get; set; }
|
---|
97 | }
|
---|
98 | }
|
---|