changeset 19495:31ac2e1a5695

New cmdline option: -ass-force-style. Allows overriding any style parameter from command line. Idea and original patch by Konstantin G. Khlebnikov { koct9i aT gmail doT com }.
author eugeni
date Tue, 22 Aug 2006 23:20:05 +0000
parents cbf4b6aa9d2a
children eacc821fd889
files cfg-common.h libass/ass.c libass/ass_mp.c libass/ass_mp.h
diffstat 4 files changed, 77 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/cfg-common.h	Tue Aug 22 23:18:58 2006 +0000
+++ b/cfg-common.h	Tue Aug 22 23:20:05 2006 +0000
@@ -305,6 +305,7 @@
 	{"ass-bottom-margin", &ass_bottom_margin, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL},
 	{"embeddedfonts", &extract_embedded_fonts, CONF_TYPE_FLAG, 0, 0, 1, NULL},
 	{"noembeddedfonts", &extract_embedded_fonts, CONF_TYPE_FLAG, 0, 1, 0, NULL},
+	{"ass-force-style", &ass_force_style_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL},
 #endif
 #ifdef HAVE_FONTCONFIG
 	{"fontconfig", &font_fontconfig, CONF_TYPE_FLAG, 0, 0, 1, NULL},
--- a/libass/ass.c	Tue Aug 22 23:18:58 2006 +0000
+++ b/libass/ass.c	Tue Aug 22 23:20:05 2006 +0000
@@ -19,6 +19,7 @@
 extern char *sub_cp;
 #endif
 extern int extract_embedded_fonts;
+extern char** ass_force_style_list;
 
 #include "mp_msg.h"
 #include "ass.h"
@@ -209,7 +210,13 @@
 	} else if (strcasecmp(tname, #name) == 0) { \
 		target->name = func(token); \
 		mp_msg(MSGT_GLOBAL, MSGL_DBG2, "%s = %s\n", #name, token);
-#define STRVAL(name) ANYVAL(name,strdup)
+
+#define STRVAL(name) \
+	} else if (strcasecmp(tname, #name) == 0) { \
+		if (target->name != NULL) free(target->name); \
+		target->name = strdup(token); \
+		mp_msg(MSGT_GLOBAL, MSGL_DBG2, "%s = %s\n", #name, token);
+		
 #define COLORVAL(name) ANYVAL(name,string2color)
 #define INTVAL(name) ANYVAL(name,atoi)
 #define FPVAL(name) ANYVAL(name,atof)
@@ -301,6 +308,68 @@
 }
 
 /**
+ * \brief Parse command line style overrides (--ass-force-style option)
+ * \param track track to apply overrides to
+ * The format for overrides is [StyleName.]Field=Value
+ */
+static void process_force_style(ass_track_t* track) {
+	char **fs, *eq, *dt, *style, *tname, *token;
+	ass_style_t* target;
+	int sid;
+	
+	if (!ass_force_style_list) return;
+	
+	for (fs = ass_force_style_list; *fs; ++fs) {
+		eq = strchr(*fs, '=');
+		if (!eq)
+			continue;
+		*eq = '\0';
+		token = eq + 1;
+
+		dt = strchr(*fs, '.');
+		if (dt) {
+			*dt = '\0';
+			style = *fs;
+			tname = dt + 1;
+		} else {
+			style = NULL;
+			tname = *fs;
+		}
+		for (sid = 0; sid < track->n_styles; ++sid) {
+			if (style == NULL || strcasecmp(track->styles[sid].Name, style) == 0) {
+				target = track->styles + sid;
+				if (0) {
+					STRVAL(FontName)
+					COLORVAL(PrimaryColour)
+					COLORVAL(SecondaryColour)
+					COLORVAL(OutlineColour)
+					COLORVAL(BackColour)
+					INTVAL(FontSize)
+					INTVAL(Bold)
+					INTVAL(Italic)
+					INTVAL(Underline)
+					INTVAL(StrikeOut)
+					INTVAL(Spacing)
+					INTVAL(Angle)
+					INTVAL(BorderStyle)
+					INTVAL(Alignment)
+					INTVAL(MarginL)
+					INTVAL(MarginR)
+					INTVAL(MarginV)
+					INTVAL(Encoding)
+					FPVAL(ScaleX)
+					FPVAL(ScaleY)
+					FPVAL(Outline)
+					FPVAL(Shadow)
+				}
+			}
+		}
+		*eq = '=';
+		if (dt) *dt = '.';
+	}
+}
+
+/**
  * \brief Parse the Style line
  * \param track track
  * \param str string to parse, zero-terminated
@@ -645,6 +714,8 @@
 		else
 			track->event_format = strdup("Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text");
 	}
+
+	process_force_style(track);
 }
 
 static int check_duplicate_event(ass_track_t* track, int ReadOrder)
@@ -862,6 +933,8 @@
 		return 0;
 	}
 
+	process_force_style(track);
+
 	mp_msg(MSGT_GLOBAL, MSGL_INFO, "LIBASS: added subtitle file: %s (%d styles, %d events)\n", fname, track->n_styles, track->n_events);
 	
 	sort_events(track);
--- a/libass/ass_mp.c	Tue Aug 22 23:18:58 2006 +0000
+++ b/libass/ass_mp.c	Tue Aug 22 23:20:05 2006 +0000
@@ -12,6 +12,7 @@
 int ass_top_margin = 0;
 int ass_bottom_margin = 0;
 int extract_embedded_fonts = 0;
+char **ass_force_style_list = NULL;
 
 extern int font_fontconfig;
 extern char* font_name;
--- a/libass/ass_mp.h	Tue Aug 22 23:18:58 2006 +0000
+++ b/libass/ass_mp.h	Tue Aug 22 23:20:05 2006 +0000
@@ -9,6 +9,7 @@
 extern int ass_top_margin;
 extern int ass_bottom_margin;
 extern int extract_embedded_fonts;
+extern char **ass_force_style_list;
 
 ass_track_t* ass_read_subdata(sub_data* subdata, double fps);