3.3 KiB
TASK font-dedupe: embed each font once (Registry spec, task 0.2)
Runs through OpenCode (specs/agents/opencode-runbook.md is attached automatically). Task 0.2 of specs/registry/tasks.md. Measured in specs/registry/measurements.md 1.2: Inter-Regular.ttf and Inter-SemiBold.ttf are in the release binary twice (once in engine PDF export, once in ui-egui), 0.79 MiB wasted; PDF export also embeds JetBrainsMono-Regular.ttf (264 KiB) that nothing else uses.
OWNS
crates/engine/src/builtin/export_commands.rs(make the three font constants public and switch the mono one).crates/engine/src/lib.rs(ONE line:pub use builtin::export_commands::{INTER_REGULAR, INTER_SEMIBOLD, JETBRAINS_MONO};; other people have uncommitted edits in this file, touch nothing else).crates/ui-egui/src/design/fonts/mod.rs(the two Inter constants and the mono constant now come from the engine; keepINTER_MEDIUMandSTIX_MATHas they are).crates/ui-egui/src/design/fonts/tests.rsonly to add the test below.
FILES TO OPEN
crates/engine/src/builtin/export_commands.rslines 30-45 (the constants andfonts()).crates/ui-egui/src/design/fonts/mod.rslines 1-30 andinstall.crates/engine/src/builtin/mod.rs(pub(crate) mod export_commands, so the re-export inlib.rsis the only public path).
GOAL / API
In export_commands.rs: pub const INTER_REGULAR: &[u8], pub const INTER_SEMIBOLD: &[u8] (same files as today) and pub const JETBRAINS_MONO: &[u8] = include_bytes!("../../../../assets/fonts/JetBrainsMono-NoLigatures.ttf"); (the UI font; PDF text has no ligature shaping, widths come from the file, so the PDF stays valid). Rustdoc on each (keep the existing sentences). lib.rs re-exports them. In ui-egui fonts mod.rs: delete the two Inter include_bytes! and the mono one, use notescraft_engine::{INTER_REGULAR, INTER_SEMIBOLD, JETBRAINS_MONO};. Do NOT delete any file under assets/fonts/ (the pdf crate's tests still read JetBrainsMono-Regular.ttf).
Expected result: the release binary shrinks by about 1.05 MiB (0.79 + 0.26).
TESTS
Add in ui-egui/src/design/fonts/tests.rs: the_ui_and_the_exporter_share_one_inter_copy asserting std::ptr::eq(notescraft_engine::INTER_REGULAR.as_ptr(), <the slice the UI installs>.as_ptr()) (expose the slice through a #[cfg(test)] pub(super) fn inter_regular() -> &'static [u8] or compare lengths and first 64 bytes if pointer access is awkward). Existing PDF export tests must still pass: if one compares exact PDF bytes or glyph widths of the mono font and fails, STOP and report the test name and the diff; do not edit the test.
VERIFY
export PATH="$HOME/.cargo/bin:$PATH"
cargo test -p notescraft-engine export
cargo test -p notescraft-ui-egui fonts
cargo clippy -p notescraft-engine -p notescraft-ui-egui --all-targets -- -D warnings
rustfmt --edition 2024 crates/engine/src/builtin/export_commands.rs crates/ui-egui/src/design/fonts/mod.rs crates/ui-egui/src/design/fonts/tests.rs
Optional if time: CARGO_TARGET_DIR=target/agent-fonts cargo build --release -p notescraft and report ls -l against 40,235,208 bytes.
DO NOT
Edit Cargo files; change INTER_MEDIUM, STIX_MATH, any font size, or the eframe features (task 0.3 does that); delete asset files; add a fonts module or crate; touch anything else in engine/src/lib.rs.