File size: 2,267 Bytes
851e5ba | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | from src.font_registry import FONTS_DIR, get_font_codepoints
from src.media import captions
def _build(tmp_path, monkeypatch, hook_title, words=None):
monkeypatch.setattr(captions, "emoji_rendering_supported", lambda: False)
output = tmp_path / "captions.ass"
built = captions.build_assemblyai_ass_subtitles(
tmp_path / "missing.mp4",
0.0,
5.0,
1080,
1920,
output,
caption_template="default",
hook_title=hook_title,
caption_words=words,
include_captions=bool(words),
)
assert built
return output.read_text(encoding="utf-8")
def test_get_font_codepoints_reads_the_cmap():
bold = get_font_codepoints(FONTS_DIR / "THEBOLDFONT.ttf")
fallback = get_font_codepoints(FONTS_DIR / f"{captions.GLYPH_FALLBACK_FONT}.ttf")
assert ord("A") in bold and ord("a") in bold
assert ord("ú") not in bold and ord("Ñ") not in bold
assert {ord(ch) for ch in "áéíóúÁÉÍÓÚñÑüÜ"} <= fallback
def test_accented_hook_title_switches_to_a_font_that_has_the_glyphs(
tmp_path, monkeypatch
):
content = _build(tmp_path, monkeypatch, "Claude ahora actúa sin que le pidas")
fallback = captions.ass_font_name(captions.GLYPH_FALLBACK_FONT)
assert f"Style: Hook,{fallback}," in content
assert f"Style: Default,{fallback}," in content
# THEBOLDFONT only draws capitals, so the fallback keeps the all-caps look.
assert "ACTÚA" in content
assert "actúa" not in content
def test_accented_caption_words_also_trigger_the_fallback(tmp_path, monkeypatch):
words = [
{"text": "Publicá", "start": 0.2, "end": 0.6},
{"text": "todos", "start": 0.6, "end": 1.0},
{"text": "días", "start": 1.0, "end": 1.4},
]
content = _build(tmp_path, monkeypatch, None, words)
assert f"\\fn{captions.ass_font_name(captions.GLYPH_FALLBACK_FONT)}" in content
assert "DÍAS" in content
def test_plain_ascii_text_keeps_the_template_font(tmp_path, monkeypatch):
content = _build(tmp_path, monkeypatch, "Claude acts before you ask")
template_font = captions.ass_font_name("THEBOLDFONT")
assert f"Style: Hook,{template_font}," in content
assert "}acts" in content and "ACTS" not in content
|