Skip to content

Commit

Permalink
font-patcher: Rename glyphs to our ID / Class name
Browse files Browse the repository at this point in the history
[why]
The glyphnames in the font files are sometimes off. We take them from
the symbol source/font and ofter they are empty or even plain wrong (esp
if we move to other codepoints).

[how]
We have the list of all glyphnames that is generated by collecting all
data from the i_*.sh files. When patching we take this information now
and use it if appropriate.

Make sure the glyphname.json file is included in our zip patcher release
and also in the Docker image. It will run as before if the file can not
be found or is invalid etc.

Suggested-by: Ulices <[email protected]>
Signed-off-by: Fini Jastrow <[email protected]>
  • Loading branch information
Finii committed Aug 25, 2024
1 parent a3f1b9e commit 71e7ae0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
**
!src/glyphs
!font-patcher
!glyphnames.json
!bin/scripts/name_parser/Fontname*.py
!bin/scripts/docker-entrypoint.sh
!.codeclimate.yml
1 change: 1 addition & 0 deletions bin/scripts/archive-font-patcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ find "${outputdir:?}" -name "FontPatcher.zip" -type f -delete
cd -- "$scripts_root_dir/../../" || exit 1
find "src/glyphs" | zip -9 "$outputdir/FontPatcher" -@
find "bin/scripts/name_parser" -name "Fontname*.py" | zip -9 "$outputdir/FontPatcher" -@
find "glyphnames.json" | zip -9 "$outputdir/FontPatcher" -@
find "font-patcher" | zip -9 "$outputdir/FontPatcher" -@

# add mini readme file
Expand Down
16 changes: 14 additions & 2 deletions font-patcher
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from __future__ import absolute_import, print_function, unicode_literals

# Change the script version when you edit this script:
script_version = "4.14.4"
script_version = "4.15.0"

version = "3.2.1"
projectName = "Nerd Fonts"
Expand Down Expand Up @@ -318,6 +318,16 @@ def create_filename(fonts):
sfnt_psubfam = '-' + sfnt_psubfam
return (sfnt_pfam + sfnt_psubfam).replace(' ', '')

def fetch_glyphnames():
""" Read the glyphname database and put it into a dictionary """
try:
glyphnamefile = os.path.abspath(os.path.dirname(sys.argv[0])) + '/glyphnames.json'
with open(glyphnamefile, 'r') as f:
namelist = json.load(f)
return { int(v['code'], 16): k for k, v in namelist.items() if 'code' in v }
except Exception as error:
logger.warning("Can not read glyphnames file (%s)", repr(error))
return {}

class font_patcher:
def __init__(self, args, conf):
Expand All @@ -333,6 +343,7 @@ class font_patcher:
self.onlybitmaps = 0
self.essential = set()
self.xavgwidth = [] # list of ints
self.glyphnames = fetch_glyphnames()

def patch(self, font):
self.sourceFont = font
Expand Down Expand Up @@ -1481,7 +1492,8 @@ class font_patcher:
# Paste it
self.sourceFont.selection.select(currentSourceFontGlyph)
self.sourceFont.paste()
self.sourceFont[currentSourceFontGlyph].glyphname = sym_glyph.glyphname
self.sourceFont[currentSourceFontGlyph].glyphname = \
self.glyphnames.get(currentSourceFontGlyph, sym_glyph.glyphname) if setName != 'Custom' else sym_glyph.glyphname
self.sourceFont[currentSourceFontGlyph].manualHints = True # No autohints for symbols

# Prepare symbol glyph dimensions
Expand Down

0 comments on commit 71e7ae0

Please sign in to comment.