Spaces:
Sleeping
Sleeping
Center native highlight captions by line anchor
Browse files- src/humeo/cutter.py +3 -6
src/humeo/cutter.py
CHANGED
|
@@ -513,19 +513,16 @@ def _format_native_highlight_ass(
|
|
| 513 |
cue_start = cue_windows[0][0] if cue_windows else cue_words[0].start_time
|
| 514 |
cue_end = cue_windows[-1][1] if cue_windows else cue_words[-1].end_time
|
| 515 |
word_offset = 0
|
|
|
|
| 516 |
for line_idx, line_words in enumerate(lines):
|
| 517 |
if not line_words:
|
| 518 |
continue
|
| 519 |
line_text = " ".join(word.word for word in line_words)
|
| 520 |
line_top = block_top + line_idx * (line_height + line_gap)
|
| 521 |
-
line_width = _text_width(font, line_text)
|
| 522 |
-
centered_left = (play_res_x - line_width) / 2.0
|
| 523 |
-
max_left = play_res_x - safe_margin_x - line_width
|
| 524 |
-
line_left = max(float(safe_margin_x), min(centered_left, max_left))
|
| 525 |
events.append(
|
| 526 |
"Dialogue: 1,"
|
| 527 |
f"{_fmt_ass_time(cue_start)},{_fmt_ass_time(cue_end)},Base,,0,0,0,,"
|
| 528 |
-
f"{{\\
|
| 529 |
)
|
| 530 |
for word_idx, word in enumerate(line_words):
|
| 531 |
cleaned = _clean_native_highlight_token(word.word)
|
|
@@ -535,7 +532,7 @@ def _format_native_highlight_ass(
|
|
| 535 |
events.append(
|
| 536 |
"Dialogue: 0,"
|
| 537 |
f"{_fmt_ass_time(word_start)},{_fmt_ass_time(word_end)},Invisible,,0,0,0,,"
|
| 538 |
-
f"{{\\
|
| 539 |
f"{_native_highlight_overlay_text(line_words, word_idx)}"
|
| 540 |
)
|
| 541 |
word_offset += len(line_words)
|
|
|
|
| 513 |
cue_start = cue_windows[0][0] if cue_windows else cue_words[0].start_time
|
| 514 |
cue_end = cue_windows[-1][1] if cue_windows else cue_words[-1].end_time
|
| 515 |
word_offset = 0
|
| 516 |
+
line_center_x = play_res_x / 2.0
|
| 517 |
for line_idx, line_words in enumerate(lines):
|
| 518 |
if not line_words:
|
| 519 |
continue
|
| 520 |
line_text = " ".join(word.word for word in line_words)
|
| 521 |
line_top = block_top + line_idx * (line_height + line_gap)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 522 |
events.append(
|
| 523 |
"Dialogue: 1,"
|
| 524 |
f"{_fmt_ass_time(cue_start)},{_fmt_ass_time(cue_end)},Base,,0,0,0,,"
|
| 525 |
+
f"{{\\an8\\pos({line_center_x:.1f},{line_top:.1f})}}{_escape_ass_text(line_text)}"
|
| 526 |
)
|
| 527 |
for word_idx, word in enumerate(line_words):
|
| 528 |
cleaned = _clean_native_highlight_token(word.word)
|
|
|
|
| 532 |
events.append(
|
| 533 |
"Dialogue: 0,"
|
| 534 |
f"{_fmt_ass_time(word_start)},{_fmt_ass_time(word_end)},Invisible,,0,0,0,,"
|
| 535 |
+
f"{{\\an8\\pos({line_center_x:.1f},{line_top:.1f})}}"
|
| 536 |
f"{_native_highlight_overlay_text(line_words, word_idx)}"
|
| 537 |
)
|
| 538 |
word_offset += len(line_words)
|