···
super().__init__(x=x, y=-y-height, width=width, height=height,
xlink__href=uri, **kwargs)
-
class Text(DrawingBasicElement):
Additional keyword arguments are output as additional arguments to the
SVG node e.g. fill="red", font_size=20, text_anchor="middle". '''
-
def __init__(self, text, fontSize, x, y, center=False, **kwargs):
if 'text_anchor' not in kwargs:
kwargs['text_anchor'] = 'middle'
fontSize = float(fontSize)
-
translate = 'translate(0,{})'.format(fontSize*0.5*center)
if 'transform' in kwargs:
kwargs['transform'] = translate + ' ' + kwargs['transform']
···
super().__init__(x=x, y=-y, font_size=fontSize, **kwargs)
self.escapedText = xml.escape(text)
def writeContent(self, idGen, isDuplicate, outputFile, dryRun):
···
super().__init__(x=x, y=-y-height, width=width, height=height,
xlink__href=uri, **kwargs)
+
class Text(DrawingParentElement):
Additional keyword arguments are output as additional arguments to the
SVG node e.g. fill="red", font_size=20, text_anchor="middle". '''
+
def __init__(self, text, fontSize, x, y, center=False, lineHeight=1,
+
singleLine = isinstance(text, str)
if 'text_anchor' not in kwargs:
kwargs['text_anchor'] = 'middle'
+
centerOffset = fontSize*0.5*center
+
emOffset = 0.4 - lineHeight * (numLines - 1) / 2
fontSize = float(fontSize)
+
translate = 'translate(0,{})'.format(centerOffset)
if 'transform' in kwargs:
kwargs['transform'] = translate + ' ' + kwargs['transform']
···
super().__init__(x=x, y=-y, font_size=fontSize, **kwargs)
+
self.escapedText = xml.escape(text)
+
for i, line in enumerate(text):
+
dy = '{}em'.format(emOffset if i == 0 else lineHeight)
+
self.appendLine(line, x=x, dy=dy)
+
def writeContent(self, idGen, isDuplicate, outputFile, dryRun):
+
outputFile.write(self.escapedText)
+
def writeChildrenContent(self, idGen, isDuplicate, outputFile, dryRun):
+
''' Override in a subclass to add data between the start and end
+
tags. This will not be called if hasContent is False. '''
+
for child in self.children:
+
child.writeSvgElement(idGen, isDuplicate, outputFile, dryRun)
+
for child in self.children:
+
child.writeSvgElement(idGen, isDuplicate, outputFile, dryRun)
+
def appendLine(self, line, **kwargs):
+
self.append(TSpan(line, **kwargs))
+
class TSpan(DrawingBasicElement):
+
''' A line of text within the Text element. '''
+
def __init__(self, text, **kwargs):
+
super().__init__(**kwargs)
self.escapedText = xml.escape(text)
def writeContent(self, idGen, isDuplicate, outputFile, dryRun):