-
Notifications
You must be signed in to change notification settings - Fork 2
/
nsrabstractdocument.h
399 lines (348 loc) · 9.66 KB
/
nsrabstractdocument.h
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
#ifndef __NSRABSTRACTDOCUMENT_H__
#define __NSRABSTRACTDOCUMENT_H__
/**
* @file nsrabstractdocument.h
* @author Alexander Saprykin
* @brief Base class for supported file type
*/
#include "nsrcroppads.h"
#include "nsrrenderinfo.h"
#include "nsrtocentry.h"
#include "nsrreadercore_global.h"
#include <QObject>
#include <QtGui/QPixmap>
#ifdef Q_OS_BLACKBERRY
# include <bb/ImageData>
# include <bb/PixelFormat>
#else
# include <QImage>
#endif
/** Maximum memroy available for files rendering, bytes */
#define NSR_CORE_DOCUMENT_MAX_HEAP (0x6000000)
/** @def NSR_CORE_IMAGE_DATATYPE Rendered page image type */
#ifdef Q_OS_BLACKBERRY
# define NSR_CORE_IMAGE_DATATYPE bb::ImageData
#else
# define NSR_CORE_IMAGE_DATATYPE QImage
#endif
/**
* @class NSRAbstractDocument nsrabstractdocument.h
* @brief Base class for supported file type
*
* Implement it to add support for any file type.
*/
class NSRREADERCORE_SHARED NSRAbstractDocument : public QObject
{
Q_OBJECT
Q_ENUMS (NSRDocumentError)
Q_ENUMS (NSRDocumentStyle)
Q_ENUMS (NSRDocumentRotation)
public:
/** File errors */
enum NSRDocumentError {
NSR_DOCUMENT_ERROR_NO = 0, /**< No errors */
NSR_DOCUMENT_ERROR_PASSWD = 1, /**< Invalid password */
NSR_DOCUMENT_ERROR_TOO_LARGE = 2, /**< File is too large */
NSR_DOCUMENT_ERROR_UNKNOWN = 3 /**< Unknown error */
};
/** Representing style */
enum NSRDocumentStyle {
NSR_DOCUMENT_STYLE_GRAPHIC = 1, /**< Graphic (image) */
NSR_DOCUMENT_STYLE_TEXT = 2 /**< Text only */
};
/** Rotation angle (clockwise) */
enum NSRDocumentRotation {
NSR_DOCUMENT_ROTATION_0 = 0, /**< No rotation */
NSR_DOCUMENT_ROTATION_90 = 90, /**< 90 degrees */
NSR_DOCUMENT_ROTATION_180 = 180, /**< 180 degrees */
NSR_DOCUMENT_ROTATION_270 = 270 /**< 270 degrees */
};
/**
* @brief Constructor with parameters
* @param file Path to file.
* @param parent Parent object.
*/
explicit NSRAbstractDocument (const QString& file, QObject *parent = 0);
/**
* @brief Destructor
*/
virtual ~NSRAbstractDocument ();
/**
* @brief Gets page count in file
* @return Page count in file.
*/
virtual int getPageCount () const = 0;
/**
* @brief Renders page internally
* @param page Page number to render, starts from 1.
*/
virtual NSRRenderInfo renderPage (int page) = 0;
/**
* @brief Gets last rendered page image
* @return Last rendered page image in case of success,
* empty object otherwise.
*/
virtual NSR_CORE_IMAGE_DATATYPE getCurrentPage () = 0;
/**
* @brief Checks whether the file is valid
* @return True if file is valid and opened successfully, false
* otherwise.
*/
virtual bool isValid () const = 0;
/**
* @brief Checks whether file supports given representing style
* @param style Style to check.
* @return True is file supports style, false otherwise.
*/
virtual bool isDocumentStyleSupported (NSRAbstractDocument::NSRDocumentStyle style) const = 0;
/**
* @brief Gets preferred representing style
* @return Preferred representing style.
*/
virtual NSRAbstractDocument::NSRDocumentStyle getPreferredDocumentStyle () const = 0;
/**
* @brief Indicates whether file has dynamic page count
* @return True in case of success, false otherwise.
* @since 1.5.2
*/
virtual bool hasDynamicPages () const = 0;
/**
* @brief Gets file TOC if any
* @return TOC in case of success, NULL otherwise.
* @since 1.5.2
*
* Caller takes ownership of the returned object.
*/
virtual NSRTocEntry * getToc () const = 0;
/**
* @brief Gets path to file
* @return Path to file.
*/
inline QString getDocumentPath () const {
return _docPath;
}
/**
* @brief Gets current zoom
* @return Current zoom, in %.
*/
virtual double getZoom () const {
return _zoom;
}
/**
* @brief Sets current zoom
* @param zoom Current zoom, in %.
* @note Zoom to width option will be reseted.
*/
virtual void setZoom (double zoom);
/**
* @brief Gets page width
* @return Page width for rendering.
* @note Used only if zoom to width is enabled and as crop
* limiter when zoom to width is disabled.
*/
virtual int getPageWidth () const {
return _pageWidth;
}
/**
* @brief Sets page width
* @param pageWidth Page width for rendering.
* @note Used only if zoom to width is enabled and as crop
* limiter when zoom to width is disabled.
*/
virtual void setPageWidth (int pageWidth) {
_pageWidth = pageWidth;
}
/**
* @brief Sets zoom to width option
* @param toWidth Whether to render page to it's width.
* @note Use setPageWidth() to set page width.
*/
virtual void setZoomToWidth (bool toWidth) {
_zoomToWidth = toWidth;
}
/**
* @brief Checks whether zoom to width option is enabled.
* @return True is zoom to width option is enabled, false otherwise.
*/
virtual bool isZoomToWidth () const {
return _zoomToWidth;
}
/**
* @brief Rotates page left by 90 degrees
*/
void rotateLeft ();
/**
* @brief Rotates page right by 90 degrees
*/
void rotateRight ();
/**
* @brief Gets rotation angle
* @return Rotation angle.
* @note Only 0, 90, 180, 270 degrees angles are supported.
*/
virtual NSRAbstractDocument::NSRDocumentRotation getRotation () const {
return _rotation;
}
/**
* @brief Sets rotation angle
* @param rotation Rotation angle.
* @note Only 0, 90, 180, 270 degrees angles are supported.
*/
virtual void setRotation (NSRAbstractDocument::NSRDocumentRotation rotation);
/**
* @brief Gets page text (if available).
* @return Page text.
*/
virtual QString getText () {
return QString ();
}
/**
* @brief Checks whether only text data is retrieved on rendering
* @return True if only text data is retrieved from file on page
* rendering.
*/
virtual bool isTextOnly () const {
return _textOnly;
}
/**
* @brief Sets text only rendering mode
* @param textOnly Text only rendering mode.
*/
virtual void setTextOnly (bool textOnly) {
_textOnly = textOnly;
}
/**
* @brief Checks whether inverted colors rendering mode is enabled
* @return True is inverted colors rendering mode is enabled, false
* otherwise.
*/
virtual bool isInvertedColors () const {
return _invertedColors;
}
/**
* @brief Sets inverted colors rendering mode
* @param isInverted Inverted colors rendering mode.
*/
virtual void setInvertedColors (bool isInverted) {
_invertedColors = isInverted;
}
/**
* @brief Checks whether autocrop option is enabled
* @return True if autocrop option is enabled, false otherwise.
*/
virtual bool isAutoCrop () const {
return _autoCrop;
}
/**
* @brief Sets autocrop option
* @param isAutoCrop Autocrop option.
*/
virtual void setAutoCrop (bool isAutoCrop) {
_autoCrop = isAutoCrop;
}
/**
* @brief Gets page crop pads
* @return Page crop pads.
* @since 1.4.2
*
* Only has meaning if autocrop feature is enabled.
*/
virtual NSRCropPads getCropPads () const {
return _cropPads;
}
/**
* @brief Sets page crop pads
* @param pads Page crop pads.
* @since 1.4.2
*
* Only has meaning if autocrop feature is enabled.
*/
virtual void setCropPads (const NSRCropPads& pads) {
_cropPads = pads;
}
/**
* @brief Gets file password
* @return File password.
*/
virtual QString getPassword () const {
return _password;
}
/**
* @brief Sets file password
* @param passwd File password.
*/
virtual void setPassword (const QString& passwd) {
_password = passwd;
}
/**
* @brief Checks whether text encoding is used to decode
* text data
* @return True if encoding is used, false otherwise.
*/
virtual bool isEncodingUsed () const {
return false;
}
/**
* @brief Gets text encoding
* @return Text encoding.
*/
virtual QString getEncoding () const {
return _encoding;
}
/**
* @brief Sets text encoding
* @param enc Text encoding.
* @sa QTextCodec
*/
virtual void setEncoding (const QString& enc);
/**
* @brief Gets last occurred error
* @return Last occurred error.
*/
NSRDocumentError getLastError () const {
return _lastError;
}
protected:
/**
* @brief Sets zoom without reseting zoom to width flag
* @param zoom Zoom value, in %.
*/
void setZoomSilent (double zoom) {
_zoom = zoom;
}
/**
* @brief Sets last occurred error
* @param err Last occurred error.
*/
void setLastError (NSRDocumentError err) {
_lastError = err;
}
/**
* @brief Validates page zoom for maximum supported
* @param pageSize Page size.
* @param zoom Zoom value, in %.
* @return Corrected (if need) zoom value, in %.
*/
double validateMaxZoom (const QSize& pageSize, double zoom) const;
/**
* @brief Gets max zoom available for given page size
* @param pageSize Page size.
* @return Max zoom value available, in %.
* @since 1.4.3
*/
double getMaxZoom (const QSize& pageSize) const;
private:
NSRCropPads _cropPads; /**< Page crop pads */
QString _docPath; /**< File path */
QString _password; /**< File password */
QString _encoding; /**< Text encoding */
double _zoom; /**< Current zoom, % */
int _pageWidth; /**< Page width */
bool _zoomToWidth; /**< Zoom to width */
bool _textOnly; /**< Text only mode */
bool _invertedColors; /**< Inverted colors mode */
bool _autoCrop; /**< Autocrop */
NSRDocumentError _lastError; /**< Last error */
NSRDocumentRotation _rotation; /**< Rotation angle */
};
#endif /* __NSRABSTRACTDOCUMENT_H__ */