-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to Phosphor Icons V2.1.0 and a Script for Auto Updates (#18)
* Write script for automatic updates New .tff font files are automatically downloaded from phosphoricons.com, and the rust code is generated for each variant. * Update to Phosphor icons v2.1.0 Released Mar 31 2024. See https://github.com/phosphor-icons/homepage/releases/tag/v2.1.0 * Modify update script to not add duotone icons After some testing, these icons don't seem to work with egui's font rendering.
- Loading branch information
1 parent
4531eb2
commit 672a8dc
Showing
11 changed files
with
7,714 additions
and
6,290 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# This script downloads the latest version of the Phosphor Icons from the | ||
# official website, extracts the TTF files into the `res` directory, and | ||
# generates the rust code for each variant file. | ||
|
||
import io | ||
import json | ||
import requests | ||
import zipfile | ||
|
||
ICON_URL = "https://phosphoricons.com/assets/phosphor-icons.zip" | ||
|
||
# Download the latest version of the Phosphor Icons | ||
print(f"[*] Downloading Icons ({ICON_URL})") | ||
response = requests.get(ICON_URL) | ||
print(f"[*] Downloaded {len(response.content)} bytes") | ||
|
||
# Extract the TTF files and the code point to icon mappings from the | ||
# corresponding selection.json files | ||
variants = {} | ||
zip = zipfile.ZipFile(io.BytesIO(response.content)) | ||
|
||
for info in zip.infolist(): | ||
if info.filename.endswith(".ttf"): | ||
variant = info.filename.split("/")[1] | ||
font = zip.read(info.filename) | ||
info = json.loads(zip.read(f"Fonts/{variant}/selection.json")) | ||
|
||
icons = {} | ||
for icon in info["icons"]: | ||
names = icon["properties"]["name"].split(", ") | ||
for name in names: | ||
icons[name] = icon["properties"]["code"] | ||
|
||
variants[variant] = (font, icons) | ||
|
||
# Remove duotone variants as they don't seem to be supported by egui font | ||
# rendering | ||
if "duotone" in variants: | ||
del variants["duotone"] | ||
|
||
print(f"[*] Found {len(variants)} variants ({', '.join(variants.keys())})") | ||
|
||
print("[*] Writing font and source files") | ||
for variant, (font, icons) in variants.items(): | ||
font_file = ( | ||
f"res/Phosphor-{variant[0].upper() + variant[1:]}.ttf" | ||
if variant != "regular" | ||
else "res/Phosphor.ttf" | ||
) | ||
with open(font_file, "wb") as file: | ||
file.write(font) | ||
|
||
with open(f"src/variants/{variant}.rs", "w") as file: | ||
file.write("#![allow(unused)]\n") | ||
for name, code in icons.items(): | ||
code_point = hex(code)[2:].upper() | ||
|
||
name = name.replace("-", "_").upper() | ||
if variant != "regular": | ||
name = name[: -(len(variant) + 1)] | ||
|
||
file.write(f'pub const {name}: &str = "\\u{{{code_point}}}";\n') | ||
|
||
print("[*] Done!") |
Oops, something went wrong.