/*****************************************************************************
* freetype.c : Put text on the video, using freetype2
*****************************************************************************
- * Copyright (C) 2002 - 2012 the VideoLAN team
+ * Copyright (C) 2002 - 2012 VLC authors and VideoLAN
* $Id$
*
* Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
* Jean-Baptiste Kempf <jb@videolan.org>
* Felix Paul Kühne <fkuehne@videolan.org>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
+ * You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
/* Default fonts */
#ifdef __APPLE__
-# define DEFAULT_FONT_FILE "/Library/Fonts/Arial Unicode.ttf"
-# define DEFAULT_FAMILY "Arial Unicode MS"
+# define SYSTEM_DEFAULT_FONT_FILE "/Library/Fonts/Arial Unicode.ttf"
+# define SYSTEM_DEFAULT_FAMILY "Arial Unicode MS"
+# define SYSTEM_DEFAULT_MONOSPACE_FONT_FILE "/System/Library/Fonts/Monaco.dfont"
+# define SYSTEM_DEFAULT_MONOSPACE_FAMILY "Monaco"
#elif defined( WIN32 )
-# define DEFAULT_FONT_FILE "arial.ttf" /* Default path font found at run-time */
-# define DEFAULT_FAMILY "Arial"
+# define SYSTEM_DEFAULT_FONT_FILE "arial.ttf" /* Default path font found at run-time */
+# define SYSTEM_DEFAULT_FAMILY "Arial"
+# define SYSTEM_DEFAULT_MONOSPACE_FONT_FILE "cour.ttf"
+# define SYSTEM_DEFAULT_MONOSPACE_FAMILY "Courier New"
#elif defined( __OS2__ )
-# define DEFAULT_FONT_FILE "/psfonts/tnrwt_k.ttf"
-# define DEFAULT_FAMILY "Times New Roman WT K"
-#elif defined( HAVE_MAEMO )
-# define DEFAULT_FONT_FILE "/usr/share/fonts/nokia/nosnb.ttf"
-# define DEFAULT_FAMILY "Nokia Sans Bold"
+# define SYSTEM_DEFAULT_FONT_FILE "/psfonts/tnrwt_k.ttf"
+# define SYSTEM_DEFAULT_FAMILY "Times New Roman WT K"
+# define SYSTEM_DEFAULT_MONOSPACE_FONT_FILE "/psfonts/mtsansdk.ttf"
+# define SYSTEM_DEFAULT_MONOSPACE_FAMILY "Monotype Sans Duospace WT K"
#elif defined( __ANDROID__ )
-# define DEFAULT_FONT_FILE "/system/fonts/DroidSans-Bold.ttf"
-# define DEFAULT_FAMILY "Droid Sans Bold"
+# define SYSTEM_DEFAULT_FONT_FILE "/system/fonts/DroidSans-Bold.ttf"
+# define SYSTEM_DEFAULT_FAMILY "Droid Sans Bold"
+# define SYSTEM_DEFAULT_MONOSPACE_FONT_FILE "/system/fonts/DroidSansMono.ttf"
+# define SYSTEM_DEFAULT_MONOSPACE_FAMILY "Droid Sans Mono"
#else
-# define DEFAULT_FONT_FILE "/usr/share/fonts/truetype/freefont/FreeSerifBold.ttf"
-# define DEFAULT_FAMILY "Serif Bold"
+# define SYSTEM_DEFAULT_FONT_FILE "/usr/share/fonts/truetype/freefont/FreeSerifBold.ttf"
+# define SYSTEM_DEFAULT_FAMILY "Serif Bold"
+# define SYSTEM_DEFAULT_MONOSPACE_FONT_FILE "/usr/share/fonts/truetype/freefont/FreeMono.ttf"
+# define SYSTEM_DEFAULT_MONOSPACE_FAMILY "Monospace"
+#endif
+
+#ifndef DEFAULT_FONT_FILE
+#define DEFAULT_FONT_FILE SYSTEM_DEFAULT_FONT_FILE
+#endif
+
+#ifndef DEFAULT_FAMILY
+#define DEFAULT_FAMILY SYSTEM_DEFAULT_FAMILY
+#endif
+
+#ifndef DEFAULT_MONOSPACE_FONT_FILE
+#define DEFAULT_MONOSPACE_FONT_FILE SYSTEM_DEFAULT_MONOSPACE_FONT_FILE
+#endif
+
+#ifndef DEFAULT_MONOSPACE_FAMILY
+#define DEFAULT_MONOSPACE_FAMILY SYSTEM_DEFAULT_MONOSPACE_FAMILY
#endif
/* Freetype */
*****************************************************************************/
static int Create ( vlc_object_t * );
static void Destroy( vlc_object_t * );
+static int OptionCallback( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void *);
#define FONT_TEXT N_("Font")
+#define MONOSPACE_FONT_TEXT N_("Monospace Font")
#define FAMILY_LONGTEXT N_("Font family for the font you want to use")
#define FONT_LONGTEXT N_("Font file for the font you want to use")
#ifdef HAVE_STYLES
add_font( "freetype-font", DEFAULT_FAMILY, FONT_TEXT, FAMILY_LONGTEXT, false )
+ add_font( "freetype-monofont", DEFAULT_MONOSPACE_FAMILY, MONOSPACE_FONT_TEXT, FAMILY_LONGTEXT, false )
#else
add_loadfile( "freetype-font", DEFAULT_FONT_FILE, FONT_TEXT, FONT_LONGTEXT, false )
+ add_loadfile( "freetype-monofont", DEFAULT_MONOSPACE_FONT_FILE, MONOSPACE_FONT_TEXT, FONT_LONGTEXT, false )
#endif
add_integer( "freetype-fontsize", 0, FONTSIZE_TEXT,
line_desc_t *p_next;
int i_width;
+ int i_height;
int i_base_line;
int i_character_count;
line_character_t *p_character;
int i_default_font_size;
int i_display_height;
char* psz_fontfamily;
+ char* psz_monofontfamily;
xml_reader_t *p_xml;
#ifdef WIN32
char* psz_win_fonts_path;
input_attachment_t **pp_font_attachments;
int i_font_attachments;
+
+ vlc_mutex_t lock;
};
/* */
filter_sys_t *p_sys = p_filter->p_sys;
int i_size = 0;
+ vlc_mutex_lock( &p_filter->p_sys->lock );
if( p_sys->i_default_font_size )
{
i_size = p_sys->i_default_font_size;
+ vlc_mutex_unlock( &p_filter->p_sys->lock );
}
else
{
+ vlc_mutex_unlock( &p_filter->p_sys->lock );
int i_ratio = var_GetInteger( p_filter, "freetype-rel-fontsize" );
if( i_ratio > 0 )
{
FcPattern *pat, *p_pat;
FcChar8* val_s;
FcBool val_b;
+ char *ret = NULL;
/* Create a pattern and fills it */
pat = FcPatternCreate();
"the requested one: '%s' != '%s'\n",
(const char*)val_s, family ); */
- if( FcResultMatch != FcPatternGetString( p_pat, FC_FILE, 0, &val_s ) )
- {
- FcPatternDestroy( p_pat );
- return NULL;
- }
+ if( FcResultMatch == FcPatternGetString( p_pat, FC_FILE, 0, &val_s ) )
+ ret = strdup( (const char*)val_s );
FcPatternDestroy( p_pat );
- return strdup( (const char*)val_s );
+ return ret;
}
#endif
#ifdef WIN32
-#define FONT_DIR_NT "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"
+#define FONT_DIR_NT _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts")
-static int GetFileFontByName( const char *font_name, char **psz_filename )
+static int GetFileFontByName( LPCTSTR font_name, char **psz_filename )
{
HKEY hKey;
- wchar_t vbuffer[MAX_PATH];
- wchar_t dbuffer[256];
+ TCHAR vbuffer[MAX_PATH];
+ TCHAR dbuffer[256];
if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, FONT_DIR_NT, 0, KEY_READ, &hKey)
!= ERROR_SUCCESS )
return 1;
- MultiByteToWideChar( CP_ACP, 0, font_name, -1, dbuffer, 256 );
- char *font_name_temp = FromWide( dbuffer );
+ char *font_name_temp = FromT( font_name );
size_t fontname_len = strlen( font_name_temp );
for( int index = 0;; index++ )
DWORD vbuflen = MAX_PATH - 1;
DWORD dbuflen = 255;
- LONG i_result = RegEnumValueW( hKey, index, vbuffer, &vbuflen,
- NULL, NULL, (LPBYTE)dbuffer, &dbuflen);
+ LONG i_result = RegEnumValue( hKey, index, vbuffer, &vbuflen,
+ NULL, NULL, (LPBYTE)dbuffer, &dbuflen);
if( i_result != ERROR_SUCCESS )
{
RegCloseKey( hKey );
return i_result;
}
- char *psz_value = FromWide( vbuffer );
+ char *psz_value = FromT( vbuffer );
char *s = strchr( psz_value,'(' );
if( s != NULL && s != psz_value ) s[-1] = '\0';
free( psz_value );
}
- *psz_filename = FromWide( dbuffer );
+ *psz_filename = FromT( dbuffer );
free( font_name_temp );
RegCloseKey( hKey );
return 0;
if( (type & RASTER_FONTTYPE) ) return 1;
// if( lpelfe->elfScript ) FIXME
- return GetFileFontByName( (const char *)lpelfe->elfFullName, (char **)lParam );
+ return GetFileFontByName( (LPCTSTR)lpelfe->elfFullName, (char **)lParam );
}
static char* Win32_Select( filter_t *p_filter, const char* family,
if( b_bold )
lf.lfWeight = FW_BOLD;
- char facename[32];
- wchar_t* psz_fbuffer = ToWide( family );
- WideCharToMultiByte( CP_ACP, 0, psz_fbuffer, -1, facename, 32, " ", 0 );
- strncpy( (LPSTR)&lf.lfFaceName, facename, 32 );
+ LPTSTR psz_fbuffer = ToT( family );
+ _tcsncpy( (LPTSTR)&lf.lfFaceName, psz_fbuffer, LF_FACESIZE );
free( psz_fbuffer );
/* */
*i_idx = 0;
+ if( psz_fontname == NULL )
+ return NULL;
+
msg_Dbg( p_filter, "looking for %s", psz_fontname );
cf_fontName = CFStringCreateWithCString( kCFAllocatorDefault, psz_fontname, kCFStringEncodingUTF8 );
if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL )
{
- msg_Err( p_filter, "ATS couldn't find either %s nor its family", psz_fontname );
- CFRelease( cf_fontName );
- return NULL;
+ msg_Dbg( p_filter, "ATS couldn't find either %s nor its family, checking PS name", psz_fontname );
+ ats_font_id = ATSFontFindFromPostScriptName( cf_fontName, kATSOptionFlagsDefault );
+
+ if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL )
+ {
+ msg_Err( p_filter, "ATS couldn't find %s (no font name, family or PS name)", psz_fontname );
+ CFRelease( cf_fontName );
+ return NULL;
+ }
}
}
CFRelease( cf_fontName );
}
}
+static inline void RenderBackground( subpicture_region_t *p_region,
+ line_desc_t *p_line_head,
+ FT_BBox *p_bbox,
+ int i_margin,
+ picture_t *p_picture,
+ int i_text_width,
+ void (*ExtractComponents)( uint32_t, uint8_t *, uint8_t *, uint8_t * ),
+ void (*BlendPixel)(picture_t *, int, int, int, int, int, int, int) )
+{
+ for( line_desc_t *p_line = p_line_head; p_line != NULL; p_line = p_line->p_next )
+ {
+ int i_align_left = i_margin;
+ int i_align_top = i_margin;
+ int line_start = 0;
+ int line_end = 0;
+ unsigned line_top = 0;
+ int line_bottom = 0;
+ int max_height = 0;
+
+ if( p_line->i_width < i_text_width )
+ {
+ /* Left offset to take into account alignment */
+ if( (p_region->i_align & 0x3) == SUBPICTURE_ALIGN_RIGHT )
+ i_align_left += ( i_text_width - p_line->i_width );
+ else if( (p_region->i_align & 0x10) == SUBPICTURE_ALIGN_LEAVETEXT)
+ i_align_left = i_margin; /* Keep it the way it is */
+ else if( (p_region->i_align & 0x3) != SUBPICTURE_ALIGN_LEFT )
+ i_align_left += ( i_text_width - p_line->i_width ) / 2;
+ }
+
+ /* Find the tallest character in the line */
+ for( int i = 0; i < p_line->i_character_count; i++ ) {
+ const line_character_t *ch = &p_line->p_character[i];
+ FT_BitmapGlyph p_glyph = ch->p_outline ? ch->p_outline : ch->p_glyph;
+ if (p_glyph->top > max_height)
+ max_height = p_glyph->top;
+ }
+
+ /* Compute the background for the line (identify leading/trailing space) */
+ for( int i = 0; i < p_line->i_character_count; i++ ) {
+ const line_character_t *ch = &p_line->p_character[i];
+ FT_BitmapGlyph p_glyph = ch->p_outline ? ch->p_outline : ch->p_glyph;
+ if (p_glyph && p_glyph->bitmap.rows > 0) {
+ // Found a non-whitespace character
+ line_start = i_align_left + p_glyph->left - p_bbox->xMin;
+ break;
+ }
+ }
+
+ /* Fudge factor to make sure caption background edges are left aligned
+ despite variable font width */
+ if (line_start < 12)
+ line_start = 0;
+
+ /* Find right boundary for bounding box for background */
+ for( int i = p_line->i_character_count; i > 0; i-- ) {
+ const line_character_t *ch = &p_line->p_character[i - 1];
+ FT_BitmapGlyph p_glyph = ch->p_shadow ? ch->p_shadow : ch->p_glyph;
+ if (p_glyph && p_glyph->bitmap.rows > 0) {
+ // Found a non-whitespace character
+ line_end = i_align_left + p_glyph->left - p_bbox->xMin + p_glyph->bitmap.width;
+ break;
+ }
+ }
+
+ /* Setup color for the background */
+ uint8_t i_x, i_y, i_z;
+ ExtractComponents( 0x000000, &i_x, &i_y, &i_z );
+
+ /* Compute the upper boundary for the background */
+ if ((i_align_top + p_line->i_base_line - max_height) < 0)
+ line_top = i_align_top + p_line->i_base_line;
+ else
+ line_top = i_align_top + p_line->i_base_line - max_height;
+
+ /* Compute lower boundary for the background */
+ line_bottom = __MIN(line_top + p_line->i_height, p_region->fmt.i_visible_height);
+
+ /* Render the actual background */
+ for( int dy = line_top; dy < line_bottom; dy++ )
+ {
+ for( int dx = line_start; dx < line_end; dx++ )
+ BlendPixel( p_picture, dx, dy, 0xff, i_x, i_y, i_z, 0xff );
+ }
+ }
+}
+
static inline int RenderAXYZ( filter_t *p_filter,
subpicture_region_t *p_region,
line_desc_t *p_line_head,
p_region->fmt = fmt;
/* Initialize the picture background */
- uint8_t i_a = p_sys->i_background_opacity;
+ vlc_mutex_lock( &p_sys->lock );
+ uint8_t i_opacity = p_sys->i_background_opacity;
+ uint32_t i_background_color = p_sys->i_background_color;
+ uint8_t i_shadow_opacity = p_sys->i_shadow_opacity;
+ uint8_t i_outline_opacity = p_sys->i_outline_opacity;
+ uint32_t i_shadow_color = p_sys->i_shadow_color;
+ uint32_t i_outline_color = p_sys->i_outline_color;
+ vlc_mutex_unlock( &p_sys->lock );
uint8_t i_x, i_y, i_z;
- ExtractComponents( p_sys->i_background_color, &i_x, &i_y, &i_z );
- FillPicture( p_picture, i_a, i_x, i_y, i_z );
+ if (p_region->b_renderbg) {
+ /* Render the background just under the text */
+ FillPicture( p_picture, 0x00, 0x00, 0x00, 0x00 );
+ RenderBackground(p_region, p_line_head, p_bbox, i_margin, p_picture, i_text_width,
+ ExtractComponents, BlendPixel);
+ } else {
+ /* Render background under entire subpicture block */
+ ExtractComponents( i_background_color, &i_x, &i_y, &i_z );
+ FillPicture( p_picture, i_opacity, i_x, i_y, i_z );
+ }
/* Render shadow then outline and then normal glyphs */
for( int g = 0; g < 3; g++ )
/* Left offset to take into account alignment */
if( (p_region->i_align & 0x3) == SUBPICTURE_ALIGN_RIGHT )
i_align_left += ( i_text_width - p_line->i_width );
+ else if( (p_region->i_align & 0x10) == SUBPICTURE_ALIGN_LEAVETEXT)
+ i_align_left = i_margin; /* Keep it the way it is */
else if( (p_region->i_align & 0x3) != SUBPICTURE_ALIGN_LEFT )
i_align_left += ( i_text_width - p_line->i_width ) / 2;
}
if( !p_glyph )
continue;
- i_a = (ch->i_color >> 24) & 0xff;
+ i_opacity = (ch->i_color >> 24) & 0xff;
uint32_t i_color;
switch (g) {
case 0:
- i_a = i_a * p_sys->i_shadow_opacity / 255;
- i_color = p_sys->i_shadow_color;
+ i_opacity = i_opacity * i_shadow_opacity / 255;
+ i_color = i_shadow_color;
break;
case 1:
- i_a = i_a * p_sys->i_outline_opacity / 255;
- i_color = p_sys->i_outline_color;
+ i_opacity = i_opacity * i_outline_opacity / 255;
+ i_color = i_outline_color;
break;
default:
i_color = ch->i_color;
BlendAXYZGlyph( p_picture,
i_glyph_x, i_glyph_y,
- i_a, i_x, i_y, i_z,
+ i_opacity, i_x, i_y, i_z,
p_glyph,
BlendPixel );
if( g == 2 && ch->i_line_thickness > 0 )
BlendAXYZLine( p_picture,
i_glyph_x, i_glyph_y + p_glyph->top,
- i_a, i_x, i_y, i_z,
+ i_opacity, i_x, i_y, i_z,
&ch[0],
i + 1 < p_line->i_character_count ? &ch[1] : NULL,
BlendPixel );
return rv;
}
+static int HandleTT(font_stack_t **p_fonts, const char *p_fontfamily )
+{
+ char *psz_unused_fontname = NULL;
+ uint32_t i_font_color = 0xffffff;
+ uint32_t i_karaoke_bg_color = 0x00ffffff;
+ int i_font_size = 24;
+
+ /* Default all attributes to the top font in the stack -- in case not
+ * all attributes are specified in the sub-font
+ */
+ PeekFont( p_fonts,
+ &psz_unused_fontname,
+ &i_font_size,
+ &i_font_color,
+ &i_karaoke_bg_color );
+
+ /* Keep all the parent's font attributes, but change to a monospace font */
+ return PushFont( p_fonts,
+ p_fontfamily,
+ i_font_size,
+ i_font_color,
+ i_karaoke_bg_color );
+}
+
/* Turn any multiple-whitespaces into single spaces */
static void HandleWhiteSpace( char *psz_node )
{
int i_style_flags )
{
char *psz_fontname = NULL;
+ vlc_mutex_lock(&p_sys->lock);
uint32_t i_font_color = p_sys->i_font_color & 0x00ffffff;
- uint32_t i_karaoke_bg_color = i_font_color;
int i_font_size = p_sys->i_font_size;
+ vlc_mutex_unlock(&p_sys->lock);
+ uint32_t i_karaoke_bg_color = i_font_color;
if( PeekFont( p_fonts, &psz_fontname, &i_font_size,
&i_font_color, &i_karaoke_bg_color ) )
if( p_font_style )
{
+ /* If the font is not specified in the style, assume the system font */
+ if(!p_font_style->psz_fontname)
+ p_font_style->psz_fontname = strdup(p_sys->psz_fontfamily);
+
rv = PushFont( &p_fonts,
p_font_style->psz_fontname,
p_font_style->i_font_size > 0 ? p_font_style->i_font_size
}
else
{
+ vlc_mutex_lock(&p_sys->lock);
+ uint32_t i_font_size = p_sys->i_font_size;
+ uint32_t i_font_color = p_sys->i_font_color;
+ uint32_t i_font_opacity = p_sys->i_font_opacity;
+ vlc_mutex_unlock(&p_sys->lock);
rv = PushFont( &p_fonts,
p_sys->psz_fontfamily,
- p_sys->i_font_size,
- (p_sys->i_font_color & 0xffffff) |
- ((p_sys->i_font_opacity & 0xff) << 24),
+ i_font_size,
+ (i_font_color & 0xffffff) |
+ ((i_font_opacity & 0xff) << 24),
0x00ffffff );
}
if( p_sys->b_font_bold )
case XML_READER_ENDELEM:
if( !strcasecmp( "font", node ) )
PopFont( &p_fonts );
+ else if( !strcasecmp( "tt", node ) )
+ PopFont( &p_fonts );
else if( !strcasecmp( "b", node ) )
i_style_flags &= ~STYLE_BOLD;
else if( !strcasecmp( "i", node ) )
case XML_READER_STARTELEM:
if( !strcasecmp( "font", node ) )
HandleFontAttributes( p_xml_reader, &p_fonts );
+ else if( !strcasecmp( "tt", node ) )
+ HandleTT( &p_fonts, p_sys->psz_monofontfamily );
else if( !strcasecmp( "b", node ) )
i_style_flags |= STYLE_BOLD;
else if( !strcasecmp( "i", node ) )
{
int i_style_received = ((p_face->style_flags & FT_STYLE_FLAG_BOLD) ? STYLE_BOLD : 0) |
((p_face->style_flags & FT_STYLE_FLAG_ITALIC ) ? STYLE_ITALIC : 0);
- if( !strcasecmp( p_face->family_name, p_style->psz_fontname ) &&
- (p_style->i_style_flags & (STYLE_BOLD | STYLE_ITALIC)) == i_style_received )
+ if( p_face->family_name != NULL
+ && !strcasecmp( p_face->family_name, p_style->psz_fontname )
+ && (p_style->i_style_flags & (STYLE_BOLD | STYLE_ITALIC))
+ == i_style_received )
return p_face;
FT_Done_Face( p_face );
msg_Err( p_filter, "Failed to set font size to %d", p_current_style->i_font_size );
if( p_sys->p_stroker )
{
- int i_radius = (p_current_style->i_font_size << 6) * p_sys->f_outline_thickness;
+ vlc_mutex_lock( &p_sys->lock );
+ double f_outline_thickness = p_sys->f_outline_thickness;
+ vlc_mutex_unlock( &p_sys->lock );
+ int i_radius = (p_current_style->i_font_size << 6) * f_outline_thickness;
FT_Stroker_Set( p_sys->p_stroker,
i_radius,
FT_STROKER_LINECAP_ROUND,
{
p_line->i_width = __MAX(line_bbox.xMax - line_bbox.xMin, 0);
p_line->i_base_line = i_base_line;
+ p_line->i_height = __MAX(i_face_height, i_face_height_previous);
if( i_ul_thickness > 0 )
{
for( int i = 0; i < p_line->i_character_count; i++ )
STYLE_ITALIC |
STYLE_UNDERLINE |
STYLE_STRIKEOUT) );
- else
+ else {
+ vlc_mutex_lock( &p_sys->lock );
+ uint8_t i_font_size = p_sys->i_font_size;
+ uint32_t i_font_color = p_sys->i_font_color;
+ uint8_t i_font_opacity = p_sys->i_font_opacity;
+ vlc_mutex_unlock( &p_sys->lock );
p_style = CreateStyle( p_sys->psz_fontfamily,
- p_sys->i_font_size,
- (p_sys->i_font_color & 0xffffff) |
- ((p_sys->i_font_opacity & 0xff) << 24),
+ i_font_size,
+ (i_font_color & 0xffffff) |
+ ((i_font_opacity & 0xff) << 24),
0x00ffffff, 0);
+ }
if( p_sys->b_font_bold )
p_style->i_style_flags |= STYLE_BOLD;
else if( !p_chroma_list || *p_chroma_list == 0 )
p_chroma_list = p_chroma_list_rgba;
- const int i_margin = p_sys->i_background_opacity > 0 ? i_max_face_height / 4 : 0;
+ vlc_mutex_lock( &p_sys->lock );
+ uint8_t i_background_opacity = p_sys->i_background_opacity;
+ vlc_mutex_unlock( &p_sys->lock );
+
+ const int i_margin = i_background_opacity > 0 ? i_max_face_height / 4 : 0;
for( const vlc_fourcc_t *p_chroma = p_chroma_list; *p_chroma != 0; p_chroma++ )
{
rv = VLC_EGENERIC;
filter_sys_t *p_sys;
char *psz_fontfile = NULL;
char *psz_fontfamily = NULL;
- int i_error = 0, fontindex = 0;
+ char *psz_monofontfile = NULL;
+ char *psz_monofontfamily = NULL;
+ int i_error = 0, fontindex = 0, monofontindex = 0;
/* Allocate structure */
p_filter->p_sys = p_sys = malloc( sizeof(*p_sys) );
p_sys->i_font_size = 0;
p_sys->i_display_height = 0;
+ vlc_mutex_init( &p_sys->lock );
+
var_Create( p_filter, "freetype-rel-fontsize",
VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+ var_Create( p_filter, "freetype-background-opacity",
+ VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+ var_Create( p_filter, "freetype-background-color",
+ VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+ var_Create( p_filter, "freetype-outline-thickness",
+ VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+ var_Create( p_filter, "freetype-color",
+ VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
psz_fontfamily = var_InheritString( p_filter, "freetype-font" );
+ psz_monofontfamily = var_InheritString( p_filter, "freetype-monofont" );
p_sys->i_default_font_size = var_InheritInteger( p_filter, "freetype-fontsize" );
p_sys->i_font_opacity = var_InheritInteger( p_filter,"freetype-opacity" );
p_sys->i_font_opacity = VLC_CLIP( p_sys->i_font_opacity, 0, 255 );
/* */
psz_fontfile = FontConfig_Select( NULL, psz_fontfamily, false, false,
p_sys->i_default_font_size, &fontindex );
+ psz_monofontfile = FontConfig_Select( NULL, psz_monofontfamily, false,
+ false, p_sys->i_default_font_size,
+ &monofontindex );
#elif defined(__APPLE__)
psz_fontfile = MacLegacy_Select( p_filter, psz_fontfamily, false, false, 0, &fontindex );
#elif defined(WIN32)
/* If nothing is found, use the default family */
if( !psz_fontfile )
psz_fontfile = strdup( psz_fontfamily );
+ if( !psz_monofontfile )
+ psz_monofontfile = strdup( psz_monofontfamily );
#else /* !HAVE_STYLES */
/* Use the default file */
psz_fontfile = psz_fontfamily;
+ psz_monofontfile = psz_monofontfamily;
#endif
+ p_sys->psz_monofontfamily = psz_monofontfamily;
/* */
i_error = FT_Init_FreeType( &p_sys->p_library );
LoadFontsFromAttachments( p_filter );
+ var_AddCallback(p_this, "freetype-rel-fontsize", OptionCallback, p_this);
+ var_AddCallback(p_this, "freetype-background-opacity", OptionCallback, p_this);
+ var_AddCallback(p_this, "freetype-background-color", OptionCallback, p_this);
+ var_AddCallback(p_this, "freetype-outline-thickness", OptionCallback, p_this);
+ var_AddCallback(p_this, "freetype-color", OptionCallback, p_this);
+
#ifdef HAVE_STYLES
free( psz_fontfile );
+ free( psz_monofontfile );
#endif
return VLC_SUCCESS;
if( p_sys->p_library ) FT_Done_FreeType( p_sys->p_library );
#ifdef HAVE_STYLES
free( psz_fontfile );
+ free( psz_monofontfile );
#endif
free( psz_fontfamily );
+ free( psz_monofontfamily );
free( p_sys );
return VLC_EGENERIC;
}
filter_t *p_filter = (filter_t *)p_this;
filter_sys_t *p_sys = p_filter->p_sys;
+ var_DelCallback(p_this, "freetype-rel-fontsize", OptionCallback, p_this);
+ var_DelCallback(p_this, "freetype-background-opacity", OptionCallback, p_this);
+ var_DelCallback(p_this, "freetype-background-color", OptionCallback, p_this);
+ var_DelCallback(p_this, "freetype-outline-thickness", OptionCallback, p_this);
+ var_DelCallback(p_this, "freetype-color", OptionCallback, p_this);
+
if( p_sys->pp_font_attachments )
{
for( int k = 0; k < p_sys->i_font_attachments; k++ )
if( p_sys->p_xml ) xml_ReaderDelete( p_sys->p_xml );
free( p_sys->psz_fontfamily );
+#ifdef WIN32
+ free( p_sys->psz_win_fonts_path );
+#endif
+
/* FcFini asserts calling the subfunction FcCacheFini()
* even if no other library functions have been made since FcInit(),
* so don't call it. */
FT_Stroker_Done( p_sys->p_stroker );
FT_Done_Face( p_sys->p_face );
FT_Done_FreeType( p_sys->p_library );
+ vlc_mutex_destroy( &p_sys->lock );
free( p_sys );
}
+static int OptionCallback( vlc_object_t *p_this, char const *psz_var,
+ vlc_value_t oldval, vlc_value_t newval, void *p_data)
+{
+ VLC_UNUSED(oldval);
+ VLC_UNUSED(p_data);
+
+ filter_t *p_filter = (filter_t *)p_this;
+ filter_sys_t *p_sys = p_filter->p_sys;
+
+ vlc_mutex_lock( &p_sys->lock );
+ if( !strcmp(psz_var, "freetype-rel-fontsize") )
+ msg_Dbg( p_this, "changed relative font size to %"PRId64, newval.i_int);
+ else if( !strcmp(psz_var, "freetype-color") ) {
+ p_sys->i_font_color = newval.i_int;
+ p_sys->i_font_color = VLC_CLIP( p_sys->i_font_color, 0, 0xFFFFFF );
+ } else if( !strcmp(psz_var, "freetype-background-opacity") ) {
+ p_sys->i_background_opacity = newval.i_int;
+ msg_Dbg( p_filter, "changed background opacity to %"PRId64, newval.i_int);
+ } else if( !strcmp(psz_var, "freetype-outline-thickness") ) {
+ p_sys->f_outline_thickness = newval.i_int / 100.;
+ p_sys->f_outline_thickness = VLC_CLIP( p_sys->f_outline_thickness, 0.0, 0.5 );
+ msg_Dbg( p_filter, "changed outline thickness to %"PRId64, newval.i_int);
+ } else if( !strcmp(psz_var, "freetype-background-color") ) {
+ p_sys->i_background_color = newval.i_int;
+ p_sys->i_background_color = VLC_CLIP( p_sys->i_background_color, 0, 0xFFFFFF );
+ msg_Dbg( p_filter, "changed background color to %"PRId64, newval.i_int);
+ }
+ vlc_mutex_unlock( &p_sys->lock );
+
+ return VLC_SUCCESS;
+}