text

Neutral glyph runs and text primitives over Garnet vector paths

Garnet text

require "garnet-text" supplies neutral glyph runs, font metrics, source clusters and text primitives over garnet-vector. The shard has no native font-library, renderer, window, scene or ECS dependency.

A Font provider supplies em-normalized glyph paths (positive Y down) and metrics. A GlyphRun retains its provider, source string, em size, direction, copied glyph placements and immutable paths for its unique glyph IDs. Placements use run-local pixel coordinates relative to the baseline. Glyph source ranges are half-open UTF-8 byte ranges; invalid codepoint boundaries are rejected. Use an optional shaping adapter to create these records from text.

run = font.shape("office", 24_f32) # e.g. the HarfBuzz adapter
recorder.translate(20_f32, 50_f32) # baseline origin
recorder.draw(run.drawing(Garnet::Color::WHITE))
# Or: entity << Garnet::Graphics::Components::Drawable.new(run.primitive)

glyphs returns a copied array. advance_x / advance_y describe the shaped advance, including spacing; bounds gives ink bounds or nil for empty/space-only content. These quantities deliberately differ. Font metrics expose ascender, descender and line gap in em units, with line_height(size) as a baseline-spacing convenience.

hit_test(x, y) selects the nearest visual glyph advance and returns its entire logical Cluster range, or nil for an empty run. It does not synthesize caret positions inside ligatures. The same retained run supplies both measurement and drawing, avoiding a second shaping pass with different options.

primitive(paint) and drawing(paint) accept solid, gradient and image-pattern paints. Paint coordinates span the whole run in pixels. Glyph outlines lower to ordinary meshes, so masks, clips, scene placement, viewports, effects and group blending use the existing graphics pipeline. No font-specific renderer hooks or CPU raster images are involved. Outlines are retained per run; tessellation and GPU caching retain their existing graphics behavior.

This is the independently useful glyph-run layer. The optional paragraph layout shard adds bidi, script itemization, fallback, Unicode wrapping, line metrics, and bidirectional caret mapping without changing this core. Editable selection/IME, color/bitmap glyphs, and hinted glyph rasterization remain separate work. The HarfBuzz adapter is the first provider.

Repository

text

Owner
Statistic
  • 0
  • 0
  • 0
  • 2
  • 1
  • 1 day ago
  • November 30, 2026
License

MIT License

Links
Synced at

Wed, 02 Dec 2026 02:08:59 GMT

Languages