安卓断电充电动画使用恢复UI,但如果我想显示纹理,它应该调用"gr_init_font()",它需要一个"font.png“来初始化字体。
我不知道哪种工具可以制作font.png。

发布于 2020-12-11 11:10:50
我自己回答,一个python脚本,Roboto-Regular.ttf,Roboto-Boldttf来生成Roboto.png:
from PIL import Image, ImageDraw, ImageFont
import os
def draw_png(name, font_size = 40):
font_reg = ImageFont.truetype(name + '-Regular' + '.ttf', font_size)
font_bold = ImageFont.truetype(name + '-Bold' + '.ttf', font_size)
text=r''' !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'''
text_width, text_height = font_bold.getsize(text)
max_w = 0
max_h = 0
for c in text:
w, h = font_bold.getsize(c)
if w > max_w:
max_w = w
if h > max_h:
max_h = h
print max_w, max_h
image = Image.new(mode='RGB', size=(max_w*96, max_h*2))
draw_table = ImageDraw.Draw(im=image)
i = 0
for c in text:
text_width, text_height = font_bold.getsize(c)
print c , text_width, text_height
draw_table.text(xy=(max_w*i, 0), text=c, fill='#ffffff', font=font_reg, anchor="mm", align="center")
draw_table.text(xy=(max_w*i, max_h), text=c, fill='#ffffff', font=font_bold, anchor="mm",align="center")
i = i + 1
image.show()
image.save( name + '.png', 'PNG')
image.close()
if __name__ == "__main__":
print('running:')
try:
draw_png('Roboto')
except Exception as e:
print( ' ERR: ', e)https://stackoverflow.com/questions/65180151
复制相似问题