ass-font
ass-font is a fast parser for extracting font names from ASS (Advanced SubStation Alpha) subtitle files. It correctly handles section headers, detects encoded files automatically, and scans both standard font definitions and inline dialogue font overrides (e.g., \fnFontName).
Used by flash-font to prepare a list of fonts that need to be injected before playback.
Features
- Robust Parsing: Scans styles (
[V4+ Styles], etc.) and event ([Events]) sections. - Inline Tag Support: Detects and extracts fonts from
\fndialogue tags correctly. - Encoding Autodetection: Automatically guesses file text encoding (e.g. Shift-JIS, UTF-8, GBK) to correctly read the subtitle files before parsing.
Usage
Extracting fonts from an ASS text string:
use extract_fonts;
let ass_content = r#"
[V4+ Styles]
Format: Name, Fontname, Fontsize
Style: Default,Arial,20
[Events]
Format: Layer, Start, End, Style, Text
Dialogue: 0,0:00:00.00,0:00:05.00,Default,{\fnOpen Sans}This is a test.
"#;
let fonts = extract_fonts;
assert_eq!;
Or read the file directly using auto-detected encoding:
use read_text_auto;
// read_text_auto automatically detects charset and returns a String
let text = read_text_auto.unwrap;
let fonts = extract_fonts;
License
MIT OR Apache-2.0