From 6a7b1eaaedbfdd3a8e6b4d899477350f2b485641 Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Sun, 4 Dec 2005 10:05:21 +0000 Subject: [PATCH] * qt4/src/poppler-qt4.h: qt4/src/fontinfo.cc: add implementation for FontInfo::typeName() * qt4/tests/check_fonts.cpp: * qt4/tests/Makefile.am: add unit test for fonts * qt4/src/Mainpage.dox: Minor typo fixes. --- ChangeLog | 11 ++++++++++ qt4/src/Mainpage.dox | 5 +++-- qt4/src/poppler-fontinfo.cc | 24 +++++++++++++++++++++ qt4/src/poppler-qt4.h | 14 ++++++++++++- qt4/tests/Makefile.am | 5 +++++ qt4/tests/check_fonts.cpp | 42 +++++++++++++++++++++++++++++++++++++ 6 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 qt4/tests/check_fonts.cpp diff --git a/ChangeLog b/ChangeLog index 3893daea..575401fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-12-04 Brad Hards + + * qt4/src/poppler-qt4.h: + qt4/src/fontinfo.cc: add implementation for + FontInfo::typeName() + + * qt4/tests/check_fonts.cpp: + * qt4/tests/Makefile.am: add unit test for fonts + + * qt4/src/Mainpage.dox: Minor typo fixes. + 2005-12-03 Kristian Høgsberg * glib/poppler-page.cc (poppler_page_set_selection_alpha): Use diff --git a/qt4/src/Mainpage.dox b/qt4/src/Mainpage.dox index 1e7aeb4a..128e29f8 100644 --- a/qt4/src/Mainpage.dox +++ b/qt4/src/Mainpage.dox @@ -1,7 +1,7 @@ /** @mainpage The Poppler Qt4 interface library -The Poppler Qt4 interface library, libpoppler-qt4, is library that +The Poppler Qt4 interface library, libpoppler-qt4, is a library that allows Qt4 programmers to easily load and render PDF files. The Poppler Qt4 interface library uses poppler internally to do its job, but the Qt4 programmer will never have to worry about poppler @@ -38,7 +38,8 @@ simply need to add the following two lines to their C++ source files: @endcode The #define statement is required at the moment. You indicate that you -think you know what you are doing. +think you know what you are doing, and understand that the API is +subject to change. A PDF document can then be loaded as follows. @code diff --git a/qt4/src/poppler-fontinfo.cc b/qt4/src/poppler-fontinfo.cc index 3e8cf8ff..18943502 100644 --- a/qt4/src/poppler-fontinfo.cc +++ b/qt4/src/poppler-fontinfo.cc @@ -66,4 +66,28 @@ FontInfo::Type FontInfo::type() const return m_data->type; } +const QString FontInfo::typeName() const +{ + switch (type()) { + case unknown: + return QObject::tr("unknown"); + case Type1: + return QObject::tr("Type 1"); + case Type1C: + return QObject::tr("Type 1C"); + case Type3: + return QObject::tr("Type 3"); + case TrueType: + return QObject::tr("TrueType"); + case CIDType0: + return QObject::tr("CID Type 0"); + case CIDType0C: + return QObject::tr("CID Type 0C"); + case CIDTrueType: + return QObject::tr("CID TrueType"); + default: + return QObject::tr("Bug: unexpected font type. Notify poppler mailing list!"); + } +} + } diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h index e7286bcb..c2e6a393 100644 --- a/qt4/src/poppler-qt4.h +++ b/qt4/src/poppler-qt4.h @@ -96,10 +96,22 @@ namespace Poppler { /** The type of font encoding + + \return a enumerated value corresponding to the font encoding used + + \sa typeName for a string equivalent */ Type type() const; - const QString &typeName() const; + /** + The name of the font encoding used + + \note if you are looking for the name of the font (as opposed to the + encoding format used), you probably want name(). + + \sa type for a enumeration version + */ + const QString typeName() const; private: FontInfoData *m_data; diff --git a/qt4/tests/Makefile.am b/qt4/tests/Makefile.am index c978a56b..8a66b405 100644 --- a/qt4/tests/Makefile.am +++ b/qt4/tests/Makefile.am @@ -46,6 +46,7 @@ stress_poppler_qt4_LDADD = $(LDADDS) if BUILD_POPPLER_QT4TESTS TESTS = \ + check_fonts \ check_metadata \ check_permissions \ check_pagemode \ @@ -53,6 +54,10 @@ TESTS = \ check_PROGRAMS = $(TESTS) +check_fonts_SOURCES = check_fonts.cpp +check_fonts.$(OBJEXT): check_fonts.moc +check_fonts_LDADD = $(UT_LDADDS) + check_metadata_SOURCES = check_metadata.cpp check_metadata.$(OBJEXT): check_metadata.moc check_metadata_LDADD = $(UT_LDADDS) diff --git a/qt4/tests/check_fonts.cpp b/qt4/tests/check_fonts.cpp new file mode 100644 index 00000000..e67987a5 --- /dev/null +++ b/qt4/tests/check_fonts.cpp @@ -0,0 +1,42 @@ +#include + +#define UNSTABLE_POPPLER_QT4 +#include + +class TestFontsData: public QObject +{ + Q_OBJECT +private slots: + void checkNoFonts(); + void checkType1(); +}; + +void TestFontsData::checkNoFonts() +{ + Poppler::Document *doc; + doc = Poppler::Document::load("../../../test/tests/image.pdf"); + QVERIFY( doc ); + + QList listOfFonts = doc->fonts(); + QCOMPARE( listOfFonts.size(), 0 ); +} + +void TestFontsData::checkType1() +{ + Poppler::Document *doc; + doc = Poppler::Document::load("../../../test/tests/text.pdf"); + QVERIFY( doc ); + + QList listOfFonts = doc->fonts(); + QCOMPARE( listOfFonts.size(), 1 ); + QCOMPARE( listOfFonts.at(0).name(), QString("Helvetica") ); + QCOMPARE( listOfFonts.at(0).type(), Poppler::FontInfo::Type1 ); + QCOMPARE( listOfFonts.at(0).typeName(), QString("Type 1") ); + + QCOMPARE( listOfFonts.at(0).isEmbedded(), false ); + QCOMPARE( listOfFonts.at(0).isSubset(), false ); +} + +QTEST_MAIN(TestFontsData) +#include "check_fonts.moc" + -- 2.22.0