1 /* this file is part of evince, a gnome document viewer
3 * Copyright (C) 2006 Carlos Garcia Campos <carlosgc@gnome.org>
5 * Evince is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * Evince is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21 #include <glib/gstdio.h>
22 #include "ev-file-helpers.h"
25 struct _EvImagePrivate {
30 #define EV_IMAGE_GET_PRIVATE(object) \
31 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_IMAGE, EvImagePrivate))
33 G_DEFINE_TYPE (EvImage, ev_image, G_TYPE_OBJECT)
36 ev_image_finalize (GObject *object)
38 EvImage *image = EV_IMAGE (object);
40 if (image->priv->pixbuf) {
41 g_object_unref (image->priv->pixbuf);
42 image->priv->pixbuf = NULL;
45 if (image->priv->tmp_uri) {
46 ev_tmp_filename_unlink (image->priv->tmp_uri);
47 g_free (image->priv->tmp_uri);
48 image->priv->tmp_uri = NULL;
51 (* G_OBJECT_CLASS (ev_image_parent_class)->finalize) (object);
55 ev_image_class_init (EvImageClass *klass)
57 GObjectClass *g_object_class;
59 g_object_class = G_OBJECT_CLASS (klass);
61 g_type_class_add_private (g_object_class, sizeof (EvImagePrivate));
63 g_object_class->finalize = ev_image_finalize;
67 ev_image_init (EvImage *image)
69 image->priv = EV_IMAGE_GET_PRIVATE (image);
73 ev_image_new_from_pixbuf (GdkPixbuf *pixbuf)
77 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
79 image = EV_IMAGE (g_object_new (EV_TYPE_IMAGE, NULL));
80 image->priv->pixbuf = g_object_ref (pixbuf);
86 ev_image_get_pixbuf (EvImage *image)
88 g_return_val_if_fail (EV_IS_IMAGE (image), NULL);
89 g_return_val_if_fail (GDK_IS_PIXBUF (image->priv->pixbuf), NULL);
91 return image->priv->pixbuf;
95 ev_image_save_tmp (EvImage *image)
99 g_return_val_if_fail (EV_IS_IMAGE (image), NULL);
100 g_return_val_if_fail (GDK_IS_PIXBUF (image->priv->pixbuf), NULL);
102 if (image->priv->tmp_uri)
103 return image->priv->tmp_uri;
105 image->priv->tmp_uri = ev_tmp_filename ("image");
106 gdk_pixbuf_save (image->priv->pixbuf,
107 image->priv->tmp_uri, "png", &error,
108 "compression", "3", NULL);
110 return image->priv->tmp_uri;
112 /* Erro saving image */
113 g_warning (error->message);
114 g_error_free (error);
115 g_free (image->priv->tmp_uri);
116 image->priv->tmp_uri = NULL;
122 ev_image_get_tmp_uri (EvImage *image)
124 g_return_val_if_fail (EV_IS_IMAGE (image), NULL);
126 return image->priv->tmp_uri;
131 ev_image_mapping_free_foreach (EvImageMapping *mapping)
133 g_object_unref (mapping->image);
138 ev_image_mapping_free (GList *image_mapping)
143 g_list_foreach (image_mapping, (GFunc) ev_image_mapping_free_foreach, NULL);
144 g_list_free (image_mapping);
148 ev_image_mapping_find (GList *image_mapping,
154 for (list = image_mapping; list; list = list->next) {
155 EvImageMapping *mapping = list->data;
157 if ((x >= mapping->x1) &&
158 (y >= mapping->y1) &&
159 (x <= mapping->x2) &&
160 (y <= mapping->y2)) {
161 return mapping->image;