1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#ifndef SKETCHBOOK_TEXT_H
#define SKETCHBOOK_TEXT_H
#include <SDL3/SDL.h>
#include <stddef.h>
/* x/y are the logical line-box top. Scale 1 is 13 px Go Mono (roughly
eight-pixel ASCII advance and a 16-pixel line box); fallback uses Fontconfig. */
bool sk_text_draw(SDL_Renderer *, float x, float y, float scale,
const char *utf8, size_t len, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* What sk_text_draw gives the text at `scale`: its advance width and the
height of its line box, in logical units. False if it cannot be laid out. */
bool sk_text_measure(SDL_Renderer *, float scale, const char *utf8, size_t len,
float *width, float *height);
/* The same in another face of the bundled Go family (`abi.Face`'s order). */
enum { SK_TEXT_MONO, SK_TEXT_MONO_BOLD, SK_TEXT_MONO_ITALIC, SK_TEXT_SANS, SK_TEXT_SANS_MEDIUM, SK_TEXT_SANS_BOLD, SK_TEXT_FACES };
bool sk_text_draw_face(SDL_Renderer *, int face, float x, float y, float scale,
const char *utf8, size_t len, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
bool sk_text_measure_face(SDL_Renderer *, int face, float scale, const char *utf8, size_t len,
float *width, float *height);
/* The same, laid out and rasterized at `raster` and drawn at `scale`: the
glyphs keep their places against each other while the size changes (a
camera moving), and one texture serves every size on the way. Its
position is not snapped to a pixel. */
bool sk_text_draw_scaled(SDL_Renderer *, int face, float x, float y, float scale, float raster,
const char *utf8, size_t len, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
void sk_text_begin_frame(SDL_Renderer *);
#endif
|