Reportlab 不能从新注册的字体中获取粗体或斜体



在我的应用程序中,我需要一个可以具有罗马尼亚语的字体,所以我找到了一个带有它们的times.ttf文件,现在我的问题是我不能使用斜体,大胆或大胆或

bolditalic

这是我的代码:

registerFont(TTFont('Times_new', '/usr/share/fonts/truetype/msttcorefonts/times.ttf', subfontIndex=0))
registerFont(TTFont('Times_new-Bold', '/usr/share/fonts/truetype/msttcorefonts/times.ttf', subfontIndex=1))
registerFont(TTFont('Times_new-Italic', '/usr/share/fonts/truetype/msttcorefonts/times.ttf', subfontIndex=2))
registerFont(TTFont('Times_new-BoldItalic', '/usr/share/fonts/truetype/msttcorefonts/times.ttf', subfontIndex=3))
registerFontFamily('Times_new', normal='Times_new', bold='Times_new-B', italic='Times_new-I',
                       boldItalic='Times_new-BI')

styles.add(ParagraphStyle(name="Times", fontName='Times_new'))
styles.add(ParagraphStyle(name="Times-indent-italic", fontName='Times_new-I'))
styles.add(ParagraphStyle(name="Times-center", fontName='Times_new-BI'))
styles.add(ParagraphStyle(name="Times-BoldItalic", fontName='Times_new-BI'))

例如:

如果我写

p_text = "Hello"
report.append(Paragraph(p_text, styles["Times-indent-italic"]))
report.append(Spacer(1, 5))

它会像这样写:你好,当我期望这样的时候:你好。基本上,我想使用的任何字体选项都将使用普通字体。任何iDeea我能做什么?

您确定要引用正确的文件名吗?在我的系统上,所有变体都在自己的TTF文件中:

$ locate times | grep ttf
/usr/local/share/fonts/webfonts/times.ttf
/usr/local/share/fonts/webfonts/timesbd.ttf
/usr/local/share/fonts/webfonts/timesbi.ttf
/usr/local/share/fonts/webfonts/timesi.ttf

我看到您仅引用" times.ttf"。也许您的代码应该阅读:

registerFont(TTFont('Times_new', '/usr/share/fonts/truetype/msttcorefonts/times.ttf', subfontIndex=0))
registerFont(TTFont('Times_new-Bold', '/usr/share/fonts/truetype/msttcorefonts/timesbd.ttf', subfontIndex=1))
registerFont(TTFont('Times_new-Italic', '/usr/share/fonts/truetype/msttcorefonts/timesi.ttf', subfontIndex=2))
registerFont(TTFont('Times_new-BoldItalic', '/usr/share/fonts/truetype/msttcorefonts/timesbi.ttf', subfontIndex=3))

最新更新