summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEduard Braun <eduard.braun2@gmx.de>2018-01-17 20:16:42 +0000
committerEduard Braun <eduard.braun2@gmx.de>2018-01-17 20:42:08 +0000
commitc33682b3abf953d449f78f6d16a91bc4781d8d3f (patch)
tree892613346ea4592924039fdfed9a5b98f102e663 /src
parentFix possible divide by zero. (diff)
downloadinkscape-c33682b3abf953d449f78f6d16a91bc4781d8d3f.tar.gz
inkscape-c33682b3abf953d449f78f6d16a91bc4781d8d3f.zip
Properly support palettes without color names
- use hexadecimal color code as a replacement in this case. - do not attempt to translate empty string / color name - fix an issue in the custom trim() function returning early for strings only consisting of a single whitespace character, e.g. "\n" Fixed bug: - https://bugs.launchpad.net/inkscape/+bug/1743708
Diffstat (limited to 'src')
-rw-r--r--src/ui/dialog/swatches.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp
index c6ab06507..d4d26e601 100644
--- a/src/ui/dialog/swatches.cpp
+++ b/src/ui/dialog/swatches.cpp
@@ -16,6 +16,7 @@
#include <errno.h>
#include <map>
#include <algorithm>
+#include <iomanip>
#include <set>
#include "swatches.h"
@@ -380,7 +381,7 @@ static char* trim( char* str ) {
str++;
}
str--;
- while ( str > ret && (( *str == ' ' || *str == '\t' ) || *str == '\r' || *str == '\n') ) {
+ while ( str >= ret && (( *str == ' ' || *str == '\t' ) || *str == '\r' || *str == '\n') ) {
*str-- = 0;
}
return ret;
@@ -453,9 +454,16 @@ void _loadPaletteFile(Glib::ustring path, gboolean user/*=FALSE*/)
}
if ( !hasErr && *ptr ) {
char* n = trim(ptr);
- if (n != NULL) {
+ if (n != NULL && *n) {
name = g_dpgettext2(NULL, "Palette", n);
}
+ if (name == "") {
+ name = Glib::ustring::compose("#%1%2%3",
+ Glib::ustring::format(std::hex, std::setw(2), std::setfill(L'0'), r),
+ Glib::ustring::format(std::hex, std::setw(2), std::setfill(L'0'), g),
+ Glib::ustring::format(std::hex, std::setw(2), std::setfill(L'0'), b)
+ ).uppercase();
+ }
}
if ( !hasErr ) {
// Add the entry now