-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathimage-load-svgz.cc
107 lines (87 loc) · 2.95 KB
/
image-load-svgz.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* Copyright (C) 2019 The Geeqie Team
*
* Author: Colin Clark
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "image-load-svgz.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <glib-object.h>
#include <glib.h>
#include "image-load.h"
namespace
{
struct ImageLoaderSvgz : public ImageLoaderBackend
{
public:
~ImageLoaderSvgz() override;
void init(AreaUpdatedCb area_updated_cb, SizePreparedCb size_prepared_cb, AreaPreparedCb area_prepared_cb, gpointer data) override;
void set_size(int width, int height) override;
gboolean write(const guchar *buf, gsize &chunk_size, gsize count, GError **error) override;
GdkPixbuf *get_pixbuf() override;
gboolean close(GError **error) override;
gchar *get_format_name() override;
gchar **get_format_mime_types() override;
private:
GdkPixbufLoader *loader;
};
gchar *ImageLoaderSvgz::get_format_name()
{
return g_strdup("svg");
}
gchar **ImageLoaderSvgz::get_format_mime_types()
{
static const gchar *mime[] = {"image/svg", nullptr};
return g_strdupv(const_cast<gchar **>(mime));
}
void ImageLoaderSvgz::init(AreaUpdatedCb area_updated_cb, SizePreparedCb size_prepared_cb, AreaPreparedCb area_prepared_cb, gpointer data)
{
g_autoptr(GError) error = nullptr;
loader = gdk_pixbuf_loader_new_with_mime_type("image/svg", &error);
if (error)
{
return;
}
g_signal_connect(G_OBJECT(loader), "area_updated", G_CALLBACK(area_updated_cb), data);
g_signal_connect(G_OBJECT(loader), "size_prepared", G_CALLBACK(size_prepared_cb), data);
g_signal_connect(G_OBJECT(loader), "area_prepared", G_CALLBACK(area_prepared_cb), data);
}
void ImageLoaderSvgz::set_size(int width, int height)
{
gdk_pixbuf_loader_set_size(loader, width, height);
}
gboolean ImageLoaderSvgz::write(const guchar *buf, gsize &chunk_size, gsize, GError **error)
{
return gdk_pixbuf_loader_write(loader, buf, chunk_size, error);
}
GdkPixbuf *ImageLoaderSvgz::get_pixbuf()
{
return gdk_pixbuf_loader_get_pixbuf(loader);
}
gboolean ImageLoaderSvgz::close(GError **error)
{
return gdk_pixbuf_loader_close(loader, error);
}
ImageLoaderSvgz::~ImageLoaderSvgz()
{
g_object_unref(G_OBJECT(loader));
}
} // namespace
std::unique_ptr<ImageLoaderBackend> get_image_loader_backend_svgz()
{
return std::make_unique<ImageLoaderSvgz>();
}
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */