-
Notifications
You must be signed in to change notification settings - Fork 2
/
nsrabstractdocument.cpp
97 lines (84 loc) · 2.47 KB
/
nsrabstractdocument.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
#include "nsrabstractdocument.h"
#include <QTextCodec>
#ifdef Q_OS_BLACKBERRY
# define NSR_CORE_MAX_PAGE_WIDTH 4000
# define NSR_CORE_MAX_PAGE_HEIGHT 4000
#else
# define NSR_CORE_MAX_PAGE_WIDTH 2000
# define NSR_CORE_MAX_PAGE_HEIGHT 2000
#endif
NSRAbstractDocument::NSRAbstractDocument (const QString& file, QObject *parent) :
QObject (parent),
_docPath (file),
_encoding ("UTF-8"),
_zoom (100.0),
_pageWidth (360),
_zoomToWidth (false),
_textOnly (false),
_invertedColors (false),
_autoCrop (false),
_lastError (NSR_DOCUMENT_ERROR_NO),
_rotation (NSR_DOCUMENT_ROTATION_0)
{
}
NSRAbstractDocument::~NSRAbstractDocument ()
{
}
void
NSRAbstractDocument::rotateLeft ()
{
_rotation = (_rotation == NSRAbstractDocument::NSR_DOCUMENT_ROTATION_0) ?
NSRAbstractDocument::NSR_DOCUMENT_ROTATION_270 :
(NSRAbstractDocument::NSRDocumentRotation) (((int) _rotation) - 90);
}
void
NSRAbstractDocument::rotateRight ()
{
_rotation = (_rotation == NSRAbstractDocument::NSR_DOCUMENT_ROTATION_270) ?
NSRAbstractDocument::NSR_DOCUMENT_ROTATION_0 :
(NSRAbstractDocument::NSRDocumentRotation) (((int) _rotation) + 90);
}
void
NSRAbstractDocument::setRotation (NSRAbstractDocument::NSRDocumentRotation rotation)
{
switch (rotation) {
case NSRAbstractDocument::NSR_DOCUMENT_ROTATION_0:
case NSRAbstractDocument::NSR_DOCUMENT_ROTATION_90:
case NSRAbstractDocument::NSR_DOCUMENT_ROTATION_180:
case NSRAbstractDocument::NSR_DOCUMENT_ROTATION_270:
_rotation = rotation;
break;
default:
_rotation = NSRAbstractDocument::NSR_DOCUMENT_ROTATION_0;
break;
}
}
void
NSRAbstractDocument::setEncoding (const QString &enc)
{
/* Empty encoding means we will use autodetection */
if (!enc.isEmpty () && QTextCodec::codecForName (enc.toAscii ()) == NULL)
return;
else
_encoding = enc;
}
void
NSRAbstractDocument::setZoom (double zoom)
{
_zoom = zoom;
_zoomToWidth = false;
}
double
NSRAbstractDocument::validateMaxZoom (const QSize& pageSize, double zoom) const
{
if (pageSize.width () * zoom / 100.0 <= NSR_CORE_MAX_PAGE_WIDTH &&
pageSize.height () * zoom / 100.0 <= NSR_CORE_MAX_PAGE_HEIGHT)
return zoom;
return getMaxZoom (pageSize);
}
double NSRAbstractDocument::getMaxZoom (const QSize &pageSize) const
{
double scale = qMin (NSR_CORE_MAX_PAGE_WIDTH / (double) pageSize.width (),
NSR_CORE_MAX_PAGE_HEIGHT / (double) pageSize.height ());
return scale * 100.0;
}