PDF: Check for allowed font name before adding modifiers to the name

This commit is contained in:
Martin Gross
2024-03-27 12:54:35 +01:00
parent d866c6954d
commit ce826e50f7

View File

@@ -935,10 +935,6 @@ class Renderer:
def _draw_textarea(self, canvas: Canvas, op: OrderPosition, order: Order, o: dict):
font = o['fontfamily']
if o['bold']:
font += ' B'
if o['italic']:
font += ' I'
# Since pdfmetrics.registerFont is global, we want to make sure that no one tries to sneak in a font, they
# should not have access to.
@@ -946,6 +942,11 @@ class Renderer:
logger.warning(f'Unauthorized use of font "{font}"')
font = 'Open Sans'
if o['bold']:
font += ' B'
if o['italic']:
font += ' I'
try:
ad = getAscentDescent(font, float(o['fontsize']))
except KeyError: # font not known, fall back