summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorChris Bass <floobleflam@gmail.com>2017-04-20 14:43:45 +0100
committerSebastian Dröge <sebastian@centricular.com>2017-04-20 18:50:05 +0100
commit9f5e41218f03866d76c1326c242b011058599c6e (patch)
tree0e2cf43fa7f3324f193c90be9cb2a26aa275389a /ext
parent6eb36406f0c62d7f82436a3d9aa6c216ffaa62ab (diff)
downloadgstreamer-plugins-bad-9f5e41218f03866d76c1326c242b011058599c6e.tar.gz
ttmlparse: Convert tabs to spaces in input
The TTML spec has an issue in which tab (U+0009) characters that are first in a sequence of whitespace characters are not suppressed at the start and end of line areas. This issue was reported in [1] and the editor of the TTML specs confirmed that this was not the intention behind the spec. The editor has created an issue to fix this in both the TTML1 and TTML2 specs [2], giving a proposal of what the spec should say. This patch updates ttmlparse to implement the intended behaviour as proposed, in which tabs in the input are converted to spaces before processing. [1] https://github.com/w3c/imsc/issues/224 [2] https://github.com/w3c/ttml1/issues/235 https://bugzilla.gnome.org/show_bug.cgi?id=781539
Diffstat (limited to 'ext')
-rw-r--r--ext/ttml/ttmlparse.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/ext/ttml/ttmlparse.c b/ext/ttml/ttmlparse.c
index 777f361c1..8e8499056 100644
--- a/ext/ttml/ttmlparse.c
+++ b/ext/ttml/ttmlparse.c
@@ -44,6 +44,12 @@
#define MAX_FONT_FAMILY_NAME_LENGTH 128
#define NSECONDS_IN_DAY 24 * 3600 * GST_SECOND
+#define TTML_CHAR_NULL 0x00
+#define TTML_CHAR_SPACE 0x20
+#define TTML_CHAR_TAB 0x09
+#define TTML_CHAR_LF 0x0A
+#define TTML_CHAR_CR 0x0D
+
GST_DEBUG_CATEGORY_EXTERN (ttmlparse_debug);
#define GST_CAT_DEFAULT ttmlparse_debug
@@ -1247,12 +1253,14 @@ ttml_handle_element_whitespace (GNode * node, gpointer data)
gunichar u = g_utf8_get_char (c);
gint nbytes = g_unichar_to_utf8 (u, buf);
- if (nbytes == 1 && buf[0] == 0xA) {
+ /* Repace each newline or tab with a space. */
+ if (nbytes == 1 && (buf[0] == TTML_CHAR_LF || buf[0] == TTML_CHAR_TAB)) {
*c = ' ';
- buf[0] = 0x20;
+ buf[0] = TTML_CHAR_SPACE;
}
- if (nbytes == 1 && (buf[0] == 0x20 || buf[0] == 0x9 || buf[0] == 0xD)) {
+ /* Collapse runs of whitespace. */
+ if (nbytes == 1 && (buf[0] == TTML_CHAR_SPACE || buf[0] == TTML_CHAR_CR)) {
++space_count;
} else {
if (space_count > 1) {
@@ -1261,7 +1269,7 @@ ttml_handle_element_whitespace (GNode * node, gpointer data)
c = new_head;
}
space_count = 0;
- if (nbytes == 1 && buf[0] == 0x0) /* Reached end of string. */
+ if (nbytes == 1 && buf[0] == TTML_CHAR_NULL)
break;
}
}