Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve patching-under-Windows compat #1786

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 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.18.0"
script_version = "4.18.1"

version = "3.3.0"
projectName = "Nerd Fonts"
Expand Down Expand Up @@ -38,7 +38,7 @@ except ImportError:
)
)

sys.path.insert(0, os.path.abspath(os.path.dirname(sys.argv[0])) + '/bin/scripts/name_parser/')
sys.path.insert(0, os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), 'bin', 'scripts', 'name_parser'))
try:
from FontnameParser import FontnameParser
from FontnameTools import FontnameTools
Expand Down Expand Up @@ -321,8 +321,8 @@ def create_filename(fonts):
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:
glyphnamefile = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), 'glyphnames.json'))
with open(glyphnamefile, 'rb') 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:
Expand Down Expand Up @@ -1845,6 +1845,7 @@ def sanitize_filename(filename, allow_dirs = False):
""" Enforces to not use forbidden characters in a filename/path. """
if filename == '.' and not allow_dirs:
return '_'
restore_colon = sys.platform == 'win32' and re.match('[a-z]:', filename, re.I)
trans = filename.maketrans('<>:"|?*', '_______')
for i in range(0x00, 0x20):
trans[i] = ord('_')
Expand All @@ -1853,7 +1854,10 @@ def sanitize_filename(filename, allow_dirs = False):
trans[ord('\\')] = ord('_')
else:
trans[ord('\\')] = ord('/') # We use Posix paths
return filename.translate(trans)
new_filename = filename.translate(trans)
if restore_colon:
new_filename = new_filename[ :1] + ':' + new_filename[2: ]
return new_filename

def get_multiglyph_boundingBox(glyphs, destGlyph = None):
""" Returns dict of the dimensions of multiple glyphs combined(, as if they are copied into destGlyph) """
Expand Down
Loading