···
# TODO: Support drawing ellipses without manually using Path
···
outputFile.write(self.TAG_NAME)
for k, v in self.args.items():
30
+
k = k.replace('__', ':')
outputFile.write('{}="{}" '.format(k,v))
···
if isinstance(other, type(self)):
50
+
class Image(DrawingBasicElement):
51
+
''' A linked or embedded raster image '''
55
+
'.bmp': 'image/bmp',
56
+
'.gif': 'image/gif',
57
+
'.jpeg':'image/jpeg',
58
+
'.jpg': 'image/jpeg',
59
+
'.png': 'image/png',
60
+
'.tif': 'image/tiff',
61
+
'.tiff':'image/tiff',
62
+
'.pdf': 'application/pdf',
63
+
'.txt': 'text/plain',
65
+
MIME_DEFAULT = 'image/png'
66
+
def __init__(self, x, y, width, height, path=None, data=None, embed=False,
67
+
mimeType=None, **kwargs):
68
+
''' Specify either the path or data argument. If path is used and
69
+
embed is True, the image file is embedded in a data URI. '''
70
+
if path is None and data is None:
71
+
raise ValueError('Either path or data arguments must be given')
72
+
if mimeType is None and path is not None:
73
+
ext = os.path.splitext(path)[1].lower()
74
+
if ext in self.MIME_MAP:
75
+
mimeType = self.MIME_MAP[ext]
77
+
mimeType = self.MIME_DEFAULT
78
+
warnings.warn('Unknown image file type "{}"'.format(ext), Warning)
79
+
if mimeType is None:
80
+
mimeType = self.MIME_DEFAULT
81
+
warnings.warn('Unspecified image type; assuming png'.format(ext), Warning)
82
+
if data is not None:
84
+
if embed and data is None:
85
+
with open(path, 'rb') as f:
90
+
encData = base64.b64encode(data).decode()
91
+
uri = 'data:{};base64,{}'.format(mimeType, encData)
92
+
super().__init__(x=x, y=-y-height, width=width, height=height,
class Rectangle(DrawingBasicElement):