diff --git a/color_randomize.py b/color_randomize.py
index bf07de4bc9104b9c2a708457f3ec8883920f43bf..4e9f8b41952a251bb7644179c70dfbbf9c16d98c 100755
--- a/color_randomize.py
+++ b/color_randomize.py
@@ -44,6 +44,8 @@ class Randomize(inkex.ColorExtension):
return hsl.to_rgb()
def modify_opacity(self, name, opacity):
+ if name != "opacity":
+ return opacity
try:
opacity = float(opacity)
except ValueError:
diff --git a/inkex/extensions.py b/inkex/extensions.py
index 6f72f8084bbcf52604d3a02fb5af6ad2d917072c..1058dce5cb1baec7334dcc40870e0ef8cdfe24fd 100644
--- a/inkex/extensions.py
+++ b/inkex/extensions.py
@@ -35,6 +35,7 @@ from .elements import load_svg, BaseElement, ShapeElement, Group, Layer, Grid, \
from .elements._utils import CloningVat
from .base import InkscapeExtension, SvgThroughMixin, SvgInputMixin, SvgOutputMixin, TempDirMixin
from .transforms import Transform
+from .properties import all_properties
# All the names that get added to the inkex API itself.
__all__ = ('EffectExtension', 'GenerateExtension', 'InputExtension',
@@ -310,9 +311,10 @@ class ColorExtension(EffectExtension):
pass # bad color value, don't touch.
# Then opacities (usually does nothing)
for name in elem.style.opacity_props:
- value = style.get(name)
- if value is not None:
- elem.style[name] = self.modify_opacity(name, value)
+ value = style(name)
+ result = self.modify_opacity(name, value)
+ if result != value and result != 1: # only modify if not equal to old or default
+ elem.style[name] = result
def _ref_cloned(self, old_id, new_id, style, name):
self._renamed[old_id] = new_id
diff --git a/tests/data/refs/color_randomize__-y__0__-t__0__-m__0__-o__100__--id__layer_group_rect_uu2__--id__layer_group_path__--id__root_rect_uu.out b/tests/data/refs/color_randomize__-y__0__-t__0__-m__0__-o__100__--id__layer_group_rect_uu2__--id__layer_group_path__--id__root_rect_uu.out
new file mode 100644
index 0000000000000000000000000000000000000000..60b426bad913a3daba1691ad7f468f5c459cf724
--- /dev/null
+++ b/tests/data/refs/color_randomize__-y__0__-t__0__-m__0__-o__100__--id__layer_group_rect_uu2__--id__layer_group_path__--id__root_rect_uu.out
@@ -0,0 +1,40 @@
+
\ No newline at end of file
diff --git a/tests/data/refs/color_randomize__-y__50__-t__50__-m__50__-o__100__--id__r1__--id__r2__--id__r3__--id__r4__--id__r5__--id__r6.out b/tests/data/refs/color_randomize__-y__50__-t__50__-m__50__-o__100__--id__r1__--id__r2__--id__r3__--id__r4__--id__r5__--id__r6.out
new file mode 100644
index 0000000000000000000000000000000000000000..480b60b92aa20f97ea9970673ab2530d483b8a12
--- /dev/null
+++ b/tests/data/refs/color_randomize__-y__50__-t__50__-m__50__-o__100__--id__r1__--id__r2__--id__r3__--id__r4__--id__r5__--id__r6.out
@@ -0,0 +1,43 @@
+
\ No newline at end of file
diff --git a/tests/data/refs/inkex_extensions_color.out b/tests/data/refs/inkex_extensions_color.out
index 00971ed4aed111eae4409098b0e1495330902f9c..f2d7ded02d29c0cdb124812b70c5bd49d47d0452 100644
--- a/tests/data/refs/inkex_extensions_color.out
+++ b/tests/data/refs/inkex_extensions_color.out
@@ -24,15 +24,15 @@
]]>
-
+
-
+
-
+
-
+
-
+
-
+
\ No newline at end of file
diff --git a/tests/data/refs/inkex_extensions_color__--id__color_svg.out b/tests/data/refs/inkex_extensions_color__--id__color_svg.out
index 00971ed4aed111eae4409098b0e1495330902f9c..f2d7ded02d29c0cdb124812b70c5bd49d47d0452 100644
--- a/tests/data/refs/inkex_extensions_color__--id__color_svg.out
+++ b/tests/data/refs/inkex_extensions_color__--id__color_svg.out
@@ -24,15 +24,15 @@
]]>
-
+
-
+
-
+
-
+
-
+
-
+
\ No newline at end of file
diff --git a/tests/data/refs/inkex_extensions_color__--id__r1.out b/tests/data/refs/inkex_extensions_color__--id__r1.out
index b14a1fb8a913e619ddf4f2520bd5708a1cea4b8f..2a106d1de3cbc0d8a88a8e2199e64359e18d8b60 100644
--- a/tests/data/refs/inkex_extensions_color__--id__r1.out
+++ b/tests/data/refs/inkex_extensions_color__--id__r1.out
@@ -24,7 +24,7 @@
]]>
-
+
diff --git a/tests/data/refs/inkex_extensions_color__--id__r1__--id__r2.out b/tests/data/refs/inkex_extensions_color__--id__r1__--id__r2.out
index 0e560286fe8bee42257edd0c3bfa063bd0c4719a..176992b4e64253a1f2004ccd64e95f63bfa2937d 100644
--- a/tests/data/refs/inkex_extensions_color__--id__r1__--id__r2.out
+++ b/tests/data/refs/inkex_extensions_color__--id__r1__--id__r2.out
@@ -24,9 +24,9 @@
]]>
-
+
-
+
diff --git a/tests/data/refs/inkex_extensions_color__--id__r2.out b/tests/data/refs/inkex_extensions_color__--id__r2.out
index 6c9b7f5fb5993164364c21a0dd250cc94e8be431..430e485b8469ec95cad79fe03e2911249ed0e3a2 100644
--- a/tests/data/refs/inkex_extensions_color__--id__r2.out
+++ b/tests/data/refs/inkex_extensions_color__--id__r2.out
@@ -26,7 +26,7 @@
-
+
diff --git a/tests/data/refs/inkex_extensions_color__--id__r3.out b/tests/data/refs/inkex_extensions_color__--id__r3.out
index 81170c8115e96d5cf104970fbe91b3e346a29fb0..f663d51bd420ce1c6dcb1c394192fb390326fb62 100644
--- a/tests/data/refs/inkex_extensions_color__--id__r3.out
+++ b/tests/data/refs/inkex_extensions_color__--id__r3.out
@@ -28,7 +28,7 @@
-
+
diff --git a/tests/data/refs/inkex_extensions_color__--id__r4.out b/tests/data/refs/inkex_extensions_color__--id__r4.out
index 6983733e2622e3ab198fc6889ea28fa94578ea60..9c93172e57e912ffbee83202f73e1fd1bcf5da12 100644
--- a/tests/data/refs/inkex_extensions_color__--id__r4.out
+++ b/tests/data/refs/inkex_extensions_color__--id__r4.out
@@ -34,7 +34,7 @@
-
+
diff --git a/tests/test_color_randomize.py b/tests/test_color_randomize.py
index 153f9db16618dd7ade50e1598ca37409c666966a..044e88ecd489faf2f9cdef0ae715956b62299e70 100644
--- a/tests/test_color_randomize.py
+++ b/tests/test_color_randomize.py
@@ -1,6 +1,7 @@
# coding=utf-8
from color_randomize import Randomize
from .test_inkex_extensions import ColorBaseCase
+from inkex.tester import ComparisonMixin, TestCase
class ColorRandomizeTest(ColorBaseCase):
effect_class = Randomize
@@ -33,8 +34,32 @@ class ColorRandomizeTest(ColorBaseCase):
(1.0, 0.43, ['-o 100']),
# Other units are available
('0.5', 0.654, ['-o 54']),
+ # Test no opacity
+ # The opacity value should be lesser than 1
]
def test_bad_opacity(self):
"""Bad opacity error handled"""
self.effect.modify_opacity('opacity', 'hello')
+
+class TestRandomizeGradients(ComparisonMixin, TestCase):
+ """Direct tests for color mechanisms"""
+ effect_class = Randomize
+ compare_file = 'svg/colors.svg'
+ python3_only = True
+
+ comparisons = [
+ ('-y 50', '-t 50', '-m 50', '-o 100', "--id=r1", "--id=r2", "--id=r3", "--id=r4",
+ "--id=r5", "--id=r6"),
+ ]
+
+class TestRandomizeOpacity(ComparisonMixin, TestCase):
+ """Direct tests for color mechanisms"""
+ effect_class = Randomize
+ compare_file = 'svg/dpiswitcher_96dpi.svg'
+ python3_only = True
+
+ comparisons = [
+ ('-y 0', '-t 0', '-m 0', '-o 100', "--id=layer_group_rect_uu2", "--id=layer_group_path",
+ "--id=root_rect_uu"),
+ ]
\ No newline at end of file