[vlc-devel] [PATCH 4/9] freetype: update freetype.c
Salah-Eddin Shaban
salshaaban at gmail.com
Sat Apr 18 19:56:16 CEST 2015
add "Text Direction" option
use LayoutText() in text_layout.c
cache loaded font faces
---
modules/text_renderer/freetype.c | 86 +++++++++++++++++++++++++++++++++++++---
1 file changed, 81 insertions(+), 5 deletions(-)
diff --git a/modules/text_renderer/freetype.c b/modules/text_renderer/freetype.c
index 4668f07..26a75fd 100644
--- a/modules/text_renderer/freetype.c
+++ b/modules/text_renderer/freetype.c
@@ -73,6 +73,8 @@
#include "text_renderer.h"
#include "platform_fonts.h"
+#include "freetype.h"
+#include "text_layout.h"
/*****************************************************************************
* Module descriptor
@@ -118,6 +120,9 @@ static void Destroy( vlc_object_t * );
#define SHADOW_ANGLE_TEXT N_("Shadow angle")
#define SHADOW_DISTANCE_TEXT N_("Shadow distance")
+#define TEXT_DIRECTION_TEXT N_("Text direction")
+#define TEXT_DIRECTION_LONGTEXT N_("Paragraph base direction for the Unicode bi-directional algorithm.")
+
static const int pi_sizes[] = { 20, 18, 16, 12, 6 };
static const char *const ppsz_sizes_text[] = {
@@ -143,6 +148,15 @@ static const char *const ppsz_outline_thickness[] = {
N_("None"), N_("Thin"), N_("Normal"), N_("Thick"),
};
+#ifdef HAVE_FRIBIDI
+static const int pi_text_direction[] = {
+ 0, 1, 2,
+};
+static const char *const ppsz_text_direction[] = {
+ N_("Left to right"), N_("Right to left"), N_("Auto"),
+};
+#endif
+
vlc_module_begin ()
set_shortname( N_("Text renderer"))
set_description( N_("Freetype2 font renderer") )
@@ -219,6 +233,14 @@ vlc_module_begin ()
add_bool( "freetype-yuvp", false, YUVP_TEXT,
YUVP_LONGTEXT, true )
+
+#ifdef HAVE_FRIBIDI
+ add_integer_with_range( "freetype-text-direction", 0, 0, 2, TEXT_DIRECTION_TEXT,
+ TEXT_DIRECTION_LONGTEXT, false )
+ change_integer_list( pi_text_direction, ppsz_text_direction )
+ change_safe()
+#endif
+
set_capability( "text renderer", 100 )
add_shortcut( "text" )
set_callbacks( Create, Destroy )
@@ -871,11 +893,18 @@ static FT_Face LoadEmbeddedFace( filter_sys_t *p_sys, const text_style_t *p_styl
return NULL;
}
-static FT_Face LoadFace( filter_t *p_filter,
- const text_style_t *p_style )
+FT_Face LoadFace( filter_t *p_filter,
+ const text_style_t *p_style )
{
filter_sys_t *p_sys = p_filter->p_sys;
+ faces_cache_t *p_cache = &p_sys->faces_cache;
+ for( int i = 0; i < p_cache->i_faces_count; ++i )
+ if( FaceStyleEquals( &p_cache->p_styles[ i ], p_style )
+ && p_cache->p_styles[ i ].i_font_size == p_style->i_font_size
+ && !( ( p_cache->p_styles[ i ].i_style_flags ^ p_style->i_style_flags ) & STYLE_HALFWIDTH ) )
+ return p_cache->p_faces[ i ];
+
/* Look for a match amongst our attachments first */
FT_Face p_face = LoadEmbeddedFace( p_sys, p_style );
@@ -925,6 +954,38 @@ static FT_Face LoadFace( filter_t *p_filter,
FT_Done_Face( p_face );
return NULL;
}
+
+ if( p_cache->i_faces_count == p_cache->i_cache_size )
+ {
+ FT_Face *p_new_faces =
+ realloc( p_cache->p_faces, p_cache->i_cache_size * 2 * sizeof( *p_cache->p_faces ) );
+ if( !p_new_faces )
+ {
+ FT_Done_Face( p_face );
+ return NULL;
+ }
+
+ p_cache->p_faces = p_new_faces;
+
+ text_style_t *p_new_styles =
+ realloc( p_cache->p_styles, p_cache->i_cache_size * 2 * sizeof( *p_cache->p_styles ) ) ;
+ if( !p_new_styles )
+ {
+ FT_Done_Face( p_face );
+ return NULL;
+ }
+
+ p_cache->p_styles = p_new_styles;
+ p_cache->i_cache_size *= 2;
+ }
+
+ text_style_t *p_face_style = p_cache->p_styles + p_cache->i_faces_count;
+ p_face_style->i_font_size = p_style->i_font_size;
+ p_face_style->i_style_flags = p_style->i_style_flags;
+ p_face_style->psz_fontname = strdup( p_style->psz_fontname );
+ p_cache->p_faces[ p_cache->i_faces_count ] = p_face;
+ ++p_cache->i_faces_count;
+
return p_face;
}
@@ -1079,9 +1140,9 @@ static int RenderCommon( filter_t *p_filter, subpicture_region_t *p_region_out,
if( !rv && i_text_length > 0 )
{
- rv = ProcessLines( p_filter,
- &p_lines, &bbox, &i_max_face_height,
- psz_text, pp_styles, pi_k_durations, i_text_length );
+ rv = LayoutText( p_filter,
+ &p_lines, &bbox, &i_max_face_height,
+ psz_text, pp_styles, pi_k_durations, i_text_length );
}
p_region_out->i_x = p_region_in->i_x;
@@ -1338,6 +1399,12 @@ static int Create( vlc_object_t *p_this )
if( Init_FT( p_this, psz_fontfile, fontindex, f_outline_thickness ) != VLC_SUCCESS )
goto error;
+ int i_faces_size = 20;
+ p_sys->faces_cache.p_faces = malloc( i_faces_size * sizeof( *p_sys->faces_cache.p_faces ) );
+ p_sys->faces_cache.p_styles = malloc( i_faces_size * sizeof( *p_sys->faces_cache.p_styles ) );
+ p_sys->faces_cache.i_cache_size = i_faces_size;
+ p_sys->faces_cache.i_faces_count = 0;
+
p_sys->pp_font_attachments = NULL;
p_sys->i_font_attachments = 0;
@@ -1382,6 +1449,15 @@ static void Destroy( vlc_object_t *p_this )
filter_t *p_filter = (filter_t *)p_this;
filter_sys_t *p_sys = p_filter->p_sys;
+ faces_cache_t *p_cache = &p_sys->faces_cache;
+ for( int i = 0; i < p_cache->i_faces_count; ++i )
+ {
+ FT_Done_Face( p_cache->p_faces[ i ] );
+ free( p_cache->p_styles[ i ].psz_fontname );
+ }
+ free( p_sys->faces_cache.p_faces );
+ free( p_sys->faces_cache.p_styles );
+
if( p_sys->pp_font_attachments )
{
for( int k = 0; k < p_sys->i_font_attachments; k++ )
--
1.9.1
More information about the vlc-devel
mailing list