Support override fonts

This commit is contained in:
Amelia 2024-04-11 18:14:27 -07:00 committed by GitHub
parent d7dac2acd4
commit e0bfb2d4df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1295,7 +1295,7 @@ const FONTS: [(&str, &str); 68] = [
("Webdings", "webdings.woff2"), ("Webdings", "webdings.woff2"),
]; ];
lazy_static::lazy_static! { lazy_static::lazy_static! {
static ref FONT_REGEX: Regex = Regex::new(r"(?m)^Style:\s.+?,(?P<font>.+?),").unwrap(); static ref FONT_REGEX: Regex = Regex::new(r"(?m)^(?:Style:\s.+?,(?P<font>.+?),|(?:Dialogue:\s(?:.+?,)+,\{(?:\\.*)?\\fn(?P<overrideFont>[\w\s]+)(?:\\.*)?)\})").unwrap();
} }
/// Get the fonts used in the subtitle. /// Get the fonts used in the subtitle.
@ -1303,7 +1303,7 @@ fn get_subtitle_stats(path: &Path) -> Result<Vec<String>> {
let mut fonts = vec![]; let mut fonts = vec![];
for capture in FONT_REGEX.captures_iter(&(fs::read_to_string(path)?)) { for capture in FONT_REGEX.captures_iter(&(fs::read_to_string(path)?)) {
if let Some(font) = capture.name("font") { if let Some(font) = (capture.name("font") || capture.name("overrideFont")) {
let font_string = font.as_str().to_string(); let font_string = font.as_str().to_string();
if !fonts.contains(&font_string) { if !fonts.contains(&font_string) {
fonts.push(font_string) fonts.push(font_string)