[vlc-commits] vlc_text_style: add text ruby
Francois Cartegnie
git at videolan.org
Fri Feb 16 19:38:15 CET 2018
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Feb 14 22:09:17 2018 +0100| [f8c2165f4e85129cf0478a532c5eeff9f35c0e06] | committer: Francois Cartegnie
vlc_text_style: add text ruby
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f8c2165f4e85129cf0478a532c5eeff9f35c0e06
---
include/vlc_text_style.h | 32 +++++++++++++++++++++++
src/libvlccore.sym | 3 +++
src/misc/text_style.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 101 insertions(+)
diff --git a/include/vlc_text_style.h b/include/vlc_text_style.h
index c24d76adcf..69b67c73e4 100644
--- a/include/vlc_text_style.h
+++ b/include/vlc_text_style.h
@@ -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;
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index e6f3abff34..740b3b53f8 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -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
diff --git a/src/misc/text_style.c b/src/misc/text_style.c
index 90de47a912..43944afb5a 100644
--- a/src/misc/text_style.c
+++ b/src/misc/text_style.c
@@ -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 )
{
More information about the vlc-commits
mailing list