How To Make a Snap-to Grid In FontForge


The rising popularity of retro, 8-bit graphics seems to also be increasing demand for bitmap-like or pixelated fonts.  Furthermore, the popularity of FontStruct also indicates a demand for the simplicity of designing fonts based on a grid layout.  Thus, given that a vectored grid feature will likely never appear in FontForge (presumably because fancy fonts rely more on custom guidelines than a grid), I will attempt to explain the simplest way(s) to make or fake a snap-to grid in FontForge.

The Tiny-em Method

If starting a new font from scratch, you have the easy option of setting a very small em size (in Element > Font Info > General > Em Size) and turning on Snap-To-Integer (in File > Preferences > Editing > SnapToInt).  Set the em size to, basically, how tall you want your characters to be in “pixels” such as 10, 12, 18, or whatever.  This “cheat” is mentioned here:

Note: TrueType fonts, however, have a tradition that the em size should be a power of 2 (as in 8, 16, 32, etc.) which is pretty limiting when hoping for a small grid to work on.

Draw Your Own Grid

This method was adapted from Scindix’s response to the above post but doesn’t involve scaling down and back up (which may not always be an option, or work that well) and is otherwise simplified a bit (with some basic math skills required).

In most cases, such as when the entire glyph set is to be blocky, you probably want to fill the entire em height and glyph width with the grid.  For example, a 1152×2048 glyph (1792 ascent, 256 descent) can be evenly divided into a 9×16 grid with each space being 128×128.

You might also break the power-of-2-em-height tradition, to make the math easier on yourself, by setting the em height to 1600 or whatever works for you (and ignore the warnings FontForge will present about this… at your own risk of course).  If you want to first test fonts that don’t follow the power-of-2 tradition, I have noticed that fonts from The Ultimate Oldschool PC Font Pack don’t bother with it.  I haven’t seen any issues with them yet.

Side note:  I have found that a good em height for TTF-to-bitmap generation in GameMaker is 800 (800 ascent, 0 descent).  Setting point size to 5 then generates a perfect pixel for each 100 units.  I still draw descenders and they convert fine.  Of course, nothing else may space your font well with a 0 descent… but nice vertical spacing isn’t the goal with GameMaker conversions.  I suppose 700 ascent, 100 descent, would have also worked, but that wasn’t the spec for this font (it should be 900 tall).  Anyhow, adjust your em height and conversion point size accordingly.

In my example here, I will draw an 8×8 grid with rectangular spaces inside a 600×1024 glyph.  To keep it interesting (because I’m adding blocky glyphs to a non-blocky font), I want the grid to occupy most of the space… but not all of it (perhaps a 100-unit margin, or so, on all sides).  If I make each grid space 50×100 units, then that adds up to an overall grid dimension of 400×800 units.

  1. Not required, but turning on Snap-To-Integer is normally a good idea for this work (File > Preferences > Editing > SnapToInt).
  2. Open a glyph for editing and switch to the Guide layer to draw the grid.
  3. Select the Rectangle tool and draw a rectangle roughly the size of the intended grid.
    • ffgrid02marked
  4. Manually edit the points of the rectangle:
    • Right-click a point, and select “Get info”:
      • Set the points to:
        • upper left:  100, 800 (I chose a left margin of 100 units)
        • upper right:  500, 800
        • lower right:  500, 0
        • lower left:  100, 0
      • Hint: You can navigate between the points in the Get Info window with the Prev and Next buttons (Alt+P and Alt+N, plus Alt+B).
    • Caution: Be sure to get your math right for even subdivision of the grid later on.
    • ffgrid03marked
  5. Draw the horizontal grid lines:
    • Select the Corner Point tool
    • For an 8×8 grid, draw 7 lines inside—but not touching—the rectangle:
      • Click here, Click there, hit Escape
        • Repeat 6 more times
      • The lines can be sloppy
      • Caution: If you touch the rectangle, the point will become a point on the rectangle instead of a new entity.
    • ffgrid04marked
  6. Stretch the lines closer to the left edge of the grid:
    • Select the Pointer tool
    • Select all left-side points of the 7 lines with a selection rectangle (or shift-clicking)
    • Drag the 7 points to near the left edge of the grid rectangle.
    • ffgrid05marked
  7. Align these 7 points to the edge of the grid (with all 7 still selected):
    • Align the 7 points to each other:
      • Right-click a selected point > Align Points (or Element > Align > Align Points)
    • Fine tune the x coordinate to 100,*:
      • While watching the point coordinate on the toolbar (the second set of coordinates on the toolbar), use the left and right arrow keys to move the selected points 1 unit at a time.
    • ffgrid06marked
  8. Space these 7 points evenly:
    • Reselect all 7 points plus the 2 left corner points of the rectangle (9 points selected now):
      • Element > Align > Space Points.
    • ffgrid07marked
  9. Repeat steps 5, 6, and 7 for the right side points.
    • ffgrid08marked
  10. Repeat steps 4-8 for the vertical grid lines.
    • ffgrid09marked
  11. At this point, you have a visible grid.  Also, at this point, snap will find the corner points of the rectangle and the endpoints of the lines (all the perimeter points), but not the internal intersections yet.  FontForge only knows how to snap to a single point and to the nearest spot on a single line, and not to an intersection of lines.  Thus, your grid is not fully snap-to ready yet.
    • Hint: If snapping is not finding the snap points strongly enough for you, increase the snap distance (File > Preferences > Editing > SnapDistance).
  12. Add all the middle points:
    • To make the grid fully snap-to ready, you need to subdivide the vertical lines by adding additional points to them.  After what you just went through to get this far, this is the easy down-hill run.
    • Select the Corner Point tool
    • Click to add a point at or near each intersection within the grid
      • 7 wide and 7 tall for 49 additional points.
    • ffgrid11marked
  13. Align all the middle points:
    • You may need to zoom in for tighter work
    • Select the Pointer tool
    • Select a row of 7 new points:
      • Right-click a selected point > Align Points (or Element > Align > Align Points)
      • Fine tune the y coordinate to multiples of 100 (the y grid spacing)
        • While watching the point coordinate on the toolbar, use the up and down arrow keys to move the selected points 1 unit at a time
        • (The x coordinate should not need fine tuning as long as you clicked reasonably close to the vertical line with each new point.  The vertical lines are on top and should have grabbed the snap first.)
      • Repeat for all 7 new rows of points.
    • Hint: You can navigate through the points with Tab and Shift+Tab while watching the point coordinates on the toolbar as a quick check of accuracy.
    • ffgrid12marked
  14. Switch to the Fore layer and test it out with the Pen tool or Corner Point tool to make sure snapping is working as expected on all points.

If you appreciate the time I’ve spent on my blog,
please also support my other work:

GRITS Racing logo and two "Billy Bub" cars engaged

GRITS Racing is a party game for up to 8 players that is part racecar simulator, part cartoon action.  Available on both and Steam.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s