X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Furi-references.cpp;h=8041fbf520f46fafbe098569f117aabd21a1c858;hb=b752616506705efd28f22c4d852d198ff40c7026;hp=793e10d98ad0ec280e02a093c746107211655c0d;hpb=0a603a1e7a1d021e5e25515f6ca592219952f95d;p=inkscape.git diff --git a/src/uri-references.cpp b/src/uri-references.cpp index 793e10d98..8041fbf52 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -12,31 +12,46 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include +#include + #include "document.h" #include "sp-object.h" #include "uri.h" #include "uri-references.h" +#include "extract-uri.h" #include -static gchar *uri_to_id(SPDocument *document, const gchar *uri); - namespace Inkscape { URIReference::URIReference(SPObject *owner) -: _owner(owner), _obj(NULL), _uri(NULL) + : _owner(owner), _owner_document(NULL), _obj(NULL), _uri(NULL) { g_assert(_owner != NULL); /* FIXME !!! attach to owner's destroy signal to clean up in case */ } +URIReference::URIReference(SPDocument *owner_document) + : _owner(NULL), _owner_document(owner_document), _obj(NULL), _uri(NULL) +{ + g_assert(_owner_document != NULL); +} + URIReference::~URIReference() { detach(); } void URIReference::attach(const URI &uri) throw(BadURIException) { - SPDocument *document = SP_OBJECT_DOCUMENT(_owner); + SPDocument *document; + if (_owner) { + document = SP_OBJECT_DOCUMENT(_owner); + } else if (_owner_document) { + document = _owner_document; + } else { + g_assert_not_reached(); + } gchar const *fragment = uri.getFragment(); if ( !uri.isRelative() || uri.getQuery() || !fragment ) { throw UnsupportedURIException(); @@ -97,13 +112,13 @@ void URIReference::_setObject(SPObject *obj) { SPObject *old_obj=_obj; _obj = obj; + _release_connection.disconnect(); if (_obj) { sp_object_href(_obj, _owner); _release_connection = _obj->connectRelease(sigc::mem_fun(*this, &URIReference::_release)); } _changed_signal.emit(old_obj, _obj); if (old_obj) { - _release_connection.disconnect(); /* release the old object _after_ the signal emission */ sp_object_hunref(old_obj, _owner); } @@ -120,48 +135,29 @@ void URIReference::_release(SPObject *obj) { } /* namespace Inkscape */ -static gchar * -uri_to_id(SPDocument *document, const gchar *uri) +SPObject* sp_css_uri_reference_resolve( SPDocument *document, const gchar *uri ) { - const gchar *e; - gchar *id; - gint len; + SPObject* ref = 0; - g_return_val_if_fail (document != NULL, NULL); + if ( document && uri && ( strncmp(uri, "url(", 4) == 0 )) { + gchar *trimmed = extract_uri( uri ); + if ( trimmed ) { + ref = sp_uri_reference_resolve( document, trimmed ); + g_free( trimmed ); + } + } - if (!uri) return NULL; - /* fixme: xpointer, everything */ - if (strncmp (uri, "url(#", 5)) return NULL; - - e = uri + 5; - while (*e) { - if (*e == ')') break; - if (!isalnum (*e) && (*e != '_') && (*e != '-') && (*e != ':') && (*e != '.')) return NULL; - e += 1; - if (!*e) return NULL; - } - - len = e - uri - 5; - if (len < 1) return NULL; - - id = (gchar*)g_new(gchar, len + 1); - memcpy (id, uri + 5, len); - id[len] = '\0'; - - return id; + return ref; } SPObject * sp_uri_reference_resolve (SPDocument *document, const gchar *uri) { - gchar *id; + SPObject* ref = 0; - id = uri_to_id(document, uri); - if (!id) return NULL; + if ( uri && (*uri == '#') ) { + ref = document->getObjectById( uri + 1 ); + } - SPObject *ref; - ref = document->getObjectById(id); - g_free(id); - return ref; + return ref; } -