PopplerPSFile *ps_file;
gchar *password;
- PopplerOrientation orientation;
- gboolean orientation_set;
-
PopplerFontInfo *font_info;
PopplerFontsIter *fonts_iter;
int fonts_scanned_pages;
pdf_selection_iface_init);
});
+
+static void
+set_rc_data (PdfDocument *pdf_document,
+ EvRenderContext *rc)
+{
+ if (rc->data == NULL) {
+ rc->data = poppler_document_get_page (pdf_document->document,
+ rc->page);
+ rc->destroy = g_object_unref;
+ } else {
+ g_assert (rc->page == poppler_page_get_index (POPPLER_PAGE (rc->data)));
+ }
+}
+
static void
pdf_document_search_free (PdfDocumentSearch *search)
{
return retval;
}
-static PopplerOrientation
-get_document_orientation (PdfDocument *pdf_document)
-{
- PopplerOrientation orientation;
- PopplerPage *page;
-
- /* Should prolly be smarter here and check more than first page */
- page = poppler_document_get_page (pdf_document->document, 0);
- if (page) {
- orientation = poppler_page_get_orientation (page);
- } else {
- orientation = POPPLER_ORIENTATION_PORTRAIT;
- }
- g_object_unref (page);
-
- return orientation;
-}
-
static gboolean
pdf_document_load (EvDocument *document,
const char *uri,
return poppler_document_get_n_pages (PDF_DOCUMENT (document)->document);
}
-/* FIXME This should not be necessary, poppler should rember it */
-static void
-set_page_orientation (PdfDocument *pdf_document, PopplerPage *page)
-{
- if (pdf_document->orientation_set) {
- poppler_page_set_orientation (page, pdf_document->orientation);
- }
-}
-
static void
pdf_document_get_page_size (EvDocument *document,
int page,
PopplerPage *poppler_page;
poppler_page = poppler_document_get_page (pdf_document->document, page);
- set_page_orientation (pdf_document, poppler_page);
poppler_page_get_size (poppler_page, width, height);
g_object_unref (poppler_page);
}
EvRenderContext *rc)
{
PdfDocument *pdf_document;
- PopplerPage *poppler_page;
GdkPixbuf *pixbuf;
double width_points, height_points;
gint width, height;
pdf_document = PDF_DOCUMENT (document);
- poppler_page = poppler_document_get_page (pdf_document->document,
- rc->page);
- set_page_orientation (pdf_document, poppler_page);
- poppler_page_get_size (poppler_page, &width_points, &height_points);
- width = (int) ((width_points * rc->scale) + 0.5);
- height = (int) ((height_points * rc->scale) + 0.5);
+ set_rc_data (pdf_document, rc);
+
+ poppler_page_get_size (POPPLER_PAGE (rc->data), &width_points, &height_points);
+
+ if (rc->rotation == 90 || rc->rotation == 270) {
+ width = (int) ((height_points * rc->scale) + 0.5);
+ height = (int) ((width_points * rc->scale) + 0.5);
+ } else {
+ width = (int) ((width_points * rc->scale) + 0.5);
+ height = (int) ((height_points * rc->scale) + 0.5);
+ }
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
FALSE, 8,
width, height);
- poppler_page_render_to_pixbuf (poppler_page,
+ poppler_page_render_to_pixbuf (POPPLER_PAGE (rc->data),
0, 0,
width, height,
rc->scale,
+ rc->rotation,
pixbuf);
- g_object_unref (poppler_page);
return pixbuf;
}
char *text;
poppler_page = poppler_document_get_page (pdf_document->document, page);
- set_page_orientation (pdf_document, poppler_page);
g_return_val_if_fail (poppler_page != NULL, NULL);
poppler_page_get_size (poppler_page, NULL, &height);
return text;
}
-static EvOrientation
-pdf_document_get_orientation (EvDocument *document)
-{
- EvOrientation result;
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
-
- if (!pdf_document->orientation_set) {
- pdf_document->orientation = get_document_orientation (pdf_document);
- }
-
- switch (pdf_document->orientation) {
- case POPPLER_ORIENTATION_PORTRAIT:
- result = EV_ORIENTATION_PORTRAIT;
- break;
- case POPPLER_ORIENTATION_LANDSCAPE:
- result = EV_ORIENTATION_LANDSCAPE;
- break;
- case POPPLER_ORIENTATION_UPSIDEDOWN:
- result = EV_ORIENTATION_UPSIDEDOWN;
- break;
- case POPPLER_ORIENTATION_SEASCAPE:
- result = EV_ORIENTATION_SEASCAPE;
- break;
- default:
- g_assert_not_reached ();
- }
-
- return result;
-}
-
-static void
-pdf_document_set_orientation (EvDocument *document, EvOrientation orientation)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
- PopplerOrientation poppler_orientation;
-
- switch (orientation) {
- case EV_ORIENTATION_PORTRAIT:
- poppler_orientation = POPPLER_ORIENTATION_PORTRAIT;
- break;
- case EV_ORIENTATION_LANDSCAPE:
- poppler_orientation = POPPLER_ORIENTATION_LANDSCAPE;
- break;
- case EV_ORIENTATION_UPSIDEDOWN:
- poppler_orientation = POPPLER_ORIENTATION_UPSIDEDOWN;
- break;
- case EV_ORIENTATION_SEASCAPE:
- poppler_orientation = POPPLER_ORIENTATION_SEASCAPE;
- break;
- default:
- g_assert_not_reached ();
- }
-
- pdf_document->orientation = poppler_orientation;
- pdf_document->orientation_set = TRUE;
-}
-
static void
pdf_document_document_iface_init (EvDocumentIface *iface)
{
iface->get_text = pdf_document_get_text;
iface->can_get_text = pdf_document_can_get_text;
iface->get_info = pdf_document_get_info;
- iface->set_orientation = pdf_document_set_orientation;
- iface->get_orientation = pdf_document_get_orientation;
};
static void
case POPPLER_FONT_TYPE_CID_TYPE2:
return _("TrueType (CID)");
default:
- return _("Unknown font type ");
+ return _("Unknown font type");
}
}
}
static GdkPixbuf *
-make_thumbnail_for_size (PdfDocument *pdf_document,
- gint page,
- gint size,
- gboolean border)
+make_thumbnail_for_size (PdfDocument *pdf_document,
+ gint page,
+ int rotation,
+ gint size,
+ gboolean border)
{
PopplerPage *poppler_page;
GdkPixbuf *pixbuf, *sub_pixbuf;
gdouble unscaled_width, unscaled_height;
poppler_page = poppler_document_get_page (pdf_document->document, page);
- set_page_orientation (pdf_document, poppler_page);
g_return_val_if_fail (poppler_page != NULL, NULL);
- pdf_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (pdf_document), page, size, &width, &height);
+ pdf_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (pdf_document), page,
+ size, &width, &height);
poppler_page_get_size (poppler_page, &unscaled_width, &unscaled_height);
scale = width / unscaled_width;
poppler_page_render_to_pixbuf (poppler_page, 0, 0,
width, height,
- scale, sub_pixbuf);
+ scale, rotation, sub_pixbuf);
g_object_unref (G_OBJECT (sub_pixbuf));
static GdkPixbuf *
pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
gint page,
+ gint rotation,
gint size,
gboolean border)
{
pdf_document = PDF_DOCUMENT (document_thumbnails);
poppler_page = poppler_document_get_page (pdf_document->document, page);
- set_page_orientation (pdf_document, poppler_page);
g_return_val_if_fail (poppler_page != NULL, NULL);
pixbuf = poppler_page_get_thumbnail (poppler_page);
}
} else {
/* There is no provided thumbnail. We need to make one. */
- pixbuf = make_thumbnail_for_size (pdf_document, page, size, border);
+ pixbuf = make_thumbnail_for_size (pdf_document, page, rotation, size, border);
}
g_object_unref (poppler_page);
pdf_document = PDF_DOCUMENT (document_thumbnails);
poppler_page = poppler_document_get_page (pdf_document->document, page);
- set_page_orientation (pdf_document, poppler_page);
g_return_if_fail (width != NULL);
g_return_if_fail (height != NULL);
page = poppler_document_get_page (search->document->document,
search->search_page);
- set_page_orientation (pdf_document, page);
ev_document_doc_mutex_lock ();
matches = poppler_page_find_text (page, search->text);
return FALSE;
poppler_page = poppler_document_get_page (pdf_document->document, page);
- set_page_orientation (pdf_document, poppler_page);
poppler_page_get_size (poppler_page, NULL, &height);
rectangle->x1 = r->x1;
rectangle->y1 = height - r->y2;
static void
pdf_document_ps_exporter_begin (EvPSExporter *exporter, const char *filename,
- int first_page, int last_page)
+ int first_page, int last_page,
+ double width, double height, gboolean duplex)
{
PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
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);
}
static void
-pdf_document_ps_exporter_do_page (EvPSExporter *exporter, int page)
+pdf_document_ps_exporter_do_page (EvPSExporter *exporter, EvRenderContext *rc)
{
PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
PopplerPage *poppler_page;
g_return_if_fail (pdf_document->ps_file != NULL);
- poppler_page = poppler_document_get_page (pdf_document->document, page);
- set_page_orientation (pdf_document, poppler_page);
+ poppler_page = poppler_document_get_page (pdf_document->document, rc->page);
poppler_page_render_to_ps (poppler_page, pdf_document->ps_file);
g_object_unref (poppler_page);
}
EvRenderContext *rc,
GdkPixbuf **pixbuf,
EvRectangle *points,
- EvRectangle *old_points)
+ EvRectangle *old_points,
+ GdkColor *text,
+ GdkColor *base)
{
PdfDocument *pdf_document;
- PopplerPage *poppler_page;
double width_points, height_points;
gint width, height;
pdf_document = PDF_DOCUMENT (selection);
- poppler_page = poppler_document_get_page (pdf_document->document,
- rc->page);
- set_page_orientation (pdf_document, poppler_page);
+ set_rc_data (pdf_document, rc);
- poppler_page_get_size (poppler_page, &width_points, &height_points);
+ poppler_page_get_size (POPPLER_PAGE (rc->data), &width_points, &height_points);
width = (int) ((width_points * rc->scale) + 0.5);
height = (int) ((height_points * rc->scale) + 0.5);
width, height);
}
- poppler_page_render_selection (poppler_page,
+ poppler_page_render_selection (POPPLER_PAGE (rc->data),
rc->scale, *pixbuf,
(PopplerRectangle *)points,
- (PopplerRectangle *)old_points);
- g_object_unref (poppler_page);
-
+ (PopplerRectangle *)old_points,
+ text,
+ base);
}
EvRectangle *points)
{
PdfDocument *pdf_document;
- PopplerPage *poppler_page;
GdkRegion *retval;
pdf_document = PDF_DOCUMENT (selection);
- poppler_page = poppler_document_get_page (pdf_document->document,
- rc->page);
- set_page_orientation (pdf_document, poppler_page);
- retval = poppler_page_get_selection_region (poppler_page, rc->scale, (PopplerRectangle *) points);
- g_object_unref (poppler_page);
+ set_rc_data (pdf_document, rc);
+
+ retval = poppler_page_get_selection_region ((PopplerPage *)rc->data, rc->scale, (PopplerRectangle *) points);
return retval;
}
pdf_document = PDF_DOCUMENT (selection);
poppler_page = poppler_document_get_page (pdf_document->document,
rc->page);
- set_page_orientation (pdf_document, poppler_page);
points.x1 = 0.0;
points.y1 = 0.0;