~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/poppler/qt4/src/poppler-annotation-helper.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
4
 * Adapting code from
 
5
 *   Copyright (C) 2004 by Enrico Ros <eros.kde@email.it>
 
6
 *
 
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)
 
10
 * any later version.
 
11
 *
 
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.
 
16
 *
 
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.
 
20
 */
 
21
 
 
22
#include <QtCore/QDebug>
 
23
 
 
24
class QColor;
 
25
 
 
26
class AnnotColor;
 
27
 
 
28
namespace Poppler {
 
29
 
 
30
class XPDFReader
 
31
{
 
32
    public:
 
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 );
 
45
};
 
46
 
 
47
void XPDFReader::lookupName( Dict * dict, char * type, QString & dest )
 
48
{
 
49
    Object nameObj;
 
50
    dict->lookup( type, &nameObj );
 
51
    if ( nameObj.isNull() )
 
52
        return;
 
53
    if ( nameObj.isName() )
 
54
        dest = nameObj.getName();
 
55
    else
 
56
        qDebug() << type << " is not Name." << endl;
 
57
    nameObj.free();
 
58
}
 
59
 
 
60
void XPDFReader::lookupString( Dict * dict, char * type, QString & dest )
 
61
{
 
62
    Object stringObj;
 
63
    dict->lookup( type, &stringObj );
 
64
    if ( stringObj.isNull() )
 
65
        return;
 
66
    if ( stringObj.isString() )
 
67
        dest = stringObj.getString()->getCString();
 
68
    else
 
69
        qDebug() << type << " is not String." << endl;
 
70
    stringObj.free();
 
71
}
 
72
 
 
73
void XPDFReader::lookupBool( Dict * dict, char * type, bool & dest )
 
74
{
 
75
    Object boolObj;
 
76
    dict->lookup( type, &boolObj );
 
77
    if ( boolObj.isNull() )
 
78
        return;
 
79
    if ( boolObj.isBool() )
 
80
        dest = boolObj.getBool() == gTrue;
 
81
    else
 
82
        qDebug() << type << " is not Bool." << endl;
 
83
    boolObj.free();
 
84
}
 
85
 
 
86
void XPDFReader::lookupInt( Dict * dict, char * type, int & dest )
 
87
{
 
88
    Object intObj;
 
89
    dict->lookup( type, &intObj );
 
90
    if ( intObj.isNull() )
 
91
        return;
 
92
    if ( intObj.isInt() )
 
93
        dest = intObj.getInt();
 
94
    else
 
95
        qDebug() << type << " is not Int." << endl;
 
96
    intObj.free();
 
97
}
 
98
 
 
99
void XPDFReader::lookupNum( Dict * dict, char * type, double & dest )
 
100
{
 
101
    Object numObj;
 
102
    dict->lookup( type, &numObj );
 
103
    if ( numObj.isNull() )
 
104
        return;
 
105
    if ( numObj.isNum() )
 
106
        dest = numObj.getNum();
 
107
    else
 
108
        qDebug() << type << " is not Num." << endl;
 
109
    numObj.free();
 
110
}
 
111
 
 
112
int XPDFReader::lookupNumArray( Dict * dict, char * type, double * dest, int len )
 
113
{
 
114
    Object arrObj;
 
115
    dict->lookup( type, &arrObj );
 
116
    if ( arrObj.isNull() )
 
117
        return 0;
 
118
    Object numObj;
 
119
    if ( arrObj.isArray() )
 
120
    {
 
121
        len = qMin( len, arrObj.arrayGetLength() );
 
122
        for ( int i = 0; i < len; i++ )
 
123
        {
 
124
            dest[i] = arrObj.arrayGet( i, &numObj )->getNum();
 
125
            numObj.free();
 
126
        }
 
127
    }
 
128
    else
 
129
    {
 
130
        len = 0;
 
131
        qDebug() << type << "is not Array." << endl;
 
132
    }
 
133
    arrObj.free();
 
134
    return len;
 
135
}
 
136
 
 
137
void XPDFReader::lookupColor( Dict * dict, char * type, QColor & dest )
 
138
{
 
139
    double c[3];
 
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));
 
142
}
 
143
 
 
144
void XPDFReader::lookupIntRef( Dict * dict, char * type, int & dest )
 
145
{
 
146
    Object refObj;
 
147
    dict->lookupNF( type, &refObj );
 
148
    if ( refObj.isNull() )
 
149
        return;
 
150
    if ( refObj.isRef() )
 
151
        dest = refObj.getRefNum();
 
152
    else
 
153
        qDebug() << type << " is not Ref." << endl;
 
154
    refObj.free();
 
155
}
 
156
 
 
157
void XPDFReader::lookupDate( Dict * dict, char * type, QDateTime & dest )
 
158
{
 
159
    Object dateObj;
 
160
    dict->lookup( type, &dateObj );
 
161
    if ( dateObj.isNull() )
 
162
        return;
 
163
    if ( dateObj.isString() )
 
164
    {
 
165
        dest = convertDate( dateObj.getString()->getCString() );
 
166
    }
 
167
    else
 
168
        qDebug() << type << " is not Date" << endl;
 
169
    dateObj.free();
 
170
}
 
171
 
 
172
void XPDFReader::transform( double * M, double x, double y, QPointF &res )
 
173
{
 
174
    res.setX( M[0] * x + M[2] * y + M[4] );
 
175
    res.setY( M[1] * x + M[3] * y + M[5] );
 
176
}
 
177
 
 
178
/** @short Helper classes for CROSSDEPS resolving and DS conversion. */
 
179
struct ResolveRevision
 
180
{
 
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)
 
186
};
 
187
 
 
188
struct ResolveWindow
 
189
{
 
190
    AnnotPopup *  popup;            // the (maybe shared) window
 
191
    Annotation *  annotation;       // annotation having the popup window
 
192
};
 
193
 
 
194
struct PostProcessText              // this handles a special pdf case conversion
 
195
{
 
196
    Annotation *  textAnnotation;   // a popup text annotation (not FreeText)
 
197
    bool          opened;           // pdf property to convert to window flags
 
198
};
 
199
 
 
200
struct PopupWindow
 
201
{
 
202
    Annotation *  dummyAnnotation;  // window properties (in pdf as Annotation)
 
203
    bool          shown;            // converted to Annotation::Hidden flag
 
204
};
 
205
 
 
206
QColor convertAnnotColor( AnnotColor *color );
 
207
 
 
208
}