From 3e3b4f09bceaec0cacec5f637ace519e0e94a29a Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Thu, 10 May 2012 18:28:57 -0400 Subject: [PATCH] Add comp-op support. --- lib/carto/tree/reference.json | 35 ++++++++++++++++++++++++++++++++ lib/carto/tree/style.js | 15 ++++++++++++-- test/rendering/image_filters.mss | 1 + 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/lib/carto/tree/reference.json b/lib/carto/tree/reference.json index c347d0f..71ed8bf 100644 --- a/lib/carto/tree/reference.json +++ b/lib/carto/tree/reference.json @@ -55,6 +55,41 @@ "default-meaning": "no filters", "type": "imagefilters", "doc": "A list of image filters. Currently supported are agg-stack-blur, emboss, blur, gray, sobel, edge-detect, x-gradient, y-gradient, sharpen" + }, + "comp-op": { + "css": "composite-operation", + "default-value": "src-over", + "default-meaning": "add the current layer on top of other layers", + "doc": "Composite operation. This defines how this layer should behave relative to layers atop or below it.", + "type": ["clear", + "src", + "dst", + "src-over", + "dst-over", + "src-in", + "dst-in", + "src-out", + "dst-out", + "src-atop", + "dst-atop", + "xor", + "plus", + "minus", + "multiply", + "screen", + "overlay", + "darken", + "lighten", + "color-dodge", + "color-burn", + "hard-light", + "soft-light", + "difference", + "exclusion", + "contrast", + "invert", + "invert-rgb" + ] } }, "map": { diff --git a/lib/carto/tree/style.js b/lib/carto/tree/style.js index f89ea0b..91f3994 100644 --- a/lib/carto/tree/style.js +++ b/lib/carto/tree/style.js @@ -16,19 +16,30 @@ tree.Style.prototype.toXML = function(env) { }); })); + var comp_op = _.flatten(this.definitions.map(function(definition) { + return definition.rules.filter(function(rule) { + return (rule.name === 'composite-operation'); + }); + })); + var rules = this.definitions.map(function(definition) { return definition.toXML(env, existing); }); - var image_filters_xml = ''; + var image_filters_xml = '', + comp_op_xml = ''; if (image_filters.length) { image_filters_xml = 'image-filters="' + image_filters.map(function(f) { return f.value.eval(env).toString(env, null, ';'); }).join(',') + '"'; } + + if (comp_op.length) { + comp_op_xml = 'comp-op="' + comp_op[0].value.eval(env).toString() + '"'; + } - return ''; + return ''; }; })(require('../tree')); diff --git a/test/rendering/image_filters.mss b/test/rendering/image_filters.mss index 5a57d74..73bd15a 100644 --- a/test/rendering/image_filters.mss +++ b/test/rendering/image_filters.mss @@ -3,5 +3,6 @@ line-color:#F00; line-width: 0.5; image-filters: blur(), sharpen(); + composite-operation: src-in; line-dasharray: 2, 3; }