20 行
1.1 KiB
Python
20 行
1.1 KiB
Python
"""Rebuild local PNGs from the retained iconfont SVG originals (pip install resvg-py)."""
|
|
import hashlib,json,pathlib,xml.etree.ElementTree as ET
|
|
import resvg_py
|
|
|
|
APP=pathlib.Path(__file__).resolve().parents[1]
|
|
SOURCE=APP/'third_party/remix-icon'
|
|
OUT=APP/'src/assets/ime-icons'
|
|
OUT.mkdir(parents=True,exist_ok=True)
|
|
metadata=json.loads((SOURCE/'icons.json').read_text(encoding='utf-8'))
|
|
for record in metadata['icons']:
|
|
raw=(SOURCE/(record['name']+'.iconfont.svg')).read_bytes()
|
|
assert hashlib.sha256(raw).hexdigest().upper()==record['iconfont_svg_sha256']
|
|
root=ET.fromstring(raw);root.attrib.pop('style',None)
|
|
color='#FFFFFF' if record['name']=='check-line' else '#515866' if record['name']=='delete-back-2-line' else '#2867D9'
|
|
for node in root.iter():node.attrib.pop('fill',None)
|
|
root.set('fill',color)
|
|
(OUT/(record['name']+'.png')).write_bytes(resvg_py.svg_to_bytes(svg_string=ET.tostring(root,encoding='unicode'),width=72,height=72))
|
|
(OUT/'LICENSE.txt').write_bytes((SOURCE/'LICENSE').read_bytes())
|
|
print('Built',len(metadata['icons']),'local 72px transparent icons; display at 20/24px')
|