0011-libvlc-add-a-basic-API-to-change-freetype-s-color-bo.patch 9.11 KB
Newer Older
1
From 35eacd8c51677d480296572e5bf58f7acaf4a5c5 Mon Sep 17 00:00:00 2001
2 3
From: =?UTF-8?q?Felix=20Paul=20K=C3=BChne?= <felix@feepk.net>
Date: Sun, 17 Dec 2017 18:05:40 +0100
Soomin Lee's avatar
Soomin Lee committed
4
Subject: [PATCH 11/26] libvlc: add a basic API to change freetype's color,
5 6 7
 bold, font and size variables on-the-fly

---
8 9 10 11 12 13
 include/vlc/libvlc_media_player.h         | 26 +++++++++
 lib/libvlc.sym                            |  6 ++
 lib/media_player.c                        |  6 ++
 lib/video.c                               | 69 ++++++++++++++++++++++-
 modules/text_renderer/freetype/freetype.c | 32 +++++++++--
 5 files changed, 134 insertions(+), 5 deletions(-)
14 15

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
16
index c431c235e9..4582688b27 100644
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -1567,6 +1567,32 @@ LIBVLC_API float libvlc_video_get_adjust_float( libvlc_media_player_t *p_mi,
 LIBVLC_API void libvlc_video_set_adjust_float( libvlc_media_player_t *p_mi,
                                                    unsigned option, float value );
 
+enum libvlc_video_textrenderer_option_t {
+    libvlc_textrender_font = 0,
+    libvlc_textrender_fontsize,
+    libvlc_textrender_fontcolor,
+    libvlc_textrender_fontforcebold,
+};
+
+LIBVLC_API bool libvlc_video_get_textrenderer_bool( libvlc_media_player_t *p_mi,
+                                                    unsigned option );
+
+LIBVLC_API void libvlc_video_set_textrenderer_bool( libvlc_media_player_t *p_mi,
+                                                    unsigned option, bool value );
+
+LIBVLC_API int libvlc_video_get_textrenderer_int( libvlc_media_player_t *p_mi,
+                                                  unsigned option );
+
+LIBVLC_API void libvlc_video_set_textrenderer_int( libvlc_media_player_t *p_mi,
+                                                   unsigned option, int value );
+
+LIBVLC_API char *libvlc_video_get_textrenderer_string( libvlc_media_player_t *p_mi,
+                                                       unsigned option );
+
+LIBVLC_API void libvlc_video_set_textrenderer_string( libvlc_media_player_t *p_mi,
+                                                      unsigned option,
+                                                      const char *psz_text );
+
 /** @} video */
 
 /** \defgroup libvlc_audio LibVLC audio controls
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
53
index 8ae5da8d0f..55f6400f69 100644
54 55
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
56
@@ -262,6 +262,9 @@ libvlc_video_get_spu_count
57 58 59 60 61 62 63 64 65
 libvlc_video_get_spu_delay
 libvlc_video_get_spu_description
 libvlc_video_get_teletext
+libvlc_video_get_textrenderer_bool
+libvlc_video_get_textrenderer_int
+libvlc_video_get_textrenderer_string
 libvlc_video_get_title_description
 libvlc_video_get_track
 libvlc_video_get_track_count
66
@@ -286,6 +289,9 @@ libvlc_video_set_spu
67 68 69 70 71 72 73 74 75 76
 libvlc_video_set_spu_delay
 libvlc_video_set_subtitle_file
 libvlc_video_set_teletext
+libvlc_video_set_textrenderer_bool
+libvlc_video_set_textrenderer_int
+libvlc_video_set_textrenderer_string
 libvlc_video_set_track
 libvlc_video_take_snapshot
 libvlc_video_new_viewpoint
diff --git a/lib/media_player.c b/lib/media_player.c
77
index fde008aaeb..7b4050164f 100644
78 79
--- a/lib/media_player.c
+++ b/lib/media_player.c
80
@@ -695,6 +695,12 @@ libvlc_media_player_new( libvlc_instance_t *instance )
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
     var_Create (mp, "saturation", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
     var_Create (mp, "gamma", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
 
+    /* SPU */
+    var_Create (mp, "freetype-font", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
+    var_Create (mp, "freetype-rel-fontsize", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+    var_Create (mp, "freetype-color", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+    var_Create (mp, "freetype-bold", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
+
      /* Audio */
     var_Create (mp, "aout", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
     var_Create (mp, "audio-device", VLC_VAR_STRING);
diff --git a/lib/video.c b/lib/video.c
index acbba3a30f..035cc0ebf1 100644
--- a/lib/video.c
+++ b/lib/video.c
@@ -812,7 +812,7 @@ static bool find_sub_source_by_name( libvlc_media_player_t *p_mi, const char *re
 }
 
 typedef const struct {
-    const char name[20];
+    const char name[25];
     unsigned type;
 } opt_t;
 
@@ -839,6 +839,7 @@ set_value( libvlc_media_player_t *p_mi, const char *restrict name,
         }
         case VLC_VAR_INTEGER:
         case VLC_VAR_FLOAT:
+        case VLC_VAR_BOOL:
         case VLC_VAR_STRING:
             if( i_expected_type != opt->type )
             {
@@ -1086,3 +1087,69 @@ float libvlc_video_get_adjust_float( libvlc_media_player_t *p_mi,
 {
     return get_float( p_mi, "adjust", adjust_option_bynumber(option) );
 }
+
+/* SPU HACK */
+
+static const opt_t *
+textrenderer_option_bynumber( unsigned option )
+{
+    static const opt_t optlist[] =
+    {
+    { "freetype-font",            VLC_VAR_STRING },
+    { "freetype-rel-fontsize",    VLC_VAR_INTEGER },
+    { "freetype-color",           VLC_VAR_INTEGER },
+    { "freetype-bold",            VLC_VAR_BOOL },
+    };
+    enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
+
+    const opt_t *r = option < num_opts ? optlist+option : NULL;
+    if( !r )
+        libvlc_printerr( "Unknown freetype option" );
+    return r;
+}
+
+/* basic text renderer support */
+
+void libvlc_video_set_textrenderer_bool( libvlc_media_player_t *p_mi,
+                                        unsigned option, bool value )
+{
+    set_value( p_mi, "freetype", textrenderer_option_bynumber(option), VLC_VAR_BOOL,
+               &(vlc_value_t) { .b_bool = value }, false );
+}
+
+
+bool libvlc_video_get_textrenderer_bool( libvlc_media_player_t *p_mi,
+                                         unsigned option )
+{
+    return get_int( p_mi, "freetype", textrenderer_option_bynumber(option) );
+}
+
+
+void libvlc_video_set_textrenderer_int( libvlc_media_player_t *p_mi,
+                                       unsigned option, int value )
+{
+    set_value( p_mi, "freetype", textrenderer_option_bynumber(option), VLC_VAR_INTEGER,
+               &(vlc_value_t) { .i_int = value }, false );
+}
+
+
+int libvlc_video_get_textrenderer_int( libvlc_media_player_t *p_mi,
+                                      unsigned option )
+{
+    return get_int( p_mi, "freetype", textrenderer_option_bynumber(option) );
+}
+
+
+void libvlc_video_set_textrenderer_string( libvlc_media_player_t *p_mi,
+                                          unsigned option, const char *psz_value )
+{
+    set_value( p_mi, "freetype", textrenderer_option_bynumber(option), VLC_VAR_STRING,
+               &(vlc_value_t){ .psz_string = (char *)psz_value }, true );
+}
+
+
+char * libvlc_video_get_textrenderer_string( libvlc_media_player_t *p_mi,
+                                            unsigned option )
+{
+    return get_string( p_mi, "freetype", textrenderer_option_bynumber(option) );
+}
diff --git a/modules/text_renderer/freetype/freetype.c b/modules/text_renderer/freetype/freetype.c
185
index b92c66ceac..ce7bd61806 100644
186 187
--- a/modules/text_renderer/freetype/freetype.c
+++ b/modules/text_renderer/freetype/freetype.c
188
@@ -952,12 +952,36 @@ static inline int RenderAXYZ( filter_t *p_filter,
189 190 191 192 193 194 195 196 197 198 199 200 201
 
 static void UpdateDefaultLiveStyles( filter_t *p_filter )
 {
-    text_style_t *p_style = p_filter->p_sys->p_default_style;
+    filter_sys_t *p_sys = p_filter->p_sys;
+
+    p_sys->p_default_style->i_background_alpha = var_InheritInteger( p_filter, "freetype-background-opacity" );
+    p_sys->p_default_style->i_background_color = var_InheritInteger( p_filter, "freetype-background-color" );
+
+    FREENULL( p_sys->p_default_style->psz_fontname );
+    p_sys->p_default_style->psz_fontname = strdup( var_InheritString( p_filter, "freetype-font" ) );
 
-    p_style->i_font_color = var_InheritInteger( p_filter, "freetype-color" );
202 203
+    int freetype_rel_size = var_InheritInteger( p_filter, "freetype-rel-fontsize" );
+    p_sys->p_forced_style->f_font_relsize = freetype_rel_size <= 0 ? 10 : 100.0 / freetype_rel_size;
204 205 206 207 208 209 210 211 212 213 214 215 216
 
-    p_style->i_background_alpha = var_InheritInteger( p_filter, "freetype-background-opacity" );
-    p_style->i_background_color = var_InheritInteger( p_filter, "freetype-background-color" );
+    p_sys->p_default_style->i_font_color = var_InheritInteger( p_filter, "freetype-color" );
+
+    if (var_InheritBool( p_filter, "freetype-bold" )) {
+        p_sys->p_forced_style->i_style_flags |= STYLE_BOLD;
+        p_sys->p_forced_style->i_features |= STYLE_HAS_FLAGS;
+    } else {
+        p_sys->p_forced_style->i_style_flags &= ~STYLE_BOLD;
+        p_sys->p_forced_style->i_features &= ~STYLE_HAS_FLAGS;
+    }
+    text_style_Merge( p_sys->p_default_style, p_sys->p_forced_style, true );
217 218 219 220 221 222 223 224 225
+
+#ifndef NDEBUG
+    msg_Dbg(p_filter, "%s: def rel font size: %f, rel font size %f, %lli; color %i, font: %s", __func__,
+                p_filter->p_sys->p_default_style->f_font_relsize,
+                p_filter->p_sys->p_forced_style->f_font_relsize,
+                var_InheritInteger( p_filter, "freetype-rel-fontsize" ),
+                p_filter->p_sys->p_default_style->i_font_color,
+                p_filter->p_sys->p_default_style->psz_fontname);
+#endif
226 227 228 229
 }
 
 static void FillDefaultStyles( filter_t *p_filter )
-- 
230
2.20.1
231