diff options
Diffstat (limited to 'src/xml')
| -rw-r--r-- | src/xml/helper-observer.cpp | 10 | ||||
| -rw-r--r-- | src/xml/node-iterators.h | 1 | ||||
| -rw-r--r-- | src/xml/rebase-hrefs.cpp | 7 | ||||
| -rw-r--r-- | src/xml/repr-io.cpp | 2 | ||||
| -rw-r--r-- | src/xml/repr-sorting.cpp | 42 | ||||
| -rw-r--r-- | src/xml/repr-sorting.h | 10 | ||||
| -rw-r--r-- | src/xml/repr-util.cpp | 49 | ||||
| -rw-r--r-- | src/xml/repr.cpp | 2 | ||||
| -rw-r--r-- | src/xml/repr.h | 28 |
9 files changed, 89 insertions, 62 deletions
diff --git a/src/xml/helper-observer.cpp b/src/xml/helper-observer.cpp index 620a88d8c..ce902ba75 100644 --- a/src/xml/helper-observer.cpp +++ b/src/xml/helper-observer.cpp @@ -11,10 +11,12 @@ SignalObserver::SignalObserver() // Add this observer to the SPObject and remove it from any previous object void SignalObserver::set(SPObject* o) { - if(_oldsel && _oldsel->repr) - _oldsel->repr->removeObserver(*this); - if(o && o->repr) - o->repr->addObserver(*this); + // XML Tree being used direcly in this function in the following code + // while it shouldn't be + if(_oldsel && _oldsel->getRepr()) + _oldsel->getRepr()->removeObserver(*this); + if(o && o->getRepr()) + o->getRepr()->addObserver(*this); _oldsel = o; } diff --git a/src/xml/node-iterators.h b/src/xml/node-iterators.h index 3d09dfd1b..389d70be0 100644 --- a/src/xml/node-iterators.h +++ b/src/xml/node-iterators.h @@ -23,6 +23,7 @@ struct NodeSiblingIteratorStrategy { return ( node ? node->next() : NULL ); } }; + struct NodeParentIteratorStrategy { static Node const *next(Node const *node) { return ( node ? node->parent() : NULL ); diff --git a/src/xml/rebase-hrefs.cpp b/src/xml/rebase-hrefs.cpp index c3876725d..065517160 100644 --- a/src/xml/rebase-hrefs.cpp +++ b/src/xml/rebase-hrefs.cpp @@ -201,10 +201,11 @@ Inkscape::XML::calc_abs_doc_base(gchar const *const doc_base) */ void Inkscape::XML::rebase_hrefs(SPDocument *const doc, gchar const *const new_base, bool const spns) { - if (!doc->base) + if (!doc->getBase()) { return; + } - gchar *const old_abs_base = calc_abs_doc_base(doc->base); + gchar *const old_abs_base = calc_abs_doc_base(doc->getBase()); gchar *const new_abs_base = calc_abs_doc_base(new_base); /* TODO: Should handle not just image but also: @@ -227,7 +228,7 @@ void Inkscape::XML::rebase_hrefs(SPDocument *const doc, gchar const *const new_b * * Note also that Inkscape only supports fragment hrefs (href="#pattern257") for many of these * cases. */ - GSList const *images = sp_document_get_resource_list(doc, "image"); + GSList const *images = doc->getResourceList("image"); for (GSList const *l = images; l != NULL; l = l->next) { Inkscape::XML::Node *ir = SP_OBJECT_REPR(l->data); diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp index b1320a4a3..5f7654ba8 100644 --- a/src/xml/repr-io.cpp +++ b/src/xml/repr-io.cpp @@ -1,5 +1,3 @@ -#define __SP_REPR_IO_C__ - /* * Dirty DOM-like tree * diff --git a/src/xml/repr-sorting.cpp b/src/xml/repr-sorting.cpp index df1d2cbb8..056236d33 100644 --- a/src/xml/repr-sorting.cpp +++ b/src/xml/repr-sorting.cpp @@ -3,18 +3,16 @@ #include "xml/repr.h" #include "xml/node-iterators.h" -static bool -same_repr(Inkscape::XML::Node &a, Inkscape::XML::Node &b) +static bool same_repr(Inkscape::XML::Node const &a, Inkscape::XML::Node const &b) { /* todo: I'm not certain that it's legal to take the address of a reference. Check the exact wording of the spec on this matter. */ return &a == &b; } -Inkscape::XML::Node * -LCA(Inkscape::XML::Node *a, Inkscape::XML::Node *b) +Inkscape::XML::Node const *LCA(Inkscape::XML::Node const *a, Inkscape::XML::Node const *b) { using Inkscape::Algorithms::longest_common_suffix; - Inkscape::XML::Node *ancestor = longest_common_suffix<Inkscape::XML::NodeParentIterator>( + Inkscape::XML::Node const *ancestor = longest_common_suffix<Inkscape::XML::NodeConstParentIterator>( a, b, NULL, &same_repr ); if ( ancestor && ancestor->type() != Inkscape::XML::DOCUMENT_NODE ) { @@ -24,22 +22,30 @@ LCA(Inkscape::XML::Node *a, Inkscape::XML::Node *b) } } -/** - * Returns a child of \a ancestor such that ret is itself an ancestor of \a descendent. - * - * The current version returns NULL if ancestor or descendent is NULL, though future versions may - * call g_log. Please update this comment if you rely on the current behaviour. - */ -Inkscape::XML::Node * -AncetreFils(Inkscape::XML::Node *descendent, Inkscape::XML::Node *ancestor) +Inkscape::XML::Node *LCA(Inkscape::XML::Node *a, Inkscape::XML::Node *b) { - if (descendent == NULL || ancestor == NULL) - return NULL; - if (sp_repr_parent(descendent) == ancestor) - return descendent; - return AncetreFils(sp_repr_parent(descendent), ancestor); + Inkscape::XML::Node const *tmp = LCA(const_cast<Inkscape::XML::Node const *>(a), const_cast<Inkscape::XML::Node const *>(b)); + return const_cast<Inkscape::XML::Node *>(tmp); } +Inkscape::XML::Node const *AncetreFils(Inkscape::XML::Node const *descendent, Inkscape::XML::Node const *ancestor) +{ + Inkscape::XML::Node const *result = 0; + if ( descendent && ancestor ) { + if (descendent->parent() == ancestor) { + result = descendent; + } else { + result = AncetreFils(descendent->parent(), ancestor); + } + } + return result; +} + +Inkscape::XML::Node *AncetreFils(Inkscape::XML::Node *descendent, Inkscape::XML::Node *ancestor) +{ + Inkscape::XML::Node const * tmp = AncetreFils(const_cast<Inkscape::XML::Node const*>(descendent), const_cast<Inkscape::XML::Node const*>(ancestor)); + return const_cast<Inkscape::XML::Node *>(tmp); +} /* Local Variables: diff --git a/src/xml/repr-sorting.h b/src/xml/repr-sorting.h index 7d5542f67..d560dfa26 100644 --- a/src/xml/repr-sorting.h +++ b/src/xml/repr-sorting.h @@ -10,6 +10,16 @@ #include "xml/xml-forward.h" Inkscape::XML::Node *LCA(Inkscape::XML::Node *a, Inkscape::XML::Node *b); +Inkscape::XML::Node const *LCA(Inkscape::XML::Node const *a, Inkscape::XML::Node const *b); + +/** + * Returns a child of \a ancestor such that ret is itself an ancestor of \a descendent. + * + * The current version returns NULL if ancestor or descendent is NULL, though future versions may + * call g_log. Please update this comment if you rely on the current behaviour. + */ +Inkscape::XML::Node const *AncetreFils(Inkscape::XML::Node const *descendent, Inkscape::XML::Node const *ancestor); + Inkscape::XML::Node *AncetreFils(Inkscape::XML::Node *descendent, Inkscape::XML::Node *ancestor); #endif // SEEN_XML_REPR_SOTRING_H diff --git a/src/xml/repr-util.cpp b/src/xml/repr-util.cpp index d310639ba..07a25ca6d 100644 --- a/src/xml/repr-util.cpp +++ b/src/xml/repr-util.cpp @@ -1,5 +1,3 @@ -#define __SP_REPR_UTIL_C__ - /** \file * Miscellaneous helpers for reprs. */ @@ -7,6 +5,7 @@ /* * Authors: * Lauris Kaplinski <lauris@ximian.com> + * Jon A. Cruz <jon@joncruz.org> * * Copyright (C) 1999-2000 Lauris Kaplinski * Copyright (C) 2000-2001 Ximian, Inc. @@ -354,8 +353,7 @@ long long int sp_repr_get_int_attribute(Inkscape::XML::Node *repr, char const *k * -1 first object's position is less than the second * @todo Rewrite this function's description to be understandable */ -int -sp_repr_compare_position(Inkscape::XML::Node *first, Inkscape::XML::Node *second) +int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second) { int p1, p2; if (sp_repr_parent(first) == sp_repr_parent(second)) { @@ -368,7 +366,7 @@ sp_repr_compare_position(Inkscape::XML::Node *first, Inkscape::XML::Node *second instance. */ // Find the lowest common ancestor(LCA) - Inkscape::XML::Node *ancestor = LCA(first, second); + Inkscape::XML::Node const *ancestor = LCA(first, second); g_assert(ancestor != NULL); if (ancestor == first) { @@ -433,40 +431,35 @@ sp_repr_lookup_child(Inkscape::XML::Node *repr, return NULL; } -/** - * @brief Find an element node with the given name - * - * This function searches the descendants of the specified node depth-first for - * the first XML node with the specified name. - * - * @param repr The node to start from - * @param name The name of the element node to find - * @param maxdepth Maximum search depth, or -1 for an unlimited depth - * @return A pointer to the matching Inkscape::XML::Node - * @relatesalso Inkscape::XML::Node - */ -Inkscape::XML::Node * -sp_repr_lookup_name( Inkscape::XML::Node *repr, gchar const *name, gint maxdepth ) +Inkscape::XML::Node const *sp_repr_lookup_name( Inkscape::XML::Node const *repr, gchar const *name, gint maxdepth ) { + Inkscape::XML::Node const *found = 0; g_return_val_if_fail(repr != NULL, NULL); g_return_val_if_fail(name != NULL, NULL); GQuark const quark = g_quark_from_string(name); - if ( (GQuark)repr->code() == quark ) return repr; - if ( maxdepth == 0 ) return NULL; - - // maxdepth == -1 means unlimited - if ( maxdepth == -1 ) maxdepth = 0; + if ( (GQuark)repr->code() == quark ) { + found = repr; + } else if ( maxdepth != 0 ) { + // maxdepth == -1 means unlimited + if ( maxdepth == -1 ) { + maxdepth = 0; + } - Inkscape::XML::Node *found = NULL; - for (Inkscape::XML::Node *child = repr->firstChild() ; child && !found; child = child->next() ) { - found = sp_repr_lookup_name( child, name, maxdepth-1 ); + for (Inkscape::XML::Node const *child = repr->firstChild() ; child && !found; child = child->next() ) { + found = sp_repr_lookup_name( child, name, maxdepth - 1 ); + } } - return found; } +Inkscape::XML::Node *sp_repr_lookup_name( Inkscape::XML::Node *repr, gchar const *name, gint maxdepth ) +{ + Inkscape::XML::Node const *found = sp_repr_lookup_name( const_cast<Inkscape::XML::Node *>(repr), name, maxdepth ); + return const_cast<Inkscape::XML::Node *>(found); +} + /** * Determine if the node is a 'title', 'desc' or 'metadata' element. */ diff --git a/src/xml/repr.cpp b/src/xml/repr.cpp index 4494d3fe6..0a384c9c1 100644 --- a/src/xml/repr.cpp +++ b/src/xml/repr.cpp @@ -1,5 +1,3 @@ -#define __SP_REPR_C__ - /** \file * A few non-inline functions of the C facade to Inkscape::XML::Node. */ diff --git a/src/xml/repr.h b/src/xml/repr.h index 3b8d532fd..bde3e533f 100644 --- a/src/xml/repr.h +++ b/src/xml/repr.h @@ -3,6 +3,7 @@ */ /* Authors: * Lauris Kaplinski <lauris@kaplinski.com> + * Jon A. Cruz <jon@joncruz.org> * * Copyright (C) 1999-2002 authors * Copyright (C) 2000-2002 Ximian, Inc. @@ -10,8 +11,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifndef __SP_REPR_H__ -#define __SP_REPR_H__ +#ifndef SEEN_SP_REPR_H +#define SEEN_SP_REPR_H #include <stdio.h> #include <glib/gtypes.h> @@ -137,12 +138,29 @@ double sp_repr_get_double_attribute(Inkscape::XML::Node *repr, gchar const *key, /// \deprecated Use sp_repr_get_int to check for success long long int sp_repr_get_int_attribute(Inkscape::XML::Node *repr, gchar const *key, long long int def); -int sp_repr_compare_position(Inkscape::XML::Node *first, Inkscape::XML::Node *second); +int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second); -/* Searching */ +// Searching +/** + * @brief Find an element node with the given name + * + * This function searches the descendants of the specified node depth-first for + * the first XML node with the specified name. + * + * @param repr The node to start from + * @param name The name of the element node to find + * @param maxdepth Maximum search depth, or -1 for an unlimited depth + * @return A pointer to the matching Inkscape::XML::Node + * @relatesalso Inkscape::XML::Node + */ Inkscape::XML::Node *sp_repr_lookup_name(Inkscape::XML::Node *repr, gchar const *name, gint maxdepth = -1); + +Inkscape::XML::Node const *sp_repr_lookup_name(Inkscape::XML::Node const *repr, + gchar const *name, + gint maxdepth = -1); + Inkscape::XML::Node *sp_repr_lookup_child(Inkscape::XML::Node *repr, gchar const *key, gchar const *value); @@ -152,7 +170,7 @@ inline Inkscape::XML::Node *sp_repr_document_first_child(Inkscape::XML::Document return const_cast<Inkscape::XML::Node *>(doc->firstChild()); } -#endif +#endif // SEEN_SP_REPR_H /* Local Variables: mode:c++ |
