summaryrefslogtreecommitdiffstats
path: root/src/display/cairo-utils.cpp
diff options
context:
space:
mode:
authorThomas Holder <thomas@thomas-holder.de>2018-11-03 21:34:23 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-11-04 16:24:42 +0000
commitc9b918d330b74b82f4e61cfa537674bcd53ade5f (patch)
tree6b5f3cf85593cf375850b53908b1cfc13e557573 /src/display/cairo-utils.cpp
parentAdd --preload option. (diff)
downloadinkscape-c9b918d330b74b82f4e61cfa537674bcd53ade5f.tar.gz
inkscape-c9b918d330b74b82f4e61cfa537674bcd53ade5f.zip
Image HTTP support
Uses Gio::File::load_contents (via URI::getContents) to load images from non-file/non-data URIs. Depends on GVfs.
Diffstat (limited to 'src/display/cairo-utils.cpp')
-rw-r--r--src/display/cairo-utils.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp
index e4cef786d..516d52678 100644
--- a/src/display/cairo-utils.cpp
+++ b/src/display/cairo-utils.cpp
@@ -363,6 +363,31 @@ Pixbuf *Pixbuf::create_from_file(std::string const &fn, double svgdpi)
std::cerr << " (" << fn << ")" << std::endl;
return nullptr;
}
+
+ pb = Pixbuf::create_from_buffer(std::move(data), len, svgdpi, fn);
+
+ if (pb) {
+ pb->_mod_time = stdir.st_mtime;
+ }
+ } else {
+ std::cerr << "Pixbuf::create_from_file: failed to get contents: " << fn << std::endl;
+ return nullptr;
+ }
+
+ return pb;
+}
+
+Pixbuf *Pixbuf::create_from_buffer(std::string const &buffer, double svgdpi, std::string const &fn)
+{
+ auto datacopy = (gchar *)g_memdup(buffer.data(), buffer.size());
+ return Pixbuf::create_from_buffer(std::move(datacopy), buffer.size(), svgdpi, fn);
+}
+
+Pixbuf *Pixbuf::create_from_buffer(gchar *&&data, gsize len, double svgdpi, std::string const &fn)
+{
+ Pixbuf *pb = nullptr;
+ GError *error = nullptr;
+ {
GdkPixbuf *buf = nullptr;
GdkPixbufLoader *loader = nullptr;
std::string::size_type idx;
@@ -432,7 +457,6 @@ Pixbuf *Pixbuf::create_from_file(std::string const &fn, double svgdpi)
if (buf) {
g_object_ref(buf);
pb = new Pixbuf(buf);
- pb->_mod_time = stdir.st_mtime;
pb->_path = fn;
if (!is_svg) {
GdkPixbufFormat *fmt = gdk_pixbuf_loader_get_format(loader);
@@ -450,9 +474,6 @@ Pixbuf *Pixbuf::create_from_file(std::string const &fn, double svgdpi)
// TODO: we could also read DPI, ICC profile, gamma correction, and other information
// from the file. This can be done by using format-specific libraries e.g. libpng.
- } else {
- std::cerr << "Pixbuf::create_from_file: failed to get contents: " << fn << std::endl;
- return nullptr;
}
return pb;