Skip to content

Latest commit

 

History

History
89 lines (64 loc) · 2.7 KB

UPDATE.md

File metadata and controls

89 lines (64 loc) · 2.7 KB

How to update font packs

FontAwesome

To update FontAwesome icons, one must:

Elusive Icons

To update Elusive Icons, one must:

  • replace the ttf font file with the new version
  • regenerate the json charmap with the icons.yml file from the upstream repository:
import yaml, json

with open('icons.yml', 'r') as file:
    icons = yaml.load(file)['icons']

charmap = {icon['id']: icon['unicode'] for icon in icons}

for icon in icons:
    if 'aliases' in icon:
        for name in icon['aliases']:
            charmap[name] = icon['unicode']

with open('charmap.json', 'w') as file:
    json.dump(charmap, file, indent=4, sort_keys=True)

Material Design Icons

To update Material Design Icons, you must:

The following script automatically download the last TTF font, generate the json charmap and display md5 hash of the TTF (to update iconic_font.py)

import re
import json
import urllib.request
import hashlib

TTF_URL = 'https://raw.githubusercontent.com/Templarian/MaterialDesign-Webfont/master/fonts/materialdesignicons-webfont.ttf'
CSS_URL = 'https://raw.githubusercontent.com/Templarian/MaterialDesign-Webfont/master/css/materialdesignicons.css'

with open('materialdesignicons-webfont.ttf', 'wb') as fp:
    req = urllib.request.urlopen(TTF_URL)
    if req.status != 200:
        raise Exception('Failed to download TTF')
    fp.write(req.read())
    req.close()

hasher = hashlib.md5()
with open('materialdesignicons-webfont.ttf', 'rb') as f:
    content = f.read()
    hasher.update(content)

ttf_calculated_hash_code = hasher.hexdigest()
print('MD5 :', ttf_calculated_hash_code)

req = urllib.request.urlopen(CSS_URL)
if req.status != 200:
    raise Exception('Failed to download CSS Charmap')

rawcss = req.read().decode()
req.close()

charmap = {}
pattern = '^\.mdi-(.+)::before {\s*content: "(.+)";\s*}$'
data = re.findall(pattern, rawcss, re.MULTILINE)
for name, key in data:
    key = key.replace('\\F', '0xf').lower()
    key = key.replace('\\', '0x')
    name = name.lower()
    charmap[name] = key

with open('materialdesignicons-webfont-charmap.json', 'w') as fp:
    json.dump(charmap, fp, indent=4, sort_keys=True)