0009-libvlc-expose-a-base-set-of-freetype-options-to-over.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. From 93c0fb563e992ad16b05f3977ea41327126e0cb3 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Felix=20Paul=20K=C3=BChne?= <fkuehne@videolan.org>
  3. Date: Mon, 23 Nov 2015 16:09:24 +0100
  4. Subject: [PATCH 09/15] libvlc: expose a base set of freetype options to
  5. overwrite the default font
  6. ---
  7. include/vlc/libvlc_media_player.h | 26 ++++++++++++
  8. lib/libvlc.sym | 6 +++
  9. lib/media_player.c | 6 +++
  10. lib/video.c | 68 ++++++++++++++++++++++++++++++-
  11. modules/text_renderer/freetype/freetype.c | 59 +++++++++++++++++++++++++--
  12. modules/text_renderer/freetype/freetype.h | 2 +
  13. 6 files changed, 163 insertions(+), 4 deletions(-)
  14. diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
  15. index 79a0b1f..3a37d3b 100644
  16. --- a/include/vlc/libvlc_media_player.h
  17. +++ b/include/vlc/libvlc_media_player.h
  18. @@ -1496,6 +1496,32 @@ LIBVLC_API float libvlc_video_get_adjust_float( libvlc_media_player_t *p_mi,
  19. LIBVLC_API void libvlc_video_set_adjust_float( libvlc_media_player_t *p_mi,
  20. unsigned option, float value );
  21. +enum libvlc_video_textrenderer_option_t {
  22. + libvlc_textrender_font = 0,
  23. + libvlc_textrender_fontsize,
  24. + libvlc_textrender_fontcolor,
  25. + libvlc_textrender_fontforcebold,
  26. +};
  27. +
  28. +LIBVLC_API bool libvlc_video_get_textrenderer_bool( libvlc_media_player_t *p_mi,
  29. + unsigned option );
  30. +
  31. +LIBVLC_API void libvlc_video_set_textrenderer_bool( libvlc_media_player_t *p_mi,
  32. + unsigned option, bool value );
  33. +
  34. +LIBVLC_API int libvlc_video_get_textrenderer_int( libvlc_media_player_t *p_mi,
  35. + unsigned option );
  36. +
  37. +LIBVLC_API void libvlc_video_set_textrenderer_int( libvlc_media_player_t *p_mi,
  38. + unsigned option, int value );
  39. +
  40. +LIBVLC_API char *libvlc_video_get_textrenderer_string( libvlc_media_player_t *p_mi,
  41. + unsigned option );
  42. +
  43. +LIBVLC_API void libvlc_video_set_textrenderer_string( libvlc_media_player_t *p_mi,
  44. + unsigned option,
  45. + const char *psz_text );
  46. +
  47. /** @} video */
  48. /** \defgroup libvlc_audio LibVLC audio controls
  49. diff --git a/lib/libvlc.sym b/lib/libvlc.sym
  50. index 733a4dd..f297970 100644
  51. --- a/lib/libvlc.sym
  52. +++ b/lib/libvlc.sym
  53. @@ -245,6 +245,9 @@ libvlc_video_get_spu_count
  54. libvlc_video_get_spu_delay
  55. libvlc_video_get_spu_description
  56. libvlc_video_get_teletext
  57. +libvlc_video_get_textrenderer_bool
  58. +libvlc_video_get_textrenderer_int
  59. +libvlc_video_get_textrenderer_string
  60. libvlc_video_get_title_description
  61. libvlc_video_get_track
  62. libvlc_video_get_track_count
  63. @@ -269,6 +272,9 @@ libvlc_video_set_spu
  64. libvlc_video_set_spu_delay
  65. libvlc_video_set_subtitle_file
  66. libvlc_video_set_teletext
  67. +libvlc_video_set_textrenderer_bool
  68. +libvlc_video_set_textrenderer_int
  69. +libvlc_video_set_textrenderer_string
  70. libvlc_video_set_track
  71. libvlc_video_take_snapshot
  72. libvlc_vlm_add_broadcast
  73. diff --git a/lib/media_player.c b/lib/media_player.c
  74. index f2e9d03..8d54c93 100644
  75. --- a/lib/media_player.c
  76. +++ b/lib/media_player.c
  77. @@ -670,6 +670,12 @@ libvlc_media_player_new( libvlc_instance_t *instance )
  78. var_Create (mp, "saturation", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
  79. var_Create (mp, "gamma", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
  80. + /* SPU */
  81. + var_Create (mp, "freetype-font", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
  82. + var_Create (mp, "freetype-rel-fontsize", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
  83. + var_Create (mp, "freetype-color", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
  84. + var_Create (mp, "freetype-bold", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
  85. +
  86. /* Audio */
  87. var_Create (mp, "aout", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
  88. var_Create (mp, "audio-device", VLC_VAR_STRING);
  89. diff --git a/lib/video.c b/lib/video.c
  90. index b2c9b34..6af4e1c 100644
  91. --- a/lib/video.c
  92. +++ b/lib/video.c
  93. @@ -635,7 +635,7 @@ static bool find_sub_source_by_name( libvlc_media_player_t *p_mi, const char *re
  94. }
  95. typedef const struct {
  96. - const char name[20];
  97. + const char name[25];
  98. unsigned type;
  99. } opt_t;
  100. @@ -664,6 +664,9 @@ set_int( libvlc_media_player_t *p_mi, const char *restrict name,
  101. case VLC_VAR_FLOAT:
  102. var_SetFloat( p_mi, opt->name, value );
  103. break;
  104. + case VLC_VAR_BOOL:
  105. + var_SetBool( p_mi, opt->name, value );
  106. + break;
  107. default:
  108. libvlc_printerr( "Invalid argument to %s in %s", name, "set int" );
  109. return;
  110. @@ -687,6 +690,8 @@ get_int( libvlc_media_player_t *p_mi, const char *restrict name,
  111. return var_GetInteger(p_mi, opt->name);
  112. case VLC_VAR_FLOAT:
  113. return lroundf(var_GetFloat(p_mi, opt->name));
  114. + case VLC_VAR_BOOL:
  115. + return var_GetBool(p_mi, opt->name);
  116. default:
  117. libvlc_printerr( "Invalid argument to %s in %s", name, "get int" );
  118. return 0;
  119. @@ -910,3 +915,64 @@ float libvlc_video_get_adjust_float( libvlc_media_player_t *p_mi,
  120. {
  121. return get_float( p_mi, "adjust", adjust_option_bynumber(option) );
  122. }
  123. +
  124. +static const opt_t *
  125. +textrenderer_option_bynumber( unsigned option )
  126. +{
  127. + static const opt_t optlist[] =
  128. + {
  129. + { "freetype-font", VLC_VAR_STRING },
  130. + { "freetype-rel-fontsize", VLC_VAR_INTEGER },
  131. + { "freetype-color", VLC_VAR_INTEGER },
  132. + { "freetype-bold", VLC_VAR_BOOL },
  133. + };
  134. + enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
  135. +
  136. + const opt_t *r = option < num_opts ? optlist+option : NULL;
  137. + if( !r )
  138. + libvlc_printerr( "Unknown freetype option" );
  139. + return r;
  140. +}
  141. +
  142. +/* basic text renderer support */
  143. +
  144. +void libvlc_video_set_textrenderer_bool( libvlc_media_player_t *p_mi,
  145. + unsigned option, bool value )
  146. +{
  147. + set_int( p_mi, "freetype", textrenderer_option_bynumber(option), value );
  148. +}
  149. +
  150. +
  151. +bool libvlc_video_get_textrenderer_bool( libvlc_media_player_t *p_mi,
  152. + unsigned option )
  153. +{
  154. + return get_int( p_mi, "freetype", textrenderer_option_bynumber(option) );
  155. +}
  156. +
  157. +
  158. +void libvlc_video_set_textrenderer_int( libvlc_media_player_t *p_mi,
  159. + unsigned option, int value )
  160. +{
  161. + set_int( p_mi, "freetype", textrenderer_option_bynumber(option), value );
  162. +}
  163. +
  164. +
  165. +int libvlc_video_get_textrenderer_int( libvlc_media_player_t *p_mi,
  166. + unsigned option )
  167. +{
  168. + return get_int( p_mi, "freetype", textrenderer_option_bynumber(option) );
  169. +}
  170. +
  171. +
  172. +void libvlc_video_set_textrenderer_string( libvlc_media_player_t *p_mi,
  173. + unsigned option, const char *psz_value )
  174. +{
  175. + set_string( p_mi, "freetype", textrenderer_option_bynumber(option), psz_value );
  176. +}
  177. +
  178. +
  179. +char * libvlc_video_get_textrenderer_string( libvlc_media_player_t *p_mi,
  180. + unsigned option )
  181. +{
  182. + return get_string( p_mi, "freetype", textrenderer_option_bynumber(option) );
  183. +}
  184. diff --git a/modules/text_renderer/freetype/freetype.c b/modules/text_renderer/freetype/freetype.c
  185. index c75770a..66a4b62 100644
  186. --- a/modules/text_renderer/freetype/freetype.c
  187. +++ b/modules/text_renderer/freetype/freetype.c
  188. @@ -77,6 +77,9 @@
  189. *****************************************************************************/
  190. static int Create ( vlc_object_t * );
  191. static void Destroy( vlc_object_t * );
  192. +static int DefaultFontStyleCallback( vlc_object_t *p_this, char const *psz_var,
  193. + vlc_value_t oldval, vlc_value_t newval,
  194. + void *p_data );
  195. #define FONT_TEXT N_("Font")
  196. #define MONOSPACE_FONT_TEXT N_("Monospace Font")
  197. @@ -929,7 +932,7 @@ static void FillDefaultStyles( filter_t *p_filter )
  198. {
  199. filter_sys_t *p_sys = p_filter->p_sys;
  200. - p_sys->p_default_style->psz_fontname = var_InheritString( p_filter, "freetype-font" );
  201. + p_sys->p_default_style->psz_fontname = var_CreateGetString( p_filter, "freetype-font" );
  202. p_sys->p_default_style->psz_monofontname = var_InheritString( p_filter, "freetype-monofont" );
  203. p_sys->p_default_style->i_font_alpha = var_InheritInteger( p_filter,"freetype-opacity" );
  204. @@ -937,6 +940,8 @@ static void FillDefaultStyles( filter_t *p_filter )
  205. p_sys->p_default_style->i_font_color = var_InheritInteger( p_filter,"freetype-color" );
  206. p_sys->p_default_style->i_font_color = VLC_CLIP( p_sys->p_default_style->i_font_color, 0, 0xFFFFFF );
  207. + p_sys->p_default_style->i_font_color = VLC_CLIP(var_CreateGetIntegerCommand( p_filter, "freetype-color") , 0, 0xFFFFFF);
  208. +
  209. p_sys->p_default_style->i_outline_alpha = var_InheritInteger( p_filter, "freetype-outline-opacity" );
  210. p_sys->p_default_style->i_outline_alpha = VLC_CLIP( p_sys->p_default_style->i_outline_alpha, 0, 255 );
  211. p_sys->p_default_style->i_outline_color = var_InheritInteger( p_filter, "freetype-outline-color" );
  212. @@ -952,11 +957,11 @@ static void FillDefaultStyles( filter_t *p_filter )
  213. p_sys->p_default_style->i_features |= STYLE_HAS_FLAGS;
  214. p_sys->p_forced_style->i_font_size = var_InheritInteger( p_filter, "freetype-fontsize" );
  215. - p_sys->p_forced_style->f_font_relsize = var_InheritInteger( p_filter, "freetype-rel-fontsize" );
  216. + p_sys->p_forced_style->f_font_relsize = var_CreateGetIntegerCommand( p_filter, "freetype-rel-fontsize" );
  217. if( p_sys->p_forced_style->f_font_relsize )
  218. p_sys->p_forced_style->f_font_relsize = 1.0 / p_sys->p_forced_style->f_font_relsize;
  219. - if( var_InheritBool( p_filter, "freetype-bold" ) )
  220. + if( var_CreateGetBoolCommand( p_filter, "freetype-bold" ) )
  221. {
  222. p_sys->p_forced_style->i_style_flags |= STYLE_BOLD;
  223. p_sys->p_forced_style->i_features |= STYLE_HAS_FLAGS;
  224. @@ -964,6 +969,12 @@ static void FillDefaultStyles( filter_t *p_filter )
  225. /* Apply forced styles to defaults, if any */
  226. text_style_Merge( p_sys->p_default_style, p_sys->p_forced_style, true );
  227. +
  228. + vlc_mutex_init( &p_sys->lock );
  229. + var_AddCallback( p_filter, "freetype-font", DefaultFontStyleCallback, p_sys );
  230. + var_AddCallback( p_filter, "freetype-rel-fontsize", DefaultFontStyleCallback, p_sys );
  231. + var_AddCallback( p_filter, "freetype-color", DefaultFontStyleCallback, p_sys );
  232. + var_AddCallback( p_filter, "freetype-bold", DefaultFontStyleCallback, p_sys );
  233. }
  234. static void FreeStylesArray( text_style_t **pp_styles, size_t i_styles )
  235. @@ -1326,6 +1337,17 @@ static void Destroy( vlc_object_t *p_this )
  236. DumpDictionary( p_filter, &p_sys->fallback_map, true, -1 );
  237. #endif
  238. + var_DelCallback( p_filter, "freetype-font", DefaultFontStyleCallback, p_sys );
  239. + var_DelCallback( p_filter, "freetype-rel-fontsize", DefaultFontStyleCallback, p_sys );
  240. + var_DelCallback( p_filter, "freetype-color", DefaultFontStyleCallback, p_sys );
  241. + var_DelCallback( p_filter, "freetype-bold", DefaultFontStyleCallback, p_sys );
  242. + vlc_mutex_destroy( &p_sys->lock );
  243. +
  244. + var_Destroy( p_filter, "freetype-font" ) ;
  245. + var_Destroy( p_filter, "freetype-rel-fontsize" );
  246. + var_Destroy( p_filter, "freetype-color" );
  247. + var_Destroy( p_filter, "freetype-bold" );
  248. +
  249. /* Attachments */
  250. if( p_sys->pp_font_attachments )
  251. {
  252. @@ -1355,3 +1377,34 @@ static void Destroy( vlc_object_t *p_this )
  253. free( p_sys );
  254. }
  255. +static int DefaultFontStyleCallback( vlc_object_t *p_this, char const *psz_var,
  256. + vlc_value_t oldval, vlc_value_t newval,
  257. + void *p_data )
  258. +{
  259. + VLC_UNUSED(oldval);
  260. + filter_t *p_filter = (filter_t *)p_this;
  261. + filter_sys_t *p_sys = (filter_sys_t *)p_data;
  262. +
  263. + vlc_mutex_lock( &p_sys->lock );
  264. + if( !strcmp( psz_var, "freetype-font" ) ) {
  265. + FREENULL( p_sys->p_default_style->psz_fontname );
  266. + p_sys->p_default_style->psz_fontname = strdup( newval.psz_string );
  267. + } else if( !strcmp( psz_var, "freetype-rel-fontsize" ) ) {
  268. + p_sys->p_forced_style->f_font_relsize = 1.0 / newval.i_int;
  269. + } else if( !strcmp( psz_var, "freetype-color" ) )
  270. + p_sys->p_default_style->i_font_color = VLC_CLIP(newval.i_int, 0, 0xFFFFFF);
  271. + else if ( !strcmp( psz_var, "freetype-bold" ) )
  272. + {
  273. + if (newval.b_bool) {
  274. + p_sys->p_forced_style->i_style_flags |= STYLE_BOLD;
  275. + p_sys->p_forced_style->i_features |= STYLE_HAS_FLAGS;
  276. + } else {
  277. + p_sys->p_forced_style->i_style_flags &= ~STYLE_BOLD;
  278. + p_sys->p_forced_style->i_features &= ~STYLE_HAS_FLAGS;
  279. + }
  280. + }
  281. + text_style_Merge( p_sys->p_default_style, p_sys->p_forced_style, true );
  282. + vlc_mutex_unlock( &p_sys->lock );
  283. +
  284. + return VLC_SUCCESS;
  285. +}
  286. diff --git a/modules/text_renderer/freetype/freetype.h b/modules/text_renderer/freetype/freetype.h
  287. index 44b2731..7f1abec 100644
  288. --- a/modules/text_renderer/freetype/freetype.h
  289. +++ b/modules/text_renderer/freetype/freetype.h
  290. @@ -137,6 +137,8 @@ struct filter_sys_t
  291. */
  292. vlc_family_t * (*pf_get_fallbacks) ( filter_t *p_filter, const char *psz_family,
  293. uni_char_t codepoint );
  294. +
  295. + vlc_mutex_t lock;
  296. };
  297. /**
  298. --
  299. 2.9.2