diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 04:02:44 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | 1f9fa4fc66c68e66e7653498f04d17052833d6c3 (patch) | |
| tree | 177d92af30f09207a2c9164a9b425c7178d5845d /vendor/fonts | |
| parent | 1229dae433b0036547b1e28e76af645b1b57d7a0 (diff) | |
| download | sketchbook-1f9fa4fc66c68e66e7653498f04d17052833d6c3.tar.gz sketchbook-1f9fa4fc66c68e66e7653498f04d17052833d6c3.zip | |
text: FreeType and HarfBuzz in the build, Pango, Cairo and glib out, glyphs from one atlas
build.zig.zon gains the freetype and harfbuzz packages pardes pins (lazy:
a gpu-only embedder brings its own), and build.zig compiles them, with the
flags pardes's window uses, together with pardes's vendor/font.c
(unchanged) and a new vendor/text.c into one static library,
sketchbook-text, which the host links. vendor/text.c replaces the Pango
shim: the ten bundled faces by #embed, opened on first use by FreeType
(font.c) and by HarfBuzz's own OpenType functions over the same bytes;
sk_text_shape shapes a run left to right at a pixel size, each advance
rounded to a whole pixel, with the line box font.c's cell metrics give;
a codepoint the face lacks comes from one fallback face (ponytail: no
fontconfig, no bidi); sk_text_font takes a sketch's own font from bytes.
src/host/Glyphs.zig is the renderer: a text command is shaped at its
canvas size, each glyph rastered by font.c's ui_font_raster at its device
size and kept, trimmed to its ink (Atlas.inkBounds), in shelves of one
2048x2048 atlas, white premultiplied by coverage, cleared and refilled
when full. Consecutive text commands are one SDL_RenderGeometry call;
upright text lands on whole device pixels, NEAREST; textScaled (and a
glyph past 512 device pixels) is unsnapped, LINEAR. The SDL debug font
fallback off Linux goes: the faces are built in everywhere.
Host.textSize measures with the same call. test/fonts.c (a Pango
specimen outside the build) goes.
Measured: a cold Debug build of the host 39.8 s before, 43.7 s after;
the Debug host 117.7 MB (35.6 MB stripped) before, 159.5 MB (46.8 MB)
after, with 6 shared libraries where it loaded 41 (pango, cairo, glib,
fontconfig, the system freetype and harfbuzz and theirs). A frame of
4500 glyphs, half changing every frame (ReleaseFast, headless): 27.5 M
instructions and 2.80 ms of CPU before, 5.33 M and 0.40 ms after; all
static: 6.44 M and 0.47 ms before, 5.28 M and 0.42 ms after.
zig build test: 192/192 steps, 146/146 tests; test/text.script's pinned
pixels hold.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'vendor/fonts')
| -rw-r--r-- | vendor/fonts/README.md | 74 |
1 files changed, 14 insertions, 60 deletions
diff --git a/vendor/fonts/README.md b/vendor/fonts/README.md index b02fd51..e9ac1ec 100644 --- a/vendor/fonts/README.md +++ b/vendor/fonts/README.md @@ -1,72 +1,26 @@ -# Native text +# Native text's faces -Linux Sketchbook text uses bundled **Go Mono** through PangoCairo: HarfBuzz -shaping, Fontconfig fallback and FreeType/Cairo grayscale antialiasing with light -hinting. This follows the rendering quality choices in Pardes `src/gui/font.c`; -it does not copy Pardes's terminal-cell shaping, bold synthesis or glyph atlas. +Sketchbook's native text is shaped by HarfBuzz and rasterized by pardes's +`vendor/font.c` over FreeType (`vendor/text.c`, built into the host as the +static library `sketchbook-text`; see `docs/text.md`). These files are its +faces, embedded in the binary with C23 `#embed`, in `abi.Face`'s order. No +installed font is read: there is no fontconfig. `Go-Mono.ttf` is from the Go project's official `golang/image` repository: https://github.com/golang/image/tree/master/font/gofont/ttfs SHA-256: `8bc66a0154bbf69cd24e5bde41a12ec9495c8a242c5def2255e4a164900f1ed7`. The complete Bigelow & Holmes / Go font license is in `LICENSE`. -Five more faces of the same family are bundled the same way, for -`f.textIn(face, ...)` (`abi.Face`, in this order after Go Mono): -`Go-Mono-Bold.ttf`, `Go-Mono-Italic.ttf`, `Go-Regular.ttf`, `Go-Medium.ttf`, -`Go-Bold.ttf`, as the `ttf-go` package installs them (the same upstream). -Each is a font description of its own (`sk_text_draw_face`); the sans -faces fall back to installed sans families instead of mono ones. +Five more faces of the same family follow it: `Go-Mono-Bold.ttf`, +`Go-Mono-Italic.ttf`, `Go-Regular.ttf`, `Go-Medium.ttf`, `Go-Bold.ttf`, as +the `ttf-go` package installs them (the same upstream). Four faces of **JetBrains Mono NL** (the family without ligatures) follow them (`.code`, `.code_bold`, `.code_italic`, `.code_medium`): `JetBrainsMonoNL-Regular.ttf`, `-Bold.ttf`, `-Italic.ttf` and `-Medium.ttf` -as the `ttf-jetbrains-mono` package installs them, under the -SIL Open Font License in `LICENSE-JetBrainsMono`. They fall back as the -mono faces do. +as the `ttf-jetbrains-mono` package installs them, under the SIL Open Font +License in `LICENSE-JetBrainsMono`. -The fonts are embedded in the binary with C23 `#embed`. It is registered in a -private Fontconfig config through a Linux memfd, so moving the executable does -not require a font installation or the source checkout. Installed outline fonts -provide Unicode fallback, in the order listed in `vendor/text.c`; actual glyph -coverage and emoji color depend on those fonts. Color font paint is preserved. -No system Fontconfig settings are modified. - -The `f.text`/`f.print` API is unchanged. Their x/y positions mean line-box top. -Scale 1 uses a nominal 13px font: Go Mono measures 8px ASCII advance and 16px -line height on the tested stack. At other sizes advances may round to a physical -pixel. Applications should allow a 16×scale line box and avoid slicing UTF-8 at -arbitrary byte boundaries. Pango shapes each supplied string independently; -applications still perform wrapping and clipping. Explicit newlines are not a -layout API. Other platforms retain SDL's debug-font fallback for now. - -`sk_text_measure` lays a string out the same way and returns its advance -width and line height (`Host.textSize`). `SKETCHBOOK_FONT`, in the -environment, names an installed family to put before Go Mono. - -Text is rasterized at the renderer's physical pixel density (including logical -presentation scale), and texture origins snap to physical pixels. Whole-run -textures retain antialiasing and shaping; no scaled 8×8 bitmap text is involved. -The renderer-owned cache retains at most 4096 strings / 128 MiB of pixel data. -ASCII runs cache white coverage masks and tint at draw time, so animated ink -reuses the same pixels. Unicode retains painted glyphs, including color emoji. -Only prior-frame textures can be evicted; exceptionally dense frames flush and -release temporary textures rather than growing the cache. Renderer destruction -releases the font map, descriptors and keys after SDL releases its textures. - -Native Linux builds need `pkg-config`, `pangocairo`, and `pangoft2` development -packages, in addition to SDL. The resulting executable uses the system Pango, -Cairo, HarfBuzz, Fontconfig and FreeType libraries. - -Run the independent regression and specimen (with system SDL3): - -```sh -cc -std=c23 -Wall -Wextra -Werror -O2 test/fonts.c -o /tmp/sketchbook-fonts \ - $(pkg-config --cflags --libs sdl3 pangocairo pangoft2) -lm -/tmp/sketchbook-fonts /tmp/sketchbook-fonts.png -``` - -It checks the primary font's advance/line box, Unicode fallback, zero-advance -combining marks, Arabic lam-alef shaping, 2× rendering density, clipping, cache -eviction and renderer cleanup. The specimen includes Latin, Greek, Cyrillic, -Japanese, Arabic, Hebrew and symbols/emoji. Missing fallback fonts fail the -coverage assertion rather than silently claiming complete Unicode support. +A codepoint a face lacks comes from one fallback: JetBrains Mono NL for the +Go faces (and a sketch's own), Go Mono for JetBrains Mono's. Neither family +has CJK, Arabic, Hebrew or emoji: those draw as the missing-glyph box. |
