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;
#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);
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);
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;
*/
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
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;
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.;
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");
style->MarginV = 20;
style->ScaleX = 1.;
style->ScaleY = 1.;
+ }
return track;
}