font

struct font

struct font

Use bitmap fonts to draw text Bitmap fonts are made from images with a matrix of characters in ascii order.

create_font

struct font *create_font(const char *filepath, int cols, int rows)

Create a new font from an image file

Return
New font, ready to use
Parameters
  • filepath -

    Image to use for font

  • cols -

    Number of columns in the font bitmap image.

  • rows -

    Number of rows in the font bitmap image.

destroy_font

void destroy_font(struct font *font)

Destory an existing font

Parameters
  • font -

    Font to cleanup and deallocate

load_font

int load_font(struct font *font, const char *filepath, int cols, int rows)

Build a font from a font image file containing 16x16 (256) characters

Return
-1 on error
Parameters
  • font -

    Font resource to generate

  • filepath -

    font image to load

  • cols -

    Number of columns in the font bitmap

  • rows -

    Number of rows in the font bitmap

cleanup_font

int cleanup_font(struct font *font)

Free any internally allocated resources for the font

Return
-1 on error
Parameters
  • font -

    Font to cleanup

draw_text

void draw_text(struct font *font, const char *text, int x, int y)

Use font to render text

Parameters
  • font -

    Font to use

  • text -

    text to render

  • x -

    x coordinates

  • y -

    y coordinates

measure_text

void measure_text(struct font *font, const char *text, int *width, int *height)

Measure the expected width and height of some text using a font

Parameters
  • font -

    Font to use

  • text -

    text to render

  • width -

    a pointer to where the width will be stored

  • height -

    a pointer to where the height will be stored