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

« back to all changes in this revision

Viewing changes to tests/poppler/qt4/tests/check_fonts.cpp

  • 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
#include <QtTest/QtTest>
 
2
 
 
3
#include <poppler-qt4.h>
 
4
 
 
5
#include <memory>
 
6
 
 
7
class TestFontsData: public QObject
 
8
{
 
9
    Q_OBJECT
 
10
private slots:
 
11
    void checkNoFonts();
 
12
    void checkType1();
 
13
    void checkType3();
 
14
    void checkTrueType();
 
15
    void checkFontIterator();
 
16
    void checkSecondDocumentQuery();
 
17
    void checkMultipleIterations();
 
18
    void checkScanForFonts();
 
19
};
 
20
 
 
21
 
 
22
QList<Poppler::FontInfo> loadFontsViaIterator( Poppler::Document *doc, int from = 0, int count = -1 )
 
23
{
 
24
    int num = count == -1 ? doc->numPages() - from : count;
 
25
    QList<Poppler::FontInfo> list;
 
26
    std::auto_ptr< Poppler::FontIterator > it( doc->newFontIterator( from ) );
 
27
    while ( it->hasNext() && num )
 
28
    {
 
29
        list += it->next();
 
30
        --num;
 
31
    }
 
32
    return list;
 
33
}
 
34
 
 
35
bool operator==( const Poppler::FontInfo &f1, const Poppler::FontInfo &f2 )
 
36
{
 
37
    if ( f1.name() != f2.name() )
 
38
        return false;
 
39
    if ( f1.file() != f2.file() )
 
40
        return false;
 
41
    if ( f1.isEmbedded() != f2.isEmbedded() )
 
42
        return false;
 
43
    if ( f1.isSubset() != f2.isSubset() )
 
44
        return false;
 
45
    if ( f1.type() != f2.type() )
 
46
        return false;
 
47
    if ( f1.typeName() != f2.typeName() )
 
48
        return false;
 
49
    return true;
 
50
}
 
51
 
 
52
 
 
53
void TestFontsData::checkNoFonts()
 
54
{
 
55
    Poppler::Document *doc;
 
56
    doc = Poppler::Document::load("../../../test/tests/image.pdf");
 
57
    QVERIFY( doc );
 
58
 
 
59
    QList<Poppler::FontInfo> listOfFonts = doc->fonts();
 
60
    QCOMPARE( listOfFonts.size(), 0 );
 
61
 
 
62
    delete doc;
 
63
}
 
64
 
 
65
void TestFontsData::checkType1()
 
66
{
 
67
    Poppler::Document *doc;
 
68
    doc = Poppler::Document::load("../../../test/tests/text.pdf");
 
69
    QVERIFY( doc );
 
70
 
 
71
    QList<Poppler::FontInfo> listOfFonts = doc->fonts();
 
72
    QCOMPARE( listOfFonts.size(), 1 );
 
73
    QCOMPARE( listOfFonts.at(0).name(), QString("Helvetica") );
 
74
    QCOMPARE( listOfFonts.at(0).type(), Poppler::FontInfo::Type1 );
 
75
    QCOMPARE( listOfFonts.at(0).typeName(), QString("Type 1") );
 
76
 
 
77
    QCOMPARE( listOfFonts.at(0).isEmbedded(), false );
 
78
    QCOMPARE( listOfFonts.at(0).isSubset(), false );
 
79
 
 
80
    delete doc;
 
81
}
 
82
 
 
83
void TestFontsData::checkType3()
 
84
{
 
85
    Poppler::Document *doc;
 
86
    doc = Poppler::Document::load("../../../test/tests/type3.pdf");
 
87
    QVERIFY( doc );
 
88
 
 
89
    QList<Poppler::FontInfo> listOfFonts = doc->fonts();
 
90
    QCOMPARE( listOfFonts.size(), 2 );
 
91
    QCOMPARE( listOfFonts.at(0).name(), QString("Helvetica") );
 
92
    QCOMPARE( listOfFonts.at(0).type(), Poppler::FontInfo::Type1 );
 
93
    QCOMPARE( listOfFonts.at(0).typeName(), QString("Type 1") );
 
94
 
 
95
    QCOMPARE( listOfFonts.at(0).isEmbedded(), false );
 
96
    QCOMPARE( listOfFonts.at(0).isSubset(), false );
 
97
 
 
98
    QCOMPARE( listOfFonts.at(1).name(), QString("") );
 
99
    QCOMPARE( listOfFonts.at(1).type(), Poppler::FontInfo::Type3 );
 
100
    QCOMPARE( listOfFonts.at(1).typeName(), QString("Type 3") );
 
101
 
 
102
    QCOMPARE( listOfFonts.at(1).isEmbedded(), true );
 
103
    QCOMPARE( listOfFonts.at(1).isSubset(), false );
 
104
 
 
105
    delete doc;
 
106
}
 
107
 
 
108
void TestFontsData::checkTrueType()
 
109
{
 
110
    Poppler::Document *doc;
 
111
    doc = Poppler::Document::load("../../../test/unittestcases/truetype.pdf");
 
112
    QVERIFY( doc );
 
113
 
 
114
    QList<Poppler::FontInfo> listOfFonts = doc->fonts();
 
115
    QCOMPARE( listOfFonts.size(), 2 );
 
116
    QCOMPARE( listOfFonts.at(0).name(), QString("Arial-BoldMT") );
 
117
    QCOMPARE( listOfFonts.at(0).type(), Poppler::FontInfo::TrueType );
 
118
    QCOMPARE( listOfFonts.at(0).typeName(), QString("TrueType") );
 
119
 
 
120
    QCOMPARE( listOfFonts.at(0).isEmbedded(), false );
 
121
    QCOMPARE( listOfFonts.at(0).isSubset(), false );
 
122
 
 
123
    QCOMPARE( listOfFonts.at(1).name(), QString("ArialMT") );
 
124
    QCOMPARE( listOfFonts.at(1).type(), Poppler::FontInfo::TrueType );
 
125
    QCOMPARE( listOfFonts.at(1).typeName(), QString("TrueType") );
 
126
 
 
127
    QCOMPARE( listOfFonts.at(1).isEmbedded(), false );
 
128
    QCOMPARE( listOfFonts.at(1).isSubset(), false );
 
129
 
 
130
    delete doc;
 
131
}
 
132
 
 
133
void TestFontsData::checkFontIterator()
 
134
{
 
135
    // loading a 1-page document
 
136
    Poppler::Document *doc;
 
137
    doc = Poppler::Document::load("../../../test/tests/type3.pdf");
 
138
    QVERIFY( doc );
 
139
    // loading a 6-pages document
 
140
    Poppler::Document *doc6 = Poppler::Document::load("../../../test/tests/cropbox.pdf");
 
141
    QVERIFY( doc6 );
 
142
 
 
143
    std::auto_ptr< Poppler::FontIterator > it;
 
144
 
 
145
    // some tests with the 1-page document:
 
146
    // - check a default iterator
 
147
    it.reset( doc->newFontIterator() );
 
148
    QVERIFY( it->hasNext() );
 
149
    // - check an iterator for negative pages to behave as 0
 
150
    it.reset( doc->newFontIterator( -1 ) );
 
151
    QVERIFY( it->hasNext() );
 
152
    // - check an iterator for pages out of the page limit
 
153
    it.reset( doc->newFontIterator( 1 ) );
 
154
    QVERIFY( !it->hasNext() );
 
155
    // - check that it reaches the end after 1 iteration
 
156
    it.reset( doc->newFontIterator() );
 
157
    QVERIFY( it->hasNext() );
 
158
    it->next();
 
159
    QVERIFY( !it->hasNext() );
 
160
 
 
161
    // some tests with the 6-page document:
 
162
    // - check a default iterator
 
163
    it.reset( doc6->newFontIterator() );
 
164
    QVERIFY( it->hasNext() );
 
165
    // - check an iterator for pages out of the page limit
 
166
    it.reset( doc6->newFontIterator( 6 ) );
 
167
    QVERIFY( !it->hasNext() );
 
168
    // - check that it reaches the end after 6 iterations
 
169
    it.reset( doc6->newFontIterator() );
 
170
    QVERIFY( it->hasNext() );
 
171
    it->next();
 
172
    QVERIFY( it->hasNext() );
 
173
    it->next();
 
174
    QVERIFY( it->hasNext() );
 
175
    it->next();
 
176
    QVERIFY( it->hasNext() );
 
177
    it->next();
 
178
    QVERIFY( it->hasNext() );
 
179
    it->next();
 
180
    QVERIFY( it->hasNext() );
 
181
    it->next();
 
182
    QVERIFY( !it->hasNext() );
 
183
 
 
184
    delete doc;
 
185
    delete doc6;
 
186
}
 
187
 
 
188
void TestFontsData::checkSecondDocumentQuery()
 
189
{
 
190
    Poppler::Document *doc;
 
191
    doc = Poppler::Document::load("../../../test/tests/type3.pdf");
 
192
    QVERIFY( doc );
 
193
 
 
194
    QList<Poppler::FontInfo> listOfFonts = doc->fonts();
 
195
    QCOMPARE( listOfFonts.size(), 2 );
 
196
    // check we get the very same result when calling fonts() again (#19405)
 
197
    QList<Poppler::FontInfo> listOfFonts2 = doc->fonts();
 
198
    QCOMPARE( listOfFonts, listOfFonts2 );
 
199
 
 
200
    delete doc;
 
201
}
 
202
 
 
203
void TestFontsData::checkMultipleIterations()
 
204
{
 
205
    Poppler::Document *doc;
 
206
    doc = Poppler::Document::load("../../../test/tests/type3.pdf");
 
207
    QVERIFY( doc );
 
208
 
 
209
    QList<Poppler::FontInfo> listOfFonts = loadFontsViaIterator( doc );
 
210
    QCOMPARE( listOfFonts.size(), 2 );
 
211
    QList<Poppler::FontInfo> listOfFonts2 = loadFontsViaIterator( doc );
 
212
    QCOMPARE( listOfFonts, listOfFonts2 );
 
213
 
 
214
    delete doc;
 
215
}
 
216
 
 
217
void TestFontsData::checkScanForFonts()
 
218
{
 
219
    Poppler::Document *doc;
 
220
    doc = Poppler::Document::load("../../../test/tests/fonts.pdf");
 
221
    QVERIFY( doc );
 
222
 
 
223
    QList<Poppler::FontInfo> listOfFonts = doc->fonts();
 
224
    QCOMPARE( listOfFonts.size(), 3 );
 
225
    // check we get the very same result when gatering fonts using scanForFonts
 
226
    QList<Poppler::FontInfo> listOfFonts2;
 
227
    for ( int i = 0; i < doc->numPages(); ++i )
 
228
    {
 
229
        doc->scanForFonts( 1, &listOfFonts2 );
 
230
    }
 
231
    QCOMPARE( listOfFonts, listOfFonts2 );
 
232
 
 
233
   // check doing a second scanForFonts gives no result
 
234
    QList<Poppler::FontInfo> listOfFonts3;
 
235
    for ( int i = 0; i < doc->numPages(); ++i )
 
236
    {
 
237
        doc->scanForFonts( 1, &listOfFonts3 );
 
238
    }
 
239
    QVERIFY( listOfFonts3.isEmpty() );
 
240
 
 
241
    delete doc;
 
242
}
 
243
 
 
244
QTEST_MAIN(TestFontsData)
 
245
#include "check_fonts.moc"
 
246