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-document-misc.h"
23 #include "ev-file-helpers.h"
26 struct _EvImagePrivate {
33 #define EV_IMAGE_GET_PRIVATE(object) \
34 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_IMAGE, EvImagePrivate))
36 G_DEFINE_TYPE (EvImage, ev_image, G_TYPE_OBJECT)
39 ev_image_finalize (GObject *object)
41 EvImage *image = EV_IMAGE (object);
43 if (image->priv->pixbuf) {
44 g_object_unref (image->priv->pixbuf);
45 image->priv->pixbuf = NULL;
48 if (image->priv->tmp_uri) {
51 filename = g_filename_from_uri (image->priv->tmp_uri, NULL, NULL);
52 ev_tmp_filename_unlink (filename);
54 g_free (image->priv->tmp_uri);
55 image->priv->tmp_uri = NULL;
58 (* G_OBJECT_CLASS (ev_image_parent_class)->finalize) (object);
62 ev_image_class_init (EvImageClass *klass)
64 GObjectClass *g_object_class;
66 g_object_class = G_OBJECT_CLASS (klass);
68 g_type_class_add_private (g_object_class, sizeof (EvImagePrivate));
70 g_object_class->finalize = ev_image_finalize;
74 ev_image_init (EvImage *image)
76 image->priv = EV_IMAGE_GET_PRIVATE (image);
80 ev_image_new (gint page,
85 image = EV_IMAGE (g_object_new (EV_TYPE_IMAGE, NULL));
86 image->priv->page = page;
87 image->priv->id = img_id;
93 ev_image_new_from_pixbuf (GdkPixbuf *pixbuf)
97 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
99 image = EV_IMAGE (g_object_new (EV_TYPE_IMAGE, NULL));
100 image->priv->pixbuf = g_object_ref (pixbuf);
106 ev_image_get_page (EvImage *image)
108 g_return_val_if_fail (EV_IS_IMAGE (image), -1);
110 return image->priv->page;
114 ev_image_get_id (EvImage *image)
116 g_return_val_if_fail (EV_IS_IMAGE (image), -1);
118 return image->priv->id;
122 ev_image_get_pixbuf (EvImage *image)
124 g_return_val_if_fail (EV_IS_IMAGE (image), NULL);
125 g_return_val_if_fail (GDK_IS_PIXBUF (image->priv->pixbuf), NULL);
127 return image->priv->pixbuf;
131 ev_image_save_tmp (EvImage *image,
134 GError *error = NULL;
137 g_return_val_if_fail (EV_IS_IMAGE (image), NULL);
138 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
140 if (image->priv->tmp_uri)
141 return image->priv->tmp_uri;
143 filename = ev_tmp_filename ("image");
144 gdk_pixbuf_save (pixbuf, filename,
146 "compression", "3", NULL);
148 image->priv->tmp_uri = g_filename_to_uri (filename, NULL, NULL);
151 return image->priv->tmp_uri;
154 /* Erro saving image */
155 g_warning ("%s", error->message);
156 g_error_free (error);
163 ev_image_get_tmp_uri (EvImage *image)
165 g_return_val_if_fail (EV_IS_IMAGE (image), NULL);
167 return image->priv->tmp_uri;
172 ev_image_mapping_free_foreach (EvImageMapping *mapping)
174 g_object_unref (mapping->image);
179 ev_image_mapping_free (GList *image_mapping)
184 g_list_foreach (image_mapping, (GFunc) ev_image_mapping_free_foreach, NULL);
185 g_list_free (image_mapping);
189 ev_image_mapping_find (GList *image_mapping,
195 for (list = image_mapping; list; list = list->next) {
196 EvImageMapping *mapping = list->data;
198 if ((x >= mapping->x1) &&
199 (y >= mapping->y1) &&
200 (x <= mapping->x2) &&
201 (y <= mapping->y2)) {
202 return mapping->image;