On Thu, Jan 05, 2023 at 07:46:38AM +0000, Julian Gilbey wrote:
> [...]
> * Create new fontawesome5-*charmap.json files from
> /usr/share/fonts-fork-awesome/css/v5-compat.css Below is a quick
> script to do this.
Oh, I hadn't checked it properly. This one works (there were two
names for the same icon).
Another thought: since the code only looks at the symbolic name
("fa5", for example), instead of having
fontawesome5-regular-webfont.ttf being a symlink to (or copy of)
forkawesome, we could just call it forkawesome-regular-webfont.ttf and
modify the qtawesome/__init__.py file to refer to these files
instead. That way, someone glancing at the package contents would
know exactly what it contains.
Best wishes,
Julian
#!/usr/bin/python3
"""Create JSON files for ForkAwesome font.
Copyright 2023 Julian Gilbey <[email protected]>
Licensed under the Expat license
"""
import json
import re
CSS = "/usr/share/fonts-fork-awesome/css/v5-compat.css"
JSONS = {
"r": "fontawesome5-regular-webfont-charmap.json",
"s": "fontawesome5-solid-webfont-charmap.json",
"b": "fontawesome5-brands-webfont-charmap.json"
}
icons: dict[str, dict[str, str]] = {"r": {}, "s": {}, "b": {}}
icon_line = re.compile(r"\.fa([rsb])\.(.*):before \{")
with open(CSS) as css:
while line := css.readline():
if icon_match := icon_line.match(line):
category, icon = icon_match.groups()
content = css.readline()
content = content.strip()
char = content.removeprefix('content: "\\').removesuffix('";')
icons[category][icon] = char
icons["r"]["fa-copy"] = icons["r"]["fa-file"]
for category, filename in JSONS.items():
with open(filename, "w") as catfile:
json.dump(icons[category], catfile, indent=4)