X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fxml%2Frepr-util.cpp;h=528902fef6505edc8609b29262f960465be0a5cf;hb=dc04c2a317d9e7ea799d78d5b4e9bf28997ca46f;hp=83231e5da54586d686949ca60b97112382b84690;hpb=8b622243be740efaa0e3966f19eb69d97e87c009;p=inkscape.git diff --git a/src/xml/repr-util.cpp b/src/xml/repr-util.cpp index 83231e5da..528902fef 100644 --- a/src/xml/repr-util.cpp +++ b/src/xml/repr-util.cpp @@ -20,16 +20,16 @@ #include #if HAVE_STRING_H -# include +# include #endif #if HAVE_STDLIB_H -# include +# include #endif #include - +#include <2geom/point.h> #include "svg/stringstream.h" #include "svg/css-ostringstream.h" @@ -149,7 +149,7 @@ static SPXMLNs *namespaces=NULL; static void sp_xml_ns_register_defaults() { - static SPXMLNs defaults[9]; + static SPXMLNs defaults[10]; defaults[0].uri = g_quark_from_static_string(SP_SODIPODI_NS_URI); defaults[0].prefix = g_quark_from_static_string("sodipodi"); @@ -194,7 +194,13 @@ sp_xml_ns_register_defaults() defaults[8].uri = g_quark_from_static_string("http://inkscape.sourceforge.net/DTD/s odipodi-0.dtd"); defaults[8].prefix = g_quark_from_static_string("sodipodi"); - defaults[8].next = NULL; + defaults[8].next = &defaults[9]; + + // This namespace URI is being phased out by Creative Commons + + defaults[9].uri = g_quark_from_static_string(SP_OLD_CC_NS_URI); + defaults[9].prefix = g_quark_from_static_string("cc"); + defaults[9].next = NULL; namespaces = &defaults[0]; } @@ -319,7 +325,7 @@ double sp_repr_get_double_attribute(Inkscape::XML::Node *repr, char const *key, return g_ascii_strtod(result, NULL); } -int sp_repr_get_int_attribute(Inkscape::XML::Node *repr, char const *key, int def) +long long int sp_repr_get_int_attribute(Inkscape::XML::Node *repr, char const *key, long long int def) { char *result; @@ -330,7 +336,7 @@ int sp_repr_get_int_attribute(Inkscape::XML::Node *repr, char const *key, int de if (result == NULL) return def; - return atoi(result); + return atoll(result); } /** @@ -338,6 +344,7 @@ int sp_repr_get_int_attribute(Inkscape::XML::Node *repr, char const *key, int de * 0 positions are equivalent * 1 first object's position is greater than the second * -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) @@ -391,7 +398,15 @@ sp_repr_compare_position(Inkscape::XML::Node *first, Inkscape::XML::Node *second } /** - * lookup child by \a key, \a value. + * @brief Find an element node using an unique attribute + * + * This function returns the first child of the specified node that has the attribute + * @c key equal to @c value. Note that this function does not recurse. + * + * @param repr The node to start from + * @param key The name of the attribute to use for comparisons + * @param value The value of the attribute to look for + * @relatesalso Inkscape::XML::Node */ Inkscape::XML::Node * sp_repr_lookup_child(Inkscape::XML::Node *repr, @@ -411,11 +426,16 @@ sp_repr_lookup_child(Inkscape::XML::Node *repr, } /** - * \brief Recursively find the Inkscape::XML::Node matching the given XML name. - * \return A pointer to the matching Inkscape::XML::Node - * \param repr The Inkscape::XML::Node to start from - * \param name The desired XML name - * + * @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 ) @@ -439,6 +459,22 @@ sp_repr_lookup_name( Inkscape::XML::Node *repr, gchar const *name, gint maxdepth return found; } +/** + * Determine if the node is a 'title', 'desc' or 'metadata' element. + */ +bool +sp_repr_is_meta_element(const Inkscape::XML::Node *node) +{ + if (node == NULL) return false; + if (node->type() != Inkscape::XML::ELEMENT_NODE) return false; + gchar const *name = node->name(); + if (name == NULL) return false; + if (!std::strcmp(name, "svg:title")) return true; + if (!std::strcmp(name, "svg:desc")) return true; + if (!std::strcmp(name, "svg:metadata")) return true; + return false; +} + /** * Parses the boolean value of an attribute "key" in repr and sets val accordingly, or to FALSE if * the attr is not set. @@ -570,6 +606,41 @@ sp_repr_set_svg_double(Inkscape::XML::Node *repr, gchar const *key, double val) return true; } +unsigned sp_repr_set_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point const & val) +{ + g_return_val_if_fail(repr != NULL, FALSE); + g_return_val_if_fail(key != NULL, FALSE); + + Inkscape::SVGOStringStream os; + os << val[Geom::X] << "," << val[Geom::Y]; + + repr->setAttribute(key, os.str().c_str()); + return true; +} + +unsigned int +sp_repr_get_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point *val) +{ + g_return_val_if_fail(repr != NULL, FALSE); + g_return_val_if_fail(key != NULL, FALSE); + g_return_val_if_fail(val != NULL, FALSE); + + gchar const *v = repr->attribute(key); + + gchar ** strarray = g_strsplit(v, ",", 2); + + if (strarray && strarray[0] && strarray[1]) { + double newx, newy; + newx = g_ascii_strtod(strarray[0], NULL); + newy = g_ascii_strtod(strarray[1], NULL); + g_strfreev (strarray); + *val = Geom::Point(newx, newy); + return TRUE; + } + + g_strfreev (strarray); + return FALSE; +} /* Local Variables: