vlc | branch: master | Jean-Baptiste Kempf <[email protected]> | Mon Apr 6 18:42:57 2015 +0200| [ef4a86984173bd968d470822a456e82514996223] | committer: Jean-Baptiste Kempf
Introduce text_segment structure and API Signed-off-by: Jean-Baptiste Kempf <[email protected]> > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ef4a86984173bd968d470822a456e82514996223 --- include/vlc_text_style.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/libvlccore.sym | 3 +++ src/misc/text_style.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) diff --git a/include/vlc_text_style.h b/include/vlc_text_style.h index d60cc97..2993faf 100644 --- a/include/vlc_text_style.h +++ b/include/vlc_text_style.h @@ -89,6 +89,26 @@ typedef struct #define STYLE_DEFAULT_FONT_SIZE 22 + +typedef struct text_segment_t text_segment_t; +/** + * Text segment for subtitles + * + * This structure is used to store a formatted text, with mixed styles + * Every segment is comprised of one text and a unique style + * + * On style change, a new segment is created with the next part of text + * and the new style, and chained to the list + * + * Create with text_segment_New and clean the chain with + * text_segment_ChainDelete + */ +struct text_segment_t { + char *psz_text; /**< text string of the segment */ + text_style_t *style; /**< style applied to this segment */ + text_segment_t *p_next; /**< next segment */ +}; + /** * Create a default text style */ @@ -109,6 +129,31 @@ VLC_API text_style_t * text_style_Duplicate( const text_style_t * ); */ VLC_API void text_style_Delete( text_style_t * ); +/** + * This function will create a new text segment. + * + * You should use text_segment_ChainDelete to destroy it, to clean all + * the linked segments. + * + * This duplicates the string passed as argument + */ +VLC_API text_segment_t *text_segment_New( const char * ); + +/** + * This function will destroy a list of text segments allocated + * by text_segment_New. + * + * You may pass it NULL. + */ +VLC_API void text_segment_ChainDelete( text_segment_t * ); + +/** + * This function will copy a text_segment and its chain into a new one + * + * You may give it NULL, but it will return NULL. + */ +VLC_API text_segment_t * text_segment_Copy( text_segment_t * ); + #ifdef __cplusplus } #endif diff --git a/src/libvlccore.sym b/src/libvlccore.sym index d8525b6..a2975d7 100644 --- a/src/libvlccore.sym +++ b/src/libvlccore.sym @@ -418,6 +418,9 @@ subpicture_region_ChainDelete subpicture_region_Copy subpicture_region_Delete subpicture_region_New +text_segment_New +text_segment_ChainDelete +text_segment_Copy vlc_tls_ClientCreate vlc_tls_Delete vlc_tls_ClientSessionCreate diff --git a/src/misc/text_style.c b/src/misc/text_style.c index f132790..1788634 100644 --- a/src/misc/text_style.c +++ b/src/misc/text_style.c @@ -94,3 +94,45 @@ void text_style_Delete( text_style_t *p_style ) free( p_style ); } +text_segment_t *text_segment_New( const char *psz_text ) +{ + text_segment_t* segment = calloc( 1, sizeof(*segment) ); + if( !segment ) + return NULL; + + segment->psz_text = strdup( psz_text ); + + return segment; +} + +void text_segment_ChainDelete( text_segment_t *segment ) +{ + while( segment != NULL ) + { + text_segment_t *p_next = segment->p_next; + + free( segment->psz_text ); + //text_style_Delete( segment->style ); + free( segment ); + + segment = p_next; + } +} + +text_segment_t *text_segment_Copy( text_segment_t *p_src ) +{ + text_segment_t *p_dst = NULL, *p_dst0 = NULL; + + while( p_src && p_src->p_next ) { + text_segment_t *p_next = text_segment_New( p_src->psz_text ); + p_src = p_src->p_next; + + if( p_dst == NULL ) + p_dst = p_dst0 = p_next; + else + p_dst->p_next = p_next; + } + + return p_dst0; +} + _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
