fix(anatomy): V1-2.2 reserve the PDF halo id in the reader and composers

A drawing defining filter#osteo-halo replaced the PDF halo (a transparent
filter erased the marker); an element holding the id before the first
defs won its resolution. The reader refuses the id in any letter case
(reserved_id), both composers refuse such a tree, the halo is always the
engine's. Exact name only: osteo-overlays stays.
This commit is contained in:
bchanot committed 2026-10-30 17:30:48 +01:00
1 parent 2f1f0764bf
commit 08efd9a792
13 files changed
+781 -34

No files matched your search

+112 -2
View File
@@ -13,11 +13,14 @@ use std::collections::HashSet;
use common::r4::{r4_oracle, repo_root, sha256_hex};
use faunosteo_core::anatomy::compose::{asset_id_of_view, compose_highlight};
use faunosteo_core::anatomy::svg::{read_svg, serialize::serialize};
use faunosteo_core::anatomy::svg::tree::parse_svg;
use faunosteo_core::anatomy::svg::{Element, read_svg, serialize::serialize};
use faunosteo_core::domain::js::parse_json;
use faunosteo_core::pdf::read::probe::{ProbeLimits, read_attached_document};
use faunosteo_core::pdf::write::export::export_pdf;
use faunosteo_core::pdf::write::input::{ExportInput, ExportWarning, LogoSlot, Rasters};
use faunosteo_core::pdf::write::input::{
ExportError, ExportErrorKind, ExportInput, ExportWarning, LogoSlot, Rasters,
};
use faunosteo_core::pdf::write::session::{
ExportSession, ExportStep, SessionError, SessionRefusal, keyed,
};
@@ -380,3 +383,110 @@ fn the_one_shot_driver_reports_absent_rasters_as_failed() {
]
);
}
/// The demo export's input as JSON, before it is typed.
fn demo_value() -> Value {
let pdf = fixture("pdf/r3/demo.fr.logos.pdf");
let located = read_attached_document(&pdf, ProbeLimits::UNBOUNDED).unwrap();
let envelope: Value = parse_json(&located.text).unwrap();
json!({
"report": envelope["report"],
"sheetSnapshot": envelope["sheetSnapshot"],
"branding": envelope["branding"],
"labels": envelope["labels"],
"locale": envelope["locale"],
"exportedAt": envelope["exportedAt"],
})
}
/// The demo export's snapshot with `edit` applied to its first drawing.
fn export_with_drawing(edit: impl Fn(&str) -> String) -> Result<ExportSession, ExportError> {
let mut input = demo_value();
let svg = input["sheetSnapshot"]["assets"][0]["svg"].as_str().unwrap();
input["sheetSnapshot"]["assets"][0]["svg"] = json!(edit(svg));
ExportSession::new(serde_json::from_value(input).unwrap())
}
/// The first drawing with `body` written right after its root's opening tag.
fn inject(body: &'static str) -> impl Fn(&str) -> String {
move |svg: &str| {
let open = svg.find("<svg").unwrap();
let end = open + svg[open..].find('>').unwrap() + 1;
format!("{}{body}{}", &svg[..end], &svg[end..])
}
}
/// V1-2.2 owner brief 2026-10-30 (reserved ids, `tests/svg_reserved_ids.rs`): a snapshot
/// drawing holding the reserved id is refused at the gate (`snapshot_invalid`, `asset
/// reserved_id`), never composed; the demo export's views carry the engine's halo filter once,
/// and every highlighted marker names it.
#[test]
fn the_pdf_refuses_a_reserved_id_and_keeps_its_own_halo() {
for body in [
"<filter id=\"osteo-halo\"><feColorMatrix type=\"matrix\" values=\"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\"/></filter>",
"<g id=\"osteo-halo\"/><defs/>",
"<g id=\"Osteo-Halo\"/>",
] {
match export_with_drawing(inject(body)) {
Err(error) => {
assert_eq!(error.kind, ExportErrorKind::SnapshotInvalid, "{body}");
assert_eq!(error.detail, "asset reserved_id", "{body}");
}
Ok(_) => panic!("{body}: composed"),
}
}
let mut session = export_with_drawing(str::to_owned).unwrap();
let png = base64(TWO_BY_ONE_PNG);
let mut haloed_views = 0;
while let ExportStep::Rasters { requests } = session.next_step().unwrap() {
for request in requests {
let root = parse_svg(&request.svg).unwrap();
let mut halos = Vec::new();
holders(&root, "osteo-halo", &mut halos);
if request.key.starts_with("view:") && request.svg.contains("url(#osteo-halo)") {
haloed_views += 1;
assert_eq!(halos.len(), 1, "{}", request.key);
assert_eq!(halos[0].qname, "filter", "{}", request.key);
assert_eq!(
serialize(halos[0]),
concat!(
"<filter xmlns=\"http://www.w3.org/2000/svg\" id=\"osteo-halo\" x=\"-100%\" y=\"-100%\" width=\"300%\" ",
"height=\"300%\" filterUnits=\"userSpaceOnUse\">",
"<feGaussianBlur in=\"SourceGraphic\" stdDeviation=\"18\" result=\"haloWide\"/>",
"<feGaussianBlur in=\"SourceGraphic\" stdDeviation=\"8\" result=\"haloTight\"/>",
"<feMerge><feMergeNode in=\"haloWide\"/><feMergeNode in=\"haloWide\"/>",
"<feMergeNode in=\"haloWide\"/><feMergeNode in=\"haloTight\"/>",
"<feMergeNode in=\"haloTight\"/><feMergeNode in=\"SourceGraphic\"/></feMerge>",
"</filter>"
),
"{}",
request.key
);
let layer = root.element_children().last().unwrap();
assert!(layer.element_children().count() > 0, "{}", request.key);
for marker in layer.element_children() {
assert_eq!(marker.attr("filter"), Some("url(#osteo-halo)"));
assert_eq!(marker.attr("fill"), Some("#b85a3f"));
}
} else {
assert!(halos.is_empty(), "{}", request.key);
}
session.add_raster(&request.key, &png).unwrap();
}
}
assert!(haloed_views > 0);
session.finish().unwrap();
assert!(session.take_part().unwrap().starts_with(b"%PDF-1.7"));
assert!(session.warnings().is_empty());
}
/// Every element holding `id`, in document order.
fn holders<'a>(element: &'a Element, id: &str, out: &mut Vec<&'a Element>) {
if element.attr("id") == Some(id) {
out.push(element);
}
for child in element.element_children() {
holders(child, id, out);
}
}