summaryrefslogtreecommitdiffstats
path: root/src/xml
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2013-03-29 23:52:42 +0000
committerMarkus Engel <markus.engel@tum.de>2013-03-29 23:52:42 +0000
commita168040d5a452544328a1e6ad35aaac351f94d44 (patch)
treefae1ba829f543a473da281bd5fa6e4deabbf6912 /src/xml
parentRemoved function pointers from SPObject and subclasses. (diff)
parentDutch translation update (diff)
downloadinkscape-a168040d5a452544328a1e6ad35aaac351f94d44.tar.gz
inkscape-a168040d5a452544328a1e6ad35aaac351f94d44.zip
merged from trunk
(bzr r11608.1.56)
Diffstat (limited to 'src/xml')
-rw-r--r--src/xml/Makefile_insert3
-rw-r--r--src/xml/composite-node-observer.h2
-rw-r--r--src/xml/event-fns.h2
-rw-r--r--src/xml/node-fns.cpp1
-rw-r--r--src/xml/quote.cpp1
-rw-r--r--src/xml/rebase-hrefs.h2
-rw-r--r--src/xml/repr-css.cpp56
-rw-r--r--src/xml/repr-io.cpp10
-rw-r--r--src/xml/repr-sorting.cpp1
-rw-r--r--src/xml/repr-util.cpp65
-rw-r--r--src/xml/repr.h21
-rw-r--r--src/xml/simple-node.cpp7
12 files changed, 58 insertions, 113 deletions
diff --git a/src/xml/Makefile_insert b/src/xml/Makefile_insert
index b10f2448b..da55d7f7e 100644
--- a/src/xml/Makefile_insert
+++ b/src/xml/Makefile_insert
@@ -40,8 +40,7 @@ ink_common_sources += \
xml/subtree.cpp \
xml/subtree.h \
xml/text-node.h \
- xml/invalid-operation-exception.h \
- xml/xml-forward.h
+ xml/invalid-operation-exception.h
# ######################
# ### CxxTest stuff ####
diff --git a/src/xml/composite-node-observer.h b/src/xml/composite-node-observer.h
index 96825d607..3e4b1673a 100644
--- a/src/xml/composite-node-observer.h
+++ b/src/xml/composite-node-observer.h
@@ -23,7 +23,7 @@ namespace Inkscape {
namespace XML {
-class NodeEventVector;
+struct NodeEventVector;
/**
* @brief An observer that relays notifications to multiple other observers
diff --git a/src/xml/event-fns.h b/src/xml/event-fns.h
index 65c65c48c..5e3b43ad8 100644
--- a/src/xml/event-fns.h
+++ b/src/xml/event-fns.h
@@ -4,7 +4,7 @@
namespace Inkscape {
namespace XML {
-class Document;
+struct Document;
class Event;
class NodeObserver;
diff --git a/src/xml/node-fns.cpp b/src/xml/node-fns.cpp
index 20e9fbc38..eb3870978 100644
--- a/src/xml/node-fns.cpp
+++ b/src/xml/node-fns.cpp
@@ -9,6 +9,7 @@
#include "xml/node-iterators.h"
#include "util/find-if-before.h"
+#include "node-fns.h"
namespace Inkscape {
namespace XML {
diff --git a/src/xml/quote.cpp b/src/xml/quote.cpp
index 51f9ffb97..030a6c764 100644
--- a/src/xml/quote.cpp
+++ b/src/xml/quote.cpp
@@ -13,6 +13,7 @@
#include <cstring>
#include <glib.h>
+#include "quote.h"
/** \return strlen(xml_quote_strdup(\a val)) (without doing the malloc).
diff --git a/src/xml/rebase-hrefs.h b/src/xml/rebase-hrefs.h
index adb09e52a..5baf96516 100644
--- a/src/xml/rebase-hrefs.h
+++ b/src/xml/rebase-hrefs.h
@@ -4,7 +4,7 @@
#include <glib.h>
#include "util/list.h"
#include "xml/attribute-record.h"
-struct SPDocument;
+class SPDocument;
namespace Inkscape {
namespace XML {
diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp
index 679ec73cb..24e2db9e1 100644
--- a/src/xml/repr-css.cpp
+++ b/src/xml/repr-css.cpp
@@ -27,6 +27,7 @@
#include "xml/repr.h"
#include "xml/simple-document.h"
#include "xml/simple-node.h"
+#include "xml/sp-css-attr.h"
#include "style.h"
#include "libcroco/cr-sel-eng.h"
@@ -270,10 +271,9 @@ double sp_repr_css_double_property(SPCSSAttr *css, gchar const *name, double def
/**
* Write a style attribute string from a list of properties stored in an SPCSAttr object.
*/
-gchar *sp_repr_css_write_string(SPCSSAttr *css)
+void sp_repr_css_write_string(SPCSSAttr *css, Glib::ustring &str)
{
- Glib::ustring buffer;
-
+ str.clear();
for ( List<AttributeRecord const> iter = css->attributeList() ;
iter ; ++iter )
{
@@ -281,28 +281,21 @@ gchar *sp_repr_css_write_string(SPCSSAttr *css)
continue;
}
- buffer.append(g_quark_to_string(iter->key));
- buffer.push_back(':');
+ str.append(g_quark_to_string(iter->key));
+ str.push_back(':');
if (!strcmp(g_quark_to_string(iter->key), "font-family")
|| !strcmp(g_quark_to_string(iter->key), "-inkscape-font-specification")) {
// we only quote font-family/font-specification, as SPStyle does
- gchar *t = g_strdup (iter->value);
- g_free (t);
- gchar *val_quoted = css2_escape_quote (iter->value);
- if (val_quoted) {
- buffer.append(val_quoted);
- g_free (val_quoted);
- }
+ Glib::ustring val_quoted = css2_escape_quote (iter->value);
+ str.append(val_quoted);
} else {
- buffer.append(iter->value); // unquoted
+ str.append(iter->value); // unquoted
}
if (rest(iter)) {
- buffer.push_back(';');
+ str.push_back(';');
}
}
-
- return (buffer.empty() ? NULL : g_strdup (buffer.c_str()));
}
/**
@@ -314,17 +307,16 @@ void sp_repr_css_set(Node *repr, SPCSSAttr *css, gchar const *attr)
g_assert(css != NULL);
g_assert(attr != NULL);
- gchar *value = sp_repr_css_write_string(css);
+ Glib::ustring value;
+ sp_repr_css_write_string(css, value);
/*
* If the new value is different from the old value, this will sometimes send a signal via
* CompositeNodeObserver::notiftyAttributeChanged() which results in calling
- * SPObject::sp_object_repr_attr_changed and thus updates the object's SPStyle. This update
+ * SPObject::repr_attr_changed and thus updates the object's SPStyle. This update
* results in another call to repr->setAttribute().
*/
- repr->setAttribute(attr, value);
-
- if (value) g_free (value);
+ repr->setAttribute(attr, value.c_str());
}
/**
@@ -360,7 +352,8 @@ static void sp_repr_css_merge_from_decl(SPCSSAttr *css, CRDeclaration const *con
guchar *const str_value_unsigned = cr_term_to_string(decl->value);
gchar *const str_value = reinterpret_cast<gchar *>(str_value_unsigned);
gchar *value_unquoted = attribute_unquote (str_value); // libcroco returns strings quoted in ""
- gchar *units = NULL;
+ Glib::ustring value_unquoted2 = value_unquoted ? value_unquoted : Glib::ustring();
+ Glib::ustring units;
/*
* Problem with parsing of units em and ex, like font-size "1.2em" and "3.4ex"
@@ -369,18 +362,22 @@ static void sp_repr_css_merge_from_decl(SPCSSAttr *css, CRDeclaration const *con
*
* HACK for now is to strip off em and ex units and add them back at the end
*/
- int l = strlen(value_unquoted);
- if (!strncmp(&value_unquoted[l-2], "em", 2) ||
- !strncmp(&value_unquoted[l-2], "ex", 2)) {
- units = g_strndup(&value_unquoted[l-2], 2);
- value_unquoted = g_strndup(value_unquoted, l-2);
+ int le = value_unquoted2.length();
+ if (le > 2) {
+ units = value_unquoted2.substr(le-2, 2);
+ if ((units == "em") || (units == "ex")) {
+ value_unquoted2 = value_unquoted2.substr(0, le-2);
+ }
+ else {
+ units.clear();
+ }
}
// libcroco uses %.17f for formatting... leading to trailing zeros or small rounding errors.
// CSSOStringStream is used here to write valid CSS (as in sp_style_write_string). This has
// the additional benefit of respecting the numerical precission set in the SVG Output
// preferences. We assume any numerical part comes first (if not, the whole string is copied).
- std::stringstream ss( value_unquoted );
+ std::stringstream ss( value_unquoted2 );
double number = 0;
std::string characters;
std::string temp;
@@ -394,10 +391,9 @@ static void sp_repr_css_merge_from_decl(SPCSSAttr *css, CRDeclaration const *con
Inkscape::CSSOStringStream os;
if( number_valid ) os << number;
os << characters;
- if (units) {
+ if (!units.empty()) {
os << units;
//g_message("sp_repr_css_merge_from_decl looks like em or ex units %s --> %s", str_value, os.str().c_str());
- g_free(units);
}
((Node *) css)->setAttribute(decl->property->stryng->str, os.str().c_str(), false);
g_free(value_unquoted);
diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp
index 29a5b4a78..1b6116936 100644
--- a/src/xml/repr-io.cpp
+++ b/src/xml/repr-io.cpp
@@ -37,6 +37,8 @@
#include "preferences.h"
+#include <glibmm/miscutils.h>
+
using Inkscape::IO::Writer;
using Inkscape::Util::List;
using Inkscape::Util::cons;
@@ -297,12 +299,18 @@ Document *sp_repr_read_file (const gchar * filename, const gchar *default_ns)
XmlSource src;
if ( (src.setFile(filename) == 0) ) {
+ int parse_options = XML_PARSE_HUGE; // do not use XML_PARSE_NOENT ! see bug lp:1025185
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ bool allowNetAccess = prefs->getBool("/options/externalresources/xml/allow_net_access", false);
+ if (!allowNetAccess) {
+ parse_options |= XML_PARSE_NONET;
+ }
doc = xmlReadIO( XmlSource::readCb,
XmlSource::closeCb,
&src,
localFilename,
src.getEncoding(),
- XML_PARSE_NOENT | XML_PARSE_HUGE);
+ parse_options);
}
}
diff --git a/src/xml/repr-sorting.cpp b/src/xml/repr-sorting.cpp
index fd485925b..09a39acb2 100644
--- a/src/xml/repr-sorting.cpp
+++ b/src/xml/repr-sorting.cpp
@@ -2,6 +2,7 @@
#include "util/longest-common-suffix.h"
#include "xml/repr.h"
#include "xml/node-iterators.h"
+#include "repr-sorting.h"
static bool same_repr(Inkscape::XML::Node const &a, Inkscape::XML::Node const &b)
{
diff --git a/src/xml/repr-util.cpp b/src/xml/repr-util.cpp
index 5b8ab12ae..6ea20b87a 100644
--- a/src/xml/repr-util.cpp
+++ b/src/xml/repr-util.cpp
@@ -69,71 +69,6 @@ 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 sp_xml_dtoa(gchar *buf, double val, unsigned int tprec, unsigned int fprec, unsigned int padf)
-{
- double dival, fval, epsilon;
- int idigits, ival, i;
- i = 0;
- if (val < 0.0) {
- buf[i++] = '-';
- val = -val;
- }
- /* Determine number of integral digits */
- if (val >= 1.0) {
- idigits = (int) floor(log10(val));
- } else {
- idigits = 0;
- }
- /* Determine the actual number of fractional digits */
- fprec = MAX(fprec, tprec - idigits);
- /* Find epsilon */
- epsilon = 0.5 * pow(10.0, - (double) fprec);
- /* Round value */
- val += epsilon;
- /* Extract integral and fractional parts */
- dival = floor(val);
- ival = (int) dival;
- fval = val - dival;
- /* Write integra */
- if (ival > 0) {
- char c[32];
- int j;
- j = 0;
- while (ival > 0) {
- c[32 - (++j)] = '0' + (ival % 10);
- ival /= 10;
- }
- memcpy(buf + i, &c[32 - j], j);
- i += j;
- tprec -= j;
- } else {
- buf[i++] = '0';
- tprec -= 1;
- }
- if ((fprec > 0) && (padf || (fval > epsilon))) {
- buf[i++] = '.';
- while ((fprec > 0) && (padf || (fval > epsilon))) {
- fval *= 10.0;
- dival = floor(fval);
- fval -= dival;
- buf[i++] = '0' + (int) dival;
- fprec -= 1;
- }
-
- }
- buf[i] = 0;
- return i;
-}
-
-
-
-/*#####################
# MAIN
#####################*/
diff --git a/src/xml/repr.h b/src/xml/repr.h
index 86a798e3e..52f07d11f 100644
--- a/src/xml/repr.h
+++ b/src/xml/repr.h
@@ -14,16 +14,11 @@
#ifndef SEEN_SP_REPR_H
#define SEEN_SP_REPR_H
-#include <stdio.h>
#include <glib.h>
-#include "gc-anchored.h"
+#include <glibmm/quark.h>
#include "xml/node.h"
#include "xml/document.h"
-#include "xml/sp-css-attr.h"
-#include "io/inkscapestream.h"
-
-#include <2geom/forward.h>
#define SP_SODIPODI_NS_URI "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
#define SP_BROKEN_SODIPODI_NS_URI "http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd"
@@ -35,6 +30,18 @@
#define SP_OLD_CC_NS_URI "http://web.resource.org/cc/"
#define SP_DC_NS_URI "http://purl.org/dc/elements/1.1/"
+class SPCSSAttr;
+
+namespace Inkscape {
+namespace IO {
+class Writer;
+} // namespace IO
+} // namespace Inkscape
+
+namespace Geom {
+class Point;
+}
+
/* SPXMLNs */
char const *sp_xml_ns_uri_prefix(gchar const *uri, gchar const *suggested);
char const *sp_xml_ns_prefix_uri(gchar const *prefix);
@@ -79,7 +86,7 @@ void sp_repr_css_unset_property(SPCSSAttr *css, gchar const *name);
bool sp_repr_css_property_is_unset(SPCSSAttr *css, gchar const *name);
double sp_repr_css_double_property(SPCSSAttr *css, gchar const *name, double defval);
-gchar *sp_repr_css_write_string(SPCSSAttr *css);
+void sp_repr_css_write_string(SPCSSAttr *css, Glib::ustring &str);
void sp_repr_css_set(Inkscape::XML::Node *repr, SPCSSAttr *css, gchar const *key);
void sp_repr_css_merge(SPCSSAttr *dst, SPCSSAttr *src);
void sp_repr_css_attr_add_from_string(SPCSSAttr *css, const gchar *data);
diff --git a/src/xml/simple-node.cpp b/src/xml/simple-node.cpp
index c197d648b..4965f81c8 100644
--- a/src/xml/simple-node.cpp
+++ b/src/xml/simple-node.cpp
@@ -318,8 +318,7 @@ SimpleNode::setAttribute(gchar const *name, gchar const *value, bool const /*is_
// Check usefulness of attributes on elements in the svg namespace, optionally don't add them to tree.
Glib::ustring element = g_quark_to_string(_name);
- //g_warning("setAttribute: %s: %s: %s", element.c_str(), name, value);
-
+ // g_message("setAttribute: %s: %s: %s", element.c_str(), name, value);
gchar* cleaned_value = g_strdup( value );
// Only check elements in SVG name space and don't block setting attribute to NULL.
@@ -347,7 +346,7 @@ SimpleNode::setAttribute(gchar const *name, gchar const *value, bool const /*is_
// tree (and thus has no parent), default values will not be tested.
if( !strcmp( name, "style" ) && (flags >= SP_ATTR_CLEAN_STYLE_WARN) ) {
g_free( cleaned_value );
- cleaned_value = sp_attribute_clean_style( this, value, flags );
+ cleaned_value = g_strdup( sp_attribute_clean_style( this, value, flags ).c_str() );
// if( g_strcmp0( value, cleaned_value ) ) {
// g_warning( "SimpleNode::setAttribute: %s", id.c_str() );
// g_warning( " original: %s", value);
@@ -401,9 +400,7 @@ SimpleNode::setAttribute(gchar const *name, gchar const *value, bool const /*is_
_observers.notifyAttributeChanged(*this, key, old_value, new_value);
//g_warning( "setAttribute notified: %s: %s: %s: %s", name, element.c_str(), old_value, new_value );
}
-
g_free( cleaned_value );
-
}
void SimpleNode::addChild(Node *generic_child, Node *generic_ref) {