diff --git a/src/style.cpp b/src/style.cpp
index 8530e2bd4bd4ab1d21dadc9aaadbbaa3b4c41552..e15c54636adf10b496766cfd5eebe0431e27ff93 100644 (file)
--- a/src/style.cpp
+++ b/src/style.cpp
#include "attributes.h"
#include "document.h"
#include "extract-uri.h"
-#include "marker-status.h"
#include "uri-references.h"
#include "sp-paint-server.h"
#include "streq.h"
@@ -156,8 +155,6 @@ static gint sp_style_write_ilengthornormal(gchar *p, gint const len, gchar const
static gint sp_style_write_itextdecoration(gchar *p, gint const len, gchar const *const key, SPITextDecoration const *const val, SPITextDecoration const *const base, guint const flags);
static gint sp_style_write_ifilter(gchar *b, gint len, gchar const *key, SPIFilter const *filter, SPIFilter const *base, guint flags);
-static void css2_unescape_unquote(SPIString *val);
-
static void sp_style_paint_clear(SPStyle *style, SPIPaint *paint);
static void sp_style_filter_clear(SPStyle *style);
style->cloned = true;
}
- /* 1. Style itself */
+ /* 1. Style attribute */
gchar const *val = repr->attribute("style");
if (val != NULL) {
sp_style_merge_from_style_string(style, val);
val = repr->attribute("font-family");
if (val) {
if (!style->text_private) sp_style_privatize_text(style);
- sp_style_read_istring(&style->text->font_family, val);
- css2_unescape_unquote(&style->text->font_family);
+ gchar *val_unquoted = attribute_unquote(val);
+ sp_style_read_istring(&style->text->font_family, val_unquoted);
+ if (val_unquoted) g_free (val_unquoted);
}
}
}
SPS_READ_PENUM_IF_UNSET(&style->enable_background, repr,
"enable-background", enum_enable_background, true);
-
+
/* 3. Merge from parent */
if (object) {
if (object->parent) {
case SP_PROP_FONT_FAMILY:
if (!style->text_private) sp_style_privatize_text(style);
if (!style->text->font_family.set) {
- sp_style_read_istring(&style->text->font_family, val);
- css2_unescape_unquote(&style->text->font_family);
+ gchar *val_unquoted = attribute_unquote(val);
+ sp_style_read_istring(&style->text->font_family, val_unquoted);
+ if (val_unquoted) g_free (val_unquoted);
}
break;
case SP_PROP_FONT_SIZE:
case SP_PROP_MARKER:
/* TODO: Call sp_uri_reference_resolve(SPDocument *document, guchar const *uri) */
/* style->marker[SP_MARKER_LOC] = g_quark_from_string(val); */
- marker_status("Setting SP_PROP_MARKER");
if (!style->marker[SP_MARKER_LOC].set) {
g_free(style->marker[SP_MARKER_LOC].value);
style->marker[SP_MARKER_LOC].value = g_strdup(val);
case SP_PROP_MARKER_START:
/* TODO: Call sp_uri_reference_resolve(SPDocument *document, guchar const *uri) */
- marker_status("Setting SP_PROP_MARKER_START");
if (!style->marker[SP_MARKER_LOC_START].set) {
g_free(style->marker[SP_MARKER_LOC_START].value);
style->marker[SP_MARKER_LOC_START].value = g_strdup(val);
break;
case SP_PROP_MARKER_MID:
/* TODO: Call sp_uri_reference_resolve(SPDocument *document, guchar const *uri) */
- marker_status("Setting SP_PROP_MARKER_MID");
if (!style->marker[SP_MARKER_LOC_MID].set) {
g_free(style->marker[SP_MARKER_LOC_MID].value);
style->marker[SP_MARKER_LOC_MID].value = g_strdup(val);
break;
case SP_PROP_MARKER_END:
/* TODO: Call sp_uri_reference_resolve(SPDocument *document, guchar const *uri) */
- marker_status("Setting SP_PROP_MARKER_END");
if (!style->marker[SP_MARKER_LOC_END].set) {
g_free(style->marker[SP_MARKER_LOC_END].value);
style->marker[SP_MARKER_LOC_END].value = g_strdup(val);
static void
sp_style_merge_from_decl_list(SPStyle *const style, CRDeclaration const *const decl_list)
{
+ // read the decls from end to start, using head recursion, so that latter declarations override
+ // (Ref: http://www.w3.org/TR/REC-CSS2/cascade.html#cascading-order point 4.)
+ // because sp_style_merge_style_from_decl only sets properties that are unset
if (decl_list->next) {
sp_style_merge_from_decl_list(style, decl_list->next);
}
@@ -1939,7 +1937,7 @@ sp_style_merge_from_dying_parent(SPStyle *const style, SPStyle const *const pare
if (!style->filter.set || style->filter.inherit)
{
- // FIXME:
+ // FIXME:
// instead of just copying over, we need to _really merge_ the two filters by combining their
// filter primitives
sp_style_merge_ifilter(style, &parent->filter);
if (style->object) {
style->object->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
}
- }
+ }
}
p += sp_style_write_ienum(p, c + BMAX - p, "stroke-linecap", enum_stroke_linecap, &style->stroke_linecap, NULL, flags);
p += sp_style_write_ienum(p, c + BMAX - p, "stroke-linejoin", enum_stroke_linejoin, &style->stroke_linejoin, NULL, flags);
- marker_status("sp_style_write_string: Writing markers");
if (style->marker[SP_MARKER_LOC].set) {
p += g_snprintf(p, c + BMAX - p, "marker:%s;", style->marker[SP_MARKER_LOC].value);
} else if (flags == SP_STYLE_FLAG_ALWAYS) {
p += sp_style_write_iscale24(p, c + BMAX - p, "stroke-opacity", &from->stroke_opacity, &to->stroke_opacity, SP_STYLE_FLAG_IFDIFF);
/* markers */
- marker_status("sp_style_write_difference: Writing markers");
if (from->marker[SP_MARKER_LOC].value != NULL) {
p += g_snprintf(p, c + BMAX - p, "marker:%s;", from->marker[SP_MARKER_LOC].value);
}
@@ -3081,7 +3077,7 @@ sp_style_read_ipaint(SPIPaint *paint, gchar const *str, SPStyle *style, SPDocume
delete tmp;
tmp = 0;
}
- paint->iccColor = tmp;
+ paint->value.iccColor = tmp;
}
}
}
if (val->inherit) {
return g_snprintf(p, len, "%s:inherit;", key);
} else {
- return g_snprintf(p, len, "%s:%s;", key, val->value);
+ gchar *val_quoted = css2_escape_quote(val->value);
+ return g_snprintf(p, len, "%s:%s;", key, val_quoted);
+ g_free (val_quoted);
}
}
return 0;
return true;
if (a->type == SP_PAINT_TYPE_COLOR)
return !(sp_color_is_equal(&a->value.color, &b->value.color)
- && ((a->iccColor == b->iccColor)
- || (a->iccColor && b->iccColor
- && (a->iccColor->colorProfile == b->iccColor->colorProfile)
- && (a->iccColor->colors == b->iccColor->colors))));
+ && ((a->value.iccColor == b->value.iccColor)
+ || (a->value.iccColor && b->value.iccColor
+ && (a->value.iccColor->colorProfile == b->value.iccColor->colorProfile)
+ && (a->value.iccColor->colors == b->value.iccColor->colors))));
/* todo: Allow for epsilon differences in iccColor->colors, e.g. changes small enough not to show up
* in the string representation. */
if (a->type == SP_PAINT_TYPE_PAINTSERVER)
case SP_PAINT_TYPE_COLOR: {
char color_buf[8];
sp_svg_write_color(color_buf, sizeof(color_buf), sp_color_get_rgba32_ualpha(&paint->value.color, 0));
- if (paint->iccColor) {
+ if (paint->value.iccColor) {
CSSOStringStream css;
- css << color_buf << " icc-color(" << paint->iccColor->colorProfile;
- for (vector<double>::const_iterator i(paint->iccColor->colors.begin()),
- iEnd(paint->iccColor->colors.end());
+ css << color_buf << " icc-color(" << paint->value.iccColor->colorProfile;
+ for (vector<double>::const_iterator i(paint->value.iccColor->colors.begin()),
+ iEnd(paint->value.iccColor->colors.end());
i != iEnd; ++i) {
css << ", " << *i;
}
}
paint->value.paint.uri = NULL;
paint->type = SP_PAINT_TYPE_NONE;
- delete paint->iccColor;
- paint->iccColor = NULL;
+ delete paint->value.iccColor;
+ paint->value.iccColor = NULL;
}
/**
- * Remove quotes from SPIString object value.
- *
- * \todo FIXME: now used for font family, but perhaps this should apply to
- * ALL strings (check CSS spec), in which case this should be part of
- * read_istring.
+ * Remove quotes and escapes from a string. Returned value must be g_free'd.
+ * Note: in CSS (in style= and in stylesheets), unquoting and unescaping is done
+ * by libcroco, our CSS parser, though it adds a new pair of "" quotes for the strings
+ * it parsed for us. So this function is only used to remove those quotes and for
+ * presentation attributes, without any unescaping. (XML unescaping
+ * (& etc) is done by XML parser.)
*/
-static void
-css2_unescape_unquote(SPIString *val)
+gchar *
+attribute_unquote(gchar const *val)
{
- if (val->set && val->value && strlen(val->value) >= 2) {
+ if (val) {
+ if (*val == '\'' || *val == '"') {
+ int l = strlen(val);
+ if (l >= 2) {
+ if ( ( val[0] == '"' && val[l - 1] == '"' ) ||
+ ( val[0] == '\'' && val[l - 1] == '\'' ) ) {
+ return (g_strndup (val+1, l-2));
+ }
+ }
+ }
+ }
- /// \todo unescape all \-escaped chars
+ return (val? g_strdup (val) : NULL);
+}
- int l = strlen(val->value);
- if ( ( val->value[0] == '"' && val->value[l - 1] == '"' ) ||
- ( val->value[0] == '\'' && val->value[l - 1] == '\'' ) ) {
- memcpy(val->value, val->value + 1, l - 2);
- val->value[l - 2] = '\0';
+/**
+ * Quote and/or escape string for writing to CSS (style=). Returned value must be g_free'd.
+ */
+gchar *
+css2_escape_quote(gchar const *val) {
+
+ Glib::ustring t;
+ bool quote = false;
+
+ for (gchar const *i = val; *i; i++) {
+ if (g_ascii_isalnum(*i) || *i=='-' || *i=='_') {
+ t.push_back(*i);
+ } else if (*i=='\'') {
+ t.push_back('\\');
+ t.push_back(*i);
+ quote = true;
+ } else {
+ t.push_back(*i);
+ quote = true;
+ }
+ if (i == val && !g_ascii_isalpha(*i)) {
+ quote = true;
}
}
-}
+ if (quote) { // we use the ' quotes so the result can go to the XML attribute
+ t.insert(t.begin(), '\'');
+ t.push_back('\'');
+ }
+
+ return (t.empty() ? NULL : g_strdup (t.c_str()));
+}
/*
Local Variables: