Skip to content

Commit

Permalink
font-patcher: Allow absolute paths on Windows
Browse files Browse the repository at this point in the history
[why]
On Windows an absolute path can start with the drive letter followed by
a colon. When we sanitize the pathname the colon is replaced by an
underscore.

[how]
Add special handling on Windows.

Signed-off-by: Fini Jastrow <[email protected]>
  • Loading branch information
Finii committed Jan 15, 2025
1 parent c1859cf commit ae17941
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 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.18.0"
script_version = "4.18.1"

version = "3.3.0"
projectName = "Nerd Fonts"
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

0 comments on commit ae17941

Please sign in to comment.