forked from yurial/libmsdoc.work
/
cborderline.cpp
102 lines (90 loc) · 2.43 KB
/
cborderline.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <sstream>
#include <map>
#include "cinitializer.h"
#include "cborderline.h"
static std::map<EBORDERSTYLE,TString> g_styles;
struct SBorderStyle
{
EBORDERSTYLE m_style;
TString m_stylename;
};
SBorderStyle g_stylesarr[] = {
{ EBORDERSTYLE_NONE, "none" },
{ EBORDERSTYLE_DASHDOT, "dashDot" },
{ EBORDERSTYLE_DASHDOTDOT, "dashDotDot" },
{ EBORDERSTYLE_DASHED, "dashed" },
{ EBORDERSTYLE_DOTTED, "dotted" },
{ EBORDERSTYLE_DOUBLE, "double" },
{ EBORDERSTYLE_HAIR, "hair" },
{ EBORDERSTYLE_MEDIUM, "medium" },
{ EBORDERSTYLE_MEDIUMDASHDOT, "mediumDashDot" },
{ EBORDERSTYLE_MEDIUMDASHDOTDOT,"mediumdashDotDot" },
{ EBORDERSTYLE_MEDIUMDASHED, "mediumDashed" },
{ EBORDERSTYLE_SLANTDASHDOT, "slantDashDot" },
{ EBORDERSTYLE_THINCK, "thinck" },
{ EBORDERSTYLE_THIN, "thin" },
};
void borderstyle_init_f()
{
for (unsigned int pos = 0; pos < sizeof(g_stylesarr)/sizeof(SBorderStyle); ++pos)
{
g_styles.insert( std::make_pair( g_stylesarr[ pos ].m_style, g_stylesarr[ pos ].m_stylename ) );
}
}
TInitializer borderstyle_init( borderstyle_init_f );
CBorderLine::CBorderLine():
m_style( EBORDERSTYLE_NONE )
{
}
CBorderLine::CBorderLine(EBORDERSTYLE style):
m_style( style )
{
}
CBorderLine::CBorderLine(EBORDERSTYLE style, const TColor& color):
m_color( color ), m_style( style )
{
}
bool CBorderLine::operator < (const CBorderLine& rvalue) const
{
if ( m_style < rvalue.m_style )
{
return true;
}
else if ( rvalue.m_style < m_style )
{
return false;
}
else if ( m_color < rvalue.m_color )
{
return true;
}
else if ( rvalue.m_color < m_color )
{
return false;
}
return false;
}
TString CBorderLine::save(const TString& tag) const
{
if ( !IsSet() )
{
return TString();
}
std::stringstream border;
border << '<' << tag << " style=\"" << g_styles[ m_style ] << '\"';
if ( m_color.IsSet() )
{
border << '>' << '\n';
border << "<color" << m_color.save() << '/' << '>' << '\n';
border << '<' << '/' << tag << '>' << '\n';
}
else
{
border << '/' << '>' << '\n';
}
return border.str();
}
bool CBorderLine::IsSet() const
{
return EBORDERSTYLE_NONE != m_style || m_color.IsSet();
}