Python 3.x Reportlab无法从新注册的字体中获取粗体或斜体

Python 3.x Reportlab无法从新注册的字体中获取粗体或斜体,python-3.x,fonts,reportlab,Python 3.x,Fonts,Reportlab,在我的应用程序中,我需要一种可以有罗马尼亚语发音符号的字体,所以我找到了一个有罗马尼亚语发音符号的times.ttf文件,我现在的问题是我不能使用斜体、粗体或粗体斜体 这是我的密码: registerFont(TTFont('Times_new', '/usr/share/fonts/truetype/msttcorefonts/times.ttf', subfontIndex=0)) registerFont(TTFont('Times_new-Bold', '/usr/share/fonts

在我的应用程序中,我需要一种可以有罗马尼亚语发音符号的字体,所以我找到了一个有罗马尼亚语发音符号的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/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))

它会这样写:你好,当我期待它像这样:你好。基本上,无论我想用什么字体,它都会使用普通字体。你知道我能做什么吗?

你确定引用的文件名正确吗?在我的系统上,所有变体都位于各自的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))

是的,你是对的,我看到了一个坏例子,在所有变体上使用相同的文件,我现在使用courier new,每个变体都有一个文件,所以答案是,每个变体都必须使用一个文件。