Dialogue working

This commit is contained in:
DazedAnon 2026-07-09 15:42:53 -05:00
parent 3fcde613a8
commit e23e8f3b10
2 changed files with 32 additions and 5 deletions

View file

@ -235,10 +235,11 @@ class TestManualFontAndWrap(unittest.TestCase):
max_line_len=80,
)
changed = ws.wrap_overflow_manual_in_scope(path, doc, hit, 36, font=14)
self.assertEqual(changed, 1)
# Both 噂 entries get body font (short "OK" included); other category skipped.
self.assertEqual(changed, 2)
saved = json.loads(path.read_text(encoding="utf-8"))
self.assertIn(r"\f[14]", saved["names"][0]["text"])
self.assertEqual(saved["names"][1]["text"], "OK")
self.assertEqual(saved["names"][1]["text"], r"\f[14]OK")
self.assertEqual(saved["names"][2]["text"], "x" * 80)
@ -482,6 +483,28 @@ class TestNameplateWrap(unittest.TestCase):
)
self.assertLessEqual(body_lines, 2)
def test_manual_group_applies_font_to_short_spoken_lines(self):
"""Group wrap with body font must not skip short lines that already fit."""
short = "Celria\nJust now...... what did you say?"
line = {
"text": short,
"speaker": "セルリア",
"speaker_src": "literal_line1_lowconf",
}
self.assertTrue(ws._apply_manual_to_line_dict(line, 70, font=21))
self.assertEqual(
line["text"],
"Celria\n\\f[21]Just now...... what did you say?",
)
# Font 0 / None: still skip short plain lines (width-only group wrap).
line2 = {
"text": short,
"speaker": "セルリア",
"speaker_src": "literal_line1_lowconf",
}
self.assertFalse(ws._apply_manual_to_line_dict(line2, 70, font=None))
self.assertEqual(line2["text"], short)
def test_dialogue_geometry_roundtrip(self):
with tempfile.TemporaryDirectory() as tmp:
work = Path(tmp)

View file

@ -1075,8 +1075,9 @@ def apply_manual_font_and_wrap(
are collapsed and rebuilt so Manual Wrap matches what the preview shows.
Nameplate lines (``Celria\\n``) stay on their own first line.
When *only_overflow_or_fonts* is True (group wrap), skip short plain lines
that already match the target layout and have no ``\\f[N]``.
When *only_overflow_or_fonts* is True, skip short plain lines that already
match the target layout and have no ``\\f[N]``. Manual group wrap passes
False whenever a body font is set so short spoken lines still get ``\\f``.
Returns ``(new_text, changed)``.
"""
@ -1195,11 +1196,14 @@ def _apply_manual_to_line_dict(
text = line.get("text")
if not isinstance(text, str) or not text.strip():
return False
# Font set: apply to every line in the group (short spoken lines included).
# Font 0 / None: only reflow lines that overflow or already have \\f[N].
only_overflow = font is None or int(font) <= 0
new_text, changed = apply_manual_font_and_wrap(
text,
width,
font=font,
only_overflow_or_fonts=True,
only_overflow_or_fonts=only_overflow,
speaker_src=str(line.get("speaker_src") or ""),
speaker=str(line.get("speaker") or ""),
)