annotate subassconvert.c @ 31978:3525dc14e3dc

Add the proper include instead of declaring the correct_pts variable extern.
author diego
date Tue, 07 Sep 2010 23:35:57 +0000
parents b41cbf02f854
children f2b40b588792
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31686
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
1 /*
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
2 * Subtitles converter to SSA/ASS in order to allow special formatting
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
3 *
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
4 * This file is part of MPlayer.
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
5 *
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
9 * (at your option) any later version.
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
10 *
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
14 * GNU General Public License for more details.
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
15 *
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License along
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
19 */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
20
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
21 #include <string.h>
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
22 #include <stdint.h>
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
23 #include <stdlib.h>
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
24 #include <stdio.h>
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
25 #include <stdarg.h>
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
26
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
27 #include "mp_msg.h"
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
28 #include "help_mp.h"
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
29 #include "bstr.h"
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
30 #include "subassconvert.h"
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
31 #include "libavutil/common.h"
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
32
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
33 struct line {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
34 char *buf;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
35 size_t bufsize;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
36 size_t len;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
37 };
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
38
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
39 #ifdef __GNUC__
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
40 static void append_text(struct line *dst, char *fmt, ...) __attribute__ ((format(printf, 2, 3)));
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
41 #endif
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
42
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
43 static void append_text(struct line *dst, char *fmt, ...)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
44 {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
45 va_list va;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
46 int ret;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
47
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
48 va_start(va, fmt);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
49 ret = vsnprintf(dst->buf + dst->len, dst->bufsize - dst->len, fmt, va);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
50 if (ret >= 0) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
51 dst->len += ret;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
52 if (dst->len > dst->bufsize)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
53 dst->len = dst->bufsize;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
54 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
55 va_end(va);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
56 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
57
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
58 static int indexof(const char *s, int c)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
59 {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
60 char *f = strchr(s, c);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
61 return f ? (f - s) : -1;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
62 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
63
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
64
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
65
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
66 /*
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
67 * SubRip
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
68 *
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
69 * Support basic tags (italic, bold, underline, strike-through)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
70 * and font tag with size, color and face attributes.
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
71 *
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
72 */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
73
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
74 struct font_tag {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
75 struct bstr face;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
76 int size;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
77 uint32_t color;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
78 };
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
79
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
80 static const struct tag_conv {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
81 const char *from;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
82 const char *to;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
83 } subrip_basic_tags[] = {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
84 {"<i>", "{\\i1}"}, {"</i>", "{\\i0}"},
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
85 {"<b>", "{\\b1}"}, {"</b>", "{\\b0}"},
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
86 {"<u>", "{\\u1}"}, {"</u>", "{\\u0}"},
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
87 {"<s>", "{\\s1}"}, {"</s>", "{\\s0}"},
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
88 {"{", "\\{"}, {"}", "\\}"},
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
89 {"\n", "\\N"}
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
90 };
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
91
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
92 static const struct {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
93 const char *s;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
94 uint32_t v;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
95 } subrip_web_colors[] = {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
96 /* 16 named HTML colors in BGR format */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
97 {"red", 0x0000ff}, {"blue", 0xff0000}, {"lime", 0x00ff00},
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
98 {"aqua", 0xffff00}, {"purple", 0x800080}, {"yellow", 0x00ffff},
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
99 {"fuchsia", 0xff00ff}, {"white", 0xffffff}, {"gray", 0x808080},
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
100 {"maroon", 0x000080}, {"olive", 0x008080}, {"black", 0x000000},
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
101 {"silver", 0xc0c0c0}, {"teal", 0x808000}, {"green", 0x008000},
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
102 {"navy", 0x800000}
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
103 };
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
104
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
105 #define SUBRIP_MAX_STACKED_FONT_TAGS 16
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
106 #define SUBRIP_FLAG_COLOR 0x01000000
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
107
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
108 /**
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
109 * \brief Convert SubRip lines into ASS markup
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
110 * \param orig original SubRip lines. The content will remain untouched.
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
111 * \param dest ASS markup destination buffer.
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
112 * \param dest_buffer_size maximum size for the destination buffer.
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
113 */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
114 void subassconvert_subrip(const char *orig, char *dest, size_t dest_buffer_size)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
115 {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
116 /* line is not const to avoid warnings with strtol, etc.
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
117 * orig content won't be changed */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
118 char *line = (char *)orig;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
119 struct line new_line = {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
120 .buf = dest,
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
121 .bufsize = dest_buffer_size,
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
122 };
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
123 struct font_tag font_stack[SUBRIP_MAX_STACKED_FONT_TAGS];
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
124 int sp = 0;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
125
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
126 font_stack[0] = (struct font_tag){}; // type with all defaults
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
127 while (*line && new_line.len < new_line.bufsize - 1) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
128 char *orig_line = line;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
129
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
130 for (int i = 0; i < FF_ARRAY_ELEMS(subrip_basic_tags); i++) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
131 const struct tag_conv *tag = &subrip_basic_tags[i];
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
132 int from_len = strlen(tag->from);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
133 if (strncmp(line, tag->from, from_len) == 0) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
134 append_text(&new_line, "%s", tag->to);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
135 line += from_len;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
136 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
137 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
138
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
139 if (strncmp(line, "</font>", 7) == 0) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
140 /* Closing font tag */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
141 line += 7;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
142
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
143 if (sp > 0) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
144 struct font_tag *tag = &font_stack[sp];
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
145 struct font_tag *last_tag = &tag[-1];
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
146 sp--;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
147
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
148 if (tag->size) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
149 if (!last_tag->size)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
150 append_text(&new_line, "{\\fs}");
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
151 else if (last_tag->size != tag->size)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
152 append_text(&new_line, "{\\fs%d}", last_tag->size);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
153 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
154
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
155 if (tag->color & SUBRIP_FLAG_COLOR) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
156 if (!(last_tag->color & SUBRIP_FLAG_COLOR))
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
157 append_text(&new_line, "{\\c}");
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
158 else if (last_tag->color != tag->color)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
159 append_text(&new_line, "{\\c&H%06X&}",
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
160 last_tag->color & 0xffffff);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
161 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
162
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
163 if (tag->face.len) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
164 if (!last_tag->face.len)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
165 append_text(&new_line, "{\\fn}");
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
166 else if (bstrcmp(last_tag->face, tag->face) != 0)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
167 append_text(&new_line, "{\\fn%.*s}",
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
168 BSTR_P(last_tag->face));
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
169 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
170 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
171 } else if (strncmp(line, "<font ", 6) == 0
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
172 && sp + 1 < FF_ARRAY_ELEMS(font_stack)) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
173 /* Opening font tag */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
174 char *potential_font_tag_start = line;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
175 int len_backup = new_line.len;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
176 struct font_tag *tag = &font_stack[sp + 1];
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
177 int has_valid_attr = 0;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
178
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
179 *tag = tag[-1]; // keep values from previous tag
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
180 line += 6;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
181
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
182 while (*line && *line != '>') {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
183 if (strncmp(line, "size=\"", 6) == 0) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
184 line += 6;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
185 tag->size = strtol(line, &line, 10);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
186 if (*line != '"' || !tag->size)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
187 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
188 append_text(&new_line, "{\\fs%d}", tag->size);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
189 has_valid_attr = 1;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
190 } else if (strncmp(line, "color=\"", 7) == 0) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
191 line += 7;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
192 if (*line == '#') {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
193 // #RRGGBB format
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
194 line++;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
195 tag->color = strtol(line, &line, 16) & 0x00ffffff;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
196 if (*line != '"')
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
197 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
198 tag->color = ((tag->color & 0xff) << 16) |
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
199 (tag->color & 0xff00) |
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
200 ((tag->color & 0xff0000) >> 16) |
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
201 SUBRIP_FLAG_COLOR;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
202 } else {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
203 // Standard web colors
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
204 int i, len = indexof(line, '"');
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
205 if (len <= 0)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
206 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
207 for (i = 0; i < FF_ARRAY_ELEMS(subrip_web_colors); i++) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
208 const char *color = subrip_web_colors[i].s;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
209 if (strlen(color) == len
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
210 && strncasecmp(line, color, len) == 0) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
211 tag->color = SUBRIP_FLAG_COLOR | subrip_web_colors[i].v;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
212 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
213 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
214 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
215
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
216 if (i == FF_ARRAY_ELEMS(subrip_web_colors)) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
217 /* We didn't find any matching color */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
218 line = strchr(line, '"'); // can't be NULL, see above
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
219 mp_msg(MSGT_SUBREADER, MSGL_WARN,
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
220 MSGTR_SUBTITLES_SubRip_UnknownFontColor, orig);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
221 append_text(&new_line, "{\\c}");
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
222 line += 2;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
223 continue;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
224 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
225
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
226 line += len;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
227 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
228 append_text(&new_line, "{\\c&H%06X&}", tag->color & 0xffffff);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
229 has_valid_attr = 1;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
230 } else if (strncmp(line, "face=\"", 6) == 0) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
231 /* Font face attribute */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
232 int len;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
233 line += 6;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
234 len = indexof(line, '"');
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
235 if (len <= 0)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
236 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
237 tag->face.start = line;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
238 tag->face.len = len;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
239 line += len;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
240 append_text(&new_line, "{\\fn%.*s}", BSTR_P(tag->face));
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
241 has_valid_attr = 1;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
242 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
243 line++;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
244 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
245
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
246 if (!has_valid_attr || *line != '>') { /* Not valid font tag */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
247 line = potential_font_tag_start;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
248 new_line.len = len_backup;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
249 } else {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
250 sp++;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
251 line++;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
252 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
253 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
254
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
255 /* Tag conversion code didn't match */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
256 if (line == orig_line)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
257 new_line.buf[new_line.len++] = *line++;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
258 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
259 new_line.buf[new_line.len] = 0;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
260 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
261
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
262
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
263 /*
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
264 * MicroDVD
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
265 *
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
266 * Based on the specifications found here:
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
267 * https://trac.videolan.org/vlc/ticket/1825#comment:6
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
268 */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
269
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
270 struct microdvd_tag {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
271 char key;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
272 int persistent;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
273 uint32_t data1;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
274 uint32_t data2;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
275 struct bstr data_string;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
276 };
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
277
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
278 #define MICRODVD_PERSISTENT_OFF 0
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
279 #define MICRODVD_PERSISTENT_ON 1
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
280 #define MICRODVD_PERSISTENT_OPENED 2
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
281
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
282 // Color, Font, Size, cHarset, stYle, Position, cOordinate
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
283 #define MICRODVD_TAGS "cfshyYpo"
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
284
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
285 static void microdvd_set_tag(struct microdvd_tag *tags, struct microdvd_tag tag)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
286 {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
287 int tag_index = indexof(MICRODVD_TAGS, tag.key);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
288
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
289 if (tag_index < 0)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
290 return;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
291 memcpy(&tags[tag_index], &tag, sizeof(tag));
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
292 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
293
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
294 // italic, bold, underline, strike-through
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
295 #define MICRODVD_STYLES "ibus"
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
296
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
297 static char *microdvd_load_tags(struct microdvd_tag *tags, char *s)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
298 {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
299 while (*s == '{') {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
300 char *start = s;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
301 char tag_char = *(s + 1);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
302 struct microdvd_tag tag = {};
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
303
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
304 if (!tag_char || *(s + 2) != ':')
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
305 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
306 s += 3;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
307
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
308 switch (tag_char) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
309
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
310 /* Style */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
311 case 'Y':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
312 tag.persistent = MICRODVD_PERSISTENT_ON;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
313 case 'y':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
314 while (*s && *s != '}') {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
315 int style_index = indexof(MICRODVD_STYLES, *s);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
316
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
317 if (style_index >= 0)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
318 tag.data1 |= (1 << style_index);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
319 s++;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
320 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
321 if (*s != '}')
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
322 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
323 /* We must distinguish persistent and non-persistent styles
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
324 * to handle this kind of style tags: {y:ib}{Y:us} */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
325 tag.key = tag_char;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
326 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
327
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
328 /* Color */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
329 case 'C':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
330 tag.persistent = MICRODVD_PERSISTENT_ON;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
331 case 'c':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
332 tag.data1 = strtol(s, &s, 16) & 0x00ffffff;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
333 if (*s != '}')
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
334 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
335 tag.key = 'c';
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
336 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
337
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
338 /* Font name */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
339 case 'F':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
340 tag.persistent = MICRODVD_PERSISTENT_ON;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
341 case 'f':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
342 {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
343 int len = indexof(s, '}');
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
344 if (len < 0)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
345 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
346 tag.data_string.start = s;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
347 tag.data_string.len = len;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
348 s += len;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
349 tag.key = 'f';
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
350 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
351 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
352
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
353 /* Font size */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
354 case 'S':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
355 tag.persistent = MICRODVD_PERSISTENT_ON;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
356 case 's':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
357 tag.data1 = strtol(s, &s, 10);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
358 if (*s != '}')
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
359 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
360 tag.key = 's';
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
361 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
362
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
363 /* Charset */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
364 case 'H':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
365 {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
366 //TODO: not yet handled, just parsed.
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
367 int len = indexof(s, '}');
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
368 if (len < 0)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
369 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
370 tag.data_string.start = s;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
371 tag.data_string.len = len;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
372 s += len;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
373 tag.key = 'h';
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
374 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
375 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
376
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
377 /* Position */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
378 case 'P':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
379 tag.persistent = MICRODVD_PERSISTENT_ON;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
380 tag.data1 = (*s++ == '1');
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
381 if (*s != '}')
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
382 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
383 tag.key = 'p';
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
384 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
385
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
386 /* Coordinates */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
387 case 'o':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
388 tag.persistent = MICRODVD_PERSISTENT_ON;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
389 tag.data1 = strtol(s, &s, 10);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
390 if (*s != ',')
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
391 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
392 s++;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
393 tag.data2 = strtol(s, &s, 10);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
394 if (*s != '}')
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
395 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
396 tag.key = 'o';
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
397 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
398
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
399 default: /* Unknown tag, we consider it's text */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
400 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
401 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
402
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
403 if (tag.key == 0)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
404 return start;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
405
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
406 microdvd_set_tag(tags, tag);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
407 s++;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
408 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
409 return s;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
410 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
411
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
412 static void microdvd_open_tags(struct line *new_line, struct microdvd_tag *tags)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
413 {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
414 for (int i = 0; i < sizeof(MICRODVD_TAGS) - 1; i++) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
415 if (tags[i].persistent == MICRODVD_PERSISTENT_OPENED)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
416 continue;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
417 switch (tags[i].key) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
418 case 'Y':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
419 case 'y':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
420 for (int sidx = 0; sidx < sizeof(MICRODVD_STYLES) - 1; sidx++)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
421 if (tags[i].data1 & (1 << sidx))
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
422 append_text(new_line, "{\\%c1}", MICRODVD_STYLES[sidx]);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
423 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
424
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
425 case 'c':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
426 append_text(new_line, "{\\c&H%06X&}", tags[i].data1);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
427 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
428
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
429 case 'f':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
430 append_text(new_line, "{\\fn%.*s}", BSTR_P(tags[i].data_string));
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
431 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
432
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
433 case 's':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
434 append_text(new_line, "{\\fs%d}", tags[i].data1);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
435 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
436
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
437 case 'p':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
438 if (tags[i].data1 == 0)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
439 append_text(new_line, "{\\an8}");
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
440 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
441
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
442 case 'o':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
443 append_text(new_line, "{\\pos(%d,%d)}",
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
444 tags[i].data1, tags[i].data2);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
445 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
446 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
447 if (tags[i].persistent == MICRODVD_PERSISTENT_ON)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
448 tags[i].persistent = MICRODVD_PERSISTENT_OPENED;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
449 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
450 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
451
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
452 static void microdvd_close_no_persistent_tags(struct line *new_line,
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
453 struct microdvd_tag *tags)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
454 {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
455 int i;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
456
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
457 for (i = sizeof(MICRODVD_TAGS) - 2; i; i--) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
458 if (tags[i].persistent != MICRODVD_PERSISTENT_OFF)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
459 continue;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
460 switch (tags[i].key) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
461
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
462 case 'y':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
463 for (int sidx = sizeof(MICRODVD_STYLES) - 2; sidx >= 0; sidx--)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
464 if (tags[i].data1 & (1 << sidx))
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
465 append_text(new_line, "{\\%c0}", MICRODVD_STYLES[sidx]);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
466 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
467
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
468 case 'c':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
469 append_text(new_line, "{\\c}");
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
470 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
471
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
472 case 'f':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
473 append_text(new_line, "{\\fn}");
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
474 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
475
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
476 case 's':
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
477 append_text(new_line, "{\\fs}");
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
478 break;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
479 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
480 tags[i].key = 0;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
481 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
482 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
483
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
484 /**
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
485 * \brief Convert MicroDVD lines into ASS markup
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
486 * \param orig original MicroDVD line. The content will remain untouched.
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
487 * \param dest ASS markup destination buffer.
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
488 * \param dest_buffer_size maximum size for the destination buffer.
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
489 */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
490 void subassconvert_microdvd(const char *orig, char *dest, size_t dest_buffer_size)
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
491 {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
492 /* line is not const to avoid warnings with strtol, etc.
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
493 * orig content won't be changed */
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
494 char *line = (char *)orig;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
495 struct line new_line = {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
496 .buf = dest,
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
497 .bufsize = dest_buffer_size,
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
498 };
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
499 struct microdvd_tag tags[sizeof(MICRODVD_TAGS) - 1] = {};
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
500
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
501 while (*line) {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
502 line = microdvd_load_tags(tags, line);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
503 microdvd_open_tags(&new_line, tags);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
504
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
505 while (*line && *line != '|')
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
506 new_line.buf[new_line.len++] = *line++;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
507
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
508 if (*line == '|') {
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
509 microdvd_close_no_persistent_tags(&new_line, tags);
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
510 append_text(&new_line, "\\N");
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
511 line++;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
512 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
513 }
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
514 new_line.buf[new_line.len] = 0;
b41cbf02f854 subtitles: convert SRT/MicroDVD markup into ASS markup
greg
parents:
diff changeset
515 }