Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions src/lib_ccx/ccx_encoders_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,21 +356,35 @@ unsigned get_decoder_line_encoded(struct encoder_ctx *ctx, unsigned char *buffer
buffer = close_tag(ctx, buffer, tagstack, 'I', &underlined, &italics, &changed_font);
}
int bytes = 0;
switch (ctx->encoding)
if (ctx->write_format == CCX_OF_SMPTETT && (line[i] == '&' || line[i] == '<' || line[i] == '>'))
{
case CCX_ENC_UTF_8:
bytes = get_char_in_utf_8(buffer, line[i]);
break;
case CCX_ENC_LATIN_1:
get_char_in_latin_1(buffer, line[i]);
bytes = 1;
break;
case CCX_ENC_UNICODE:
get_char_in_unicode(buffer, line[i]);
bytes = 2;
break;
case CCX_ENC_ASCII: // Consider to remove ASCII encoding or write get_char_in_ascii(...)
break;
const char *entity = NULL;
if (line[i] == '&')
entity = "&amp;";
else if (line[i] == '<')
entity = "&lt;";
else if (line[i] == '>')
entity = "&gt;";
bytes = encode_line(ctx, buffer, (unsigned char *)entity);
}
else
{
switch (ctx->encoding)
{
case CCX_ENC_UTF_8:
bytes = get_char_in_utf_8(buffer, line[i]);
break;
case CCX_ENC_LATIN_1:
get_char_in_latin_1(buffer, line[i]);
bytes = 1;
break;
case CCX_ENC_UNICODE:
get_char_in_unicode(buffer, line[i]);
bytes = 2;
break;
case CCX_ENC_ASCII: // Consider to remove ASCII encoding or write get_char_in_ascii(...)
break;
}
}
buffer += bytes;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib_ccx/ccx_encoders_smptett.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ int write_cc_buffer_as_smptett(struct eia608_screen *data, struct encoder_ctx *c
if (written > 0 && (size_t)written < remaining)
final_len += written;

char *temp_pointer = strchr((const char *)(context->subline), '#'); // locating color code
char *temp_pointer = strchr(start, '#'); // locating color code

char color_code[8];
if (temp_pointer)
Expand All @@ -408,7 +408,7 @@ int write_cc_buffer_as_smptett(struct eia608_screen *data, struct encoder_ctx *c
color_code[0] = '\0';
}

temp_pointer = strchr((const char *)(context->subline), '>'); // The content is in between <font ..> and </font>
temp_pointer = strchr(start, '>'); // The content is in between <font ..> and </font>

if (temp_pointer)
{
Expand Down
24 changes: 20 additions & 4 deletions src/lib_ccx/ccx_encoders_webvtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,26 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co
// write current text symbol
if (line[j] != '\0')
{
unsigned char buf[5] = {0};
// Note: reference should be safe even when j == COLUMNS; characters is nul-terminated
int bytes = get_char_in_utf_8(buf, data->characters[i][j]);
write_wrapped(context->out->fh, buf, bytes);
unsigned char c = data->characters[i][j];
if (c == '&')
{
write_wrapped(context->out->fh, "&amp;", 5);
}
else if (c == '<')
{
write_wrapped(context->out->fh, "&lt;", 4);
}
else if (c == '>')
{
write_wrapped(context->out->fh, "&gt;", 4);
}
else
{
unsigned char buf[5] = {0};
// Note: reference should be safe even when j == COLUMNS; characters is nul-terminated
int bytes = get_char_in_utf_8(buf, c);
write_wrapped(context->out->fh, buf, bytes);
}
}

if (ccx_options.use_webvtt_styling)
Expand Down
Loading