diff options
author | Oleg Oshmyan <chortos@inbox.lv> | 2013-06-15 22:02:54 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-06-22 19:07:58 +0200 |
commit | 5523d3d5e0ba0fc747b9159d59bf2c57f6a79715 (patch) | |
tree | bb83a20c1e727963dfd673d222e33afc3d0bada0 | |
parent | b992975a3543e7d539e6a3b568dd6b1f198e9561 (diff) | |
download | libass-5523d3d5e0ba0fc747b9159d59bf2c57f6a79715.tar.bz2 libass-5523d3d5e0ba0fc747b9159d59bf2c57f6a79715.tar.xz |
Fix \r style lookup
Make \rSTYLENAME with an invalid STYLENAME fall back to
line style rather than to Default. This fixes issue #104.
-rw-r--r-- | libass/ass_parse.c | 2 | ||||
-rw-r--r-- | libass/ass_utils.c | 20 | ||||
-rw-r--r-- | libass/ass_utils.h | 1 |
3 files changed, 22 insertions, 1 deletions
diff --git a/libass/ass_parse.c b/libass/ass_parse.c index bb64971..8e76048 100644 --- a/libass/ass_parse.c +++ b/libass/ass_parse.c @@ -756,7 +756,7 @@ char *parse_tag(ASS_Renderer *render_priv, char *p, double pwr) strncpy(style, start, p - start); style[p - start] = '\0'; reset_render_context(render_priv, - render_priv->track->styles + lookup_style(render_priv->track, style)); + lookup_style_strict(render_priv->track, style)); free(style); } else reset_render_context(render_priv, NULL); diff --git a/libass/ass_utils.c b/libass/ass_utils.c index df7c447..ba31261 100644 --- a/libass/ass_utils.c +++ b/libass/ass_utils.c @@ -224,6 +224,26 @@ int lookup_style(ASS_Track *track, char *name) return i; // use the first style } +/** + * \brief find style by name as in \r + * \param track track + * \param name style name + * \return style in track->styles + * Returns NULL if no style has the given name. + */ +ASS_Style *lookup_style_strict(ASS_Track *track, char *name) +{ + int i; + for (i = track->n_styles - 1; i >= 0; --i) { + if (strcmp(track->styles[i].Name, name) == 0) + return track->styles + i; + } + ass_msg(track->library, MSGL_WARN, + "[%p]: Warning: no style named '%s' found", + track, name); + return NULL; +} + #ifdef CONFIG_ENCA void *ass_guess_buffer_cp(ASS_Library *library, unsigned char *buffer, int buflen, char *preferred_language, diff --git a/libass/ass_utils.h b/libass/ass_utils.h index 2d0c6f9..e5e0ecd 100644 --- a/libass/ass_utils.h +++ b/libass/ass_utils.h @@ -53,6 +53,7 @@ int parse_ycbcr_matrix(char *str); unsigned ass_utf8_get_char(char **str); void ass_msg(ASS_Library *priv, int lvl, char *fmt, ...); int lookup_style(ASS_Track *track, char *name); +ASS_Style *lookup_style_strict(ASS_Track *track, char *name); #ifdef CONFIG_ENCA void *ass_guess_buffer_cp(ASS_Library *library, unsigned char *buffer, int buflen, char *preferred_language, |