Skip to content

Print programs with editor-based layout and typesetting#264

Draft
osnr wants to merge 46 commits into
mainfrom
osnr/fields
Draft

Print programs with editor-based layout and typesetting#264
osnr wants to merge 46 commits into
mainfrom
osnr/fields

Conversation

@osnr
Copy link
Copy Markdown
Collaborator

@osnr osnr commented May 27, 2026

WIP. Still needs support for

  1. A4 / non-letter paper
  2. multi-page printing
IMG_5303
IMG_5302.MOV

The program gets printed at whatever text scale you had in the editor at print time, and with the editor's exact margins and font.

The goal here is to let you edit 'in place' and preview in place so you can test real-world geometric constructs like fields as you program. We want to make the printed code feel like a real interaction element and not just a nice-to-have for the human reader.

osnr added 30 commits May 13, 2026 12:05
This doesn't seem to affect folk-hex, but it might affect other
systems / require re-measuring geometry.

This still doesn't provide perfectly calibrated prints: I think there
are some margin issues:
https://moral.net.au/writing/2023/05/19/printer_actual_size/
where there was a risk we would reuse a not-yet-destroyed match and
then accidentally stomp its destructorSet in the final stage of match
destruction. This now uses a sentinel to distinguish 'removed' and
'fully destroyed' stages.
Want to use for on-top editor.
Goal here is to be able to prototype and preview fields at scale / in
context while writing a program that uses them. The detached editor
wouldn't work for this.
Printing should share as much layout logic with draw as possible.
Turn off Hold of quad rendering -- this may cause blinking, but
hopefully -atomically can handle.

Make tag in print preview not detect.
It's not perfectly aligned -- need to look into.

Also still some subtleties with different paper formats to fix / make
sure work. Basically, I think the editor needs to be
format-aware/media-aware in order for this all to make sense.
Next: use the calibration pdf to calibrate tag size and margins such
that we can print at accurate scale after calibration, and such that
we calibrate at exactly the same tag size that we print programs at.
so that we can live-update them when we hotpatch a dependency
program (they won't just hang around the global namespace for that
interp).
Need to make everything use the same print pipeline so we can be sure
that the user is actually calibrating what they'll actually use to
print programs.
@osnr osnr requested review from cwervo, ppkn and smj-edison May 27, 2026 21:37
@osnr
Copy link
Copy Markdown
Collaborator Author

osnr commented May 27, 2026

Some weird other changes here:

  • jimtcl interpreter now tracks column numbers (so we can find field locations later)
  • local fns get revoked when block exits, so they don't stick around in scope (so they get hot-reloaded properly)
  • calibration tags and printed pages are now slightly smaller, should be same size -- you should recalibrate. this should help calibration accuracy in practice (more points per pose, more robust against user tag measurement error since printed tag is same size as calibrated tag)
  • quads are not held, just wished, which may introduce more blinking (need to look at using -atomically for this). fixes some removal race

</iframe>
<p>You can download the PDF and print it yourself, or print through Folk if your printer is set up: <button id="board-print-through-folk">Print Calibration Board through Folk</button></p>
<img width="200" src="/calibrate/board.png" style="border: 1px solid gray">
<p>Make sure your printer is set up for Folk to print.</p>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we link to Printer Support — https://github.com/FolkComputer/folk#printer-support here?

When the calibration measurements are /measurements/ {
set m_tag [expr {double([string trimright [dict get $measurements tagSideLength] mm])}]
set m_left [expr {double([string trimright [dict get $measurements left] mm])}]
set m_bottom [expr {double([string trimright [dict get $measurements bottom] mm])}]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of using expr {double()} here?

When /k/ is a keyboard with /...opts/ &\
/nobody/ wishes /k/ does not create an editor {
# Old editor data is incompatible.
file delete $::env(HOME)/folk-data/hold/editor.folk
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this delete on every boot?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I believe it will still be loaded by the time this runs, which may be an issue (I haven't read the rest of the code yet though).

Copy link
Copy Markdown
Collaborator

@smj-edison smj-edison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really exciting, it feels like the digital and physical worlds are coming even closer with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants