Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge #283: Text: the line before a column, frame or page break is a last line

aiongg8c6bab93c791
diff --cc crates/compose/src/lib.rs
index a72e44815,9928ecd1f..ba483e133
--- a/crates/compose/src/lib.rs
+++ b/crates/compose/src/lib.rs
@@@ -1042,39 -840,22 +1042,49 @@@ fn compose_with_db(doc: &Document, stor
moved = true;
break;
}
- let ind_l = pp.left_indent + if line_no == 0 { pp.first_line_indent } else { 0.0 };
+ // A drop cap sits at the start-side indent; the first-line indent doesn't move it.
+ let beside = drop_cap.as_ref().filter(|dc| line_no < dc.lines && col_first_line == 0).map(DropCap::indent);
+ let (ind_l, ind_r) = match beside {
+ Some(w) if rtl => (pp.left_indent, pp.right_indent + w),
+ Some(w) => (pp.left_indent + w, pp.right_indent),
+ None => (pp.left_indent + if line_no == 0 { pp.first_line_indent } else { 0.0 }, pp.right_indent),
+ };
let lx0 = x0 + ind_l;
- let lx1 = x1 - pp.right_indent;
+ let lx1 = x1 - ind_r;
let last = k + 1 == breaks.len();
+ // The break character that ends this line, if any (it is the line's last glyph).
+ let brk = if b.forced && e > s {
+ e.checked_sub(1).and_then(|i| glyphs.get(i)).map(|g| g.ch).filter(|&c| breaker::is_forced(c))
+ } else {
+ None
+ };
+ // A column, frame or page break ends the line as a paragraph's last line (last-line
+ // alignment); a justified line ended by a forced line break stays justified.
+ let ends_para = last || matches!(brk, Some(story::COLUMN_BREAK | story::FRAME_BREAK | story::PAGE_BREAK));
+ let forced_mid = brk == Some(story::FORCED_LINE_BREAK) && !last;
let (mut placed, end_x, ratio) =
- layout_line(&glyphs, s, e, b.hyphen, lx0, lx1, col.x0, &pp, &spacing, last, b.forced && !last, f.left_page, &bidi_info);
+ layout_line(&glyphs, s, e, b.hyphen, lx0, lx1, col.x0, &pp, &spacing, ends_para, forced_mid, f.left_page, &bidi_info);
+ // The spaces the break trimmed off the end follow the line undrawn, so the caret
+ // and the selection reach them; alignment and justification ignore them.
+ if pp.direction != designcraft_doc::TextDirection::RightToLeft && !placed.iter().any(|g| g.rtl) {
+ let mut x = end_x;
+ for g in glyphs.get(e..(g0 + b.next).min(glyphs.len())).unwrap_or(&[]).iter().filter(|g| g.is_space()) {
+ placed.push(PlacedGlyph { visible: false, ..place(g, x) });
+ x += g.adv;
+ }
+ }
+ let mut drop_box = None;
+ if line_no == 0
+ && let Some(dc) = &drop_cap
+ {
+ let at = if rtl { x1 - pp.right_indent - dc.width } else { x0 + pp.left_indent - dc.lsb };
+ placed.splice(0..0, place_drop_cap(dc, at, rtl));
+ drop_box = Some(DropCapBox {
+ end: dc.end,
+ baseline: baseline + dc.drop,
+ rect: Rect::new(at, baseline - asc, at + dc.width, baseline + dc.drop + desc),
+ });
+ }
ruby::annotate(db, &styles_tab, &mut placed, doc.settings.glyph_fallback);
let range_end = if last { prange.end } else { glyphs.get(g0 + b.next).map(|g| g.byte).unwrap_or(prange.end) };
let range_start = glyphs.get(s).map(|g| g.byte).unwrap_or(prange.start).min(range_end);
@@@ -1143,10 -904,9 +1153,9 @@@
line_no += 1;
// Column / frame / page break characters.
if b.forced && e < glyphs.len() + 1 {
- let brk = glyphs.get(g0 + b.next.saturating_sub(1)).map(|g| g.ch);
let jumped = match brk {
Some(story::COLUMN_BREAK) => {
- cur.next_column(&cols);
+ next_column(&mut cur);
true
}
Some(story::FRAME_BREAK) | Some(story::PAGE_BREAK) => {