Files

22 lines
799 B
Python

#!/usr/bin/env python3
"""Check how the padded labels measure up (and why the tag column drifts)."""
import re
from PIL import ImageFont
CFG = '/path/to/pf/ParavisGrub/grub.cfg'
font = ImageFont.truetype('/tmp/Paravis.ttf', 18)
for line in open(CFG, encoding='utf-8'):
m = re.match(r'\s*menuentry "(.+?)" --hotkey=(\S+)', line)
if not m:
continue
label, hk = m.group(1), m.group(2)
w_all = font.getlength(label)
stripped = label.rstrip()
w_txt = font.getlength(stripped)
tag = re.search(r'\((\w+)\)$', stripped)
body = stripped[:tag.start()] if tag else stripped
w_body = font.getlength(body)
print('hk=%-2s total=%6.1f body=%6.1f tagstarts=%6.1f spaces=%2d %r' % (
hk, w_all, w_body, w_body, len(label) - len(stripped), stripped[:40]))