1
#include <QtTest/QtTest>
3
#include <poppler-qt4.h>
7
class TestFontsData: public QObject
15
void checkFontIterator();
16
void checkSecondDocumentQuery();
17
void checkMultipleIterations();
18
void checkScanForFonts();
22
QList<Poppler::FontInfo> loadFontsViaIterator( Poppler::Document *doc, int from = 0, int count = -1 )
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 )
35
bool operator==( const Poppler::FontInfo &f1, const Poppler::FontInfo &f2 )
37
if ( f1.name() != f2.name() )
39
if ( f1.file() != f2.file() )
41
if ( f1.isEmbedded() != f2.isEmbedded() )
43
if ( f1.isSubset() != f2.isSubset() )
45
if ( f1.type() != f2.type() )
47
if ( f1.typeName() != f2.typeName() )
53
void TestFontsData::checkNoFonts()
55
Poppler::Document *doc;
56
doc = Poppler::Document::load("../../../test/tests/image.pdf");
59
QList<Poppler::FontInfo> listOfFonts = doc->fonts();
60
QCOMPARE( listOfFonts.size(), 0 );
65
void TestFontsData::checkType1()
67
Poppler::Document *doc;
68
doc = Poppler::Document::load("../../../test/tests/text.pdf");
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") );
77
QCOMPARE( listOfFonts.at(0).isEmbedded(), false );
78
QCOMPARE( listOfFonts.at(0).isSubset(), false );
83
void TestFontsData::checkType3()
85
Poppler::Document *doc;
86
doc = Poppler::Document::load("../../../test/tests/type3.pdf");
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") );
95
QCOMPARE( listOfFonts.at(0).isEmbedded(), false );
96
QCOMPARE( listOfFonts.at(0).isSubset(), false );
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") );
102
QCOMPARE( listOfFonts.at(1).isEmbedded(), true );
103
QCOMPARE( listOfFonts.at(1).isSubset(), false );
108
void TestFontsData::checkTrueType()
110
Poppler::Document *doc;
111
doc = Poppler::Document::load("../../../test/unittestcases/truetype.pdf");
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") );
120
QCOMPARE( listOfFonts.at(0).isEmbedded(), false );
121
QCOMPARE( listOfFonts.at(0).isSubset(), false );
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") );
127
QCOMPARE( listOfFonts.at(1).isEmbedded(), false );
128
QCOMPARE( listOfFonts.at(1).isSubset(), false );
133
void TestFontsData::checkFontIterator()
135
// loading a 1-page document
136
Poppler::Document *doc;
137
doc = Poppler::Document::load("../../../test/tests/type3.pdf");
139
// loading a 6-pages document
140
Poppler::Document *doc6 = Poppler::Document::load("../../../test/tests/cropbox.pdf");
143
std::auto_ptr< Poppler::FontIterator > it;
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() );
159
QVERIFY( !it->hasNext() );
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() );
172
QVERIFY( it->hasNext() );
174
QVERIFY( it->hasNext() );
176
QVERIFY( it->hasNext() );
178
QVERIFY( it->hasNext() );
180
QVERIFY( it->hasNext() );
182
QVERIFY( !it->hasNext() );
188
void TestFontsData::checkSecondDocumentQuery()
190
Poppler::Document *doc;
191
doc = Poppler::Document::load("../../../test/tests/type3.pdf");
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 );
203
void TestFontsData::checkMultipleIterations()
205
Poppler::Document *doc;
206
doc = Poppler::Document::load("../../../test/tests/type3.pdf");
209
QList<Poppler::FontInfo> listOfFonts = loadFontsViaIterator( doc );
210
QCOMPARE( listOfFonts.size(), 2 );
211
QList<Poppler::FontInfo> listOfFonts2 = loadFontsViaIterator( doc );
212
QCOMPARE( listOfFonts, listOfFonts2 );
217
void TestFontsData::checkScanForFonts()
219
Poppler::Document *doc;
220
doc = Poppler::Document::load("../../../test/tests/fonts.pdf");
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 )
229
doc->scanForFonts( 1, &listOfFonts2 );
231
QCOMPARE( listOfFonts, listOfFonts2 );
233
// check doing a second scanForFonts gives no result
234
QList<Poppler::FontInfo> listOfFonts3;
235
for ( int i = 0; i < doc->numPages(); ++i )
237
doc->scanForFonts( 1, &listOfFonts3 );
239
QVERIFY( listOfFonts3.isEmpty() );
244
QTEST_MAIN(TestFontsData)
245
#include "check_fonts.moc"