Skip to content

Commit 971a997

Browse files
committed
Make octopus.setDropAnimations(true) mean something
1 parent a66e797 commit 971a997

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/SubtitleOctopus.cpp

+19-5
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,19 @@ static int _is_animated_tag(char *begin, char *end) {
154154
return 0;
155155
}
156156

157-
static int _is_event_animated(ASS_Event *event) {
157+
static void _remove_tag(char *begin, char *end) {
158+
// overwrite the tag with whitespace so libass won't see it
159+
for (; begin < end; begin++) *begin = ' ';
160+
}
161+
162+
static int _is_event_animated(ASS_Event *event, bool drop_animations) {
158163
// event is complex if it's animated in any way,
159164
// either by having non-empty Effect or
160165
// by having tags (enclosed in '{}' in Text)
161-
if (event->Effect && event->Effect[0] != '\0') return 1;
166+
if (event->Effect && event->Effect[0] != '\0') {
167+
if (!drop_animations) return 1;
168+
event->Effect[0] = '\0';
169+
}
162170

163171
int escaped = 0;
164172
char *tagStart = NULL;
@@ -172,13 +180,19 @@ static int _is_event_animated(ASS_Event *event) {
172180
break;
173181
case '}':
174182
if (!escaped && tagStart != NULL) {
175-
if (_is_animated_tag(tagStart, p)) return 1;
183+
if (_is_animated_tag(tagStart, p)) {
184+
if (!drop_animations) return 1;
185+
_remove_tag(tagStart, p);
186+
}
176187
tagStart = NULL;
177188
}
178189
break;
179190
case ';':
180191
if (tagStart != NULL) {
181-
if (_is_animated_tag(tagStart, p)) return 1;
192+
if (_is_animated_tag(tagStart, p)) {
193+
if (!drop_animations) return 1;
194+
_remove_tag(tagStart, p + 1 /* +1 is because we want to drop ';' as well */);
195+
}
182196
}
183197
tagStart = p + 1;
184198
break;
@@ -537,7 +551,7 @@ class SubtitleOctopus {
537551
ASS_Event *cur = track->events;
538552
int *animated = m_is_event_animated;
539553
for (int i = 0; i < track->n_events; i++, cur++, animated++) {
540-
*animated = _is_event_animated(cur);
554+
*animated = _is_event_animated(cur, m_drop_animations);
541555
}
542556
}
543557

0 commit comments

Comments
 (0)