]> git.sesse.net Git - vlc/commitdiff
Freetype: introduce a dummy font selector
authorJean-Baptiste Kempf <jb@videolan.org>
Sun, 15 Dec 2013 16:22:12 +0000 (17:22 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Sun, 15 Dec 2013 16:37:13 +0000 (17:37 +0100)
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

modules/text_renderer/freetype.c
modules/text_renderer/platform_fonts.c
modules/text_renderer/platform_fonts.h

index 9409930158af6b572ffe1676379a01223302020c..5007810c2d1c1775eac0da0ccaa3c3a4ddf8245a 100644 (file)
  #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 );
index b19b511eaacca030662a0730d9fbd615063d86f2..31ea7305375d949a0c308489716a1dda8eb1128d 100644 (file)
@@ -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;
+}
index 602ce5e5134b641100cba4d2d690df7809ccebb3..287a3961de963fcf26f9e68885325e919a0415af 100644 (file)
@@ -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)