[poppler] poppler/qt4/tests: Makefile.am, NONE, 1.1 check_orientation.cpp, NONE, 1.1 stress-poppler-qt4.cpp, NONE, 1.1 test-poppler-qt4.cpp, NONE, 1.1

Brad Hards bradh at freedesktop.org
Tue Jun 28 03:00:12 PDT 2005


Update of /cvs/poppler/poppler/qt4/tests
In directory gabe:/tmp/cvs-serv23886/qt4/tests

Added Files:
	Makefile.am check_orientation.cpp stress-poppler-qt4.cpp 
	test-poppler-qt4.cpp 
Log Message:
Initial import of Qt4 bindings, and for a Qt4 "Arthur" (QPainter)
backend renderer.

The bindings are currently unstable - you can expect substantial change
in both source and binary interfaces. 

The Arthur renderer currently does a reasonable job of rendering path
and fill, but the image rendering doesn't work (for reasons that aren't
clear to me) and text rendering doesn't use the right glyphs - it just
draws with the current font. There is a lot of work to do on this
too. Help is, of coure, welcome.



--- NEW FILE: Makefile.am ---
INCLUDES =					\
	-I$(top_srcdir)				\
	-I$(top_srcdir)/poppler			\
	-I$(top_srcdir)/qt4/src			\
	$(POPPLER_QT4_CXXFLAGS)

LDADDS =					\
	$(top_builddir)/poppler/libpoppler.la	\
	$(top_builddir)/qt4/src/libpoppler-qt4.la	\
	$(POPPLER_QT4_LIBS)

noinst_PROGRAMS = test-poppler-qt4 stress-poppler-qt4


test_poppler_qt4_SOURCES =			\
       test-poppler-qt4.cpp

test_poppler_qt4_LDADD = $(LDADDS)



stress_poppler_qt4_SOURCES =			\
       stress-poppler-qt4.cpp

stress_poppler_qt4_LDADD = $(LDADDS)

TESTS = \
	check_orientation


check_PROGRAMS = $(TESTS)

check_orientation_SOURCES = check_orientation.cpp
check_orientation_LDADD = $(LDADDS)

--- NEW FILE: check_orientation.cpp ---
#include <stdlib.h>
#include <QtCore/QtCore>
#include <QtGui/QtGui>
#include <ctype.h>

#define UNSTABLE_POPPLER_QT4
#include <poppler-qt4.h>

int main( int argc, char **argv )
{
    QApplication a( argc, argv );               // QApplication required!

    Poppler::Document *doc = Poppler::Document::load("orientation.pdf");
    if (!doc)
    {
	exit(1);
    }
  
    Poppler::Page *page = doc->page(0);
    if ( !( page->orientation() == Poppler::Page::Landscape ) ) {
	exit(2);
    }

    page = doc->page(1);
    if ( !( page->orientation() == Poppler::Page::Portrait ) ) {
	exit(3);
    }

    page = doc->page(2);
    if ( !( page->orientation() == Poppler::Page::Seascape ) ) {
	exit(4);
    }

    page = doc->page(3);
    if ( !( page->orientation() == Poppler::Page::UpsideDown ) ) {
	exit(5);
    }

    exit(0);
}

--- NEW FILE: stress-poppler-qt4.cpp ---
#include <iostream>
#include <QtCore/QtCore>
#include <QtGui/QtGui>
#include <ctype.h>

#define UNSTABLE_POPPLER_QT4
#include <poppler-qt4.h>

int main( int argc, char **argv )
{
    QApplication a( argc, argv );               // QApplication required!

    Q_UNUSED( argc );
    Q_UNUSED( argv );

    QTime t;
    t.start();
    QDir dbDir( QString( "./pdfdb" ) );
    if ( !dbDir.exists() ) {
	qWarning() << "Database directory does not exist";
    }

    QStringList excludeSubDirs;
    excludeSubDirs << "000048" << "000607";

    foreach ( QString subdir, dbDir.entryList(QStringList() << "0000*", QDir::Dirs) ) {
	if ( excludeSubDirs.contains(subdir) ) {
	    // then skip it
	} else {
	    QString path = "./pdfdb/" + subdir + "/data.pdf";
	    std::cout <<"Doing " << path.toLatin1().data() << " :";
	    Poppler::Document *doc = Poppler::Document::load( path );
	    if (!doc) {
		qWarning() << "doc not loaded";
	    } else {
		doc->pdfVersion();
		doc->info("Title");
		doc->info("Subject");
		doc->info("Author");
		doc->info("Keywords");
		doc->info("Creator");
		doc->info("Producer");
		doc->date("CreationDate").toString();
		doc->date("ModDate").toString();
		doc->numPages();
		doc->isLinearized();
		doc->isEncrypted();
		doc->okToPrint();
		doc->okToCopy();
		doc->okToChange();
		doc->okToAddNotes();
		doc->pageMode();

		QPixmap *pixmap = new QPixmap;
		for( int index = 0; index < doc->numPages(); ++index ) {
		    Poppler::Page *page = doc->page( index );
		    page->renderToPixmap(&pixmap, page->pageSize());
		    page->pageSize();
		    page->orientation();
		    std::cout << ".";
		    std::cout.flush();
		}
		std::cout << std::endl;
	    }
	}
    }

    std::cout << "Elapsed time: " << (t.elapsed()/1000) << std::endl;

}

--- NEW FILE: test-poppler-qt4.cpp ---
#include <stdlib.h>
#include <QtCore/QtCore>
#include <QtGui/QtGui>
#include <ctype.h>

#define UNSTABLE_POPPLER_QT4
#include <poppler-qt4.h>

class PDFDisplay : public QWidget           // picture display widget
{
public:
    PDFDisplay( Poppler::Document *d );
    ~PDFDisplay();
protected:
    void        paintEvent( QPaintEvent * );
private:
    QPixmap	*pixmap;
    Poppler::Document *doc;
};

PDFDisplay::PDFDisplay( Poppler::Document *d )
{
    doc = d;
    if (doc) {
	Poppler::Page *page = doc->page("1");
	if (page) {
	    page->renderToPixmap(&pixmap, page->pageSize());
	    delete page;
	}
    } else {
	qWarning() << "doc not loaded";
    }
}

PDFDisplay::~PDFDisplay()
{
    delete doc;
    delete pixmap;
}

void PDFDisplay::paintEvent( QPaintEvent *e )
{
    QPainter paint( this );                     // paint widget
    if (pixmap) {
	paint.drawPixmap(0, 0, *pixmap);
    } else {
	qWarning() << "no pixmap";
    }
}

int main( int argc, char **argv )
{
    QApplication a( argc, argv );               // QApplication required!

    if ( argc < 2  || (argc == 3 && strcmp(argv[2], "-extract") != 0) || argc > 3)
    {
	// use argument as file name
	qWarning() << "usage: test-poppler-qt filename [-extract]";
	exit(1);
    }
  
    Poppler::Document *doc = Poppler::Document::load(argv[1]);
    if (!doc)
    {
	qWarning() << "doc not loaded";
	exit(1);
    }
  
    // output some meta-data
    qDebug() << "    PDF Version: " << doc->pdfVersion();
    qDebug() << "          Title: " << doc->info("Title");
    qDebug() << "        Subject: " << doc->info("Subject");
    qDebug() << "         Author: " << doc->info("Author");
    qDebug() << "      Key words: " << doc->info("Keywords");
    qDebug() << "        Creator: " << doc->info("Creator");
    qDebug() << "       Producer: " << doc->info("Producer");
    qDebug() << "   Date created: " << doc->date("CreationDate").toString();
    qDebug() << "  Date modified: " << doc->date("ModDate").toString();
    qDebug() << "Number of pages: " << doc->numPages();
    qDebug() << "     Linearised: " << doc->isLinearized();
    qDebug() << "      Encrypted: " << doc->isEncrypted();
    qDebug() << "    OK to print: " << doc->okToPrint();
    qDebug() << "     OK to copy: " << doc->okToCopy();
    qDebug() << "   OK to change: " << doc->okToChange();
    qDebug() << "OK to add notes: " << doc->okToAddNotes();
    qDebug() << "      Page mode: " << doc->pageMode();
    QStringList fontNameList;
    foreach( Poppler::FontInfo font, doc->fonts() )
	fontNameList += font.name();
    qDebug() << "          Fonts: " << fontNameList.join( ", " );

    Poppler::Page *page = doc->page(0);
    qDebug() << "    Page 1 size: " << page->pageSize().width()/72 << "inches x " << page->pageSize().height()/72 << "inches";
    if ( page->orientation() == Poppler::Page::Landscape ) {
	qDebug() << "Landscape layout";
    } else if ( page->orientation() == Poppler::Page::Portrait ) {
	qDebug() << "Portrait layout";
    } else {
	qDebug() << "Unknown layout";
    }


    if (argc == 2)
    {  
	PDFDisplay test( doc );        // create picture display
	test.setWindowTitle("Poppler-Qt4 Test");
	test.show();                            // show it

	return a.exec();                        // start event loop
    }
    else
    {
	Poppler::Page *page = doc->page(0);

	QLabel *l = new QLabel(page->text(QRectF()), 0);
	l->show();
	delete page;
	delete doc;
	return a.exec();
    }
}



More information about the poppler mailing list