Repository navigation
Expand file tree
/
Copy pathPdfModule.cpp
More file actions
185 lines (154 loc) · 3.46 KB
/
Copy pathPdfModule.cpp
File metadata and controls
185 lines (154 loc) · 3.46 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
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
/**
*
* @file PdfModule.cpp
* @author Gaspard Kirira
*
* Copyright 2026, Gaspard Kirira.
* All rights reserved.
* https://github.com/rixcpp/pdf
*
* Use of this source code is governed by a MIT license
* that can be found in the License file.
*
* Rix
*
*/
#include <rix/pdf/PdfModule.hpp>
#include <utility>
namespace rixlib::pdf
{
PdfError PdfErrorModule::none() const
{
return make_pdf_ok();
}
PdfError PdfErrorModule::make(
PdfErrorCode code,
std::string message) const
{
return make_pdf_error(
code,
std::move(message));
}
std::string_view PdfErrorModule::to_string(
PdfErrorCode code) const noexcept
{
return rixlib::pdf::to_string(code);
}
std::string_view PdfErrorModule::to_string(
const PdfError &error) const noexcept
{
return rixlib::pdf::to_string(error.code());
}
bool PdfErrorModule::ok(const PdfError &error) const noexcept
{
return error.ok();
}
bool PdfErrorModule::failed(const PdfError &error) const noexcept
{
return error.has_error();
}
bool PdfErrorModule::is(
const PdfError &error,
PdfErrorCode code) const noexcept
{
return error.is(code);
}
PdfResult<Image> PdfImageModule::load_jpeg(
std::string_view path) const
{
return Image::load_jpeg(path);
}
PdfResult<Image> PdfImageModule::from_jpeg_bytes(
std::vector<std::uint8_t> bytes) const
{
return Image::from_jpeg_bytes(std::move(bytes));
}
PdfResult<std::string> PdfWriterModule::write(
const Document &document) const
{
writer::PdfWriter pdf_writer;
return pdf_writer.write(document);
}
PdfStatus PdfWriterModule::save(
const Document &document,
std::string_view path) const
{
writer::PdfWriter pdf_writer;
return pdf_writer.save(document, path);
}
writer::PdfWriter PdfWriterModule::create() const
{
return writer::PdfWriter{};
}
Document PdfModule::document() const
{
return Document{};
}
Document PdfModule::document(
PageSize page_size,
Margins margins) const
{
return Document{
page_size,
margins};
}
PdfResult<std::string> PdfModule::write(
const Document &document) const
{
return writer.write(document);
}
PdfStatus PdfModule::save(
const Document &document,
std::string_view path) const
{
return writer.save(document, path);
}
PdfStatus PdfModule::make_text(
std::string_view path,
std::string_view content,
std::string_view title) const
{
auto doc = document();
if (!title.empty())
{
doc.set_title(std::string(title));
}
auto &page = doc.add_page();
auto y = page.y_top();
if (!title.empty())
{
y = page.heading(
page.x_left(),
y,
title,
1);
y -= 10.0F;
}
page.paragraph(
page.x_left(),
y,
page.content_width(),
content);
return save(doc, path);
}
std::string PdfModule::version() const
{
return rixlib::pdf::version();
}
int PdfModule::version_major() const noexcept
{
return rixlib::pdf::version_major();
}
int PdfModule::version_minor() const noexcept
{
return rixlib::pdf::version_minor();
}
int PdfModule::version_patch() const noexcept
{
return rixlib::pdf::version_patch();
}
int PdfModule::version_number() const noexcept
{
return rixlib::pdf::version_number();
}
} // namespace rixlib::pdf