#include "djvu-links.h"
#include "djvu-document-private.h"
#include "ev-document-thumbnails.h"
+#include "ev-file-exporter.h"
#include "ev-document-misc.h"
#include "ev-document-find.h"
#include "ev-document-links.h"
static void djvu_document_document_iface_init (EvDocumentIface *iface);
static void djvu_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
+static void djvu_document_file_exporter_iface_init (EvFileExporterIface *iface);
static void djvu_document_find_iface_init (EvDocumentFindIface *iface);
static void djvu_document_document_links_iface_init (EvDocumentLinksIface *iface);
(DjvuDocument, djvu_document, G_TYPE_OBJECT,
{
G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, djvu_document_document_iface_init);
- G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, djvu_document_document_thumbnails_iface_init)
+ G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, djvu_document_document_thumbnails_iface_init);
+ G_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER, djvu_document_file_exporter_iface_init);
G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND, djvu_document_find_iface_init);
G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LINKS, djvu_document_document_links_iface_init);
});
if (djvu_document->d_document)
ddjvu_document_release (djvu_document->d_document);
+
+ if (djvu_document->opts)
+ g_string_free (djvu_document->opts, TRUE);
+ if (djvu_document->ps_filename)
+ g_free (djvu_document->ps_filename);
+
ddjvu_context_release (djvu_document->d_context);
ddjvu_format_release (djvu_document->d_format);
g_free (djvu_document->uri);
static void
djvu_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
- gint page,
- gint suggested_width,
- gint *width,
- gint *height)
+ EvRenderContext *rc,
+ gint *width,
+ gint *height)
{
DjvuDocument *djvu_document = DJVU_DOCUMENT (document);
- gdouble p_width, p_height;
- gdouble page_ratio;
+ gdouble page_width, page_height;
- djvu_document_get_page_size (EV_DOCUMENT(djvu_document), page, &p_width, &p_height);
+ djvu_document_get_page_size (EV_DOCUMENT(djvu_document), rc->page,
+ &page_width, &page_height);
- page_ratio = p_height / p_width;
- *width = suggested_width;
- *height = (gint) (suggested_width * page_ratio);
-
- return;
+ if (rc->rotation == 90 || rc->rotation == 270) {
+ *width = (gint) (page_height * rc->scale);
+ *height = (gint) (page_width * rc->scale);
+ } else {
+ *width = (gint) (page_width * rc->scale);
+ *height = (gint) (page_height * rc->scale);
+ }
}
static GdkPixbuf *
-djvu_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
- gint page,
- gint rotation,
- gint width,
- gboolean border)
+djvu_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
+ EvRenderContext *rc,
+ gboolean border)
{
DjvuDocument *djvu_document = DJVU_DOCUMENT (document);
GdkPixbuf *pixbuf, *rotated_pixbuf;
+ gdouble page_width, page_height;
gint thumb_width, thumb_height;
-
guchar *pixels;
g_return_val_if_fail (djvu_document->d_document, NULL);
+
+ djvu_document_get_page_size (EV_DOCUMENT(djvu_document), rc->page,
+ &page_width, &page_height);
- djvu_document_thumbnails_get_dimensions (document, page, width, &thumb_width, &thumb_height);
-
+ thumb_width = (gint) (page_width * rc->scale);
+ thumb_height = (gint) (page_height * rc->scale);
+
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
thumb_width, thumb_height);
gdk_pixbuf_fill (pixbuf, 0xffffffff);
pixels = gdk_pixbuf_get_pixels (pixbuf);
- while (ddjvu_thumbnail_status (djvu_document->d_document, page, 1) < DDJVU_JOB_OK)
+ while (ddjvu_thumbnail_status (djvu_document->d_document, rc->page, 1) < DDJVU_JOB_OK)
djvu_handle_events(djvu_document, TRUE);
- ddjvu_thumbnail_render (djvu_document->d_document, page,
+ ddjvu_thumbnail_render (djvu_document->d_document, rc->page,
&thumb_width, &thumb_height,
djvu_document->d_format,
gdk_pixbuf_get_rowstride (pixbuf),
(gchar *)pixels);
- rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rotation);
+ rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rc->rotation);
g_object_unref (pixbuf);
if (border) {
GdkPixbuf *tmp_pixbuf = rotated_pixbuf;
- rotated_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, 0, tmp_pixbuf);
+
+ rotated_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf);
g_object_unref (tmp_pixbuf);
}
iface->get_dimensions = djvu_document_thumbnails_get_dimensions;
}
+/* EvFileExporterIface */
+static gboolean
+djvu_document_file_exporter_format_supported (EvFileExporter *exporter,
+ EvFileExporterFormat format)
+{
+ return (format == EV_FILE_FORMAT_PS); // only exporting to PS is implemented.
+}
+
+static void
+djvu_document_file_exporter_begin (EvFileExporter *exporter,
+ EvFileExporterFormat format,
+ const char *filename, /* for storing the temp ps file */
+ int first_page,
+ int last_page,
+ double width,
+ double height,
+ gboolean duplex)
+{
+ DjvuDocument *djvu_document = DJVU_DOCUMENT (exporter);
+
+ if (djvu_document->ps_filename)
+ g_free (djvu_document->ps_filename);
+ djvu_document->ps_filename = g_strdup(filename);
+
+ g_string_assign(djvu_document->opts, "-page=");
+}
+
+static void
+djvu_document_file_exporter_do_page (EvFileExporter *exporter, EvRenderContext *rc)
+{
+ DjvuDocument *djvu_document = DJVU_DOCUMENT (exporter);
+
+ g_string_append_printf(djvu_document->opts, "%d,", (rc->page) + 1);
+}
+
+static void
+djvu_document_file_exporter_end (EvFileExporter *exporter)
+{
+ int d_optc = 1;
+ const char *d_optv[d_optc];
+
+ DjvuDocument *djvu_document = DJVU_DOCUMENT (exporter);
+
+ FILE *fn = fopen(djvu_document->ps_filename, "w");
+ if (fn == NULL) {
+ g_warning(_("Cannot open file “%s”."), djvu_document->ps_filename);
+ return;
+ }
+
+ d_optv[0] = djvu_document->opts->str;
+
+ ddjvu_job_t * job = ddjvu_document_print(djvu_document->d_document, fn, d_optc, d_optv);
+ while (!ddjvu_job_done(job) ) {
+ djvu_handle_events (djvu_document, TRUE);
+ }
+
+ fclose(fn);
+}
+
+static void
+djvu_document_file_exporter_iface_init (EvFileExporterIface *iface)
+{
+ iface->format_supported = djvu_document_file_exporter_format_supported;
+ iface->begin = djvu_document_file_exporter_begin;
+ iface->do_page = djvu_document_file_exporter_do_page;
+ iface->end = djvu_document_file_exporter_end;
+}
+
static void
djvu_document_init (DjvuDocument *djvu_document)
{
djvu_document->d_context = ddjvu_context_create ("Evince");
djvu_document->d_format = ddjvu_format_create (DDJVU_FORMAT_RGB24, 0, 0);
ddjvu_format_set_row_order (djvu_document->d_format,1);
+
+ djvu_document->ps_filename = NULL;
+ djvu_document->opts = g_string_new ("");
djvu_document->d_document = NULL;
}