Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 154 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ image = { version = "0.25", default-features = false, features = ["png", "jpeg"]
encoding_rs = "0.8.35"
# XML for the SVG reader (streaming parser, no entity expansion beyond the five predefined ones)
quick-xml = "0.42"
# PDF page rendering for PDF underlays: the craft apps' shared, patched Hayro reader, at
# craft-pdf's revision (pure Rust; no embedded fonts: the 14 standard PDF fonts are not
# bundled, a PDF that relies on them without embedding them shows no text).
hayro = { version = "=0.7.1", default-features = false }

# ui
craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "6e7f28518dd1cb57e1624bdc269c3c14316b13ae", features = ["serde"] }
Expand All @@ -65,6 +69,10 @@ arboard = { version = "3.6", default-features = false }
krilla = { version = "=0.8.2", git = "https://github.com/storytold/craft-libs", rev = "6e7f28518dd1cb57e1624bdc269c3c14316b13ae" }
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "6e7f28518dd1cb57e1624bdc269c3c14316b13ae" }
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "6e7f28518dd1cb57e1624bdc269c3c14316b13ae" }
hayro = { git = "https://github.com/storytold/craft-libs", rev = "6e7f28518dd1cb57e1624bdc269c3c14316b13ae" }
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "6e7f28518dd1cb57e1624bdc269c3c14316b13ae" }
hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "6e7f28518dd1cb57e1624bdc269c3c14316b13ae" }
hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "6e7f28518dd1cb57e1624bdc269c3c14316b13ae" }

[workspace.lints.rust]
unsafe_code = "forbid"
Expand Down
21 changes: 18 additions & 3 deletions apps/cadcraft-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ fn install_io() {
groups: cadcraft_io::entity_groups,
entity: cadcraft_io::entity_from_groups,
});
// PDF underlays (PDFATTACH) read their pages.
cadcraft_engine::cmd::underlay::set_pdf(cadcraft_engine::cmd::underlay::PdfHooks {
page: cadcraft_io::pdf_read::page_info,
render: cadcraft_io::pdf_read::render_page,
region: cadcraft_io::pdf_read::render_page_region,
layers: cadcraft_io::pdf_layers::layer_list,
with_layers: cadcraft_io::pdf_layers::apply_layers,
});
}

fn open(s: &mut Session, path: &str) -> Result<(), String> {
Expand Down Expand Up @@ -293,12 +301,19 @@ fn convert(args: &[String]) -> Result<(), String> {
}

/// The warning for the model-space entities of `path` an image can't show, by type (those kept
/// as unknown objects, `Proxy` in `info`), or `None` when there are none.
/// as unknown objects, `Proxy` in `info`, and PDF underlays, whose page isn't plotted), or `None`
/// when there are none.
fn undrawn_message(d: &cadcraft_engine::doc::Drawing, path: &str) -> Option<String> {
let mut types: std::collections::BTreeMap<&str, usize> = std::collections::BTreeMap::new();
for e in d.model.iter() {
if let cadcraft_engine::doc::EntityKind::Unknown(u) = &e.kind {
let n = types.entry(u.dxf_type.as_str()).or_insert(0);
// PDF underlays' pages aren't plotted yet: only their frame is.
let undrawn = match &e.kind {
cadcraft_engine::doc::EntityKind::Unknown(u) => Some(u.dxf_type.as_str()),
cadcraft_engine::doc::EntityKind::PdfUnderlay(_) => Some("PDFUNDERLAY"),
_ => None,
};
if let Some(t) = undrawn {
let n = types.entry(t).or_insert(0);
*n = n.saturating_add(1);
}
}
Expand Down
6 changes: 4 additions & 2 deletions apps/cadcraft-cli/tests/it/undrawn_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ fn cli(args: &[&str]) -> Output {
Command::new(env!("CARGO_BIN_EXE_cadcraft-cli")).args(args).output().unwrap()
}

/// A line, two foreign REGIONs and a PDF underlay: the last three are kept as unknown entities.
/// A line, two foreign REGIONs, kept as unknown entities, and a PDF underlay, whose page an image
/// doesn't draw yet.
const PROXIES: &str = "0\nSECTION\n2\nENTITIES\n\
0\nLINE\n8\n0\n10\n0\n20\n0\n11\n5\n21\n5\n\
0\nREGION\n8\n0\n70\n1\n1\nabc\n\
Expand All @@ -25,7 +26,8 @@ fn convert_to_an_image_warns_about_entities_it_cannot_draw() {

let out = cli(&["info", input]);
let v: serde_json::Value = serde_json::from_slice(&out.stdout).unwrap();
assert_eq!(v["counts"]["Proxy"], 3, "{v}");
assert_eq!(v["counts"]["Proxy"], 2, "{v}");
assert_eq!(v["counts"]["PDF Underlay"], 1, "{v}");

for ext in ["svg", "png", "pdf"] {
let image = dir.join(format!("out.{ext}"));
Expand Down
8 changes: 8 additions & 0 deletions apps/cadcraft-web/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ mod web {
groups: cadcraft_io::entity_groups,
entity: cadcraft_io::entity_from_groups,
});
// PDF underlays (PDFATTACH) read their pages.
cadcraft_engine::cmd::underlay::set_pdf(cadcraft_engine::cmd::underlay::PdfHooks {
page: cadcraft_io::pdf_read::page_info,
render: cadcraft_io::pdf_read::render_page,
region: cadcraft_io::pdf_read::render_page_region,
layers: cadcraft_io::pdf_layers::layer_list,
with_layers: cadcraft_io::pdf_layers::apply_layers,
});
// `?host=parent`: a same-origin page framing CADCraft (such as a Nextcloud app) opens
// drawings in it and stores what it saves. Otherwise there is no file system here: saved
// files reach the user as browser downloads.
Expand Down
15 changes: 15 additions & 0 deletions apps/cadcraft/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ pub fn install_io() {
groups: cadcraft_io::entity_groups,
entity: cadcraft_io::entity_from_groups,
});
// PDF underlays (PDFATTACH) read their pages.
cadcraft_engine::cmd::underlay::set_pdf(cadcraft_engine::cmd::underlay::PdfHooks {
page: cadcraft_io::pdf_read::page_info,
render: cadcraft_io::pdf_read::render_page,
region: cadcraft_io::pdf_read::render_page_region,
layers: cadcraft_io::pdf_layers::layer_list,
with_layers: cadcraft_io::pdf_layers::apply_layers,
});
}

fn services() -> Services {
Expand All @@ -150,6 +158,13 @@ fn services() -> Services {
dialog.pick_file().map(|p| p.to_string_lossy().to_string())
})),
no_file_system: false,
pick_pdf: Some(Box::new(|| {
rfd::FileDialog::new()
.add_filter(i18n::t("PDF files"), &["pdf"])
.add_filter(i18n::t("All files"), &["*"])
.pick_file()
.map(|p| p.to_string_lossy().to_string())
})),
}
}

Expand Down
3 changes: 3 additions & 0 deletions contributors/people.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,6 @@ sync_github_name = false
real_name = "Robert Lee"
sync_github_name = true

[people.ATARYS-LAB]
display_name = "Julien - ATARYS"
sync_github_name = false
Loading