-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathfilepdf.cpp
292 lines (196 loc) · 5.84 KB
/
filepdf.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
License: GPL-2
An electronic filing cabinet: scan, print, stack, arrange
Copyright (C) 2009 Simon Glass, [email protected]
.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
X-Comment: On Debian GNU/Linux systems, the complete text of the GNU General
Public License can be found in the /usr/share/common-licenses/GPL file.
*/
#include <QDebug>
#include <QFile>
#include "filepdf.h"
#include "pdfio.h"
#define DPI 300.0
Filepdf::Filepdf (const QString &dir, const QString &filename, Desk *desk)
: File (dir, filename, desk, Type_pdf)
{
_pdfio = 0;
}
Filepdf::~Filepdf ()
{
if (_pdfio)
delete _pdfio;
}
err_info *Filepdf::load (void)
{
if (!_pdfio)
_pdfio = new Pdfio (_pathname);
if (!_valid)
{
CALL (_pdfio->open ());
_valid = true;
}
return NULL;
}
// was desk->ensureMax
/** create the file (on the filesystem). It doesn't need to be written to
as we will call flush() later for that */
err_info *Filepdf::create (void)
{
if (!_pdfio)
_pdfio = new Pdfio (_pathname);
return _pdfio->create ();
}
err_info *Filepdf::flush (void)
{
return _pdfio->flush ();
}
err_info *Filepdf::remove (void)
{
//FIXME: perhaps this should be implemented by File
// currently only works if the object is about to be destroyed
QFile file (_dir + _filename);
if (file.exists () && !file.remove ())
return err_make (ERRFN, ERR_could_not_remove_file2,
file.fileName ().toLatin1 ().constData(),
file.errorString ().toLatin1 ().constData());
return NULL;
}
int Filepdf::pagecount (void)
{
if (_pdfio)
return _pdfio->numPages ();
return 1;
}
// accessing and changing metadata
err_info *Filepdf::getPageTitle (int pagenum, QString &title)
{
return _pdfio->getPageTitle (pagenum, title);
}
err_info *Filepdf::getAnnot (e_annot type, QString &text)
{
QString name = getAnnotName (type);
return _pdfio->getAnnot (name, text);
}
err_info *Filepdf::putAnnot (QHash<int, QString> &)
{
return not_impl ();
}
err_info *Filepdf::putEnvelope (QStringList &)
{
return not_impl ();
}
err_info *Filepdf::getPageText (int pagenum, QString &str)
{
return _pdfio->getPageText (pagenum, str);
}
/** gets the total size of a file in bytes. this should include data not
yet flushed to the filesystem */
int Filepdf::getSize (void)
{
return _size;
}
err_info *Filepdf::renamePage (int, QString &)
{
return not_impl ();
}
err_info *Filepdf::getImageInfo (int pagenum, QSize &size,
QSize &true_size, int &bpp, int &image_size, int &compressed_size,
QDateTime ×tamp)
{
if (!_pdfio)
return NULL;
CALL (_pdfio->getImageSize (pagenum, false, size, bpp));
true_size = size;
image_size = size.width () * size.height () * bpp / 8;
compressed_size = -1;
timestamp = _timestamp;
return NULL;
}
err_info *Filepdf::getPreviewInfo (int pagenum, QSize &size, int &bpp)
{
return _pdfio->getImageSize (pagenum, true, size, bpp);
}
// image related
QPixmap Filepdf::pixmap (bool recalc)
{
err_info *err = NULL;
if (recalc)
err = getPreviewPixmap (_pagenum, _pixmap, false);
return err || _pixmap.isNull () ? unknownPixmap () : _pixmap;
}
err_info *Filepdf::getPreviewPixmap (int pagenum, QPixmap &pixmap, bool blank)
{
QImage image;
CALL (_pdfio->getImage (_filename, pagenum, image, DPI / 24, DPI / 24, true));
if (blank)
colour_image_for_blank (image);
pixmap = QPixmap::fromImage(image);
// qDebug () << "pixmap" << pixmap.width () << pixmap.height ();
return NULL;
}
err_info *Filepdf::getImage (int pagenum, bool,
QImage &image, QSize &size, QSize &trueSize, int &bpp, bool blank)
{
// this gives us the page size at 72dpi, but does work for our DPI
// CALL (_pdfio->getImageSize (pagenum, size));
CALL (_pdfio->getImage (_filename, pagenum, image, DPI, DPI, false));
if (blank)
colour_image_for_blank (image);
trueSize = size = image.size ();
bpp = image.depth ();
// qDebug () << "pixmap" << pixmap.width () << pixmap.height ();
return NULL;
}
// operations on files
err_info *Filepdf::addPage (const Filepage *mp, bool do_flush)
{
CALL (_pdfio->addPage (mp));
if (do_flush)
CALL (flush ());
return NULL;
}
err_info *Filepdf::removePages (QBitArray &,
QByteArray &, int &)
{
return not_impl ();
}
err_info *Filepdf::restorePages (QBitArray &,
QByteArray &, int )
{
return not_impl ();
}
err_info *Filepdf::unstackPages (int pagenum, int pagecount, bool remove,
File *fdest)
{
Filepdf *dest = (Filepdf *)fdest;
CALL (dest->_pdfio->insertPages (_pdfio, pagenum, pagecount));
// now remove from src file if required
if (remove)
CALL (_pdfio->deletePages (pagenum, pagecount));
return NULL;
}
err_info *Filepdf::stackStack (File *fsrc)
{
Filepdf *src = (Filepdf *)fsrc;
return _pdfio->appendFrom (src->_pdfio);
}
err_info *Filepdf::duplicate (File *&, File::e_type, const QString &,
int, Operation &, bool &supported)
{
supported = false;
return NULL;
}