/**
* @file
* Miscellaneous helpers for reprs.
*/
/*
* Authors:
* Lauris Kaplinski <lauris@ximian.com>
* Jon A. Cruz <jon@joncruz.org>
*
* Copyright (C) 1999-2000 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
* g++ port Copyright (C) 2003 Nathan Hurst
*
* Licensed under GNU GPL
*/
#include "config.h"
#include <math.h>
#if HAVE_STRING_H
# include <cstring>
#endif
#if HAVE_STDLIB_H
# include <cstdlib>
#endif
#include <glib.h>
#include "svg/stringstream.h"
#include "svg/css-ostringstream.h"
#include "svg/svg-length.h"
#include "xml/repr-sorting.h"
struct SPXMLNs {
};
/*#####################
# DEFINITIONS
#####################*/
#ifndef FALSE
# define FALSE 0
#endif
#ifndef TRUE
#endif
#ifndef MAX
# define MAX(a,b) (((a) < (b)) ? (b) : (a))
#endif
/*#####################
# FORWARD DECLARATIONS
#####################*/
static void sp_xml_ns_register_defaults();
static char *sp_xml_ns_auto_prefix(char const *uri);
/*#####################
# MAIN
#####################*/
/**
* SPXMLNs
*/
/*
* There are the prefixes to use for the XML namespaces defined
* in repr.h
*/
static void sp_xml_ns_register_defaults()
{
// Inkscape versions prior to 0.44 would write this namespace
// URI instead of the correct sodipodi namespace; by adding this
// entry to the table last (where it gets used for URI -> prefix
// lookups, but not prefix -> URI lookups), we effectively transfer
// elements in this namespace to the correct sodipodi namespace:
// "Duck prion"
// This URL became widespread due to a bug in versions <= 0.43
defaults[9].uri = g_quark_from_static_string("http://inkscape.sourceforge.net/DTD/s odipodi-0.dtd");
// This namespace URI is being phased out by Creative Commons
namespaces = &defaults[0];
}
{
char *new_prefix;
}
start = "ns";
}
if (sp_xml_ns_prefix_uri(new_prefix)) {
char *temp;
int counter=0;
do {
} while (sp_xml_ns_prefix_uri(temp));
new_prefix = temp;
}
return new_prefix;
}
{
char const *prefix;
if (!namespaces) {
}
break;
}
}
if (!prefix) {
char *new_prefix;
if (suggested) {
while (found) {
}
else {
break;
}
}
if (found) { // prefix already used?
} else { // safe to use suggested
}
} else {
}
namespaces = ns;
}
return prefix;
}
{
char const *uri;
if (!namespaces) {
}
break;
}
}
return uri;
}
/**
* Works for different-parent objects, so long as they have a common ancestor. Return value:
* 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
*/
{
/* Basic case - first and second have same parent */
} else {
/* Special case - the two objects have different parents. They
could be in different groups or on different layers for
instance. */
// Find the lowest common ancestor(LCA)
return 1;
return -1;
} else {
}
}
return 0;
/* effic: Assuming that the parent--child relationship is consistent
(i.e. that the parent really does contain first and second among
its list of children), it should be equivalent to walk along the
children and see which we encounter first (returning 0 iff first
== second).
Given that this function is used solely for sorting, we can use a
similar approach to do the sort: gather the things to be sorted,
into an STL vector (to allow random access and faster
traversals). Do a single pass of the parent's children; for each
child, do a pass on whatever items in the vector we haven't yet
encountered. If the child is found, then swap it to the
beginning of the yet-unencountered elements of the vector.
Continue until no more than one remains unencountered. --
pjrm */
}
bool sp_repr_compare_position_bool(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second){
}
/**
* 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
*/
{
if ( (child_value == value) ||
{
return child;
}
}
return NULL;
}
Inkscape::XML::Node const *sp_repr_lookup_name( Inkscape::XML::Node const *repr, gchar const *name, gint maxdepth )
{
} else if ( maxdepth != 0 ) {
// maxdepth == -1 means unlimited
if ( maxdepth == -1 ) {
maxdepth = 0;
}
for (Inkscape::XML::Node const *child = repr->firstChild() ; child && !found; child = child->next() ) {
}
}
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 const *>(repr), name, maxdepth );
}
std::vector<Inkscape::XML::Node const *> sp_repr_lookup_name_many( Inkscape::XML::Node const *repr, gchar const *name, gint maxdepth )
{
}
if ( maxdepth != 0 ) {
// maxdepth == -1 means unlimited
if ( maxdepth == -1 ) {
maxdepth = 0;
}
}
}
return nodes;
}
/**
* Determine if the node is a 'title', 'desc' or 'metadata' element.
*/
{
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.
*
* \return TRUE if the attr was set, FALSE otherwise.
*/
{
gchar const *v;
if (v != NULL) {
if (!g_ascii_strcasecmp(v, "true") ||
!g_ascii_strcasecmp(v, "yes" ) ||
!g_ascii_strcasecmp(v, "y" ) ||
(atoi(v) != 0)) {
} else {
}
return TRUE;
} else {
return FALSE;
}
}
{
gchar const *v;
if (v != NULL) {
return TRUE;
}
return FALSE;
}
{
if (v != NULL) {
return TRUE;
}
return FALSE;
}
{
return true;
}
{
gchar c[32];
return true;
}
/**
* Set a property attribute to \a val [slightly rounded], in the format
* required for CSS properties: in particular, it never uses exponent
* notation.
*/
{
return true;
}
/**
* For attributes where an exponent is allowed.
*
* Not suitable for property attributes (fill-opacity, font-size etc.).
*/
{
return true;
}
/**
* For attributes where an exponent is allowed.
*
* Not suitable for property attributes.
*/
{
return true;
}
{
return true;
}
{
return TRUE;
}
return FALSE;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :