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