我已经看到了一些关于如何通过不同模块检索字体列表的答案,例如在matlab或Tkinter,但我不想包含像这样的大型库来解决我当前检索的问题这个清单。
后台:我正在开发一个html到pdf系统,它可以在OSX和ubuntu服务器上运行,所以答案不能只是单个操作系统实现
TL; DR: python中是否有任何光模块/库可以让我检索托管服务器上的现有字体列表?
答案 0 :(得分:2)
我写了一个脚本来验证是否安装了Helvetica Neue和Courier:
def verify_fonts_are_installed_for_statements():
import subprocess
from os import path
potential_locations = [
'/usr/bin/fc-list',
'/usr/sbin/fc-list',
'/usr/local/sbin/fc-list',
'/usr/local/bin/fc-list',
]
valid_path = None
for file_path in potential_locations:
if path.exists(file_path):
valid_path = file_path
break
if valid_path is None:
raise IOError('could not find fc-list to verify fonts exist.')
cmd = [valid_path]
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
if 'Helvetica Neue' not in output:
raise FontNotInstalledException('Helvetica Neue')
if 'Courier' not in output:
raise FontNotInstalledException('Courier')
log.debug('Courier and Helvetica Neue were found to be installed.')