diff options
Diffstat (limited to 'sub')
-rw-r--r-- | sub/ass_mp.c | 3 | ||||
-rw-r--r-- | sub/subassconvert.c | 72 | ||||
-rw-r--r-- | sub/subreader.c | 10 |
3 files changed, 54 insertions, 31 deletions
diff --git a/sub/ass_mp.c b/sub/ass_mp.c index 0713248db0..88c55862f2 100644 --- a/sub/ass_mp.c +++ b/sub/ass_mp.c @@ -248,8 +248,7 @@ void mp_ass_configure(ASS_Renderer *priv, struct MPOpts *opts, int w, int h, int hinting; ass_set_frame_size(priv, w, h); ass_set_margins(priv, opts->ass_top_margin, opts->ass_bottom_margin, 0, 0); - ass_set_use_margins(priv, opts->ass_use_margins); - ass_set_font_scale(priv, opts->ass_font_scale); + mp_ass_reload_options(priv, opts); if (!unscaled && (opts->ass_hinting & 4)) hinting = 0; else diff --git a/sub/subassconvert.c b/sub/subassconvert.c index 2a56b46022..bbd789f91f 100644 --- a/sub/subassconvert.c +++ b/sub/subassconvert.c @@ -106,6 +106,27 @@ static const struct { #define SUBRIP_MAX_STACKED_FONT_TAGS 16 +/* read the attribute value starting at *s, and skip *s past the value + * return the value in out_value, with possible '"' stripped + * return whether the attribute is well formed */ +static bool read_value(char **s, struct bstr *out_value) +{ + char term = '\0'; + if (**s == '"') { + term = '"'; + (*s)++; + } + out_value->start = *s; + out_value->len = 0; + unsigned char *start = *s; + unsigned char *end = term ? strchr(start, term) : strpbrk(start, " >"); + if (!end) + return false; + out_value->len = end - out_value->start; + *s = end + (term ? 1 : 0); + return true; +} + void subassconvert_subrip(const char *orig, char *dest, int dest_buffer_size) { /* line is not const to avoid warnings with strtol, etc. @@ -174,34 +195,35 @@ void subassconvert_subrip(const char *orig, char *dest, int dest_buffer_size) line += 6; while (*line && *line != '>') { - if (strncmp(line, "size=\"", 6) == 0) { - line += 6; - tag->size = strtol(line, &line, 10); - if (*line != '"') + if (strncmp(line, "size=", 5) == 0) { + line += 5; + struct bstr val; + if (!read_value(&line, &val)) + break; + tag->size = bstrtoll(val, &val, 10); + if (val.len) break; append_text(&new_line, "{\\fs%d}", tag->size); tag->has_size = true; has_valid_attr = true; - } else if (strncmp(line, "color=\"", 7) == 0) { - line += 7; - if (*line == '#') { + } else if (strncmp(line, "color=", 6) == 0) { + line += 6; + struct bstr val; + if (!read_value(&line, &val)) + break; + if (bstr_eatstart(&val, bstr("#"))) { // #RRGGBB format - line++; - tag->color = strtol(line, &line, 16) & 0x00ffffff; - if (*line != '"') + tag->color = bstrtoll(val, &val, 16) & 0x00ffffff; + if (val.len) break; tag->color = ((tag->color & 0xff) << 16) | (tag->color & 0xff00) | ((tag->color & 0xff0000) >> 16); } else { // Standard web colors - int len = indexof(line, '"'); - if (len <= 0) - break; for (int i = 0; i < FF_ARRAY_ELEMS(subrip_web_colors); i++) { char *color = subrip_web_colors[i].s; - if (strlen(color) == len - && strncasecmp(line, color, len) == 0) { + if (bstrcasecmp(val, bstr(color)) == 0) { tag->color = subrip_web_colors[i].v; goto foundcolor; } @@ -211,29 +233,25 @@ void subassconvert_subrip(const char *orig, char *dest, int dest_buffer_size) mp_tmsg(MSGT_SUBREADER, MSGL_WARN, "SubRip: unknown font color in subtitle: %s\n", orig); append_text(&new_line, "{\\c}"); - line += len + 1; continue; - foundcolor: - line += len; + foundcolor: ; } append_text(&new_line, "{\\c&H%06X&}", tag->color); tag->has_color = true; has_valid_attr = true; - } else if (strncmp(line, "face=\"", 6) == 0) { + } else if (strncmp(line, "face=", 5) == 0) { /* Font face attribute */ - line += 6; - int len = indexof(line, '"'); - if (len <= 0) + line += 5; + struct bstr val; + if (!read_value(&line, &val)) break; - tag->face.start = line; - tag->face.len = len; - line += len; + tag->face = val; append_text(&new_line, "{\\fn%.*s}", BSTR_P(tag->face)); tag->has_face = true; has_valid_attr = true; - } - line++; + } else + line++; } if (!has_valid_attr || *line != '>') { /* Not valid font tag */ diff --git a/sub/subreader.c b/sub/subreader.c index f694f57a7c..ad4142d50a 100644 --- a/sub/subreader.c +++ b/sub/subreader.c @@ -1505,7 +1505,11 @@ sub_data* sub_read_file(char *filename, float fps, struct MPOpts *opts) utf16--; mpsub_multiplier = (uses_time ? 100.0 : 1.0); - if (sub_format==SUB_INVALID) {mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: Could not determine file format\n");return NULL;} + if (sub_format==SUB_INVALID) { + mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: Could not determine file format\n"); + free_stream(fd); + return NULL; + } srp=sr+sub_format; mp_msg(MSGT_SUBREADER, MSGL_V, "SUB: Detected subtitle file format: %s\n", srp->name); @@ -1533,7 +1537,8 @@ sub_data* sub_read_file(char *filename, float fps, struct MPOpts *opts) subcp_close(); sub_utf8=sub_utf8_prev; #endif - return NULL; + free_stream(fd); + return NULL; } #ifdef CONFIG_SORTSUB @@ -1570,6 +1575,7 @@ sub_data* sub_read_file(char *filename, float fps, struct MPOpts *opts) #endif free(first); free(alloced_sub); + free_stream(fd); return NULL; } // Apply any post processing that needs recoding first |