summaryrefslogtreecommitdiff
path: root/vendor/text.h
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/text.h')
-rw-r--r--vendor/text.h67
1 files changed, 46 insertions, 21 deletions
diff --git a/vendor/text.h b/vendor/text.h
index aa49db8..355ad90 100644
--- a/vendor/text.h
+++ b/vendor/text.h
@@ -1,26 +1,51 @@
+/* sketchbook's text: the faces (`abi.Face`'s ten, bundled, and a sketch's
+ own from bytes), shaped by HarfBuzz and rasterized by pardes's font.c.
+ One static library, `sketchbook-text`, linked by the host and by a
+ sketch's tests, so both measure with the same code. */
#ifndef SKETCHBOOK_TEXT_H
#define SKETCHBOOK_TEXT_H
-#include <SDL3/SDL.h>
+#include "font.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). */
+#include <stdint.h>
+
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_CODE, SK_TEXT_CODE_BOLD, SK_TEXT_CODE_ITALIC, SK_TEXT_CODE_MEDIUM, 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 *);
+#define SK_TEXT_MAX_FACES 64
+
+/* One glyph of a shaped run: `face` draws it (the run's, or its fallback),
+ `cluster` is the byte it starts at, `x`/`y` its pen position in whole
+ pixels from the run's start (y down). */
+typedef struct {
+ uint32_t glyph;
+ uint32_t cluster;
+ int32_t x;
+ int32_t y;
+ uint8_t face;
+} SkGlyph;
+
+/* `utf8` in `face` at `px` pixels, left to right: at most `max` glyphs into
+ `out` (NULL to measure only). Returns how many there are (more than `max`
+ when they did not fit), with the run's advance, its ascent and its line's
+ height, all in whole pixels: each glyph's advance is rounded, and the
+ line box is FreeType's at that size (font.h's cell metrics). Invalid
+ UTF-8 shapes as U+FFFD; an unknown face as the mono. */
+int sk_text_shape(int face, float px, const char *utf8, size_t len, SkGlyph *out, int max,
+ int32_t *advance, int32_t *ascent, int32_t *height);
+
+/* `sk_text_shape` measured: the run's advance, with `xs` (when not NULL,
+ `len` of them) the x of each byte from the run's start, a byte inside a
+ cluster at its cluster's. What `abi.Host.VTable.textRun` serves. */
+int32_t sk_text_run(int face, float px, const char *utf8, size_t len, float *xs,
+ int32_t *ascent, int32_t *height);
+
+/* `glyph`'s own advance in `face` at `px`, in whole pixels (what the
+ renderer centres font.c's raster in, so the glyph lands on its origin). */
+int32_t sk_text_advance(int face, float px, uint32_t glyph);
+
+/* A face for a sketch's own font, its bytes copied: the same id for the
+ same bytes. -1 when FreeType refuses them or every face is taken. */
+int sk_text_font(const uint8_t *bytes, size_t len);
+
+/* What rasterizes `face` (font.h's ui_font_raster), NULL if none. */
+UIFont *sk_text_ui(int face);
+
#endif