~ubuntu-branches/ubuntu/trusty/gthumb/trusty

« back to all changes in this revision

Viewing changes to extensions/cairo_io/cairo-io-svg.c

  • Committer: Package Import Robot
  • Author(s): Jackson Doak
  • Date: 2013-08-31 06:24:51 UTC
  • mfrom: (1.3.17) (5.2.24 sid)
  • Revision ID: package-import@ubuntu.com-20130831062451-0958soi720z0byp6
Tags: 3:3.2.5-1
* New upstream release. Closes: #716729 LP: #1201073
* Set myself as maintainer. Closes: #711827
* debian/control:
  - Build-depend on yelp-tools, libgstreamer1.0-dev, libsecret-1-dev,
    libgstreamer-plugins-base1.0-dev, libwebp-dev
  - Bump standards-version to 3.9.4
  - Bump debhelper to 8
  - Make git URLs canonical
  - Drop depend on libiptcdata0-dev. Closes: #697087
  - Drop depend on gnome keyring since libsecret replaces it
* debian/compat: Set as 8
* debian/rules: 
  - Add --enable-libwebp for WebP support
  - Add --disable-silent-rules for verbose building
  - Enable hardening
* Create debian/source/options
* Refresh all patches so they apply cleanly

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
 
3
 
/*
4
 
 *  GThumb
5
 
 *
6
 
 *  Copyright (C) 2011 Free Software Foundation, Inc.
7
 
 *
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.
12
 
 *
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.
17
 
 *
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/>.
20
 
 */
21
 
 
22
 
#include <config.h>
23
 
#include <gthumb.h>
24
 
#include <librsvg/rsvg.h>
25
 
#include <librsvg/rsvg-cairo.h>
26
 
#include "cairo-io-svg.h"
27
 
 
28
 
 
29
 
/* GthImageSvg (private class) */
30
 
 
31
 
 
32
 
#define GTH_IMAGE_SVG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), gth_image_svg_get_type(), GthImageSvg))
33
 
 
34
 
 
35
 
typedef struct {
36
 
        GthImage __parent;
37
 
        RsvgHandle *rsvg;
38
 
        int         original_width;
39
 
        int         original_height;
40
 
        double      last_zoom;
41
 
} GthImageSvg;
42
 
 
43
 
 
44
 
typedef GthImageClass GthImageSvgClass;
45
 
 
46
 
 
47
 
static gpointer gth_image_svg_parent_class;
48
 
 
49
 
 
50
 
G_DEFINE_TYPE (GthImageSvg, gth_image_svg, GTH_TYPE_IMAGE)
51
 
 
52
 
 
53
 
static void
54
 
gth_image_svg_finalize (GObject *object)
55
 
{
56
 
        GthImageSvg *self;
57
 
 
58
 
        self = GTH_IMAGE_SVG (object);
59
 
        _g_object_unref (self->rsvg);
60
 
 
61
 
        G_OBJECT_CLASS (gth_image_svg_parent_class)->finalize (object);
62
 
}
63
 
 
64
 
 
65
 
static void
66
 
gth_image_svg_init (GthImageSvg *self)
67
 
{
68
 
        self->rsvg = NULL;
69
 
        self->original_width = 0;
70
 
        self->original_height = 0;
71
 
        self->last_zoom = 0.0;
72
 
}
73
 
 
74
 
 
75
 
static gboolean
76
 
gth_image_svg_get_is_zoomable (GthImage *base)
77
 
{
78
 
        return (((GthImageSvg *) base)->rsvg != NULL);
79
 
}
80
 
 
81
 
 
82
 
static gboolean
83
 
gth_image_svg_set_zoom (GthImage *base,
84
 
                        double    zoom,
85
 
                        int      *original_width,
86
 
                        int      *original_height)
87
 
{
88
 
        GthImageSvg     *self;
89
 
        cairo_surface_t *surface;
90
 
        cairo_t         *cr;
91
 
        gboolean         changed = FALSE;
92
 
 
93
 
        self = GTH_IMAGE_SVG (base);
94
 
        if (self->rsvg == NULL)
95
 
                return FALSE;
96
 
 
97
 
        if (zoom != self->last_zoom) {
98
 
                self->last_zoom = zoom;
99
 
 
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);
107
 
                changed = TRUE;
108
 
 
109
 
                cairo_destroy (cr);
110
 
                cairo_surface_destroy (surface);
111
 
        }
112
 
 
113
 
        if (original_width != NULL)
114
 
                *original_width = self->original_width;
115
 
        if (original_height != NULL)
116
 
                *original_height = self->original_height;
117
 
 
118
 
        return changed;
119
 
}
120
 
 
121
 
 
122
 
static void
123
 
gth_image_svg_class_init (GthImageSvgClass *klass)
124
 
{
125
 
        GObjectClass  *object_class;
126
 
        GthImageClass *image_class;
127
 
 
128
 
        object_class = G_OBJECT_CLASS (klass);
129
 
        object_class->finalize = gth_image_svg_finalize;
130
 
 
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;
134
 
}
135
 
 
136
 
 
137
 
static GthImage *
138
 
gth_image_svg_new (void)
139
 
{
140
 
        return g_object_new (gth_image_svg_get_type (), NULL);
141
 
}
142
 
 
143
 
 
144
 
static void
145
 
gth_image_svg_set_handle (GthImageSvg *self,
146
 
                          RsvgHandle  *rsvg)
147
 
{
148
 
        RsvgDimensionData dimension_data;
149
 
 
150
 
        if (self->rsvg == rsvg)
151
 
                return;
152
 
 
153
 
        self->rsvg = g_object_ref (rsvg);
154
 
 
155
 
        rsvg_handle_get_dimensions (self->rsvg, &dimension_data);
156
 
        self->original_width = dimension_data.width;
157
 
        self->original_height = dimension_data.height;
158
 
 
159
 
        gth_image_svg_set_zoom (GTH_IMAGE (self), 1.0, NULL, NULL);
160
 
}
161
 
 
162
 
 
163
 
/* -- _cairo_image_surface_create_from_svg -- */
164
 
 
165
 
 
166
 
GthImage *
167
 
_cairo_image_surface_create_from_svg (GthFileData   *file_data,
168
 
                                      int            requested_size,
169
 
                                      int           *original_width,
170
 
                                      int           *original_height,
171
 
                                      gpointer       user_data,
172
 
                                      GCancellable  *cancellable,
173
 
                                      GError       **error)
174
 
{
175
 
        GthImage   *image;
176
 
        RsvgHandle *rsvg;
177
 
 
178
 
        image = gth_image_svg_new ();
179
 
        rsvg = rsvg_handle_new_from_gfile_sync (file_data->file,
180
 
                                                RSVG_HANDLE_FLAGS_NONE,
181
 
                                                cancellable,
182
 
                                                error);
183
 
        if (rsvg != NULL) {
184
 
                gth_image_svg_set_handle (GTH_IMAGE_SVG (image), rsvg);
185
 
                g_object_unref (rsvg);
186
 
        }
187
 
 
188
 
        return image;
189
 
}