1
/* poppler-annotation-helper.h: qt interface to poppler
2
* Copyright (C) 2006, 2008, Albert Astals Cid <aacid@kde.org>
3
* Copyright (C) 2008, Pino Toscano <pino@kde.org>
5
* Copyright (C) 2004 by Enrico Ros <eros.kde@email.it>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2, or (at your option)
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
22
#include <QtCore/QDebug>
33
// find named symbol and parse it
34
static inline void lookupName( Dict *, char *, QString & dest );
35
static inline void lookupString( Dict *, char *, QString & dest );
36
static inline void lookupBool( Dict *, char *, bool & dest );
37
static inline void lookupInt( Dict *, char *, int & dest );
38
static inline void lookupNum( Dict *, char *, double & dest );
39
static inline int lookupNumArray( Dict *, char *, double * dest, int len );
40
static inline void lookupColor( Dict *, char *, QColor & color );
41
static inline void lookupIntRef( Dict *, char *, int & dest );
42
static inline void lookupDate( Dict *, char *, QDateTime & dest );
43
// transform from user coords to normalized ones using the matrix M
44
static inline void transform( double * M, double x, double y, QPointF &res );
47
void XPDFReader::lookupName( Dict * dict, char * type, QString & dest )
50
dict->lookup( type, &nameObj );
51
if ( nameObj.isNull() )
53
if ( nameObj.isName() )
54
dest = nameObj.getName();
56
qDebug() << type << " is not Name." << endl;
60
void XPDFReader::lookupString( Dict * dict, char * type, QString & dest )
63
dict->lookup( type, &stringObj );
64
if ( stringObj.isNull() )
66
if ( stringObj.isString() )
67
dest = stringObj.getString()->getCString();
69
qDebug() << type << " is not String." << endl;
73
void XPDFReader::lookupBool( Dict * dict, char * type, bool & dest )
76
dict->lookup( type, &boolObj );
77
if ( boolObj.isNull() )
79
if ( boolObj.isBool() )
80
dest = boolObj.getBool() == gTrue;
82
qDebug() << type << " is not Bool." << endl;
86
void XPDFReader::lookupInt( Dict * dict, char * type, int & dest )
89
dict->lookup( type, &intObj );
90
if ( intObj.isNull() )
93
dest = intObj.getInt();
95
qDebug() << type << " is not Int." << endl;
99
void XPDFReader::lookupNum( Dict * dict, char * type, double & dest )
102
dict->lookup( type, &numObj );
103
if ( numObj.isNull() )
105
if ( numObj.isNum() )
106
dest = numObj.getNum();
108
qDebug() << type << " is not Num." << endl;
112
int XPDFReader::lookupNumArray( Dict * dict, char * type, double * dest, int len )
115
dict->lookup( type, &arrObj );
116
if ( arrObj.isNull() )
119
if ( arrObj.isArray() )
121
len = qMin( len, arrObj.arrayGetLength() );
122
for ( int i = 0; i < len; i++ )
124
dest[i] = arrObj.arrayGet( i, &numObj )->getNum();
131
qDebug() << type << "is not Array." << endl;
137
void XPDFReader::lookupColor( Dict * dict, char * type, QColor & dest )
140
if ( XPDFReader::lookupNumArray( dict, type, c, 3 ) == 3 )
141
dest = QColor( (int)(c[0]*255.0), (int)(c[1]*255.0), (int)(c[2]*255.0));
144
void XPDFReader::lookupIntRef( Dict * dict, char * type, int & dest )
147
dict->lookupNF( type, &refObj );
148
if ( refObj.isNull() )
150
if ( refObj.isRef() )
151
dest = refObj.getRefNum();
153
qDebug() << type << " is not Ref." << endl;
157
void XPDFReader::lookupDate( Dict * dict, char * type, QDateTime & dest )
160
dict->lookup( type, &dateObj );
161
if ( dateObj.isNull() )
163
if ( dateObj.isString() )
165
dest = convertDate( dateObj.getString()->getCString() );
168
qDebug() << type << " is not Date" << endl;
172
void XPDFReader::transform( double * M, double x, double y, QPointF &res )
174
res.setX( M[0] * x + M[2] * y + M[4] );
175
res.setY( M[1] * x + M[3] * y + M[5] );
178
/** @short Helper classes for CROSSDEPS resolving and DS conversion. */
179
struct ResolveRevision
181
int prevAnnotationID; // ID of the annotation to be reparended
182
int nextAnnotationID; // (only needed for speeding up resolving)
183
Annotation * nextAnnotation; // annotation that will act as parent
184
Annotation::RevScope nextScope; // scope of revision (Reply)
185
Annotation::RevType nextType; // type of revision (None)
190
AnnotPopup * popup; // the (maybe shared) window
191
Annotation * annotation; // annotation having the popup window
194
struct PostProcessText // this handles a special pdf case conversion
196
Annotation * textAnnotation; // a popup text annotation (not FreeText)
197
bool opened; // pdf property to convert to window flags
202
Annotation * dummyAnnotation; // window properties (in pdf as Annotation)
203
bool shown; // converted to Annotation::Hidden flag
206
QColor convertAnnotColor( AnnotColor *color );