jovian / venusian-velvet
Lustrous, Velvet's renderer for Venusian Topside: framebuffers, rasterizers, painters, strokers, raycasters, glyphs and typography drivers, in PHP and in C through the house extensions.
Requires
- php: ~8.4.27||^8.5.12
- venusian/topside: ^0.11.5
Requires (Dev)
- pestphp/pest: ^4
Suggests
- ext-fb: lustrous-c framebuffers
- ext-paint: lustrous-c painters
- ext-rasterize: lustrous-c rasterizers, strokers and glyphs
- ext-raycast: lustrous-c raycasters
- ext-typog: lustrous-c font catalog, faces and shaper
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-17 15:11:11 UTC
README
Lustrous, Velvet's own renderer: the framebuffers, rasterizers, painters, strokers, raycasters, glyphs and typography drivers Velvet draws with on the CPU. Each part comes twice: lustrous-php, in plain PHP with no extension, and lustrous-c, in C through the house extensions. auto picks C where its extension is loaded and PHP everywhere else.
Requirements
- Linux or macOS, PHP 8.4+.
- venusian/topside 0.11, which holds Velvet (
VelvetGE\) and the contracts these drivers implement. - For
lustrous-c, by part (each optional; without it that part runs in PHP):
| Part | Extension |
|---|---|
| Framebuffers | ext-fb 0.11.1 |
| Rasterizers, strokers | ext-rasterize 0.11 |
| Glyphs | ext-rasterize with RasterSpanStore, drawing into frames in ext-fb memory |
| Painters | ext-paint 0.11 |
| Raycasters | ext-raycast 0.11 |
| Typography | ext-typog 0.11 |
ext-velvet, where installed, stands in for ext-fb, ext-rasterize and ext-paint.
Install
composer require jovian/venusian-velvet
The provider registers every driver it can run. Velvet's parts are named in config/velvet.php; Typography's and Rendering's own managers in config/typography.php and config/rendering.php:
// config/velvet.php 'cpu' => [ 'framebuffers' => ['default' => env('VELVET_FRAMEBUFFER', 'lustrous-c-full')], 'rasterizers' => ['default' => env('VELVET_RASTERIZER', 'auto')], 'painters' => ['default' => env('VELVET_PAINTER', 'auto')], 'glyphs' => ['default' => env('VELVET_GLYPHS', 'auto')], ],
Usage
Nothing changes in application code: a canvas drawn by Velvet draws with Lustrous.
use Surface\NutsAndBolts\Color; use Surface\Typography\Typography; $text = Typography::set("Hello\nworld", Typography::font('body'), width: 320); $surface->render(fn ($g) => $g->text($text, 20, 40, Color::hex('#fff')));
What is registered depends on what the PHP has loaded. With every extension:
use Jovian\Engines\Velvet\Providers\VenusianVelvetServiceProvider as Lustrous; array_keys(Lustrous::rasterizationDrivers()); // ['lustrous-php', 'lustrous-c', 'auto']
and with none (php -n), ['lustrous-php', 'auto'], where auto is the PHP driver.
A font face on its own:
use Jovian\Engines\Velvet\Lustrous\Typography\PHPLandFontFaceDriver; use Surface\Contracts\Typography\FontSource; $face = (new PHPLandFontFaceDriver())->face(new FontSource('/System/Library/Fonts/Supplemental/Arial.ttf', 0)); $face->unitsPerEm(); // 2048 $glyph = $face->glyph(0x41); // 36, 'A' $face->advance($glyph); // 1366, in font units $face->metrics(14)->ascent; // 12.673828125 $face->outline($glyph); // a Path in font units, y up
Behaviour
- Where each part registers. Framebuffers, rasterizers, painters, raycasters and glyphs register on Velvet's managers (
velvet.framebuffers,velvet.rasterizers,velvet.painters,velvet.raycasters,velvet.glyphs). Strokers register on Rendering'sstrokers, the font catalog, face and shaper on Typography'stypography.catalogs,typography.facesandtypography.shapers, and the image decoders on Images'images.decoders: those serve every engine, not Velvet alone. - Framebuffers.
lustrous-phpandlustrous-cmake a full frame. A kind by name,lustrous-php-<kind>orlustrous-c-<kind>, makes that kind:full,dirty,epaper,pagedorring. Paged and ring frames takevelvet.cpu.framebuffers.lustrous.page_rowsandframes. auto. Chooses between Lustrous's two drivers and nothing else. For glyphs it chooses per frame: glyphs kept in C for a frame in C memory, in PHP for every other frame, so neither store crosses into the other.- Typography. The PHP and C readers parse TrueType and CFF outlines, character maps, metrics,
kern, and variable fonts (fvar,avar1,gvar,HVAR,MVAR). The catalogs scantypography.directoriesandtypography.files, match a request by CSS's font-matching rules, and keep their scan instorage/framework/cache/fonts.jsonunlesstypography.cachenames a file. - Refusals. Each throws the part's exception, naming what is wrong:
- a
lustrous-cdriver made where its extension is missing or too old; - a font with CFF2 outlines,
avarversion 2, or no outlines Lustrous reads (Apple'shvgl, bitmap-only fonts). The catalogs never offer such a face; - a font whose tables are damaged or larger than their file.
- a
- Shaping. Character to glyph, advances and the
kerntable: no ligatures, noGPOSkerning, no complex scripts. Typography'sharfbuzzshaper (jovian/venusian-harfbuzz) does those. - Images. Registered on Images'
images.decoders,lustrous-cfirst where ext-imgdec can write an address, thenlustrous-php. The C decoder writes the frame's memory. The PHP decoder writes PNG and JPEG from gd and TIFF in PHP, through the frame's ownwriteRgba8(), and refuses a frame that has memory. gd keeps alpha in 7 bits (0 opaque, 127 clear) and it is widened255 − ((a << 1) + (a >> 6)). A 512×512 JPEG took 54 ms this way. - Pixels stay where the frame keeps them. A
lustrous-cpart works on C memory and hands back no pixels to PHP.
Testing
See .okf/runbooks/testing.md. The suite runs in a workbench beside venusian/topside, never in the repo root.
License
MIT. See LICENSE.