[vlc-commits] vlc_subpicture: add balanced text region flag

Francois Cartegnie git at videolan.org
Mon Jun 26 14:15:35 CEST 2017


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Jun 26 14:09:02 2017 +0200| [fb2afd86ab7acdc485ff563e823f61e5f65a6cab] | committer: Francois 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.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fb2afd86ab7acdc485ff563e823f61e5f65a6cab
---

 include/vlc_subpicture.h                     |  1 +
 modules/text_renderer/freetype/freetype.c    |  3 ++-
 modules/text_renderer/freetype/text_layout.c | 17 +++++++++++------
 modules/text_renderer/freetype/text_layout.h |  3 ++-
 src/misc/subpicture.c                        |  1 +
 5 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/include/vlc_subpicture.h b/include/vlc_subpicture.h
index d3a1242864..0cb358aeb8 100644
--- a/include/vlc_subpicture.h
+++ b/include/vlc_subpicture.h
@@ -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 */
 
diff --git a/modules/text_renderer/freetype/freetype.c b/modules/text_renderer/freetype/freetype.c
index 01532000c7..39994a01b0 100644
--- a/modules/text_renderer/freetype/freetype.c
+++ b/modules/text_renderer/freetype/freetype.c
@@ -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;
diff --git a/modules/text_renderer/freetype/text_layout.c b/modules/text_renderer/freetype/text_layout.c
index bbd88f5dfc..e25ff1f844 100644
--- a/modules/text_renderer/freetype/text_layout.c
+++ b/modules/text_renderer/freetype/text_layout.c
@@ -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 );
diff --git a/modules/text_renderer/freetype/text_layout.h b/modules/text_renderer/freetype/text_layout.h
index 0cb3aca710..b67674bf94 100644
--- a/modules/text_renderer/freetype/text_layout.h
+++ b/modules/text_renderer/freetype/text_layout.h
@@ -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 );
diff --git a/src/misc/subpicture.c b/src/misc/subpicture.c
index 10adc29d75..fdf111fb69 100644
--- a/src/misc/subpicture.c
+++ b/src/misc/subpicture.c
@@ -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;



More information about the vlc-commits mailing list