在我的电脑上,我只有一个用于Ubuntu Condensed字体的文件.即:
/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-C.ttf
Run Code Online (Sandbox Code Playgroud)
但是,在LibreOffice中,我可以将此字体设为粗体和斜体:
在Ubuntu字体测试器网页上,我还可以为Ubuntu Condensed系列设置不同的字体粗细(即常规和粗体)和不同的字体样式(即正常和斜体).在CSS中,这可能转化为:
/* CSS for bold and italic Ubuntu Condensed font */
font-family: Ubuntu Condensed;
font-style: italic;
font-weight: 700;
Run Code Online (Sandbox Code Playgroud)
要么:
/* CSS for regular and normal Ubuntu Condensed font */
font-family: Ubuntu Condensed;
font-style: normal;
font-weight: 400;
Run Code Online (Sandbox Code Playgroud)
但是,当谈到Python的PIL/Pillow时,我找不到ImageFont中任何可以修改字体样式和/或重量的工作选项,除了用ImageFont.truetype()
函数加载不同的字体文件.
对于"常规"Ubuntu字体(不是Condensed),我可以加载四个单独文件中的一个,以在Python中获得普通,粗体,斜体和粗体+斜体样式:
/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-R.ttf
/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-RI.ttf
/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-B.ttf
/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-BI.ttf
Run Code Online (Sandbox Code Playgroud)
但不适用于Ubuntu Condensed.
所以问题是,是否可以在PIL/Pillow中使用粗体和/或斜体Ubuntu Condensed字体绘制图像?或者至少可以生成四个Ubuntu Condensed文件,以便它可以像Python中的Ubuntu字体一样使用?