Commit b8ce6743 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen Committed by Jean-Baptiste Kempf

tx3g: Replace subtext.h's segment_t with text_segment_t

parent a9c0a1ba
......@@ -107,6 +107,8 @@ 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 */
size_t i_size; //FIXME: substx3g specific
};
/**
......
#include <vlc_strings.h>
#include <vlc_text_style.h>
typedef struct
{
......@@ -6,21 +7,10 @@ typedef struct
unsigned int i_value;
} subpicture_updater_sys_option_t;
typedef struct segment_t segment_t;
struct segment_t
{
char *psz_string;
unsigned int i_size;
segment_t *p_next;
/* styles applied to that segment */
text_style_t styles;
};
struct subpicture_updater_sys_t {
char *text;
char *html;
segment_t *p_htmlsegments;
text_segment_t *p_htmlsegments;
int align;
int x;
......@@ -42,15 +32,6 @@ struct subpicture_updater_sys_t {
int16_t i_drop_shadow_alpha;
};
static void SegmentFree( segment_t *p_segment )
{
if ( p_segment )
{
free( p_segment->psz_string );
free( p_segment );
}
}
static void MakeHtmlNewLines( char **ppsz_src )
{
unsigned int i_nlcount = 0;
......@@ -146,13 +127,13 @@ static void HtmlAppend( char **ppsz_dst, const char *psz_src,
*ppsz_dst = psz_text;
}
static char *SegmentsToHtml( segment_t *p_head, const float f_scale )
static char *SegmentsToHtml( text_segment_t *p_head, const float f_scale )
{
char *psz_dst = NULL;
char *psz_ret = NULL;
while( p_head )
{
HtmlAppend( &psz_dst, p_head->psz_string, &p_head->styles, f_scale );
HtmlAppend( &psz_dst, p_head->psz_text, p_head->style, f_scale );
p_head = p_head->p_next;
}
int i_ret = asprintf( &psz_ret, "<text>%s</text>", psz_dst );
......@@ -280,9 +261,9 @@ static void SubpictureTextDestroy(subpicture_t *subpic)
free(sys->html);
while( sys->p_htmlsegments )
{
segment_t *p_segment = sys->p_htmlsegments;
sys->p_htmlsegments = sys->p_htmlsegments->p_next;
SegmentFree( p_segment );
text_segment_t *p_segment = sys->p_htmlsegments;
sys->p_htmlsegments = p_segment->p_next;
text_segment_Delete( p_segment );
}
free(sys);
}
......
......@@ -117,14 +117,14 @@ static char * str8indup( const char *psz_string, size_t i_skip, size_t n )
return strndup( psz_string, psz_tmp - psz_string );
}
static void SegmentDoSplit( segment_t *p_segment, uint16_t i_start, uint16_t i_end,
segment_t **pp_segment_left,
segment_t **pp_segment_middle,
segment_t **pp_segment_right )
static void SegmentDoSplit( text_segment_t *p_segment, uint16_t i_start, uint16_t i_end,
text_segment_t **pp_segment_left,
text_segment_t **pp_segment_middle,
text_segment_t **pp_segment_right )
{
segment_t *p_segment_left = *pp_segment_left;
segment_t *p_segment_right = *pp_segment_right;
segment_t *p_segment_middle = *pp_segment_middle;
text_segment_t *p_segment_left = *pp_segment_left;
text_segment_t *p_segment_right = *pp_segment_right;
text_segment_t *p_segment_middle = *pp_segment_middle;
p_segment_left = p_segment_middle = p_segment_right = NULL;
if ( (p_segment->i_size - i_start < 1) || (p_segment->i_size - i_end < 1) )
......@@ -132,26 +132,29 @@ static void SegmentDoSplit( segment_t *p_segment, uint16_t i_start, uint16_t i_e
if ( i_start > 0 )
{
p_segment_left = calloc( 1, sizeof(segment_t) );
char* psz_text = str8indup( p_segment->psz_text, 0, i_start );
p_segment_left = text_segment_New( psz_text );
free( psz_text );
if ( !p_segment_left ) goto error;
memcpy( &p_segment_left->styles, &p_segment->styles, sizeof(text_style_t) );
p_segment_left->psz_string = str8indup( p_segment->psz_string, 0, i_start );
p_segment_left->i_size = str8len( p_segment_left->psz_string );
p_segment_left->style = text_style_Duplicate( p_segment->style );
p_segment_left->i_size = str8len( p_segment_left->psz_text );
}
p_segment_middle = calloc( 1, sizeof(segment_t) );
char* psz_text = str8indup( p_segment->psz_text, i_start, i_end - i_start + 1 );
p_segment_middle = text_segment_New( psz_text );
free( psz_text );
if ( !p_segment_middle ) goto error;
memcpy( &p_segment_middle->styles, &p_segment->styles, sizeof(text_style_t) );
p_segment_middle->psz_string = str8indup( p_segment->psz_string, i_start, i_end - i_start + 1 );
p_segment_middle->i_size = str8len( p_segment_middle->psz_string );
p_segment_middle->style = text_style_Duplicate( p_segment->style );
p_segment_middle->i_size = str8len( p_segment_middle->psz_text );
if ( i_end < (p_segment->i_size - 1) )
{
p_segment_right = calloc( 1, sizeof(segment_t) );
char* psz_text = str8indup( p_segment->psz_text, i_end + 1, p_segment->i_size - i_end - 1 );
p_segment_right = text_segment_New( psz_text );
free( psz_text );
if ( !p_segment_right ) goto error;
memcpy( &p_segment_right->styles, &p_segment->styles, sizeof(text_style_t) );
p_segment_right->psz_string = str8indup( p_segment->psz_string, i_end + 1, p_segment->i_size - i_end - 1 );
p_segment_right->i_size = str8len( p_segment_right->psz_string );
p_segment_right->style = text_style_Duplicate( p_segment->style );
p_segment_right->i_size = str8len( p_segment_right->psz_text );
}
if ( p_segment_left ) p_segment_left->p_next = p_segment_middle;
......@@ -164,16 +167,16 @@ static void SegmentDoSplit( segment_t *p_segment, uint16_t i_start, uint16_t i_e
return;
error:
SegmentFree( p_segment_left );
SegmentFree( p_segment_middle );
SegmentFree( p_segment_right );
text_segment_Delete( p_segment_left );
text_segment_Delete( p_segment_middle );
text_segment_Delete( p_segment_right );
}
static bool SegmentSplit( segment_t *p_prev, segment_t **pp_segment,
static bool SegmentSplit( text_segment_t *p_prev, text_segment_t **pp_segment,
const uint16_t i_start, const uint16_t i_end,
const text_style_t *p_styles )
{
segment_t *p_segment_left = NULL, *p_segment_middle = NULL, *p_segment_right = NULL;
text_segment_t *p_segment_left = NULL, *p_segment_middle = NULL, *p_segment_right = NULL;
if ( (*pp_segment)->i_size == 0 ) return false;
if ( i_start > i_end ) return false;
......@@ -184,13 +187,13 @@ static bool SegmentSplit( segment_t *p_prev, segment_t **pp_segment,
if ( !p_segment_middle )
{
/* Failed */
SegmentFree( p_segment_left );
SegmentFree( p_segment_right );
text_segment_Delete( p_segment_left );
text_segment_Delete( p_segment_right );
return false;
}
segment_t *p_next = (*pp_segment)->p_next;
SegmentFree( *pp_segment );
text_segment_t *p_next = (*pp_segment)->p_next;
text_segment_Delete( *pp_segment );
*pp_segment = ( p_segment_left ) ? p_segment_left : p_segment_middle ;
if ( p_prev ) p_prev->p_next = *pp_segment;
......@@ -199,20 +202,21 @@ static bool SegmentSplit( segment_t *p_prev, segment_t **pp_segment,
else
p_segment_middle->p_next = p_next;
p_segment_middle->styles = *p_styles;
text_style_Delete( p_segment_middle->style );
p_segment_middle->style = text_style_Duplicate( p_styles );
return true;
}
/* Creates a new segment using the given style and split existing ones according
to the start & end offsets */
static void ApplySegmentStyle( segment_t **pp_segment, const uint16_t i_absstart,
static void ApplySegmentStyle( text_segment_t **pp_segment, const uint16_t i_absstart,
const uint16_t i_absend, const text_style_t *p_styles )
{
/* find the matching segment */
uint16_t i_curstart = 0;
segment_t *p_prev = NULL;
segment_t *p_cur = *pp_segment;
text_segment_t *p_prev = NULL;
text_segment_t *p_cur = *pp_segment;
while ( p_cur )
{
uint16_t i_curend = i_curstart + p_cur->i_size - 1;
......@@ -278,26 +282,21 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
for( uint16_t i=0; i < i_psz_bytelength; i++ )
if ( psz_subtitle[i] == '\r' ) psz_subtitle[i] = '\n';
segment_t *p_segment = calloc( 1, sizeof(segment_t) );
if ( !p_segment )
{
free( psz_subtitle );
return NULL;
}
p_segment->psz_string = strdup( psz_subtitle );
text_segment_t *p_segment = text_segment_New( psz_subtitle );
p_segment->i_size = str8len( psz_subtitle );
if ( p_dec->fmt_in.subs.p_style )
{
p_segment->styles.i_font_color = p_dec->fmt_in.subs.p_style->i_font_color;
p_segment->styles.i_font_alpha = p_dec->fmt_in.subs.p_style->i_font_alpha;
p_segment->style = text_style_New();
p_segment->style->i_font_color = p_dec->fmt_in.subs.p_style->i_font_color;
p_segment->style->i_font_alpha = p_dec->fmt_in.subs.p_style->i_font_alpha;
if ( p_dec->fmt_in.subs.p_style->i_style_flags )
p_segment->styles.i_style_flags = p_dec->fmt_in.subs.p_style->i_style_flags;
p_segment->styles.i_font_size = p_dec->fmt_in.subs.p_style->i_font_size;
p_segment->style->i_style_flags = p_dec->fmt_in.subs.p_style->i_style_flags;
p_segment->style->i_font_size = p_dec->fmt_in.subs.p_style->i_font_size;
}
if ( !p_segment->psz_string )
if ( !p_segment->psz_text )
{
SegmentFree( p_segment );
text_segment_Delete( p_segment );
free( psz_subtitle );
return NULL;
}
......@@ -307,7 +306,7 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
if( !p_spu )
{
free( psz_subtitle );
SegmentFree( p_segment );
text_segment_Delete( p_segment );
return NULL;
}
subpicture_updater_sys_t *p_spu_sys = p_spu->updater.p_sys;
......
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