forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttributedString.cpp
More file actions
99 lines (81 loc) · 1.86 KB
/
AttributedString.cpp
File metadata and controls
99 lines (81 loc) · 1.86 KB
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
//
// AttributedString.cpp
//
#include "Poco/PDF/AttributedString.h"
#include "Poco/Format.h"
namespace Poco {
namespace PDF {
AttributedString::AttributedString():
_align(ALIGN_LEFT),
_style(STYLE_PLAIN),
_fontName("Helvetica"),
_fontSize(10)
{
}
AttributedString::AttributedString(const char* content):
_content(content),
_align(ALIGN_LEFT),
_style(STYLE_PLAIN),
_fontName("Helvetica"),
_fontSize(10)
{
}
AttributedString::AttributedString(const std::string& content, Alignment align, int style):
_content(content),
_align(align),
_style(static_cast<Style>(style)),
_fontName("Helvetica"),
_fontSize(10)
{
}
AttributedString::~AttributedString()
{
}
void AttributedString::setAttribute(int attr, const Poco::Dynamic::Var& value)
{
switch (attr)
{
case ATTR_FONT:
_fontName = value.toString();
return;
case ATTR_SIZE:
_fontSize = value;
return;
case ATTR_STYLE:
_style = value.convert<int>();
return;
case ATTR_ALIGN:
_align = static_cast<Alignment>(value.convert<int>());
return;
default:
throw InvalidArgumentException(
format("AttributeString::setAttribute: %d", attr));
}
}
Poco::Dynamic::Var AttributedString::getAttribute(int attr)
{
switch (attr)
{
case ATTR_FONT: return _fontName;
case ATTR_SIZE: return _fontSize;
case ATTR_STYLE: return static_cast<int>(_style);
case ATTR_ALIGN: return static_cast<int>(_align);
default:
throw InvalidArgumentException(
format("AttributeString::setAttribute: %d", attr));
}
}
void AttributedString::clearAttribute(int attr)
{
switch (attr)
{
case ATTR_FONT: _fontName = "Helvetica"; return;
case ATTR_SIZE: _fontSize = 10; return;
case ATTR_STYLE: _style = STYLE_PLAIN; return;
case ATTR_ALIGN: _align = ALIGN_LEFT; return;
default:
throw InvalidArgumentException(
format("AttributeString::setAttribute: %d", attr));
}
}
} } // namespace Poco::PDF