1 | // |
---|---|
2 | // AttributedString.cpp |
3 | // |
4 | // Library: PDF |
5 | // Package: PDFCore |
6 | // Module: AttributedString |
7 | // |
8 | // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | |
15 | #include "Poco/PDF/AttributedString.h" |
16 | #include "Poco/Format.h" |
17 | |
18 | namespace Poco { |
19 | namespace PDF { |
20 | |
21 | |
22 | AttributedString::AttributedString() |
23 | { |
24 | } |
25 | |
26 | |
27 | AttributedString::AttributedString(const char* content): _content(content) |
28 | { |
29 | } |
30 | |
31 | |
32 | AttributedString::AttributedString(const std::string& content, Alignment align, int style): |
33 | _content(content), _align(align), _style(static_cast<Style>(style)) |
34 | { |
35 | } |
36 | |
37 | |
38 | AttributedString::~AttributedString() |
39 | { |
40 | } |
41 | |
42 | |
43 | void AttributedString::setAttribute(int attr, const Poco::Dynamic::Var& value) |
44 | { |
45 | switch (attr) |
46 | { |
47 | case ATTR_FONT: |
48 | _fontName = value.toString(); |
49 | return; |
50 | case ATTR_SIZE: |
51 | _fontSize = value; |
52 | return; |
53 | case ATTR_STYLE: |
54 | _style = value.convert<int>(); |
55 | return; |
56 | case ATTR_ALIGN: |
57 | _align = static_cast<Alignment>(value.convert<int>()); |
58 | return; |
59 | default: |
60 | throw InvalidArgumentException( |
61 | format("AttributeString::setAttribute: %d", attr)); |
62 | } |
63 | } |
64 | |
65 | |
66 | Poco::Dynamic::Var AttributedString::getAttribute(int attr) |
67 | { |
68 | switch (attr) |
69 | { |
70 | case ATTR_FONT: return _fontName; |
71 | case ATTR_SIZE: return _fontSize; |
72 | case ATTR_STYLE: return static_cast<int>(_style); |
73 | case ATTR_ALIGN: return static_cast<int>(_align); |
74 | default: |
75 | throw InvalidArgumentException( |
76 | format("AttributeString::setAttribute: %d", attr)); |
77 | } |
78 | } |
79 | |
80 | |
81 | void AttributedString::clearAttribute(int attr) |
82 | { |
83 | switch (attr) |
84 | { |
85 | case ATTR_FONT: _fontName = "Helvetica"; return; |
86 | case ATTR_SIZE: _fontSize = 10; return; |
87 | case ATTR_STYLE: _style = STYLE_PLAIN; return; |
88 | case ATTR_ALIGN: _align = ALIGN_LEFT; return; |
89 | default: |
90 | throw InvalidArgumentException( |
91 | format("AttributeString::setAttribute: %d", attr)); |
92 | } |
93 | } |
94 | |
95 | |
96 | } } // namespace Poco::PDF |
97 |