From 3ca38f2237e73d24a87fbe7e13d3c6e12374df0c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 10:01:43 -0800 Subject: [PATCH] =?UTF-8?q?Paragraph:=20Kurikaeshi=20Moji=20Shori=20draws?= =?UTF-8?q?=20=E3=82=9D=20or=20=E3=83=BD=20with=20a=20combining=20voicing?= =?UTF-8?q?=20mark=20as=20voiced?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ゝ or ヽ followed by U+3099, which a font draws as one glyph, is now drawn at a line start as ゞ or ヾ would be, instead of as the plain kana. A mark that shares its cluster with other glyphs, or with any other combining character, keeps its own glyphs. --- crates/text/src/layout/flow.rs | 28 ++++++++++++++++++++++------ crates/text/src/layout/on_path.rs | 5 +++-- crates/text/src/tests.rs | 23 +++++++++++++++++++++++ docs/mcp.md | 3 ++- 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/crates/text/src/layout/flow.rs b/crates/text/src/layout/flow.rs index 50f0cef433..36881e20d8 100644 --- a/crates/text/src/layout/flow.rs +++ b/crates/text/src/layout/flow.rs @@ -1301,14 +1301,30 @@ fn emit_line_glyph( /// a line, when `g` is a repeat mark, and the character it shows: the character [`repeated_char`] /// gives for the character `base` finds before the mark, shaped in the mark's style with the type's /// features (so vertical type gets the font's vertical forms), from the same face, with the mark's -/// advance and place, so the line breaks stay as they are. None when `g` is no repeat mark, belongs -/// to a tate-chu-yoko or warichu block, `base` gives None, nothing before it fits, or the face draws -/// the character with no glyph or with more than one. `base` runs only for a repeat mark. -pub(super) fn repeat_mark_glyph(cx: &Ctx<'_>, g: &SGlyph, base: impl FnOnce() -> Option>) -> Option<(SGlyph, char)> { +/// advance and place, so the line breaks stay as they are. ゝ or ヽ followed by a combining voicing +/// mark (U+3099) in one glyph counts as ゞ or ヾ. None when `g` is no repeat mark, belongs to a +/// tate-chu-yoko or warichu block, holds other characters with the mark, shares its cluster with the +/// glyph after it (`next`), `base` gives None, nothing before it fits, or the face draws the +/// character with no glyph or with more than one. `base` runs only for a repeat mark. +pub(super) fn repeat_mark_glyph( + cx: &Ctx<'_>, + g: &SGlyph, + next: Option<&SGlyph>, + base: impl FnOnce() -> Option>, +) -> Option<(SGlyph, char)> { if g.tcy.is_some() || g.wari.is_some() || g.inline.is_some() || !matches!(g.ch, '々' | 'ゝ' | 'ゞ' | 'ヽ' | 'ヾ') { return None; } - let c = repeated_char(base()?, "", g.ch)?; + if next.is_some_and(|n| n.byte == g.byte) { + return None; + } + let mark = match cx.text.get(g.byte..g.byte + g.len)? { + "ゝ\u{3099}" => 'ゞ', + "ヽ\u{3099}" => 'ヾ', + cluster if cluster.len() == g.ch.len_utf8() => g.ch, + _ => return None, + }; + let c = repeated_char(base()?, "", mark)?; let mut buf = [0; 4]; let s: &str = c.encode_utf8(&mut buf); let mut shaped = Vec::with_capacity(1); @@ -1328,7 +1344,7 @@ fn line_start_repeat(cx: &mut Ctx<'_>, paragraph: &ParagraphData<'_, '_>, first: } let g = paragraph.sg.get(first)?; let text = cx.text; - let (glyph, c) = repeat_mark_glyph(cx, g, || paragraph.repeat_base_before(text, g.byte))?; + let (glyph, c) = repeat_mark_glyph(cx, g, paragraph.sg.get(first + 1), || paragraph.repeat_base_before(text, g.byte))?; cx.out.repeat_marks.push((g.byte, c)); Some(glyph) } diff --git a/crates/text/src/layout/on_path.rs b/crates/text/src/layout/on_path.rs index 80aaa5ea9a..b69470b9d9 100644 --- a/crates/text/src/layout/on_path.rs +++ b/crates/text/src/layout/on_path.rs @@ -418,8 +418,9 @@ fn line_start_repeat(cx: &Ctx<'_>, t: &TextObject, pr: &Range, glyphs: &m if !t.first_para_continues || !t.para_at(0).kurikaeshi_moji_shori { return None; } - let g = glyphs.iter_mut().find(|g| g.len > 0 && g.byte == pr.start)?; - let (glyph, c) = repeat_mark_glyph(cx, g, || Some(t.first_para_lead))?; + let at = glyphs.iter().position(|g| g.len > 0 && g.byte == pr.start)?; + let (glyph, c) = repeat_mark_glyph(cx, glyphs.get(at)?, glyphs.get(at + 1), || Some(t.first_para_lead))?; + let g = glyphs.get_mut(at)?; *g = glyph; Some((g.byte, c)) } diff --git a/crates/text/src/tests.rs b/crates/text/src/tests.rs index 147b6a4818..c04200a94f 100644 --- a/crates/text/src/tests.rs +++ b/crates/text/src/tests.rs @@ -2828,6 +2828,29 @@ fn kurikaeshi_moji_shori_draws_the_repeated_character_at_a_line_start() { assert_eq!(gid_of(&layout(&db, &t), 0), glyph('々'), "type on a path in a frame that does not continue"); } +/// Kurikaeshi Moji Shori: ゝ or ヽ typed with a combining voicing mark (U+3099) after it, which the +/// font draws as one glyph, is drawn as the voiced character at a line start, as ゞ and ヾ are. +#[test] +fn kurikaeshi_moji_shori_draws_a_decomposed_voiced_mark_voiced() { + use crate::test_fonts::{REPEAT_MARK_FAMILY, repeat_mark_font}; + 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 face = db.style_face(&st).expect("face"); + let glyph = |c: char| Some(face.glyph_for(c)); + let gid_of = |l: &TextLayout, b: usize| l.glyphs.iter().find(|g| g.byte == b).map(|g| g.gid); + for (text, mark, want) in [("す\u{2028}ゝ\u{3099}", 'ゞ', 'ず'), ("サ\u{2028}ヽ\u{3099}", 'ヾ', 'ザ')] { + let at = text.find(['ゝ', 'ヽ']).expect("mark"); + let mut t = TextObject::point(Point::ZERO, text, st.clone()); + let off = layout(&db, &t); + assert_eq!(gid_of(&off, at), glyph(mark), "{text:?}: off, the font draws the voiced mark"); + t.para.kurikaeshi_moji_shori = true; + let on = layout(&db, &t); + assert_eq!(gid_of(&on, at), glyph(want), "{text:?}"); + assert_eq!(on.repeat_marks, [(at, want)], "{text:?}"); + } +} + /// Kurikaeshi Moji Shori: a paragraph with a repeat mark at the start of each of many lines is laid /// out in one scan of its text, not one scan of everything before each line. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index 0769d0a97e..9dadf1c1d2 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -9463,7 +9463,8 @@ VectorCraft's set of marks and its rules: 々 repeats a Han ideograph, ゝ and repeated character is the last one before the mark in the paragraph that is not a repeat mark, a soft return or a combining voicing mark (U+3099, U+309A), looking back into the frames before when threaded type continues a paragraph from one frame into the next; ゝ and ヽ draw it without its voicing marks, and ゞ and ヾ draw its voiced form, or the -plain kana when it has none. A mark is drawn as it is when nothing before it in the paragraph fits, when the font has no glyph for the character, at the start of a +plain kana when it has none; ゝ or ヽ followed by a combining voicing mark (U+3099) counts as ゞ or ヾ when the font draws the +pair as one glyph, and is drawn as it is when the font draws two. A mark is drawn as it is when nothing before it in the paragraph fits, when the font has no glyph for the character, at the start of a paragraph, and inside tate-chu-yoko or warichu. Off by default. It is saved with the paragraph (`kurikaeshi_moji_shori` in `para`) only when on, paragraph styles carry it (`kurikaeshi_moji_shori` in a paragraph style's attributes), and Reset Panel turns it off. A value that is not true, false or null is refused, `null` leaves the