Commit f8c2165f authored by François Cartegnie's avatar François Cartegnie 🤞

vlc_text_style: add text ruby

parent 0c17ee76
......@@ -116,6 +116,19 @@ typedef struct
typedef struct text_segment_t text_segment_t;
typedef struct text_segment_ruby_t text_segment_ruby_t;
/**
* Text segment ruby for subtitles
* Each ruby has an anchor to the segment char.
*/
struct text_segment_ruby_t
{
char *psz_base;
char *psz_rt;
text_segment_ruby_t *p_next;
};
/**
* Text segment for subtitles
*
......@@ -132,6 +145,7 @@ 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 */
text_segment_ruby_t *p_ruby; /**< ruby descriptions */
};
/**
......@@ -210,6 +224,24 @@ VLC_API void text_segment_ChainDelete( text_segment_t * );
*/
VLC_API text_segment_t * text_segment_Copy( text_segment_t * );
/**
* This function will create a ruby section for a text_segment
*
*/
VLC_API text_segment_ruby_t *text_segment_ruby_New( const char *psz_base,
const char *psz_rt );
/**
* Deletes a ruby sections chain
*/
VLC_API void text_segment_ruby_ChainDelete( text_segment_ruby_t *p_ruby );
/**
* This function creates a text segment from a ruby section,
* and creates fallback string.
*/
VLC_API text_segment_t *text_segment_FromRuby( text_segment_ruby_t *p_ruby );
static const struct {
const char *psz_name;
uint32_t i_value;
......
......@@ -433,6 +433,9 @@ text_segment_NewInheritStyle
text_segment_Delete
text_segment_ChainDelete
text_segment_Copy
text_segment_FromRuby
text_segment_ruby_New
text_segment_ruby_ChainDelete
vlc_tls_ClientCreate
vlc_tls_ServerCreate
vlc_tls_Delete
......
......@@ -156,6 +156,49 @@ void text_style_Delete( text_style_t *p_style )
free( p_style );
}
void text_segment_ruby_ChainDelete( text_segment_ruby_t *p_ruby )
{
while( p_ruby )
{
text_segment_ruby_t *p_next = p_ruby->p_next;
free( p_ruby->psz_base );
free( p_ruby->psz_rt );
free( p_ruby );
p_ruby = p_next;
}
}
text_segment_ruby_t *text_segment_ruby_New( const char *psz_base,
const char *psz_rt )
{
text_segment_ruby_t *p_rb = malloc(sizeof(*p_rb));
if( p_rb )
{
p_rb->p_next = NULL;
p_rb->psz_base = strdup( psz_base );
p_rb->psz_rt = strdup( psz_rt );
if( !p_rb->psz_base || !p_rb->psz_rt )
{
text_segment_ruby_ChainDelete( p_rb );
return NULL;
}
}
return p_rb;
}
static text_segment_ruby_t *text_segment_ruby_Duplicate( const text_segment_ruby_t *p_src )
{
text_segment_ruby_t *p_dup = NULL;
text_segment_ruby_t **pp_append = &p_dup;
for ( ; p_src ; p_src = p_src->p_next )
{
*pp_append = text_segment_ruby_New( p_src->psz_base, p_src->psz_rt );
if( *pp_append )
pp_append = &((*pp_append)->p_next);
}
return p_dup;
}
text_segment_t *text_segment_New( const char *psz_text )
{
text_segment_t* segment = calloc( 1, sizeof(*segment) );
......@@ -184,12 +227,34 @@ text_segment_t *text_segment_NewInheritStyle( const text_style_t* p_style )
return p_segment;
}
text_segment_t *text_segment_FromRuby( text_segment_ruby_t *p_ruby )
{
text_segment_t *p_segment = text_segment_New( NULL );
if( p_segment )
{
p_segment->p_ruby = p_ruby;
size_t i_base = 1;
for( text_segment_ruby_t *p = p_ruby; p; p = p->p_next )
i_base += strlen( p->psz_base );
p_segment->psz_text = malloc( i_base );
/* Fallback for those not understanding p_ruby */
if( p_segment->psz_text )
{
*p_segment->psz_text = 0;
for( text_segment_ruby_t *p = p_ruby; p; p = p->p_next )
strcat( p_segment->psz_text, p->psz_base );
}
}
return p_segment;
}
void text_segment_Delete( text_segment_t* segment )
{
if ( segment != NULL )
{
free( segment->psz_text );
text_style_Delete( segment->style );
text_segment_ruby_ChainDelete( segment->p_ruby );
free( segment );
}
}
......@@ -217,6 +282,7 @@ text_segment_t *text_segment_Copy( text_segment_t *p_src )
break;
p_new->style = text_style_Duplicate( p_src->style );
p_new->p_ruby = text_segment_ruby_Duplicate( p_src->p_ruby );
if( p_dst == NULL )
{
......
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