Commit 5bcb0a03 authored by Laurent Aimar's avatar Laurent Aimar

Added margin when using a background in freetype.

parent 75ebe274
...@@ -755,17 +755,20 @@ static inline void BlendYUVALine( picture_t *p_picture, ...@@ -755,17 +755,20 @@ static inline void BlendYUVALine( picture_t *p_picture,
static int RenderYUVA( filter_t *p_filter, static int RenderYUVA( filter_t *p_filter,
subpicture_region_t *p_region, subpicture_region_t *p_region,
line_desc_t *p_line_head, line_desc_t *p_line_head,
FT_BBox *p_bbox ) FT_BBox *p_bbox,
int i_margin )
{ {
filter_sys_t *p_sys = p_filter->p_sys; filter_sys_t *p_sys = p_filter->p_sys;
/* Create a new subpicture region */ /* Create a new subpicture region */
const int i_text_width = p_bbox->xMax - p_bbox->xMin;
const int i_text_height = p_bbox->yMax - p_bbox->yMin;
video_format_t fmt; video_format_t fmt;
video_format_Init( &fmt, VLC_CODEC_YUVA ); video_format_Init( &fmt, VLC_CODEC_YUVA );
fmt.i_width = fmt.i_width =
fmt.i_visible_width = p_bbox->xMax - p_bbox->xMin; fmt.i_visible_width = i_text_width + 2 * i_margin;
fmt.i_height = fmt.i_height =
fmt.i_visible_height = p_bbox->yMax - p_bbox->yMin; fmt.i_visible_height = i_text_height + 2 * i_margin;
picture_t *p_picture = p_region->p_picture = picture_NewFromFormat( &fmt ); picture_t *p_picture = p_region->p_picture = picture_NewFromFormat( &fmt );
if( !p_region->p_picture ) if( !p_region->p_picture )
...@@ -789,16 +792,16 @@ static int RenderYUVA( filter_t *p_filter, ...@@ -789,16 +792,16 @@ static int RenderYUVA( filter_t *p_filter,
/* Render all lines */ /* Render all lines */
for( line_desc_t *p_line = p_line_head; p_line != NULL; p_line = p_line->p_next ) for( line_desc_t *p_line = p_line_head; p_line != NULL; p_line = p_line->p_next )
{ {
/* Left offset to take into account alignment */ int i_align_left = i_margin;
int i_align_left = 0; if( p_line->i_width < i_text_width )
if( p_line->i_width < fmt.i_visible_width )
{ {
/* Left offset to take into account alignment */
if( (p_region->i_align & 0x3) == SUBPICTURE_ALIGN_RIGHT ) if( (p_region->i_align & 0x3) == SUBPICTURE_ALIGN_RIGHT )
i_align_left = ( fmt.i_visible_width - p_line->i_width ); i_align_left += ( i_text_width - p_line->i_width );
else if( (p_region->i_align & 0x3) != SUBPICTURE_ALIGN_LEFT ) else if( (p_region->i_align & 0x3) != SUBPICTURE_ALIGN_LEFT )
i_align_left = ( fmt.i_visible_width - p_line->i_width ) / 2; i_align_left += ( i_text_width - p_line->i_width ) / 2;
} }
int i_align_top = 0; int i_align_top = i_margin;
/* Render all glyphs and underline/strikethrough */ /* Render all glyphs and underline/strikethrough */
for( int i = 0; i < p_line->i_character_count; i++ ) for( int i = 0; i < p_line->i_character_count; i++ )
...@@ -1611,6 +1614,7 @@ static void BBoxEnlarge( FT_BBox *p_max, const FT_BBox *p ) ...@@ -1611,6 +1614,7 @@ static void BBoxEnlarge( FT_BBox *p_max, const FT_BBox *p )
static int ProcessLines( filter_t *p_filter, static int ProcessLines( filter_t *p_filter,
line_desc_t **pp_lines, line_desc_t **pp_lines,
FT_BBox *p_bbox, FT_BBox *p_bbox,
int *pi_max_face_height,
uint32_t *psz_text, uint32_t *psz_text,
text_style_t **pp_styles, text_style_t **pp_styles,
...@@ -1706,6 +1710,7 @@ static int ProcessLines( filter_t *p_filter, ...@@ -1706,6 +1710,7 @@ static int ProcessLines( filter_t *p_filter,
} }
free( p_new_positions ); free( p_new_positions );
*pi_max_face_height = 0;
*pp_lines = NULL; *pp_lines = NULL;
line_desc_t **pp_line_next = pp_lines; line_desc_t **pp_line_next = pp_lines;
...@@ -1967,6 +1972,8 @@ static int ProcessLines( filter_t *p_filter, ...@@ -1967,6 +1972,8 @@ static int ProcessLines( filter_t *p_filter,
pp_line_next = &p_line->p_next; pp_line_next = &p_line->p_next;
} }
*pi_max_face_height = __MAX( *pi_max_face_height, i_face_height );
/* Skip what we have rendered and the line delimitor if present */ /* Skip what we have rendered and the line delimitor if present */
i_start = i_index; i_start = i_index;
if( i_start < i_len && psz_text[i_start] == '\n' ) if( i_start < i_len && psz_text[i_start] == '\n' )
...@@ -2026,6 +2033,7 @@ static int RenderCommon( filter_t *p_filter, subpicture_region_t *p_region_out, ...@@ -2026,6 +2033,7 @@ static int RenderCommon( filter_t *p_filter, subpicture_region_t *p_region_out,
int rv = VLC_SUCCESS; int rv = VLC_SUCCESS;
int i_text_length = 0; int i_text_length = 0;
FT_BBox bbox; FT_BBox bbox;
int i_max_face_height;
line_desc_t *p_lines = NULL; line_desc_t *p_lines = NULL;
uint32_t *pi_k_durations = NULL; uint32_t *pi_k_durations = NULL;
...@@ -2118,7 +2126,7 @@ static int RenderCommon( filter_t *p_filter, subpicture_region_t *p_region_out, ...@@ -2118,7 +2126,7 @@ static int RenderCommon( filter_t *p_filter, subpicture_region_t *p_region_out,
if( !rv && i_text_length > 0 ) if( !rv && i_text_length > 0 )
{ {
rv = ProcessLines( p_filter, rv = ProcessLines( p_filter,
&p_lines, &bbox, &p_lines, &bbox, &i_max_face_height,
psz_text, pp_styles, pi_k_durations, i_text_length ); psz_text, pp_styles, pi_k_durations, i_text_length );
} }
...@@ -2132,7 +2140,10 @@ static int RenderCommon( filter_t *p_filter, subpicture_region_t *p_region_out, ...@@ -2132,7 +2140,10 @@ static int RenderCommon( filter_t *p_filter, subpicture_region_t *p_region_out,
if( var_InheritBool( p_filter, "freetype-yuvp" ) ) if( var_InheritBool( p_filter, "freetype-yuvp" ) )
RenderYUVP( p_filter, p_region_out, p_lines, &bbox ); RenderYUVP( p_filter, p_region_out, p_lines, &bbox );
else else
RenderYUVA( p_filter, p_region_out, p_lines, &bbox ); RenderYUVA( p_filter, p_region_out,
p_lines,
&bbox,
p_sys->i_background_opacity > 0 ? i_max_face_height / 4 : 0 );
/* With karaoke, we're going to have to render the text a number /* With karaoke, we're going to have to render the text a number
* of times to show the progress marker on the text. * of times to show the progress marker on the text.
......
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