Font selection

As it turns out, font selection is almost as trivial to implement as the persistent count file, above.

We had to add a -r option (for "render"), and a little bit of logic to determine which font was being specified:

case    'r':
    if (!strcmp (optarg, "8x8")) {
        optr = render_8x8;
    } else if (!strcmp (optarg, "7seg")) {
        optr = render_7segment;
    } else {
        // error message
        exit (EXIT_FAILURE);
    }
    break;

The specified font is selected by storing a function pointer to the font-rendering function in the optr variable. Once that's done, it's a simple matter of storing the function pointer into a new field (called render) within the OCB:

typedef struct my_ocb_s
{
  iofunc_ocb_t  base;
  unsigned char *output;
  int           size;
  void          (*render) (char *string,
                           unsigned char *bitmap,
                           int x, int y);
}   my_ocb_t;

Then, in io_read(), we replaced the hard-coded call to render_7segment():

render_7segment (string, input, optx, opty);

with a call through the OCB's new pointer:

(*ocb -> render) (string, input, optx, opty);

Fairly painless. Of course, we needed to create a new font and font-rendering module, which probably took more time to do than the actual modifications. See the source in 8x8.c for the details of the new font.