[vlc-commits] text_renderer: freetype: use structure as parameter for layout

Francois Cartegnie git at videolan.org
Fri Feb 16 19:38:06 CET 2018


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Feb  9 19:04:35 2018 +0100| [e82cde4e395cdb4bdc70a2d53ebb7e525f0e4cc2] | committer: Francois Cartegnie

text_renderer: freetype: use structure as parameter for layout

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

 modules/text_renderer/freetype/freetype.c    | 29 ++++++++++++------------
 modules/text_renderer/freetype/text_layout.c | 33 ++++++++++++++--------------
 modules/text_renderer/freetype/text_layout.h | 33 +++++++++++++++++-----------
 3 files changed, 50 insertions(+), 45 deletions(-)

diff --git a/modules/text_renderer/freetype/freetype.c b/modules/text_renderer/freetype/freetype.c
index 2973180d6e..a7f97d7d49 100644
--- a/modules/text_renderer/freetype/freetype.c
+++ b/modules/text_renderer/freetype/freetype.c
@@ -1119,11 +1119,12 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region_out,
         return VLC_EGENERIC;
     }
 
-    text_style_t **pp_styles = NULL;
-    uni_char_t *p_uchars = NULL;
-    size_t i_uchars = SegmentsToTextAndStyles( p_filter, p_region_in->p_text,
-                                               &p_uchars, &pp_styles );
-    if( i_uchars == 0 )
+    layout_text_block_t text_block = { 0 };
+    text_block.b_balanced = p_region_in->b_balanced_text;
+    text_block.b_grid = p_region_in->b_gridmode;
+    text_block.i_count = SegmentsToTextAndStyles( p_filter, p_region_in->p_text,
+                                                  &text_block.p_uchars, &text_block.pp_styles );
+    if( text_block.i_count == 0 )
         return VLC_EGENERIC;
 
     /* */
@@ -1132,7 +1133,6 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region_out,
     int i_max_face_height;
     line_desc_t *p_lines = NULL;
 
-    uint32_t *pi_k_durations   = NULL;
     unsigned i_max_width = p_filter->fmt_out.video.i_visible_width;
     if( p_region_in->i_max_width > 0 && (unsigned) p_region_in->i_max_width < i_max_width )
         i_max_width = p_region_in->i_max_width;
@@ -1152,14 +1152,13 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region_out,
     if( (unsigned)i_margin * 2 >= i_max_width || (unsigned)i_margin * 2 >= i_max_height )
         i_margin = 0;
 
-    rv = LayoutText( p_filter,
-                     p_uchars, pp_styles, pi_k_durations, i_uchars,
-                     p_region_in->b_gridmode, p_region_in->b_balanced_text,
-                     i_max_width, i_max_height, &p_lines, &bbox, &i_max_face_height );
+    text_block.i_max_width = i_max_width;
+    text_block.i_max_height = i_max_height;
+    rv = LayoutTextBlock( p_filter, &text_block, &p_lines, &bbox, &i_max_face_height );
 
     /* Don't attempt to render text that couldn't be layed out
      * properly. */
-    if( !rv && i_uchars > 0 && bbox.xMin < bbox.xMax && bbox.yMin < bbox.yMax )
+    if( !rv && text_block.i_count > 0 && bbox.xMin < bbox.xMax && bbox.yMin < bbox.yMax )
     {
         const vlc_fourcc_t p_chroma_list_yuvp[] = { VLC_CODEC_YUVP, 0 };
         const vlc_fourcc_t p_chroma_list_rgba[] = { VLC_CODEC_RGBA, 0 };
@@ -1275,15 +1274,15 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region_out,
         /* With karaoke, we're going to have to render the text a number
          * of times to show the progress marker on the text.
          */
-        if( pi_k_durations )
+        if( text_block.pi_k_durations )
             var_SetBool( p_filter, "text-rerender", true );
     }
 
     FreeLines( p_lines );
 
-    free( p_uchars );
-    FreeStylesArray( pp_styles, i_uchars );
-    free( pi_k_durations );
+    free( text_block.p_uchars );
+    FreeStylesArray( text_block.pp_styles, text_block.i_count );
+    free( text_block.pi_k_durations );
 
     return rv;
 }
diff --git a/modules/text_renderer/freetype/text_layout.c b/modules/text_renderer/freetype/text_layout.c
index 9d8a4fceab..9c135741a9 100644
--- a/modules/text_renderer/freetype/text_layout.c
+++ b/modules/text_renderer/freetype/text_layout.c
@@ -1531,12 +1531,10 @@ error:
     return NULL;
 }
 
-int LayoutText( filter_t *p_filter,
-                const uni_char_t *p_uchars, text_style_t **pp_styles,
-                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 )
+int LayoutTextBlock( filter_t *p_filter,
+                     const layout_text_block_t *p_textblock,
+                     line_desc_t **pp_lines, FT_BBox *p_bbox,
+                     int *pi_max_face_height )
 {
     line_desc_t *p_first_line = 0;
     line_desc_t **pp_line = &p_first_line;
@@ -1545,9 +1543,9 @@ int LayoutText( filter_t *p_filter,
     unsigned i_max_advance_x = 0;
     int i_max_face_height = 0;
 
-    for( int i = 0; i <= i_len; ++i )
+    for( int i = 0; i <= p_textblock->i_count; ++i )
     {
-        if( i == i_len || p_uchars[ i ] == '\n' )
+        if( i == p_textblock->i_count || p_textblock->p_uchars[ i ] == '\n' )
         {
             if( i_paragraph_start == i )
             {
@@ -1558,10 +1556,10 @@ int LayoutText( filter_t *p_filter,
             paragraph_t *p_paragraph =
                     BuildParagraph( p_filter,
                                     i - i_paragraph_start,
-                                    &p_uchars[i_paragraph_start],
-                                    &pp_styles[i_paragraph_start],
-                                    pi_k_dates ?
-                                    &pi_k_dates[i_paragraph_start] : NULL,
+                                    &p_textblock->p_uchars[i_paragraph_start],
+                                    &p_textblock->pp_styles[i_paragraph_start],
+                                    p_textblock->pi_k_durations ?
+                                    &p_textblock->pi_k_durations[i_paragraph_start] : NULL,
                                     20, &i_max_advance_x );
             if( !p_paragraph )
             {
@@ -1570,8 +1568,9 @@ int LayoutText( filter_t *p_filter,
             }
 
             if( LayoutParagraph( p_filter, p_paragraph,
-                                 i_max_width, i_max_advance_x, pp_line,
-                                 b_grid, b_balance ) )
+                                 p_textblock->i_max_width,
+                                 i_max_advance_x, pp_line,
+                                 p_textblock->b_grid, p_textblock->b_balanced ) )
             {
                 FreeParagraph( p_paragraph );
                 if( p_first_line ) FreeLines( p_first_line );
@@ -1584,9 +1583,9 @@ int LayoutText( filter_t *p_filter,
             {
                 /* only cut at max i_max_height + 1 line due to
                  * approximate font sizing vs region size */
-                if( i_max_height > 0 && i_total_height > i_max_height )
+                if( p_textblock->i_max_height > 0 && i_total_height > p_textblock->i_max_height )
                 {
-                    i_total_height = i_max_height + 1;
+                    i_total_height = p_textblock->i_max_height + 1;
                     line_desc_t *p_todelete = *pp_line;
                     while( p_todelete ) /* Drop extra lines */
                     {
@@ -1595,7 +1594,7 @@ int LayoutText( filter_t *p_filter,
                         p_todelete = p_next;
                     }
                     *pp_line = NULL;
-                    i = i_len + 1; /* force no more paragraphs */
+                    i = p_textblock->i_count + 1; /* force no more paragraphs */
                     break; /* ! no p_next ! */
                 }
                 else if( (*pp_line)->i_height > i_max_face_height )
diff --git a/modules/text_renderer/freetype/text_layout.h b/modules/text_renderer/freetype/text_layout.h
index cd5f0499d8..a1794ce7d9 100644
--- a/modules/text_renderer/freetype/text_layout.h
+++ b/modules/text_renderer/freetype/text_layout.h
@@ -64,23 +64,30 @@ void FreeLines( line_desc_t *p_lines );
 line_desc_t *NewLine( int i_count );
 
 /**
+ * \struct layout_text_block_t
+ * \brief LayoutText parameters
+ */
+typedef struct
+{
+    uni_char_t *p_uchars;       /*!< array of size \p i_count character codepoints */
+    text_style_t **pp_styles;   /*!< array of size \p i_count character styles */
+    uint32_t *pi_k_durations;   /*!< array of size \p i_count karaoke timestamps */
+    size_t i_count;             /*!< length of the arrays */
+
+    bool b_balanced;            /*!< true for grid-mode text */
+    bool b_grid;                /*!< true for balanced wrapped lines */
+    unsigned i_max_width;       /*!< maximum available width to layout text */
+    unsigned i_max_height;      /*!< maximum available height to layout text */
+} layout_text_block_t;
+
+/**
  * Layout the text with shaping, bidirectional support, and font fallback if available.
  *
  * \param p_filter the FreeType module object [IN]
- * \param p_uchars array of size \p i_len containing character codepoints [IN]
- * \param pp_styles array of size \p i_len containing character styles [IN]
- * \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 p_textblock layout_text_block_t describing text to layout [IN]
  * \param pp_lines the list of line_desc_t's with rendered glyphs [OUT]
  * \param p_bbox the bounding box of all the lines [OUT]
  * \param pi_max_face_height maximum line height [OUT]
  */
-int LayoutText( filter_t *p_filter,
-                const uni_char_t *p_uchars, text_style_t **pp_styles,
-                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 );
+int LayoutTextBlock( filter_t *p_filter, const layout_text_block_t *p_textblock,
+                     line_desc_t **pp_lines, FT_BBox *p_bbox, int *pi_max_face_height );



More information about the vlc-commits mailing list