summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Owens <doctormo@gmail.com>2018-09-22 13:36:52 +0000
committerMartin Owens <doctormo@gmail.com>2018-09-22 13:36:52 +0000
commita38c853203992fd6cf987fa6aeb088924656fb08 (patch)
tree260360822aba681c90610589a2141d999de9a908 /src
parentRemove most write overrides and replace to get_value plus one generic write m... (diff)
downloadinkscape-a38c853203992fd6cf987fa6aeb088924656fb08.tar.gz
inkscape-a38c853203992fd6cf987fa6aeb088924656fb08.zip
Move URL toString to a more useful place and some minor fixes
Diffstat (limited to 'src')
-rw-r--r--src/object/uri.h20
-rw-r--r--src/style-internal.cpp16
2 files changed, 26 insertions, 10 deletions
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
@@ -117,6 +117,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.
*/
URI &operator=(URI const &uri);
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<const SPIBase*>(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