mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-01 10:13:09 -06:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f17b53970 | ||
|
|
17655fe628 | ||
|
|
127bb2e8d4 |
@@ -1,69 +0,0 @@
|
||||
# Accessibility
|
||||
|
||||
Source: `standards/app-accessibility.md` in [storytold/craft-contrib](https://github.com/storytold/craft-contrib/blob/main/standards/app-accessibility.md); do not edit this copy directly. Propose changes to the shared statement in [`storytold/craft-contrib`](https://github.com/storytold/craft-contrib).
|
||||
|
||||
We want people who use screen readers, braille displays, screen magnifiers, voice control, high contrast, large text, reduced motion, or keyboard navigation to be able to get their work done in the Craft applications.
|
||||
|
||||
## Supported environments and how accessibility works
|
||||
|
||||
The Craft applications draw their own interface in Rust with `egui` and expose accessibility information through **AccessKit**:
|
||||
|
||||
- **Windows:** UI Automation (for tools such as NVDA, JAWS, and Narrator)
|
||||
- **macOS:** NSAccessibility (VoiceOver)
|
||||
- **Linux and FreeBSD:** AT-SPI (Orca)
|
||||
- **Web (WebAssembly):** Browser accessibility tree in modern evergreen browsers
|
||||
- **Display and motion:** Light and dark themes, along with ongoing work to honour system high-contrast, text-scaling, and reduced-motion settings
|
||||
- **Headless and command-line workflows:** Most Craft applications also ship a command-line and automation binary (`<app>-cli`) that can inspect and edit documents from a terminal without using the graphical interface; see [This application](#this-application) below
|
||||
|
||||
**Current status:** The Craft suite is in early-alpha development. We use WCAG 2.2 and W3C's [WCAG2ICT](https://www.w3.org/TR/wcag2ict-22/) as practical reference points for user needs ([RFC-0014](https://github.com/storytold/craft-contrib/blob/main/rfcs/0014-accessibility.md)), while manual testing with assistive technologies across every tool and surface is still in progress.
|
||||
|
||||
## Known limitations and workarounds
|
||||
|
||||
Shared framework improvements are tracked in [storytold/craft-libs#437](https://github.com/storytold/craft-libs/issues/437). Current suite-wide gaps include:
|
||||
|
||||
- **Custom drawn surfaces (canvases, pages, grids, timelines, node graphs, and layer lists):** Some custom-painted views do not yet publish complete `AccessKit` nodes, caret bounds for magnifiers, or editable states (for example, `AccessKit`'s Windows adapter reporting `Document` nodes as read-only, which can prevent typing echo in screen readers). *Workaround:* Use structured inspector panels where available, or run headless commands through `<app>-cli` when a task does not need direct canvas interaction.
|
||||
- **Focus in menus, toolbars, and dialogs:** Some popups, menus, or keyboard access-key overlays may leave focus in the underlying document or not yet restore focus cleanly when dismissed. *Workaround:* Press `Escape` to close open popups, `Alt` or `F10` for menu/toolbar navigation, and `F6` to move between major regions where supported.
|
||||
- **Unannounced state changes:** Shortcuts or background tasks that change state away from focus do not yet consistently announce updates through a live region.
|
||||
- **Pointer-heavy interactions:** Certain timeline, node-wiring, or object-placement gestures do not yet have non-dragging keyboard alternatives.
|
||||
|
||||
See [This application](#this-application) below for repository-specific links and details.
|
||||
|
||||
## Reporting an accessibility barrier
|
||||
|
||||
If you run into an accessibility barrier, please open an issue using the link in [This application](#this-application) below (or let us know in the [ArtCraft Discord](https://discord.gg/artcraft) if GitHub's issue form gets in the way).
|
||||
|
||||
- **No personal disclosure needed:** You never have to disclose a disability or explain why you use assistive technology.
|
||||
- **Screenshots and recordings are optional:** Plain-text descriptions are always welcome and sufficient.
|
||||
- **Helpful details to share (when convenient):**
|
||||
- What you were trying to do, what happened, and what you expected
|
||||
- Application version (or commit) and operating system or browser
|
||||
- Input method, display settings, or assistive technology and version (for example, NVDA, JAWS, Narrator, VoiceOver, Orca, screen magnifier, high contrast, text scaling, or keyboard-only)
|
||||
|
||||
## How we respond
|
||||
|
||||
- **Triage and labels:** Maintainers and triagers label barrier reports with `accessibility` and set priority during triage based on impact—barriers that block a core workflow are treated as high-priority bugs, and barriers that risk losing work are critical.
|
||||
- **Assistive-technology verification (`needs screen reader test`):** Pull requests that fix a reported assistive-technology barrier or add custom accessibility-tree or focus behaviour are labelled `needs screen reader test` so someone using assistive technology can verify a build and share what they observed; if the barrier remains, we reopen the issue.
|
||||
|
||||
## Note for contributors and coding agents
|
||||
|
||||
`ACCESSIBILITY.md` is a user-facing overview, **not** an extra rule set or audit checklist for coding agents:
|
||||
|
||||
- **Follow `AGENTS.md` and [`standards/accessibility.md`](https://github.com/storytold/craft-contrib/blob/main/standards/accessibility.md) for engineering work,** and keep every pull request scoped strictly to its issue. Do not widen an unrelated change to audit or rework surrounding UI.
|
||||
- **Design for the actual user need—do not overbuild or apply naive readings of standards.** Accessibility guidelines exist to support real workflows and give flexible ways to meet them. Understand what a criterion genuinely requires in context before changing UI: for example, a button whose label or icon is legible and whose focus or selection ring already has clear contrast does **not** need its resting fill or border restyled to hit a 3:1 ratio, and inherently spatial or freehand tools should not have artificial keyboard grids bolted onto them.
|
||||
- **Preserve visual design and shared primitives.** Use shared theme tokens and shared widgets from `storytold/craft-libs` instead of inventing one-off styling, contrast overrides, focus shims, or live-region scaffolding inside an application.
|
||||
- **Be candid in pull requests.** Automated accessibility-tree checks never prove a change works with a real screen reader; describe only what was actually verified.
|
||||
|
||||
## Ownership
|
||||
|
||||
Maintained by the `craft-app-team` maintainers in [`storytold`](https://github.com/storytold). Shared updates belong in [`storytold/craft-contrib`](https://github.com/storytold/craft-contrib); repository-specific facts follow below.
|
||||
|
||||
## This application
|
||||
|
||||
**DeckCraft** (`storytold/deckcraft`) is an open-source presentation and slide-show editor written in pure Rust.
|
||||
|
||||
- **Published application builds:** macOS, Windows, Linux, FreeBSD, and Web (WebAssembly)
|
||||
- **Command-line and automation interface:** `deckcraft-cli` provides headless terminal and automation access for scripted workflows without the graphical interface
|
||||
- **Report an accessibility barrier:** [Open an issue in `storytold/deckcraft`](https://github.com/storytold/deckcraft/issues/new)
|
||||
- **Tracked accessibility issues:** [Open issues labelled `accessibility` in `storytold/deckcraft`](https://github.com/storytold/deckcraft/issues?q=is%3Aissue+state%3Aopen+label%3Aaccessibility)
|
||||
- **Pull requests awaiting assistive-technology verification:** [Pull requests labelled `needs screen reader test` in `storytold/deckcraft`](https://github.com/storytold/deckcraft/pulls?q=is%3Apr+label%3A%22needs+screen+reader+test%22)
|
||||
- **Contributor and agent rules for this repository:** [`AGENTS.md`](AGENTS.md)
|
||||
Generated
+45
-59
@@ -220,9 +220,6 @@ name = "arbitrary"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3bc62ac97cc33321f50863d514c3bc38a453947a8f9e781137e47c7401020aed"
|
||||
dependencies = [
|
||||
"derive_arbitrary",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arboard"
|
||||
@@ -240,7 +237,7 @@ dependencies = [
|
||||
"objc2-foundation 0.3.2",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
"wl-clipboard-rs",
|
||||
"x11rb",
|
||||
]
|
||||
@@ -817,6 +814,15 @@ dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "constant_time_eq"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9eb6feb175df65d0a3ccd3e73484e940d0ac664e8034f0519fd49a93db3071d9"
|
||||
dependencies = [
|
||||
"rustversion",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.4"
|
||||
@@ -964,7 +970,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
"zip 9.1.0",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1131,7 +1137,7 @@ dependencies = [
|
||||
"verifysign",
|
||||
"winreg",
|
||||
"winsafe",
|
||||
"zip 9.1.0",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1182,7 +1188,7 @@ source = "git+https://github.com/storytold/craft-libs?rev=254e9a409b410dc93c0e06
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
"zip 9.1.0",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1192,7 +1198,7 @@ source = "git+https://github.com/storytold/craft-libs?rev=8048f8ef92da80fb3ce5a0
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
"zip 9.1.0",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1304,7 +1310,7 @@ dependencies = [
|
||||
"deckcraft-engine",
|
||||
"deckcraft-mcp",
|
||||
"serde_json",
|
||||
"zip 3.0.0",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1339,7 +1345,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
"zip 3.0.0",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1362,7 +1368,7 @@ dependencies = [
|
||||
"craft-rtf",
|
||||
"deckcraft-model",
|
||||
"serde_json",
|
||||
"zip 3.0.0",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1461,7 +1467,7 @@ dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
"zip 3.0.0",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1548,17 +1554,6 @@ version = "0.5.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e"
|
||||
|
||||
[[package]]
|
||||
name = "derive_arbitrary"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b034bd7d5f032402a2479444dcc6f74e36a03f31854d41680fb240ef682a1ac"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dify"
|
||||
version = "0.8.0"
|
||||
@@ -1940,7 +1935,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3363,7 +3358,7 @@ version = "0.50.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
|
||||
dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3866,7 +3861,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.45.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4518,7 +4513,7 @@ dependencies = [
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys 0.12.1",
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4575,7 +4570,7 @@ dependencies = [
|
||||
"security-framework",
|
||||
"security-framework-sys",
|
||||
"webpki-root-certs",
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5255,10 +5250,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"getrandom 0.3.4",
|
||||
"getrandom 0.4.3",
|
||||
"once_cell",
|
||||
"rustix 1.1.5",
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6220,7 +6215,7 @@ version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||
dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6924,6 +6919,20 @@ name = "zeroize"
|
||||
version = "1.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879"
|
||||
dependencies = [
|
||||
"zeroize_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zeroize_derive"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerotrie"
|
||||
@@ -6964,32 +6973,21 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zip"
|
||||
version = "3.0.0"
|
||||
version = "9.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12598812502ed0105f607f941c386f43d441e00148fce9dec3ca5ffb0bde9308"
|
||||
dependencies = [
|
||||
"arbitrary",
|
||||
"crc32fast",
|
||||
"flate2",
|
||||
"indexmap",
|
||||
"memchr",
|
||||
"zopfli",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zip"
|
||||
version = "9.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2886b00003a72c4ccee3f42cfc34908d33b2508a74d827dc2a4244706475c704"
|
||||
checksum = "2d8dbe089cf6b0448b78f5fc50139ab5aaa40d08ac07cdc1baf2c13add35fcce"
|
||||
dependencies = [
|
||||
"constant_time_eq",
|
||||
"crc32fast",
|
||||
"flate2",
|
||||
"getrandom 0.4.3",
|
||||
"indexmap",
|
||||
"libc",
|
||||
"memchr",
|
||||
"nix",
|
||||
"typed-path",
|
||||
"windows-sys 0.61.2",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7004,18 +7002,6 @@ version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
||||
|
||||
[[package]]
|
||||
name = "zopfli"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"crc32fast",
|
||||
"log",
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zune-core"
|
||||
version = "0.5.3"
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.
|
||||
craft-ui = { git = "https://github.com/storytold/craft-libs", rev = "63196e66f3033a6623eb629af95a104d26986725", version = "=0.1.0" }
|
||||
i_overlay = "9"
|
||||
quick-xml = "0.41"
|
||||
zip = { version = "3", default-features = false, features = ["deflate"] }
|
||||
zip = { version = "=9.8.2", default-features = false, features = ["deflate-flate2"] }
|
||||
miniz_oxide = { version = "0.9", default-features = false, features = ["with-alloc"] }
|
||||
|
||||
# ui
|
||||
|
||||
@@ -24,10 +24,10 @@ fn without_slide2(deck: &[u8]) -> Vec<u8> {
|
||||
let mut f = zin.by_index(i).unwrap();
|
||||
let mut data = vec![];
|
||||
f.read_to_end(&mut data).unwrap();
|
||||
if f.name() == "ppt/slides/slide2.xml" {
|
||||
if f.name().expect("ZIP member name") == "ppt/slides/slide2.xml" {
|
||||
data = b"<p:sld".to_vec();
|
||||
}
|
||||
out.start_file(f.name(), options).unwrap();
|
||||
out.start_file(f.name().expect("ZIP member name"), options).unwrap();
|
||||
out.write_all(&data).unwrap();
|
||||
}
|
||||
out.finish().unwrap().into_inner()
|
||||
|
||||
@@ -232,7 +232,7 @@ mod font_script_tests {
|
||||
let mut xml = String::new();
|
||||
for i in 0..zip.len() {
|
||||
let mut f = zip.by_index(i).unwrap();
|
||||
if f.name().starts_with("ppt/slides/slide") && f.name().ends_with(".xml") {
|
||||
if f.name().expect("ZIP member name").starts_with("ppt/slides/slide") && f.name().expect("ZIP member name").ends_with(".xml") {
|
||||
std::io::Read::read_to_string(&mut f, &mut xml).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -311,7 +311,7 @@ mod font_script_tests {
|
||||
let mut xml = String::new();
|
||||
for i in 0..zip.len() {
|
||||
let mut f = zip.by_index(i).unwrap();
|
||||
if f.name().starts_with("ppt/slides/slide") && f.name().ends_with(".xml") {
|
||||
if f.name().expect("ZIP member name").starts_with("ppt/slides/slide") && f.name().expect("ZIP member name").ends_with(".xml") {
|
||||
std::io::Read::read_to_string(&mut f, &mut xml).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4494,7 +4494,7 @@ fn smartart_round_trips_through_pptx_as_a_diagram() {
|
||||
let bytes = deckcraft_pptx::export(&doc).unwrap();
|
||||
let names: Vec<String> = {
|
||||
let z = zip::ZipArchive::new(std::io::Cursor::new(&bytes)).unwrap();
|
||||
z.file_names().map(String::from).collect()
|
||||
z.file_names().map(|name| name.expect("ZIP member name")).map(String::from).collect()
|
||||
};
|
||||
for part in ["data1", "layout1", "quickStyle1", "colors1", "drawing1"] {
|
||||
assert!(names.iter().any(|n| n == &format!("ppt/diagrams/{part}.xml")), "{part} in {names:?}");
|
||||
@@ -6104,10 +6104,10 @@ fn opening_a_pptx_with_an_unreadable_slide_says_so() {
|
||||
let mut f = zin.by_index(i).unwrap();
|
||||
let mut d = vec![];
|
||||
f.read_to_end(&mut d).unwrap();
|
||||
if f.name() == "ppt/slides/slide2.xml" {
|
||||
if f.name().expect("ZIP member name") == "ppt/slides/slide2.xml" {
|
||||
d = b"<p:sld".to_vec();
|
||||
}
|
||||
out.start_file(f.name(), o).unwrap();
|
||||
out.start_file(f.name().expect("ZIP member name"), o).unwrap();
|
||||
out.write_all(&d).unwrap();
|
||||
}
|
||||
let broken = out.finish().unwrap().into_inner();
|
||||
|
||||
@@ -102,7 +102,7 @@ fn pptx_native_edit_save_reopen_keeps_chart_parts() {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let mut data = vec![];
|
||||
f.read_to_end(&mut data).expect("read");
|
||||
payloads.push((f.name().to_string(), data));
|
||||
payloads.push((f.name().expect("ZIP member name").to_string(), data));
|
||||
}
|
||||
assert!(payloads.iter().any(|(n, d)| n.starts_with("ppt/embeddings/") && d == WORKBOOK));
|
||||
assert!(payloads.iter().any(|(n, d)| n.starts_with("ppt/drawings/") && d == DRAWING));
|
||||
|
||||
@@ -91,7 +91,7 @@ fn with_timing(bytes: &[u8], clicks: impl Fn(&mut u32, &str, &str) -> Vec<String
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
for i in 0..src.len() {
|
||||
let mut f = src.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
let mut data = Vec::new();
|
||||
f.read_to_end(&mut data).expect("read");
|
||||
if name == "ppt/slides/slide1.xml" {
|
||||
|
||||
@@ -53,7 +53,7 @@ fn rewrite_manifest(bytes: &[u8], edit: impl FnOnce(&mut Value)) -> Vec<u8> {
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let f = z.by_index(i).unwrap();
|
||||
if f.name() == "presentation.json" {
|
||||
if f.name().expect("ZIP member name") == "presentation.json" {
|
||||
out.start_file("presentation.json", zip::write::SimpleFileOptions::default()).unwrap();
|
||||
out.write_all(&serde_json::to_vec(&json).unwrap()).unwrap();
|
||||
} else {
|
||||
@@ -120,7 +120,7 @@ fn chart_payloads_in_every_shape_owner_get_distinct_entries() {
|
||||
p.handout_master = Some(Arc::new(Master { shapes, ..Default::default() }));
|
||||
let bytes = save(&p).unwrap();
|
||||
let z = zip::ZipArchive::new(Cursor::new(bytes.as_slice())).unwrap();
|
||||
assert_eq!(z.file_names().filter(|name| name.starts_with("chart-parts/")).count(), 5);
|
||||
assert_eq!(z.file_names().map(|name| name.expect("ZIP member name")).filter(|name| name.starts_with("chart-parts/")).count(), 5);
|
||||
assert_eq!(load(&bytes).unwrap(), p);
|
||||
}
|
||||
|
||||
@@ -131,11 +131,11 @@ fn missing_or_corrupt_chart_payload_is_reported() {
|
||||
let mut z = zip::ZipArchive::new(Cursor::new(bytes.as_slice())).unwrap();
|
||||
let mut json: Value = serde_json::from_slice(&read_entry(&mut z, "presentation.json").unwrap()).unwrap();
|
||||
let name = part_json(&mut json).unwrap()["nativeEntry"].as_str().unwrap().to_owned();
|
||||
let start = z.by_name(&name).unwrap().data_start() as usize;
|
||||
let start = z.by_name(&name).unwrap().data_start().expect("member data offset") as usize;
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let f = z.by_index(i).unwrap();
|
||||
if f.name() != name {
|
||||
if f.name().expect("ZIP member name") != name {
|
||||
out.raw_copy_file(f).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -200,7 +200,7 @@ fn corrupt_chart_members_stop_before_reusing_the_inflation_budget() {
|
||||
let mut bytes = save(&with_two_parts()).unwrap();
|
||||
let offsets: Vec<_> = {
|
||||
let mut z = zip::ZipArchive::new(Cursor::new(bytes.as_slice())).unwrap();
|
||||
(0..2).map(|i| z.by_name(&format!("chart-parts/{i}")).unwrap().data_start() as usize).collect()
|
||||
(0..2).map(|i| z.by_name(&format!("chart-parts/{i}")).unwrap().data_start().expect("member data offset") as usize).collect()
|
||||
};
|
||||
for offset in offsets {
|
||||
bytes[offset] ^= 0xff;
|
||||
@@ -227,7 +227,7 @@ fn duplicate_physical_zip_names_are_indexed_and_inflated_once() {
|
||||
}
|
||||
assert_eq!(replaced, 2);
|
||||
let z = zip::ZipArchive::new(Cursor::new(bytes.as_slice())).unwrap();
|
||||
assert_eq!(z.file_names().filter(|n| n.starts_with("chart-parts/")).count(), 1);
|
||||
assert_eq!(z.file_names().map(|name| name.expect("ZIP member name")).filter(|n| n.starts_with("chart-parts/")).count(), 1);
|
||||
let (q, damaged) = load_within(&bytes, Budget::media(10, 2)).unwrap();
|
||||
assert_eq!(damaged.len(), 1, "the second reference is missing, not inflated again");
|
||||
let ShapeKind::Group { children, .. } = &q.slides[0].shapes[0].kind else { panic!("group") };
|
||||
|
||||
@@ -109,7 +109,7 @@ fn a_load_of_a_damaged_package_gives_the_golden_report() {
|
||||
let mut out = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let Ok(f) = z.by_index_raw(i) else { continue };
|
||||
if f.name() != "media/1" && f.name() != "chart-parts/1" {
|
||||
if f.name().expect("ZIP member name") != "media/1" && f.name().expect("ZIP member name") != "chart-parts/1" {
|
||||
out.raw_copy_file(f).unwrap_or_else(|e| panic!("{e}"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ fn without(bytes: &[u8], drop: &str) -> Vec<u8> {
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let f = z.by_index(i).unwrap();
|
||||
if f.name() != drop {
|
||||
if f.name().expect("ZIP member name") != drop {
|
||||
out.raw_copy_file(f).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -219,7 +219,7 @@ fn repeated_media_ids_are_read_once() {
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
if f.name() == "presentation.json" {
|
||||
if f.name().expect("ZIP member name") == "presentation.json" {
|
||||
let mut json = vec![];
|
||||
f.read_to_end(&mut json).unwrap();
|
||||
let mut v: serde_json::Value = serde_json::from_slice(&json).unwrap();
|
||||
|
||||
Binary file not shown.
@@ -1,7 +1,9 @@
|
||||
//! A series-level `c:dLbls/c:delete val="1"` hides that series' labels although the
|
||||
//! chart-wide `showVal` is on (#1977).
|
||||
|
||||
use std::io::{Cursor, Read, Write};
|
||||
#[path = "support/chart_fixture.rs"]
|
||||
mod chart_fixture;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use deckcraft_geom::Xfrm;
|
||||
@@ -26,26 +28,6 @@ fn bar_chart_pptx() -> Vec<u8> {
|
||||
deckcraft_pptx::export(&p).expect("export")
|
||||
}
|
||||
|
||||
fn reimport(bytes: &[u8], f: impl Fn(&str) -> String) -> Presentation {
|
||||
let mut zip = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let opts = zip::write::SimpleFileOptions::default();
|
||||
for i in 0..zip.len() {
|
||||
let mut entry = zip.by_index(i).expect("entry");
|
||||
let name = entry.name().to_string();
|
||||
let mut data = vec![];
|
||||
entry.read_to_end(&mut data).expect("read");
|
||||
if name.starts_with("ppt/charts/chart") && name.ends_with(".xml") && !name.contains("_rels") {
|
||||
let xml = String::from_utf8(data).expect("chart xml");
|
||||
data = f(&xml).into_bytes();
|
||||
}
|
||||
out.start_file(&name, opts).expect("start");
|
||||
out.write_all(&data).expect("write");
|
||||
}
|
||||
let patched = out.finish().expect("finish").into_inner();
|
||||
deckcraft_pptx::import(&patched).expect("import")
|
||||
}
|
||||
|
||||
fn chart_of(p: &Presentation) -> &Chart {
|
||||
let s = p.slides.first().expect("slide");
|
||||
for sh in &s.shapes {
|
||||
@@ -58,7 +40,7 @@ fn chart_of(p: &Presentation) -> &Chart {
|
||||
|
||||
#[test]
|
||||
fn series_dlbls_delete_hides_that_series_labels() {
|
||||
let p = reimport(&bar_chart_pptx(), |xml| {
|
||||
let p = chart_fixture::reimport(&bar_chart_pptx(), |xml| {
|
||||
xml.replacen("<c:cat>", r#"<c:dLbls><c:delete val="1"/></c:dLbls><c:cat>"#, 1).replacen(
|
||||
"<c:gapWidth",
|
||||
r#"<c:dLbls><c:showVal val="1"/></c:dLbls><c:gapWidth"#,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
//! Series-level data labels: `c:dLbls/c:showVal` on a series overrides the chart-wide setting,
|
||||
//! and a bare `<c:showVal/>` (no `val` attribute) means true, as the schema's default (#868).
|
||||
|
||||
use std::io::{Cursor, Read, Write};
|
||||
#[path = "support/chart_fixture.rs"]
|
||||
mod chart_fixture;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use deckcraft_geom::Xfrm;
|
||||
@@ -27,27 +29,6 @@ fn bar_chart_pptx() -> Vec<u8> {
|
||||
deckcraft_pptx::export(&p).expect("export")
|
||||
}
|
||||
|
||||
/// Rewrite the chart part's XML through `f` and re-import the deck.
|
||||
fn reimport(bytes: &[u8], f: impl Fn(&str) -> String) -> Presentation {
|
||||
let mut zip = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let opts = zip::write::SimpleFileOptions::default();
|
||||
for i in 0..zip.len() {
|
||||
let mut entry = zip.by_index(i).expect("entry");
|
||||
let name = entry.name().to_string();
|
||||
let mut data = vec![];
|
||||
entry.read_to_end(&mut data).expect("read");
|
||||
if name.starts_with("ppt/charts/chart") && name.ends_with(".xml") && !name.contains("_rels") {
|
||||
let xml = String::from_utf8(data).expect("chart xml");
|
||||
data = f(&xml).into_bytes();
|
||||
}
|
||||
out.start_file(&name, opts).expect("start");
|
||||
out.write_all(&data).expect("write");
|
||||
}
|
||||
let patched = out.finish().expect("finish").into_inner();
|
||||
deckcraft_pptx::import(&patched).expect("import")
|
||||
}
|
||||
|
||||
fn chart_of(p: &Presentation) -> &Chart {
|
||||
let s = p.slides.first().expect("slide");
|
||||
for sh in &s.shapes {
|
||||
@@ -62,7 +43,7 @@ fn chart_of(p: &Presentation) -> &Chart {
|
||||
/// setting is off; the other series stay quiet.
|
||||
#[test]
|
||||
fn bare_series_showval_shows_labels() {
|
||||
let p = reimport(&bar_chart_pptx(), |xml| xml.replacen("<c:cat>", r#"<c:dLbls><c:showVal/></c:dLbls><c:cat>"#, 1));
|
||||
let p = chart_fixture::reimport(&bar_chart_pptx(), |xml| xml.replacen("<c:cat>", r#"<c:dLbls><c:showVal/></c:dLbls><c:cat>"#, 1));
|
||||
let c = chart_of(&p);
|
||||
assert!(!c.data_labels, "the chart-wide setting stays off");
|
||||
assert_eq!(c.series[0].data_labels, Some(true), "a bare showVal means true");
|
||||
@@ -76,7 +57,7 @@ fn bare_series_showval_shows_labels() {
|
||||
/// `val="0"` on the series hides its labels although the chart-wide setting is on.
|
||||
#[test]
|
||||
fn series_showval_false_hides_labels() {
|
||||
let p = reimport(&bar_chart_pptx(), |xml| {
|
||||
let p = chart_fixture::reimport(&bar_chart_pptx(), |xml| {
|
||||
xml.replacen("<c:cat>", r#"<c:dLbls><c:showVal val="0"/></c:dLbls><c:cat>"#, 1).replacen(
|
||||
"<c:gapWidth",
|
||||
r#"<c:dLbls><c:showVal/></c:dLbls><c:gapWidth"#,
|
||||
@@ -138,7 +119,7 @@ fn combo_chart_pptx() -> Vec<u8> {
|
||||
/// keeps them off, even when the other group asks for them (#868).
|
||||
#[test]
|
||||
fn a_combo_chart_keeps_each_groups_own_label_setting() {
|
||||
let p = reimport(&combo_chart_pptx(), |xml| {
|
||||
let p = chart_fixture::reimport(&combo_chart_pptx(), |xml| {
|
||||
// The bar group asks for no labels, the line group for labels.
|
||||
xml.replacen("<c:gapWidth", r#"<c:dLbls><c:showVal val="0"/></c:dLbls><c:gapWidth"#, 1).replacen(
|
||||
"<c:marker val=\"1\"/>",
|
||||
@@ -158,7 +139,7 @@ fn a_combo_chart_keeps_each_groups_own_label_setting() {
|
||||
#[test]
|
||||
fn chart_options_data_labels_on_overrides_series_off() {
|
||||
use deckcraft_engine::Session;
|
||||
let p = reimport(&bar_chart_pptx(), |xml| xml.replace("<c:cat>", r#"<c:dLbls><c:showVal val="0"/></c:dLbls><c:cat>"#));
|
||||
let p = chart_fixture::reimport(&bar_chart_pptx(), |xml| xml.replace("<c:cat>", r#"<c:dLbls><c:showVal val="0"/></c:dLbls><c:cat>"#));
|
||||
assert!(chart_of(&p).series.iter().all(|s| !chart_of(&p).series_data_labels(s)), "every series starts quiet");
|
||||
let path = std::env::temp_dir().join("deckcraft_series_labels_off.pptx");
|
||||
std::fs::write(&path, deckcraft_pptx::export(&p).expect("export")).expect("write");
|
||||
|
||||
@@ -19,7 +19,7 @@ fn rewrite(bytes: &[u8], edit: impl Fn(&str, String) -> String) -> Vec<u8> {
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
for i in 0..src.len() {
|
||||
let mut f = src.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
let mut data = Vec::new();
|
||||
f.read_to_end(&mut data).expect("read");
|
||||
if name.ends_with(".xml") {
|
||||
|
||||
@@ -17,7 +17,7 @@ fn deck_with(effect: &str, behaviour: &str) -> Vec<bool> {
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
let mut d = vec![];
|
||||
f.read_to_end(&mut d).expect("read");
|
||||
if name == "ppt/slides/slide1.xml" {
|
||||
|
||||
@@ -31,7 +31,7 @@ fn with_workbook(bytes: &[u8]) -> Vec<u8> {
|
||||
let mut chart_part = None;
|
||||
for i in 0..zip.len() {
|
||||
let mut f = zip.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
let mut data = vec![];
|
||||
f.read_to_end(&mut data).expect("read");
|
||||
if name.starts_with("ppt/charts/chart") && name.ends_with(".xml") && !name.contains("_rels") {
|
||||
@@ -70,7 +70,7 @@ fn parts(bytes: &[u8]) -> Vec<(String, Vec<u8>)> {
|
||||
let mut out = vec![];
|
||||
for i in 0..zip.len() {
|
||||
let mut f = zip.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
let mut data = vec![];
|
||||
f.read_to_end(&mut data).expect("read");
|
||||
out.push((name, data));
|
||||
@@ -156,7 +156,7 @@ fn rewrite(src: &[u8], edit: impl Fn(&str, Vec<u8>) -> Vec<u8>, extra: &[(&str,
|
||||
let opts = zip::write::SimpleFileOptions::default();
|
||||
for i in 0..zip.len() {
|
||||
let mut f = zip.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
let mut data = vec![];
|
||||
f.read_to_end(&mut data).expect("read");
|
||||
let data = edit(&name, data);
|
||||
|
||||
@@ -58,10 +58,10 @@ fn rewrite(bytes: &[u8], drop: &[&str]) -> Vec<u8> {
|
||||
let mut out = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
if drop.iter().any(|d| f.name() == *d) {
|
||||
if drop.iter().any(|d| f.name().expect("ZIP member name") == *d) {
|
||||
continue;
|
||||
}
|
||||
out.start_file(f.name(), zip::write::SimpleFileOptions::default()).expect("start");
|
||||
out.start_file(f.name().expect("ZIP member name"), zip::write::SimpleFileOptions::default()).expect("start");
|
||||
std::io::copy(&mut f, &mut out).expect("copy");
|
||||
}
|
||||
out.finish().expect("finish").into_inner()
|
||||
@@ -161,8 +161,8 @@ fn owned_modern_part_still_suppresses_later_legacy() {
|
||||
let mut out = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
out.start_file(f.name(), zip::write::SimpleFileOptions::default()).expect("start");
|
||||
if f.name() == "ppt/slides/_rels/slide2.xml.rels" {
|
||||
out.start_file(f.name().expect("ZIP member name"), zip::write::SimpleFileOptions::default()).expect("start");
|
||||
if f.name().expect("ZIP member name") == "ppt/slides/_rels/slide2.xml.rels" {
|
||||
std::io::Write::write_all(&mut out, rels2.as_bytes()).expect("write");
|
||||
} else {
|
||||
std::io::copy(&mut f, &mut out).expect("copy");
|
||||
@@ -193,8 +193,8 @@ fn legacy_only_package_imports() {
|
||||
let mut out = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
out.start_file(f.name(), zip::write::SimpleFileOptions::default()).expect("start");
|
||||
if f.name() == "ppt/slides/slide1.xml" {
|
||||
out.start_file(f.name().expect("ZIP member name"), zip::write::SimpleFileOptions::default()).expect("start");
|
||||
if f.name().expect("ZIP member name") == "ppt/slides/slide1.xml" {
|
||||
let mut xml = String::new();
|
||||
f.read_to_string(&mut xml).expect("utf8");
|
||||
if let Some(start) = xml.find("<p:extLst>") {
|
||||
@@ -246,7 +246,7 @@ fn every_written_xml_part_binds_its_prefixes() {
|
||||
let mut modern = 0;
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
if !(name.ends_with(".xml") || name.ends_with(".rels")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! package and the content parts. A second save must come out the same as the first.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::io::{Cursor, Read, Write};
|
||||
use std::io::{Cursor, Write};
|
||||
use std::sync::Arc;
|
||||
|
||||
use deckcraft_model::chart::{Chart, ChartType};
|
||||
@@ -120,19 +120,7 @@ struct Pkg {
|
||||
|
||||
impl Pkg {
|
||||
fn open(bytes: &[u8]) -> Self {
|
||||
let mut zip = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
let mut parts = BTreeMap::new();
|
||||
for i in 0..zip.len() {
|
||||
let mut f = zip.by_index(i).expect("entry");
|
||||
if f.is_dir() {
|
||||
continue;
|
||||
}
|
||||
let name = f.name().trim_start_matches('/').to_string();
|
||||
let mut data = vec![];
|
||||
f.read_to_end(&mut data).expect("read");
|
||||
parts.insert(name, data);
|
||||
}
|
||||
Pkg { parts }
|
||||
Pkg { parts: super::zip_fixture::corpus_parts(bytes) }
|
||||
}
|
||||
|
||||
fn replace(&self, name: &str, data: Vec<u8>) -> Vec<u8> {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! content parts. A second save keeps the same part names and text.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::io::{Cursor, Read, Write};
|
||||
use std::io::{Cursor, Write};
|
||||
use std::sync::Arc;
|
||||
|
||||
use deckcraft_model::anim::{AnimStart, Animation, TextBuild};
|
||||
@@ -221,19 +221,7 @@ struct Pkg {
|
||||
|
||||
impl Pkg {
|
||||
fn open(bytes: &[u8]) -> Self {
|
||||
let mut zip = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
let mut parts = BTreeMap::new();
|
||||
for i in 0..zip.len() {
|
||||
let mut f = zip.by_index(i).expect("entry");
|
||||
if f.is_dir() {
|
||||
continue;
|
||||
}
|
||||
let name = f.name().trim_start_matches('/').to_string();
|
||||
let mut data = vec![];
|
||||
f.read_to_end(&mut data).expect("read");
|
||||
parts.insert(name, data);
|
||||
}
|
||||
Pkg { parts }
|
||||
Pkg { parts: super::zip_fixture::corpus_parts(bytes) }
|
||||
}
|
||||
|
||||
fn bytes(&self) -> Vec<u8> {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! Relationship-bearing SmartArt and OLE parts stay with issue #203. Media playback options stay
|
||||
//! with #74. Animation rewind (`cTn fill="remove"`) stays with #77. This file does not assert those.
|
||||
|
||||
use std::io::{Cursor, Read, Write};
|
||||
use std::io::{Cursor, Read};
|
||||
use std::sync::Arc;
|
||||
|
||||
use deckcraft_color::Rgba;
|
||||
@@ -284,33 +284,6 @@ fn ink_and_timing_survive(q: &Presentation) {
|
||||
assert!(pulse.trigger.is_none());
|
||||
}
|
||||
|
||||
/// An exported deck with `parts` added (or replaced) and `edit` applied to every XML part.
|
||||
fn with_parts(parts: &[(&str, Vec<u8>)], edit: impl Fn(&str, String) -> String) -> Vec<u8> {
|
||||
let base = deckcraft_pptx::export(&defaults::new_presentation(None)).expect("export");
|
||||
let mut z = zip::ZipArchive::new(Cursor::new(base)).expect("zip");
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let o = zip::write::SimpleFileOptions::default();
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
if parts.iter().any(|(n, _)| *n == name) {
|
||||
continue;
|
||||
}
|
||||
let mut d = vec![];
|
||||
f.read_to_end(&mut d).expect("read");
|
||||
if name.ends_with(".xml") || name.ends_with(".rels") {
|
||||
d = edit(&name, String::from_utf8(d).expect("utf8")).into_bytes();
|
||||
}
|
||||
out.start_file(name, o).expect("start");
|
||||
out.write_all(&d).expect("write");
|
||||
}
|
||||
for (name, data) in parts {
|
||||
out.start_file(*name, o).expect("start");
|
||||
out.write_all(data).expect("write");
|
||||
}
|
||||
out.finish().expect("finish").into_inner()
|
||||
}
|
||||
|
||||
fn zip_text(bytes: &[u8], name: &str) -> String {
|
||||
let mut z = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
let mut f = z.by_name(name).unwrap_or_else(|_| panic!("no {name}"));
|
||||
@@ -337,7 +310,7 @@ fn an_alternate_content_model_keeps_the_glb_and_its_poster() {
|
||||
let model = glb(7);
|
||||
let poster = png([200, 30, 40]);
|
||||
let frame = r#"<mc:AlternateContent xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"><mc:Choice xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" Requires="am3d"><p:contentPart r:id="rIdModel"><p:nvContentPartPr><p:cNvPr id="60" name="Model from file"/><p:cNvContentPartPr/><p:nvPr/></p:nvContentPartPr><p:xfrm><a:off x="508000" y="635000"/><a:ext cx="1524000" cy="1143000"/></p:xfrm></p:contentPart></mc:Choice><mc:Fallback><p:pic><p:nvPicPr><p:cNvPr id="61" name="Model poster"/><p:cNvPicPr><a:picLocks noChangeAspect="1"/></p:cNvPicPr><p:nvPr/></p:nvPicPr><p:blipFill><a:blip r:embed="rIdPoster"/><a:stretch><a:fillRect/></a:stretch></p:blipFill><p:spPr><a:xfrm><a:off x="508000" y="635000"/><a:ext cx="1524000" cy="1143000"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></p:spPr></p:pic></mc:Fallback></mc:AlternateContent>"#;
|
||||
let bytes = with_parts(&[("ppt/media/model.glb", model.clone()), ("ppt/media/poster.png", poster.clone())], |name, s| {
|
||||
let bytes = super::zip_fixture::with_parts(&[("ppt/media/model.glb", model.clone()), ("ppt/media/poster.png", poster.clone())], |name, s| {
|
||||
if name == "ppt/slides/slide1.xml" {
|
||||
s.replacen("</p:spTree>", &format!("{frame}</p:spTree>"), 1)
|
||||
} else if name == "ppt/slides/_rels/slide1.xml.rels" {
|
||||
@@ -368,19 +341,22 @@ fn an_alternate_content_model_keeps_the_glb_and_its_poster() {
|
||||
fn an_ink_content_part_still_uses_its_fallback_picture() {
|
||||
let poster = png([10, 10, 10]);
|
||||
let frame = r#"<mc:AlternateContent xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"><mc:Choice Requires="p14"><p:contentPart r:id="rIdInk"><p:nvContentPartPr><p:cNvPr id="50" name="Ink marks"/><p:cNvContentPartPr/><p:nvPr/></p:nvContentPartPr></p:contentPart></mc:Choice><mc:Fallback><p:pic><p:nvPicPr><p:cNvPr id="51" name="Ink poster"/><p:cNvPicPr/><p:nvPr/></p:nvPicPr><p:blipFill><a:blip r:embed="rIdPoster"/><a:stretch><a:fillRect/></a:stretch></p:blipFill><p:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="914400" cy="914400"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></p:spPr></p:pic></mc:Fallback></mc:AlternateContent>"#;
|
||||
let bytes = with_parts(&[("ppt/ink/ink1.xml", b"<ink/>".to_vec()), ("ppt/media/ink-poster.png", poster.clone())], |name, s| {
|
||||
if name == "ppt/slides/slide1.xml" {
|
||||
s.replacen("</p:spTree>", &format!("{frame}</p:spTree>"), 1)
|
||||
} else if name == "ppt/slides/_rels/slide1.xml.rels" {
|
||||
s.replacen(
|
||||
let bytes = super::zip_fixture::with_parts(
|
||||
&[("ppt/ink/ink1.xml", b"<ink/>".to_vec()), ("ppt/media/ink-poster.png", poster.clone())],
|
||||
|name, s| {
|
||||
if name == "ppt/slides/slide1.xml" {
|
||||
s.replacen("</p:spTree>", &format!("{frame}</p:spTree>"), 1)
|
||||
} else if name == "ppt/slides/_rels/slide1.xml.rels" {
|
||||
s.replacen(
|
||||
"</Relationships>",
|
||||
r#"<Relationship Id="rIdInk" Type="http://schemas.microsoft.com/office/2007/relationships/ink" Target="../ink/ink1.xml"/><Relationship Id="rIdPoster" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="../media/ink-poster.png"/></Relationships>"#,
|
||||
1,
|
||||
)
|
||||
} else {
|
||||
s
|
||||
}
|
||||
});
|
||||
} else {
|
||||
s
|
||||
}
|
||||
},
|
||||
);
|
||||
let p = deckcraft_pptx::import(&bytes).expect("import");
|
||||
assert!(p.slides[0].shapes.iter().all(|s| s.name != "Ink marks"));
|
||||
let s = by_name(&p, "Ink poster");
|
||||
|
||||
@@ -327,7 +327,7 @@ fn rewrite_zip_entry(bytes: &[u8], entry_name: &str, f: impl Fn(&str) -> String)
|
||||
let opts = zip::write::SimpleFileOptions::default().compression_method(zip::CompressionMethod::Deflated);
|
||||
for i in 0..r.len() {
|
||||
let mut file = r.by_index(i).unwrap();
|
||||
let name = file.name().to_string();
|
||||
let name = file.name().expect("ZIP member name").to_string();
|
||||
let mut buf = Vec::new();
|
||||
file.read_to_end(&mut buf).unwrap();
|
||||
w.start_file(&name, opts).unwrap();
|
||||
|
||||
@@ -19,7 +19,7 @@ fn repack(bytes: &[u8], parts: &[(&str, String)]) -> Vec<u8> {
|
||||
let opts = zip::write::SimpleFileOptions::default();
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
if parts.iter().any(|(n, _)| *n == name) {
|
||||
continue;
|
||||
}
|
||||
@@ -253,8 +253,12 @@ fn themes_masters_and_layouts_survive_a_round_trip() {
|
||||
// A second save keeps the same theme and master parts.
|
||||
let names = |bytes: &[u8]| {
|
||||
let z = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
let mut v: Vec<String> =
|
||||
z.file_names().filter(|n| n.contains("theme") || n.contains("slideMaster") || n.contains("slideLayout")).map(str::to_string).collect();
|
||||
let mut v: Vec<String> = z
|
||||
.file_names()
|
||||
.map(|name| name.expect("ZIP member name"))
|
||||
.filter(|n| n.contains("theme") || n.contains("slideMaster") || n.contains("slideLayout"))
|
||||
.map(std::borrow::Cow::into_owned)
|
||||
.collect();
|
||||
v.sort();
|
||||
v
|
||||
};
|
||||
|
||||
@@ -1,30 +1,11 @@
|
||||
//! Fills read from decks written by other tools.
|
||||
|
||||
use std::io::{Cursor, Read, Write};
|
||||
use std::io::Cursor;
|
||||
|
||||
use deckcraft_geom::Xfrm;
|
||||
use deckcraft_model::style::{Fill, PictureFill, PictureMode};
|
||||
use deckcraft_model::{Shape, ShapeId, defaults};
|
||||
|
||||
/// `bytes` with `edit` applied to every slide part.
|
||||
fn edit_slides(bytes: &[u8], edit: impl Fn(String) -> String) -> Vec<u8> {
|
||||
let mut z = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let o = zip::write::SimpleFileOptions::default();
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let mut d = vec![];
|
||||
f.read_to_end(&mut d).expect("read");
|
||||
let name = f.name().to_string();
|
||||
if name.starts_with("ppt/slides/slide") && name.ends_with(".xml") {
|
||||
d = edit(String::from_utf8(d).expect("utf8")).into_bytes();
|
||||
}
|
||||
out.start_file(name, o).expect("start");
|
||||
out.write_all(&d).expect("write");
|
||||
}
|
||||
out.finish().expect("finish").into_inner()
|
||||
}
|
||||
|
||||
fn png() -> Vec<u8> {
|
||||
let mut out = Cursor::new(vec![]);
|
||||
image::DynamicImage::ImageRgb8(image::RgbImage::from_pixel(4, 4, image::Rgb([10, 200, 30])))
|
||||
@@ -62,7 +43,7 @@ fn textured_mode(bytes: &[u8]) -> PictureMode {
|
||||
fn a_shape_picture_fill_without_stretch_or_tile_tiles() {
|
||||
// tdf#128596: `<a:blipFill><a:blip/></a:blipFill>` on a shape, as some tools write it;
|
||||
// PowerPoint tiles the picture at its own size.
|
||||
let bare = edit_slides(&deck(), |s| {
|
||||
let bare = super::zip_fixture::edit_slides(&deck(), |s| {
|
||||
let s = regex_free_strip(&s, "<a:stretch>", "</a:stretch>");
|
||||
assert!(!s.contains("<a:stretch"), "the test deck lost its stretch");
|
||||
s
|
||||
@@ -167,8 +148,9 @@ fn a_gradient_tile_rect_is_read_and_round_trips() {
|
||||
let s = q.slides[0].shapes.iter().find(|s| s.name == "Corner").expect("shape");
|
||||
assert_eq!(s.fill, Some(Fill::Gradient(g)));
|
||||
// As written by PowerPoint (attributes it leaves out are 0).
|
||||
let edited =
|
||||
edit_slides(&bytes, |x| x.replace("<a:tileRect l=\"-100000\" t=\"-100000\" r=\"0\" b=\"0\"/>", "<a:tileRect l=\"-100000\" t=\"-100000\"/>"));
|
||||
let edited = super::zip_fixture::edit_slides(&bytes, |x| {
|
||||
x.replace("<a:tileRect l=\"-100000\" t=\"-100000\" r=\"0\" b=\"0\"/>", "<a:tileRect l=\"-100000\" t=\"-100000\"/>")
|
||||
});
|
||||
let q = deckcraft_pptx::import(&edited).expect("import");
|
||||
let s = q.slides[0].shapes.iter().find(|s| s.name == "Corner").expect("shape");
|
||||
assert!(matches!(&s.fill, Some(Fill::Gradient(g)) if g.tile == [-1.0, -1.0, 0.0, 0.0]), "{:?}", s.fill);
|
||||
@@ -200,7 +182,7 @@ fn a_table_naming_no_style_is_drawn_with_the_table_grid() {
|
||||
// Written with its style, it reads back as written.
|
||||
assert_eq!(style(&bytes), "none");
|
||||
// Without a:tableStyleId PowerPoint draws thin dark grid lines.
|
||||
let bare = edit_slides(&bytes, |x| {
|
||||
let bare = super::zip_fixture::edit_slides(&bytes, |x| {
|
||||
let (Some(a), Some(b)) = (x.find("<a:tableStyleId>"), x.find("</a:tableStyleId>")) else { return x };
|
||||
format!("{}{}", &x[..a], &x[b + "</a:tableStyleId>".len()..])
|
||||
});
|
||||
@@ -235,7 +217,7 @@ fn black_and_white_and_inverted_alpha_pictures_round_trip() {
|
||||
#[test]
|
||||
fn an_upright_picture_fill_round_trips() {
|
||||
let bytes = deck();
|
||||
let edited = edit_slides(&bytes, |x| x.replacen("rotWithShape=\"1\"", "rotWithShape=\"0\"", 1));
|
||||
let edited = super::zip_fixture::edit_slides(&bytes, |x| x.replacen("rotWithShape=\"1\"", "rotWithShape=\"0\"", 1));
|
||||
let q = deckcraft_pptx::import(&edited).expect("import");
|
||||
let s = q.slides[0].shapes.iter().find(|s| s.name == "Textured").expect("shape");
|
||||
let Some(Fill::Picture(pf)) = &s.fill else { panic!("{:?}", s.fill) };
|
||||
|
||||
@@ -21,7 +21,7 @@ fn deck() -> Vec<u8> {
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
for i in 0..src.len() {
|
||||
let mut f = src.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
let mut data = Vec::new();
|
||||
f.read_to_end(&mut data).expect("read");
|
||||
let edit = |d: Vec<u8>, at: &str, add: &str| String::from_utf8(d).expect("utf8").replacen(at, &format!("{add}{at}"), 1).into_bytes();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Lock and hidden state (Selection pane): what PowerPoint writes for Lock, and what it reads as locked.
|
||||
|
||||
use std::io::{Cursor, Read, Write};
|
||||
use std::io::Cursor;
|
||||
|
||||
use deckcraft_geom::Xfrm;
|
||||
use deckcraft_model::style::PictureFill;
|
||||
@@ -78,30 +78,8 @@ fn find<'a>(s: &'a Slide, name: &str) -> &'a Shape {
|
||||
found.unwrap_or_else(|| panic!("no shape {name}"))
|
||||
}
|
||||
|
||||
fn entries(bytes: &[u8]) -> Vec<(String, Vec<u8>)> {
|
||||
let mut z = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
(0..z.len())
|
||||
.map(|i| {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let mut d = vec![];
|
||||
f.read_to_end(&mut d).expect("read");
|
||||
(f.name().to_string(), d)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn rezip(es: &[(String, Vec<u8>)]) -> Vec<u8> {
|
||||
let mut z = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let o = zip::write::SimpleFileOptions::default();
|
||||
for (n, d) in es {
|
||||
z.start_file(n.as_str(), o).expect("start");
|
||||
z.write_all(d).expect("write");
|
||||
}
|
||||
z.finish().expect("finish").into_inner()
|
||||
}
|
||||
|
||||
fn slide1_xml(bytes: &[u8]) -> String {
|
||||
let es = entries(bytes);
|
||||
let es = super::zip_fixture::entries(bytes);
|
||||
let (_, d) = es.iter().find(|(n, _)| n == "ppt/slides/slide1.xml").expect("slide1");
|
||||
String::from_utf8(d.clone()).expect("utf8")
|
||||
}
|
||||
@@ -168,7 +146,7 @@ fn partial_locks_are_not_lock() {
|
||||
if let Some(s) = p.slides.first_mut() {
|
||||
std::sync::Arc::make_mut(s).shapes = vec![a, b, c, d];
|
||||
}
|
||||
let mut es = entries(&deckcraft_pptx::export(&p).expect("export"));
|
||||
let mut es = super::zip_fixture::entries(&deckcraft_pptx::export(&p).expect("export"));
|
||||
let slide = es.iter_mut().find(|(n, _)| n == "ppt/slides/slide1.xml").expect("slide1");
|
||||
let xml = String::from_utf8(slide.1.clone()).expect("utf8");
|
||||
let swap = |xml: String, name: &str, locks: &str| {
|
||||
@@ -186,7 +164,7 @@ fn partial_locks_are_not_lock() {
|
||||
let xml =
|
||||
swap(xml, "C", r#"<a:spLocks noGrp="1" noRot="1" noMove="1" noResize="1" noEditPoints="1" noAdjustHandles="1" noChangeShapeType="1"/>"#);
|
||||
slide.1 = xml.into_bytes();
|
||||
let q = deckcraft_pptx::import(&rezip(&es)).expect("import");
|
||||
let q = deckcraft_pptx::import(&super::zip_fixture::zip_of(&es)).expect("import");
|
||||
let s = &q.slides[0];
|
||||
assert!(!find(s, "A").locked);
|
||||
assert!(!find(s, "B").locked);
|
||||
@@ -202,10 +180,10 @@ fn empty_locks_element_is_unlocked() {
|
||||
if let Some(s) = p.slides.first_mut() {
|
||||
std::sync::Arc::make_mut(s).shapes = vec![a];
|
||||
}
|
||||
let mut es = entries(&deckcraft_pptx::export(&p).expect("export"));
|
||||
let mut es = super::zip_fixture::entries(&deckcraft_pptx::export(&p).expect("export"));
|
||||
let slide = es.iter_mut().find(|(n, _)| n == "ppt/slides/slide1.xml").expect("slide1");
|
||||
let xml = String::from_utf8(slide.1.clone()).expect("utf8").replacen("<p:cNvSpPr/>", "<p:cNvSpPr><a:spLocks/></p:cNvSpPr>", 1);
|
||||
slide.1 = xml.into_bytes();
|
||||
let q = deckcraft_pptx::import(&rezip(&es)).expect("import");
|
||||
let q = deckcraft_pptx::import(&super::zip_fixture::zip_of(&es)).expect("import");
|
||||
assert!(!find(&q.slides[0], "A").locked);
|
||||
}
|
||||
|
||||
@@ -30,5 +30,6 @@ mod table_styles;
|
||||
mod tags;
|
||||
mod transition_xml;
|
||||
mod trigger_steps;
|
||||
mod zip_fixture;
|
||||
|
||||
mod picture_backing;
|
||||
|
||||
@@ -26,7 +26,7 @@ fn entries(bytes: &[u8]) -> Vec<(String, Vec<u8>)> {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let mut d = vec![];
|
||||
std::io::Read::read_to_end(&mut f, &mut d).expect("read");
|
||||
(f.name().to_string(), d)
|
||||
(f.name().expect("ZIP member name").to_string(), d)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ fn imported(body_style: &str) -> Presentation {
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let mut part = z.by_index(i).expect("part");
|
||||
let name = part.name().to_string();
|
||||
let name = part.name().expect("ZIP member name").to_string();
|
||||
let mut data = Vec::new();
|
||||
part.read_to_end(&mut data).expect("read");
|
||||
if name.starts_with("ppt/slideMasters/slideMaster") && name.ends_with(".xml") {
|
||||
|
||||
@@ -1,35 +1,11 @@
|
||||
//! Equations whose math namespace is declared above the equation: on the slide root or on a wrapper.
|
||||
|
||||
use std::io::{Cursor, Read, Write};
|
||||
|
||||
use deckcraft_geom::Xfrm;
|
||||
use deckcraft_model::text::{Paragraph, Run, RunKind, RunProps, TextBody};
|
||||
use deckcraft_model::{Shape, ShapeId, defaults};
|
||||
|
||||
const NS_M: &str = r#"xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math""#;
|
||||
|
||||
fn entries(bytes: &[u8]) -> Vec<(String, Vec<u8>)> {
|
||||
let mut z = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
(0..z.len())
|
||||
.map(|i| {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let mut d = vec![];
|
||||
f.read_to_end(&mut d).expect("read");
|
||||
(f.name().to_string(), d)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn rezip(es: &[(String, Vec<u8>)]) -> Vec<u8> {
|
||||
let mut z = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let o = zip::write::SimpleFileOptions::default();
|
||||
for (n, d) in es {
|
||||
z.start_file(n.as_str(), o).expect("start");
|
||||
z.write_all(d).expect("write");
|
||||
}
|
||||
z.finish().expect("finish").into_inner()
|
||||
}
|
||||
|
||||
/// Export an equation, move its `xmlns:m` from the equation to the element `host` opens, and
|
||||
/// return the OMML read back.
|
||||
fn moved_to(host: &str) -> String {
|
||||
@@ -52,7 +28,7 @@ fn moved_to(host: &str) -> String {
|
||||
if let Some(s) = p.slides.first_mut() {
|
||||
std::sync::Arc::make_mut(s).shapes = vec![eq];
|
||||
}
|
||||
let mut es = entries(&deckcraft_pptx::export(&p).expect("export"));
|
||||
let mut es = super::zip_fixture::entries(&deckcraft_pptx::export(&p).expect("export"));
|
||||
let slide = es.iter_mut().find(|(n, _)| n == "ppt/slides/slide1.xml").expect("slide1");
|
||||
let xml = String::from_utf8(slide.1.clone()).expect("utf8");
|
||||
assert!(xml.contains(host), "{xml}");
|
||||
@@ -60,7 +36,7 @@ fn moved_to(host: &str) -> String {
|
||||
assert_eq!(xml.matches(NS_M).count(), 1);
|
||||
slide.1 = xml.into_bytes();
|
||||
|
||||
let q = deckcraft_pptx::import(&rezip(&es)).expect("import");
|
||||
let q = deckcraft_pptx::import(&super::zip_fixture::zip_of(&es)).expect("import");
|
||||
let shape = q.slides[0].shapes.iter().find(|s| s.name == "Equation").expect("shape");
|
||||
let run = shape.text.as_ref().and_then(|t| t.paragraphs.first()).and_then(|p| p.runs.first()).expect("run");
|
||||
match &run.kind {
|
||||
|
||||
@@ -40,13 +40,13 @@ fn clips(nodes: impl Fn(u32, u32) -> String) -> Vec<MediaClip> {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let mut d = vec![];
|
||||
f.read_to_end(&mut d).expect("read");
|
||||
if f.name() == "ppt/slides/slide1.xml" {
|
||||
if f.name().expect("ZIP member name") == "ppt/slides/slide1.xml" {
|
||||
let s = String::from_utf8(d).expect("utf8");
|
||||
assert!(!s.contains("<p:timing"));
|
||||
let end = s.rfind("</p:sld>").expect("end");
|
||||
d = format!("{}{timing}{}", &s[..end], &s[end..]).into_bytes();
|
||||
}
|
||||
out.start_file(f.name(), zip::write::SimpleFileOptions::default()).expect("start");
|
||||
out.start_file(f.name().expect("ZIP member name"), zip::write::SimpleFileOptions::default()).expect("start");
|
||||
out.write_all(&d).expect("write");
|
||||
}
|
||||
let q = deckcraft_pptx::import(&out.finish().expect("finish").into_inner()).expect("import");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Speaker notes keep their run and paragraph formatting: a bold heading, indented points with
|
||||
//! custom bullets, plain lines.
|
||||
|
||||
use std::io::{Cursor, Read, Write};
|
||||
use std::io::{Cursor, Read};
|
||||
use std::sync::Arc;
|
||||
|
||||
use deckcraft_model::defaults;
|
||||
@@ -21,23 +21,7 @@ fn empty_notes_deck() -> Vec<u8> {
|
||||
let mut p = defaults::new_presentation(None);
|
||||
Arc::make_mut(&mut p.slides[0]).notes = TextBody::from_text("placeholder");
|
||||
let bytes = deckcraft_pptx::export(&p).expect("export");
|
||||
let mut src = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let mut found = false;
|
||||
for i in 0..src.len() {
|
||||
let mut f = src.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let mut data = vec![];
|
||||
f.read_to_end(&mut data).expect("read");
|
||||
if name == NOTES {
|
||||
data = EMPTY_NOTES_XML.as_bytes().to_vec();
|
||||
found = true;
|
||||
}
|
||||
out.start_file(name, zip::write::SimpleFileOptions::default()).expect("start");
|
||||
out.write_all(&data).expect("write");
|
||||
}
|
||||
assert!(found, "the export has no {NOTES}");
|
||||
out.finish().expect("finish").into_inner()
|
||||
super::zip_fixture::replace_part(bytes, NOTES, EMPTY_NOTES_XML.as_bytes())
|
||||
}
|
||||
|
||||
/// A deck with one notes slide, its notes replaced by [`NOTES_XML`].
|
||||
@@ -45,23 +29,7 @@ fn deck() -> Vec<u8> {
|
||||
let mut p = defaults::new_presentation(None);
|
||||
Arc::make_mut(&mut p.slides[0]).notes = TextBody::from_text("placeholder");
|
||||
let bytes = deckcraft_pptx::export(&p).expect("export");
|
||||
let mut src = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let mut found = false;
|
||||
for i in 0..src.len() {
|
||||
let mut f = src.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let mut data = vec![];
|
||||
f.read_to_end(&mut data).expect("read");
|
||||
if name == NOTES {
|
||||
data = NOTES_XML.as_bytes().to_vec();
|
||||
found = true;
|
||||
}
|
||||
out.start_file(name, zip::write::SimpleFileOptions::default()).expect("start");
|
||||
out.write_all(&data).expect("write");
|
||||
}
|
||||
assert!(found, "the export has no {NOTES}");
|
||||
out.finish().expect("finish").into_inner()
|
||||
super::zip_fixture::replace_part(bytes, NOTES, NOTES_XML.as_bytes())
|
||||
}
|
||||
|
||||
fn assert_formatted(notes: &TextBody) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! Embedded (OLE) objects and their preview pictures, as other versions of PowerPoint write them.
|
||||
|
||||
use std::io::{Cursor, Read, Write};
|
||||
use std::io::Cursor;
|
||||
|
||||
use deckcraft_model::{ShapeKind, defaults};
|
||||
use deckcraft_model::ShapeKind;
|
||||
|
||||
fn png() -> Vec<u8> {
|
||||
let mut out = Cursor::new(vec![]);
|
||||
@@ -12,33 +12,6 @@ fn png() -> Vec<u8> {
|
||||
out.into_inner()
|
||||
}
|
||||
|
||||
/// An exported deck with `parts` added (or replaced) and `edit` applied to every part's text.
|
||||
fn with_parts(parts: &[(&str, Vec<u8>)], edit: impl Fn(&str, String) -> String) -> Vec<u8> {
|
||||
let base = deckcraft_pptx::export(&defaults::new_presentation(None)).expect("export");
|
||||
let mut z = zip::ZipArchive::new(Cursor::new(base)).expect("zip");
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let o = zip::write::SimpleFileOptions::default();
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
if parts.iter().any(|(n, _)| *n == name) {
|
||||
continue;
|
||||
}
|
||||
let mut d = vec![];
|
||||
f.read_to_end(&mut d).expect("read");
|
||||
if name.ends_with(".xml") || name.ends_with(".rels") {
|
||||
d = edit(&name, String::from_utf8(d).expect("utf8")).into_bytes();
|
||||
}
|
||||
out.start_file(name, o).expect("start");
|
||||
out.write_all(&d).expect("write");
|
||||
}
|
||||
for (name, data) in parts {
|
||||
out.start_file(*name, o).expect("start");
|
||||
out.write_all(data).expect("write");
|
||||
}
|
||||
out.finish().expect("finish").into_inner()
|
||||
}
|
||||
|
||||
/// PowerPoint 2007 style: `p:oleObj spid` with no `p:pic`; the preview is the `v:imagedata` of the
|
||||
/// VML shape with that id in the slide's legacy drawing part.
|
||||
fn ole_deck(spid_in_vml: &str) -> Vec<u8> {
|
||||
@@ -51,7 +24,7 @@ fn ole_deck(spid_in_vml: &str) -> Vec<u8> {
|
||||
let vml_rels = r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="../media/preview.png"/><Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="../media/other.png"/></Relationships>"#;
|
||||
let frame = r#"<p:graphicFrame><p:nvGraphicFramePr><p:cNvPr id="900" name="Object 3"/><p:cNvGraphicFramePr/><p:nvPr/></p:nvGraphicFramePr><p:xfrm><a:off x="0" y="0"/><a:ext cx="1828800" cy="914400"/></p:xfrm><a:graphic><a:graphicData uri="http://schemas.openxmlformats.org/presentationml/2006/ole"><p:oleObj spid="_x0000_s681987" name="Slide" r:id="rIdOle" imgW="4664160" imgH="3497400" progId="PowerPoint.Slide.8"><p:embed/></p:oleObj></a:graphicData></a:graphic></p:graphicFrame>"#;
|
||||
with_parts(
|
||||
super::zip_fixture::with_parts(
|
||||
&[
|
||||
("ppt/drawings/vmlDrawing1.vml", vml.into_bytes()),
|
||||
("ppt/drawings/_rels/vmlDrawing1.vml.rels", vml_rels.as_bytes().to_vec()),
|
||||
@@ -107,7 +80,7 @@ fn an_ole_objects_fallback_picture_gives_it_its_fill_and_outline() {
|
||||
)
|
||||
};
|
||||
let deck = |frame: String| {
|
||||
with_parts(&[("ppt/media/eq.png", png()), ("ppt/embeddings/oleObject1.bin", vec![0; 16])], move |name, s| {
|
||||
super::zip_fixture::with_parts(&[("ppt/media/eq.png", png()), ("ppt/embeddings/oleObject1.bin", vec![0; 16])], move |name, s| {
|
||||
if name == "ppt/slides/slide1.xml" {
|
||||
s.replacen("</p:spTree>", &format!("{frame}</p:spTree>"), 1)
|
||||
} else if name == "ppt/slides/_rels/slide1.xml.rels" {
|
||||
|
||||
@@ -40,7 +40,7 @@ fn deck_with(frames: &str) -> Vec<u8> {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let mut d = vec![];
|
||||
f.read_to_end(&mut d).expect("read");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
if name == "ppt/slides/slide1.xml" {
|
||||
let s = String::from_utf8(d).expect("utf8");
|
||||
let at = s.rfind("</p:spTree>").expect("spTree");
|
||||
|
||||
@@ -41,7 +41,7 @@ fn import_with_timing(build: impl Fn(&[u32]) -> String) -> Vec<(String, AnimStar
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
let mut d = vec![];
|
||||
f.read_to_end(&mut d).expect("read");
|
||||
if name == "ppt/slides/slide1.xml" {
|
||||
|
||||
@@ -1,29 +1,9 @@
|
||||
//! Placeholder inheritance in decks written by PowerPoint.
|
||||
|
||||
use std::io::{Cursor, Read, Write};
|
||||
|
||||
use deckcraft_geom::Xfrm;
|
||||
use deckcraft_model::style::PictureFill;
|
||||
use deckcraft_model::{Geom, PhType, Placeholder, Shape, ShapeId, ShapeKind, defaults};
|
||||
|
||||
/// `bytes` with `edit` applied to every slide part.
|
||||
fn edit_slides(bytes: &[u8], edit: impl Fn(String) -> String) -> Vec<u8> {
|
||||
let mut z = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let o = zip::write::SimpleFileOptions::default();
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let mut d = vec![];
|
||||
f.read_to_end(&mut d).expect("read");
|
||||
let name = f.name().to_string();
|
||||
if name.starts_with("ppt/slides/slide") && name.ends_with(".xml") {
|
||||
d = edit(String::from_utf8(d).expect("utf8")).into_bytes();
|
||||
}
|
||||
out.start_file(name, o).expect("start");
|
||||
out.write_all(&d).expect("write");
|
||||
}
|
||||
out.finish().expect("finish").into_inner()
|
||||
}
|
||||
use std::io::Cursor;
|
||||
|
||||
#[test]
|
||||
fn a_placeholder_without_geometry_takes_its_layouts() {
|
||||
@@ -40,7 +20,7 @@ fn a_placeholder_without_geometry_takes_its_layouts() {
|
||||
}
|
||||
let bytes = deckcraft_pptx::export(&p).expect("export");
|
||||
// Strip the slide's own geometry, as PowerPoint writes inheriting placeholders.
|
||||
let bare = edit_slides(&bytes, |s| {
|
||||
let bare = super::zip_fixture::edit_slides(&bytes, |s| {
|
||||
let mut s = s;
|
||||
while let Some(i) = s.find("<a:prstGeom") {
|
||||
let Some(j) = s[i..].find("</a:prstGeom>").map(|j| j + i + "</a:prstGeom>".len()) else { break };
|
||||
@@ -97,7 +77,7 @@ fn a_picture_placeholder_without_geometry_takes_its_layouts() {
|
||||
};
|
||||
std::sync::Arc::make_mut(&mut p.slides[0]).shapes = vec![pic];
|
||||
let bytes = deckcraft_pptx::export(&p).expect("export");
|
||||
let bare = edit_slides(&bytes, |mut s| {
|
||||
let bare = super::zip_fixture::edit_slides(&bytes, |mut s| {
|
||||
while let Some(i) = s.find("<a:prstGeom") {
|
||||
let Some(j) = s[i..].find("</a:prstGeom>").map(|j| j + i + "</a:prstGeom>".len()) else { break };
|
||||
s.replace_range(i..j, "");
|
||||
|
||||
@@ -1175,7 +1175,7 @@ fn wordart_warps_and_their_adjusts_round_trip() {
|
||||
let mut out = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for i in 0..zip.len() {
|
||||
let mut f = zip.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
let mut data = vec![];
|
||||
std::io::Read::read_to_end(&mut f, &mut data).expect("read");
|
||||
if name == "ppt/slides/slide1.xml" {
|
||||
@@ -1309,7 +1309,7 @@ fn transition_defaults_read_like_powerpoint() {
|
||||
let mut out = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for i in 0..zip.len() {
|
||||
let mut f = zip.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
let mut data = vec![];
|
||||
std::io::Read::read_to_end(&mut f, &mut data).expect("read");
|
||||
if name == "ppt/slides/slide1.xml" {
|
||||
@@ -1513,7 +1513,7 @@ fn an_embedded_font_list_already_in_the_package_is_read() {
|
||||
let mut out = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for i in 0..zip.len() {
|
||||
let mut f = zip.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
let mut data = vec![];
|
||||
std::io::Read::read_to_end(&mut f, &mut data).expect("read");
|
||||
if name == "ppt/presentation.xml" {
|
||||
@@ -1657,7 +1657,7 @@ fn patch_slides(bytes: Vec<u8>, from: &str, to: &str) -> Vec<u8> {
|
||||
let mut out = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
let mut data = vec![];
|
||||
f.read_to_end(&mut data).expect("read");
|
||||
if name.starts_with("ppt/slides/slide") && name.ends_with(".xml") {
|
||||
@@ -1806,7 +1806,7 @@ fn repack(pkg: &[u8], edit: impl Fn(&str, String) -> String, extra: &[(&str, &[u
|
||||
let opts = zip::write::SimpleFileOptions::default();
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
let mut data = vec![];
|
||||
f.read_to_end(&mut data).unwrap();
|
||||
if name.ends_with(".xml") || name.ends_with(".rels") {
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
//! The deck is built here: an export of a new presentation with a SmartArt frame, data part and
|
||||
//! drawing part written by the test.
|
||||
|
||||
use std::io::{Cursor, Read, Write};
|
||||
|
||||
use deckcraft_engine::render::place_slide;
|
||||
use deckcraft_geom::{Point, Rect};
|
||||
use deckcraft_model::{Presentation, ShapeKind, defaults};
|
||||
@@ -34,28 +32,6 @@ fn drawing_shape(prst: &str, shape: (f64, f64, f64, f64, f64), text_rect: (f64,
|
||||
)
|
||||
}
|
||||
|
||||
fn entries(bytes: &[u8]) -> Vec<(String, Vec<u8>)> {
|
||||
let mut z = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
(0..z.len())
|
||||
.map(|i| {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let mut d = vec![];
|
||||
f.read_to_end(&mut d).expect("read");
|
||||
(f.name().to_string(), d)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn zip_of(files: &[(String, Vec<u8>)]) -> Vec<u8> {
|
||||
let mut z = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let o = zip::write::SimpleFileOptions::default();
|
||||
for (n, d) in files {
|
||||
z.start_file(n.as_str(), o).expect("start");
|
||||
z.write_all(d).expect("write");
|
||||
}
|
||||
z.finish().expect("finish").into_inner()
|
||||
}
|
||||
|
||||
fn replace(files: &mut [(String, Vec<u8>)], name: &str, from: &str, to: &str) {
|
||||
let (_, d) = files.iter_mut().find(|(n, _)| n == name).unwrap_or_else(|| panic!("{name} missing"));
|
||||
let s = String::from_utf8(d.clone()).expect("utf8");
|
||||
@@ -65,7 +41,7 @@ fn replace(files: &mut [(String, Vec<u8>)], name: &str, from: &str, to: &str) {
|
||||
|
||||
/// A deck whose first slide holds a SmartArt frame drawn by `shapes`.
|
||||
fn smartart_deck(shapes: &[String]) -> Vec<u8> {
|
||||
let mut files = entries(&deckcraft_pptx::export(&defaults::new_presentation(None)).expect("export"));
|
||||
let mut files = super::zip_fixture::entries(&deckcraft_pptx::export(&defaults::new_presentation(None)).expect("export"));
|
||||
let (fx, fy, fw, fh) = FRAME;
|
||||
let frame = format!(
|
||||
r#"<p:graphicFrame><p:nvGraphicFramePr><p:cNvPr id="90" name="Diagram 1"/><p:cNvGraphicFramePr/><p:nvPr/></p:nvGraphicFramePr><p:xfrm><a:off x="{}" y="{}"/><a:ext cx="{}" cy="{}"/></p:xfrm><a:graphic><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/diagram"><dgm:relIds xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" r:dm="rIdDm" r:lo="rIdLo" r:qs="rIdQs" r:cs="rIdCs"/></a:graphicData></a:graphic></p:graphicFrame></p:spTree>"#,
|
||||
@@ -90,7 +66,7 @@ fn smartart_deck(shapes: &[String]) -> Vec<u8> {
|
||||
);
|
||||
files.push(("ppt/diagrams/data1.xml".into(), data.as_bytes().to_vec()));
|
||||
files.push(("ppt/diagrams/drawing1.xml".into(), drawing.into_bytes()));
|
||||
zip_of(&files)
|
||||
super::zip_fixture::zip_of(&files)
|
||||
}
|
||||
|
||||
/// Each text of slide 1 with the slide-space box it is laid out in (insets applied), the number of
|
||||
|
||||
@@ -21,7 +21,7 @@ fn content_types_last(bytes: &[u8]) -> Vec<u8> {
|
||||
let stored = SimpleFileOptions::default().compression_method(zip::CompressionMethod::Stored);
|
||||
out.start_file("ppt/media/padding.bin", stored).expect("start");
|
||||
out.write_all(&vec![0u8; 64 * 1024]).expect("padding");
|
||||
let names: Vec<String> = (0..src.len()).map(|i| src.by_index(i).expect("entry").name().to_string()).collect();
|
||||
let names: Vec<String> = (0..src.len()).map(|i| src.by_index(i).expect("entry").name().expect("ZIP member name").into_owned()).collect();
|
||||
for name in names.iter().filter(|n| *n != "[Content_Types].xml").chain(std::iter::once(&"[Content_Types].xml".to_string())) {
|
||||
let mut data = Vec::new();
|
||||
src.by_name(name).expect("by_name").read_to_end(&mut data).expect("read");
|
||||
|
||||
@@ -40,7 +40,7 @@ fn table_deck() -> Vec<u8> {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let mut d = vec![];
|
||||
f.read_to_end(&mut d).expect("read");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
if name == "ppt/tableStyles.xml" {
|
||||
d = style_xml().into_bytes();
|
||||
} else if name.starts_with("ppt/slides/slide") && name.ends_with(".xml") {
|
||||
|
||||
@@ -26,7 +26,7 @@ fn tags_survive_round_trip() {
|
||||
let mut ct = String::new();
|
||||
zip.by_name("[Content_Types].xml").expect("ct").read_to_string(&mut ct).expect("read");
|
||||
assert!(ct.contains("presentationml.tags+xml"));
|
||||
assert_eq!((0..zip.len()).filter(|i| zip.by_index(*i).is_ok_and(|f| f.name().starts_with("ppt/tags/"))).count(), 3);
|
||||
assert_eq!((0..zip.len()).filter(|i| zip.by_index(*i).is_ok_and(|f| f.name().expect("ZIP member name").starts_with("ppt/tags/"))).count(), 3);
|
||||
|
||||
let back = deckcraft_pptx::import(&bytes).expect("import");
|
||||
assert_eq!(back.tags, p.tags);
|
||||
@@ -67,7 +67,7 @@ fn a_tags_part_listed_many_times_is_copied_once_and_capped() {
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
for i in 0..zip.len() {
|
||||
let mut f = zip.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
let mut data = vec![];
|
||||
f.read_to_end(&mut data).expect("read");
|
||||
out.start_file(&name, zip::write::SimpleFileOptions::default()).expect("start");
|
||||
@@ -131,7 +131,7 @@ fn new_tag_parts_are_not_parsed_or_cached_after_the_budget_is_exhausted() {
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
for i in 0..zip.len() {
|
||||
let mut f = zip.by_index(i).expect("entry");
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
let mut data = vec![];
|
||||
f.read_to_end(&mut data).expect("read");
|
||||
out.start_file(&name, zip::write::SimpleFileOptions::default()).expect("start");
|
||||
|
||||
@@ -21,7 +21,7 @@ fn import_with(xml: &str) -> Transition {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let mut d = vec![];
|
||||
f.read_to_end(&mut d).expect("read");
|
||||
if f.name() == "ppt/slides/slide1.xml" {
|
||||
if f.name().expect("ZIP member name") == "ppt/slides/slide1.xml" {
|
||||
let s = String::from_utf8(d).expect("utf8");
|
||||
let t = s.find("<p:transition").expect("transition");
|
||||
let a = s[..t].rfind("<mc:AlternateContent").expect("mc start");
|
||||
@@ -29,7 +29,7 @@ fn import_with(xml: &str) -> Transition {
|
||||
let b = t + s[t..].find(end).expect("mc end") + end.len();
|
||||
d = format!("{}{xml}{}", &s[..a], &s[b..]).into_bytes();
|
||||
}
|
||||
out.start_file(f.name(), o).expect("start");
|
||||
out.start_file(f.name().expect("ZIP member name"), o).expect("start");
|
||||
out.write_all(&d).expect("write");
|
||||
}
|
||||
let bytes = out.finish().expect("finish").into_inner();
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
//! Ordered ZIP helpers for the in-memory PPTX fixtures in this integration binary.
|
||||
|
||||
use std::io::{Cursor, Read, Seek, Write};
|
||||
|
||||
use deckcraft_model::defaults;
|
||||
|
||||
fn payload_first_entry(archive: &mut zip::ZipArchive<impl Read + Seek>, index: usize) -> (String, Vec<u8>) {
|
||||
let mut entry = archive.by_index(index).expect("entry");
|
||||
let mut data = Vec::new();
|
||||
entry.read_to_end(&mut data).expect("read");
|
||||
(entry.name().expect("ZIP member name").into_owned(), data)
|
||||
}
|
||||
|
||||
pub(super) fn entries(bytes: &[u8]) -> Vec<(String, Vec<u8>)> {
|
||||
let mut archive = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
(0..archive.len()).map(|index| payload_first_entry(&mut archive, index)).collect()
|
||||
}
|
||||
|
||||
pub(super) fn zip_of(files: &[(String, Vec<u8>)]) -> Vec<u8> {
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let options = zip::write::SimpleFileOptions::default();
|
||||
for (name, data) in files {
|
||||
out.start_file(name.as_str(), options).expect("start");
|
||||
out.write_all(data).expect("write");
|
||||
}
|
||||
out.finish().expect("finish").into_inner()
|
||||
}
|
||||
|
||||
/// `bytes` with `edit` applied to every slide part.
|
||||
pub(super) fn edit_slides(bytes: &[u8], edit: impl Fn(String) -> String) -> Vec<u8> {
|
||||
let mut z = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let o = zip::write::SimpleFileOptions::default();
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let mut d = vec![];
|
||||
f.read_to_end(&mut d).expect("read");
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
if name.starts_with("ppt/slides/slide") && name.ends_with(".xml") {
|
||||
d = edit(String::from_utf8(d).expect("utf8")).into_bytes();
|
||||
}
|
||||
out.start_file(name, o).expect("start");
|
||||
out.write_all(&d).expect("write");
|
||||
}
|
||||
out.finish().expect("finish").into_inner()
|
||||
}
|
||||
|
||||
pub(super) fn replace_part(bytes: Vec<u8>, part: &str, replacement: &[u8]) -> Vec<u8> {
|
||||
let mut src = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let mut found = false;
|
||||
for i in 0..src.len() {
|
||||
let mut f = src.by_index(i).expect("entry");
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
let mut data = vec![];
|
||||
f.read_to_end(&mut data).expect("read");
|
||||
if name == part {
|
||||
data = replacement.to_vec();
|
||||
found = true;
|
||||
}
|
||||
out.start_file(name, zip::write::SimpleFileOptions::default()).expect("start");
|
||||
out.write_all(&data).expect("write");
|
||||
}
|
||||
assert!(found, "the export has no {part}");
|
||||
out.finish().expect("finish").into_inner()
|
||||
}
|
||||
|
||||
/// An exported deck with `parts` added (or replaced) and `edit` applied to every XML part.
|
||||
pub(super) fn with_parts(parts: &[(&str, Vec<u8>)], edit: impl Fn(&str, String) -> String) -> Vec<u8> {
|
||||
let base = deckcraft_pptx::export(&defaults::new_presentation(None)).expect("export");
|
||||
let mut z = zip::ZipArchive::new(Cursor::new(base)).expect("zip");
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let o = zip::write::SimpleFileOptions::default();
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).expect("entry");
|
||||
let name = f.name().expect("ZIP member name").to_string();
|
||||
if parts.iter().any(|(n, _)| *n == name) {
|
||||
continue;
|
||||
}
|
||||
let mut d = vec![];
|
||||
f.read_to_end(&mut d).expect("read");
|
||||
if name.ends_with(".xml") || name.ends_with(".rels") {
|
||||
d = edit(&name, String::from_utf8(d).expect("utf8")).into_bytes();
|
||||
}
|
||||
out.start_file(name, o).expect("start");
|
||||
out.write_all(&d).expect("write");
|
||||
}
|
||||
for (name, data) in parts {
|
||||
out.start_file(*name, o).expect("start");
|
||||
out.write_all(data).expect("write");
|
||||
}
|
||||
out.finish().expect("finish").into_inner()
|
||||
}
|
||||
|
||||
pub(super) fn corpus_parts(bytes: &[u8]) -> std::collections::BTreeMap<String, Vec<u8>> {
|
||||
let mut zip = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
let mut parts = std::collections::BTreeMap::new();
|
||||
for i in 0..zip.len() {
|
||||
let mut f = zip.by_index(i).expect("entry");
|
||||
if f.is_dir() {
|
||||
continue;
|
||||
}
|
||||
let name = f.name().expect("ZIP member name").trim_start_matches('/').to_string();
|
||||
let mut data = vec![];
|
||||
f.read_to_end(&mut data).expect("read");
|
||||
parts.insert(name, data);
|
||||
}
|
||||
parts
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
use std::io::{Cursor, Read, Write};
|
||||
|
||||
use deckcraft_model::Presentation;
|
||||
|
||||
/// Rewrite the chart part's XML through `f` and re-import the deck.
|
||||
pub(super) fn reimport(bytes: &[u8], f: impl Fn(&str) -> String) -> Presentation {
|
||||
let mut zip = zip::ZipArchive::new(Cursor::new(bytes)).expect("zip");
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let opts = zip::write::SimpleFileOptions::default();
|
||||
for i in 0..zip.len() {
|
||||
let mut entry = zip.by_index(i).expect("entry");
|
||||
let name = entry.name().expect("ZIP member name").to_string();
|
||||
let mut data = vec![];
|
||||
entry.read_to_end(&mut data).expect("read");
|
||||
if name.starts_with("ppt/charts/chart") && name.ends_with(".xml") && !name.contains("_rels") {
|
||||
let xml = String::from_utf8(data).expect("chart xml");
|
||||
data = f(&xml).into_bytes();
|
||||
}
|
||||
out.start_file(&name, opts).expect("start");
|
||||
out.write_all(&data).expect("write");
|
||||
}
|
||||
let patched = out.finish().expect("finish").into_inner();
|
||||
deckcraft_pptx::import(&patched).expect("import")
|
||||
}
|
||||
Reference in New Issue
Block a user