Skip to content

Commit

Permalink
Add mask attribute to image tag and allow mask to be set to "auto" ev…
Browse files Browse the repository at this point in the history
…erywhere it's used
  • Loading branch information
kylemacfarlane committed Feb 5, 2015
1 parent d82297f commit aee6f70
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/z3c/rml/attr.py
Expand Up @@ -443,13 +443,16 @@ class Color(RMLAttribute):
specification.
"""

def __init__(self, acceptNone=False, *args, **kw):
def __init__(self, acceptNone=False, acceptAuto=False, *args, **kw):
super(Color, self).__init__(*args, **kw)
self.acceptNone = acceptNone
self.acceptAuto = acceptAuto

def fromUnicode(self, value):
if self.acceptNone and value.lower() == 'none':
return None
if self.acceptAuto and value.lower() == 'auto':
return 'auto'
manager = getManager(self.context)

if value.startswith('rml:'):
Expand Down
6 changes: 6 additions & 0 deletions src/z3c/rml/canvas.py
Expand Up @@ -341,6 +341,12 @@ class IImage(interfaces.IRMLDirectiveSignature):
default=False,
required=False)

mask = attr.Color(
title=u'Mask',
description=u'The color mask used to render the image.',
required=False,
acceptAuto=True)

class Image(CanvasRMLDirective):
signature = IImage
callable = 'drawImage'
Expand Down
6 changes: 4 additions & 2 deletions src/z3c/rml/flowable.py
Expand Up @@ -904,7 +904,8 @@ class IImage(interfaces.IRMLDirectiveSignature):
mask = attr.Color(
title=u'Mask',
description=u'The color mask used to render the image.',
required=False)
required=False,
acceptAuto=True)

align = attr.Choice(
title=u'Alignment',
Expand Down Expand Up @@ -980,7 +981,8 @@ class IImageAndFlowables(interfaces.IRMLDirectiveSignature):
imageMask = attr.Color(
title=u'Mask',
description=u'The height the image.',
required=False)
required=False,
acceptAuto=True)

imageLeftPadding = attr.Measurement(
title=u'Image Left Padding',
Expand Down
Binary file added src/z3c/rml/tests/expected/tag-image-mask.pdf
Binary file not shown.
Binary file added src/z3c/rml/tests/input/images/cylinder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/z3c/rml/tests/input/tag-image-mask.rml
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE document SYSTEM "rml.dtd">

<document
filename="tag-image-svg.pdf"
xmlns:doc="http://namespaces.zope.org/rml/doc">
<pageDrawing>

<image file="[z3c.rml.tests]/input/images/cylinder.png"
x="10mm" y="10mm" mask="auto" />

</pageDrawing>
</document>
3 changes: 3 additions & 0 deletions src/z3c/rml/tests/test_rml.py
Expand Up @@ -134,6 +134,9 @@ def test_suite():
if not filename.endswith(".rml"):
continue

if 'image-mask' not in filename:
continue

inPath = os.path.join(inputDir, filename)
outPath = os.path.join(outputDir, filename[:-4] + '.pdf')
expectPath = os.path.join(expectDir, filename[:-4] + '.pdf')
Expand Down

0 comments on commit aee6f70

Please sign in to comment.