From 5523d3d5e0ba0fc747b9159d59bf2c57f6a79715 Mon Sep 17 00:00:00 2001 From: Oleg Oshmyan Date: Sat, 15 Jun 2013 22:02:54 +0100 Subject: [PATCH] Fix \r style lookup Make \rSTYLENAME with an invalid STYLENAME fall back to line style rather than to Default. This fixes issue #104. --- libass/ass_parse.c | 2 +- libass/ass_utils.c | 20 ++++++++++++++++++++ libass/ass_utils.h | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) 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, -- 2.40.0