From 7aaeaacc08de60fd324646afe69f4dbed93f89d4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sun, 10 Jun 2018 16:20:18 +0200 Subject: Allow inkscape handle units and percent in dasharray and dashoffset. Add pref optional to scale dashes on stroke scale --- src/style-internal.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/style-internal.cpp') diff --git a/src/style-internal.cpp b/src/style-internal.cpp index 429353493..4ed59e82e 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -2034,20 +2034,17 @@ SPIDashArray::read( gchar const *str ) { return; } - // std::vector tokens = Glib::Regex::split_simple("[,\\s]+", str ); + std::vector tokens = Glib::Regex::split_simple("[,\\s]+", str ); - gchar *e = nullptr; bool LineSolid = true; - while (e != str && *str != '\0') { - /* TODO: Should allow rather than just a unitless (px) number. */ - double number = g_ascii_strtod(str, (char **) &e); - values.push_back( number ); - if (number > 0.00000001) + for (auto token:tokens) { + SVGLength svglength; + double value = atof(token.c_str()); + if(value > 0.00000001) { LineSolid = false; - if (e != str) { - str = e; } - while (str && *str && !(isalnum(*str) || *str=='.')) str += 1; + svglength.read(token.c_str()); + values.push_back(svglength); } if (LineSolid) { @@ -2074,7 +2071,7 @@ SPIDashArray::write( guint const flags, SPStyleSrc const &style_src_req, SPIBase if (i) { os << ", "; } - os << this->values[i]; + os << this->values[i].write().c_str(); } os << important_str(); os << ";"; @@ -2088,7 +2085,9 @@ SPIDashArray::write( guint const flags, SPStyleSrc const &style_src_req, SPIBase void SPIDashArray::cascade( const SPIBase* const parent ) { if( const SPIDashArray* p = dynamic_cast(parent) ) { - if( !set || inherit ) values = p->values; // Always inherits + if( !set || inherit ) { + values = p->values; // Always inherits + } } else { std::cerr << "SPIDashArray::cascade(): Incorrect parent type" << std::endl; } @@ -2112,10 +2111,13 @@ SPIDashArray::merge( const SPIBase* const parent ) { bool SPIDashArray::operator==(const SPIBase& rhs) { if( const SPIDashArray* r = dynamic_cast(&rhs) ) { - return values == r->values && SPIBase::operator==(rhs); - } else { - return false; + for (int i = 0;i < values.size(); i++) { + if (values[i] != r->values[i]) { + return false; + } + } } + return SPIBase::operator==(rhs); } -- cgit v1.2.3