forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPage.cpp
189 lines (142 loc) · 4.12 KB
/
Page.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//
// Page.cpp
//
// $Id: //poco/Main/PDF/src/Page.cpp#2 $
//
// Library: PDF
// Package: PDFCore
// Module: Page
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/PDF/Page.h"
#include "Poco/PDF/PDFException.h"
#undef min
#undef max
#include <limits>
namespace Poco {
namespace PDF {
Page::Page(HPDF_Doc* pPDF,
const HPDF_Page& page,
Size pageSize,
Orientation orientation):
_pPDF(pPDF),
_page(page),
_size(pageSize),
_orientation(orientation),
_pCurrentFont(0)
{
}
Page::Page(const Page& other):
_pPDF(other._pPDF),
_page(other._page),
_size(other._size),
_orientation(other._orientation)
{
}
Page::~Page()
{
}
Page& Page::operator = (const Page& page)
{
Page tmp(page);
swap(tmp);
return *this;
}
void Page::swap(Page& other)
{
using std::swap;
swap(_pPDF, other._pPDF);
swap(_page, other._page);
swap(_size, other._size);
swap(_orientation, other._orientation);
}
void Page::writeOnce(float xPos, float yPos, const std::string& text)
{
beginText();
write(xPos, yPos, text);
endText();
}
int Page::writeOnceInRectangle(float left,
float top,
float right,
float bottom,
const std::string& text,
TextAlignment align)
{
beginText();
int ret = writeInRectangle(left, top, right, bottom, text, align);
endText();
return ret;
}
float Page::textWidth(const std::string& text)
{
return HPDF_Page_TextWidth(_page, text.c_str());
}
void Page::setRotation(int angle)
{
if (0 != angle % 90 || angle > std::numeric_limits<HPDF_UINT16>::max())
throw InvalidArgumentException("Invalid angle value.");
HPDF_Page_SetRotate(_page, static_cast<HPDF_UINT16>(angle));
}
const Destination& Page::createDestination(const std::string& name)
{
DestinationContainer::iterator it = _destinations.find(name);
if (_destinations.end() != it)
throw InvalidArgumentException("Destination already exists.");
Destination dest(_pPDF, HPDF_Page_CreateDestination(_page), name);
std::pair<DestinationContainer::iterator, bool> ret =
_destinations.insert(DestinationContainer::value_type(name, dest));
if (ret.second) return ret.first->second;
throw IllegalStateException("Could not create destination.");
}
const TextAnnotation& Page::createTextAnnotation(const std::string& name,
const Rectangle& rect,
const std::string& text,
const Encoder& encoder)
{
TextAnnotationContainer::iterator it = _textAnnotations.find(name);
if (_textAnnotations.end() != it)
throw InvalidArgumentException("Annotation already exists.");
TextAnnotation ann(_pPDF,
HPDF_Page_CreateTextAnnot(_page, rect, text.c_str(), encoder),
name);
std::pair<TextAnnotationContainer::iterator, bool> ret =
_textAnnotations.insert(TextAnnotationContainer::value_type(name, ann));
if (ret.second) return ret.first->second;
throw IllegalStateException("Could not create annotation.");
}
const LinkAnnotation& Page::createLinkAnnotation(const std::string& name,
const Rectangle& rect,
const Destination& dest)
{
LinkAnnotationContainer::iterator it = _linkAnnotations.find(name);
if (_linkAnnotations.end() != it)
throw InvalidArgumentException("Annotation already exists.");
LinkAnnotation ann(_pPDF,
HPDF_Page_CreateLinkAnnot(_page, rect, dest),
name);
std::pair<LinkAnnotationContainer::iterator, bool> ret =
_linkAnnotations.insert(LinkAnnotationContainer::value_type(name, ann));
if (ret.second) return ret.first->second;
throw IllegalStateException("Could not create annotation.");
}
const LinkAnnotation& Page::createURILinkAnnotation(const std::string& name,
const Rectangle& rect,
const std::string& uri)
{
LinkAnnotationContainer::iterator it = _linkAnnotations.find(name);
if (_linkAnnotations.end() != it)
throw InvalidArgumentException("Annotation already exists.");
LinkAnnotation ann(_pPDF,
HPDF_Page_CreateURILinkAnnot(_page, rect, uri.c_str()),
name);
std::pair<LinkAnnotationContainer::iterator, bool> ret =
_linkAnnotations.insert(LinkAnnotationContainer::value_type(name, ann));
if (ret.second) return ret.first->second;
throw IllegalStateException("Could not create annotation.");
}
} } // namespace Poco::PDF