Skip to content

Refactor string drawing functions

sphere requested to merge font_drawer into next

This branch implements general-use functions for drawing strings & measuring string width/height, and replaces the existing string drawing & measuring functions with #defines using these generalized functions, removing a lot of duplicated code in the process.

V_DrawFontStringAtFixed

  • x, y: The fixed_t coordinates.
  • option: Video flags.
  • pscale, vscale: The fixed_t horizontal & vertical scale at which the characters get drawn. These also affect space width and line spacing.
  • string: The string to draw.
  • font: A font definition (fontdef_t, see below).

V_DrawAlignedFontStringAtFixed

  • Similar to the above, but also allows centered and right-aligned drawing, which is set using a text_align enum.
  • text_align has 3 options: align_left, align_center and align_right.
  • Unlike previous centered & right-aligned string drawing functions, this function properly aligns multi-line strings.

V_FontStringWidth & V_FontStringHeight

  • string: The string to measure the width/height of, taking newlines into account.
  • option: Video flags.
  • font: A font definition (fontdef_t, see below).

Instead of just patch_t arrays, fonts like hu_font or tny_font are now stored as the following structure, with some additional parameters:

fontdef_t

  • chars[]: The patch_t array containing all the font's graphics.
  • kerning: The distance between each character. Can also be negative, to move characters closer together.
  • spacewidth: The width of a space.
  • charwidth: The width of one character. Only used for old video flags like V_MONOSPACE and V_OLDSPACING.
  • linespacing: The height difference between two lines, used for newlines. (Gets overridden by V_RETURN8, which sets it to 8.)
Edited by sphere

Merge request reports