DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge #860: fix(compose): odd/even page starts keep their parity at the top of a frame
aiongg3497da393991
diff --cc crates/compose/src/lib.rsindex 5c8441ca3,6d4c4bb9f..667cfa0f6--- a/crates/compose/src/lib.rs+++ b/crates/compose/src/lib.rs@@@ -887,56 -566,21 +887,59 @@@ fn compose_with_db(doc: &Document, storpi = j;continue 'paras;}+ if pi >= np {+ // The story ends here: Balance Columns evens out the columns of its last frame.+ if balance_frames > 0+ && let Some(j) = balance_end(&mut trial, &mut limits, &cur, &cols, frames, &out, np, balance_runs < balance_budget)+ {+ balance_runs += 1;+ rewind(j, &snaps, ¬e_snaps, &mut notes, &mut out, &mut cur, &mut list_counter, &mut force_col, &mut line_cap);+ pi = j;+ continue 'paras;+ }+ break 'paras;+ }+ if deleted.get(pi).copied().unwrap_or(false) {+ // A deleted paragraph takes no room; for keeps it stands in for the one before it.+ let filler = info.last().map_or(+ ParaInfo {+ start: (cur.fi, cur.col),+ at_top: cur.last_baseline.is_none(),+ end: (cur.fi, cur.col),+ lines: 0,+ lines_in_end_col: 0,+ keep_with_next: 0,+ keep_together: false,+ keep_all: false,+ keep_first: 1,+ keep_last: 1,+ },+ |p| ParaInfo { lines_in_end_col: 0, ..p.clone() },+ );+ info.push(filler);+ pi += 1;+ continue;+ }+ let prange = para_ranges[pi].clone();let pf = &story.paras[pi];- let (pp, base_chars) = doc.styles.resolve_para(pf);+ let (mut pp, base_chars) = doc.styles.resolve_para(pf);// A break character that ends the previous paragraph sends this one on, like a start option.- let after_break = pi- .checked_sub(1)- .and_then(|p| para_ranges.get(p))- .and_then(|r| story.text.get(r.clone()))- .and_then(|t| t.chars().next_back())- .and_then(break_start);+ // Deleted paragraphs in between don't count, nor does a deleted or hidden break.+ let after_break = (0..pi).rev().find(|p| !deleted.get(*p).copied().unwrap_or(false)).and_then(|p| {+ let r = para_ranges.get(p)?;+ let (i, c) = story.text.get(r.clone())?.char_indices().next_back()?;+ let start = break_start(c)?;+ let (_, chars) = doc.styles.resolve_para(story.paras.get(p)?);+ let props = doc.styles.resolve_char(&chars, story.char_format_at(r.start + i + c.len_utf8()));+ let gone = props.change == designcraft_doc::ChangeMark::Deleted || doc.conditions_hide(&props.conditions);+ (!gone).then_some(start)+ });if let Some(t) = story.para_table(pi) {+ let start = after_break.unwrap_or(pp.start_paragraph);if cur.last_baseline.is_some() {- cur.start(after_break.unwrap_or(pp.start_paragraph), &cols, frames, doc);+ cur.start(start, &cols, frames, doc);+ } else {+ cur.start_at_top(start, frames, doc);}let at_top = cur.last_baseline.is_none();let start_at = (cur.fi, cur.col);@@@ -1246,30 -795,27 +1249,35 @@@};// A paragraph start or a break character; Next Column while a paragraph spans columns is// the next frame, as above.- let begin_at = |cur: &mut Cursor, start: StartParagraph| match start {- StartParagraph::NextColumn => next_column(cur),+ let go = |cur: &mut Cursor, start: StartParagraph| match start {+ StartParagraph::NextColumn => {+ let (fi, col) = (cur.fi, cur.col);+ next_column(cur);+ if cur.fi == fi && cur.col != col {+ cur.band.tail = Some((cur.pi, cur.col));+ }+ }other => cur.start(other, &cols, frames, doc),};- // Paragraph start options.- if let Some(start) = after_break- && cur.last_baseline.is_some()- {- go(&mut cur, start);+ // Paragraph start options. At the top of a frame there is nothing to break away from, but+ // an odd or even page start still has to land on a page of that parity.+ if let Some(start) = after_break {+ if cur.last_baseline.is_some() {- begin_at(&mut cur, start);++ go(&mut cur, start);+ } else {+ cur.start_at_top(start, frames, doc);+ }}if force_col[pi] {next_column(&mut cur);}if cur.last_baseline.is_some() {- begin_at(&mut cur, pp.start_paragraph);+ go(&mut cur, pp.start_paragraph);+ } else {+ cur.start_at_top(pp.start_paragraph, frames, doc);}+ // Text in the columns above a spanning paragraph, or a split block starting below text.+ let mut text_above = cur.split.is_none() && split_cfg.is_some();if spanning && cur.fi < frames.len() {// Close the band: the paragraph goes below the deepest of its columns, which are// balanced first.