mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-24 10:16:59 -06:00
Merge pull request #1148 from y-az/fix/page-number-digits
Breaker: keep a page number's digits together
This commit is contained in:
@@ -563,7 +563,11 @@ fn overlong_words(items: &[Item], ig: &[usize], glyphs: &[Glyph], measure: f64)
|
||||
let marks = out.get_or_insert_with(|| vec![false; glyphs.len()]);
|
||||
for i in a..b {
|
||||
let (Some(g), Some(next)) = (glyphs.get(i), glyphs.get(i + 1)) else { continue };
|
||||
// Glyphs of one source character (an automatic page number's digits, a
|
||||
// multi-glyph cluster) stay together, as InDesign keeps them.
|
||||
let one_char = next.byte == g.byte && (next.len == 0 || next.len == g.len);
|
||||
let ok = !g.no_break
|
||||
&& !one_char
|
||||
&& g.break_after != Some(false)
|
||||
&& next.ch != SOFT_HYPHEN
|
||||
&& !is_forced(next.ch)
|
||||
|
||||
@@ -474,6 +474,23 @@ fn jump_object_keeps_grid_aligned_lines_on_the_grid() {
|
||||
assert!((l.baseline - want).abs() < 1e-6, "{} vs {want}", l.baseline);
|
||||
}
|
||||
|
||||
/// An automatic page number wider than its frame stays on one line and hangs out, as in InDesign
|
||||
/// ("136" in a frame made for two digits); breaking it put "13" over "4".
|
||||
#[test]
|
||||
fn page_number_wider_than_its_frame_stays_whole() {
|
||||
let text = designcraft_doc::story::PAGE_NUMBER.to_string();
|
||||
let (d, sid, _) = doc_with(&text, Rect::new(0.0, 0.0, 10.0, 40.0), ParaAttrs::default());
|
||||
let mut specs = frame_specs(&d, sid);
|
||||
specs[0].page_name = Some("136".into());
|
||||
let cs = compose(&d, d.story(sid).unwrap(), &specs, &ComposeOptions::default());
|
||||
let lines = all_lines(&cs);
|
||||
assert_eq!(lines.len(), 1, "{lines:?}");
|
||||
assert!(!cs.is_overset());
|
||||
// A word of ordinary letters that doesn't fit still breaks where it must.
|
||||
let (d, sid, _) = doc_with("Wordwiderthanframe", Rect::new(0.0, 0.0, 30.0, 200.0), ParaAttrs::default());
|
||||
assert!(all_lines(&compose_story(&d, sid, &ComposeOptions::default())).len() > 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hostile_wrap_geometry_terminates() {
|
||||
let (d, sid) = wrap_doc(ParaAttrs { grid_align: Some(GridAlign::AllLines), ..Default::default() }, &[]);
|
||||
|
||||
Reference in New Issue
Block a user