[librsvg: 10/11] Clean up rsvg-defs a bit
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 10/11] Clean up rsvg-defs a bit
- Date: Tue, 5 Dec 2017 00:56:41 +0000 (UTC)
commit 5fc44d9cf5e3b20ac06264d93554bd7fa701f788
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Dec 4 18:29:46 2017 -0600
Clean up rsvg-defs a bit
rsvg-defs.c | 54 ++++++++++++++++++++++++++----------------------------
rsvg-io.c | 2 +-
rsvg-io.h | 4 ----
3 files changed, 27 insertions(+), 33 deletions(-)
---
diff --git a/rsvg-defs.c b/rsvg-defs.c
index efe7acd..e74e115 100644
--- a/rsvg-defs.c
+++ b/rsvg-defs.c
@@ -50,52 +50,50 @@ rsvg_defs_new (RsvgHandle *handle)
return result;
}
-static int
-rsvg_defs_load_extern (const RsvgDefs * defs, const char *name)
+static RsvgHandle *
+rsvg_defs_load_extern (const RsvgDefs * defs, const char *uri)
{
- RsvgHandle *handle;
- gchar *filename, *base_uri;
+ RsvgHandle *handle = NULL;
char *data;
gsize data_len;
- gboolean rv;
-
- filename = _rsvg_io_get_file_path (name, rsvg_handle_get_base_uri (defs->ctx));
- data = _rsvg_handle_acquire_data (defs->ctx, name, NULL, &data_len, NULL);
+ data = _rsvg_handle_acquire_data (defs->ctx, uri, NULL, &data_len, NULL);
if (data) {
handle = rsvg_handle_new ();
-
- base_uri = rsvg_get_base_uri_from_filename (filename);
- rsvg_handle_set_base_uri (handle, base_uri);
- g_free (base_uri);
-
- rv = rsvg_handle_write (handle, (guchar *) data, data_len, NULL);
- rv = rsvg_handle_close (handle, NULL) && rv;
- if (rv) {
- g_hash_table_insert (defs->externs, g_strdup (name), handle);
+ rsvg_handle_set_base_uri (handle, uri);
+
+ if (rsvg_handle_write (handle, (guchar *) data, data_len, NULL)
+ && rsvg_handle_close (handle, NULL)) {
+ g_hash_table_insert (defs->externs, g_strdup (uri), handle);
+ } else {
+ g_object_unref (handle);
+ handle = NULL;
}
g_free (data);
}
- g_free (filename);
- return 0;
+ return handle;
}
static RsvgNode *
-rsvg_defs_extern_lookup (const RsvgDefs * defs, const char *filename, const char *name)
+rsvg_defs_extern_lookup (const RsvgDefs * defs, const char *possibly_relative_uri, const char *name)
{
- RsvgHandle *file;
- file = (RsvgHandle *) g_hash_table_lookup (defs->externs, filename);
- if (file == NULL) {
- if (rsvg_defs_load_extern (defs, filename))
- return NULL;
- file = (RsvgHandle *) g_hash_table_lookup (defs->externs, filename);
+ RsvgHandle *handle;
+ char *uri;
+
+ uri = rsvg_handle_resolve_uri (defs->ctx, possibly_relative_uri);
+ if (!uri)
+ return NULL;
+
+ handle = (RsvgHandle *) g_hash_table_lookup (defs->externs, uri);
+ if (handle == NULL) {
+ handle = rsvg_defs_load_extern (defs, uri);
}
- if (file != NULL)
- return g_hash_table_lookup (file->priv->defs->hash, name);
+ if (handle != NULL)
+ return g_hash_table_lookup (handle->priv->defs->hash, name);
else
return NULL;
}
diff --git a/rsvg-io.c b/rsvg-io.c
index d989929..79c7863 100644
--- a/rsvg-io.c
+++ b/rsvg-io.c
@@ -325,7 +325,7 @@ _rsvg_io_acquire_stream (const char *href,
return g_memory_input_stream_new_from_data (data, len, (GDestroyNotify) g_free);
}
- if ((data = rsvg_acquire_file_data (href, base_uri, mime_type, &len, cancellable, NULL)))
+ if ((data = rsvg_acquire_file_data (href, mime_type, &len, cancellable, NULL)))
return g_memory_input_stream_new_from_data (data, len, (GDestroyNotify) g_free);
if ((stream = rsvg_acquire_gvfs_stream (href, base_uri, mime_type, cancellable, error)))
diff --git a/rsvg-io.h b/rsvg-io.h
index d710ccf..50e0002 100644
--- a/rsvg-io.h
+++ b/rsvg-io.h
@@ -26,10 +26,6 @@
#include <glib.h>
#include <gio/gio.h>
-G_GNUC_INTERNAL
-gchar *_rsvg_io_get_file_path (const gchar *filename,
- const gchar *basedir);
-
char *_rsvg_io_acquire_data (const char *uri,
const char *base_uri,
char **mime_type,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]