How To Make a Snap-to Grid In FontForge


The rising popularity of retro, 8-bit graphics seem to also be increasing demand for bitmap-like 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 more professional 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 the limitation that the em size must 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 this example, I will draw an 8×8-space grid with rectangular-shaped spaces inside a 600×1024 glyph.  To keep it interesting, 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.  (Feel free to make your grid take over the entire glyph space if you desire.)

  1. Open an glyph for editing and switch to the Guide layer to draw the grid.
  2. Select the Rectangle tool and draw a rectangle roughly the size of the intended grid.
    • ffgrid02marked
  3. 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
  4. 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, Click, 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
  5. 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
  6. 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
  7. 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
  8. Repeat steps 5, 6, and 7 for the right side points.
    • ffgrid08marked
  9. Repeat steps 4-8 for the vertical grid lines.
    • ffgrid09marked
  10. 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).
  11. 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
  12. 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
  13. 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.



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 )

Google+ photo

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

Connecting to %s