gpt4 book ai didi

python - 如何从Python脚本获取X字体路径?

转载 作者:太空宇宙 更新时间:2023-11-03 17:43:32 25 4
gpt4 key购买 nike

从在 X 下启动的 Python 脚本中,我想获取字体路径。

脚本将字体路径传递给Xvnc(TightVNC 和 TigerVNC 的一部分)。是的,我知道,要启动 VNC 服务器,可以使用 startvnc,它负责设置字体路径。但是,startvnc 执行了一些在本例中不需要的操作。另外,我想使用与启动脚本的 X 服务器上完全相同的字体路径。

我考虑解析xset q的输出。但是:

  • 我不知道这有多可靠,即输出是否始终格式化同样的方法。

  • 输出可能包含实际上不是路径的占位符。为了例如,内置:/usr/share/fonts/misc,/usr/share/fonts/Type1,内置

最佳答案

阅读 manual对于 xorg.conf,最安全的选择是解析配置文件(我假设 setx q 解析)中的 FontPath 行,如下所示:

FontPath "path" sets the search path for fonts. This path is a comma separated list of font path elements which the Xorg server searches for font databases.

使用Python的re模块中,字体路径(因为可以指定多个 FontPath)可以这样解析:

import re
regex = re.compile(r'^\s*FontPath\s+(.*)\s*$', re.MULTILINE)

with open('xorg.conf') as f:
data = f.read()
matches = regex.findall(data)

关于python - 如何从Python脚本获取X字体路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30141195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com