diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 09:06:20 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | 303478956e0086467a9073d7f6fa67b51b6580ad (patch) | |
| tree | 6c69e13eef575b514433373893e1f14c435b4f1a /build.zig | |
| parent | c94455e1a8d2a430d8dcd74603bcd0d7b27aeb68 (diff) | |
| download | sketchbook-303478956e0086467a9073d7f6fa67b51b6580ad.tar.gz sketchbook-303478956e0086467a9073d7f6fa67b51b6580ad.zip | |
text: sk.text measures anywhere, Frame.paragraph wraps, aligns, spans, reveals and finds a caret
The ABI's one text entry is textRun (Host.VTable.textSize goes): a run in
a face at a scale, as data, its advance and line box and each byte's x,
a pure function of the font, the scale and the bytes, never of the
display; and font, a face for a sketch's own TTF/OTF bytes (abi.Face is
non-exhaustive: faces past the ten are a sketch's). The native host
serves them from vendor/text.c (sk_text_run, sk_text_font), the web host
from canvas measureText and FontFace (web/host.js), and the web draws
each run in the page's monospace or sans-serif in the face's weight and
style instead of 8 px a character.
src/sketch/text.zig (sk.text) does the rest in plain Zig, the same on
every host: size, layout and font anywhere, update included (the glue
sets the host before each call into the sketch; a test binary has none
and calls sketchbook-text directly, which App.addTest now links); a
Paragraph is a face, scale and colour, a width to wrap at spaces, an
alignment, spans (from a byte on: a colour, a face, a scale), reveal
(the first N glyphs drawn, the layout the whole text's) and a caret
byte, and its Layout the size, lines, glyphs and the caret's place.
f.paragraph draws one, a Command.text a piece. f.text, f.textIn and
f.print are a paragraph with no width when the bytes hold a \n, else
the one command they were; host.textSize and textSizeIn stay, one line
through textRun.
Test: sk.text's own tests (a wrap, the space not counted, centred and
right, a caret at a line's start and end and after a \n, a span twice
the size, a word wider than the width, an empty text; reveal drawing the
first glyphs of the same layout), run through sketchbook-text; and
test/text.zig draws a centred paragraph with a red and a double-size span
and a caret from its Layout, which test/text.script pins. zig build
test-text runs these and the atlas's comparison with pardes's raster.
Every other pinned pixel of test/text.script holds: the lines it pins are
the same pixels Pango drew.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 24 |
1 files changed, 19 insertions, 5 deletions
@@ -109,12 +109,16 @@ pub fn build(b: *Build) void { b.step("test-sessions", "Test the sessions database: frames, keyframes, marks, clips").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = host, .filters = &.{"session"} })).step); b.step("test-presentation", "Test presentation feedback, pacing and trace snapshots").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = host, .filters = &.{"presentation"} })).step); + // The sketch library's tests measure text with no host: through + // sketchbook-text, as an app's tests do (`App.addTest`). + const sketch_tests = b.createModule(.{ .root_source_file = b.path("src/sketch/root.zig"), .target = target, .optimize = optimize, .imports = sketch_imports }); + sketch_tests.linkLibrary(text_library); const test_audio = b.step("test-audio", "Test sound: the voice mixer (reconciling, limiting, pitch, groups), sfxr, and a made sound played as a voice"); test_audio.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = host, .filters = &.{ "voice", "mixer" } })).step); - test_audio.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("src/sketch/root.zig"), .target = target, .optimize = optimize, .imports = sketch_imports }), .filters = &.{"sfxr"} })).step); + test_audio.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = sketch_tests, .filters = &.{"sfxr"} })).step); const setup_tests = b.step("test-setup", "Test resource setup lifecycle and arguments"); - for ([_]*Build.Module{ host, b.createModule(.{ .root_source_file = b.path("src/sketch/root.zig"), .target = target, .optimize = optimize, .imports = sketch_imports }) }) |module| setup_tests.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = module, .filters = &.{"setup"} })).step); + for ([_]*Build.Module{ host, sketch_tests }) |module| setup_tests.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = module, .filters = &.{"setup"} })).step); const host_exe = b.addExecutable(.{ .name = "sketchbook", @@ -127,7 +131,7 @@ pub fn build(b: *Build) void { }); b.installArtifact(host_exe); - var sb: Sketchbook = .{ .b = b, .target = target, .optimize = optimize, .modules = .{ .abi = abi, .sketch = sketch, .host = host, .tracy = tracy, .vector = undefined, .scope = undefined, .anim = undefined, .gltf = gltf, .cloud9 = cloud9 }, .host_exe = host_exe, .gltf_generator = gltf_generator, .web = b.path("web"), .glsl = b.path("src/glsl.zig"), .tools = b.path("tools"), .anim_dir = b.path("src/anim"), .gltf_render_dir = b.path("src/gltf_render"), .script_optimize = optimize, .shared = .create(b) }; + var sb: Sketchbook = .{ .b = b, .target = target, .optimize = optimize, .modules = .{ .abi = abi, .sketch = sketch, .host = host, .tracy = tracy, .vector = undefined, .scope = undefined, .anim = undefined, .gltf = gltf, .cloud9 = cloud9 }, .host_exe = host_exe, .text = text_library, .gltf_generator = gltf_generator, .web = b.path("web"), .glsl = b.path("src/glsl.zig"), .tools = b.path("tools"), .anim_dir = b.path("src/anim"), .gltf_render_dir = b.path("src/gltf_render"), .script_optimize = optimize, .shared = .create(b) }; // Vector graphics: built with the same shader step apps use. Both forms // of its shaders are exported, so apps' web builds can swap them too. @@ -185,7 +189,7 @@ pub fn build(b: *Build) void { b.createModule(.{ .root_source_file = b.path("src/scope/root.zig"), .target = target, .optimize = optimize, .imports = scope_imports }), b.createModule(.{ .root_source_file = b.path("src/glsl.zig"), .target = target, .optimize = optimize }), b.createModule(.{ .root_source_file = b.path("src/abi.zig"), .target = target, .optimize = optimize }), - b.createModule(.{ .root_source_file = b.path("src/sketch/root.zig"), .target = target, .optimize = optimize, .imports = sketch_imports }), + sketch_tests, b.createModule(.{ .root_source_file = b.path("src/math/root.zig"), .target = target, .optimize = optimize }), b.createModule(.{ .root_source_file = b.path("src/host/root.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "abi", .module = abi }, .{ .name = "c", .module = c }, .{ .name = "gpu", .module = gpu }, .{ .name = "tracy", .module = tracy }, .{ .name = "cloud9", .module = cloud9 }, .{ .name = "xitdb", .module = xitdb }, .{ .name = "font_atlas", .module = font_atlas } } }), }) |module| test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = module })).step); @@ -264,7 +268,12 @@ pub fn build(b: *Build) void { test_web.dependOn(&render_web.step); // `Host.textSize` against the text drawn (test/text.zig). const text = sb.app(.{ .name = "text", .root_source_file = b.path("test/text.zig") }); - test_step.dependOn(&text.addScript(text.addExecutable(), b.path("test/text.script"), .{}).step); + const text_script = text.addScript(text.addExecutable(), b.path("test/text.script"), .{}); + test_step.dependOn(&text_script.step); + const test_text = b.step("test-text", "Test text: layout (sketch.text), the atlas's rasters against pardes's, and test/text.script"); + test_text.dependOn(&text_script.step); + test_text.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = sketch_tests, .filters = &.{"paragraph"} })).step); + test_text.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = host, .filters = &.{"pardes's"} })).step); // A sound the sketch made, as a voice: once per serial, not again on a // replay (test/voices.zig). const voices = sb.app(.{ .name = "voices", .root_source_file = b.path("test/voices.zig") }); @@ -831,6 +840,7 @@ pub fn init(b: *Build, options: Options) Sketchbook { .optimize = options.optimize, .modules = .{ .abi = dep.module("abi"), .sketch = dep.module("sketch"), .host = dep.module("host"), .tracy = dep.module("tracy"), .vector = dep.module("vector"), .scope = dep.module("scope"), .anim = dep.module("anim"), .gltf = dep.module("gltf"), .cloud9 = dep.module("cloud9") }, .host_exe = dep.artifact("sketchbook"), + .text = dep.artifact("sketchbook-text"), .gltf_generator = dep.artifact("gltf-bindings"), .web = dep.path("web"), .glsl = dep.path("src/glsl.zig"), @@ -884,6 +894,9 @@ pub const Sketchbook = struct { modules: struct { abi: *Build.Module, sketch: *Build.Module, host: *Build.Module, tracy: *Build.Module, vector: *Build.Module, scope: *Build.Module, anim: *Build.Module, gltf: *Build.Module, cloud9: *Build.Module }, /// The generic host: loads and hot-reloads a sketch library. host_exe: *Build.Step.Compile, + /// FreeType, HarfBuzz and vendor/text.c: what the host measures text + /// with, linked into an app's tests (`App.addTest`) so they measure too. + text: *Build.Step.Compile, /// `host.js` and the `index.html` template. web: Build.LazyPath, /// The GLSL declaration generator (see `addGlslLayouts`). @@ -1636,6 +1649,7 @@ pub const App = struct { .imports = app.imports, }); if (options.root_source_file != null) module.addImport("app", app.module); + module.linkLibrary(app.sb.text); return b.addTest(.{ .root_module = module }); } |
