From 1303adf8622ed8113c4d2247af8acf12678ef29d Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 12 Mar 2018 11:09:47 +0100 Subject: CSS property 'font-variation-settings' contains comma separated value pairs. Previous version assumed no commas. Fix reading and writing property. Update test. --- src/style-internal.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/style-internal.cpp') 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 tokens = Glib::Regex::split_simple(",", str); + + // Match a pattern of a CSS of length 4, whitespace, CSS . + // (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 of length 4, whitespace, CSS . - // (CSS string is quoted). Glib::RefPtr 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(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(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; -- cgit v1.2.3