···
# TODO: Support drawing ellipses without manually using Path
···
outputFile.write(self.TAG_NAME)
for k, v in self.args.items():
outputFile.write('{}="{}" '.format(k,v))
···
if isinstance(other, type(self)):
class Rectangle(DrawingBasicElement):
···
# TODO: Support drawing ellipses without manually using Path
···
outputFile.write(self.TAG_NAME)
for k, v in self.args.items():
+
k = k.replace('__', ':')
outputFile.write('{}="{}" '.format(k,v))
···
if isinstance(other, type(self)):
+
class Image(DrawingBasicElement):
+
''' A linked or embedded raster image '''
+
'.pdf': 'application/pdf',
+
MIME_DEFAULT = 'image/png'
+
def __init__(self, x, y, width, height, path=None, data=None, embed=False,
+
mimeType=None, **kwargs):
+
''' Specify either the path or data argument. If path is used and
+
embed is True, the image file is embedded in a data URI. '''
+
if path is None and data is None:
+
raise ValueError('Either path or data arguments must be given')
+
if mimeType is None and path is not None:
+
ext = os.path.splitext(path)[1].lower()
+
if ext in self.MIME_MAP:
+
mimeType = self.MIME_MAP[ext]
+
mimeType = self.MIME_DEFAULT
+
warnings.warn('Unknown image file type "{}"'.format(ext), Warning)
+
mimeType = self.MIME_DEFAULT
+
warnings.warn('Unspecified image type; assuming png'.format(ext), Warning)
+
if embed and data is None:
+
with open(path, 'rb') as f:
+
encData = base64.b64encode(data).decode()
+
uri = 'data:{};base64,{}'.format(mimeType, encData)
+
super().__init__(x=x, y=-y-height, width=width, height=height,
class Rectangle(DrawingBasicElement):