DOCX Input: Add font-weight/style normal declarations, needed by Amazon's renderers

This commit is contained in:
Kovid Goyal 2025-04-18 21:23:03 +05:30
parent f9023cced6
commit b78ebe5fbc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -167,10 +167,15 @@ class Fonts:
fname = self.write(name, dest_dir, docx, variant) fname = self.write(name, dest_dir, docx, variant)
if fname is not None: if fname is not None:
d = {'font-family':'"{}"'.format(name.replace('"', '')), 'src': f'url("fonts/{fname}")'} d = {'font-family':'"{}"'.format(name.replace('"', '')), 'src': f'url("fonts/{fname}")'}
# The Kindle rendered needs font-weight/style normal for non bold/italic fonts
if 'Bold' in variant: if 'Bold' in variant:
d['font-weight'] = 'bold' d['font-weight'] = 'bold'
else:
d['font-weight'] = 'normal'
if 'Italic' in variant: if 'Italic' in variant:
d['font-style'] = 'italic' d['font-style'] = 'italic'
else:
d['font-style'] = 'normal'
d = [f'{k}: {v}' for k, v in iteritems(d)] d = [f'{k}: {v}' for k, v in iteritems(d)]
d = ';\n\t'.join(d) d = ';\n\t'.join(d)
defs.append(f'@font-face {{\n\t{d}\n}}\n') defs.append(f'@font-face {{\n\t{d}\n}}\n')