[poppler] 2 commits - glib/demo glib/poppler.h glib/poppler-page.cc glib/poppler-page.h glib/reference
Carlos Garcia Campos
carlosgc at kemper.freedesktop.org
Sun Oct 17 03:38:28 PDT 2010
glib/demo/print.c | 96 ++++++++++++++++++++++++++++++++++--
glib/poppler-page.cc | 77 +++++++++++++++++++++++++---
glib/poppler-page.h | 3 +
glib/poppler.h | 19 +++++++
glib/reference/poppler-sections.txt | 4 +
5 files changed, 187 insertions(+), 12 deletions(-)
New commits:
commit d26d0fab2ddfff853f6681a3518813a2d65a4112
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date: Sun Oct 17 12:36:46 2010 +0200
[glib-demo] Use printing options in print demo
diff --git a/glib/demo/print.c b/glib/demo/print.c
index 77e625e..d1c89a9 100644
--- a/glib/demo/print.c
+++ b/glib/demo/print.c
@@ -21,10 +21,20 @@
#include <gtk/gtk.h>
#include "print.h"
+typedef enum {
+ PRINT_DOCUMENT,
+ PRINT_DOCUMENT_MARKUPS,
+ PRINT_DOCUMENT_STAMPS
+} PgdPrintOptions;
+
typedef struct {
PopplerDocument *doc;
+ GtkWidget *options_combo;
+ PgdPrintOptions options;
} PgdPrintDemo;
+#define PGD_PRINT_OPTIONS "pgd-print-options"
+
static void
pgd_print_free (PgdPrintDemo *demo)
{
@@ -53,18 +63,91 @@ pgd_print_draw_page (GtkPrintOperation *op,
gint page_nr,
PgdPrintDemo *demo)
{
- PopplerPage *page;
- cairo_t *cr;
+ PopplerPage *page;
+ cairo_t *cr;
+ GtkPrintSettings *settings;
+ PgdPrintOptions options;
+ PopplerPrintFlags flags = 0;
page = poppler_document_get_page (demo->doc, page_nr);
if (!page)
return;
+ settings = gtk_print_operation_get_print_settings (op);
+ /* Workaround for gtk+ bug, we need to save the options ourselves */
+ options = demo->options;
+#if 0
+ options = gtk_print_settings_get_int_with_default (settings,
+ PGD_PRINT_OPTIONS,
+ PRINT_DOCUMENT_MARKUPS);
+#endif
+ switch (options) {
+ case PRINT_DOCUMENT:
+ flags |= POPPLER_PRINT_DOCUMENT;
+ break;
+ case PRINT_DOCUMENT_MARKUPS:
+ flags |= POPPLER_PRINT_MARKUP_ANNOTS;
+ break;
+ case PRINT_DOCUMENT_STAMPS:
+ flags |= POPPLER_PRINT_STAMP_ANNOTS_ONLY;
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
cr = gtk_print_context_get_cairo_context (context);
- poppler_page_render_for_printing (page, cr);
+ poppler_page_render_for_printing_with_options (page, cr, flags);
g_object_unref (page);
}
+static GObject *
+pgd_print_create_custom_widget (GtkPrintOperation *op,
+ PgdPrintDemo *demo)
+{
+ GtkWidget *hbox;
+ GtkWidget *label, *combo;
+ GtkPrintSettings *settings;
+ PgdPrintOptions options;
+
+ settings = gtk_print_operation_get_print_settings (op);
+ options = gtk_print_settings_get_int_with_default (settings,
+ PGD_PRINT_OPTIONS,
+ PRINT_DOCUMENT_MARKUPS);
+
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
+
+ label = gtk_label_new ("Print: ");
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ gtk_widget_show (label);
+
+ combo = gtk_combo_box_new_text ();
+ demo->options_combo = combo;
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "Document");
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "Document and markup");
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "Document and stamps");
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), options);
+ gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0);
+ gtk_widget_show (combo);
+
+ return G_OBJECT (hbox);
+}
+
+static void
+pgd_print_custom_widget_apply (GtkPrintOperation *op,
+ GtkWidget *widget,
+ PgdPrintDemo *demo)
+{
+ GtkPrintSettings *settings;
+ PgdPrintOptions options;
+
+ settings = gtk_print_operation_get_print_settings (op);
+ options = gtk_combo_box_get_active (GTK_COMBO_BOX (demo->options_combo));
+ /* Workaround for gtk+ bug, we need to save the options ourselves */
+ demo->options = options;
+ gtk_print_settings_set_int (settings, PGD_PRINT_OPTIONS, options);
+}
+
static void
pgd_print_print (GtkWidget *button,
PgdPrintDemo *demo)
@@ -73,12 +156,19 @@ pgd_print_print (GtkWidget *button,
GError *error = NULL;
op = gtk_print_operation_new ();
+ gtk_print_operation_set_custom_tab_label (op, "PDF Options");
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);
+ g_signal_connect (op, "create_custom_widget",
+ G_CALLBACK (pgd_print_create_custom_widget),
+ demo);
+ g_signal_connect (op, "custom_widget_apply",
+ G_CALLBACK (pgd_print_custom_widget_apply),
+ demo);
gtk_print_operation_run (op,
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
GTK_WINDOW (gtk_widget_get_toplevel (button)),
commit 4a71dcdd350d0c0515ca349f0b875b33289d25ee
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date: Sun Oct 17 12:31:41 2010 +0200
[glib] Add poppler_page_render_for_printing_with_options()
It allows to print with the same options acroread has:
- Print document
- Print document and markup
- Print document and stamps
diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc
index 0e5de5c..4e2bef5 100644
--- a/glib/poppler-page.cc
+++ b/glib/poppler-page.cc
@@ -327,18 +327,55 @@ copy_cairo_surface_to_pixbuf (cairo_surface_t *surface,
}
#endif /* POPPLER_WITH_GDK */
+static gboolean
+annot_is_markup (Annot *annot)
+{
+ switch (annot->getType())
+ {
+ case Annot::typeLink:
+ case Annot::typePopup:
+ case Annot::typeMovie:
+ case Annot::typeScreen:
+ case Annot::typePrinterMark:
+ case Annot::typeTrapNet:
+ case Annot::typeWatermark:
+ case Annot::type3D:
+ case Annot::typeWidget:
+ return FALSE;
+ default:
+ return TRUE;
+ }
+}
+
static GBool
poppler_print_annot_cb (Annot *annot, void *user_data)
{
- if (annot->getFlags () & Annot::flagPrint)
- return gTrue;
+ PopplerPrintFlags user_print_flags = (PopplerPrintFlags)GPOINTER_TO_INT (user_data);
+
+ if (annot->getFlags () & Annot::flagHidden)
+ return gFalse;
+
+ if (user_print_flags & POPPLER_PRINT_STAMP_ANNOTS_ONLY) {
+ return (annot->getType() == Annot::typeStamp) ?
+ (annot->getFlags () & Annot::flagPrint) :
+ (annot->getType() == Annot::typeWidget);
+ }
+
+ if (user_print_flags & POPPLER_PRINT_MARKUP_ANNOTS) {
+ return annot_is_markup (annot) ?
+ (annot->getFlags () & Annot::flagPrint) :
+ (annot->getType() == Annot::typeWidget);
+ }
+
+ /* Print document only, form fields are always printed */
return (annot->getType() == Annot::typeWidget);
}
static void
-_poppler_page_render (PopplerPage *page,
- cairo_t *cairo,
- GBool printing)
+_poppler_page_render (PopplerPage *page,
+ cairo_t *cairo,
+ GBool printing,
+ PopplerPrintFlags print_flags)
{
CairoOutputDev *output_dev;
@@ -363,7 +400,8 @@ _poppler_page_render (PopplerPage *page,
printing,
page->document->doc->getCatalog (),
NULL, NULL,
- printing ? poppler_print_annot_cb : NULL, NULL);
+ printing ? poppler_print_annot_cb : NULL,
+ printing ? GINT_TO_POINTER ((gint)print_flags) : NULL);
cairo_restore (cairo);
output_dev->setCairo (NULL);
@@ -389,7 +427,28 @@ poppler_page_render (PopplerPage *page,
if (!page->text)
page->text = new TextPage(gFalse);
- _poppler_page_render (page, cairo, gFalse);
+ _poppler_page_render (page, cairo, gFalse, (PopplerPrintFlags)0);
+}
+
+/**
+ * poppler_page_render_for_printing_with_options:
+ * @page: the page to render from
+ * @cairo: cairo context to render to
+ * @options: print options
+ *
+ * Render the page to the given cairo context for printing
+ * with the specified options
+ *
+ * Since: 0.16
+ **/
+void
+poppler_page_render_for_printing_with_options (PopplerPage *page,
+ cairo_t *cairo,
+ PopplerPrintFlags options)
+{
+ g_return_if_fail (POPPLER_IS_PAGE (page));
+
+ _poppler_page_render (page, cairo, gTrue, options);
}
/**
@@ -404,8 +463,8 @@ poppler_page_render_for_printing (PopplerPage *page,
cairo_t *cairo)
{
g_return_if_fail (POPPLER_IS_PAGE (page));
-
- _poppler_page_render (page, cairo, gTrue);
+
+ _poppler_page_render (page, cairo, gTrue, POPPLER_PRINT_ALL);
}
static cairo_surface_t *
diff --git a/glib/poppler-page.h b/glib/poppler-page.h
index e6cf5ee..ceb77af 100644
--- a/glib/poppler-page.h
+++ b/glib/poppler-page.h
@@ -72,6 +72,9 @@ void poppler_page_render (PopplerPage *pa
cairo_t *cairo);
void poppler_page_render_for_printing (PopplerPage *page,
cairo_t *cairo);
+void poppler_page_render_for_printing_with_options (PopplerPage *page,
+ cairo_t *cairo,
+ PopplerPrintFlags options);
cairo_surface_t *poppler_page_get_thumbnail (PopplerPage *page);
void poppler_page_render_selection (PopplerPage *page,
cairo_t *cairo,
diff --git a/glib/poppler.h b/glib/poppler.h
index b9b4fd3..008f5d8 100644
--- a/glib/poppler.h
+++ b/glib/poppler.h
@@ -134,6 +134,25 @@ typedef enum
POPPLER_SELECTION_LINE
} PopplerSelectionStyle;
+/**
+ * PopplerPrintFlags:
+ * @POPPLER_PRINT_DOCUMENT: print main document contents
+ * @POPPLER_PRINT_MARKUP_ANNOTS: print document and markup annotations
+ * @POPPLER_PRINT_STAMP_ANNOTS_ONLY: print doucment and only stamp annotations
+ * @POPPLER_PRINT_ALL: print main document contents and all markup annotations
+ *
+ * Printing flags
+ *
+ * Since: 0.16
+ */
+typedef enum /*< flags >*/
+{
+ POPPLER_PRINT_DOCUMENT = 0,
+ POPPLER_PRINT_MARKUP_ANNOTS = 1 << 0,
+ POPPLER_PRINT_STAMP_ANNOTS_ONLY = 1 << 1,
+ POPPLER_PRINT_ALL = POPPLER_PRINT_MARKUP_ANNOTS
+} PopplerPrintFlags;
+
typedef struct _PopplerDocument PopplerDocument;
typedef struct _PopplerIndexIter PopplerIndexIter;
typedef struct _PopplerFontsIter PopplerFontsIter;
diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt
index 5bc665d..f06b6eb 100644
--- a/glib/reference/poppler-sections.txt
+++ b/glib/reference/poppler-sections.txt
@@ -25,6 +25,7 @@ poppler_page_get_thumbnail
poppler_page_get_thumbnail_pixbuf
poppler_page_render
poppler_page_render_for_printing
+poppler_page_render_for_printing_with_options
poppler_page_render_to_pixbuf
poppler_page_render_to_pixbuf_for_printing
poppler_page_render_to_ps
@@ -324,6 +325,7 @@ PopplerError
PopplerOrientation
PopplerBackend
PopplerColor
+PopplerPrintFlags
poppler_get_backend
poppler_get_version
poppler_date_parse
@@ -336,6 +338,7 @@ POPPLER_TYPE_COLOR
POPPLER_TYPE_BACKEND
POPPLER_TYPE_ERROR
POPPLER_TYPE_ORIENTATION
+POPPLER_TYPE_PRINT_FLAGS
<SUBSECTION Private>
poppler_error_get_type
@@ -343,6 +346,7 @@ poppler_error_quark
poppler_backend_get_type
poppler_color_get_type
poppler_orientation_get_type
+poppler_print_flags_get_type
</SECTION>
<SECTION>
More information about the poppler
mailing list