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

vlc_subpicture: add balanced text region flag

By default width of wrapped lines tries to be balanced.
This is only relevant for displaying subtitles.
parent 14bbab92
......@@ -67,6 +67,7 @@ struct subpicture_region_t
text_segment_t *p_text; /**< subtitle text, made of a list of segments */
bool b_noregionbg; /**< render background under text only */
bool b_gridmode; /** if the decoder sends row/cols based output */
bool b_balanced_text; /** try to balance wrapped text lines */
int i_max_width; /** horizontal rendering/cropping limit */
int i_max_height; /** vertical rendering/cropping limit */
......
......@@ -1144,7 +1144,8 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region_out,
i_max_height -= p_region_in->i_y;
rv = LayoutText( p_filter,
psz_text, pp_styles, pi_k_durations, i_text_length, p_region_in->b_gridmode,
psz_text, pp_styles, pi_k_durations, i_text_length,
p_region_in->b_gridmode, p_region_in->b_balanced_text,
i_max_width, i_max_height, &p_lines, &bbox, &i_max_face_height );
p_region_out->i_x = p_region_in->i_x;
......
......@@ -1321,7 +1321,7 @@ static inline bool IsWhitespaceAt( paragraph_t *p_paragraph, size_t i )
static int LayoutParagraph( filter_t *p_filter, paragraph_t *p_paragraph,
unsigned i_max_width, unsigned i_max_advance_x,
line_desc_t **pp_lines, bool b_grid )
line_desc_t **pp_lines, bool b_grid, bool b_balance )
{
if( p_paragraph->i_size <= 0 || p_paragraph->i_runs_count <= 0 )
{
......@@ -1346,7 +1346,7 @@ static int LayoutParagraph( filter_t *p_filter, paragraph_t *p_paragraph,
int i_line_start = 0;
FT_Pos i_width = 0;
FT_Pos i_preferred_width = 0;
FT_Pos i_preferred_width = i_max_width;
FT_Pos i_total_width = 0;
FT_Pos i_last_space_width = 0;
int i_last_space = -1;
......@@ -1372,8 +1372,11 @@ static int LayoutParagraph( filter_t *p_filter, paragraph_t *p_paragraph,
return VLC_SUCCESS;
}
int i_line_count = i_total_width / (i_max_width - i_max_advance_x) + 1;
i_preferred_width = i_total_width / i_line_count;
if( b_balance )
{
int i_line_count = i_total_width / (i_max_width - i_max_advance_x) + 1;
i_preferred_width = i_total_width / i_line_count;
}
for( int i = 0; i <= p_paragraph->i_size; ++i )
{
......@@ -1483,7 +1486,8 @@ error:
int LayoutText( filter_t *p_filter,
const uni_char_t *psz_text, text_style_t **pp_styles,
uint32_t *pi_k_dates, int i_len, bool b_grid,
uint32_t *pi_k_dates, int i_len,
bool b_grid, bool b_balance,
unsigned i_max_width, unsigned i_max_height,
line_desc_t **pp_lines, FT_BBox *p_bbox, int *pi_max_face_height )
{
......@@ -1547,7 +1551,8 @@ int LayoutText( filter_t *p_filter,
#endif
if( LayoutParagraph( p_filter, p_paragraph,
i_max_width, i_max_advance_x, pp_line, b_grid ) )
i_max_width, i_max_advance_x, pp_line,
b_grid, b_balance ) )
goto error;
FreeParagraph( p_paragraph );
......
......@@ -71,6 +71,7 @@ line_desc_t *NewLine( int i_count );
* \param pi_k_dates array of size \p i_len containing karaoke timestamps for characters [IN]
* \param i_len length of the arrays \p psz_text, \p pp_styles, and \p pi_k_dates [IN]
* \param b_grid true for grid-mode text [IN]
* \param b_balance true for balanced wrapped lines [IN]
* \param i_max_width maximum available width to layout text [IN]
* \param i_max_height maximum available height to layout text [IN]
* \param pp_lines the list of line_desc_t's with rendered glyphs [OUT]
......@@ -79,6 +80,6 @@ line_desc_t *NewLine( int i_count );
*/
int LayoutText( filter_t *p_filter,
const uni_char_t *psz_text, text_style_t **pp_styles,
uint32_t *pi_k_dates, int i_len, bool b_grid,
uint32_t *pi_k_dates, int i_len, bool b_grid, bool b_balance,
unsigned i_max_width, unsigned i_max_height,
line_desc_t **pp_lines, FT_BBox *p_bbox, int *pi_max_face_height );
......@@ -230,6 +230,7 @@ subpicture_region_t *subpicture_region_New( const video_format_t *p_fmt )
}
p_region->i_alpha = 0xff;
p_region->b_balanced_text = true;
if( p_fmt->i_chroma == VLC_CODEC_TEXT )
return p_region;
......
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