diff --git a/src/style.cpp b/src/style.cpp
index 5817df3428e746eb08736edae748ff5ba45c599d..0b946f3488ede5da9b9bcabcb56ced53586c2889 100644 (file)
--- a/src/style.cpp
+++ b/src/style.cpp
#define __SP_STYLE_C__
-/** \file
- * SVG stylesheets implementation.
- *
- * Authors:
+/** @file
+ * @brief SVG stylesheets implementation.
+ */
+/* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Peter Moulder <pmoulder@mail.csse.monash.edu.au>
* bulia byak <buliabyak@users.sf.net>
# include "config.h"
#endif
+#include <cstring>
+#include <string>
+
#include "libcroco/cr-sel-eng.h"
#include "xml/croco-node-iface.h"
#include "style.h"
#include "svg/css-ostringstream.h"
#include "xml/repr.h"
+#include "xml/simple-document.h"
#include "unit-constants.h"
-#include "isnan.h"
+#include "2geom/isnan.h"
#include "macros.h"
+#include "preferences.h"
#include "sp-filter-reference.h"
@@ -100,8 +105,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 sp_style_paint_clear(SPStyle *style, SPIPaint *paint);
-
static void sp_style_filter_clear(SPStyle *style);
#define SPS_READ_IENUM_IF_UNSET(v,s,d,i) if (!(v)->set) {sp_style_read_ienum((v), (s), (d), (i));}
static void
sp_style_object_release(SPObject *object, SPStyle *style)
{
+ (void)object; // TODO
style->object = NULL;
}
static void
sp_style_filter_ref_modified(SPObject *obj, guint flags, SPStyle *style)
{
+ (void)flags; // TODO
SPFilter *filter=static_cast<SPFilter *>(obj);
if (style->getFilter() == filter)
{
static void
sp_style_paint_server_ref_modified(SPObject *obj, guint flags, SPStyle *style)
{
+ (void)flags; // TODO
SPPaintServer *server = static_cast<SPPaintServer *>(obj);
- if ((style->fill.type == SP_PAINT_TYPE_PAINTSERVER)
+ if ((style->fill.isPaintserver())
&& style->getFillPaintServer() == server)
{
if (style->object) {
@@ -387,14 +393,14 @@ sp_style_paint_server_ref_modified(SPObject *obj, guint flags, SPStyle *style)
*/
style->object->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
}
- } else if ((style->stroke.type == SP_PAINT_TYPE_PAINTSERVER)
+ } else if ((style->stroke.isPaintserver())
&& style->getStrokePaintServer() == server)
{
if (style->object) {
/// \todo fixme:
style->object->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
}
- } else {
+ } else if (server) {
g_assert_not_reached();
}
}
style->fill_ps_modified_connection.~connection();
style->stroke_ps_modified_connection.~connection();
- sp_style_paint_clear(style, &style->fill);
- sp_style_paint_clear(style, &style->stroke);
+ style->fill.clear();
+ style->stroke.clear();
sp_style_filter_clear(style);
g_free(style->stroke_dash.dash);
sp_style_read_dash(style, val);
}
}
+
if (!style->stroke_dashoffset_set) {
- /* fixme */
val = repr->attribute("stroke-dashoffset");
if (sp_svg_number_read_d(val, &style->stroke_dash.offset)) {
style->stroke_dashoffset_set = TRUE;
+ } else if (val && !strcmp(val, "inherit")) {
+ style->stroke_dashoffset_set = TRUE;
+ style->stroke_dashoffset_inherit = TRUE;
} else {
style->stroke_dashoffset_set = FALSE;
}
}
+
+ /* -inkscape-font-specification */
+ if (!style->text_private || !style->text->font_specification.set) {
+ val = repr->attribute("-inkscape-font-specification");
+ if (val) {
+ if (!style->text_private) sp_style_privatize_text(style);
+ gchar *val_unquoted = attribute_unquote(val);
+ sp_style_read_istring(&style->text->font_specification, val_unquoted);
+ if (val_unquoted) g_free (val_unquoted);
+ }
+ }
/* font-family */
if (!style->text_private || !style->text->font_family.set) {
/**
- * Read style properties from repr only.
+ * Read style properties from preferences.
+ * @param style The style to write to
+ * @param path Preferences directory from which the style should be read
*/
void
-sp_style_read_from_repr(SPStyle *style, Inkscape::XML::Node *repr)
+sp_style_read_from_prefs(SPStyle *style, Glib::ustring const &path)
{
g_return_if_fail(style != NULL);
- g_return_if_fail(repr != NULL);
-
- sp_style_read(style, NULL, repr);
+ g_return_if_fail(path != "");
+
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+
+ // not optimal: we reconstruct the node based on the prefs, then pass it to
+ // sp_style_read for actual processing.
+ Inkscape::XML::SimpleDocument *tempdoc = new Inkscape::XML::SimpleDocument;
+ Inkscape::XML::Node *tempnode = tempdoc->createElement("temp");
+
+ std::vector<Inkscape::Preferences::Entry> attrs = prefs->getAllEntries(path);
+ for (std::vector<Inkscape::Preferences::Entry>::iterator i = attrs.begin(); i != attrs.end(); ++i) {
+ tempnode->setAttribute(i->getEntryName().data(), i->getString().data());
+ }
+
+ sp_style_read(style, NULL, tempnode);
+
+ Inkscape::GC::release(tempnode);
+ Inkscape::GC::release(tempdoc);
+ delete tempdoc;
}
g_return_if_fail(val != NULL);
switch (id) {
+ case SP_PROP_INKSCAPE_FONT_SPEC:
+ if (!style->text_private) sp_style_privatize_text(style);
+ if (!style->text->font_specification.set) {
+ gchar *val_unquoted = attribute_unquote(val);
+ sp_style_read_istring(&style->text->font_specification, val_unquoted);
+ if (val_unquoted) g_free (val_unquoted);
+ }
+ break;
/* CSS2 */
/* Font */
case SP_PROP_FONT_FAMILY:
/* SVG */
/* Clip/Mask */
case SP_PROP_CLIP_PATH:
- g_warning("Unimplemented style property SP_PROP_CLIP_PATH: value: %s", val);
+ /** \todo
+ * This is a workaround. Inkscape only supports 'clip-path' as SVG attribute, not as
+ * style property. By having both CSS and SVG attribute set, editing of clip-path
+ * will fail, since CSS always overwrites SVG attributes.
+ * Fixes Bug #324849
+ */
+ g_warning("attribute 'clip-path' given as CSS");
+ style->object->repr->setAttribute("clip-path", val);
break;
case SP_PROP_CLIP_RULE:
g_warning("Unimplemented style property SP_PROP_CLIP_RULE: value: %s", val);
break;
case SP_PROP_MASK:
- g_warning("Unimplemented style property SP_PROP_MASK: value: %s", val);
+ /** \todo
+ * See comment for SP_PROP_CLIP_PATH
+ */
+ g_warning("attribute 'mask' given as CSS");
+ style->object->repr->setAttribute("mask", val);
break;
case SP_PROP_OPACITY:
if (!style->opacity.set) {
break;
case SP_PROP_STROKE_DASHOFFSET:
if (!style->stroke_dashoffset_set) {
- /* fixme */
if (sp_svg_number_read_d(val, &style->stroke_dash.offset)) {
style->stroke_dashoffset_set = TRUE;
+ } else if (val && !strcmp(val, "inherit")) {
+ style->stroke_dashoffset_set = TRUE;
+ style->stroke_dashoffset_inherit = TRUE;
} else {
style->stroke_dashoffset_set = FALSE;
}
@@ -1472,11 +1531,7 @@ sp_style_merge_from_parent(SPStyle *const style, SPStyle const *const parent)
style->stroke_miterlimit.value = parent->stroke_miterlimit.value;
}
- if (!style->stroke_dasharray_set && parent->stroke_dasharray_set) {
- /** \todo
- * This code looks wrong. Why does the logic differ from the
- * above properties? Similarly dashoffset below.
- */
+ if (!style->stroke_dasharray_set || style->stroke_dasharray_inherit) {
style->stroke_dash.n_dash = parent->stroke_dash.n_dash;
if (style->stroke_dash.n_dash > 0) {
style->stroke_dash.dash = g_new(gdouble, style->stroke_dash.n_dash);
}
}
- if (!style->stroke_dashoffset_set && parent->stroke_dashoffset_set) {
+ if (!style->stroke_dashoffset_set || style->stroke_dashoffset_inherit) {
style->stroke_dash.offset = parent->stroke_dash.offset;
}
@@ -1499,6 +1554,13 @@ sp_style_merge_from_parent(SPStyle *const style, SPStyle const *const parent)
}
}
+ if (style->text && parent->text) {
+ if (!style->text->font_specification.set || style->text->font_specification.inherit) {
+ g_free(style->text->font_specification.value);
+ style->text->font_specification.value = g_strdup(parent->text->font_specification.value);
+ }
+ }
+
/* Markers - Free the old value and make copy of the new */
for (unsigned i = SP_MARKER_LOC; i < SP_MARKER_LOC_QTY; i++) {
if (!style->marker[i].set || style->marker[i].inherit) {
* I haven't given this much attention. See comments below about
* currentColor, colorProfile, and relative URIs.
*/
- if (!child.set || child.inherit || child.currentcolor) {
+ if (!child.set || child.inherit) {
sp_style_merge_ipaint(style, &child, &parent);
child.set = parent.set;
child.inherit = parent.inherit;
@@ -1642,7 +1704,7 @@ sp_style_merge_length_prop_from_dying_parent(LengthT &child, LengthT const &pare
* fixme: Have separate ex ratio parameter.
* Get x height from libnrtype or pango.
*/
- if (!isFinite(child.value)) {
+ if (!IS_FINITE(child.value)) {
child.value = child.computed;
child.unit = SP_CSS_UNIT_NONE;
}
@@ -1884,10 +1946,14 @@ sp_style_merge_from_dying_parent(SPStyle *const style, SPStyle const *const pare
/* Font */
if (style->text && parent->text) {
+ sp_style_merge_string_prop_from_dying_parent(style->text->font_specification,
+ parent->text->font_specification);
+
sp_style_merge_string_prop_from_dying_parent(style->text->font_family,
parent->text->font_family);
}
+
/* Properties that don't inherit by default. Most of these need special handling. */
{
/*
@@ -1982,9 +2048,6 @@ sp_style_merge_from_dying_parent(SPStyle *const style, SPStyle const *const pare
if (!style->filter.set || style->filter.inherit)
{
- // 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);
}
@@ -2038,10 +2101,11 @@ sp_style_merge_from_dying_parent(SPStyle *const style, SPStyle const *const pare
}
/* Note: this will need length handling once dasharray_offset supports units. */
- if (!style->stroke_dashoffset_set && parent->stroke_dashoffset_set) {
+ if ((!style->stroke_dashoffset_set || style->stroke_dashoffset_inherit) && parent->stroke_dashoffset_set && !parent->stroke_dashoffset_inherit) {
style->stroke_dash.offset = parent->stroke_dash.offset;
style->stroke_dashoffset_set = parent->stroke_dashoffset_set;
- /* fixme: we don't currently allow stroke-dashoffset to be `inherit'. TODO: Try to
+ style->stroke_dashoffset_inherit = parent->stroke_dashoffset_inherit;
+ /* TODO: Try to
* represent it as a normal SPILength; though will need to do something about existing
* users of stroke_dash.offset and stroke_dashoffset_set. */
}
@@ -2074,8 +2138,12 @@ sp_style_set_ipaint_to_uri(SPStyle *style, SPIPaint *paint, const Inkscape::URI
static void
sp_style_set_ipaint_to_uri_string (SPStyle *style, SPIPaint *paint, const gchar *uri)
{
- const Inkscape::URI IURI(uri);
- sp_style_set_ipaint_to_uri(style, paint, &IURI, style->document);
+ try {
+ const Inkscape::URI IURI(uri);
+ sp_style_set_ipaint_to_uri(style, paint, &IURI, style->document);
+ } catch (...) {
+ g_warning("URI failed to parse: %s", uri);
+ }
}
void
static void
sp_style_merge_ipaint(SPStyle *style, SPIPaint *paint, SPIPaint const *parent)
{
- sp_style_paint_clear(style, paint);
-
if ((paint->set && paint->currentcolor) || parent->currentcolor) {
+ bool isset = paint->set;
+ paint->clear();
+ paint->set = isset;
paint->currentcolor = TRUE;
- paint->type = SP_PAINT_TYPE_COLOR;
- sp_color_copy(&paint->value.color, &style->color.value.color);
+ paint->setColor(style->color.value.color);
return;
}
- paint->type = parent->type;
- switch (paint->type) {
- case SP_PAINT_TYPE_COLOR:
- sp_color_copy(&paint->value.color, &parent->value.color);
- break;
- case SP_PAINT_TYPE_PAINTSERVER:
- if (parent->value.href) {
- sp_style_set_ipaint_to_uri(style, paint, parent->value.href->getURI(), parent->value.href->getOwnerDocument());
- }
- break;
- case SP_PAINT_TYPE_NONE:
- break;
- default:
- g_assert_not_reached();
- break;
+ paint->clear();
+ if ( parent->isPaintserver() ) {
+ if (parent->value.href) {
+ sp_style_set_ipaint_to_uri(style, paint, parent->value.href->getURI(), parent->value.href->getOwnerDocument());
+ } else {
+ g_warning("Expected paint server not found.");
+ }
+ } else if ( parent->isColor() ) {
+ paint->setColor( parent->value.color );
+ } else if ( parent->isNoneSet() ) {
+ paint->noneSet = TRUE;
+ } else if ( parent->isNone() ) {
+ //
+ } else {
+ g_assert_not_reached();
}
}
@@ -2125,6 +2193,10 @@ sp_style_merge_ipaint(SPStyle *style, SPIPaint *paint, SPIPaint const *parent)
static void
sp_style_merge_ifilter(SPStyle *style, SPIFilter const *parent)
{
+ // FIXME:
+ // instead of just copying over, we need to _really merge_ the two filters by combining their
+ // filter primitives
+
sp_style_filter_clear(style);
style->filter.set = parent->set;
style->filter.inherit = parent->inherit;
if (style->filter.href && style->filter.href->getObject())
style->filter.href->detach();
- if (style->filter.href && parent->href) {
+ // it may be that this style has not yet created its SPFilterReference
+ if (!style->filter.href && style->object && SP_OBJECT_DOCUMENT(style->object)) {
+ style->filter.href = new SPFilterReference(SP_OBJECT_DOCUMENT(style->object));
+ style->filter.href->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_style_filter_ref_changed), style));
+ }
+
+ if (style->filter.href && parent->href && parent->href->getObject()) {
try {
style->filter.href->attach(*parent->href->getURI());
} catch (Inkscape::BadURIException &e) {
p += sp_style_write_ienum(p, c + BMAX - p, "text-anchor", enum_text_anchor, &style->text_anchor, NULL, flags);
/// \todo fixme: Per type methods need default flag too (lauris)
- p += sp_style_write_iscale24(p, c + BMAX - p, "opacity", &style->opacity, NULL, flags);
- p += sp_style_write_ipaint(p, c + BMAX - p, "color", &style->color, NULL, flags);
+
+ if (style->opacity.value != SP_SCALE24_MAX) {
+ p += sp_style_write_iscale24(p, c + BMAX - p, "opacity", &style->opacity, NULL, flags);
+ }
+
+ if (!style->color.noneSet) { // CSS does not permit "none" for color
+ p += sp_style_write_ipaint(p, c + BMAX - p, "color", &style->color, NULL, flags);
+ }
+
p += sp_style_write_ipaint(p, c + BMAX - p, "fill", &style->fill, NULL, flags);
- p += sp_style_write_iscale24(p, c + BMAX - p, "fill-opacity", &style->fill_opacity, NULL, flags);
- p += sp_style_write_ienum(p, c + BMAX - p, "fill-rule", enum_fill_rule, &style->fill_rule, NULL, flags);
+ // if fill:none, skip writing fill properties
+ if (!style->fill.noneSet) {
+ p += sp_style_write_iscale24(p, c + BMAX - p, "fill-opacity", &style->fill_opacity, NULL, flags);
+ p += sp_style_write_ienum(p, c + BMAX - p, "fill-rule", enum_fill_rule, &style->fill_rule, NULL, flags);
+ }
+
p += sp_style_write_ipaint(p, c + BMAX - p, "stroke", &style->stroke, NULL, flags);
- p += sp_style_write_ilength(p, c + BMAX - p, "stroke-width", &style->stroke_width, NULL, flags);
- 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);
+ // stroke width affects markers, so write it if there's stroke OR any markers
+ if (!style->stroke.noneSet ||
+ style->marker[SP_MARKER_LOC].set ||
+ style->marker[SP_MARKER_LOC_START].set ||
+ style->marker[SP_MARKER_LOC_MID].set ||
+ style->marker[SP_MARKER_LOC_END].set) {
+ p += sp_style_write_ilength(p, c + BMAX - p, "stroke-width", &style->stroke_width, NULL, flags);
+ }
+
+ // if stroke:none, skip writing stroke properties
+ if (!style->stroke.noneSet) {
+ 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);
+ p += sp_style_write_ifloat(p, c + BMAX - p, "stroke-miterlimit", &style->stroke_miterlimit, NULL, flags);
+ p += sp_style_write_iscale24(p, c + BMAX - p, "stroke-opacity", &style->stroke_opacity, NULL, flags);
+
+ /** \todo fixme: */
+ if ((flags == SP_STYLE_FLAG_ALWAYS)
+ || style->stroke_dasharray_set)
+ {
+ if (style->stroke_dasharray_inherit) {
+ p += g_snprintf(p, c + BMAX - p, "stroke-dasharray:inherit;");
+ } else if (style->stroke_dash.n_dash && style->stroke_dash.dash) {
+ p += g_snprintf(p, c + BMAX - p, "stroke-dasharray:");
+ gint i;
+ for (i = 0; i < style->stroke_dash.n_dash; i++) {
+ Inkscape::CSSOStringStream os;
+ if (i) {
+ os << ", ";
+ }
+ os << style->stroke_dash.dash[i];
+ p += g_strlcpy(p, os.str().c_str(), c + BMAX - p);
+ }
+ if (p < c + BMAX) {
+ *p++ = ';';
+ }
+ } else {
+ p += g_snprintf(p, c + BMAX - p, "stroke-dasharray:none;");
+ }
+ }
+
+ /** \todo fixme: */
+ if (style->stroke_dashoffset_set) {
+ if (style->stroke_dashoffset_inherit) {
+ p += g_snprintf(p, c + BMAX - p, "stroke-dashoffset:inherit;");
+ } else {
+ Inkscape::CSSOStringStream os;
+ os << "stroke-dashoffset:" << style->stroke_dash.offset << ";";
+ p += g_strlcpy(p, os.str().c_str(), c + BMAX - p);
+ }
+ } else if (flags == SP_STYLE_FLAG_ALWAYS) {
+ p += g_snprintf(p, c + BMAX - p, "stroke-dashoffset:0;");
+ }
+ }
+
+ bool marker_none = false;
+ gchar *master = style->marker[SP_MARKER_LOC].value;
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 += g_snprintf(p, c + BMAX - p, "marker:none;");
+ marker_none = true;
}
- if (style->marker[SP_MARKER_LOC_START].set) {
+ if (style->marker[SP_MARKER_LOC_START].set
+ && (!master || strcmp(master, style->marker[SP_MARKER_LOC_START].value))) {
p += g_snprintf(p, c + BMAX - p, "marker-start:%s;", style->marker[SP_MARKER_LOC_START].value);
- } else if (flags == SP_STYLE_FLAG_ALWAYS) {
+ } else if (flags == SP_STYLE_FLAG_ALWAYS && !marker_none) {
p += g_snprintf(p, c + BMAX - p, "marker-start:none;");
}
- if (style->marker[SP_MARKER_LOC_MID].set) {
+ if (style->marker[SP_MARKER_LOC_MID].set
+ && (!master || strcmp(master, style->marker[SP_MARKER_LOC_MID].value))) {
p += g_snprintf(p, c + BMAX - p, "marker-mid:%s;", style->marker[SP_MARKER_LOC_MID].value);
- } else if (flags == SP_STYLE_FLAG_ALWAYS) {
+ } else if (flags == SP_STYLE_FLAG_ALWAYS && !marker_none) {
p += g_snprintf(p, c + BMAX - p, "marker-mid:none;");
}
- if (style->marker[SP_MARKER_LOC_END].set) {
+ if (style->marker[SP_MARKER_LOC_END].set
+ && (!master || strcmp(master, style->marker[SP_MARKER_LOC_END].value))) {
p += g_snprintf(p, c + BMAX - p, "marker-end:%s;", style->marker[SP_MARKER_LOC_END].value);
- } else if (flags == SP_STYLE_FLAG_ALWAYS) {
+ } else if (flags == SP_STYLE_FLAG_ALWAYS && !marker_none) {
p += g_snprintf(p, c + BMAX - p, "marker-end:none;");
}
- p += sp_style_write_ifloat(p, c + BMAX - p, "stroke-miterlimit", &style->stroke_miterlimit, NULL, flags);
-
- /** \todo fixme: */
- if ((flags == SP_STYLE_FLAG_ALWAYS)
- || style->stroke_dasharray_set)
- {
- if (style->stroke_dasharray_inherit) {
- p += g_snprintf(p, c + BMAX - p, "stroke-dasharray:inherit;");
- } else if (style->stroke_dash.n_dash && style->stroke_dash.dash) {
- p += g_snprintf(p, c + BMAX - p, "stroke-dasharray:");
- gint i;
- for (i = 0; i < style->stroke_dash.n_dash; i++) {
- Inkscape::CSSOStringStream os;
- if (i) {
- os << ", ";
- }
- os << style->stroke_dash.dash[i];
- p += g_strlcpy(p, os.str().c_str(), c + BMAX - p);
- }
- if (p < c + BMAX) {
- *p++ = ';';
- }
- } else {
- p += g_snprintf(p, c + BMAX - p, "stroke-dasharray:none;");
- }
- }
-
- /** \todo fixme: */
- if (style->stroke_dashoffset_set) {
- Inkscape::CSSOStringStream os;
- os << "stroke-dashoffset:" << style->stroke_dash.offset << ";";
- p += g_strlcpy(p, os.str().c_str(), c + BMAX - p);
- } else if (flags == SP_STYLE_FLAG_ALWAYS) {
- p += g_snprintf(p, c + BMAX - p, "stroke-dashoffset:0;");
- }
-
- p += sp_style_write_iscale24(p, c + BMAX - p, "stroke-opacity", &style->stroke_opacity, NULL, flags);
-
p += sp_style_write_ienum(p, c + BMAX - p, "visibility", enum_visibility, &style->visibility, NULL, flags);
p += sp_style_write_ienum(p, c + BMAX - p, "display", enum_display, &style->display, NULL, flags);
p += sp_style_write_ienum(p, c + BMAX - p, "overflow", enum_overflow, &style->overflow, NULL, flags);
@@ -2325,54 +2434,79 @@ sp_style_write_difference(SPStyle const *const from, SPStyle const *const to)
if (from->opacity.set && from->opacity.value != SP_SCALE24_MAX) {
p += sp_style_write_iscale24(p, c + BMAX - p, "opacity", &from->opacity, &to->opacity, SP_STYLE_FLAG_IFSET);
}
- p += sp_style_write_ipaint(p, c + BMAX - p, "color", &from->color, &to->color, SP_STYLE_FLAG_IFSET);
+
+ if (!from->color.noneSet) { // CSS does not permit "none" for color
+ p += sp_style_write_ipaint(p, c + BMAX - p, "color", &from->color, &to->color, SP_STYLE_FLAG_IFSET);
+ }
+
p += sp_style_write_ipaint(p, c + BMAX - p, "fill", &from->fill, &to->fill, SP_STYLE_FLAG_IFDIFF);
- p += sp_style_write_iscale24(p, c + BMAX - p, "fill-opacity", &from->fill_opacity, &to->fill_opacity, SP_STYLE_FLAG_IFDIFF);
- p += sp_style_write_ienum(p, c + BMAX - p, "fill-rule", enum_fill_rule, &from->fill_rule, &to->fill_rule, SP_STYLE_FLAG_IFDIFF);
+ // if fill:none, skip writing fill properties
+ if (!from->fill.noneSet) {
+ p += sp_style_write_iscale24(p, c + BMAX - p, "fill-opacity", &from->fill_opacity, &to->fill_opacity, SP_STYLE_FLAG_IFDIFF);
+ p += sp_style_write_ienum(p, c + BMAX - p, "fill-rule", enum_fill_rule, &from->fill_rule, &to->fill_rule, SP_STYLE_FLAG_IFDIFF);
+ }
+
p += sp_style_write_ipaint(p, c + BMAX - p, "stroke", &from->stroke, &to->stroke, SP_STYLE_FLAG_IFDIFF);
- p += sp_style_write_ilength(p, c + BMAX - p, "stroke-width", &from->stroke_width, &to->stroke_width, SP_STYLE_FLAG_IFDIFF);
- p += sp_style_write_ienum(p, c + BMAX - p, "stroke-linecap", enum_stroke_linecap,
- &from->stroke_linecap, &to->stroke_linecap, SP_STYLE_FLAG_IFDIFF);
- p += sp_style_write_ienum(p, c + BMAX - p, "stroke-linejoin", enum_stroke_linejoin,
- &from->stroke_linejoin, &to->stroke_linejoin, SP_STYLE_FLAG_IFDIFF);
- p += sp_style_write_ifloat(p, c + BMAX - p, "stroke-miterlimit",
- &from->stroke_miterlimit, &to->stroke_miterlimit, SP_STYLE_FLAG_IFDIFF);
- /** \todo fixme: */
- if (from->stroke_dasharray_set) {
- if (from->stroke_dasharray_inherit) {
- p += g_snprintf(p, c + BMAX - p, "stroke-dasharray:inherit;");
- } else if (from->stroke_dash.n_dash && from->stroke_dash.dash) {
- p += g_snprintf(p, c + BMAX - p, "stroke-dasharray:");
- for (gint i = 0; i < from->stroke_dash.n_dash; i++) {
- Inkscape::CSSOStringStream os;
- if (i) {
- os << ", ";
+
+ // stroke width affects markers, so write it if there's stroke OR any markers
+ if (!from->stroke.noneSet ||
+ from->marker[SP_MARKER_LOC].set ||
+ from->marker[SP_MARKER_LOC_START].set ||
+ from->marker[SP_MARKER_LOC_MID].set ||
+ from->marker[SP_MARKER_LOC_END].set) {
+ p += sp_style_write_ilength(p, c + BMAX - p, "stroke-width", &from->stroke_width, &to->stroke_width, SP_STYLE_FLAG_IFDIFF);
+ }
+
+ // if stroke:none, skip writing stroke properties
+ if (!from->stroke.noneSet) {
+ p += sp_style_write_ienum(p, c + BMAX - p, "stroke-linecap", enum_stroke_linecap,
+ &from->stroke_linecap, &to->stroke_linecap, SP_STYLE_FLAG_IFDIFF);
+ p += sp_style_write_ienum(p, c + BMAX - p, "stroke-linejoin", enum_stroke_linejoin,
+ &from->stroke_linejoin, &to->stroke_linejoin, SP_STYLE_FLAG_IFDIFF);
+ p += sp_style_write_ifloat(p, c + BMAX - p, "stroke-miterlimit",
+ &from->stroke_miterlimit, &to->stroke_miterlimit, SP_STYLE_FLAG_IFDIFF);
+ /** \todo fixme: */
+ if (from->stroke_dasharray_set) {
+ if (from->stroke_dasharray_inherit) {
+ p += g_snprintf(p, c + BMAX - p, "stroke-dasharray:inherit;");
+ } else if (from->stroke_dash.n_dash && from->stroke_dash.dash) {
+ p += g_snprintf(p, c + BMAX - p, "stroke-dasharray:");
+ for (gint i = 0; i < from->stroke_dash.n_dash; i++) {
+ Inkscape::CSSOStringStream os;
+ if (i) {
+ os << ", ";
+ }
+ os << from->stroke_dash.dash[i];
+ p += g_strlcpy(p, os.str().c_str(), c + BMAX - p);
}
- os << from->stroke_dash.dash[i];
+ p += g_snprintf(p, c + BMAX - p, ";");
+ }
+ }
+ /* fixme: */
+ if (from->stroke_dashoffset_set) {
+ if (from->stroke_dashoffset_inherit) {
+ p += g_snprintf(p, c + BMAX - p, "stroke-dashoffset:inherit;");
+ } else {
+ Inkscape::CSSOStringStream os;
+ os << "stroke-dashoffset:" << from->stroke_dash.offset << ";";
p += g_strlcpy(p, os.str().c_str(), c + BMAX - p);
}
- p += g_snprintf(p, c + BMAX - p, ";");
}
+ p += sp_style_write_iscale24(p, c + BMAX - p, "stroke-opacity", &from->stroke_opacity, &to->stroke_opacity, SP_STYLE_FLAG_IFDIFF);
}
- /* fixme: */
- if (from->stroke_dashoffset_set) {
- Inkscape::CSSOStringStream os;
- os << "stroke-dashoffset:" << from->stroke_dash.offset << ";";
- p += g_strlcpy(p, os.str().c_str(), c + BMAX - p);
- }
- p += sp_style_write_iscale24(p, c + BMAX - p, "stroke-opacity", &from->stroke_opacity, &to->stroke_opacity, SP_STYLE_FLAG_IFDIFF);
/* markers */
- if (from->marker[SP_MARKER_LOC].value != NULL) {
- p += g_snprintf(p, c + BMAX - p, "marker:%s;", from->marker[SP_MARKER_LOC].value);
+ gchar *master = from->marker[SP_MARKER_LOC].value;
+ if (master != NULL) {
+ p += g_snprintf(p, c + BMAX - p, "marker:%s;", master);
}
- if (from->marker[SP_MARKER_LOC_START].value != NULL) {
+ if (from->marker[SP_MARKER_LOC_START].value != NULL && (!master || strcmp(master, from->marker[SP_MARKER_LOC_START].value))) {
p += g_snprintf(p, c + BMAX - p, "marker-start:%s;", from->marker[SP_MARKER_LOC_START].value);
}
- if (from->marker[SP_MARKER_LOC_MID].value != NULL) {
+ if (from->marker[SP_MARKER_LOC_MID].value != NULL && (!master || strcmp(master, from->marker[SP_MARKER_LOC_MID].value))) {
p += g_snprintf(p, c + BMAX - p, "marker-mid:%s;", from->marker[SP_MARKER_LOC_MID].value);
}
- if (from->marker[SP_MARKER_LOC_END].value != NULL) {
+ if (from->marker[SP_MARKER_LOC_END].value != NULL && (!master || strcmp(master, from->marker[SP_MARKER_LOC_END].value))) {
p += g_snprintf(p, c + BMAX - p, "marker-end:%s;", from->marker[SP_MARKER_LOC_END].value);
}
{
g_return_if_fail(style != NULL);
- sp_style_paint_clear(style, &style->fill);
- sp_style_paint_clear(style, &style->stroke);
+ style->fill.clear();
+ style->stroke.clear();
sp_style_filter_clear(style);
- if (style->fill.value.href)
+ if (style->fill.value.href) {
delete style->fill.value.href;
- if (style->stroke.value.href)
+ style->fill.value.href = NULL;
+ }
+ if (style->stroke.value.href) {
delete style->stroke.value.href;
- if (style->filter.href)
+ style->stroke.value.href = NULL;
+ }
+ if (style->filter.href) {
delete style->filter.href;
+ style->filter.href = NULL;
+ }
if (style->stroke_dash.dash) {
g_free(style->stroke_dash.dash);
}
+ style->stroke_dasharray_inherit = FALSE;
+ style->stroke_dashoffset_inherit = FALSE;
+
/** \todo fixme: Do that text manipulation via parents */
SPObject *object = style->object;
SPDocument *document = style->document;
style->text = text;
style->text_private = text_private;
- /* fixme: */
+ style->text->font_specification.set = FALSE;
style->text->font.set = FALSE;
style->text->font_family.set = FALSE;
style->overflow.set = FALSE;
style->overflow.value = style->overflow.computed = SP_CSS_OVERFLOW_VISIBLE;
- style->color.type = SP_PAINT_TYPE_COLOR;
- sp_color_set_rgb_float(&style->color.value.color, 0.0, 0.0, 0.0);
+ style->color.clear();
+ style->color.setColor(0.0, 0.0, 0.0);
- style->fill.type = SP_PAINT_TYPE_COLOR;
- sp_color_set_rgb_float(&style->fill.value.color, 0.0, 0.0, 0.0);
+ style->fill.clear();
+ style->fill.setColor(0.0, 0.0, 0.0);
style->fill_opacity.value = SP_SCALE24_MAX;
style->fill_rule.value = style->fill_rule.computed = SP_WIND_RULE_NONZERO;
- style->stroke.type = SP_PAINT_TYPE_NONE;
- style->stroke.set = FALSE;
- sp_color_set_rgb_float(&style->stroke.value.color, 0.0, 0.0, 0.0);
+ style->stroke.clear();
style->stroke_opacity.value = SP_SCALE24_MAX;
style->stroke_width.set = FALSE;
ts->refcount = 1;
sp_text_style_clear(ts);
+ ts->font_specification.value = g_strdup("Bitstream Vera Sans");
ts->font.value = g_strdup("Bitstream Vera Sans");
ts->font_family.value = g_strdup("Bitstream Vera Sans");
static void
sp_text_style_clear(SPTextStyle *ts)
{
+ ts->font_specification.set = FALSE;
ts->font.set = FALSE;
ts->font_family.set = FALSE;
}
st->refcount -= 1;
if (st->refcount < 1) {
+ g_free(st->font_specification.value);
g_free(st->font.value);
g_free(st->font_family.value);
g_free(st);
SPTextStyle *nt = g_new0(SPTextStyle, 1);
nt->refcount = 1;
+ nt->font_specification.value = g_strdup(st->font_specification.value);
nt->font.value = g_strdup(st->font.value);
nt->font_family.value = g_strdup(st->font_family.value);
@@ -2706,6 +2851,7 @@ sp_text_style_write(gchar *p, guint const len, SPTextStyle const *const st, guin
flags = SP_STYLE_FLAG_IFSET;
d += sp_style_write_istring(p + d, len - d, "font-family", &st->font_family, NULL, flags);
+ d += sp_style_write_istring(p + d, len - d, "-inkscape-font-specification", &st->font_specification, NULL, flags);
return d;
}
static void
sp_style_read_icolor(SPIPaint *paint, gchar const *str, SPStyle *style, SPDocument *document)
{
+ (void)style; // TODO
+ (void)document; // TODO
paint->currentcolor = FALSE; /* currentColor not a valid <color>. */
if (!strcmp(str, "inherit")) {
paint->set = TRUE;
@@ -2965,8 +3113,7 @@ sp_style_read_icolor(SPIPaint *paint, gchar const *str, SPStyle *style, SPDocume
} else {
guint32 const rgb0 = sp_svg_read_color(str, 0xff);
if (rgb0 != 0xff) {
- paint->type = SP_PAINT_TYPE_COLOR;
- sp_color_set_rgb_rgba32(&paint->value.color, rgb0);
+ paint->setColor(rgb0);
paint->set = TRUE;
paint->inherit = FALSE;
}
@@ -2986,19 +3133,12 @@ sp_style_read_ipaint(SPIPaint *paint, gchar const *str, SPStyle *style, SPDocume
++str;
}
- if (paint->value.href && paint->value.href->getObject()) {
- paint->value.href->detach();
- }
- paint->colorSet = FALSE;
- paint->currentcolor = FALSE;
- paint->noneSet = FALSE;
+ paint->clear();
if (streq(str, "inherit")) {
paint->set = TRUE;
paint->inherit = TRUE;
} else {
- paint->type = SP_PAINT_TYPE_NONE;
- paint->inherit = FALSE;
if ( strneq(str, "url", 3) ) {
gchar *uri = extract_uri( str, &str );
while ( g_ascii_isspace(*str) ) {
@@ -3006,7 +3146,6 @@ sp_style_read_ipaint(SPIPaint *paint, gchar const *str, SPStyle *style, SPDocume
}
// TODO check on and comment the comparrison "paint != &style->color".
if ( uri && *uri && (paint != &style->color) ) {
- paint->type = SP_PAINT_TYPE_PAINTSERVER;
paint->set = TRUE;
// it may be that this style's SPIPaint has not yet created its URIReference;
@@ -3031,12 +3170,8 @@ sp_style_read_ipaint(SPIPaint *paint, gchar const *str, SPStyle *style, SPDocume
} else {
guint32 const rgb0 = sp_svg_read_color(str, &str, 0xff);
if (rgb0 != 0xff) {
- if ( paint->type != SP_PAINT_TYPE_PAINTSERVER ) {
- paint->type = SP_PAINT_TYPE_COLOR;
- }
- sp_color_set_rgb_rgba32(&paint->value.color, rgb0);
+ paint->setColor( rgb0 );
paint->set = TRUE;
- paint->colorSet = true;
while (g_ascii_isspace(*str)) {
++str;
@@ -3047,7 +3182,7 @@ sp_style_read_ipaint(SPIPaint *paint, gchar const *str, SPStyle *style, SPDocume
delete tmp;
tmp = 0;
}
- paint->value.iccColor = tmp;
+ paint->value.color.icc = tmp;
}
}
}
return g_snprintf(p, len, "%s:inherit;", key);
} else {
gchar *val_quoted = css2_escape_quote(val->value);
- return g_snprintf(p, len, "%s:%s;", key, val_quoted);
- g_free (val_quoted);
+ if (val_quoted) {
+ return g_snprintf(p, len, "%s:%s;", key, val_quoted);
+ g_free (val_quoted);
+ }
}
}
return 0;
@@ -3523,18 +3660,30 @@ sp_style_write_itextdecoration(gchar *p, gint const len, gchar const *const key,
static bool
sp_paint_differ(SPIPaint const *const a, SPIPaint const *const b)
{
- if (a->type != b->type)
+ if ( (a->isColor() != b->isColor())
+ || (a->isPaintserver() != b->isPaintserver())
+ || (a->set != b->set)
+ || (a->currentcolor != b->currentcolor)
+ || (a->inherit!= b->inherit) ) {
return true;
- if (a->type == SP_PAINT_TYPE_COLOR)
- return !(sp_color_is_equal(&a->value.color, &b->value.color)
- && ((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 refactor to allow for mixed paints (rgb() *and* url(), etc)
+
+ if ( a->isPaintserver() ) {
+ return (a->value.href == NULL || b->value.href == NULL || a->value.href->getObject() != b->value.href->getObject());
+ }
+
+ if ( a->isColor() ) {
+ return !( (a->value.color == b->value.color)
+ && ((a->value.color.icc == b->value.color.icc)
+ || (a->value.color.icc && b->value.color.icc
+ && (a->value.color.icc->colorProfile == b->value.color.icc->colorProfile)
+ && (a->value.color.icc->colors == b->value.color.icc->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)
- return (a->value.href == NULL || b->value.href == NULL || a->value.href->getObject() != b->value.href->getObject());
+ }
+
return false;
}
css << "currentColor";
}
- if ( paint->colorSet ) {
+ if ( paint->colorSet && !paint->currentcolor ) {
if ( !css.str().empty() ) {
css << " ";
}
char color_buf[8];
- sp_svg_write_color(color_buf, sizeof(color_buf), sp_color_get_rgba32_ualpha(&paint->value.color, 0));
+ sp_svg_write_color(color_buf, sizeof(color_buf), paint->value.color.toRGBA32( 0 ));
css << color_buf;
}
- if (paint->value.iccColor) {
+ if (paint->value.color.icc && !paint->currentcolor) {
if ( !css.str().empty() ) {
css << " ";
}
- css << "icc-color(" << paint->value.iccColor->colorProfile;
- for (vector<double>::const_iterator i(paint->value.iccColor->colors.begin()),
- iEnd(paint->value.iccColor->colors.end());
+ css << "icc-color(" << paint->value.color.icc->colorProfile;
+ for (vector<double>::const_iterator i(paint->value.color.icc->colors.begin()),
+ iEnd(paint->value.color.icc->colors.end());
i != iEnd; ++i) {
css << ", " << *i;
}
}
if ( !css.str().empty() ) {
- retval = g_snprintf( b, len, "%s:%s;", key, css.gcharp() );
+ retval = g_snprintf( b, len, "%s:%s;", key, css.str().c_str() );
}
}
SPIFilter const *const val, SPIFilter const *const base,
guint const flags)
{
+ (void)base; // TODO
if ((flags & SP_STYLE_FLAG_ALWAYS)
|| ((flags & SP_STYLE_FLAG_IFSET) && val->set)
|| ((flags & SP_STYLE_FLAG_IFDIFF) && val->set))
}
-/**
- * Clear paint object, and disconnect style from paintserver (if present).
- */
-static void
-sp_style_paint_clear(SPStyle *style, SPIPaint *paint)
+void SPIPaint::clear()
{
- if (paint->value.href && paint->value.href->getObject())
- paint->value.href->detach();
-
- paint->type = SP_PAINT_TYPE_NONE;
- delete paint->value.iccColor;
- paint->value.iccColor = NULL;
+ set = false;
+ inherit = false;
+ currentcolor = false;
+ colorSet = false;
+ noneSet = false;
+ value.color.set( 0 );
+ if ( value.href && value.href->getObject() )
+ {
+ value.href->detach();
+ }
}
sp_style_filter_clear(SPStyle *style)
{
if (style->filter.href && style->filter.href->getObject())
- style->filter.href->detach();
+ style->filter.href->detach();
}
@@ -3723,13 +3873,15 @@ sp_style_set_property_url (SPObject *item, gchar const *property, SPObject *link
if (repr == NULL) return;
- g_return_if_fail(linked != NULL);
-
- gchar *val = g_strdup_printf("url(#%s)", SP_OBJECT_ID(linked));
-
SPCSSAttr *css = sp_repr_css_attr_new();
- sp_repr_css_set_property(css, property, val);
- g_free(val);
+ if (linked) {
+ gchar *val = g_strdup_printf("url(#%s)", SP_OBJECT_ID(linked));
+ sp_repr_css_set_property(css, property, val);
+ g_free(val);
+ } else {
+ sp_repr_css_unset_property(css, "filter");
+ }
+
if (recursive) {
sp_repr_css_change_recursive(repr, css, "style");
} else {
if (style->stroke_dashoffset_set) {
repr->setAttribute("stroke-dashoffset", NULL);
}
+ if (style->text_private && style->text->font_specification.set) {
+ repr->setAttribute("-inkscape-font-specification", NULL);
+ }
if (style->text_private && style->text->font_family.set) {
repr->setAttribute("font-family", NULL);
}
sp_css_attr_unset_text(SPCSSAttr *css)
{
sp_repr_css_set_property(css, "font", NULL); // not implemented yet
+ sp_repr_css_set_property(css, "-inkscape-font-specification", NULL);
sp_repr_css_set_property(css, "font-size", NULL);
sp_repr_css_set_property(css, "font-size-adjust", NULL); // not implemented yet
sp_repr_css_set_property(css, "font-style", NULL);
if (is_url(sp_repr_css_property(css, "color-profile", NULL))) sp_repr_css_set_property(css, "color-profile", NULL);
if (is_url(sp_repr_css_property(css, "cursor", NULL))) sp_repr_css_set_property(css, "cursor", NULL);
if (is_url(sp_repr_css_property(css, "filter", NULL))) sp_repr_css_set_property(css, "filter", NULL);
+ if (is_url(sp_repr_css_property(css, "marker", NULL))) sp_repr_css_set_property(css, "marker", NULL);
if (is_url(sp_repr_css_property(css, "marker-start", NULL))) sp_repr_css_set_property(css, "marker-start", NULL);
if (is_url(sp_repr_css_property(css, "marker-mid", NULL))) sp_repr_css_set_property(css, "marker-mid", NULL);
if (is_url(sp_repr_css_property(css, "marker-end", NULL))) sp_repr_css_set_property(css, "marker-end", NULL);