Commit ef4a8698 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Introduce text_segment structure and API

Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 94ed9110
......@@ -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
......
......@@ -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
......
......@@ -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;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment