@@ -85,6 +85,7 @@ struct state_text {
8585 int width ; // pixels
8686 int text_base_y ;
8787 int margin_x , margin_y ;
88+ char * req_font ;
8889
8990 // font size
9091 int text_height_pt ;
@@ -133,7 +134,7 @@ static void * text_init(const char *config) {
133134 color_printf ("%s" , wrap_paragraph (desc ));
134135 color_printf ("\nUsage:\n" );
135136 color_printf ("\t" TBOLD ("-p text:<text>" ) "\n" );
136- color_printf ("\t" TBOLD ("-p text:x=<x>:y=<y>:h=<text_height>:t=<text>" ) "\n" );
137+ color_printf ("\t" TBOLD ("-p text[ :x=<x>:y=<y>:h=<text_height>:f=<font>] :t=<text>" ) "\n" );
137138 color_printf ("\nExamples:\n" );
138139 color_printf (TBOLD ("\t-p text:stream1\n"
139140 "\t-p text:x=100:y=100:h=20:t=text\n"
@@ -156,6 +157,8 @@ static void * text_init(const char *config) {
156157 s -> req_y = atoi (item + 2 );
157158 } else if (strstr (item , "h=" ) != NULL ) {
158159 s -> req_h = atoi (item + 2 );
160+ } else if (strstr (item , "f=" ) != NULL ) {
161+ s -> req_font = strdup (strchr (item , '=' ) + 1 );
159162 } else if (strstr (item , "t=" ) != NULL ) {
160163 replace_all (item + 2 , DELDEL , ":" );
161164 s -> text = strdup (item + 2 );
@@ -201,6 +204,35 @@ get_magick_error(const MagickWand *wand)
201204 return MagickGetException (wand , & except );
202205}
203206
207+ /// @returns false if req_font specified but not found
208+ static MagickBooleanType
209+ set_font (DrawingWand * dw , const char * req_font )
210+ {
211+ const char * req_tmp [] = { req_font , NULL };
212+ const char * const * font_candidates =
213+ req_font != NULL ? req_tmp : get_font_candidates ();
214+ while (* font_candidates != NULL ) {
215+ FILE * f = fopen (* font_candidates , "rb" );
216+ if (f != NULL ) {
217+ fclose (f );
218+ if (DrawSetFont (dw , * font_candidates ) != MagickTrue ) {
219+ MSG (WARNING , "DraweSetFont failed!\n" );
220+ continue ;
221+ }
222+ MSG (INFO , "Using font: %s\n" , * font_candidates );
223+ return MagickTrue ;
224+ }
225+ MSG (VERBOSE , "font %s not found\n" , * font_candidates );
226+ font_candidates += 1 ;
227+ }
228+ if (req_font != NULL ) {
229+ return MagickFalse ;
230+ }
231+ MSG (ERROR ,
232+ "Could not find useable font! Continue using system one...\n" );
233+ return MagickTrue ;
234+ }
235+
204236static bool
205237text_postprocess_reconfigure (void * state , struct video_desc desc )
206238{
@@ -249,10 +281,8 @@ text_postprocess_reconfigure(void *state, struct video_desc desc)
249281
250282 s -> dw = NewDrawingWand ();
251283 DrawSetFontSize (s -> dw , s -> text_height_pt );
252- MagickBooleanType status = DrawSetFont (s -> dw , "helvetica" );
284+ MagickBooleanType status = set_font (s -> dw , s -> req_font );
253285 if (status != MagickTrue ) {
254- MSG (WARNING , "DraweSetFont failed: %s!\n" ,
255- get_magick_error (s -> wand_text ));
256286 return false;
257287 }
258288 {
@@ -279,23 +309,6 @@ text_postprocess_reconfigure(void *state, struct video_desc desc)
279309 return false;
280310 }
281311
282- const char * const * font_candidates = get_font_candidates ();
283- while (* font_candidates != NULL ) {
284- FILE * f = fopen (* font_candidates , "rb" );
285- if (f != NULL ) {
286- fclose (f );
287- DrawSetFont (s -> dw , * font_candidates );
288- MSG (INFO , "Using font: %s\n" , * font_candidates );
289- break ;
290- }
291- MSG (VERBOSE , "font %s not found\n" , * font_candidates );
292- font_candidates += 1 ;
293- }
294- while (* font_candidates == NULL ) {
295- MSG (ERROR , "Could not find useable font!\n" );
296- return false;
297- }
298-
299312 status = MagickSetDepth (s -> wand_bg , 8 );
300313 status &= MagickSetDepth (s -> wand_text , 8 );
301314 assert (status == MagickTrue && "[text vo_pp.] MagickSetDepth failed" );
@@ -480,6 +493,7 @@ static void text_done(void *state)
480493
481494 free (s -> data );
482495 free (s -> text );
496+ free (s -> req_font );
483497 free (s );
484498}
485499
0 commit comments