1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
6
* Copyright (C) 2011 Free Software Foundation, Inc.
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24
#include <librsvg/rsvg.h>
25
#include <librsvg/rsvg-cairo.h>
26
#include "cairo-io-svg.h"
29
/* GthImageSvg (private class) */
32
#define GTH_IMAGE_SVG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), gth_image_svg_get_type(), GthImageSvg))
44
typedef GthImageClass GthImageSvgClass;
47
static gpointer gth_image_svg_parent_class;
50
G_DEFINE_TYPE (GthImageSvg, gth_image_svg, GTH_TYPE_IMAGE)
54
gth_image_svg_finalize (GObject *object)
58
self = GTH_IMAGE_SVG (object);
59
_g_object_unref (self->rsvg);
61
G_OBJECT_CLASS (gth_image_svg_parent_class)->finalize (object);
66
gth_image_svg_init (GthImageSvg *self)
69
self->original_width = 0;
70
self->original_height = 0;
71
self->last_zoom = 0.0;
76
gth_image_svg_get_is_zoomable (GthImage *base)
78
return (((GthImageSvg *) base)->rsvg != NULL);
83
gth_image_svg_set_zoom (GthImage *base,
89
cairo_surface_t *surface;
91
gboolean changed = FALSE;
93
self = GTH_IMAGE_SVG (base);
94
if (self->rsvg == NULL)
97
if (zoom != self->last_zoom) {
98
self->last_zoom = zoom;
100
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
101
zoom * self->original_width,
102
zoom * self->original_height);
103
cr = cairo_create (surface);
104
cairo_scale (cr, zoom, zoom);
105
rsvg_handle_render_cairo (self->rsvg, cr);
106
gth_image_set_cairo_surface (base, surface);
110
cairo_surface_destroy (surface);
113
if (original_width != NULL)
114
*original_width = self->original_width;
115
if (original_height != NULL)
116
*original_height = self->original_height;
123
gth_image_svg_class_init (GthImageSvgClass *klass)
125
GObjectClass *object_class;
126
GthImageClass *image_class;
128
object_class = G_OBJECT_CLASS (klass);
129
object_class->finalize = gth_image_svg_finalize;
131
image_class = GTH_IMAGE_CLASS (klass);
132
image_class->get_is_zoomable = gth_image_svg_get_is_zoomable;
133
image_class->set_zoom = gth_image_svg_set_zoom;
138
gth_image_svg_new (void)
140
return g_object_new (gth_image_svg_get_type (), NULL);
145
gth_image_svg_set_handle (GthImageSvg *self,
148
RsvgDimensionData dimension_data;
150
if (self->rsvg == rsvg)
153
self->rsvg = g_object_ref (rsvg);
155
rsvg_handle_get_dimensions (self->rsvg, &dimension_data);
156
self->original_width = dimension_data.width;
157
self->original_height = dimension_data.height;
159
gth_image_svg_set_zoom (GTH_IMAGE (self), 1.0, NULL, NULL);
163
/* -- _cairo_image_surface_create_from_svg -- */
167
_cairo_image_surface_create_from_svg (GthFileData *file_data,
170
int *original_height,
172
GCancellable *cancellable,
178
image = gth_image_svg_new ();
179
rsvg = rsvg_handle_new_from_gfile_sync (file_data->file,
180
RSVG_HANDLE_FLAGS_NONE,
184
gth_image_svg_set_handle (GTH_IMAGE_SVG (image), rsvg);
185
g_object_unref (rsvg);