[vlc-devel] [PATCH 1/2] Added hotkeys to increase/decrease subtitle fontsize

Subodh Shrestha forsubodh at gmail.com
Tue Mar 4 08:24:48 CET 2014


Ctrl+a increases subtitle fontsize
Ctrl+Shift+a decreases subtitle fontsize
Tested on Ubuntu 12.04 32-bit
---
 include/vlc_keys.h               |    2 ++
 modules/control/hotkeys.c        |   31 ++++++++++++++++++++++++++++---
 modules/text_renderer/freetype.c |   11 ++++++++++-
 src/config/keys.c                |    6 ++++++
 src/libvlc-module.c              |   19 +++++++++++++++++++
 5 files changed, 65 insertions(+), 4 deletions(-)

diff --git a/include/vlc_keys.h b/include/vlc_keys.h
index aafa589..883bc41 100644
--- a/include/vlc_keys.h
+++ b/include/vlc_keys.h
@@ -223,6 +223,8 @@ typedef enum vlc_action {
     ACTIONID_PROGRAM_SID_NEXT,
     ACTIONID_PROGRAM_SID_PREV,
     ACTIONID_INTF_POPUP_MENU,
+    ACTIONID_FONTSIZE_UP,
+    ACTIONID_FONTSIZE_DOWN
 
 } vlc_action_t;
 
diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c
index 1e7fcdf..42a06e0 100644
--- a/modules/control/hotkeys.c
+++ b/modules/control/hotkeys.c
@@ -110,7 +110,7 @@ static int Open( vlc_object_t *p_this )
     p_sys->p_last_vout = NULL;
     p_sys->subtitle_delaybookmarks.i_time_audio = 0;
     p_sys->subtitle_delaybookmarks.i_time_subtitle = 0;
-
+ 
     var_AddCallback( p_intf->p_libvlc, "key-action", ActionEvent, p_intf );
     return VLC_SUCCESS;
 }
@@ -129,7 +129,7 @@ static void Close( vlc_object_t *p_this )
     free( p_sys );
 }
 
-static int PutAction( intf_thread_t *p_intf, int i_action )
+static int PutAction( intf_thread_t *p_intf, int i_action, filter_t *p_filter)
 {
     intf_sys_t *p_sys = p_intf->p_sys;
     playlist_t *p_playlist = pl_Get( p_intf );
@@ -1046,6 +1046,28 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
             if( p_vout && vout_OSDEpg( p_vout, input_GetItem( p_input ) ) )
                 DisplayPosition( p_intf, p_vout, p_input );
             break;
+
+        case ACTIONID_FONTSIZE_UP:
+            if ( p_filter )
+            {
+                int rel_fontsize = var_InheritInteger( p_filter, "freetype-rel-fontsize");
+                msg_Err(p_filter, "Old Relative Fontsize:%i", rel_fontsize);
+                var_Create( p_filter, "freetype-rel-fontsize", VLC_VAR_INTEGER);
+                var_SetInteger( p_filter, "freetype-rel-fontsize", --rel_fontsize);
+                msg_Err(p_filter, "New Relative Fontsize:%i", rel_fontsize);
+            }
+            break;
+
+        case ACTIONID_FONTSIZE_DOWN:
+            if( p_filter )
+            {
+                int rel_fontsize = var_InheritInteger( p_filter, "freetype-rel-fontsize");
+                msg_Err(p_filter, "Old Relative Fontsize:%i", rel_fontsize);
+                var_Create( p_filter, "freetype-rel-fontsize", VLC_VAR_INTEGER);
+                var_SetInteger( p_filter, "freetype-rel-fontsize", ++rel_fontsize);
+                msg_Err(p_filter, "New Relative Fontsize:%i", rel_fontsize);
+            }
+            break;
     }
 
     if( p_vout )
@@ -1062,12 +1084,15 @@ static int ActionEvent( vlc_object_t *libvlc, char const *psz_var,
                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_data;
+    //SS>>
+    filter_t *p_filter = (filter_t *)libvlc;
+    //SS<<
 
     (void)libvlc;
     (void)psz_var;
     (void)oldval;
 
-    return PutAction( p_intf, newval.i_int );
+    return PutAction( p_intf, newval.i_int , p_filter);
 }
 
 static void PlayBookmark( intf_thread_t *p_intf, int i_num )
diff --git a/modules/text_renderer/freetype.c b/modules/text_renderer/freetype.c
index 573d49b..7938ebc 100644
--- a/modules/text_renderer/freetype.c
+++ b/modules/text_renderer/freetype.c
@@ -1609,7 +1609,7 @@ static int RenderCommon( filter_t *p_filter, subpicture_region_t *p_region_out,
         free( pp_styles );
         return VLC_EGENERIC;
     }
-
+    
     /* Reset the default fontsize in case screen metrics have changed */
     p_filter->p_sys->style.i_font_size = GetFontSize( p_filter );
 
@@ -1624,6 +1624,8 @@ static int RenderCommon( filter_t *p_filter, subpicture_region_t *p_region_out,
 
     if( b_html )
     {
+        //SS
+        msg_Err(p_filter, "here");
         stream_t *p_sub = stream_MemoryNew( VLC_OBJECT(p_filter),
                                             (uint8_t *) p_region_in->psz_html,
                                             strlen( p_region_in->psz_html ),
@@ -1665,6 +1667,11 @@ static int RenderCommon( filter_t *p_filter, subpicture_region_t *p_region_out,
                 rv = VLC_EGENERIC;
             }
         }
+        //SS >>
+        //msg_Err(p_filter, "test: %i", p_region_in->p_style->i_font_size);
+        //SetFontSize( p_filter, 10);
+        //p_sys->style.i_font_size = 60;
+        //SS <<
         if( !rv )
         {
             rv = ProcessNodes( p_filter,
@@ -1679,6 +1686,8 @@ static int RenderCommon( filter_t *p_filter, subpicture_region_t *p_region_out,
     }
     else
     {
+        //SS
+        msg_Err(p_filter, "here2");
         text_style_t *p_style;
         if( p_region_in->p_style )
             p_style = CreateStyle( p_region_in->p_style->psz_fontname ? p_region_in->p_style->psz_fontname
diff --git a/src/config/keys.c b/src/config/keys.c
index 07c0d75..46407eb 100644
--- a/src/config/keys.c
+++ b/src/config/keys.c
@@ -288,6 +288,8 @@ static const struct action actions[] =
     { "deinterlace-mode", ACTIONID_DEINTERLACE_MODE, },
     { "disc-menu", ACTIONID_DISC_MENU, },
     { "faster", ACTIONID_FASTER, },
+    { "fontsize-up", ACTIONID_FONTSIZE_UP, },
+    { "fontsize-down", ACTIONID_FONTSIZE_DOWN, },
     { "frame-next", ACTIONID_FRAME_NEXT, },
     { "incr-scalefactor", ACTIONID_SCALE_UP, },
     { "intf-boss", ACTIONID_INTF_BOSS, },
@@ -447,6 +449,9 @@ static void vlc_InitAction (vlc_object_t *obj, void **map,
                             const char *confname, vlc_action_t action)
 {
     char *keys = var_InheritString (obj, confname);
+    //SS >>
+    msg_Err( obj, "For action:%s key found %s", confname, keys );
+    //SS <<
     if (keys == NULL)
         return;
 
@@ -473,6 +478,7 @@ static void vlc_InitAction (vlc_object_t *obj, void **map,
 struct vlc_actions *vlc_InitActions (libvlc_int_t *libvlc)
 {
     vlc_object_t *obj = VLC_OBJECT(libvlc);
+    msg_Err( libvlc, "init actions" );
     struct hotkey *keys;
     struct vlc_actions *as = malloc (sizeof (*as) + (ACTIONS_COUNT + 1) * sizeof (*keys));
 
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index 11fd1cb..ac7a682 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -1431,6 +1431,13 @@ static const char *const mouse_wheel_texts[] =
 #define AUDI_DEVICE_CYCLE_KEY_TEXT N_("Cycle through audio devices")
 #define AUDI_DEVICE_CYCLE_KEY_LONGTEXT N_("Cycle through available audio devices")
 
+//SS >>
+#define FONTSIZE_UP_KEY_TEXT N_("Increase font size")
+#define FONTSIZE_UP_KEY_LONGTEXT N_("Increase font size using hotkey")
+
+#define FONTSIZE_DOWN_KEY_TEXT N_("Decrease font size")
+#define FONTSIZE_DOWN_KEY_LONGTEXT N_("Decrease font size using hotkey")
+//SS<<
 /*
  * Quick usage guide for the configuration options:
  *
@@ -2388,6 +2395,11 @@ vlc_module_begin ()
 
 /* Playlist clear */
 #   define KEY_PLAY_CLEAR         "Ctrl+w"
+
+//SS >>
+#   define KEY_FONTSIZE_UP        "Ctrl+a"
+#   define KEY_FONTSIZE_DOWN      "Ctrl+Shift+a"
+//SS <<
 #endif
 
     add_key( "key-toggle-fullscreen", KEY_TOGGLE_FULLSCREEN, TOGGLE_FULLSCREEN_KEY_TEXT,
@@ -2615,6 +2627,13 @@ vlc_module_begin ()
     add_key( "key-clear-playlist", KEY_PLAY_CLEAR,
              PLAY_CLEAR_KEY_TEXT, PLAY_CLEAR_KEY_LONGTEXT, true )
 
+    //SS >>
+    add_key( "key-fontsize-up", KEY_FONTSIZE_UP,
+             FONTSIZE_UP_KEY_TEXT, FONTSIZE_UP_KEY_LONGTEXT, true)
+    add_key( "key-fontsize-down", KEY_FONTSIZE_DOWN,
+             FONTSIZE_DOWN_KEY_TEXT, FONTSIZE_DOWN_KEY_LONGTEXT, true)
+             
+    //SS <<
 
     add_string( "bookmark1", NULL,
              BOOKMARK1_TEXT, BOOKMARK_LONGTEXT, false )
-- 
1.7.9.5




More information about the vlc-devel mailing list