Fix CJ-Latin space at manual line breaks (#6700)

Co-authored-by: Laurenz Mädje <laurmaedje@gmail.com>
This commit is contained in:
Y.D.X. 2025-09-04 17:17:00 +08:00 committed by GitHub
parent 560e49b67c
commit c340c27924
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 2 deletions

View File

@ -149,6 +149,7 @@ pub fn line<'a>(
// Trim the line at the end, if necessary for this breakpoint.
let trim = range.start + breakpoint.trim(full).len();
let trimmed_range = range.start..trim;
// Collect the items for the line.
let mut items = Items::new();
@ -179,7 +180,8 @@ pub fn line<'a>(
trim_weak_spacing(&mut items);
// Deal with CJ characters at line boundaries.
adjust_cj_at_line_boundaries(p, full, &mut items);
// Use the trimmed range for robust boundary checks.
adjust_cj_at_line_boundaries(p, trimmed_range, &mut items);
// Compute the line's width.
let width = items.iter().map(Item::natural_width).sum();
@ -319,7 +321,11 @@ fn collect_range<'a>(
///
/// See Requirements for Chinese Text Layout, Section 3.1.6.3 Compression of
/// punctuation marks at line start or line end.
fn adjust_cj_at_line_boundaries(p: &Preparation, text: &str, items: &mut Items) {
///
/// The `range` should only contain regular texts, with linebreaks trimmed.
fn adjust_cj_at_line_boundaries(p: &Preparation, range: Range, items: &mut Items) {
let text = &p.text[range];
if text.starts_with(BEGIN_PUNCT_PAT)
|| (p.config.cjk_latin_spacing && text.starts_with(is_of_cj_script))
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -84,6 +84,19 @@ abc字#linebreak()
abc字\
--- issue-6539-cjk-latin-spacing-at-manual-linebreak ---
// Issue #6539
#set text(cjk-latin-spacing: auto)
#set box(width: 2.3em, stroke: (x: green))
#box(align(end)[甲国\ T国])
#box(align(end)[乙国 \ T国])
#box(align(end)[丙国 T国])
#box(align(end)[丁国T国])
--- issue-2650-cjk-latin-spacing-meta ---
测a试