Merge remote-tracking branch 'origin/main' into craft-flags-review

This commit is contained in:
David Mann
2026-11-12 22:20:41 +01:00
6 changed files with 57 additions and 12 deletions
+2
View File
@@ -0,0 +1,2 @@
[lints]
cargo.unused_workspace_dependencies = "allow"
+2
View File
@@ -149,11 +149,13 @@ chrono = { version = "0.4.45", default-features = false, features = ["std"] }
[workspace.lints.rust]
unsafe_code = "forbid"
unused_workspace_dependencies = "allow"
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(craft_pdf_unicode_fixtures)"] }
[workspace.lints.clippy]
cognitive_complexity = "deny"
too_many_arguments = "deny"
unused_workspace_dependencies = "allow"
wildcard_imports = "deny"
dbg_macro = "warn"
todo = "warn"
+2 -1
View File
@@ -74,7 +74,8 @@ impl Value {
}
/// The `crs:` settings of a packet, by name without the prefix (`Exposure2012`). Where a name
/// occurs more than once (in several `rdf:Description`s), the last one is kept.
/// occurs more than once (in several `rdf:Description`s), the first text-bearing value is kept,
/// as [`craft_metadata::parse_xmp`] reads every packet: a blank repeat must not hide it.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Settings {
pub entries: BTreeMap<String, Value>,
+6 -2
View File
@@ -78,10 +78,14 @@ fn structures_other_prefixes_and_other_namespaces() {
assert_eq!(masks.items().first().and_then(|m| m.field("crs:What")).and_then(XmpValue::text), Some("Correction"));
assert_eq!(s.get("Empty"), Some(&Value::Text(String::new())));
assert_eq!(s.get("format"), None);
// The last value of a repeated name wins.
// A repeated name keeps its first value, as `craft_metadata` reads every packet: an empty
// repeat must not hide what an earlier description said.
let second = format!("/><rdf:Description xmlns:crs=\"{CRS_NS}\" crs:Texture=\"2\"/></rdf:RDF>");
let twice = with("crs:Texture=\"1\"").replace("/></rdf:RDF>", &second);
assert_eq!(Settings::parse(twice.as_bytes()).unwrap().text("Texture"), Some("2"));
assert_eq!(Settings::parse(twice.as_bytes()).unwrap().text("Texture"), Some("1"));
let blank = format!("/><rdf:Description xmlns:crs=\"{CRS_NS}\" crs:Texture=\"\"/></rdf:RDF>");
let hiding = with("crs:Texture=\"1\"").replace("/></rdf:RDF>", &blank);
assert_eq!(Settings::parse(hiding.as_bytes()).unwrap().text("Texture"), Some("1"), "a blank repeat does not win");
}
#[test]
+36 -9
View File
@@ -764,20 +764,32 @@ mod tests {
/// Sizes the digests were taken at: wide, tall and square.
const GOLD_SIZES: [(f64, f64); 4] = [(120.0, 80.0), (300.0, 50.0), (64.0, 64.0), (50.0, 300.0)];
/// `v` as the digest prints it: a value that prints as zero at 3 decimal places becomes
/// `0.0`, so a residue such as `-1.4e-14` left by a sine or cosine of a right angle prints
/// `0.000` whatever its sign. Its sign depends on the platform's libm, and `{:.3}` prints a
/// negative residue as `-0.000`.
fn digest_coord(v: f64) -> f64 {
if v.abs() < 0.0005 { 0.0 } else { v }
}
/// FNV-1a over each outline's path elements, for every adjust set and size. Coordinates are
/// printed to 3 decimal places so last-bit libm differences between platforms do not change it.
/// printed to 3 decimal places through [`digest_coord`] so last-bit libm differences between
/// platforms do not change it.
fn outline_digest(name: &str) -> u64 {
use std::fmt::Write;
let c = digest_coord;
let mut text = String::new();
for adj in GOLD_ADJ {
for (w, h) in GOLD_SIZES {
let g = build(name, w, h, adj).unwrap_or_else(|| panic!("{name} builds no outline"));
for el in g.outline().elements() {
let _ = match *el {
PathEl::MoveTo(p) => write!(text, "M{:.3},{:.3}", p.x, p.y),
PathEl::LineTo(p) => write!(text, "L{:.3},{:.3}", p.x, p.y),
PathEl::QuadTo(a, p) => write!(text, "Q{:.3},{:.3},{:.3},{:.3}", a.x, a.y, p.x, p.y),
PathEl::CurveTo(a, b, p) => write!(text, "C{:.3},{:.3},{:.3},{:.3},{:.3},{:.3}", a.x, a.y, b.x, b.y, p.x, p.y),
PathEl::MoveTo(p) => write!(text, "M{:.3},{:.3}", c(p.x), c(p.y)),
PathEl::LineTo(p) => write!(text, "L{:.3},{:.3}", c(p.x), c(p.y)),
PathEl::QuadTo(a, p) => write!(text, "Q{:.3},{:.3},{:.3},{:.3}", c(a.x), c(a.y), c(p.x), c(p.y)),
PathEl::CurveTo(a, b, p) => {
write!(text, "C{:.3},{:.3},{:.3},{:.3},{:.3},{:.3}", c(a.x), c(a.y), c(b.x), c(b.y), c(p.x), c(p.y))
}
PathEl::ClosePath => write!(text, "Z"),
};
}
@@ -789,21 +801,23 @@ mod tests {
/// Digests of every name's outlines as the string dispatch built them (craft-libs 2b35d243;
/// DeckCraft's fc35ad67 gave other digests for curvedRightArrow and curvedDownArrow), so
/// this refactor is proven output-identical: any changed outline fails here.
/// this refactor is proven output-identical: any changed outline fails here. pieWedge,
/// curvedRightArrow and curvedDownArrow were taken again when [`digest_coord`] began printing
/// their near-zero residues as `0.000`; their outlines are unchanged.
const GOLDEN: [(&str, u64); 38] = [
("lineInv", 0x4a58a16923e54a4f),
("nonIsoscelesTrapezoid", 0x79eca0b36812e282),
("pieWedge", 0x2a0d3ffe5e9a481d),
("pieWedge", 0x5fb58e0214989f4d),
("leftRightArrowCallout", 0x9cd88f0ab55f76e5),
("upDownArrowCallout", 0x568bc91708855007),
("quadArrowCallout", 0xca59015298b1584b),
("circularArrow", 0x4227aa468cfe990e),
("leftCircularArrow", 0x6fc3779ce4b08914),
("leftRightCircularArrow", 0x9dd43d9ba80e47df),
("curvedRightArrow", 0x83e7dd251401715d),
("curvedRightArrow", 0xf60d53e01a88930c),
("curvedLeftArrow", 0x82472848de4a9fec),
("curvedUpArrow", 0xcfbd88c1aea4bf9d),
("curvedDownArrow", 0xa6f75eaf0ee71d49),
("curvedDownArrow", 0x01b1ac2f13de11b9),
("swooshArrow", 0x63ff193fdf1d0427),
("callout1", 0xe7e0410f96282e8d),
("callout2", 0xcaa7730106a9ee1b),
@@ -831,6 +845,19 @@ mod tests {
("chartPlus", 0x979031aae16250d7),
];
/// A near-zero residue prints the same whichever sign the platform's libm left on it, and
/// values that round away from zero keep their sign.
#[test]
fn digest_prints_near_zero_residues_without_a_sign() {
let print = |v: f64| format!("{:.3}", digest_coord(v));
for v in [-1.4210854715202004e-14, 1.4210854715202004e-14, -7.105427357601002e-15, -0.0, 0.0, -0.00049, 0.00049] {
assert_eq!(print(v), "0.000", "{v:e}");
}
assert_eq!(print(-0.0006), "-0.001");
assert_eq!(print(-12.25), "-12.250");
assert_eq!(print(0.0006), "0.001");
}
/// Every name builds the same outline as before the `Name` enum, and unknown names build nothing.
#[test]
fn outlines_match_the_string_dispatch() {
+9
View File
@@ -293,6 +293,14 @@ pub fn setup(setup: &Setup, op: &Operation, first: bool) -> Vec<Command> {
/// Registration-mark commands: mark geometry, then the search (or manual positioning) request.
/// The device answers ` 0\x03` (see [`parse_status`]) once it has the marks.
///
/// The full registration sequence (TB99 through TB55, plus TB123/TB124 for search and
/// TB23 for manual positioning) is documented in the community driver [py_silhouette]
/// (`zero_on_registration_mark()`), which reverse-engineered the protocol from public
/// behaviour — not from any proprietary binary. The `TB54,0,0` sub-command sets the
/// registration-mark offset to zero (the mark is at its expected position).
///
/// [py_silhouette]: https://github.com/mossblaser/py_silhouette/blob/main/py_silhouette/device.py
pub fn registration(reg: &Registration) -> Vec<Command> {
let raw = |s: &str| Command::Raw(s.to_string());
let mut c = vec![
@@ -302,6 +310,7 @@ pub fn registration(reg: &Registration) -> Vec<Command> {
raw("TB52,2"),
raw("TB51,400"),
raw("TB53,10"),
raw("TB54,0,0"),
raw("TB55,1"),
];
let (h, w) = (su(reg.length_mm), su(reg.width_mm));