Jazz2::UI::Font class

Bitmap font renderer.

The renderer loads a bitmap font from a custom file format with full Unicode support and renders it to a canvas. It can also measure the size of a string without rendering it.

Text formatting

The renderer supports inline text formatting using the "\f[…]" notation. Unknown attributes are ignored. Following attributes are supported:

  • "\f[c:#RRGGBB]" — Sets the font color that can be specified in a hex value in RGB format
    • The game usually renders text using a colorization shader that uses a different color space to be able to change the text color more precisely, so the specified color must be adjusted accordingly
  • "\f[/c]" — Resets the font color
  • "\f[w:XX]" — Sets the character spacing as a percentage, recommended range is 80% to 120%
  • "\f[/w]" — Resets the character spacing

Constructors, destructors, conversion operators

Font(StringView path, const std::uint32_t* palette)

Public functions

auto GetSizeInPixels() const -> std::int32_t
Returns font size in pixels.
auto GetAscentInPixels() const -> std::int32_t
Returns font ascent in pixels.
auto MeasureChar(char32_t c) const -> Vector2f
Returns size of a single character.
auto MeasureString(StringView text, float scale = 1.0f, float charSpacing = 1.0f, float lineSpacing = 1.0f) -> Vector2f
Returns size of a string.
auto MeasureStringEx(StringView text, float scale, float charSpacing, float maxWidth, std::int32_t* charFit, float* charFitWidths) -> Vector2f
Returns size of a string and its cumulative widths.
void DrawString(Canvas* canvas, StringView text, std::int32_t& charOffset, float x, float y, std::uint16_t z, Alignment align, Colorf color, float scale = 1.0f, float angleOffset = 0.0f, float varianceX = 4.0f, float varianceY = 4.0f, float speed = 0.4f, float charSpacing = 1.0f, float lineSpacing = 1.0f)
Draws a string.

Constants

static Colorf DefaultColor constexpr
Default (yellow) font color.
static Colorf TransparentDefaultColor constexpr
Default (yellow) font color with 60% transparency.
static Colorf RandomColor constexpr
Random (rainbow) font color.
static Colorf TransparentRandomColor constexpr
Random (rainbow) font color with 60% transparency.