Code

Add translator hint.
[inkscape.git] / src / xml / repr-util.cpp
index 75ae692af5c39ba2291ac47ee508f6488e180087..42b957d438da11b857b5266032c5a9ee68d1b9bd 100644 (file)
@@ -149,7 +149,7 @@ static SPXMLNs *namespaces=NULL;
 static void
 sp_xml_ns_register_defaults()
 {
-    static SPXMLNs defaults[7];
+    static SPXMLNs defaults[9];
 
     defaults[0].uri = g_quark_from_static_string(SP_SODIPODI_NS_URI);
     defaults[0].prefix = g_quark_from_static_string("sodipodi");
@@ -177,7 +177,24 @@ sp_xml_ns_register_defaults()
 
     defaults[6].uri = g_quark_from_static_string(SP_DC_NS_URI);
     defaults[6].prefix = g_quark_from_static_string("dc");
-    defaults[6].next = NULL;
+    defaults[6].next = &defaults[7];
+
+    // 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:
+
+    defaults[7].uri = g_quark_from_static_string(SP_BROKEN_SODIPODI_NS_URI);
+    defaults[7].prefix = g_quark_from_static_string("sodipodi");
+    defaults[7].next = &defaults[8];
+
+    // "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");
+    defaults[8].prefix = g_quark_from_static_string("sodipodi");
+    defaults[8].next = NULL;
 
     namespaces = &defaults[0];
 }
@@ -212,7 +229,6 @@ sp_xml_ns_auto_prefix(char const *uri)
 gchar const *
 sp_xml_ns_uri_prefix(gchar const *uri, gchar const *suggested)
 {
-    SPXMLNs *iter;
     char const *prefix;
 
     if (!uri) return NULL;
@@ -223,32 +239,46 @@ sp_xml_ns_uri_prefix(gchar const *uri, gchar const *suggested)
 
     GQuark const key = g_quark_from_string(uri);
     prefix = NULL;
-    for ( iter = namespaces ; iter ; iter = iter->next ) {
+    for ( SPXMLNs *iter=namespaces ; iter ; iter = iter->next ) {
         if ( iter->uri == key ) {
             prefix = g_quark_to_string(iter->prefix);
             break;
         }
     }
+
     if (!prefix) {
-        char const *new_prefix;
+        char *new_prefix;
         SPXMLNs *ns;
         if (suggested) {
-            new_prefix = suggested;
+            GQuark const prefix_key=g_quark_from_string(suggested);
+
+            SPXMLNs *found=namespaces;
+            while ( found && found->prefix != prefix_key ) {
+                found = found->next;
+            }
+
+            if (found) { // prefix already used?
+                new_prefix = sp_xml_ns_auto_prefix(uri);
+            } else { // safe to use suggested
+                new_prefix = g_strdup(suggested);
+            }
         } else {
             new_prefix = sp_xml_ns_auto_prefix(uri);
         }
+
         ns = g_new(SPXMLNs, 1);
-        if (ns) {
-            ns->uri = g_quark_from_string(uri);
-            ns->prefix = g_quark_from_string(new_prefix);
-            ns->next = namespaces;
-            namespaces = ns;
-            prefix = g_quark_to_string(ns->prefix);
-        }
-        if (!suggested) {
-            g_free((char *)new_prefix);
-        }
+        g_assert( ns != NULL );
+        ns->uri = g_quark_from_string(uri);
+        ns->prefix = g_quark_from_string(new_prefix);
+
+        g_free(new_prefix);
+
+        ns->next = namespaces;
+        namespaces = ns;
+
+        prefix = g_quark_to_string(ns->prefix);
     }
+
     return prefix;
 }
 
@@ -289,7 +319,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;
 
@@ -300,7 +330,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);
 }
 
 /**