How to create (in simple terms) a Monospace Font?

Hi,

I’ve been an user for Glyphs Mini since a while. Now i want to create a Monospace Font. Every Character in this font has already the same width. But unfortunately i cannot export it explicitly to a Monospace Font. I’m sure there is something missing, but i cannot figure out what. So i’ve downloaded the Trial-Version of the “big” Glyph but now i’m stuck. Can anyone help me creating my Monospace Font? That would be awesome.

Thanks in advance …

1 Like

What do you mean by ‘explicitly exporting to monospaced font’?

Hi mekkablue,

I want the font to have every character in the same width. This is a Icon-Font and every Icon has different width-sizes although i have declared the width to be the same for every Icon. I don’t know how to explain it better. So i thought, that there - maybe - is a hidden function, which force every character to be the same width? I’m not using Glyphs that much, therefore i really don’t know every functionality. :slight_smile: So probably i’ve done anything wrong, did i?

Go to font view, select all, set width in the lower left corner of the window. Is that what you’re looking for?

You also need to set the isFixedPitch custom parameter:

2 Likes

It’s only there to tell the renderer to give each letter the same pixel advance width, right?

Also, mekkablue’s instruction demonstrated in video (in Japanese UI, but it shouldn’t matter).
https://dl.dropboxusercontent.com/u/12398274/SameWidth.mp4

Thank you very much. The missing link was the “isFixedPitch”-hint. For a “real” Monospace-Font i guess this is necessary. Now the font works like a charm. Super!

Thanks again :slight_smile:

Not available in Mini. But not really necessary either. Do you happen to know which software actually respects the isFixedPitch bit?

But if it is a icon font, the isfixedpitch is not needed. That is important to be able to use it as a Monospace font in some environments (set in a text editor or terminal) only show fonts that have that check (among a few other things). So if you need the font every else, setting the width for all glyphs to the same value should be enough.

Some time ago (I think in 10.9 or 10.10), I did some testing with FontBook. It ignored the bit for the Smart Collection. Didn’t test Terminal though.

I think it’s related to hinting. Have you tried it in Windows?

Okay, i guess my challenge was a bit special. The font as i’ve exported from Glyphs Mini works in “normal” Applications like for example InDesign as expected. But I need the font for an app, in which the icons should iterate through. And here it comes to my issue. This App cuts away the blank space left and right from the Glyphs-content. So every Icon-content has a different width but all glyphs have the same width. Now with the test-version of Glyphs and the isFixedPitch-option this font works as expected. Probably this is a very special case, but if anyone runs into the same issue may find this post helpful. For me and my special case this was the solution.

Thank you all again :slight_smile:

1 Like

Which app on which OS?

It’s an app for IOS 8 (not 9 :slight_smile: ) and the IDE is Xcode. But i guess it will be the same for other IDEs. Maybe it would be a good idea for future releases of Glyphs Mini to add the “isFixedPitch”-functionality. Perhaps out there are many other people who wants to build an font easy and don’t need the full functionality of Glyphs. Don’t you think?

I think about it.

Sounds great :slight_smile:

I was looking for tips to create a monospaced font from an existing font. So I wrote a script you can run in the Macro Panel:

# Make your font Monospace!
print "Script by Charles @ https://wonderunit.com/"

# JUST CHANGE THIS VALUE FOR WIDTH:
width = 600
  
import math

# Clear the kerning table, if any
Glyphs.font.kerning = {}

num = 0

for glyph in Glyphs.font.glyphs:
  for layer in glyph.layers:
    glyphWidth = layer.bounds.size.width
    leftSpace = math.floor((width - glyphWidth)/2)
    layer.LSB = leftSpace
    layer.width = width
    num+=1
    
print "Done! {} glyphs were monospaced.".format(num)

Make sure you aren’t working on your original glyphs project, it will destroy all your old width and kerning info.

1 Like

Actually, this is necessary. Try not to be so conceited in your assumptions because some of us actually develop apps instead of just consuming fonts in a design studio.

When you build your own iOS app in Xcode, you’ll see that unless it’s explicitly set, TextKit and UIKit don’t preserve the width. The OS – or TextKit, Core Graphics below that – automatically renders the spacing to the left of the second 1 to be narrower than the 0, for prettier display. Unless you specify that it’s a Monospace font in the metadata. It’s not an Xcode problem; it’s how iOS reads a font file. watchOS and macOS behave similarly.

For example, let’s say your UILabel animates text from 101 to 100 – a common operation for counters and HP. If you don’t specify fixed-width (Monospace) in the font metadata, then the second zero in 100 will suddenly push the “10” to its left farther left, rather than maintaining a consistent position for all three digits, as the eye expects during a countdown. Then because the 7, 8, and 9 also render at different widths, the entire counter looks like it’s expanding and contracting as you animate the number down.

This is definitely a necessary make-or-break feature!

I recommend adding an isFixedPitch section or help article for Monospace fonts in the handbook, rather than just using the glossary, where it’s mentioned as an aside. This will help app developers immensely when they’re looking for how to create a font that preserves width across all glyphs, programmatically.

I think setting this boolean addresses the problem, but it isn’t clear from reading the Glyphs 3.0.4 handbook where this post table is, where we can set this parameter. The other user’s reply on this forum is more helpful and seems like it belongs in the handbook.

I’m pretty sure that if you have a font where all numbers have the same width, that MacOS renders that as such.
Screen Shot 2022-06-17 at 15.06.18

When you define a font in Xcode (in Interface Builder or per NS/UIFont) you portably mean the system font and that is a proportional. But it has several sets of numbers. The default numbers are proportional but you can specify to get monospace numbers. That is handled by Opentype/AAT feature and has nothing to do with the isFixedPitch flag in the font.

And MacOS doesn’t care much about the isFixedPitch flag. Xcode will use any font in the code editor:
Screen Shot 2022-06-17 at 15.11.04

This is what Mekkablue meant what he said that the isFixedPitch flag is (mostly) not needed.