DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge #282: Text: a line with a tab wraps at the column edge
aiongg57688aa82e05
diff --cc crates/compose/src/breaker.rsindex 8aec5df04,7646aaba2..6a83ff424--- a/crates/compose/src/breaker.rs+++ b/crates/compose/src/breaker.rs@@@ -748,16 -673,8 +757,17 @@@ pub fn greedycontinue;}let hang_r = right_hang(g, sp);+ let adv = if g.ch == '\t' { tab(line, x, i) } else { g.adv };- if x + adv - hang_r > w + shrink+ let end_shrink = crate::mojikumi::end_elastic(g, sp.justify, sp.kinsoku_priority != 3)[1];+ let available = shrink + sp.box_elastic(g).1.iter().sum::<f64>() + end_shrink;+ if sp.kinsoku_priority == 2- && x + g.adv - hang_r > w++ && x + adv - hang_r > w+ && let Some((end, hyphen)) = last_natural+ {+ brk = Some((end, hyphen, false));+ break;+ }- if x + g.adv - hang_r > w + available.max(0.0)++ if x + adv - hang_r > w + available.max(0.0)&& i > start&& (last_ok.is_some() || glyphs.get(i - 1).is_none_or(|p| p.break_after != Some(false) && !p.no_break)){@@@ -772,8 -689,10 +782,8 @@@});break;}- x += g.adv;+ x += adv;- if sp.justify {- shrink += sp.box_elastic(g).1.iter().sum::<f64>();- }+ shrink += sp.box_elastic(g).1.iter().sum::<f64>();if i + 1 < n && !glyphs[i + 1].is_space() && !g.no_break && g.break_after != Some(false) {if matches!(g.ch, '-' | '\u{2010}' | '\u{2013}' | '\u{2014}' | '/')|| g.break_after.unwrap_or_else(|| cjk_break(g, &glyphs[i + 1], sp))diff --cc crates/compose/src/lib.rsindex a8e40ec55,51bd406e2..f8b35530b--- a/crates/compose/src/lib.rs+++ b/crates/compose/src/lib.rs@@@ -685,22 -607,17 +685,26 @@@ fn compose_with_db(doc: &Document, storlet spacing = spacing_for(&pp, base_chars.size);let mut lines: Vec<(std::ops::Range<usize>, String)> = Vec::new();for _ in 0..3 {- let width = |j: usize| (col.width() - pp.left_indent - pp.right_indent - if j == 0 { pp.first_line_indent } else { 0.0 }).max(1.0);- // The same spacing, hyphenation and breaker as the layout below.+ // The same drop cap, spacing, hyphenation and breaker as the layout below.let mut gl = sp.glyphs.clone();+ let dc = split_drop_cap(db, &mut gl, drop_end, pp.drop_cap_lines, base_leading, base_cap, drop_grid, drop_align);+ let width = |j: usize| {+ let ind = match &dc {+ Some(dc) if j < dc.lines => dc.indent(),+ _ if j == 0 => pp.first_line_indent,+ _ => 0.0,+ };+ (col.width() - pp.left_indent - pp.right_indent - ind).max(1.0)+ };apply_desired_spacing(&mut gl, &pp);+ mojikumi::apply(&mut gl, &doc.styles, &pp.mojikumi);let hy = hyphenation_points(&story.text, &gl, &pp, &hyph_exceptions, &foreign_ranges(doc, story, prange.clone(), &base_chars));let breaks = if pp.composer == Composer::SingleLine || gl.iter().any(|g| g.ch == '\t') || gl.len() > 4000 {- breaker::greedy(&gl, &hy, &spacing, &width)+ let tab = |j: usize, x: f64, i: usize| {+ let ind = pp.left_indent + if j == 0 { pp.first_line_indent } else { 0.0 };+ tab_advance(&pp.tabs, ind + x, gl.get(i + 1..).unwrap_or_default()).0+ };+ breaker::greedy(&gl, &hy, &spacing, &width, &tab)} else if pp.balance_ragged && !spacing.justify {breaker::balanced(&gl, &hy, &spacing, &width)} else {