[vlc-commits] freetype: make paragraph lines equal in width, more or less
Salah-Eddin Shaban
git at videolan.org
Tue May 12 10:30:57 CEST 2015
vlc | branch: master | Salah-Eddin Shaban <salshaaban at gmail.com> | Tue May 12 09:16:03 2015 +0300| [531289a15f259b0b2599d814a4fff5d127ee3ff7] | committer: Jean-Baptiste Kempf
freetype: make paragraph lines equal in width, more or less
Libass does the same, and I think it's a good idea. But their method is IMO overly complicated.
Or else I'm over-simplifying things. But this seems to work very well.
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=531289a15f259b0b2599d814a4fff5d127ee3ff7
---
modules/text_renderer/text_layout.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/modules/text_renderer/text_layout.c b/modules/text_renderer/text_layout.c
index 28e120c..18a195e 100644
--- a/modules/text_renderer/text_layout.c
+++ b/modules/text_renderer/text_layout.c
@@ -1078,7 +1078,7 @@ static int LayoutLine( filter_t *p_filter,
}
static int LayoutParagraph( filter_t *p_filter, paragraph_t *p_paragraph,
- int i_max_width, line_desc_t **pp_lines )
+ int i_max_pixel_width, line_desc_t **pp_lines )
{
if( p_paragraph->i_size <= 0 || p_paragraph->i_runs_count <= 0 )
{
@@ -1090,14 +1090,24 @@ static int LayoutParagraph( filter_t *p_filter, paragraph_t *p_paragraph,
int i_line_start = 0;
FT_Pos i_width = 0;
+ FT_Pos i_max_width = i_max_pixel_width << 6;
+ FT_Pos i_preferred_width = 0;
+ FT_Pos i_total_width = 0;
+ FT_Pos i_last_space_width = 0;
int i_last_space = -1;
line_desc_t *p_first_line = 0;
line_desc_t **pp_line = &p_first_line;
-#ifdef HAVE_FRIBIDI
for( int i = 0; i < p_paragraph->i_size; ++i )
+ {
+#ifdef HAVE_FRIBIDI
p_paragraph->pi_reordered_indices[ i ] = i;
#endif
+ i_total_width += p_paragraph->p_glyph_bitmaps[ i ].i_x_advance;
+ }
+
+ int i_line_count = i_total_width / i_max_width + 1;
+ i_preferred_width = i_total_width / i_line_count;
for( int i = 0; i <= p_paragraph->i_size; ++i )
{
@@ -1141,11 +1151,13 @@ static int LayoutParagraph( filter_t *p_filter, paragraph_t *p_paragraph,
}
i_last_space = i;
+ i_last_space_width = i_width;
}
i_width += p_paragraph->p_glyph_bitmaps[ i ].i_x_advance;
- if( FT_CEIL( i_width ) >= i_max_width )
+ if( i_last_space_width >= i_preferred_width
+ || i_width >= i_max_width )
{
if( i_line_start == i )
{
@@ -1168,6 +1180,7 @@ static int LayoutParagraph( filter_t *p_filter, paragraph_t *p_paragraph,
i_line_start = i_end_offset;
i = i_line_start - 1;
i_width = 0;
+ i_last_space_width = 0;
}
}
More information about the vlc-commits
mailing list