4 * Copyright (C) 2009-2015 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #include "bcdisplayinfo.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"
31 #include "bccmodels.h"
41 #include <X11/extensions/XShm.h>
42 #include <fontconfig/fontconfig.h>
43 #include <fontconfig/fcfreetype.h>
50 int BC_Resources::error = 0;
52 VFrame* BC_Resources::bg_image = 0;
53 VFrame* BC_Resources::menu_bg = 0;
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 const char *BC_Resources::fc_properties[] = { FC_SLANT, FC_WEIGHT, FC_WIDTH };
63 #define LEN_FCPROP (sizeof(BC_Resources::fc_properties) / sizeof(const char*))
65 static const char *def_small_font = "-*-helvetica-medium-r-normal-*-%d-*"; // 10
66 static const char *def_small_font2 = "-*-helvetica-medium-r-normal-*-%d-*"; // 11
67 static const char *def_medium_font = "-*-helvetica-bold-r-normal-*-%d-*"; // 14
68 static const char *def_medium_font2 = "-*-helvetica-bold-r-normal-*-%d-*"; // 14
69 static const char *def_large_font = "-*-helvetica-bold-r-normal-*-%d-*"; // 18
70 static const char *def_large_font2 = "-*-helvetica-bold-r-normal-*-%d-*"; // 20
71 static const char *def_big_font =
72 "-*-bitstream charter-bold-r-normal-*-*-0-%d-%d-p-0-iso8859-1"; // 160
73 static const char *def_big_font2 =
74 "-*-nimbus sans l-bold-r-normal-*-*-0-%d-%d-p-0-iso8859-1"; // 160
75 static const char *def_small_fontset = "-*-helvetica-medium-r-normal-*-%d-*";// 10
76 static const char *def_medium_fontset = "-*-helvetica-bold-r-normal-*-%d-*"; // 14
77 static const char *def_large_fontset = "-*-helvetica-bold-r-normal-*-%d-*"; // 18
78 static const char *def_big_fontset = "-*-helvetica-bold-r-normal-*-%d-*"; // 24
79 static const char *def_small_font_xft = "Sans:pixelsize=%.4f"; // 10.6667
80 static const char *def_small_b_font_xft = "Sans:bold:pixelsize=%.4f"; // 10.6667
81 static const char *def_medium_font_xft = "Sans:pixelsize=%.4f"; // 13.3333
82 static const char *def_medium_b_font_xft = "Sans:bold:pixelsize=%.4f"; // 13.3333
83 static const char *def_large_font_xft = "Sans:pixelsize=%.4f"; // 21.3333
84 static const char *def_large_b_font_xft = "Sans:bold:pixelsize=%.4f"; // 21.3333
85 static const char *def_big_font_xft = "Sans:pixelsize=37.3333"; // 37.3333
86 static const char *def_big_b_font_xft = "Sans:bold:pixelsize=37.33333"; // 37.3333
88 #define default_font_xft2 "-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*"
90 const char* BC_Resources::small_font = 0;
91 const char* BC_Resources::small_font2 = 0;
92 const char* BC_Resources::medium_font = 0;
93 const char* BC_Resources::medium_font2 = 0;
94 const char* BC_Resources::large_font = 0;
95 const char* BC_Resources::large_font2 = 0;
96 const char* BC_Resources::big_font = 0;
97 const char* BC_Resources::big_font2 = 0;
98 const char* BC_Resources::small_fontset = 0;
99 const char* BC_Resources::medium_fontset = 0;
100 const char* BC_Resources::large_fontset = 0;
101 const char* BC_Resources::big_fontset = 0;
102 const char* BC_Resources::small_font_xft = 0;
103 const char* BC_Resources::small_font_xft2 = 0;
104 const char* BC_Resources::small_b_font_xft = 0;
105 const char* BC_Resources::medium_font_xft = 0;
106 const char* BC_Resources::medium_font_xft2 = 0;
107 const char* BC_Resources::medium_b_font_xft = 0;
108 const char* BC_Resources::large_font_xft = 0;
109 const char* BC_Resources::large_font_xft2 = 0;
110 const char* BC_Resources::large_b_font_xft = 0;
111 const char* BC_Resources::big_font_xft = 0;
112 const char* BC_Resources::big_font_xft2 = 0;
113 const char* BC_Resources::big_b_font_xft = 0;
115 #define def_font(v, s...) do { sprintf(string,def_##v,s); v = cstrdup(string); } while(0)
116 #define set_font(v, s) do { sprintf(string, "%s", s); v = cstrdup(string); } while(0)
117 #define iround(v) ((int)(v+0.5))
118 void BC_Resources::init_font_defs(double scale)
120 char string[BCTEXTLEN];
121 def_font(small_font, iround(scale*11));
122 def_font(small_font2, iround(scale*11));
123 def_font(medium_font, iround(scale*14));
124 def_font(medium_font2, iround(scale*14));
125 def_font(large_font, iround(scale*18));
126 def_font(large_font2, iround(scale*20));
127 def_font(big_font, iround(scale*160), iround(scale*160));
128 def_font(big_font2, iround(scale*160), iround(scale*160));
129 def_font(small_fontset, iround(scale*10));
130 def_font(medium_fontset, iround(scale*14));
131 def_font(large_fontset, iround(scale*18));
132 def_font(big_fontset, iround(scale*24));
133 def_font(small_font_xft, (scale*10.6667));
134 def_font(small_b_font_xft, (scale*10.6667));
135 def_font(medium_font_xft, (scale*13.3333));
136 def_font(medium_b_font_xft,(scale*13.3333));
137 def_font(large_font_xft, (scale*21.3333));
138 def_font(large_b_font_xft, (scale*21.3333));
139 def_font(big_font_xft, (scale*37.3333));
140 def_font(big_b_font_xft, (scale*37.3333));
142 set_font(small_font_xft2, default_font_xft2);
143 set_font(medium_font_xft2, default_font_xft2);
144 set_font(large_font_xft2, default_font_xft2);
145 set_font(big_font_xft2, default_font_xft2);
147 void BC_Resources::finit_font_defs()
149 delete [] small_font;
150 delete [] small_font2;
151 delete [] medium_font;
152 delete [] medium_font2;
153 delete [] large_font;
154 delete [] large_font2;
157 delete [] small_fontset;
158 delete [] medium_fontset;
159 delete [] large_fontset;
160 delete [] big_fontset;
161 delete [] small_font_xft;
162 delete [] small_b_font_xft;
163 delete [] medium_font_xft;
164 delete [] medium_b_font_xft;
165 delete [] large_font_xft;
166 delete [] large_b_font_xft;
167 delete [] big_font_xft;
168 delete [] big_b_font_xft;
170 delete [] small_font_xft2;
171 delete [] medium_font_xft2;
172 delete [] large_font_xft2;
173 delete [] big_font_xft2;
176 suffix_to_type_t BC_Resources::suffix_to_type[] =
178 { "m2v", ICON_FILM },
179 { "mov", ICON_FILM },
180 { "mp2", ICON_SOUND },
181 { "mp3", ICON_SOUND },
182 { "ac3", ICON_SOUND },
183 { "mpg", ICON_FILM },
184 { "vob", ICON_FILM },
185 { "ifo", ICON_FILM },
187 { "vts", ICON_FILM },
188 { "wav", ICON_SOUND }
191 BC_Signals* BC_Resources::signal_handler = 0;
192 Mutex BC_Resources::fontconfig_lock("BC_Resources::fonconfig_lock");
194 int BC_Resources::x_error_handler(Display *display, XErrorEvent *event)
196 #if defined(OUTPUT_X_ERROR)
198 XGetErrorText(event->display, event->error_code, string, 1024);
199 fprintf(stderr, "BC_Resources::x_error_handler: error_code=%d opcode=%d,%d %s\n",
206 BC_Resources::error = 1;
207 // This bug only happens in 32 bit mode.
208 // if(sizeof(long) == 4)
209 // BC_WindowBase::get_resources()->use_xft = 0;
213 int BC_Resources::machine_cpus = 1;
215 int BC_Resources::get_machine_cpus()
218 FILE *proc = fopen("/proc/cpuinfo", "r");
220 char string[BCTEXTLEN], *cp;
221 while(!feof(proc) && fgets(string, sizeof(string), proc) ) {
222 if( !strncasecmp(string, "processor", 9) &&
223 (cp = strchr(string, ':')) != 0 ) {
224 int n = atol(cp+1) + 1;
225 if( n > cpus ) cpus = n;
227 else if( !strncasecmp(string, "cpus detected", 13) &&
228 (cp = strchr(string, ':')) != 0 )
236 void BC_Resources::new_vframes(int n, VFrame *vframes[], ...)
239 va_start(ap, vframes);
240 for( int i=0; i<n; ++i )
241 vframes[i] = va_arg(ap, VFrame *);
245 VFrame *BC_Resources::default_type_to_icon[6] = { 0, };
246 VFrame *BC_Resources::default_bar = 0;
247 VFrame *BC_Resources::default_cancel_images[3] = { 0, };
248 VFrame *BC_Resources::default_ok_images[3] = { 0, };
249 VFrame *BC_Resources::default_usethis_images[3] = { 0, };
251 VFrame *BC_Resources::default_checkbox_images[5] = { 0, };
252 VFrame *BC_Resources::default_radial_images[5] = { 0, };
253 VFrame *BC_Resources::default_label_images[5] = { 0, };
255 VFrame *BC_Resources::default_menuitem_data[3] = { 0, };
256 VFrame *BC_Resources::default_menubar_data[3] = { 0, };
257 VFrame *BC_Resources::default_menu_popup_bg = 0;
258 VFrame *BC_Resources::default_menu_bar_bg = 0;
259 VFrame *BC_Resources::default_check_image = 0;
260 VFrame *BC_Resources::default_filebox_text_images[3] = { 0, };
261 VFrame *BC_Resources::default_filebox_icons_images[3] = { 0, };
262 VFrame *BC_Resources::default_filebox_updir_images[3] = { 0, };
263 VFrame *BC_Resources::default_filebox_newfolder_images[3] = { 0, };
264 VFrame *BC_Resources::default_filebox_rename_images[3] = { 0, };
265 VFrame *BC_Resources::default_filebox_delete_images[3] = { 0, };
266 VFrame *BC_Resources::default_filebox_reload_images[3] = { 0, };
267 VFrame *BC_Resources::default_listbox_button[4] = { 0, };
268 VFrame *BC_Resources::default_listbox_bg = 0;
269 VFrame *BC_Resources::default_listbox_expand[5] = { 0, };
270 VFrame *BC_Resources::default_listbox_column[3] = { 0, };
271 VFrame *BC_Resources::default_listbox_up = 0;
272 VFrame *BC_Resources::default_listbox_dn = 0;
273 VFrame *BC_Resources::default_pot_images[3] = { 0, };
274 VFrame *BC_Resources::default_progress_images[2] = { 0, };
275 VFrame *BC_Resources::default_medium_7segment[20] = { 0, };
277 BC_Resources::BC_Resources()
281 double default_scale = 1.0; // display_size/1000.;
282 char *env = getenv("BC_FONT_SCALE");
283 font_scale = env ? atof(env) : default_scale;
284 if( font_scale <= 0 ) font_scale = 1;
285 init_font_defs(font_scale);
286 env = getenv("BC_ICON_SCALE");
287 icon_scale = env ? atof(env) : default_scale;
288 if( icon_scale <= 0 ) icon_scale = 1;
290 id_lock = new Mutex("BC_Resources::id_lock");
291 create_window_lock = new Mutex("BC_Resources::create_window_lock", 1);
293 machine_cpus = get_machine_cpus();
295 for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
296 filebox_history[i].path[0] = 0;
302 little_endian = (*(const u_int32_t*)"\01\0\0\0") & 1;
303 wide_encoding = little_endian ? "UTF32LE" : "UTF32BE";
306 #include "images/file_folder_png.h"
307 #include "images/file_unknown_png.h"
308 #include "images/file_film_png.h"
309 #include "images/file_sound_png.h"
310 #include "images/file_label_png.h"
311 #include "images/file_column_png.h"
312 new_vframes(6,default_type_to_icon,
313 new VFramePng(file_folder_png),
314 new VFramePng(file_unknown_png),
315 new VFramePng(file_film_png),
316 new VFramePng(file_sound_png),
317 new VFramePng(file_label_png),
318 new VFramePng(file_column_png));
320 #include "images/bar_png.h"
321 default_bar = new VFramePng(bar_png);
323 #include "images/cancel_up_png.h"
324 #include "images/cancel_hi_png.h"
325 #include "images/cancel_dn_png.h"
326 new_vframes(3,default_cancel_images,
327 new VFramePng(cancel_up_png),
328 new VFramePng(cancel_hi_png),
329 new VFramePng(cancel_dn_png));
331 #include "images/ok_up_png.h"
332 #include "images/ok_hi_png.h"
333 #include "images/ok_dn_png.h"
334 new_vframes(3,default_ok_images,
335 new VFramePng(ok_up_png),
336 new VFramePng(ok_hi_png),
337 new VFramePng(ok_dn_png));
339 #include "images/usethis_up_png.h"
340 #include "images/usethis_uphi_png.h"
341 #include "images/usethis_dn_png.h"
342 new_vframes(3,default_usethis_images,
343 new VFramePng(usethis_up_png),
344 new VFramePng(usethis_uphi_png),
345 new VFramePng(usethis_dn_png));
348 #include "images/checkbox_checked_png.h"
349 #include "images/checkbox_dn_png.h"
350 #include "images/checkbox_checkedhi_png.h"
351 #include "images/checkbox_up_png.h"
352 #include "images/checkbox_hi_png.h"
353 new_vframes(5,default_checkbox_images,
354 new VFramePng(checkbox_up_png),
355 new VFramePng(checkbox_hi_png),
356 new VFramePng(checkbox_checked_png),
357 new VFramePng(checkbox_dn_png),
358 new VFramePng(checkbox_checkedhi_png));
360 #include "images/radial_checked_png.h"
361 #include "images/radial_dn_png.h"
362 #include "images/radial_checkedhi_png.h"
363 #include "images/radial_up_png.h"
364 #include "images/radial_hi_png.h"
365 new_vframes(5,default_radial_images,
366 new VFramePng(radial_up_png),
367 new VFramePng(radial_hi_png),
368 new VFramePng(radial_checked_png),
369 new VFramePng(radial_dn_png),
370 new VFramePng(radial_checkedhi_png));
372 new_vframes(5,default_label_images,
373 new VFramePng(radial_up_png),
374 new VFramePng(radial_hi_png),
375 new VFramePng(radial_checked_png),
376 new VFramePng(radial_dn_png),
377 new VFramePng(radial_checkedhi_png));
380 #include "images/menuitem_up_png.h"
381 #include "images/menuitem_hi_png.h"
382 #include "images/menuitem_dn_png.h"
383 new_vframes(3,default_menuitem_data,
384 new VFramePng(menuitem_up_png),
385 new VFramePng(menuitem_hi_png),
386 new VFramePng(menuitem_dn_png));
388 #include "images/menubar_up_png.h"
389 #include "images/menubar_hi_png.h"
390 #include "images/menubar_dn_png.h"
391 new_vframes(3,default_menubar_data,
392 new VFramePng(menubar_up_png),
393 new VFramePng(menubar_hi_png),
394 new VFramePng(menubar_dn_png));
396 #include "images/menu_popup_bg_png.h"
397 default_menu_popup_bg = new VFramePng(menu_popup_bg_png);
399 #include "images/menubar_bg_png.h"
400 default_menu_bar_bg = new VFramePng(menubar_bg_png);
402 #include "images/check_png.h"
403 default_check_image = new VFramePng(check_png);
405 #include "images/file_text_up_png.h"
406 #include "images/file_text_hi_png.h"
407 #include "images/file_text_dn_png.h"
408 #include "images/file_icons_up_png.h"
409 #include "images/file_icons_hi_png.h"
410 #include "images/file_icons_dn_png.h"
411 #include "images/file_newfolder_up_png.h"
412 #include "images/file_newfolder_hi_png.h"
413 #include "images/file_newfolder_dn_png.h"
414 #include "images/file_rename_up_png.h"
415 #include "images/file_rename_hi_png.h"
416 #include "images/file_rename_dn_png.h"
417 #include "images/file_updir_up_png.h"
418 #include "images/file_updir_hi_png.h"
419 #include "images/file_updir_dn_png.h"
420 #include "images/file_delete_up_png.h"
421 #include "images/file_delete_hi_png.h"
422 #include "images/file_delete_dn_png.h"
423 #include "images/file_reload_up_png.h"
424 #include "images/file_reload_hi_png.h"
425 #include "images/file_reload_dn_png.h"
426 new_vframes(3,default_filebox_text_images,
427 new VFramePng(file_text_up_png),
428 new VFramePng(file_text_hi_png),
429 new VFramePng(file_text_dn_png));
431 new_vframes(3,default_filebox_icons_images,
432 new VFramePng(file_icons_up_png),
433 new VFramePng(file_icons_hi_png),
434 new VFramePng(file_icons_dn_png));
436 new_vframes(3,default_filebox_updir_images,
437 new VFramePng(file_updir_up_png),
438 new VFramePng(file_updir_hi_png),
439 new VFramePng(file_updir_dn_png));
441 new_vframes(3,default_filebox_newfolder_images,
442 new VFramePng(file_newfolder_up_png),
443 new VFramePng(file_newfolder_hi_png),
444 new VFramePng(file_newfolder_dn_png));
446 new_vframes(3,default_filebox_rename_images,
447 new VFramePng(file_rename_up_png),
448 new VFramePng(file_rename_hi_png),
449 new VFramePng(file_rename_dn_png));
451 new_vframes(3,default_filebox_delete_images,
452 new VFramePng(file_delete_up_png),
453 new VFramePng(file_delete_hi_png),
454 new VFramePng(file_delete_dn_png));
456 new_vframes(3,default_filebox_reload_images,
457 new VFramePng(file_reload_up_png),
458 new VFramePng(file_reload_hi_png),
459 new VFramePng(file_reload_dn_png));
461 #include "images/listbox_button_dn_png.h"
462 #include "images/listbox_button_hi_png.h"
463 #include "images/listbox_button_up_png.h"
464 #include "images/listbox_button_disabled_png.h"
465 new_vframes(4,default_listbox_button,
466 new VFramePng(listbox_button_up_png),
467 new VFramePng(listbox_button_hi_png),
468 new VFramePng(listbox_button_dn_png),
469 new VFramePng(listbox_button_disabled_png));
471 default_listbox_bg = 0;
473 #include "images/listbox_expandchecked_png.h"
474 #include "images/listbox_expandcheckedhi_png.h"
475 #include "images/listbox_expanddn_png.h"
476 #include "images/listbox_expandup_png.h"
477 #include "images/listbox_expanduphi_png.h"
478 new_vframes(5,default_listbox_expand,
479 new VFramePng(listbox_expandup_png),
480 new VFramePng(listbox_expanduphi_png),
481 new VFramePng(listbox_expandchecked_png),
482 new VFramePng(listbox_expanddn_png),
483 new VFramePng(listbox_expandcheckedhi_png));
485 #include "images/listbox_columnup_png.h"
486 #include "images/listbox_columnhi_png.h"
487 #include "images/listbox_columndn_png.h"
488 new_vframes(3,default_listbox_column,
489 new VFramePng(listbox_columnup_png),
490 new VFramePng(listbox_columnhi_png),
491 new VFramePng(listbox_columndn_png));
493 #include "images/listbox_up_png.h"
494 default_listbox_up = new VFramePng(listbox_up_png);
496 #include "images/listbox_dn_png.h"
497 default_listbox_dn = new VFramePng(listbox_dn_png);
499 #include "images/pot_hi_png.h"
500 #include "images/pot_up_png.h"
501 #include "images/pot_dn_png.h"
502 new_vframes(3,default_pot_images,
503 new VFramePng(pot_up_png),
504 new VFramePng(pot_hi_png),
505 new VFramePng(pot_dn_png));
507 #include "images/progress_up_png.h"
508 #include "images/progress_hi_png.h"
509 new_vframes(2,default_progress_images,
510 new VFramePng(progress_up_png),
511 new VFramePng(progress_hi_png));
513 #include "images/7seg_small/0_png.h"
514 #include "images/7seg_small/1_png.h"
515 #include "images/7seg_small/2_png.h"
516 #include "images/7seg_small/3_png.h"
517 #include "images/7seg_small/4_png.h"
518 #include "images/7seg_small/5_png.h"
519 #include "images/7seg_small/6_png.h"
520 #include "images/7seg_small/7_png.h"
521 #include "images/7seg_small/8_png.h"
522 #include "images/7seg_small/9_png.h"
523 #include "images/7seg_small/colon_png.h"
524 #include "images/7seg_small/period_png.h"
525 #include "images/7seg_small/a_png.h"
526 #include "images/7seg_small/b_png.h"
527 #include "images/7seg_small/c_png.h"
528 #include "images/7seg_small/d_png.h"
529 #include "images/7seg_small/e_png.h"
530 #include "images/7seg_small/f_png.h"
531 #include "images/7seg_small/space_png.h"
532 #include "images/7seg_small/dash_png.h"
533 new_vframes(20,default_medium_7segment,
534 new VFramePng(_0_png),
535 new VFramePng(_1_png),
536 new VFramePng(_2_png),
537 new VFramePng(_3_png),
538 new VFramePng(_4_png),
539 new VFramePng(_5_png),
540 new VFramePng(_6_png),
541 new VFramePng(_7_png),
542 new VFramePng(_8_png),
543 new VFramePng(_9_png),
544 new VFramePng(colon_png),
545 new VFramePng(period_png),
546 new VFramePng(a_png),
547 new VFramePng(b_png),
548 new VFramePng(c_png),
549 new VFramePng(d_png),
550 new VFramePng(e_png),
551 new VFramePng(f_png),
552 new VFramePng(space_png),
553 new VFramePng(dash_png));
555 type_to_icon = default_type_to_icon;
556 bar_data = default_bar;
557 check = default_check_image;
558 listbox_button = default_listbox_button;
559 listbox_bg = default_listbox_bg;
560 listbox_expand = default_listbox_expand;
561 listbox_column = default_listbox_column;
562 listbox_up = default_listbox_up;
563 listbox_dn = default_listbox_dn;
564 listbox_title_overlap = 0;
565 listbox_title_margin = 0;
566 listbox_title_color = BLACK;
567 listbox_title_hotspot = 5;
569 listbox_border1 = DKGREY;
570 listbox_border2_hi = RED;
571 listbox_border2 = BLACK;
572 listbox_border3_hi = RED;
573 listbox_border3 = MEGREY;
574 listbox_border4 = WHITE;
575 listbox_selected = BLUE;
576 listbox_highlighted = LTGREY;
577 listbox_inactive = WHITE;
578 listbox_text = BLACK;
581 pan_text_color = YELLOW;
583 generic_button_margin = 15;
584 draw_clock_background=1;
594 bg_light2 = bg_color;
597 border_light1 = bg_color;
598 border_light2 = MEGREY;
599 border_shadow1 = BLACK;
600 border_shadow2 = bg_color;
602 default_text_color = BLACK;
603 disabled_text_color = DMGREY;
605 button_light = MEGREY; // bright corner
606 // button_highlighted = LTGREY; // face when highlighted
607 button_highlighted = 0xffe000; // face when highlighted
608 button_down = MDGREY; // face when down
609 // button_up = MEGREY; // face when up
610 button_up = 0xffc000; // face when up
611 button_shadow = BLACK; // dark corner
612 button_uphighlighted = RED; // upper side when highlighted
615 tumble_duration = 150;
617 ok_images = default_ok_images;
618 cancel_images = default_cancel_images;
619 usethis_button_images = default_usethis_images;
620 filebox_descend_images = default_ok_images;
623 menu_highlighted = LTBLUE;
626 menu_shadow = DKCYAN;
628 menu_title_bg = default_menubar_data;
629 menu_popup_bg = default_menu_popup_bg;
630 menu_bar_bg = default_menu_bar_bg;
632 popupmenu_images = 0;
635 popupmenu_margin = 10;
637 popupmenu_triangle_margin = 10;
640 menu_title_text = BLACK;
641 popup_title_text = BLACK;
642 menu_item_text = BLACK;
643 menu_highlighted_fontcolor = BLACK;
644 progress_text = BLACK;
648 text_default = BLACK;
649 highlight_inverse = WHITE ^ BLUE;
650 text_background = WHITE;
651 text_background_hi = LTYELLOW;
652 text_background_noborder_hi = LTGREY;
653 text_background_noborder = -1;
654 text_border1 = DKGREY;
655 text_border2 = BLACK;
656 text_border2_hi = RED;
657 text_border3 = MEGREY;
658 text_border3_hi = LTPINK;
659 text_border4 = WHITE;
660 text_highlight = BLUE;
661 text_selected_highlight = SLBLUE;
662 text_inactive_highlight = MEGREY;
664 toggle_highlight_bg = 0;
665 toggle_text_margin = 0;
667 // Delays must all be different for repeaters
671 tooltip_delay = 1000;
672 tooltip_bg_color = YELLOW;
673 tooltips_enabled = 1;
674 textbox_focus_policy = 0;
676 filebox_margin = 110;
678 filebox_mode = LISTBOX_TEXT;
679 sprintf(filebox_filter, "*");
682 filebox_columntype[0] = FILEBOX_NAME;
683 filebox_columntype[1] = FILEBOX_SIZE;
684 filebox_columntype[2] = FILEBOX_DATE;
685 filebox_columntype[3] = FILEBOX_EXTENSION;
686 filebox_columnwidth[0] = 200;
687 filebox_columnwidth[1] = 100;
688 filebox_columnwidth[2] = 100;
689 filebox_columnwidth[3] = 100;
690 dirbox_columntype[0] = FILEBOX_NAME;
691 dirbox_columntype[1] = FILEBOX_DATE;
692 dirbox_columnwidth[0] = 200;
693 dirbox_columnwidth[1] = 100;
695 filebox_text_images = default_filebox_text_images;
696 filebox_icons_images = default_filebox_icons_images;
697 filebox_updir_images = default_filebox_updir_images;
698 filebox_newfolder_images = default_filebox_newfolder_images;
699 filebox_rename_images = default_filebox_rename_images;
700 filebox_delete_images = default_filebox_delete_images;
701 filebox_reload_images = default_filebox_reload_images;
702 directory_color = BLUE;
705 filebox_sortcolumn = 0;
706 filebox_sortorder = BC_ListBox::SORT_ASCENDING;
707 dirbox_sortcolumn = 0;
708 dirbox_sortorder = BC_ListBox::SORT_ASCENDING;
711 pot_images = default_pot_images;
713 pot_x1 = pot_images[0]->get_w() / 2 - pot_offset;
714 pot_y1 = pot_images[0]->get_h() / 2 - pot_offset;
716 pot_needle_color = BLACK;
718 progress_images = default_progress_images;
722 meter_font = SMALLFONT_3D;
723 meter_font_color = RED;
726 medium_7segment = default_medium_7segment;
728 audiovideo_color = RED;
732 // Xft has priority over font set
734 // But Xft dies in 32 bit mode after some amount of drawing.
742 recursive_resizing = 1;
747 void BC_Resources::del_vframes(VFrame *vframes[], int n)
749 while( --n >= 0 ) delete vframes[n];
752 BC_Resources::~BC_Resources()
755 delete create_window_lock;
756 del_vframes(default_type_to_icon, 6);
758 del_vframes(default_cancel_images, 3);
759 del_vframes(default_ok_images, 3);
760 del_vframes(default_usethis_images, 3);
762 del_vframes(default_checkbox_images, 5);
763 del_vframes(default_radial_images, 5);
764 del_vframes(default_label_images, 5);
766 del_vframes(default_menuitem_data, 3);
767 del_vframes(default_menubar_data, 3);
768 delete default_menu_popup_bg;
769 delete default_menu_bar_bg;
770 delete default_check_image;
771 del_vframes(default_filebox_text_images, 3);
772 del_vframes(default_filebox_icons_images, 3);
773 del_vframes(default_filebox_updir_images, 3);
774 del_vframes(default_filebox_newfolder_images, 3);
775 del_vframes(default_filebox_rename_images, 3);
776 del_vframes(default_filebox_delete_images, 3);
777 del_vframes(default_filebox_reload_images, 3);
778 del_vframes(default_listbox_button, 4);
779 delete default_listbox_bg;
780 del_vframes(default_listbox_expand, 5);
781 del_vframes(default_listbox_column, 3);
782 delete default_listbox_up;
783 delete default_listbox_dn;
784 del_vframes(default_pot_images, 3);
785 del_vframes(default_progress_images, 2);
786 del_vframes(default_medium_7segment, 20);
788 fontlist->remove_all_objects();
794 int BC_Resources::initialize_display(BC_WindowBase *window)
796 // Set up IPC cleanup handlers
799 // Test for shm. Must come before yuv test
805 void BC_Resources::init_shm(BC_WindowBase *window)
808 int (*old_handler)(Display *, XErrorEvent *) =
809 XSetErrorHandler(BC_Resources::x_error_handler);
811 if(XShmQueryExtension(window->display))
813 XShmSegmentInfo test_shm;
814 memset(&test_shm,0,sizeof(test_shm));
815 XImage *test_image = XShmCreateImage(window->display, window->vis,
816 window->default_depth, ZPixmap, (char*)NULL, &test_shm, 5, 5);
817 BC_Resources::error = 0;
818 test_shm.shmid = shmget(IPC_PRIVATE, 5 * test_image->bytes_per_line, (IPC_CREAT | 0600));
819 if(test_shm.shmid != -1) {
820 char *data = (char *)shmat(test_shm.shmid, NULL, 0);
821 if(data != (void *)-1) {
822 shmctl(test_shm.shmid, IPC_RMID, 0);
823 test_shm.shmaddr = data;
824 test_shm.readOnly = 0;
826 if(XShmAttach(window->display, &test_shm)) {
827 XSync(window->display, False);
834 XDestroyImage(test_image);
835 if(BC_Resources::error) use_shm = 0;
837 XSetErrorHandler(old_handler);
843 BC_Synchronous* BC_Resources::get_synchronous()
848 void BC_Resources::set_synchronous(BC_Synchronous *synchronous)
850 this->synchronous = synchronous;
856 int BC_Resources::get_bg_color() { return bg_color; }
858 int BC_Resources::get_bg_shadow1() { return bg_shadow1; }
860 int BC_Resources::get_bg_shadow2() { return bg_shadow2; }
862 int BC_Resources::get_bg_light1() { return bg_light1; }
864 int BC_Resources::get_bg_light2() { return bg_light2; }
867 int BC_Resources::get_id()
869 id_lock->lock("BC_Resources::get_id");
875 int BC_Resources::get_filebox_id()
877 id_lock->lock("BC_Resources::get_filebox_id");
878 int result = filebox_id++;
884 void BC_Resources::set_signals(BC_Signals *signal_handler)
886 BC_Resources::signal_handler = signal_handler;
889 int BC_Resources::init_fontconfig(const char *search_path)
891 if( fontlist ) return 0;
892 fontlist = new ArrayList<BC_FontEntry*>;
894 #define get_str(str,sep,ptr,cond) do { char *out = str; \
895 while( *ptr && !strchr(sep,*ptr) && (cond) ) *out++ = *ptr++; \
899 #define skip_str(sep, ptr) do { \
900 while( *ptr && strchr(sep,*ptr) ) ++ptr; \
903 char find_command[BCTEXTLEN];
904 char *fp = find_command, *ep = fp+sizeof(find_command)-1;
905 fp += snprintf(fp, ep-fp, "find '%s'", search_path);
906 const char *bc_font_path = getenv("BC_FONT_PATH");
908 const char *path = bc_font_path;
909 for( int len=0; *path; path+=len ) {
910 const char *cp = strchr(path,':');
911 len = !cp ? strlen(path) : cp-path;
912 char font_path[BCTEXTLEN];
913 memcpy(font_path, path, len); font_path[len] = 0;
915 fp += snprintf(fp, ep-fp, " '%s'", font_path);
918 fp += snprintf(fp, ep-fp, " -name 'fonts.scale' -print -exec cat {} \\;");
919 FILE *in = popen(find_command, "r");
921 FT_Library freetype_library = 0;
922 // FT_Face freetype_face = 0;
923 // FT_Init_FreeType(&freetype_library);
925 char line[BCTEXTLEN], current_dir[BCTEXTLEN];
928 while( !feof(in) && fgets(line, BCTEXTLEN, in) ) {
929 if(!strlen(line)) break;
933 // Get current directory
935 get_str(current_dir, "\n", in_ptr,1);
936 for( int i=strlen(current_dir); --i>=0 && current_dir[i]!='/'; )
941 //printf("TitleMain::build_fonts %s\n", line);
942 BC_FontEntry *entry = new BC_FontEntry;
943 char string[BCTEXTLEN];
945 get_str(string, "\n", in_ptr, in_ptr[0]!=' ' || in_ptr[1]!='-');
946 entry->path = cstrcat(2, current_dir, string);
948 skip_str(" -", in_ptr);
949 get_str(string, "-\n", in_ptr, 1);
950 if( !string[0] ) { delete entry; continue; }
951 entry->foundry = cstrdup(string);
952 if(*in_ptr == '-') in_ptr++;
954 get_str(string, "-\n", in_ptr, 1);
955 if( !string[0] ) { delete entry; continue; }
956 entry->family = cstrdup(string);
957 if(*in_ptr == '-') in_ptr++;
959 get_str(string, "-\n", in_ptr, 1);
960 entry->weight = cstrdup(string);
961 if(*in_ptr == '-') in_ptr++;
963 get_str(string, "-\n", in_ptr, 1);
964 entry->slant = cstrdup(string);
965 if(*in_ptr == '-') in_ptr++;
967 get_str(string, "-\n", in_ptr, 1);
968 entry->swidth = cstrdup(string);
969 if(*in_ptr == '-') in_ptr++;
971 get_str(string, "-\n", in_ptr, 1);
972 entry->adstyle = cstrdup(string);
973 if(*in_ptr == '-') in_ptr++;
975 get_str(string, "-\n", in_ptr, 1);
976 entry->pixelsize = atol(string);
977 if(*in_ptr == '-') in_ptr++;
979 get_str(string, "-\n", in_ptr, 1);
980 entry->pointsize = atol(string);
981 if(*in_ptr == '-') in_ptr++;
983 get_str(string, "-\n", in_ptr, 1);
984 entry->xres = atol(string);
985 if(*in_ptr == '-') in_ptr++;
987 get_str(string, "-\n", in_ptr, 1);
988 entry->yres = atol(string);
989 if(*in_ptr == '-') in_ptr++;
991 get_str(string, "-\n", in_ptr, 1);
992 entry->spacing = cstrdup(string);
993 if(*in_ptr == '-') in_ptr++;
995 get_str(string, "-\n", in_ptr, 1);
996 entry->avg_width = atol(string);
997 if(*in_ptr == '-') in_ptr++;
999 get_str(string, "-\n", in_ptr, 1);
1000 entry->registry = cstrdup(string);
1001 if(*in_ptr == '-') in_ptr++;
1003 get_str(string, "-\n", in_ptr, 1);
1004 entry->encoding = cstrdup(string);
1005 if(*in_ptr == '-') in_ptr++;
1008 //printf("TitleMain::build_fonts 1 %s\n", entry->path);
1009 // This takes a real long time to do. Instead just take all fonts
1010 // if(!load_freetype_face(freetype_library,
1011 // freetype_face, entry->path) )
1013 sprintf(line, "%s (%s)", entry->family, entry->foundry);
1014 entry->displayname = cstrdup(line);
1016 if(!strcasecmp(entry->weight, "demibold")) {
1017 entry->fixed_style |= BC_FONT_BOLD;
1018 entry->style |= FL_WEIGHT_DEMIBOLD;
1020 else if(!strcasecmp(entry->weight, "bold")) {
1021 entry->fixed_style |= BC_FONT_BOLD;
1022 entry->style |= FL_WEIGHT_BOLD;
1025 entry->style |= FL_WEIGHT_NORMAL;
1028 if(!strcasecmp(entry->slant, "r")) {
1029 entry->style |= FL_SLANT_ROMAN;
1031 else if(!strcasecmp(entry->slant, "i")) {
1032 entry->style |= FL_SLANT_ITALIC;
1033 entry->fixed_style |= BC_FONT_ITALIC;
1035 else if(!strcasecmp(entry->slant, "o")) {
1036 entry->style |= FL_SLANT_OBLIQUE;
1037 entry->fixed_style |= BC_FONT_ITALIC;
1040 if(!strcasecmp(entry->swidth, "normal"))
1041 entry->style |= FL_WIDTH_NORMAL;
1042 else if(!strcasecmp(entry->swidth, "ultracondensed"))
1043 entry->style |= FL_WIDTH_ULTRACONDENSED;
1044 else if(!strcasecmp(entry->swidth, "extracondensed"))
1045 entry->style |= FL_WIDTH_EXTRACONDENSED;
1046 else if(!strcasecmp(entry->swidth, "condensed"))
1047 entry->style |= FL_WIDTH_CONDENSED;
1048 else if(!strcasecmp(entry->swidth, "semicondensed"))
1049 entry->style |= FL_WIDTH_SEMICONDENSED;
1050 else if(!strcasecmp(entry->swidth, "semiexpanded"))
1051 entry->style |= FL_WIDTH_SEMIEXPANDED;
1052 else if(!strcasecmp(entry->swidth, "expanded"))
1053 entry->style |= FL_WIDTH_EXPANDED;
1054 else if(!strcasecmp(entry->swidth, "extraexpanded"))
1055 entry->style |= FL_WIDTH_EXTRAEXPANDED;
1056 else if(!strcasecmp(entry->swidth, "ultraexpanded"))
1057 entry->style |= FL_WIDTH_ULTRAEXPANDED;
1059 entry->style |= FL_WIDTH_NORMAL;
1061 fontlist->append(entry);
1062 // printf("TitleMain::build_fonts %s: success\n", entry->path);
1063 //printf("TitleMain::build_fonts 2\n");
1068 // Load all the fonts from fontconfig
1072 FcChar8 *family, *file, *foundry, *style, *format;
1073 int slant, spacing, width, weight;
1074 int force_style = 0;
1075 // if you want limit search to TrueType put 1
1076 int limit_to_trutype = 1;
1079 char tmpstring[BCTEXTLEN];
1082 config = FcConfigGetCurrent();
1083 FcConfigSetRescanInterval(config, 0);
1085 pat = FcPatternCreate();
1086 os = FcObjectSetBuild ( FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
1087 FC_WIDTH, FC_SLANT, FC_FONTFORMAT, FC_SPACING, FC_STYLE, (char *) 0);
1088 FcPatternAddBool(pat, FC_SCALABLE, true);
1091 char langstr[LEN_LANG * 3];
1092 strcpy(langstr, language);
1095 strcat(langstr, "-");
1096 strcat(langstr, region);
1099 FcLangSet *ls = FcLangSetCreate();
1100 if(FcLangSetAdd(ls, (const FcChar8*)langstr))
1101 if(FcPatternAddLangSet(pat, FC_LANG, ls))
1102 FcLangSetDestroy(ls);
1105 fs = FcFontList(config, pat, os);
1106 FcPatternDestroy(pat);
1107 FcObjectSetDestroy(os);
1109 for (i = 0; fs && i < fs->nfont; i++) {
1110 FcPattern *font = fs->fonts[i];
1112 FcPatternGetString(font, FC_FONTFORMAT, 0, &format);
1113 //on this point you can limit font search
1114 if(limit_to_trutype && strcmp((char *)format, "TrueType"))
1117 sprintf(tmpstring, "%s", format);
1118 BC_FontEntry *entry = new BC_FontEntry;
1119 if(FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
1120 entry->path = cstrdup((char*)file);
1123 if(FcPatternGetString(font, FC_FOUNDRY, 0, &foundry) == FcResultMatch) {
1124 entry->foundry = cstrdup((char*)foundry);
1127 if(FcPatternGetInteger(font, FC_WEIGHT, 0, &weight) == FcResultMatch) {
1129 case FC_WEIGHT_THIN:
1130 case FC_WEIGHT_EXTRALIGHT:
1131 case FC_WEIGHT_LIGHT:
1132 case FC_WEIGHT_BOOK:
1134 entry->weight = cstrdup("medium");
1137 case FC_WEIGHT_NORMAL:
1138 case FC_WEIGHT_MEDIUM:
1140 entry->weight = cstrdup("medium");
1143 case FC_WEIGHT_BLACK:
1144 case FC_WEIGHT_SEMIBOLD:
1145 case FC_WEIGHT_BOLD:
1146 entry->weight = cstrdup("bold");
1147 entry->fixed_style |= BC_FONT_BOLD;
1150 case FC_WEIGHT_EXTRABOLD:
1151 case FC_WEIGHT_EXTRABLACK:
1153 entry->weight = cstrdup("bold");
1154 entry->fixed_style |= BC_FONT_BOLD;
1159 if(FcPatternGetString(font, FC_FAMILY, 0, &family) == FcResultMatch)
1160 entry->family = cstrdup((char*)family);
1162 if(FcPatternGetInteger(font, FC_SLANT, 0, &slant) == FcResultMatch) {
1164 case FC_SLANT_ROMAN:
1166 entry->slant = cstrdup("r");
1167 entry->style |= FL_SLANT_ROMAN;
1169 case FC_SLANT_ITALIC:
1170 entry->slant = cstrdup("i");
1171 entry->style |= FL_SLANT_ITALIC;
1172 entry->fixed_style |= BC_FONT_ITALIC;
1174 case FC_SLANT_OBLIQUE:
1175 entry->slant = cstrdup("o");
1176 entry->style |= FL_SLANT_OBLIQUE;
1177 entry->fixed_style |= BC_FONT_ITALIC;
1182 if(FcPatternGetInteger(font, FC_WIDTH, 0, &width) == FcResultMatch) {
1184 case FC_WIDTH_ULTRACONDENSED:
1185 entry->swidth = cstrdup("ultracondensed");
1188 case FC_WIDTH_EXTRACONDENSED:
1189 entry->swidth = cstrdup("extracondensed");
1192 case FC_WIDTH_CONDENSED:
1193 entry->swidth = cstrdup("condensed");
1195 case FC_WIDTH_SEMICONDENSED:
1196 entry->swidth = cstrdup("semicondensed");
1199 case FC_WIDTH_NORMAL:
1201 entry->swidth = cstrdup("normal");
1204 case FC_WIDTH_SEMIEXPANDED:
1205 entry->swidth = cstrdup("semiexpanded");
1208 case FC_WIDTH_EXPANDED:
1209 entry->swidth = cstrdup("expanded");
1212 case FC_WIDTH_EXTRAEXPANDED:
1213 entry->swidth = cstrdup("extraexpanded");
1216 case FC_WIDTH_ULTRAEXPANDED:
1217 entry->swidth = cstrdup("ultraexpanded");
1222 if(FcPatternGetInteger(font, FC_SPACING, 0, &spacing) == FcResultMatch) {
1226 entry->spacing = cstrdup("p");
1230 entry->spacing = cstrdup("d");
1234 entry->spacing = cstrdup("m");
1238 entry->spacing = cstrdup("c");
1243 // Add fake stuff for compatibility
1244 entry->adstyle = cstrdup(" ");
1245 entry->pixelsize = 0;
1246 entry->pointsize = 0;
1249 entry->avg_width = 0;
1250 entry->registry = cstrdup("utf");
1251 entry->encoding = cstrdup("8");
1253 if(!FcPatternGetString(font, FC_STYLE, 0, &style) == FcResultMatch)
1256 // If font has a style unmanaged by titler plugin, force style to be displayed on name
1257 // in this way we can shown all available fonts styles.
1259 sprintf(tmpstring, "%s (%s)", entry->family, style);
1260 entry->displayname = cstrdup(tmpstring);
1263 if(strcmp(entry->foundry, "unknown")) {
1264 sprintf(tmpstring, "%s (%s)", entry->family, entry->foundry);
1265 entry->displayname = cstrdup(tmpstring);
1268 sprintf(tmpstring, "%s", entry->family);
1269 entry->displayname = cstrdup(tmpstring);
1273 fontlist->append(entry);
1276 FcFontSetDestroy(fs);
1277 if(freetype_library)
1278 FT_Done_FreeType(freetype_library);
1279 // for(int i = 0; i < fonts->total; i++)
1280 // fonts->values[i]->dump();
1282 FcConfigAppFontAddDir(0, (const FcChar8*)search_path);
1283 FcConfigSetRescanInterval(0, 0);
1285 os = FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
1286 FC_WIDTH, FC_SLANT, FC_SPACING, FC_STYLE, (char *)0);
1287 pat = FcPatternCreate();
1288 FcPatternAddBool(pat, FC_SCALABLE, true);
1292 char langstr[LEN_LANG * 3];
1293 strcpy(langstr, language);
1297 strcat(langstr, "-");
1298 strcat(langstr, region);
1301 FcLangSet *ls = FcLangSetCreate();
1302 if(FcLangSetAdd(ls, (const FcChar8*)langstr))
1303 if(FcPatternAddLangSet(pat, FC_LANG, ls))
1304 FcLangSetDestroy(ls);
1307 fs = FcFontList(0, pat, os);
1308 FcPatternDestroy(pat);
1309 FcObjectSetDestroy(os);
1311 for(int i = 0; i < fs->nfont; i++)
1313 FcPattern *font = fs->fonts[i];
1314 BC_FontEntry *entry = new BC_FontEntry;
1317 if(FcPatternGetString(font, FC_FILE, 0, &strvalue) == FcResultMatch)
1319 entry->path = new char[strlen((char*)strvalue) + 1];
1320 strcpy(entry->path, (char*)strvalue);
1323 if(FcPatternGetString(font, FC_FOUNDRY, 0, &strvalue) == FcResultMatch)
1325 entry->foundry = new char[strlen((char*)strvalue) + 1];
1326 strcpy(entry->foundry, (char *)strvalue);
1329 if(FcPatternGetString(font, FC_FAMILY, 0, &strvalue) == FcResultMatch)
1331 entry->family = new char[strlen((char*)strvalue) + 2];
1332 strcpy(entry->family, (char*)strvalue);
1336 if(FcPatternGetInteger(font, FC_SLANT, 0, &intvalue) == FcResultMatch)
1340 case FC_SLANT_ROMAN:
1342 entry->style |= FL_SLANT_ROMAN;
1345 case FC_SLANT_ITALIC:
1346 entry->style |= FL_SLANT_ITALIC;
1349 case FC_SLANT_OBLIQUE:
1350 entry->style |= FL_SLANT_OBLIQUE;
1355 if(FcPatternGetInteger(font, FC_WEIGHT, 0, &intvalue) == FcResultMatch)
1359 case FC_WEIGHT_THIN:
1360 entry->style |= FL_WEIGHT_THIN;
1363 case FC_WEIGHT_EXTRALIGHT:
1364 entry->style |= FL_WEIGHT_EXTRALIGHT;
1367 case FC_WEIGHT_LIGHT:
1368 entry->style |= FL_WEIGHT_LIGHT;
1371 case FC_WEIGHT_BOOK:
1372 entry->style |= FL_WEIGHT_BOOK;
1375 case FC_WEIGHT_NORMAL:
1377 entry->style |= FL_WEIGHT_NORMAL;
1380 case FC_WEIGHT_MEDIUM:
1381 entry->style |= FL_WEIGHT_MEDIUM;
1384 case FC_WEIGHT_DEMIBOLD:
1385 entry->style |= FL_WEIGHT_DEMIBOLD;
1388 case FC_WEIGHT_BOLD:
1389 entry->style |= FL_WEIGHT_BOLD;
1392 case FC_WEIGHT_EXTRABOLD:
1393 entry->style |= FL_WEIGHT_EXTRABOLD;
1396 case FC_WEIGHT_BLACK:
1397 entry->style |= FL_WEIGHT_BLACK;
1400 case FC_WEIGHT_EXTRABLACK:
1401 entry->style |= FL_WEIGHT_EXTRABLACK;
1406 if(FcPatternGetInteger(font, FC_WIDTH, 0, &intvalue) == FcResultMatch)
1410 case FC_WIDTH_ULTRACONDENSED:
1411 entry->style |= FL_WIDTH_ULTRACONDENSED;
1414 case FC_WIDTH_EXTRACONDENSED:
1415 entry->style |= FL_WIDTH_EXTRACONDENSED;
1418 case FC_WIDTH_CONDENSED:
1419 entry->style |= FL_WIDTH_CONDENSED;
1422 case FC_WIDTH_SEMICONDENSED:
1423 entry->style = FL_WIDTH_SEMICONDENSED;
1426 case FC_WIDTH_NORMAL:
1428 entry->style |= FL_WIDTH_NORMAL;
1431 case FC_WIDTH_SEMIEXPANDED:
1432 entry->style |= FL_WIDTH_SEMIEXPANDED;
1435 case FC_WIDTH_EXPANDED:
1436 entry->style |= FL_WIDTH_EXPANDED;
1439 case FC_WIDTH_EXTRAEXPANDED:
1440 entry->style |= FL_WIDTH_EXTRAEXPANDED;
1443 case FC_WIDTH_ULTRAEXPANDED:
1444 entry->style |= FL_WIDTH_ULTRAEXPANDED;
1448 if(FcPatternGetInteger(font, FC_SPACING, 0, &intvalue) == FcResultMatch)
1452 case FC_PROPORTIONAL:
1454 entry->style |= FL_PROPORTIONAL;
1458 entry->style |= FL_DUAL;
1462 entry->style |= FL_MONO;
1466 entry->style |= FL_CHARCELL;
1470 if(entry->foundry && strcmp(entry->foundry, "unknown"))
1472 char tempstr[BCTEXTLEN];
1473 sprintf(tempstr, "%s (%s)", entry->family, entry->foundry);
1474 entry->displayname = new char[strlen(tempstr) + 1];
1475 strcpy(entry->displayname, tempstr);
1479 entry->displayname = new char[strlen(entry->family) + 1];
1480 strcpy(entry->displayname, entry->family);
1482 fontlist->append(entry);
1484 FcFontSetDestroy(fs);
1488 #define STYLE_MATCH(fst, stl, msk) ((fst) & (msk) & (stl)) && \
1489 !((fst) & ~(style) & (msk))
1491 BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style,
1492 int mask, int preferred)
1494 BC_FontEntry *entry, *style_match, *preferred_match;
1500 preferred_match = 0;
1504 for(int i = 0; i < fontlist->total; i++)
1506 entry = fontlist->values[i];
1508 if(strcmp(entry->displayname, displayname) == 0 &&
1509 STYLE_MATCH(entry->style, style, mask))
1512 style_match = entry;
1513 if(!preferred_match && entry->fixed_style == preferred)
1514 preferred_match = entry;
1518 return preferred_match;
1524 // No exact match - assume normal width font
1525 style |= FL_WIDTH_NORMAL;
1526 mask |= FL_WIDTH_MASK;
1528 preferred_match = 0;
1530 for(int i = 0; i < fontlist->total; i++)
1532 entry = fontlist->values[i];
1534 if(STYLE_MATCH(entry->style, style, mask))
1537 style_match = entry;
1539 if(!preferred_match && (entry->style & preferred))
1540 preferred_match = entry;
1542 if(!strncasecmp(displayname, entry->family,
1543 strlen(entry->family)))
1549 return preferred_match;
1554 size_t BC_Resources::encode(const char *from_enc, const char *to_enc,
1555 char *input, int input_length, char *output, int output_length)
1557 size_t inbytes, outbytes = 0;
1559 char *outbase = output;
1561 if(!from_enc || *from_enc == 0)
1564 if(!to_enc || *to_enc == 0)
1567 if(input_length < 0)
1568 inbytes = strlen(input);
1570 inbytes = input_length;
1572 if(strcmp(from_enc, to_enc) && inbytes)
1574 if((cd = iconv_open(to_enc, from_enc)) == (iconv_t)-1)
1576 printf(_("Conversion from %s to %s is not available\n"),
1581 outbytes = output_length - 1;
1583 iconv(cd, &input, &inbytes, &output, &outbytes);
1586 inbytes = output - outbase;
1590 memcpy(output, input, inbytes);
1591 outbytes -= inbytes;
1593 for(int i = 0; i < 4; i++)
1602 void BC_Resources::encode_to_utf8(char *buffer, int buflen)
1604 if(BC_Resources::locale_utf8) return;
1606 encode(encoding, 0, buffer, buflen, lbuf, buflen);
1607 strcpy(buffer, lbuf);
1610 int BC_Resources::find_font_by_char(FT_ULong char_code, char *path_new, const FT_Face oldface)
1612 FcPattern *font, *ofont;
1618 // Do not search control codes
1622 if( (ofont = FcFreeTypeQueryFace(oldface, (const FcChar8*)"", 4097, 0)) != 0 ) {
1623 if( (font = find_similar_font(char_code, ofont)) != 0 ) {
1624 if(FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
1625 strcpy(path_new, (char*)file);
1628 FcPatternDestroy(font);
1630 FcPatternDestroy(ofont);
1635 FcPattern* BC_Resources::find_similar_font(FT_ULong char_code, FcPattern *oldfont)
1637 FcPattern *pat, *font;
1643 // Do not search control codes
1647 fontconfig_lock.lock("BC_Resources::find_similar_font");
1648 pat = FcPatternCreate();
1649 os = FcObjectSetBuild(FC_FILE, FC_CHARSET, FC_SCALABLE, FC_FAMILY,
1650 FC_SLANT, FC_WEIGHT, FC_WIDTH, (char *)0);
1652 FcPatternAddBool(pat, FC_SCALABLE, true);
1653 fcs = FcCharSetCreate();
1654 if(FcCharSetAddChar(fcs, char_code))
1655 FcPatternAddCharSet(pat, FC_CHARSET, fcs);
1656 FcCharSetDestroy(fcs);
1657 for( int i=0; i<(int)LEN_FCPROP; ++i ) {
1658 if(FcPatternGetInteger(oldfont, fc_properties[i], 0, &ival) == FcResultMatch)
1659 FcPatternAddInteger(pat, fc_properties[i], ival);
1661 fs = FcFontList(0, pat, os);
1662 for( int i=LEN_FCPROP; --i>=0 && !fs->nfont; ) {
1663 FcFontSetDestroy(fs);
1664 FcPatternDel(pat, fc_properties[i]);
1665 fs = FcFontList(0, pat, os);
1667 FcPatternDestroy(pat);
1668 FcObjectSetDestroy(os);
1672 for (int i = 0; i < fs->nfont; i++)
1674 font = fs->fonts[i];
1675 if(FcPatternGetCharSet(font, FC_CHARSET, 0, &fcs) == FcResultMatch)
1677 if(FcCharSetHasChar(fcs, char_code))
1679 pat = FcPatternDuplicate(font);
1684 FcFontSetDestroy(fs);
1685 fontconfig_lock.unlock();
1690 void BC_Resources::dump_fonts(FILE *fp)
1692 for( int i=0; i<fontlist->total; ++i ) {
1693 BC_FontEntry *ep = fontlist->values[i];
1694 fprintf(fp,"%s = %s\n",ep->displayname,ep->path);
1695 fprintf(fp," %s:%s:%s:%s:%s:%s:%d:%d:%d:%d:%d:%s:%d:%s:%s:%d\n",
1696 ep->foundry, ep->family, ep->weight, ep->slant, ep->swidth, ep->adstyle,
1697 ep->pixelsize, ep->pointsize, ep->xres, ep->yres, ep->style, ep->spacing,
1698 ep->avg_width, ep->registry, ep->encoding, ep->fixed_style);