diff options
author | eugeni <eugeni@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2006-09-03 17:42:31 +0000 |
---|---|---|
committer | eugeni <eugeni@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2006-09-03 17:42:31 +0000 |
commit | 9d3ed04d47732deccce6ea74932a96ccc290fead (patch) | |
tree | 3a574e128b8730ef77131a132b5e9624c66a9a93 /libass | |
parent | 8ed46df92fd8ba6d687db6bbac2dde36dff67a5c (diff) |
Add -ass-styles option. It allows to load styles from a file and use them
for plain text subtitles rendering.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@19658 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libass')
-rw-r--r-- | libass/ass.c | 53 | ||||
-rw-r--r-- | libass/ass.h | 6 | ||||
-rw-r--r-- | libass/ass_mp.c | 15 | ||||
-rw-r--r-- | libass/ass_mp.h | 1 |
4 files changed, 61 insertions, 14 deletions
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); |