[poppler] poppler/glib: poppler-document.cc, 1.17, 1.18 poppler-document.h, 1.11, 1.12 poppler-private.h, 1.6, 1.7 poppler.h, 1.7, 1.8 test-poppler-glib.c, 1.11, 1.12

Kristian Hogsberg krh at freedesktop.org
Mon Jun 13 09:09:35 PDT 2005


Update of /cvs/poppler/poppler/glib
In directory gabe:/tmp/cvs-serv27952/glib

Modified Files:
	poppler-document.cc poppler-document.h poppler-private.h 
	poppler.h test-poppler-glib.c 
Log Message:
2005-06-13  Kristian Høgsberg  <krh at redhat.com>

        * glib/poppler-document.cc:
        * glib/poppler-document.h:
        * glib/poppler-private.h:
        * glib/poppler.h:
        * glib/test-poppler-glib.c:
        * poppler/Makefile.am: Patch from Marco to extract font info from
        document.



Index: poppler-document.cc
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler-document.cc,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- poppler-document.cc	29 May 2005 14:59:34 -0000	1.17
+++ poppler-document.cc	13 Jun 2005 16:09:33 -0000	1.18
@@ -26,6 +26,7 @@
 #include <GfxState.h>
 #include <SplashOutputDev.h>
 #include <Stream.h>
+#include <FontInfo.h>
 
 #include "poppler.h"
 #include "poppler-private.h"
@@ -745,6 +746,136 @@
 	
 }
 
+struct _PopplerFontsIter
+{
+	GooList *items;
+	int index;
+};
+
+GType
+poppler_fonts_iter_get_type (void)
+{
+  static GType our_type = 0;
+
+  if (our_type == 0)
+    our_type = g_boxed_type_register_static ("PopplerFontsIter",
+					     (GBoxedCopyFunc) poppler_fonts_iter_copy,
+					     (GBoxedFreeFunc) poppler_fonts_iter_free);
+
+  return our_type;
+}
+
+const char *
+poppler_fonts_iter_get_name (PopplerFontsIter *iter)
+{
+	FontInfo *info;
+
+	info = (FontInfo *)iter->items->get (iter->index);
+
+	return info->getName()->getCString();
+}
+
+gboolean
+poppler_fonts_iter_next (PopplerFontsIter *iter)
+{
+	g_return_val_if_fail (iter != NULL, FALSE);
+
+	iter->index++;
+	if (iter->index >= iter->items->getLength())
+		return FALSE;
+
+	return TRUE;
+}
+
+PopplerFontsIter *
+poppler_fonts_iter_copy (PopplerFontsIter *iter)
+{
+	PopplerFontsIter *new_iter;
+
+	g_return_val_if_fail (iter != NULL, NULL);
+
+	new_iter = g_new0 (PopplerFontsIter, 1);
+	*new_iter = *iter;
+
+	new_iter->items = new GooList ();
+	for (int i = 0; i < iter->items->getLength(); i++) {
+		FontInfo *info = (FontInfo *)iter->items->get(i);
+		new_iter->items->append (new FontInfo (*info));
+	}
+
+	return new_iter;
+}
+
+void
+poppler_fonts_iter_free (PopplerFontsIter *iter)
+{
+	if (iter == NULL)
+		return;
+
+	deleteGooList (iter->items, FontInfo);
+
+	g_free (iter);
+}
+
+static PopplerFontsIter *
+poppler_fonts_iter_new (GooList *items)
+{
+	PopplerFontsIter *iter;
+
+	iter = g_new0 (PopplerFontsIter, 1);
+	iter->items = items;
+	iter->index = 0;
+
+	return iter;
+}
+
+PopplerFontInfo *
+poppler_font_info_new (PopplerDocument *document)
+{
+	PopplerFontInfo *font_info;
+
+	g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL);
+
+	font_info = g_new0 (PopplerFontInfo, 1);
+	font_info->document = (PopplerDocument *) g_object_ref (document);
+	font_info->scanner = new FontInfoScanner(document->doc);
+
+	return font_info;
+}
+
+gboolean
+poppler_font_info_scan (PopplerFontInfo   *font_info,
+			int                n_pages,
+			PopplerFontsIter **iter)
+{
+	GooList *items;
+
+	g_return_val_if_fail (iter != NULL, FALSE);
+
+	items = font_info->scanner->scan(n_pages);
+
+	if (items == NULL) {
+		*iter = NULL;
+	} else if (items->getLength() == 0) {
+		*iter = NULL;
+		delete items;
+	} else {
+		*iter = poppler_fonts_iter_new(items);
+	}
+	
+	return (items != NULL);
+}
+
+void
+poppler_font_info_free (PopplerFontInfo *font_info)
+{
+	g_return_if_fail (font_info != NULL);
+
+	delete font_info->scanner;
+
+	g_object_unref (font_info->document);
+}
+
 /**
  * poppler_ps_file_new:
  * @document: a #PopplerDocument

Index: poppler-document.h
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler-document.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- poppler-document.h	23 May 2005 04:23:53 -0000	1.11
+++ poppler-document.h	13 Jun 2005 16:09:33 -0000	1.12
@@ -103,6 +103,19 @@
 PopplerAction    *poppler_index_iter_get_action (PopplerIndexIter  *iter);
 gboolean          poppler_index_iter_next       (PopplerIndexIter  *iter);
 
+/* Interface for getting the Fonts of a poppler_document */
+PopplerFontInfo  *poppler_font_info_new         (PopplerDocument   *document);
+gboolean          poppler_font_info_scan        (PopplerFontInfo   *font_info,
+						 int                n_pages,
+						 PopplerFontsIter **iter);
+void		  poppler_font_info_free	(PopplerFontInfo   *font_info);
+
+GType             poppler_fonts_iter_get_type   (void) G_GNUC_CONST;
+PopplerFontsIter *poppler_fonts_iter_copy       (PopplerFontsIter  *iter);
+void              poppler_fonts_iter_free       (PopplerFontsIter  *iter);
+const char       *poppler_fonts_iter_get_name   (PopplerFontsIter  *iter);
+gboolean          poppler_fonts_iter_next       (PopplerFontsIter  *iter);
+
 /* Export to ps */
 PopplerPSFile *poppler_ps_file_new   (PopplerDocument *document,
 				      const char      *filename,

Index: poppler-private.h
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler-private.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- poppler-private.h	21 Apr 2005 05:20:25 -0000	1.6
+++ poppler-private.h	13 Jun 2005 16:09:33 -0000	1.7
@@ -5,6 +5,7 @@
 #include <PDFDoc.h>
 #include <PSOutputDev.h>
 #include <Link.h>
+#include <FontInfo.h>
 
 #if defined (HAVE_CAIRO)
 #include <CairoOutputDevImage.h>
@@ -30,6 +31,12 @@
   PSOutputDev *out;
 };
 
+struct _PopplerFontInfo
+{
+  PopplerDocument *document;
+  FontInfoScanner *scanner;
+};
+
 struct _PopplerPage
 {
   GObject parent_instance;

Index: poppler.h
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- poppler.h	11 May 2005 20:01:43 -0000	1.7
+++ poppler.h	13 Jun 2005 16:09:33 -0000	1.8
@@ -45,9 +45,11 @@
 
 typedef struct _PopplerDocument    PopplerDocument;
 typedef struct _PopplerIndexIter   PopplerIndexIter;
+typedef struct _PopplerFontsIter   PopplerFontsIter;
 typedef struct _PopplerRectangle   PopplerRectangle;
 typedef struct _PopplerLinkMapping PopplerLinkMapping;
 typedef struct _PopplerPage        PopplerPage;
+typedef struct _PopplerFontInfo    PopplerFontInfo;
 typedef struct _PopplerPSFile      PopplerPSFile;
 typedef union  _PopplerAction      PopplerAction;
 

Index: test-poppler-glib.c
===================================================================
RCS file: /cvs/poppler/poppler/glib/test-poppler-glib.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- test-poppler-glib.c	29 May 2005 14:59:34 -0000	1.11
+++ test-poppler-glib.c	13 Jun 2005 16:09:33 -0000	1.12
@@ -15,6 +15,8 @@
   PopplerPageLayout layout;
   PopplerPageMode mode;
   PopplerViewerPreferences view_prefs;
+  PopplerFontInfo *font_info;
+  PopplerFontsIter *fonts_iter;
   GEnumValue *enum_value;
 
   g_object_get (document,
@@ -53,6 +55,18 @@
   g_print ("\tcreation date:\t%d\n", creation_date);
   g_print ("\tmodified date:\t%d\n", mod_date);
 
+  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);
+    }
+  }
+  poppler_font_info_free (font_info);
+
   /* FIXME: print out the view prefs when we support it */
 
   g_free (title);



More information about the poppler mailing list