Merge pull request #1307 from ynput/Update-qtmaterialsymbols-to-a-more-recent-font-version

Update Material Symbols to the latest version, add function to re-generate json file.
This commit is contained in:
Philippe Leprince 2025-06-04 15:49:11 +02:00 committed by GitHub
commit 92d5859556
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 635 additions and 11 deletions

View file

@ -5,12 +5,32 @@ CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
def get_font_filepath(
font_name: Optional[str] = "MaterialSymbolsOutlined"
font_name: Optional[str] = "MaterialSymbolsOutlined-Regular"
) -> str:
return os.path.join(CURRENT_DIR, f"{font_name}.ttf")
def get_mapping_filepath(
font_name: Optional[str] = "MaterialSymbolsOutlined"
font_name: Optional[str] = "MaterialSymbolsOutlined-Regular"
) -> str:
return os.path.join(CURRENT_DIR, f"{font_name}.json")
def regenerate_mapping():
"""Regenerate the MaterialSymbolsOutlined.json file, assuming
MaterialSymbolsOutlined.codepoints and the TrueType font file have been
updated to support the new symbols.
"""
import json
jfile = get_mapping_filepath()
cpfile = jfile.replace(".json", ".codepoints")
with open(cpfile, "r") as cpf:
codepoints = cpf.read()
mapping = {}
for cp in codepoints.splitlines():
name, code = cp.split()
mapping[name] = int(f"0x{code}", 16)
with open(jfile, "w") as jf:
json.dump(mapping, jf, indent=4)