Files

67 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""Build the GRUB theme for the main menu from the PSD design."""
import os
from psd_tools import PSDImage
from PIL import Image
SRC = '/path/to/pf/PSD/UEFI/x64/main/main.psd'
OUT = '/path/to/pf/ParavisGrub/theme/main'
os.makedirs(OUT, exist_ok=True)
KEEP = {'главное меню', 'дополнительное меню', '© paravis.ru', 'paravis flash'}
psd = PSDImage.open(SRC)
def keep_headers(layer):
for ch in layer:
if ch.kind == 'type' and (ch.name or '').strip().lower() not in KEEP:
ch.visible = False
elif ch.kind == 'group':
keep_headers(ch)
for layer in psd:
nm = (layer.name or '')
if nm.startswith('ТЕКСТ_БЕЗ_ОБВОДКИ'):
for ch in layer:
ch.visible = False
elif nm.startswith('ТЕКСТ_С_ОБВОДКОЙ'):
keep_headers(layer)
bg = psd.composite()
bg.save(os.path.join(OUT, 'background.png'))
print('background:', bg.size)
# --- highlight bar -> 9-slice (w / c / e)
bar = Image.open(os.path.join(OUT, 'sel_bar.png')).convert('RGBA')
W, H = bar.size
cap_w = 28
cap_e = 84
bar.crop((0, 0, cap_w, H)).save(os.path.join(OUT, 'sel_w.png'))
bar.crop((W - cap_e, 0, W, H)).save(os.path.join(OUT, 'sel_e.png'))
# center: 1px column from the flat middle, replicated
mid = bar.crop((W // 2, 0, W // 2 + 1, H))
mid.resize((4, H)).save(os.path.join(OUT, 'sel_c.png'))
print('sel slices: w=%dx%d c=4x%d e=%dx%d' % (cap_w, H, H, cap_e, H))
# --- font info
fonts = set()
for layer in psd.descendants():
if layer.kind == 'type':
try:
eng = layer.engine_dict or {}
for run in (eng.get('StyleRun') or {}).get('RunArray') or []:
f = run.get('StyleSheet', {}).get('StyleSheetData', {}).get('Font')
if f is not None:
fonts.add(f)
except Exception:
pass
print('font indices used:', sorted(fonts))
try:
fs = psd.font_set
for i in sorted(fonts):
print(' font[%s]:' % i, fs[i] if i < len(fs) else '?')
except Exception as e:
print(' font_set unreadable:', e)