From 24e7eb329732e5a1780a3989c6f8fc437ff7b908 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 26 Nov 2026 16:29:35 +0100 Subject: [PATCH] :bug: Keep the style of a squeezed span after a warichu note A character right after a horizontal warichu note vanished when line adjustment squeezed the line (push-in first, the default): it was laid out about 0.01px wide. Skia's `getText()` finalizes the paragraph builder, and that drops the style block just pushed for a span that holds no text yet. The squeeze reads the builder text right after that push, so the start of the span joined the block before it: after a note, the near-zero style of the note's anchor. The span style is now pushed again after the read. AI-assisted-by: claude-opus-5-5 --- render-wasm/src/shapes/text_horizontal/mod.rs | 16 ++++-- .../src/shapes/text_horizontal/tests.rs | 57 +++++++++++++++++++ 2 files changed, 68 insertions(+), 5 deletions(-) diff --git a/render-wasm/src/shapes/text_horizontal/mod.rs b/render-wasm/src/shapes/text_horizontal/mod.rs index 706e6ebb82..b06fa09bbb 100644 --- a/render-wasm/src/shapes/text_horizontal/mod.rs +++ b/render-wasm/src/shapes/text_horizontal/mod.rs @@ -393,11 +393,14 @@ fn add_text_with_sheds( continue; } let start = *builder_start.get_or_insert_with(|| { - builder - .paragraph_builder() - .get_text() - .encode_utf16() - .count() + let paragraph_builder = builder.paragraph_builder(); + let start = paragraph_builder.get_text().encode_utf16().count(); + // `get_text` finalizes the builder, which drops the style block + // the caller pushed for this span while it holds no text yet: the + // span text would join the block before it, such as a warichu + // anchor's near-zero size. Open it again; popped at the end. + paragraph_builder.push_style(text_style); + start }); builder.add_extra_spacing(start + at, letter_spacing - tracking); let mut style = text_style.clone(); @@ -415,6 +418,9 @@ fn add_text_with_sheds( &text[piece_start..], span.font_size, ); + if builder_start.is_some() { + builder.paragraph_builder().pop(); + } } /// The horizontal passes of one paragraph that layout, painting, position diff --git a/render-wasm/src/shapes/text_horizontal/tests.rs b/render-wasm/src/shapes/text_horizontal/tests.rs index d251851f16..d4c0a9abab 100644 --- a/render-wasm/src/shapes/text_horizontal/tests.rs +++ b/render-wasm/src/shapes/text_horizontal/tests.rs @@ -3063,3 +3063,60 @@ fn mainland_text_in_a_traditional_face_sheds_as_in_hong_kong() { "the centred 。 gives up a quarter of its 16px em to 」" ); } + +#[test] +fn push_in_squeeze_keeps_the_character_after_a_warichu_note() { + // The squeeze sheds aki inside the span after the note; that span must + // keep its own style, not the note's near-zero style anchor. + init_state(); + // Its notdef glyph is 1em wide, so the kanji have their real advances. + let family = crate::shapes::FontFamily::new(Uuid::nil(), 700, crate::shapes::FontStyle::Normal); + let span = |text: &str| { + let mut span = make_span(text, 0.0); + span.font_size = 32.0; + span.font_family = family; + span + }; + let mut note = span("二〇二六年に移転した新しい建物"); + note.warichu = true; + let mut content = super::super::text::TextContent::new( + crate::math::Rect::from_xywh(0.0, 0.0, 400.0, 200.0), + crate::shapes::GrowType::AutoHeight, + ); + content.set_line_adjustment(LineAdjustment::PushInFirst); + content.add_paragraph(make_paragraph( + vec![span("東京の本社("), note, span("あ)で会議を行う。")], + 0.0, + )); + let mut shape = crate::shapes::Shape::new(Uuid::nil()); + shape.set_selrect(0.0, 0.0, 400.0, 200.0); + let mut resources = + crate::render::RenderResources::try_new_headless().expect("headless resources"); + resources + .fonts + .add( + family, + crate::shapes::text_vertical::test_support::VPAL_TEST_FONT, + false, + false, + ) + .expect("test font"); + let _guard = crate::globals::TestRenderResourcesGuard::install(&mut resources); + + let adjustments = content.horizontal_line_adjustments().expect("adjusted"); + let squeezed = adjustments[0].as_ref().expect("first paragraph"); + assert!( + !squeezed.sheds[2].is_empty(), + "the line squeezes after the note" + ); + let data = super::super::text::calculate_position_data(&shape, &content, false); + + let after_note: Vec<_> = data + .iter() + .filter(|entry| entry.span == 2 && entry.start_pos == 0) + .collect(); + assert!( + after_note.iter().any(|entry| entry.width > 16.0), + "あ after the note keeps its width: {after_note:?}" + ); +}