From a38c853203992fd6cf987fa6aeb088924656fb08 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Sat, 22 Sep 2018 09:36:52 -0400 Subject: Move URL toString to a more useful place and some minor fixes --- src/object/uri.h | 20 ++++++++++++++++++++ src/style-internal.cpp | 16 ++++++---------- 2 files changed, 26 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/object/uri.h b/src/object/uri.h index f0b59780e..b2cdcf778 100644 --- a/src/object/uri.h +++ b/src/object/uri.h @@ -116,6 +116,26 @@ public: */ char *toString() const { return _impl->toString(); } + /** + * Return a more useful std::string with optional url(...) + * useful for css printing. + */ + std::string toStdString(bool with_braces=false) const { + char *uri = this->toString(); + auto ret = std::string(""); + if(uri) { + if(with_braces) { + ret += "url("; + ret += uri; + ret += ")"; + } else { + ret += uri; + } + free((void *) uri); + } + return ret; + } + /** * Assignment operator. */ diff --git a/src/style-internal.cpp b/src/style-internal.cpp index 042ef171d..60120c725 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -70,10 +70,8 @@ inline bool should_write( guint const flags, bool set, bool dfp, bool src) { const Glib::ustring SPIBase::write(guint const flags, SPStyleSrc const &style_src_req, SPIBase const *const base) const { - SPIBase const *const my_base = dynamic_cast(base); - bool dfp = (!inherits || !my_base || (my_base != this)); // Different from parent bool src = (style_src_req == style_src || !(flags & SP_STYLE_FLAG_IFSRC)); - if (should_write(flags, set, dfp, src)) { + if (should_write(flags, set, !inherits, src)) { auto value = this->get_value(); if ( !value.empty() ) { return (name + ":" + value + important_str() + ";"); @@ -997,6 +995,7 @@ SPIEastAsian::read( gchar const *str ) { const Glib::ustring SPIEastAsian::get_value() const { if(this->inherit) return Glib::ustring("inherit"); + if(this->value == 0) return Glib::ustring("normal"); auto ret = Glib::ustring(""); unsigned j = 1; auto enums = enum_font_variant_east_asian; @@ -1137,8 +1136,9 @@ void SPIColor::read( gchar const *str ) { const Glib::ustring SPIColor::get_value() const { - if(this->inherit) return Glib::ustring("inherit"); + // currentcolor goes first to handle special case for 'color' property if(this->currentcolor) return Glib::ustring("currentColor"); + if(this->inherit) return Glib::ustring("inherit"); char color_buf[8]; sp_svg_write_color(color_buf, sizeof(color_buf), this->value.color.toRGBA32( 0 )); @@ -1349,9 +1349,7 @@ const Glib::ustring SPIPaint::get_value() const // url must go first as other values can serve as fallbacks auto ret = Glib::ustring(""); if (this->value.href && this->value.href->getURI()) { - gchar *uri = this->value.href->getURI()->toString(); - ret += g_strdup_printf("url(%s)", uri); - g_free((void *) uri); + ret += this->value.href->getURI()->toStdString(true); } switch(this->paintOrigin) { case SP_CSS_PAINT_ORIGIN_CURRENT_COLOR: @@ -1714,9 +1712,7 @@ SPIFilter::read( gchar const *str ) { const Glib::ustring SPIFilter::get_value() const { if(this->inherit) return Glib::ustring("inherit"); - auto uri = Glib::ustring(this->href->getURI()->toString()); - Glib::ustring ret = "url(" + uri + ")"; - return ret; + return this->href->getURI()->toStdString(true); } void -- cgit v1.2.3