Add build, deploy and test sources
This commit is contained in:
1 parent
b962581812
commit
3d1a08f230
259 files changed
+15273
No files matched your search
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
python3 - <<'EOF'
|
||||
from PIL import Image
|
||||
im = Image.open('/mnt/f/efi/Paravis/Boot/xor/Main1.bmp').convert('RGB')
|
||||
crop = im.crop((40, 470, 480, 510))
|
||||
crop = crop.resize((crop.width*3, crop.height*3), Image.LANCZOS)
|
||||
crop.save('/path/to/pf/KRD/crop-kaspersky.png')
|
||||
crop2 = im.crop((40, 412, 480, 452)).resize((440*3, 40*3), Image.LANCZOS)
|
||||
crop2.save('/path/to/pf/KRD/crop-gfm.png')
|
||||
print('ok')
|
||||
EOF
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
python3 - <<'EOF'
|
||||
import numpy as np
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
bmp = Image.open('/mnt/f/efi/Paravis/Boot/xor/Main1.bmp').convert('L')
|
||||
|
||||
def cmp(cropbox, text, path, size, stroke=0):
|
||||
crop = bmp.crop(cropbox)
|
||||
A = np.array(crop) < 128
|
||||
ys, xs = np.where(A)
|
||||
T = A[ys.min():ys.max()+1, xs.min():xs.max()+1]
|
||||
f = ImageFont.truetype(path, size)
|
||||
img = Image.new('L', (800, 100), 255)
|
||||
ImageDraw.Draw(img).text((20, 20), text, font=f, fill=0, stroke_width=stroke, stroke_fill=0)
|
||||
m = np.array(img) < 128
|
||||
ys2, xs2 = np.where(m)
|
||||
B = m[ys2.min():ys2.max()+1, xs2.min():xs2.max()+1]
|
||||
ha, wa = T.shape; hb, wb = B.shape; best = 0
|
||||
for dy in range(-4, 5):
|
||||
for dx in range(-5, 6):
|
||||
y0 = max(0, dy); x0 = max(0, dx)
|
||||
y1 = min(ha, hb+dy); x1 = min(wa, wb+dx)
|
||||
if y1 <= y0 or x1 <= x0: continue
|
||||
s1 = T[y0:y1, x0:x1]; s2 = B[y0-dy:y1-dy, x0-dx:x1-dx]
|
||||
u = np.logical_or(s1, s2).sum()
|
||||
if u: best = max(best, np.logical_and(s1, s2).sum()/u)
|
||||
return T.shape, B.shape, best
|
||||
|
||||
tests = [
|
||||
('Перезагрузка (R)', (44, 620, 240, 650)),
|
||||
('Super Grub2 (поиск и запуск ОС)', (44, 126, 470, 155)),
|
||||
]
|
||||
fonts = {
|
||||
'SegoeUI-Semibold23': ('/mnt/c/Windows/Fonts/seguisb.ttf', 23),
|
||||
'SegoeUI-Bold22': ('/mnt/c/Windows/Fonts/segoeuib.ttf', 22),
|
||||
'SegoeUI23': ('/mnt/c/Windows/Fonts/segoeui.ttf', 23),
|
||||
'Ubuntu23': ('/mnt/d/GIT/aspia_no2fa-3.0/vcpkg4aspia/buildtrees/harfbuzz/src/14.2.1-f76ca539fc.clean/test/subset/data/fonts/Ubuntu-Regular.ttf', 23),
|
||||
'Roboto23': ('/mnt/d/GIT/aspia_no2fa-3.0/vcpkg4aspia/buildtrees/harfbuzz/src/14.2.1-f76ca539fc.clean/test/subset/data/fonts/Roboto-Regular.ttf', 23),
|
||||
}
|
||||
for t, box in tests:
|
||||
print('==', t)
|
||||
for name,(path,size) in fonts.items():
|
||||
try:
|
||||
ts, bs, s = cmp(box, t, path, size)
|
||||
print(f' {name:22s} target={ts} rendered={bs} IoU={s:.3f}')
|
||||
except Exception as e:
|
||||
print(' ', name, 'err', e)
|
||||
EOF
|
||||
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
F=/path/to/pf/PSD/fonts/Montserrat-SemiBold.ttf
|
||||
echo "=== сигнатура:"
|
||||
xxd -l 16 "$F"
|
||||
pip install --quiet fonttools brotli >/dev/null 2>&1
|
||||
python3 - <<'EOF'
|
||||
from fontTools.ttLib import TTFont
|
||||
import os
|
||||
src = '/path/to/pf/PSD/fonts/Montserrat-SemiBold.ttf'
|
||||
with open(src, 'rb') as fh:
|
||||
sig = fh.read(4)
|
||||
print('sig:', sig)
|
||||
dst = '/path/to/pf/PSD/fonts/Montserrat-SemiBold.ttf'
|
||||
if sig in (b'wOFF', b'wOF2'):
|
||||
f = TTFont(src)
|
||||
f.flavor = None
|
||||
out = '/path/to/pf/PSD/fonts/Montserrat-SemiBold.ttf'
|
||||
f.save(out)
|
||||
print('converted ->', out, os.path.getsize(out), 'bytes')
|
||||
elif sig in (b'\x00\x01\x00\x00', b'true', b'OTTO'):
|
||||
print('already ttf/otf')
|
||||
else:
|
||||
print('unknown')
|
||||
EOF
|
||||
ls -l /path/to/pf/PSD/fonts/
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
python3 -m pip install --quiet --break-system-packages fonttools 2>/dev/null || true
|
||||
python3 - <<'EOF'
|
||||
from fontTools.ttLib import TTFont
|
||||
p='/tmp/Montserrat.ttf'
|
||||
f=TTFont(p)
|
||||
print('family:', f['name'].getDebugName(1), '| subfamily:', f['name'].getDebugName(2))
|
||||
if 'fvar' in f:
|
||||
for a in f['fvar'].axes:
|
||||
print(' axis', a.axisTag, a.minValue, a.defaultValue, a.maxValue)
|
||||
else:
|
||||
print(' static font')
|
||||
EOF
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/bin/bash
|
||||
pip install --quiet pillow numpy >/dev/null 2>&1
|
||||
python3 - <<'EOF'
|
||||
import numpy as np
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
import glob, os
|
||||
|
||||
# 1. Кроп надписи с картинки
|
||||
bmp = Image.open('/mnt/f/efi/Paravis/Boot/xor/Main1.bmp').convert('L')
|
||||
crop = bmp.crop((44, 476, 316, 506)) # с запасом вокруг текста
|
||||
a = np.array(crop)
|
||||
target = (a < 128) # тёмный текст
|
||||
ys, xs = np.where(target)
|
||||
print('target ink bbox:', xs.min(), xs.max(), ys.min(), ys.max(), 'pixels:', target.sum())
|
||||
|
||||
text = 'Kaspersky Rescue Disk 18'
|
||||
|
||||
def render(font_path, size):
|
||||
try:
|
||||
f = ImageFont.truetype(font_path, size)
|
||||
except Exception:
|
||||
return None
|
||||
img = Image.new('L', (600, 80), 255)
|
||||
d = ImageDraw.Draw(img)
|
||||
try:
|
||||
d.text((10, 10), text, font=f, fill=0)
|
||||
except Exception:
|
||||
return None
|
||||
m = np.array(img) < 128
|
||||
if not m.any():
|
||||
return None
|
||||
ys, xs = np.where(m)
|
||||
return m[ys.min():ys.max()+1, xs.min():xs.max()+1]
|
||||
|
||||
def score(A, B):
|
||||
# A: target crop, B: rendered mask; пробуем сдвиги
|
||||
best = -1
|
||||
ha, wa = A.shape; hb, wb = B.shape
|
||||
for dy in range(-3, 4):
|
||||
for dx in range(-3, 4):
|
||||
# размещаем B в A со сдвигом
|
||||
y0 = max(0, dy); x0 = max(0, dx)
|
||||
y1 = min(ha, hb + dy); x1 = min(wa, wb + dx)
|
||||
if y1 <= y0 or x1 <= x0: continue
|
||||
sub = A[y0:y1, x0:x1]
|
||||
subB = B[y0-dy:y1-dy, x0-dx:x1-dx]
|
||||
inter = np.logical_and(sub, subB).sum()
|
||||
union = np.logical_or(sub, subB).sum()
|
||||
if union == 0: continue
|
||||
s = inter / union
|
||||
if s > best: best = s
|
||||
return best
|
||||
|
||||
# цель обрезаем по чернилам для корректного сравнения
|
||||
ys, xs = np.where(target)
|
||||
T = target[ys.min():ys.max()+1, xs.min():xs.max()+1]
|
||||
|
||||
results = []
|
||||
fonts = glob.glob('/mnt/c/Windows/Fonts/*.ttf') + glob.glob('/mnt/c/Windows/Fonts/*.otf')
|
||||
for fp in fonts:
|
||||
for size in (20, 21, 21.63, 22, 23):
|
||||
B = render(fp, size)
|
||||
if B is None: continue
|
||||
if abs(B.shape[1] - T.shape[1]) > 12: # грубый отсев по ширине
|
||||
continue
|
||||
s = score(T, B)
|
||||
if s > 0:
|
||||
results.append((s, os.path.basename(fp), size, B.shape))
|
||||
|
||||
results.sort(reverse=True)
|
||||
print('--- top-15:')
|
||||
for s, name, size, shape in results[:15]:
|
||||
print(f' {s:.3f} {name:32s} size={size:<5} shape={shape}')
|
||||
EOF
|
||||
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
python3 - <<'EOF'
|
||||
import numpy as np, glob
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
bmp = Image.open('/mnt/f/efi/Paravis/Boot/xor/Main1.bmp').convert('L')
|
||||
crop = bmp.crop((44, 476, 316, 506))
|
||||
A = np.array(crop) < 128
|
||||
ys, xs = np.where(A)
|
||||
T = A[ys.min():ys.max()+1, xs.min():xs.max()+1]
|
||||
TH, TW = T.shape
|
||||
print('target', TW, 'x', TH)
|
||||
|
||||
fonts = {
|
||||
'Roboto': '/mnt/d/GIT/aspia_no2fa-3.0/vcpkg4aspia/buildtrees/harfbuzz/src/14.2.1-f76ca539fc.clean/test/subset/data/fonts/Roboto-Regular.ttf',
|
||||
'SourceSansPro': '/mnt/d/GIT/aspia_no2fa-3.0/vcpkg4aspia/buildtrees/harfbuzz/src/14.2.1-f76ca539fc.clean/test/subset/data/fonts/SourceSansPro-Regular.otf',
|
||||
'Ubuntu': '/mnt/d/GIT/aspia_no2fa-3.0/vcpkg4aspia/buildtrees/harfbuzz/src/14.2.1-f76ca539fc.clean/test/subset/data/fonts/Ubuntu-Regular.ttf',
|
||||
'SegoeUI-Semibold': '/mnt/c/Windows/Fonts/seguisb.ttf',
|
||||
'SegoeUI-Bold': '/mnt/c/Windows/Fonts/segoeuib.ttf',
|
||||
'SegoeUI': '/mnt/c/Windows/Fonts/segoeui.ttf',
|
||||
}
|
||||
text = 'Kaspersky Rescue Disk 18'
|
||||
|
||||
def render(path, size):
|
||||
try:
|
||||
f = ImageFont.truetype(path, size)
|
||||
except Exception:
|
||||
return None
|
||||
img = Image.new('L', (700, 100), 255)
|
||||
d = ImageDraw.Draw(img)
|
||||
try:
|
||||
d.text((20, 20), text, font=f, fill=0)
|
||||
except Exception:
|
||||
return None
|
||||
m = np.array(img) < 128
|
||||
if not m.any(): return None
|
||||
ys, xs = np.where(m)
|
||||
return m[ys.min():ys.max()+1, xs.min():xs.max()+1]
|
||||
|
||||
def iou(A, B):
|
||||
ha, wa = A.shape; hb, wb = B.shape
|
||||
best = 0
|
||||
for dy in range(-3, 4):
|
||||
for dx in range(-4, 5):
|
||||
y0 = max(0, dy); x0 = max(0, dx)
|
||||
y1 = min(ha, hb+dy); x1 = min(wa, wb+dx)
|
||||
if y1 <= y0 or x1 <= x0: continue
|
||||
s1 = A[y0:y1, x0:x1]; s2 = B[y0-dy:y1-dy, x0-dx:x1-dx]
|
||||
u = np.logical_or(s1, s2).sum()
|
||||
if u: best = max(best, np.logical_and(s1, s2).sum()/u)
|
||||
return best
|
||||
|
||||
rows = [('ORIGINAL', crop)]
|
||||
for name, path in fonts.items():
|
||||
best = (0, None, None)
|
||||
for size10 in range(190, 260, 5):
|
||||
size = size10/10.0
|
||||
B = render(path, size)
|
||||
if B is None: continue
|
||||
if abs(B.shape[1]-TW) > 10: continue
|
||||
s = iou(T, B)
|
||||
if s > best[0]: best = (s, size, B)
|
||||
if best[1]:
|
||||
print(f'{name:18s} size={best[1]:.1f} IoU={best[0]:.3f}')
|
||||
im = Image.new('RGB', (272, 30), (233,233,233))
|
||||
try:
|
||||
f = ImageFont.truetype(path, best[1])
|
||||
ImageDraw.Draw(im).text((6, 2), text, font=f, fill=(41,55,84))
|
||||
except Exception:
|
||||
pass
|
||||
rows.append((f'{name} {best[1]}', im))
|
||||
|
||||
scale = 3
|
||||
out = Image.new('RGB', (272*scale, sum(r[1].height*scale+6 for r in rows)+10), (255,255,255))
|
||||
y = 5
|
||||
d = ImageDraw.Draw(out)
|
||||
for name, im in rows:
|
||||
im2 = im.resize((im.width*scale, im.height*scale), Image.LANCZOS)
|
||||
out.paste(im2, (0, y)); d.text((272*scale-200, y+2), name, fill=(0,0,0))
|
||||
y += im2.height+6
|
||||
out.save('/path/to/pf/KRD/font-candidates2.png')
|
||||
print('saved')
|
||||
EOF
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
python3 - <<'EOF'
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
text = 'Kaspersky Rescue Disk 18'
|
||||
orig = Image.open('/mnt/f/efi/Paravis/Boot/xor/Main1.bmp').convert('RGB').crop((44, 476, 316, 506))
|
||||
|
||||
cands = [
|
||||
('Segoe UI Semibold', '/mnt/c/Windows/Fonts/seguisb.ttf', 23),
|
||||
('Segoe UI Bold', '/mnt/c/Windows/Fonts/segoeuib.ttf', 22),
|
||||
('Segoe UI', '/mnt/c/Windows/Fonts/segoeui.ttf', 23),
|
||||
('Arial Bold', '/mnt/c/Windows/Fonts/arialbd.ttf', 21),
|
||||
('Tahoma Bold', '/mnt/c/Windows/Fonts/tahomabd.ttf', 21),
|
||||
('Verdana Bold', '/mnt/c/Windows/Fonts/verdanab.ttf', 20),
|
||||
('Calibri Bold', '/mnt/c/Windows/Fonts/calibrib.ttf', 23),
|
||||
('Trebuchet Bold', '/mnt/c/Windows/Fonts/trebucbd.ttf', 22),
|
||||
('Franklin Gothic', '/mnt/c/Windows/Fonts/framd.ttf', 22),
|
||||
('PhagsPa Bold', '/mnt/c/Windows/Fonts/phagspab.ttf', 22),
|
||||
]
|
||||
|
||||
rows = [('ORIGINAL', orig)]
|
||||
for name, path, size in cands:
|
||||
try:
|
||||
f = ImageFont.truetype(path, size)
|
||||
except Exception as e:
|
||||
print('skip', name, e); continue
|
||||
img = Image.new('RGB', (272, 30), (233, 233, 233))
|
||||
d = ImageDraw.Draw(img)
|
||||
d.text((6, 2), text, font=f, fill=(41, 55, 84))
|
||||
rows.append((name, img))
|
||||
|
||||
scale = 3
|
||||
W = 272 * scale
|
||||
H = sum(r[1].height * scale + 6 for r in rows) + 10
|
||||
out = Image.new('RGB', (W, H), (255, 255, 255))
|
||||
y = 5
|
||||
d2 = ImageDraw.Draw(out)
|
||||
for name, im in rows:
|
||||
im2 = im.resize((im.width*scale, im.height*scale), Image.LANCZOS)
|
||||
out.paste(im2, (0, y))
|
||||
d2.text((W-190, y+2), name, fill=(0, 0, 0))
|
||||
y += im2.height + 6
|
||||
out.save('/path/to/pf/KRD/font-candidates.png')
|
||||
print('saved')
|
||||
EOF
|
||||
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
python3 - <<'EOF'
|
||||
import numpy as np, glob, os
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
bmp = Image.open('/mnt/f/efi/Paravis/Boot/xor/Main1.bmp').convert('L')
|
||||
crop = bmp.crop((44, 620, 240, 650))
|
||||
A = np.array(crop) < 128
|
||||
ys, xs = np.where(A)
|
||||
T = A[ys.min():ys.max()+1, xs.min():xs.max()+1]
|
||||
TH, TW = T.shape
|
||||
print('target', TW, TH)
|
||||
|
||||
texts = [('Перезагрузка (R)', (44, 620, 240, 650), T)]
|
||||
|
||||
def render(path, text, size, stroke=0):
|
||||
try:
|
||||
f = ImageFont.truetype(path, size)
|
||||
img = Image.new('L', (900, 120), 255)
|
||||
ImageDraw.Draw(img).text((20, 20), text, font=f, fill=0, stroke_width=stroke, stroke_fill=0)
|
||||
except Exception:
|
||||
return None
|
||||
m = np.array(img) < 128
|
||||
if not m.any(): return None
|
||||
ys, xs = np.where(m)
|
||||
return m[ys.min():ys.max()+1, xs.min():xs.max()+1]
|
||||
|
||||
def iou(A, B):
|
||||
ha, wa = A.shape; hb, wb = B.shape; best = 0
|
||||
for dy in range(-4, 5):
|
||||
for dx in range(-5, 6):
|
||||
y0 = max(0, dy); x0 = max(0, dx)
|
||||
y1 = min(ha, hb+dy); x1 = min(wa, wb+dx)
|
||||
if y1 <= y0 or x1 <= x0: continue
|
||||
s1 = A[y0:y1, x0:x1]; s2 = B[y0-dy:y1-dy, x0-dx:x1-dx]
|
||||
u = np.logical_or(s1, s2).sum()
|
||||
if u: best = max(best, np.logical_and(s1, s2).sum()/u)
|
||||
return best
|
||||
|
||||
fonts = glob.glob('/mnt/c/Windows/Fonts/*.ttf') + glob.glob('/mnt/c/Windows/Fonts/*.otf')
|
||||
fonts += glob.glob('/mnt/d/GIT/aspia_no2fa-3.0/vcpkg4aspia/buildtrees/harfbuzz/src/*/test/subset/data/fonts/*.ttf')
|
||||
fonts += glob.glob('/mnt/d/GIT/aspia_no2fa-3.0/vcpkg4aspia/buildtrees/harfbuzz/src/*/test/subset/data/fonts/*.otf')
|
||||
|
||||
res = []
|
||||
for fp in fonts:
|
||||
for size10 in range(200, 245, 5):
|
||||
size = size10/10.0
|
||||
B = render(fp, 'Перезагрузка (R)', size)
|
||||
if B is None or abs(B.shape[1]-TW) > 6: continue
|
||||
s = iou(T, B)
|
||||
res.append((s, os.path.basename(fp), size, B.shape[1]))
|
||||
res.sort(reverse=True)
|
||||
seen = set(); out = []
|
||||
for s, n, size, w in res:
|
||||
if n in seen: continue
|
||||
seen.add(n); out.append((s, n, size, w))
|
||||
if len(out) >= 20: break
|
||||
for s, n, size, w in out:
|
||||
print(f' {s:.3f} {n:34s} size={size:<5} w={w}')
|
||||
EOF
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
python3 - <<'EOF'
|
||||
import numpy as np
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
bmp = Image.open('/mnt/f/efi/Paravis/Boot/xor/Main1.bmp').convert('L')
|
||||
crop = bmp.crop((44, 476, 316, 506))
|
||||
A = np.array(crop) < 128
|
||||
ys, xs = np.where(A); T = A[ys.min():ys.max()+1, xs.min():xs.max()+1]
|
||||
|
||||
text = 'Kaspersky Rescue Disk 18'
|
||||
path = '/mnt/c/Windows/Fonts/seguisb.ttf'
|
||||
|
||||
def render(size, stroke):
|
||||
f = ImageFont.truetype(path, size)
|
||||
img = Image.new('L', (700, 100), 255)
|
||||
d = ImageDraw.Draw(img)
|
||||
d.text((20, 20), text, font=f, fill=0, stroke_width=stroke, stroke_fill=0)
|
||||
m = np.array(img) < 128
|
||||
ys, xs = np.where(m)
|
||||
return m[ys.min():ys.max()+1, xs.min():xs.max()+1]
|
||||
|
||||
def iou(A, B):
|
||||
ha, wa = A.shape; hb, wb = B.shape; best = 0
|
||||
for dy in range(-4, 5):
|
||||
for dx in range(-5, 6):
|
||||
y0 = max(0, dy); x0 = max(0, dx)
|
||||
y1 = min(ha, hb+dy); x1 = min(wa, wb+dx)
|
||||
if y1 <= y0 or x1 <= x0: continue
|
||||
s1 = A[y0:y1, x0:x1]; s2 = B[y0-dy:y1-dy, x0-dx:x1-dx]
|
||||
u = np.logical_or(s1, s2).sum()
|
||||
if u: best = max(best, np.logical_and(s1, s2).sum()/u)
|
||||
return best
|
||||
|
||||
best = (-1,)
|
||||
for size10 in range(215, 245, 5):
|
||||
for stroke10 in range(0, 9, 2):
|
||||
size = size10/10.0; stroke = stroke10/10.0
|
||||
B = render(size, stroke)
|
||||
if abs(B.shape[1]-T.shape[1]) > 8: continue
|
||||
s = iou(T, B)
|
||||
print(f' size={size:.1f} stroke={stroke:.1f} w={B.shape[1]} IoU={s:.3f}')
|
||||
if s > best[0]: best = (s, size, stroke)
|
||||
print('BEST:', best)
|
||||
EOF
|
||||
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
cd /tmp
|
||||
# Montserrat (SemiBold) — шрифт из макета
|
||||
if [ ! -f /tmp/Montserrat-SemiBold.ttf ]; then
|
||||
curl -sSL --max-time 300 -o /tmp/Montserrat.ttf \
|
||||
"https://github.com/google/fonts/raw/main/ofl/montserrat/Montserrat%5Bwght%5D.ttf" || true
|
||||
curl -sSL --max-time 300 -o /tmp/Montserrat-SemiBold.ttf \
|
||||
"https://github.com/google/fonts/raw/main/ofl/montserrat/static/Montserrat-SemiBold.ttf" || true
|
||||
fi
|
||||
ls -l /tmp/Montserrat-SemiBold.ttf 2>/dev/null || echo " semibold download failed"
|
||||
file /tmp/Montserrat-SemiBold.ttf 2>/dev/null | head -1
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
T=/path/to/pf/ParavisGrub/theme/main
|
||||
mkdir -p "$T"
|
||||
|
||||
echo "=== instantiate Montserrat 600 (SemiBold) + pf2"
|
||||
python3 - <<'EOF'
|
||||
from fontTools.ttLib import TTFont
|
||||
from fontTools.varLib.instancer import instantiateVariableFont
|
||||
f = TTFont('/tmp/Montserrat.ttf')
|
||||
inst = instantiateVariableFont(f, {'wght': 600})
|
||||
inst.save('/tmp/Montserrat-SemiBold.ttf')
|
||||
print(' saved /tmp/Montserrat-SemiBold.ttf')
|
||||
EOF
|
||||
grub-mkfont -s 17 -o "$T/paravis.pf2" /tmp/Montserrat-SemiBold.ttf
|
||||
ls -l "$T/paravis.pf2"
|
||||
@@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
python3 - <<'EOF'
|
||||
import numpy as np
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
bmp = Image.open('/mnt/f/efi/Paravis/Boot/xor/Main1.bmp').convert('L')
|
||||
crop = bmp.crop((44, 476, 316, 506))
|
||||
A = np.array(crop) < 128
|
||||
ys, xs = np.where(A); T = A[ys.min():ys.max()+1, xs.min():xs.max()+1]
|
||||
print('target', T.shape)
|
||||
|
||||
text = 'Kaspersky Rescue Disk 18'
|
||||
path = '/path/to/pf/PSD/fonts/Montserrat-SemiBold.ttf'
|
||||
|
||||
def render(size):
|
||||
f = ImageFont.truetype(path, size)
|
||||
img = Image.new('L', (700, 100), 255)
|
||||
ImageDraw.Draw(img).text((20, 20), text, font=f, fill=0)
|
||||
m = np.array(img) < 128
|
||||
ys, xs = np.where(m)
|
||||
return m[ys.min():ys.max()+1, xs.min():xs.max()+1]
|
||||
|
||||
def iou(A, B):
|
||||
ha, wa = A.shape; hb, wb = B.shape; best = 0
|
||||
for dy in range(-4, 5):
|
||||
for dx in range(-5, 6):
|
||||
y0 = max(0, dy); x0 = max(0, dx)
|
||||
y1 = min(ha, hb+dy); x1 = min(wa, wb+dx)
|
||||
if y1 <= y0 or x1 <= x0: continue
|
||||
s1 = A[y0:y1, x0:x1]; s2 = B[y0-dy:y1-dy, x0-dx:x1-dx]
|
||||
u = np.logical_or(s1, s2).sum()
|
||||
if u: best = max(best, np.logical_and(s1, s2).sum()/u)
|
||||
return best
|
||||
|
||||
best = (0,)
|
||||
for size10 in range(190, 245, 5):
|
||||
size = size10/10.0
|
||||
B = render(size)
|
||||
s = iou(T, B)
|
||||
print(f' size={size:<5} w={B.shape[1]:<4} h={B.shape[0]:<3} IoU={s:.3f}')
|
||||
if s > best[0]: best = (s, size)
|
||||
|
||||
print('BEST', best)
|
||||
# картинка-сравнение
|
||||
im = Image.new('RGB', (272, 30), (233,233,233))
|
||||
ImageDraw.Draw(im).text((6, 2), text, font=ImageFont.truetype(path, best[1]), fill=(41,55,84))
|
||||
orig = Image.open('/mnt/f/efi/Paravis/Boot/xor/Main1.bmp').convert('RGB').crop((44, 476, 316, 506))
|
||||
out = Image.new('RGB', (272*3, 30*3*2+20), (255,255,255))
|
||||
out.paste(orig.resize((orig.width*3, orig.height*3), Image.LANCZOS), (0,0))
|
||||
out.paste(im.resize((im.width*3, im.height*3), Image.LANCZOS), (0,30*3+10))
|
||||
out.save('/path/to/pf/KRD/montserrat-check.png')
|
||||
print('saved')
|
||||
EOF
|
||||
@@ -0,0 +1,61 @@
|
||||
#!/bin/bash
|
||||
python3 - <<'EOF'
|
||||
import numpy as np
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
path = '/path/to/pf/PSD/fonts/Montserrat-VF.ttf'
|
||||
bmp = Image.open('/mnt/f/efi/Paravis/Boot/xor/Main1.bmp').convert('L')
|
||||
crop = bmp.crop((44, 476, 316, 506))
|
||||
A = np.array(crop) < 128
|
||||
ys, xs = np.where(A); T = A[ys.min():ys.max()+1, xs.min():xs.max()+1]
|
||||
print('target', T.shape)
|
||||
|
||||
text = 'Kaspersky Rescue Disk 18'
|
||||
|
||||
def render(size, wght):
|
||||
f = ImageFont.truetype(path, size)
|
||||
try:
|
||||
f.set_variation_by_axes([wght])
|
||||
except Exception as e:
|
||||
print('var err', e); return None
|
||||
img = Image.new('L', (700, 100), 255)
|
||||
ImageDraw.Draw(img).text((20, 20), text, font=f, fill=0)
|
||||
m = np.array(img) < 128
|
||||
ys, xs = np.where(m)
|
||||
return m[ys.min():ys.max()+1, xs.min():xs.max()+1]
|
||||
|
||||
def iou(A, B):
|
||||
ha, wa = A.shape; hb, wb = B.shape; best = 0
|
||||
for dy in range(-4, 5):
|
||||
for dx in range(-5, 6):
|
||||
y0 = max(0, dy); x0 = max(0, dx)
|
||||
y1 = min(ha, hb+dy); x1 = min(wa, wb+dx)
|
||||
if y1 <= y0 or x1 <= x0: continue
|
||||
s1 = A[y0:y1, x0:x1]; s2 = B[y0-dy:y1-dy, x0-dx:x1-dx]
|
||||
u = np.logical_or(s1, s2).sum()
|
||||
if u: best = max(best, np.logical_and(s1, s2).sum()/u)
|
||||
return best
|
||||
|
||||
best = (0,)
|
||||
for wght in (500, 550, 600, 650, 700):
|
||||
for size10 in range(190, 240, 5):
|
||||
size = size10/10.0
|
||||
B = render(size, wght)
|
||||
if B is None: continue
|
||||
s = iou(T, B)
|
||||
if abs(B.shape[1]-T.shape[1]) < 8:
|
||||
print(f' w={wght} size={size:<5} w_px={B.shape[1]:<4} IoU={s:.3f}')
|
||||
if s > best[0]: best = (s, size, wght)
|
||||
print('BEST', best)
|
||||
|
||||
s, size, wght = best
|
||||
im = Image.new('RGB', (272, 30), (233,233,233))
|
||||
f = ImageFont.truetype(path, size); f.set_variation_by_axes([wght])
|
||||
ImageDraw.Draw(im).text((6, 2), text, font=f, fill=(41,55,84))
|
||||
orig = Image.open('/mnt/f/efi/Paravis/Boot/xor/Main1.bmp').convert('RGB').crop((44, 476, 316, 506))
|
||||
out = Image.new('RGB', (272*3, 30*3*2+20), (255,255,255))
|
||||
out.paste(orig.resize((orig.width*3, orig.height*3), Image.LANCZOS), (0,0))
|
||||
out.paste(im.resize((im.width*3, im.height*3), Image.LANCZOS), (0,30*3+10))
|
||||
out.save('/path/to/pf/KRD/montserrat-check.png')
|
||||
print('saved')
|
||||
EOF
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
import struct, sys
|
||||
|
||||
d = open(sys.argv[1], 'rb').read()
|
||||
print('size', len(d), 'head', d[:16])
|
||||
pos = 12
|
||||
while pos + 8 <= len(d) and pos < 200000:
|
||||
name = d[pos:pos+4]
|
||||
if not all(65 <= c <= 90 for c in name):
|
||||
print(' stop at', pos, name)
|
||||
break
|
||||
ln_be = struct.unpack('>I', d[pos+4:pos+8])[0]
|
||||
ln_le = struct.unpack('<I', d[pos+4:pos+8])[0]
|
||||
print(' %s at %d len_be=%d len_le=%d' % (name.decode('latin1'), pos, ln_be, ln_le))
|
||||
pos += 8 + ln_be
|
||||
if ln_be > len(d):
|
||||
break
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
import struct
|
||||
|
||||
PATH = '/path/to/pf/ParavisGrub/theme/paravis.pf2'
|
||||
d = open(PATH, 'rb').read()
|
||||
|
||||
pos = 12
|
||||
sec = {}
|
||||
while pos + 8 <= len(d):
|
||||
name = d[pos:pos+4]
|
||||
if not all(65 <= c <= 90 for c in name):
|
||||
break
|
||||
length = struct.unpack('>I', d[pos+4:pos+8])[0]
|
||||
body_start = pos + 8
|
||||
if length == 0xFFFFFFFF:
|
||||
body = d[body_start:]
|
||||
pos = len(d)
|
||||
else:
|
||||
body = d[body_start:body_start + length]
|
||||
pos = body_start + length
|
||||
sec[name] = body
|
||||
|
||||
chix, data = sec[b'CHIX'], sec[b'DATA']
|
||||
print('chix', len(chix), 'data', len(data), 'entries', len(chix) / 9)
|
||||
|
||||
def parse(order):
|
||||
widths = {}
|
||||
for i in range(len(chix) // 9):
|
||||
e = chix[i * 9:(i + 1) * 9]
|
||||
code = int.from_bytes(e[0:4], order)
|
||||
off = int.from_bytes(e[5:9], 'big')
|
||||
rec = data[off:off + 16]
|
||||
if len(rec) < 16:
|
||||
continue
|
||||
w, h, xo, yo, dw, dh, dxo, dyo = struct.unpack('>HHhhhhhh', rec)
|
||||
widths[chr(code) if code < 0x110000 else '?'] = dw
|
||||
return widths
|
||||
|
||||
for order in ('big', 'little'):
|
||||
w = parse(order)
|
||||
sample = {c: w.get(c) for c in ' A1('}
|
||||
codes = sorted(ord(c) for c in w if c != '?')
|
||||
print(order, 'glyphs', len(w), 'sample', sample,
|
||||
'range', hex(codes[0]) if codes else '-', hex(codes[-1]) if codes else '-')
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Exact text width from a GRUB pf2 font (what GRUB itself uses)."""
|
||||
import struct
|
||||
|
||||
|
||||
def load_pf2(path):
|
||||
data = open(path, 'rb').read()
|
||||
if data[:4] != b'FILE':
|
||||
raise ValueError('not a pf2 file')
|
||||
pos = 12
|
||||
sec = {}
|
||||
while pos + 8 <= len(data):
|
||||
name = data[pos:pos + 4]
|
||||
length = struct.unpack('>I', data[pos + 4:pos + 8])[0]
|
||||
sec[name] = data[pos + 8:pos + 8 + length]
|
||||
pos += 8 + length
|
||||
|
||||
chix = sec.get(b'CHIX', b'')
|
||||
dat = sec.get(b'DATA', b'')
|
||||
widths = {}
|
||||
for i in range(len(chix) // 8):
|
||||
code, off = struct.unpack('>II', chix[i * 8:(i + 1) * 8])
|
||||
rec = dat[off:off + 16]
|
||||
if len(rec) < 16:
|
||||
continue
|
||||
_w, _h, _xo, _yo, dw, _dh, _dxo, _dyo = struct.unpack('>HHhhhhhh', rec)
|
||||
widths[chr(code)] = dw
|
||||
return widths
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
w = load_pf2(sys.argv[1])
|
||||
for ch in ' Aa1(9)':
|
||||
print(repr(ch), w.get(ch))
|
||||
print('space width:', w.get(' '), '| glyphs:', len(w))
|
||||
print('thin spaces:', w.get('\u2009'), w.get('\u200a'), w.get('\u00a0'))
|
||||
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Dump PSD structure with text content / fonts / geometry."""
|
||||
import sys
|
||||
from psd_tools import PSDImage
|
||||
|
||||
path = sys.argv[1] if len(sys.argv) > 1 else '/path/to/pf/PSD/UEFI/x64/main/main.psd'
|
||||
psd = PSDImage.open(path)
|
||||
print('canvas %dx%d' % (psd.width, psd.height))
|
||||
|
||||
|
||||
def walk(layer, depth=0):
|
||||
pad = ' ' * depth
|
||||
kind = layer.kind
|
||||
name = (layer.name or '')
|
||||
bbox = layer.bbox
|
||||
vis = 'vis' if layer.visible else 'HID'
|
||||
extra = ''
|
||||
try:
|
||||
if kind == 'type':
|
||||
eng = layer.engine_dict or {}
|
||||
txt = None
|
||||
try:
|
||||
txt = layer.text
|
||||
except Exception:
|
||||
pass
|
||||
style = (eng.get('StyleRun') or {}).get('RunArray') or []
|
||||
font = size = None
|
||||
if style:
|
||||
rs = style[0].get('StyleSheet', {}).get('StyleSheetData', {})
|
||||
font = rs.get('Font')
|
||||
size = rs.get('FontSize')
|
||||
extra = ' text=%r font=%s size=%s' % ((txt or '')[:40], font, size)
|
||||
except Exception as e:
|
||||
extra = ' <%s>' % e
|
||||
print('%s%-10s %-30s %-24s %s%s' % (pad, kind, name[:30], str(bbox), vis, extra))
|
||||
if kind == 'group':
|
||||
for ch in layer:
|
||||
walk(ch, depth + 1)
|
||||
|
||||
|
||||
for l in psd:
|
||||
walk(l)
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
pip install --quiet psd-tools 2>/dev/null || pip3 install --quiet psd-tools 2>/dev/null
|
||||
python3 - <<'EOF'
|
||||
from psd_tools import PSDImage
|
||||
import os
|
||||
|
||||
files = [
|
||||
('legacy', '/path/to/pf/PSD/main/main.psd'),
|
||||
('uefi-x64', '/path/to/pf/PSD/UEFI/x64/main/main.psd'),
|
||||
('uefi-x86', '/path/to/pf/PSD/UEFI/x86/main/main.psd'),
|
||||
]
|
||||
for tag, path in files:
|
||||
print('='*70)
|
||||
print(tag, path, os.path.getsize(path), 'bytes')
|
||||
psd = PSDImage.open(path)
|
||||
print(' size:', psd.width, 'x', psd.height, 'layers:', len(list(psd.descendants())))
|
||||
for layer in psd.descendants():
|
||||
if layer.kind == 'type':
|
||||
try:
|
||||
eng = layer.engine_dict
|
||||
rd = eng.get('ResourceDict', {})
|
||||
fonts = eng.get('FontSet', [])
|
||||
fname = None
|
||||
sz = None
|
||||
for f in fonts:
|
||||
fname = f.get('Name')
|
||||
st = eng.get('StyleRun', {}).get('RunArray', [])
|
||||
for s in st:
|
||||
ss = s.get('StyleSheet', {}).get('StyleSheetData', {})
|
||||
sz = ss.get('FontSize')
|
||||
col = ss.get('FillColor', {}).get('Values')
|
||||
print(' TEXT:', repr(layer.text[:60]))
|
||||
print(' font:', fname, ' size:', sz, ' color:', col)
|
||||
print(' bbox:', layer.bbox)
|
||||
except Exception as e:
|
||||
print(' layer err:', e)
|
||||
EOF
|
||||
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Export background / highlight from the PSD design (UEFI x64 main)."""
|
||||
import os
|
||||
from psd_tools import PSDImage
|
||||
|
||||
SRC = '/path/to/pf/PSD/UEFI/x64/main/main.psd'
|
||||
OUT = '/path/to/pf/ParavisGrub/theme/main'
|
||||
os.makedirs(OUT, exist_ok=True)
|
||||
|
||||
KEEP_TEXT = {'Главное Меню', 'Дополнительное Меню', '© Paravis.RU', 'Paravis Flash'}
|
||||
|
||||
|
||||
def hide_item_text(layer):
|
||||
"""Hide menu-item text layers, keep headers/decoration."""
|
||||
for ch in layer:
|
||||
if ch.kind == 'type' and (ch.name or '') not in KEEP_TEXT:
|
||||
ch.visible = False
|
||||
elif ch.kind == 'group':
|
||||
hide_item_text(ch)
|
||||
|
||||
|
||||
psd = PSDImage.open(SRC)
|
||||
for layer in psd:
|
||||
nm = layer.name or ''
|
||||
if nm.startswith('ТЕКСТ_БЕЗ_ОБВОДКИ'):
|
||||
for ch in layer:
|
||||
ch.visible = False
|
||||
elif nm.startswith('ТЕКСТ_С_ОБВОДКОЙ'):
|
||||
hide_item_text(layer)
|
||||
|
||||
img = psd.composite()
|
||||
img.save(os.path.join(OUT, 'background.png'))
|
||||
print('background.png', img.size)
|
||||
|
||||
# --- highlight bar: take F2 (item 1) from the hidden "ВЫДЕЛЕНЫЕ_ПУНКТЫ" group
|
||||
psd2 = PSDImage.open(SRC)
|
||||
sel = None
|
||||
for layer in psd2.descendants():
|
||||
if (layer.name or '').strip() in ('F2', 'F3') and layer.kind == 'pixel':
|
||||
if layer.name.strip() == 'F2':
|
||||
sel = layer
|
||||
if sel is None:
|
||||
print('highlight layer not found')
|
||||
else:
|
||||
bar = sel.topil()
|
||||
bar.save(os.path.join(OUT, 'sel_bar.png'))
|
||||
print('sel_bar.png', bar.size, 'bbox', sel.bbox)
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python3
|
||||
from psd_tools import PSDImage
|
||||
|
||||
psd = PSDImage.open('/path/to/pf/PSD/UEFI/x64/main/main.psd')
|
||||
names = set()
|
||||
for layer in psd.descendants():
|
||||
if layer.kind != 'type':
|
||||
continue
|
||||
try:
|
||||
rd = layer.resource_dict or {}
|
||||
for fs in rd.get('FontSet', []) or []:
|
||||
n = fs.get('Name') if hasattr(fs, 'get') else getattr(fs, 'Name', None)
|
||||
if n:
|
||||
names.add(n)
|
||||
except Exception as e:
|
||||
pass
|
||||
print('fonts in document:', sorted(names) or 'not found')
|
||||
|
||||
# fallback: raw resource block scan
|
||||
try:
|
||||
from psd_tools.constants import Resource
|
||||
for k, v in psd.image_resources.items():
|
||||
if 'Font' in str(k):
|
||||
print('resource', k, str(v)[:400])
|
||||
except Exception as e:
|
||||
print('image_resources:', e)
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
python3 - <<'EOF'
|
||||
from psd_tools import PSDImage
|
||||
import os
|
||||
|
||||
for tag, path in [
|
||||
('legacy', '/path/to/pf/PSD/main/main.psd'),
|
||||
('uefi-x64', '/path/to/pf/PSD/UEFI/x64/main/main.psd'),
|
||||
('uefi-x86', '/path/to/pf/PSD/UEFI/x86/main/main.psd'),
|
||||
]:
|
||||
print('='*60); print(tag)
|
||||
psd = PSDImage.open(path)
|
||||
fonts = set()
|
||||
for layer in psd.descendants():
|
||||
if layer.kind != 'type':
|
||||
continue
|
||||
try:
|
||||
eng = layer.engine_dict
|
||||
for f in eng.get('FontSet', []):
|
||||
fonts.add(f.get('Name'))
|
||||
except Exception:
|
||||
pass
|
||||
print(' fonts:', sorted(fonts))
|
||||
# один пример для каждой из интересующих строк
|
||||
for layer in psd.descendants():
|
||||
if layer.kind == 'type' and layer.text and ('Grub2' in layer.text or 'Kaspersky' in layer.text):
|
||||
eng = layer.engine_dict
|
||||
fs = [f.get('Name') for f in eng.get('FontSet', [])]
|
||||
runs = eng.get('StyleRun', {}).get('RunArray', [])
|
||||
info = []
|
||||
for r in runs:
|
||||
d = r.get('StyleSheet', {}).get('StyleSheetData', {})
|
||||
info.append((d.get('Font'), d.get('FontSize'), d.get('FillColor', {}).get('Values')))
|
||||
print(' text:', repr(layer.text[:55]))
|
||||
print(' fonts=', fs, ' runs=', info, ' bbox=', layer.bbox)
|
||||
EOF
|
||||
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo "=== install psd-tools"
|
||||
pip3 install --quiet psd-tools 2>/dev/null || pip3 install --quiet --break-system-packages psd-tools
|
||||
python3 - <<'EOF'
|
||||
from psd_tools import PSDImage
|
||||
p = PSDImage.open('/path/to/pf/PSD/UEFI/x64/main/main.psd')
|
||||
print('canvas: %dx%d mode=%s' % (p.width, p.height, p.color_mode))
|
||||
print('layers (top-level):')
|
||||
for i, l in enumerate(p):
|
||||
print(' %2d %-28s type=%-8s visible=%-5s bbox=%s opacity=%s' % (
|
||||
i, (l.name or '')[:28], l.kind, l.visible, l.bbox, l.opacity))
|
||||
EOF
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
python3 - <<'EOF'
|
||||
from psd_tools import PSDImage
|
||||
psd = PSDImage.open('/path/to/pf/PSD/main/main.psd')
|
||||
for layer in psd.descendants():
|
||||
if layer.kind == 'type' and layer.text and 'Kaspersky' in layer.text:
|
||||
eng = layer.engine_dict
|
||||
print('keys:', list(eng.keys()))
|
||||
fs = eng.get('FontSet')
|
||||
print('FontSet type:', type(fs), 'len:', len(fs) if fs else 0)
|
||||
if fs:
|
||||
for f in fs[:5]:
|
||||
print(' entry keys:', list(f.keys()))
|
||||
print(' ', {k: (v if not isinstance(v, list) else v[:6]) for k, v in f.items()})
|
||||
rd = eng.get('ResourceDict')
|
||||
print('ResourceDict keys:', list(rd.keys()) if rd else None)
|
||||
break
|
||||
EOF
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python3
|
||||
from psd_tools import PSDImage
|
||||
import sys
|
||||
|
||||
for p in sys.argv[1:]:
|
||||
print('=' * 20, p.split('/')[-1])
|
||||
psd = PSDImage.open(p)
|
||||
for layer in psd:
|
||||
print(' group %-30s vis=%s bbox=%s' % ((layer.name or '')[:30], layer.visible, layer.bbox))
|
||||
for ch in layer:
|
||||
if ch.kind == 'type':
|
||||
print(' type %-32s vis=%s bbox=%s' % ((ch.name or '')[:32], ch.visible, ch.bbox))
|
||||
elif ch.kind == 'pixel':
|
||||
print(' pixel %-32s vis=%s bbox=%s' % ((ch.name or '')[:32], ch.visible, ch.bbox))
|
||||
else:
|
||||
print(' %-6s %-32s vis=%s' % (ch.kind, (ch.name or '')[:32], ch.visible))
|
||||
@@ -0,0 +1,66 @@
|
||||
#!/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)
|
||||
Reference in new issue
Block a user