* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+#include "config.h"
+
#include <math.h>
#include <string.h>
#include <gtk/gtk.h>
#include <poppler.h>
#include <poppler-document.h>
#include <poppler-page.h>
+#ifdef HAVE_CAIRO_PDF
+#include <cairo-pdf.h>
+#endif
#include <glib/gi18n.h>
#include "ev-poppler.h"
-#include "ev-ps-exporter.h"
+#include "ev-file-exporter.h"
#include "ev-document-find.h"
#include "ev-document-misc.h"
#include "ev-document-links.h"
#include "ev-document-fonts.h"
#include "ev-document-security.h"
#include "ev-document-thumbnails.h"
+#include "ev-document-transition.h"
#include "ev-selection.h"
#include "ev-attachment.h"
int search_page;
} PdfDocumentSearch;
+typedef struct {
+ EvFileExporterFormat format;
+ PopplerPSFile *ps_file;
+#ifdef HAVE_CAIRO_PDF
+ cairo_t *pdf_cairo;
+#endif
+} PdfPrintContext;
+
struct _PdfDocumentClass
{
GObjectClass parent_class;
GObject parent_instance;
PopplerDocument *document;
- PopplerPSFile *ps_file;
gchar *password;
PopplerFontInfo *font_info;
int fonts_scanned_pages;
PdfDocumentSearch *search;
+ PdfPrintContext *print_ctx;
};
static void pdf_document_document_iface_init (EvDocumentIface *iface);
static void pdf_document_document_links_iface_init (EvDocumentLinksIface *iface);
static void pdf_document_document_fonts_iface_init (EvDocumentFontsIface *iface);
static void pdf_document_find_iface_init (EvDocumentFindIface *iface);
-static void pdf_document_ps_exporter_iface_init (EvPSExporterIface *iface);
+static void pdf_document_file_exporter_iface_init (EvFileExporterIface *iface);
static void pdf_selection_iface_init (EvSelectionIface *iface);
+static void pdf_document_page_transition_iface_init (EvDocumentTransitionIface *iface);
static void pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
gint page,
gint size,
static EvLink *ev_link_from_action (PdfDocument *pdf_document,
PopplerAction *action);
static void pdf_document_search_free (PdfDocumentSearch *search);
+static void pdf_print_context_free (PdfPrintContext *ctx);
G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT,
pdf_document_document_fonts_iface_init);
G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND,
pdf_document_find_iface_init);
- G_IMPLEMENT_INTERFACE (EV_TYPE_PS_EXPORTER,
- pdf_document_ps_exporter_iface_init);
+ G_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER,
+ pdf_document_file_exporter_iface_init);
G_IMPLEMENT_INTERFACE (EV_TYPE_SELECTION,
pdf_selection_iface_init);
+ G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_TRANSITION,
+ pdf_document_page_transition_iface_init);
});
{
PdfDocument *pdf_document = PDF_DOCUMENT(object);
+ if (pdf_document->print_ctx) {
+ pdf_print_context_free (pdf_document->print_ctx);
+ pdf_document->print_ctx = NULL;
+ }
+
if (pdf_document->search) {
pdf_document_search_free (pdf_document->search);
pdf_document->search = NULL;
EV_DOCUMENT_INFO_MOD_DATE |
EV_DOCUMENT_INFO_LINEARIZED |
EV_DOCUMENT_INFO_N_PAGES |
- EV_DOCUMENT_INFO_SECURITY;
-
+ EV_DOCUMENT_INFO_SECURITY |
+ EV_DOCUMENT_INFO_PAPER_SIZE;
g_object_get (PDF_DOCUMENT (document)->document,
"title", &(info->title),
"linearized", &(info->linearized),
NULL);
+ pdf_document_get_page_size(document, 0,
+ &(info->paper_width),
+ &(info->paper_height));
+
+ // Convert to mm.
+ info->paper_width = info->paper_width / 72.0f * 25.4f;
+ info->paper_height = info->paper_height / 72.0f * 25.4f;
+
switch (layout) {
case POPPLER_PAGE_LAYOUT_SINGLE_PAGE:
info->layout = EV_DOCUMENT_LAYOUT_SINGLE_PAGE;
width, height);
gdk_pixbuf_fill (pixbuf, 0xffffffff);
+ ev_document_fc_mutex_lock ();
poppler_page_render_to_pixbuf (poppler_page, 0, 0,
width, height,
scale, rotation, pixbuf);
+ ev_document_fc_mutex_unlock ();
g_object_unref (poppler_page);
search_string);
}
-int
+static int
pdf_document_find_get_n_results (EvDocumentFind *document_find, int page)
{
PdfDocumentSearch *search = PDF_DOCUMENT (document_find)->search;
}
}
-gboolean
+static gboolean
pdf_document_find_get_result (EvDocumentFind *document_find,
int page,
int n_result,
return TRUE;
}
-int
+static int
pdf_document_find_page_has_results (EvDocumentFind *document_find,
int page)
{
return search && search->pages[page] != NULL;
}
-double
+static double
pdf_document_find_get_progress (EvDocumentFind *document_find)
{
PdfDocumentSearch *search;
iface->cancel = pdf_document_find_cancel;
}
+static const gboolean supported_formats[] = {
+ TRUE, /* EV_FILE_FORMAT_PS */
+#ifdef HAVE_CAIRO_PDF
+#ifdef HAVE_POPPLER_PAGE_RENDER
+ TRUE, /* EV_FILE_FORMAT_PDF */
+#else
+ FALSE, /* EV_FILE_FORMAT_PDF */
+#endif
+#endif
+};
+
static void
-pdf_document_ps_exporter_begin (EvPSExporter *exporter, const char *filename,
- int first_page, int last_page,
- double width, double height, gboolean duplex)
+pdf_print_context_free (PdfPrintContext *ctx)
+{
+ if (!ctx)
+ return;
+
+ if (ctx->ps_file) {
+ poppler_ps_file_free (ctx->ps_file);
+ ctx->ps_file = NULL;
+ }
+#ifdef HAVE_CAIRO_PDF
+ if (ctx->pdf_cairo) {
+ cairo_destroy (ctx->pdf_cairo);
+ ctx->pdf_cairo = NULL;
+ }
+#endif
+ g_free (ctx);
+}
+
+static gboolean
+pdf_document_file_exporter_format_supported (EvFileExporter *exporter,
+ EvFileExporterFormat format)
+{
+ return supported_formats[format];
+}
+
+static void
+pdf_document_file_exporter_begin (EvFileExporter *exporter,
+ EvFileExporterFormat format,
+ const char *filename,
+ int first_page,
+ int last_page,
+ double width,
+ double height,
+ gboolean duplex)
{
PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
+ PdfPrintContext *ctx;
+
+ if (pdf_document->print_ctx)
+ pdf_print_context_free (pdf_document->print_ctx);
+ pdf_document->print_ctx = g_new0 (PdfPrintContext, 1);
+ ctx = pdf_document->print_ctx;
+ ctx->format = format;
- pdf_document->ps_file = poppler_ps_file_new (pdf_document->document, filename,
- first_page,
- last_page - first_page + 1);
- poppler_ps_file_set_paper_size (pdf_document->ps_file, width, height);
- poppler_ps_file_set_duplex (pdf_document->ps_file, duplex);
+ switch (format) {
+ case EV_FILE_FORMAT_PS:
+ ctx->ps_file = poppler_ps_file_new (pdf_document->document,
+ filename, first_page,
+ last_page - first_page + 1);
+ poppler_ps_file_set_paper_size (ctx->ps_file, width, height);
+ poppler_ps_file_set_duplex (ctx->ps_file, duplex);
+
+ break;
+ case EV_FILE_FORMAT_PDF: {
+#ifdef HAVE_CAIRO_PDF
+ cairo_surface_t *surface;
+
+ surface = cairo_pdf_surface_create (filename, width, height);
+ ctx->pdf_cairo = cairo_create (surface);
+ cairo_surface_destroy (surface);
+#endif
+ }
+ break;
+ default:
+ g_assert_not_reached ();
+ }
}
static void
-pdf_document_ps_exporter_do_page (EvPSExporter *exporter, EvRenderContext *rc)
+pdf_document_file_exporter_do_page (EvFileExporter *exporter, EvRenderContext *rc)
{
PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
+ PdfPrintContext *ctx = pdf_document->print_ctx;
PopplerPage *poppler_page;
- g_return_if_fail (pdf_document->ps_file != NULL);
+ g_return_if_fail (pdf_document->print_ctx != NULL);
poppler_page = poppler_document_get_page (pdf_document->document, rc->page);
- poppler_page_render_to_ps (poppler_page, pdf_document->ps_file);
+
+ switch (ctx->format) {
+ case EV_FILE_FORMAT_PS:
+ poppler_page_render_to_ps (poppler_page, ctx->ps_file);
+ break;
+ case EV_FILE_FORMAT_PDF:
+#ifdef HAVE_POPPLER_PAGE_RENDER
+ poppler_page_render (poppler_page, ctx->pdf_cairo);
+#endif
+#ifdef HAVE_CAIRO_PDF
+ cairo_show_page (ctx->pdf_cairo);
+#endif
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
g_object_unref (poppler_page);
}
static void
-pdf_document_ps_exporter_end (EvPSExporter *exporter)
+pdf_document_file_exporter_end (EvFileExporter *exporter)
{
PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
- poppler_ps_file_free (pdf_document->ps_file);
- pdf_document->ps_file = NULL;
+ pdf_print_context_free (pdf_document->print_ctx);
+ pdf_document->print_ctx = NULL;
}
static void
-pdf_document_ps_exporter_iface_init (EvPSExporterIface *iface)
+pdf_document_file_exporter_iface_init (EvFileExporterIface *iface)
{
- iface->begin = pdf_document_ps_exporter_begin;
- iface->do_page = pdf_document_ps_exporter_do_page;
- iface->end = pdf_document_ps_exporter_end;
+ iface->format_supported = pdf_document_file_exporter_format_supported;
+ iface->begin = pdf_document_file_exporter_begin;
+ iface->do_page = pdf_document_file_exporter_do_page;
+ iface->end = pdf_document_file_exporter_end;
}
-
-void
+static void
pdf_selection_render_selection (EvSelection *selection,
EvRenderContext *rc,
GdkPixbuf **pixbuf,
}
-GdkRegion *
+static GdkRegion *
pdf_selection_get_selection_region (EvSelection *selection,
EvRenderContext *rc,
EvRectangle *points)
return retval;
}
-GdkRegion *
+static GdkRegion *
pdf_selection_get_selection_map (EvSelection *selection,
EvRenderContext *rc)
{
iface->get_selection_map = pdf_selection_get_selection_map;
}
+/* Page Transitions */
+static gdouble
+pdf_document_get_page_duration (EvDocumentTransition *trans,
+ gint page)
+{
+#ifdef HAVE_POPPLER_PAGE_GET_DURATION
+ PdfDocument *pdf_document;
+ PopplerPage *poppler_page;
+ gdouble duration = -1;
+
+ pdf_document = PDF_DOCUMENT (trans);
+ poppler_page = poppler_document_get_page (pdf_document->document, page);
+ if (!poppler_page)
+ return -1;
+
+ duration = poppler_page_get_duration (poppler_page);
+ g_object_unref (poppler_page);
+
+ return duration;
+#else
+ return -1;
+#endif /* HAVE_POPPLER_PAGE_GET_DURATION */
+}
+
+static void
+pdf_document_page_transition_iface_init (EvDocumentTransitionIface *iface)
+{
+ iface->get_page_duration = pdf_document_get_page_duration;
+}
+
PdfDocument *
pdf_document_new (void)
{