Skip to content

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

Merge #310: Justification: tight word spacing doesn't isolate a word; fixed-width spaces don't stretch

aionggf977482e06d4
diff --cc crates/compose/src/breaker.rs
index bf2c23450,5327bdf60..33e55002f
--- a/crates/compose/src/breaker.rs
+++ b/crates/compose/src/breaker.rs
@@@ -166,20 -180,7 +190,21 @@@ const NONE: usize = usize::MAX
impl Item {
fn boxed(w: f64, st: [f64; 3], sh: [f64; 3]) -> Item {
- Item { kind: Kind::Box, w, st, sh, p: 0.0, flagged: false, auto: false, hang: 0.0, zone_from: NONE, emergency: false, over: 0.0 }
+ Item {
+ kind: Kind::Box,
+ w,
+ st,
+ sh,
+ p: 0.0,
+ flagged: false,
+ auto: false,
+ hang: 0.0,
+ edge_elastic: [0.0; 2],
+ start_elastic: [0.0; 2],
+ zone_from: NONE,
+ emergency: false,
++ over: 0.0,
+ }
}
fn glue(w: f64, st: f64, sh: f64) -> Item {
Item {
@@@ -191,27 -192,13 +216,29 @@@
flagged: false,
auto: false,
hang: 0.0,
+ edge_elastic: [0.0; 2],
+ start_elastic: [0.0; 2],
zone_from: NONE,
emergency: false,
+ over: 0.0,
}
}
fn penalty(w: f64, p: f64, flagged: bool) -> Item {
- Item { kind: Kind::Penalty, w, st: [0.0; 3], sh: [0.0; 3], p, flagged, auto: false, hang: 0.0, zone_from: NONE, emergency: false, over: 0.0 }
+ Item {
+ kind: Kind::Penalty,
+ w,
+ st: [0.0; 3],
+ sh: [0.0; 3],
+ p,
+ flagged,
+ auto: false,
+ hang: 0.0,
+ edge_elastic: [0.0; 2],
+ start_elastic: [0.0; 2],
+ zone_from: NONE,
+ emergency: false,
++ over: 0.0,
+ }
}
}
@@@ -362,9 -346,7 +389,10 @@@ fn items(glyphs: &[Glyph], hyph_after:
let (st, sh) = sp.space_elastic(g);
let mut gl = Item::glue(w, st, sh);
gl.hang = prev_hang;
+ if let Some(prev) = i.checked_sub(1).and_then(|j| glyphs.get(j)) {
+ gl.edge_elastic = crate::mojikumi::end_elastic(prev, sp.justify, sp.kinsoku_priority != 3);
+ }
+ gl.over = sp.space_overflow(g);
last_space = it.len();
it.push(gl);
ig.push(i);
@@@ -552,8 -528,9 +583,9 @@@ fn kp_pass
line: 0,
fitness: 1,
tw: first_hang,
- ty: [0.0; 3],
- tz: [0.0; 3],
+ ty: [-first_elastic[0], 0.0, 0.0],
+ tz: [-first_elastic[1], 0.0, 0.0],
+ to: 0.0,
demerits: 0.0,
prev: None,
hyphens: 0,