summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1857b67)
raw | patch | inline | side by side (parent: 1857b67)
author | joncruz <joncruz@users.sourceforge.net> | |
Sun, 20 Sep 2009 00:12:39 +0000 (00:12 +0000) | ||
committer | joncruz <joncruz@users.sourceforge.net> | |
Sun, 20 Sep 2009 00:12:39 +0000 (00:12 +0000) |
src/ui/dialog/document-properties.cpp | patch | blob | history |
index 423778276e8fd32752bbe40a0909b0e6225882a3..105d220a968f84f953f0d0cbbcd88a7ff17d5374 100644 (file)
_menu.show_all();
}
-void
-DocumentProperties::linkSelectedProfile()
+/**
+ * Cleans up name to remove disallowed characters.
+ * Some discussion at http://markmail.org/message/bhfvdfptt25kgtmj
+ * Allowed ASCII first characters: ':', 'A'-'Z', '_', 'a'-'z'
+ * Allowed ASCII remaining chars add: '-', '.', '0'-'9',
+ *
+ * @param str the string to clean up.
+ */
+static void sanitizeName( Glib::ustring& str )
+{
+ if (str.size() > 1) {
+ char val = str.at(0);
+ if (((val < 'A') || (val > 'Z'))
+ && ((val < 'a') || (val > 'z'))
+ && (val != '_')
+ && (val != ':')) {
+ str.replace(0, 1, "_");
+ }
+ for (Glib::ustring::size_type i = 1; i < str.size(); i++) {
+ char val = str.at(i);
+ if (((val < 'A') || (val > 'Z'))
+ && ((val < 'a') || (val > 'z'))
+ && ((val < '0') || (val > '9'))
+ && (val != '_')
+ && (val != ':')
+ && (val != '-')
+ && (val != '.')) {
+ str.replace(i, 1, "_");
+ }
+ }
+ }
+}
+
+void DocumentProperties::linkSelectedProfile()
{
//store this profile in the SVG document (create <color-profile> element in the XML)
// TODO remove use of 'active' desktop
}
Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
Inkscape::XML::Node *cprofRepr = xml_doc->createElement("svg:color-profile");
- cprofRepr->setAttribute("name", (gchar*) _menu.get_active()->get_data("name"));
+ gchar* tmp = static_cast<gchar*>(_menu.get_active()->get_data("name"));
+ Glib::ustring nameStr = tmp ? tmp : "profile"; // TODO add some auto-numbering to avoid collisions
+ sanitizeName(nameStr);
+ cprofRepr->setAttribute("name", nameStr.c_str());
cprofRepr->setAttribute("xlink:href", (gchar*) _menu.get_active()->get_data("filepath"));
// Checks whether there is a defs element. Creates it when needed