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, };
362 BC_Resources::BC_Resources()
366 double default_scale = 1.0; // display_size/1000.;
367 char *env = getenv("BC_FONT_DEBUG");
368 font_debug = env ? atoi(env) : 0;
369 env = getenv("BC_FONT_SCALE");
370 font_scale = env ? atof(env) : default_scale;
371 if( font_scale <= 0 ) font_scale = 1;
372 init_font_defs(font_scale);
373 env = getenv("BC_ICON_SCALE");
374 icon_scale = env ? atof(env) : default_scale;
375 if( icon_scale <= 0 ) icon_scale = 1;
377 id_lock = new Mutex("BC_Resources::id_lock");
378 create_window_lock = new Mutex("BC_Resources::create_window_lock", 1);
380 machine_cpus = get_machine_cpus();
382 for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
383 filebox_history[i].path[0] = 0;
389 little_endian = (*(const u_int32_t*)"\01\0\0\0") & 1;
390 wide_encoding = little_endian ? "UTF32LE" : "UTF32BE";
393 #include "images/file_folder_png.h"
394 #include "images/file_unknown_png.h"
395 #include "images/file_film_png.h"
396 #include "images/file_sound_png.h"
397 #include "images/file_label_png.h"
398 #include "images/file_column_png.h"
399 new_vframes(6,default_type_to_icon,
400 new VFramePng(file_folder_png),
401 new VFramePng(file_unknown_png),
402 new VFramePng(file_film_png),
403 new VFramePng(file_sound_png),
404 new VFramePng(file_label_png),
405 new VFramePng(file_column_png));
407 #include "images/bar_png.h"
408 default_bar = new VFramePng(bar_png);
410 #include "images/cancel_up_png.h"
411 #include "images/cancel_hi_png.h"
412 #include "images/cancel_dn_png.h"
413 new_vframes(3,default_cancel_images,
414 new VFramePng(cancel_up_png),
415 new VFramePng(cancel_hi_png),
416 new VFramePng(cancel_dn_png));
418 #include "images/ok_up_png.h"
419 #include "images/ok_hi_png.h"
420 #include "images/ok_dn_png.h"
421 new_vframes(3,default_ok_images,
422 new VFramePng(ok_up_png),
423 new VFramePng(ok_hi_png),
424 new VFramePng(ok_dn_png));
426 #include "images/usethis_up_png.h"
427 #include "images/usethis_uphi_png.h"
428 #include "images/usethis_dn_png.h"
429 new_vframes(3,default_usethis_images,
430 new VFramePng(usethis_up_png),
431 new VFramePng(usethis_uphi_png),
432 new VFramePng(usethis_dn_png));
435 #include "images/checkbox_checked_png.h"
436 #include "images/checkbox_dn_png.h"
437 #include "images/checkbox_checkedhi_png.h"
438 #include "images/checkbox_up_png.h"
439 #include "images/checkbox_hi_png.h"
440 new_vframes(5,default_checkbox_images,
441 new VFramePng(checkbox_up_png),
442 new VFramePng(checkbox_hi_png),
443 new VFramePng(checkbox_checked_png),
444 new VFramePng(checkbox_dn_png),
445 new VFramePng(checkbox_checkedhi_png));
447 #include "images/radial_checked_png.h"
448 #include "images/radial_dn_png.h"
449 #include "images/radial_checkedhi_png.h"
450 #include "images/radial_up_png.h"
451 #include "images/radial_hi_png.h"
452 new_vframes(5,default_radial_images,
453 new VFramePng(radial_up_png),
454 new VFramePng(radial_hi_png),
455 new VFramePng(radial_checked_png),
456 new VFramePng(radial_dn_png),
457 new VFramePng(radial_checkedhi_png));
459 new_vframes(5,default_label_images,
460 new VFramePng(radial_up_png),
461 new VFramePng(radial_hi_png),
462 new VFramePng(radial_checked_png),
463 new VFramePng(radial_dn_png),
464 new VFramePng(radial_checkedhi_png));
467 #include "images/menuitem_up_png.h"
468 #include "images/menuitem_hi_png.h"
469 #include "images/menuitem_dn_png.h"
470 new_vframes(3,default_menuitem_data,
471 new VFramePng(menuitem_up_png),
472 new VFramePng(menuitem_hi_png),
473 new VFramePng(menuitem_dn_png));
475 #include "images/menubar_up_png.h"
476 #include "images/menubar_hi_png.h"
477 #include "images/menubar_dn_png.h"
478 new_vframes(3,default_menubar_data,
479 new VFramePng(menubar_up_png),
480 new VFramePng(menubar_hi_png),
481 new VFramePng(menubar_dn_png));
483 #include "images/menu_popup_bg_png.h"
484 default_menu_popup_bg = new VFramePng(menu_popup_bg_png);
486 #include "images/menubar_bg_png.h"
487 default_menu_bar_bg = new VFramePng(menubar_bg_png);
489 #include "images/check_png.h"
490 default_check_image = new VFramePng(check_png);
492 #include "images/file_text_up_png.h"
493 #include "images/file_text_hi_png.h"
494 #include "images/file_text_dn_png.h"
495 new_vframes(3,default_filebox_text_images,
496 new VFramePng(file_text_up_png),
497 new VFramePng(file_text_hi_png),
498 new VFramePng(file_text_dn_png));
500 #include "images/file_icons_up_png.h"
501 #include "images/file_icons_hi_png.h"
502 #include "images/file_icons_dn_png.h"
503 new_vframes(3,default_filebox_icons_images,
504 new VFramePng(file_icons_up_png),
505 new VFramePng(file_icons_hi_png),
506 new VFramePng(file_icons_dn_png));
508 #include "images/file_updir_up_png.h"
509 #include "images/file_updir_hi_png.h"
510 #include "images/file_updir_dn_png.h"
511 new_vframes(3,default_filebox_updir_images,
512 new VFramePng(file_updir_up_png),
513 new VFramePng(file_updir_hi_png),
514 new VFramePng(file_updir_dn_png));
516 #include "images/file_newfolder_up_png.h"
517 #include "images/file_newfolder_hi_png.h"
518 #include "images/file_newfolder_dn_png.h"
519 new_vframes(3,default_filebox_newfolder_images,
520 new VFramePng(file_newfolder_up_png),
521 new VFramePng(file_newfolder_hi_png),
522 new VFramePng(file_newfolder_dn_png));
524 #include "images/file_rename_up_png.h"
525 #include "images/file_rename_hi_png.h"
526 #include "images/file_rename_dn_png.h"
527 new_vframes(3,default_filebox_rename_images,
528 new VFramePng(file_rename_up_png),
529 new VFramePng(file_rename_hi_png),
530 new VFramePng(file_rename_dn_png));
532 #include "images/file_delete_up_png.h"
533 #include "images/file_delete_hi_png.h"
534 #include "images/file_delete_dn_png.h"
535 new_vframes(3,default_filebox_delete_images,
536 new VFramePng(file_delete_up_png),
537 new VFramePng(file_delete_hi_png),
538 new VFramePng(file_delete_dn_png));
540 #include "images/file_reload_up_png.h"
541 #include "images/file_reload_hi_png.h"
542 #include "images/file_reload_dn_png.h"
543 new_vframes(3,default_filebox_reload_images,
544 new VFramePng(file_reload_up_png),
545 new VFramePng(file_reload_hi_png),
546 new VFramePng(file_reload_dn_png));
548 #include "images/file_size_capb_up_png.h"
549 #include "images/file_size_capb_hi_png.h"
550 #include "images/file_size_capb_dn_png.h"
551 #include "images/file_size_lwrb_up_png.h"
552 #include "images/file_size_lwrb_hi_png.h"
553 #include "images/file_size_lwrb_dn_png.h"
554 #include "images/file_size_semi_up_png.h"
555 #include "images/file_size_semi_hi_png.h"
556 #include "images/file_size_semi_dn_png.h"
557 #include "images/file_size_zero_up_png.h"
558 #include "images/file_size_zero_hi_png.h"
559 #include "images/file_size_zero_dn_png.h"
560 new_vframes(12,default_filebox_szfmt_images,
561 new VFramePng(file_size_zero_up_png),
562 new VFramePng(file_size_zero_hi_png),
563 new VFramePng(file_size_zero_dn_png),
564 new VFramePng(file_size_lwrb_up_png),
565 new VFramePng(file_size_lwrb_hi_png),
566 new VFramePng(file_size_lwrb_dn_png),
567 new VFramePng(file_size_capb_up_png),
568 new VFramePng(file_size_capb_hi_png),
569 new VFramePng(file_size_capb_dn_png),
570 new VFramePng(file_size_semi_up_png),
571 new VFramePng(file_size_semi_hi_png),
572 new VFramePng(file_size_semi_dn_png));
574 #include "images/listbox_button_dn_png.h"
575 #include "images/listbox_button_hi_png.h"
576 #include "images/listbox_button_up_png.h"
577 #include "images/listbox_button_disabled_png.h"
578 new_vframes(4,default_listbox_button,
579 new VFramePng(listbox_button_up_png),
580 new VFramePng(listbox_button_hi_png),
581 new VFramePng(listbox_button_dn_png),
582 new VFramePng(listbox_button_disabled_png));
584 default_listbox_bg = 0;
586 #include "images/listbox_expandchecked_png.h"
587 #include "images/listbox_expandcheckedhi_png.h"
588 #include "images/listbox_expanddn_png.h"
589 #include "images/listbox_expandup_png.h"
590 #include "images/listbox_expanduphi_png.h"
591 new_vframes(5,default_listbox_expand,
592 new VFramePng(listbox_expandup_png),
593 new VFramePng(listbox_expanduphi_png),
594 new VFramePng(listbox_expandchecked_png),
595 new VFramePng(listbox_expanddn_png),
596 new VFramePng(listbox_expandcheckedhi_png));
598 #include "images/listbox_columnup_png.h"
599 #include "images/listbox_columnhi_png.h"
600 #include "images/listbox_columndn_png.h"
601 new_vframes(3,default_listbox_column,
602 new VFramePng(listbox_columnup_png),
603 new VFramePng(listbox_columnhi_png),
604 new VFramePng(listbox_columndn_png));
606 #include "images/listbox_up_png.h"
607 default_listbox_up = new VFramePng(listbox_up_png);
609 #include "images/listbox_dn_png.h"
610 default_listbox_dn = new VFramePng(listbox_dn_png);
612 #include "images/pot_hi_png.h"
613 #include "images/pot_up_png.h"
614 #include "images/pot_dn_png.h"
615 new_vframes(3,default_pot_images,
616 new VFramePng(pot_up_png),
617 new VFramePng(pot_hi_png),
618 new VFramePng(pot_dn_png));
620 #include "images/progress_up_png.h"
621 #include "images/progress_hi_png.h"
622 new_vframes(2,default_progress_images,
623 new VFramePng(progress_up_png),
624 new VFramePng(progress_hi_png));
626 #include "images/7seg_small/0_png.h"
627 #include "images/7seg_small/1_png.h"
628 #include "images/7seg_small/2_png.h"
629 #include "images/7seg_small/3_png.h"
630 #include "images/7seg_small/4_png.h"
631 #include "images/7seg_small/5_png.h"
632 #include "images/7seg_small/6_png.h"
633 #include "images/7seg_small/7_png.h"
634 #include "images/7seg_small/8_png.h"
635 #include "images/7seg_small/9_png.h"
636 #include "images/7seg_small/colon_png.h"
637 #include "images/7seg_small/period_png.h"
638 #include "images/7seg_small/a_png.h"
639 #include "images/7seg_small/b_png.h"
640 #include "images/7seg_small/c_png.h"
641 #include "images/7seg_small/d_png.h"
642 #include "images/7seg_small/e_png.h"
643 #include "images/7seg_small/f_png.h"
644 #include "images/7seg_small/space_png.h"
645 #include "images/7seg_small/dash_png.h"
646 new_vframes(20,default_medium_7segment,
647 new VFramePng(_0_png),
648 new VFramePng(_1_png),
649 new VFramePng(_2_png),
650 new VFramePng(_3_png),
651 new VFramePng(_4_png),
652 new VFramePng(_5_png),
653 new VFramePng(_6_png),
654 new VFramePng(_7_png),
655 new VFramePng(_8_png),
656 new VFramePng(_9_png),
657 new VFramePng(colon_png),
658 new VFramePng(period_png),
659 new VFramePng(a_png),
660 new VFramePng(b_png),
661 new VFramePng(c_png),
662 new VFramePng(d_png),
663 new VFramePng(e_png),
664 new VFramePng(f_png),
665 new VFramePng(space_png),
666 new VFramePng(dash_png));
668 type_to_icon = default_type_to_icon;
669 bar_data = default_bar;
670 check = default_check_image;
671 listbox_button = default_listbox_button;
672 listbox_bg = default_listbox_bg;
673 listbox_expand = default_listbox_expand;
674 listbox_column = default_listbox_column;
675 listbox_up = default_listbox_up;
676 listbox_dn = default_listbox_dn;
677 listbox_title_overlap = 0;
678 listbox_title_margin = 0;
679 listbox_title_color = BLACK;
680 listbox_title_hotspot = 5;
682 listbox_border1 = DKGREY;
683 listbox_border2_hi = RED;
684 listbox_border2 = BLACK;
685 listbox_border3_hi = RED;
686 listbox_border3 = MEGREY;
687 listbox_border4 = WHITE;
688 listbox_selected = BLUE;
689 listbox_highlighted = LTGREY;
690 listbox_inactive = WHITE;
691 listbox_text = BLACK;
694 pan_text_color = YELLOW;
696 generic_button_margin = 15;
697 draw_clock_background=1;
707 bg_light2 = bg_color;
710 border_light1 = bg_color;
711 border_light2 = MEGREY;
712 border_shadow1 = BLACK;
713 border_shadow2 = bg_color;
715 default_text_color = BLACK;
716 disabled_text_color = DMGREY;
718 button_light = MEGREY; // bright corner
719 // button_highlighted = LTGREY; // face when highlighted
720 button_highlighted = 0xffe000; // face when highlighted
721 button_down = MDGREY; // face when down
722 // button_up = MEGREY; // face when up
723 button_up = 0xffc000; // face when up
724 button_shadow = BLACK; // dark corner
725 button_uphighlighted = RED; // upper side when highlighted
728 tumble_duration = 150;
730 ok_images = default_ok_images;
731 cancel_images = default_cancel_images;
732 usethis_button_images = default_usethis_images;
733 filebox_descend_images = default_ok_images;
736 menu_highlighted = LTBLUE;
739 menu_shadow = DKCYAN;
741 menu_title_bg = default_menubar_data;
742 menu_popup_bg = default_menu_popup_bg;
743 menu_bar_bg = default_menu_bar_bg;
745 popupmenu_images = 0;
748 popupmenu_margin = 10;
750 popupmenu_triangle_margin = 10;
753 menu_title_text = BLACK;
754 popup_title_text = BLACK;
755 menu_item_text = BLACK;
756 menu_highlighted_fontcolor = BLACK;
757 progress_text = BLACK;
758 grab_input_focus = 1;
760 text_default = BLACK;
761 highlight_inverse = WHITE ^ BLUE;
762 text_background = WHITE;
763 text_background_disarmed = 0xc08080;
764 text_background_hi = LTYELLOW;
765 text_background_noborder_hi = LTGREY;
766 text_background_noborder = -1;
767 text_border1 = DKGREY;
768 text_border2 = BLACK;
769 text_border2_hi = RED;
770 text_border3 = MEGREY;
771 text_border3_hi = LTPINK;
772 text_border4 = WHITE;
773 text_highlight = BLUE;
774 text_selected_highlight = SLBLUE;
775 text_inactive_highlight = MEGREY;
777 toggle_highlight_bg = 0;
778 toggle_text_margin = 0;
780 // Delays must all be different for repeaters
784 tooltip_delay = 1000;
785 tooltip_bg_color = YELLOW;
786 tooltips_enabled = 1;
787 textbox_focus_policy = 0;
789 filebox_margin = 110;
791 filebox_mode = LISTBOX_TEXT;
792 sprintf(filebox_filter, "*");
795 filebox_columntype[0] = FILEBOX_NAME;
796 filebox_columntype[1] = FILEBOX_SIZE;
797 filebox_columntype[2] = FILEBOX_DATE;
798 filebox_columntype[3] = FILEBOX_EXTENSION;
799 filebox_columnwidth[0] = 200;
800 filebox_columnwidth[1] = 100;
801 filebox_columnwidth[2] = 100;
802 filebox_columnwidth[3] = 100;
803 dirbox_columntype[0] = FILEBOX_NAME;
804 dirbox_columntype[1] = FILEBOX_DATE;
805 dirbox_columnwidth[0] = 200;
806 dirbox_columnwidth[1] = 100;
808 filebox_text_images = default_filebox_text_images;
809 filebox_icons_images = default_filebox_icons_images;
810 filebox_updir_images = default_filebox_updir_images;
811 filebox_newfolder_images = default_filebox_newfolder_images;
812 filebox_rename_images = default_filebox_rename_images;
813 filebox_delete_images = default_filebox_delete_images;
814 filebox_reload_images = default_filebox_reload_images;
815 filebox_szfmt_images = default_filebox_szfmt_images;
816 filebox_size_format = FILEBOX_SIZE_RAW;
817 directory_color = BLUE;
820 filebox_sortcolumn = 0;
821 filebox_sortorder = BC_ListBox::SORT_ASCENDING;
822 dirbox_sortcolumn = 0;
823 dirbox_sortorder = BC_ListBox::SORT_ASCENDING;
826 pot_images = default_pot_images;
828 pot_x1 = pot_images[0]->get_w() / 2 - pot_offset;
829 pot_y1 = pot_images[0]->get_h() / 2 - pot_offset;
831 pot_needle_color = BLACK;
833 progress_images = default_progress_images;
837 meter_font = SMALLFONT_3D;
838 meter_font_color = RED;
841 medium_7segment = default_medium_7segment;
843 audiovideo_color = RED;
847 // Xft has priority over font set
849 // But Xft dies in 32 bit mode after some amount of drawing.
857 recursive_resizing = 1;
862 void BC_Resources::del_vframes(VFrame *vframes[], int n)
864 while( --n >= 0 ) delete vframes[n];
867 BC_Resources::~BC_Resources()
870 delete create_window_lock;
871 del_vframes(default_type_to_icon, 6);
873 del_vframes(default_cancel_images, 3);
874 del_vframes(default_ok_images, 3);
875 del_vframes(default_usethis_images, 3);
877 del_vframes(default_checkbox_images, 5);
878 del_vframes(default_radial_images, 5);
879 del_vframes(default_label_images, 5);
881 del_vframes(default_menuitem_data, 3);
882 del_vframes(default_menubar_data, 3);
883 delete default_menu_popup_bg;
884 delete default_menu_bar_bg;
885 delete default_check_image;
886 del_vframes(default_filebox_text_images, 3);
887 del_vframes(default_filebox_icons_images, 3);
888 del_vframes(default_filebox_updir_images, 3);
889 del_vframes(default_filebox_newfolder_images, 3);
890 del_vframes(default_filebox_rename_images, 3);
891 del_vframes(default_filebox_delete_images, 3);
892 del_vframes(default_filebox_reload_images, 3);
893 del_vframes(default_filebox_szfmt_images, 12);
894 del_vframes(default_listbox_button, 4);
895 delete default_listbox_bg;
896 del_vframes(default_listbox_expand, 5);
897 del_vframes(default_listbox_column, 3);
898 delete default_listbox_up;
899 delete default_listbox_dn;
900 del_vframes(default_pot_images, 3);
901 del_vframes(default_progress_images, 2);
902 del_vframes(default_medium_7segment, 20);
904 fontlist->remove_all_objects();
910 int BC_Resources::initialize_display(BC_WindowBase *window)
912 // Set up IPC cleanup handlers
915 // Test for shm. Must come before yuv test
921 void BC_Resources::init_shm(BC_WindowBase *window)
924 int (*old_handler)(Display *, XErrorEvent *) =
925 XSetErrorHandler(BC_Resources::x_error_handler);
927 if(XShmQueryExtension(window->display))
929 XShmSegmentInfo test_shm;
930 memset(&test_shm,0,sizeof(test_shm));
931 XImage *test_image = XShmCreateImage(window->display, window->vis,
932 window->default_depth, ZPixmap, (char*)NULL, &test_shm, 5, 5);
933 BC_Resources::error = 0;
934 test_shm.shmid = shmget(IPC_PRIVATE, 5 * test_image->bytes_per_line, (IPC_CREAT | 0600));
935 if(test_shm.shmid != -1) {
936 char *data = (char *)shmat(test_shm.shmid, NULL, 0);
937 if(data != (void *)-1) {
938 shmctl(test_shm.shmid, IPC_RMID, 0);
939 test_shm.shmaddr = data;
940 test_shm.readOnly = 0;
942 if(XShmAttach(window->display, &test_shm)) {
943 XSync(window->display, False);
950 XDestroyImage(test_image);
951 if(BC_Resources::error) use_shm = 0;
953 XSetErrorHandler(old_handler);
959 BC_Synchronous* BC_Resources::get_synchronous()
964 void BC_Resources::set_synchronous(BC_Synchronous *synchronous)
966 this->synchronous = synchronous;
972 int BC_Resources::get_bg_color() { return bg_color; }
974 int BC_Resources::get_bg_shadow1() { return bg_shadow1; }
976 int BC_Resources::get_bg_shadow2() { return bg_shadow2; }
978 int BC_Resources::get_bg_light1() { return bg_light1; }
980 int BC_Resources::get_bg_light2() { return bg_light2; }
983 int BC_Resources::get_id()
985 id_lock->lock("BC_Resources::get_id");
991 int BC_Resources::get_filebox_id()
993 id_lock->lock("BC_Resources::get_filebox_id");
994 int result = filebox_id++;
1000 void BC_Resources::set_signals(BC_Signals *signal_handler)
1002 BC_Resources::signal_handler = signal_handler;
1005 int BC_Resources::init_fontconfig(const char *search_path)
1007 if( fontlist ) return 0;
1008 fontlist = new ArrayList<BC_FontEntry*>;
1010 #define get_str(str,sep,ptr,cond) do { char *out = str; \
1011 while( *ptr && !strchr(sep,*ptr) && (cond) ) *out++ = *ptr++; \
1015 #define skip_str(sep, ptr) do { \
1016 while( *ptr && strchr(sep,*ptr) ) ++ptr; \
1019 char find_command[BCTEXTLEN];
1020 char *fp = find_command, *ep = fp+sizeof(find_command)-1;
1021 fp += snprintf(fp, ep-fp, "%s", "find");
1022 const char *bc_font_path = getenv("BC_FONT_PATH");
1023 // if BC_FONT_PATH starts with ':', omit default path
1024 if( !(bc_font_path && bc_font_path[0] == ':') )
1025 fp += snprintf(fp, ep-fp, " '%s'", search_path);
1026 if( bc_font_path ) {
1027 const char *path = bc_font_path;
1029 char font_path[BCTEXTLEN];
1030 const char *cp = strchr(path,':');
1031 int len = !cp ? strlen(path) : cp-path;
1033 memcpy(font_path, path, len);
1034 font_path[len] = 0; path += len;
1035 fp += snprintf(fp, ep-fp, " '%s'", font_path);
1040 fp += snprintf(fp, ep-fp, " -name 'fonts.scale' -print -exec cat {} \\;");
1041 FILE *in = popen(find_command, "r");
1043 FT_Library freetype_library = 0;
1044 // FT_Face freetype_face = 0;
1045 // ft_Init_FreeType(&freetype_library);
1047 char line[BCTEXTLEN], current_dir[BCTEXTLEN];
1050 while( !feof(in) && fgets(line, BCTEXTLEN, in) ) {
1051 if(!strlen(line)) break;
1053 char *in_ptr = line;
1055 // Get current directory
1056 if(line[0] == '/') {
1057 get_str(current_dir, "\n", in_ptr,1);
1058 for( int i=strlen(current_dir); --i>=0 && current_dir[i]!='/'; )
1063 //printf("TitleMain::build_fonts %s\n", line);
1064 BC_FontEntry *entry = new BC_FontEntry;
1065 char string[BCTEXTLEN];
1067 get_str(string, "\n", in_ptr, in_ptr[0]!=' ' || in_ptr[1]!='-');
1068 entry->path = cstrcat(2, current_dir, string);
1070 skip_str(" -", in_ptr);
1071 get_str(string, "-\n", in_ptr, 1);
1072 if( !string[0] ) { delete entry; continue; }
1073 entry->foundry = cstrdup(string);
1074 if(*in_ptr == '-') in_ptr++;
1076 get_str(string, "-\n", in_ptr, 1);
1077 if( !string[0] ) { delete entry; continue; }
1078 entry->family = cstrdup(string);
1079 if(*in_ptr == '-') in_ptr++;
1081 get_str(string, "-\n", in_ptr, 1);
1082 entry->weight = cstrdup(string);
1083 if(*in_ptr == '-') in_ptr++;
1085 get_str(string, "-\n", in_ptr, 1);
1086 entry->slant = cstrdup(string);
1087 if(*in_ptr == '-') in_ptr++;
1089 get_str(string, "-\n", in_ptr, 1);
1090 entry->swidth = cstrdup(string);
1091 if(*in_ptr == '-') in_ptr++;
1093 get_str(string, "-\n", in_ptr, 1);
1094 entry->adstyle = cstrdup(string);
1095 if(*in_ptr == '-') in_ptr++;
1097 get_str(string, "-\n", in_ptr, 1);
1098 entry->pixelsize = atol(string);
1099 if(*in_ptr == '-') in_ptr++;
1101 get_str(string, "-\n", in_ptr, 1);
1102 entry->pointsize = atol(string);
1103 if(*in_ptr == '-') in_ptr++;
1105 get_str(string, "-\n", in_ptr, 1);
1106 entry->xres = atol(string);
1107 if(*in_ptr == '-') in_ptr++;
1109 get_str(string, "-\n", in_ptr, 1);
1110 entry->yres = atol(string);
1111 if(*in_ptr == '-') in_ptr++;
1113 get_str(string, "-\n", in_ptr, 1);
1114 entry->spacing = cstrdup(string);
1115 if(*in_ptr == '-') in_ptr++;
1117 get_str(string, "-\n", in_ptr, 1);
1118 entry->avg_width = atol(string);
1119 if(*in_ptr == '-') in_ptr++;
1121 get_str(string, "-\n", in_ptr, 1);
1122 entry->registry = cstrdup(string);
1123 if(*in_ptr == '-') in_ptr++;
1125 get_str(string, "-\n", in_ptr, 1);
1126 entry->encoding = cstrdup(string);
1127 if(*in_ptr == '-') in_ptr++;
1130 //printf("TitleMain::build_fonts 1 %s\n", entry->path);
1131 // This takes a real long time to do. Instead just take all fonts
1132 // if(!load_freetype_face(freetype_library,
1133 // freetype_face, entry->path) )
1135 sprintf(line, "%s (%s)", entry->family, entry->foundry);
1136 entry->displayname = cstrdup(line);
1138 if(!strcasecmp(entry->weight, "demibold")) {
1139 entry->fixed_style |= BC_FONT_BOLD;
1140 entry->style |= FL_WEIGHT_DEMIBOLD;
1142 else if(!strcasecmp(entry->weight, "bold")) {
1143 entry->fixed_style |= BC_FONT_BOLD;
1144 entry->style |= FL_WEIGHT_BOLD;
1147 entry->style |= FL_WEIGHT_NORMAL;
1150 if(!strcasecmp(entry->slant, "r")) {
1151 entry->style |= FL_SLANT_ROMAN;
1153 else if(!strcasecmp(entry->slant, "i")) {
1154 entry->style |= FL_SLANT_ITALIC;
1155 entry->fixed_style |= BC_FONT_ITALIC;
1157 else if(!strcasecmp(entry->slant, "o")) {
1158 entry->style |= FL_SLANT_OBLIQUE;
1159 entry->fixed_style |= BC_FONT_ITALIC;
1162 if(!strcasecmp(entry->swidth, "normal"))
1163 entry->style |= FL_WIDTH_NORMAL;
1164 else if(!strcasecmp(entry->swidth, "ultracondensed"))
1165 entry->style |= FL_WIDTH_ULTRACONDENSED;
1166 else if(!strcasecmp(entry->swidth, "extracondensed"))
1167 entry->style |= FL_WIDTH_EXTRACONDENSED;
1168 else if(!strcasecmp(entry->swidth, "condensed"))
1169 entry->style |= FL_WIDTH_CONDENSED;
1170 else if(!strcasecmp(entry->swidth, "semicondensed"))
1171 entry->style |= FL_WIDTH_SEMICONDENSED;
1172 else if(!strcasecmp(entry->swidth, "semiexpanded"))
1173 entry->style |= FL_WIDTH_SEMIEXPANDED;
1174 else if(!strcasecmp(entry->swidth, "expanded"))
1175 entry->style |= FL_WIDTH_EXPANDED;
1176 else if(!strcasecmp(entry->swidth, "extraexpanded"))
1177 entry->style |= FL_WIDTH_EXTRAEXPANDED;
1178 else if(!strcasecmp(entry->swidth, "ultraexpanded"))
1179 entry->style |= FL_WIDTH_ULTRAEXPANDED;
1181 entry->style |= FL_WIDTH_NORMAL;
1183 fontlist->append(entry);
1185 dump_font_entry(stdout, "font 0: ", entry);
1187 // printf("TitleMain::build_fonts %s: success\n", entry->path);
1188 //printf("TitleMain::build_fonts 2\n");
1192 if( bc_font_path && bc_font_path[0] == ':' )
1195 // Load all the fonts from fontconfig
1199 FcChar8 *family, *file, *foundry, *style, *format;
1200 int slant, spacing, width, weight;
1201 int force_style = 0;
1202 // if you want limit search to TrueType put 1
1203 int limit_to_trutype = 1;
1206 char tmpstring[BCTEXTLEN];
1209 config = fcConfigGetCurrent();
1210 fcConfigSetRescanInterval(config, 0);
1212 pat = fcPatternCreate();
1213 os = fcObjectSetBuild( FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
1214 FC_WIDTH, FC_SLANT, FC_FONTFORMAT, FC_SPACING, FC_STYLE, (char *) 0);
1215 fcPatternAddBool(pat, FC_SCALABLE, true);
1218 char langstr[LEN_LANG * 3];
1219 strcpy(langstr, language);
1222 strcat(langstr, "-");
1223 strcat(langstr, region);
1226 FcLangSet *ls = fcLangSetCreate();
1227 if(fcLangSetAdd(ls, (const FcChar8*)langstr))
1228 if(fcPatternAddLangSet(pat, FC_LANG, ls))
1229 fcLangSetDestroy(ls);
1232 fs = fcFontList(config, pat, os);
1233 fcPatternDestroy(pat);
1234 fcObjectSetDestroy(os);
1236 for (i = 0; fs && i < fs->nfont; i++) {
1237 FcPattern *font = fs->fonts[i];
1239 fcPatternGetString(font, FC_FONTFORMAT, 0, &format);
1240 //on this point you can limit font search
1241 if(limit_to_trutype && strcmp((char *)format, "TrueType"))
1244 sprintf(tmpstring, "%s", format);
1245 BC_FontEntry *entry = new BC_FontEntry;
1246 if(fcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
1247 entry->path = cstrdup((char*)file);
1250 if(fcPatternGetString(font, FC_FOUNDRY, 0, &foundry) == FcResultMatch) {
1251 entry->foundry = cstrdup((char*)foundry);
1254 if(fcPatternGetInteger(font, FC_WEIGHT, 0, &weight) == FcResultMatch) {
1256 case FC_WEIGHT_THIN:
1257 case FC_WEIGHT_EXTRALIGHT:
1258 case FC_WEIGHT_LIGHT:
1259 case FC_WEIGHT_BOOK:
1261 entry->weight = cstrdup("medium");
1264 case FC_WEIGHT_NORMAL:
1265 case FC_WEIGHT_MEDIUM:
1267 entry->weight = cstrdup("medium");
1270 case FC_WEIGHT_BLACK:
1271 case FC_WEIGHT_SEMIBOLD:
1272 case FC_WEIGHT_BOLD:
1273 entry->weight = cstrdup("bold");
1274 entry->fixed_style |= BC_FONT_BOLD;
1277 case FC_WEIGHT_EXTRABOLD:
1278 case FC_WEIGHT_EXTRABLACK:
1280 entry->weight = cstrdup("bold");
1281 entry->fixed_style |= BC_FONT_BOLD;
1286 if(fcPatternGetString(font, FC_FAMILY, 0, &family) == FcResultMatch)
1287 entry->family = cstrdup((char*)family);
1289 if(fcPatternGetInteger(font, FC_SLANT, 0, &slant) == FcResultMatch) {
1291 case FC_SLANT_ROMAN:
1293 entry->slant = cstrdup("r");
1294 entry->style |= FL_SLANT_ROMAN;
1296 case FC_SLANT_ITALIC:
1297 entry->slant = cstrdup("i");
1298 entry->style |= FL_SLANT_ITALIC;
1299 entry->fixed_style |= BC_FONT_ITALIC;
1301 case FC_SLANT_OBLIQUE:
1302 entry->slant = cstrdup("o");
1303 entry->style |= FL_SLANT_OBLIQUE;
1304 entry->fixed_style |= BC_FONT_ITALIC;
1309 if(fcPatternGetInteger(font, FC_WIDTH, 0, &width) == FcResultMatch) {
1311 case FC_WIDTH_ULTRACONDENSED:
1312 entry->swidth = cstrdup("ultracondensed");
1315 case FC_WIDTH_EXTRACONDENSED:
1316 entry->swidth = cstrdup("extracondensed");
1319 case FC_WIDTH_CONDENSED:
1320 entry->swidth = cstrdup("condensed");
1322 case FC_WIDTH_SEMICONDENSED:
1323 entry->swidth = cstrdup("semicondensed");
1326 case FC_WIDTH_NORMAL:
1328 entry->swidth = cstrdup("normal");
1331 case FC_WIDTH_SEMIEXPANDED:
1332 entry->swidth = cstrdup("semiexpanded");
1335 case FC_WIDTH_EXPANDED:
1336 entry->swidth = cstrdup("expanded");
1339 case FC_WIDTH_EXTRAEXPANDED:
1340 entry->swidth = cstrdup("extraexpanded");
1343 case FC_WIDTH_ULTRAEXPANDED:
1344 entry->swidth = cstrdup("ultraexpanded");
1349 if(fcPatternGetInteger(font, FC_SPACING, 0, &spacing) == FcResultMatch) {
1353 entry->spacing = cstrdup("p");
1357 entry->spacing = cstrdup("d");
1361 entry->spacing = cstrdup("m");
1365 entry->spacing = cstrdup("c");
1370 // Add fake stuff for compatibility
1371 entry->adstyle = cstrdup(" ");
1372 entry->pixelsize = 0;
1373 entry->pointsize = 0;
1376 entry->avg_width = 0;
1377 entry->registry = cstrdup("utf");
1378 entry->encoding = cstrdup("8");
1380 if( fcPatternGetString(font, FC_STYLE, 0, &style) != FcResultMatch )
1383 // If font has a style unmanaged by titler plugin, force style to be displayed on name
1384 // in this way we can shown all available fonts styles.
1386 sprintf(tmpstring, "%s (%s)", entry->family, style);
1387 entry->displayname = cstrdup(tmpstring);
1390 if(strcmp(entry->foundry, "unknown")) {
1391 sprintf(tmpstring, "%s (%s)", entry->family, entry->foundry);
1392 entry->displayname = cstrdup(tmpstring);
1395 sprintf(tmpstring, "%s", entry->family);
1396 entry->displayname = cstrdup(tmpstring);
1400 fontlist->append(entry);
1402 dump_font_entry(stdout, "font 1: ", entry);
1405 fcFontSetDestroy(fs);
1406 if(freetype_library)
1407 ft_Done_FreeType(freetype_library);
1408 // for(int i = 0; i < fonts->total; i++)
1409 // fonts->values[i]->dump();
1411 fcConfigAppFontAddDir(0, (const FcChar8*)search_path);
1412 fcConfigSetRescanInterval(0, 0);
1414 os = fcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
1415 FC_WIDTH, FC_SLANT, FC_SPACING, FC_STYLE, (char *)0);
1416 pat = fcPatternCreate();
1417 fcPatternAddBool(pat, FC_SCALABLE, true);
1421 char langstr[LEN_LANG * 3];
1422 strcpy(langstr, language);
1426 strcat(langstr, "-");
1427 strcat(langstr, region);
1430 FcLangSet *ls = fcLangSetCreate();
1431 if(fcLangSetAdd(ls, (const FcChar8*)langstr))
1432 if(fcPatternAddLangSet(pat, FC_LANG, ls))
1433 fcLangSetDestroy(ls);
1436 fs = fcFontList(0, pat, os);
1437 fcPatternDestroy(pat);
1438 fcObjectSetDestroy(os);
1440 for(int i = 0; i < fs->nfont; i++)
1442 FcPattern *font = fs->fonts[i];
1443 BC_FontEntry *entry = new BC_FontEntry;
1446 if(fcPatternGetString(font, FC_FILE, 0, &strvalue) == FcResultMatch)
1448 entry->path = new char[strlen((char*)strvalue) + 1];
1449 strcpy(entry->path, (char*)strvalue);
1452 if(fcPatternGetString(font, FC_FOUNDRY, 0, &strvalue) == FcResultMatch)
1454 entry->foundry = new char[strlen((char*)strvalue) + 1];
1455 strcpy(entry->foundry, (char *)strvalue);
1458 if(fcPatternGetString(font, FC_FAMILY, 0, &strvalue) == FcResultMatch)
1460 entry->family = new char[strlen((char*)strvalue) + 2];
1461 strcpy(entry->family, (char*)strvalue);
1465 if(fcPatternGetInteger(font, FC_SLANT, 0, &intvalue) == FcResultMatch)
1469 case FC_SLANT_ROMAN:
1471 entry->style |= FL_SLANT_ROMAN;
1474 case FC_SLANT_ITALIC:
1475 entry->style |= FL_SLANT_ITALIC;
1478 case FC_SLANT_OBLIQUE:
1479 entry->style |= FL_SLANT_OBLIQUE;
1484 if(fcPatternGetInteger(font, FC_WEIGHT, 0, &intvalue) == FcResultMatch)
1488 case FC_WEIGHT_THIN:
1489 entry->style |= FL_WEIGHT_THIN;
1492 case FC_WEIGHT_EXTRALIGHT:
1493 entry->style |= FL_WEIGHT_EXTRALIGHT;
1496 case FC_WEIGHT_LIGHT:
1497 entry->style |= FL_WEIGHT_LIGHT;
1500 case FC_WEIGHT_BOOK:
1501 entry->style |= FL_WEIGHT_BOOK;
1504 case FC_WEIGHT_NORMAL:
1506 entry->style |= FL_WEIGHT_NORMAL;
1509 case FC_WEIGHT_MEDIUM:
1510 entry->style |= FL_WEIGHT_MEDIUM;
1513 case FC_WEIGHT_DEMIBOLD:
1514 entry->style |= FL_WEIGHT_DEMIBOLD;
1517 case FC_WEIGHT_BOLD:
1518 entry->style |= FL_WEIGHT_BOLD;
1521 case FC_WEIGHT_EXTRABOLD:
1522 entry->style |= FL_WEIGHT_EXTRABOLD;
1525 case FC_WEIGHT_BLACK:
1526 entry->style |= FL_WEIGHT_BLACK;
1529 case FC_WEIGHT_EXTRABLACK:
1530 entry->style |= FL_WEIGHT_EXTRABLACK;
1535 if(fcPatternGetInteger(font, FC_WIDTH, 0, &intvalue) == FcResultMatch)
1539 case FC_WIDTH_ULTRACONDENSED:
1540 entry->style |= FL_WIDTH_ULTRACONDENSED;
1543 case FC_WIDTH_EXTRACONDENSED:
1544 entry->style |= FL_WIDTH_EXTRACONDENSED;
1547 case FC_WIDTH_CONDENSED:
1548 entry->style |= FL_WIDTH_CONDENSED;
1551 case FC_WIDTH_SEMICONDENSED:
1552 entry->style = FL_WIDTH_SEMICONDENSED;
1555 case FC_WIDTH_NORMAL:
1557 entry->style |= FL_WIDTH_NORMAL;
1560 case FC_WIDTH_SEMIEXPANDED:
1561 entry->style |= FL_WIDTH_SEMIEXPANDED;
1564 case FC_WIDTH_EXPANDED:
1565 entry->style |= FL_WIDTH_EXPANDED;
1568 case FC_WIDTH_EXTRAEXPANDED:
1569 entry->style |= FL_WIDTH_EXTRAEXPANDED;
1572 case FC_WIDTH_ULTRAEXPANDED:
1573 entry->style |= FL_WIDTH_ULTRAEXPANDED;
1577 if(fcPatternGetInteger(font, FC_SPACING, 0, &intvalue) == FcResultMatch)
1581 case FC_PROPORTIONAL:
1583 entry->style |= FL_PROPORTIONAL;
1587 entry->style |= FL_DUAL;
1591 entry->style |= FL_MONO;
1595 entry->style |= FL_CHARCELL;
1599 if(entry->foundry && strcmp(entry->foundry, "unknown"))
1601 char tempstr[BCTEXTLEN];
1602 sprintf(tempstr, "%s (%s)", entry->family, entry->foundry);
1603 entry->displayname = new char[strlen(tempstr) + 1];
1604 strcpy(entry->displayname, tempstr);
1608 entry->displayname = new char[strlen(entry->family) + 1];
1609 strcpy(entry->displayname, entry->family);
1611 fontlist->append(entry);
1613 dump_font_entry(stdout, "font 2: ", entry);
1615 fcFontSetDestroy(fs);
1619 #define STYLE_MATCH(fst, stl, msk) ((fst) & (msk) & (stl)) && \
1620 !((fst) & ~(style) & (msk))
1622 BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style,
1623 int mask, int preferred)
1625 BC_FontEntry *entry, *style_match, *preferred_match;
1631 preferred_match = 0;
1635 for(int i = 0; i < fontlist->total; i++)
1637 entry = fontlist->values[i];
1639 if(strcmp(entry->displayname, displayname) == 0 &&
1640 STYLE_MATCH(entry->style, style, mask))
1643 style_match = entry;
1644 if(!preferred_match && entry->fixed_style == preferred)
1645 preferred_match = entry;
1649 return preferred_match;
1655 // No exact match - assume normal width font
1656 style |= FL_WIDTH_NORMAL;
1657 mask |= FL_WIDTH_MASK;
1659 preferred_match = 0;
1661 for(int i = 0; i < fontlist->total; i++)
1663 entry = fontlist->values[i];
1665 if(STYLE_MATCH(entry->style, style, mask))
1668 style_match = entry;
1670 if(!preferred_match && (entry->style & preferred))
1671 preferred_match = entry;
1673 if(!strncasecmp(displayname, entry->family,
1674 strlen(entry->family)))
1680 return preferred_match;
1687 uint8_t *obfr, *out, *oend;
1688 uint8_t *ibfr, *inp, *iend;
1690 utf8conv(void *out, int olen, void *inp, int ilen) {
1691 this->obfr = this->out = (uint8_t*)out;
1692 this->oend = this->out + olen;
1693 this->ibfr = this->inp = (uint8_t*)inp;
1694 this->iend = this->inp + ilen;
1696 int cur() { return inp>=iend ? -1 : *inp; }
1697 int next() { return inp>=iend ? -1 : *inp++; }
1698 int next(int ch) { return out>=oend ? -1 : *out++ = ch; }
1699 int ilen() { return inp-ibfr; }
1700 int olen() { return out-obfr; }
1702 int wnext(unsigned int v);
1706 wnext(unsigned int v)
1708 if( v < 0x00000080 ) { next(v); return 1; }
1709 int n = v < 0x00000800 ? 2 : v < 0x00010000 ? 3 :
1710 v < 0x00200000 ? 4 : v < 0x04000000 ? 5 : 6;
1711 int m = (0xff00 >> n), i = n-1;
1712 next((v>>(6*i)) | m);
1713 while( --i >= 0 ) next(((v>>(6*i)) & 0x3f) | 0x80);
1720 int v = 0, n = 0, ch = next();
1722 switch( (ch=next()) ) {
1723 case 'n': return '\n';
1724 case 't': return '\t';
1725 case 'r': return '\r';
1726 case 'b': return '\b';
1727 case 'f': return '\f';
1728 case 'v': return '\v';
1729 case 'a': return '\a';
1730 case '0': case '1': case '2': case '3':
1731 case '4': case '5': case '6': case '7':
1733 for( int i=3; --i>0; v=v*8+ch, next() )
1734 if( (ch=cur()-'0') < 0 || ch >= 8 ) break;
1736 case 'x': n = 2; break;
1737 case 'u': n = 4; break;
1738 case 'U': n = 8; break;
1741 for( int i=n; --i>=0; v=v*16+ch, next() ) {
1742 if( (ch=cur()-'0')>=0 && ch<10 ) continue;
1743 if( (ch-='A'-'0'-10)>=10 && ch<16 ) continue;
1744 if( (ch-='a'-'A')<10 || ch>=16 ) break;
1747 else if( ch >= 0x80 ) {
1748 static const unsigned char byts[] = {
1749 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 5,
1752 n = i<0 ? 0 : byts[i/4];
1753 for( v=ch, i=n; --i>=0; v+=next() ) v <<= 6;
1754 static const unsigned int ofs[6] = {
1755 0x00000000U, 0x00003080U, 0x000E2080U,
1756 0x03C82080U, 0xFA082080U, 0x82082080U
1766 size_t BC_Resources::encode(const char *from_enc, const char *to_enc,
1767 char *input, int input_length, char *output, int output_length)
1769 if( !from_enc || *from_enc == 0 ||
1770 !strcmp(from_enc,"UTF8") || !strcmp(from_enc, "US-ASCII") )
1773 if( !to_enc || *to_enc == 0 ||
1774 !strcmp(to_enc,"UTF8") || !strcmp(to_enc, "US-ASCII") )
1778 char *outbase = output;
1779 size_t inbytes = input_length < 0 ? strlen(input) : input_length;
1780 size_t outbytes = output_length;
1782 if( inbytes && outbytes ) {
1783 if( !strcmp(from_enc, to_enc) ) {
1784 if( inbytes > outbytes ) inbytes = outbytes;
1785 memcpy(output, input, inbytes);
1787 outbytes -= inbytes;
1789 else if( !strcmp(from_enc, "UTF-8") && !strcmp(to_enc,"UTF32LE") ) {
1790 utf8conv uc(0,0, input,inbytes);
1791 uint32_t *op = (uint32_t *)output;
1792 uint32_t *ep = (uint32_t *)(output+output_length);
1793 for( int wch; op<ep && (wch=uc.wnext())>=0; *op++=wch );
1794 output = (char *)op;
1795 outbytes = (char*)ep - output;
1797 else if( !strcmp(from_enc, "UTF32LE") && !strcmp(to_enc,"UTF-8") ) {
1798 utf8conv uc(output,output_length, 0,0);
1799 uint32_t *ip = (uint32_t *)input;
1800 uint32_t *ep = (uint32_t *)(input+inbytes);
1801 for( ; ip<ep && uc.wnext(*ip)>=0; ++ip );
1802 output += uc.olen();
1803 outbytes -= uc.olen();
1805 else if( (cd = iconv_open(to_enc, from_enc)) != (iconv_t)-1 ) {
1806 iconv(cd, &input, &inbytes, &output, &outbytes);
1810 printf(_("Conversion from %s to %s is not available\n"),
1814 if( outbytes > sizeof(uint32_t) )
1815 outbytes = sizeof(uint32_t);
1816 for( uint32_t i = 0; i < outbytes; i++)
1818 return output - outbase;
1821 void BC_Resources::encode_to_utf8(char *buffer, int buflen)
1823 if(BC_Resources::locale_utf8) return;
1825 encode(encoding, 0, buffer, buflen, lbuf, buflen);
1826 strcpy(buffer, lbuf);
1829 int BC_Resources::find_font_by_char(FT_ULong char_code, char *path_new, const FT_Face oldface)
1831 FcPattern *font, *ofont;
1837 // Do not search control codes
1841 if( (ofont = fcFreeTypeQueryFace(oldface, (const FcChar8*)"", 4097, 0)) != 0 ) {
1842 if( (font = find_similar_font(char_code, ofont)) != 0 ) {
1843 if(fcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
1844 strcpy(path_new, (char*)file);
1847 fcPatternDestroy(font);
1849 fcPatternDestroy(ofont);
1854 FcPattern* BC_Resources::find_similar_font(FT_ULong char_code, FcPattern *oldfont)
1856 FcPattern *pat, *font;
1862 // Do not search control codes
1866 fontconfig_lock.lock("BC_Resources::find_similar_font");
1867 pat = fcPatternCreate();
1868 os = fcObjectSetBuild(FC_FILE, FC_CHARSET, FC_SCALABLE, FC_FAMILY,
1869 FC_SLANT, FC_WEIGHT, FC_WIDTH, (char *)0);
1871 fcPatternAddBool(pat, FC_SCALABLE, true);
1872 fcs = fcCharSetCreate();
1873 if(fcCharSetAddChar(fcs, char_code))
1874 fcPatternAddCharSet(pat, FC_CHARSET, fcs);
1875 fcCharSetDestroy(fcs);
1876 for( int i=0; i<(int)LEN_FCPROP; ++i ) {
1877 if(fcPatternGetInteger(oldfont, fc_properties[i], 0, &ival) == FcResultMatch)
1878 fcPatternAddInteger(pat, fc_properties[i], ival);
1880 fs = fcFontList(0, pat, os);
1881 for( int i=LEN_FCPROP; --i>=0 && !fs->nfont; ) {
1882 fcFontSetDestroy(fs);
1883 fcPatternDel(pat, fc_properties[i]);
1884 fs = fcFontList(0, pat, os);
1886 fcPatternDestroy(pat);
1887 fcObjectSetDestroy(os);
1891 for (int i = 0; i < fs->nfont; i++)
1893 font = fs->fonts[i];
1894 if(fcPatternGetCharSet(font, FC_CHARSET, 0, &fcs) == FcResultMatch)
1896 if(fcCharSetHasChar(fcs, char_code))
1898 pat = fcPatternDuplicate(font);
1903 fcFontSetDestroy(fs);
1904 fontconfig_lock.unlock();
1909 void BC_Resources::dump_fonts(FILE *fp)
1911 for( int i=0; i<fontlist->total; ++i )
1912 dump_font_entry(fp, "", fontlist->values[i]);
1915 void BC_Resources::dump_font_entry(FILE *fp, const char *cp, BC_FontEntry *ep)
1917 fprintf(fp,"%s%s = %s\n",cp,ep->displayname,ep->path);
1918 fprintf(fp," %s:%s:%s:%s:%s:%s:%d:%d:%d:%d:%d:%s:%d:%s:%s:%d\n",
1919 ep->foundry, ep->family, ep->weight, ep->slant, ep->swidth, ep->adstyle,
1920 ep->pixelsize, ep->pointsize, ep->xres, ep->yres, ep->style, ep->spacing,
1921 ep->avg_width, ep->registry, ep->encoding, ep->fixed_style);