e340060099810ba20429b593bceaca7ab9bd80e7
[goodguy/history.git] / cinelerra-5.1 / guicast / bcresources.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2009-2015 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "bcdisplayinfo.h"
23 #include "bcipc.h"
24 #include "bclistbox.inc"
25 #include "bcfontentry.h"
26 #include "bcresources.h"
27 #include "bcsignals.h"
28 #include "bcsynchronous.h"
29 #include "bcwindowbase.h"
30 #include "bccolors.h"
31 #include "bccmodels.h"
32 #include "cstrdup.h"
33 #include "fonts.h"
34 #include "language.h"
35 #include "vframe.h"
36
37 #include <string.h>
38 #include <iconv.h>
39 #include <sys/ipc.h>
40 #include <sys/shm.h>
41 #include <X11/extensions/XShm.h>
42 #include <fontconfig/fontconfig.h>
43 #include <fontconfig/fcfreetype.h>
44 #include <unistd.h>
45
46
47
48
49
50 int BC_Resources::error = 0;
51
52 VFrame* BC_Resources::bg_image = 0;
53 VFrame* BC_Resources::menu_bg = 0;
54
55 int BC_Resources::locale_utf8 = 0;
56 int BC_Resources::little_endian = 0;
57 char BC_Resources::language[LEN_LANG] = {0};
58 char BC_Resources::region[LEN_LANG] = {0};
59 char BC_Resources::encoding[LEN_ENCOD] = {0};
60 const char *BC_Resources::wide_encoding = 0;
61 ArrayList<BC_FontEntry*> *BC_Resources::fontlist = 0;
62 int BC_Resources::font_debug = 0;
63 const char *BC_Resources::fc_properties[] = { FC_SLANT, FC_WEIGHT, FC_WIDTH };
64 #define LEN_FCPROP (sizeof(BC_Resources::fc_properties) / sizeof(const char*))
65
66 static const char *def_small_font = "-*-helvetica-medium-r-normal-*-%d-*";  // 10
67 static const char *def_small_font2 = "-*-helvetica-medium-r-normal-*-%d-*"; // 11
68 static const char *def_medium_font = "-*-helvetica-bold-r-normal-*-%d-*";   // 14
69 static const char *def_medium_font2 = "-*-helvetica-bold-r-normal-*-%d-*";  // 14
70 static const char *def_large_font = "-*-helvetica-bold-r-normal-*-%d-*";    // 18
71 static const char *def_large_font2 = "-*-helvetica-bold-r-normal-*-%d-*";   // 20
72 static const char *def_big_font =
73   "-*-bitstream charter-bold-r-normal-*-*-0-%d-%d-p-0-iso8859-1"; // 160
74 static const char *def_big_font2 =
75   "-*-nimbus sans l-bold-r-normal-*-*-0-%d-%d-p-0-iso8859-1";     // 160
76 static const char *def_clock_font = "-*-helvetica-bold-r-normal-*-%d-*";      // 16
77 static const char *def_clock_font2 = "-*-helvetica-bold-r-normal-*-%d-*";     // 18
78 static const char *def_small_fontset =  "-*-helvetica-medium-r-normal-*-%d-*";// 10
79 static const char *def_medium_fontset = "-*-helvetica-bold-r-normal-*-%d-*";  // 14
80 static const char *def_large_fontset =  "-*-helvetica-bold-r-normal-*-%d-*";  // 18
81 static const char *def_big_fontset =    "-*-helvetica-bold-r-normal-*-%d-*";  // 24
82 static const char *def_clock_fontset = "-*-helvetica-bold-r-normal-*-%d-*";   // 16
83
84 static const char *def_small_font_xft = "Sans:pixelsize=%.4f";           // 10.6667
85 static const char *def_small_b_font_xft = "Sans:bold:pixelsize=%.4f";    // 10.6667
86 static const char *def_medium_font_xft = "Sans:pixelsize=%.4f";          // 13.3333
87 static const char *def_medium_b_font_xft = "Sans:bold:pixelsize=%.4f";   // 13.3333
88 static const char *def_large_font_xft = "Sans:pixelsize=%.4f";           // 21.3333
89 static const char *def_large_b_font_xft = "Sans:bold:pixelsize=%.4f";    // 21.3333
90 static const char *def_big_font_xft = "Sans:pixelsize=37.3333";          // 37.3333
91 static const char *def_big_b_font_xft = "Sans:bold:pixelsize=37.33333";  // 37.3333
92 static const char *def_clock_font_xft = "Sans:pixelsize=%.4f";           // 16
93
94 #define default_font_xft2 "-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*"
95
96 const char* BC_Resources::small_font = 0;
97 const char* BC_Resources::small_font2 = 0;
98 const char* BC_Resources::medium_font = 0;
99 const char* BC_Resources::medium_font2 = 0;
100 const char* BC_Resources::large_font = 0;
101 const char* BC_Resources::large_font2 = 0;
102 const char* BC_Resources::big_font = 0;
103 const char* BC_Resources::big_font2 = 0;
104 const char* BC_Resources::clock_font = 0;
105 const char* BC_Resources::clock_font2 = 0;
106 const char* BC_Resources::small_fontset = 0;
107 const char* BC_Resources::medium_fontset = 0;
108 const char* BC_Resources::large_fontset = 0;
109 const char* BC_Resources::big_fontset = 0;
110 const char* BC_Resources::clock_fontset = 0;
111 const char* BC_Resources::small_font_xft = 0;
112 const char* BC_Resources::small_font_xft2 = 0;
113 const char* BC_Resources::small_b_font_xft = 0;
114 const char* BC_Resources::medium_font_xft = 0;
115 const char* BC_Resources::medium_font_xft2 = 0;
116 const char* BC_Resources::medium_b_font_xft = 0;
117 const char* BC_Resources::large_font_xft = 0;
118 const char* BC_Resources::large_font_xft2 = 0;
119 const char* BC_Resources::large_b_font_xft = 0;
120 const char* BC_Resources::big_font_xft = 0;
121 const char* BC_Resources::big_font_xft2 = 0;
122 const char* BC_Resources::big_b_font_xft = 0;
123 const char* BC_Resources::clock_font_xft = 0;
124 const char* BC_Resources::clock_font_xft2 = 0;
125
126 #define def_font(v, s...) do { sprintf(string,def_##v,s); v = cstrdup(string); } while(0)
127 #define set_font(v, s) do { sprintf(string, "%s", s); v = cstrdup(string); } while(0)
128 #define iround(v) ((int)(v+0.5))
129 void BC_Resources::init_font_defs(double scale)
130 {
131         char string[BCTEXTLEN];
132         def_font(small_font,       iround(scale*11));
133         def_font(small_font2,      iround(scale*11));
134         def_font(medium_font,      iround(scale*14));
135         def_font(medium_font2,     iround(scale*14));
136         def_font(large_font,       iround(scale*18));
137         def_font(large_font2,      iround(scale*20));
138         def_font(big_font,         iround(scale*160), iround(scale*160));
139         def_font(big_font2,        iround(scale*16), iround(scale*16));
140         def_font(clock_font,       iround(scale*16));
141         def_font(clock_font2,      iround(scale*18));
142         def_font(small_fontset,    iround(scale*10));
143         def_font(medium_fontset,   iround(scale*14));
144         def_font(large_fontset,    iround(scale*18));
145         def_font(big_fontset,      iround(scale*24));
146         def_font(clock_fontset,    iround(scale*16));
147         def_font(small_font_xft,   (scale*10.6667));
148         def_font(small_b_font_xft, (scale*10.6667));
149         def_font(medium_font_xft,  (scale*13.3333));
150         def_font(medium_b_font_xft,(scale*13.3333));
151         def_font(large_font_xft,   (scale*21.3333));
152         def_font(large_b_font_xft, (scale*21.3333));
153         def_font(big_font_xft,     (scale*37.3333));
154         def_font(big_b_font_xft,   (scale*37.3333));
155         def_font(clock_font_xft,   (scale*16.));
156
157         set_font(small_font_xft2,  default_font_xft2);
158         set_font(medium_font_xft2, default_font_xft2);
159         set_font(large_font_xft2,  default_font_xft2);
160         set_font(big_font_xft2,    default_font_xft2);
161         set_font(clock_font_xft2,  default_font_xft2);
162 }
163 void BC_Resources::finit_font_defs()
164 {
165         delete [] small_font;
166         delete [] small_font2;
167         delete [] medium_font;
168         delete [] medium_font2;
169         delete [] large_font;
170         delete [] large_font2;
171         delete [] big_font;
172         delete [] big_font2;
173         delete [] clock_font;
174         delete [] clock_font2;
175         delete [] small_fontset;
176         delete [] medium_fontset;
177         delete [] large_fontset;
178         delete [] big_fontset;
179         delete [] clock_fontset;
180         delete [] small_font_xft;
181         delete [] small_b_font_xft;
182         delete [] medium_font_xft;
183         delete [] medium_b_font_xft;
184         delete [] large_font_xft;
185         delete [] large_b_font_xft;
186         delete [] big_font_xft;
187         delete [] big_b_font_xft;
188         delete [] clock_font_xft;
189
190         delete [] small_font_xft2;
191         delete [] medium_font_xft2;
192         delete [] large_font_xft2;
193         delete [] big_font_xft2;
194         delete [] clock_font_xft2;
195 }
196
197
198 suffix_to_type_t BC_Resources::suffix_to_type[] =
199 {
200     { "aac", ICON_SOUND },
201     { "ac3", ICON_SOUND },
202     { "dts", ICON_SOUND },
203     { "f4a", ICON_SOUND },
204     { "flac", ICON_SOUND },
205     { "m4a", ICON_SOUND },
206     { "mp2", ICON_SOUND },
207     { "mp3", ICON_SOUND },
208     { "mpc", ICON_SOUND },
209     { "oga", ICON_SOUND },
210     { "ogg", ICON_SOUND },
211     { "opus", ICON_SOUND },
212     { "ra", ICON_SOUND },
213     { "tta", ICON_SOUND },
214     { "vox", ICON_SOUND },
215     { "wav", ICON_SOUND },
216     { "wma", ICON_SOUND },
217     { "3gp", ICON_FILM },
218     { "avi", ICON_FILM },
219     { "bmp", ICON_FILM },
220     { "cr2", ICON_FILM },
221     { "dnxhd", ICON_FILM },
222     { "drc", ICON_FILM },
223     { "dv", ICON_FILM },
224     { "dvd", ICON_FILM },
225     { "exr", ICON_FILM },
226     { "f4v", ICON_FILM },
227     { "flv", ICON_FILM },
228     { "gif", ICON_FILM },
229     { "gxf", ICON_FILM },
230     { "h263", ICON_FILM },
231     { "h264", ICON_FILM },
232     { "h265", ICON_FILM },
233     { "hevc", ICON_FILM },
234     { "ifo", ICON_FILM },
235     { "jpeg", ICON_FILM },
236     { "jpg", ICON_FILM },
237     { "m2t", ICON_FILM },
238     { "m2ts", ICON_FILM },
239     { "m2v", ICON_FILM },
240     { "m4p", ICON_FILM },
241     { "m4v", ICON_FILM },
242     { "mkv", ICON_FILM },
243     { "mov", ICON_FILM },
244     { "mp4", ICON_FILM },
245     { "mpe", ICON_FILM },
246     { "mpeg", ICON_FILM },
247     { "mpg", ICON_FILM },
248     { "mpv", ICON_FILM },
249     { "mts", ICON_FILM },
250     { "mxf", ICON_FILM },
251     { "ogv", ICON_FILM },
252     { "pcm", ICON_FILM },
253     { "pgm", ICON_FILM },
254     { "png", ICON_FILM },
255     { "ppm", ICON_FILM },
256     { "qt", ICON_FILM },
257     { "rm", ICON_FILM },
258     { "rmvb", ICON_FILM },
259     { "rv", ICON_FILM },
260     { "swf", ICON_FILM },
261     { "tif", ICON_FILM },
262     { "tiff", ICON_FILM },
263     { "ts",  ICON_FILM },
264     { "vob", ICON_FILM },
265     { "vts", ICON_FILM },
266     { "webm", ICON_FILM },
267     { "webp", ICON_FILM },
268     { "wmv", ICON_FILM },
269     { "xml", ICON_FILM },
270     { "y4m", ICON_FILM },
271     { 0, 0 },
272 };
273
274 BC_Signals* BC_Resources::signal_handler = 0;
275 Mutex BC_Resources::fontconfig_lock("BC_Resources::fonconfig_lock");
276
277 int BC_Resources::x_error_handler(Display *display, XErrorEvent *event)
278 {
279 #if defined(OUTPUT_X_ERROR)
280         char string[1024];
281         XGetErrorText(event->display, event->error_code, string, 1024);
282         fprintf(stderr, "BC_Resources::x_error_handler: error_code=%d opcode=%d,%d %s\n",
283                 event->error_code,
284                 event->request_code,
285                 event->minor_code,
286                 string);
287 #endif
288
289         BC_Resources::error = 1;
290 // This bug only happens in 32 bit mode.
291 //      if(sizeof(long) == 4)
292 //              BC_WindowBase::get_resources()->use_xft = 0;
293         return 0;
294 }
295
296 int BC_Resources::machine_cpus = 1;
297
298 int BC_Resources::get_machine_cpus()
299 {
300         int cpus = 1;
301         FILE *proc = fopen("/proc/cpuinfo", "r");
302         if( proc ) {
303                 char string[BCTEXTLEN], *cp;
304                 while(!feof(proc) && fgets(string, sizeof(string), proc) ) {
305                         if( !strncasecmp(string, "processor", 9) &&
306                             (cp = strchr(string, ':')) != 0 ) {
307                                 int n = atol(cp+1) + 1;
308                                 if( n > cpus ) cpus = n;
309                         }
310                         else if( !strncasecmp(string, "cpus detected", 13) &&
311                             (cp = strchr(string, ':')) != 0 )
312                                 cpus = atol(cp+1);
313                 }
314                 fclose(proc);
315         }
316         return cpus;
317 }
318
319 void BC_Resources::new_vframes(int n, VFrame *vframes[], ...)
320 {
321         va_list ap;
322         va_start(ap, vframes);
323         for( int i=0; i<n; ++i )
324                 vframes[i] = va_arg(ap, VFrame *);
325         va_end(ap);
326 }
327
328 VFrame *BC_Resources::default_type_to_icon[6] = { 0, };
329 VFrame *BC_Resources::default_bar = 0;
330 VFrame *BC_Resources::default_cancel_images[3] = { 0, };
331 VFrame *BC_Resources::default_ok_images[3] = { 0, };
332 VFrame *BC_Resources::default_usethis_images[3] = { 0, };
333 #if 0
334 VFrame *BC_Resources::default_checkbox_images[5] = { 0, };
335 VFrame *BC_Resources::default_radial_images[5] = { 0, };
336 VFrame *BC_Resources::default_label_images[5] = { 0, };
337 #endif
338 VFrame *BC_Resources::default_menuitem_data[3] = { 0, };
339 VFrame *BC_Resources::default_menubar_data[3] = { 0, };
340 VFrame *BC_Resources::default_menu_popup_bg = 0;
341 VFrame *BC_Resources::default_menu_bar_bg = 0;
342 VFrame *BC_Resources::default_check_image = 0;
343 VFrame *BC_Resources::default_filebox_text_images[3] = { 0, };
344 VFrame *BC_Resources::default_filebox_icons_images[3] = { 0, };
345 VFrame *BC_Resources::default_filebox_updir_images[3] = { 0, };
346 VFrame *BC_Resources::default_filebox_newfolder_images[3] = { 0, };
347 VFrame *BC_Resources::default_filebox_rename_images[3] = { 0, };
348 VFrame *BC_Resources::default_filebox_delete_images[3] = { 0, };
349 VFrame *BC_Resources::default_filebox_reload_images[3] = { 0, };
350 VFrame *BC_Resources::default_filebox_szfmt_images[12] = { 0, };
351 VFrame *BC_Resources::default_listbox_button[4] = { 0, };
352 VFrame *BC_Resources::default_listbox_bg = 0;
353 VFrame *BC_Resources::default_listbox_expand[5] = { 0, };
354 VFrame *BC_Resources::default_listbox_column[3] = { 0, };
355 VFrame *BC_Resources::default_listbox_up = 0;
356 VFrame *BC_Resources::default_listbox_dn = 0;
357 VFrame *BC_Resources::default_pot_images[3] = { 0, };
358 VFrame *BC_Resources::default_progress_images[2] = { 0, };
359 VFrame *BC_Resources::default_medium_7segment[20] = { 0, };
360
361 BC_Resources::BC_Resources()
362 {
363         synchronous = 0;
364         vframe_shm = 0;
365         double default_scale = 1.0; // display_size/1000.;
366         char *env = getenv("BC_FONT_DEBUG");
367         font_debug = env ? atoi(env) : 0;
368         env = getenv("BC_FONT_SCALE");
369         font_scale = env ? atof(env) : default_scale;
370         if( font_scale <= 0 ) font_scale = 1;
371         init_font_defs(font_scale);
372         env = getenv("BC_ICON_SCALE");
373         icon_scale = env ? atof(env) : default_scale;
374         if( icon_scale <= 0 ) icon_scale = 1;
375
376         id_lock = new Mutex("BC_Resources::id_lock");
377         create_window_lock = new Mutex("BC_Resources::create_window_lock", 1);
378         id = 0;
379         machine_cpus = get_machine_cpus();
380
381         for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
382                 filebox_history[i].path[0] = 0;
383
384 #ifdef HAVE_XFT
385         XftInitFtLibrary();
386 #endif
387
388         little_endian = (*(const u_int32_t*)"\01\0\0\0") & 1;
389         wide_encoding = little_endian ?  "UTF32LE" : "UTF32BE";
390         use_xvideo = 1;
391
392 #include "images/file_folder_png.h"
393 #include "images/file_unknown_png.h"
394 #include "images/file_film_png.h"
395 #include "images/file_sound_png.h"
396 #include "images/file_label_png.h"
397 #include "images/file_column_png.h"
398 new_vframes(6,default_type_to_icon,
399         new VFramePng(file_folder_png),
400         new VFramePng(file_unknown_png),
401         new VFramePng(file_film_png),
402         new VFramePng(file_sound_png),
403         new VFramePng(file_label_png),
404         new VFramePng(file_column_png));
405
406 #include "images/bar_png.h"
407         default_bar = new VFramePng(bar_png);
408
409 #include "images/cancel_up_png.h"
410 #include "images/cancel_hi_png.h"
411 #include "images/cancel_dn_png.h"
412 new_vframes(3,default_cancel_images,
413         new VFramePng(cancel_up_png),
414         new VFramePng(cancel_hi_png),
415         new VFramePng(cancel_dn_png));
416
417 #include "images/ok_up_png.h"
418 #include "images/ok_hi_png.h"
419 #include "images/ok_dn_png.h"
420 new_vframes(3,default_ok_images,
421         new VFramePng(ok_up_png),
422         new VFramePng(ok_hi_png),
423         new VFramePng(ok_dn_png));
424
425 #include "images/usethis_up_png.h"
426 #include "images/usethis_uphi_png.h"
427 #include "images/usethis_dn_png.h"
428 new_vframes(3,default_usethis_images,
429         new VFramePng(usethis_up_png),
430         new VFramePng(usethis_uphi_png),
431         new VFramePng(usethis_dn_png));
432
433 #if 0
434 #include "images/checkbox_checked_png.h"
435 #include "images/checkbox_dn_png.h"
436 #include "images/checkbox_checkedhi_png.h"
437 #include "images/checkbox_up_png.h"
438 #include "images/checkbox_hi_png.h"
439 new_vframes(5,default_checkbox_images,
440         new VFramePng(checkbox_up_png),
441         new VFramePng(checkbox_hi_png),
442         new VFramePng(checkbox_checked_png),
443         new VFramePng(checkbox_dn_png),
444         new VFramePng(checkbox_checkedhi_png));
445
446 #include "images/radial_checked_png.h"
447 #include "images/radial_dn_png.h"
448 #include "images/radial_checkedhi_png.h"
449 #include "images/radial_up_png.h"
450 #include "images/radial_hi_png.h"
451 new_vframes(5,default_radial_images,
452         new VFramePng(radial_up_png),
453         new VFramePng(radial_hi_png),
454         new VFramePng(radial_checked_png),
455         new VFramePng(radial_dn_png),
456         new VFramePng(radial_checkedhi_png));
457
458 new_vframes(5,default_label_images,
459         new VFramePng(radial_up_png),
460         new VFramePng(radial_hi_png),
461         new VFramePng(radial_checked_png),
462         new VFramePng(radial_dn_png),
463         new VFramePng(radial_checkedhi_png));
464 #endif
465
466 #include "images/menuitem_up_png.h"
467 #include "images/menuitem_hi_png.h"
468 #include "images/menuitem_dn_png.h"
469 new_vframes(3,default_menuitem_data,
470         new VFramePng(menuitem_up_png),
471         new VFramePng(menuitem_hi_png),
472         new VFramePng(menuitem_dn_png));
473
474 #include "images/menubar_up_png.h"
475 #include "images/menubar_hi_png.h"
476 #include "images/menubar_dn_png.h"
477 new_vframes(3,default_menubar_data,
478         new VFramePng(menubar_up_png),
479         new VFramePng(menubar_hi_png),
480         new VFramePng(menubar_dn_png));
481
482 #include "images/menu_popup_bg_png.h"
483         default_menu_popup_bg = new VFramePng(menu_popup_bg_png);
484
485 #include "images/menubar_bg_png.h"
486         default_menu_bar_bg = new VFramePng(menubar_bg_png);
487
488 #include "images/check_png.h"
489         default_check_image = new VFramePng(check_png);
490
491 #include "images/file_text_up_png.h"
492 #include "images/file_text_hi_png.h"
493 #include "images/file_text_dn_png.h"
494 new_vframes(3,default_filebox_text_images,
495         new VFramePng(file_text_up_png),
496         new VFramePng(file_text_hi_png),
497         new VFramePng(file_text_dn_png));
498
499 #include "images/file_icons_up_png.h"
500 #include "images/file_icons_hi_png.h"
501 #include "images/file_icons_dn_png.h"
502 new_vframes(3,default_filebox_icons_images,
503         new VFramePng(file_icons_up_png),
504         new VFramePng(file_icons_hi_png),
505         new VFramePng(file_icons_dn_png));
506
507 #include "images/file_updir_up_png.h"
508 #include "images/file_updir_hi_png.h"
509 #include "images/file_updir_dn_png.h"
510 new_vframes(3,default_filebox_updir_images,
511         new VFramePng(file_updir_up_png),
512         new VFramePng(file_updir_hi_png),
513         new VFramePng(file_updir_dn_png));
514
515 #include "images/file_newfolder_up_png.h"
516 #include "images/file_newfolder_hi_png.h"
517 #include "images/file_newfolder_dn_png.h"
518 new_vframes(3,default_filebox_newfolder_images,
519         new VFramePng(file_newfolder_up_png),
520         new VFramePng(file_newfolder_hi_png),
521         new VFramePng(file_newfolder_dn_png));
522
523 #include "images/file_rename_up_png.h"
524 #include "images/file_rename_hi_png.h"
525 #include "images/file_rename_dn_png.h"
526 new_vframes(3,default_filebox_rename_images,
527         new VFramePng(file_rename_up_png),
528         new VFramePng(file_rename_hi_png),
529         new VFramePng(file_rename_dn_png));
530
531 #include "images/file_delete_up_png.h"
532 #include "images/file_delete_hi_png.h"
533 #include "images/file_delete_dn_png.h"
534 new_vframes(3,default_filebox_delete_images,
535         new VFramePng(file_delete_up_png),
536         new VFramePng(file_delete_hi_png),
537         new VFramePng(file_delete_dn_png));
538
539 #include "images/file_reload_up_png.h"
540 #include "images/file_reload_hi_png.h"
541 #include "images/file_reload_dn_png.h"
542 new_vframes(3,default_filebox_reload_images,
543         new VFramePng(file_reload_up_png),
544         new VFramePng(file_reload_hi_png),
545         new VFramePng(file_reload_dn_png));
546
547 #include "images/file_size_capb_up_png.h"
548 #include "images/file_size_capb_hi_png.h"
549 #include "images/file_size_capb_dn_png.h"
550 #include "images/file_size_lwrb_up_png.h"
551 #include "images/file_size_lwrb_hi_png.h"
552 #include "images/file_size_lwrb_dn_png.h"
553 #include "images/file_size_semi_up_png.h"
554 #include "images/file_size_semi_hi_png.h"
555 #include "images/file_size_semi_dn_png.h"
556 #include "images/file_size_zero_up_png.h"
557 #include "images/file_size_zero_hi_png.h"
558 #include "images/file_size_zero_dn_png.h"
559 new_vframes(12,default_filebox_szfmt_images,
560         new VFramePng(file_size_zero_up_png),
561         new VFramePng(file_size_zero_hi_png),
562         new VFramePng(file_size_zero_dn_png),
563         new VFramePng(file_size_lwrb_up_png),
564         new VFramePng(file_size_lwrb_hi_png),
565         new VFramePng(file_size_lwrb_dn_png),
566         new VFramePng(file_size_capb_up_png),
567         new VFramePng(file_size_capb_hi_png),
568         new VFramePng(file_size_capb_dn_png),
569         new VFramePng(file_size_semi_up_png),
570         new VFramePng(file_size_semi_hi_png),
571         new VFramePng(file_size_semi_dn_png));
572
573 #include "images/listbox_button_dn_png.h"
574 #include "images/listbox_button_hi_png.h"
575 #include "images/listbox_button_up_png.h"
576 #include "images/listbox_button_disabled_png.h"
577 new_vframes(4,default_listbox_button,
578         new VFramePng(listbox_button_up_png),
579         new VFramePng(listbox_button_hi_png),
580         new VFramePng(listbox_button_dn_png),
581         new VFramePng(listbox_button_disabled_png));
582
583 default_listbox_bg = 0;
584
585 #include "images/listbox_expandchecked_png.h"
586 #include "images/listbox_expandcheckedhi_png.h"
587 #include "images/listbox_expanddn_png.h"
588 #include "images/listbox_expandup_png.h"
589 #include "images/listbox_expanduphi_png.h"
590 new_vframes(5,default_listbox_expand,
591         new VFramePng(listbox_expandup_png),
592         new VFramePng(listbox_expanduphi_png),
593         new VFramePng(listbox_expandchecked_png),
594         new VFramePng(listbox_expanddn_png),
595         new VFramePng(listbox_expandcheckedhi_png));
596
597 #include "images/listbox_columnup_png.h"
598 #include "images/listbox_columnhi_png.h"
599 #include "images/listbox_columndn_png.h"
600 new_vframes(3,default_listbox_column,
601         new VFramePng(listbox_columnup_png),
602         new VFramePng(listbox_columnhi_png),
603         new VFramePng(listbox_columndn_png));
604
605 #include "images/listbox_up_png.h"
606         default_listbox_up = new VFramePng(listbox_up_png);
607
608 #include "images/listbox_dn_png.h"
609         default_listbox_dn = new VFramePng(listbox_dn_png);
610
611 #include "images/pot_hi_png.h"
612 #include "images/pot_up_png.h"
613 #include "images/pot_dn_png.h"
614 new_vframes(3,default_pot_images,
615         new VFramePng(pot_up_png),
616         new VFramePng(pot_hi_png),
617         new VFramePng(pot_dn_png));
618
619 #include "images/progress_up_png.h"
620 #include "images/progress_hi_png.h"
621 new_vframes(2,default_progress_images,
622         new VFramePng(progress_up_png),
623         new VFramePng(progress_hi_png));
624
625 #include "images/7seg_small/0_png.h"
626 #include "images/7seg_small/1_png.h"
627 #include "images/7seg_small/2_png.h"
628 #include "images/7seg_small/3_png.h"
629 #include "images/7seg_small/4_png.h"
630 #include "images/7seg_small/5_png.h"
631 #include "images/7seg_small/6_png.h"
632 #include "images/7seg_small/7_png.h"
633 #include "images/7seg_small/8_png.h"
634 #include "images/7seg_small/9_png.h"
635 #include "images/7seg_small/colon_png.h"
636 #include "images/7seg_small/period_png.h"
637 #include "images/7seg_small/a_png.h"
638 #include "images/7seg_small/b_png.h"
639 #include "images/7seg_small/c_png.h"
640 #include "images/7seg_small/d_png.h"
641 #include "images/7seg_small/e_png.h"
642 #include "images/7seg_small/f_png.h"
643 #include "images/7seg_small/space_png.h"
644 #include "images/7seg_small/dash_png.h"
645 new_vframes(20,default_medium_7segment,
646         new VFramePng(_0_png),
647         new VFramePng(_1_png),
648         new VFramePng(_2_png),
649         new VFramePng(_3_png),
650         new VFramePng(_4_png),
651         new VFramePng(_5_png),
652         new VFramePng(_6_png),
653         new VFramePng(_7_png),
654         new VFramePng(_8_png),
655         new VFramePng(_9_png),
656         new VFramePng(colon_png),
657         new VFramePng(period_png),
658         new VFramePng(a_png),
659         new VFramePng(b_png),
660         new VFramePng(c_png),
661         new VFramePng(d_png),
662         new VFramePng(e_png),
663         new VFramePng(f_png),
664         new VFramePng(space_png),
665         new VFramePng(dash_png));
666
667         type_to_icon = default_type_to_icon;
668         bar_data = default_bar;
669         check = default_check_image;
670         listbox_button = default_listbox_button;
671         listbox_bg = default_listbox_bg;
672         listbox_expand = default_listbox_expand;
673         listbox_column = default_listbox_column;
674         listbox_up = default_listbox_up;
675         listbox_dn = default_listbox_dn;
676         listbox_title_overlap = 0;
677         listbox_title_margin = 0;
678         listbox_title_color = BLACK;
679         listbox_title_hotspot = 5;
680
681         listbox_border1 = DKGREY;
682         listbox_border2_hi = RED;
683         listbox_border2 = BLACK;
684         listbox_border3_hi = RED;
685         listbox_border3 = MEGREY;
686         listbox_border4 = WHITE;
687         listbox_selected = BLUE;
688         listbox_highlighted = LTGREY;
689         listbox_inactive = WHITE;
690         listbox_text = BLACK;
691
692         pan_data = 0;
693         pan_text_color = YELLOW;
694
695         generic_button_margin = 15;
696         draw_clock_background=1;
697
698         use_shm = -1;
699         shm_reply = 1;
700
701 // Initialize
702         bg_color = ORANGE;
703         bg_shadow1 = DKGREY;
704         bg_shadow2 = BLACK;
705         bg_light1 = WHITE;
706         bg_light2 = bg_color;
707
708
709         border_light1 = bg_color;
710         border_light2 = MEGREY;
711         border_shadow1 = BLACK;
712         border_shadow2 = bg_color;
713
714         default_text_color = BLACK;
715         disabled_text_color = DMGREY;
716
717         button_light = MEGREY;           // bright corner
718 //      button_highlighted = LTGREY;  // face when highlighted
719         button_highlighted = 0xffe000;  // face when highlighted
720         button_down = MDGREY;         // face when down
721 //      button_up = MEGREY;           // face when up
722         button_up = 0xffc000;           // face when up
723         button_shadow = BLACK;       // dark corner
724         button_uphighlighted = RED;   // upper side when highlighted
725
726         tumble_data = 0;
727         tumble_duration = 150;
728
729         ok_images = default_ok_images;
730         cancel_images = default_cancel_images;
731         usethis_button_images = default_usethis_images;
732         filebox_descend_images = default_ok_images;
733
734         menu_light = LTCYAN;
735         menu_highlighted = LTBLUE;
736         menu_down = MDCYAN;
737         menu_up = MECYAN;
738         menu_shadow = DKCYAN;
739
740         menu_title_bg = default_menubar_data;
741         menu_popup_bg = default_menu_popup_bg;
742         menu_bar_bg = default_menu_bar_bg;
743
744         popupmenu_images = 0;
745
746
747         popupmenu_margin = 10;
748         popupmenu_btnup = 1;
749         popupmenu_triangle_margin = 10;
750
751         min_menu_w = 0;
752         menu_title_text = BLACK;
753         popup_title_text = BLACK;
754         menu_item_text = BLACK;
755         menu_highlighted_fontcolor = BLACK;
756         progress_text = BLACK;
757         grab_input_focus = 1;
758
759         text_default = BLACK;
760         highlight_inverse = WHITE ^ BLUE;
761         text_background = WHITE;
762         text_background_disarmed = 0xc08080;
763         text_background_hi = LTYELLOW;
764         text_background_noborder_hi = LTGREY;
765         text_background_noborder = -1;
766         text_border1 = DKGREY;
767         text_border2 = BLACK;
768         text_border2_hi = RED;
769         text_border3 = MEGREY;
770         text_border3_hi = LTPINK;
771         text_border4 = WHITE;
772         text_highlight = BLUE;
773         text_selected_highlight = SLBLUE;
774         text_inactive_highlight = MEGREY;
775
776         toggle_highlight_bg = 0;
777         toggle_text_margin = 0;
778
779 // Delays must all be different for repeaters
780         double_click = 300;
781         blink_rate = 250;
782         scroll_repeat = 150;
783         tooltip_delay = 1000;
784         tooltip_bg_color = YELLOW;
785         tooltips_enabled = 1;
786         textbox_focus_policy = 0;
787
788         filebox_margin = 110;
789         dirbox_margin = 90;
790         filebox_mode = LISTBOX_TEXT;
791         sprintf(filebox_filter, "*");
792         filebox_w = 640;
793         filebox_h = 480;
794         filebox_columntype[0] = FILEBOX_NAME;
795         filebox_columntype[1] = FILEBOX_SIZE;
796         filebox_columntype[2] = FILEBOX_DATE;
797         filebox_columntype[3] = FILEBOX_EXTENSION;
798         filebox_columnwidth[0] = 200;
799         filebox_columnwidth[1] = 100;
800         filebox_columnwidth[2] = 100;
801         filebox_columnwidth[3] = 100;
802         dirbox_columntype[0] = FILEBOX_NAME;
803         dirbox_columntype[1] = FILEBOX_DATE;
804         dirbox_columnwidth[0] = 200;
805         dirbox_columnwidth[1] = 100;
806
807         filebox_text_images = default_filebox_text_images;
808         filebox_icons_images = default_filebox_icons_images;
809         filebox_updir_images = default_filebox_updir_images;
810         filebox_newfolder_images = default_filebox_newfolder_images;
811         filebox_rename_images = default_filebox_rename_images;
812         filebox_delete_images = default_filebox_delete_images;
813         filebox_reload_images = default_filebox_reload_images;
814         filebox_szfmt_images = default_filebox_szfmt_images;
815         filebox_size_format = FILEBOX_SIZE_RAW;
816         directory_color = BLUE;
817         file_color = BLACK;
818
819         filebox_sortcolumn = 0;
820         filebox_sortorder = BC_ListBox::SORT_ASCENDING;
821         dirbox_sortcolumn = 0;
822         dirbox_sortorder = BC_ListBox::SORT_ASCENDING;
823
824
825         pot_images = default_pot_images;
826         pot_offset = 2;
827         pot_x1 = pot_images[0]->get_w() / 2 - pot_offset;
828         pot_y1 = pot_images[0]->get_h() / 2 - pot_offset;
829         pot_r = pot_x1;
830         pot_needle_color = BLACK;
831
832         progress_images = default_progress_images;
833
834         xmeter_images = 0;
835         ymeter_images = 0;
836         meter_font = SMALLFONT_3D;
837         meter_font_color = RED;
838         meter_title_w = 20;
839         meter_3d = 1;
840         medium_7segment = default_medium_7segment;
841
842         audiovideo_color = RED;
843
844         use_fontset = 0;
845
846 // Xft has priority over font set
847 #ifdef HAVE_XFT
848 // But Xft dies in 32 bit mode after some amount of drawing.
849         use_xft = 1;
850 #else
851         use_xft = 0;
852 #endif
853
854
855         drag_radius = 10;
856         recursive_resizing = 1;
857
858
859 }
860
861 void BC_Resources::del_vframes(VFrame *vframes[], int n)
862 {
863         while( --n >= 0 ) delete vframes[n];
864 }
865
866 BC_Resources::~BC_Resources()
867 {
868         delete id_lock;
869         delete create_window_lock;
870         del_vframes(default_type_to_icon, 6);
871         delete default_bar;
872         del_vframes(default_cancel_images, 3);
873         del_vframes(default_ok_images, 3);
874         del_vframes(default_usethis_images, 3);
875 #if 0
876         del_vframes(default_checkbox_images, 5);
877         del_vframes(default_radial_images, 5);
878         del_vframes(default_label_images, 5);
879 #endif
880         del_vframes(default_menuitem_data, 3);
881         del_vframes(default_menubar_data, 3);
882         delete default_menu_popup_bg;
883         delete default_menu_bar_bg;
884         delete default_check_image;
885         del_vframes(default_filebox_text_images, 3);
886         del_vframes(default_filebox_icons_images, 3);
887         del_vframes(default_filebox_updir_images, 3);
888         del_vframes(default_filebox_newfolder_images, 3);
889         del_vframes(default_filebox_rename_images, 3);
890         del_vframes(default_filebox_delete_images, 3);
891         del_vframes(default_filebox_reload_images, 3);
892         del_vframes(default_filebox_szfmt_images, 12);
893         del_vframes(default_listbox_button, 4);
894         delete default_listbox_bg;
895         del_vframes(default_listbox_expand, 5);
896         del_vframes(default_listbox_column, 3);
897         delete default_listbox_up;
898         delete default_listbox_dn;
899         del_vframes(default_pot_images, 3);
900         del_vframes(default_progress_images, 2);
901         del_vframes(default_medium_7segment, 20);
902         if( fontlist ) {
903                 fontlist->remove_all_objects();
904                 delete fontlist;
905         }
906         finit_font_defs();
907 }
908
909 int BC_Resources::initialize_display(BC_WindowBase *window)
910 {
911 // Set up IPC cleanup handlers
912 //      bc_init_ipc();
913
914 // Test for shm.  Must come before yuv test
915         init_shm(window);
916         return 0;
917 }
918
919
920 void BC_Resources::init_shm(BC_WindowBase *window)
921 {
922         use_shm = 0;
923         int (*old_handler)(Display *, XErrorEvent *) =
924                 XSetErrorHandler(BC_Resources::x_error_handler);
925
926         if(XShmQueryExtension(window->display))
927         {
928                 XShmSegmentInfo test_shm;
929                 memset(&test_shm,0,sizeof(test_shm));
930                 XImage *test_image = XShmCreateImage(window->display, window->vis,
931                         window->default_depth, ZPixmap, (char*)NULL, &test_shm, 5, 5);
932                 BC_Resources::error = 0;
933                 test_shm.shmid = shmget(IPC_PRIVATE, 5 * test_image->bytes_per_line, (IPC_CREAT | 0600));
934                 if(test_shm.shmid != -1) {
935                         char *data = (char *)shmat(test_shm.shmid, NULL, 0);
936                         if(data != (void *)-1) {
937                                 shmctl(test_shm.shmid, IPC_RMID, 0);
938                                 test_shm.shmaddr = data;
939                                 test_shm.readOnly = 0;
940
941                                 if(XShmAttach(window->display, &test_shm)) {
942                                         XSync(window->display, False);
943                                         use_shm = 1;
944                                 }
945                                 shmdt(data);
946                         }
947                 }
948
949                 XDestroyImage(test_image);
950                 if(BC_Resources::error) use_shm = 0;
951         }
952         XSetErrorHandler(old_handler);
953 }
954
955
956
957
958 BC_Synchronous* BC_Resources::get_synchronous()
959 {
960         return synchronous;
961 }
962
963 void BC_Resources::set_synchronous(BC_Synchronous *synchronous)
964 {
965         this->synchronous = synchronous;
966 }
967
968
969
970
971 int BC_Resources::get_bg_color() { return bg_color; }
972
973 int BC_Resources::get_bg_shadow1() { return bg_shadow1; }
974
975 int BC_Resources::get_bg_shadow2() { return bg_shadow2; }
976
977 int BC_Resources::get_bg_light1() { return bg_light1; }
978
979 int BC_Resources::get_bg_light2() { return bg_light2; }
980
981
982 int BC_Resources::get_id()
983 {
984         id_lock->lock("BC_Resources::get_id");
985         int result = id++;
986         id_lock->unlock();
987         return result;
988 }
989
990 int BC_Resources::get_filebox_id()
991 {
992         id_lock->lock("BC_Resources::get_filebox_id");
993         int result = filebox_id++;
994         id_lock->unlock();
995         return result;
996 }
997
998
999 void BC_Resources::set_signals(BC_Signals *signal_handler)
1000 {
1001         BC_Resources::signal_handler = signal_handler;
1002 }
1003
1004 int BC_Resources::init_fontconfig(const char *search_path)
1005 {
1006         if( fontlist ) return 0;
1007         fontlist = new ArrayList<BC_FontEntry*>;
1008
1009 #define get_str(str,sep,ptr,cond) do { char *out = str; \
1010   while( *ptr && !strchr(sep,*ptr) && (cond) ) *out++ = *ptr++; \
1011   *out = 0; \
1012 } while(0)
1013
1014 #define skip_str(sep, ptr) do { \
1015   while( *ptr && strchr(sep,*ptr) ) ++ptr; \
1016 } while(0)
1017
1018         char find_command[BCTEXTLEN];
1019         char *fp = find_command, *ep = fp+sizeof(find_command)-1;
1020         fp += snprintf(fp, ep-fp, "%s", "find");
1021         const char *bc_font_path = getenv("BC_FONT_PATH");
1022 // if BC_FONT_PATH starts with ':', omit default path
1023         if( !(bc_font_path && bc_font_path[0] == ':') )
1024                 fp += snprintf(fp, ep-fp, " '%s'", search_path);
1025         if( bc_font_path ) {
1026                 const char *path = bc_font_path;
1027                 while( *path ) {
1028                         char font_path[BCTEXTLEN];
1029                         const char *cp = strchr(path,':');
1030                         int len = !cp ? strlen(path) : cp-path;
1031                         if( len > 0 ) {
1032                                 memcpy(font_path, path, len);
1033                                 font_path[len] = 0;  path += len;
1034                                 fp += snprintf(fp, ep-fp, " '%s'", font_path);
1035                         }
1036                         if( cp ) ++path;
1037                 }
1038         }
1039         fp += snprintf(fp, ep-fp, " -name 'fonts.scale' -print -exec cat {} \\;");
1040         FILE *in = popen(find_command, "r");
1041
1042         FT_Library freetype_library = 0;
1043 //      FT_Face freetype_face = 0;
1044 //      FT_Init_FreeType(&freetype_library);
1045
1046         char line[BCTEXTLEN], current_dir[BCTEXTLEN];
1047         current_dir[0] = 0;
1048
1049         while( !feof(in) && fgets(line, BCTEXTLEN, in) ) {
1050                 if(!strlen(line)) break;
1051
1052                 char *in_ptr = line;
1053
1054 // Get current directory
1055                 if(line[0] == '/') {
1056                         get_str(current_dir, "\n", in_ptr,1);
1057                         for( int i=strlen(current_dir); --i>=0 && current_dir[i]!='/'; )
1058                                 current_dir[i] = 0;
1059                         continue;
1060                 }
1061
1062 //printf("TitleMain::build_fonts %s\n", line);
1063                 BC_FontEntry *entry = new BC_FontEntry;
1064                 char string[BCTEXTLEN];
1065 // Path
1066                 get_str(string, "\n", in_ptr, in_ptr[0]!=' ' || in_ptr[1]!='-');
1067                 entry->path = cstrcat(2, current_dir, string);
1068 // Foundary
1069                 skip_str(" -", in_ptr);
1070                 get_str(string, "-\n", in_ptr, 1);
1071                 if( !string[0] ) { delete entry;  continue; }
1072                 entry->foundry = cstrdup(string);
1073                 if(*in_ptr == '-') in_ptr++;
1074 // Family
1075                 get_str(string, "-\n", in_ptr, 1);
1076                 if( !string[0] ) { delete entry;  continue; }
1077                 entry->family = cstrdup(string);
1078                 if(*in_ptr == '-') in_ptr++;
1079 // Weight
1080                 get_str(string, "-\n", in_ptr, 1);
1081                 entry->weight = cstrdup(string);
1082                 if(*in_ptr == '-') in_ptr++;
1083 // Slant
1084                 get_str(string, "-\n", in_ptr, 1);
1085                 entry->slant = cstrdup(string);
1086                 if(*in_ptr == '-') in_ptr++;
1087 // SWidth
1088                 get_str(string, "-\n", in_ptr, 1);
1089                 entry->swidth = cstrdup(string);
1090                 if(*in_ptr == '-') in_ptr++;
1091 // Adstyle
1092                 get_str(string, "-\n", in_ptr, 1);
1093                 entry->adstyle = cstrdup(string);
1094                 if(*in_ptr == '-') in_ptr++;
1095 // pixelsize
1096                 get_str(string, "-\n", in_ptr, 1);
1097                 entry->pixelsize = atol(string);
1098                 if(*in_ptr == '-') in_ptr++;
1099 // pointsize
1100                 get_str(string, "-\n", in_ptr, 1);
1101                 entry->pointsize = atol(string);
1102                 if(*in_ptr == '-') in_ptr++;
1103 // xres
1104                 get_str(string, "-\n", in_ptr, 1);
1105                 entry->xres = atol(string);
1106                 if(*in_ptr == '-') in_ptr++;
1107 // yres
1108                 get_str(string, "-\n", in_ptr, 1);
1109                 entry->yres = atol(string);
1110                 if(*in_ptr == '-') in_ptr++;
1111 // spacing
1112                 get_str(string, "-\n", in_ptr, 1);
1113                 entry->spacing = cstrdup(string);
1114                 if(*in_ptr == '-') in_ptr++;
1115 // avg_width
1116                 get_str(string, "-\n", in_ptr, 1);
1117                 entry->avg_width = atol(string);
1118                 if(*in_ptr == '-') in_ptr++;
1119 // registry
1120                 get_str(string, "-\n", in_ptr, 1);
1121                 entry->registry = cstrdup(string);
1122                 if(*in_ptr == '-') in_ptr++;
1123 // encoding
1124                 get_str(string, "-\n", in_ptr, 1);
1125                 entry->encoding = cstrdup(string);
1126                 if(*in_ptr == '-') in_ptr++;
1127
1128 // Add to list
1129 //printf("TitleMain::build_fonts 1 %s\n", entry->path);
1130 // This takes a real long time to do.  Instead just take all fonts
1131 //              if(!load_freetype_face(freetype_library,
1132 //                      freetype_face, entry->path) )
1133 // Fix parameters
1134                 sprintf(line, "%s (%s)", entry->family, entry->foundry);
1135                 entry->displayname = cstrdup(line);
1136
1137                 if(!strcasecmp(entry->weight, "demibold")) {
1138                         entry->fixed_style |= BC_FONT_BOLD;
1139                         entry->style |= FL_WEIGHT_DEMIBOLD;
1140                 }
1141                 else if(!strcasecmp(entry->weight, "bold")) {
1142                         entry->fixed_style |= BC_FONT_BOLD;
1143                         entry->style |= FL_WEIGHT_BOLD;
1144                 }
1145                 else {
1146                         entry->style |= FL_WEIGHT_NORMAL;
1147                 }
1148
1149                 if(!strcasecmp(entry->slant, "r")) {
1150                         entry->style |= FL_SLANT_ROMAN;
1151                 }
1152                 else if(!strcasecmp(entry->slant, "i")) {
1153                         entry->style |= FL_SLANT_ITALIC;
1154                         entry->fixed_style |= BC_FONT_ITALIC;
1155                 }
1156                 else if(!strcasecmp(entry->slant, "o")) {
1157                         entry->style |= FL_SLANT_OBLIQUE;
1158                         entry->fixed_style |= BC_FONT_ITALIC;
1159                 }
1160
1161                 if(!strcasecmp(entry->swidth, "normal"))
1162                         entry->style |= FL_WIDTH_NORMAL;
1163                 else if(!strcasecmp(entry->swidth, "ultracondensed"))
1164                         entry->style |= FL_WIDTH_ULTRACONDENSED;
1165                 else if(!strcasecmp(entry->swidth, "extracondensed"))
1166                         entry->style |= FL_WIDTH_EXTRACONDENSED;
1167                 else if(!strcasecmp(entry->swidth, "condensed"))
1168                         entry->style |= FL_WIDTH_CONDENSED;
1169                 else if(!strcasecmp(entry->swidth, "semicondensed"))
1170                         entry->style |= FL_WIDTH_SEMICONDENSED;
1171                 else if(!strcasecmp(entry->swidth, "semiexpanded"))
1172                         entry->style |= FL_WIDTH_SEMIEXPANDED;
1173                 else if(!strcasecmp(entry->swidth, "expanded"))
1174                         entry->style |= FL_WIDTH_EXPANDED;
1175                 else if(!strcasecmp(entry->swidth, "extraexpanded"))
1176                         entry->style |= FL_WIDTH_EXTRAEXPANDED;
1177                 else if(!strcasecmp(entry->swidth, "ultraexpanded"))
1178                         entry->style |= FL_WIDTH_ULTRAEXPANDED;
1179                 else
1180                         entry->style |= FL_WIDTH_NORMAL;
1181
1182                 fontlist->append(entry);
1183                 if( font_debug )
1184                         dump_font_entry(stdout, "font 0: ", entry);
1185
1186 //              printf("TitleMain::build_fonts %s: success\n",  entry->path);
1187 //printf("TitleMain::build_fonts 2\n");
1188         }
1189         pclose(in);
1190
1191         if( bc_font_path && bc_font_path[0] == ':' )
1192                 return 0;
1193
1194 // Load all the fonts from fontconfig
1195         FcPattern *pat;
1196         FcFontSet *fs;
1197         FcObjectSet *os;
1198         FcChar8 *family, *file, *foundry, *style, *format;
1199         int slant, spacing, width, weight;
1200         int force_style = 0;
1201 // if you want limit search to TrueType put 1
1202         int limit_to_trutype = 1;
1203         FcConfig *config;
1204         int i;
1205         char tmpstring[BCTEXTLEN];
1206         if(!FcInit())
1207                 return 1;
1208         config = FcConfigGetCurrent();
1209         FcConfigSetRescanInterval(config, 0);
1210
1211         pat = FcPatternCreate();
1212         os = FcObjectSetBuild ( FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
1213                 FC_WIDTH, FC_SLANT, FC_FONTFORMAT, FC_SPACING, FC_STYLE, (char *) 0);
1214         FcPatternAddBool(pat, FC_SCALABLE, true);
1215
1216         if(language[0]) {
1217                 char langstr[LEN_LANG * 3];
1218                 strcpy(langstr, language);
1219
1220                 if(region[0]) {
1221                         strcat(langstr, "-");
1222                         strcat(langstr, region);
1223                 }
1224
1225                 FcLangSet *ls =  FcLangSetCreate();
1226                 if(FcLangSetAdd(ls, (const FcChar8*)langstr))
1227                 if(FcPatternAddLangSet(pat, FC_LANG, ls))
1228                 FcLangSetDestroy(ls);
1229         }
1230
1231         fs = FcFontList(config, pat, os);
1232         FcPatternDestroy(pat);
1233         FcObjectSetDestroy(os);
1234
1235         for (i = 0; fs && i < fs->nfont; i++) {
1236                 FcPattern *font = fs->fonts[i];
1237                 force_style = 0;
1238                 FcPatternGetString(font, FC_FONTFORMAT, 0, &format);
1239                 //on this point you can limit font search
1240                 if(limit_to_trutype && strcmp((char *)format, "TrueType"))
1241                         continue;
1242
1243                 sprintf(tmpstring, "%s", format);
1244                 BC_FontEntry *entry = new BC_FontEntry;
1245                 if(FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
1246                         entry->path = cstrdup((char*)file);
1247                 }
1248
1249                 if(FcPatternGetString(font, FC_FOUNDRY, 0, &foundry) == FcResultMatch) {
1250                         entry->foundry = cstrdup((char*)foundry);
1251                 }
1252
1253                 if(FcPatternGetInteger(font, FC_WEIGHT, 0, &weight) == FcResultMatch) {
1254                         switch(weight) {
1255                         case FC_WEIGHT_THIN:
1256                         case FC_WEIGHT_EXTRALIGHT:
1257                         case FC_WEIGHT_LIGHT:
1258                         case FC_WEIGHT_BOOK:
1259                                 force_style = 1;
1260                                 entry->weight = cstrdup("medium");
1261                                 break;
1262
1263                         case FC_WEIGHT_NORMAL:
1264                         case FC_WEIGHT_MEDIUM:
1265                         default:
1266                                 entry->weight = cstrdup("medium");
1267                                 break;
1268
1269                         case FC_WEIGHT_BLACK:
1270                         case FC_WEIGHT_SEMIBOLD:
1271                         case FC_WEIGHT_BOLD:
1272                                 entry->weight = cstrdup("bold");
1273                                 entry->fixed_style |= BC_FONT_BOLD;
1274                                 break;
1275
1276                         case FC_WEIGHT_EXTRABOLD:
1277                         case FC_WEIGHT_EXTRABLACK:
1278                                 force_style = 1;
1279                                 entry->weight = cstrdup("bold");
1280                                 entry->fixed_style |= BC_FONT_BOLD;
1281                                 break;
1282                         }
1283                 }
1284
1285                 if(FcPatternGetString(font, FC_FAMILY, 0, &family) == FcResultMatch)
1286                         entry->family = cstrdup((char*)family);
1287
1288                 if(FcPatternGetInteger(font, FC_SLANT, 0, &slant) == FcResultMatch) {
1289                         switch(slant) {
1290                         case FC_SLANT_ROMAN:
1291                         default:
1292                                 entry->slant = cstrdup("r");
1293                                 entry->style |= FL_SLANT_ROMAN;
1294                                 break;
1295                         case FC_SLANT_ITALIC:
1296                                 entry->slant = cstrdup("i");
1297                                 entry->style |= FL_SLANT_ITALIC;
1298                                 entry->fixed_style |= BC_FONT_ITALIC;
1299                                 break;
1300                         case FC_SLANT_OBLIQUE:
1301                                 entry->slant = cstrdup("o");
1302                                 entry->style |= FL_SLANT_OBLIQUE;
1303                                 entry->fixed_style |= BC_FONT_ITALIC;
1304                                 break;
1305                         }
1306                 }
1307
1308                 if(FcPatternGetInteger(font, FC_WIDTH, 0, &width) == FcResultMatch) {
1309                         switch(width) {
1310                         case FC_WIDTH_ULTRACONDENSED:
1311                                 entry->swidth = cstrdup("ultracondensed");
1312                                 break;
1313
1314                         case FC_WIDTH_EXTRACONDENSED:
1315                                 entry->swidth = cstrdup("extracondensed");
1316                                 break;
1317
1318                         case FC_WIDTH_CONDENSED:
1319                                 entry->swidth = cstrdup("condensed");
1320                                 break;
1321                         case FC_WIDTH_SEMICONDENSED:
1322                                 entry->swidth = cstrdup("semicondensed");
1323                                 break;
1324
1325                         case FC_WIDTH_NORMAL:
1326                         default:
1327                                 entry->swidth = cstrdup("normal");
1328                                 break;
1329
1330                         case FC_WIDTH_SEMIEXPANDED:
1331                                 entry->swidth = cstrdup("semiexpanded");
1332                                 break;
1333
1334                         case FC_WIDTH_EXPANDED:
1335                                 entry->swidth = cstrdup("expanded");
1336                                 break;
1337
1338                         case FC_WIDTH_EXTRAEXPANDED:
1339                                 entry->swidth = cstrdup("extraexpanded");
1340                                 break;
1341
1342                         case FC_WIDTH_ULTRAEXPANDED:
1343                                 entry->swidth = cstrdup("ultraexpanded");
1344                                 break;
1345                         }
1346                 }
1347
1348                 if(FcPatternGetInteger(font, FC_SPACING, 0, &spacing) == FcResultMatch) {
1349                         switch(spacing) {
1350                         case 0:
1351                         default:
1352                                 entry->spacing = cstrdup("p");
1353                                 break;
1354
1355                         case 90:
1356                                 entry->spacing = cstrdup("d");
1357                                 break;
1358
1359                         case 100:
1360                                 entry->spacing = cstrdup("m");
1361                                 break;
1362
1363                         case 110:
1364                                 entry->spacing = cstrdup("c");
1365                                 break;
1366                         }
1367                 }
1368
1369                 // Add fake stuff for compatibility
1370                 entry->adstyle = cstrdup(" ");
1371                 entry->pixelsize = 0;
1372                 entry->pointsize = 0;
1373                 entry->xres = 0;
1374                 entry->yres = 0;
1375                 entry->avg_width = 0;
1376                 entry->registry = cstrdup("utf");
1377                 entry->encoding = cstrdup("8");
1378
1379                 if( FcPatternGetString(font, FC_STYLE, 0, &style) != FcResultMatch )
1380                         force_style = 0;
1381
1382                 // If font has a style unmanaged by titler plugin, force style to be displayed on name
1383                 // in this way we can shown all available fonts styles.
1384                 if(force_style) {
1385                         sprintf(tmpstring, "%s (%s)", entry->family, style);
1386                         entry->displayname = cstrdup(tmpstring);
1387                 }
1388                 else {
1389                         if(strcmp(entry->foundry, "unknown")) {
1390                                 sprintf(tmpstring, "%s (%s)", entry->family, entry->foundry);
1391                                 entry->displayname = cstrdup(tmpstring);
1392                         }
1393                         else {
1394                                 sprintf(tmpstring, "%s", entry->family);
1395                                 entry->displayname = cstrdup(tmpstring);
1396                         }
1397
1398                 }
1399                 fontlist->append(entry);
1400                 if( font_debug )
1401                         dump_font_entry(stdout, "font 1: ", entry);
1402         }
1403
1404         FcFontSetDestroy(fs);
1405         if(freetype_library)
1406                 FT_Done_FreeType(freetype_library);
1407 // for(int i = 0; i < fonts->total; i++)
1408 //      fonts->values[i]->dump();
1409
1410         FcConfigAppFontAddDir(0, (const FcChar8*)search_path);
1411         FcConfigSetRescanInterval(0, 0);
1412
1413         os = FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
1414                 FC_WIDTH, FC_SLANT, FC_SPACING, FC_STYLE, (char *)0);
1415         pat = FcPatternCreate();
1416         FcPatternAddBool(pat, FC_SCALABLE, true);
1417
1418         if(language[0])
1419         {
1420                 char langstr[LEN_LANG * 3];
1421                 strcpy(langstr, language);
1422
1423                 if(region[0])
1424                 {
1425                         strcat(langstr, "-");
1426                         strcat(langstr, region);
1427                 }
1428
1429                 FcLangSet *ls =  FcLangSetCreate();
1430                 if(FcLangSetAdd(ls, (const FcChar8*)langstr))
1431                         if(FcPatternAddLangSet(pat, FC_LANG, ls))
1432                 FcLangSetDestroy(ls);
1433         }
1434
1435         fs = FcFontList(0, pat, os);
1436         FcPatternDestroy(pat);
1437         FcObjectSetDestroy(os);
1438
1439         for(int i = 0; i < fs->nfont; i++)
1440         {
1441                 FcPattern *font = fs->fonts[i];
1442                 BC_FontEntry *entry = new BC_FontEntry;
1443
1444                 FcChar8 *strvalue;
1445                 if(FcPatternGetString(font, FC_FILE, 0, &strvalue) == FcResultMatch)
1446                 {
1447                         entry->path = new char[strlen((char*)strvalue) + 1];
1448                         strcpy(entry->path, (char*)strvalue);
1449                 }
1450
1451                 if(FcPatternGetString(font, FC_FOUNDRY, 0, &strvalue) == FcResultMatch)
1452                 {
1453                         entry->foundry = new char[strlen((char*)strvalue) + 1];
1454                         strcpy(entry->foundry, (char *)strvalue);
1455                 }
1456
1457                 if(FcPatternGetString(font, FC_FAMILY, 0, &strvalue) == FcResultMatch)
1458                 {
1459                         entry->family = new char[strlen((char*)strvalue) + 2];
1460                         strcpy(entry->family, (char*)strvalue);
1461                 }
1462
1463                 int intvalue;
1464                 if(FcPatternGetInteger(font, FC_SLANT, 0, &intvalue) == FcResultMatch)
1465                 {
1466                         switch(intvalue)
1467                         {
1468                         case FC_SLANT_ROMAN:
1469                         default:
1470                                 entry->style |= FL_SLANT_ROMAN;
1471                                 break;
1472
1473                         case FC_SLANT_ITALIC:
1474                                 entry->style |= FL_SLANT_ITALIC;
1475                                 break;
1476
1477                         case FC_SLANT_OBLIQUE:
1478                                 entry->style |= FL_SLANT_OBLIQUE;
1479                                 break;
1480                         }
1481                 }
1482
1483                 if(FcPatternGetInteger(font, FC_WEIGHT, 0, &intvalue) == FcResultMatch)
1484                 {
1485                         switch(intvalue)
1486                         {
1487                         case FC_WEIGHT_THIN:
1488                                 entry->style |= FL_WEIGHT_THIN;
1489                                 break;
1490
1491                         case FC_WEIGHT_EXTRALIGHT:
1492                                 entry->style |= FL_WEIGHT_EXTRALIGHT;
1493                                 break;
1494
1495                         case FC_WEIGHT_LIGHT:
1496                                 entry->style |= FL_WEIGHT_LIGHT;
1497                                 break;
1498
1499                         case FC_WEIGHT_BOOK:
1500                                 entry->style |= FL_WEIGHT_BOOK;
1501                                 break;
1502
1503                         case FC_WEIGHT_NORMAL:
1504                         default:
1505                                 entry->style |= FL_WEIGHT_NORMAL;
1506                                 break;
1507
1508                         case FC_WEIGHT_MEDIUM:
1509                                 entry->style |= FL_WEIGHT_MEDIUM;
1510                                 break;
1511
1512                         case FC_WEIGHT_DEMIBOLD:
1513                                 entry->style |= FL_WEIGHT_DEMIBOLD;
1514                                 break;
1515
1516                         case FC_WEIGHT_BOLD:
1517                                 entry->style |= FL_WEIGHT_BOLD;
1518                                 break;
1519
1520                         case FC_WEIGHT_EXTRABOLD:
1521                                 entry->style |= FL_WEIGHT_EXTRABOLD;
1522                                 break;
1523
1524                         case FC_WEIGHT_BLACK:
1525                                 entry->style |= FL_WEIGHT_BLACK;
1526                                 break;
1527
1528                         case FC_WEIGHT_EXTRABLACK:
1529                                 entry->style |= FL_WEIGHT_EXTRABLACK;
1530                                 break;
1531                         }
1532                 }
1533
1534                 if(FcPatternGetInteger(font, FC_WIDTH, 0, &intvalue) == FcResultMatch)
1535                 {
1536                         switch(intvalue)
1537                         {
1538                         case FC_WIDTH_ULTRACONDENSED:
1539                                 entry->style |= FL_WIDTH_ULTRACONDENSED;
1540                                 break;
1541
1542                         case FC_WIDTH_EXTRACONDENSED:
1543                                 entry->style |= FL_WIDTH_EXTRACONDENSED;
1544                                 break;
1545
1546                         case FC_WIDTH_CONDENSED:
1547                                 entry->style |= FL_WIDTH_CONDENSED;
1548                                 break;
1549
1550                         case FC_WIDTH_SEMICONDENSED:
1551                                 entry->style = FL_WIDTH_SEMICONDENSED;
1552                                 break;
1553
1554                         case FC_WIDTH_NORMAL:
1555                         default:
1556                                 entry->style |= FL_WIDTH_NORMAL;
1557                                 break;
1558
1559                         case FC_WIDTH_SEMIEXPANDED:
1560                                 entry->style |= FL_WIDTH_SEMIEXPANDED;
1561                                 break;
1562
1563                         case FC_WIDTH_EXPANDED:
1564                                 entry->style |= FL_WIDTH_EXPANDED;
1565                                 break;
1566
1567                         case FC_WIDTH_EXTRAEXPANDED:
1568                                 entry->style |= FL_WIDTH_EXTRAEXPANDED;
1569                                 break;
1570
1571                         case FC_WIDTH_ULTRAEXPANDED:
1572                                 entry->style |= FL_WIDTH_ULTRAEXPANDED;
1573                                 break;
1574                         }
1575                 }
1576                 if(FcPatternGetInteger(font, FC_SPACING, 0, &intvalue) == FcResultMatch)
1577                 {
1578                         switch(intvalue)
1579                         {
1580                         case FC_PROPORTIONAL:
1581                         default:
1582                                 entry->style |= FL_PROPORTIONAL;
1583                                 break;
1584
1585                         case FC_DUAL:
1586                                 entry->style |= FL_DUAL;
1587                                 break;
1588
1589                         case FC_MONO:
1590                                 entry->style |= FL_MONO;
1591                                 break;
1592
1593                         case FC_CHARCELL:
1594                                 entry->style |= FL_CHARCELL;
1595                                 break;
1596                         }
1597                 }
1598                 if(entry->foundry && strcmp(entry->foundry, "unknown"))
1599                 {
1600                         char tempstr[BCTEXTLEN];
1601                         sprintf(tempstr, "%s (%s)", entry->family, entry->foundry);
1602                         entry->displayname = new char[strlen(tempstr) + 1];
1603                         strcpy(entry->displayname, tempstr);
1604                 }
1605                 else
1606                 {
1607                         entry->displayname = new char[strlen(entry->family) + 1];
1608                         strcpy(entry->displayname, entry->family);
1609                 }
1610                 fontlist->append(entry);
1611                 if( font_debug )
1612                         dump_font_entry(stdout, "font 2: ", entry);
1613         }
1614         FcFontSetDestroy(fs);
1615         return 0;
1616 }
1617
1618 #define STYLE_MATCH(fst, stl, msk) ((fst) & (msk) & (stl)) && \
1619        !((fst) & ~(style) & (msk))
1620
1621 BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style,
1622         int mask, int preferred)
1623 {
1624         BC_FontEntry *entry, *style_match, *preferred_match;
1625
1626         if(!fontlist)
1627                 return 0;
1628
1629         style_match = 0;
1630         preferred_match = 0;
1631
1632         if(displayname)
1633         {
1634                 for(int i = 0; i < fontlist->total; i++)
1635                 {
1636                         entry = fontlist->values[i];
1637
1638                         if(strcmp(entry->displayname, displayname) == 0 &&
1639                                         STYLE_MATCH(entry->style, style, mask))
1640                         {
1641                                 if(!style_match)
1642                                         style_match = entry;
1643                                 if(!preferred_match && entry->fixed_style == preferred)
1644                                         preferred_match = entry;
1645                         }
1646                 }
1647                 if(preferred_match)
1648                         return preferred_match;
1649
1650                 if(style_match)
1651                         return style_match;
1652         }
1653
1654 // No exact match - assume normal width font
1655         style |= FL_WIDTH_NORMAL;
1656         mask |= FL_WIDTH_MASK;
1657         style_match = 0;
1658         preferred_match = 0;
1659
1660         for(int i = 0; i < fontlist->total; i++)
1661         {
1662                 entry = fontlist->values[i];
1663
1664                 if(STYLE_MATCH(entry->style, style, mask))
1665                 {
1666                         if(!style_match)
1667                                 style_match = entry;
1668
1669                         if(!preferred_match && (entry->style & preferred))
1670                                 preferred_match = entry;
1671
1672                         if(!strncasecmp(displayname, entry->family,
1673                                         strlen(entry->family)))
1674                         return entry;
1675                 }
1676         }
1677
1678         if(preferred_match)
1679                 return preferred_match;
1680
1681         return style_match;
1682 }
1683
1684 size_t BC_Resources::encode(const char *from_enc, const char *to_enc,
1685         char *input, int input_length, char *output, int output_length)
1686 {
1687         size_t inbytes, outbytes = 0;
1688         iconv_t cd;
1689         char *outbase = output;
1690
1691         if(!from_enc || *from_enc == 0)
1692                 from_enc = "UTF-8";
1693
1694         if(!to_enc || *to_enc == 0)
1695                 to_enc = "UTF-8";
1696
1697         if(input_length < 0)
1698                 inbytes = strlen(input);
1699         else
1700                 inbytes = input_length;
1701
1702         if(strcmp(from_enc, to_enc) && inbytes)
1703         {
1704                 if((cd = iconv_open(to_enc, from_enc)) == (iconv_t)-1)
1705                 {
1706                         printf(_("Conversion from %s to %s is not available\n"),
1707                                 from_enc, to_enc);
1708                         return 0;
1709                 }
1710
1711                 outbytes = output_length - 1;
1712
1713                 iconv(cd, &input, &inbytes, &output, &outbytes);
1714
1715                 iconv_close(cd);
1716                 inbytes = output - outbase;
1717         }
1718         else if(inbytes)
1719         {
1720                 memcpy(output,  input, inbytes);
1721                 outbytes -= inbytes;
1722         }
1723         for(int i = 0; i < 4; i++)
1724         {
1725                 output[i] = 0;
1726                 if(outbytes-- == 0)
1727                         break;
1728         }
1729         return inbytes;
1730 }
1731
1732 void BC_Resources::encode_to_utf8(char *buffer, int buflen)
1733 {
1734         if(BC_Resources::locale_utf8) return;
1735         char lbuf[buflen];
1736         encode(encoding, 0, buffer, buflen, lbuf, buflen);
1737         strcpy(buffer, lbuf);
1738 }
1739
1740 int BC_Resources::find_font_by_char(FT_ULong char_code, char *path_new, const FT_Face oldface)
1741 {
1742         FcPattern *font, *ofont;
1743         FcChar8 *file;
1744         int result = 0;
1745
1746         *path_new = 0;
1747
1748         // Do not search control codes
1749         if(char_code < ' ')
1750                 return 0;
1751
1752         if( (ofont = FcFreeTypeQueryFace(oldface, (const FcChar8*)"", 4097, 0)) != 0 ) {
1753                 if( (font = find_similar_font(char_code, ofont)) != 0 ) {
1754                         if(FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
1755                                 strcpy(path_new, (char*)file);
1756                                 result = 1;
1757                         }
1758                         FcPatternDestroy(font);
1759                 }
1760                 FcPatternDestroy(ofont);
1761         }
1762         return result;
1763 }
1764
1765 FcPattern* BC_Resources::find_similar_font(FT_ULong char_code, FcPattern *oldfont)
1766 {
1767         FcPattern *pat, *font;
1768         FcFontSet *fs;
1769         FcObjectSet *os;
1770         FcCharSet *fcs;
1771         int ival;
1772
1773         // Do not search control codes
1774         if(char_code < ' ')
1775                 return 0;
1776
1777         fontconfig_lock.lock("BC_Resources::find_similar_font");
1778         pat = FcPatternCreate();
1779         os = FcObjectSetBuild(FC_FILE, FC_CHARSET, FC_SCALABLE, FC_FAMILY,
1780                 FC_SLANT, FC_WEIGHT, FC_WIDTH, (char *)0);
1781
1782         FcPatternAddBool(pat, FC_SCALABLE, true);
1783         fcs = FcCharSetCreate();
1784         if(FcCharSetAddChar(fcs, char_code))
1785                 FcPatternAddCharSet(pat, FC_CHARSET, fcs);
1786         FcCharSetDestroy(fcs);
1787         for( int i=0; i<(int)LEN_FCPROP; ++i ) {
1788                 if(FcPatternGetInteger(oldfont, fc_properties[i], 0, &ival) == FcResultMatch)
1789                         FcPatternAddInteger(pat, fc_properties[i], ival);
1790         }
1791         fs = FcFontList(0, pat, os);
1792         for( int i=LEN_FCPROP; --i>=0 && !fs->nfont; ) {
1793                 FcFontSetDestroy(fs);
1794                 FcPatternDel(pat, fc_properties[i]);
1795                 fs = FcFontList(0, pat, os);
1796         }
1797         FcPatternDestroy(pat);
1798         FcObjectSetDestroy(os);
1799
1800         pat = 0;
1801
1802         for (int i = 0; i < fs->nfont; i++)
1803         {
1804                 font = fs->fonts[i];
1805                 if(FcPatternGetCharSet(font, FC_CHARSET, 0, &fcs) == FcResultMatch)
1806                 {
1807                         if(FcCharSetHasChar(fcs, char_code))
1808                         {
1809                                 pat =  FcPatternDuplicate(font);
1810                                 break;
1811                         }
1812                 }
1813         }
1814         FcFontSetDestroy(fs);
1815         fontconfig_lock.unlock();
1816
1817         return pat;
1818 }
1819
1820 void BC_Resources::dump_fonts(FILE *fp)
1821 {
1822         for( int i=0; i<fontlist->total; ++i )
1823                 dump_font_entry(fp, "", fontlist->values[i]);
1824 }
1825
1826 void BC_Resources::dump_font_entry(FILE *fp, const char *cp,  BC_FontEntry *ep)
1827 {
1828         fprintf(fp,"%s%s = %s\n",cp,ep->displayname,ep->path);
1829         fprintf(fp,"  %s:%s:%s:%s:%s:%s:%d:%d:%d:%d:%d:%s:%d:%s:%s:%d\n",
1830                 ep->foundry, ep->family, ep->weight, ep->slant, ep->swidth, ep->adstyle,
1831                 ep->pixelsize, ep->pointsize, ep->xres, ep->yres, ep->style, ep->spacing,
1832                 ep->avg_width, ep->registry, ep->encoding, ep->fixed_style);
1833 }
1834