diff --git a/ROADMAP.md b/ROADMAP.md index 85924dd57..a2a335e4e 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -2,7 +2,7 @@ **Stage: alpha** · next: beta, ~26 points and ~162–292 h away (one Opus 5.5 agent; ~33–67 h wall-clock with 5 agents) -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-02 · **Change:** minor (the desktop UI takes a system face for Ethiopic, Devanagari, Gurmukhi, Gujarati, Tamil, Telugu, Kannada and Malayalam, Sinhala, Lao, Myanmar, Khmer, Armenian and Georgian as it did for Hebrew and Arabic, so a String variable's Amharic value draws in the panels instead of boxes (#2014); glass's light is a line on its bevel and splay turns the bend towards the centre; glass bends with a thick-lens profile and splits its colours over 8 steps; glass effects take variables and keep their frost within 0–100; web host bridge: `?host=parent` or `data-host="page"` hands a page the app's files, documented in the hosting guide; a connector end moved with Cmd/Ctrl held goes on any part of an object, and stays there as the object moves or resizes; a tap on a plugin panel's button keeps what was typed in its fields; a Dash cap setting (none, round or square) on Dash and Custom strokes, drawn on both ends of every dash; library analytics list how many layers and files use each style and variable; the Controller menu names each button as PlayStation and Switch controllers do; widgets draw lines and SVG pictures (plugin API 6); a connector end dropped along a side of a shape attaches to that side (#1708); regression tests pin a rounded shape's one-sided stroke and SVG ids and font families without XML-forbidden characters (#1351, #1124); a damaged image is refused with a reason instead of showing as an empty box (#1474); an image copied in another app pastes again on the desktop, and in the browser for the first time (#492); SwiftUI and Compose code names a bound variable by its iOS or Android code syntax; the colour picker's Image tab shows a placeholder and Upload from computer, an asset preview, and a file dropped on it replaces the image, keeping the fill mode, crop and position (#1682); the Frame tool's Phone presets have the iPhone 17 family (#1691); Show in folder works in the Flatpak build and selects the file on Linux (#1701); a dashed line starts and ends with a half-length dash, on the canvas and in exports; the Pages, Layers and Assets search fields keep their text in the middle of the field (#1703); a board connector's path can be reshaped by dragging its path handles (#1710); boards have 16 more shapes (arrows, polygons, star, plus and flowchart symbols), in pickers that lay them out in a grid; library analytics count insertions and show insertions and detachments over the past 30 days, 90 days or year; a stroke's Custom style takes a dash pattern of any length as a comma-separated list (#1681); a control request can set its own timeout, up to 10 minutes (`timeoutMs`; `figcraft-cli mcp --attach PORT --timeout SECONDS`) (#1696); gap 6: a widget opens its plugin's panel (plugin API 5), whose callbacks redraw it; the keyboard's Menu key opens the context menu, as Shift+F10 does; an Open link action can open in place of the prototype, with "Open in new tab" off (gap 15); a collection of this file can be extended (Extend collection on its row, `variable.extendCollection`), its extension following its edits at once, and extended collections extend again in the file; the eyedropper with Cmd/Ctrl+Shift makes a colour style or variable of what it picks; a live session's welcome sends the document compressed to clients that read it, about seven times smaller (#1665); a control request that times out says truthfully whether it was dropped or is still running and will take effect, and only screenshots and input blame the window (#1673); a board keeps earlier votes' results, listed newest first in Results and deleted one at a time; the object a stamp will stick to is outlined while the stamp tool is over it or a stamp is dragged over it, and board objects take no drops (gap 24); a server can list the files shared from it now for everyone who reaches it, Home ▸ Online shows them and their links carry no secret (`team_files`, part of #742); team library analytics count detached instances per component and file (gap 10); skipping the Open link notice by command is saved with the preferences at once (gap 15); a selected connector's bar on a board sets its start and end points, solid or dashed, its weight and any colour (#1596); cells copied from a spreadsheet paste onto a board as a table; a long layer name stays on one line in the Export button and the Dev Mode header, ending with an ellipsis, and no longer covers the Design panel (#1650); with hundreds of layers selected, the Design panel and the selection overlays stop going over the whole selection on every frame, so dragging 648 layers averages about 1.1 ms of UI per frame (#1571); plugin panels show pictures: an `image` control, base64 within 256 KB and 4,096 px a side, named by its label (gap 6); `.fig` connector labels without a saved snapshot are kept, centred on their line (gap 1); a drag moving many layers re-runs only what sits around them, not each layer's bindings, sizing, text and instance checks, on every move (#1571); damaged font tracking table offsets are checked instead of wrapping on 32-bit targets, and font indexing makes its existing offset bounds explicit (#1125); Bosnian (`bs`) draft catalog; text style dedupe is O(spans) via a last-two cache and fingerprint buckets (#1102); pasted layers whose image the clipboard lacks are named and show a placeholder that reads as missing (#1646); paint-style colours on layers pasted from another design app keep their style instead of turning black (#1638); progress docs cleaned of what merges left twice: rows merged into one, repeated status items removed, and `cargo xtask docs` (in `ci`) fails on a repeated table row or status item; a name typed for a variable or collection finds the one with that exact id before one named like it, and stored mode ids, font family variables and the panels' labels read exact ids (#1613); plugin widgets have hover styles: a layer's `hover` fill, stroke, opacity or text colour shows while the pointer is over it (gap 6); `.fig` elbowed and curved connectors without a saved path are routed like board connectors instead of drawn straight (gap 1); every file a command reads whole by path is a regular file within a cap that fits it: documents 16 GiB, placed images 256 MiB, CLI scripts 1 GiB; `figcraft-cli connect publish` publishes a code repository's code connect mappings to a design file (gap 16); while a drag only moves a large selection, its outlines, box, slots, spacing and Design panel values are worked out once and shifted, not rebuilt on every move (#1571); Shift+Cmd/Ctrl+Enter on a selected board shape adds the next shape already joined to it, and goes on typing (#1597); an imported or pasted file finds an installed family under the other names its fonts give it, and with other case and spacing, instead of reporting it missing (#1292); a development example generates figcraft-cli's shell completions and man pages from its clap definitions (part of #1396); `.fig` ZIP image reads share a total byte budget and count skipped images in the import warnings (#1076); German terminology corrections (M10): gradient stops, OpenType stylistic sets and the Home-screen preference; a component set's property rows fit the 240 px right panel: variant values wrap two to a line there and every + and − stays in view; the server key is checked by comparing SHA-256 hashes of the presented and the kept key, as the deployment guide says (#1130); opening a file contacts no team library server it names until you check it (#1097); a hostile server can no longer grow a client's memory with made-up people, and a session remembers a bounded number of deleted layer ids (#1121); `doc.list` gives AI agents and plugins the open files' names, not their paths (#1117); with a large selection, frames where nothing changed reuse the selection's outlines, box and slots and the Design panel's instance and position values instead of working them out again (#1571); team libraries and plugins larger than the 16 MiB download burst can be downloaded again, more slowly (#1089); a batch keeps one undo snapshot, not one per step (#1099); files nested 256 levels deep import on the browser's 1 MB stack (#1101); SVG and PDF exports count pattern sources and the renders they embed from the layer's depth, so one cap bounds a whole export (#1082); an explicit variables file path (`variable.import`, the `variables` of `file.open` and `file.import`) is refused past 256 MiB or when it isn't a regular file, as the sibling `variables.json` already was (part of #1114); joining and leaving a file nobody is editing reads and writes nothing on the server: it stays loaded a minute after everyone leaves (#1074); opening a `.figcraft` file unpacks at most 6 GiB in all (2 GiB in the browser), every area together (#1079); hovering the canvas hit-tests once per pointer move, not on every frame, and moving an auto layout frame no longer lays out its contents again on every move (#1571); `.fig` instance expansion no longer walks variable nodes for every instance or copies every outer override row into each nested instance (#1077); `comment.people` lists names that were only @mentioned, and `comment.next` and `comment.prompt` carry the mentions too (#1415); grid auto-placement looks for free cells a 64-bit word at a time and skips what blocks it, with the same placements (#1083); with the pen out, Enter or a double-click ends the path and edits the vector with the Move tool instead of drawing on (#1430); a recovery copy made while a version is previewed holds the file, not the version shown; a FigJam `.jam` file opens as a board (#1342); the Actions palette offers only commands that run from it, and no second row reading like a menu item: Place image opens the file dialog (#1574); share links can comment: a third access level beside edit and view, whose holder sees the file live and adds, replies to, reacts to and resolves comments but can't change the design; Preferences ▸ Scroll wheel zoom: a mouse wheel zooms the canvas about the pointer and Cmd/Ctrl+wheel scrolls (#1390); `comment.list {mentions}` lists only the threads that @mention a name (#1415); in the browser an internal error that stops the page keeps its unsaved files, which open again on reload (#1123); boolean operations refuse input past their caps, and a boolean group past them draws without its result (#1104); figcraft-cli parses its arguments with clap, following RFC-0012 (#1396); the selection and hover outlines of rounded rectangles and frames follow their corners (#1506); component properties keep the order they were made in when one is renamed, and Make slot asks for the slot's name first (#1536, #1537); the browser build publishes files to a server, so Share ▸ Online and Publish to server work there (#917); the browser build uses the fonts installed on the computer once asked, each read when text uses it (#1051); SVG import reads `color()` and `color-mix()` colours, with a note and a grey for those it can't (#1550); the portable Windows zip keeps its settings, recovery copies and plugins in `config\` beside the executable, starting with an installed copy's preferences; the window starts on other graphics when its first ones fail before the first frame: Direct3D 12 compiles with FXC and no device compiles wgpu's indirect-validation shaders, then Vulkan, OpenGL and lower requirements on the power-saving GPU (#965, #1438); Thai, Lao, Khmer and Burmese lines break between words (#1219); an AI agent attached over MCP shows where it works (#1416); a manual overlay's position can be dragged on the canvas (#405); one name for live sessions and comments: Preferences ▸ Your name, in the Join dialog too, kept in the browser, and a rename shows at once in the sessions you are in (#1380); requests that change a server's files have a budget per address, the server key's too, and join codes are found by their hash (#1075); the Join dialog shows a join from the click until its file is ready, with Cancel, and a failed join with Try again (#1381); SVG import draws each pattern tile once per scale, within the layer budget (#1080); Vietnamese letters typed with combining marks (decomposed) take one font that has every mark, instead of missing-glyph boxes beside the letter (#1478); comment.list reports each message's @mentions (#1415); mask groups draw only over the area they can paint, and nested isolated layers share one memory budget (#1061); components can't contain their own instances, directly or through other components; `edit.duplicate` returns an id map with `map: true` (#995); the batches kept for reconnecting apps are bounded in bytes by default, and `figcraft-server` takes `max_log_mb` (#1069); MCP and control calls name their document (#998); sibling placement in live sessions searches instead of counting (#1065); an AI agent attached over MCP comments under its own name, with an Agent label (#1414); the instance-swap menus have a search field (#1338); a refused batch's fixes take time linear in the batch (#1063); the connector tool shows the connector it will make while dragging, ends snapping to attach points (#1387); large images on the canvas draw from a smaller copy, so two 16k images no longer lag (#1483); a file's JPEG thumbnail can't crash the home screen (#1491's progressive JPEG check, now shared); `.fig` import: library text styles linked by asset key, and override rows restating a nested level (#1234); `.fig` import keeps the file's saved line breaks while the text and its box are unedited (#1236); Download a missing free font from the Missing fonts window (`font.download`, #754); the web build's wasm back under its 24 MiB gate (#1472); shadows of images with transparent pixels follow their alpha (#1289); Crop image: Object ▸ Crop image, the right-click menu and the image fill row enter crop mode (`image.crop`, #1464); offline Penpot 2.x import/export (#1143); optional batch continue-on-error with per-step outcomes (#1386); the Design panel's sections on one grid (#858); FigJam outer shape outlines and sticky body fallback beside author text (#1341, #1397); images placed at their own size, 2x screenshots in points (#1360); the toolbar on one 32 pt grid, without its Resources button (#1210); M4: zero-length round-capped dashes draw dots; dash expansion uses the existing safety budget; extracted from #1143; Arabic draft catalog; scaled instances keep their scale when their main is rebuilt (#922); .fig embedded images are copied once per blob, not once per hash (#1059); page ruler guides survive save and reopen (#1476); colour picker LCH and OKLCH models; non-ASCII layer names transliterate in code export (#1235); branches in live sessions and branch history entries, gap 17; plugin widgets take text input and a property menu (plugin API 4); boards: templates and tables; boards: a shared timer and voting sessions; boards: the dot grid, connector ends dragged to re-attach, curved connectors; Installed weights of an embedded font family (#1246); `.sketch` import, best effort (Sketch 48 and newer); CJK line breaking: JIS X 4051's line-start and line-end sets completed with the halfwidth small kana, the halfwidth and spacing (semi-)voiced sound marks, the iteration marks 〱–〵 and the halfwidth parentheses, with behaviour cases for each; Adobe Fonts found on macOS (#298); egui 0.37 hidden-capture deadline contract; Dev Mode measurements kept on the canvas and a read-only layers panel; boards: a board area row and progress entry; community fixes in #507, #510, #529 and #530: auto-save, a text box by dragging, batch step references, removing someone from a live session, Russian and Turkish catalogs reviewed, Czech and Indonesian drafts, the Japanese draft completed, zoom previews, the web clipboard, Alt-drag snapping and Cmd+D repeat, recovery copies, crash and rollback fixes, colour emoji, `.fig` import fixes; earlier changes are in the revision history below) · **Target:** Figma Design (desktop app 126.10.7) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-02 · **Change:** minor (the desktop UI takes a system face for Ethiopic, Devanagari, Gurmukhi, Gujarati, Tamil, Telugu, Kannada and Malayalam, Sinhala, Lao, Myanmar, Khmer, Armenian and Georgian as it did for Hebrew and Arabic, so a String variable's Amharic value draws in the panels instead of boxes (#2014); glass bends towards its core, and rounded rectangles work it out in closed form; glass's light is a line on its bevel and splay turns the bend towards the centre; glass bends with a thick-lens profile and splits its colours over 8 steps; glass effects take variables and keep their frost within 0–100; web host bridge: `?host=parent` or `data-host="page"` hands a page the app's files, documented in the hosting guide; a connector end moved with Cmd/Ctrl held goes on any part of an object, and stays there as the object moves or resizes; a tap on a plugin panel's button keeps what was typed in its fields; a Dash cap setting (none, round or square) on Dash and Custom strokes, drawn on both ends of every dash; library analytics list how many layers and files use each style and variable; the Controller menu names each button as PlayStation and Switch controllers do; widgets draw lines and SVG pictures (plugin API 6); a connector end dropped along a side of a shape attaches to that side (#1708); regression tests pin a rounded shape's one-sided stroke and SVG ids and font families without XML-forbidden characters (#1351, #1124); a damaged image is refused with a reason instead of showing as an empty box (#1474); an image copied in another app pastes again on the desktop, and in the browser for the first time (#492); SwiftUI and Compose code names a bound variable by its iOS or Android code syntax; the colour picker's Image tab shows a placeholder and Upload from computer, an asset preview, and a file dropped on it replaces the image, keeping the fill mode, crop and position (#1682); the Frame tool's Phone presets have the iPhone 17 family (#1691); Show in folder works in the Flatpak build and selects the file on Linux (#1701); a dashed line starts and ends with a half-length dash, on the canvas and in exports; the Pages, Layers and Assets search fields keep their text in the middle of the field (#1703); a board connector's path can be reshaped by dragging its path handles (#1710); boards have 16 more shapes (arrows, polygons, star, plus and flowchart symbols), in pickers that lay them out in a grid; library analytics count insertions and show insertions and detachments over the past 30 days, 90 days or year; a stroke's Custom style takes a dash pattern of any length as a comma-separated list (#1681); a control request can set its own timeout, up to 10 minutes (`timeoutMs`; `figcraft-cli mcp --attach PORT --timeout SECONDS`) (#1696); gap 6: a widget opens its plugin's panel (plugin API 5), whose callbacks redraw it; the keyboard's Menu key opens the context menu, as Shift+F10 does; an Open link action can open in place of the prototype, with "Open in new tab" off (gap 15); a collection of this file can be extended (Extend collection on its row, `variable.extendCollection`), its extension following its edits at once, and extended collections extend again in the file; the eyedropper with Cmd/Ctrl+Shift makes a colour style or variable of what it picks; a live session's welcome sends the document compressed to clients that read it, about seven times smaller (#1665); a control request that times out says truthfully whether it was dropped or is still running and will take effect, and only screenshots and input blame the window (#1673); a board keeps earlier votes' results, listed newest first in Results and deleted one at a time; the object a stamp will stick to is outlined while the stamp tool is over it or a stamp is dragged over it, and board objects take no drops (gap 24); a server can list the files shared from it now for everyone who reaches it, Home ▸ Online shows them and their links carry no secret (`team_files`, part of #742); team library analytics count detached instances per component and file (gap 10); skipping the Open link notice by command is saved with the preferences at once (gap 15); a selected connector's bar on a board sets its start and end points, solid or dashed, its weight and any colour (#1596); cells copied from a spreadsheet paste onto a board as a table; a long layer name stays on one line in the Export button and the Dev Mode header, ending with an ellipsis, and no longer covers the Design panel (#1650); with hundreds of layers selected, the Design panel and the selection overlays stop going over the whole selection on every frame, so dragging 648 layers averages about 1.1 ms of UI per frame (#1571); plugin panels show pictures: an `image` control, base64 within 256 KB and 4,096 px a side, named by its label (gap 6); `.fig` connector labels without a saved snapshot are kept, centred on their line (gap 1); a drag moving many layers re-runs only what sits around them, not each layer's bindings, sizing, text and instance checks, on every move (#1571); damaged font tracking table offsets are checked instead of wrapping on 32-bit targets, and font indexing makes its existing offset bounds explicit (#1125); Bosnian (`bs`) draft catalog; text style dedupe is O(spans) via a last-two cache and fingerprint buckets (#1102); pasted layers whose image the clipboard lacks are named and show a placeholder that reads as missing (#1646); paint-style colours on layers pasted from another design app keep their style instead of turning black (#1638); progress docs cleaned of what merges left twice: rows merged into one, repeated status items removed, and `cargo xtask docs` (in `ci`) fails on a repeated table row or status item; a name typed for a variable or collection finds the one with that exact id before one named like it, and stored mode ids, font family variables and the panels' labels read exact ids (#1613); plugin widgets have hover styles: a layer's `hover` fill, stroke, opacity or text colour shows while the pointer is over it (gap 6); `.fig` elbowed and curved connectors without a saved path are routed like board connectors instead of drawn straight (gap 1); every file a command reads whole by path is a regular file within a cap that fits it: documents 16 GiB, placed images 256 MiB, CLI scripts 1 GiB; `figcraft-cli connect publish` publishes a code repository's code connect mappings to a design file (gap 16); while a drag only moves a large selection, its outlines, box, slots, spacing and Design panel values are worked out once and shifted, not rebuilt on every move (#1571); Shift+Cmd/Ctrl+Enter on a selected board shape adds the next shape already joined to it, and goes on typing (#1597); an imported or pasted file finds an installed family under the other names its fonts give it, and with other case and spacing, instead of reporting it missing (#1292); a development example generates figcraft-cli's shell completions and man pages from its clap definitions (part of #1396); `.fig` ZIP image reads share a total byte budget and count skipped images in the import warnings (#1076); German terminology corrections (M10): gradient stops, OpenType stylistic sets and the Home-screen preference; a component set's property rows fit the 240 px right panel: variant values wrap two to a line there and every + and − stays in view; the server key is checked by comparing SHA-256 hashes of the presented and the kept key, as the deployment guide says (#1130); opening a file contacts no team library server it names until you check it (#1097); a hostile server can no longer grow a client's memory with made-up people, and a session remembers a bounded number of deleted layer ids (#1121); `doc.list` gives AI agents and plugins the open files' names, not their paths (#1117); with a large selection, frames where nothing changed reuse the selection's outlines, box and slots and the Design panel's instance and position values instead of working them out again (#1571); team libraries and plugins larger than the 16 MiB download burst can be downloaded again, more slowly (#1089); a batch keeps one undo snapshot, not one per step (#1099); files nested 256 levels deep import on the browser's 1 MB stack (#1101); SVG and PDF exports count pattern sources and the renders they embed from the layer's depth, so one cap bounds a whole export (#1082); an explicit variables file path (`variable.import`, the `variables` of `file.open` and `file.import`) is refused past 256 MiB or when it isn't a regular file, as the sibling `variables.json` already was (part of #1114); joining and leaving a file nobody is editing reads and writes nothing on the server: it stays loaded a minute after everyone leaves (#1074); opening a `.figcraft` file unpacks at most 6 GiB in all (2 GiB in the browser), every area together (#1079); hovering the canvas hit-tests once per pointer move, not on every frame, and moving an auto layout frame no longer lays out its contents again on every move (#1571); `.fig` instance expansion no longer walks variable nodes for every instance or copies every outer override row into each nested instance (#1077); `comment.people` lists names that were only @mentioned, and `comment.next` and `comment.prompt` carry the mentions too (#1415); grid auto-placement looks for free cells a 64-bit word at a time and skips what blocks it, with the same placements (#1083); with the pen out, Enter or a double-click ends the path and edits the vector with the Move tool instead of drawing on (#1430); a recovery copy made while a version is previewed holds the file, not the version shown; a FigJam `.jam` file opens as a board (#1342); the Actions palette offers only commands that run from it, and no second row reading like a menu item: Place image opens the file dialog (#1574); share links can comment: a third access level beside edit and view, whose holder sees the file live and adds, replies to, reacts to and resolves comments but can't change the design; Preferences ▸ Scroll wheel zoom: a mouse wheel zooms the canvas about the pointer and Cmd/Ctrl+wheel scrolls (#1390); `comment.list {mentions}` lists only the threads that @mention a name (#1415); in the browser an internal error that stops the page keeps its unsaved files, which open again on reload (#1123); boolean operations refuse input past their caps, and a boolean group past them draws without its result (#1104); figcraft-cli parses its arguments with clap, following RFC-0012 (#1396); the selection and hover outlines of rounded rectangles and frames follow their corners (#1506); component properties keep the order they were made in when one is renamed, and Make slot asks for the slot's name first (#1536, #1537); the browser build publishes files to a server, so Share ▸ Online and Publish to server work there (#917); the browser build uses the fonts installed on the computer once asked, each read when text uses it (#1051); SVG import reads `color()` and `color-mix()` colours, with a note and a grey for those it can't (#1550); the portable Windows zip keeps its settings, recovery copies and plugins in `config\` beside the executable, starting with an installed copy's preferences; the window starts on other graphics when its first ones fail before the first frame: Direct3D 12 compiles with FXC and no device compiles wgpu's indirect-validation shaders, then Vulkan, OpenGL and lower requirements on the power-saving GPU (#965, #1438); Thai, Lao, Khmer and Burmese lines break between words (#1219); an AI agent attached over MCP shows where it works (#1416); a manual overlay's position can be dragged on the canvas (#405); one name for live sessions and comments: Preferences ▸ Your name, in the Join dialog too, kept in the browser, and a rename shows at once in the sessions you are in (#1380); requests that change a server's files have a budget per address, the server key's too, and join codes are found by their hash (#1075); the Join dialog shows a join from the click until its file is ready, with Cancel, and a failed join with Try again (#1381); SVG import draws each pattern tile once per scale, within the layer budget (#1080); Vietnamese letters typed with combining marks (decomposed) take one font that has every mark, instead of missing-glyph boxes beside the letter (#1478); comment.list reports each message's @mentions (#1415); mask groups draw only over the area they can paint, and nested isolated layers share one memory budget (#1061); components can't contain their own instances, directly or through other components; `edit.duplicate` returns an id map with `map: true` (#995); the batches kept for reconnecting apps are bounded in bytes by default, and `figcraft-server` takes `max_log_mb` (#1069); MCP and control calls name their document (#998); sibling placement in live sessions searches instead of counting (#1065); an AI agent attached over MCP comments under its own name, with an Agent label (#1414); the instance-swap menus have a search field (#1338); a refused batch's fixes take time linear in the batch (#1063); the connector tool shows the connector it will make while dragging, ends snapping to attach points (#1387); large images on the canvas draw from a smaller copy, so two 16k images no longer lag (#1483); a file's JPEG thumbnail can't crash the home screen (#1491's progressive JPEG check, now shared); `.fig` import: library text styles linked by asset key, and override rows restating a nested level (#1234); `.fig` import keeps the file's saved line breaks while the text and its box are unedited (#1236); Download a missing free font from the Missing fonts window (`font.download`, #754); the web build's wasm back under its 24 MiB gate (#1472); shadows of images with transparent pixels follow their alpha (#1289); Crop image: Object ▸ Crop image, the right-click menu and the image fill row enter crop mode (`image.crop`, #1464); offline Penpot 2.x import/export (#1143); optional batch continue-on-error with per-step outcomes (#1386); the Design panel's sections on one grid (#858); FigJam outer shape outlines and sticky body fallback beside author text (#1341, #1397); images placed at their own size, 2x screenshots in points (#1360); the toolbar on one 32 pt grid, without its Resources button (#1210); M4: zero-length round-capped dashes draw dots; dash expansion uses the existing safety budget; extracted from #1143; Arabic draft catalog; scaled instances keep their scale when their main is rebuilt (#922); .fig embedded images are copied once per blob, not once per hash (#1059); page ruler guides survive save and reopen (#1476); colour picker LCH and OKLCH models; non-ASCII layer names transliterate in code export (#1235); branches in live sessions and branch history entries, gap 17; plugin widgets take text input and a property menu (plugin API 4); boards: templates and tables; boards: a shared timer and voting sessions; boards: the dot grid, connector ends dragged to re-attach, curved connectors; Installed weights of an embedded font family (#1246); `.sketch` import, best effort (Sketch 48 and newer); CJK line breaking: JIS X 4051's line-start and line-end sets completed with the halfwidth small kana, the halfwidth and spacing (semi-)voiced sound marks, the iteration marks 〱–〵 and the halfwidth parentheses, with behaviour cases for each; Adobe Fonts found on macOS (#298); egui 0.37 hidden-capture deadline contract; Dev Mode measurements kept on the canvas and a read-only layers panel; boards: a board area row and progress entry; community fixes in #507, #510, #529 and #530: auto-save, a text box by dragging, batch step references, removing someone from a live session, Russian and Turkish catalogs reviewed, Czech and Indonesian drafts, the Japanese draft completed, zoom previews, the web clipboard, Alt-drag snapping and Cmd+D repeat, recovery copies, crash and rollback fixes, colour emoji, `.fig` import fixes; earlier changes are in the revision history below) · **Target:** Figma Design (desktop app 126.10.7) FigCraft is a clean-room, open-source, pure-Rust reimplementation of the Figma design workflow, native on macOS, Windows, Linux and FreeBSD and in the browser, fully drivable by agents through @@ -359,6 +359,8 @@ Ranked; detail and milestones in [`docs/roadmap.md`](docs/roadmap.md). | Date | Change | Summary | |---|---|---| +| 2026-11-02 | patch | M8, #1885: a glass whose shape is too big to keep whole at the zoom (past `MAX_SHAPE_PX` with its core's margin) bends along its edge normals instead of working out a core, so its fields never cover more pixels than a kept shape's, and the core's feature transform holds 16 bytes a pixel. The edge normals are box-blurred twice again and the bend directions once, as documented. Test: `glass::tests::a_shape_too_big_to_keep_bends_along_its_normals`. Numbers unchanged | +| 2026-11-02 | minor | M3, #1885: glass bends the backdrop towards its core, the shape shrunk by `depth` and the bevel, as the reference tool's: round a sharp corner the bend turns smoothly instead of meeting along the diagonal, and a part thinner than twice that (a capsule, a letter's stroke) bends across itself towards its own middle (pixels about as deep as any within 2 px). Rectangles, frames, components, instances and sections whose corners aren't smoothed work their glass out in closed form, with nothing to rasterise, transform or keep: a zoom frame draws in 40 ms instead of 54 and a resize frame in 46 instead of 67 (`glass_render_timings`, release, 2×). Other shapes keep their fields, with the bend directions for the last two depths asked for beside them, so dragging the Depth slider works out only those again. Tests: `glass::tests::a_sharp_corner_bends_round_towards_the_core`, `glass::tests::a_thin_part_bends_across_itself`, `glass::tests::neighbouring_strokes_bend_towards_their_own_middles`, `glass::tests::a_rounded_rectangle_in_closed_form_matches_its_distance_transform`, `glass_cut_tests::what_the_shape_depends_on_works_it_out_again_and_nothing_else_does`. Numbers unchanged | | 2026-11-02 | minor | M3, #1885: glass's light is a line on its 1-unit bevel added to the backdrop, as the reference tool's: fully where the edge faces the light, none below 0.35 of facing it and 0.6 as much on the opposite side, with a faint gradient across the curve, 5% darker facing the light and lighter opposite (it was a glow mixed towards white, as deep as `splay` made it). `splay` turns the bend from along the edge's normal towards the way away from the layer's centre, as the reference tool's does, and no longer widens the light: files with a splay above 0 look different. The direction to the centre is worked out in the shape's own frame, so cut renders match. Tests: `glass::tests::the_light_lies_on_the_bevel_and_the_gradient_across_the_curve`, `backdrop_tests::splay_turns_the_bend_towards_the_centre`, `glass_cut_tests::the_light_is_a_line_on_the_bevel`. Numbers unchanged | | 2026-11-02 | minor | M3, #1885: glass bends the backdrop with the reference tool's thick-lens profile: most a 1-unit bevel in from the edge, falling off as the 3.5th power of the way out of the curve to nothing `depth` further in, and a fifth as much on the bevel itself (it fell off as the square of the way in from the very edge). Dispersion splits the channels over 8 steps with a triangular window, red moving furthest and blue least, as far apart as the reference tool's (at 100% red and blue move 0.16 of the bend apart; it was three samples, blue furthest), and `Glass::max_bend` bounds red's furthest step, so the backdrop read around a pane covers every sample. Tests: `glass::tests::the_bend_follows_the_thick_lens_profile`, `glass::tests::dispersion_splits_the_channels_along_the_bend`. Numbers unchanged | | 2026-11-02 | minor | M3, #1885: glass effects take variables (light angle, intensity, refraction, depth, dispersion, frost and splay, on layers and in effect styles, and from the Design panel's glass fields), and a glass's frost stays within 0–100, the reference tool's range: a larger frost from an older file draws at 100, and the field, a bound variable and scaling stop there. Numbers unchanged | diff --git a/crates/doc/src/props.rs b/crates/doc/src/props.rs index 75dca8913..11c3c16a4 100644 --- a/crates/doc/src/props.rs +++ b/crates/doc/src/props.rs @@ -662,8 +662,8 @@ pub struct Glass { pub dispersion: f64, /// Blur of the backdrop (a blur radius, document units, 0–[`Self::MAX_FROST`]). pub frost: f64, - /// Which way the curved edge bends the backdrop: along the edge's normal (0) to away from the - /// layer's centre (1). + /// Which way the curved edge bends the backdrop: towards the shape's core (0; along the edge's + /// normal for a shape too big to work one out) to away from the layer's centre (1). pub splay: f64, } diff --git a/crates/render/src/backdrop.rs b/crates/render/src/backdrop.rs index 031046c18..97aec946b 100644 --- a/crates/render/src/backdrop.rs +++ b/crates/render/src/backdrop.rs @@ -160,7 +160,7 @@ pub fn effects(n: &Node, frame: EffectFrame<'_>) -> Option { fx::mask_by(&mut l, cov.as_ref()?, false); l } - EffectKind::Glass(g) => glass::glass(g, frame)?, + EffectKind::Glass(g) => glass::glass(g, frame, glass::RoundedRect::of(n))?, _ => continue, }; match out.as_mut() { diff --git a/crates/render/src/glass.rs b/crates/render/src/glass.rs index 0ccbf2c2f..f84aad971 100644 --- a/crates/render/src/glass.rs +++ b/crates/render/src/glass.rs @@ -16,15 +16,17 @@ //! later render asks for the same shape at the same zoom they are worked out for the whole shape, //! in its own pixel frame, and kept in a cache of at most [`MAX_CACHED_BYTES`]: moving or editing //! what lies under the glass, dragging its sliders, panning and patching the canvas reuse them. -//! Zooming doesn't (each zoom is new). +//! Zooming doesn't (each zoom is new). The bend directions towards the core depend on the depth +//! too: they are kept beside them for the last two depths asked for, so dragging the Depth slider +//! works out only those again. use std::collections::HashMap; use std::hash::{DefaultHasher, Hash, Hasher}; use std::sync::{Arc, Mutex, OnceLock}; -use figcraft_doc::Glass; -use figcraft_geom::Affine; +use figcraft_doc::{Glass, Node, NodeKind}; use figcraft_geom::kurbo::Shape as _; +use figcraft_geom::{Affine, Point}; use tiny_skia::Pixmap; use crate::backdrop::EffectFrame; @@ -33,8 +35,9 @@ use crate::shadow::{Outline, spread_alpha}; /// Squared distance transform of one row or column (Felzenszwalb & Huttenlocher): `f` holds 0 at /// sources and a large value elsewhere; `d` gets each sample's squared distance to the nearest -/// source. `v` and `z` are scratch space (`f.len()` and `f.len() + 1` long). -fn edt_1d(f: &[f64], d: &mut [f64], v: &mut [usize], z: &mut [f64]) { +/// source, and `src`, when given, that source's index. `v` and `z` are scratch space (`f.len()` and +/// `f.len() + 1` long). +fn edt_1d(f: &[f64], d: &mut [f64], v: &mut [usize], z: &mut [f64], mut src: Option<&mut [usize]>) { let n = f.len(); // Every index below stays under these lengths (k <= q < n), checked once here. if n == 0 || d.len() < n || v.len() < n || z.len() < n + 1 { @@ -75,6 +78,9 @@ fn edt_1d(f: &[f64], d: &mut [f64], v: &mut [usize], z: &mut [f64]) { } let dv = qf - v[k] as f64; d[q] = dv * dv + f[v[k]]; + if let Some(o) = src.as_deref_mut().and_then(|s| s.get_mut(q)) { + *o = v[k]; + } } } @@ -92,7 +98,7 @@ pub fn inside_distance(cov: &Pixmap) -> Vec { *fy = *gv; } } - edt_1d(f.get(..h).unwrap_or(&[]), d.get_mut(..h).unwrap_or(&mut []), &mut v, &mut z); + edt_1d(f.get(..h).unwrap_or(&[]), d.get_mut(..h).unwrap_or(&mut []), &mut v, &mut z, None); for y in 0..h { if let (Some(gv), Some(dy)) = (g.get_mut(y * w + x), d.get(y)) { *gv = *dy; @@ -104,7 +110,7 @@ pub fn inside_distance(cov: &Pixmap) -> Vec { if let (Some(src), Some(dst)) = (g.get(row..row + w), f.get_mut(..w)) { dst.copy_from_slice(src); } - edt_1d(f.get(..w).unwrap_or(&[]), d.get_mut(..w).unwrap_or(&mut []), &mut v, &mut z); + edt_1d(f.get(..w).unwrap_or(&[]), d.get_mut(..w).unwrap_or(&mut []), &mut v, &mut z, None); if let (Some(dst), Some(src)) = (g.get_mut(row..row + w), d.get(..w)) { dst.copy_from_slice(src); } @@ -113,6 +119,133 @@ pub fn inside_distance(cov: &Pixmap) -> Vec { g.iter().map(|s| if *s > 0.0 { (s.sqrt() - 0.5).max(0.0) as f32 } else { 0.0 }).collect() } +/// [`nearest_sites`]' answer for a pixel with no site. +const NO_SITE: u32 = u32::MAX; + +/// For each pixel of a `w` × `h` grid, the nearest pixel (centre to centre) where `site` is true, as +/// its index, or [`NO_SITE`] when there is none: the exact Euclidean feature transform (the distance +/// transform above, keeping where each distance comes from). 16 bytes a pixel at most. +fn nearest_sites(site: &[bool], w: usize, h: usize) -> Vec { + const FAR: f64 = 1e20; + let n = w.max(h); + let (mut f, mut d, mut v, mut z, mut src) = (vec![0f64; n], vec![0f64; n], vec![0usize; n], vec![0f64; n + 1], vec![0usize; n]); + // Down each column: the squared distance to its nearest site, and that site's row. + let (mut col_d, mut col_row) = (vec![FAR; w * h], vec![NO_SITE; w * h]); + for x in 0..w { + for y in 0..h { + if let Some(fy) = f.get_mut(y) { + *fy = if site.get(y * w + x).copied().unwrap_or(false) { 0.0 } else { FAR }; + } + } + edt_1d(f.get(..h).unwrap_or(&[]), d.get_mut(..h).unwrap_or(&mut []), &mut v, &mut z, src.get_mut(..h)); + for y in 0..h { + if let (Some(cd), Some(cr), Some(dy), Some(sy)) = (col_d.get_mut(y * w + x), col_row.get_mut(y * w + x), d.get(y), src.get(y)) { + (*cd, *cr) = (*dy, u32::try_from(*sy).unwrap_or(NO_SITE)); + } + } + } + // Along each row: the nearest of those, by the column it is in. + let mut out = vec![NO_SITE; w * h]; + for y in 0..h { + let row = y * w; + if let (Some(dst), Some(from)) = (f.get_mut(..w), col_d.get(row..row + w)) { + dst.copy_from_slice(from); + } + edt_1d(f.get(..w).unwrap_or(&[]), d.get_mut(..w).unwrap_or(&mut []), &mut v, &mut z, src.get_mut(..w)); + for x in 0..w { + if let (Some(dx), Some(sx)) = (d.get(x), src.get(x)) + && *dx < FAR / 2.0 + && let (Some(o), Some(&sy)) = (out.get_mut(row + x), col_row.get(row + *sx)) + && sy != NO_SITE + { + *o = u32::try_from(sy as usize * w + sx).unwrap_or(NO_SITE); + } + } + } + out +} + +/// The largest of `src` (`w` × `h`) within `r` pixels across and down of each pixel (a square +/// window): running maxima along the rows, then the columns. +fn max_within(src: &[f32], w: usize, h: usize, r: usize) -> Vec { + let (mut rows, mut out) = (vec![0f32; w * h], vec![0f32; w * h]); + max_pass(src, &mut rows, w, h, r, true); + max_pass(&rows, &mut out, w, h, r, false); + out +} + +/// One pass of [`max_within`] along rows (`rows`) or columns: a queue holds the window's candidates +/// for its largest, falling from the front, so each value enters and leaves it once. +fn max_pass(src: &[f32], dst: &mut [f32], w: usize, h: usize, r: usize, rows: bool) { + let (lines, len, step, across) = if rows { (h, w, 1, w) } else { (w, h, w, 1) }; + let mut queue = std::collections::VecDeque::new(); + for l in 0..lines { + let base = l * across; + let at = |i: usize| src.get(base + i * step).copied().unwrap_or(0.0); + queue.clear(); + let mut next = 0; + for i in 0..len { + while next < len && next <= i + r { + let v = at(next); + while queue.back().is_some_and(|&b| at(b) <= v) { + queue.pop_back(); + } + queue.push_back(next); + next += 1; + } + while queue.front().is_some_and(|&f| f + r < i) { + queue.pop_front(); + } + if let (Some(o), Some(&f)) = (dst.get_mut(base + i * step), queue.front()) { + *o = at(f); + } + } + } +} + +/// How far around (pixels) a pixel counts as the middle of a thin part: no deeper than the pixels +/// within this many across and down, give or take [`RIDGE_SLACK`]. +const RIDGE_PX: usize = 2; + +/// How much shallower than the deepest pixel within [`RIDGE_PX`] a pixel can be and still count as +/// a thin part's middle: half a pixel per pixel, so a gently tapering stroke keeps its middle while +/// the diagonal running into a corner (depth rising by 0.7 px per pixel, more in the window) and +/// the band along an edge (1 px per pixel) do not. +const RIDGE_SLACK: f32 = 0.5 * RIDGE_PX as f32; + +/// Unit inward directions from each pixel of a shape (`dist`, its inside distance field, `w` × `h`) +/// to the nearest point of its core, which the glass bends the backdrop towards: where the shape +/// is `reach` pixels deep or more, and the middle of each part thinner than that (a capsule, a +/// letter's stroke: pixels about as deep as any within [`RIDGE_PX`]). Bending towards the core +/// rather than along the edge's normal rounds a sharp corner's bend (no seam along its diagonal) +/// and makes a thin part bend across itself, each part towards its own middle. Box-blurred once +/// over `r` pixels (the normals twice: these are smooth already, but turn round at a thin part's +/// middle); zero on the core and outside. +fn bend_directions(dist: &[f32], w: usize, h: usize, reach: f32, r: usize) -> Vec<(f32, f32)> { + // The maxima and the core are dropped before the directions are made, keeping the peak down. + let near = { + let around = max_within(dist, w, h, RIDGE_PX); + let core: Vec = dist.iter().zip(&around).map(|(d, m)| *d > 0.0 && (*d >= reach - 1e-3 || *d >= m - RIDGE_SLACK - 1e-3)).collect(); + nearest_sites(&core, w, h) + }; + let (mut gx, mut gy) = (vec![0f32; w * h], vec![0f32; w * h]); + for (i, &s) in near.iter().enumerate() { + if s != NO_SITE + && let Some(d) = dist.get(i) + && *d > 0.0 + && let (Some(a), Some(b)) = (gx.get_mut(i), gy.get_mut(i)) + { + let s = s as usize; + let (dx, dy) = ((s % w) as f32 - (i % w) as f32, (s / w) as f32 - (i / w) as f32); + let len = (dx * dx + dy * dy).sqrt(); + if len > 1e-6 { + (*a, *b) = (dx / len, dy / len); + } + } + } + smoothed_units(gx, gy, w, h, r, 1) +} + /// Running-sum box blur of a `w` × `h` field along rows (`stride` 1) or columns (`stride` `w`), /// radius `r`, zero outside. fn box_pass(src: &[f32], dst: &mut [f32], w: usize, h: usize, r: usize, rows: bool) { @@ -151,9 +284,15 @@ fn smooth_normals(dist: &[f32], w: usize, h: usize, r: usize) -> Vec<(f32, f32)> } } } + smoothed_units(gx, gy, w, h, r, 2) +} + +/// The vectors (`gx`, `gy`) of a `w` × `h` field box-blurred `times` over `r` pixels and made unit +/// length; zero where they cancel out (no direction). +fn smoothed_units(mut gx: Vec, mut gy: Vec, w: usize, h: usize, r: usize, times: usize) -> Vec<(f32, f32)> { let mut tmp = vec![0f32; w * h]; for g in [&mut gx, &mut gy] { - for _ in 0..2 { + for _ in 0..times { box_pass(g, &mut tmp, w, h, r, true); box_pass(&tmp, g, w, h, r, false); } @@ -303,9 +442,10 @@ fn sample(p: &Pixmap, x: f32, y: f32) -> [f32; 4] { }) } -/// A shape's coverage (alpha), distance to its edge and smoothed inward normals over a window of -/// pixels whose top-left pixel is (`x0`, `y0`). -struct Fields { +/// A shape's coverage (alpha), distance to its edge and smoothed inward normals (which the light +/// reads) over a window of pixels whose top-left pixel is (`x0`, `y0`): what the shape and the zoom +/// alone decide, so it is kept whatever the depth ([`whole_shape`]). +struct EdgeFields { x0: i64, y0: i64, w: usize, @@ -313,36 +453,101 @@ struct Fields { cov: Vec, dist: Vec, normals: Vec<(f32, f32)>, + /// How far the normals and the bend directions are smoothed (pixels). + r: usize, + /// The bend directions for the last [`KEPT_BENDS`] core depths asked for, by their bits, the + /// most recent last ([`EdgeFields::bends()`]). + bends: Mutex>, } -/// Bytes a field pixel holds: coverage, distance and a normal. -const FIELD_PX_BYTES: u64 = 1 + 4 + 8; +/// How many depths' bend directions a kept shape holds: two glass layers of the same shape with +/// different depths don't take turns working theirs out. +const KEPT_BENDS: usize = 2; -impl Fields { +/// Inward bend directions ([`bend_directions`]) over an [`EdgeFields`] window. +type Bends = Arc>; + +/// The fields `glass` reads: a shape's [`EdgeFields`] and its bend directions for one depth. +struct Fields { + edge: Arc, + /// `None` for a shape too big to work out a core ([`fits_whole`]): it bends along its normals. + bends: Option, +} + +/// Bytes a field pixel holds: coverage, distance, a normal and [`KEPT_BENDS`] bend directions. +const FIELD_PX_BYTES: u64 = 1 + 4 + 8 + 8 * KEPT_BENDS as u64; + +/// A pixel of [`Fields`]: coverage (0–1), distance to the edge, inward normal, inward bend direction. +type FieldPx = (f32, f32, (f32, f32), (f32, f32)); + +impl EdgeFields { /// The fields of `cov`, the shape's coverage on the window at (`x0`, `y0`), normals smoothed /// over `r` pixels. - fn new(cov: &Pixmap, x0: i64, y0: i64, r: usize) -> Fields { + fn new(cov: &Pixmap, x0: i64, y0: i64, r: usize) -> EdgeFields { FIELDS_COMPUTED.with(|n| n.set(n.get() + 1)); let dist = inside_distance(cov); let (w, h) = (cov.width() as usize, cov.height() as usize); let normals = smooth_normals(&dist, w, h, r); let cov = cov.data().chunks_exact(4).map(|p| p.get(3).copied().unwrap_or(0)).collect(); - Fields { x0, y0, w, h, cov, dist, normals } + EdgeFields { x0, y0, w, h, cov, dist, normals, r, bends: Mutex::new(Vec::new()) } } - /// Coverage (0–1), distance and inward normal at pixel (`x`, `y`); `None` outside the window. - fn at(&self, x: i64, y: i64) -> Option<(f32, f32, (f32, f32))> { - let (fx, fy) = (x.checked_sub(self.x0)?, y.checked_sub(self.y0)?); - if fx < 0 || fy < 0 || fx >= self.w as i64 || fy >= self.h as i64 { + /// The bend directions towards the core `reach` pixels in: kept from a recent render at the + /// same depth, else worked out and kept in place of the least recent (bands of one render + /// asking at once wait for the first). + fn bends(&self, reach: f32) -> Bends { + let bits = reach.to_bits(); + let mut kept = self.bends.lock().unwrap_or_else(std::sync::PoisonError::into_inner); + if let Some(i) = kept.iter().position(|(b, _)| *b == bits) { + let hit = kept.remove(i); + let bends = hit.1.clone(); + kept.push(hit); + return bends; + } + BENDS_COMPUTED.with(|n| n.set(n.get() + 1)); + let bends = Arc::new(bend_directions(&self.dist, self.w, self.h, reach, self.r)); + if kept.len() >= KEPT_BENDS { + kept.remove(0); + } + kept.push((bits, bends.clone())); + bends + } +} + +impl Fields { + /// The fields of `cov`, the shape's coverage on the window at (`x0`, `y0`), normals and bend + /// directions smoothed over `r` pixels, bending towards the core `reach` pixels in (along the + /// normals without a `reach`). + fn new(cov: &Pixmap, x0: i64, y0: i64, r: usize, reach: Option) -> Fields { + Fields::of(Arc::new(EdgeFields::new(cov, x0, y0, r)), reach) + } + + /// `edge`'s fields bending towards the core `reach` pixels in (along the normals without one). + fn of(edge: Arc, reach: Option) -> Fields { + let bends = reach.map(|reach| edge.bends(reach)); + Fields { edge, bends } + } + + /// The fields at pixel (`x`, `y`); `None` outside the window. + fn at(&self, x: i64, y: i64) -> Option { + let e = &*self.edge; + let (fx, fy) = (x.checked_sub(e.x0)?, y.checked_sub(e.y0)?); + if fx < 0 || fy < 0 || fx >= e.w as i64 || fy >= e.h as i64 { return None; } - let i = fy as usize * self.w + fx as usize; - Some((f32::from(*self.cov.get(i)?) / 255.0, *self.dist.get(i)?, *self.normals.get(i)?)) + let i = fy as usize * e.w + fx as usize; + let normal = *e.normals.get(i)?; + let bend = match &self.bends { + Some(bends) => *bends.get(i)?, + None => normal, + }; + Some((f32::from(*e.cov.get(i)?) / 255.0, *e.dist.get(i)?, normal, bend)) } } thread_local! { static FIELDS_COMPUTED: std::cell::Cell = const { std::cell::Cell::new(0) }; + static BENDS_COMPUTED: std::cell::Cell = const { std::cell::Cell::new(0) }; } /// How many times this thread has worked out a glass shape's fields: what a cache miss costs. For @@ -351,9 +556,16 @@ pub fn glass_fields_computed() -> u64 { FIELDS_COMPUTED.with(std::cell::Cell::get) } -/// What a glass shape's fields depend on, with the transform's translation reduced to its fraction -/// of a pixel: the same shape at the same zoom has the same key wherever it is and however a render -/// cuts it. +/// How many times this thread has worked out a glass shape's bend directions towards its core: a +/// new shape, or a kept one at a new depth. For tests and benchmarks. +pub fn glass_bends_computed() -> u64 { + BENDS_COMPUTED.with(std::cell::Cell::get) +} + +/// What a glass shape's [`EdgeFields`] depend on, with the transform's translation reduced to its +/// fraction of a pixel: the same shape at the same zoom has the same key wherever it is and however +/// a render cuts it. Not the depth (beyond the margin and smoothing): the bend directions that +/// depend on it are worked out from the kept fields ([`EdgeFields::bends()`]). #[derive(Clone, Debug, PartialEq, Eq, Hash)] struct ShapeKey { path: u64, @@ -376,7 +588,7 @@ const MAX_CACHED_BYTES: u64 = 128 << 20; const MAX_CACHED_BYTES: u64 = 32 << 20; /// A shape's fields once worked out; parallel bands wanting the same shape wait for one of them. -type Slot = Arc>>>; +type Slot = Arc>>>; /// The shapes' fields by key, at most `budget` bytes; the least recently used go first. A shape is /// kept from the second render that asks for it: one asked for once (each step of a zoom, a pane @@ -440,20 +652,33 @@ fn shape_cache() -> &'static Mutex { C.get_or_init(|| Mutex::new(ShapeCache::new(MAX_CACHED_BYTES))) } +/// Whether `shape` (through `xf`) fits [`MAX_SHAPE_PX`] whole with a margin `m` round it: the +/// window a kept shape's fields cover ([`whole_shape`]). Depends on the shape and the zoom alone, so +/// every band and patch of a render answers the same. +fn fits_whole(shape: &Outline, xf: Affine, m: u32) -> bool { + let Some(own) = own_frame(xf) else { return false }; + let bb = (own.xf * shape.0.clone()).bounding_box(); + let margin = f64::from(m.div_ceil(32).saturating_mul(32)); + let (w, h) = (bb.x1.ceil() - bb.x0.floor() + 2.0 + 2.0 * margin, bb.y1.ceil() - bb.y0.floor() + 2.0 + 2.0 * margin); + let px = w * h; + px.is_finite() && px <= MAX_SHAPE_PX as f64 +} + /// The fields `glass` reads for a `w` × `h` layer whose `shape` maps through `xf` (local → layer -/// pixels), exact for distances up to the margin `m`, normals smoothed over `r` pixels, and the -/// shift from layer pixels to the fields' pixels. +/// pixels), exact for distances up to the margin `m`, normals and bend directions smoothed over +/// `r` pixels, bending towards the core `reach` pixels in, and the shift from layer pixels to the +/// fields' pixels. /// /// A shape asked for again in a later render, whose window fits [`MAX_SHAPE_PX`], is worked out /// whole, in its own frame (the translation's fraction of a pixel), and kept: a band, a canvas /// patch or the next frame of a drag reads the same fields. Otherwise it is worked out for the part /// shown plus the margin. -fn shape_fields(shape: &Outline, xf: Affine, w: u32, h: u32, m: u32, r: usize) -> Option<(Arc, (i64, i64))> { - if let Some(whole) = whole_shape(shape, xf, m, r) { - return Some(whole); +fn shape_fields(shape: &Outline, xf: Affine, w: u32, h: u32, m: u32, r: usize, reach: Option) -> Option<(Fields, (i64, i64))> { + if let Some((edge, shift)) = whole_shape(shape, xf, m, r) { + return Some((Fields::of(edge, reach), shift)); } let cov = spread_alpha(std::slice::from_ref(shape), 0.0, Affine::translate((f64::from(m), f64::from(m))) * xf, w + 2 * m, h + 2 * m)?; - Some((Arc::new(Fields::new(&cov, -i64::from(m), -i64::from(m), r)), (0, 0))) + Some((Fields::new(&cov, -i64::from(m), -i64::from(m), r, reach), (0, 0))) } /// A layer transform split so the same shape at the same zoom lands on the same pixels of its own @@ -484,9 +709,9 @@ fn own_frame(xf: Affine) -> Option { Some(OwnFrame { shift, frac, xf: Affine::new([a, b, c, d, frac.0 as f64 / STEPS, frac.1 as f64 / STEPS]) }) } -/// [`shape_fields`] for a whole shape, from the cache; `None` when it isn't kept (first asked for -/// in this render, too big, or its transform too far out). -fn whole_shape(shape: &Outline, xf: Affine, m: u32, r: usize) -> Option<(Arc, (i64, i64))> { +/// [`shape_fields`]' [`EdgeFields`] for a whole shape, from the cache; `None` when it isn't kept +/// (first asked for in this render, too big, or its transform too far out). +fn whole_shape(shape: &Outline, xf: Affine, m: u32, r: usize) -> Option<(Arc, (i64, i64))> { let [a, b, c, d, _, _] = xf.as_coeffs(); let OwnFrame { shift, frac, xf: own } = own_frame(xf)?; let bb = (own * shape.0.clone()).bounding_box(); @@ -518,26 +743,178 @@ fn whole_shape(shape: &Outline, xf: Affine, m: u32, r: usize) -> Option<(Arc Option { + let rect_like = matches!( + n.kind, + NodeKind::Rectangle + | NodeKind::Frame + | NodeKind::Component { .. } + | NodeKind::ComponentSet { .. } + | NodeKind::Instance { .. } + | NodeKind::Section { .. } + ); + let sized = n.width.is_finite() && n.height.is_finite() && n.width > 0.0 && n.height > 0.0; + (rect_like && sized && n.corners.smoothing == 0.0).then(|| { + // Clamped as `rounded_rect` clamps them: each radius to half the shorter side. + let most = n.width.min(n.height) / 2.0; + let radii = n.corners.radii.map(|r| if r.is_finite() { r.clamp(0.0, most) } else { 0.0 }); + RoundedRect { width: n.width, height: n.height, radii } + }) + } +} + +/// Signed distance from `q` (relative to the centre) to a rectangle reaching `half` each way with +/// corner radius `r` (negative inside), and its outward gradient: the unit normal along the sides, +/// pointing away from the corner's centre round the corners. +fn rounded_rect_sd(q: (f64, f64), half: (f64, f64), r: f64) -> (f64, (f64, f64)) { + let (sx, sy) = (if q.0 < 0.0 { -1.0 } else { 1.0 }, if q.1 < 0.0 { -1.0 } else { 1.0 }); + let k = (q.0.abs() - half.0 + r, q.1.abs() - half.1 + r); + if k.0 > 0.0 && k.1 > 0.0 { + let len = (k.0 * k.0 + k.1 * k.1).sqrt(); + (len - r, (sx * k.0 / len, sy * k.1 / len)) + } else if k.0 > k.1 { + (k.0 - r, (sx, 0.0)) + } else { + (k.1 - r, (0.0, sy)) + } +} + +/// The radius of the corner of `radii` (top-left, top-right, bottom-right, bottom-left) whose +/// quarter `q` (relative to the centre, y down) lies in. +fn corner_of(radii: [f64; 4], q: (f64, f64)) -> f64 { + let i = match (q.0 < 0.0, q.1 < 0.0) { + (true, true) => 0, + (false, true) => 1, + (false, false) => 2, + (true, false) => 3, + }; + radii.get(i).copied().unwrap_or(0.0) +} + +/// A rounded rectangle's glass fields worked out pixel by pixel, in closed form: no coverage to +/// rasterise, no distance transform, nothing to cache. The same fields as [`Fields`] (the bend +/// directions round the corners towards the rectangle shrunk by the core's depth, the middle line +/// of one thinner than twice that), exact rather than from pixels, and the same wherever a render +/// cuts it: each pixel is placed in the layer's own frame. +struct AnalyticRect { + /// Layer pixels → the shape's own frame. + shift: (i64, i64), + /// The shape's own frame → local coordinates. + inv: Affine, + /// Local → device directions (the transform's linear part), and its scale. + linear: [f64; 4], + scale: f64, + half: (f64, f64), + radii: [f64; 4], + /// The corners the light's normals round to: each radius at least the bevel (a sharp corner's + /// bevel catches the light along its diagonal), at most the half side. + bevels: [f64; 4], + /// The corners the bend rounds to: each radius at least the core's depth, at most the half + /// side ([`bend_directions`]). + rounds: [f64; 4], +} + +impl AnalyticRect { + /// `rect`'s fields for a layer whose `xf` maps local coordinates to its pixels, with a `bevel` + /// and bending towards the core `reach` pixels in; `None` when `xf` isn't a rotation, flip and + /// even scale (skewed or stretched rectangles go through the distance transform) or its + /// translation is too far out. + fn new(rect: RoundedRect, xf: Affine, bevel: f64, reach: f64) -> Option { + let own = own_frame(xf)?; + let [a, b, c, d, _, _] = own.xf.as_coeffs(); + let (sq_x, sq_y) = (a * a + b * b, c * c + d * d); + let even = (sq_x - sq_y).abs() <= 1e-9 * sq_x && (a * c + b * d).abs() <= 1e-9 * sq_x; + let scale = sq_x.sqrt(); + if !(even && scale.is_finite() && scale > 1e-9) { + return None; + } + let half = (rect.width / 2.0, rect.height / 2.0); + let at_least = |least: f64| rect.radii.map(|r| r.max(least / scale).min(half.0.min(half.1))); + let (bevels, rounds) = (at_least(bevel), at_least(reach)); + Some(AnalyticRect { shift: own.shift, inv: own.xf.inverse(), linear: [a, b, c, d], scale, half, radii: rect.radii, bevels, rounds }) + } + + /// The fields at layer pixel (`x`, `y`): coverage (box-filtered from the signed distance), + /// distance in, inward normal and inward bend direction. + fn at(&self, x: i64, y: i64) -> FieldPx { + let p = self.inv * Point::new((x - self.shift.0) as f64 + 0.5, (y - self.shift.1) as f64 + 0.5); + let q = (p.x - self.half.0, p.y - self.half.1); + let (sd, _) = rounded_rect_sd(q, self.half, corner_of(self.radii, q)); + let (_, normal) = rounded_rect_sd(q, self.half, corner_of(self.bevels, q)); + let (_, round) = rounded_rect_sd(q, self.half, corner_of(self.rounds, q)); + let [a, b, c, d] = self.linear; + let inward = |n: (f64, f64)| (-((a * n.0 + c * n.1) / self.scale) as f32, -((b * n.0 + d * n.1) / self.scale) as f32); + let sd = sd * self.scale; + ((0.5 - sd).clamp(0.0, 1.0) as f32, (-sd).max(0.0) as f32, inward(normal), inward(round)) + } +} + +/// Where a glass reads its fields: worked out in closed form for a rounded rectangle, from its +/// coverage otherwise. +enum Geometry { + Rect(AnalyticRect), + Fields(Fields, (i64, i64)), +} + +impl Geometry { + /// The fields at layer pixel (`x`, `y`); `None` where there are none. + fn at(&self, x: i64, y: i64) -> Option { + match self { + Geometry::Rect(r) => Some(r.at(x, y)), + Geometry::Fields(f, shift) => f.at(x - shift.0, y - shift.1), + } + } +} + /// The glass of a `w` × `h` layer whose `shape` maps through `xf` (local → layer pixels), from -/// `back`, its backdrop padded by `pad` pixels each way, at `scale` device pixels per unit. -pub fn glass(g: &Glass, frame: EffectFrame<'_>) -> Option { +/// `back`, its backdrop padded by `pad` pixels each way, at `scale` device pixels per unit. `rect`: +/// the rounded rectangle the shape is, when it is one, so its fields are worked out in closed form. +pub fn glass(g: &Glass, frame: EffectFrame<'_>, rect: Option) -> Option { let EffectFrame { shape, back, pad, size: (w, h), xf, scale } = frame; let g = g.sanitized(); let depth = (g.depth * scale).clamp(1.0, 1024.0); let bevel = (BEVEL * scale).min(1024.0); let r = (depth * 0.1).clamp(1.0, 8.0) as usize; - // Coverage with a margin, so wherever the layer is cut every distance the pixels read is - // exact: the bend's and the gradient's (within `depth` + `bevel`; the light lies on the bevel) - // and those the normals are smoothed from (2r + 1 further). - let m = (depth + bevel).ceil() as u32 + 4 * r as u32 + 4; - let (fields, shift) = shape_fields(shape, xf, w, h, m, r)?; + // The core the backdrop bends towards lies `reach` in from the edge ([`bend_directions`]). + let reach = (depth + bevel) as f32; + // Coverage with a margin, so wherever the layer is cut every field the pixels read is the + // whole render's: the distances the bend and the gradient read (within `depth` + `bevel`; the + // light lies on the bevel), the core they bend towards (its nearest pixel up to √2 × `reach` + // further, round a sharp corner, so 1.5 × `reach`; its depths exact within `reach` and + // [`RIDGE_PX`] of it), and those the normals and bends are smoothed from (2r + 1 further). + let plain = (depth + bevel).ceil() as u32 + 4 * r as u32 + 4; + let cored = plain + (1.5 * reach).ceil() as u32 + RIDGE_PX as u32; + // A core takes a wider margin and more bytes a pixel, so only a shape whose whole window fits + // [`MAX_SHAPE_PX`] works one out: a bigger one bends along its edge normals, so no render + // allocates a core's fields over more pixels than a kept shape holds. + let core = fits_whole(shape, xf, cored).then_some(reach); + let m = if core.is_some() { cored } else { plain }; + let geometry = match rect.and_then(|rect| AnalyticRect::new(rect, xf, bevel, f64::from(reach))) { + Some(analytic) => Geometry::Rect(analytic), + None => { + let (fields, shift) = shape_fields(shape, xf, w, h, m, r, core)?; + Geometry::Fields(fields, shift) + } + }; let mut frosted = back.clone(); fx::blur(&mut frosted, g.frost / 2.0 * scale); let ang = g.light_angle.to_radians(); @@ -555,7 +932,7 @@ pub fn glass(g: &Glass, frame: EffectFrame<'_>) -> Option { let dst = out.data_mut(); for y in 0..h as usize { for x in 0..w as usize { - let Some((c, d, inward)) = fields.at(x as i64 - shift.0, y as i64 - shift.1) else { continue }; + let Some((c, d, inward, toward)) = geometry.at(x as i64, y as i64) else { continue }; if c <= 0.0 { continue; } @@ -565,7 +942,7 @@ pub fn glass(g: &Glass, frame: EffectFrame<'_>) -> Option { // are 0 there): the channels' samples are at the same point, so one sample. (dispersed(&frosted, bx, by, 0.0, 0.0, 0.0), 0.0) } else { - // The curve's outward direction: the edge's normal, turned by `splay` towards the + // The curve's outward direction: away from its core, turned by `splay` towards the // way away from the centre (not renormalised: where the two part, the bend is less). let away = if splay > 0.0 { let px = ((x as i64 - sx) as f64 + 0.5 - centre.x) as f32; @@ -575,7 +952,7 @@ pub fn glass(g: &Glass, frame: EffectFrame<'_>) -> Option { } else { (0.0, 0.0) }; - let out_dir = (-inward.0 * (1.0 - splay) + away.0 * splay, -inward.1 * (1.0 - splay) + away.1 * splay); + let out_dir = (-toward.0 * (1.0 - splay) + away.0 * splay, -toward.1 * (1.0 - splay) + away.1 * splay); // No refraction: nothing bends, so one sample (`dispersed` with no move). let bend = bend_at(d, depth, bevel, refraction); let k = if bend == 0.0 { 0.0 } else { dispersion }; @@ -671,6 +1048,124 @@ mod tests { assert_eq!(spread[2], 0.0); } + /// A `w` × `h` coverage with the rectangles `rects` (x, y, width, height) filled. + fn coverage(w: u32, h: u32, rects: &[(f32, f32, f32, f32)]) -> Pixmap { + let mut p = Pixmap::new(w, h).unwrap(); + let paint = tiny_skia::Paint { shader: tiny_skia::Shader::SolidColor(tiny_skia::Color::WHITE), ..Default::default() }; + for (x, y, rw, rh) in rects { + p.fill_rect(tiny_skia::Rect::from_xywh(*x, *y, *rw, *rh).unwrap(), &paint, tiny_skia::Transform::identity(), None); + } + p + } + + fn bend_dir(f: &Fields, x: i64, y: i64) -> (f32, f32) { + f.at(x, y).unwrap().3 + } + + fn close(a: (f32, f32), b: (f32, f32), tol: f32) -> bool { + (a.0 - b.0).abs() <= tol && (a.1 - b.1).abs() <= tol + } + + #[test] + fn a_sharp_corner_bends_round_towards_the_core() { + // A 120 × 80 rectangle at (20, 20), bending towards its core 20 px in. + let f = Fields::new(&coverage(160, 120, &[(20.0, 20.0, 120.0, 80.0)]), 0, 0, 1, Some(20.0)); + let s = std::f32::consts::FRAC_1_SQRT_2; + // Halfway down the left side: straight in. In the corner: diagonally, towards the core's own + // corner 20 px in. + assert!(close(bend_dir(&f, 21, 60), (1.0, 0.0), 0.02), "{:?}", bend_dir(&f, 21, 60)); + assert!(close(bend_dir(&f, 22, 22), (s, s), 0.05), "{:?}", bend_dir(&f, 22, 22)); + // Mirror images across the corner's diagonal, with no seam along it: neighbours agree. + let (a, b) = (bend_dir(&f, 24, 29), bend_dir(&f, 29, 24)); + assert!(close(a, (b.1, b.0), 1e-4), "{a:?} vs {b:?}"); + let (on, off) = (bend_dir(&f, 26, 26), bend_dir(&f, 27, 26)); + assert!(close(on, off, 0.1), "{on:?} vs {off:?}"); + } + + #[test] + fn a_shape_too_big_to_keep_bends_along_its_normals() { + // A small shape fits whole with a core's margin; one wider than the kept-shape limit + // doesn't, at this zoom or with this margin, wherever it sits. + let shape = |w: f64, h: f64| -> Outline { (figcraft_geom::kurbo::Rect::new(0.0, 0.0, w, h).to_path(0.1), tiny_skia::FillRule::Winding) }; + assert!(fits_whole(&shape(200.0, 120.0), Affine::translate((10.5, 3.0)), 64)); + assert!(!fits_whole(&shape(4000.0, 3000.0), Affine::translate((10.5, 3.0)), 64)); + assert!(!fits_whole(&shape(200.0, 120.0), Affine::scale(40.0), 64)); + // Without a core the fields hold no bend directions, and bend along the normals. + let f = Fields::new(&coverage(160, 120, &[(20.0, 20.0, 120.0, 80.0)]), 0, 0, 1, None); + assert!(f.bends.is_none()); + for (x, y) in [(21, 60), (24, 24), (80, 21)] { + let (_, _, normal, bend) = f.at(x, y).unwrap(); + assert_eq!(normal, bend, "({x}, {y})"); + } + } + + #[test] + fn a_thin_part_bends_across_itself() { + // A 200 × 12 bar, thinner than twice the reach: its core is its middle line, and each side + // bends towards it. + let f = Fields::new(&coverage(240, 40, &[(20.0, 14.0, 200.0, 12.0)]), 0, 0, 1, Some(20.0)); + assert!(close(bend_dir(&f, 120, 14), (0.0, 1.0), 0.02), "top: {:?}", bend_dir(&f, 120, 14)); + assert!(close(bend_dir(&f, 120, 25), (0.0, -1.0), 0.02), "bottom: {:?}", bend_dir(&f, 120, 25)); + assert!(f.bends.as_ref().unwrap().iter().all(|(x, y)| x.is_finite() && y.is_finite())); + } + + #[test] + fn neighbouring_strokes_bend_towards_their_own_middles() { + // Two 8 px strokes 2 px apart, like letters: the facing edges bend away from each other, + // each into its own stroke. + let f = Fields::new(&coverage(60, 60, &[(10.0, 10.0, 8.0, 40.0), (20.0, 10.0, 8.0, 40.0)]), 0, 0, 1, Some(20.0)); + assert!(bend_dir(&f, 17, 30).0 < -0.9, "{:?}", bend_dir(&f, 17, 30)); + assert!(bend_dir(&f, 20, 30).0 > 0.9, "{:?}", bend_dir(&f, 20, 30)); + } + + #[test] + fn rounded_rectangle_distances_and_normals() { + let half = (60.0, 40.0); + // Halfway along the left side, 3 in: 3 deep, the normal straight out. + let (sd, n) = rounded_rect_sd((-57.0, 0.0), half, 10.0); + assert!((sd + 3.0).abs() < 1e-9 && n == (-1.0, 0.0), "{sd} {n:?}"); + // Round a 10-unit corner: the distance to its arc, the normal away from its centre. + let (sd, n) = rounded_rect_sd((-57.0, -37.0), half, 10.0); + let (cx, cy) = (-50.0, -30.0); + let len = ((-57.0f64 - cx).powi(2) + (-37.0f64 - cy).powi(2)).sqrt(); + assert!((sd - (len - 10.0)).abs() < 1e-9, "{sd}"); + assert!((n.0 + 7.0 / len).abs() < 1e-9 && (n.1 + 7.0 / len).abs() < 1e-9, "{n:?}"); + // Outside, past the right side. + assert!((rounded_rect_sd((65.0, 0.0), half, 10.0).0 - 5.0).abs() < 1e-9); + assert_eq!([(-1.0, -1.0), (1.0, -1.0), (1.0, 1.0), (-1.0, 1.0)].map(|q| corner_of([1.0, 2.0, 3.0, 4.0], q)), [1.0, 2.0, 3.0, 4.0]); + } + + #[test] + fn a_rounded_rectangle_in_closed_form_matches_its_distance_transform() { + // A 120 × 80 rectangle at (20, 20), bending towards its core 21 px in, both ways. + let fields = Fields::new(&coverage(160, 120, &[(20.0, 20.0, 120.0, 80.0)]), 0, 0, 2, Some(21.0)); + let rect = RoundedRect { width: 120.0, height: 80.0, radii: [0.0; 4] }; + let closed = AnalyticRect::new(rect, Affine::translate((20.0, 20.0)), 1.0, 21.0).unwrap(); + for (x, y) in [(21, 60), (60, 21), (138, 60), (80, 98), (24, 24), (30, 26), (135, 95), (80, 60)] { + let (a, b) = (fields.at(x, y).unwrap(), closed.at(x, y)); + assert!((a.0 - b.0).abs() < 1e-3 && (a.1 - b.1).abs() < 1e-3, "({x}, {y}) coverage and depth: {a:?} vs {b:?}"); + assert!(a.1 >= 21.0 || close(a.3, b.3, 0.08), "({x}, {y}) bend: {a:?} vs {b:?}"); + } + // Rotated a quarter turn, the fields turn with it; skewed or stretched, no closed form. + let turned = AnalyticRect::new(rect, Affine::translate((100.0, 20.0)) * Affine::rotate(std::f64::consts::FRAC_PI_2), 1.0, 21.0).unwrap(); + assert!(close(turned.at(98, 60).2, (-1.0, 0.0), 1e-6), "{:?}", turned.at(98, 60)); + assert!(AnalyticRect::new(rect, Affine::new([1.0, 0.0, 0.3, 1.0, 0.0, 0.0]), 1.0, 21.0).is_none()); + assert!(AnalyticRect::new(rect, Affine::scale_non_uniform(2.0, 1.0), 1.0, 21.0).is_none()); + } + + #[test] + fn nearest_sites_and_running_maxima() { + // Sites at (1, 1) and (8, 3) on a 10 × 5 grid. + let mut site = vec![false; 50]; + site[11] = true; + site[38] = true; + let near = nearest_sites(&site, 10, 5); + assert_eq!((near[0], near[4], near[49], near[37]), (11, 11, 38, 38)); + assert!(nearest_sites(&[false; 6], 3, 2).iter().all(|s| *s == NO_SITE)); + let m = max_within(&[1.0, 5.0, 2.0, 0.0, 0.0, 3.0], 6, 1, 1); + assert_eq!(m, [5.0, 5.0, 5.0, 2.0, 3.0, 3.0]); + } + /// At full dispersion red's furthest step stays within `Glass::max_bend` of the pixel, all /// along the bend, so the backdrop read around a pane covers it: one white pixel further out /// than that is never seen. diff --git a/crates/render/src/glass_cut_tests.rs b/crates/render/src/glass_cut_tests.rs index 9bd74f80d..bac1e2af6 100644 --- a/crates/render/src/glass_cut_tests.rs +++ b/crates/render/src/glass_cut_tests.rs @@ -121,32 +121,39 @@ fn glass_digests() { #[test] fn a_cut_through_the_pane_matches_the_whole_render() { - // The last look is deep (300 units), so the curve reaches far in from every cut. + // The last two looks are deep, so the curve reaches far in from every cut: 60 units (at 2× a + // core 122 px in, which takes the widest margin a core gets) and 300 (too big for a core). let looks = [ wide_light(), Glass::default(), Glass { splay: 0.5, frost: 0.0, refraction: 0.0, ..Glass::default() }, // Splay with the bend and dispersion on: the dispersed samples follow the turned bend. Glass { splay: 1.0, frost: 0.0, ..Glass::default() }, + Glass { depth: 60.0, ..Glass::default() }, Glass { depth: 300.0, ..wide_light() }, ]; // Rounded corners without the pane's fill: a fill's curved edge rasters 1–2 levels apart in a // cut, and that is the fill, not the glass. - for radius in [0.0, 40.0] { + // Plain corners work out in closed form; smoothed ones (sharp ones too: any smoothing counts) + // from the coverage, the deepest look too big for a core and bending along its normals. + for (radius, smoothing) in [(0.0, 0.0), (40.0, 0.0), (0.0, 0.6), (40.0, 0.6)] { for g in &looks { let (mut d, p, pane) = pane_over_stripes(g.clone(), radius); + d.get_mut(pane).unwrap().corners.smoothing = smoothing; if radius > 0.0 { d.get_mut(pane).unwrap().fills.clear(); } for (cut, diff) in cut_diffs(&d, p) { - assert_eq!(diff, (0, 0), "cut at {cut} px, radius {radius}, with {g:?}"); + assert_eq!(diff, (0, 0), "cut at {cut} px, radius {radius}, smoothing {smoothing}, with {g:?}"); } } } } /// A `w` × `h` pane of glass `g` at (`x`, `y`) over stripes, alone on its page: (document, page, -/// pane). Each test gives its own size, so tests running at once don't share cached shapes. +/// pane). Each test gives its own size, so tests running at once don't share cached shapes. Its +/// corners are smoothed, so its fields come from its coverage and are kept (a plain rounded +/// rectangle's are worked out in closed form, with nothing to keep). fn pane(g: Glass, x: f64, y: f64, w: f64, h: f64) -> (Document, NodeId, NodeId) { let mut d = Document::new("glass"); let p = d.first_page().unwrap(); @@ -158,6 +165,7 @@ fn pane(g: Glass, x: f64, y: f64, w: f64, h: f64) -> (Document, NodeId, NodeId) let n = d.get_mut(pane).unwrap(); n.transform = Affine::translate((x, y)); n.corners.radii = [12.0; 4]; + n.corners.smoothing = 0.6; n.effects = vec![Effect { kind: EffectKind::Glass(g), visible: true }]; (d, p, pane) } @@ -173,6 +181,14 @@ fn computed(f: impl FnOnce()) -> u64 { crate::glass::glass_fields_computed() - before } +/// How many glass shapes, and how many shapes' bend directions towards their core, `f` works out +/// on this thread. +fn computed_and_bent(f: impl FnOnce()) -> (u64, u64) { + let before = (crate::glass::glass_fields_computed(), crate::glass::glass_bends_computed()); + f(); + (crate::glass::glass_fields_computed() - before.0, crate::glass::glass_bends_computed() - before.1) +} + #[test] fn kept_fields_render_the_same_pixels_as_fresh_ones() { let (d, p, _) = pane(Glass::default(), 40.0, 30.0, 211.0, 137.0); @@ -211,6 +227,13 @@ fn what_the_shape_depends_on_works_it_out_again_and_nothing_else_does() { assert_eq!(computed(|| drop(render(&d, p, (0.0, 0.0), 1.0))), 1, "part of a pixel"); d.get_mut(pane).unwrap().width = 230.0; assert_eq!(computed(|| drop(render(&d, p, (0.0, 0.0), 1.0))), 1, "shape"); + let _ = render(&d, p, (0.0, 0.0), 1.0); + // A depth a unit more keeps the same margin: the kept shape is reused, and only the bend + // towards the core, which moves with the depth, is worked out again, once (a Depth slider + // dragged works out nothing else). + set(&mut d, Glass { depth: 21.0, ..Glass::default() }); + assert_eq!(computed_and_bent(|| drop(render(&d, p, (0.0, 0.0), 1.0))), (0, 1), "depth, within the same margin"); + assert_eq!(computed_and_bent(|| drop(render(&d, p, (0.0, 0.0), 1.0))), (0, 0), "the same depth again"); set(&mut d, Glass { depth: 70.0, ..Glass::default() }); assert_eq!(computed(|| drop(render(&d, p, (0.0, 0.0), 1.0))), 1, "depth"); } diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 3b31d3228..5d910dabf 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1,6 +1,6 @@ # FigCraft parity with Figma -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-02 · **Change:** minor (glass's light is a line on its bevel and splay turns the bend towards the centre; glass bends with a thick-lens profile and splits its colours over 8 steps, measured against the reference tool; bulleted lists use the same bullet at every level of indentation, as the help center says, instead of a white bullet and a square at the deeper levels; typing `1)` and a space at the start of a paragraph starts a numbered list, as `1.` does, both being the help center's creation characters; a link on text is underlined by default, as the help center says, and Underline takes the underline off while the link stays; a Dash cap setting (none, round or square) on Dash and Custom strokes, drawn on both ends of every dash; gap 6: widgets draw lines and SVG pictures (plugin API 6); gap 6: a widget opens its plugin's panel (plugin API 5), whose callbacks redraw it; the browser build uses the fonts installed on the computer once asked, each read when text uses it (#1051); plugin widgets have hover styles: a layer's `hover` fill, stroke, opacity or text colour shows while the pointer is over it (gap 6); Thai, Lao, Khmer and Burmese lines break between words (#1219); MCP and control calls name their document (#998); shadows of images with transparent pixels follow their alpha (#1289); Arabic draft catalog; truncated text fills its last line before the ellipsis and keeps truncating when resized; auto-height text with max lines (#1375, #1376, #1377), numbers unchanged; plugin widgets take text input and a property menu (plugin API 4); boards: templates and tables; boards: a shared timer and voting sessions; boards: the dot grid, connector ends dragged to re-attach, curved connectors; `.sketch` import, best effort: import/export breadth 86% → 87%, file formats 60% → 61%, headline numbers unchanged; Canvas & navigation's remaining work no longer lists outline mode's Include hidden layers and Include object bounds; boards: area 22 (weight 0, outside the weighted sum); CJK line breaking: JIS X 4051's line-start and line-end sets completed with the halfwidth small kana, the halfwidth and spacing (semi-)voiced sound marks, iteration marks 〱–〵 and the halfwidth parentheses; Turkish reviewed, Czech and Indonesian drafts, the Japanese draft completed; reviewed Russian catalog and integer plurals; vector edit mode regions: hover hatch, selection and drag; plugin log byte/count limits (#191); core editor leftovers: component playground, auto gap handles, variables inside styles, inner shadows and background blur on groups, command-made text readable on dark pages, a one-step frame/group convert, delays on mouse triggers and manual overlay offsets, wrapped-line alignment; starter templates, a Templates tab and Getting started tips on the home screen: essentials ~57% → ~59%; everyday editing partials: number fields, outline options, Hide when publishing, cursors, panel widths, dark pages, numbers unchanged but menu breadth 211/211; text box sizes measured against documents re-saved by other software: whole-pixel line heights, advances on a 1024-per-em grid, letter spacing between glyphs only, numbers unchanged; .fig export checked by opening written files in other software, numbers unchanged; a public figcraft-server: open hosting, owner tokens, per-address limits, idle expiry, moderation, install.sh; experimental .fig export; keyboard shortcut parity suite and bindings; Simplified Chinese draft catalog; Latin American Spanish overlay; prototyping tail: gamepad triggers, widgets in prototypes, mode lookups; plugin directory on figcraft-server; Japanese and Korean draft catalogs and CJK UI fonts; plugin widgets and the plugin panel tail; French, German and Brazilian Portuguese draft catalogs; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and edit tail; dev resources links; extended collections tail; branch version history and finer list merges; headline percentages recomputed from the area table: feature breadth ~84%, core ~94%, mainstream ~50%; text lists, hanging punctuation and decoration styles; comments and version history behaviour suite and fixes; canvas navigation, guides and grids behaviour suite and fixes; export and inspect behaviour suite and fixes; .fig import: editable vector networks and more layer kinds; shapes and vector behaviour suite and fixes; paint and effects behaviour suite and fixes; frames, groups, sections and masks behaviour suite and fixes; styles and variables behaviour suite and fixes; prototyping behaviour suite and fixes; components behaviour suite and fixes; embedded image colour profiles; layers panel keyboard: F2 rename, Shift+F10 context menu, keyboard box selection, 10k-layer QA; per-side stroke weight variables; text behaviour suite: CJK line breaking, metrics, vertical trim; selection and transform behaviour suite and fixes; `.fig` import, best effort; auto layout behaviour suite and fixes; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; localization layer with a draft Spanish catalog; hosting figcraft-server: wss in the desktop app, server releases, deployment guide; plugin panels and settings; canvas fixes: boolean hit testing on the result, group drags, frame outlines and slices; code connect; stretch and scatter brushes, pen pressure; text on a path and pattern fills; team libraries on the server and swap library; branches: create, update from main, review and merge; animated GIF fills and TIFF images; Open recent, outlines for the selection and mask outlines: menu breadth 100%; extended collections, variables import/export, gradient stop and variant bindings; feature breadth ~80%; ready ~49%; last major: full re-measure against Figma desktop 126.10.7; rows for the community batches: Selection colors, smart-selection spacing and a Present tab (#753), `.fig` import fidelity, paste from another design app, a `.fig` copy from Save as; control requests while the window is minimised (#720); catalog counts re-measured; automation roots (#715); number variables in the text content picker (#629); frames and sections convert into each other (#719)) · **Target:** Figma Design (desktop app 126.10.7, macOS) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-02 · **Change:** minor (glass bends towards its core, rounded rectangles in closed form; glass's light is a line on its bevel and splay turns the bend towards the centre; glass bends with a thick-lens profile and splits its colours over 8 steps, measured against the reference tool; bulleted lists use the same bullet at every level of indentation, as the help center says, instead of a white bullet and a square at the deeper levels; typing `1)` and a space at the start of a paragraph starts a numbered list, as `1.` does, both being the help center's creation characters; a link on text is underlined by default, as the help center says, and Underline takes the underline off while the link stays; a Dash cap setting (none, round or square) on Dash and Custom strokes, drawn on both ends of every dash; gap 6: widgets draw lines and SVG pictures (plugin API 6); gap 6: a widget opens its plugin's panel (plugin API 5), whose callbacks redraw it; the browser build uses the fonts installed on the computer once asked, each read when text uses it (#1051); plugin widgets have hover styles: a layer's `hover` fill, stroke, opacity or text colour shows while the pointer is over it (gap 6); Thai, Lao, Khmer and Burmese lines break between words (#1219); MCP and control calls name their document (#998); shadows of images with transparent pixels follow their alpha (#1289); Arabic draft catalog; truncated text fills its last line before the ellipsis and keeps truncating when resized; auto-height text with max lines (#1375, #1376, #1377), numbers unchanged; plugin widgets take text input and a property menu (plugin API 4); boards: templates and tables; boards: a shared timer and voting sessions; boards: the dot grid, connector ends dragged to re-attach, curved connectors; `.sketch` import, best effort: import/export breadth 86% → 87%, file formats 60% → 61%, headline numbers unchanged; Canvas & navigation's remaining work no longer lists outline mode's Include hidden layers and Include object bounds; boards: area 22 (weight 0, outside the weighted sum); CJK line breaking: JIS X 4051's line-start and line-end sets completed with the halfwidth small kana, the halfwidth and spacing (semi-)voiced sound marks, iteration marks 〱–〵 and the halfwidth parentheses; Turkish reviewed, Czech and Indonesian drafts, the Japanese draft completed; reviewed Russian catalog and integer plurals; vector edit mode regions: hover hatch, selection and drag; plugin log byte/count limits (#191); core editor leftovers: component playground, auto gap handles, variables inside styles, inner shadows and background blur on groups, command-made text readable on dark pages, a one-step frame/group convert, delays on mouse triggers and manual overlay offsets, wrapped-line alignment; starter templates, a Templates tab and Getting started tips on the home screen: essentials ~57% → ~59%; everyday editing partials: number fields, outline options, Hide when publishing, cursors, panel widths, dark pages, numbers unchanged but menu breadth 211/211; text box sizes measured against documents re-saved by other software: whole-pixel line heights, advances on a 1024-per-em grid, letter spacing between glyphs only, numbers unchanged; .fig export checked by opening written files in other software, numbers unchanged; a public figcraft-server: open hosting, owner tokens, per-address limits, idle expiry, moderation, install.sh; experimental .fig export; keyboard shortcut parity suite and bindings; Simplified Chinese draft catalog; Latin American Spanish overlay; prototyping tail: gamepad triggers, widgets in prototypes, mode lookups; plugin directory on figcraft-server; Japanese and Korean draft catalogs and CJK UI fonts; plugin widgets and the plugin panel tail; French, German and Brazilian Portuguese draft catalogs; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and edit tail; dev resources links; extended collections tail; branch version history and finer list merges; headline percentages recomputed from the area table: feature breadth ~84%, core ~94%, mainstream ~50%; text lists, hanging punctuation and decoration styles; comments and version history behaviour suite and fixes; canvas navigation, guides and grids behaviour suite and fixes; export and inspect behaviour suite and fixes; .fig import: editable vector networks and more layer kinds; shapes and vector behaviour suite and fixes; paint and effects behaviour suite and fixes; frames, groups, sections and masks behaviour suite and fixes; styles and variables behaviour suite and fixes; prototyping behaviour suite and fixes; components behaviour suite and fixes; embedded image colour profiles; layers panel keyboard: F2 rename, Shift+F10 context menu, keyboard box selection, 10k-layer QA; per-side stroke weight variables; text behaviour suite: CJK line breaking, metrics, vertical trim; selection and transform behaviour suite and fixes; `.fig` import, best effort; auto layout behaviour suite and fixes; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; localization layer with a draft Spanish catalog; hosting figcraft-server: wss in the desktop app, server releases, deployment guide; plugin panels and settings; canvas fixes: boolean hit testing on the result, group drags, frame outlines and slices; code connect; stretch and scatter brushes, pen pressure; text on a path and pattern fills; team libraries on the server and swap library; branches: create, update from main, review and merge; animated GIF fills and TIFF images; Open recent, outlines for the selection and mask outlines: menu breadth 100%; extended collections, variables import/export, gradient stop and variant bindings; feature breadth ~80%; ready ~49%; last major: full re-measure against Figma desktop 126.10.7; rows for the community batches: Selection colors, smart-selection spacing and a Present tab (#753), `.fig` import fidelity, paste from another design app, a `.fig` copy from Save as; control requests while the window is minimised (#720); catalog counts re-measured; automation roots (#715); number variables in the text content picker (#629); frames and sections convert into each other (#719)) · **Target:** Figma Design (desktop app 126.10.7, macOS) The authoritative assessment of how close FigCraft is to Figma Design. [`ROADMAP.md`](../ROADMAP.md) summarizes it; [`gaps.md`](gaps.md) is the ranked work list; the measured menu checklist is @@ -596,7 +596,9 @@ Carried over from the ROADMAP's "Shipped so far" (2026-10-10). The test count th that sees the whole backdrop, inside clipping frames, faded groups and masks too; both blurs uniform or progressive (the radius ramps between two points, dragged on the canvas); noise in mono, duo and multi colour with grain size, density and blend mode; texture with clip to shape; - glass with light angle and intensity, refraction, depth, dispersion, frost and splay; the same in + glass with light angle and intensity, refraction, depth, dispersion, frost and splay (a thick lens + bending towards the shape's core, its light a line on the bevel, matched to the reference tool on + synthetic files); the same in PNG, PDF and SVG exports, SVG embedding renders of noise grains, texture, progressive and background blur and glass); corner radii with smoothing; constraints; auto layout (horizontal, vertical, wrap, grid; hug/fill/fixed; min/max; @@ -648,6 +650,7 @@ Carried over from the ROADMAP's "Shipped so far" (2026-10-10). The test count th | Date | Change | Summary | |---|---|---| +| 2026-11-02 | minor | M3, #1885: glass bends towards its core, the shape shrunk by `depth` and the bevel, as the reference tool's: round a sharp corner the bend turns smoothly, and a thin part (a capsule, a letter's stroke) bends across itself, checked side by side on a capsule 44 units tall. Rounded rectangles work it out in closed form. A shape too big to keep whole at the zoom bends along its edge normals instead, so no render works out a core over more pixels than a kept shape holds. Tests: `glass::tests::a_sharp_corner_bends_round_towards_the_core`, `glass::tests::a_thin_part_bends_across_itself`, `glass::tests::a_shape_too_big_to_keep_bends_along_its_normals`, `glass_cut_tests::a_cut_through_the_pane_matches_the_whole_render`. Grade unchanged. | | 2026-11-02 | minor | M3, #1885: glass's light is a line on its 1-unit bevel added to the backdrop, as the reference tool's: fully where the edge faces the light, none below 0.35 of facing it, 0.6 as much on the opposite side, with a faint gradient across the curve. `splay` turns the bend from along the edge's normal towards the way away from the layer's centre and no longer widens the light, as in the reference tool. Checked side by side on synthetic files: a splay of 1 bends the backdrop towards the centre in both. Tests: `glass::tests::the_light_lies_on_the_bevel_and_the_gradient_across_the_curve`, `backdrop_tests::splay_turns_the_bend_towards_the_centre`, `glass_cut_tests::the_light_is_a_line_on_the_bevel`. Grade unchanged. | | 2026-11-02 | minor | M3, #1885: glass bends the backdrop with the reference tool's thick-lens profile (most a 1-unit bevel in from the edge, falling off as the 3.5th power of the way out of the curve to nothing `depth` further in) and splits its colours over 8 steps, red and blue 0.16 of the bend apart at 100% dispersion. Measured against the reference tool on synthetic files at 2×: the black band a pane pulls to its edge ends within 3 px of the reference tool's, and red and blue part 2.27 px at 50% dispersion and 4.66 px at 100% (2.38 and 4.69 there). Tests: `glass::tests::the_bend_follows_the_thick_lens_profile`, `glass::tests::dispersion_splits_the_channels_along_the_bend`. Grade unchanged. | | 2026-11-01 | patch | M4: bulleted lists draw the same bullet at every level of indentation ("Figma bullets will keep the same styling at all levels of indentation", Create bulleted and numbered lists); the deeper levels drew a white bullet and a small square, pinned as silent before. Numbered levels (1., a., i.) are unchanged. Found by a documentation audit of the text rules. Test: `tail_tests::list_numbering_by_level` (the bullets row). Numbers unchanged |