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;
645 grab_input_focus = 1;
647 text_default = BLACK;
648 highlight_inverse = WHITE ^ BLUE;
649 text_background = WHITE;
650 text_background_hi = LTYELLOW;
651 text_background_noborder_hi = LTGREY;
652 text_background_noborder = -1;
653 text_border1 = DKGREY;
654 text_border2 = BLACK;
655 text_border2_hi = RED;
656 text_border3 = MEGREY;
657 text_border3_hi = LTPINK;
658 text_border4 = WHITE;
659 text_highlight = BLUE;
660 text_selected_highlight = SLBLUE;
661 text_inactive_highlight = MEGREY;
663 toggle_highlight_bg = 0;
664 toggle_text_margin = 0;
666 // Delays must all be different for repeaters
670 tooltip_delay = 1000;
671 tooltip_bg_color = YELLOW;
672 tooltips_enabled = 1;
673 textbox_focus_policy = 0;
675 filebox_margin = 110;
677 filebox_mode = LISTBOX_TEXT;
678 sprintf(filebox_filter, "*");
681 filebox_columntype[0] = FILEBOX_NAME;
682 filebox_columntype[1] = FILEBOX_SIZE;
683 filebox_columntype[2] = FILEBOX_DATE;
684 filebox_columntype[3] = FILEBOX_EXTENSION;
685 filebox_columnwidth[0] = 200;
686 filebox_columnwidth[1] = 100;
687 filebox_columnwidth[2] = 100;
688 filebox_columnwidth[3] = 100;
689 dirbox_columntype[0] = FILEBOX_NAME;
690 dirbox_columntype[1] = FILEBOX_DATE;
691 dirbox_columnwidth[0] = 200;
692 dirbox_columnwidth[1] = 100;
694 filebox_text_images = default_filebox_text_images;
695 filebox_icons_images = default_filebox_icons_images;
696 filebox_updir_images = default_filebox_updir_images;
697 filebox_newfolder_images = default_filebox_newfolder_images;
698 filebox_rename_images = default_filebox_rename_images;
699 filebox_delete_images = default_filebox_delete_images;
700 filebox_reload_images = default_filebox_reload_images;
701 directory_color = BLUE;
704 filebox_sortcolumn = 0;
705 filebox_sortorder = BC_ListBox::SORT_ASCENDING;
706 dirbox_sortcolumn = 0;
707 dirbox_sortorder = BC_ListBox::SORT_ASCENDING;
710 pot_images = default_pot_images;
712 pot_x1 = pot_images[0]->get_w() / 2 - pot_offset;
713 pot_y1 = pot_images[0]->get_h() / 2 - pot_offset;
715 pot_needle_color = BLACK;
717 progress_images = default_progress_images;
721 meter_font = SMALLFONT_3D;
722 meter_font_color = RED;
725 medium_7segment = default_medium_7segment;
727 audiovideo_color = RED;
731 // Xft has priority over font set
733 // But Xft dies in 32 bit mode after some amount of drawing.
741 recursive_resizing = 1;
746 void BC_Resources::del_vframes(VFrame *vframes[], int n)
748 while( --n >= 0 ) delete vframes[n];
751 BC_Resources::~BC_Resources()
754 delete create_window_lock;
755 del_vframes(default_type_to_icon, 6);
757 del_vframes(default_cancel_images, 3);
758 del_vframes(default_ok_images, 3);
759 del_vframes(default_usethis_images, 3);
761 del_vframes(default_checkbox_images, 5);
762 del_vframes(default_radial_images, 5);
763 del_vframes(default_label_images, 5);
765 del_vframes(default_menuitem_data, 3);
766 del_vframes(default_menubar_data, 3);
767 delete default_menu_popup_bg;
768 delete default_menu_bar_bg;
769 delete default_check_image;
770 del_vframes(default_filebox_text_images, 3);
771 del_vframes(default_filebox_icons_images, 3);
772 del_vframes(default_filebox_updir_images, 3);
773 del_vframes(default_filebox_newfolder_images, 3);
774 del_vframes(default_filebox_rename_images, 3);
775 del_vframes(default_filebox_delete_images, 3);
776 del_vframes(default_filebox_reload_images, 3);
777 del_vframes(default_listbox_button, 4);
778 delete default_listbox_bg;
779 del_vframes(default_listbox_expand, 5);
780 del_vframes(default_listbox_column, 3);
781 delete default_listbox_up;
782 delete default_listbox_dn;
783 del_vframes(default_pot_images, 3);
784 del_vframes(default_progress_images, 2);
785 del_vframes(default_medium_7segment, 20);
787 fontlist->remove_all_objects();
793 int BC_Resources::initialize_display(BC_WindowBase *window)
795 // Set up IPC cleanup handlers
798 // Test for shm. Must come before yuv test
804 void BC_Resources::init_shm(BC_WindowBase *window)
807 int (*old_handler)(Display *, XErrorEvent *) =
808 XSetErrorHandler(BC_Resources::x_error_handler);
810 if(XShmQueryExtension(window->display))
812 XShmSegmentInfo test_shm;
813 memset(&test_shm,0,sizeof(test_shm));
814 XImage *test_image = XShmCreateImage(window->display, window->vis,
815 window->default_depth, ZPixmap, (char*)NULL, &test_shm, 5, 5);
816 BC_Resources::error = 0;
817 test_shm.shmid = shmget(IPC_PRIVATE, 5 * test_image->bytes_per_line, (IPC_CREAT | 0600));
818 if(test_shm.shmid != -1) {
819 char *data = (char *)shmat(test_shm.shmid, NULL, 0);
820 if(data != (void *)-1) {
821 shmctl(test_shm.shmid, IPC_RMID, 0);
822 test_shm.shmaddr = data;
823 test_shm.readOnly = 0;
825 if(XShmAttach(window->display, &test_shm)) {
826 XSync(window->display, False);
833 XDestroyImage(test_image);
834 if(BC_Resources::error) use_shm = 0;
836 XSetErrorHandler(old_handler);
842 BC_Synchronous* BC_Resources::get_synchronous()
847 void BC_Resources::set_synchronous(BC_Synchronous *synchronous)
849 this->synchronous = synchronous;
855 int BC_Resources::get_bg_color() { return bg_color; }
857 int BC_Resources::get_bg_shadow1() { return bg_shadow1; }
859 int BC_Resources::get_bg_shadow2() { return bg_shadow2; }
861 int BC_Resources::get_bg_light1() { return bg_light1; }
863 int BC_Resources::get_bg_light2() { return bg_light2; }
866 int BC_Resources::get_id()
868 id_lock->lock("BC_Resources::get_id");
874 int BC_Resources::get_filebox_id()
876 id_lock->lock("BC_Resources::get_filebox_id");
877 int result = filebox_id++;
883 void BC_Resources::set_signals(BC_Signals *signal_handler)
885 BC_Resources::signal_handler = signal_handler;
888 int BC_Resources::init_fontconfig(const char *search_path)
890 if( fontlist ) return 0;
891 fontlist = new ArrayList<BC_FontEntry*>;
893 #define get_str(str,sep,ptr,cond) do { char *out = str; \
894 while( *ptr && !strchr(sep,*ptr) && (cond) ) *out++ = *ptr++; \
898 #define skip_str(sep, ptr) do { \
899 while( *ptr && strchr(sep,*ptr) ) ++ptr; \
902 char find_command[BCTEXTLEN];
903 char *fp = find_command, *ep = fp+sizeof(find_command)-1;
904 fp += snprintf(fp, ep-fp, "find '%s'", search_path);
905 const char *bc_font_path = getenv("BC_FONT_PATH");
907 const char *path = bc_font_path;
908 for( int len=0; *path; path+=len ) {
909 const char *cp = strchr(path,':');
910 len = !cp ? strlen(path) : cp-path;
911 char font_path[BCTEXTLEN];
912 memcpy(font_path, path, len); font_path[len] = 0;
914 fp += snprintf(fp, ep-fp, " '%s'", font_path);
917 fp += snprintf(fp, ep-fp, " -name 'fonts.scale' -print -exec cat {} \\;");
918 FILE *in = popen(find_command, "r");
920 FT_Library freetype_library = 0;
921 // FT_Face freetype_face = 0;
922 // FT_Init_FreeType(&freetype_library);
924 char line[BCTEXTLEN], current_dir[BCTEXTLEN];
927 while( !feof(in) && fgets(line, BCTEXTLEN, in) ) {
928 if(!strlen(line)) break;
932 // Get current directory
934 get_str(current_dir, "\n", in_ptr,1);
935 for( int i=strlen(current_dir); --i>=0 && current_dir[i]!='/'; )
940 //printf("TitleMain::build_fonts %s\n", line);
941 BC_FontEntry *entry = new BC_FontEntry;
942 char string[BCTEXTLEN];
944 get_str(string, "\n", in_ptr, in_ptr[0]!=' ' || in_ptr[1]!='-');
945 entry->path = cstrcat(2, current_dir, string);
947 skip_str(" -", in_ptr);
948 get_str(string, "-\n", in_ptr, 1);
949 if( !string[0] ) { delete entry; continue; }
950 entry->foundry = cstrdup(string);
951 if(*in_ptr == '-') in_ptr++;
953 get_str(string, "-\n", in_ptr, 1);
954 if( !string[0] ) { delete entry; continue; }
955 entry->family = cstrdup(string);
956 if(*in_ptr == '-') in_ptr++;
958 get_str(string, "-\n", in_ptr, 1);
959 entry->weight = cstrdup(string);
960 if(*in_ptr == '-') in_ptr++;
962 get_str(string, "-\n", in_ptr, 1);
963 entry->slant = cstrdup(string);
964 if(*in_ptr == '-') in_ptr++;
966 get_str(string, "-\n", in_ptr, 1);
967 entry->swidth = cstrdup(string);
968 if(*in_ptr == '-') in_ptr++;
970 get_str(string, "-\n", in_ptr, 1);
971 entry->adstyle = cstrdup(string);
972 if(*in_ptr == '-') in_ptr++;
974 get_str(string, "-\n", in_ptr, 1);
975 entry->pixelsize = atol(string);
976 if(*in_ptr == '-') in_ptr++;
978 get_str(string, "-\n", in_ptr, 1);
979 entry->pointsize = atol(string);
980 if(*in_ptr == '-') in_ptr++;
982 get_str(string, "-\n", in_ptr, 1);
983 entry->xres = atol(string);
984 if(*in_ptr == '-') in_ptr++;
986 get_str(string, "-\n", in_ptr, 1);
987 entry->yres = atol(string);
988 if(*in_ptr == '-') in_ptr++;
990 get_str(string, "-\n", in_ptr, 1);
991 entry->spacing = cstrdup(string);
992 if(*in_ptr == '-') in_ptr++;
994 get_str(string, "-\n", in_ptr, 1);
995 entry->avg_width = atol(string);
996 if(*in_ptr == '-') in_ptr++;
998 get_str(string, "-\n", in_ptr, 1);
999 entry->registry = cstrdup(string);
1000 if(*in_ptr == '-') in_ptr++;
1002 get_str(string, "-\n", in_ptr, 1);
1003 entry->encoding = cstrdup(string);
1004 if(*in_ptr == '-') in_ptr++;
1007 //printf("TitleMain::build_fonts 1 %s\n", entry->path);
1008 // This takes a real long time to do. Instead just take all fonts
1009 // if(!load_freetype_face(freetype_library,
1010 // freetype_face, entry->path) )
1012 sprintf(line, "%s (%s)", entry->family, entry->foundry);
1013 entry->displayname = cstrdup(line);
1015 if(!strcasecmp(entry->weight, "demibold")) {
1016 entry->fixed_style |= BC_FONT_BOLD;
1017 entry->style |= FL_WEIGHT_DEMIBOLD;
1019 else if(!strcasecmp(entry->weight, "bold")) {
1020 entry->fixed_style |= BC_FONT_BOLD;
1021 entry->style |= FL_WEIGHT_BOLD;
1024 entry->style |= FL_WEIGHT_NORMAL;
1027 if(!strcasecmp(entry->slant, "r")) {
1028 entry->style |= FL_SLANT_ROMAN;
1030 else if(!strcasecmp(entry->slant, "i")) {
1031 entry->style |= FL_SLANT_ITALIC;
1032 entry->fixed_style |= BC_FONT_ITALIC;
1034 else if(!strcasecmp(entry->slant, "o")) {
1035 entry->style |= FL_SLANT_OBLIQUE;
1036 entry->fixed_style |= BC_FONT_ITALIC;
1039 if(!strcasecmp(entry->swidth, "normal"))
1040 entry->style |= FL_WIDTH_NORMAL;
1041 else if(!strcasecmp(entry->swidth, "ultracondensed"))
1042 entry->style |= FL_WIDTH_ULTRACONDENSED;
1043 else if(!strcasecmp(entry->swidth, "extracondensed"))
1044 entry->style |= FL_WIDTH_EXTRACONDENSED;
1045 else if(!strcasecmp(entry->swidth, "condensed"))
1046 entry->style |= FL_WIDTH_CONDENSED;
1047 else if(!strcasecmp(entry->swidth, "semicondensed"))
1048 entry->style |= FL_WIDTH_SEMICONDENSED;
1049 else if(!strcasecmp(entry->swidth, "semiexpanded"))
1050 entry->style |= FL_WIDTH_SEMIEXPANDED;
1051 else if(!strcasecmp(entry->swidth, "expanded"))
1052 entry->style |= FL_WIDTH_EXPANDED;
1053 else if(!strcasecmp(entry->swidth, "extraexpanded"))
1054 entry->style |= FL_WIDTH_EXTRAEXPANDED;
1055 else if(!strcasecmp(entry->swidth, "ultraexpanded"))
1056 entry->style |= FL_WIDTH_ULTRAEXPANDED;
1058 entry->style |= FL_WIDTH_NORMAL;
1060 fontlist->append(entry);
1061 // printf("TitleMain::build_fonts %s: success\n", entry->path);
1062 //printf("TitleMain::build_fonts 2\n");
1067 // Load all the fonts from fontconfig
1071 FcChar8 *family, *file, *foundry, *style, *format;
1072 int slant, spacing, width, weight;
1073 int force_style = 0;
1074 // if you want limit search to TrueType put 1
1075 int limit_to_trutype = 1;
1078 char tmpstring[BCTEXTLEN];
1081 config = FcConfigGetCurrent();
1082 FcConfigSetRescanInterval(config, 0);
1084 pat = FcPatternCreate();
1085 os = FcObjectSetBuild ( FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
1086 FC_WIDTH, FC_SLANT, FC_FONTFORMAT, FC_SPACING, FC_STYLE, (char *) 0);
1087 FcPatternAddBool(pat, FC_SCALABLE, true);
1090 char langstr[LEN_LANG * 3];
1091 strcpy(langstr, language);
1094 strcat(langstr, "-");
1095 strcat(langstr, region);
1098 FcLangSet *ls = FcLangSetCreate();
1099 if(FcLangSetAdd(ls, (const FcChar8*)langstr))
1100 if(FcPatternAddLangSet(pat, FC_LANG, ls))
1101 FcLangSetDestroy(ls);
1104 fs = FcFontList(config, pat, os);
1105 FcPatternDestroy(pat);
1106 FcObjectSetDestroy(os);
1108 for (i = 0; fs && i < fs->nfont; i++) {
1109 FcPattern *font = fs->fonts[i];
1111 FcPatternGetString(font, FC_FONTFORMAT, 0, &format);
1112 //on this point you can limit font search
1113 if(limit_to_trutype && strcmp((char *)format, "TrueType"))
1116 sprintf(tmpstring, "%s", format);
1117 BC_FontEntry *entry = new BC_FontEntry;
1118 if(FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
1119 entry->path = cstrdup((char*)file);
1122 if(FcPatternGetString(font, FC_FOUNDRY, 0, &foundry) == FcResultMatch) {
1123 entry->foundry = cstrdup((char*)foundry);
1126 if(FcPatternGetInteger(font, FC_WEIGHT, 0, &weight) == FcResultMatch) {
1128 case FC_WEIGHT_THIN:
1129 case FC_WEIGHT_EXTRALIGHT:
1130 case FC_WEIGHT_LIGHT:
1131 case FC_WEIGHT_BOOK:
1133 entry->weight = cstrdup("medium");
1136 case FC_WEIGHT_NORMAL:
1137 case FC_WEIGHT_MEDIUM:
1139 entry->weight = cstrdup("medium");
1142 case FC_WEIGHT_BLACK:
1143 case FC_WEIGHT_SEMIBOLD:
1144 case FC_WEIGHT_BOLD:
1145 entry->weight = cstrdup("bold");
1146 entry->fixed_style |= BC_FONT_BOLD;
1149 case FC_WEIGHT_EXTRABOLD:
1150 case FC_WEIGHT_EXTRABLACK:
1152 entry->weight = cstrdup("bold");
1153 entry->fixed_style |= BC_FONT_BOLD;
1158 if(FcPatternGetString(font, FC_FAMILY, 0, &family) == FcResultMatch)
1159 entry->family = cstrdup((char*)family);
1161 if(FcPatternGetInteger(font, FC_SLANT, 0, &slant) == FcResultMatch) {
1163 case FC_SLANT_ROMAN:
1165 entry->slant = cstrdup("r");
1166 entry->style |= FL_SLANT_ROMAN;
1168 case FC_SLANT_ITALIC:
1169 entry->slant = cstrdup("i");
1170 entry->style |= FL_SLANT_ITALIC;
1171 entry->fixed_style |= BC_FONT_ITALIC;
1173 case FC_SLANT_OBLIQUE:
1174 entry->slant = cstrdup("o");
1175 entry->style |= FL_SLANT_OBLIQUE;
1176 entry->fixed_style |= BC_FONT_ITALIC;
1181 if(FcPatternGetInteger(font, FC_WIDTH, 0, &width) == FcResultMatch) {
1183 case FC_WIDTH_ULTRACONDENSED:
1184 entry->swidth = cstrdup("ultracondensed");
1187 case FC_WIDTH_EXTRACONDENSED:
1188 entry->swidth = cstrdup("extracondensed");
1191 case FC_WIDTH_CONDENSED:
1192 entry->swidth = cstrdup("condensed");
1194 case FC_WIDTH_SEMICONDENSED:
1195 entry->swidth = cstrdup("semicondensed");
1198 case FC_WIDTH_NORMAL:
1200 entry->swidth = cstrdup("normal");
1203 case FC_WIDTH_SEMIEXPANDED:
1204 entry->swidth = cstrdup("semiexpanded");
1207 case FC_WIDTH_EXPANDED:
1208 entry->swidth = cstrdup("expanded");
1211 case FC_WIDTH_EXTRAEXPANDED:
1212 entry->swidth = cstrdup("extraexpanded");
1215 case FC_WIDTH_ULTRAEXPANDED:
1216 entry->swidth = cstrdup("ultraexpanded");
1221 if(FcPatternGetInteger(font, FC_SPACING, 0, &spacing) == FcResultMatch) {
1225 entry->spacing = cstrdup("p");
1229 entry->spacing = cstrdup("d");
1233 entry->spacing = cstrdup("m");
1237 entry->spacing = cstrdup("c");
1242 // Add fake stuff for compatibility
1243 entry->adstyle = cstrdup(" ");
1244 entry->pixelsize = 0;
1245 entry->pointsize = 0;
1248 entry->avg_width = 0;
1249 entry->registry = cstrdup("utf");
1250 entry->encoding = cstrdup("8");
1252 if(!FcPatternGetString(font, FC_STYLE, 0, &style) == FcResultMatch)
1255 // If font has a style unmanaged by titler plugin, force style to be displayed on name
1256 // in this way we can shown all available fonts styles.
1258 sprintf(tmpstring, "%s (%s)", entry->family, style);
1259 entry->displayname = cstrdup(tmpstring);
1262 if(strcmp(entry->foundry, "unknown")) {
1263 sprintf(tmpstring, "%s (%s)", entry->family, entry->foundry);
1264 entry->displayname = cstrdup(tmpstring);
1267 sprintf(tmpstring, "%s", entry->family);
1268 entry->displayname = cstrdup(tmpstring);
1272 fontlist->append(entry);
1275 FcFontSetDestroy(fs);
1276 if(freetype_library)
1277 FT_Done_FreeType(freetype_library);
1278 // for(int i = 0; i < fonts->total; i++)
1279 // fonts->values[i]->dump();
1281 FcConfigAppFontAddDir(0, (const FcChar8*)search_path);
1282 FcConfigSetRescanInterval(0, 0);
1284 os = FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
1285 FC_WIDTH, FC_SLANT, FC_SPACING, FC_STYLE, (char *)0);
1286 pat = FcPatternCreate();
1287 FcPatternAddBool(pat, FC_SCALABLE, true);
1291 char langstr[LEN_LANG * 3];
1292 strcpy(langstr, language);
1296 strcat(langstr, "-");
1297 strcat(langstr, region);
1300 FcLangSet *ls = FcLangSetCreate();
1301 if(FcLangSetAdd(ls, (const FcChar8*)langstr))
1302 if(FcPatternAddLangSet(pat, FC_LANG, ls))
1303 FcLangSetDestroy(ls);
1306 fs = FcFontList(0, pat, os);
1307 FcPatternDestroy(pat);
1308 FcObjectSetDestroy(os);
1310 for(int i = 0; i < fs->nfont; i++)
1312 FcPattern *font = fs->fonts[i];
1313 BC_FontEntry *entry = new BC_FontEntry;
1316 if(FcPatternGetString(font, FC_FILE, 0, &strvalue) == FcResultMatch)
1318 entry->path = new char[strlen((char*)strvalue) + 1];
1319 strcpy(entry->path, (char*)strvalue);
1322 if(FcPatternGetString(font, FC_FOUNDRY, 0, &strvalue) == FcResultMatch)
1324 entry->foundry = new char[strlen((char*)strvalue) + 1];
1325 strcpy(entry->foundry, (char *)strvalue);
1328 if(FcPatternGetString(font, FC_FAMILY, 0, &strvalue) == FcResultMatch)
1330 entry->family = new char[strlen((char*)strvalue) + 2];
1331 strcpy(entry->family, (char*)strvalue);
1335 if(FcPatternGetInteger(font, FC_SLANT, 0, &intvalue) == FcResultMatch)
1339 case FC_SLANT_ROMAN:
1341 entry->style |= FL_SLANT_ROMAN;
1344 case FC_SLANT_ITALIC:
1345 entry->style |= FL_SLANT_ITALIC;
1348 case FC_SLANT_OBLIQUE:
1349 entry->style |= FL_SLANT_OBLIQUE;
1354 if(FcPatternGetInteger(font, FC_WEIGHT, 0, &intvalue) == FcResultMatch)
1358 case FC_WEIGHT_THIN:
1359 entry->style |= FL_WEIGHT_THIN;
1362 case FC_WEIGHT_EXTRALIGHT:
1363 entry->style |= FL_WEIGHT_EXTRALIGHT;
1366 case FC_WEIGHT_LIGHT:
1367 entry->style |= FL_WEIGHT_LIGHT;
1370 case FC_WEIGHT_BOOK:
1371 entry->style |= FL_WEIGHT_BOOK;
1374 case FC_WEIGHT_NORMAL:
1376 entry->style |= FL_WEIGHT_NORMAL;
1379 case FC_WEIGHT_MEDIUM:
1380 entry->style |= FL_WEIGHT_MEDIUM;
1383 case FC_WEIGHT_DEMIBOLD:
1384 entry->style |= FL_WEIGHT_DEMIBOLD;
1387 case FC_WEIGHT_BOLD:
1388 entry->style |= FL_WEIGHT_BOLD;
1391 case FC_WEIGHT_EXTRABOLD:
1392 entry->style |= FL_WEIGHT_EXTRABOLD;
1395 case FC_WEIGHT_BLACK:
1396 entry->style |= FL_WEIGHT_BLACK;
1399 case FC_WEIGHT_EXTRABLACK:
1400 entry->style |= FL_WEIGHT_EXTRABLACK;
1405 if(FcPatternGetInteger(font, FC_WIDTH, 0, &intvalue) == FcResultMatch)
1409 case FC_WIDTH_ULTRACONDENSED:
1410 entry->style |= FL_WIDTH_ULTRACONDENSED;
1413 case FC_WIDTH_EXTRACONDENSED:
1414 entry->style |= FL_WIDTH_EXTRACONDENSED;
1417 case FC_WIDTH_CONDENSED:
1418 entry->style |= FL_WIDTH_CONDENSED;
1421 case FC_WIDTH_SEMICONDENSED:
1422 entry->style = FL_WIDTH_SEMICONDENSED;
1425 case FC_WIDTH_NORMAL:
1427 entry->style |= FL_WIDTH_NORMAL;
1430 case FC_WIDTH_SEMIEXPANDED:
1431 entry->style |= FL_WIDTH_SEMIEXPANDED;
1434 case FC_WIDTH_EXPANDED:
1435 entry->style |= FL_WIDTH_EXPANDED;
1438 case FC_WIDTH_EXTRAEXPANDED:
1439 entry->style |= FL_WIDTH_EXTRAEXPANDED;
1442 case FC_WIDTH_ULTRAEXPANDED:
1443 entry->style |= FL_WIDTH_ULTRAEXPANDED;
1447 if(FcPatternGetInteger(font, FC_SPACING, 0, &intvalue) == FcResultMatch)
1451 case FC_PROPORTIONAL:
1453 entry->style |= FL_PROPORTIONAL;
1457 entry->style |= FL_DUAL;
1461 entry->style |= FL_MONO;
1465 entry->style |= FL_CHARCELL;
1469 if(entry->foundry && strcmp(entry->foundry, "unknown"))
1471 char tempstr[BCTEXTLEN];
1472 sprintf(tempstr, "%s (%s)", entry->family, entry->foundry);
1473 entry->displayname = new char[strlen(tempstr) + 1];
1474 strcpy(entry->displayname, tempstr);
1478 entry->displayname = new char[strlen(entry->family) + 1];
1479 strcpy(entry->displayname, entry->family);
1481 fontlist->append(entry);
1483 FcFontSetDestroy(fs);
1487 #define STYLE_MATCH(fst, stl, msk) ((fst) & (msk) & (stl)) && \
1488 !((fst) & ~(style) & (msk))
1490 BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style,
1491 int mask, int preferred)
1493 BC_FontEntry *entry, *style_match, *preferred_match;
1499 preferred_match = 0;
1503 for(int i = 0; i < fontlist->total; i++)
1505 entry = fontlist->values[i];
1507 if(strcmp(entry->displayname, displayname) == 0 &&
1508 STYLE_MATCH(entry->style, style, mask))
1511 style_match = entry;
1512 if(!preferred_match && entry->fixed_style == preferred)
1513 preferred_match = entry;
1517 return preferred_match;
1523 // No exact match - assume normal width font
1524 style |= FL_WIDTH_NORMAL;
1525 mask |= FL_WIDTH_MASK;
1527 preferred_match = 0;
1529 for(int i = 0; i < fontlist->total; i++)
1531 entry = fontlist->values[i];
1533 if(STYLE_MATCH(entry->style, style, mask))
1536 style_match = entry;
1538 if(!preferred_match && (entry->style & preferred))
1539 preferred_match = entry;
1541 if(!strncasecmp(displayname, entry->family,
1542 strlen(entry->family)))
1548 return preferred_match;
1553 size_t BC_Resources::encode(const char *from_enc, const char *to_enc,
1554 char *input, int input_length, char *output, int output_length)
1556 size_t inbytes, outbytes = 0;
1558 char *outbase = output;
1560 if(!from_enc || *from_enc == 0)
1563 if(!to_enc || *to_enc == 0)
1566 if(input_length < 0)
1567 inbytes = strlen(input);
1569 inbytes = input_length;
1571 if(strcmp(from_enc, to_enc) && inbytes)
1573 if((cd = iconv_open(to_enc, from_enc)) == (iconv_t)-1)
1575 printf(_("Conversion from %s to %s is not available\n"),
1580 outbytes = output_length - 1;
1582 iconv(cd, &input, &inbytes, &output, &outbytes);
1585 inbytes = output - outbase;
1589 memcpy(output, input, inbytes);
1590 outbytes -= inbytes;
1592 for(int i = 0; i < 4; i++)
1601 void BC_Resources::encode_to_utf8(char *buffer, int buflen)
1603 if(BC_Resources::locale_utf8) return;
1605 encode(encoding, 0, buffer, buflen, lbuf, buflen);
1606 strcpy(buffer, lbuf);
1609 int BC_Resources::find_font_by_char(FT_ULong char_code, char *path_new, const FT_Face oldface)
1611 FcPattern *font, *ofont;
1617 // Do not search control codes
1621 if( (ofont = FcFreeTypeQueryFace(oldface, (const FcChar8*)"", 4097, 0)) != 0 ) {
1622 if( (font = find_similar_font(char_code, ofont)) != 0 ) {
1623 if(FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
1624 strcpy(path_new, (char*)file);
1627 FcPatternDestroy(font);
1629 FcPatternDestroy(ofont);
1634 FcPattern* BC_Resources::find_similar_font(FT_ULong char_code, FcPattern *oldfont)
1636 FcPattern *pat, *font;
1642 // Do not search control codes
1646 fontconfig_lock.lock("BC_Resources::find_similar_font");
1647 pat = FcPatternCreate();
1648 os = FcObjectSetBuild(FC_FILE, FC_CHARSET, FC_SCALABLE, FC_FAMILY,
1649 FC_SLANT, FC_WEIGHT, FC_WIDTH, (char *)0);
1651 FcPatternAddBool(pat, FC_SCALABLE, true);
1652 fcs = FcCharSetCreate();
1653 if(FcCharSetAddChar(fcs, char_code))
1654 FcPatternAddCharSet(pat, FC_CHARSET, fcs);
1655 FcCharSetDestroy(fcs);
1656 for( int i=0; i<(int)LEN_FCPROP; ++i ) {
1657 if(FcPatternGetInteger(oldfont, fc_properties[i], 0, &ival) == FcResultMatch)
1658 FcPatternAddInteger(pat, fc_properties[i], ival);
1660 fs = FcFontList(0, pat, os);
1661 for( int i=LEN_FCPROP; --i>=0 && !fs->nfont; ) {
1662 FcFontSetDestroy(fs);
1663 FcPatternDel(pat, fc_properties[i]);
1664 fs = FcFontList(0, pat, os);
1666 FcPatternDestroy(pat);
1667 FcObjectSetDestroy(os);
1671 for (int i = 0; i < fs->nfont; i++)
1673 font = fs->fonts[i];
1674 if(FcPatternGetCharSet(font, FC_CHARSET, 0, &fcs) == FcResultMatch)
1676 if(FcCharSetHasChar(fcs, char_code))
1678 pat = FcPatternDuplicate(font);
1683 FcFontSetDestroy(fs);
1684 fontconfig_lock.unlock();
1689 void BC_Resources::dump_fonts(FILE *fp)
1691 for( int i=0; i<fontlist->total; ++i ) {
1692 BC_FontEntry *ep = fontlist->values[i];
1693 fprintf(fp,"%s = %s\n",ep->displayname,ep->path);
1694 fprintf(fp," %s:%s:%s:%s:%s:%s:%d:%d:%d:%d:%d:%s:%d:%s:%s:%d\n",
1695 ep->foundry, ep->family, ep->weight, ep->slant, ep->swidth, ep->adstyle,
1696 ep->pixelsize, ep->pointsize, ep->xres, ep->yres, ep->style, ep->spacing,
1697 ep->avg_width, ep->registry, ep->encoding, ep->fixed_style);