repr-util.cpp revision 8b622243be740efaa0e3966f19eb69d97e87c009
#define __SP_REPR_UTIL_C__
/** \file
* Miscellaneous helpers for reprs.
*/
/*
* Authors:
* Lauris Kaplinski <lauris@ximian.com>
*
* 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 <string.h>
#endif
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
#include <glib.h>
#include "svg/stringstream.h"
#include "svg/css-ostringstream.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);
/*#####################
# UTILITY
#####################*/
/**
* Locale-independent double to string conversion
*/
unsigned int
{
i = 0;
if (val < 0.0) {
buf[i++] = '-';
}
/* Determine number of integral digits */
if (val >= 1.0) {
} else {
idigits = 0;
}
/* Determine the actual number of fractional digits */
/* Find epsilon */
/* Round value */
/* Extract integral and fractional parts */
/* Write integra */
if (ival > 0) {
char c[32];
int j;
j = 0;
while (ival > 0) {
ival /= 10;
}
i += j;
tprec -= j;
} else {
buf[i++] = '0';
tprec -= 1;
}
buf[i++] = '.';
fval *= 10.0;
fprec -= 1;
}
}
buf[i] = 0;
return i;
}
/*#####################
# MAIN
#####################*/
/**
* SPXMLNs
*/
/*
* There are the prefixes to use for the XML namespaces defined
* in repr.h
*/
static void
{
// 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[8].uri = g_quark_from_static_string("http://inkscape.sourceforge.net/DTD/s odipodi-0.dtd");
namespaces = &defaults[0];
}
char *
sp_xml_ns_auto_prefix(char const *uri)
{
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;
}
gchar const *
{
char const *prefix;
if (!namespaces) {
}
break;
}
}
if (!prefix) {
char *new_prefix;
if (suggested) {
}
if (found) { // prefix already used?
} else { // safe to use suggested
}
} else {
}
namespaces = ns;
}
return prefix;
}
gchar const *
{
char const *uri;
if (!namespaces) {
}
break;
}
}
return uri;
}
{
char *result;
}
{
char *result;
}
/**
* 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
*/
int
{
/* 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 */
}
/**
* lookup child by \a key, \a value.
*/
{
if ( child_value == value ||
{
return child;
}
}
return NULL;
}
/**
* \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
*
*/
{
// maxdepth == -1 means unlimited
}
return found;
}
/**
* 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.
*/
unsigned int
{
gchar const *v;
if (v != NULL) {
if (!g_strcasecmp(v, "true") ||
!g_strcasecmp(v, "yes" ) ||
!g_strcasecmp(v, "y" ) ||
(atoi(v) != 0)) {
} else {
}
return TRUE;
} else {
return FALSE;
}
}
unsigned int
{
gchar const *v;
if (v != NULL) {
return TRUE;
}
return FALSE;
}
unsigned int
{
gchar const *v;
if (v != NULL) {
return TRUE;
}
return FALSE;
}
unsigned int
{
return true;
}
unsigned int
{
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.
*/
unsigned int
{
return true;
}
/**
* For attributes where an exponent is allowed.
*
* Not suitable for property attributes (fill-opacity, font-size etc.).
*/
unsigned int
{
return true;
}
/*
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:encoding=utf-8:textwidth=99 :