将不同的字体样式应用于不同的文本行(python + Raspberry Pi)

时间:2018-08-11 12:44:37

标签: python text fonts raspberry-pi lines

我正在使用导入请求从网页读取文本。 文本的组织方式为: 标题1(第1行) 报价A(第2行) 报价B(第3行) 标题2(第4行) 报价C(第5行) 引用D(第6行) ... 理想情况下,我希望能够控制前三行的字体,大小和颜色(文本的格式为一个标题和两个引号) 到目前为止,我正在阅读文本,然后使用Luma的终端库将文本打印到外部OLED显示器

global data
global allLines
data  =requests.get('https://api.thingspeak.com/webpage....')
allLines = data.text.split('\n')#split it into lines

使用'split'将文本分成几行,并传递给列表allLines 此时,我制作了一种字体:

def make_font(name, size):
    font_path = os.path.abspath(os.path.join(
        os.path.dirname(__file__), 'fonts', name))
    return ImageFont.truetype(font_path, size)

然后开始阅读每一行,每行都具有相同的字体,大小和颜色:

for fontname, size in [("Volter__28Goldfish_29.ttf", 24)]:
    font = make_font(fontname, size) if fontname else None

for line in allLines:           
        term = terminal(device, font, color="blue", line_height=22)
        term.println(line)
        time.sleep(1)

        term.clear()
        term.flush()

我觉得应该在组织for循环的方式中发生一些事情,但无法弄清楚是什么。谁能指出我的资源或提出想法?

0 个答案:

没有答案