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"
36 #include "workarounds.h"
42 #include <X11/extensions/XShm.h>
43 #include <fontconfig/fontconfig.h>
44 #include <fontconfig/fcfreetype.h>
51 int BC_Resources::error = 0;
53 VFrame* BC_Resources::bg_image = 0;
54 VFrame* BC_Resources::menu_bg = 0;
56 int BC_Resources::locale_utf8 = 0;
57 int BC_Resources::little_endian = 0;
58 char BC_Resources::language[LEN_LANG] = {0};
59 char BC_Resources::region[LEN_LANG] = {0};
60 char BC_Resources::encoding[LEN_ENCOD] = {0};
61 const char *BC_Resources::wide_encoding = 0;
62 ArrayList<BC_FontEntry*> *BC_Resources::fontlist = 0;
63 int BC_Resources::font_debug = 0;
64 const char *BC_Resources::fc_properties[] = { FC_SLANT, FC_WEIGHT, FC_WIDTH };
65 #define LEN_FCPROP (sizeof(BC_Resources::fc_properties) / sizeof(const char*))
67 static const char *def_small_font = "-*-helvetica-medium-r-normal-*-%d-*"; // 10
68 static const char *def_small_font2 = "-*-helvetica-medium-r-normal-*-%d-*"; // 11
69 static const char *def_medium_font = "-*-helvetica-bold-r-normal-*-%d-*"; // 14
70 static const char *def_medium_font2 = "-*-helvetica-bold-r-normal-*-%d-*"; // 14
71 static const char *def_large_font = "-*-helvetica-bold-r-normal-*-%d-*"; // 18
72 static const char *def_large_font2 = "-*-helvetica-bold-r-normal-*-%d-*"; // 20
73 static const char *def_big_font =
74 "-*-bitstream charter-bold-r-normal-*-*-0-%d-%d-p-0-iso8859-1"; // 160
75 static const char *def_big_font2 =
76 "-*-nimbus sans l-bold-r-normal-*-*-0-%d-%d-p-0-iso8859-1"; // 160
77 static const char *def_clock_font = "-*-helvetica-bold-r-normal-*-%d-*"; // 16
78 static const char *def_clock_font2 = "-*-helvetica-bold-r-normal-*-%d-*"; // 18
79 static const char *def_small_fontset = "-*-helvetica-medium-r-normal-*-%d-*";// 10
80 static const char *def_medium_fontset = "-*-helvetica-bold-r-normal-*-%d-*"; // 14
81 static const char *def_large_fontset = "-*-helvetica-bold-r-normal-*-%d-*"; // 18
82 static const char *def_big_fontset = "-*-helvetica-bold-r-normal-*-%d-*"; // 24
83 static const char *def_clock_fontset = "-*-helvetica-bold-r-normal-*-%d-*"; // 16
85 static const char *def_small_font_xft = "Sans:pixelsize=%.4f"; // 10.6667
86 static const char *def_small_b_font_xft = "Sans:bold:pixelsize=%.4f"; // 10.6667
87 static const char *def_medium_font_xft = "Sans:pixelsize=%.4f"; // 13.3333
88 static const char *def_medium_b_font_xft = "Sans:bold:pixelsize=%.4f"; // 13.3333
89 static const char *def_large_font_xft = "Sans:pixelsize=%.4f"; // 21.3333
90 static const char *def_large_b_font_xft = "Sans:bold:pixelsize=%.4f"; // 21.3333
91 static const char *def_big_font_xft = "Sans:pixelsize=37.3333"; // 37.3333
92 static const char *def_big_b_font_xft = "Sans:bold:pixelsize=37.33333"; // 37.3333
93 static const char *def_clock_font_xft = "Sans:pixelsize=%.4f"; // 16
95 #define default_font_xft2 "-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*"
97 const char* BC_Resources::small_font = 0;
98 const char* BC_Resources::small_font2 = 0;
99 const char* BC_Resources::medium_font = 0;
100 const char* BC_Resources::medium_font2 = 0;
101 const char* BC_Resources::large_font = 0;
102 const char* BC_Resources::large_font2 = 0;
103 const char* BC_Resources::big_font = 0;
104 const char* BC_Resources::big_font2 = 0;
105 const char* BC_Resources::clock_font = 0;
106 const char* BC_Resources::clock_font2 = 0;
107 const char* BC_Resources::small_fontset = 0;
108 const char* BC_Resources::medium_fontset = 0;
109 const char* BC_Resources::large_fontset = 0;
110 const char* BC_Resources::big_fontset = 0;
111 const char* BC_Resources::clock_fontset = 0;
112 const char* BC_Resources::small_font_xft = 0;
113 const char* BC_Resources::small_font_xft2 = 0;
114 const char* BC_Resources::small_b_font_xft = 0;
115 const char* BC_Resources::medium_font_xft = 0;
116 const char* BC_Resources::medium_font_xft2 = 0;
117 const char* BC_Resources::medium_b_font_xft = 0;
118 const char* BC_Resources::large_font_xft = 0;
119 const char* BC_Resources::large_font_xft2 = 0;
120 const char* BC_Resources::large_b_font_xft = 0;
121 const char* BC_Resources::big_font_xft = 0;
122 const char* BC_Resources::big_font_xft2 = 0;
123 const char* BC_Resources::big_b_font_xft = 0;
124 const char* BC_Resources::clock_font_xft = 0;
125 const char* BC_Resources::clock_font_xft2 = 0;
127 #define def_font(v, s...) do { sprintf(string,def_##v,s); v = cstrdup(string); } while(0)
128 #define set_font(v, s) do { sprintf(string, "%s", s); v = cstrdup(string); } while(0)
129 #define iround(v) ((int)(v+0.5))
130 void BC_Resources::init_font_defs(double scale)
132 char string[BCTEXTLEN];
133 def_font(small_font, iround(scale*11));
134 def_font(small_font2, iround(scale*11));
135 def_font(medium_font, iround(scale*14));
136 def_font(medium_font2, iround(scale*14));
137 def_font(large_font, iround(scale*18));
138 def_font(large_font2, iround(scale*20));
139 def_font(big_font, iround(scale*160), iround(scale*160));
140 def_font(big_font2, iround(scale*16), iround(scale*16));
141 def_font(clock_font, iround(scale*16));
142 def_font(clock_font2, iround(scale*18));
143 def_font(small_fontset, iround(scale*10));
144 def_font(medium_fontset, iround(scale*14));
145 def_font(large_fontset, iround(scale*18));
146 def_font(big_fontset, iround(scale*24));
147 def_font(clock_fontset, iround(scale*16));
148 def_font(small_font_xft, (scale*10.6667));
149 def_font(small_b_font_xft, (scale*10.6667));
150 def_font(medium_font_xft, (scale*13.3333));
151 def_font(medium_b_font_xft,(scale*13.3333));
152 def_font(large_font_xft, (scale*21.3333));
153 def_font(large_b_font_xft, (scale*21.3333));
154 def_font(big_font_xft, (scale*37.3333));
155 def_font(big_b_font_xft, (scale*37.3333));
156 def_font(clock_font_xft, (scale*16.));
158 set_font(small_font_xft2, default_font_xft2);
159 set_font(medium_font_xft2, default_font_xft2);
160 set_font(large_font_xft2, default_font_xft2);
161 set_font(big_font_xft2, default_font_xft2);
162 set_font(clock_font_xft2, default_font_xft2);
164 void BC_Resources::finit_font_defs()
166 delete [] small_font;
167 delete [] small_font2;
168 delete [] medium_font;
169 delete [] medium_font2;
170 delete [] large_font;
171 delete [] large_font2;
174 delete [] clock_font;
175 delete [] clock_font2;
176 delete [] small_fontset;
177 delete [] medium_fontset;
178 delete [] large_fontset;
179 delete [] big_fontset;
180 delete [] clock_fontset;
181 delete [] small_font_xft;
182 delete [] small_b_font_xft;
183 delete [] medium_font_xft;
184 delete [] medium_b_font_xft;
185 delete [] large_font_xft;
186 delete [] large_b_font_xft;
187 delete [] big_font_xft;
188 delete [] big_b_font_xft;
189 delete [] clock_font_xft;
191 delete [] small_font_xft2;
192 delete [] medium_font_xft2;
193 delete [] large_font_xft2;
194 delete [] big_font_xft2;
195 delete [] clock_font_xft2;
199 suffix_to_type_t BC_Resources::suffix_to_type[] =
201 { "aac", ICON_SOUND },
202 { "ac3", ICON_SOUND },
203 { "dts", ICON_SOUND },
204 { "f4a", ICON_SOUND },
205 { "flac", ICON_SOUND },
206 { "m4a", ICON_SOUND },
207 { "mp2", ICON_SOUND },
208 { "mp3", ICON_SOUND },
209 { "mpc", ICON_SOUND },
210 { "oga", ICON_SOUND },
211 { "ogg", ICON_SOUND },
212 { "opus", ICON_SOUND },
213 { "ra", ICON_SOUND },
214 { "tta", ICON_SOUND },
215 { "vox", ICON_SOUND },
216 { "wav", ICON_SOUND },
217 { "wma", ICON_SOUND },
218 { "3gp", ICON_FILM },
219 { "avi", ICON_FILM },
220 { "bmp", ICON_FILM },
221 { "cr2", ICON_FILM },
222 { "dnxhd", ICON_FILM },
223 { "drc", ICON_FILM },
225 { "dvd", ICON_FILM },
226 { "exr", ICON_FILM },
227 { "f4v", ICON_FILM },
228 { "flv", ICON_FILM },
229 { "gif", ICON_FILM },
230 { "gxf", ICON_FILM },
231 { "h263", ICON_FILM },
232 { "h264", ICON_FILM },
233 { "h265", ICON_FILM },
234 { "hevc", ICON_FILM },
235 { "ifo", ICON_FILM },
236 { "jpeg", ICON_FILM },
237 { "jpg", ICON_FILM },
238 { "m2t", ICON_FILM },
239 { "m2ts", ICON_FILM },
240 { "m2v", ICON_FILM },
241 { "m4p", ICON_FILM },
242 { "m4v", ICON_FILM },
243 { "mkv", ICON_FILM },
244 { "mov", ICON_FILM },
245 { "mp4", ICON_FILM },
246 { "mpe", ICON_FILM },
247 { "mpeg", ICON_FILM },
248 { "mpg", ICON_FILM },
249 { "mpv", ICON_FILM },
250 { "mts", ICON_FILM },
251 { "mxf", ICON_FILM },
252 { "ogv", ICON_FILM },
253 { "pcm", ICON_FILM },
254 { "pgm", ICON_FILM },
255 { "png", ICON_FILM },
256 { "ppm", ICON_FILM },
259 { "rmvb", ICON_FILM },
261 { "swf", ICON_FILM },
262 { "tif", ICON_FILM },
263 { "tiff", ICON_FILM },
265 { "vob", ICON_FILM },
266 { "vts", ICON_FILM },
267 { "webm", ICON_FILM },
268 { "webp", ICON_FILM },
269 { "wmv", ICON_FILM },
270 { "xml", ICON_FILM },
271 { "y4m", ICON_FILM },
275 BC_Signals* BC_Resources::signal_handler = 0;
276 Mutex BC_Resources::fontconfig_lock("BC_Resources::fonconfig_lock");
278 int BC_Resources::x_error_handler(Display *display, XErrorEvent *event)
280 #if defined(OUTPUT_X_ERROR)
282 XGetErrorText(event->display, event->error_code, string, 1024);
283 fprintf(stderr, "BC_Resources::x_error_handler: error_code=%d opcode=%d,%d %s\n",
290 BC_Resources::error = 1;
291 // This bug only happens in 32 bit mode.
292 // if(sizeof(long) == 4)
293 // BC_WindowBase::get_resources()->use_xft = 0;
297 int BC_Resources::machine_cpus = 1;
299 int BC_Resources::get_machine_cpus()
302 FILE *proc = fopen("/proc/cpuinfo", "r");
304 char string[BCTEXTLEN], *cp;
305 while(!feof(proc) && fgets(string, sizeof(string), proc) ) {
306 if( !strncasecmp(string, "processor", 9) &&
307 (cp = strchr(string, ':')) != 0 ) {
308 int n = atol(cp+1) + 1;
309 if( n > cpus ) cpus = n;
311 else if( !strncasecmp(string, "cpus detected", 13) &&
312 (cp = strchr(string, ':')) != 0 )
320 void BC_Resources::new_vframes(int n, VFrame *vframes[], ...)
323 va_start(ap, vframes);
324 for( int i=0; i<n; ++i )
325 vframes[i] = va_arg(ap, VFrame *);
329 VFrame *BC_Resources::default_type_to_icon[6] = { 0, };
330 VFrame *BC_Resources::default_bar = 0;
331 VFrame *BC_Resources::default_cancel_images[3] = { 0, };
332 VFrame *BC_Resources::default_ok_images[3] = { 0, };
333 VFrame *BC_Resources::default_usethis_images[3] = { 0, };
335 VFrame *BC_Resources::default_checkbox_images[5] = { 0, };
336 VFrame *BC_Resources::default_radial_images[5] = { 0, };
337 VFrame *BC_Resources::default_label_images[5] = { 0, };
339 VFrame *BC_Resources::default_menuitem_data[3] = { 0, };
340 VFrame *BC_Resources::default_menubar_data[3] = { 0, };
341 VFrame *BC_Resources::default_menu_popup_bg = 0;
342 VFrame *BC_Resources::default_menu_bar_bg = 0;
343 VFrame *BC_Resources::default_check_image = 0;
344 VFrame *BC_Resources::default_filebox_text_images[3] = { 0, };
345 VFrame *BC_Resources::default_filebox_icons_images[3] = { 0, };
346 VFrame *BC_Resources::default_filebox_updir_images[3] = { 0, };
347 VFrame *BC_Resources::default_filebox_newfolder_images[3] = { 0, };
348 VFrame *BC_Resources::default_filebox_rename_images[3] = { 0, };
349 VFrame *BC_Resources::default_filebox_delete_images[3] = { 0, };
350 VFrame *BC_Resources::default_filebox_reload_images[3] = { 0, };
351 VFrame *BC_Resources::default_filebox_szfmt_images[12] = { 0, };
352 VFrame *BC_Resources::default_listbox_button[4] = { 0, };
353 VFrame *BC_Resources::default_listbox_bg = 0;
354 VFrame *BC_Resources::default_listbox_expand[5] = { 0, };
355 VFrame *BC_Resources::default_listbox_column[3] = { 0, };
356 VFrame *BC_Resources::default_listbox_up = 0;
357 VFrame *BC_Resources::default_listbox_dn = 0;
358 VFrame *BC_Resources::default_pot_images[3] = { 0, };
359 VFrame *BC_Resources::default_progress_images[2] = { 0, };
360 VFrame *BC_Resources::default_medium_7segment[20] = { 0, };
361 VFrame *BC_Resources::default_vscroll_data[10] = { 0, };
362 VFrame *BC_Resources::default_hscroll_data[10] = { 0, };
363 VFrame *BC_Resources::default_icon_img = 0;
365 BC_Resources::BC_Resources(float x_scale, float y_scale)
367 BC_WindowBase::resources = this;
373 if( x_scale <= 0 ) x_scale = 1;
374 if( y_scale <= 0 ) y_scale = x_scale;
375 this->x_scale = x_scale;
376 this->y_scale = y_scale;
377 float default_scale = bmin(x_scale, y_scale);
378 const char *env = getenv("BC_FONT_DEBUG");
379 font_debug = env ? atoi(env) : 0;
380 env = getenv("BC_FONT_SCALE");
381 font_scale = env ? atof(env) : default_scale;
382 if( font_scale <= 0 ) font_scale = 1;
383 init_font_defs(font_scale);
384 env = getenv("BC_ICON_SCALE");
385 icon_scale = env ? atof(env) : default_scale;
386 if( icon_scale <= 0 ) icon_scale = 1;
388 id_lock = new Mutex("BC_Resources::id_lock");
389 create_window_lock = new Mutex("BC_Resources::create_window_lock", 1);
391 machine_cpus = get_machine_cpus();
393 for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
394 filebox_history[i].path[0] = 0;
401 little_endian = (*(const u_int32_t*)"\01\0\0\0") & 1;
402 wide_encoding = little_endian ? "UTF32LE" : "UTF32BE";
405 #include "images/file_folder_png.h"
406 #include "images/file_unknown_png.h"
407 #include "images/file_film_png.h"
408 #include "images/file_sound_png.h"
409 #include "images/file_label_png.h"
410 #include "images/file_column_png.h"
411 new_vframes(6,default_type_to_icon,
412 new VFramePng(file_folder_png),
413 new VFramePng(file_unknown_png),
414 new VFramePng(file_film_png),
415 new VFramePng(file_sound_png),
416 new VFramePng(file_label_png),
417 new VFramePng(file_column_png));
419 #include "images/bar_png.h"
420 default_bar = new VFramePng(bar_png);
422 #include "images/cancel_up_png.h"
423 #include "images/cancel_hi_png.h"
424 #include "images/cancel_dn_png.h"
425 new_vframes(3,default_cancel_images,
426 new VFramePng(cancel_up_png),
427 new VFramePng(cancel_hi_png),
428 new VFramePng(cancel_dn_png));
430 #include "images/ok_up_png.h"
431 #include "images/ok_hi_png.h"
432 #include "images/ok_dn_png.h"
433 new_vframes(3,default_ok_images,
434 new VFramePng(ok_up_png),
435 new VFramePng(ok_hi_png),
436 new VFramePng(ok_dn_png));
438 #include "images/usethis_up_png.h"
439 #include "images/usethis_uphi_png.h"
440 #include "images/usethis_dn_png.h"
441 new_vframes(3,default_usethis_images,
442 new VFramePng(usethis_up_png),
443 new VFramePng(usethis_uphi_png),
444 new VFramePng(usethis_dn_png));
447 #include "images/checkbox_checked_png.h"
448 #include "images/checkbox_dn_png.h"
449 #include "images/checkbox_checkedhi_png.h"
450 #include "images/checkbox_up_png.h"
451 #include "images/checkbox_hi_png.h"
452 new_vframes(5,default_checkbox_images,
453 new VFramePng(checkbox_up_png),
454 new VFramePng(checkbox_hi_png),
455 new VFramePng(checkbox_checked_png),
456 new VFramePng(checkbox_dn_png),
457 new VFramePng(checkbox_checkedhi_png));
459 #include "images/radial_checked_png.h"
460 #include "images/radial_dn_png.h"
461 #include "images/radial_checkedhi_png.h"
462 #include "images/radial_up_png.h"
463 #include "images/radial_hi_png.h"
464 new_vframes(5,default_radial_images,
465 new VFramePng(radial_up_png),
466 new VFramePng(radial_hi_png),
467 new VFramePng(radial_checked_png),
468 new VFramePng(radial_dn_png),
469 new VFramePng(radial_checkedhi_png));
471 new_vframes(5,default_label_images,
472 new VFramePng(radial_up_png),
473 new VFramePng(radial_hi_png),
474 new VFramePng(radial_checked_png),
475 new VFramePng(radial_dn_png),
476 new VFramePng(radial_checkedhi_png));
479 #include "images/menuitem_up_png.h"
480 #include "images/menuitem_hi_png.h"
481 #include "images/menuitem_dn_png.h"
482 new_vframes(3,default_menuitem_data,
483 new VFramePng(menuitem_up_png),
484 new VFramePng(menuitem_hi_png),
485 new VFramePng(menuitem_dn_png));
487 #include "images/menubar_up_png.h"
488 #include "images/menubar_hi_png.h"
489 #include "images/menubar_dn_png.h"
490 new_vframes(3,default_menubar_data,
491 new VFramePng(menubar_up_png),
492 new VFramePng(menubar_hi_png),
493 new VFramePng(menubar_dn_png));
495 #include "images/menu_popup_bg_png.h"
496 default_menu_popup_bg = new VFramePng(menu_popup_bg_png);
498 #include "images/menubar_bg_png.h"
499 default_menu_bar_bg = new VFramePng(menubar_bg_png);
501 #include "images/check_png.h"
502 default_check_image = new VFramePng(check_png);
504 #include "images/file_text_up_png.h"
505 #include "images/file_text_hi_png.h"
506 #include "images/file_text_dn_png.h"
507 new_vframes(3,default_filebox_text_images,
508 new VFramePng(file_text_up_png),
509 new VFramePng(file_text_hi_png),
510 new VFramePng(file_text_dn_png));
512 #include "images/file_icons_up_png.h"
513 #include "images/file_icons_hi_png.h"
514 #include "images/file_icons_dn_png.h"
515 new_vframes(3,default_filebox_icons_images,
516 new VFramePng(file_icons_up_png),
517 new VFramePng(file_icons_hi_png),
518 new VFramePng(file_icons_dn_png));
520 #include "images/file_updir_up_png.h"
521 #include "images/file_updir_hi_png.h"
522 #include "images/file_updir_dn_png.h"
523 new_vframes(3,default_filebox_updir_images,
524 new VFramePng(file_updir_up_png),
525 new VFramePng(file_updir_hi_png),
526 new VFramePng(file_updir_dn_png));
528 #include "images/file_newfolder_up_png.h"
529 #include "images/file_newfolder_hi_png.h"
530 #include "images/file_newfolder_dn_png.h"
531 new_vframes(3,default_filebox_newfolder_images,
532 new VFramePng(file_newfolder_up_png),
533 new VFramePng(file_newfolder_hi_png),
534 new VFramePng(file_newfolder_dn_png));
536 #include "images/file_rename_up_png.h"
537 #include "images/file_rename_hi_png.h"
538 #include "images/file_rename_dn_png.h"
539 new_vframes(3,default_filebox_rename_images,
540 new VFramePng(file_rename_up_png),
541 new VFramePng(file_rename_hi_png),
542 new VFramePng(file_rename_dn_png));
544 #include "images/file_delete_up_png.h"
545 #include "images/file_delete_hi_png.h"
546 #include "images/file_delete_dn_png.h"
547 new_vframes(3,default_filebox_delete_images,
548 new VFramePng(file_delete_up_png),
549 new VFramePng(file_delete_hi_png),
550 new VFramePng(file_delete_dn_png));
552 #include "images/file_reload_up_png.h"
553 #include "images/file_reload_hi_png.h"
554 #include "images/file_reload_dn_png.h"
555 new_vframes(3,default_filebox_reload_images,
556 new VFramePng(file_reload_up_png),
557 new VFramePng(file_reload_hi_png),
558 new VFramePng(file_reload_dn_png));
560 #include "images/file_size_capb_up_png.h"
561 #include "images/file_size_capb_hi_png.h"
562 #include "images/file_size_capb_dn_png.h"
563 #include "images/file_size_lwrb_up_png.h"
564 #include "images/file_size_lwrb_hi_png.h"
565 #include "images/file_size_lwrb_dn_png.h"
566 #include "images/file_size_semi_up_png.h"
567 #include "images/file_size_semi_hi_png.h"
568 #include "images/file_size_semi_dn_png.h"
569 #include "images/file_size_zero_up_png.h"
570 #include "images/file_size_zero_hi_png.h"
571 #include "images/file_size_zero_dn_png.h"
572 new_vframes(12,default_filebox_szfmt_images,
573 new VFramePng(file_size_zero_up_png),
574 new VFramePng(file_size_zero_hi_png),
575 new VFramePng(file_size_zero_dn_png),
576 new VFramePng(file_size_lwrb_up_png),
577 new VFramePng(file_size_lwrb_hi_png),
578 new VFramePng(file_size_lwrb_dn_png),
579 new VFramePng(file_size_capb_up_png),
580 new VFramePng(file_size_capb_hi_png),
581 new VFramePng(file_size_capb_dn_png),
582 new VFramePng(file_size_semi_up_png),
583 new VFramePng(file_size_semi_hi_png),
584 new VFramePng(file_size_semi_dn_png));
586 #include "images/listbox_button_dn_png.h"
587 #include "images/listbox_button_hi_png.h"
588 #include "images/listbox_button_up_png.h"
589 #include "images/listbox_button_disabled_png.h"
590 new_vframes(4,default_listbox_button,
591 new VFramePng(listbox_button_up_png),
592 new VFramePng(listbox_button_hi_png),
593 new VFramePng(listbox_button_dn_png),
594 new VFramePng(listbox_button_disabled_png));
596 default_listbox_bg = 0;
598 #include "images/listbox_expandchecked_png.h"
599 #include "images/listbox_expandcheckedhi_png.h"
600 #include "images/listbox_expanddn_png.h"
601 #include "images/listbox_expandup_png.h"
602 #include "images/listbox_expanduphi_png.h"
603 new_vframes(5,default_listbox_expand,
604 new VFramePng(listbox_expandup_png),
605 new VFramePng(listbox_expanduphi_png),
606 new VFramePng(listbox_expandchecked_png),
607 new VFramePng(listbox_expanddn_png),
608 new VFramePng(listbox_expandcheckedhi_png));
610 #include "images/listbox_columnup_png.h"
611 #include "images/listbox_columnhi_png.h"
612 #include "images/listbox_columndn_png.h"
613 new_vframes(3,default_listbox_column,
614 new VFramePng(listbox_columnup_png),
615 new VFramePng(listbox_columnhi_png),
616 new VFramePng(listbox_columndn_png));
618 #include "images/listbox_up_png.h"
619 default_listbox_up = new VFramePng(listbox_up_png);
621 #include "images/listbox_dn_png.h"
622 default_listbox_dn = new VFramePng(listbox_dn_png);
624 #include "images/pot_hi_png.h"
625 #include "images/pot_up_png.h"
626 #include "images/pot_dn_png.h"
627 new_vframes(3,default_pot_images,
628 new VFramePng(pot_up_png),
629 new VFramePng(pot_hi_png),
630 new VFramePng(pot_dn_png));
632 #include "images/progress_up_png.h"
633 #include "images/progress_hi_png.h"
634 new_vframes(2,default_progress_images,
635 new VFramePng(progress_up_png),
636 new VFramePng(progress_hi_png));
638 #include "images/7seg_small/0_png.h"
639 #include "images/7seg_small/1_png.h"
640 #include "images/7seg_small/2_png.h"
641 #include "images/7seg_small/3_png.h"
642 #include "images/7seg_small/4_png.h"
643 #include "images/7seg_small/5_png.h"
644 #include "images/7seg_small/6_png.h"
645 #include "images/7seg_small/7_png.h"
646 #include "images/7seg_small/8_png.h"
647 #include "images/7seg_small/9_png.h"
648 #include "images/7seg_small/colon_png.h"
649 #include "images/7seg_small/period_png.h"
650 #include "images/7seg_small/a_png.h"
651 #include "images/7seg_small/b_png.h"
652 #include "images/7seg_small/c_png.h"
653 #include "images/7seg_small/d_png.h"
654 #include "images/7seg_small/e_png.h"
655 #include "images/7seg_small/f_png.h"
656 #include "images/7seg_small/space_png.h"
657 #include "images/7seg_small/dash_png.h"
658 new_vframes(20,default_medium_7segment,
659 new VFramePng(_0_png),
660 new VFramePng(_1_png),
661 new VFramePng(_2_png),
662 new VFramePng(_3_png),
663 new VFramePng(_4_png),
664 new VFramePng(_5_png),
665 new VFramePng(_6_png),
666 new VFramePng(_7_png),
667 new VFramePng(_8_png),
668 new VFramePng(_9_png),
669 new VFramePng(colon_png),
670 new VFramePng(period_png),
671 new VFramePng(a_png),
672 new VFramePng(b_png),
673 new VFramePng(c_png),
674 new VFramePng(d_png),
675 new VFramePng(e_png),
676 new VFramePng(f_png),
677 new VFramePng(space_png),
678 new VFramePng(dash_png));
680 #include "images/hscroll_handle_up_png.h"
681 #include "images/hscroll_handle_hi_png.h"
682 #include "images/hscroll_handle_dn_png.h"
683 #include "images/hscroll_handle_bg_png.h"
684 #include "images/hscroll_left_up_png.h"
685 #include "images/hscroll_left_hi_png.h"
686 #include "images/hscroll_left_dn_png.h"
687 #include "images/hscroll_right_up_png.h"
688 #include "images/hscroll_right_hi_png.h"
689 #include "images/hscroll_right_dn_png.h"
690 new_vframes(10,default_hscroll_data,
691 new VFramePng(hscroll_handle_up_png),
692 new VFramePng(hscroll_handle_hi_png),
693 new VFramePng(hscroll_handle_dn_png),
694 new VFramePng(hscroll_handle_bg_png),
695 new VFramePng(hscroll_left_up_png),
696 new VFramePng(hscroll_left_hi_png),
697 new VFramePng(hscroll_left_dn_png),
698 new VFramePng(hscroll_right_up_png),
699 new VFramePng(hscroll_right_hi_png),
700 new VFramePng(hscroll_right_dn_png));
702 #include "images/vscroll_handle_up_png.h"
703 #include "images/vscroll_handle_hi_png.h"
704 #include "images/vscroll_handle_dn_png.h"
705 #include "images/vscroll_handle_bg_png.h"
706 #include "images/vscroll_left_up_png.h"
707 #include "images/vscroll_left_hi_png.h"
708 #include "images/vscroll_left_dn_png.h"
709 #include "images/vscroll_right_up_png.h"
710 #include "images/vscroll_right_hi_png.h"
711 #include "images/vscroll_right_dn_png.h"
712 new_vframes(10,default_vscroll_data,
713 new VFramePng(vscroll_handle_up_png),
714 new VFramePng(vscroll_handle_hi_png),
715 new VFramePng(vscroll_handle_dn_png),
716 new VFramePng(vscroll_handle_bg_png),
717 new VFramePng(vscroll_left_up_png),
718 new VFramePng(vscroll_left_hi_png),
719 new VFramePng(vscroll_left_dn_png),
720 new VFramePng(vscroll_right_up_png),
721 new VFramePng(vscroll_right_hi_png),
722 new VFramePng(vscroll_right_dn_png));
724 #include "images/default_icon_png.h"
725 default_icon_img = new VFramePng(default_icon_png);
727 type_to_icon = default_type_to_icon;
728 bar_data = default_bar;
729 check = default_check_image;
730 listbox_button = default_listbox_button;
731 listbox_bg = default_listbox_bg;
732 listbox_expand = default_listbox_expand;
733 listbox_column = default_listbox_column;
734 listbox_up = default_listbox_up;
735 listbox_dn = default_listbox_dn;
736 hscroll_data = default_hscroll_data;
737 vscroll_data = default_vscroll_data;
738 default_icon = default_icon_img;
740 listbox_title_overlap = 0;
741 listbox_title_margin = 0;
742 listbox_title_color = BLACK;
743 listbox_title_hotspot = xS(5);
745 listbox_border1 = DKGREY;
746 listbox_border2_hi = RED;
747 listbox_border2 = BLACK;
748 listbox_border3_hi = RED;
749 listbox_border3 = MEGREY;
750 listbox_border4 = WHITE;
751 listbox_selected = BLUE;
752 listbox_highlighted = LTGREY;
753 listbox_inactive = WHITE;
754 listbox_text = BLACK;
757 pan_text_color = YELLOW;
759 generic_button_margin = xS(15);
760 draw_clock_background=1;
767 bg_light2 = bg_color;
770 border_light1 = bg_color;
771 border_light2 = MEGREY;
772 border_shadow1 = BLACK;
773 border_shadow2 = bg_color;
775 default_text_color = BLACK;
776 disabled_text_color = DMGREY;
778 button_light = MEGREY; // bright corner
779 // button_highlighted = LTGREY; // face when highlighted
780 button_highlighted = 0xffe000; // face when highlighted
781 button_down = MDGREY; // face when down
782 // button_up = MEGREY; // face when up
783 button_up = 0xffc000; // face when up
784 button_shadow = BLACK; // dark corner
785 button_uphighlighted = RED; // upper side when highlighted
788 tumblepatch_data = 0;
789 tumble_duration = 150;
791 ok_images = default_ok_images;
792 cancel_images = default_cancel_images;
793 usethis_button_images = default_usethis_images;
794 filebox_descend_images = default_ok_images;
797 menu_highlighted = LTBLUE;
800 menu_shadow = DKCYAN;
802 menu_title_bg = default_menubar_data;
803 menu_popup_bg = default_menu_popup_bg;
804 menu_bar_bg = default_menu_bar_bg;
806 popupmenu_images = 0;
809 popupmenu_margin = xS(10);
811 popupmenu_triangle_margin = xS(10);
814 menu_title_text = BLACK;
815 popup_title_text = BLACK;
816 menu_item_text = BLACK;
817 menu_highlighted_fontcolor = BLACK;
818 progress_text = BLACK;
819 grab_input_focus = 1;
821 text_default = BLACK;
822 highlight_inverse = WHITE ^ BLUE;
823 text_background = WHITE;
824 text_background_disarmed = 0xc08080;
825 text_background_hi = LTYELLOW;
826 text_background_noborder_hi = LTGREY;
827 text_background_noborder = -1;
828 text_border1 = DKGREY;
829 text_border2 = BLACK;
830 text_border2_hi = RED;
831 text_border3 = MEGREY;
832 text_border3_hi = LTPINK;
833 text_border4 = WHITE;
834 text_highlight = BLUE;
835 text_selected_highlight = SLBLUE;
836 text_inactive_highlight = MEGREY;
838 toggle_highlight_bg = 0;
839 toggle_text_margin = 0;
841 // Delays must all be different for repeaters
845 tooltip_delay = 1000;
846 tooltip_bg_color = YELLOW;
847 tooltips_enabled = 1;
848 textbox_focus_policy = 0;
850 filebox_margin = yS(110);
851 dirbox_margin = yS(90);
852 filebox_mode = LISTBOX_TEXT;
853 sprintf(filebox_filter, "*");
856 filebox_columntype[0] = FILEBOX_NAME;
857 filebox_columntype[1] = FILEBOX_SIZE;
858 filebox_columntype[2] = FILEBOX_DATE;
859 filebox_columntype[3] = FILEBOX_EXTENSION;
860 filebox_columnwidth[0] = xS(300);
861 filebox_columnwidth[1] = xS(100);
862 filebox_columnwidth[2] = xS(150);
863 filebox_columnwidth[3] = xS(49);
864 dirbox_columntype[0] = FILEBOX_NAME;
865 dirbox_columntype[1] = FILEBOX_DATE;
866 dirbox_columnwidth[0] = xS(400);
867 dirbox_columnwidth[1] = xS(199);
869 filebox_text_images = default_filebox_text_images;
870 filebox_icons_images = default_filebox_icons_images;
871 filebox_updir_images = default_filebox_updir_images;
872 filebox_newfolder_images = default_filebox_newfolder_images;
873 filebox_rename_images = default_filebox_rename_images;
874 filebox_delete_images = default_filebox_delete_images;
875 filebox_reload_images = default_filebox_reload_images;
876 filebox_szfmt_images = default_filebox_szfmt_images;
877 filebox_size_format = FILEBOX_SIZE_RAW;
878 directory_color = BLUE;
881 filebox_sortcolumn = 0;
882 filebox_sortorder = BC_ListBox::SORT_ASCENDING;
883 dirbox_sortcolumn = 0;
884 dirbox_sortorder = BC_ListBox::SORT_ASCENDING;
887 pot_images = default_pot_images;
889 pot_x1 = pot_images[0]->get_w() / 2 - xS(pot_offset);
890 pot_y1 = pot_images[0]->get_h() / 2 - yS(pot_offset);
892 pot_needle_color = BLACK;
894 progress_images = default_progress_images;
898 meter_font = SMALLFONT_3D;
899 meter_font_color = RED;
900 meter_title_w = xS(20);
902 medium_7segment = default_medium_7segment;
904 audiovideo_color = RED;
908 // Xft has priority over font set
910 // But Xft dies in 32 bit mode after some amount of drawing.
916 drag_radius = xS(10);
917 recursive_resizing = 1;
920 void BC_Resources::del_vframes(VFrame *vframes[], int n)
922 while( --n >= 0 ) delete vframes[n];
925 BC_Resources::~BC_Resources()
928 delete create_window_lock;
929 del_vframes(default_type_to_icon, 6);
931 del_vframes(default_cancel_images, 3);
932 del_vframes(default_ok_images, 3);
933 del_vframes(default_usethis_images, 3);
935 del_vframes(default_checkbox_images, 5);
936 del_vframes(default_radial_images, 5);
937 del_vframes(default_label_images, 5);
939 del_vframes(default_menuitem_data, 3);
940 del_vframes(default_menubar_data, 3);
941 delete default_menu_popup_bg;
942 delete default_menu_bar_bg;
943 delete default_check_image;
944 del_vframes(default_filebox_text_images, 3);
945 del_vframes(default_filebox_icons_images, 3);
946 del_vframes(default_filebox_updir_images, 3);
947 del_vframes(default_filebox_newfolder_images, 3);
948 del_vframes(default_filebox_rename_images, 3);
949 del_vframes(default_filebox_delete_images, 3);
950 del_vframes(default_filebox_reload_images, 3);
951 del_vframes(default_filebox_szfmt_images, 12);
952 del_vframes(default_listbox_button, 4);
953 delete default_listbox_bg;
954 del_vframes(default_listbox_expand, 5);
955 del_vframes(default_listbox_column, 3);
956 delete default_listbox_up;
957 delete default_listbox_dn;
958 del_vframes(default_pot_images, 3);
959 del_vframes(default_progress_images, 2);
960 del_vframes(default_medium_7segment, 20);
961 del_vframes(default_vscroll_data, 10);
962 del_vframes(default_hscroll_data, 10);
964 fontlist->remove_all_objects();
967 delete default_icon_img;
971 int BC_Resources::initialize_display(BC_WindowBase *window)
973 // Set up IPC cleanup handlers
976 // Test for shm. Must come before yuv test
982 void BC_Resources::init_shm(BC_WindowBase *window)
985 int (*old_handler)(Display *, XErrorEvent *) =
986 XSetErrorHandler(BC_Resources::x_error_handler);
988 if(XShmQueryExtension(window->display))
990 XShmSegmentInfo test_shm;
991 memset(&test_shm,0,sizeof(test_shm));
992 XImage *test_image = XShmCreateImage(window->display, window->vis,
993 window->default_depth, ZPixmap, (char*)NULL, &test_shm, 5, 5);
994 BC_Resources::error = 0;
995 test_shm.shmid = shmget(IPC_PRIVATE, 5 * test_image->bytes_per_line, (IPC_CREAT | 0600));
996 if(test_shm.shmid != -1) {
997 char *data = (char *)shmat(test_shm.shmid, NULL, 0);
998 if(data != (void *)-1) {
999 shmctl(test_shm.shmid, IPC_RMID, 0);
1000 test_shm.shmaddr = data;
1001 test_shm.readOnly = 0;
1003 if(XShmAttach(window->display, &test_shm)) {
1004 XSync(window->display, False);
1011 XDestroyImage(test_image);
1012 if(BC_Resources::error) use_shm = 0;
1014 XSetErrorHandler(old_handler);
1020 BC_Synchronous* BC_Resources::get_synchronous()
1025 void BC_Resources::set_synchronous(BC_Synchronous *synchronous)
1027 this->synchronous = synchronous;
1033 int BC_Resources::get_bg_color() { return bg_color; }
1035 int BC_Resources::get_bg_shadow1() { return bg_shadow1; }
1037 int BC_Resources::get_bg_shadow2() { return bg_shadow2; }
1039 int BC_Resources::get_bg_light1() { return bg_light1; }
1041 int BC_Resources::get_bg_light2() { return bg_light2; }
1044 int BC_Resources::get_id()
1046 id_lock->lock("BC_Resources::get_id");
1052 int BC_Resources::get_filebox_id()
1054 id_lock->lock("BC_Resources::get_filebox_id");
1055 int result = filebox_id++;
1061 void BC_Resources::set_signals(BC_Signals *signal_handler)
1063 BC_Resources::signal_handler = signal_handler;
1066 int BC_Resources::init_fontconfig(const char *search_path)
1068 if( fontlist ) return 0;
1069 fontlist = new ArrayList<BC_FontEntry*>;
1071 #define get_str(str,sep,ptr,cond) do { char *out = str; \
1072 while( *ptr && !strchr(sep,*ptr) && (cond) ) *out++ = *ptr++; \
1076 #define skip_str(sep, ptr) do { \
1077 while( *ptr && strchr(sep,*ptr) ) ++ptr; \
1080 char find_command[BCTEXTLEN];
1081 char *fp = find_command, *ep = fp+sizeof(find_command)-1;
1082 fp += snprintf(fp, ep-fp, "%s", "find");
1083 const char *bc_font_path = getenv("BC_FONT_PATH");
1084 // if BC_FONT_PATH starts with ':', omit default path
1085 if( !(bc_font_path && bc_font_path[0] == ':') )
1086 fp += snprintf(fp, ep-fp, " '%s'", search_path);
1087 if( bc_font_path ) {
1088 const char *path = bc_font_path;
1090 char font_path[BCTEXTLEN];
1091 const char *cp = strchr(path,':');
1092 int len = !cp ? strlen(path) : cp-path;
1094 memcpy(font_path, path, len);
1095 font_path[len] = 0; path += len;
1096 fp += snprintf(fp, ep-fp, " '%s'", font_path);
1101 fp += snprintf(fp, ep-fp, " -name 'fonts.scale' -print -exec cat {} \\;");
1102 FILE *in = popen(find_command, "r");
1104 FT_Library freetype_library = 0;
1105 // FT_Face freetype_face = 0;
1106 // ft_Init_FreeType(&freetype_library);
1108 char line[BCTEXTLEN], current_dir[BCTEXTLEN];
1111 while( !feof(in) && fgets(line, BCTEXTLEN, in) ) {
1112 if(!strlen(line)) break;
1114 char *in_ptr = line;
1116 // Get current directory
1117 if(line[0] == '/') {
1118 get_str(current_dir, "\n", in_ptr,1);
1119 for( int i=strlen(current_dir); --i>=0 && current_dir[i]!='/'; )
1124 //printf("TitleMain::build_fonts %s\n", line);
1125 BC_FontEntry *entry = new BC_FontEntry;
1126 char string[BCTEXTLEN];
1128 get_str(string, "\n", in_ptr, in_ptr[0]!=' ' || in_ptr[1]!='-');
1129 entry->path = cstrcat(2, current_dir, string);
1131 skip_str(" -", in_ptr);
1132 get_str(string, "-\n", in_ptr, 1);
1133 if( !string[0] ) { delete entry; continue; }
1134 entry->foundry = cstrdup(string);
1135 if(*in_ptr == '-') in_ptr++;
1137 get_str(string, "-\n", in_ptr, 1);
1138 if( !string[0] ) { delete entry; continue; }
1139 entry->family = cstrdup(string);
1140 if(*in_ptr == '-') in_ptr++;
1142 get_str(string, "-\n", in_ptr, 1);
1143 entry->weight = cstrdup(string);
1144 if(*in_ptr == '-') in_ptr++;
1146 get_str(string, "-\n", in_ptr, 1);
1147 entry->slant = cstrdup(string);
1148 if(*in_ptr == '-') in_ptr++;
1150 get_str(string, "-\n", in_ptr, 1);
1151 entry->swidth = cstrdup(string);
1152 if(*in_ptr == '-') in_ptr++;
1154 get_str(string, "-\n", in_ptr, 1);
1155 entry->adstyle = cstrdup(string);
1156 if(*in_ptr == '-') in_ptr++;
1158 get_str(string, "-\n", in_ptr, 1);
1159 entry->pixelsize = atol(string);
1160 if(*in_ptr == '-') in_ptr++;
1162 get_str(string, "-\n", in_ptr, 1);
1163 entry->pointsize = atol(string);
1164 if(*in_ptr == '-') in_ptr++;
1166 get_str(string, "-\n", in_ptr, 1);
1167 entry->xres = atol(string);
1168 if(*in_ptr == '-') in_ptr++;
1170 get_str(string, "-\n", in_ptr, 1);
1171 entry->yres = atol(string);
1172 if(*in_ptr == '-') in_ptr++;
1174 get_str(string, "-\n", in_ptr, 1);
1175 entry->spacing = cstrdup(string);
1176 if(*in_ptr == '-') in_ptr++;
1178 get_str(string, "-\n", in_ptr, 1);
1179 entry->avg_width = atol(string);
1180 if(*in_ptr == '-') in_ptr++;
1182 get_str(string, "-\n", in_ptr, 1);
1183 entry->registry = cstrdup(string);
1184 if(*in_ptr == '-') in_ptr++;
1186 get_str(string, "-\n", in_ptr, 1);
1187 entry->encoding = cstrdup(string);
1188 if(*in_ptr == '-') in_ptr++;
1191 //printf("TitleMain::build_fonts 1 %s\n", entry->path);
1192 // This takes a real long time to do. Instead just take all fonts
1193 // if(!load_freetype_face(freetype_library,
1194 // freetype_face, entry->path) )
1196 sprintf(line, "%s (%s)", entry->family, entry->foundry);
1197 entry->displayname = cstrdup(line);
1199 if(!strcasecmp(entry->weight, "demibold")) {
1200 entry->fixed_style |= BC_FONT_BOLD;
1201 entry->style |= FL_WEIGHT_DEMIBOLD;
1203 else if(!strcasecmp(entry->weight, "bold")) {
1204 entry->fixed_style |= BC_FONT_BOLD;
1205 entry->style |= FL_WEIGHT_BOLD;
1208 entry->style |= FL_WEIGHT_NORMAL;
1211 if(!strcasecmp(entry->slant, "r")) {
1212 entry->style |= FL_SLANT_ROMAN;
1214 else if(!strcasecmp(entry->slant, "i")) {
1215 entry->style |= FL_SLANT_ITALIC;
1216 entry->fixed_style |= BC_FONT_ITALIC;
1218 else if(!strcasecmp(entry->slant, "o")) {
1219 entry->style |= FL_SLANT_OBLIQUE;
1220 entry->fixed_style |= BC_FONT_ITALIC;
1223 if(!strcasecmp(entry->swidth, "normal"))
1224 entry->style |= FL_WIDTH_NORMAL;
1225 else if(!strcasecmp(entry->swidth, "ultracondensed"))
1226 entry->style |= FL_WIDTH_ULTRACONDENSED;
1227 else if(!strcasecmp(entry->swidth, "extracondensed"))
1228 entry->style |= FL_WIDTH_EXTRACONDENSED;
1229 else if(!strcasecmp(entry->swidth, "condensed"))
1230 entry->style |= FL_WIDTH_CONDENSED;
1231 else if(!strcasecmp(entry->swidth, "semicondensed"))
1232 entry->style |= FL_WIDTH_SEMICONDENSED;
1233 else if(!strcasecmp(entry->swidth, "semiexpanded"))
1234 entry->style |= FL_WIDTH_SEMIEXPANDED;
1235 else if(!strcasecmp(entry->swidth, "expanded"))
1236 entry->style |= FL_WIDTH_EXPANDED;
1237 else if(!strcasecmp(entry->swidth, "extraexpanded"))
1238 entry->style |= FL_WIDTH_EXTRAEXPANDED;
1239 else if(!strcasecmp(entry->swidth, "ultraexpanded"))
1240 entry->style |= FL_WIDTH_ULTRAEXPANDED;
1242 entry->style |= FL_WIDTH_NORMAL;
1244 fontlist->append(entry);
1246 dump_font_entry(stdout, "font 0: ", entry);
1248 // printf("TitleMain::build_fonts %s: success\n", entry->path);
1249 //printf("TitleMain::build_fonts 2\n");
1253 if( bc_font_path && bc_font_path[0] == ':' )
1256 // Load all the fonts from fontconfig
1260 FcChar8 *family, *file, *foundry, *style, *format;
1261 int slant, spacing, width, weight;
1262 int force_style = 0;
1263 // if you want limit search to TrueType put 1
1264 int limit_to_trutype = 1;
1267 char tmpstring[BCTEXTLEN];
1270 config = fcConfigGetCurrent();
1271 fcConfigSetRescanInterval(config, 0);
1273 pat = fcPatternCreate();
1274 os = fcObjectSetBuild( FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
1275 FC_WIDTH, FC_SLANT, FC_FONTFORMAT, FC_SPACING, FC_STYLE, (char *) 0);
1276 fcPatternAddBool(pat, FC_SCALABLE, true);
1279 char langstr[LEN_LANG * 3];
1280 strcpy(langstr, language);
1283 strcat(langstr, "-");
1284 strcat(langstr, region);
1287 FcLangSet *ls = fcLangSetCreate();
1288 if(fcLangSetAdd(ls, (const FcChar8*)langstr))
1289 if(fcPatternAddLangSet(pat, FC_LANG, ls))
1290 fcLangSetDestroy(ls);
1293 fs = fcFontList(config, pat, os);
1294 fcPatternDestroy(pat);
1295 fcObjectSetDestroy(os);
1297 for (i = 0; fs && i < fs->nfont; i++) {
1298 FcPattern *font = fs->fonts[i];
1300 fcPatternGetString(font, FC_FONTFORMAT, 0, &format);
1301 //on this point you can limit font search
1302 if(limit_to_trutype && strcmp((char *)format, "TrueType"))
1305 sprintf(tmpstring, "%s", format);
1306 BC_FontEntry *entry = new BC_FontEntry;
1307 if(fcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
1308 entry->path = cstrdup((char*)file);
1311 if(fcPatternGetString(font, FC_FOUNDRY, 0, &foundry) == FcResultMatch) {
1312 entry->foundry = cstrdup((char*)foundry);
1315 if(fcPatternGetInteger(font, FC_WEIGHT, 0, &weight) == FcResultMatch) {
1317 case FC_WEIGHT_THIN:
1318 case FC_WEIGHT_EXTRALIGHT:
1319 case FC_WEIGHT_LIGHT:
1320 case FC_WEIGHT_BOOK:
1322 entry->weight = cstrdup("medium");
1325 case FC_WEIGHT_NORMAL:
1326 case FC_WEIGHT_MEDIUM:
1328 entry->weight = cstrdup("medium");
1331 case FC_WEIGHT_BLACK:
1332 case FC_WEIGHT_SEMIBOLD:
1333 case FC_WEIGHT_BOLD:
1334 entry->weight = cstrdup("bold");
1335 entry->fixed_style |= BC_FONT_BOLD;
1338 case FC_WEIGHT_EXTRABOLD:
1339 case FC_WEIGHT_EXTRABLACK:
1341 entry->weight = cstrdup("bold");
1342 entry->fixed_style |= BC_FONT_BOLD;
1347 if(fcPatternGetString(font, FC_FAMILY, 0, &family) == FcResultMatch)
1348 entry->family = cstrdup((char*)family);
1350 if(fcPatternGetInteger(font, FC_SLANT, 0, &slant) == FcResultMatch) {
1352 case FC_SLANT_ROMAN:
1354 entry->slant = cstrdup("r");
1355 entry->style |= FL_SLANT_ROMAN;
1357 case FC_SLANT_ITALIC:
1358 entry->slant = cstrdup("i");
1359 entry->style |= FL_SLANT_ITALIC;
1360 entry->fixed_style |= BC_FONT_ITALIC;
1362 case FC_SLANT_OBLIQUE:
1363 entry->slant = cstrdup("o");
1364 entry->style |= FL_SLANT_OBLIQUE;
1365 entry->fixed_style |= BC_FONT_ITALIC;
1370 if(fcPatternGetInteger(font, FC_WIDTH, 0, &width) == FcResultMatch) {
1372 case FC_WIDTH_ULTRACONDENSED:
1373 entry->swidth = cstrdup("ultracondensed");
1376 case FC_WIDTH_EXTRACONDENSED:
1377 entry->swidth = cstrdup("extracondensed");
1380 case FC_WIDTH_CONDENSED:
1381 entry->swidth = cstrdup("condensed");
1383 case FC_WIDTH_SEMICONDENSED:
1384 entry->swidth = cstrdup("semicondensed");
1387 case FC_WIDTH_NORMAL:
1389 entry->swidth = cstrdup("normal");
1392 case FC_WIDTH_SEMIEXPANDED:
1393 entry->swidth = cstrdup("semiexpanded");
1396 case FC_WIDTH_EXPANDED:
1397 entry->swidth = cstrdup("expanded");
1400 case FC_WIDTH_EXTRAEXPANDED:
1401 entry->swidth = cstrdup("extraexpanded");
1404 case FC_WIDTH_ULTRAEXPANDED:
1405 entry->swidth = cstrdup("ultraexpanded");
1410 if(fcPatternGetInteger(font, FC_SPACING, 0, &spacing) == FcResultMatch) {
1414 entry->spacing = cstrdup("p");
1418 entry->spacing = cstrdup("d");
1422 entry->spacing = cstrdup("m");
1426 entry->spacing = cstrdup("c");
1431 // Add fake stuff for compatibility
1432 entry->adstyle = cstrdup(" ");
1433 entry->pixelsize = 0;
1434 entry->pointsize = 0;
1437 entry->avg_width = 0;
1438 entry->registry = cstrdup("utf");
1439 entry->encoding = cstrdup("8");
1441 if( fcPatternGetString(font, FC_STYLE, 0, &style) != FcResultMatch )
1444 // If font has a style unmanaged by titler plugin, force style to be displayed on name
1445 // in this way we can shown all available fonts styles.
1447 sprintf(tmpstring, "%s (%s)", entry->family, style);
1448 entry->displayname = cstrdup(tmpstring);
1451 if(strcmp(entry->foundry, "unknown")) {
1452 sprintf(tmpstring, "%s (%s)", entry->family, entry->foundry);
1453 entry->displayname = cstrdup(tmpstring);
1456 sprintf(tmpstring, "%s", entry->family);
1457 entry->displayname = cstrdup(tmpstring);
1461 fontlist->append(entry);
1463 dump_font_entry(stdout, "font 1: ", entry);
1466 fcFontSetDestroy(fs);
1467 if(freetype_library)
1468 ft_Done_FreeType(freetype_library);
1469 // for(int i = 0; i < fonts->total; i++)
1470 // fonts->values[i]->dump();
1472 fcConfigAppFontAddDir(0, (const FcChar8*)search_path);
1473 fcConfigSetRescanInterval(0, 0);
1475 os = fcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
1476 FC_WIDTH, FC_SLANT, FC_SPACING, FC_STYLE, (char *)0);
1477 pat = fcPatternCreate();
1478 fcPatternAddBool(pat, FC_SCALABLE, true);
1482 char langstr[LEN_LANG * 3];
1483 strcpy(langstr, language);
1487 strcat(langstr, "-");
1488 strcat(langstr, region);
1491 FcLangSet *ls = fcLangSetCreate();
1492 if(fcLangSetAdd(ls, (const FcChar8*)langstr))
1493 if(fcPatternAddLangSet(pat, FC_LANG, ls))
1494 fcLangSetDestroy(ls);
1497 fs = fcFontList(0, pat, os);
1498 fcPatternDestroy(pat);
1499 fcObjectSetDestroy(os);
1501 for(int i = 0; i < fs->nfont; i++)
1503 FcPattern *font = fs->fonts[i];
1504 BC_FontEntry *entry = new BC_FontEntry;
1507 if(fcPatternGetString(font, FC_FILE, 0, &strvalue) == FcResultMatch)
1509 entry->path = new char[strlen((char*)strvalue) + 1];
1510 strcpy(entry->path, (char*)strvalue);
1513 if(fcPatternGetString(font, FC_FOUNDRY, 0, &strvalue) == FcResultMatch)
1515 entry->foundry = new char[strlen((char*)strvalue) + 1];
1516 strcpy(entry->foundry, (char *)strvalue);
1519 if(fcPatternGetString(font, FC_FAMILY, 0, &strvalue) == FcResultMatch)
1521 entry->family = new char[strlen((char*)strvalue) + 2];
1522 strcpy(entry->family, (char*)strvalue);
1526 if(fcPatternGetInteger(font, FC_SLANT, 0, &intvalue) == FcResultMatch)
1530 case FC_SLANT_ROMAN:
1532 entry->style |= FL_SLANT_ROMAN;
1535 case FC_SLANT_ITALIC:
1536 entry->style |= FL_SLANT_ITALIC;
1539 case FC_SLANT_OBLIQUE:
1540 entry->style |= FL_SLANT_OBLIQUE;
1545 if(fcPatternGetInteger(font, FC_WEIGHT, 0, &intvalue) == FcResultMatch)
1549 case FC_WEIGHT_THIN:
1550 entry->style |= FL_WEIGHT_THIN;
1553 case FC_WEIGHT_EXTRALIGHT:
1554 entry->style |= FL_WEIGHT_EXTRALIGHT;
1557 case FC_WEIGHT_LIGHT:
1558 entry->style |= FL_WEIGHT_LIGHT;
1561 case FC_WEIGHT_BOOK:
1562 entry->style |= FL_WEIGHT_BOOK;
1565 case FC_WEIGHT_NORMAL:
1567 entry->style |= FL_WEIGHT_NORMAL;
1570 case FC_WEIGHT_MEDIUM:
1571 entry->style |= FL_WEIGHT_MEDIUM;
1574 case FC_WEIGHT_DEMIBOLD:
1575 entry->style |= FL_WEIGHT_DEMIBOLD;
1578 case FC_WEIGHT_BOLD:
1579 entry->style |= FL_WEIGHT_BOLD;
1582 case FC_WEIGHT_EXTRABOLD:
1583 entry->style |= FL_WEIGHT_EXTRABOLD;
1586 case FC_WEIGHT_BLACK:
1587 entry->style |= FL_WEIGHT_BLACK;
1590 case FC_WEIGHT_EXTRABLACK:
1591 entry->style |= FL_WEIGHT_EXTRABLACK;
1596 if(fcPatternGetInteger(font, FC_WIDTH, 0, &intvalue) == FcResultMatch)
1600 case FC_WIDTH_ULTRACONDENSED:
1601 entry->style |= FL_WIDTH_ULTRACONDENSED;
1604 case FC_WIDTH_EXTRACONDENSED:
1605 entry->style |= FL_WIDTH_EXTRACONDENSED;
1608 case FC_WIDTH_CONDENSED:
1609 entry->style |= FL_WIDTH_CONDENSED;
1612 case FC_WIDTH_SEMICONDENSED:
1613 entry->style = FL_WIDTH_SEMICONDENSED;
1616 case FC_WIDTH_NORMAL:
1618 entry->style |= FL_WIDTH_NORMAL;
1621 case FC_WIDTH_SEMIEXPANDED:
1622 entry->style |= FL_WIDTH_SEMIEXPANDED;
1625 case FC_WIDTH_EXPANDED:
1626 entry->style |= FL_WIDTH_EXPANDED;
1629 case FC_WIDTH_EXTRAEXPANDED:
1630 entry->style |= FL_WIDTH_EXTRAEXPANDED;
1633 case FC_WIDTH_ULTRAEXPANDED:
1634 entry->style |= FL_WIDTH_ULTRAEXPANDED;
1638 if(fcPatternGetInteger(font, FC_SPACING, 0, &intvalue) == FcResultMatch)
1642 case FC_PROPORTIONAL:
1644 entry->style |= FL_PROPORTIONAL;
1648 entry->style |= FL_DUAL;
1652 entry->style |= FL_MONO;
1656 entry->style |= FL_CHARCELL;
1660 if(entry->foundry && strcmp(entry->foundry, "unknown"))
1662 char tempstr[BCTEXTLEN];
1663 sprintf(tempstr, "%s (%s)", entry->family, entry->foundry);
1664 entry->displayname = new char[strlen(tempstr) + 1];
1665 strcpy(entry->displayname, tempstr);
1669 entry->displayname = new char[strlen(entry->family) + 1];
1670 strcpy(entry->displayname, entry->family);
1672 fontlist->append(entry);
1674 dump_font_entry(stdout, "font 2: ", entry);
1676 fcFontSetDestroy(fs);
1680 #define STYLE_MATCH(fst, stl, msk) ((fst) & (msk) & (stl)) && \
1681 !((fst) & ~(style) & (msk))
1683 BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style,
1684 int mask, int preferred)
1686 BC_FontEntry *entry, *style_match, *preferred_match;
1692 preferred_match = 0;
1696 for(int i = 0; i < fontlist->total; i++)
1698 entry = fontlist->values[i];
1700 if(strcmp(entry->displayname, displayname) == 0 &&
1701 STYLE_MATCH(entry->style, style, mask))
1704 style_match = entry;
1705 if(!preferred_match && entry->fixed_style == preferred)
1706 preferred_match = entry;
1710 return preferred_match;
1716 // No exact match - assume normal width font
1717 style |= FL_WIDTH_NORMAL;
1718 mask |= FL_WIDTH_MASK;
1720 preferred_match = 0;
1722 for(int i = 0; i < fontlist->total; i++)
1724 entry = fontlist->values[i];
1726 if(STYLE_MATCH(entry->style, style, mask))
1729 style_match = entry;
1731 if(!preferred_match && (entry->style & preferred))
1732 preferred_match = entry;
1734 if(!strncasecmp(displayname, entry->family,
1735 strlen(entry->family)))
1741 return preferred_match;
1748 uint8_t *obfr, *out, *oend;
1749 uint8_t *ibfr, *inp, *iend;
1751 utf8conv(void *out, int olen, void *inp, int ilen) {
1752 this->obfr = this->out = (uint8_t*)out;
1753 this->oend = this->out + olen;
1754 this->ibfr = this->inp = (uint8_t*)inp;
1755 this->iend = this->inp + ilen;
1757 int cur() { return inp>=iend ? -1 : *inp; }
1758 int next() { return inp>=iend ? -1 : *inp++; }
1759 int next(int ch) { return out>=oend ? -1 : *out++ = ch; }
1760 int ilen() { return inp-ibfr; }
1761 int olen() { return out-obfr; }
1763 int wnext(unsigned int v);
1767 wnext(unsigned int v)
1769 if( v < 0x00000080 ) { next(v); return 1; }
1770 int n = v < 0x00000800 ? 2 : v < 0x00010000 ? 3 :
1771 v < 0x00200000 ? 4 : v < 0x04000000 ? 5 : 6;
1772 int m = (0xff00 >> n), i = n-1;
1773 next((v>>(6*i)) | m);
1774 while( --i >= 0 ) next(((v>>(6*i)) & 0x3f) | 0x80);
1781 int v = 0, n = 0, ch = next();
1783 static const unsigned char byts[] = {
1784 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 5,
1787 n = i<0 ? 0 : byts[i/4];
1788 for( v=ch, i=n; --i>=0; v+=next() ) v <<= 6;
1789 static const unsigned int ofs[6] = {
1790 0x00000000U, 0x00003080U, 0x000E2080U,
1791 0x03C82080U, 0xFA082080U, 0x82082080U
1801 size_t BC_Resources::encode(const char *from_enc, const char *to_enc,
1802 char *input, int input_length, char *output, int output_length)
1804 if( !from_enc || *from_enc == 0 ||
1805 !strcmp(from_enc,"UTF8") || !strcmp(from_enc, "US-ASCII") )
1808 if( !to_enc || *to_enc == 0 ||
1809 !strcmp(to_enc,"UTF8") || !strcmp(to_enc, "US-ASCII") )
1813 char *outbase = output;
1814 size_t inbytes = input_length < 0 ? strlen(input) : input_length;
1815 size_t outbytes = output_length;
1817 if( inbytes && outbytes ) {
1818 if( !strcmp(from_enc, to_enc) ) {
1819 if( inbytes > outbytes ) inbytes = outbytes;
1820 memcpy(output, input, inbytes);
1822 outbytes -= inbytes;
1824 else if( !strcmp(from_enc, "UTF-8") && !strcmp(to_enc,"UTF32LE") ) {
1825 utf8conv uc(0,0, input,inbytes);
1826 uint32_t *op = (uint32_t *)output;
1827 uint32_t *ep = (uint32_t *)(output+output_length);
1828 for( int wch; op<ep && (wch=uc.wnext())>=0; *op++=wch );
1829 output = (char *)op;
1830 outbytes = (char*)ep - output;
1832 else if( !strcmp(from_enc, "UTF32LE") && !strcmp(to_enc,"UTF-8") ) {
1833 utf8conv uc(output,output_length, 0,0);
1834 uint32_t *ip = (uint32_t *)input;
1835 uint32_t *ep = (uint32_t *)(input+inbytes);
1836 for( ; ip<ep && uc.wnext(*ip)>=0; ++ip );
1837 output += uc.olen();
1838 outbytes -= uc.olen();
1840 else if( (cd = iconv_open(to_enc, from_enc)) != (iconv_t)-1 ) {
1841 iconv(cd, &input, &inbytes, &output, &outbytes);
1845 printf(_("Conversion from %s to %s is not available\n"),
1849 if( outbytes > sizeof(uint32_t) )
1850 outbytes = sizeof(uint32_t);
1851 for( uint32_t i = 0; i < outbytes; i++)
1853 return output - outbase;
1856 void BC_Resources::encode_to_utf8(char *buffer, int buflen)
1858 if(BC_Resources::locale_utf8) return;
1860 encode(encoding, 0, buffer, -1, lbuf, buflen);
1861 strcpy(buffer, lbuf);
1864 int BC_Resources::find_font_by_char(FT_ULong char_code, char *path_new, const FT_Face oldface)
1866 FcPattern *font, *ofont;
1872 // Do not search control codes
1876 if( (ofont = fcFreeTypeQueryFace(oldface, (const FcChar8*)"", 4097, 0)) != 0 ) {
1877 if( (font = find_similar_font(char_code, ofont)) != 0 ) {
1878 if(fcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
1879 strcpy(path_new, (char*)file);
1882 fcPatternDestroy(font);
1884 fcPatternDestroy(ofont);
1889 FcPattern* BC_Resources::find_similar_font(FT_ULong char_code, FcPattern *oldfont)
1891 FcPattern *pat, *font;
1897 // Do not search control codes
1901 fontconfig_lock.lock("BC_Resources::find_similar_font");
1902 pat = fcPatternCreate();
1903 os = fcObjectSetBuild(FC_FILE, FC_CHARSET, FC_SCALABLE, FC_FAMILY,
1904 FC_SLANT, FC_WEIGHT, FC_WIDTH, (char *)0);
1906 fcPatternAddBool(pat, FC_SCALABLE, true);
1907 fcs = fcCharSetCreate();
1908 if(fcCharSetAddChar(fcs, char_code))
1909 fcPatternAddCharSet(pat, FC_CHARSET, fcs);
1910 fcCharSetDestroy(fcs);
1911 for( int i=0; i<(int)LEN_FCPROP; ++i ) {
1912 if(fcPatternGetInteger(oldfont, fc_properties[i], 0, &ival) == FcResultMatch)
1913 fcPatternAddInteger(pat, fc_properties[i], ival);
1915 fs = fcFontList(0, pat, os);
1916 for( int i=LEN_FCPROP; --i>=0 && !fs->nfont; ) {
1917 fcFontSetDestroy(fs);
1918 fcPatternDel(pat, fc_properties[i]);
1919 fs = fcFontList(0, pat, os);
1921 fcPatternDestroy(pat);
1922 fcObjectSetDestroy(os);
1926 for (int i = 0; i < fs->nfont; i++)
1928 font = fs->fonts[i];
1929 if(fcPatternGetCharSet(font, FC_CHARSET, 0, &fcs) == FcResultMatch)
1931 if(fcCharSetHasChar(fcs, char_code))
1933 pat = fcPatternDuplicate(font);
1938 fcFontSetDestroy(fs);
1939 fontconfig_lock.unlock();
1944 void BC_Resources::dump_fonts(FILE *fp)
1946 for( int i=0; i<fontlist->total; ++i )
1947 dump_font_entry(fp, "", fontlist->values[i]);
1950 void BC_Resources::dump_font_entry(FILE *fp, const char *cp, BC_FontEntry *ep)
1952 fprintf(fp,"%s%s = %s\n",cp,ep->displayname,ep->path);
1953 fprintf(fp," %s:%s:%s:%s:%s:%s:%d:%d:%d:%d:%d:%s:%d:%s:%s:%d\n",
1954 ep->foundry, ep->family, ep->weight, ep->slant, ep->swidth, ep->adstyle,
1955 ep->pixelsize, ep->pointsize, ep->xres, ep->yres, ep->style, ep->spacing,
1956 ep->avg_width, ep->registry, ep->encoding, ep->fixed_style);