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 273b7aa commit 21ec336
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion font-patcher
Original file line number Diff line number Diff line change
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[1] = ':'
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 21ec336

Please sign in to comment.