在我的电脑上,似乎只有一个Ubuntu Condensed字体文件。即:
/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-C.ttf
然而,在LibreOffice中,我可以将此字体设置为粗体和斜体:
![enter image description here](https://istack.dev59.com/OiOnH.webp)
/* CSS for bold and italic Ubuntu Condensed font */
font-family: Ubuntu Condensed;
font-style: italic;
font-weight: 700;
或者:
/* CSS for regular and normal Ubuntu Condensed font */
font-family: Ubuntu Condensed;
font-style: normal;
font-weight: 400;
然而,当涉及到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
但是Ubuntu Condensed字体无法实现加粗或斜体。
所以问题是,是否有可能在PIL/Pillow中使用加粗和/或斜体的Ubuntu Condensed字体绘制图像?或者至少是否有可能生成四个Ubuntu Condensed文件,以便可以像从Python使用Ubuntu字体一样使用它?
ImageFont
模块吗?它具有load()
和TrueType()
函数,在这里可能会很有用。 (编辑:这里是文档!) - ladygremlinUbuntu-C.ttf
,然后选择我想要的样式(比如斜体或正常)。似乎没有这方面的选项。 - Andriy Makukha