summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2011-08-29 13:44:13 +0000
committertavmjong-free <tavmjong@free.fr>2011-08-29 13:44:13 +0000
commit5489ec55d35af6640606ad16b73930d505958faf (patch)
tree600eaca700b351b157804bcc1e2e63af943223f3 /src
parentFix compilation on Windows after libnr removal (diff)
downloadinkscape-5489ec55d35af6640606ad16b73930d505958faf.tar.gz
inkscape-5489ec55d35af6640606ad16b73930d505958faf.zip
Add minimal support for reading color-interpolation and color-interpolation-filters
properties (however, Inkscape assumes sRGB everywhere at the moment). Change color-interpolation-filters from attribute to style property in sp-filter.cpp as it is not allowed as an attribute in a <filter> (it is only allowed as an attribute in filter primitives). Added color-interpolation-filters:sRGB to style when new filter is created in filter-chemistry.cpp. (bzr r10591)
Diffstat (limited to 'src')
-rw-r--r--src/filter-chemistry.cpp6
-rw-r--r--src/sp-filter.cpp14
-rw-r--r--src/style.cpp47
-rw-r--r--src/style.h10
4 files changed, 71 insertions, 6 deletions
diff --git a/src/filter-chemistry.cpp b/src/filter-chemistry.cpp
index 1b63bf6f9..b8c4cf901 100644
--- a/src/filter-chemistry.cpp
+++ b/src/filter-chemistry.cpp
@@ -97,6 +97,12 @@ SPFilter *new_filter(SPDocument *document)
Inkscape::XML::Node *repr;
repr = xml_doc->createElement("svg:filter");
+ // Inkscape only supports sRGB. See note in sp-filter.cpp.
+ SPCSSAttr *css = sp_repr_css_attr_new();
+ sp_repr_css_set_property(css, "color-interpolation-filters", "sRGB");
+ sp_repr_css_change(repr, css, "style");
+ sp_repr_css_attr_unref(css);
+
// Append the new filter node to defs
defs->appendChild(repr);
Inkscape::GC::release(repr);
diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp
index a7c1aa1fb..d0fd59802 100644
--- a/src/sp-filter.cpp
+++ b/src/sp-filter.cpp
@@ -370,12 +370,22 @@ sp_filter_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::N
// TODO: This is evil, correctly implement support for color-interpolation-filters!!!
// The color-interpolation-filters attribute is initially set to linearRGB according to the SVG standard.
- // However, Inkscape completely ignores it and implicitly assumes that it is sRGB (like color-interpolation-filters).
+ // However, Inkscape completely ignores it and implicitly assumes that it is sRGB (like color-interpolation).
// This results in a discrepancy between Inkscape and other renderers in how they render filters.
// To mitigate this problem I've (Jasper van de Gronde,th.v.d.gronde@hccnet.nl) added this to ensure that at least
// any filters written by Inkscape will henceforth be rendered the same in other renderers.
// In the future Inkscape should have proper support for the color-interpolation properties and this should be changed.
- repr->setAttribute("color-interpolation-filters", "sRGB");
+
+ // repr->setAttribute("color-interpolation-filters", "sRGB");
+
+ // Actually, the above line is not correct as the attribute is only allowed on filter
+ // primitives and not <filter> objects. However, it is allowed as a property in a style
+ // attribute. Note, this property must also be set in sp-filter-chemistry, filter_new() as the
+ // code here is not necessarily called when a new filter is created. 29 Aug 2011 Tav.
+ SPCSSAttr *css = sp_repr_css_attr_new();
+ sp_repr_css_set_property(css, "color-interpolation-filters", "sRGB");
+ sp_repr_css_change(repr, css, "style");
+ sp_repr_css_attr_unref(css);
if (((SPObjectClass *) filter_parent_class)->write) {
((SPObjectClass *) filter_parent_class)->write(object, doc, repr, flags);
diff --git a/src/style.cpp b/src/style.cpp
index 44d2b0761..ffb56dfa5 100644
--- a/src/style.cpp
+++ b/src/style.cpp
@@ -342,6 +342,13 @@ static SPStyleEnum const enum_clip_rule[] = {
{NULL, -1}
};
+static SPStyleEnum const enum_color_interpolation[] = {
+ {"auto", SP_CSS_COLOR_INTERPOLATION_AUTO},
+ {"sRGB", SP_CSS_COLOR_INTERPOLATION_SRGB},
+ {"linearRGB", SP_CSS_COLOR_INTERPOLATION_LINEARRGB},
+ {NULL, -1}
+};
+
/**
* Release callback.
*/
@@ -662,6 +669,10 @@ sp_style_read(SPStyle *style, SPObject *object, Inkscape::XML::Node *repr)
: NULL ));
}
}
+ /* color interpolation */
+ SPS_READ_PENUM_IF_UNSET(&style->color_interpolation, repr, "color_interpolation", enum_color_interpolation, true);
+ /* color interpolation filters*/
+ SPS_READ_PENUM_IF_UNSET(&style->color_interpolation_filters, repr, "color_interpolation_filters", enum_color_interpolation, true);
/* fill */
if (!style->fill.set) {
val = repr->attribute("fill");
@@ -1209,10 +1220,18 @@ sp_style_merge_property(SPStyle *style, gint id, gchar const *val)
break;
/* Paint */
case SP_PROP_COLOR_INTERPOLATION:
- g_warning("Unimplemented style property SP_PROP_COLOR_INTERPOLATION: value: %s", val);
+ // We read it but issue warning
+ SPS_READ_IENUM_IF_UNSET(&style->color_interpolation, val, enum_color_interpolation, true);
+ if( style->color_interpolation.value != SP_CSS_COLOR_INTERPOLATION_SRGB ) {
+ g_warning("Inkscape currently only supports color-interpolation = sRGB");
+ }
break;
case SP_PROP_COLOR_INTERPOLATION_FILTERS:
- g_warning("Unimplemented style property SP_PROP_INTERPOLATION_FILTERS: value: %s", val);
+ // We read it but issue warning
+ SPS_READ_IENUM_IF_UNSET(&style->color_interpolation_filters, val, enum_color_interpolation, true);
+ if( style->color_interpolation_filters.value != SP_CSS_COLOR_INTERPOLATION_SRGB ) {
+ g_warning("Inkscape currently only supports color-interpolation-filters = sRGB");
+ }
break;
case SP_PROP_COLOR_PROFILE:
g_warning("Unimplemented style property SP_PROP_COLOR_PROFILE: value: %s", val);
@@ -1710,6 +1729,13 @@ sp_style_merge_from_parent(SPStyle *const style, SPStyle const *const parent)
if (!style->color.set || style->color.inherit) {
sp_style_merge_ipaint(style, &style->color, &parent->color);
}
+ if (!style->color_interpolation.set || style->color_interpolation.inherit) {
+ style->color_interpolation.computed = parent->color_interpolation.computed;
+ }
+ if (!style->color_interpolation_filters.set || style->color_interpolation_filters.inherit) {
+ style->color_interpolation_filters.computed = parent->color_interpolation_filters.computed;
+ }
+
/* Fill */
if (!style->fill.set || style->fill.inherit || style->fill.currentcolor) {
@@ -2095,8 +2121,8 @@ sp_style_merge_from_dying_parent(SPStyle *const style, SPStyle const *const pare
{
SPIEnum SPStyle::*const fields[] = {
&SPStyle::clip_rule,
- //nyi: SPStyle::color_interpolation,
- //nyi: SPStyle::color_interpolation_filters,
+ &SPStyle::color_interpolation,
+ &SPStyle::color_interpolation_filters,
//nyi: SPStyle::color_rendering,
&SPStyle::direction,
&SPStyle::fill_rule,
@@ -2533,6 +2559,9 @@ sp_style_write_string(SPStyle const *const style, guint const 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_ienum(p, c + BMAX - p, "color-interpolation", enum_color_interpolation, &style->color_interpolation, NULL, flags);
+ p += sp_style_write_ienum(p, c + BMAX - p, "color-interpolation-filters", enum_color_interpolation, &style->color_interpolation_filters, NULL, flags);
+
p += sp_style_write_ipaint(p, c + BMAX - p, "fill", &style->fill, NULL, flags);
// if fill:none, skip writing fill properties
@@ -2700,6 +2729,8 @@ sp_style_write_difference(SPStyle const *const from, SPStyle const *const to)
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_ienum(p, c + BMAX - p, "color-interpolation", enum_color_interpolation, &from->color_interpolation, &to->color_interpolation, SP_STYLE_FLAG_IFDIFF);
+ p += sp_style_write_ienum(p, c + BMAX - p, "color-interpolation-filters", enum_color_interpolation, &from->color_interpolation_filters, &to->color_interpolation_filters, SP_STYLE_FLAG_IFDIFF);
p += sp_style_write_ipaint(p, c + BMAX - p, "fill", &from->fill, &to->fill, SP_STYLE_FLAG_IFDIFF);
// if fill:none, skip writing fill properties
@@ -2943,6 +2974,8 @@ sp_style_clear(SPStyle *style)
style->color.clear();
style->color.setColor(0.0, 0.0, 0.0);
+ style->color_interpolation.value = style->color_interpolation.computed = SP_CSS_COLOR_INTERPOLATION_SRGB;
+ style->color_interpolation_filters.value = style->color_interpolation_filters.computed = SP_CSS_COLOR_INTERPOLATION_LINEARRGB;
style->fill.clear();
style->fill.setColor(0.0, 0.0, 0.0);
@@ -4290,6 +4323,12 @@ sp_style_unset_property_attrs(SPObject *o)
if (style->color.set) {
repr->setAttribute("color", NULL);
}
+ if (style->color_interpolation.set) {
+ repr->setAttribute("color-interpolation", NULL);
+ }
+ if (style->color_interpolation_filters.set) {
+ repr->setAttribute("color-interpolation-filters", NULL);
+ }
if (style->fill.set) {
repr->setAttribute("fill", NULL);
}
diff --git a/src/style.h b/src/style.h
index b8b3d6c0d..6150b03c7 100644
--- a/src/style.h
+++ b/src/style.h
@@ -349,6 +349,10 @@ struct SPStyle {
/** color */
SPIPaint color;
+ /** color-interpolation */
+ SPIEnum color_interpolation;
+ /** color-interpolation-filters */
+ SPIEnum color_interpolation_filters;
/** fill */
SPIPaint fill;
@@ -579,6 +583,12 @@ enum SPEnableBackground {
SP_CSS_BACKGROUND_NEW
};
+enum SPColorInterpolation {
+ SP_CSS_COLOR_INTERPOLATION_AUTO,
+ SP_CSS_COLOR_INTERPOLATION_SRGB,
+ SP_CSS_COLOR_INTERPOLATION_LINEARRGB
+};
+
/// An SPTextStyle has a refcount, a font family, and a font name.
struct SPTextStyle {
int refcount;