#include "config.h"
-#ifdef HAVE_POPPLER_FORM_FIELD_BUTTON_GET_BUTTON_TYPE
-#define HAVE_FORMS
-#endif
-
#include <math.h>
#include <string.h>
#include <gtk/gtk.h>
typedef struct {
EvFileExporterFormat format;
- gboolean landscape;
-
/* Pages per sheet */
gint pages_per_sheet;
gint pages_printed;
gint pages_x;
gint pages_y;
- gdouble page_width;
- gdouble page_height;
+ gdouble paper_width;
+ gdouble paper_height;
#ifdef HAVE_CAIRO_PRINT
cairo_t *cr;
static void pdf_document_search_free (PdfDocumentSearch *search);
static void pdf_print_context_free (PdfPrintContext *ctx);
-#ifdef HAVE_FORMS
G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT,
{
G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_TRANSITION,
pdf_document_page_transition_iface_init);
});
-#else /* !HAVE_FORMS */
-G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT,
- {
- G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
- pdf_document_document_iface_init);
- G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_SECURITY,
- pdf_document_security_iface_init);
- G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
- pdf_document_document_thumbnails_iface_init);
- G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LINKS,
- pdf_document_document_links_iface_init);
- G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_IMAGES,
- pdf_document_document_images_iface_init);
- G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FONTS,
- pdf_document_document_fonts_iface_init);
- G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND,
- pdf_document_find_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);
- });
-#endif /* HAVE_FORMS */
static void
set_rc_data (PdfDocument *pdf_document,
break;
}
- if (!link) {
+ if (!link || strlen (ev_link_get_title (link)) <= 0) {
poppler_action_free (action);
+ if (link)
+ g_object_unref (link);
+
continue;
}
PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
PdfPrintContext *ctx;
gdouble width, height;
- gboolean landscape, change_orient = FALSE;
#ifdef HAVE_CAIRO_PRINT
cairo_surface_t *surface = NULL;
#endif
ctx->format = fc->format;
ctx->pages_per_sheet = fc->pages_per_sheet;
- landscape = (fc->orientation == EV_FILE_EXPORTER_LANDSCAPE);
- change_orient = landscape;
+ ctx->paper_width = fc->paper_width;
+ ctx->paper_height = fc->paper_height;
switch (fc->pages_per_sheet) {
default:
ctx->pages_y = 1;
break;
case 2:
- landscape = !landscape;
ctx->pages_x = 1;
ctx->pages_y = 2;
break;
ctx->pages_y = 2;
break;
case 6:
- landscape = !landscape;
ctx->pages_x = 2;
ctx->pages_y = 3;
break;
break;
}
- ctx->landscape = landscape;
-
- if (change_orient) {
- width = fc->paper_height;
- height = fc->paper_width;
- } else {
- width = fc->paper_width;
- height = fc->paper_height;
- }
-
- if (landscape) {
- gint tmp;
-
- tmp = ctx->pages_x;
- ctx->pages_x = ctx->pages_y;
- ctx->pages_y = tmp;
-
- ctx->page_width = height / ctx->pages_x;
- ctx->page_height = width / ctx->pages_y;
- } else {
- ctx->page_width = width / ctx->pages_x;
- ctx->page_height = height / ctx->pages_y;
- }
-
ctx->pages_printed = 0;
switch (fc->format) {
case EV_FILE_FORMAT_PS:
#ifdef HAVE_CAIRO_PS
- surface = cairo_ps_surface_create (fc->filename, width, height);
+ surface = cairo_ps_surface_create (fc->filename, fc->paper_width, fc->paper_height);
#else
ctx->ps_file = poppler_ps_file_new (pdf_document->document,
fc->filename, fc->first_page,
break;
case EV_FILE_FORMAT_PDF:
#ifdef HAVE_CAIRO_PDF
- surface = cairo_pdf_surface_create (fc->filename, width, height);
+ surface = cairo_pdf_surface_create (fc->filename, fc->paper_width, fc->paper_height);
#endif
break;
default:
#ifdef HAVE_CAIRO_PRINT
ctx->cr = cairo_create (surface);
- if (landscape) {
- cairo_matrix_t matrix;
-
- cairo_translate (ctx->cr, width, 0);
- cairo_matrix_init (&matrix,
- 0, 1,
- -1, 0,
- 0, 0);
- cairo_transform (ctx->cr, &matrix);
- }
cairo_surface_destroy (surface);
#endif
}
PdfPrintContext *ctx = pdf_document->print_ctx;
PopplerPage *poppler_page;
#ifdef HAVE_CAIRO_PRINT
- gdouble page_width, page_height;
- gint x, y;
+ gdouble page_width, page_height;
+ gint x, y;
+ gboolean rotate, landscape;
+ gdouble width, height;
+ gdouble pwidth, pheight;
+ gdouble xscale, yscale;
#endif
g_return_if_fail (pdf_document->print_ctx != NULL);
x = (ctx->pages_printed % ctx->pages_per_sheet) % ctx->pages_x;
y = (ctx->pages_printed % ctx->pages_per_sheet) / ctx->pages_x;
poppler_page_get_size (poppler_page, &page_width, &page_height);
-
- cairo_save (ctx->cr);
- cairo_translate (ctx->cr,
- x * ctx->page_width,
- y * ctx->page_height);
- if (ctx->landscape) {
- cairo_scale (ctx->cr,
- ctx->page_height / page_height,
- ctx->page_height / page_height);
+
+ if (page_width > page_height && page_width > ctx->paper_width) {
+ rotate = TRUE;
} else {
- cairo_scale (ctx->cr,
- ctx->page_width / page_width,
- ctx->page_height / page_height);
+ rotate = FALSE;
+ }
+
+ landscape = (ctx->paper_width > ctx->paper_height);
+
+ /* Use always portrait mode and rotate when necessary */
+ if (ctx->paper_width > ctx->paper_height) {
+ width = ctx->paper_height;
+ height = ctx->paper_width;
+ rotate = !rotate;
+
+ cairo_ps_surface_set_size (cairo_get_target (ctx->cr),
+ width, height);
+ } else {
+ width = ctx->paper_width;
+ height = ctx->paper_height;
+ }
+
+ if (ctx->pages_per_sheet == 2 || ctx->pages_per_sheet == 6) {
+ rotate = !rotate;
+ }
+
+ if (rotate) {
+ gint tmp1;
+ gdouble tmp2;
+
+ tmp1 = x;
+ x = y;
+ y = tmp1;
+
+ tmp2 = page_width;
+ page_width = page_height;
+ page_height = tmp2;
+
+ }
+
+ pwidth = width / ctx->pages_x;
+ pheight = height / ctx->pages_y;
+
+ if ((page_width > pwidth || page_height > pheight) ||
+ (page_width < pwidth && page_height < pheight)) {
+ xscale = pwidth / page_width;
+ yscale = pheight / page_height;
+
+ if (yscale < xscale) {
+ xscale = yscale;
+ } else {
+ yscale = xscale;
+ }
+
+ } else {
+ xscale = yscale = 1;
}
+ /* TODO: center */
+
+ cairo_save (ctx->cr);
+ if (rotate) {
+ cairo_matrix_t matrix;
+
+ cairo_translate (ctx->cr, width, 0);
+ cairo_matrix_init (&matrix,
+ 0, 1,
+ -1, 0,
+ 0, 0);
+ cairo_transform (ctx->cr, &matrix);
+ }
+
+ cairo_translate (ctx->cr,
+ x * (rotate ? pheight : pwidth),
+ y * (rotate ? pwidth : pheight));
+ cairo_scale (ctx->cr, xscale, yscale);
+
#ifdef HAVE_POPPLER_PAGE_RENDER
poppler_page_render (poppler_page, ctx->cr);
#endif
rect->y2 = poppler_rect.y2;
}
-#ifdef HAVE_FORMS
static EvFormField *
ev_form_field_from_poppler_field (PopplerFormField *poppler_field)
{
field_text->do_scroll = poppler_form_field_text_do_scroll (poppler_field);
field_text->is_rich_text = poppler_form_field_text_is_rich_text (poppler_field);
field_text->is_password = poppler_form_field_text_is_password (poppler_field);
-
-#ifdef HAVE_POPPLER_FORM_FIELD_TEXT_GET_MAX_LEN
field_text->max_len = poppler_form_field_text_get_max_len (poppler_field);
-#endif
field_text->text = poppler_form_field_text_get_text (poppler_field);
}
iface->form_field_choice_set_text = pdf_document_forms_form_field_choice_set_text;
iface->form_field_choice_get_text = pdf_document_forms_form_field_choice_get_text;
}
-#endif /* HAVE_FORMS */
+