-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[why] The octicons got a lot updates. But they do not have a font anymore. [how] Keep our old codepoints constant, but add the new icons thereafter. This commit just moves all the mechanics in and moves the (old) font. No actual update here. The mapping file has been created with the analyze_octicons script. Fixes: #490 Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
- Loading branch information
Showing
6 changed files
with
411 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 GitHub Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python3 | ||
# coding=utf8 | ||
|
||
# This extracts the names and source and destination codepoints | ||
# of the old octicons font file to keep their codepoints stable | ||
# | ||
# You do not need to redo it, the result is in the repo | ||
# | ||
# Usage: | ||
# fontforge analyze_octicons > mapping | ||
|
||
import fontforge | ||
|
||
octi_orig = "octicons.ttf" | ||
current_cp = 0xF400 | ||
|
||
print('# Examining {}'.format(octi_orig)) | ||
|
||
font = fontforge.open(octi_orig) | ||
for glyph in font.glyphs('encoding'): | ||
point = glyph.unicode | ||
if point < 0: | ||
continue | ||
desti = glyph.unicode | ||
if point < 0xF000: | ||
desti = point | ||
else: | ||
desti = current_cp | ||
current_cp += 1 | ||
print("{:X} {:X} {}".format(point, desti, glyph.glyphname)) | ||
|
||
font.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
#!/usr/bin/env python3 | ||
# coding=utf8 | ||
|
||
import sys | ||
import os | ||
import re | ||
import subprocess | ||
import fontforge | ||
|
||
# Double-quotes required here, for version-bump.sh: | ||
version = "2.3.3" | ||
|
||
archive = 'v18.2.0.tar.gz' | ||
|
||
vectorsdir = 'icons' | ||
fontdir = '.' | ||
fontfile = 'octicons.ttf' | ||
glyphsetfile = 'i_oct.sh' | ||
glyphsetsdir = '../../../bin/scripts/lib' | ||
|
||
subset = '-16' # use 16 px subset if possible | ||
subset_other = '-24' # use 24 px subset otherwise | ||
|
||
def renamer(old_name): | ||
""" Return new equivalent icon name """ | ||
return { | ||
'trashcan' : 'trash', | ||
'cloud-download' : 'download', | ||
'cloud-upload' : 'upload', | ||
'clippy' : 'paste', | ||
'mail-read' : 'read', | ||
'primitive-dot' : 'dot-fill', | ||
'primitive-square' : 'square-fill', | ||
'settings' : 'sliders', | ||
'dashboard' : 'meter', | ||
'paintcan' : 'paintbrush', | ||
}.get(old_name, old_name) | ||
|
||
def addIcon(codepoint, name, filename): | ||
""" Add one outline file and rescale/move """ | ||
dBB = [120, 0, 1000-120, 900] # just some nice sizes | ||
filename = os.path.join(vectorsdir, filename) | ||
glyph = font.createChar(codepoint, name) | ||
glyph.importOutlines(filename) | ||
glyph.manualHints = True | ||
|
||
def createGlyphInfo(icon_datasets, filepathname, into): | ||
""" Write the glyphinfo file """ | ||
with open(filepathname, 'w', encoding = 'utf8') as f: | ||
f.write(u'#!/usr/bin/env bash\n') | ||
f.write(intro) | ||
f.write(u'# Script Version: (autogenerated)\n') | ||
f.write(u'test -n "$__i_oct_loaded" && return || __i_oct_loaded=1\n') | ||
for _, codepoint, name in icon_datasets: | ||
codepoint = int(codepoint, 16) | ||
f.write(u"i='{}' i_oct_{}=$i\n".format(chr(codepoint), name)) | ||
f.write(u'unset i\n') | ||
|
||
print('\nReading mapping file') | ||
old_mapping = [] | ||
with open('mapping', 'r') as f: | ||
for line in f.readlines(): | ||
if line.startswith('#'): | ||
continue | ||
old_mapping.append(tuple(re.split(' +', line.strip()))) | ||
print('Found {} entries'.format(len(old_mapping))) | ||
old_mapping.sort(key=(lambda x: x[0])) | ||
|
||
print('Fetching octicons archive "{}"\n'.format(archive)) | ||
if subprocess.call('curl -OL https://github.com/primer/octicons/archive/' + archive, shell=True): | ||
sys.exit('Error fetching octicons archive') | ||
print('\nUnpacking octicons archive') | ||
if subprocess.call('rm -rf icons octicons-* && tar zxf *.gz && mv octicons-*/icons . && rm -rf octicons-*', shell=True): | ||
sys.exit('Error unpacking archive') | ||
|
||
svgs = os.listdir(vectorsdir) | ||
print('Found {} svgs'.format(len(svgs))) | ||
names = { s[0:-len('-xx.svg')] for s in svgs if s.endswith(subset + '.svg') or s.endswith(subset_other + '.svg') } | ||
print('Found {} icons after de-duplicating\n'.format(len(names))) | ||
|
||
num_found = 0 | ||
num_missing = 0 | ||
misslist = '' | ||
renamelist = '' | ||
freeslots = [] | ||
|
||
new_mapping = [] | ||
for i, j, old_n in old_mapping: | ||
if old_n in names: | ||
names.remove(old_n) | ||
new_mapping.append((i, j, old_n)) | ||
num_found += 1 | ||
continue | ||
new_n = renamer(old_n) | ||
if new_n in names: | ||
renamelist += 'Renamed {} -> {}\n'.format(old_n, new_n) | ||
names.remove(new_n) | ||
new_mapping.append((i, j, new_n)) | ||
num_found += 1 | ||
continue | ||
misslist += 'Missing {}\n'.format(old_n) | ||
freeslots.append((i, j)) | ||
num_missing += 1 | ||
|
||
print(renamelist) | ||
print(misslist) | ||
print('Found {} (of {}, missing {}) and new {}'.format(num_found, len(old_mapping), num_missing, len(names))) | ||
|
||
names = list(names) | ||
names.sort() | ||
for n in list(names): | ||
if len(freeslots) == 0: | ||
break | ||
i, j = freeslots[0] | ||
new_mapping.append((i, j, n)) | ||
names.remove(n) | ||
freeslots = freeslots[1:] | ||
|
||
print('Filled in missing, remaining new {}'.format(len(names))) | ||
|
||
i_max = 0 | ||
j_max = 0 | ||
for i, j, _ in new_mapping: | ||
i = int(i, 16) | ||
j = int(j, 16) | ||
if i > i_max: | ||
i_max = i | ||
if j > j_max: | ||
j_max = j | ||
|
||
for n in names: | ||
i_max += 1 | ||
j_max += 1 | ||
new_mapping.append(('{:X}'.format(i_max), '{:X}'.format(j_max), n)) | ||
|
||
print('Appended remaining new, total new mapping {}'.format(len(new_mapping))) | ||
|
||
new_mapping.sort(key=(lambda x: x[0])) | ||
with open('mapping', 'w') as f: | ||
for i, j, n in new_mapping: | ||
f.write('{} {} {}\n'.format(i, j, n)) | ||
|
||
font = fontforge.font() | ||
font.fontname = 'OcticonsNerdFont-Regular' | ||
font.fullname = 'Octicons Nerd Font Regular' | ||
font.familyname = 'Octicons Nerd Font' | ||
font.em = 2048 | ||
font.encoding = 'UnicodeFull' | ||
|
||
# Add valid space glyph to avoid "unknown character" box on IE11 | ||
glyph = font.createChar(32) | ||
glyph.width = 200 | ||
|
||
font.sfntRevision = None # Auto-set (refreshed) by fontforge | ||
font.version = version | ||
font.copyright = 'GitHub Inc.' | ||
font.appendSFNTName('English (US)', 'Version', archive + '; ' + version) | ||
font.appendSFNTName('English (US)', 'Vendor URL', 'https://github.com/ryanoasis/nerd-fonts') | ||
font.appendSFNTName('English (US)', 'Copyright', 'GitHub Inc.') | ||
|
||
for codepoint, _, name in new_mapping: | ||
codepoint = int(codepoint, 16) | ||
filename = name + subset + '.svg' | ||
if filename not in svgs: | ||
filename = name + subset_other + '.svg' | ||
addIcon(codepoint, name, filename) | ||
|
||
num_icons = len(new_mapping) | ||
|
||
print('Generating {} with {} glyphs'.format(fontfile, num_icons)) | ||
font.generate(os.path.join(fontdir, fontfile), flags=("no-FFTM-table",)) | ||
|
||
codepoints = [ int(p, 16) for _, p, _ in new_mapping ] | ||
intro = u'# Octicons ({} icons)\n'.format(num_icons) | ||
intro += u'# Codepoints: {:X}-{:X} with gaps\n'.format(min(codepoints), max(codepoints)) | ||
intro += u'# Nerd Fonts Version: {}\n'.format(version) | ||
|
||
print('Generating GlyphInfo {}'.format(glyphsetfile)) | ||
createGlyphInfo(new_mapping, os.path.join(glyphsetsdir, glyphsetfile), intro) | ||
print('Finished') |
Oops, something went wrong.