try:
pdfmetrics.getFont(fontname)
except Exception:
- _logger.warning('Could not locate font %s, substituting default: %s',
- fontname, default_fontname)
+ addition = ""
+ if " " in fontname:
+ addition = ". Your font contains spaces which is not valid in RML."
+ _logger.warning('Could not locate font %s, substituting default: %s%s',
+ fontname, default_fontname, addition)
fontname = default_fontname
return fontname
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
+ if mode:
+ mode = mode.lower()
+
if fontname not in pdfmetrics._fonts:
pdfmetrics.registerFont(TTFont(fontname, filename))
if mode == 'all':
addMapping(face, 0, 1, fontname) #italic
addMapping(face, 1, 0, fontname) #bold
addMapping(face, 1, 1, fontname) #italic and bold
- elif (mode== 'normal') or (mode == 'regular'):
- addMapping(face, 0, 0, fontname) #normal
- elif mode == 'italic':
+ elif mode in ['italic', 'oblique']:
addMapping(face, 0, 1, fontname) #italic
elif mode == 'bold':
addMapping(face, 1, 0, fontname) #bold
- elif mode == 'bolditalic':
+ elif mode in ('bolditalic', 'bold italic','boldoblique', 'bold oblique'):
addMapping(face, 1, 1, fontname) #italic and bold
+ else:
+ addMapping(face, 0, 0, fontname) #normal
def _textual_image(self, node):
rc = ''
text = utils.xml2str(text)
try:
self.canvas.drawString(text=text, **v)
- except TypeError as e:
+ except TypeError:
_logger.error("Bad RML: <drawString> tag requires attributes 'x' and 'y'!")
- raise e
+ raise
def _drawCenteredString(self, node):
v = utils.attr_get(node, ['x','y'])