[vlc-commits] Freetype: introduce a dummy font selector

Jean-Baptiste Kempf git at videolan.org
Sun Dec 15 17:37:28 CET 2013


vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Sun Dec 15 17:22:12 2013 +0100| [783fdab819b72b2e1a96bd9d177cb5011fea6e40] | committer: Jean-Baptiste Kempf

Freetype: introduce a dummy font selector

When we don't have a way to select a font by family, use the basic font
(default or the config one)

This reduces the number of HAVE_STYLES usage and avoid a few bugs

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

 modules/text_renderer/freetype.c       |   63 ++++++++------------------------
 modules/text_renderer/platform_fonts.c |   25 +++++++++++++
 modules/text_renderer/platform_fonts.h |    4 ++
 3 files changed, 45 insertions(+), 47 deletions(-)

diff --git a/modules/text_renderer/freetype.c b/modules/text_renderer/freetype.c
index 9409930..5007810 100644
--- a/modules/text_renderer/freetype.c
+++ b/modules/text_renderer/freetype.c
@@ -56,26 +56,22 @@
  #define FT_MulFix(v, s) (((v)*(s))>>16)
 #endif
 
-/* apple stuff */
-#ifdef __APPLE__
-#include <TargetConditionals.h>
-#if !TARGET_OS_IPHONE
-#include <Carbon/Carbon.h>
-#endif
-#include <sys/param.h>                         /* for MAXPATHLEN */
-#undef HAVE_FONTCONFIG
-#define HAVE_STYLES
-#endif
-
 /* RTL */
 #if defined(HAVE_FRIBIDI)
 # include <fribidi/fribidi.h>
 #endif
 
-/* Win32 GDI */
-#ifdef _WIN32
+/* apple stuff */
+#ifdef __APPLE__
+# include <TargetConditionals.h>
+# undef HAVE_FONTCONFIG
 # define HAVE_STYLES
+#endif
+
+/* Win32 */
+#ifdef _WIN32
 # undef HAVE_FONTCONFIG
+# define HAVE_STYLES
 #endif
 
 /* FontConfig */
@@ -1926,29 +1922,17 @@ static int Create( vlc_object_t *p_this )
 #ifdef HAVE_STYLES
         psz_fontname = strdup( DEFAULT_FAMILY );
 #else
-# ifdef _WIN32
-        /* Get Windows Font folder */
-        char *psz_win_fonts_path = GetWindowsFontPath();
-        if( asprintf( &psz_fontname, "%s"DEFAULT_FONT_FILE, psz_win_fonts_path ) == -1 )
-        {
-            psz_fontname = NULL;
-            goto error;
-        }
-        free(psz_win_fonts_path);
-# else
-        psz_fontname = strdup( DEFAULT_FONT_FILE );
-# endif
-        msg_Err( p_filter,"User specified an empty fontfile, using %s", psz_fontname );
+        psz_fontname = File_Select( DEFAULT_FONT_FILE );
 #endif
     }
 
-
     /* Set the current font file */
     p_sys->style.psz_fontname = psz_fontname;
+    p_sys->style.psz_monofontname = psz_monofontfamily;
 
-#ifdef HAVE_STYLES
 #ifdef HAVE_FONTCONFIG
     p_sys->pf_select = FontConfig_Select;
+    FontConfig_BuildCache( p_filter );
 #elif defined( __APPLE__ )
 #if !TARGET_OS_IPHONE
     p_sys->pf_select = MacLegacy_Select;
@@ -1956,11 +1940,7 @@ static int Create( vlc_object_t *p_this )
 #elif defined( _WIN32 )
     p_sys->pf_select = Win32_Select;
 #else
-# error selection not implemented
-#endif
-
-#ifdef HAVE_FONTCONFIG
-    FontConfig_BuildCache( p_filter );
+    p_sys->pf_select = Dummy_Select;
 #endif
 
     /* */
@@ -1970,20 +1950,13 @@ static int Create( vlc_object_t *p_this )
                                           false, p_sys->i_default_font_size,
                                           &monofontindex );
     msg_Dbg( p_filter, "Using %s as font from file %s", psz_fontname, psz_fontfile );
+    msg_Dbg( p_filter, "Using %s as mono-font from file %s", psz_monofontfamily, psz_monofontfile );
 
     /* If nothing is found, use the default family */
     if( !psz_fontfile )
-        psz_fontfile = strdup( psz_fontname );
+        psz_fontfile = File_Select( psz_fontname );
     if( !psz_monofontfile )
-        psz_monofontfile = strdup( psz_monofontfamily );
-
-#else /* !HAVE_STYLES */
-    /* Use the default file */
-    p_sys->pf_select = NULL;
-    psz_fontfile = psz_fontname;
-    psz_monofontfile = psz_monofontfamily;
-#endif
-    p_sys->style.psz_monofontname = psz_monofontfamily;
+        psz_monofontfile = File_Select( psz_monofontfamily );
 
     if( Init_FT( p_this, psz_fontfile, fontindex, f_outline_thickness ) != VLC_SUCCESS )
         goto error;
@@ -1996,18 +1969,14 @@ static int Create( vlc_object_t *p_this )
 
     LoadFontsFromAttachments( p_filter );
 
-#ifdef HAVE_STYLES
     free( psz_fontfile );
     free( psz_monofontfile );
-#endif
 
     return VLC_SUCCESS;
 
 error:
-#ifdef HAVE_STYLES
     free( psz_fontfile );
     free( psz_monofontfile );
-#endif
     free( psz_fontname );
     free( psz_monofontfamily );
     free( p_sys );
diff --git a/modules/text_renderer/platform_fonts.c b/modules/text_renderer/platform_fonts.c
index b19b511..31ea730 100644
--- a/modules/text_renderer/platform_fonts.c
+++ b/modules/text_renderer/platform_fonts.c
@@ -413,3 +413,28 @@ char* MacLegacy_Select( filter_t *p_filter, const char* psz_fontname,
 #endif
 #endif
 
+char* Dummy_Select( filter_t *p_filter, const char* psz_font,
+                    bool b_bold, bool b_italic, int i_size, int *i_idx )
+{
+    VLC_UNUSED(p_filter);
+    VLC_UNUSED(b_bold);
+    VLC_UNUSED(b_italic);
+    VLC_UNUSED(i_size);
+    VLC_UNUSED(i_idx);
+
+    char *psz_fontname;
+# ifdef _WIN32
+    /* Get Windows Font folder */
+    char *psz_win_fonts_path = GetWindowsFontPath();
+    if( asprintf( &psz_fontname, "%s\\%s", psz_win_fonts_path, psz_font ) == -1 )
+    {
+        psz_fontname = NULL;
+        return NULL;
+    }
+    free(psz_win_fonts_path);
+# else
+    psz_fontname = strdup( psz_font );
+# endif
+
+    return psz_fontname;
+}
diff --git a/modules/text_renderer/platform_fonts.h b/modules/text_renderer/platform_fonts.h
index 602ce5e..287a396 100644
--- a/modules/text_renderer/platform_fonts.h
+++ b/modules/text_renderer/platform_fonts.h
@@ -99,3 +99,7 @@ char* MacLegacy_Select( filter_t *p_filter, const char* psz_fontname,
 #endif
 #endif
 
+char* Dummy_Select( filter_t *p_filter, const char* family,
+                    bool b_bold, bool b_italic, int i_size, int *i_idx );
+
+#define File_Select(a) Dummy_Select(NULL, a, 0, 0, 0, NULL)



More information about the vlc-commits mailing list