mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-29 20:56:47 -06:00
Conflicts resolved per file (both sides kept unless noted):
crates/engine/src/atomic.rs | 1 | main's: `write_file` removed (main routes command writes through `crate::io::write_file`); its one caller in file.rs now uses `crate::io::write_file`
crates/engine/src/cmd/datamerge/fill.rs | 1 | next's `Graphic` literal (has `clip` and `wrap`, which next's `Graphic` carries)
crates/engine/src/cmd/datamerge/mod.rs | 1 | main's `read_path_capped` (crate::io metadata/read_capped, roots checked); next's capped read is the same behaviour
crates/engine/src/cmd/datamerge/parse.rs | 1 | main's (`crate::io::metadata`, `crate::io::Metadata`)
crates/engine/src/cmd/edit.rs | 1 | next's `spread_param(p, "edit.paste")` (the second argument is the command id on both sides)
crates/engine/src/cmd/export.rs | 3 | main's: EPUB params doc, `toc_title` once (main's position; next's duplicate dropped)
crates/engine/src/cmd/file.rs | 7 | place doc: next's (lists page/rect/autoflow params #803 checks); next's recent-file functions + main's `foreign_document`; next's open (load_bytes, warnings, non-DesignCraft refusal) with main's checked `crate::io::read_file` for the bytes; main's `check_write` be
crates/engine/src/cmd/find.rs | 7 | main's Find scope (FindContext, scope/selection/story, continuation, UTF-8 repair) on next's `designcraft_compose::grep::Grep` (dialect GREP): find uses `find_all` capped at MAX_MATCHES, change uses `replacements`/`find_all` (literal change text not expanded), fin
crates/engine/src/cmd/fonts.rs | 1 | next's (`has_style`, resolved/replacement face); `has_style` already compares styles ignoring spacing and case, which is main's `same_style` fix; main's test kept
crates/engine/src/cmd/interchange.rs | 1 | next's `import_idml_report_with_previews` (previews for unreadable links)
crates/engine/src/cmd/layout.rs | 8 | pages.insert: main's overflow-safe `after` + next's checked `parent_ref`; main's duplicateSpread doc; layout.section: next's `SectionEdit` (already keeps unnamed settings, #717) with main's `d.repaginate()` moved into `SectionEdit::apply` (remove and set paths),
crates/engine/src/cmd/links.rs | 5 | next's links.list (no doc clone); main's `text_status` via crate::io; `use std::io::Read` dropped (unused after main's read_capped); test literals main's. `link_missing` (next) uses `crate::io::exists` for the file-guard scan
crates/engine/src/cmd/object.rs | 4 | object.fill/stroke tint-alone: main's (23e1680e7; out-of-range tint is an error, which main's test asserts); object.fit doc: next's (lists `axis`)
crates/engine/src/cmd/paths.rs | 1 | next's (shatai transform on outlines)
crates/engine/src/cmd/place_text.rs | 1 | next's `add_flow_frame` (used by autoflow)
crates/engine/src/cmd/preflight.rs | 2 | next's overset/unplacedStory issue (its `overset_location` already applies the parent transform main's #738 fix adds); next's two test modules kept with main's
crates/engine/src/cmd/scripts.rs | 1 | combined: next's `in_undo_step = false` (#406) + main's full rollback of a failed script (#709)
crates/engine/src/cmd/style.rs | 14 | param docs next's (gradient swatch.create, swatch stops, model colours); create_para next's; rename_style main's structure (rename entry, then `redirect_style_refs`), redirect has next's full reference set (cells, defaults, notes, TOC) + main's never-based-on-it
crates/engine/src/cmd/text.rs | 10 | main's selectSentence/Paragraph/Story + select_around; next's selectionAttrs (mixed) + main's openTypeFeatures/type.feature; main's comments; tracked typing: next's `reserve_command_text` + main's `insert_format_at`; empty-paragraph mark formatting main's (with `
crates/engine/src/cmd/thread.rs | 1 | next's `spread_param(p, "text.thread")`
crates/engine/src/dtd.rs | 1 | next's linear, depth-bounded `expand_parameter_entities` with main's budget (input + 1 MiB, `MAX_EXPANDED_BYTES`) and message ("expand the DTD beyond"); 16 MiB constant removed; both sides' tests pass on message
crates/engine/src/guard.rs | 2 | main's whole-transaction snapshot (docs, active, journal; #742) + next's `in_undo_step` restore; tests both
crates/engine/src/lib.rs | 5 | LoadedGraphic doc next's; next's `new_document_preview`; execute: main's `discard_stale_find_scope()` before next's nested-undo run; modules both (tests_autosize, tests_file_guard, tests_params, tests_roots)
crates/engine/src/recovery.rs | 1 | next's test (superset of main's assertion)
crates/engine/src/tests.rs | 4 | moved tests deduplicated (identical on both sides); next's preflight and direct-selection/kerning tests + main's style-delete, locked-frame and baseline-fit tests
crates/engine/src/tests_idml.rs | 3 | main's order (drop cap and margins tests identical on both sides, once each)
crates/ui-egui/src/canvas.rs | 3 | next's screen_options/DisplayKey block and tests kept; two tests that auto-merge had added twice (parent_guides_on_a_page_are_not_picked_there, baseline_grid_lines_are_the_ones_on_the_page) kept once; main's `typing`/`screen_at`/`click` helpers and its tests clicks
crates/ui-egui/src/control.rs | 3 | main's `count` check and pending budget (control queue + synthetic queue); exact-budget test runs both sides' cases (click 255 on 9,492 pending; drag 9492×255)
crates/ui-egui/src/cursors.rs | 1 | main's (same Pen cursor set)
crates/ui-egui/src/dialogs.rs | 14 | dialog body (newDocument … alert match) is next's text, with main's Find/Change scope reset (`set_field`, `reset_find_scope`, `find_change_params`) and main's Create Guides / Margins and Columns arms ported in; `Dialog::new` ruby section (next) + main's `set_fi
crates/ui-egui/src/i18n.rs | 7 | ka and pl modules, languages, statics and lookups both; `category_first` covers uk, ru, pl, ka and `count_label` keeps next's Czech plurals; shared TABLE union; next's duplicate rows for Auto, Number:, Gutter:, Top:, Bottom:, Inside:, Outside:, Left:, Right: dropped
crates/ui-egui/src/i18n/ar.rs | 2 | union of rows, no duplicate keys
crates/ui-egui/src/i18n/it.rs | 1 | union of rows, no duplicate keys
crates/ui-egui/src/i18n/ja.rs | 1 | union of rows, no duplicate keys
crates/ui-egui/src/i18n/pt_br.rs | 1 | union of rows, no duplicate keys
crates/ui-egui/src/i18n/uk.rs | 1 | union of rows, no duplicate keys
crates/ui-egui/src/icons.rs | 2 | both tests (main's typography icon, next's distribute icons)
crates/ui-egui/src/lib.rs | 11 | UiState: next's tabs_panel + main's last_color/last_gradient; `cursors` field once; next's SVG paste and paste-on-spread-in-view; next's extensionless document open; opens_as_document next's comment; tests both (next's control bar / key-name tests, main's rich black
crates/ui-egui/src/menus.rs | 15 | app.language doc next's text with pl and ka; UI_COMMANDS both (next's Tabs, Toggle Presentation, Apply None text; main's panel commands, Apply Color, Apply Gradient); Edit › Interface Language stays out (next moved it to Preferences); Type menu main's order with
crates/ui-egui/src/panels/glyphs.rs | 1 | next's (already has main's scroll-bar fix); the scroll-bar test module auto-merge had added twice kept once
crates/ui-egui/src/panels/layers.rs | 3 | next's drag-and-drop `object_rows`, with main's features ported into it: selection reveal (layer opens, row scrolls into view once), selected rows highlighted (also a group whose member is selected), double-click rename in place (`object.rename` queued like
crates/ui-egui/src/panels/mod.rs | 6 | tabs + typography modules and color_panel_tests; SelInfo has wrap_side/wrap_contour and wrap_offsets (offsets from the graphic's own wrap when it is selected); next's swatch_picker returning the chip response; next's content_selection_tests
crates/ui-egui/src/panels/pages.rs | 1 | next's (parents dragged by id)
crates/ui-egui/src/panels/properties.rs | 4 | next's swatch popup (Apply To, Tint); main's four wrap offsets then next's Wrap To / Contour Type; test fixtures main's (`..Default::default()`, no unused builder)
crates/ui-egui/src/panels/swatches.rs | 3 | main's Delete Swatch button + next's New Swatch comment; next's draggable rows; click: main's PICKED + fill/stroke in front, with next's no-apply on double-click
crates/ui-egui/src/toolbar.rs | 2 | main's Apply Color / Gradient / None wells and functions; next's apply_none doc line
crates/compose/src/lib.rs | 5 | next's line loop kept (mark_leading + last_line_mark, wrap segments/carry, grid gyoudori); main's mark-chars base_leading block (auto-merged) stays beside it. `fits`: next's #106 rule (baseline fit for horizontal frames, full descent for paths, vertical text, footnote
crates/compose/src/tests.rs | 5 | next's tests (tombstone set, sliver/one-sided/contour/clipping wrap tests, borders, lists, kenten, grid, anchored wrap, balance, shaped frames) plus main's an_empty_last_paragraph_isnt_overset; main's wrap_object_beside_one_narrow_column_leaves_the_other_alone re-ad
crates/doc/src/assets.rs | 1 | main's doc comment (same meaning)
crates/doc/src/build.rs | 3 | parent_page_for: next's parent_page_for_side (RTL-aware); single_sided_page_shows_first_parent_page test kept once, at main's position
crates/doc/src/item.rs | 1 | next's rotated_group_bounds_follow_the_children_outlines test kept
crates/doc/src/lib.rs | 1 | next's kerning_increment field kept; main's "Bulleted & Numbered" wording
crates/doc/src/page.rs | 1 | next's outer_page_indices + parent_page_for_side (integration of parent-margins with rtl-master-sides); main's parent_page_index dropped, its only caller (build.rs) uses parent_page_for_side
crates/doc/src/slice.rs | 5 | extract: next's `marked()` (get-based, fix_notes/fix_endnotes/fix_marks; main's version indexed slices and could panic); insert_story: main's take() limit on endnote/editorial payload copies with next's id comment, redundant `let ne`/`let nn` dropped; main's excess_note
crates/geom/src/corners.rs | 1 | next's box_outline_rounds_only_closed_corners test kept
crates/render/src/damage.rs | 1 | next's wrapping-anchored-object damage test kept
crates/render/src/fx.rs | 2 | feather: next's choke/corners sigma+join inside main's structure (body and clip at device resolution, with_filters(.., None)); inner glow centre: next's blend `mix` with main's clip argument (bp, xf)
crates/render/src/lib.rs | 3 | next's layer comment; next's front baseline grid draw after items; gradient match on g.kind (main's tuple scrutinee did not match the single-pattern arms)
crates/render/src/text.rs | 5 | paint_glyphs: main's paint_stroke closure structure with next's stroke overprint (overprinting helper, stroke `(TextPaint, bool)`); callers pass next's overprint_fill/overprint_stroke
crates/render/tests/placed_pdf.rs | 1 | main's `near` helper version
crates/tools/src/lib.rs | 1 | main's (PenConvert already declared below, avoids a duplicate variant)
crates/tools/src/pen.rs | 1 | main's module doc
crates/tools/src/select.rs | 1 | next's Drag::Corner variant (live corners) kept
crates/tools/src/tests.rs | 4 | next's tests (content drag, live corners, table border drag, eyedropper matchFrom, fitting handles, pen cursors once); eyedropper_ignores_inactive keeps next's samples_image check (main's exact-JSON compare lacks matchFrom) with main's `..Default::default()` Asset lit
crates/tools/src/text.rs | 2 | next's table border drag (BorderDrag, border_at) kept, then main's comment on locked text frames
crates/tools/src/xform.rs | 2 | main's explicit `Vec<&Item>` for shown children; next's eyedropper matchFrom (integration 796e9d713)
Cargo.toml | 2 | main's craft-pdf workspace dep added (craft-print stays once, in next's craft-libs block); [patch.crates-io] keeps next's winit (rust-windowing #4694 backport) and adds main's krilla patch; main's skylartaylor winit left out (see UNSURE 1)
Cargo.lock | 1 | union: next's craft-atomic and craft-cms entries plus main's craft-pdf entry; needs `cargo` normalisation
README.md | 1 | Open bullet combines INDD import via indd-utils (next) and editable PowerPoint export (main); main's paragraph break kept
contributors/people.toml | 1 | both people kept (switch87 from next, Nmarello from main)
apps/designcraft-cli/src/main.rs | 4 | next's `Export` enum dispatch kept; main's .pptx export added as `Export::Pptx` (run prints slides and warnings, script runs file.exportPptx); main's `--pdf-options` null-as-{} parse; usage lines list .pptx
apps/designcraft/src/main.rs | 3 | `startup.leave()` right after `app.ui` (main #380) and next's macOS `sync_movable` kept after the IME discard; next's Apple Events install kept; main's macOS Dock Quit `with_close_requested_on_terminate` block left out (needs the skylartaylor winit; UNSURE 1)
crates/fonts/src/fontdb.rs | 9 | FONT6 aliases (next) combined with #911 WWS names (main): ScannedFace and both CatalogEntry constructors carry `wws` and `aliases`; `canonical_family` falls back to WWS family names; `exact_style_traits` canonicalises then tries typographic, then WWS names (`named_st
crates/format/src/lib.rs | 1 | tests: both sides kept (next's r7a nullable-default tests; main's oversized ZIP entry/asset/entry-count tests)
crates/idml/src/import.rs | 11 | main's bounded `Package` reader under next's `import_idml_report_with_previews` (metadata read through `pkg.part`); next's `tab_list_repaired` kept; ruler origin: next's `settings.ruler_origin`, and main's guide import reads it (main's private `RulerOrigin` enum and
crates/idml/src/tests.rs | 6 | item-level union: all next tests plus main's new ones (ruler guides, package limits, CJK leading model, liquid page rules module, mojikumi); no test dropped
crates/mcp/src/backend.rs | 1 | test comment merged from both
crates/pdf/src/tests.rs | 1 | tests: both sides kept
crates/pdf/src/text.rs | 4 | next's (skew `tan`, cluster `start`, ruby overprint warning); main had no change here beyond base
crates/textimport/src/docx.rs | 5 | next's (ListCounter integration for list levels, page-break test position); main's side was the older form of the same code
crates/epub/src/lib.rs | 30 | non-test code is next's (StoryWriter holds img_src/images/no_alt/heading_ids; covers main's #787/#791/#782 fixes, plus #314 group transforms, anchored images in images_without_alt, endnote story skipped in the TOC); tests: next's set plus main's extra css_weight_style a
docs/control-protocol.md | 2 | next's rows (ui.paste, count 1–255, documentGrid) and wording
docs/file-format-parity.md | 1 | rows combined (next's ICC notes, main's TIFF indexed colour)
docs/gaps.md | 2 | status change notes unioned; Flex Layout removed from missing (main implemented it), next's Parent Options sentence kept
docs/localization-parity.md | 4 | Polish and Georgian rows; 5 languages beyond the twelve; file list includes cs and ka; both history rows
docs/roadmap.md | 1 | M1 next's (#186 fixed on next), M2 main's IME wording
docs/target-app-parity.md | 6 | next's status line; File formats row next's, UI/UX row main's (IME no longer failing); UI line next's plus main's Swatches detail; one Page tool line (main's fuller one); Load styles and main's fuller Pathfinder line both kept, main's duplicate short Pathfinder line r
docs/ui-parity.md | 1 | IME row main's, Font menu row next's
i18n/fr.rs: five rows dropped that main's shared table now has (Row, Open Path, Flex Layout, Current Page Number, Rulers).
354 lines
16 KiB
Rust
354 lines
16 KiB
Rust
use designcraft_geom::Rect;
|
|
|
|
use super::*;
|
|
use crate::build::NewDocument;
|
|
|
|
fn doc() -> Document {
|
|
Document::new(&NewDocument { pages: 2, ..Default::default() })
|
|
}
|
|
|
|
#[test]
|
|
fn threading_moves_frames_and_text() {
|
|
let mut d = doc();
|
|
let lid = d.default_layer();
|
|
let (a, sa) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(10.0, 10.0, 100.0, 100.0), lid, "first", ParaFormat::default()).unwrap();
|
|
let (b, sb) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(110.0, 10.0, 200.0, 100.0), lid, "second", ParaFormat::default()).unwrap();
|
|
d.thread(a, b).unwrap();
|
|
d.check().unwrap();
|
|
assert!(d.story(sb).is_none());
|
|
let st = d.story(sa).unwrap();
|
|
assert_eq!(st.text, "first\nsecond");
|
|
assert_eq!(st.frames, vec![a, b]);
|
|
assert_eq!(d.next_frame(a), Some(b));
|
|
assert_eq!(d.prev_frame(b), Some(a));
|
|
d.unthread_after(a).unwrap();
|
|
d.check().unwrap();
|
|
assert_eq!(d.story(sa).unwrap().frames, vec![a]);
|
|
assert_ne!(d.item(b).unwrap().text_frame().unwrap().story, sa);
|
|
}
|
|
|
|
#[test]
|
|
fn thread_to_empty_frame_converts_it() {
|
|
let mut d = doc();
|
|
let lid = d.default_layer();
|
|
let (a, sa) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(10.0, 10.0, 100.0, 100.0), lid, "x", ParaFormat::default()).unwrap();
|
|
let id = ItemId(d.alloc());
|
|
let it = Item::new(id, lid, Shape::Rectangle, designcraft_geom::shapes::rectangle(Rect::new(0.0, 200.0, 50.0, 300.0)));
|
|
d.insert_item(SpreadRef::Doc(0), it, None).unwrap();
|
|
d.thread(a, id).unwrap();
|
|
assert!(d.item(id).unwrap().is_text_frame());
|
|
assert_eq!(d.story(sa).unwrap().frames, vec![a, id]);
|
|
d.check().unwrap();
|
|
assert!(d.thread(a, a).is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn threading_merges_tables_notes_and_endnotes() {
|
|
let mut d = doc();
|
|
let lid = d.default_layer();
|
|
let (a, sa) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(10.0, 10.0, 100.0, 100.0), lid, "first", ParaFormat::default()).unwrap();
|
|
let (b, sb) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(110.0, 10.0, 200.0, 100.0), lid, "second", ParaFormat::default()).unwrap();
|
|
for (sid, note) in [(sa, "Note A"), (sb, "Note B")] {
|
|
let st = d.story_mut(sid).unwrap();
|
|
st.insert_note(3, note, ParaFormat::default());
|
|
// Both stories hold a table with id 1.
|
|
let n = st.len();
|
|
st.insert_table(n, crate::table::Table::new(1, 2, 2, 0, 0, 80.0));
|
|
}
|
|
let st = d.story_mut(sb).unwrap();
|
|
st.insert_endnote(2, "End B", ParaFormat::default());
|
|
st.insert(1, &crate::NOTE_MARK.to_string());
|
|
d.thread(a, b).unwrap();
|
|
d.check().unwrap();
|
|
let st = d.story(sa).unwrap();
|
|
assert!(d.story(sb).is_none());
|
|
assert_eq!(st.tables.len(), 2);
|
|
assert_eq!(st.notes.len(), 2);
|
|
assert_eq!(st.notes[1].text.text, "Note B");
|
|
assert_eq!(st.endnotes.len(), 1);
|
|
assert_eq!(st.endnotes[0].text.text, "End B");
|
|
assert_eq!(st.editorial.len(), 1);
|
|
}
|
|
|
|
#[test]
|
|
fn empty_frame_threaded_before_a_story_joins_it_at_the_front() {
|
|
let mut d = doc();
|
|
let lid = d.default_layer();
|
|
let (a, sa) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(10.0, 10.0, 100.0, 100.0), lid, "", ParaFormat::default()).unwrap();
|
|
let (b, sb) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(110.0, 10.0, 200.0, 100.0), lid, "Hello", ParaFormat::default()).unwrap();
|
|
d.thread_keeping_story(a, b).unwrap();
|
|
d.check().unwrap();
|
|
assert!(d.story(sa).is_none());
|
|
let st = d.story(sb).unwrap();
|
|
assert_eq!(st.frames, vec![a, b]);
|
|
assert_eq!(st.text, "Hello");
|
|
}
|
|
|
|
#[test]
|
|
fn empty_story_takes_the_threaded_text_without_a_blank_paragraph() {
|
|
let mut d = doc();
|
|
let lid = d.default_layer();
|
|
let (a, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(10.0, 10.0, 100.0, 100.0), lid, "", ParaFormat::default()).unwrap();
|
|
let (a2, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(10.0, 110.0, 100.0, 200.0), lid, "", ParaFormat::default()).unwrap();
|
|
d.thread(a, a2).unwrap();
|
|
let (b, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(110.0, 10.0, 200.0, 100.0), lid, "Hello", ParaFormat::default()).unwrap();
|
|
d.thread(a2, b).unwrap();
|
|
d.check().unwrap();
|
|
let st = d.story(d.item(a).unwrap().text_frame().unwrap().story).unwrap();
|
|
assert_eq!(st.frames, vec![a, a2, b]);
|
|
assert_eq!(st.text, "Hello");
|
|
}
|
|
|
|
#[test]
|
|
fn threading_from_an_empty_frame_makes_it_a_text_frame() {
|
|
let mut d = doc();
|
|
let lid = d.default_layer();
|
|
let id = ItemId(d.alloc());
|
|
let it = Item::new(id, lid, Shape::Rectangle, designcraft_geom::shapes::rectangle(Rect::new(0.0, 200.0, 50.0, 300.0)));
|
|
d.insert_item(SpreadRef::Doc(0), it, None).unwrap();
|
|
let (b, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(110.0, 10.0, 200.0, 100.0), lid, "Hello", ParaFormat::default()).unwrap();
|
|
d.thread(id, b).unwrap();
|
|
d.check().unwrap();
|
|
let st = d.story(d.item(id).unwrap().text_frame().unwrap().story).unwrap();
|
|
assert_eq!(st.frames, vec![id, b]);
|
|
assert_eq!(st.text, "Hello");
|
|
}
|
|
|
|
#[test]
|
|
fn removing_a_frame_from_its_thread_keeps_the_text_in_the_others() {
|
|
let mut d = doc();
|
|
let lid = d.default_layer();
|
|
let (a, sa) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(10.0, 10.0, 100.0, 100.0), lid, "words", ParaFormat::default()).unwrap();
|
|
let (b, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(110.0, 10.0, 200.0, 100.0), lid, "", ParaFormat::default()).unwrap();
|
|
let (c, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(210.0, 10.0, 300.0, 100.0), lid, "", ParaFormat::default()).unwrap();
|
|
d.thread(a, b).unwrap();
|
|
d.thread(b, c).unwrap();
|
|
d.remove_from_thread(b).unwrap();
|
|
d.check().unwrap();
|
|
assert_eq!(d.story(sa).unwrap().frames, vec![a, c]);
|
|
assert_eq!(d.story(sa).unwrap().text, "words");
|
|
let own = d.item(b).unwrap().text_frame().unwrap().story;
|
|
assert_ne!(own, sa);
|
|
assert!(d.story(own).unwrap().text.is_empty());
|
|
// A frame alone in its story has no thread to leave.
|
|
assert!(d.remove_from_thread(b).is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn a_frame_removed_from_a_vertical_thread_stays_vertical() {
|
|
let mut d = doc();
|
|
let lid = d.default_layer();
|
|
let (a, sa) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(10.0, 10.0, 100.0, 100.0), lid, "縦書き", ParaFormat::default()).unwrap();
|
|
let (b, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(110.0, 10.0, 200.0, 100.0), lid, "", ParaFormat::default()).unwrap();
|
|
d.story_mut(sa).unwrap().vertical = true;
|
|
d.thread(a, b).unwrap();
|
|
d.remove_from_thread(b).unwrap();
|
|
d.check().unwrap();
|
|
assert!(d.frame_vertical(d.item(a).unwrap()));
|
|
assert!(d.frame_vertical(d.item(b).unwrap()), "the removed frame keeps the story's direction");
|
|
}
|
|
|
|
#[test]
|
|
fn a_frame_removed_from_a_right_to_left_thread_keeps_its_column_order() {
|
|
let mut d = doc();
|
|
let lid = d.default_layer();
|
|
let (a, sa) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(10.0, 10.0, 100.0, 100.0), lid, "نص", ParaFormat::default()).unwrap();
|
|
let (b, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(110.0, 10.0, 200.0, 100.0), lid, "", ParaFormat::default()).unwrap();
|
|
d.story_mut(sa).unwrap().direction = crate::TextDirection::RightToLeft;
|
|
d.thread(a, b).unwrap();
|
|
d.remove_from_thread(b).unwrap();
|
|
d.check().unwrap();
|
|
let own = d.item(b).unwrap().text_frame().unwrap().story;
|
|
assert_eq!(d.story(own).unwrap().direction, crate::TextDirection::RightToLeft);
|
|
}
|
|
|
|
#[test]
|
|
fn frames_keep_their_story_direction_through_threading() {
|
|
let mut d = doc();
|
|
let lid = d.default_layer();
|
|
let r = |x: f64| Rect::new(x, 10.0, x + 50.0, 100.0);
|
|
let vertical = |d: &Document, f: ItemId| d.item(f).is_some_and(|i| d.frame_vertical(i));
|
|
let (a, sa) = d.add_text_frame(SpreadRef::Doc(0), r(0.0), lid, "縦", ParaFormat::default()).unwrap();
|
|
let (b, _) = d.add_text_frame(SpreadRef::Doc(0), r(60.0), lid, "", ParaFormat::default()).unwrap();
|
|
d.story_mut(sa).unwrap().vertical = true;
|
|
// A horizontal frame threaded onto a vertical story turns vertical.
|
|
d.thread(a, b).unwrap();
|
|
assert!(vertical(&d, a) && vertical(&d, b));
|
|
// Threading the vertical story's second frame after a horizontal frame: it turns horizontal,
|
|
// and the frame left before it stays vertical.
|
|
let (h, _) = d.add_text_frame(SpreadRef::Doc(0), r(120.0), lid, "横", ParaFormat::default()).unwrap();
|
|
d.thread(h, b).unwrap();
|
|
assert!(vertical(&d, a) && !vertical(&d, b) && !vertical(&d, h));
|
|
// Breaking a vertical thread leaves the frames after the break vertical.
|
|
let (c, _) = d.add_text_frame(SpreadRef::Doc(0), r(180.0), lid, "", ParaFormat::default()).unwrap();
|
|
d.thread(a, c).unwrap();
|
|
d.unthread_after(a).unwrap();
|
|
assert!(vertical(&d, a) && vertical(&d, c));
|
|
assert_ne!(d.item(c).unwrap().text_frame().unwrap().story, sa);
|
|
d.check().unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn frames_keep_their_column_direction_through_threading() {
|
|
use crate::TextDirection::{LeftToRight, RightToLeft};
|
|
let mut d = doc();
|
|
let lid = d.default_layer();
|
|
let r = |x: f64| Rect::new(x, 10.0, x + 50.0, 100.0);
|
|
let direction = |d: &Document, f: ItemId| d.story(d.item(f).unwrap().text_frame().unwrap().story).unwrap().direction;
|
|
let (a, sa) = d.add_text_frame(SpreadRef::Doc(0), r(0.0), lid, "نص", ParaFormat::default()).unwrap();
|
|
let (b, _) = d.add_text_frame(SpreadRef::Doc(0), r(60.0), lid, "", ParaFormat::default()).unwrap();
|
|
d.story_mut(sa).unwrap().direction = RightToLeft;
|
|
d.thread(a, b).unwrap();
|
|
assert_eq!((direction(&d, a), direction(&d, b)), (RightToLeft, RightToLeft));
|
|
// Threading the right-to-left story's second frame after a left-to-right frame: the frame
|
|
// left before it stays right to left.
|
|
let (h, _) = d.add_text_frame(SpreadRef::Doc(0), r(120.0), lid, "abc", ParaFormat::default()).unwrap();
|
|
d.thread(h, b).unwrap();
|
|
assert_eq!((direction(&d, a), direction(&d, b), direction(&d, h)), (RightToLeft, LeftToRight, LeftToRight));
|
|
// Breaking a right-to-left thread leaves the frames after the break right to left.
|
|
let (c, _) = d.add_text_frame(SpreadRef::Doc(0), r(180.0), lid, "", ParaFormat::default()).unwrap();
|
|
d.thread(a, c).unwrap();
|
|
d.unthread_after(a).unwrap();
|
|
assert_ne!(d.item(c).unwrap().text_frame().unwrap().story, sa);
|
|
assert_eq!((direction(&d, a), direction(&d, c)), (RightToLeft, RightToLeft));
|
|
d.check().unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn removing_last_frame_deletes_story() {
|
|
let mut d = doc();
|
|
let lid = d.default_layer();
|
|
let (a, sa) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(10.0, 10.0, 100.0, 100.0), lid, "x", ParaFormat::default()).unwrap();
|
|
d.remove_item(a).unwrap();
|
|
assert!(d.story(sa).is_none());
|
|
d.check().unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn hit_testing_respects_layers() {
|
|
let mut d = doc();
|
|
let lid = d.default_layer();
|
|
let (a, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(10.0, 10.0, 100.0, 100.0), lid, "x", ParaFormat::default()).unwrap();
|
|
assert_eq!(d.hit_item(0, designcraft_geom::Point::new(50.0, 50.0), 2.0), Some(a));
|
|
assert_eq!(d.hit_item(0, designcraft_geom::Point::new(300.0, 300.0), 2.0), None);
|
|
d.layer_mut(lid).unwrap().locked = true;
|
|
assert_eq!(d.hit_item(0, designcraft_geom::Point::new(50.0, 50.0), 2.0), None);
|
|
}
|
|
|
|
#[test]
|
|
fn page_numbers_saturate_at_the_largest_start() {
|
|
// A start number from a file or an old command: page 2 overflowed (a panic in debug builds).
|
|
let mut d = crate::Document::new(&crate::build::NewDocument { pages: 3, facing_pages: false, ..Default::default() });
|
|
d.sections = vec![crate::Section {
|
|
start: 0,
|
|
start_number: Some(u32::MAX),
|
|
style: Default::default(),
|
|
prefix: String::new(),
|
|
marker: String::new(),
|
|
include_prefix: false,
|
|
}];
|
|
assert_eq!((0..3).map(|i| d.page_number(i)).collect::<Vec<_>>(), [u32::MAX; 3]);
|
|
d.sections.push(crate::Section { start: 2, start_number: None, ..d.sections[0].clone() });
|
|
assert_eq!(d.page_number(2), u32::MAX, "a section continuing it saturates too");
|
|
}
|
|
|
|
#[test]
|
|
fn page_names_follow_sections() {
|
|
let mut d = Document::new(&NewDocument { pages: 6, ..Default::default() });
|
|
assert_eq!(d.page_name(0), "1");
|
|
d.sections.push(Section {
|
|
start: 2,
|
|
start_number: Some(1),
|
|
style: NumberStyle::LowerRoman,
|
|
prefix: "A-".into(),
|
|
marker: String::new(),
|
|
include_prefix: true,
|
|
});
|
|
assert_eq!(d.page_name(1), "2");
|
|
assert_eq!(d.page_name(2), "A-i");
|
|
assert_eq!(d.page_name(4), "A-iii");
|
|
// A section that continues numbering.
|
|
d.sections.push(Section {
|
|
start: 5,
|
|
start_number: None,
|
|
style: NumberStyle::Arabic,
|
|
prefix: String::new(),
|
|
marker: String::new(),
|
|
include_prefix: false,
|
|
});
|
|
assert_eq!(d.page_name(5), "4");
|
|
}
|
|
|
|
/// A section restarting at 1 on page 2 leaves two odd (right) pages in a row; each gets its own
|
|
/// spread instead of sharing one with the odd page on the left.
|
|
#[test]
|
|
fn consecutive_right_pages_get_separate_spreads() {
|
|
let mut d = Document::new(&NewDocument { pages: 4, ..Default::default() });
|
|
d.sections.push(Section {
|
|
start: 1,
|
|
start_number: Some(1),
|
|
style: NumberStyle::Arabic,
|
|
prefix: String::new(),
|
|
marker: String::new(),
|
|
include_prefix: false,
|
|
});
|
|
d.repaginate();
|
|
let sides: Vec<Vec<PageSide>> = d.spreads.iter().map(|s| s.pages.iter().map(|p| p.side).collect()).collect();
|
|
assert_eq!(sides, vec![vec![PageSide::Right], vec![PageSide::Right], vec![PageSide::Left, PageSide::Right]]);
|
|
let flat: Vec<PageSide> = sides.into_iter().flatten().collect();
|
|
for (i, side) in flat.iter().enumerate() {
|
|
assert_eq!(*side == PageSide::Right, d.page_number(i) % 2 == 1, "page {i}");
|
|
}
|
|
d.check().unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn hostile_section_start_numbers_saturate() {
|
|
let mut d = Document::new(&NewDocument { pages: 3, ..Default::default() });
|
|
let first = d.sections.iter_mut().find(|s| s.start == 0).unwrap();
|
|
first.start_number = Some(u32::MAX);
|
|
let continuing = Section { start: 2, start_number: None, ..first.clone() };
|
|
d.sections.push(continuing);
|
|
assert_eq!(d.page_number(1), u32::MAX);
|
|
assert_eq!(d.page_number(2), u32::MAX);
|
|
assert_eq!(d.page_name(2), u32::MAX.to_string());
|
|
}
|
|
|
|
#[test]
|
|
fn document_serde_roundtrip() {
|
|
let mut d = doc();
|
|
let lid = d.default_layer();
|
|
d.add_text_frame(SpreadRef::Doc(0), Rect::new(10.0, 10.0, 100.0, 100.0), lid, "héllo\nworld", ParaFormat::default()).unwrap();
|
|
let s = serde_json::to_string(&d).unwrap();
|
|
let back: Document = serde_json::from_str(&s).unwrap();
|
|
assert_eq!(d, back);
|
|
back.check().unwrap();
|
|
}
|
|
|
|
/// A file can set `next_id` to `u64::MAX`; the next allocated id then overflowed (IDML export
|
|
/// adds to it too). Such a document is rejected when it is checked on load.
|
|
#[test]
|
|
fn next_id_near_the_top_is_rejected() {
|
|
let mut d = Document::new(&crate::build::NewDocument::default());
|
|
d.check().unwrap();
|
|
d.next_id = u64::MAX;
|
|
assert!(d.check().is_err());
|
|
d.next_id = crate::MAX_NEXT_ID;
|
|
d.check().unwrap();
|
|
}
|
|
|
|
/// A placed PDF saved before its crop choice was stored loads with the crop box (the whole page),
|
|
/// and that default isn't written out.
|
|
#[test]
|
|
fn placed_pdf_without_a_crop_choice_loads_with_the_crop_box() {
|
|
let a: Asset = serde_json::from_str(r#"{"id": 7, "name": "a.pdf", "mime": "application/pdf", "page": 1}"#).unwrap();
|
|
assert_eq!((a.pdf_crop, a.pdf_box, a.shown_box()), (PdfCrop::Crop, None, None));
|
|
let json = serde_json::to_string(&a).unwrap();
|
|
assert!(!json.contains("pdfCrop") && !json.contains("pdfBox"), "{json}");
|
|
let trim = Asset { pdf_crop: PdfCrop::Trim, pdf_box: Some([0.1, 0.1, 0.9, 0.9]), ..a };
|
|
let back: Asset = serde_json::from_str(&serde_json::to_string(&trim).unwrap()).unwrap();
|
|
assert_eq!((back.pdf_crop, back.shown_box()), (PdfCrop::Trim, Some([0.1, 0.1, 0.9, 0.9])));
|
|
// A box with no area shows the whole page.
|
|
assert_eq!(Asset { pdf_box: Some([0.5, 0.5, 0.5, 0.9]), ..back }.shown_box(), None);
|
|
}
|