diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2018-03-12 10:09:47 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2018-03-12 10:09:47 +0000 |
| commit | 1303adf8622ed8113c4d2247af8acf12678ef29d (patch) | |
| tree | 9129cea73418bda4cddf28d62247582a2ce78c22 /src/style-internal.cpp | |
| parent | Fix bug that prevented changing 'font-variation-settings' setting. (diff) | |
| download | inkscape-1303adf8622ed8113c4d2247af8acf12678ef29d.tar.gz inkscape-1303adf8622ed8113c4d2247af8acf12678ef29d.zip | |
CSS property 'font-variation-settings' contains comma separated value pairs.
Previous version assumed no commas. Fix reading and writing property. Update test.
Diffstat (limited to 'src/style-internal.cpp')
| -rw-r--r-- | src/style-internal.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/style-internal.cpp b/src/style-internal.cpp index bdd549347..84ff75cfa 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -538,24 +538,26 @@ SPIFontVariationSettings::read( gchar const *str ) { return; } + + std::vector<Glib::ustring> tokens = Glib::Regex::split_simple(",", str); + + // Match a pattern of a CSS <string> of length 4, whitespace, CSS <number>. + // (CSS string is quoted with double quotes). + // Matching must use a Glib::ustring or matching may produce // subtle errors which may be shown by an "Invalid byte sequence // in conversion input" error. - Glib::ustring string(str); - - // Match a pattern of a CSS <string> of length 4, whitespace, CSS <number>. - // (CSS string is quoted). Glib::RefPtr<Glib::Regex> regex = Glib::Regex::create("\"(\\w{4})\"\\s+([-+]?\\d*\\.?\\d+([eE][-+]?\\d+)?)"); Glib::MatchInfo matchInfo; - regex->match(string, matchInfo); - - while (matchInfo.matches()) { - - float value = std::stod(matchInfo.fetch(2)); - axes.insert(std::pair<Glib::ustring,float>(matchInfo.fetch(1), value)); - matchInfo.next(); + for (auto token: tokens) { + regex->match(token, matchInfo); + if (matchInfo.matches()) { + float value = std::stod(matchInfo.fetch(2)); + axes.insert(std::pair<Glib::ustring,float>(matchInfo.fetch(1), value)); + } } + if (!axes.empty()) { set = true; inherit = false; @@ -628,12 +630,13 @@ SPIFontVariationSettings::toString() const { Inkscape::CSSOStringStream os; for (auto it=axes.begin(); it!=axes.end(); ++it){ - os << "'" << it->first << "' " << it->second << " "; + os << "'" << it->first << "' " << it->second << ", "; } std::string string = os.str(); // Glib::ustring doesn't have pop_back() if (!string.empty()) { string.pop_back(); // Delete extra space at end + string.pop_back(); // Delete extra comma at end } return string; |
