feat(domain): R4.5e wasm proof export, resources per page, N-1 and TS-engine read-back, cost comparison

export_pdf_for_test on the proofs build (ExportInput JSON + base64 rasters): the 14 O2
runs give the native digests through wasm; the frozen O11 scanner reads every R4 PDF and
the N-1 Zod readers accept its envelope; a stripped R4 PDF answers attachment_stripped;
the TypeScript engine reads the R4 PDFs back to the R3 outcome; E2 size ≤ R3 + 5 %. Page
resources list the images the page draws (listing every embed cost 9 MB on CAP). Node,
stub rasters, TS → Rust: demo 198 → 36 ms, L 772 → 57 ms, CAP 5.7 s → 0.22 s; files
236 KB, 386 KB, 1.6 MB against 243 KB, 463 KB, 2.2 MB. Module with the writer linked
(proofs build): 531.6 KB gzip; shipped unchanged at 426 KB until R4.6 links it.
This commit is contained in:
bchanot committed 2026-10-18 23:21:05 +02:00
1 parent 4d45de5745
commit 50c8fe0b33
21 files changed
+485 -19

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@ mod conclusion;
mod footer;
mod header;
mod observation;
mod png;
pub mod png;
use super::draw_log::{DrawLog, Rgb, rgb};
use super::input::{CheckedInput, ExportError, ExportErrorKind, ExportWarning, LogoSlot, Rasters};
+22 -6
View File
@@ -10,7 +10,7 @@
use miniz_oxide::deflate::compress_to_vec_zlib;
use super::content::{font_resource_name, image_resource_name, page_content};
use super::draw_log::{DrawLog, Embed, PAGE_HEIGHT, PAGE_WIDTH};
use super::draw_log::{DrawLog, DrawOp, Embed, PAGE_HEIGHT, PAGE_WIDTH, PageLog};
use super::input::{ExportError, ExportErrorKind};
use super::objects::{Objects, Ref, dict, hex_ascii, hex_text, literal, name, numbers, pdf_date};
use super::png::{DecodedPng, decode_png};
@@ -101,15 +101,31 @@ fn write_fonts(objects: &mut Objects) -> [(Font, Ref); 3] {
})
}
fn resources(fonts: &[(Font, Ref); 3], images: &[Ref]) -> String {
/// The page's resources: the three fonts, and the images the page draws (as pdf-lib listed
/// per page what its calls used; listing every embed on every page costs megabytes on a
/// report at the caps).
fn resources(fonts: &[(Font, Ref); 3], images: &[Ref], page: &PageLog) -> String {
let font_entries: Vec<String> = fonts
.iter()
.map(|(font, r)| format!("/{} {}", font_resource_name(*font), r.text()))
.collect();
let image_entries: Vec<String> = images
let mut used: Vec<usize> = page
.ops
.iter()
.enumerate()
.map(|(i, r)| format!("/{} {}", image_resource_name(i), r.text()))
.filter_map(|op| match op {
DrawOp::Image(image) => Some(image.embed),
_ => None,
})
.collect();
used.sort_unstable();
used.dedup();
let image_entries: Vec<String> = used
.into_iter()
.filter_map(|i| {
images
.get(i)
.map(|r| format!("/{} {}", image_resource_name(i), r.text()))
})
.collect();
format!(
"<< /Font << {} >> /XObject << {} >> >>",
@@ -166,7 +182,7 @@ fn write_page(
("Parent", shared.pages.text()),
("MediaBox", numbers(&[0.0, 0.0, PAGE_WIDTH, PAGE_HEIGHT])),
("Contents", content.text()),
("Resources", resources(shared.fonts, shared.images)),
("Resources", resources(shared.fonts, shared.images, page)),
];
if !annots.is_empty() {
entries.push(("Annots", format!("[{}]", annots.join(" "))));