]> granicus.if.org Git - libass/commitdiff
Fix \r style lookup
authorOleg Oshmyan <chortos@inbox.lv>
Sat, 15 Jun 2013 21:02:54 +0000 (22:02 +0100)
committerwm4 <wm4@nowhere>
Sat, 22 Jun 2013 17:07:58 +0000 (19:07 +0200)
Make \rSTYLENAME with an invalid STYLENAME fall back to
line style rather than to Default. This fixes issue #104.

libass/ass_parse.c
libass/ass_utils.c
libass/ass_utils.h

index bb649715e44d0e09fecdf7a20c6d6004a94aaa55..8e760487372cbe6e47729cdd37e8b08c29d65fdf 100644 (file)
@@ -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);
index df7c447f3be2354a1dbda5dfccc9749ac30fcae0..ba31261a7198b3f9930aa58bf152b5ede9f2f4d8 100644 (file)
@@ -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,
index 2d0c6f9de539005755677d196ee6b19cf7188086..e5e0ecd1348857637d27b1201683819a92f13084 100644 (file)
@@ -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,