1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* pixbuf-document.h: Implementation of EvDocument for PIXBUF
3 * Copyright (C) 2004, Anders Carlsson <andersca@gnome.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU 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.
20 #include "pixbuf-document.h"
22 struct _PixbufDocumentClass
24 GObjectClass parent_class;
27 struct _PixbufDocument
29 GObject parent_instance;
35 gint x_offset, y_offset;
38 typedef struct _PixbufDocumentClass PixbufDocumentClass;
40 static void pixbuf_document_document_iface_init (EvDocumentIface *iface);
42 G_DEFINE_TYPE_WITH_CODE (PixbufDocument, pixbuf_document, G_TYPE_OBJECT,
43 { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
44 pixbuf_document_document_iface_init) });
46 static GObjectClass *parent_class;
49 pixbuf_document_load (EvDocument *document,
53 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
58 /* FIXME: We could actually load uris */
59 filename = g_filename_from_uri (uri, NULL, error);
63 pixbuf = gdk_pixbuf_new_from_file (filename, error);
68 pixbuf_document->pixbuf = pixbuf;
74 pixbuf_document_get_n_pages (EvDocument *document)
80 pixbuf_document_set_page (EvDocument *document,
87 pixbuf_document_get_page (EvDocument *document)
93 pixbuf_document_set_target (EvDocument *document,
96 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
98 pixbuf_document->target = target;
102 pixbuf_document_set_scale (EvDocument *document,
105 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
107 pixbuf_document->scale = scale;
111 pixbuf_document_set_page_offset (EvDocument *document,
115 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
117 pixbuf_document->x_offset = x;
118 pixbuf_document->y_offset = y;
122 pixbuf_document_get_page_size (EvDocument *document,
126 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
128 *width = gdk_pixbuf_get_width (pixbuf_document->pixbuf);
129 *height = gdk_pixbuf_get_height (pixbuf_document->pixbuf);
133 pixbuf_document_render (EvDocument *document,
139 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
141 if (pixbuf_document->scale == 1.0) {
142 gdk_draw_pixbuf (pixbuf_document->target, NULL, pixbuf_document->pixbuf,
145 clip_width, clip_height, GDK_RGB_DITHER_NORMAL,
149 GdkPixbuf *tmp_pixbuf;
151 tmp_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (pixbuf_document->pixbuf),
152 gdk_pixbuf_get_has_alpha (pixbuf_document->pixbuf),
153 gdk_pixbuf_get_bits_per_sample (pixbuf_document->pixbuf),
154 clip_width, clip_height);
156 gdk_pixbuf_scale (pixbuf_document->pixbuf, tmp_pixbuf, 0, 0, clip_width, clip_height,
157 clip_x * pixbuf_document->scale,
158 clip_y * pixbuf_document->scale,
159 pixbuf_document->scale, pixbuf_document->scale,
160 GDK_INTERP_BILINEAR);
162 gdk_draw_pixbuf (pixbuf_document->target, NULL, tmp_pixbuf,
164 clip_x + pixbuf_document->x_offset,
165 clip_y + pixbuf_document->y_offset,
166 clip_width, clip_height, GDK_RGB_DITHER_NORMAL,
169 g_object_unref (tmp_pixbuf);
174 pixbuf_document_begin_find (EvDocument *document,
175 const char *search_string,
176 gboolean case_sensitive)
182 pixbuf_document_end_find (EvDocument *document)
187 pixbuf_document_finalize (GObject *object)
189 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (object);
191 g_object_unref (pixbuf_document->pixbuf);
193 G_OBJECT_CLASS (parent_class)->finalize (object);
197 pixbuf_document_class_init (PixbufDocumentClass *klass)
199 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
201 parent_class = g_type_class_peek_parent (klass);
203 gobject_class->finalize = pixbuf_document_finalize;
207 pixbuf_document_document_iface_init (EvDocumentIface *iface)
209 iface->load = pixbuf_document_load;
210 iface->get_n_pages = pixbuf_document_get_n_pages;
211 iface->set_page = pixbuf_document_set_page;
212 iface->get_page = pixbuf_document_get_page;
213 iface->set_scale = pixbuf_document_set_scale;
214 iface->set_target = pixbuf_document_set_target;
215 iface->set_page_offset = pixbuf_document_set_page_offset;
216 iface->get_page_size = pixbuf_document_get_page_size;
217 iface->render = pixbuf_document_render;
218 iface->begin_find = pixbuf_document_begin_find;
219 iface->end_find = pixbuf_document_end_find;
223 pixbuf_document_init (PixbufDocument *pixbuf_document)
225 pixbuf_document->scale = 1.0;
227 pixbuf_document->x_offset = 10;
228 pixbuf_document->y_offset = 10;