mirror of
https://github.com/ryanoasis/nerd-fonts.git
synced 2024-11-19 16:39:20 +02:00
font-patcher: Rename glyphs to our ID / Class name
[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 <hasecilu@tuta.io> Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
parent
0900e07e97
commit
662a61440f
@ -2,6 +2,7 @@
|
||||
**
|
||||
!src/glyphs
|
||||
!font-patcher
|
||||
!glyphnames.json
|
||||
!bin/scripts/name_parser/Fontname*.py
|
||||
!bin/scripts/docker-entrypoint.sh
|
||||
!.codeclimate.yml
|
||||
|
@ -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
|
||||
|
16
font-patcher
16
font-patcher
@ -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.9"
|
||||
script_version = "4.15.0"
|
||||
|
||||
version = "3.2.1"
|
||||
projectName = "Nerd Fonts"
|
||||
@ -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):
|
||||
@ -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
|
||||
@ -1488,7 +1499,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
|
||||
|
Loading…
Reference in New Issue
Block a user