Skip to content

Commit

Permalink
image delegates ratio on drawImage
Browse files Browse the repository at this point in the history
  • Loading branch information
rapto committed Dec 17, 2022
1 parent 8b3b493 commit 353fc1a
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/z3c/rml/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,14 @@ class IImage(interfaces.IRMLDirectiveSignature):
required=False,
acceptAuto=True)

anchor = attr.Choice(
title=u'Text Anchor',
description=u'The position in the text to which the coordinates refer.',
choices='''nw n ne
w c e
sw s se'''.split(),
required=False)


class Image(CanvasRMLDirective):
signature = IImage
Expand All @@ -384,24 +392,8 @@ class Image(CanvasRMLDirective):

def process(self):
kwargs = dict(self.getAttributeValues(attrMapping=self.attrMapping))
preserve = kwargs.pop('preserveAspectRatio')
show = kwargs.pop('showBoundary')

if preserve:
imgX, imgY = kwargs['image'].getSize()

# Scale image correctly, if width and/or height were specified
if 'width' in kwargs and 'height' not in kwargs:
kwargs['height'] = imgY * kwargs['width'] / imgX
elif 'height' in kwargs and 'width' not in kwargs:
kwargs['width'] = imgX * kwargs['height'] / imgY
elif 'width' in kwargs and 'height' in kwargs:
if float(kwargs['width']) / \
kwargs['height'] > float(imgX) / imgY:
kwargs['width'] = imgX * kwargs['height'] / imgY
else:
kwargs['height'] = imgY * kwargs['width'] / imgX

canvas = attr.getManager(self, interfaces.ICanvasManager).canvas
getattr(canvas, self.callable)(**kwargs)

Expand Down

0 comments on commit 353fc1a

Please sign in to comment.