From 60396cbeefe16cc9b28df499a7fa46faf905bef4 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 24 Jul 2013 22:03:13 -0400 Subject: [PATCH] add support for direct-image-filters --- lib/carto/tree/style.js | 13 ++++++++++++- test/rendering-mss/scale-hsla-filter.mss | 5 +++++ test/rendering-mss/scale-hsla-filter.xml | 5 +++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/rendering-mss/scale-hsla-filter.mss create mode 100644 test/rendering-mss/scale-hsla-filter.xml diff --git a/lib/carto/tree/style.js b/lib/carto/tree/style.js index 059c93e..3aac090 100644 --- a/lib/carto/tree/style.js +++ b/lib/carto/tree/style.js @@ -5,13 +5,16 @@ var _ = require('underscore'); // return a stringified style for Mapnik tree.StyleXML = function(name, attachment, definitions, env) { var existing = {}; - var image_filters = [], comp_op = [], opacity = []; + var image_filters = [], direct_image_filters = [], comp_op = [], opacity = []; for (var i = 0; i < definitions.length; i++) { for (var j = 0; j < definitions[i].rules.length; j++) { if (definitions[i].rules[j].name === 'image-filters') { image_filters.push(definitions[i].rules[j]); } + if (definitions[i].rules[j].name === 'direct-image-filters') { + direct_image_filters.push(definitions[i].rules[j]); + } if (definitions[i].rules[j].name === 'comp-op') { comp_op.push(definitions[i].rules[j]); } @@ -35,6 +38,14 @@ tree.StyleXML = function(name, attachment, definitions, env) { }).value().join(',') + '"'; } + if (direct_image_filters.length) { + attrs_xml += ' direct-image-filters="' + _.chain(image_filters) + // prevent identical filters from being duplicated in the style + .uniq(function(i) { return i.id; }).map(function(f) { + return f.ev(env).toXML(env, true, ',', 'direct-image-filter'); + }).value().join(',') + '"'; + } + if (comp_op.length) { attrs_xml += ' comp-op="' + comp_op[0].value.ev(env).toString() + '"'; } diff --git a/test/rendering-mss/scale-hsla-filter.mss b/test/rendering-mss/scale-hsla-filter.mss new file mode 100644 index 0000000..84843ed --- /dev/null +++ b/test/rendering-mss/scale-hsla-filter.mss @@ -0,0 +1,5 @@ +#layer { + polygon-fill:red; + image-filters:scale-hsla(.5,.5,.5,.5,.5,.5,.5,.5); + direct-image-filters:scale-hsla(.5,.5,.5,.5,.5,.5,.5,.5); +} \ No newline at end of file diff --git a/test/rendering-mss/scale-hsla-filter.xml b/test/rendering-mss/scale-hsla-filter.xml new file mode 100644 index 0000000..e52c149 --- /dev/null +++ b/test/rendering-mss/scale-hsla-filter.xml @@ -0,0 +1,5 @@ + \ No newline at end of file