Skip to content

Commit

Permalink
Update to Phosphor Icons V2.1.0 and a Script for Auto Updates (#18)
Browse files Browse the repository at this point in the history
* 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
connorslade authored Jul 30, 2024
1 parent 4531eb2 commit 672a8dc
Show file tree
Hide file tree
Showing 11 changed files with 7,714 additions and 6,290 deletions.
Binary file modified res/Phosphor-Bold.ttf
Binary file not shown.
Binary file modified res/Phosphor-Fill.ttf
Binary file not shown.
Binary file modified res/Phosphor-Light.ttf
Binary file not shown.
Binary file modified res/Phosphor-Thin.ttf
Binary file not shown.
Binary file modified res/Phosphor.ttf
Binary file not shown.
64 changes: 64 additions & 0 deletions scripts/update.py
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!")
Loading

0 comments on commit 672a8dc

Please sign in to comment.