feat(domain): R4.4 scaffold of the pdf writer module (feature pdf-write, text contract, test targets)
This commit is contained in:
1 parent
a3f756513c
commit
71bcb742c9
13 files changed
+92
-4
No files matched your search
@@ -17,6 +17,8 @@ ts = ["dep:ts-rs"]
|
||||
# The PDF reader (R4, plan §B.1.2): byte scan, inflation, attachment probe, import. The wasm
|
||||
# facade enables it; the worker never does.
|
||||
pdf-read = ["dep:miniz_oxide"]
|
||||
# The PDF writer (R4, plan §B.1.3): layout to a draw log (R4.4), the serialiser (R4.5).
|
||||
pdf-write = []
|
||||
|
||||
[dependencies]
|
||||
serde.workspace = true
|
||||
@@ -55,5 +57,13 @@ required-features = ["pdf-read"]
|
||||
name = "pdf_robustness"
|
||||
required-features = ["pdf-read"]
|
||||
|
||||
[[test]]
|
||||
name = "pdf_text"
|
||||
required-features = ["pdf-write"]
|
||||
|
||||
[[test]]
|
||||
name = "pdf_layout"
|
||||
required-features = ["pdf-write"]
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -11,3 +11,5 @@ pub mod import;
|
||||
pub mod json_js;
|
||||
#[cfg(feature = "pdf-read")]
|
||||
pub mod read;
|
||||
#[cfg(feature = "pdf-write")]
|
||||
pub mod write;
|
||||
@@ -0,0 +1,3 @@
|
||||
//! R4.4a: the AFM metrics of Helvetica, Helvetica-Bold and Times-Roman over WinAnsi, and
|
||||
//! the Unicode tables the text rules need, generated from the O4 and O5 oracles by
|
||||
//! `scripts/r4-afm-data.mjs`. Written by the R4.4a track.
|
||||
@@ -0,0 +1,8 @@
|
||||
//! R4.4a: `formatDate` of `render/dates.ts`. Written by the R4.4a track.
|
||||
|
||||
use crate::domain::archive::Locale;
|
||||
|
||||
/// Long date in the locale for a `YYYY-MM-DD` value; anything else printed unchanged.
|
||||
pub fn format_date(_iso_date: &str, _locale: Locale) -> String {
|
||||
unimplemented!("R4.4a")
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
//! R4.4b: the draw log. Written by the layout track.
|
||||
@@ -0,0 +1 @@
|
||||
//! R4.4b: the export input and its checks. Written by the layout track.
|
||||
@@ -0,0 +1 @@
|
||||
//! R4.4b: the page layouts. Written by the layout track.
|
||||
@@ -0,0 +1,14 @@
|
||||
//! The PDF writer (R4, plan §B.1.3). R4.4 brings the layout: the pages of a report as a
|
||||
//! [`draw_log::DrawLog`], every drawing call of `packages/pdf/src/render/*` reproduced at
|
||||
//! full precision in the TypeScript's call order (header, title, images, sections per
|
||||
//! observation page, the conclusion page, then the footers of every page), pinned by the
|
||||
//! O1 oracle (`apps/app/tests/fixtures/goldens/r4/draw.*.json`) and the Step 6 goldens. The
|
||||
//! text rules (`text`, `afm_data`) and the dates (`dates`) are pinned by O4, O5 and O6. The
|
||||
//! serialiser that turns the log into PDF bytes is R4.5.
|
||||
|
||||
pub mod afm_data;
|
||||
pub mod dates;
|
||||
pub mod draw_log;
|
||||
pub mod input;
|
||||
pub mod layout;
|
||||
pub mod text;
|
||||
@@ -0,0 +1,46 @@
|
||||
//! R4.4a: the text rules of the engine (`packages/pdf/src/text.ts`, `render/text.ts`).
|
||||
//! Written by the R4.4a track; the signatures below are the contract the layout uses.
|
||||
|
||||
/// The three standard fonts the engine embeds (`render/fonts.ts`), by their PDF base name.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum Font {
|
||||
Helvetica,
|
||||
HelveticaBold,
|
||||
TimesRoman,
|
||||
}
|
||||
|
||||
impl Font {
|
||||
/// The base font name, as the draw log and the PDF carry it.
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Helvetica => "Helvetica",
|
||||
Self::HelveticaBold => "Helvetica-Bold",
|
||||
Self::TimesRoman => "Times-Roman",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `safeText`: Cc, Cf, Zl and Zp dropped, other non-WinAnsi code points `?`.
|
||||
pub fn safe_text(_text: &str) -> String {
|
||||
unimplemented!("R4.4a")
|
||||
}
|
||||
|
||||
/// JavaScript `String.prototype.toUpperCase()`.
|
||||
pub fn js_upper(_text: &str) -> String {
|
||||
unimplemented!("R4.4a")
|
||||
}
|
||||
|
||||
/// JavaScript `String.prototype.trim()`.
|
||||
pub fn js_trim(_text: &str) -> &str {
|
||||
unimplemented!("R4.4a")
|
||||
}
|
||||
|
||||
/// `measure(font, text, size) = widthOfTextAtSize(safeText(text), size)`.
|
||||
pub fn measure(_font: Font, _text: &str, _size: f64) -> f64 {
|
||||
unimplemented!("R4.4a")
|
||||
}
|
||||
|
||||
/// `wrapLines(text, font, size, max)`: split on JS `\s+`, each word made safe, greedy join.
|
||||
pub fn wrap_lines(_text: &str, _font: Font, _size: f64, _max: f64) -> Vec<String> {
|
||||
unimplemented!("R4.4a")
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
//! R4.4b placeholder.
|
||||
@@ -0,0 +1 @@
|
||||
//! R4.4a placeholder.
|
||||
@@ -18,7 +18,7 @@ default = []
|
||||
proofs = []
|
||||
|
||||
[dependencies]
|
||||
faunosteo-core = { path = "../core", features = ["pdf-read"] }
|
||||
faunosteo-core = { path = "../core", features = ["pdf-read", "pdf-write"] }
|
||||
wasm-bindgen.workspace = true
|
||||
|
||||
[lints]
|
||||
|
||||
@@ -17,11 +17,11 @@ cargo clippy --workspace --all-targets --locked -- -D warnings
|
||||
cargo test --workspace --locked
|
||||
# The PDF reader (R4) is feature-gated in the core: its code and suites compile only here
|
||||
# and in the wasm module, never in the worker.
|
||||
cargo clippy -p faunosteo-core --all-targets --features pdf-read --locked -- -D warnings
|
||||
cargo test -p faunosteo-core --features pdf-read --locked
|
||||
cargo clippy -p faunosteo-core --all-targets --features pdf-read,pdf-write --locked -- -D warnings
|
||||
cargo test -p faunosteo-core --features pdf-read,pdf-write --locked
|
||||
# Exports the TypeScript types of the contracts (ts-rs) into packages/core-wasm/types.
|
||||
# `git status --porcelain --untracked-files=all -- packages/core-wasm/types` must stay
|
||||
# empty afterwards (scripts/check-all.sh, .gitea/workflows/ci.yml): the committed types
|
||||
# never drift from the Rust structs, and a new type file counts as drift.
|
||||
cargo test -p faunosteo-core --features ts,pdf-read --locked
|
||||
cargo test -p faunosteo-core --features ts,pdf-read,pdf-write --locked
|
||||
cargo deny check licenses bans sources
|
||||
Reference in new issue
Block a user