| 1 | # How to update font packs |
| 2 | |
| 3 | ## FontAwesome |
| 4 | |
| 5 | To update _FontAwesome_ icons, one must: |
| 6 | |
| 7 | - check what is the latest released version here: https://github.com/FortAwesome/Font-Awesome/releases/ |
| 8 | - update font version in \_\_init__.py |
| 9 | - remove outdated files in the fonts dir |
| 10 | - run: `python setup.py update_fa6 --fa-version X.X.X` |
| 11 | - update FA version number, icon counts and URLs inside: |
| 12 | - README.md |
| 13 | - qtawesome/docs/source/usage.rst |
| 14 | |
| 15 | ## Elusive Icons |
| 16 | |
| 17 | To update _Elusive Icons_, one must: |
| 18 | |
| 19 | - replace the ttf font file with the new version |
| 20 | - regenerate the json charmap with the `icons.yml` file from the upstream repository: |
| 21 | - update Elusive Icons version number, icon counts and URLs inside: |
| 22 | - README.md |
| 23 | - qtawesome/docs/source/usage.rst |
| 24 | |
| 25 | ```Python |
| 26 | import yaml, json |
| 27 | |
| 28 | with open('icons.yml', 'r') as file: |
| 29 | icons = yaml.load(file)['icons'] |
| 30 | |
| 31 | charmap = {icon['id']: icon['unicode'] for icon in icons} |
| 32 | |
| 33 | for icon in icons: |
| 34 | if 'aliases' in icon: |
| 35 | for name in icon['aliases']: |
| 36 | charmap[name] = icon['unicode'] |
| 37 | |
| 38 | with open('charmap.json', 'w') as file: |
| 39 | json.dump(charmap, file, indent=4, sort_keys=True) |
| 40 | ``` |
| 41 | |
| 42 | ## Material Design Icons |
| 43 | |
| 44 | To update _Material Design Icons 6.x_, you must: |
| 45 | |
| 46 | - download ttf from <https://raw.githubusercontent.com/Templarian/MaterialDesign-Webfont/master/fonts/materialdesignicons-webfont.ttf> |
| 47 | - regenerate the json charmap with the `materialdesignicons.css` file from <https://raw.githubusercontent.com/Templarian/MaterialDesign-Webfont/master/css/materialdesignicons.css> |
| 48 | - update Material Design Icons version number, icon counts and URLs inside: |
| 49 | - README.md |
| 50 | - qtawesome/docs/source/usage.rst |
| 51 | |
| 52 | The following script automatically download the last TTF font, generate the json charmap and display md5 hash of the TTF (to update \_\_init__.py) |
| 53 | |
| 54 | ```Python |
| 55 | import re |
| 56 | import json |
| 57 | import urllib.request |
| 58 | import hashlib |
| 59 | |
| 60 | |
| 61 | VERSION = '6.9.96' # Update version as required |
| 62 | TTF_URL = 'https://raw.githubusercontent.com/Templarian/MaterialDesign-Webfont/master/fonts/materialdesignicons-webfont.ttf' |
| 63 | CSS_URL = 'https://raw.githubusercontent.com/Templarian/MaterialDesign-Webfont/master/css/materialdesignicons.css' |
| 64 | FONT_FILENAME = "materialdesignicons6-webfont-{version}.ttf".format( |
| 65 | version=VERSION |
| 66 | ) |
| 67 | FONT_CHARMAP_FILENAME = ( |
| 68 | "materialdesignicons6-webfont-charmap-{version}.json".format( |
| 69 | version=VERSION |
| 70 | ) |
| 71 | ) |
| 72 | |
| 73 | |
| 74 | with open(FONT_FILENAME, 'wb') as fp: |
| 75 | req = urllib.request.urlopen(TTF_URL) |
| 76 | if req.status != 200: |
| 77 | raise Exception('Failed to download TTF') |
| 78 | fp.write(req.read()) |
| 79 | req.close() |
| 80 | |
| 81 | hasher = hashlib.md5() |
| 82 | with open(FONT_FILENAME, 'rb') as f: |
| 83 | content = f.read() |
| 84 | hasher.update(content) |
| 85 | |
| 86 | ttf_calculated_hash_code = hasher.hexdigest() |
| 87 | print('MD5 :', ttf_calculated_hash_code) |
| 88 | |
| 89 | req = urllib.request.urlopen(CSS_URL) |
| 90 | if req.status != 200: |
| 91 | raise Exception('Failed to download CSS Charmap') |
| 92 | |
| 93 | rawcss = req.read().decode() |
| 94 | req.close() |
| 95 | |
| 96 | charmap = {} |
| 97 | pattern = '^\.mdi-(.+)::before {\s*content: "(.+)";\s*}$' |
| 98 | data = re.findall(pattern, rawcss, re.MULTILINE) |
| 99 | for name, key in data: |
| 100 | key = key.replace('\\F', '0xf').lower() |
| 101 | key = key.replace('\\', '0x') |
| 102 | name = name.lower() |
| 103 | charmap[name] = key |
| 104 | |
| 105 | with open(FONT_CHARMAP_FILENAME, 'w') as fp: |
| 106 | json.dump(charmap, fp, indent=4, sort_keys=True) |
| 107 | |
| 108 | ``` |
| 109 | |
| 110 | ## Phosphor |
| 111 | |
| 112 | To update _Phosphor_, you must: |
| 113 | |
| 114 | - download ttf from <https://raw.githubusercontent.com/phosphor-icons/phosphor-icons/master/src/font/phosphor.ttf> |
| 115 | - regenerate the json charmap with the `phosphor.css` file from <https://raw.githubusercontent.com/phosphor-icons/phosphor-icons/master/src/css/phosphor.css> |
| 116 | - update Phosphor version number, icon counts and URLs inside: |
| 117 | - README.md |
| 118 | - qtawesome/docs/source/usage.rst |
| 119 | |
| 120 | The following script automatically download the last TTF font, generate the json charmap and display md5 hash of the TTF (to update \_\_init__.py) |
| 121 | |
| 122 | ```Python |
| 123 | import re |
| 124 | import json |
| 125 | import urllib.request |
| 126 | import hashlib |
| 127 | |
| 128 | VERSION = '1.3.0' # Update version as required |
| 129 | TTF_URL = 'https://raw.githubusercontent.com/phosphor-icons/phosphor-icons/master/src/font/phosphor.ttf' |
| 130 | CSS_URL = 'https://raw.githubusercontent.com/phosphor-icons/phosphor-icons/master/src/css/phosphor.css' |
| 131 | FONT_FILENAME = 'phosphor-{version}.ttf'.format(version=VERSION) |
| 132 | FONT_CHARMAP_FILENAME = "phosphor-charmap-{version}.json".format( |
| 133 | version=VERSION |
| 134 | ) |
| 135 | |
| 136 | with open(FONT_FILENAME, 'wb') as fp: |
| 137 | req = urllib.request.urlopen(TTF_URL) |
| 138 | if req.status != 200: |
| 139 | raise Exception('Failed to download TTF') |
| 140 | fp.write(req.read()) |
| 141 | req.close() |
| 142 | |
| 143 | hasher = hashlib.md5() |
| 144 | with open(FONT_FILENAME, 'rb') as f: |
| 145 | content = f.read() |
| 146 | hasher.update(content) |
| 147 | |
| 148 | ttf_calculated_hash_code = hasher.hexdigest() |
| 149 | print('MD5 :', ttf_calculated_hash_code) |
| 150 | |
| 151 | req = urllib.request.urlopen(CSS_URL) |
| 152 | if req.status != 200: |
| 153 | raise Exception('Failed to download CSS Charmap') |
| 154 | |
| 155 | rawcss = req.read().decode() |
| 156 | req.close() |
| 157 | |
| 158 | charmap = {} |
| 159 | pattern = '^\.ph-(.+):before {\s*content: "(.+)";\s*}$' |
| 160 | data = re.findall(pattern, rawcss, re.MULTILINE) |
| 161 | for name, key in data: |
| 162 | key = key.replace('\\', '0x') |
| 163 | name = name.lower() |
| 164 | charmap[name] = key |
| 165 | |
| 166 | with open(FONT_CHARMAP_FILENAME, 'w') as fp: |
| 167 | json.dump(charmap, fp, indent=4, sort_keys=True) |
| 168 | |
| 169 | ``` |
| 170 | |
| 171 | ## Remix Icon |
| 172 | |
| 173 | To update _Remix Icon_, you must: |
| 174 | |
| 175 | - download ttf from <https://raw.githubusercontent.com/Remix-Design/RemixIcon/master/fonts/remixicon.ttf> |
| 176 | - regenerate the json charmap with the `remixicon.css` file from <https://raw.githubusercontent.com/Remix-Design/RemixIcon/master/fonts/remixicon.css> |
| 177 | - update Remix Icon version number, icon counts and URLs inside: |
| 178 | - README.md |
| 179 | - qtawesome/docs/source/usage.rst |
| 180 | |
| 181 | The following script automatically download the last TTF font, generate the json charmap and display md5 hash of the TTF (to update \_\_init__.py) |
| 182 | |
| 183 | ```Python |
| 184 | import re |
| 185 | import json |
| 186 | import urllib.request |
| 187 | import hashlib |
| 188 | |
| 189 | VERSION = '2.5.0' # Update version as required |
| 190 | TTF_URL = 'https://raw.githubusercontent.com/Remix-Design/RemixIcon/master/fonts/remixicon.ttf' |
| 191 | CSS_URL = 'https://raw.githubusercontent.com/Remix-Design/RemixIcon/master/fonts/remixicon.css' |
| 192 | FONT_FILENAME = 'remixicon-{version}.ttf'.format(version=VERSION) |
| 193 | FONT_CHARMAP_FILENAME = "remixicon-charmap-{version}.json".format( |
| 194 | version=VERSION |
| 195 | ) |
| 196 | |
| 197 | with open(FONT_FILENAME, 'wb') as fp: |
| 198 | req = urllib.request.urlopen(TTF_URL) |
| 199 | if req.status != 200: |
| 200 | raise Exception('Failed to download TTF') |
| 201 | fp.write(req.read()) |
| 202 | req.close() |
| 203 | |
| 204 | hasher = hashlib.md5() |
| 205 | with open(FONT_FILENAME, 'rb') as f: |
| 206 | content = f.read() |
| 207 | hasher.update(content) |
| 208 | |
| 209 | ttf_calculated_hash_code = hasher.hexdigest() |
| 210 | print('MD5 :', ttf_calculated_hash_code) |
| 211 | |
| 212 | req = urllib.request.urlopen(CSS_URL) |
| 213 | if req.status != 200: |
| 214 | raise Exception('Failed to download CSS Charmap') |
| 215 | |
| 216 | rawcss = req.read().decode() |
| 217 | req.close() |
| 218 | |
| 219 | charmap = {} |
| 220 | pattern = '^\.ri-(.+):before {\s*content: "(.+)";\s*}$' |
| 221 | data = re.findall(pattern, rawcss, re.MULTILINE) |
| 222 | for name, key in data: |
| 223 | key = key.replace('\\', '0x') |
| 224 | name = name.lower() |
| 225 | charmap[name] = key |
| 226 | |
| 227 | with open(FONT_CHARMAP_FILENAME, 'w') as fp: |
| 228 | json.dump(charmap, fp, indent=4, sort_keys=True) |
| 229 | |
| 230 | ``` |
| 231 | |
| 232 | ## Microsoft's Codicons |
| 233 | |
| 234 | To update _Codicons_ icons, one must: |
| 235 | |
| 236 | - check what is the latest released version here: https://github.com/microsoft/vscode-codicons/releases |
| 237 | - update font version in \_\_init__.py |
| 238 | - remove outdated files in the fonts dir |
| 239 | - run: `python setup.py update_msc --msc-version X.X.X` |
| 240 | - update Codicons version number, icon counts and URLs inside: |
| 241 | - README.md |
| 242 | - qtawesome/docs/source/usage.rst |