[poppler] 3 commits - glib/test-poppler-glib.c qt4/src qt4/tests

Albert Astals Cid aacid at kemper.freedesktop.org
Wed Oct 31 15:53:53 PDT 2007


 glib/test-poppler-glib.c         |  514 ---------------------------------------
 qt4/src/poppler-qt4.h            |   64 ++++
 qt4/tests/Makefile.am            |   13 
 qt4/tests/check_password.cpp     |   87 ++++++
 qt4/tests/stress-poppler-dir.cpp |   63 ++++
 qt4/tests/test-poppler-qt4.cpp   |   15 -
 6 files changed, 231 insertions(+), 525 deletions(-)

New commits:
commit a968dcc759379f48265c91bea63ca4cf987d94a9
Author: Albert Astals Cid <tsdgeos at bluebox.localdomain>
Date:   Wed Oct 31 23:53:39 2007 +0100

    Tests for passwords

diff --git a/qt4/tests/Makefile.am b/qt4/tests/Makefile.am
index 96c5e74..3e13f4e 100644
--- a/qt4/tests/Makefile.am
+++ b/qt4/tests/Makefile.am
@@ -18,7 +18,8 @@ SUFFIXES: .moc
 	moc -i $< -o $@
 
 noinst_PROGRAMS = test-poppler-qt4 stress-poppler-qt4 \
-	poppler-fonts test-password-qt4 poppler-attachments
+	poppler-fonts test-password-qt4 stress-poppler-dir \
+	poppler-attachments
 
 
 test_poppler_qt4_SOURCES =			\
@@ -49,6 +50,11 @@ stress_poppler_qt4_SOURCES =			\
 
 stress_poppler_qt4_LDADD = $(LDADDS)
 
+stress_poppler_dir_SOURCES =			\
+       stress-poppler-dir.cpp
+
+stress_poppler_dir_LDADD = $(LDADDS)
+
 if BUILD_POPPLER_QT4
 TESTS = \
 	check_attachments	\
@@ -57,6 +63,7 @@ TESTS = \
 	check_metadata         	\
 	check_permissions      	\
 	check_pagemode    	\
+	check_password    	\
 	check_pagelayout
 
 check_PROGRAMS = $(TESTS)
@@ -89,5 +96,9 @@ check_pagelayout_SOURCES = check_pagelayout.cpp
 check_pagelayout.$(OBJEXT): check_pagelayout.moc
 check_pagelayout_LDADD = $(LDADDS)
 
+check_password_SOURCES = check_password.cpp
+check_password.$(OBJEXT): check_password.moc
+check_password_LDADD = $(LDADDS)
+
 endif
 
diff --git a/qt4/tests/check_password.cpp b/qt4/tests/check_password.cpp
new file mode 100644
index 0000000..a6d6819
--- /dev/null
+++ b/qt4/tests/check_password.cpp
@@ -0,0 +1,87 @@
+#include <QtTest/QtTest>
+
+#include <poppler-qt4.h>
+
+class TestPassword: public QObject
+{
+    Q_OBJECT
+private slots:
+    void password1();
+    void password1a();
+    void password2();
+    void password2a();
+    void password2b();
+    void password3();
+};
+
+
+// BUG:4557
+void TestPassword::password1()
+{
+    Poppler::Document *doc;
+    doc = Poppler::Document::load(QFile::decodeName("../../../test/unittestcases/Gday garçon - open.pdf"), "", QString::fromUtf8("garçon").toLatin1() );
+    QVERIFY( doc );
+    QCOMPARE( doc->isLocked(), false );
+
+    delete doc;
+}
+
+
+void TestPassword::password1a()
+{
+    Poppler::Document *doc;
+    doc = Poppler::Document::load(QFile::decodeName("../../../test/unittestcases/Gday garçon - open.pdf") );
+    QVERIFY( doc );
+    QVERIFY( doc->isLocked() );
+    doc->unlock( "", QString::fromUtf8("garçon").toLatin1() );
+    QCOMPARE( doc->isLocked(), false );
+
+    delete doc;
+}
+
+void TestPassword::password2()
+{
+    Poppler::Document *doc;
+    doc = Poppler::Document::load(QFile::decodeName("../../../test/unittestcases/Gday garçon - owner.pdf"), QString::fromUtf8("garçon").toLatin1(), "" );
+    QVERIFY( doc );
+    QCOMPARE( doc->isLocked(), false );
+
+    delete doc;
+}
+
+void TestPassword::password2a()
+{
+    Poppler::Document *doc;
+    doc = Poppler::Document::load(QFile::decodeName("../../../test/unittestcases/Gday garçon - owner.pdf"), QString::fromUtf8("garçon").toLatin1() );
+    QVERIFY( doc );
+    QCOMPARE( doc->isLocked(), false );
+
+    delete doc;
+}
+
+void TestPassword::password2b()
+{
+    Poppler::Document *doc;
+    doc = Poppler::Document::load(QFile::decodeName("../../../test/unittestcases/Gday garçon - owner.pdf") );
+    QVERIFY( doc );
+    doc->unlock( QString::fromUtf8("garçon").toLatin1(), "" );
+    QCOMPARE( doc->isLocked(), false );
+
+    delete doc;
+}
+
+void TestPassword::password3()
+{
+    Poppler::Document *doc;
+    doc = Poppler::Document::load( QFile::decodeName("../../../test/unittestcases/PasswordEncrypted.pdf") );
+    QVERIFY( doc );
+    QVERIFY( doc->isLocked() );
+    doc->unlock( "", "password" );
+    QCOMPARE( doc->isLocked(), false );
+
+    delete doc;
+}
+
+QTEST_MAIN(TestPassword)
+#include "check_password.moc"
+
diff --git a/qt4/tests/stress-poppler-dir.cpp b/qt4/tests/stress-poppler-dir.cpp
new file mode 100644
index 0000000..3cdd6bc
--- /dev/null
+++ b/qt4/tests/stress-poppler-dir.cpp
@@ -0,0 +1,63 @@
+#include <iostream>
+#include <QtCore/QtCore>
+#include <QtGui/QtGui>
+#include <ctype.h>
+
+#include <poppler-qt4.h>
+
+int main( int argc, char **argv )
+{
+    QApplication a( argc, argv );               // QApplication required!
+
+    QTime t;
+    t.start();
+
+    QDir directory( argv[1] );
+    foreach ( const QString fileName, directory.entryList() ) {
+        if (fileName.endsWith("pdf") ) {
+	    qDebug() << "Doing" << fileName.toLatin1().data() << ":";
+	    Poppler::Document *doc = Poppler::Document::load( directory.canonicalPath()+"/"+fileName );
+	    if (!doc) {
+		qWarning() << "doc not loaded";
+	    } else if ( doc->isLocked() ) {
+	        if (! doc->unlock( "", "password" ) ) {
+		    qWarning() << "couldn't unlock document";
+		    delete doc;
+		}
+	    } 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();
+
+		for( int index = 0; index < doc->numPages(); ++index ) {
+		    Poppler::Page *page = doc->page( index );
+		    QImage image = page->renderToImage();
+		    page->pageSize();
+		    page->orientation();
+		    delete page;
+		    std::cout << ".";
+		    std::cout.flush();
+		}
+		std::cout << std::endl;
+		delete doc;
+	    }
+	}
+    }
+
+    std::cout << "Elapsed time: " << (t.elapsed()/1000) << "seconds" << std::endl;
+
+}
diff --git a/qt4/tests/test-poppler-qt4.cpp b/qt4/tests/test-poppler-qt4.cpp
index 6d319b4..4785312 100644
--- a/qt4/tests/test-poppler-qt4.cpp
+++ b/qt4/tests/test-poppler-qt4.cpp
@@ -105,7 +105,7 @@ int main( int argc, char **argv )
 	exit(1);
     }
   
-    Poppler::Document *doc = Poppler::Document::load(argv[1]);
+    Poppler::Document *doc = Poppler::Document::load(QFile::decodeName(argv[1]));
     if (!doc)
     {
 	qWarning() << "doc not loaded";
@@ -136,8 +136,19 @@ int main( int argc, char **argv )
 	fontNameList += font.name();
     qDebug() << "          Fonts: " << fontNameList.join( ", " );
 
+    if ( doc->hasEmbeddedFiles() ) {
+        qDebug() << "Embedded files:";
+        foreach( Poppler::EmbeddedFile *file, doc->embeddedFiles() ) {
+	    qDebug() << "   " << file->name();
+	}
+	qDebug();
+    } else {
+        qDebug() << "No embedded files";
+    }
+
+
     Poppler::Page *page = doc->page(0);
-    qDebug() << "    Page 1 size: " << page->pageSize().width()/72 << "inches x " << page->pageSize().height()/72 << "inches";
+    qDebug() << "Page 1 size: " << page->pageSize().width()/72 << "inches x " << page->pageSize().height()/72 << "inches";
     delete page;
 
     if (argc == 2 || (argc == 3 && strcmp(argv[2], "-arthur") == 0))
commit 7b7a08863a8278dee7aa1fe7789cf72223c26b35
Author: Brad Hards <bradh at frogmouth.net>
Date:   Wed Oct 31 23:53:27 2007 +0100

    Improve documentation

diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h
index 3b61c2c..ca74f5b 100644
--- a/qt4/src/poppler-qt4.h
+++ b/qt4/src/poppler-qt4.h
@@ -178,6 +178,9 @@ namespace Poppler {
 	*/
 	QString typeName() const;
 
+	/**
+	   Standard assignment operator
+	*/
 	FontInfo& operator=( const FontInfo &fi );
 
     private:
@@ -264,7 +267,14 @@ namespace Poppler {
 	*/
 	~Page();
 
-	enum Rotation { Rotate0 = 0, Rotate90 = 1, Rotate180 = 2, Rotate270 = 3 };
+	/**
+	   The type of rotation to apply for an operation
+	*/
+	enum Rotation { Rotate0 = 0,   ///< Do not rotate
+			Rotate90 = 1,  ///< Rotate 90 degrees clockwise
+			Rotate180 = 2, ///< Rotate 180 degrees
+			Rotate270 = 3  ///< Rotate 270 degrees clockwise (90 degrees counterclockwise)
+	};
 
 	/**
 	   The kinds of page actions
@@ -324,9 +334,20 @@ namespace Poppler {
 	**/
 	QString text(const QRectF &rect) const;
 	
-	
-	enum SearchDirection { FromTop, NextResult, PreviousResult };
-	enum SearchMode { CaseSensitive, CaseInsensitive };
+	/**
+	   The starting point for a search
+	*/
+	enum SearchDirection { FromTop,        ///< Start sorting at the top of the document
+			       NextResult,     ///< Find the next result, moving "down the page"
+			       PreviousResult  ///< Find the previous result, moving "up the page"
+	};
+
+	/**
+	   The type of search to perform
+	*/
+	enum SearchMode { CaseSensitive,   ///< Case differences cause no match in searching
+			  CaseInsensitive  ///< Case differences are ignored in matching
+	};
 	
 	/**
 	   Returns true if the specified text was found.
@@ -336,6 +357,7 @@ namespace Poppler {
 	               indicates where to continue searching for
 	   \param direction in which direction do the search
 	   \param caseSensitive be case sensitive?
+	   \param rotate the rotation to apply for the search order
 	**/
 	bool search(const QString &text, QRectF &rect, SearchDirection direction, SearchMode caseSensitive, Rotation rotate = Rotate0) const;
 	
@@ -492,13 +514,22 @@ namespace Poppler {
 	   Load the document from a file on disk
 
 	   \param filePath the name (and path, if required) of the file to load
+	   \param ownerPassword the owner password to use in loading the file.
+	   \param userPassword the user ("open") password to use in loading the file
 
 	   \return NULL on error
 
+	   \note Passwords must be Latin1 encoded. If you have a password that is
+	   a UTF8 string, you need to use QString::toLatin1() (or similar) to convert
+	   the password first. If you have a UTF8 character array, consider
+	   converting it to a QString first (QString::fromUtf8(), or similar) before
+	   converting to Latin1 encoding.
+
 	   \warning The application owns the pointer to Document, and this should
 	   be deleted when no longer required.
 	
-	   \warning The returning document may be locked.
+	   \warning The returning document may be locked if a password is required
+	   to open the file, and one is not provided (as the userPassword).
 	*/
 	static Document *load(const QString & filePath,
 			      const QByteArray &ownerPassword=QByteArray(),
@@ -510,6 +541,14 @@ namespace Poppler {
 	   \param fileContents the file contents. They are copied so there is no need 
 	                       to keep the byte array around for the full life time of 
 	                       the document.
+	   \param ownerPassword the owner password to use in loading the file.
+	   \param userPassword the user ("open") password to use in loading the file
+
+	   \note Passwords must be Latin1 encoded. If you have a password that is
+	   a UTF8 string, you need to use QString::toLatin1() (or similar) to convert
+	   the password first. If you have a UTF8 character array, consider
+	   converting it to a QString first (QString::fromUtf8(), or similar) before
+	   converting to Latin1 encoding.
 
 	   \warning The application owns the pointer to Document, and this should
 	   be deleted when no longer required.
@@ -563,6 +602,15 @@ namespace Poppler {
 
 	/**
 	   Provide the passwords required to unlock the document
+
+	   \param ownerPassword the owner password to use in loading the file.
+	   \param userPassword the user ("open") password to use in loading the file
+
+	   \note Passwords must be Latin1 encoded. If you have a password that is
+	   a UTF8 string, you need to use QString::toLatin1() (or similar) to convert
+	   the password first. If you have a UTF8 character array, consider
+	   converting it to a QString first (QString::fromUtf8(), or similar) before
+	   converting to Latin1 encoding.
 	*/
 	bool unlock(const QByteArray &ownerPassword, const QByteArray &userPassword);
 
@@ -973,17 +1021,17 @@ height = dummy.height();
 	~SoundObject();
 
 	/**
-	   Is the sound embedded (\ref Embedded ) or external (\ref External )?
+	   Is the sound embedded (SoundObject::Embedded) or external (SoundObject::External)?
 	*/
 	SoundType soundType() const;
 
 	/**
-	   The URL of the sound file to be played, in case of \ref External
+	   The URL of the sound file to be played, in case of SoundObject::External
 	*/
 	QString url() const;
 
 	/**
-	   The data of the sound, in case of \ref Embedded
+	   The data of the sound, in case of SoundObject::Embedded
 	*/
 	QByteArray data() const;
 
commit 96493c9409186a7e964e894c7f730962b6995fd7
Author: Albert Astals Cid <tsdgeos at bluebox.localdomain>
Date:   Wed Oct 31 23:51:25 2007 +0100

    remove old file

diff --git a/glib/test-poppler-glib.c b/glib/test-poppler-glib.c
deleted file mode 100644
index 007353c..0000000
--- a/glib/test-poppler-glib.c
+++ /dev/null
@@ -1,514 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include "poppler.h"
-
-#define FAIL(msg) \
-	do { fprintf (stderr, "FAIL: %s\n", msg); exit (-1); } while (0)
-
-static gchar *
-poppler_format_date (GTime utime)
-{
-	time_t time = (time_t) utime;
-	struct tm t;
-	char s[256];
-	const char *fmt_hack = "%c";
-	size_t len;
-
-	if (time == 0 || !localtime_r (&time, &t)) return NULL;
-
-	len = strftime (s, sizeof (s), fmt_hack, &t);
-	if (len == 0 || s[0] == '\0') return NULL;
-
-	return g_locale_to_utf8 (s, -1, NULL, NULL, NULL);
-}
-
-static void
-print_index (PopplerIndexIter *iter)
-{
-  do
-    {
-      PopplerAction *action;
-      PopplerIndexIter *child;
-
-      action = poppler_index_iter_get_action (iter);
-      g_print ("Action: %d\n", action->type);
-      poppler_action_free (action);
-      child = poppler_index_iter_get_child (iter);
-      if (child)
-	print_index (child);
-      poppler_index_iter_free (child);
-    }
-  while (poppler_index_iter_next (iter));
-}
-
-static void
-print_document_info (PopplerDocument *document)
-{
-  gchar *title, *format, *author, *subject, *keywords, *creator, *producer, *linearized;
-  GTime creation_date, mod_date;
-  gchar *strdate;
-  PopplerPageLayout layout;
-  PopplerPageMode mode;
-  PopplerViewerPreferences view_prefs;
-  PopplerFontInfo *font_info;
-  PopplerFontsIter *fonts_iter;
-  PopplerIndexIter *index_iter;
-  GEnumValue *enum_value;
-
-  g_object_get (document,
-		"title", &title,
-		"format", &format,
-		"author", &author,
-		"subject", &subject,
-		"keywords", &keywords,
-		"creation-date", &creation_date,
-		"mod-date", &mod_date,
-		"creator", &creator,
-		"producer", &producer,	
-		"linearized", &linearized,
-		"page-mode", &mode,
-		"page-layout", &layout,
-		"viewer-preferences", &view_prefs,
-		NULL);
-
-  printf ("\t---------------------------------------------------------\n");
-  printf ("\tDocument Metadata\n");
-  printf ("\t---------------------------------------------------------\n");
-  if (title)  printf   ("\ttitle:\t\t%s\n", title);
-  if (format) printf   ("\tformat:\t\t%s\n", format);
-  if (author) printf   ("\tauthor:\t\t%s\n", author);
-  if (subject) printf  ("\tsubject:\t%s\n", subject);
-  if (keywords) printf ("\tkeywords:\t%s\n", keywords);
-  if (creator) printf ("\tcreator:\t%s\n", creator);
-  if (producer) printf ("\tproducer:\t%s\n", producer);
-  if (linearized) printf ("\tlinearized:\t%s\n", linearized);
-  
-  enum_value = g_enum_get_value ((GEnumClass *) g_type_class_peek (POPPLER_TYPE_PAGE_MODE), mode);
-  g_print ("\tpage mode:\t%s\n", enum_value->value_name);
-  enum_value = g_enum_get_value ((GEnumClass *) g_type_class_peek (POPPLER_TYPE_PAGE_LAYOUT), layout);
-  g_print ("\tpage layout:\t%s\n", enum_value->value_name);
-
-  strdate = poppler_format_date (creation_date);
-  if (strdate)
-    {
-      g_print ("\tcreation date:\t%s\n", strdate);
-      g_free (strdate);
-    }
-  strdate = poppler_format_date (mod_date);
-  if (strdate)
-    {
-      g_print ("\tmodified date:\t%s\n", strdate);
-      g_free (strdate);
-    }
-
-  g_print ("\tfonts:\n");
-  font_info = poppler_font_info_new (document);
-  while (poppler_font_info_scan (font_info, 20, &fonts_iter)) {
-    if (fonts_iter) {
-      do {
-        g_print ("\t\t\t%s\n", poppler_fonts_iter_get_name (fonts_iter));
-      } while (poppler_fonts_iter_next (fonts_iter));
-      poppler_fonts_iter_free (fonts_iter);
-    }
-  }
-  g_object_unref (font_info);
-
-  index_iter = poppler_index_iter_new (document);
-  if (index_iter)
-    {
-      g_print ("\tindex:\n");
-      print_index (index_iter);
-      poppler_index_iter_free (index_iter);
-    }
-  
-
-  
-  /* FIXME: print out the view prefs when we support it */
-
-  g_free (title);
-  g_free (format);
-  g_free (author);
-  g_free (subject);
-  g_free (keywords);
-  g_free (creator);
-  g_free (producer); 
-  g_free (linearized);
-}
-
-static const gchar *
-transition_effect_name (PopplerPageTransitionType type)
-{
-  switch (type)
-    {
-      case POPPLER_PAGE_TRANSITION_REPLACE:
-	return "Replace";
-      case POPPLER_PAGE_TRANSITION_SPLIT:
-	return "Split";
-      case POPPLER_PAGE_TRANSITION_BLINDS:
-	return "Blinds";
-      case POPPLER_PAGE_TRANSITION_BOX:
-	return "Box";
-      case POPPLER_PAGE_TRANSITION_WIPE:
-	return "Wipe";
-      case POPPLER_PAGE_TRANSITION_DISSOLVE:
-	return "Dissolve";
-      case POPPLER_PAGE_TRANSITION_GLITTER:
-	return "Glitter";
-      case POPPLER_PAGE_TRANSITION_FLY:
-	return "Fly";
-      case POPPLER_PAGE_TRANSITION_PUSH:
-	return "Push";
-      case POPPLER_PAGE_TRANSITION_COVER:
-	return "Cover";
-      case POPPLER_PAGE_TRANSITION_UNCOVER:
-	return "Uncover";
-      case POPPLER_PAGE_TRANSITION_FADE:
-	return "Fade";
-    }
-
-  return "Unknown";
-}
-
-static void
-print_page_transition (PopplerPageTransition *transition)
-{
-  printf ("\t\tEffect: %s\n", transition_effect_name (transition->type));
-  printf ("\t\tAlignment: %s\n",
-	  transition->alignment == POPPLER_PAGE_TRANSITION_HORIZONTAL ?
-	  "Horizontal" : "Vertical");
-  printf ("\t\tDirection: %s\n",
-	  transition->direction == POPPLER_PAGE_TRANSITION_INWARD ?
-	  "Inward" : "Outward");
-  printf ("\t\tDuration: %d\n", transition->duration);
-  printf ("\t\tAngle: %d\n", transition->angle);
-  printf ("\t\tScale: %.2f\n", transition->scale);
-  printf ("\t\tRectangular: %s\n", transition->rectangular ? "Yes" : "No");
-}
-
-static void
-form_field_text_print (PopplerFormField *field)
-{
-  PopplerFormTextType type;
-  gchar *text;
-
-  type = poppler_form_field_text_get_text_type (field);
-  printf ("\t\tType:\t\tText\n");
-  printf ("\t\tMultiline:\t%s\n",
-	  type == POPPLER_FORM_TEXT_MULTILINE ? "Yes" : "No");
-  printf ("\t\tFileSelect:\t%s\n",
-	  type == POPPLER_FORM_TEXT_FILE_SELECT ? "Yes" : "No");
-  printf ("\t\tDoSpellCheck:\t%s\n",
-	  poppler_form_field_text_do_spell_check (field) ? "Yes" : "No");
-  printf ("\t\tDoScroll:\t%s\n",
-	  poppler_form_field_text_do_scroll (field) ? "Yes" : "No");
-  printf ("\t\tIsRichText:\t%s\n",
-	  poppler_form_field_text_is_rich_text (field) ? "Yes" : "No");
-  printf ("\t\tPassword:\t%s\n",
-	  poppler_form_field_text_is_password (field) ? "Yes" : "No");
-  printf ("\t\tMaxLen:\t\t%d\n", poppler_form_field_text_get_max_len (field));
-  text = poppler_form_field_text_get_text (field);
-  printf ("\t\tContent:\t%s\n", text ? text : "");
-  g_free (text);
-}
-
-static void
-form_field_button_print (PopplerFormField *field)
-{
-  PopplerFormButtonType button_type;
-  const gchar *button_type_str;
-
-  button_type = poppler_form_field_button_get_button_type (field);
-
-  switch (button_type)
-    {
-      case POPPLER_FORM_BUTTON_PUSH:
-        button_type_str = "Push";
-	break;
-      case POPPLER_FORM_BUTTON_CHECK:
-        button_type_str = "Check box";
-	break;
-      case POPPLER_FORM_BUTTON_RADIO:
-        button_type_str = "Radio Button";
-	break;
-      default:
-        g_assert_not_reached ();
-    }
-  
-  printf ("\t\tType:\t\tButton\n");
-  printf ("\t\tButton type:\t%s\n", button_type_str);
-  if (button_type != POPPLER_FORM_BUTTON_PUSH)
-    printf ("\t\tState:\t\t%s\n",
-	    poppler_form_field_button_get_state (field) ? "Active" : "Inactive");
-}
-
-static void
-form_field_choice_print (PopplerFormField *field)
-{
-  gint i, n_items;
-  
-  printf ("\t\tType:\t\tChoice\n");
-  printf ("\t\tSubType:\t%s\n",
-	  poppler_form_field_choice_get_choice_type (field) == POPPLER_FORM_CHOICE_COMBO ?
-	  "Combo" : "List");
-  printf ("\t\tEditable:\t%s\n",
-	  poppler_form_field_choice_is_editable (field) ? "Yes" : "No");
-  printf ("\t\tCan select multiple: %s\n",
-	  poppler_form_field_choice_can_select_multiple (field) ? "Yes" : "No");
-  printf ("\t\tDoSpellCheck:\t%s\n",
-	  poppler_form_field_choice_do_spell_check (field) ? "Yes" : "No");
-  printf ("\t\tCommit on change: %s\n",
-	  poppler_form_field_choice_commit_on_change (field) ? "Yes" : "No");
-  
-  n_items = poppler_form_field_choice_get_n_items (field);
-  for (i = 0; i < n_items; i++)
-    {
-      gchar *item;
-
-      item = poppler_form_field_choice_get_item (field, i);
-      printf ("\t\t\tItem %d: %s %s\n", i, item ? item : "",
-	      poppler_form_field_choice_is_item_selected (field, i) ?
-	      "(selected)" : "");
-      g_free (item);
-    }
-}
-
-static void
-form_field_print (PopplerFormField *field)
-{
-  printf ("\t\tFont Size:\t%.2f\n",
-	  poppler_form_field_get_font_size (field));
-  printf ("\t\tReadOnly:\t%s\n",
-	  poppler_form_field_is_read_only (field) ? "Yes" : "No");
-  
-  switch (poppler_form_field_get_field_type (field))
-    {
-    case POPPLER_FORM_FIELD_TEXT:
-      form_field_text_print (field);
-      break;
-    case POPPLER_FORM_FIELD_BUTTON:
-      form_field_button_print (field);
-      break;
-    case POPPLER_FORM_FIELD_CHOICE:
-      form_field_choice_print (field);
-      break;
-    default:
-      printf ("\t\tUnknown form field\n");
-    }
-  printf ("\n");
-}
-
-int main (int argc, char *argv[])
-{
-  PopplerDocument *document;
-  PopplerBackend backend;
-  PopplerPage *page;
-  PopplerPageTransition *transition;
-  PopplerFormField *field;
-  GEnumValue *enum_value;
-  char *label;
-  GError *error;
-  GdkPixbuf *pixbuf, *thumb;
-  double width, height;
-  GList *list, *l;
-  char *text;
-  double duration;
-  PopplerRectangle area;
-  gint num_images;
-  gint num_forms;
-  gint form_id;
-
-  if (argc != 3)
-    FAIL ("usage: test-poppler-glib file://FILE PAGE");
-
-  g_type_init ();
-
-  g_print ("Poppler version %s\n", poppler_get_version ());
-  backend = poppler_get_backend ();
-  enum_value = g_enum_get_value ((GEnumClass *) g_type_class_ref (POPPLER_TYPE_BACKEND), backend);
-  g_print ("Backend is %s\n", enum_value->value_name);
-
-  error = NULL;
-  document = poppler_document_new_from_file (argv[1], NULL, &error);
-  if (document == NULL)
-    FAIL (error->message);
-
-  print_document_info (document); 
-
-  page = poppler_document_get_page_by_label (document, argv[2]);
-  if (page == NULL)
-    FAIL ("page not found");
-
-  poppler_page_get_size (page, &width, &height);
-  printf ("\tpage size:\t%f inches by %f inches\n", width / 72, height / 72);
-
-  duration = poppler_page_get_duration (page);
-  if (duration > 0)
-    printf ("\tpage duration:\t%f second(s)\n", duration);
-  else
-    printf ("\tpage duration:\tno duration for page\n");
-
-  transition = poppler_page_get_transition (page);
-  if (transition) {
-    printf ("\tpage transition:\n");
-    print_page_transition (transition);
-    poppler_page_transition_free (transition);
-  } else {
-    printf ("\tpage transition:no transition effect for page\n");
-  }
-
-  thumb = poppler_page_get_thumbnail (page);
-  if (thumb != NULL) {
-    gdk_pixbuf_save (thumb, "thumb.png", "png", &error, NULL);
-    if (error != NULL)
-      FAIL (error->message);
-    else
-      printf ("\tthumbnail:\tsaved as thumb.png\n");
-    g_object_unref (G_OBJECT (thumb));
-  }
-  else
-    printf ("\tthumbnail:\tno thumbnail for page\n");
-
-  g_object_get (page, "label", &label, NULL);
-  printf ("\tpage label:\t%s\n", label);
-  g_free (label);
-
-  pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 220, 220);
-  gdk_pixbuf_fill (pixbuf, 0x00106000);
-  poppler_page_render_to_pixbuf (page, 100, 100, 200, 200, 1, 0, pixbuf);
-
-  gdk_pixbuf_save (pixbuf, "slice.png", "png", &error, NULL);
-  printf ("\tslice:\t\tsaved 200x200 slice at (100, 100) as slice.png\n");
-  if (error != NULL) {
-    FAIL (error->message);
-    g_error_free (error);
-  }
-
-  g_object_unref (G_OBJECT (pixbuf));
-
-  area.x1 = 0;
-  area.y1 = 0;
-  area.x2 = width;
-  area.y2 = height;
-
-  text = poppler_page_get_text (page, POPPLER_SELECTION_GLYPH, &area);
-  if (text)
-    {
-      FILE *file = fopen ("dump.txt", "w");
-      if (file)
-	{
-	  fwrite (text, strlen (text), 1, file);
-	  fclose (file);
-	}
-      g_free (text);
-    }
-
-  list = poppler_page_find_text (page, "Bitwise");
-  printf ("\n");  
-  printf ("\tFound text \"Bitwise\" at positions:\n");
-  for (l = list; l != NULL; l = l->next)
-    {
-      PopplerRectangle *rect = l->data;
-
-      printf ("  (%f,%f)-(%f,%f)\n", rect->x1, rect->y1, rect->x2, rect->y2);
-    }
-
-  list = poppler_page_get_image_mapping (page);
-  num_images = g_list_length (list);
-  printf ("\n");
-  if (num_images > 0)
-    printf ("\tFound %d images at positions:\n", num_images);
-  else
-    printf ("\tNo images found\n");
-  for (l = list; l != NULL; l = l->next)
-    {
-      PopplerImageMapping *mapping;
-      
-      mapping = (PopplerImageMapping *)l->data;
-      printf ("\t\t(%f, %f) - (%f, %f)\n",
-	      mapping->area.x1,
-	      mapping->area.y1,
-	      mapping->area.x2,
-	      mapping->area.y2);
-    }
-  poppler_page_free_image_mapping (list);
-
-  list = poppler_page_get_form_field_mapping (page);
-  num_forms = g_list_length (list);
-  printf ("\n");
-  if (num_forms > 0)
-    printf ("\tFound %d form fields at positions:\n", num_forms);
-  else
-    printf ("\tNo forms fields found\n");
-  for (l = list; l != NULL; l = l->next)
-    {
-      PopplerFormFieldMapping *mapping;
-
-      mapping = (PopplerFormFieldMapping *)l->data;
-
-      form_id = poppler_form_field_get_id (mapping->field);
-      
-      printf ("\t\tId: %d: (%f, %f) - (%f, %f)\n",
-	      form_id,
-	      mapping->area.x1,
-	      mapping->area.y1,
-	      mapping->area.x2,
-	      mapping->area.y2);
-      form_field_print (mapping->field);
-    }
-  poppler_page_free_form_field_mapping (list);
-
-  if (num_forms > 0)
-    {
-      field = poppler_document_get_form_field (document, form_id);
-      printf ("\tForm field for id %d\n", form_id);
-      form_field_print (field);
-      g_object_unref (field);
-    }
-  
-  if (poppler_document_has_attachments (document))
-    {
-      int i = 0;
-
-      g_print ("Attachments found:\n\n");
-
-      list = poppler_document_get_attachments (document);
-      for (l = list; l; l = l->next)
-	{
-	  PopplerAttachment *attachment;
-	  char *filename, *strdate;
-
-	  filename = g_strdup_printf ("/tmp/attach%d", i);
-	  attachment = l->data;
-	  g_print ("\tname: %s\n", attachment->name);
-	  g_print ("\tdescription: %s\n", attachment->description);
-	  g_print ("\tsize: %d\n", attachment->size);
-	  strdate = poppler_format_date (attachment->ctime);
-	  if (strdate)
-	    {
-	      g_print ("\tcreation date: %s\n", strdate);
-	      g_free (strdate);
-	    }
-	  strdate = poppler_format_date (attachment->mtime);
-	  if (strdate)
-	    {
-	      g_print ("\tmodification date: %s\n", strdate);
-	      g_free (strdate);
-	    }
-	  poppler_attachment_save (attachment, filename, NULL);
-	  g_free (filename);
-	  g_print ("\n");
-	  i++;
-	}
-      g_list_foreach (list, (GFunc) g_object_unref, NULL);
-      g_list_free (list);
-    }
-  else
-    g_print ("\tNo attachments found\n");
-
-  g_object_unref (G_OBJECT (page));
-  g_object_unref (G_OBJECT (document));
-
-  return 0;
-}


More information about the poppler mailing list