Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix monospace/overlap problem #283

Merged
merged 1 commit into from
Jun 20, 2019
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
34 changes: 22 additions & 12 deletions font-patcher
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,17 @@ def get_dim(glyph):
}

def set_width(sourceFont, width):
sourceFont.selection.all()
for glyph in sourceFont.selection.byGlyphs:
glyph.width = width
# changed to glyphs() method as selection.byGlyphs was read only
for glyph in sourceFont.glyphs():
try:
if glyph.left_side_bearing < 0.0:
glyph.left_side_bearing = 0.0
if glyph.right_side_bearing < 0.0:
glyph.right_side_bearing = 0.0
glyph.width = width
except:
pass


def get_scale_factor(font_dim, sym_dim):
scale_ratio = 1
Expand Down Expand Up @@ -707,13 +715,6 @@ def copy_glyphs(sourceFont, sourceFontStart, sourceFontEnd, symbolFont, symbolFo
align_matrix = psMat.translate(x_align_distance, y_align_distance)
sourceFont.transform(align_matrix)

# Needed for setting 'advance width' on each glyph so they do not overlap,
# also ensures the font is considered monospaced on Windows by setting the
# same width for all character glyphs.
# This needs to be done for all glyphs, even the ones that are empty and
# didn't go through the scaling operations.
sourceFont[currentSourceFontGlyph].width = font_dim['width']

# Ensure after horizontal adjustments and centering that the glyph
# does not overlap the bearings (edges)
if sourceFont[currentSourceFontGlyph].left_side_bearing < 0:
Expand All @@ -722,6 +723,15 @@ def copy_glyphs(sourceFont, sourceFontStart, sourceFontEnd, symbolFont, symbolFo
if sourceFont[currentSourceFontGlyph].right_side_bearing < 0:
sourceFont[currentSourceFontGlyph].right_side_bearing = 0.0

# Needed for setting 'advance width' on each glyph so they do not overlap,
# also ensures the font is considered monospaced on Windows by setting the
# same width for all character glyphs.
# This needs to be done for all glyphs, even the ones that are empty and
# didn't go through the scaling operations.
# moved this after changing the bearings because i think it was
# messing up the glyph width to have it before
sourceFont[currentSourceFontGlyph].width = font_dim['width']

# reset selection so iteration works properly @todo fix? rookie misunderstanding?
# This is likely needed because the selection was changed when the glyph was copy/pasted
if symbolFontStart == 0:
Expand All @@ -740,7 +750,8 @@ if args.extension == "":
else:
extension = '.'+args.extension

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