[vlc-commits] STL: support change of style mid-sentence
Jean-Baptiste Kempf
git at videolan.org
Thu Jan 26 15:23:59 CET 2017
vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Thu Jan 26 00:58:07 2017 +0100| [0a439e275305fd4f95a18fef4ff62c2343284662] | committer: Jean-Baptiste Kempf
STL: support change of style mid-sentence
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0a439e275305fd4f95a18fef4ff62c2343284662
---
modules/codec/stl.c | 39 +++++++++++++++++++++++++++------------
1 file changed, 27 insertions(+), 12 deletions(-)
diff --git a/modules/codec/stl.c b/modules/codec/stl.c
index 1544388..f9e0705 100644
--- a/modules/codec/stl.c
+++ b/modules/codec/stl.c
@@ -85,6 +85,10 @@ static text_segment_t *ParseText(const uint8_t *data, size_t size, const char *c
if (text == NULL)
return NULL;
+ text_segment_t *segment = text_segment_New( NULL );
+ if (segment == NULL)
+ return NULL;
+
size_t text_size = 0;
for (size_t i = 0; i < size; i++) {
@@ -96,28 +100,39 @@ static text_segment_t *ParseText(const uint8_t *data, size_t size, const char *c
continue;
if (code & 0x60)
text[text_size++] = code;
- /* italics begin/end 0x80/0x81, underline being/end 0x82/0x83
- * TODO: handle the endings */
- if (code == 0x80 || code == 0x82 )
+ /* italics begin/end 0x80/0x81, underline being/end 0x82/0x83 */
+ if (code >= 0x80 && code <= 0x83 )
{
- style = text_style_Create( STYLE_NO_DEFAULTS );
- if (code == 0x80)
- style->i_style_flags |= STYLE_ITALIC;
- if (code == 0x82)
- style->i_style_flags |= STYLE_UNDERLINE;
- style->i_features |= STYLE_HAS_FLAGS;
+ /* Style Change, we do a new segment */
+ if( text_size != 0 )
+ {
+ segment->p_next = ParseText( &data[i], (size - i), charset);
+ break;
+ }
+ else
+ {
+ style = text_style_Create( STYLE_NO_DEFAULTS );
+ if (code == 0x80)
+ style->i_style_flags |= STYLE_ITALIC;
+ if (code == 0x81)
+ style->i_style_flags &= STYLE_ITALIC;
+ if (code == 0x82)
+ style->i_style_flags |= STYLE_UNDERLINE;
+ if (code == 0x83)
+ style->i_style_flags &= STYLE_UNDERLINE;
+ style->i_features |= STYLE_HAS_FLAGS;
+ }
}
if (code == 0x8a)
text[text_size++] = '\n';
}
- char *u8 = FromCharset(charset, text, text_size);
+ segment->psz_text = FromCharset(charset, text, text_size);
free(text);
- text_segment_t *segment = text_segment_New( u8 );
- free( u8 );
if( style )
segment->style = style;
+
return segment;
}
More information about the vlc-commits
mailing list