Paragraph: Kurikaeshi Moji Shori keeps one record per mark when area type flows again

Vertically aligned area type in a frame that is not a rectangle flows its
text again until it settles, and each pass added the line-start repeat
marks to the layout's records once more, so SVG export could look up the
wrong character. Each pass now starts from empty records, and an undone
pass restores the ones before it.
This commit is contained in:
dotCooCoo
2026-11-15 09:38:15 -08:00
parent 74f139062b
commit a5b84d8e2a
2 changed files with 25 additions and 1 deletions
+2 -1
View File
@@ -529,13 +529,14 @@ pub(super) fn align_vertically(cx: &mut Ctx<'_>, paras: &[Range<usize>], t: &Tex
std::mem::take(&mut cx.out.lines),
std::mem::take(&mut cx.out.inlines),
std::mem::take(&mut cx.out.markers),
std::mem::take(&mut cx.out.repeat_marks),
std::mem::replace(&mut cx.out.overflow, false),
);
flow(cx, paras, t, Some(regions));
if laid_out(&cx.out) < before {
// Text no longer fits (lines got narrower, or flow around a wrap object): undo the
// pass and try a smaller step.
(cx.out.glyphs, cx.out.lines, cx.out.inlines, cx.out.markers, cx.out.overflow) = prev;
(cx.out.glyphs, cx.out.lines, cx.out.inlines, cx.out.markers, cx.out.repeat_marks, cx.out.overflow) = prev;
for (r, (shift, gap)) in regions.iter_mut().zip(saved) {
r.shift = shift;
r.gap = gap;
+23
View File
@@ -2832,6 +2832,29 @@ fn kurikaeshi_moji_shori_scans_a_paragraph_once() {
assert!(l.glyphs.iter().filter(|g| g.byte > 0 && text.get(g.byte..).is_some_and(|s| s.starts_with('々'))).all(|g| g.gid == face.glyph_for('時')));
}
/// Kurikaeshi Moji Shori: area type in a frame that isn't a rectangle, centered vertically, flows
/// again until it settles, and keeps one record for each repeat mark it draws as another character.
#[test]
fn vertically_centered_repeat_marks_in_a_round_frame_are_recorded_once() {
use crate::test_fonts::{REPEAT_MARK_FAMILY, repeat_mark_font};
use vectorcraft_doc::VerticalAlign;
let db = FontDb::with_font_dirs(vec![]);
db.add_font(repeat_mark_font().expect("test font"));
let st = CharStyle { size: 20.0, font_family: REPEAT_MARK_FAMILY.into(), font_style: "Regular".into(), ..CharStyle::default() };
let text = format!("時{}", "\u{2028}々".repeat(5));
let frame = kurbo::Ellipse::new((150.0, 150.0), (150.0, 150.0), 0.0).to_path(0.1);
let mut t = area(&text, st, Rect::new(0.0, 0.0, 300.0, 300.0), Justify::Left);
t.kind = TextKind::Area { frame: PathData::from_bezpath(&frame) };
t.para.kurikaeshi_moji_shori = true;
let top = layout(&db, &t);
let marks: Vec<(usize, char)> = text.match_indices('々').map(|(b, _)| (b, '時')).collect();
assert_eq!(top.repeat_marks, marks);
t.area.vertical_align = VerticalAlign::Center;
let lay = layout(&db, &t);
assert!(lay.lines[0].baseline > top.lines[0].baseline + 1.0, "the text moves down");
assert_eq!(lay.repeat_marks, marks);
}
/// Bunri-Kinshi: a justified line spreads its room over the gaps between its CJK characters but not
/// over the gap inside a vertical kana repeat mark, and still fills its width.
#[test]