Type: Soft picks the same line composer as a set made from it

A paragraph that pushes characters in is broken line by line when it
holds a character its kinsoku rules keep off a line's start or end.
With the built-in Hard and Soft sets that check used every character
Hard keeps off a line's start, so small kana and the prolonged sound
mark, which Soft lets start a line, sent a Soft paragraph to the
single-line composer while a set made from Soft kept the every-line
composer. The check now uses the paragraph's own rules.
This commit is contained in:
dotCooCoo committed 2026-11-14 14:57:34 -08:00
1 parent 96d28deab2
commit bfdffe55a3
2 files changed
+31 -6

No files matched your search

+9 -6
View File
@@ -10,7 +10,7 @@ use super::vertical::{
use super::{
Affine, BidiInfo, Burasagari, CharStyle, Composer, Ctx, EPS, Flex, Justify, KinsokuShoriType, LeadingModel, LineFit, LineInfo, ListMarker,
ParaStyle, Params, Point, Punct, Range, SGlyph, SingleWordJustify, TextObject, apply_desired, cap_x_heights, compose, fit_line, hyphen_glyph,
is_cjk, is_word_space, kashida, mark_word_ends, no_line_end, no_line_start, style_metrics,
is_cjk, is_word_space, kashida, mark_word_ends, style_metrics,
};
use crate::justify::is_format_control;
use crate::shape::{keep_inseparable_pairs, keep_inseparable_sequences, keep_korean_words};
@@ -21,6 +21,13 @@ fn pushes_in(para: &ParaStyle) -> bool {
!KinsokuRules::of(para).is_none() && para.kinsoku_type != KinsokuShoriType::PushOutOnly
}
/// May paragraph `para` push one of glyphs `sg` in onto a line: does it push characters in, and
/// hold a character its kinsoku rules keep off a line's start or end?
pub(super) fn may_push_in(para: &ParaStyle, sg: &[SGlyph]) -> bool {
let kinsoku = KinsokuRules::of(para);
pushes_in(para) && sg.iter().any(|g| kinsoku.cannot_start(g.ch) || kinsoku.cannot_end(g.ch))
}
/// Paragraphs longer than this (glyphs) are always broken line by line.
const MAX_COMPOSE_GLYPHS: usize = 200_000;
@@ -53,11 +60,7 @@ fn compose_para(
let kinsoku = KinsokuRules::of(para);
let may_hang = para.burasagari != Burasagari::None && sg.iter().any(|g| hangs(g, kinsoku));
// So is a paragraph that may push characters kinsoku keeps off a line's ends in onto a line.
let kept_off_ends = |c: char| match kinsoku {
KinsokuRules::Custom(set) => set.cannot_start(c) || set.cannot_end(c),
KinsokuRules::BuiltIn(_) => no_line_start(c) || no_line_end(c),
};
let may_push_in = pushes_in(para) && sg.iter().any(|g| kept_off_ends(g.ch));
let may_push_in = may_push_in(para, sg);
// A tab's width depends on where it falls in its line, which the composer's fixed glyph widths
// can't follow: such a paragraph is broken line by line ([`break_line`] measures its tabs).
// The tab of a list marker is on the first line, with the marker, and has a fixed width.
+22
View File
@@ -1231,6 +1231,28 @@ fn a_custom_set_keeps_its_own_characters_off_line_ends() {
assert_eq!(ends, [1, 2, 4, 5]);
}
/// Soft and a set made from it choose the same composer: small kana and the prolonged sound mark,
/// which Soft lets start a line, do not send a paragraph that pushes in to the single-line
/// composer with either, while Hard, which keeps them off a line's start, does.
#[test]
fn soft_and_a_set_made_from_it_push_in_the_same_characters() {
use KinsokuShoriType::{PushInFirst, PushOutOnly};
let glyphs = full_width("あゃいーう");
let para = |kinsoku: Kinsoku, own: bool, kinsoku_type: KinsokuShoriType| ParaStyle {
kinsoku,
kinsoku_set: own.then(|| Arc::new(crate::shape::kinsoku_set_from(kinsoku, "From"))),
kinsoku_type,
..ParaStyle::default()
};
assert!(!flow::may_push_in(&para(Kinsoku::Soft, false, PushInFirst), &glyphs), "built-in Soft");
assert!(!flow::may_push_in(&para(Kinsoku::Soft, true, PushInFirst), &glyphs), "a set made from Soft");
assert!(flow::may_push_in(&para(Kinsoku::Hard, false, PushInFirst), &glyphs), "built-in Hard");
assert!(flow::may_push_in(&para(Kinsoku::Hard, true, PushInFirst), &glyphs), "a set made from Hard");
assert!(!flow::may_push_in(&para(Kinsoku::Hard, false, PushOutOnly), &glyphs), "Push Out Only");
let bracket = full_width("あい」う");
assert!(flow::may_push_in(&para(Kinsoku::Soft, false, PushInFirst), &bracket), "Soft keeps 」 off a line's start");
}
/// With Burasagari, a custom set hangs its own Hanging Punctuation and not the comma and full stop
/// the built-in sets hang: 、 hangs outside a full line with Hard and with a set that lists it; with
/// a set that lists only ! it starts the next line, while ! hangs.