[poppler] 3 commits - glib/demo poppler/poppler-config.h.in

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Fri Jan 15 03:07:49 PST 2010


 glib/demo/Makefile.am       |    2 
 glib/demo/main.c            |    4 -
 glib/demo/print.c           |  135 ++++++++++++++++++++++++++++++++++++++++++++
 glib/demo/print.h           |   31 ++++++++++
 glib/demo/render.c          |   47 ++++++++++++---
 poppler/poppler-config.h.in |   10 +++
 6 files changed, 219 insertions(+), 10 deletions(-)

New commits:
commit b64d4bd46b052feb0b143f1348773afbd93e5e33
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Fri Nov 27 11:47:22 2009 +0100

    [glib-demo] Add print demo

diff --git a/glib/demo/Makefile.am b/glib/demo/Makefile.am
index 4c301de..fef1d5c 100644
--- a/glib/demo/Makefile.am
+++ b/glib/demo/Makefile.am
@@ -36,6 +36,8 @@ poppler_glib_demo_SOURCES = 			\
 	outline.c				\
 	page.h					\
 	page.c					\
+	print.h					\
+	print.c					\
 	render.h				\
 	render.c				\
 	text.h					\
diff --git a/glib/demo/main.c b/glib/demo/main.c
index 36994bb..89e4eeb 100644
--- a/glib/demo/main.c
+++ b/glib/demo/main.c
@@ -35,6 +35,7 @@
 #include "layers.h"
 #include "text.h"
 #include "find.h"
+#include "print.h"
 
 enum {
 	PGD_TITLE_COLUMN,
@@ -62,7 +63,8 @@ static const PopplerGlibDemo demo_list[] = {
 	{ "Attachments",      pgd_attachments_create_widget },
 	{ "Layers",           pgd_layers_create_widget },
 	{ "Text",             pgd_text_create_widget },
-	{ "Find",             pgd_find_create_widget }
+	{ "Find",             pgd_find_create_widget },
+	{ "Print",             pgd_print_create_widget }
 };
 
 static void
diff --git a/glib/demo/print.c b/glib/demo/print.c
new file mode 100644
index 0000000..77e625e
--- /dev/null
+++ b/glib/demo/print.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2009 Carlos Garcia Campos  <carlosgc at gnome.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+#include "print.h"
+
+typedef struct {
+	PopplerDocument *doc;
+} PgdPrintDemo;
+
+static void
+pgd_print_free (PgdPrintDemo *demo)
+{
+	if (!demo)
+		return;
+
+	if (demo->doc) {
+		g_object_unref (demo->doc);
+		demo->doc = NULL;
+	}
+
+	g_free (demo);
+}
+
+static void
+pgd_print_begin_print (GtkPrintOperation *op,
+		       GtkPrintContext   *context,
+		       PgdPrintDemo      *demo)
+{
+	gtk_print_operation_set_n_pages (op, poppler_document_get_n_pages (demo->doc));
+}
+
+static void
+pgd_print_draw_page (GtkPrintOperation *op,
+		     GtkPrintContext   *context,
+		     gint               page_nr,
+		     PgdPrintDemo      *demo)
+{
+	PopplerPage *page;
+	cairo_t     *cr;
+
+	page = poppler_document_get_page (demo->doc, page_nr);
+	if (!page)
+		return;
+
+	cr = gtk_print_context_get_cairo_context (context);
+	poppler_page_render_for_printing (page, cr);
+	g_object_unref (page);
+}
+
+static void
+pgd_print_print (GtkWidget    *button,
+		 PgdPrintDemo *demo)
+{
+	GtkPrintOperation *op;
+	GError            *error = NULL;
+
+	op = gtk_print_operation_new ();
+	g_signal_connect (op, "begin-print",
+			  G_CALLBACK (pgd_print_begin_print),
+			  demo);
+	g_signal_connect (op, "draw-page",
+			  G_CALLBACK (pgd_print_draw_page),
+			  demo);
+	gtk_print_operation_run (op,
+				 GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
+				 GTK_WINDOW (gtk_widget_get_toplevel (button)),
+				 &error);
+	if (error) {
+		GtkWidget *dialog;
+
+		dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (button)),
+						 GTK_DIALOG_DESTROY_WITH_PARENT,
+						 GTK_MESSAGE_ERROR,
+						 GTK_BUTTONS_CLOSE,
+						 "%s", error->message);
+		g_error_free (error);
+
+		g_signal_connect (dialog, "response",
+				  G_CALLBACK (gtk_widget_destroy), NULL);
+
+		gtk_widget_show (dialog);
+	}
+	g_object_unref (op);
+}
+
+GtkWidget *
+pgd_print_create_widget (PopplerDocument *document)
+{
+	PgdPrintDemo *demo;
+	GtkWidget    *vbox;
+	GtkWidget    *hbox;
+	GtkWidget    *button;
+
+	demo = g_new0 (PgdPrintDemo, 1);
+
+	demo->doc = g_object_ref (document);
+
+	vbox = gtk_vbox_new (FALSE, 12);
+
+	hbox = gtk_hbox_new (FALSE, 6);
+
+	button = gtk_button_new_with_label ("Print...");
+	g_signal_connect (G_OBJECT (button), "clicked",
+			  G_CALLBACK (pgd_print_print),
+			  (gpointer)demo);
+	gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+	gtk_widget_show (button);
+
+	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
+	gtk_widget_show (hbox);
+
+	g_object_weak_ref (G_OBJECT (vbox),
+			   (GWeakNotify)pgd_print_free,
+			   (gpointer)demo);
+
+	return vbox;
+}
diff --git a/glib/demo/print.h b/glib/demo/print.h
new file mode 100644
index 0000000..667259c
--- /dev/null
+++ b/glib/demo/print.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2009 Carlos Garcia Campos  <carlosgc at gnome.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <gtk/gtk.h>
+#include <poppler.h>
+
+#ifndef _PRINT_H_
+#define _PRINT_H_
+
+G_BEGIN_DECLS
+
+GtkWidget *pgd_print_create_widget (PopplerDocument *document);
+
+G_END_DECLS
+
+#endif /* _PRINT_H_ */
commit ba2c746f358a5785d8cbaaf03d8628ee3754c388
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Fri Nov 27 09:52:50 2009 +0100

    [glib-demo] Add render for printing option to render demo

diff --git a/glib/demo/render.c b/glib/demo/render.c
index 610d7d6..f8f65bf 100644
--- a/glib/demo/render.c
+++ b/glib/demo/render.c
@@ -39,6 +39,7 @@ typedef struct {
 	gdouble          scale;
 	gint             rotate;
 	GdkRectangle     slice;
+	gboolean         printing;
 	
 	GtkWidget       *swindow;
 	GtkWidget       *darea;
@@ -191,8 +192,11 @@ pgd_render_start (GtkButton     *button,
 		
 		if (demo->rotate != 0)
 			cairo_rotate (cr, demo->rotate * G_PI / 180.0);
-		
-		poppler_page_render (page, cr);
+
+		if (demo->printing)
+			poppler_page_render_for_printing (page, cr);
+		else
+			poppler_page_render (page, cr);
 		cairo_restore (cr);
 
 		cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
@@ -209,13 +213,23 @@ pgd_render_start (GtkButton     *button,
 		demo->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
 					       FALSE, 8, width, height);
 		gdk_pixbuf_fill (demo->pixbuf, 0xffffff);
-		poppler_page_render_to_pixbuf (page,
-					       x, y,
-					       width,
-					       height,
-					       demo->scale,
-					       demo->rotate,
-					       demo->pixbuf);
+		if (demo->printing) {
+			poppler_page_render_to_pixbuf_for_printing (page,
+								    x, y,
+								    width,
+								    height,
+								    demo->scale,
+								    demo->rotate,
+								    demo->pixbuf);
+		} else {
+			poppler_page_render_to_pixbuf (page,
+						       x, y,
+						       width,
+						       height,
+						       demo->scale,
+						       demo->rotate,
+						       demo->pixbuf);
+		}
 		g_timer_stop (timer);
 #endif /* POPPLER_WITH_GDK */
 #if defined (HAVE_CAIRO)
@@ -284,6 +298,13 @@ pgd_render_rotate_selector_changed (GtkComboBox   *combobox,
 }
 
 static void
+pgd_render_printing_selector_changed (GtkToggleButton *tooglebutton,
+				      PgdRenderDemo *demo)
+{
+	demo->printing = gtk_toggle_button_get_active (tooglebutton);
+}
+
+static void
 pgd_render_mode_selector_changed (GtkComboBox   *combobox,
 				  PgdRenderDemo *demo)
 {
@@ -309,6 +330,7 @@ pgd_render_properties_selector_create (PgdRenderDemo *demo)
 	GtkWidget *scale_hbox, *scale_selector;
 	GtkWidget *rotate_hbox, *rotate_selector;
 	GtkWidget *mode_hbox, *mode_selector;
+	GtkWidget *printing_selector;
 	GtkWidget *slice_hbox, *slice_selector;
 	GtkWidget *button;
 	gint       n_pages;
@@ -405,6 +427,13 @@ pgd_render_properties_selector_create (PgdRenderDemo *demo)
 	gtk_box_pack_start (GTK_BOX (hbox), mode_hbox, FALSE, TRUE, 0);
 	gtk_widget_show (mode_hbox);
 
+	printing_selector = gtk_check_button_new_with_label ("Printing");
+	g_signal_connect (printing_selector, "toggled",
+			  G_CALLBACK (pgd_render_printing_selector_changed),
+			  (gpointer)demo);
+	gtk_box_pack_start (GTK_BOX (hbox), printing_selector, FALSE, TRUE, 0);
+	gtk_widget_show (printing_selector);
+
 	hbox = gtk_hbox_new (FALSE, 12);
 	gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
 	gtk_widget_show (hbox);
commit 9a478008ccb61641f09bd77eaa55033cca266c43
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Fri Jan 15 12:03:11 2010 +0100

    Add FONTCONFIGURATION macros to poppler-config.h
    
    They are used in a header file (GlobalParams.h). It fixes a crash
    when opening any document.

diff --git a/poppler/poppler-config.h.in b/poppler/poppler-config.h.in
index 016a081..f8db4ba 100644
--- a/poppler/poppler-config.h.in
+++ b/poppler/poppler-config.h.in
@@ -39,6 +39,16 @@
 #undef TEXTOUT_WORD_LIST
 #endif
 
+/* Use fontconfig font configuration backend */
+#ifndef WITH_FONTCONFIGURATION_FONTCONFIG
+#undef WITH_FONTCONFIGURATION_FONTCONFIG
+#endif
+
+/* Use win32 font configuration backend */
+#ifndef WITH_FONTCONFIGURATION_WIN32
+#undef WITH_FONTCONFIGURATION_WIN32
+#endif
+
 // Also, there's a couple of preprocessor symbols in the header files
 // that are used but never defined: DISABLE_OUTLINE, DEBUG_MEM and
 


More information about the poppler mailing list