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 #if defined(__FreeBSD__)
43 #include <sys/sysctl.h>
45 #include <X11/extensions/XShm.h>
46 #include <fontconfig/fontconfig.h>
47 #include <fontconfig/fcfreetype.h>
54 int BC_Resources::error = 0;
56 VFrame* BC_Resources::bg_image = 0;
57 VFrame* BC_Resources::menu_bg = 0;
59 int BC_Resources::locale_utf8 = 0;
60 int BC_Resources::little_endian = 0;
61 char BC_Resources::language[LEN_LANG] = {0};
62 char BC_Resources::region[LEN_LANG] = {0};
63 char BC_Resources::encoding[LEN_ENCOD] = {0};
64 const char *BC_Resources::wide_encoding = 0;
65 ArrayList<BC_FontEntry*> *BC_Resources::fontlist = 0;
66 int BC_Resources::font_debug = 0;
67 const char *BC_Resources::fc_properties[] = { FC_SLANT, FC_WEIGHT, FC_WIDTH };
68 #define LEN_FCPROP (sizeof(BC_Resources::fc_properties) / sizeof(const char*))
70 static const char *def_small_font = "-*-helvetica-medium-r-normal-*-%d-*"; // 10
71 static const char *def_small_font2 = "-*-helvetica-medium-r-normal-*-%d-*"; // 11
72 static const char *def_medium_font = "-*-helvetica-bold-r-normal-*-%d-*"; // 14
73 static const char *def_medium_font2 = "-*-helvetica-bold-r-normal-*-%d-*"; // 14
74 static const char *def_large_font = "-*-helvetica-bold-r-normal-*-%d-*"; // 18
75 static const char *def_large_font2 = "-*-helvetica-bold-r-normal-*-%d-*"; // 20
76 static const char *def_big_font =
77 "-*-bitstream charter-bold-r-normal-*-*-0-%d-%d-p-0-iso8859-1"; // 160
78 static const char *def_big_font2 =
79 "-*-nimbus sans l-bold-r-normal-*-*-0-%d-%d-p-0-iso8859-1"; // 160
80 static const char *def_clock_font = "-*-helvetica-bold-r-normal-*-%d-*"; // 16
81 static const char *def_clock_font2 = "-*-helvetica-bold-r-normal-*-%d-*"; // 18
82 static const char *def_small_fontset = "-*-helvetica-medium-r-normal-*-%d-*";// 10
83 static const char *def_medium_fontset = "-*-helvetica-bold-r-normal-*-%d-*"; // 14
84 static const char *def_large_fontset = "-*-helvetica-bold-r-normal-*-%d-*"; // 18
85 static const char *def_big_fontset = "-*-helvetica-bold-r-normal-*-%d-*"; // 24
86 static const char *def_clock_fontset = "-*-helvetica-bold-r-normal-*-%d-*"; // 16
88 static const char *def_small_font_xft = "Sans:pixelsize=%.4f"; // 10.6667
89 static const char *def_small_b_font_xft = "Sans:bold:pixelsize=%.4f"; // 10.6667
90 static const char *def_medium_font_xft = "Sans:pixelsize=%.4f"; // 13.3333
91 static const char *def_medium_b_font_xft = "Sans:bold:pixelsize=%.4f"; // 13.3333
92 static const char *def_large_font_xft = "Sans:pixelsize=%.4f"; // 21.3333
93 static const char *def_large_b_font_xft = "Sans:bold:pixelsize=%.4f"; // 21.3333
94 static const char *def_big_font_xft = "Sans:pixelsize=37.3333"; // 37.3333
95 static const char *def_big_b_font_xft = "Sans:bold:pixelsize=37.33333"; // 37.3333
96 static const char *def_clock_font_xft = "Sans:pixelsize=%.4f"; // 16
98 #define default_font_xft2 "-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*"
100 const char* BC_Resources::small_font = 0;
101 const char* BC_Resources::small_font2 = 0;
102 const char* BC_Resources::medium_font = 0;
103 const char* BC_Resources::medium_font2 = 0;
104 const char* BC_Resources::large_font = 0;
105 const char* BC_Resources::large_font2 = 0;
106 const char* BC_Resources::big_font = 0;
107 const char* BC_Resources::big_font2 = 0;
108 const char* BC_Resources::clock_font = 0;
109 const char* BC_Resources::clock_font2 = 0;
110 const char* BC_Resources::small_fontset = 0;
111 const char* BC_Resources::medium_fontset = 0;
112 const char* BC_Resources::large_fontset = 0;
113 const char* BC_Resources::big_fontset = 0;
114 const char* BC_Resources::clock_fontset = 0;
115 const char* BC_Resources::small_font_xft = 0;
116 const char* BC_Resources::small_font_xft2 = 0;
117 const char* BC_Resources::small_b_font_xft = 0;
118 const char* BC_Resources::medium_font_xft = 0;
119 const char* BC_Resources::medium_font_xft2 = 0;
120 const char* BC_Resources::medium_b_font_xft = 0;
121 const char* BC_Resources::large_font_xft = 0;
122 const char* BC_Resources::large_font_xft2 = 0;
123 const char* BC_Resources::large_b_font_xft = 0;
124 const char* BC_Resources::big_font_xft = 0;
125 const char* BC_Resources::big_font_xft2 = 0;
126 const char* BC_Resources::big_b_font_xft = 0;
127 const char* BC_Resources::clock_font_xft = 0;
128 const char* BC_Resources::clock_font_xft2 = 0;
130 #define def_font(v, s...) do { sprintf(string,def_##v,s); v = cstrdup(string); } while(0)
131 #define set_font(v, s) do { sprintf(string, "%s", s); v = cstrdup(string); } while(0)
132 #define iround(v) ((int)(v+0.5))
133 void BC_Resources::init_font_defs(double scale)
135 char string[BCTEXTLEN];
136 def_font(small_font, iround(scale*11));
137 def_font(small_font2, iround(scale*11));
138 def_font(medium_font, iround(scale*14));
139 def_font(medium_font2, iround(scale*14));
140 def_font(large_font, iround(scale*18));
141 def_font(large_font2, iround(scale*20));
142 def_font(big_font, iround(scale*160), iround(scale*160));
143 def_font(big_font2, iround(scale*16), iround(scale*16));
144 def_font(clock_font, iround(scale*16));
145 def_font(clock_font2, iround(scale*18));
146 def_font(small_fontset, iround(scale*10));
147 def_font(medium_fontset, iround(scale*14));
148 def_font(large_fontset, iround(scale*18));
149 def_font(big_fontset, iround(scale*24));
150 def_font(clock_fontset, iround(scale*16));
151 def_font(small_font_xft, (scale*10.6667));
152 def_font(small_b_font_xft, (scale*10.6667));
153 def_font(medium_font_xft, (scale*13.3333));
154 def_font(medium_b_font_xft,(scale*13.3333));
155 def_font(large_font_xft, (scale*21.3333));
156 def_font(large_b_font_xft, (scale*21.3333));
157 def_font(big_font_xft, (scale*37.3333));
158 def_font(big_b_font_xft, (scale*37.3333));
159 def_font(clock_font_xft, (scale*16.));
161 set_font(small_font_xft2, default_font_xft2);
162 set_font(medium_font_xft2, default_font_xft2);
163 set_font(large_font_xft2, default_font_xft2);
164 set_font(big_font_xft2, default_font_xft2);
165 set_font(clock_font_xft2, default_font_xft2);
167 void BC_Resources::finit_font_defs()
169 delete [] small_font;
170 delete [] small_font2;
171 delete [] medium_font;
172 delete [] medium_font2;
173 delete [] large_font;
174 delete [] large_font2;
177 delete [] clock_font;
178 delete [] clock_font2;
179 delete [] small_fontset;
180 delete [] medium_fontset;
181 delete [] large_fontset;
182 delete [] big_fontset;
183 delete [] clock_fontset;
184 delete [] small_font_xft;
185 delete [] small_b_font_xft;
186 delete [] medium_font_xft;
187 delete [] medium_b_font_xft;
188 delete [] large_font_xft;
189 delete [] large_b_font_xft;
190 delete [] big_font_xft;
191 delete [] big_b_font_xft;
192 delete [] clock_font_xft;
194 delete [] small_font_xft2;
195 delete [] medium_font_xft2;
196 delete [] large_font_xft2;
197 delete [] big_font_xft2;
198 delete [] clock_font_xft2;
202 suffix_to_type_t BC_Resources::suffix_to_type[] =
204 { "aac", ICON_SOUND },
205 { "ac3", ICON_SOUND },
206 { "dts", ICON_SOUND },
207 { "f4a", ICON_SOUND },
208 { "flac", ICON_SOUND },
209 { "m4a", ICON_SOUND },
210 { "mp2", ICON_SOUND },
211 { "mp3", ICON_SOUND },
212 { "mpc", ICON_SOUND },
213 { "oga", ICON_SOUND },
214 { "ogg", ICON_SOUND },
215 { "opus", ICON_SOUND },
216 { "ra", ICON_SOUND },
217 { "tta", ICON_SOUND },
218 { "vox", ICON_SOUND },
219 { "wav", ICON_SOUND },
220 { "wma", ICON_SOUND },
221 { "3gp", ICON_FILM },
222 { "avi", ICON_FILM },
223 { "bmp", ICON_FILM },
224 { "cr2", ICON_FILM },
225 { "dnxhd", ICON_FILM },
226 { "drc", ICON_FILM },
228 { "dvd", ICON_FILM },
229 { "exr", ICON_FILM },
230 { "f4v", ICON_FILM },
231 { "flv", ICON_FILM },
232 { "gif", ICON_FILM },
233 { "gxf", ICON_FILM },
234 { "h263", ICON_FILM },
235 { "h264", ICON_FILM },
236 { "h265", ICON_FILM },
237 { "hevc", ICON_FILM },
238 { "ifo", ICON_FILM },
239 { "jpeg", ICON_FILM },
240 { "jpg", ICON_FILM },
241 { "m2t", ICON_FILM },
242 { "m2ts", ICON_FILM },
243 { "m2v", ICON_FILM },
244 { "m4p", ICON_FILM },
245 { "m4v", ICON_FILM },
246 { "mkv", ICON_FILM },
247 { "mov", ICON_FILM },
248 { "mp4", ICON_FILM },
249 { "mpe", ICON_FILM },
250 { "mpeg", ICON_FILM },
251 { "mpg", ICON_FILM },
252 { "mpv", ICON_FILM },
253 { "mts", ICON_FILM },
254 { "mxf", ICON_FILM },
255 { "ogv", ICON_FILM },
256 { "pcm", ICON_FILM },
257 { "pgm", ICON_FILM },
258 { "png", ICON_FILM },
259 { "ppm", ICON_FILM },
262 { "rmvb", ICON_FILM },
264 { "swf", ICON_FILM },
265 { "tif", ICON_FILM },
266 { "tiff", ICON_FILM },
268 { "vob", ICON_FILM },
269 { "vts", ICON_FILM },
270 { "webm", ICON_FILM },
271 { "webp", ICON_FILM },
272 { "wmv", ICON_FILM },
273 { "xml", ICON_FILM },
274 { "y4m", ICON_FILM },
278 BC_Signals* BC_Resources::signal_handler = 0;
279 Mutex BC_Resources::fontconfig_lock("BC_Resources::fonconfig_lock");
281 int BC_Resources::x_error_handler(Display *display, XErrorEvent *event)
283 #if defined(OUTPUT_X_ERROR)
285 XGetErrorText(event->display, event->error_code, string, 1024);
286 fprintf(stderr, "BC_Resources::x_error_handler: error_code=%d opcode=%d,%d %s\n",
293 BC_Resources::error = 1;
294 // This bug only happens in 32 bit mode.
295 // if(sizeof(long) == 4)
296 // BC_WindowBase::get_resources()->use_xft = 0;
300 int BC_Resources::machine_cpus = 1;
302 int BC_Resources::get_machine_cpus()
304 #if !defined(__FreeBSD__)
306 FILE *proc = fopen("/proc/cpuinfo", "r");
308 char string[BCTEXTLEN], *cp;
309 while(!feof(proc) && fgets(string, sizeof(string), proc) ) {
310 if( !strncasecmp(string, "processor", 9) &&
311 (cp = strchr(string, ':')) != 0 ) {
312 int n = atol(cp+1) + 1;
313 if( n > cpus ) cpus = n;
315 else if( !strncasecmp(string, "cpus detected", 13) &&
316 (cp = strchr(string, ':')) != 0 )
324 size_t len = sizeof(ncpu);
327 if( sysctl(mib, 2, &ncpu, &len, 0, 0) ) ncpu = 1;
332 void BC_Resources::new_vframes(int n, VFrame *vframes[], ...)
335 va_start(ap, vframes);
336 for( int i=0; i<n; ++i )
337 vframes[i] = va_arg(ap, VFrame *);
341 VFrame *BC_Resources::default_type_to_icon[6] = { 0, };
342 VFrame *BC_Resources::default_bar = 0;
343 VFrame *BC_Resources::default_cancel_images[3] = { 0, };
344 VFrame *BC_Resources::default_ok_images[3] = { 0, };
345 VFrame *BC_Resources::default_usethis_images[3] = { 0, };
347 VFrame *BC_Resources::default_checkbox_images[5] = { 0, };
348 VFrame *BC_Resources::default_radial_images[5] = { 0, };
349 VFrame *BC_Resources::default_label_images[5] = { 0, };
351 VFrame *BC_Resources::default_menuitem_data[3] = { 0, };
352 VFrame *BC_Resources::default_menubar_data[3] = { 0, };
353 VFrame *BC_Resources::default_menu_popup_bg = 0;
354 VFrame *BC_Resources::default_menu_bar_bg = 0;
355 VFrame *BC_Resources::default_check_image = 0;
356 VFrame *BC_Resources::default_filebox_text_images[3] = { 0, };
357 VFrame *BC_Resources::default_filebox_icons_images[3] = { 0, };
358 VFrame *BC_Resources::default_filebox_updir_images[3] = { 0, };
359 VFrame *BC_Resources::default_filebox_newfolder_images[3] = { 0, };
360 VFrame *BC_Resources::default_filebox_rename_images[3] = { 0, };
361 VFrame *BC_Resources::default_filebox_delete_images[3] = { 0, };
362 VFrame *BC_Resources::default_filebox_reload_images[3] = { 0, };
363 VFrame *BC_Resources::default_filebox_szfmt_images[12] = { 0, };
364 VFrame *BC_Resources::default_listbox_button[4] = { 0, };
365 VFrame *BC_Resources::default_listbox_bg = 0;
366 VFrame *BC_Resources::default_listbox_expand[5] = { 0, };
367 VFrame *BC_Resources::default_listbox_column[3] = { 0, };
368 VFrame *BC_Resources::default_listbox_up = 0;
369 VFrame *BC_Resources::default_listbox_dn = 0;
370 VFrame *BC_Resources::default_pot_images[3] = { 0, };
371 VFrame *BC_Resources::default_progress_images[2] = { 0, };
372 VFrame *BC_Resources::default_medium_7segment[20] = { 0, };
373 VFrame *BC_Resources::default_vscroll_data[10] = { 0, };
374 VFrame *BC_Resources::default_hscroll_data[10] = { 0, };
375 VFrame *BC_Resources::default_icon_img = 0;
377 BC_Resources::BC_Resources(float x_scale, float y_scale)
379 BC_WindowBase::resources = this;
382 #if !defined(__FreeBSD__)
389 if( x_scale <= 0 ) x_scale = 1;
390 if( y_scale <= 0 ) y_scale = x_scale;
391 this->x_scale = x_scale;
392 this->y_scale = y_scale;
393 float default_scale = bmin(x_scale, y_scale);
394 const char *env = getenv("BC_FONT_DEBUG");
395 font_debug = env ? atoi(env) : 0;
396 env = getenv("BC_FONT_SCALE");
397 font_scale = env ? atof(env) : default_scale;
398 if( font_scale <= 0 ) font_scale = 1;
399 init_font_defs(font_scale);
400 env = getenv("BC_ICON_SCALE");
401 icon_scale = env ? atof(env) : default_scale;
402 if( icon_scale <= 0 ) icon_scale = 1;
404 id_lock = new Mutex("BC_Resources::id_lock");
405 create_window_lock = new Mutex("BC_Resources::create_window_lock", 1);
407 machine_cpus = get_machine_cpus();
409 for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
410 filebox_history[i].path[0] = 0;
417 little_endian = (*(const u_int32_t*)"\01\0\0\0") & 1;
418 wide_encoding = little_endian ? "UTF32LE" : "UTF32BE";
421 #include "images/file_folder_png.h"
422 #include "images/file_unknown_png.h"
423 #include "images/file_film_png.h"
424 #include "images/file_sound_png.h"
425 #include "images/file_label_png.h"
426 #include "images/file_column_png.h"
427 new_vframes(6,default_type_to_icon,
428 new VFramePng(file_folder_png),
429 new VFramePng(file_unknown_png),
430 new VFramePng(file_film_png),
431 new VFramePng(file_sound_png),
432 new VFramePng(file_label_png),
433 new VFramePng(file_column_png));
435 #include "images/bar_png.h"
436 default_bar = new VFramePng(bar_png);
438 #include "images/cancel_up_png.h"
439 #include "images/cancel_hi_png.h"
440 #include "images/cancel_dn_png.h"
441 new_vframes(3,default_cancel_images,
442 new VFramePng(cancel_up_png),
443 new VFramePng(cancel_hi_png),
444 new VFramePng(cancel_dn_png));
446 #include "images/ok_up_png.h"
447 #include "images/ok_hi_png.h"
448 #include "images/ok_dn_png.h"
449 new_vframes(3,default_ok_images,
450 new VFramePng(ok_up_png),
451 new VFramePng(ok_hi_png),
452 new VFramePng(ok_dn_png));
454 #include "images/usethis_up_png.h"
455 #include "images/usethis_uphi_png.h"
456 #include "images/usethis_dn_png.h"
457 new_vframes(3,default_usethis_images,
458 new VFramePng(usethis_up_png),
459 new VFramePng(usethis_uphi_png),
460 new VFramePng(usethis_dn_png));
463 #include "images/checkbox_checked_png.h"
464 #include "images/checkbox_dn_png.h"
465 #include "images/checkbox_checkedhi_png.h"
466 #include "images/checkbox_up_png.h"
467 #include "images/checkbox_hi_png.h"
468 new_vframes(5,default_checkbox_images,
469 new VFramePng(checkbox_up_png),
470 new VFramePng(checkbox_hi_png),
471 new VFramePng(checkbox_checked_png),
472 new VFramePng(checkbox_dn_png),
473 new VFramePng(checkbox_checkedhi_png));
475 #include "images/radial_checked_png.h"
476 #include "images/radial_dn_png.h"
477 #include "images/radial_checkedhi_png.h"
478 #include "images/radial_up_png.h"
479 #include "images/radial_hi_png.h"
480 new_vframes(5,default_radial_images,
481 new VFramePng(radial_up_png),
482 new VFramePng(radial_hi_png),
483 new VFramePng(radial_checked_png),
484 new VFramePng(radial_dn_png),
485 new VFramePng(radial_checkedhi_png));
487 new_vframes(5,default_label_images,
488 new VFramePng(radial_up_png),
489 new VFramePng(radial_hi_png),
490 new VFramePng(radial_checked_png),
491 new VFramePng(radial_dn_png),
492 new VFramePng(radial_checkedhi_png));
495 #include "images/menuitem_up_png.h"
496 #include "images/menuitem_hi_png.h"
497 #include "images/menuitem_dn_png.h"
498 new_vframes(3,default_menuitem_data,
499 new VFramePng(menuitem_up_png),
500 new VFramePng(menuitem_hi_png),
501 new VFramePng(menuitem_dn_png));
503 #include "images/menubar_up_png.h"
504 #include "images/menubar_hi_png.h"
505 #include "images/menubar_dn_png.h"
506 new_vframes(3,default_menubar_data,
507 new VFramePng(menubar_up_png),
508 new VFramePng(menubar_hi_png),
509 new VFramePng(menubar_dn_png));
511 #include "images/menu_popup_bg_png.h"
512 default_menu_popup_bg = new VFramePng(menu_popup_bg_png);
514 #include "images/menubar_bg_png.h"
515 default_menu_bar_bg = new VFramePng(menubar_bg_png);
517 #include "images/check_png.h"
518 default_check_image = new VFramePng(check_png);
520 #include "images/file_text_up_png.h"
521 #include "images/file_text_hi_png.h"
522 #include "images/file_text_dn_png.h"
523 new_vframes(3,default_filebox_text_images,
524 new VFramePng(file_text_up_png),
525 new VFramePng(file_text_hi_png),
526 new VFramePng(file_text_dn_png));
528 #include "images/file_icons_up_png.h"
529 #include "images/file_icons_hi_png.h"
530 #include "images/file_icons_dn_png.h"
531 new_vframes(3,default_filebox_icons_images,
532 new VFramePng(file_icons_up_png),
533 new VFramePng(file_icons_hi_png),
534 new VFramePng(file_icons_dn_png));
536 #include "images/file_updir_up_png.h"
537 #include "images/file_updir_hi_png.h"
538 #include "images/file_updir_dn_png.h"
539 new_vframes(3,default_filebox_updir_images,
540 new VFramePng(file_updir_up_png),
541 new VFramePng(file_updir_hi_png),
542 new VFramePng(file_updir_dn_png));
544 #include "images/file_newfolder_up_png.h"
545 #include "images/file_newfolder_hi_png.h"
546 #include "images/file_newfolder_dn_png.h"
547 new_vframes(3,default_filebox_newfolder_images,
548 new VFramePng(file_newfolder_up_png),
549 new VFramePng(file_newfolder_hi_png),
550 new VFramePng(file_newfolder_dn_png));
552 #include "images/file_rename_up_png.h"
553 #include "images/file_rename_hi_png.h"
554 #include "images/file_rename_dn_png.h"
555 new_vframes(3,default_filebox_rename_images,
556 new VFramePng(file_rename_up_png),
557 new VFramePng(file_rename_hi_png),
558 new VFramePng(file_rename_dn_png));
560 #include "images/file_delete_up_png.h"
561 #include "images/file_delete_hi_png.h"
562 #include "images/file_delete_dn_png.h"
563 new_vframes(3,default_filebox_delete_images,
564 new VFramePng(file_delete_up_png),
565 new VFramePng(file_delete_hi_png),
566 new VFramePng(file_delete_dn_png));
568 #include "images/file_reload_up_png.h"
569 #include "images/file_reload_hi_png.h"
570 #include "images/file_reload_dn_png.h"
571 new_vframes(3,default_filebox_reload_images,
572 new VFramePng(file_reload_up_png),
573 new VFramePng(file_reload_hi_png),
574 new VFramePng(file_reload_dn_png));
576 #include "images/file_size_capb_up_png.h"
577 #include "images/file_size_capb_hi_png.h"
578 #include "images/file_size_capb_dn_png.h"
579 #include "images/file_size_lwrb_up_png.h"
580 #include "images/file_size_lwrb_hi_png.h"
581 #include "images/file_size_lwrb_dn_png.h"
582 #include "images/file_size_semi_up_png.h"
583 #include "images/file_size_semi_hi_png.h"
584 #include "images/file_size_semi_dn_png.h"
585 #include "images/file_size_zero_up_png.h"
586 #include "images/file_size_zero_hi_png.h"
587 #include "images/file_size_zero_dn_png.h"
588 new_vframes(12,default_filebox_szfmt_images,
589 new VFramePng(file_size_zero_up_png),
590 new VFramePng(file_size_zero_hi_png),
591 new VFramePng(file_size_zero_dn_png),
592 new VFramePng(file_size_lwrb_up_png),
593 new VFramePng(file_size_lwrb_hi_png),
594 new VFramePng(file_size_lwrb_dn_png),
595 new VFramePng(file_size_capb_up_png),
596 new VFramePng(file_size_capb_hi_png),
597 new VFramePng(file_size_capb_dn_png),
598 new VFramePng(file_size_semi_up_png),
599 new VFramePng(file_size_semi_hi_png),
600 new VFramePng(file_size_semi_dn_png));
602 #include "images/listbox_button_dn_png.h"
603 #include "images/listbox_button_hi_png.h"
604 #include "images/listbox_button_up_png.h"
605 #include "images/listbox_button_disabled_png.h"
606 new_vframes(4,default_listbox_button,
607 new VFramePng(listbox_button_up_png),
608 new VFramePng(listbox_button_hi_png),
609 new VFramePng(listbox_button_dn_png),
610 new VFramePng(listbox_button_disabled_png));
612 default_listbox_bg = 0;
614 #include "images/listbox_expandchecked_png.h"
615 #include "images/listbox_expandcheckedhi_png.h"
616 #include "images/listbox_expanddn_png.h"
617 #include "images/listbox_expandup_png.h"
618 #include "images/listbox_expanduphi_png.h"
619 new_vframes(5,default_listbox_expand,
620 new VFramePng(listbox_expandup_png),
621 new VFramePng(listbox_expanduphi_png),
622 new VFramePng(listbox_expandchecked_png),
623 new VFramePng(listbox_expanddn_png),
624 new VFramePng(listbox_expandcheckedhi_png));
626 #include "images/listbox_columnup_png.h"
627 #include "images/listbox_columnhi_png.h"
628 #include "images/listbox_columndn_png.h"
629 new_vframes(3,default_listbox_column,
630 new VFramePng(listbox_columnup_png),
631 new VFramePng(listbox_columnhi_png),
632 new VFramePng(listbox_columndn_png));
634 #include "images/listbox_up_png.h"
635 default_listbox_up = new VFramePng(listbox_up_png);
637 #include "images/listbox_dn_png.h"
638 default_listbox_dn = new VFramePng(listbox_dn_png);
640 #include "images/pot_hi_png.h"
641 #include "images/pot_up_png.h"
642 #include "images/pot_dn_png.h"
643 new_vframes(3,default_pot_images,
644 new VFramePng(pot_up_png),
645 new VFramePng(pot_hi_png),
646 new VFramePng(pot_dn_png));
648 #include "images/progress_up_png.h"
649 #include "images/progress_hi_png.h"
650 new_vframes(2,default_progress_images,
651 new VFramePng(progress_up_png),
652 new VFramePng(progress_hi_png));
654 #include "images/7seg_small/0_png.h"
655 #include "images/7seg_small/1_png.h"
656 #include "images/7seg_small/2_png.h"
657 #include "images/7seg_small/3_png.h"
658 #include "images/7seg_small/4_png.h"
659 #include "images/7seg_small/5_png.h"
660 #include "images/7seg_small/6_png.h"
661 #include "images/7seg_small/7_png.h"
662 #include "images/7seg_small/8_png.h"
663 #include "images/7seg_small/9_png.h"
664 #include "images/7seg_small/colon_png.h"
665 #include "images/7seg_small/period_png.h"
666 #include "images/7seg_small/a_png.h"
667 #include "images/7seg_small/b_png.h"
668 #include "images/7seg_small/c_png.h"
669 #include "images/7seg_small/d_png.h"
670 #include "images/7seg_small/e_png.h"
671 #include "images/7seg_small/f_png.h"
672 #include "images/7seg_small/space_png.h"
673 #include "images/7seg_small/dash_png.h"
674 new_vframes(20,default_medium_7segment,
675 new VFramePng(_0_png),
676 new VFramePng(_1_png),
677 new VFramePng(_2_png),
678 new VFramePng(_3_png),
679 new VFramePng(_4_png),
680 new VFramePng(_5_png),
681 new VFramePng(_6_png),
682 new VFramePng(_7_png),
683 new VFramePng(_8_png),
684 new VFramePng(_9_png),
685 new VFramePng(colon_png),
686 new VFramePng(period_png),
687 new VFramePng(a_png),
688 new VFramePng(b_png),
689 new VFramePng(c_png),
690 new VFramePng(d_png),
691 new VFramePng(e_png),
692 new VFramePng(f_png),
693 new VFramePng(space_png),
694 new VFramePng(dash_png));
696 #include "images/hscroll_handle_up_png.h"
697 #include "images/hscroll_handle_hi_png.h"
698 #include "images/hscroll_handle_dn_png.h"
699 #include "images/hscroll_handle_bg_png.h"
700 #include "images/hscroll_left_up_png.h"
701 #include "images/hscroll_left_hi_png.h"
702 #include "images/hscroll_left_dn_png.h"
703 #include "images/hscroll_right_up_png.h"
704 #include "images/hscroll_right_hi_png.h"
705 #include "images/hscroll_right_dn_png.h"
706 new_vframes(10,default_hscroll_data,
707 new VFramePng(hscroll_handle_up_png),
708 new VFramePng(hscroll_handle_hi_png),
709 new VFramePng(hscroll_handle_dn_png),
710 new VFramePng(hscroll_handle_bg_png),
711 new VFramePng(hscroll_left_up_png),
712 new VFramePng(hscroll_left_hi_png),
713 new VFramePng(hscroll_left_dn_png),
714 new VFramePng(hscroll_right_up_png),
715 new VFramePng(hscroll_right_hi_png),
716 new VFramePng(hscroll_right_dn_png));
718 #include "images/vscroll_handle_up_png.h"
719 #include "images/vscroll_handle_hi_png.h"
720 #include "images/vscroll_handle_dn_png.h"
721 #include "images/vscroll_handle_bg_png.h"
722 #include "images/vscroll_left_up_png.h"
723 #include "images/vscroll_left_hi_png.h"
724 #include "images/vscroll_left_dn_png.h"
725 #include "images/vscroll_right_up_png.h"
726 #include "images/vscroll_right_hi_png.h"
727 #include "images/vscroll_right_dn_png.h"
728 new_vframes(10,default_vscroll_data,
729 new VFramePng(vscroll_handle_up_png),
730 new VFramePng(vscroll_handle_hi_png),
731 new VFramePng(vscroll_handle_dn_png),
732 new VFramePng(vscroll_handle_bg_png),
733 new VFramePng(vscroll_left_up_png),
734 new VFramePng(vscroll_left_hi_png),
735 new VFramePng(vscroll_left_dn_png),
736 new VFramePng(vscroll_right_up_png),
737 new VFramePng(vscroll_right_hi_png),
738 new VFramePng(vscroll_right_dn_png));
740 #include "images/default_icon_png.h"
741 default_icon_img = new VFramePng(default_icon_png);
743 type_to_icon = default_type_to_icon;
744 bar_data = default_bar;
745 check = default_check_image;
746 listbox_button = default_listbox_button;
747 listbox_bg = default_listbox_bg;
748 listbox_expand = default_listbox_expand;
749 listbox_column = default_listbox_column;
750 listbox_up = default_listbox_up;
751 listbox_dn = default_listbox_dn;
752 hscroll_data = default_hscroll_data;
753 vscroll_data = default_vscroll_data;
754 default_icon = default_icon_img;
756 listbox_title_overlap = 0;
757 listbox_title_margin = 0;
758 listbox_title_color = BLACK;
759 listbox_title_hotspot = xS(5);
761 listbox_border1 = DKGREY;
762 listbox_border2_hi = RED;
763 listbox_border2 = BLACK;
764 listbox_border3_hi = RED;
765 listbox_border3 = MEGREY;
766 listbox_border4 = WHITE;
767 listbox_selected = BLUE;
768 listbox_highlighted = LTGREY;
769 listbox_inactive = WHITE;
770 listbox_text = BLACK;
773 pan_text_color = YELLOW;
775 generic_button_margin = xS(15);
776 draw_clock_background=1;
783 bg_light2 = bg_color;
786 border_light1 = bg_color;
787 border_light2 = MEGREY;
788 border_shadow1 = BLACK;
789 border_shadow2 = bg_color;
791 default_text_color = BLACK;
792 disabled_text_color = DMGREY;
794 button_light = MEGREY; // bright corner
795 // button_highlighted = LTGREY; // face when highlighted
796 button_highlighted = 0xffe000; // face when highlighted
797 button_down = MDGREY; // face when down
798 // button_up = MEGREY; // face when up
799 button_up = 0xffc000; // face when up
800 button_shadow = BLACK; // dark corner
801 button_uphighlighted = RED; // upper side when highlighted
804 tumblepatch_data = 0;
805 tumble_duration = 150;
807 ok_images = default_ok_images;
808 cancel_images = default_cancel_images;
809 usethis_button_images = default_usethis_images;
810 filebox_descend_images = default_ok_images;
813 menu_highlighted = LTBLUE;
816 menu_shadow = DKCYAN;
818 menu_title_bg = default_menubar_data;
819 menu_popup_bg = default_menu_popup_bg;
820 menu_bar_bg = default_menu_bar_bg;
822 popupmenu_images = 0;
825 popupmenu_margin = xS(10);
827 popupmenu_triangle_margin = xS(10);
830 menu_title_text = BLACK;
831 popup_title_text = BLACK;
832 menu_item_text = BLACK;
833 menu_highlighted_fontcolor = BLACK;
834 progress_text = BLACK;
835 grab_input_focus = 1;
837 text_default = BLACK;
838 highlight_inverse = WHITE ^ BLUE;
839 text_background = WHITE;
840 text_background_disarmed = 0xc08080;
841 text_background_hi = LTYELLOW;
842 text_background_noborder_hi = LTGREY;
843 text_background_noborder = -1;
844 text_border1 = DKGREY;
845 text_border2 = BLACK;
846 text_border2_hi = RED;
847 text_border3 = MEGREY;
848 text_border3_hi = LTPINK;
849 text_border4 = WHITE;
850 text_highlight = BLUE;
851 text_selected_highlight = SLBLUE;
852 text_inactive_highlight = MEGREY;
854 toggle_highlight_bg = 0;
855 toggle_text_margin = 0;
857 // Delays must all be different for repeaters
861 tooltip_delay = 1000;
862 tooltip_bg_color = YELLOW;
863 tooltips_enabled = 1;
864 textbox_focus_policy = 0;
866 filebox_margin = yS(110);
867 dirbox_margin = yS(90);
868 filebox_mode = LISTBOX_TEXT;
869 sprintf(filebox_filter, "*");
872 filebox_columntype[0] = FILEBOX_NAME;
873 filebox_columntype[1] = FILEBOX_SIZE;
874 filebox_columntype[2] = FILEBOX_DATE;
875 filebox_columntype[3] = FILEBOX_EXTENSION;
876 filebox_columnwidth[0] = xS(300);
877 filebox_columnwidth[1] = xS(100);
878 filebox_columnwidth[2] = xS(150);
879 filebox_columnwidth[3] = xS(49);
880 dirbox_columntype[0] = FILEBOX_NAME;
881 dirbox_columntype[1] = FILEBOX_DATE;
882 dirbox_columnwidth[0] = xS(400);
883 dirbox_columnwidth[1] = xS(199);
885 filebox_text_images = default_filebox_text_images;
886 filebox_icons_images = default_filebox_icons_images;
887 filebox_updir_images = default_filebox_updir_images;
888 filebox_newfolder_images = default_filebox_newfolder_images;
889 filebox_rename_images = default_filebox_rename_images;
890 filebox_delete_images = default_filebox_delete_images;
891 filebox_reload_images = default_filebox_reload_images;
892 filebox_szfmt_images = default_filebox_szfmt_images;
893 filebox_size_format = FILEBOX_SIZE_RAW;
894 directory_color = BLUE;
897 filebox_sortcolumn = 0;
898 filebox_sortorder = BC_ListBox::SORT_ASCENDING;
899 dirbox_sortcolumn = 0;
900 dirbox_sortorder = BC_ListBox::SORT_ASCENDING;
903 pot_images = default_pot_images;
905 pot_x1 = pot_images[0]->get_w() / 2 - xS(pot_offset);
906 pot_y1 = pot_images[0]->get_h() / 2 - yS(pot_offset);
908 pot_needle_color = BLACK;
910 progress_images = default_progress_images;
914 meter_font = SMALLFONT_3D;
915 meter_font_color = RED;
916 meter_title_w = xS(20);
918 medium_7segment = default_medium_7segment;
920 audiovideo_color = RED;
924 // Xft has priority over font set
926 // But Xft dies in 32 bit mode after some amount of drawing.
932 drag_radius = xS(10);
933 recursive_resizing = 1;
936 void BC_Resources::del_vframes(VFrame *vframes[], int n)
938 while( --n >= 0 ) delete vframes[n];
941 BC_Resources::~BC_Resources()
944 delete create_window_lock;
945 del_vframes(default_type_to_icon, 6);
947 del_vframes(default_cancel_images, 3);
948 del_vframes(default_ok_images, 3);
949 del_vframes(default_usethis_images, 3);
951 del_vframes(default_checkbox_images, 5);
952 del_vframes(default_radial_images, 5);
953 del_vframes(default_label_images, 5);
955 del_vframes(default_menuitem_data, 3);
956 del_vframes(default_menubar_data, 3);
957 delete default_menu_popup_bg;
958 delete default_menu_bar_bg;
959 delete default_check_image;
960 del_vframes(default_filebox_text_images, 3);
961 del_vframes(default_filebox_icons_images, 3);
962 del_vframes(default_filebox_updir_images, 3);
963 del_vframes(default_filebox_newfolder_images, 3);
964 del_vframes(default_filebox_rename_images, 3);
965 del_vframes(default_filebox_delete_images, 3);
966 del_vframes(default_filebox_reload_images, 3);
967 del_vframes(default_filebox_szfmt_images, 12);
968 del_vframes(default_listbox_button, 4);
969 delete default_listbox_bg;
970 del_vframes(default_listbox_expand, 5);
971 del_vframes(default_listbox_column, 3);
972 delete default_listbox_up;
973 delete default_listbox_dn;
974 del_vframes(default_pot_images, 3);
975 del_vframes(default_progress_images, 2);
976 del_vframes(default_medium_7segment, 20);
977 del_vframes(default_vscroll_data, 10);
978 del_vframes(default_hscroll_data, 10);
980 fontlist->remove_all_objects();
983 delete default_icon_img;
987 int BC_Resources::initialize_display(BC_WindowBase *window)
989 // Set up IPC cleanup handlers
992 // Test for shm. Must come before yuv test
998 void BC_Resources::init_shm(BC_WindowBase *window)
1001 int (*old_handler)(Display *, XErrorEvent *) =
1002 XSetErrorHandler(BC_Resources::x_error_handler);
1004 if(XShmQueryExtension(window->display))
1006 XShmSegmentInfo test_shm;
1007 memset(&test_shm,0,sizeof(test_shm));
1008 XImage *test_image = XShmCreateImage(window->display, window->vis,
1009 window->default_depth, ZPixmap, (char*)NULL, &test_shm, 5, 5);
1010 BC_Resources::error = 0;
1011 test_shm.shmid = shmget(IPC_PRIVATE, 5 * test_image->bytes_per_line, (IPC_CREAT | 0600));
1012 if(test_shm.shmid != -1) {
1013 char *data = (char *)shmat(test_shm.shmid, NULL, 0);
1014 if(data != (void *)-1) {
1015 shmctl(test_shm.shmid, IPC_RMID, 0);
1016 test_shm.shmaddr = data;
1017 test_shm.readOnly = 0;
1019 if(XShmAttach(window->display, &test_shm)) {
1020 XSync(window->display, False);
1027 XDestroyImage(test_image);
1028 if(BC_Resources::error) use_shm = 0;
1030 XSetErrorHandler(old_handler);
1036 BC_Synchronous* BC_Resources::get_synchronous()
1041 void BC_Resources::set_synchronous(BC_Synchronous *synchronous)
1043 this->synchronous = synchronous;
1049 int BC_Resources::get_bg_color() { return bg_color; }
1051 int BC_Resources::get_bg_shadow1() { return bg_shadow1; }
1053 int BC_Resources::get_bg_shadow2() { return bg_shadow2; }
1055 int BC_Resources::get_bg_light1() { return bg_light1; }
1057 int BC_Resources::get_bg_light2() { return bg_light2; }
1060 int BC_Resources::get_id()
1062 id_lock->lock("BC_Resources::get_id");
1068 int BC_Resources::get_filebox_id()
1070 id_lock->lock("BC_Resources::get_filebox_id");
1071 int result = filebox_id++;
1077 void BC_Resources::set_signals(BC_Signals *signal_handler)
1079 BC_Resources::signal_handler = signal_handler;
1082 int BC_Resources::init_fontconfig(const char *search_path)
1084 if( fontlist ) return 0;
1085 fontlist = new ArrayList<BC_FontEntry*>;
1087 #define get_str(str,sep,ptr,cond) do { char *out = str; \
1088 while( *ptr && !strchr(sep,*ptr) && (cond) ) *out++ = *ptr++; \
1092 #define skip_str(sep, ptr) do { \
1093 while( *ptr && strchr(sep,*ptr) ) ++ptr; \
1096 char find_command[BCTEXTLEN];
1097 char *fp = find_command, *ep = fp+sizeof(find_command)-1;
1098 fp += snprintf(fp, ep-fp, "%s", "find");
1099 const char *bc_font_path = getenv("BC_FONT_PATH");
1100 // if BC_FONT_PATH starts with ':', omit default path
1101 if( !(bc_font_path && bc_font_path[0] == ':') )
1102 fp += snprintf(fp, ep-fp, " '%s'", search_path);
1103 if( bc_font_path ) {
1104 const char *path = bc_font_path;
1106 char font_path[BCTEXTLEN];
1107 const char *cp = strchr(path,':');
1108 int len = !cp ? strlen(path) : cp-path;
1110 memcpy(font_path, path, len);
1111 font_path[len] = 0; path += len;
1112 fp += snprintf(fp, ep-fp, " '%s'", font_path);
1117 fp += snprintf(fp, ep-fp, " -name 'fonts.scale' -print -exec cat {} \\;");
1118 FILE *in = popen(find_command, "r");
1120 FT_Library freetype_library = 0;
1121 // FT_Face freetype_face = 0;
1122 // ft_Init_FreeType(&freetype_library);
1124 char line[BCTEXTLEN], current_dir[BCTEXTLEN];
1127 while( !feof(in) && fgets(line, BCTEXTLEN, in) ) {
1128 if(!strlen(line)) break;
1130 char *in_ptr = line;
1132 // Get current directory
1133 if(line[0] == '/') {
1134 get_str(current_dir, "\n", in_ptr,1);
1135 for( int i=strlen(current_dir); --i>=0 && current_dir[i]!='/'; )
1140 //printf("TitleMain::build_fonts %s\n", line);
1141 BC_FontEntry *entry = new BC_FontEntry;
1142 char string[BCTEXTLEN];
1144 get_str(string, "\n", in_ptr, in_ptr[0]!=' ' || in_ptr[1]!='-');
1145 entry->path = cstrcat(2, current_dir, string);
1147 skip_str(" -", in_ptr);
1148 get_str(string, "-\n", in_ptr, 1);
1149 if( !string[0] ) { delete entry; continue; }
1150 entry->foundry = cstrdup(string);
1151 if(*in_ptr == '-') in_ptr++;
1153 get_str(string, "-\n", in_ptr, 1);
1154 if( !string[0] ) { delete entry; continue; }
1155 entry->family = cstrdup(string);
1156 if(*in_ptr == '-') in_ptr++;
1158 get_str(string, "-\n", in_ptr, 1);
1159 entry->weight = cstrdup(string);
1160 if(*in_ptr == '-') in_ptr++;
1162 get_str(string, "-\n", in_ptr, 1);
1163 entry->slant = cstrdup(string);
1164 if(*in_ptr == '-') in_ptr++;
1166 get_str(string, "-\n", in_ptr, 1);
1167 entry->swidth = cstrdup(string);
1168 if(*in_ptr == '-') in_ptr++;
1170 get_str(string, "-\n", in_ptr, 1);
1171 entry->adstyle = cstrdup(string);
1172 if(*in_ptr == '-') in_ptr++;
1174 get_str(string, "-\n", in_ptr, 1);
1175 entry->pixelsize = atol(string);
1176 if(*in_ptr == '-') in_ptr++;
1178 get_str(string, "-\n", in_ptr, 1);
1179 entry->pointsize = atol(string);
1180 if(*in_ptr == '-') in_ptr++;
1182 get_str(string, "-\n", in_ptr, 1);
1183 entry->xres = atol(string);
1184 if(*in_ptr == '-') in_ptr++;
1186 get_str(string, "-\n", in_ptr, 1);
1187 entry->yres = atol(string);
1188 if(*in_ptr == '-') in_ptr++;
1190 get_str(string, "-\n", in_ptr, 1);
1191 entry->spacing = cstrdup(string);
1192 if(*in_ptr == '-') in_ptr++;
1194 get_str(string, "-\n", in_ptr, 1);
1195 entry->avg_width = atol(string);
1196 if(*in_ptr == '-') in_ptr++;
1198 get_str(string, "-\n", in_ptr, 1);
1199 entry->registry = cstrdup(string);
1200 if(*in_ptr == '-') in_ptr++;
1202 get_str(string, "-\n", in_ptr, 1);
1203 entry->encoding = cstrdup(string);
1204 if(*in_ptr == '-') in_ptr++;
1207 //printf("TitleMain::build_fonts 1 %s\n", entry->path);
1208 // This takes a real long time to do. Instead just take all fonts
1209 // if(!load_freetype_face(freetype_library,
1210 // freetype_face, entry->path) )
1212 sprintf(line, "%s (%s)", entry->family, entry->foundry);
1213 entry->displayname = cstrdup(line);
1215 if(!strcasecmp(entry->weight, "demibold")) {
1216 entry->fixed_style |= BC_FONT_BOLD;
1217 entry->style |= FL_WEIGHT_DEMIBOLD;
1219 else if(!strcasecmp(entry->weight, "bold")) {
1220 entry->fixed_style |= BC_FONT_BOLD;
1221 entry->style |= FL_WEIGHT_BOLD;
1224 entry->style |= FL_WEIGHT_NORMAL;
1227 if(!strcasecmp(entry->slant, "r")) {
1228 entry->style |= FL_SLANT_ROMAN;
1230 else if(!strcasecmp(entry->slant, "i")) {
1231 entry->style |= FL_SLANT_ITALIC;
1232 entry->fixed_style |= BC_FONT_ITALIC;
1234 else if(!strcasecmp(entry->slant, "o")) {
1235 entry->style |= FL_SLANT_OBLIQUE;
1236 entry->fixed_style |= BC_FONT_ITALIC;
1239 if(!strcasecmp(entry->swidth, "normal"))
1240 entry->style |= FL_WIDTH_NORMAL;
1241 else if(!strcasecmp(entry->swidth, "ultracondensed"))
1242 entry->style |= FL_WIDTH_ULTRACONDENSED;
1243 else if(!strcasecmp(entry->swidth, "extracondensed"))
1244 entry->style |= FL_WIDTH_EXTRACONDENSED;
1245 else if(!strcasecmp(entry->swidth, "condensed"))
1246 entry->style |= FL_WIDTH_CONDENSED;
1247 else if(!strcasecmp(entry->swidth, "semicondensed"))
1248 entry->style |= FL_WIDTH_SEMICONDENSED;
1249 else if(!strcasecmp(entry->swidth, "semiexpanded"))
1250 entry->style |= FL_WIDTH_SEMIEXPANDED;
1251 else if(!strcasecmp(entry->swidth, "expanded"))
1252 entry->style |= FL_WIDTH_EXPANDED;
1253 else if(!strcasecmp(entry->swidth, "extraexpanded"))
1254 entry->style |= FL_WIDTH_EXTRAEXPANDED;
1255 else if(!strcasecmp(entry->swidth, "ultraexpanded"))
1256 entry->style |= FL_WIDTH_ULTRAEXPANDED;
1258 entry->style |= FL_WIDTH_NORMAL;
1260 fontlist->append(entry);
1262 dump_font_entry(stdout, "font 0: ", entry);
1264 // printf("TitleMain::build_fonts %s: success\n", entry->path);
1265 //printf("TitleMain::build_fonts 2\n");
1269 if( bc_font_path && bc_font_path[0] == ':' )
1272 // Load all the fonts from fontconfig
1276 FcChar8 *family, *file, *foundry, *style, *format;
1277 int slant, spacing, width, weight;
1278 int force_style = 0;
1279 // if you want limit search to TrueType put 1
1280 int limit_to_trutype = 1;
1283 char tmpstring[BCTEXTLEN];
1286 config = fcConfigGetCurrent();
1287 fcConfigSetRescanInterval(config, 0);
1289 pat = fcPatternCreate();
1290 os = fcObjectSetBuild( FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
1291 FC_WIDTH, FC_SLANT, FC_FONTFORMAT, FC_SPACING, FC_STYLE, (char *) 0);
1292 fcPatternAddBool(pat, FC_SCALABLE, true);
1295 char langstr[LEN_LANG * 3];
1296 strcpy(langstr, language);
1299 strcat(langstr, "-");
1300 strcat(langstr, region);
1303 FcLangSet *ls = fcLangSetCreate();
1304 if(fcLangSetAdd(ls, (const FcChar8*)langstr))
1305 if(fcPatternAddLangSet(pat, FC_LANG, ls))
1306 fcLangSetDestroy(ls);
1309 fs = fcFontList(config, pat, os);
1310 fcPatternDestroy(pat);
1311 fcObjectSetDestroy(os);
1313 for (i = 0; fs && i < fs->nfont; i++) {
1314 FcPattern *font = fs->fonts[i];
1316 fcPatternGetString(font, FC_FONTFORMAT, 0, &format);
1317 //on this point you can limit font search
1318 if(limit_to_trutype && strcmp((char *)format, "TrueType"))
1321 sprintf(tmpstring, "%s", format);
1322 BC_FontEntry *entry = new BC_FontEntry;
1323 if(fcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
1324 entry->path = cstrdup((char*)file);
1327 if(fcPatternGetString(font, FC_FOUNDRY, 0, &foundry) == FcResultMatch) {
1328 entry->foundry = cstrdup((char*)foundry);
1331 if(fcPatternGetInteger(font, FC_WEIGHT, 0, &weight) == FcResultMatch) {
1333 case FC_WEIGHT_THIN:
1334 case FC_WEIGHT_EXTRALIGHT:
1335 case FC_WEIGHT_LIGHT:
1336 case FC_WEIGHT_BOOK:
1338 entry->weight = cstrdup("medium");
1341 case FC_WEIGHT_NORMAL:
1342 case FC_WEIGHT_MEDIUM:
1344 entry->weight = cstrdup("medium");
1347 case FC_WEIGHT_BLACK:
1348 case FC_WEIGHT_SEMIBOLD:
1349 case FC_WEIGHT_BOLD:
1350 entry->weight = cstrdup("bold");
1351 entry->fixed_style |= BC_FONT_BOLD;
1354 case FC_WEIGHT_EXTRABOLD:
1355 case FC_WEIGHT_EXTRABLACK:
1357 entry->weight = cstrdup("bold");
1358 entry->fixed_style |= BC_FONT_BOLD;
1363 if(fcPatternGetString(font, FC_FAMILY, 0, &family) == FcResultMatch)
1364 entry->family = cstrdup((char*)family);
1366 if(fcPatternGetInteger(font, FC_SLANT, 0, &slant) == FcResultMatch) {
1368 case FC_SLANT_ROMAN:
1370 entry->slant = cstrdup("r");
1371 entry->style |= FL_SLANT_ROMAN;
1373 case FC_SLANT_ITALIC:
1374 entry->slant = cstrdup("i");
1375 entry->style |= FL_SLANT_ITALIC;
1376 entry->fixed_style |= BC_FONT_ITALIC;
1378 case FC_SLANT_OBLIQUE:
1379 entry->slant = cstrdup("o");
1380 entry->style |= FL_SLANT_OBLIQUE;
1381 entry->fixed_style |= BC_FONT_ITALIC;
1386 if(fcPatternGetInteger(font, FC_WIDTH, 0, &width) == FcResultMatch) {
1388 case FC_WIDTH_ULTRACONDENSED:
1389 entry->swidth = cstrdup("ultracondensed");
1392 case FC_WIDTH_EXTRACONDENSED:
1393 entry->swidth = cstrdup("extracondensed");
1396 case FC_WIDTH_CONDENSED:
1397 entry->swidth = cstrdup("condensed");
1399 case FC_WIDTH_SEMICONDENSED:
1400 entry->swidth = cstrdup("semicondensed");
1403 case FC_WIDTH_NORMAL:
1405 entry->swidth = cstrdup("normal");
1408 case FC_WIDTH_SEMIEXPANDED:
1409 entry->swidth = cstrdup("semiexpanded");
1412 case FC_WIDTH_EXPANDED:
1413 entry->swidth = cstrdup("expanded");
1416 case FC_WIDTH_EXTRAEXPANDED:
1417 entry->swidth = cstrdup("extraexpanded");
1420 case FC_WIDTH_ULTRAEXPANDED:
1421 entry->swidth = cstrdup("ultraexpanded");
1426 if(fcPatternGetInteger(font, FC_SPACING, 0, &spacing) == FcResultMatch) {
1430 entry->spacing = cstrdup("p");
1434 entry->spacing = cstrdup("d");
1438 entry->spacing = cstrdup("m");
1442 entry->spacing = cstrdup("c");
1447 // Add fake stuff for compatibility
1448 entry->adstyle = cstrdup(" ");
1449 entry->pixelsize = 0;
1450 entry->pointsize = 0;
1453 entry->avg_width = 0;
1454 entry->registry = cstrdup("utf");
1455 entry->encoding = cstrdup("8");
1457 if( fcPatternGetString(font, FC_STYLE, 0, &style) != FcResultMatch )
1460 // If font has a style unmanaged by titler plugin, force style to be displayed on name
1461 // in this way we can shown all available fonts styles.
1463 sprintf(tmpstring, "%s (%s)", entry->family, style);
1464 entry->displayname = cstrdup(tmpstring);
1467 if(strcmp(entry->foundry, "unknown")) {
1468 sprintf(tmpstring, "%s (%s)", entry->family, entry->foundry);
1469 entry->displayname = cstrdup(tmpstring);
1472 sprintf(tmpstring, "%s", entry->family);
1473 entry->displayname = cstrdup(tmpstring);
1477 fontlist->append(entry);
1479 dump_font_entry(stdout, "font 1: ", entry);
1482 fcFontSetDestroy(fs);
1483 if(freetype_library)
1484 ft_Done_FreeType(freetype_library);
1485 // for(int i = 0; i < fonts->total; i++)
1486 // fonts->values[i]->dump();
1488 fcConfigAppFontAddDir(0, (const FcChar8*)search_path);
1489 fcConfigSetRescanInterval(0, 0);
1491 os = fcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
1492 FC_WIDTH, FC_SLANT, FC_SPACING, FC_STYLE, (char *)0);
1493 pat = fcPatternCreate();
1494 fcPatternAddBool(pat, FC_SCALABLE, true);
1498 char langstr[LEN_LANG * 3];
1499 strcpy(langstr, language);
1503 strcat(langstr, "-");
1504 strcat(langstr, region);
1507 FcLangSet *ls = fcLangSetCreate();
1508 if(fcLangSetAdd(ls, (const FcChar8*)langstr))
1509 if(fcPatternAddLangSet(pat, FC_LANG, ls))
1510 fcLangSetDestroy(ls);
1513 fs = fcFontList(0, pat, os);
1514 fcPatternDestroy(pat);
1515 fcObjectSetDestroy(os);
1517 for(int i = 0; i < fs->nfont; i++)
1519 FcPattern *font = fs->fonts[i];
1520 BC_FontEntry *entry = new BC_FontEntry;
1523 if(fcPatternGetString(font, FC_FILE, 0, &strvalue) == FcResultMatch)
1525 entry->path = new char[strlen((char*)strvalue) + 1];
1526 strcpy(entry->path, (char*)strvalue);
1529 if(fcPatternGetString(font, FC_FOUNDRY, 0, &strvalue) == FcResultMatch)
1531 entry->foundry = new char[strlen((char*)strvalue) + 1];
1532 strcpy(entry->foundry, (char *)strvalue);
1535 if(fcPatternGetString(font, FC_FAMILY, 0, &strvalue) == FcResultMatch)
1537 entry->family = new char[strlen((char*)strvalue) + 2];
1538 strcpy(entry->family, (char*)strvalue);
1542 if(fcPatternGetInteger(font, FC_SLANT, 0, &intvalue) == FcResultMatch)
1546 case FC_SLANT_ROMAN:
1548 entry->style |= FL_SLANT_ROMAN;
1551 case FC_SLANT_ITALIC:
1552 entry->style |= FL_SLANT_ITALIC;
1555 case FC_SLANT_OBLIQUE:
1556 entry->style |= FL_SLANT_OBLIQUE;
1561 if(fcPatternGetInteger(font, FC_WEIGHT, 0, &intvalue) == FcResultMatch)
1565 case FC_WEIGHT_THIN:
1566 entry->style |= FL_WEIGHT_THIN;
1569 case FC_WEIGHT_EXTRALIGHT:
1570 entry->style |= FL_WEIGHT_EXTRALIGHT;
1573 case FC_WEIGHT_LIGHT:
1574 entry->style |= FL_WEIGHT_LIGHT;
1577 case FC_WEIGHT_BOOK:
1578 entry->style |= FL_WEIGHT_BOOK;
1581 case FC_WEIGHT_NORMAL:
1583 entry->style |= FL_WEIGHT_NORMAL;
1586 case FC_WEIGHT_MEDIUM:
1587 entry->style |= FL_WEIGHT_MEDIUM;
1590 case FC_WEIGHT_DEMIBOLD:
1591 entry->style |= FL_WEIGHT_DEMIBOLD;
1594 case FC_WEIGHT_BOLD:
1595 entry->style |= FL_WEIGHT_BOLD;
1598 case FC_WEIGHT_EXTRABOLD:
1599 entry->style |= FL_WEIGHT_EXTRABOLD;
1602 case FC_WEIGHT_BLACK:
1603 entry->style |= FL_WEIGHT_BLACK;
1606 case FC_WEIGHT_EXTRABLACK:
1607 entry->style |= FL_WEIGHT_EXTRABLACK;
1612 if(fcPatternGetInteger(font, FC_WIDTH, 0, &intvalue) == FcResultMatch)
1616 case FC_WIDTH_ULTRACONDENSED:
1617 entry->style |= FL_WIDTH_ULTRACONDENSED;
1620 case FC_WIDTH_EXTRACONDENSED:
1621 entry->style |= FL_WIDTH_EXTRACONDENSED;
1624 case FC_WIDTH_CONDENSED:
1625 entry->style |= FL_WIDTH_CONDENSED;
1628 case FC_WIDTH_SEMICONDENSED:
1629 entry->style = FL_WIDTH_SEMICONDENSED;
1632 case FC_WIDTH_NORMAL:
1634 entry->style |= FL_WIDTH_NORMAL;
1637 case FC_WIDTH_SEMIEXPANDED:
1638 entry->style |= FL_WIDTH_SEMIEXPANDED;
1641 case FC_WIDTH_EXPANDED:
1642 entry->style |= FL_WIDTH_EXPANDED;
1645 case FC_WIDTH_EXTRAEXPANDED:
1646 entry->style |= FL_WIDTH_EXTRAEXPANDED;
1649 case FC_WIDTH_ULTRAEXPANDED:
1650 entry->style |= FL_WIDTH_ULTRAEXPANDED;
1654 if(fcPatternGetInteger(font, FC_SPACING, 0, &intvalue) == FcResultMatch)
1658 case FC_PROPORTIONAL:
1660 entry->style |= FL_PROPORTIONAL;
1664 entry->style |= FL_DUAL;
1668 entry->style |= FL_MONO;
1672 entry->style |= FL_CHARCELL;
1676 if(entry->foundry && strcmp(entry->foundry, "unknown"))
1678 char tempstr[BCTEXTLEN];
1679 sprintf(tempstr, "%s (%s)", entry->family, entry->foundry);
1680 entry->displayname = new char[strlen(tempstr) + 1];
1681 strcpy(entry->displayname, tempstr);
1685 entry->displayname = new char[strlen(entry->family) + 1];
1686 strcpy(entry->displayname, entry->family);
1688 fontlist->append(entry);
1690 dump_font_entry(stdout, "font 2: ", entry);
1692 fcFontSetDestroy(fs);
1696 #define STYLE_MATCH(fst, stl, msk) ((fst) & (msk) & (stl)) && \
1697 !((fst) & ~(style) & (msk))
1699 BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style,
1700 int mask, int preferred)
1702 BC_FontEntry *entry, *style_match, *preferred_match;
1708 preferred_match = 0;
1712 for(int i = 0; i < fontlist->total; i++)
1714 entry = fontlist->values[i];
1716 if(strcmp(entry->displayname, displayname) == 0 &&
1717 STYLE_MATCH(entry->style, style, mask))
1720 style_match = entry;
1721 if(!preferred_match && entry->fixed_style == preferred)
1722 preferred_match = entry;
1726 return preferred_match;
1732 // No exact match - assume normal width font
1733 style |= FL_WIDTH_NORMAL;
1734 mask |= FL_WIDTH_MASK;
1736 preferred_match = 0;
1738 for(int i = 0; i < fontlist->total; i++)
1740 entry = fontlist->values[i];
1742 if(STYLE_MATCH(entry->style, style, mask))
1745 style_match = entry;
1747 if(!preferred_match && (entry->style & preferred))
1748 preferred_match = entry;
1750 if(!strncasecmp(displayname, entry->family,
1751 strlen(entry->family)))
1757 return preferred_match;
1764 uint8_t *obfr, *out, *oend;
1765 uint8_t *ibfr, *inp, *iend;
1767 utf8conv(void *out, int olen, void *inp, int ilen) {
1768 this->obfr = this->out = (uint8_t*)out;
1769 this->oend = this->out + olen;
1770 this->ibfr = this->inp = (uint8_t*)inp;
1771 this->iend = this->inp + ilen;
1773 int cur() { return inp>=iend ? -1 : *inp; }
1774 int next() { return inp>=iend ? -1 : *inp++; }
1775 int next(int ch) { return out>=oend ? -1 : *out++ = ch; }
1776 int ilen() { return inp-ibfr; }
1777 int olen() { return out-obfr; }
1779 int wnext(unsigned int v);
1783 wnext(unsigned int v)
1785 if( v < 0x00000080 ) { next(v); return 1; }
1786 int n = v < 0x00000800 ? 2 : v < 0x00010000 ? 3 :
1787 v < 0x00200000 ? 4 : v < 0x04000000 ? 5 : 6;
1788 int m = (0xff00 >> n), i = n-1;
1789 next((v>>(6*i)) | m);
1790 while( --i >= 0 ) next(((v>>(6*i)) & 0x3f) | 0x80);
1797 int v = 0, n = 0, ch = next();
1799 static const unsigned char byts[] = {
1800 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 5,
1803 n = i<0 ? 0 : byts[i/4];
1804 for( v=ch, i=n; --i>=0; v+=next() ) v <<= 6;
1805 static const unsigned int ofs[6] = {
1806 0x00000000U, 0x00003080U, 0x000E2080U,
1807 0x03C82080U, 0xFA082080U, 0x82082080U
1817 size_t BC_Resources::encode(const char *from_enc, const char *to_enc,
1818 char *input, int input_length, char *output, int output_length)
1820 if( !from_enc || *from_enc == 0 ||
1821 !strcmp(from_enc,"UTF8") || !strcmp(from_enc, "US-ASCII") )
1824 if( !to_enc || *to_enc == 0 ||
1825 !strcmp(to_enc,"UTF8") || !strcmp(to_enc, "US-ASCII") )
1829 char *outbase = output;
1830 size_t inbytes = input_length < 0 ? strlen(input) : input_length;
1831 size_t outbytes = output_length;
1833 if( inbytes && outbytes ) {
1834 if( !strcmp(from_enc, to_enc) ) {
1835 if( inbytes > outbytes ) inbytes = outbytes;
1836 memcpy(output, input, inbytes);
1838 outbytes -= inbytes;
1840 else if( !strcmp(from_enc, "UTF-8") && !strcmp(to_enc,"UTF32LE") ) {
1841 utf8conv uc(0,0, input,inbytes);
1842 uint32_t *op = (uint32_t *)output;
1843 uint32_t *ep = (uint32_t *)(output+output_length);
1844 for( int wch; op<ep && (wch=uc.wnext())>=0; *op++=wch );
1845 output = (char *)op;
1846 outbytes = (char*)ep - output;
1848 else if( !strcmp(from_enc, "UTF32LE") && !strcmp(to_enc,"UTF-8") ) {
1849 utf8conv uc(output,output_length, 0,0);
1850 uint32_t *ip = (uint32_t *)input;
1851 uint32_t *ep = (uint32_t *)(input+inbytes);
1852 for( ; ip<ep && uc.wnext(*ip)>=0; ++ip );
1853 output += uc.olen();
1854 outbytes -= uc.olen();
1856 else if( (cd = iconv_open(to_enc, from_enc)) != (iconv_t)-1 ) {
1857 iconv(cd, &input, &inbytes, &output, &outbytes);
1861 printf(_("Conversion from %s to %s is not available\n"),
1865 if( outbytes > sizeof(uint32_t) )
1866 outbytes = sizeof(uint32_t);
1867 for( uint32_t i = 0; i < outbytes; i++)
1869 return output - outbase;
1872 void BC_Resources::encode_to_utf8(char *buffer, int buflen)
1874 if(BC_Resources::locale_utf8) return;
1876 encode(encoding, 0, buffer, -1, lbuf, buflen);
1877 strcpy(buffer, lbuf);
1880 int BC_Resources::find_font_by_char(FT_ULong char_code, char *path_new, const FT_Face oldface)
1882 FcPattern *font, *ofont;
1888 // Do not search control codes
1892 if( (ofont = fcFreeTypeQueryFace(oldface, (const FcChar8*)"", 4097, 0)) != 0 ) {
1893 if( (font = find_similar_font(char_code, ofont)) != 0 ) {
1894 if(fcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
1895 strcpy(path_new, (char*)file);
1898 fcPatternDestroy(font);
1900 fcPatternDestroy(ofont);
1905 FcPattern* BC_Resources::find_similar_font(FT_ULong char_code, FcPattern *oldfont)
1907 FcPattern *pat, *font;
1913 // Do not search control codes
1917 fontconfig_lock.lock("BC_Resources::find_similar_font");
1918 pat = fcPatternCreate();
1919 os = fcObjectSetBuild(FC_FILE, FC_CHARSET, FC_SCALABLE, FC_FAMILY,
1920 FC_SLANT, FC_WEIGHT, FC_WIDTH, (char *)0);
1922 fcPatternAddBool(pat, FC_SCALABLE, true);
1923 fcs = fcCharSetCreate();
1924 if(fcCharSetAddChar(fcs, char_code))
1925 fcPatternAddCharSet(pat, FC_CHARSET, fcs);
1926 fcCharSetDestroy(fcs);
1927 for( int i=0; i<(int)LEN_FCPROP; ++i ) {
1928 if(fcPatternGetInteger(oldfont, fc_properties[i], 0, &ival) == FcResultMatch)
1929 fcPatternAddInteger(pat, fc_properties[i], ival);
1931 fs = fcFontList(0, pat, os);
1932 for( int i=LEN_FCPROP; --i>=0 && !fs->nfont; ) {
1933 fcFontSetDestroy(fs);
1934 fcPatternDel(pat, fc_properties[i]);
1935 fs = fcFontList(0, pat, os);
1937 fcPatternDestroy(pat);
1938 fcObjectSetDestroy(os);
1942 for (int i = 0; i < fs->nfont; i++)
1944 font = fs->fonts[i];
1945 if(fcPatternGetCharSet(font, FC_CHARSET, 0, &fcs) == FcResultMatch)
1947 if(fcCharSetHasChar(fcs, char_code))
1949 pat = fcPatternDuplicate(font);
1954 fcFontSetDestroy(fs);
1955 fontconfig_lock.unlock();
1960 void BC_Resources::dump_fonts(FILE *fp)
1962 for( int i=0; i<fontlist->total; ++i )
1963 dump_font_entry(fp, "", fontlist->values[i]);
1966 void BC_Resources::dump_font_entry(FILE *fp, const char *cp, BC_FontEntry *ep)
1968 fprintf(fp,"%s%s = %s\n",cp,ep->displayname,ep->path);
1969 fprintf(fp," %s:%s:%s:%s:%s:%s:%d:%d:%d:%d:%d:%s:%d:%s:%s:%d\n",
1970 ep->foundry, ep->family, ep->weight, ep->slant, ep->swidth, ep->adstyle,
1971 ep->pixelsize, ep->pointsize, ep->xres, ep->yres, ep->style, ep->spacing,
1972 ep->avg_width, ep->registry, ep->encoding, ep->fixed_style);