* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+#include "config.h"
+
+#include <config.h>
#include <gtk/gtk.h>
+#include <glib/gi18n.h>
#include <string.h>
+
#include "imposter.h"
#include "impress-document.h"
#include "ev-document-thumbnails.h"
static void impress_document_document_iface_init (EvDocumentIface *iface);
static void impress_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
-G_DEFINE_TYPE_WITH_CODE (ImpressDocument, impress_document, G_TYPE_OBJECT,
- { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
- impress_document_document_iface_init);
+EV_BACKEND_REGISTER_WITH_CODE (ImpressDocument, impress_document,
+ {
G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
impress_document_document_thumbnails_iface_init);
});
filename = g_filename_from_uri (uri, NULL, error);
if (!filename)
{
- //FIXME
- //g_error_set ();
+ g_set_error (error,
+ EV_DOCUMENT_ERROR,
+ EV_DOCUMENT_ERROR_INVALID,
+ _("Remote files aren't supported"));
return FALSE;
}
if (!imp)
{
- //FIXME translate the err, set error
+ g_set_error (error,
+ EV_DOCUMENT_ERROR,
+ EV_DOCUMENT_ERROR_INVALID,
+ _("Invalid document"));
g_free (filename);
return FALSE;
}
g_return_val_if_fail (page != NULL, FALSE);
+ ev_document_doc_mutex_lock ();
imp_context_set_page (impress_document->ctx, page);
imp_render (impress_document->ctx, impress_document);
+ ev_document_doc_mutex_unlock ();
impress_document->pixbuf = gdk_pixbuf_get_from_drawable (NULL,
GDK_DRAWABLE (impress_document->pixmap),
0, 0,
0, 0,
PAGE_WIDTH, PAGE_HEIGHT);
+
g_cond_broadcast (impress_document->cond);
return FALSE;
}
static GdkPixbuf *
-impress_document_render_pixbuf (EvDocument *document,
+impress_document_render_pixbuf (EvDocument *document,
EvRenderContext *rc)
{
ImpressDocument *impress_document = IMPRESS_DOCUMENT (document);
- GdkPixbuf *scaled_pixbuf;
-
- g_return_val_if_fail (IMPRESS_IS_DOCUMENT (document), 0);
- g_return_val_if_fail (impress_document->imp != NULL, 0);
+ GdkPixbuf *pixbuf;
+ g_return_val_if_fail (IMPRESS_IS_DOCUMENT (document), NULL);
+ g_return_val_if_fail (impress_document->imp != NULL, NULL);
+
impress_document->pagenum = rc->page;
g_mutex_lock (impress_document->mutex);
impress_document->cond = g_cond_new ();
+ ev_document_fc_mutex_unlock ();
+ ev_document_doc_mutex_unlock ();
g_idle_add ((GSourceFunc) imp_render_get_from_drawable, impress_document);
-
g_cond_wait (impress_document->cond, impress_document->mutex);
g_cond_free (impress_document->cond);
+ ev_document_doc_mutex_lock ();
+ ev_document_fc_mutex_lock ();
+
g_mutex_unlock (impress_document->mutex);
- scaled_pixbuf = gdk_pixbuf_scale_simple (impress_document->pixbuf,
- PAGE_WIDTH * rc->scale,
- PAGE_HEIGHT * rc->scale,
- GDK_INTERP_BILINEAR);
- gdk_pixbuf_unref (impress_document->pixbuf);
+ pixbuf = impress_document->pixbuf;
impress_document->pixbuf = NULL;
- return scaled_pixbuf;
+ return pixbuf;
+}
+
+static cairo_surface_t *
+impress_document_render (EvDocument *document,
+ EvRenderContext *rc)
+{
+ GdkPixbuf *pixbuf;
+ cairo_surface_t *surface, *scaled_surface;
+
+ pixbuf = impress_document_render_pixbuf (document, rc);
+
+ /* FIXME: impress backend should be ported to cairo */
+ surface = ev_document_misc_surface_from_pixbuf (pixbuf);
+ g_object_unref (pixbuf);
+
+ scaled_surface = ev_document_misc_surface_rotate_and_scale (surface,
+ (PAGE_WIDTH * rc->scale) + 0.5,
+ (PAGE_HEIGHT * rc->scale) + 0.5,
+ rc->rotation);
+ cairo_surface_destroy (surface);
+
+ return scaled_surface;
}
static void
{
ImpressDocument *impress_document = IMPRESS_DOCUMENT (object);
- g_mutex_free (impress_document->mutex);
+ if (impress_document->mutex)
+ g_mutex_free (impress_document->mutex);
+
+ if (impress_document->imp)
+ imp_close (impress_document->imp);
+
+ if (impress_document->ctx)
+ imp_delete_context (impress_document->ctx);
- imp_close (impress_document->imp);
- imp_delete_context (impress_document->ctx);
- g_free (impress_document->pango_ctx);
- g_object_unref (G_OBJECT (impress_document->pixmap));
- g_object_unref (impress_document->gc);
+ if (impress_document->pango_ctx)
+ g_object_unref (impress_document->pango_ctx);
+
+ if (impress_document->pixmap)
+ g_object_unref (G_OBJECT (impress_document->pixmap));
+
+ if (impress_document->gc)
+ g_object_unref (impress_document->gc);
G_OBJECT_CLASS (impress_document_parent_class)->finalize (object);
}
gobject_class->finalize = impress_document_finalize;
}
-static gboolean
-impress_document_can_get_text (EvDocument *document)
-{
- return FALSE;
-}
-
static EvDocumentInfo *
impress_document_get_info (EvDocument *document)
{
{
iface->load = impress_document_load;
iface->save = impress_document_save;
- iface->can_get_text = impress_document_can_get_text;
iface->get_n_pages = impress_document_get_n_pages;
iface->get_page_size = impress_document_get_page_size;
- iface->render_pixbuf = impress_document_render_pixbuf;
+ iface->render = impress_document_render;
iface->get_info = impress_document_get_info;
}
static GdkPixbuf *
impress_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
- gint page,
- gint rotation,
- gint size,
- gboolean border)
+ EvRenderContext *rc,
+ gboolean border)
{
- GdkPixbuf *pixbuf = NULL;
+ GdkPixbuf *pixbuf;
+ GdkPixbuf *scaled_pixbuf;
gdouble w, h;
- EvRenderContext *rc;
- impress_document_get_page_size (EV_DOCUMENT (document),
- page,
- &w, &h);
-
- rc = ev_render_context_new (rotation, page, size/w);
pixbuf = impress_document_render_pixbuf (EV_DOCUMENT (document), rc);
- g_object_unref (G_OBJECT (rc));
+ scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
+ (PAGE_WIDTH * rc->scale),
+ (PAGE_HEIGHT * rc->scale),
+ GDK_INTERP_BILINEAR);
+ g_object_unref (pixbuf);
if (border)
{
- GdkPixbuf *tmp_pixbuf = pixbuf;
- pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, 0, tmp_pixbuf);
+ GdkPixbuf *tmp_pixbuf = scaled_pixbuf;
+
+ scaled_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf);
g_object_unref (tmp_pixbuf);
}
- return pixbuf;
+ return scaled_pixbuf;
}
static void
impress_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
- gint page,
- gint suggested_width,
- gint *width,
- gint *height)
+ EvRenderContext *rc,
+ gint *width,
+ gint *height)
{
- gdouble page_ratio;
- gdouble w, h;
+ gdouble page_width, page_height;
impress_document_get_page_size (EV_DOCUMENT (document),
- page,
- &w, &h);
- g_return_if_fail (w > 0);
- page_ratio = h/w;
- *width = suggested_width;
- *height = (gint) (suggested_width * page_ratio);
+ rc->page,
+ &page_width, &page_height);
+
+ 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 void
impress_document->pixmap = gdk_pixmap_new (window,
PAGE_WIDTH, PAGE_HEIGHT, -1);
impress_document->gc = gdk_gc_new (impress_document->pixmap);
- impress_document->pango_ctx = gdk_pango_context_get ();
+ impress_document->pango_ctx = gdk_pango_context_get_for_screen (gdk_screen_get_default ());
}
/*