@@ -489,9 +489,17 @@ def get_dim(glyph):
489
489
}
490
490
491
491
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
+
495
503
496
504
def get_scale_factor (font_dim , sym_dim ):
497
505
scale_ratio = 1
@@ -707,13 +715,6 @@ def copy_glyphs(sourceFont, sourceFontStart, sourceFontEnd, symbolFont, symbolFo
707
715
align_matrix = psMat .translate (x_align_distance , y_align_distance )
708
716
sourceFont .transform (align_matrix )
709
717
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
-
717
718
# Ensure after horizontal adjustments and centering that the glyph
718
719
# does not overlap the bearings (edges)
719
720
if sourceFont [currentSourceFontGlyph ].left_side_bearing < 0 :
@@ -722,6 +723,15 @@ def copy_glyphs(sourceFont, sourceFontStart, sourceFontEnd, symbolFont, symbolFo
722
723
if sourceFont [currentSourceFontGlyph ].right_side_bearing < 0 :
723
724
sourceFont [currentSourceFontGlyph ].right_side_bearing = 0.0
724
725
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
+
725
735
# reset selection so iteration works properly @todo fix? rookie misunderstanding?
726
736
# This is likely needed because the selection was changed when the glyph was copy/pasted
727
737
if symbolFontStart == 0 :
@@ -740,7 +750,8 @@ if args.extension == "":
740
750
else :
741
751
extension = '.' + args .extension
742
752
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 :
744
755
# Force width to be equal on all glyphs to ensure the font is considered monospaced on Windows.
745
756
# This needs to be done on all characters, as some information seems to be lost from the original font file.
746
757
# This is only a problem with ttf files, otf files seem to be okay.
@@ -786,4 +797,3 @@ print("\nGenerated: {}".format(sourceFont.fullname))
786
797
if args .postprocess :
787
798
subprocess .call ([args .postprocess , args .outputdir + "/" + sourceFont .fullname + extension ])
788
799
print ("\n Post Processed: {}" .format (sourceFont .fullname ))
789
-
0 commit comments