text_font.h
The backend neutral half of the text renderer. It covers atlas metrics, measuring, wrapping, elision and glyph emission.
#include "isolenui/text/text_font.h". The guide starts at Fonts and measuring.
Laying a line to bend
Explained in Low level surface.
text_font_laidtext_font_lay_dirFonts and measuring
Explained in Fonts and measuring.
text_fonttext_linetext_font_loadtext_font_freetext_font_release_pixelstext_font_measuretext_font_ascenttext_font_descenttext_font_line_heighttext_font_min_widthtext_font_wraptext_font_elideTEXT_FONT_TERMINATEDTEXT_MAX_FACESDrawing
Explained in Drawing.
text_font_aligntext_font_lefttext_font_centretext_font_righttext_font_drawtext_font_draw_intext_font_draw_fit26.6 fixed point
Explained in 26.6 fixed point.
text_font_measure_runtext_font_ascent26text_font_descent26text_font_line_height26text_font_underline26Low level surface
Explained in Low level surface.
text_font_glyphtext_font_kerntext_font_findtext_font_kerningtext_font_utf8_nexttext_font_glyph_recordtext_font_emittext_font_emit_inTEXT_GLYPH_NONETEXT_ASCII_LOWTEXT_ASCII_HIGHTEXT_ASCII_SPANDirection aware text
Explained in Direction and bidi.
text_font_starttext_font_endtext_font::fallbacktext_font::fallback_handletext_font_plaintext_font_measure_dirtext_font_draw_in_dirtext_font_draw_fit_dirtext_font_wrap_dirtext_font_min_width_dirtext_font_draw_line_dirisolen_app_desc::no_fallbackisolen_app_desc::no_shapingExample
text_fonts.cpp
#include "isolenui/text/text_font.h"
// the atlas resolves beside the executable, the same rule
// isolen_app_desc::font follows
static bool boot_font(text_font* f)
{
return text_font_load(f, "assets\\objectivity.atlas");
}
// TEXT_FONT_TERMINATED as the length walks to the nul, any other length is
// a byte count, so a slice of a larger buffer needs no copy
static void measure_caption(const text_font* f, const char* utf8, float width)
{
const uint32_t face = 0u;
const float px = 16.0f;
const float tracking = 0.0f;
const float full_w =
text_font_measure(f, face, utf8, TEXT_FONT_TERMINATED, px, tracking);
const float first_word_w = text_font_measure(f, face, utf8, 5u, px, tracking);
// the widest run that cannot break, what a column must never go below
const float floor_w =
text_font_min_width(f, face, utf8, TEXT_FONT_TERMINATED, px, tracking);
text_line lines[8];
const uint32_t line_count = text_font_wrap(
f, face, utf8, TEXT_FONT_TERMINATED, px, tracking, width, lines, 8u);
const float block_h =
float(line_count < 8u ? line_count : 8u) * text_font_line_height(f, px);
char elided[64];
text_font_elide(f, face, utf8, TEXT_FONT_TERMINATED, px, tracking, width,
elided, sizeof(elided));
(void)full_w;
(void)first_word_w;
(void)floor_w;
(void)block_h;
}
// a font that only measures can drop its atlas pixels, but one bound to a gfx
// device must keep them, a backend switch uploads the atlas again and
// gfx_font_bind refuses a font whose pixels are gone
static void measure_only(text_font* f)
{
text_font_release_pixels(f);
const float ascent = text_font_ascent(f, 24.0f);
const float descent = text_font_descent(f, 24.0f);
(void)ascent;
(void)descent;
}