Skip to content

Commit

Permalink
feat: add nerd-font-patcher 3.1.1 (script version 4.8.2)
Browse files Browse the repository at this point in the history
Taken from Nixpkgs master and extracted.
  • Loading branch information
flexiondotorg committed Jul 16, 2024
1 parent 109771d commit 98dd293
Show file tree
Hide file tree
Showing 36 changed files with 4,494 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
gitkraken = pkgs.callPackage ./gitkraken { };
joplin-desktop = pkgs.callPackage ./joplin-desktop { };
lima-bin = pkgs.callPackage ./lima-bin { };
nerd-font-patcher = pkgs.callPackage ./nerd-font-patcher { };
obs-studio = pkgs.callPackage ./obs-studio { };
obs-studio-plugins = pkgs.callPackage ./obs-studio/plugins { };
wavebox = pkgs.callPackage ./wavebox { };
Expand Down
363 changes: 363 additions & 0 deletions pkgs/nerd-font-patcher/3.1.1/bin/scripts/name_parser/FontnameParser.py

Large diffs are not rendered by default.

426 changes: 426 additions & 0 deletions pkgs/nerd-font-patcher/3.1.1/bin/scripts/name_parser/FontnameTools.py

Large diffs are not rendered by default.

2,072 changes: 2,072 additions & 0 deletions pkgs/nerd-font-patcher/3.1.1/font-patcher

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions pkgs/nerd-font-patcher/3.1.1/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

# Nerd Fonts

This is font-patcher python script (and required source files) from a Nerd Fonts release.

## Running

* To execute run: `fontforge --script ./font-patcher --complete <YOUR FONT FILE>`
* For more CLI options and help: `fontforge --script ./font-patcher --help`

## Further info

For more information see:
* https://github.com/ryanoasis/nerd-fonts/
* https://github.com/ryanoasis/nerd-fonts/releases/latest/
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions pkgs/nerd-font-patcher/3.1.1/src/glyphs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Contents

This directory contains all the glyphs (glyph sets) that the `font-patcher` puts into the fonts.

If a icon font here is updated, do not forget to update the database file in `bin/script/libs`.

The 'Seti and Original' icons (in `original-source.otf`) is automatically generated from the glyphs in `src/svgs`.
Do not edit and commit changes to that font directly.
Binary file not shown.
395 changes: 395 additions & 0 deletions pkgs/nerd-font-patcher/3.1.1/src/glyphs/codicons/LICENSE.txt

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
34 changes: 34 additions & 0 deletions pkgs/nerd-font-patcher/3.1.1/src/glyphs/font-awesome/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Font Awesome Free License
-------------------------

Font Awesome Free is free, open source, and GPL friendly. You can use it for
commercial projects, open source projects, or really almost whatever you want.
Full Font Awesome Free license: https://fontawesome.com/license/free.

# Icons: CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/)
In the Font Awesome Free download, the CC BY 4.0 license applies to all icons
packaged as SVG and JS file types.

# Fonts: SIL OFL 1.1 License (https://scripts.sil.org/OFL)
In the Font Awesome Free download, the SIL OFL license applies to all icons
packaged as web and desktop font files.

# Code: MIT License (https://opensource.org/licenses/MIT)
In the Font Awesome Free download, the MIT license applies to all non-font and
non-icon files.

# Attribution
Attribution is required by MIT, SIL OFL, and CC BY licenses. Downloaded Font
Awesome Free files already contain embedded comments with sufficient
attribution, so you shouldn't need to do anything additional when using these
files normally.

We've kept attribution comments terse, so we ask that you do not actively work
to remove them from files, especially code. They're a great way for folks to
learn about Font Awesome.

# Brand Icons
All brand icons are trademarks of their respective owners. The use of these
trademarks does not indicate endorsement of the trademark holder by Font
Awesome, nor vice versa. **Please do not use brand logos for any purpose except
to represent the company, product, or service to which they refer.**
Binary file not shown.
20 changes: 20 additions & 0 deletions pkgs/nerd-font-patcher/3.1.1/src/glyphs/materialdesign/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Pictogrammers Free License
--------------------------

This icon collection is released as free, open source, and GPL friendly by
the [Pictogrammers](http://pictogrammers.com/) icon group. You may use it
for commercial projects, open source projects, or anything really.

# Icons: Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0)
Some of the icons are redistributed under the Apache 2.0 license. All other
icons are either redistributed under their respective licenses or are
distributed under the Apache 2.0 license.

# Fonts: Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0)
All web and desktop fonts are distributed under the Apache 2.0 license. Web
and desktop fonts contain some icons that are redistributed under the Apache
2.0 license. All other icons are either redistributed under their respective
licenses or are distributed under the Apache 2.0 license.

# Code: MIT (https://opensource.org/licenses/MIT)
The MIT license applies to all non-font and non-icon files.
Binary file not shown.
Binary file not shown.
23 changes: 23 additions & 0 deletions pkgs/nerd-font-patcher/3.1.1/src/glyphs/materialdesign/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Contents

This folder contains the source for the (current) Material Design Icons.
Source is https://github.com/Templarian/MaterialDesign-Font

Last fetch date is Oct 6, 2022.

After fetching a new file one needs to correct our cheat-sheet by updating `bin/scripts/lib/i_md.sh`.
Use the tool:
```
cd bin/scripts
mv lib/i_md.sh lib/i_md.sh_
python3 generate-glyph-info-from-set.py --start f0001 -end f1af0 -font ../../src/glyphs/materialdesign/MaterialDesignIconsDesktop.ttf -offset 0 -prefix md > lib/i_md.sh
```

Open old and new definitions shell script and copy the header from the old file to the autogenerated file. Adapt the values in the new file's header. Remove the last line in the new file (it contains the number of glyphs that is needed for the updated header). Yes, that is some manual labor.


## Source bugs fixed

Glyph 0xF1522 is broken in the original font. We fixed that one glyph manually.

See https://github.com/Templarian/MaterialDesign-Font/issues/9
Binary file not shown.
21 changes: 21 additions & 0 deletions pkgs/nerd-font-patcher/3.1.1/src/glyphs/octicons/LICENSE
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.
32 changes: 32 additions & 0 deletions pkgs/nerd-font-patcher/3.1.1/src/glyphs/octicons/analyze_octicons
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()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
181 changes: 181 additions & 0 deletions pkgs/nerd-font-patcher/3.1.1/src/glyphs/octicons/generate
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
#!/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-bump.sh is not working here, need to adjust manually!
version = "3.0.0"

archive = 'v18.3.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.replace('-', '_')))
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-* && cp file-symlink-directory-*.svg icons', 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')
Loading

0 comments on commit 98dd293

Please sign in to comment.