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()
369 double default_scale = 1.0; // display_size/1000.;
370 char *env = getenv("BC_FONT_DEBUG");
371 font_debug = env ? atoi(env) : 0;
372 env = getenv("BC_FONT_SCALE");
373 font_scale = env ? atof(env) : default_scale;
374 if( font_scale <= 0 ) font_scale = 1;
375 init_font_defs(font_scale);
376 env = getenv("BC_ICON_SCALE");
377 icon_scale = env ? atof(env) : default_scale;
378 if( icon_scale <= 0 ) icon_scale = 1;
380 id_lock = new Mutex("BC_Resources::id_lock");
381 create_window_lock = new Mutex("BC_Resources::create_window_lock", 1);
383 machine_cpus = get_machine_cpus();
385 for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
386 filebox_history[i].path[0] = 0;
393 little_endian = (*(const u_int32_t*)"\01\0\0\0") & 1;
394 wide_encoding = little_endian ? "UTF32LE" : "UTF32BE";
397 #include "images/file_folder_png.h"
398 #include "images/file_unknown_png.h"
399 #include "images/file_film_png.h"
400 #include "images/file_sound_png.h"
401 #include "images/file_label_png.h"
402 #include "images/file_column_png.h"
403 new_vframes(6,default_type_to_icon,
404 new VFramePng(file_folder_png),
405 new VFramePng(file_unknown_png),
406 new VFramePng(file_film_png),
407 new VFramePng(file_sound_png),
408 new VFramePng(file_label_png),
409 new VFramePng(file_column_png));
411 #include "images/bar_png.h"
412 default_bar = new VFramePng(bar_png);
414 #include "images/cancel_up_png.h"
415 #include "images/cancel_hi_png.h"
416 #include "images/cancel_dn_png.h"
417 new_vframes(3,default_cancel_images,
418 new VFramePng(cancel_up_png),
419 new VFramePng(cancel_hi_png),
420 new VFramePng(cancel_dn_png));
422 #include "images/ok_up_png.h"
423 #include "images/ok_hi_png.h"
424 #include "images/ok_dn_png.h"
425 new_vframes(3,default_ok_images,
426 new VFramePng(ok_up_png),
427 new VFramePng(ok_hi_png),
428 new VFramePng(ok_dn_png));
430 #include "images/usethis_up_png.h"
431 #include "images/usethis_uphi_png.h"
432 #include "images/usethis_dn_png.h"
433 new_vframes(3,default_usethis_images,
434 new VFramePng(usethis_up_png),
435 new VFramePng(usethis_uphi_png),
436 new VFramePng(usethis_dn_png));
439 #include "images/checkbox_checked_png.h"
440 #include "images/checkbox_dn_png.h"
441 #include "images/checkbox_checkedhi_png.h"
442 #include "images/checkbox_up_png.h"
443 #include "images/checkbox_hi_png.h"
444 new_vframes(5,default_checkbox_images,
445 new VFramePng(checkbox_up_png),
446 new VFramePng(checkbox_hi_png),
447 new VFramePng(checkbox_checked_png),
448 new VFramePng(checkbox_dn_png),
449 new VFramePng(checkbox_checkedhi_png));
451 #include "images/radial_checked_png.h"
452 #include "images/radial_dn_png.h"
453 #include "images/radial_checkedhi_png.h"
454 #include "images/radial_up_png.h"
455 #include "images/radial_hi_png.h"
456 new_vframes(5,default_radial_images,
457 new VFramePng(radial_up_png),
458 new VFramePng(radial_hi_png),
459 new VFramePng(radial_checked_png),
460 new VFramePng(radial_dn_png),
461 new VFramePng(radial_checkedhi_png));
463 new_vframes(5,default_label_images,
464 new VFramePng(radial_up_png),
465 new VFramePng(radial_hi_png),
466 new VFramePng(radial_checked_png),
467 new VFramePng(radial_dn_png),
468 new VFramePng(radial_checkedhi_png));
471 #include "images/menuitem_up_png.h"
472 #include "images/menuitem_hi_png.h"
473 #include "images/menuitem_dn_png.h"
474 new_vframes(3,default_menuitem_data,
475 new VFramePng(menuitem_up_png),
476 new VFramePng(menuitem_hi_png),
477 new VFramePng(menuitem_dn_png));
479 #include "images/menubar_up_png.h"
480 #include "images/menubar_hi_png.h"
481 #include "images/menubar_dn_png.h"
482 new_vframes(3,default_menubar_data,
483 new VFramePng(menubar_up_png),
484 new VFramePng(menubar_hi_png),
485 new VFramePng(menubar_dn_png));
487 #include "images/menu_popup_bg_png.h"
488 default_menu_popup_bg = new VFramePng(menu_popup_bg_png);
490 #include "images/menubar_bg_png.h"
491 default_menu_bar_bg = new VFramePng(menubar_bg_png);
493 #include "images/check_png.h"
494 default_check_image = new VFramePng(check_png);
496 #include "images/file_text_up_png.h"
497 #include "images/file_text_hi_png.h"
498 #include "images/file_text_dn_png.h"
499 new_vframes(3,default_filebox_text_images,
500 new VFramePng(file_text_up_png),
501 new VFramePng(file_text_hi_png),
502 new VFramePng(file_text_dn_png));
504 #include "images/file_icons_up_png.h"
505 #include "images/file_icons_hi_png.h"
506 #include "images/file_icons_dn_png.h"
507 new_vframes(3,default_filebox_icons_images,
508 new VFramePng(file_icons_up_png),
509 new VFramePng(file_icons_hi_png),
510 new VFramePng(file_icons_dn_png));
512 #include "images/file_updir_up_png.h"
513 #include "images/file_updir_hi_png.h"
514 #include "images/file_updir_dn_png.h"
515 new_vframes(3,default_filebox_updir_images,
516 new VFramePng(file_updir_up_png),
517 new VFramePng(file_updir_hi_png),
518 new VFramePng(file_updir_dn_png));
520 #include "images/file_newfolder_up_png.h"
521 #include "images/file_newfolder_hi_png.h"
522 #include "images/file_newfolder_dn_png.h"
523 new_vframes(3,default_filebox_newfolder_images,
524 new VFramePng(file_newfolder_up_png),
525 new VFramePng(file_newfolder_hi_png),
526 new VFramePng(file_newfolder_dn_png));
528 #include "images/file_rename_up_png.h"
529 #include "images/file_rename_hi_png.h"
530 #include "images/file_rename_dn_png.h"
531 new_vframes(3,default_filebox_rename_images,
532 new VFramePng(file_rename_up_png),
533 new VFramePng(file_rename_hi_png),
534 new VFramePng(file_rename_dn_png));
536 #include "images/file_delete_up_png.h"
537 #include "images/file_delete_hi_png.h"
538 #include "images/file_delete_dn_png.h"
539 new_vframes(3,default_filebox_delete_images,
540 new VFramePng(file_delete_up_png),
541 new VFramePng(file_delete_hi_png),
542 new VFramePng(file_delete_dn_png));
544 #include "images/file_reload_up_png.h"
545 #include "images/file_reload_hi_png.h"
546 #include "images/file_reload_dn_png.h"
547 new_vframes(3,default_filebox_reload_images,
548 new VFramePng(file_reload_up_png),
549 new VFramePng(file_reload_hi_png),
550 new VFramePng(file_reload_dn_png));
552 #include "images/file_size_capb_up_png.h"
553 #include "images/file_size_capb_hi_png.h"
554 #include "images/file_size_capb_dn_png.h"
555 #include "images/file_size_lwrb_up_png.h"
556 #include "images/file_size_lwrb_hi_png.h"
557 #include "images/file_size_lwrb_dn_png.h"
558 #include "images/file_size_semi_up_png.h"
559 #include "images/file_size_semi_hi_png.h"
560 #include "images/file_size_semi_dn_png.h"
561 #include "images/file_size_zero_up_png.h"
562 #include "images/file_size_zero_hi_png.h"
563 #include "images/file_size_zero_dn_png.h"
564 new_vframes(12,default_filebox_szfmt_images,
565 new VFramePng(file_size_zero_up_png),
566 new VFramePng(file_size_zero_hi_png),
567 new VFramePng(file_size_zero_dn_png),
568 new VFramePng(file_size_lwrb_up_png),
569 new VFramePng(file_size_lwrb_hi_png),
570 new VFramePng(file_size_lwrb_dn_png),
571 new VFramePng(file_size_capb_up_png),
572 new VFramePng(file_size_capb_hi_png),
573 new VFramePng(file_size_capb_dn_png),
574 new VFramePng(file_size_semi_up_png),
575 new VFramePng(file_size_semi_hi_png),
576 new VFramePng(file_size_semi_dn_png));
578 #include "images/listbox_button_dn_png.h"
579 #include "images/listbox_button_hi_png.h"
580 #include "images/listbox_button_up_png.h"
581 #include "images/listbox_button_disabled_png.h"
582 new_vframes(4,default_listbox_button,
583 new VFramePng(listbox_button_up_png),
584 new VFramePng(listbox_button_hi_png),
585 new VFramePng(listbox_button_dn_png),
586 new VFramePng(listbox_button_disabled_png));
588 default_listbox_bg = 0;
590 #include "images/listbox_expandchecked_png.h"
591 #include "images/listbox_expandcheckedhi_png.h"
592 #include "images/listbox_expanddn_png.h"
593 #include "images/listbox_expandup_png.h"
594 #include "images/listbox_expanduphi_png.h"
595 new_vframes(5,default_listbox_expand,
596 new VFramePng(listbox_expandup_png),
597 new VFramePng(listbox_expanduphi_png),
598 new VFramePng(listbox_expandchecked_png),
599 new VFramePng(listbox_expanddn_png),
600 new VFramePng(listbox_expandcheckedhi_png));
602 #include "images/listbox_columnup_png.h"
603 #include "images/listbox_columnhi_png.h"
604 #include "images/listbox_columndn_png.h"
605 new_vframes(3,default_listbox_column,
606 new VFramePng(listbox_columnup_png),
607 new VFramePng(listbox_columnhi_png),
608 new VFramePng(listbox_columndn_png));
610 #include "images/listbox_up_png.h"
611 default_listbox_up = new VFramePng(listbox_up_png);
613 #include "images/listbox_dn_png.h"
614 default_listbox_dn = new VFramePng(listbox_dn_png);
616 #include "images/pot_hi_png.h"
617 #include "images/pot_up_png.h"
618 #include "images/pot_dn_png.h"
619 new_vframes(3,default_pot_images,
620 new VFramePng(pot_up_png),
621 new VFramePng(pot_hi_png),
622 new VFramePng(pot_dn_png));
624 #include "images/progress_up_png.h"
625 #include "images/progress_hi_png.h"
626 new_vframes(2,default_progress_images,
627 new VFramePng(progress_up_png),
628 new VFramePng(progress_hi_png));
630 #include "images/7seg_small/0_png.h"
631 #include "images/7seg_small/1_png.h"
632 #include "images/7seg_small/2_png.h"
633 #include "images/7seg_small/3_png.h"
634 #include "images/7seg_small/4_png.h"
635 #include "images/7seg_small/5_png.h"
636 #include "images/7seg_small/6_png.h"
637 #include "images/7seg_small/7_png.h"
638 #include "images/7seg_small/8_png.h"
639 #include "images/7seg_small/9_png.h"
640 #include "images/7seg_small/colon_png.h"
641 #include "images/7seg_small/period_png.h"
642 #include "images/7seg_small/a_png.h"
643 #include "images/7seg_small/b_png.h"
644 #include "images/7seg_small/c_png.h"
645 #include "images/7seg_small/d_png.h"
646 #include "images/7seg_small/e_png.h"
647 #include "images/7seg_small/f_png.h"
648 #include "images/7seg_small/space_png.h"
649 #include "images/7seg_small/dash_png.h"
650 new_vframes(20,default_medium_7segment,
651 new VFramePng(_0_png),
652 new VFramePng(_1_png),
653 new VFramePng(_2_png),
654 new VFramePng(_3_png),
655 new VFramePng(_4_png),
656 new VFramePng(_5_png),
657 new VFramePng(_6_png),
658 new VFramePng(_7_png),
659 new VFramePng(_8_png),
660 new VFramePng(_9_png),
661 new VFramePng(colon_png),
662 new VFramePng(period_png),
663 new VFramePng(a_png),
664 new VFramePng(b_png),
665 new VFramePng(c_png),
666 new VFramePng(d_png),
667 new VFramePng(e_png),
668 new VFramePng(f_png),
669 new VFramePng(space_png),
670 new VFramePng(dash_png));
672 #include "images/hscroll_handle_up_png.h"
673 #include "images/hscroll_handle_hi_png.h"
674 #include "images/hscroll_handle_dn_png.h"
675 #include "images/hscroll_handle_bg_png.h"
676 #include "images/hscroll_left_up_png.h"
677 #include "images/hscroll_left_hi_png.h"
678 #include "images/hscroll_left_dn_png.h"
679 #include "images/hscroll_right_up_png.h"
680 #include "images/hscroll_right_hi_png.h"
681 #include "images/hscroll_right_dn_png.h"
682 new_vframes(10,default_hscroll_data,
683 new VFramePng(hscroll_handle_up_png),
684 new VFramePng(hscroll_handle_hi_png),
685 new VFramePng(hscroll_handle_dn_png),
686 new VFramePng(hscroll_handle_bg_png),
687 new VFramePng(hscroll_left_up_png),
688 new VFramePng(hscroll_left_hi_png),
689 new VFramePng(hscroll_left_dn_png),
690 new VFramePng(hscroll_right_up_png),
691 new VFramePng(hscroll_right_hi_png),
692 new VFramePng(hscroll_right_dn_png));
694 #include "images/vscroll_handle_up_png.h"
695 #include "images/vscroll_handle_hi_png.h"
696 #include "images/vscroll_handle_dn_png.h"
697 #include "images/vscroll_handle_bg_png.h"
698 #include "images/vscroll_left_up_png.h"
699 #include "images/vscroll_left_hi_png.h"
700 #include "images/vscroll_left_dn_png.h"
701 #include "images/vscroll_right_up_png.h"
702 #include "images/vscroll_right_hi_png.h"
703 #include "images/vscroll_right_dn_png.h"
704 new_vframes(10,default_vscroll_data,
705 new VFramePng(vscroll_handle_up_png),
706 new VFramePng(vscroll_handle_hi_png),
707 new VFramePng(vscroll_handle_dn_png),
708 new VFramePng(vscroll_handle_bg_png),
709 new VFramePng(vscroll_left_up_png),
710 new VFramePng(vscroll_left_hi_png),
711 new VFramePng(vscroll_left_dn_png),
712 new VFramePng(vscroll_right_up_png),
713 new VFramePng(vscroll_right_hi_png),
714 new VFramePng(vscroll_right_dn_png));
716 #include "images/default_icon_png.h"
717 default_icon_img = new VFramePng(default_icon_png);
719 type_to_icon = default_type_to_icon;
720 bar_data = default_bar;
721 check = default_check_image;
722 listbox_button = default_listbox_button;
723 listbox_bg = default_listbox_bg;
724 listbox_expand = default_listbox_expand;
725 listbox_column = default_listbox_column;
726 listbox_up = default_listbox_up;
727 listbox_dn = default_listbox_dn;
728 hscroll_data = default_hscroll_data;
729 vscroll_data = default_vscroll_data;
730 default_icon = default_icon_img;
732 listbox_title_overlap = 0;
733 listbox_title_margin = 0;
734 listbox_title_color = BLACK;
735 listbox_title_hotspot = 5;
737 listbox_border1 = DKGREY;
738 listbox_border2_hi = RED;
739 listbox_border2 = BLACK;
740 listbox_border3_hi = RED;
741 listbox_border3 = MEGREY;
742 listbox_border4 = WHITE;
743 listbox_selected = BLUE;
744 listbox_highlighted = LTGREY;
745 listbox_inactive = WHITE;
746 listbox_text = BLACK;
749 pan_text_color = YELLOW;
751 generic_button_margin = 15;
752 draw_clock_background=1;
762 bg_light2 = bg_color;
765 border_light1 = bg_color;
766 border_light2 = MEGREY;
767 border_shadow1 = BLACK;
768 border_shadow2 = bg_color;
770 default_text_color = BLACK;
771 disabled_text_color = DMGREY;
773 button_light = MEGREY; // bright corner
774 // button_highlighted = LTGREY; // face when highlighted
775 button_highlighted = 0xffe000; // face when highlighted
776 button_down = MDGREY; // face when down
777 // button_up = MEGREY; // face when up
778 button_up = 0xffc000; // face when up
779 button_shadow = BLACK; // dark corner
780 button_uphighlighted = RED; // upper side when highlighted
783 tumble_duration = 150;
785 ok_images = default_ok_images;
786 cancel_images = default_cancel_images;
787 usethis_button_images = default_usethis_images;
788 filebox_descend_images = default_ok_images;
791 menu_highlighted = LTBLUE;
794 menu_shadow = DKCYAN;
796 menu_title_bg = default_menubar_data;
797 menu_popup_bg = default_menu_popup_bg;
798 menu_bar_bg = default_menu_bar_bg;
800 popupmenu_images = 0;
803 popupmenu_margin = 10;
805 popupmenu_triangle_margin = 10;
808 menu_title_text = BLACK;
809 popup_title_text = BLACK;
810 menu_item_text = BLACK;
811 menu_highlighted_fontcolor = BLACK;
812 progress_text = BLACK;
813 grab_input_focus = 1;
815 text_default = BLACK;
816 highlight_inverse = WHITE ^ BLUE;
817 text_background = WHITE;
818 text_background_disarmed = 0xc08080;
819 text_background_hi = LTYELLOW;
820 text_background_noborder_hi = LTGREY;
821 text_background_noborder = -1;
822 text_border1 = DKGREY;
823 text_border2 = BLACK;
824 text_border2_hi = RED;
825 text_border3 = MEGREY;
826 text_border3_hi = LTPINK;
827 text_border4 = WHITE;
828 text_highlight = BLUE;
829 text_selected_highlight = SLBLUE;
830 text_inactive_highlight = MEGREY;
832 toggle_highlight_bg = 0;
833 toggle_text_margin = 0;
835 // Delays must all be different for repeaters
839 tooltip_delay = 1000;
840 tooltip_bg_color = YELLOW;
841 tooltips_enabled = 1;
842 textbox_focus_policy = 0;
844 filebox_margin = 110;
846 filebox_mode = LISTBOX_TEXT;
847 sprintf(filebox_filter, "*");
850 filebox_columntype[0] = FILEBOX_NAME;
851 filebox_columntype[1] = FILEBOX_SIZE;
852 filebox_columntype[2] = FILEBOX_DATE;
853 filebox_columntype[3] = FILEBOX_EXTENSION;
854 filebox_columnwidth[0] = 200;
855 filebox_columnwidth[1] = 100;
856 filebox_columnwidth[2] = 100;
857 filebox_columnwidth[3] = 100;
858 dirbox_columntype[0] = FILEBOX_NAME;
859 dirbox_columntype[1] = FILEBOX_DATE;
860 dirbox_columnwidth[0] = 200;
861 dirbox_columnwidth[1] = 100;
863 filebox_text_images = default_filebox_text_images;
864 filebox_icons_images = default_filebox_icons_images;
865 filebox_updir_images = default_filebox_updir_images;
866 filebox_newfolder_images = default_filebox_newfolder_images;
867 filebox_rename_images = default_filebox_rename_images;
868 filebox_delete_images = default_filebox_delete_images;
869 filebox_reload_images = default_filebox_reload_images;
870 filebox_szfmt_images = default_filebox_szfmt_images;
871 filebox_size_format = FILEBOX_SIZE_RAW;
872 directory_color = BLUE;
875 filebox_sortcolumn = 0;
876 filebox_sortorder = BC_ListBox::SORT_ASCENDING;
877 dirbox_sortcolumn = 0;
878 dirbox_sortorder = BC_ListBox::SORT_ASCENDING;
881 pot_images = default_pot_images;
883 pot_x1 = pot_images[0]->get_w() / 2 - pot_offset;
884 pot_y1 = pot_images[0]->get_h() / 2 - pot_offset;
886 pot_needle_color = BLACK;
888 progress_images = default_progress_images;
892 meter_font = SMALLFONT_3D;
893 meter_font_color = RED;
896 medium_7segment = default_medium_7segment;
898 audiovideo_color = RED;
902 // Xft has priority over font set
904 // But Xft dies in 32 bit mode after some amount of drawing.
912 recursive_resizing = 1;
917 void BC_Resources::del_vframes(VFrame *vframes[], int n)
919 while( --n >= 0 ) delete vframes[n];
922 BC_Resources::~BC_Resources()
925 delete create_window_lock;
926 del_vframes(default_type_to_icon, 6);
928 del_vframes(default_cancel_images, 3);
929 del_vframes(default_ok_images, 3);
930 del_vframes(default_usethis_images, 3);
932 del_vframes(default_checkbox_images, 5);
933 del_vframes(default_radial_images, 5);
934 del_vframes(default_label_images, 5);
936 del_vframes(default_menuitem_data, 3);
937 del_vframes(default_menubar_data, 3);
938 delete default_menu_popup_bg;
939 delete default_menu_bar_bg;
940 delete default_check_image;
941 del_vframes(default_filebox_text_images, 3);
942 del_vframes(default_filebox_icons_images, 3);
943 del_vframes(default_filebox_updir_images, 3);
944 del_vframes(default_filebox_newfolder_images, 3);
945 del_vframes(default_filebox_rename_images, 3);
946 del_vframes(default_filebox_delete_images, 3);
947 del_vframes(default_filebox_reload_images, 3);
948 del_vframes(default_filebox_szfmt_images, 12);
949 del_vframes(default_listbox_button, 4);
950 delete default_listbox_bg;
951 del_vframes(default_listbox_expand, 5);
952 del_vframes(default_listbox_column, 3);
953 delete default_listbox_up;
954 delete default_listbox_dn;
955 del_vframes(default_pot_images, 3);
956 del_vframes(default_progress_images, 2);
957 del_vframes(default_medium_7segment, 20);
959 fontlist->remove_all_objects();
962 delete default_icon_img;
966 int BC_Resources::initialize_display(BC_WindowBase *window)
968 // Set up IPC cleanup handlers
971 // Test for shm. Must come before yuv test
977 void BC_Resources::init_shm(BC_WindowBase *window)
980 int (*old_handler)(Display *, XErrorEvent *) =
981 XSetErrorHandler(BC_Resources::x_error_handler);
983 if(XShmQueryExtension(window->display))
985 XShmSegmentInfo test_shm;
986 memset(&test_shm,0,sizeof(test_shm));
987 XImage *test_image = XShmCreateImage(window->display, window->vis,
988 window->default_depth, ZPixmap, (char*)NULL, &test_shm, 5, 5);
989 BC_Resources::error = 0;
990 test_shm.shmid = shmget(IPC_PRIVATE, 5 * test_image->bytes_per_line, (IPC_CREAT | 0600));
991 if(test_shm.shmid != -1) {
992 char *data = (char *)shmat(test_shm.shmid, NULL, 0);
993 if(data != (void *)-1) {
994 shmctl(test_shm.shmid, IPC_RMID, 0);
995 test_shm.shmaddr = data;
996 test_shm.readOnly = 0;
998 if(XShmAttach(window->display, &test_shm)) {
999 XSync(window->display, False);
1006 XDestroyImage(test_image);
1007 if(BC_Resources::error) use_shm = 0;
1009 XSetErrorHandler(old_handler);
1015 BC_Synchronous* BC_Resources::get_synchronous()
1020 void BC_Resources::set_synchronous(BC_Synchronous *synchronous)
1022 this->synchronous = synchronous;
1028 int BC_Resources::get_bg_color() { return bg_color; }
1030 int BC_Resources::get_bg_shadow1() { return bg_shadow1; }
1032 int BC_Resources::get_bg_shadow2() { return bg_shadow2; }
1034 int BC_Resources::get_bg_light1() { return bg_light1; }
1036 int BC_Resources::get_bg_light2() { return bg_light2; }
1039 int BC_Resources::get_id()
1041 id_lock->lock("BC_Resources::get_id");
1047 int BC_Resources::get_filebox_id()
1049 id_lock->lock("BC_Resources::get_filebox_id");
1050 int result = filebox_id++;
1056 void BC_Resources::set_signals(BC_Signals *signal_handler)
1058 BC_Resources::signal_handler = signal_handler;
1061 int BC_Resources::init_fontconfig(const char *search_path)
1063 if( fontlist ) return 0;
1064 fontlist = new ArrayList<BC_FontEntry*>;
1066 #define get_str(str,sep,ptr,cond) do { char *out = str; \
1067 while( *ptr && !strchr(sep,*ptr) && (cond) ) *out++ = *ptr++; \
1071 #define skip_str(sep, ptr) do { \
1072 while( *ptr && strchr(sep,*ptr) ) ++ptr; \
1075 char find_command[BCTEXTLEN];
1076 char *fp = find_command, *ep = fp+sizeof(find_command)-1;
1077 fp += snprintf(fp, ep-fp, "%s", "find");
1078 const char *bc_font_path = getenv("BC_FONT_PATH");
1079 // if BC_FONT_PATH starts with ':', omit default path
1080 if( !(bc_font_path && bc_font_path[0] == ':') )
1081 fp += snprintf(fp, ep-fp, " '%s'", search_path);
1082 if( bc_font_path ) {
1083 const char *path = bc_font_path;
1085 char font_path[BCTEXTLEN];
1086 const char *cp = strchr(path,':');
1087 int len = !cp ? strlen(path) : cp-path;
1089 memcpy(font_path, path, len);
1090 font_path[len] = 0; path += len;
1091 fp += snprintf(fp, ep-fp, " '%s'", font_path);
1096 fp += snprintf(fp, ep-fp, " -name 'fonts.scale' -print -exec cat {} \\;");
1097 FILE *in = popen(find_command, "r");
1099 FT_Library freetype_library = 0;
1100 // FT_Face freetype_face = 0;
1101 // ft_Init_FreeType(&freetype_library);
1103 char line[BCTEXTLEN], current_dir[BCTEXTLEN];
1106 while( !feof(in) && fgets(line, BCTEXTLEN, in) ) {
1107 if(!strlen(line)) break;
1109 char *in_ptr = line;
1111 // Get current directory
1112 if(line[0] == '/') {
1113 get_str(current_dir, "\n", in_ptr,1);
1114 for( int i=strlen(current_dir); --i>=0 && current_dir[i]!='/'; )
1119 //printf("TitleMain::build_fonts %s\n", line);
1120 BC_FontEntry *entry = new BC_FontEntry;
1121 char string[BCTEXTLEN];
1123 get_str(string, "\n", in_ptr, in_ptr[0]!=' ' || in_ptr[1]!='-');
1124 entry->path = cstrcat(2, current_dir, string);
1126 skip_str(" -", in_ptr);
1127 get_str(string, "-\n", in_ptr, 1);
1128 if( !string[0] ) { delete entry; continue; }
1129 entry->foundry = cstrdup(string);
1130 if(*in_ptr == '-') in_ptr++;
1132 get_str(string, "-\n", in_ptr, 1);
1133 if( !string[0] ) { delete entry; continue; }
1134 entry->family = cstrdup(string);
1135 if(*in_ptr == '-') in_ptr++;
1137 get_str(string, "-\n", in_ptr, 1);
1138 entry->weight = cstrdup(string);
1139 if(*in_ptr == '-') in_ptr++;
1141 get_str(string, "-\n", in_ptr, 1);
1142 entry->slant = cstrdup(string);
1143 if(*in_ptr == '-') in_ptr++;
1145 get_str(string, "-\n", in_ptr, 1);
1146 entry->swidth = cstrdup(string);
1147 if(*in_ptr == '-') in_ptr++;
1149 get_str(string, "-\n", in_ptr, 1);
1150 entry->adstyle = cstrdup(string);
1151 if(*in_ptr == '-') in_ptr++;
1153 get_str(string, "-\n", in_ptr, 1);
1154 entry->pixelsize = atol(string);
1155 if(*in_ptr == '-') in_ptr++;
1157 get_str(string, "-\n", in_ptr, 1);
1158 entry->pointsize = atol(string);
1159 if(*in_ptr == '-') in_ptr++;
1161 get_str(string, "-\n", in_ptr, 1);
1162 entry->xres = atol(string);
1163 if(*in_ptr == '-') in_ptr++;
1165 get_str(string, "-\n", in_ptr, 1);
1166 entry->yres = atol(string);
1167 if(*in_ptr == '-') in_ptr++;
1169 get_str(string, "-\n", in_ptr, 1);
1170 entry->spacing = cstrdup(string);
1171 if(*in_ptr == '-') in_ptr++;
1173 get_str(string, "-\n", in_ptr, 1);
1174 entry->avg_width = atol(string);
1175 if(*in_ptr == '-') in_ptr++;
1177 get_str(string, "-\n", in_ptr, 1);
1178 entry->registry = cstrdup(string);
1179 if(*in_ptr == '-') in_ptr++;
1181 get_str(string, "-\n", in_ptr, 1);
1182 entry->encoding = cstrdup(string);
1183 if(*in_ptr == '-') in_ptr++;
1186 //printf("TitleMain::build_fonts 1 %s\n", entry->path);
1187 // This takes a real long time to do. Instead just take all fonts
1188 // if(!load_freetype_face(freetype_library,
1189 // freetype_face, entry->path) )
1191 sprintf(line, "%s (%s)", entry->family, entry->foundry);
1192 entry->displayname = cstrdup(line);
1194 if(!strcasecmp(entry->weight, "demibold")) {
1195 entry->fixed_style |= BC_FONT_BOLD;
1196 entry->style |= FL_WEIGHT_DEMIBOLD;
1198 else if(!strcasecmp(entry->weight, "bold")) {
1199 entry->fixed_style |= BC_FONT_BOLD;
1200 entry->style |= FL_WEIGHT_BOLD;
1203 entry->style |= FL_WEIGHT_NORMAL;
1206 if(!strcasecmp(entry->slant, "r")) {
1207 entry->style |= FL_SLANT_ROMAN;
1209 else if(!strcasecmp(entry->slant, "i")) {
1210 entry->style |= FL_SLANT_ITALIC;
1211 entry->fixed_style |= BC_FONT_ITALIC;
1213 else if(!strcasecmp(entry->slant, "o")) {
1214 entry->style |= FL_SLANT_OBLIQUE;
1215 entry->fixed_style |= BC_FONT_ITALIC;
1218 if(!strcasecmp(entry->swidth, "normal"))
1219 entry->style |= FL_WIDTH_NORMAL;
1220 else if(!strcasecmp(entry->swidth, "ultracondensed"))
1221 entry->style |= FL_WIDTH_ULTRACONDENSED;
1222 else if(!strcasecmp(entry->swidth, "extracondensed"))
1223 entry->style |= FL_WIDTH_EXTRACONDENSED;
1224 else if(!strcasecmp(entry->swidth, "condensed"))
1225 entry->style |= FL_WIDTH_CONDENSED;
1226 else if(!strcasecmp(entry->swidth, "semicondensed"))
1227 entry->style |= FL_WIDTH_SEMICONDENSED;
1228 else if(!strcasecmp(entry->swidth, "semiexpanded"))
1229 entry->style |= FL_WIDTH_SEMIEXPANDED;
1230 else if(!strcasecmp(entry->swidth, "expanded"))
1231 entry->style |= FL_WIDTH_EXPANDED;
1232 else if(!strcasecmp(entry->swidth, "extraexpanded"))
1233 entry->style |= FL_WIDTH_EXTRAEXPANDED;
1234 else if(!strcasecmp(entry->swidth, "ultraexpanded"))
1235 entry->style |= FL_WIDTH_ULTRAEXPANDED;
1237 entry->style |= FL_WIDTH_NORMAL;
1239 fontlist->append(entry);
1241 dump_font_entry(stdout, "font 0: ", entry);
1243 // printf("TitleMain::build_fonts %s: success\n", entry->path);
1244 //printf("TitleMain::build_fonts 2\n");
1248 if( bc_font_path && bc_font_path[0] == ':' )
1251 // Load all the fonts from fontconfig
1255 FcChar8 *family, *file, *foundry, *style, *format;
1256 int slant, spacing, width, weight;
1257 int force_style = 0;
1258 // if you want limit search to TrueType put 1
1259 int limit_to_trutype = 1;
1262 char tmpstring[BCTEXTLEN];
1265 config = fcConfigGetCurrent();
1266 fcConfigSetRescanInterval(config, 0);
1268 pat = fcPatternCreate();
1269 os = fcObjectSetBuild( FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
1270 FC_WIDTH, FC_SLANT, FC_FONTFORMAT, FC_SPACING, FC_STYLE, (char *) 0);
1271 fcPatternAddBool(pat, FC_SCALABLE, true);
1274 char langstr[LEN_LANG * 3];
1275 strcpy(langstr, language);
1278 strcat(langstr, "-");
1279 strcat(langstr, region);
1282 FcLangSet *ls = fcLangSetCreate();
1283 if(fcLangSetAdd(ls, (const FcChar8*)langstr))
1284 if(fcPatternAddLangSet(pat, FC_LANG, ls))
1285 fcLangSetDestroy(ls);
1288 fs = fcFontList(config, pat, os);
1289 fcPatternDestroy(pat);
1290 fcObjectSetDestroy(os);
1292 for (i = 0; fs && i < fs->nfont; i++) {
1293 FcPattern *font = fs->fonts[i];
1295 fcPatternGetString(font, FC_FONTFORMAT, 0, &format);
1296 //on this point you can limit font search
1297 if(limit_to_trutype && strcmp((char *)format, "TrueType"))
1300 sprintf(tmpstring, "%s", format);
1301 BC_FontEntry *entry = new BC_FontEntry;
1302 if(fcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
1303 entry->path = cstrdup((char*)file);
1306 if(fcPatternGetString(font, FC_FOUNDRY, 0, &foundry) == FcResultMatch) {
1307 entry->foundry = cstrdup((char*)foundry);
1310 if(fcPatternGetInteger(font, FC_WEIGHT, 0, &weight) == FcResultMatch) {
1312 case FC_WEIGHT_THIN:
1313 case FC_WEIGHT_EXTRALIGHT:
1314 case FC_WEIGHT_LIGHT:
1315 case FC_WEIGHT_BOOK:
1317 entry->weight = cstrdup("medium");
1320 case FC_WEIGHT_NORMAL:
1321 case FC_WEIGHT_MEDIUM:
1323 entry->weight = cstrdup("medium");
1326 case FC_WEIGHT_BLACK:
1327 case FC_WEIGHT_SEMIBOLD:
1328 case FC_WEIGHT_BOLD:
1329 entry->weight = cstrdup("bold");
1330 entry->fixed_style |= BC_FONT_BOLD;
1333 case FC_WEIGHT_EXTRABOLD:
1334 case FC_WEIGHT_EXTRABLACK:
1336 entry->weight = cstrdup("bold");
1337 entry->fixed_style |= BC_FONT_BOLD;
1342 if(fcPatternGetString(font, FC_FAMILY, 0, &family) == FcResultMatch)
1343 entry->family = cstrdup((char*)family);
1345 if(fcPatternGetInteger(font, FC_SLANT, 0, &slant) == FcResultMatch) {
1347 case FC_SLANT_ROMAN:
1349 entry->slant = cstrdup("r");
1350 entry->style |= FL_SLANT_ROMAN;
1352 case FC_SLANT_ITALIC:
1353 entry->slant = cstrdup("i");
1354 entry->style |= FL_SLANT_ITALIC;
1355 entry->fixed_style |= BC_FONT_ITALIC;
1357 case FC_SLANT_OBLIQUE:
1358 entry->slant = cstrdup("o");
1359 entry->style |= FL_SLANT_OBLIQUE;
1360 entry->fixed_style |= BC_FONT_ITALIC;
1365 if(fcPatternGetInteger(font, FC_WIDTH, 0, &width) == FcResultMatch) {
1367 case FC_WIDTH_ULTRACONDENSED:
1368 entry->swidth = cstrdup("ultracondensed");
1371 case FC_WIDTH_EXTRACONDENSED:
1372 entry->swidth = cstrdup("extracondensed");
1375 case FC_WIDTH_CONDENSED:
1376 entry->swidth = cstrdup("condensed");
1378 case FC_WIDTH_SEMICONDENSED:
1379 entry->swidth = cstrdup("semicondensed");
1382 case FC_WIDTH_NORMAL:
1384 entry->swidth = cstrdup("normal");
1387 case FC_WIDTH_SEMIEXPANDED:
1388 entry->swidth = cstrdup("semiexpanded");
1391 case FC_WIDTH_EXPANDED:
1392 entry->swidth = cstrdup("expanded");
1395 case FC_WIDTH_EXTRAEXPANDED:
1396 entry->swidth = cstrdup("extraexpanded");
1399 case FC_WIDTH_ULTRAEXPANDED:
1400 entry->swidth = cstrdup("ultraexpanded");
1405 if(fcPatternGetInteger(font, FC_SPACING, 0, &spacing) == FcResultMatch) {
1409 entry->spacing = cstrdup("p");
1413 entry->spacing = cstrdup("d");
1417 entry->spacing = cstrdup("m");
1421 entry->spacing = cstrdup("c");
1426 // Add fake stuff for compatibility
1427 entry->adstyle = cstrdup(" ");
1428 entry->pixelsize = 0;
1429 entry->pointsize = 0;
1432 entry->avg_width = 0;
1433 entry->registry = cstrdup("utf");
1434 entry->encoding = cstrdup("8");
1436 if( fcPatternGetString(font, FC_STYLE, 0, &style) != FcResultMatch )
1439 // If font has a style unmanaged by titler plugin, force style to be displayed on name
1440 // in this way we can shown all available fonts styles.
1442 sprintf(tmpstring, "%s (%s)", entry->family, style);
1443 entry->displayname = cstrdup(tmpstring);
1446 if(strcmp(entry->foundry, "unknown")) {
1447 sprintf(tmpstring, "%s (%s)", entry->family, entry->foundry);
1448 entry->displayname = cstrdup(tmpstring);
1451 sprintf(tmpstring, "%s", entry->family);
1452 entry->displayname = cstrdup(tmpstring);
1456 fontlist->append(entry);
1458 dump_font_entry(stdout, "font 1: ", entry);
1461 fcFontSetDestroy(fs);
1462 if(freetype_library)
1463 ft_Done_FreeType(freetype_library);
1464 // for(int i = 0; i < fonts->total; i++)
1465 // fonts->values[i]->dump();
1467 fcConfigAppFontAddDir(0, (const FcChar8*)search_path);
1468 fcConfigSetRescanInterval(0, 0);
1470 os = fcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
1471 FC_WIDTH, FC_SLANT, FC_SPACING, FC_STYLE, (char *)0);
1472 pat = fcPatternCreate();
1473 fcPatternAddBool(pat, FC_SCALABLE, true);
1477 char langstr[LEN_LANG * 3];
1478 strcpy(langstr, language);
1482 strcat(langstr, "-");
1483 strcat(langstr, region);
1486 FcLangSet *ls = fcLangSetCreate();
1487 if(fcLangSetAdd(ls, (const FcChar8*)langstr))
1488 if(fcPatternAddLangSet(pat, FC_LANG, ls))
1489 fcLangSetDestroy(ls);
1492 fs = fcFontList(0, pat, os);
1493 fcPatternDestroy(pat);
1494 fcObjectSetDestroy(os);
1496 for(int i = 0; i < fs->nfont; i++)
1498 FcPattern *font = fs->fonts[i];
1499 BC_FontEntry *entry = new BC_FontEntry;
1502 if(fcPatternGetString(font, FC_FILE, 0, &strvalue) == FcResultMatch)
1504 entry->path = new char[strlen((char*)strvalue) + 1];
1505 strcpy(entry->path, (char*)strvalue);
1508 if(fcPatternGetString(font, FC_FOUNDRY, 0, &strvalue) == FcResultMatch)
1510 entry->foundry = new char[strlen((char*)strvalue) + 1];
1511 strcpy(entry->foundry, (char *)strvalue);
1514 if(fcPatternGetString(font, FC_FAMILY, 0, &strvalue) == FcResultMatch)
1516 entry->family = new char[strlen((char*)strvalue) + 2];
1517 strcpy(entry->family, (char*)strvalue);
1521 if(fcPatternGetInteger(font, FC_SLANT, 0, &intvalue) == FcResultMatch)
1525 case FC_SLANT_ROMAN:
1527 entry->style |= FL_SLANT_ROMAN;
1530 case FC_SLANT_ITALIC:
1531 entry->style |= FL_SLANT_ITALIC;
1534 case FC_SLANT_OBLIQUE:
1535 entry->style |= FL_SLANT_OBLIQUE;
1540 if(fcPatternGetInteger(font, FC_WEIGHT, 0, &intvalue) == FcResultMatch)
1544 case FC_WEIGHT_THIN:
1545 entry->style |= FL_WEIGHT_THIN;
1548 case FC_WEIGHT_EXTRALIGHT:
1549 entry->style |= FL_WEIGHT_EXTRALIGHT;
1552 case FC_WEIGHT_LIGHT:
1553 entry->style |= FL_WEIGHT_LIGHT;
1556 case FC_WEIGHT_BOOK:
1557 entry->style |= FL_WEIGHT_BOOK;
1560 case FC_WEIGHT_NORMAL:
1562 entry->style |= FL_WEIGHT_NORMAL;
1565 case FC_WEIGHT_MEDIUM:
1566 entry->style |= FL_WEIGHT_MEDIUM;
1569 case FC_WEIGHT_DEMIBOLD:
1570 entry->style |= FL_WEIGHT_DEMIBOLD;
1573 case FC_WEIGHT_BOLD:
1574 entry->style |= FL_WEIGHT_BOLD;
1577 case FC_WEIGHT_EXTRABOLD:
1578 entry->style |= FL_WEIGHT_EXTRABOLD;
1581 case FC_WEIGHT_BLACK:
1582 entry->style |= FL_WEIGHT_BLACK;
1585 case FC_WEIGHT_EXTRABLACK:
1586 entry->style |= FL_WEIGHT_EXTRABLACK;
1591 if(fcPatternGetInteger(font, FC_WIDTH, 0, &intvalue) == FcResultMatch)
1595 case FC_WIDTH_ULTRACONDENSED:
1596 entry->style |= FL_WIDTH_ULTRACONDENSED;
1599 case FC_WIDTH_EXTRACONDENSED:
1600 entry->style |= FL_WIDTH_EXTRACONDENSED;
1603 case FC_WIDTH_CONDENSED:
1604 entry->style |= FL_WIDTH_CONDENSED;
1607 case FC_WIDTH_SEMICONDENSED:
1608 entry->style = FL_WIDTH_SEMICONDENSED;
1611 case FC_WIDTH_NORMAL:
1613 entry->style |= FL_WIDTH_NORMAL;
1616 case FC_WIDTH_SEMIEXPANDED:
1617 entry->style |= FL_WIDTH_SEMIEXPANDED;
1620 case FC_WIDTH_EXPANDED:
1621 entry->style |= FL_WIDTH_EXPANDED;
1624 case FC_WIDTH_EXTRAEXPANDED:
1625 entry->style |= FL_WIDTH_EXTRAEXPANDED;
1628 case FC_WIDTH_ULTRAEXPANDED:
1629 entry->style |= FL_WIDTH_ULTRAEXPANDED;
1633 if(fcPatternGetInteger(font, FC_SPACING, 0, &intvalue) == FcResultMatch)
1637 case FC_PROPORTIONAL:
1639 entry->style |= FL_PROPORTIONAL;
1643 entry->style |= FL_DUAL;
1647 entry->style |= FL_MONO;
1651 entry->style |= FL_CHARCELL;
1655 if(entry->foundry && strcmp(entry->foundry, "unknown"))
1657 char tempstr[BCTEXTLEN];
1658 sprintf(tempstr, "%s (%s)", entry->family, entry->foundry);
1659 entry->displayname = new char[strlen(tempstr) + 1];
1660 strcpy(entry->displayname, tempstr);
1664 entry->displayname = new char[strlen(entry->family) + 1];
1665 strcpy(entry->displayname, entry->family);
1667 fontlist->append(entry);
1669 dump_font_entry(stdout, "font 2: ", entry);
1671 fcFontSetDestroy(fs);
1675 #define STYLE_MATCH(fst, stl, msk) ((fst) & (msk) & (stl)) && \
1676 !((fst) & ~(style) & (msk))
1678 BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style,
1679 int mask, int preferred)
1681 BC_FontEntry *entry, *style_match, *preferred_match;
1687 preferred_match = 0;
1691 for(int i = 0; i < fontlist->total; i++)
1693 entry = fontlist->values[i];
1695 if(strcmp(entry->displayname, displayname) == 0 &&
1696 STYLE_MATCH(entry->style, style, mask))
1699 style_match = entry;
1700 if(!preferred_match && entry->fixed_style == preferred)
1701 preferred_match = entry;
1705 return preferred_match;
1711 // No exact match - assume normal width font
1712 style |= FL_WIDTH_NORMAL;
1713 mask |= FL_WIDTH_MASK;
1715 preferred_match = 0;
1717 for(int i = 0; i < fontlist->total; i++)
1719 entry = fontlist->values[i];
1721 if(STYLE_MATCH(entry->style, style, mask))
1724 style_match = entry;
1726 if(!preferred_match && (entry->style & preferred))
1727 preferred_match = entry;
1729 if(!strncasecmp(displayname, entry->family,
1730 strlen(entry->family)))
1736 return preferred_match;
1743 uint8_t *obfr, *out, *oend;
1744 uint8_t *ibfr, *inp, *iend;
1746 utf8conv(void *out, int olen, void *inp, int ilen) {
1747 this->obfr = this->out = (uint8_t*)out;
1748 this->oend = this->out + olen;
1749 this->ibfr = this->inp = (uint8_t*)inp;
1750 this->iend = this->inp + ilen;
1752 int cur() { return inp>=iend ? -1 : *inp; }
1753 int next() { return inp>=iend ? -1 : *inp++; }
1754 int next(int ch) { return out>=oend ? -1 : *out++ = ch; }
1755 int ilen() { return inp-ibfr; }
1756 int olen() { return out-obfr; }
1758 int wnext(unsigned int v);
1762 wnext(unsigned int v)
1764 if( v < 0x00000080 ) { next(v); return 1; }
1765 int n = v < 0x00000800 ? 2 : v < 0x00010000 ? 3 :
1766 v < 0x00200000 ? 4 : v < 0x04000000 ? 5 : 6;
1767 int m = (0xff00 >> n), i = n-1;
1768 next((v>>(6*i)) | m);
1769 while( --i >= 0 ) next(((v>>(6*i)) & 0x3f) | 0x80);
1776 int v = 0, n = 0, ch = next();
1778 switch( (ch=next()) ) {
1779 case 'n': return '\n';
1780 case 't': return '\t';
1781 case 'r': return '\r';
1782 case 'b': return '\b';
1783 case 'f': return '\f';
1784 case 'v': return '\v';
1785 case 'a': return '\a';
1786 case '0': case '1': case '2': case '3':
1787 case '4': case '5': case '6': case '7':
1789 for( int i=3; --i>0; v=v*8+ch, next() )
1790 if( (ch=cur()-'0') < 0 || ch >= 8 ) break;
1792 case 'x': n = 2; break;
1793 case 'u': n = 4; break;
1794 case 'U': n = 8; break;
1797 for( int i=n; --i>=0; v=v*16+ch, next() ) {
1798 if( (ch=cur()-'0')>=0 && ch<10 ) continue;
1799 if( (ch-='A'-'0'-10)>=10 && ch<16 ) continue;
1800 if( (ch-='a'-'A')<10 || ch>=16 ) break;
1803 else if( ch >= 0x80 ) {
1804 static const unsigned char byts[] = {
1805 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 5,
1808 n = i<0 ? 0 : byts[i/4];
1809 for( v=ch, i=n; --i>=0; v+=next() ) v <<= 6;
1810 static const unsigned int ofs[6] = {
1811 0x00000000U, 0x00003080U, 0x000E2080U,
1812 0x03C82080U, 0xFA082080U, 0x82082080U
1822 size_t BC_Resources::encode(const char *from_enc, const char *to_enc,
1823 char *input, int input_length, char *output, int output_length)
1825 if( !from_enc || *from_enc == 0 ||
1826 !strcmp(from_enc,"UTF8") || !strcmp(from_enc, "US-ASCII") )
1829 if( !to_enc || *to_enc == 0 ||
1830 !strcmp(to_enc,"UTF8") || !strcmp(to_enc, "US-ASCII") )
1834 char *outbase = output;
1835 size_t inbytes = input_length < 0 ? strlen(input) : input_length;
1836 size_t outbytes = output_length;
1838 if( inbytes && outbytes ) {
1839 if( !strcmp(from_enc, to_enc) ) {
1840 if( inbytes > outbytes ) inbytes = outbytes;
1841 memcpy(output, input, inbytes);
1843 outbytes -= inbytes;
1845 else if( !strcmp(from_enc, "UTF-8") && !strcmp(to_enc,"UTF32LE") ) {
1846 utf8conv uc(0,0, input,inbytes);
1847 uint32_t *op = (uint32_t *)output;
1848 uint32_t *ep = (uint32_t *)(output+output_length);
1849 for( int wch; op<ep && (wch=uc.wnext())>=0; *op++=wch );
1850 output = (char *)op;
1851 outbytes = (char*)ep - output;
1853 else if( !strcmp(from_enc, "UTF32LE") && !strcmp(to_enc,"UTF-8") ) {
1854 utf8conv uc(output,output_length, 0,0);
1855 uint32_t *ip = (uint32_t *)input;
1856 uint32_t *ep = (uint32_t *)(input+inbytes);
1857 for( ; ip<ep && uc.wnext(*ip)>=0; ++ip );
1858 output += uc.olen();
1859 outbytes -= uc.olen();
1861 else if( (cd = iconv_open(to_enc, from_enc)) != (iconv_t)-1 ) {
1862 iconv(cd, &input, &inbytes, &output, &outbytes);
1866 printf(_("Conversion from %s to %s is not available\n"),
1870 if( outbytes > sizeof(uint32_t) )
1871 outbytes = sizeof(uint32_t);
1872 for( uint32_t i = 0; i < outbytes; i++)
1874 return output - outbase;
1877 void BC_Resources::encode_to_utf8(char *buffer, int buflen)
1879 if(BC_Resources::locale_utf8) return;
1881 encode(encoding, 0, buffer, buflen, lbuf, buflen);
1882 strcpy(buffer, lbuf);
1885 int BC_Resources::find_font_by_char(FT_ULong char_code, char *path_new, const FT_Face oldface)
1887 FcPattern *font, *ofont;
1893 // Do not search control codes
1897 if( (ofont = fcFreeTypeQueryFace(oldface, (const FcChar8*)"", 4097, 0)) != 0 ) {
1898 if( (font = find_similar_font(char_code, ofont)) != 0 ) {
1899 if(fcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
1900 strcpy(path_new, (char*)file);
1903 fcPatternDestroy(font);
1905 fcPatternDestroy(ofont);
1910 FcPattern* BC_Resources::find_similar_font(FT_ULong char_code, FcPattern *oldfont)
1912 FcPattern *pat, *font;
1918 // Do not search control codes
1922 fontconfig_lock.lock("BC_Resources::find_similar_font");
1923 pat = fcPatternCreate();
1924 os = fcObjectSetBuild(FC_FILE, FC_CHARSET, FC_SCALABLE, FC_FAMILY,
1925 FC_SLANT, FC_WEIGHT, FC_WIDTH, (char *)0);
1927 fcPatternAddBool(pat, FC_SCALABLE, true);
1928 fcs = fcCharSetCreate();
1929 if(fcCharSetAddChar(fcs, char_code))
1930 fcPatternAddCharSet(pat, FC_CHARSET, fcs);
1931 fcCharSetDestroy(fcs);
1932 for( int i=0; i<(int)LEN_FCPROP; ++i ) {
1933 if(fcPatternGetInteger(oldfont, fc_properties[i], 0, &ival) == FcResultMatch)
1934 fcPatternAddInteger(pat, fc_properties[i], ival);
1936 fs = fcFontList(0, pat, os);
1937 for( int i=LEN_FCPROP; --i>=0 && !fs->nfont; ) {
1938 fcFontSetDestroy(fs);
1939 fcPatternDel(pat, fc_properties[i]);
1940 fs = fcFontList(0, pat, os);
1942 fcPatternDestroy(pat);
1943 fcObjectSetDestroy(os);
1947 for (int i = 0; i < fs->nfont; i++)
1949 font = fs->fonts[i];
1950 if(fcPatternGetCharSet(font, FC_CHARSET, 0, &fcs) == FcResultMatch)
1952 if(fcCharSetHasChar(fcs, char_code))
1954 pat = fcPatternDuplicate(font);
1959 fcFontSetDestroy(fs);
1960 fontconfig_lock.unlock();
1965 void BC_Resources::dump_fonts(FILE *fp)
1967 for( int i=0; i<fontlist->total; ++i )
1968 dump_font_entry(fp, "", fontlist->values[i]);
1971 void BC_Resources::dump_font_entry(FILE *fp, const char *cp, BC_FontEntry *ep)
1973 fprintf(fp,"%s%s = %s\n",cp,ep->displayname,ep->path);
1974 fprintf(fp," %s:%s:%s:%s:%s:%s:%d:%d:%d:%d:%d:%s:%d:%s:%s:%d\n",
1975 ep->foundry, ep->family, ep->weight, ep->slant, ep->swidth, ep->adstyle,
1976 ep->pixelsize, ep->pointsize, ep->xres, ep->yres, ep->style, ep->spacing,
1977 ep->avg_width, ep->registry, ep->encoding, ep->fixed_style);