aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--cfg-common.h1
-rw-r--r--libass/ass.c53
-rw-r--r--libass/ass.h6
-rw-r--r--libass/ass_mp.c15
-rw-r--r--libass/ass_mp.h1
5 files changed, 62 insertions, 14 deletions
diff --git a/cfg-common.h b/cfg-common.h
index 57880aaccb..a3e2c736e2 100644
--- a/cfg-common.h
+++ b/cfg-common.h
@@ -318,6 +318,7 @@
{"ass-force-style", &ass_force_style_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL},
{"ass-color", &ass_color, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"ass-border-color", &ass_border_color, CONF_TYPE_STRING, 0, 0, 0, NULL},
+ {"ass-styles", &ass_styles_file, CONF_TYPE_STRING, 0, 0, 0, NULL},
#endif
#ifdef HAVE_FONTCONFIG
{"fontconfig", &font_fontconfig, CONF_TYPE_FLAG, 0, 0, 1, NULL},
diff --git a/libass/ass.c b/libass/ass.c
index 0425989f0a..0107a44e29 100644
--- a/libass/ass.c
+++ b/libass/ass.c
@@ -28,8 +28,10 @@ extern char** ass_force_style_list;
char *get_path(char *);
+typedef enum {PST_UNKNOWN = 0, PST_INFO, PST_STYLES, PST_EVENTS, PST_FONTS} parser_state_t;
+
struct parser_priv_s {
- enum {PST_UNKNOWN = 0, PST_INFO, PST_STYLES, PST_EVENTS, PST_FONTS} state;
+ parser_state_t state;
char* fontname;
char* fontdata;
int fontdata_size;
@@ -844,18 +846,15 @@ static char* sub_recode(char* data, size_t size)
#endif // ICONV
/**
- * \brief Read subtitles from file.
- * \param fname file name
- * \return newly allocated track
-*/
-ass_track_t* ass_read_file(char* fname)
+ * \brief read file contents into newly allocated buffer, recoding to utf-8
+ */
+static char* read_file(char* fname)
{
int res;
long sz;
long bytes_read;
char* buf;
- ass_track_t* track;
-
+
FILE* fp = fopen(fname, "rb");
if (!fp) {
mp_msg(MSGT_GLOBAL, MSGL_WARN, "ass_read_file(%s): fopen failed\n", fname);
@@ -899,11 +898,25 @@ ass_track_t* ass_read_file(char* fname)
if (sub_cp) {
char* tmpbuf = sub_recode(buf, sz);
free(buf);
- if (!tmpbuf)
- return 0;
buf = tmpbuf;
}
#endif
+ return buf;
+}
+
+/**
+ * \brief Read subtitles from file.
+ * \param fname file name
+ * \return newly allocated track
+*/
+ass_track_t* ass_read_file(char* fname)
+{
+ char* buf;
+ ass_track_t* track;
+
+ buf = read_file(fname);
+ if (!buf)
+ return 0;
track = ass_new_track();
track->name = strdup(fname);
@@ -930,6 +943,26 @@ ass_track_t* ass_read_file(char* fname)
return track;
}
+/**
+ * \brief read styles from file into already initialized track
+ */
+int ass_read_styles(ass_track_t* track, char* fname)
+{
+ char* buf;
+ parser_state_t old_state;
+
+ buf = read_file(fname);
+ if (!buf)
+ return 1;
+
+ old_state = track->parser_priv->state;
+ track->parser_priv->state = PST_STYLES;
+ process_text(track, buf);
+ track->parser_priv->state = old_state;
+
+ return 0;
+}
+
static char* validate_fname(char* name)
{
char* fname;
diff --git a/libass/ass.h b/libass/ass.h
index a99b7540a6..ecf7c1a129 100644
--- a/libass/ass.h
+++ b/libass/ass.h
@@ -130,6 +130,12 @@ void ass_process_chunk(ass_track_t* track, char *data, int size, long long timec
ass_track_t* ass_read_file(char* fname);
/**
+ * \brief read styles from file into already initialized track
+ * \return 0 on success
+ */
+int ass_read_styles(ass_track_t* track, char* fname);
+
+/**
* \brief Process embedded matroska font. Saves it to ~/.mplayer/fonts.
* \param name attachment name
* \param data binary font data
diff --git a/libass/ass_mp.c b/libass/ass_mp.c
index ec4994e096..92b8eb4823 100644
--- a/libass/ass_mp.c
+++ b/libass/ass_mp.c
@@ -19,6 +19,7 @@ char **ass_force_style_list = NULL;
int ass_use_margins = 0;
char* ass_color = NULL;
char* ass_border_color = NULL;
+char* ass_styles_file = NULL;
extern int font_fontconfig;
extern char* font_name;
@@ -30,10 +31,6 @@ extern void process_force_style(ass_track_t* track);
ass_track_t* ass_default_track() {
ass_track_t* track = ass_new_track();
- ass_style_t* style;
- int sid;
- double fs;
- uint32_t c1, c2;
track->track_type = TRACK_TYPE_ASS;
track->Timer = 100.;
@@ -41,6 +38,15 @@ ass_track_t* ass_default_track() {
track->PlayResY = 288;
track->WrapStyle = 0;
+ if (ass_styles_file)
+ ass_read_styles(track, ass_styles_file);
+
+ if (track->n_styles == 0) {
+ ass_style_t* style;
+ int sid;
+ double fs;
+ uint32_t c1, c2;
+
sid = ass_alloc_style(track);
style = track->styles + sid;
style->Name = strdup("Default");
@@ -71,6 +77,7 @@ ass_track_t* ass_default_track() {
style->MarginV = 20;
style->ScaleX = 1.;
style->ScaleY = 1.;
+ }
return track;
}
diff --git a/libass/ass_mp.h b/libass/ass_mp.h
index 7ac1e2a3b8..8e385de66e 100644
--- a/libass/ass_mp.h
+++ b/libass/ass_mp.h
@@ -13,6 +13,7 @@ extern char **ass_force_style_list;
extern int ass_use_margins;
extern char* ass_color;
extern char* ass_border_color;
+extern char* ass_styles_file;
ass_track_t* ass_default_track();
int ass_process_subtitle(ass_track_t* track, subtitle* sub);