Skip to content

Commit 6cd466d

Browse files
authored
Merge pull request ryanoasis#283 from haasosaurus/master
fix monospace/overlap problem
2 parents 652d045 + b33cfb0 commit 6cd466d

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

font-patcher

+22-12
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,17 @@ def get_dim(glyph):
489489
}
490490

491491
def set_width(sourceFont, width):
492-
sourceFont.selection.all()
493-
for glyph in sourceFont.selection.byGlyphs:
494-
glyph.width = width
492+
# changed to glyphs() method as selection.byGlyphs was read only
493+
for glyph in sourceFont.glyphs():
494+
try:
495+
if glyph.left_side_bearing < 0.0:
496+
glyph.left_side_bearing = 0.0
497+
if glyph.right_side_bearing < 0.0:
498+
glyph.right_side_bearing = 0.0
499+
glyph.width = width
500+
except:
501+
pass
502+
495503

496504
def get_scale_factor(font_dim, sym_dim):
497505
scale_ratio = 1
@@ -707,13 +715,6 @@ def copy_glyphs(sourceFont, sourceFontStart, sourceFontEnd, symbolFont, symbolFo
707715
align_matrix = psMat.translate(x_align_distance, y_align_distance)
708716
sourceFont.transform(align_matrix)
709717

710-
# Needed for setting 'advance width' on each glyph so they do not overlap,
711-
# also ensures the font is considered monospaced on Windows by setting the
712-
# same width for all character glyphs.
713-
# This needs to be done for all glyphs, even the ones that are empty and
714-
# didn't go through the scaling operations.
715-
sourceFont[currentSourceFontGlyph].width = font_dim['width']
716-
717718
# Ensure after horizontal adjustments and centering that the glyph
718719
# does not overlap the bearings (edges)
719720
if sourceFont[currentSourceFontGlyph].left_side_bearing < 0:
@@ -722,6 +723,15 @@ def copy_glyphs(sourceFont, sourceFontStart, sourceFontEnd, symbolFont, symbolFo
722723
if sourceFont[currentSourceFontGlyph].right_side_bearing < 0:
723724
sourceFont[currentSourceFontGlyph].right_side_bearing = 0.0
724725

726+
# Needed for setting 'advance width' on each glyph so they do not overlap,
727+
# also ensures the font is considered monospaced on Windows by setting the
728+
# same width for all character glyphs.
729+
# This needs to be done for all glyphs, even the ones that are empty and
730+
# didn't go through the scaling operations.
731+
# moved this after changing the bearings because i think it was
732+
# messing up the glyph width to have it before
733+
sourceFont[currentSourceFontGlyph].width = font_dim['width']
734+
725735
# reset selection so iteration works properly @todo fix? rookie misunderstanding?
726736
# This is likely needed because the selection was changed when the glyph was copy/pasted
727737
if symbolFontStart == 0:
@@ -740,7 +750,8 @@ if args.extension == "":
740750
else:
741751
extension = '.'+args.extension
742752

743-
if args.single and extension == '.ttf':
753+
# removed the ttf condition as i think it is necessary for all monospace fonts to have glyphs of equal width
754+
if args.single:
744755
# Force width to be equal on all glyphs to ensure the font is considered monospaced on Windows.
745756
# This needs to be done on all characters, as some information seems to be lost from the original font file.
746757
# This is only a problem with ttf files, otf files seem to be okay.
@@ -786,4 +797,3 @@ print("\nGenerated: {}".format(sourceFont.fullname))
786797
if args.postprocess:
787798
subprocess.call([args.postprocess, args.outputdir + "/" + sourceFont.fullname + extension])
788799
print("\nPost Processed: {}".format(sourceFont.fullname))
789-

0 commit comments

Comments
 (0)