]> granicus.if.org Git - libass/commitdiff
Much improved "Default" style
authorGrigori Goronzy <greg@blackbox>
Sat, 9 Apr 2011 02:06:39 +0000 (04:06 +0200)
committerGrigori Goronzy <greg@blackbox>
Sat, 9 Apr 2011 02:16:26 +0000 (04:16 +0200)
Make the "Default" style, useful as a fallback and required by few
scripts for proper rendering, actually do something sensible. Font,
sizes, et cetera are set up mostly like VSFilter.

libass/ass.c

index 368377251e486cda276ef96f7374440c87d16320..ff2e3953741c0a3384bbc3e8bda9dd7ed4577007 100644 (file)
@@ -163,6 +163,32 @@ static void rskip_spaces(char **str, char *limit)
     *str = p;
 }
 
+/**
+ * \brief Set up default style
+ * \param style style to edit to defaults
+ * The parameters are mostly taken directly from VSFilter source for
+ * best compatibility.
+ */
+static void set_default_style(ASS_Style *style)
+{
+    style->Name             = strdup("Default");
+    style->FontName         = strdup("Arial");
+    style->FontSize         = 18;
+    style->PrimaryColour    = 0xffffff00;
+    style->SecondaryColour  = 0x00ffff00;
+    style->OutlineColour    = 0x00000000;
+    style->BackColour       = 0x00000000;
+    style->Bold             = 200;
+    style->ScaleX           = 1.0;
+    style->ScaleY           = 1.0;
+    style->Spacing          = 0;
+    style->BorderStyle      = 1;
+    style->Outline          = 2;
+    style->Shadow           = 3;
+    style->Alignment        = 2;
+    style->MarginL = style->MarginR = style->MarginV = 20;
+}
+
 /**
  * \brief find style by name
  * \param track track
@@ -308,8 +334,8 @@ static int process_event_tail(ASS_Track *track, ASS_Event *event,
         // add "Default" style to the end
         // will be used if track does not contain a default style (or even does not contain styles at all)
         int sid = ass_alloc_style(track);
-        track->styles[sid].Name = strdup("Default");
-        track->styles[sid].FontName = strdup("Arial");
+        set_default_style(&track->styles[sid]);
+        track->default_style = sid;
     }
 
     for (i = 0; i < n_ignored; ++i) {
@@ -468,6 +494,14 @@ static int process_style(ASS_Track *track, char *str)
 
     q = format = strdup(track->style_format);
 
+    // Add default style first
+    if (track->n_styles == 0) {
+        // will be used if track does not contain a default style (or even does not contain styles at all)
+        int sid = ass_alloc_style(track);
+        set_default_style(&track->styles[sid]);
+        track->default_style = sid;
+    }
+
     ass_msg(track->library, MSGL_V, "[%p] Style: %s", track, str);
 
     sid = ass_alloc_style(track);