cpitclaudel / monospacifier

Convert variable-pitch fonts to monospace (useful for unicode and indentation-friendly programming)
GNU General Public License v3.0
379 stars 31 forks source link

AttributeError, and keeping the aspect ratio? #3

Closed michael-brade closed 8 years ago

michael-brade commented 8 years ago

Hi, this is an absolutely awesome tool! Thank you so much, you saved me hours of work! It still took me hours to figure out that I needed to monospace my font, and it was only luck that I stumbled across this neat little tool - it is not easy to find.

Still, I have two small issues with it. One, it sort of crashes with --copy-metrics, but it does seem to save the font anyway:

Traceback (most recent call last):
  File "./monospacifier.py", line 281, in <module>
    main()
  File "./monospacifier.py", line 267, in main
    results = list(process_fonts(args.references, args.inputs, args.save_to, args.merge, args.copy_metrics))
  File "./monospacifier.py", line 256, in process_fonts
    path = make_monospace(reference, fallback, gscaler, save_to, copy_metrics)
  File "./monospacifier.py", line 206, in make_monospace
    fscaler.copy_metrics(reference)
  File "./monospacifier.py", line 169, in copy_metrics
    setattr(self.font, metric, getattr(reference, metric))
AttributeError: 'fontforge.font' object has no attribute 'os2_capheight'

And two, the generated font's glyphs (octicons in my case) get squeezed horizontally more than vertically, so the round ones now look more like an egg rather than a circle. Would it be possible to supply a parameter that keeps the aspect ratio of the glyphs?

Or, even better in this case: keep the size of the visible "drawing" and shrink only the glyph's canvas width so that the icon might be drawn over neighbouring glyphs. I wouldn't care, I can simply add a space in front and after it, but that would look better :)

thanks!

cpitclaudel commented 8 years ago

HI Michael,

Thanks for the bug report; I'll look into it! As for your feature request, that one should be easy: on line 225, instead of

            gscaler = StretchingGlyphScaler(ref_width, FontScaler.average_width(fallback))

you want

            gscaler = BasicGlyphScaler(ref_width, FontScaler.average_width(fallback))

Does that work?

cpitclaudel commented 8 years ago

Should be fixed! Can you try again? Thanks!

michael-brade commented 8 years ago

Yes, indeed it is fixed, and it works! Thanks for the quick reply, it was too quick for me to even notice :)

I had to change the call to

gscaler = BasicGlyphScaler(ref_width)

though, otherwise __init__ complains about the additional argument.

cpitclaudel commented 8 years ago

Indeed, my mistake :) Glad to know it works now!