add resource wdw folder expanders, fix plugin close deadlock detect
[goodguy/history.git] / cinelerra-5.1 / guicast / bcresources.C
index e3769675d030ed9eb8f7b113de99c73f2f6d9e9f..5746e6c20ff895fad571e8fc994a408e4bd5ff21 100644 (file)
 #include "bcsignals.h"
 #include "bcsynchronous.h"
 #include "bcwindowbase.h"
-#include "colors.h"
+#include "bccolors.h"
 #include "bccmodels.h"
 #include "cstrdup.h"
 #include "fonts.h"
 #include "language.h"
 #include "vframe.h"
+#include "workarounds.h"
 
 #include <string.h>
 #include <iconv.h>
@@ -59,6 +60,7 @@ char BC_Resources::region[LEN_LANG] = {0};
 char BC_Resources::encoding[LEN_ENCOD] = {0};
 const char *BC_Resources::wide_encoding = 0;
 ArrayList<BC_FontEntry*> *BC_Resources::fontlist = 0;
+int BC_Resources::font_debug = 0;
 const char *BC_Resources::fc_properties[] = { FC_SLANT, FC_WEIGHT, FC_WIDTH };
 #define LEN_FCPROP (sizeof(BC_Resources::fc_properties) / sizeof(const char*))
 
@@ -72,10 +74,14 @@ static const char *def_big_font =
   "-*-bitstream charter-bold-r-normal-*-*-0-%d-%d-p-0-iso8859-1"; // 160
 static const char *def_big_font2 =
   "-*-nimbus sans l-bold-r-normal-*-*-0-%d-%d-p-0-iso8859-1";     // 160
+static const char *def_clock_font = "-*-helvetica-bold-r-normal-*-%d-*";      // 16
+static const char *def_clock_font2 = "-*-helvetica-bold-r-normal-*-%d-*";     // 18
 static const char *def_small_fontset =  "-*-helvetica-medium-r-normal-*-%d-*";// 10
 static const char *def_medium_fontset = "-*-helvetica-bold-r-normal-*-%d-*";  // 14
 static const char *def_large_fontset =  "-*-helvetica-bold-r-normal-*-%d-*";  // 18
 static const char *def_big_fontset =    "-*-helvetica-bold-r-normal-*-%d-*";  // 24
+static const char *def_clock_fontset = "-*-helvetica-bold-r-normal-*-%d-*";   // 16
+
 static const char *def_small_font_xft = "Sans:pixelsize=%.4f";           // 10.6667
 static const char *def_small_b_font_xft = "Sans:bold:pixelsize=%.4f";    // 10.6667
 static const char *def_medium_font_xft = "Sans:pixelsize=%.4f";          // 13.3333
@@ -84,6 +90,7 @@ static const char *def_large_font_xft = "Sans:pixelsize=%.4f";           // 21.3
 static const char *def_large_b_font_xft = "Sans:bold:pixelsize=%.4f";    // 21.3333
 static const char *def_big_font_xft = "Sans:pixelsize=37.3333";          // 37.3333
 static const char *def_big_b_font_xft = "Sans:bold:pixelsize=37.33333";  // 37.3333
+static const char *def_clock_font_xft = "Sans:pixelsize=%.4f";           // 16
 
 #define default_font_xft2 "-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*"
 
@@ -95,10 +102,13 @@ const char* BC_Resources::large_font = 0;
 const char* BC_Resources::large_font2 = 0;
 const char* BC_Resources::big_font = 0;
 const char* BC_Resources::big_font2 = 0;
+const char* BC_Resources::clock_font = 0;
+const char* BC_Resources::clock_font2 = 0;
 const char* BC_Resources::small_fontset = 0;
 const char* BC_Resources::medium_fontset = 0;
 const char* BC_Resources::large_fontset = 0;
 const char* BC_Resources::big_fontset = 0;
+const char* BC_Resources::clock_fontset = 0;
 const char* BC_Resources::small_font_xft = 0;
 const char* BC_Resources::small_font_xft2 = 0;
 const char* BC_Resources::small_b_font_xft = 0;
@@ -111,6 +121,8 @@ const char* BC_Resources::large_b_font_xft = 0;
 const char* BC_Resources::big_font_xft = 0;
 const char* BC_Resources::big_font_xft2 = 0;
 const char* BC_Resources::big_b_font_xft = 0;
+const char* BC_Resources::clock_font_xft = 0;
+const char* BC_Resources::clock_font_xft2 = 0;
 
 #define def_font(v, s...) do { sprintf(string,def_##v,s); v = cstrdup(string); } while(0)
 #define set_font(v, s) do { sprintf(string, "%s", s); v = cstrdup(string); } while(0)
@@ -125,11 +137,14 @@ void BC_Resources::init_font_defs(double scale)
        def_font(large_font,       iround(scale*18));
        def_font(large_font2,      iround(scale*20));
        def_font(big_font,         iround(scale*160), iround(scale*160));
-       def_font(big_font2,        iround(scale*160), iround(scale*160));
+       def_font(big_font2,        iround(scale*16), iround(scale*16));
+       def_font(clock_font,       iround(scale*16));
+       def_font(clock_font2,      iround(scale*18));
        def_font(small_fontset,    iround(scale*10));
        def_font(medium_fontset,   iround(scale*14));
        def_font(large_fontset,    iround(scale*18));
        def_font(big_fontset,      iround(scale*24));
+       def_font(clock_fontset,    iround(scale*16));
        def_font(small_font_xft,   (scale*10.6667));
        def_font(small_b_font_xft, (scale*10.6667));
        def_font(medium_font_xft,  (scale*13.3333));
@@ -138,11 +153,13 @@ void BC_Resources::init_font_defs(double scale)
        def_font(large_b_font_xft, (scale*21.3333));
        def_font(big_font_xft,     (scale*37.3333));
        def_font(big_b_font_xft,   (scale*37.3333));
+       def_font(clock_font_xft,   (scale*16.));
 
        set_font(small_font_xft2,  default_font_xft2);
        set_font(medium_font_xft2, default_font_xft2);
        set_font(large_font_xft2,  default_font_xft2);
        set_font(big_font_xft2,    default_font_xft2);
+       set_font(clock_font_xft2,  default_font_xft2);
 }
 void BC_Resources::finit_font_defs()
 {
@@ -154,10 +171,13 @@ void BC_Resources::finit_font_defs()
        delete [] large_font2;
        delete [] big_font;
        delete [] big_font2;
+       delete [] clock_font;
+       delete [] clock_font2;
        delete [] small_fontset;
        delete [] medium_fontset;
        delete [] large_fontset;
        delete [] big_fontset;
+       delete [] clock_fontset;
        delete [] small_font_xft;
        delete [] small_b_font_xft;
        delete [] medium_font_xft;
@@ -166,26 +186,90 @@ void BC_Resources::finit_font_defs()
        delete [] large_b_font_xft;
        delete [] big_font_xft;
        delete [] big_b_font_xft;
+       delete [] clock_font_xft;
 
        delete [] small_font_xft2;
        delete [] medium_font_xft2;
        delete [] large_font_xft2;
        delete [] big_font_xft2;
+       delete [] clock_font_xft2;
 }
 
+
 suffix_to_type_t BC_Resources::suffix_to_type[] =
 {
-       { "m2v", ICON_FILM },
-       { "mov", ICON_FILM },
-       { "mp2", ICON_SOUND },
-       { "mp3", ICON_SOUND },
-       { "ac3", ICON_SOUND },
-       { "mpg", ICON_FILM },
-       { "vob", ICON_FILM },
-       { "ifo", ICON_FILM },
-       { "ts",  ICON_FILM },
-       { "vts", ICON_FILM },
-       { "wav", ICON_SOUND }
+    { "aac", ICON_SOUND },
+    { "ac3", ICON_SOUND },
+    { "dts", ICON_SOUND },
+    { "f4a", ICON_SOUND },
+    { "flac", ICON_SOUND },
+    { "m4a", ICON_SOUND },
+    { "mp2", ICON_SOUND },
+    { "mp3", ICON_SOUND },
+    { "mpc", ICON_SOUND },
+    { "oga", ICON_SOUND },
+    { "ogg", ICON_SOUND },
+    { "opus", ICON_SOUND },
+    { "ra", ICON_SOUND },
+    { "tta", ICON_SOUND },
+    { "vox", ICON_SOUND },
+    { "wav", ICON_SOUND },
+    { "wma", ICON_SOUND },
+    { "3gp", ICON_FILM },
+    { "avi", ICON_FILM },
+    { "bmp", ICON_FILM },
+    { "cr2", ICON_FILM },
+    { "dnxhd", ICON_FILM },
+    { "drc", ICON_FILM },
+    { "dv", ICON_FILM },
+    { "dvd", ICON_FILM },
+    { "exr", ICON_FILM },
+    { "f4v", ICON_FILM },
+    { "flv", ICON_FILM },
+    { "gif", ICON_FILM },
+    { "gxf", ICON_FILM },
+    { "h263", ICON_FILM },
+    { "h264", ICON_FILM },
+    { "h265", ICON_FILM },
+    { "hevc", ICON_FILM },
+    { "ifo", ICON_FILM },
+    { "jpeg", ICON_FILM },
+    { "jpg", ICON_FILM },
+    { "m2t", ICON_FILM },
+    { "m2ts", ICON_FILM },
+    { "m2v", ICON_FILM },
+    { "m4p", ICON_FILM },
+    { "m4v", ICON_FILM },
+    { "mkv", ICON_FILM },
+    { "mov", ICON_FILM },
+    { "mp4", ICON_FILM },
+    { "mpe", ICON_FILM },
+    { "mpeg", ICON_FILM },
+    { "mpg", ICON_FILM },
+    { "mpv", ICON_FILM },
+    { "mts", ICON_FILM },
+    { "mxf", ICON_FILM },
+    { "ogv", ICON_FILM },
+    { "pcm", ICON_FILM },
+    { "pgm", ICON_FILM },
+    { "png", ICON_FILM },
+    { "ppm", ICON_FILM },
+    { "qt", ICON_FILM },
+    { "rm", ICON_FILM },
+    { "rmvb", ICON_FILM },
+    { "rv", ICON_FILM },
+    { "swf", ICON_FILM },
+    { "tif", ICON_FILM },
+    { "tiff", ICON_FILM },
+    { "ts",  ICON_FILM },
+    { "vob", ICON_FILM },
+    { "vts", ICON_FILM },
+    { "webm", ICON_FILM },
+    { "webp", ICON_FILM },
+    { "wmv", ICON_FILM },
+    { "xml", ICON_FILM },
+    { "y4m", ICON_FILM },
+    { 0, 0 },
 };
 
 BC_Signals* BC_Resources::signal_handler = 0;
@@ -264,6 +348,7 @@ VFrame *BC_Resources::default_filebox_newfolder_images[3] = { 0, };
 VFrame *BC_Resources::default_filebox_rename_images[3] = { 0, };
 VFrame *BC_Resources::default_filebox_delete_images[3] = { 0, };
 VFrame *BC_Resources::default_filebox_reload_images[3] = { 0, };
+VFrame *BC_Resources::default_filebox_szfmt_images[12] = { 0, };
 VFrame *BC_Resources::default_listbox_button[4] = { 0, };
 VFrame *BC_Resources::default_listbox_bg = 0;
 VFrame *BC_Resources::default_listbox_expand[5] = { 0, };
@@ -273,13 +358,17 @@ VFrame *BC_Resources::default_listbox_dn = 0;
 VFrame *BC_Resources::default_pot_images[3] = { 0, };
 VFrame *BC_Resources::default_progress_images[2] = { 0, };
 VFrame *BC_Resources::default_medium_7segment[20] = { 0, };
+VFrame *BC_Resources::default_vscroll_data[10] = { 0, };
+VFrame *BC_Resources::default_hscroll_data[10] = { 0, };
 
 BC_Resources::BC_Resources()
 {
        synchronous = 0;
        vframe_shm = 0;
        double default_scale = 1.0; // display_size/1000.;
-       char *env = getenv("BC_FONT_SCALE");
+       char *env = getenv("BC_FONT_DEBUG");
+       font_debug = env ? atoi(env) : 0;
+       env = getenv("BC_FONT_SCALE");
        font_scale = env ? atof(env) : default_scale;
        if( font_scale <= 0 ) font_scale = 1;
        init_font_defs(font_scale);
@@ -296,7 +385,8 @@ BC_Resources::BC_Resources()
                filebox_history[i].path[0] = 0;
 
 #ifdef HAVE_XFT
-       XftInitFtLibrary();
+       xftInit(0);
+       xftInitFtLibrary();
 #endif
 
        little_endian = (*(const u_int32_t*)"\01\0\0\0") & 1;
@@ -405,59 +495,85 @@ new_vframes(3,default_menubar_data,
 #include "images/file_text_up_png.h"
 #include "images/file_text_hi_png.h"
 #include "images/file_text_dn_png.h"
-#include "images/file_icons_up_png.h"
-#include "images/file_icons_hi_png.h"
-#include "images/file_icons_dn_png.h"
-#include "images/file_newfolder_up_png.h"
-#include "images/file_newfolder_hi_png.h"
-#include "images/file_newfolder_dn_png.h"
-#include "images/file_rename_up_png.h"
-#include "images/file_rename_hi_png.h"
-#include "images/file_rename_dn_png.h"
-#include "images/file_updir_up_png.h"
-#include "images/file_updir_hi_png.h"
-#include "images/file_updir_dn_png.h"
-#include "images/file_delete_up_png.h"
-#include "images/file_delete_hi_png.h"
-#include "images/file_delete_dn_png.h"
-#include "images/file_reload_up_png.h"
-#include "images/file_reload_hi_png.h"
-#include "images/file_reload_dn_png.h"
 new_vframes(3,default_filebox_text_images,
        new VFramePng(file_text_up_png),
        new VFramePng(file_text_hi_png),
        new VFramePng(file_text_dn_png));
 
+#include "images/file_icons_up_png.h"
+#include "images/file_icons_hi_png.h"
+#include "images/file_icons_dn_png.h"
 new_vframes(3,default_filebox_icons_images,
        new VFramePng(file_icons_up_png),
        new VFramePng(file_icons_hi_png),
        new VFramePng(file_icons_dn_png));
 
+#include "images/file_updir_up_png.h"
+#include "images/file_updir_hi_png.h"
+#include "images/file_updir_dn_png.h"
 new_vframes(3,default_filebox_updir_images,
        new VFramePng(file_updir_up_png),
        new VFramePng(file_updir_hi_png),
        new VFramePng(file_updir_dn_png));
 
+#include "images/file_newfolder_up_png.h"
+#include "images/file_newfolder_hi_png.h"
+#include "images/file_newfolder_dn_png.h"
 new_vframes(3,default_filebox_newfolder_images,
        new VFramePng(file_newfolder_up_png),
        new VFramePng(file_newfolder_hi_png),
        new VFramePng(file_newfolder_dn_png));
 
+#include "images/file_rename_up_png.h"
+#include "images/file_rename_hi_png.h"
+#include "images/file_rename_dn_png.h"
 new_vframes(3,default_filebox_rename_images,
        new VFramePng(file_rename_up_png),
        new VFramePng(file_rename_hi_png),
        new VFramePng(file_rename_dn_png));
 
+#include "images/file_delete_up_png.h"
+#include "images/file_delete_hi_png.h"
+#include "images/file_delete_dn_png.h"
 new_vframes(3,default_filebox_delete_images,
        new VFramePng(file_delete_up_png),
        new VFramePng(file_delete_hi_png),
        new VFramePng(file_delete_dn_png));
 
+#include "images/file_reload_up_png.h"
+#include "images/file_reload_hi_png.h"
+#include "images/file_reload_dn_png.h"
 new_vframes(3,default_filebox_reload_images,
        new VFramePng(file_reload_up_png),
        new VFramePng(file_reload_hi_png),
        new VFramePng(file_reload_dn_png));
 
+#include "images/file_size_capb_up_png.h"
+#include "images/file_size_capb_hi_png.h"
+#include "images/file_size_capb_dn_png.h"
+#include "images/file_size_lwrb_up_png.h"
+#include "images/file_size_lwrb_hi_png.h"
+#include "images/file_size_lwrb_dn_png.h"
+#include "images/file_size_semi_up_png.h"
+#include "images/file_size_semi_hi_png.h"
+#include "images/file_size_semi_dn_png.h"
+#include "images/file_size_zero_up_png.h"
+#include "images/file_size_zero_hi_png.h"
+#include "images/file_size_zero_dn_png.h"
+new_vframes(12,default_filebox_szfmt_images,
+       new VFramePng(file_size_zero_up_png),
+       new VFramePng(file_size_zero_hi_png),
+       new VFramePng(file_size_zero_dn_png),
+       new VFramePng(file_size_lwrb_up_png),
+       new VFramePng(file_size_lwrb_hi_png),
+       new VFramePng(file_size_lwrb_dn_png),
+       new VFramePng(file_size_capb_up_png),
+       new VFramePng(file_size_capb_hi_png),
+       new VFramePng(file_size_capb_dn_png),
+       new VFramePng(file_size_semi_up_png),
+       new VFramePng(file_size_semi_hi_png),
+       new VFramePng(file_size_semi_dn_png));
+
 #include "images/listbox_button_dn_png.h"
 #include "images/listbox_button_hi_png.h"
 #include "images/listbox_button_up_png.h"
@@ -552,6 +668,50 @@ new_vframes(20,default_medium_7segment,
        new VFramePng(space_png),
        new VFramePng(dash_png));
 
+#include "images/hscroll_handle_up_png.h"
+#include "images/hscroll_handle_hi_png.h"
+#include "images/hscroll_handle_dn_png.h"
+#include "images/hscroll_handle_bg_png.h"
+#include "images/hscroll_left_up_png.h"
+#include "images/hscroll_left_hi_png.h"
+#include "images/hscroll_left_dn_png.h"
+#include "images/hscroll_right_up_png.h"
+#include "images/hscroll_right_hi_png.h"
+#include "images/hscroll_right_dn_png.h"
+new_vframes(10,default_hscroll_data,
+       new VFramePng(hscroll_handle_up_png),
+       new VFramePng(hscroll_handle_hi_png),
+       new VFramePng(hscroll_handle_dn_png),
+       new VFramePng(hscroll_handle_bg_png),
+       new VFramePng(hscroll_left_up_png),
+       new VFramePng(hscroll_left_hi_png),
+       new VFramePng(hscroll_left_dn_png),
+       new VFramePng(hscroll_right_up_png),
+       new VFramePng(hscroll_right_hi_png),
+       new VFramePng(hscroll_right_dn_png));
+
+#include "images/vscroll_handle_up_png.h"
+#include "images/vscroll_handle_hi_png.h"
+#include "images/vscroll_handle_dn_png.h"
+#include "images/vscroll_handle_bg_png.h"
+#include "images/vscroll_left_up_png.h"
+#include "images/vscroll_left_hi_png.h"
+#include "images/vscroll_left_dn_png.h"
+#include "images/vscroll_right_up_png.h"
+#include "images/vscroll_right_hi_png.h"
+#include "images/vscroll_right_dn_png.h"
+new_vframes(10,default_vscroll_data,
+       new VFramePng(vscroll_handle_up_png),
+       new VFramePng(vscroll_handle_hi_png),
+       new VFramePng(vscroll_handle_dn_png),
+       new VFramePng(vscroll_handle_bg_png),
+       new VFramePng(vscroll_left_up_png),
+       new VFramePng(vscroll_left_hi_png),
+       new VFramePng(vscroll_left_dn_png),
+       new VFramePng(vscroll_right_up_png),
+       new VFramePng(vscroll_right_hi_png),
+       new VFramePng(vscroll_right_dn_png));
+
        type_to_icon = default_type_to_icon;
        bar_data = default_bar;
        check = default_check_image;
@@ -561,6 +721,9 @@ new_vframes(20,default_medium_7segment,
        listbox_column = default_listbox_column;
        listbox_up = default_listbox_up;
        listbox_dn = default_listbox_dn;
+       hscroll_data = default_hscroll_data;
+       vscroll_data = default_vscroll_data;
+
        listbox_title_overlap = 0;
        listbox_title_margin = 0;
        listbox_title_color = BLACK;
@@ -647,6 +810,7 @@ new_vframes(20,default_medium_7segment,
        text_default = BLACK;
        highlight_inverse = WHITE ^ BLUE;
        text_background = WHITE;
+       text_background_disarmed = 0xc08080;
        text_background_hi = LTYELLOW;
        text_background_noborder_hi = LTGREY;
        text_background_noborder = -1;
@@ -698,6 +862,8 @@ new_vframes(20,default_medium_7segment,
        filebox_rename_images = default_filebox_rename_images;
        filebox_delete_images = default_filebox_delete_images;
        filebox_reload_images = default_filebox_reload_images;
+       filebox_szfmt_images = default_filebox_szfmt_images;
+       filebox_size_format = FILEBOX_SIZE_RAW;
        directory_color = BLUE;
        file_color = BLACK;
 
@@ -774,6 +940,7 @@ BC_Resources::~BC_Resources()
        del_vframes(default_filebox_rename_images, 3);
        del_vframes(default_filebox_delete_images, 3);
        del_vframes(default_filebox_reload_images, 3);
+       del_vframes(default_filebox_szfmt_images, 12);
        del_vframes(default_listbox_button, 4);
        delete default_listbox_bg;
        del_vframes(default_listbox_expand, 5);
@@ -901,17 +1068,23 @@ int BC_Resources::init_fontconfig(const char *search_path)
 
        char find_command[BCTEXTLEN];
        char *fp = find_command, *ep = fp+sizeof(find_command)-1;
-       fp += snprintf(fp, ep-fp, "find '%s'", search_path);
+       fp += snprintf(fp, ep-fp, "%s", "find");
        const char *bc_font_path = getenv("BC_FONT_PATH");
+// if BC_FONT_PATH starts with ':', omit default path
+       if( !(bc_font_path && bc_font_path[0] == ':') )
+               fp += snprintf(fp, ep-fp, " '%s'", search_path);
        if( bc_font_path ) {
                const char *path = bc_font_path;
-               for( int len=0; *path; path+=len ) {
-                       const char *cp = strchr(path,':');
-                       len = !cp ? strlen(path) : cp-path;
+               while( *path ) {
                        char font_path[BCTEXTLEN];
-                       memcpy(font_path, path, len);  font_path[len] = 0;
-                       if( cp ) ++len;
-                       fp += snprintf(fp, ep-fp, " '%s'", font_path);
+                       const char *cp = strchr(path,':');
+                       int len = !cp ? strlen(path) : cp-path;
+                       if( len > 0 ) {
+                               memcpy(font_path, path, len);
+                               font_path[len] = 0;  path += len;
+                               fp += snprintf(fp, ep-fp, " '%s'", font_path);
+                       }
+                       if( cp ) ++path;
                }
         }
        fp += snprintf(fp, ep-fp, " -name 'fonts.scale' -print -exec cat {} \\;");
@@ -919,7 +1092,7 @@ int BC_Resources::init_fontconfig(const char *search_path)
 
        FT_Library freetype_library = 0;
 //     FT_Face freetype_face = 0;
-//     FT_Init_FreeType(&freetype_library);
+//     ft_Init_FreeType(&freetype_library);
 
        char line[BCTEXTLEN], current_dir[BCTEXTLEN];
        current_dir[0] = 0;
@@ -1058,11 +1231,16 @@ int BC_Resources::init_fontconfig(const char *search_path)
                        entry->style |= FL_WIDTH_NORMAL;
 
                fontlist->append(entry);
+               if( font_debug )
+                       dump_font_entry(stdout, "font 0: ", entry);
+
 //             printf("TitleMain::build_fonts %s: success\n",  entry->path);
 //printf("TitleMain::build_fonts 2\n");
        }
        pclose(in);
 
+       if( bc_font_path && bc_font_path[0] == ':' )
+               return 0;
 
 // Load all the fonts from fontconfig
        FcPattern *pat;
@@ -1076,15 +1254,15 @@ int BC_Resources::init_fontconfig(const char *search_path)
        FcConfig *config;
        int i;
        char tmpstring[BCTEXTLEN];
-       if(!FcInit())
+       if(!fcInit())
                return 1;
-       config = FcConfigGetCurrent();
-       FcConfigSetRescanInterval(config, 0);
+       config = fcConfigGetCurrent();
+       fcConfigSetRescanInterval(config, 0);
 
-       pat = FcPatternCreate();
-       os = FcObjectSetBuild ( FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
+       pat = fcPatternCreate();
+       os = fcObjectSetBuild( FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
                FC_WIDTH, FC_SLANT, FC_FONTFORMAT, FC_SPACING, FC_STYLE, (char *) 0);
-       FcPatternAddBool(pat, FC_SCALABLE, true);
+       fcPatternAddBool(pat, FC_SCALABLE, true);
 
        if(language[0]) {
                char langstr[LEN_LANG * 3];
@@ -1095,35 +1273,35 @@ int BC_Resources::init_fontconfig(const char *search_path)
                        strcat(langstr, region);
                }
 
-               FcLangSet *ls =  FcLangSetCreate();
-               if(FcLangSetAdd(ls, (const FcChar8*)langstr))
-               if(FcPatternAddLangSet(pat, FC_LANG, ls))
-               FcLangSetDestroy(ls);
+               FcLangSet *ls =  fcLangSetCreate();
+               if(fcLangSetAdd(ls, (const FcChar8*)langstr))
+               if(fcPatternAddLangSet(pat, FC_LANG, ls))
+               fcLangSetDestroy(ls);
        }
 
-       fs = FcFontList(config, pat, os);
-       FcPatternDestroy(pat);
-       FcObjectSetDestroy(os);
+       fs = fcFontList(config, pat, os);
+       fcPatternDestroy(pat);
+       fcObjectSetDestroy(os);
 
        for (i = 0; fs && i < fs->nfont; i++) {
                FcPattern *font = fs->fonts[i];
                force_style = 0;
-               FcPatternGetString(font, FC_FONTFORMAT, 0, &format);
+               fcPatternGetString(font, FC_FONTFORMAT, 0, &format);
                //on this point you can limit font search
                if(limit_to_trutype && strcmp((char *)format, "TrueType"))
                        continue;
 
                sprintf(tmpstring, "%s", format);
                BC_FontEntry *entry = new BC_FontEntry;
-               if(FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
+               if(fcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
                        entry->path = cstrdup((char*)file);
                }
 
-               if(FcPatternGetString(font, FC_FOUNDRY, 0, &foundry) == FcResultMatch) {
+               if(fcPatternGetString(font, FC_FOUNDRY, 0, &foundry) == FcResultMatch) {
                        entry->foundry = cstrdup((char*)foundry);
                }
 
-               if(FcPatternGetInteger(font, FC_WEIGHT, 0, &weight) == FcResultMatch) {
+               if(fcPatternGetInteger(font, FC_WEIGHT, 0, &weight) == FcResultMatch) {
                        switch(weight) {
                        case FC_WEIGHT_THIN:
                        case FC_WEIGHT_EXTRALIGHT:
@@ -1155,10 +1333,10 @@ int BC_Resources::init_fontconfig(const char *search_path)
                        }
                }
 
-               if(FcPatternGetString(font, FC_FAMILY, 0, &family) == FcResultMatch)
+               if(fcPatternGetString(font, FC_FAMILY, 0, &family) == FcResultMatch)
                        entry->family = cstrdup((char*)family);
 
-               if(FcPatternGetInteger(font, FC_SLANT, 0, &slant) == FcResultMatch) {
+               if(fcPatternGetInteger(font, FC_SLANT, 0, &slant) == FcResultMatch) {
                        switch(slant) {
                        case FC_SLANT_ROMAN:
                        default:
@@ -1178,7 +1356,7 @@ int BC_Resources::init_fontconfig(const char *search_path)
                        }
                }
 
-               if(FcPatternGetInteger(font, FC_WIDTH, 0, &width) == FcResultMatch) {
+               if(fcPatternGetInteger(font, FC_WIDTH, 0, &width) == FcResultMatch) {
                        switch(width) {
                        case FC_WIDTH_ULTRACONDENSED:
                                entry->swidth = cstrdup("ultracondensed");
@@ -1218,7 +1396,7 @@ int BC_Resources::init_fontconfig(const char *search_path)
                        }
                }
 
-               if(FcPatternGetInteger(font, FC_SPACING, 0, &spacing) == FcResultMatch) {
+               if(fcPatternGetInteger(font, FC_SPACING, 0, &spacing) == FcResultMatch) {
                        switch(spacing) {
                        case 0:
                        default:
@@ -1249,7 +1427,7 @@ int BC_Resources::init_fontconfig(const char *search_path)
                entry->registry = cstrdup("utf");
                entry->encoding = cstrdup("8");
 
-               if(!FcPatternGetString(font, FC_STYLE, 0, &style) == FcResultMatch)
+               if( fcPatternGetString(font, FC_STYLE, 0, &style) != FcResultMatch )
                        force_style = 0;
 
                // If font has a style unmanaged by titler plugin, force style to be displayed on name
@@ -1270,21 +1448,23 @@ int BC_Resources::init_fontconfig(const char *search_path)
 
                }
                fontlist->append(entry);
+               if( font_debug )
+                       dump_font_entry(stdout, "font 1: ", entry);
        }
 
-       FcFontSetDestroy(fs);
+       fcFontSetDestroy(fs);
        if(freetype_library)
-               FT_Done_FreeType(freetype_library);
+               ft_Done_FreeType(freetype_library);
 // for(int i = 0; i < fonts->total; i++)
 //     fonts->values[i]->dump();
 
-       FcConfigAppFontAddDir(0, (const FcChar8*)search_path);
-       FcConfigSetRescanInterval(0, 0);
+       fcConfigAppFontAddDir(0, (const FcChar8*)search_path);
+       fcConfigSetRescanInterval(0, 0);
 
-       os = FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
+       os = fcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT,
                FC_WIDTH, FC_SLANT, FC_SPACING, FC_STYLE, (char *)0);
-       pat = FcPatternCreate();
-       FcPatternAddBool(pat, FC_SCALABLE, true);
+       pat = fcPatternCreate();
+       fcPatternAddBool(pat, FC_SCALABLE, true);
 
        if(language[0])
        {
@@ -1297,15 +1477,15 @@ int BC_Resources::init_fontconfig(const char *search_path)
                        strcat(langstr, region);
                }
 
-               FcLangSet *ls =  FcLangSetCreate();
-               if(FcLangSetAdd(ls, (const FcChar8*)langstr))
-                       if(FcPatternAddLangSet(pat, FC_LANG, ls))
-               FcLangSetDestroy(ls);
+               FcLangSet *ls =  fcLangSetCreate();
+               if(fcLangSetAdd(ls, (const FcChar8*)langstr))
+                       if(fcPatternAddLangSet(pat, FC_LANG, ls))
+               fcLangSetDestroy(ls);
        }
 
-       fs = FcFontList(0, pat, os);
-       FcPatternDestroy(pat);
-       FcObjectSetDestroy(os);
+       fs = fcFontList(0, pat, os);
+       fcPatternDestroy(pat);
+       fcObjectSetDestroy(os);
 
        for(int i = 0; i < fs->nfont; i++)
        {
@@ -1313,26 +1493,26 @@ int BC_Resources::init_fontconfig(const char *search_path)
                BC_FontEntry *entry = new BC_FontEntry;
 
                FcChar8 *strvalue;
-               if(FcPatternGetString(font, FC_FILE, 0, &strvalue) == FcResultMatch)
+               if(fcPatternGetString(font, FC_FILE, 0, &strvalue) == FcResultMatch)
                {
                        entry->path = new char[strlen((char*)strvalue) + 1];
                        strcpy(entry->path, (char*)strvalue);
                }
 
-               if(FcPatternGetString(font, FC_FOUNDRY, 0, &strvalue) == FcResultMatch)
+               if(fcPatternGetString(font, FC_FOUNDRY, 0, &strvalue) == FcResultMatch)
                {
                        entry->foundry = new char[strlen((char*)strvalue) + 1];
                        strcpy(entry->foundry, (char *)strvalue);
                }
 
-               if(FcPatternGetString(font, FC_FAMILY, 0, &strvalue) == FcResultMatch)
+               if(fcPatternGetString(font, FC_FAMILY, 0, &strvalue) == FcResultMatch)
                {
                        entry->family = new char[strlen((char*)strvalue) + 2];
                        strcpy(entry->family, (char*)strvalue);
                }
 
                int intvalue;
-               if(FcPatternGetInteger(font, FC_SLANT, 0, &intvalue) == FcResultMatch)
+               if(fcPatternGetInteger(font, FC_SLANT, 0, &intvalue) == FcResultMatch)
                {
                        switch(intvalue)
                        {
@@ -1351,7 +1531,7 @@ int BC_Resources::init_fontconfig(const char *search_path)
                        }
                }
 
-               if(FcPatternGetInteger(font, FC_WEIGHT, 0, &intvalue) == FcResultMatch)
+               if(fcPatternGetInteger(font, FC_WEIGHT, 0, &intvalue) == FcResultMatch)
                {
                        switch(intvalue)
                        {
@@ -1402,7 +1582,7 @@ int BC_Resources::init_fontconfig(const char *search_path)
                        }
                }
 
-               if(FcPatternGetInteger(font, FC_WIDTH, 0, &intvalue) == FcResultMatch)
+               if(fcPatternGetInteger(font, FC_WIDTH, 0, &intvalue) == FcResultMatch)
                {
                        switch(intvalue)
                        {
@@ -1444,7 +1624,7 @@ int BC_Resources::init_fontconfig(const char *search_path)
                                break;
                        }
                }
-               if(FcPatternGetInteger(font, FC_SPACING, 0, &intvalue) == FcResultMatch)
+               if(fcPatternGetInteger(font, FC_SPACING, 0, &intvalue) == FcResultMatch)
                {
                        switch(intvalue)
                        {
@@ -1479,8 +1659,10 @@ int BC_Resources::init_fontconfig(const char *search_path)
                        strcpy(entry->displayname, entry->family);
                }
                fontlist->append(entry);
+               if( font_debug )
+                       dump_font_entry(stdout, "font 2: ", entry);
        }
-       FcFontSetDestroy(fs);
+       fcFontSetDestroy(fs);
        return 0;
 }
 
@@ -1550,52 +1732,140 @@ BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style,
        return style_match;
 }
 
+
+class utf8conv {
+       uint8_t *obfr, *out, *oend;
+       uint8_t *ibfr, *inp, *iend;
+public:
+       utf8conv(void *out, int olen, void *inp, int ilen) {
+               this->obfr = this->out = (uint8_t*)out;
+               this->oend = this->out + olen;
+               this->ibfr = this->inp = (uint8_t*)inp;
+               this->iend = this->inp + ilen;
+       }
+       int cur() { return inp>=iend ? -1 : *inp; }
+       int next() { return inp>=iend ? -1 : *inp++; }
+       int next(int ch) { return out>=oend ? -1 : *out++ = ch; }
+       int ilen() { return inp-ibfr; }
+       int olen() { return out-obfr; }
+       int wnext();
+       int wnext(unsigned int v);
+};
+
+int utf8conv::
+wnext(unsigned int v)
+{
+  if( v < 0x00000080 ) { next(v);  return 1; }
+  int n = v < 0x00000800 ? 2 : v < 0x00010000 ? 3 :
+          v < 0x00200000 ? 4 : v < 0x04000000 ? 5 : 6;
+  int m = (0xff00 >> n), i = n-1;
+  next((v>>(6*i)) | m);
+  while( --i >= 0 ) next(((v>>(6*i)) & 0x3f) | 0x80);
+  return n;
+}
+
+int utf8conv::
+wnext()
+{
+  int v = 0, n = 0, ch = next();
+  if( ch == '\\' ) {
+    switch( (ch=next()) ) {
+    case 'n': return '\n';
+    case 't': return '\t';
+    case 'r': return '\r';
+    case 'b': return '\b';
+    case 'f': return '\f';
+    case 'v': return '\v';
+    case 'a': return '\a';
+    case '0': case '1': case '2': case '3':
+    case '4': case '5': case '6': case '7':
+      v = ch - '0';
+      for( int i=3; --i>0; v=v*8+ch, next() )
+        if( (ch=cur()-'0') < 0 || ch >= 8 ) break;
+      return v;
+    case 'x':  n = 2;  break;
+    case 'u':  n = 4;  break;
+    case 'U':  n = 8;  break;
+    default: return ch;
+    }
+    for( int i=n; --i>=0; v=v*16+ch, next() ) {
+      if( (ch=cur()-'0')>=0 && ch<10 ) continue;
+      if( (ch-='A'-'0'-10)>=10 && ch<16 ) continue;
+      if( (ch-='a'-'A')<10 || ch>=16 ) break;
+    }
+  }
+  else if( ch >= 0x80 ) {
+    static const unsigned char byts[] = {
+      1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 5,
+    };
+    int i = ch - 0xc0;
+    n = i<0 ? 0 : byts[i/4];
+    for( v=ch, i=n; --i>=0; v+=next() ) v <<= 6;
+    static const unsigned int ofs[6] = {
+      0x00000000U, 0x00003080U, 0x000E2080U,
+      0x03C82080U, 0xFA082080U, 0x82082080U
+    };
+    v -= ofs[n];
+  }
+  else
+    v = ch;
+  return v;
+}
+
+
 size_t BC_Resources::encode(const char *from_enc, const char *to_enc,
        char *input, int input_length, char *output, int output_length)
 {
-       size_t inbytes, outbytes = 0;
-       iconv_t cd;
-       char *outbase = output;
-
-       if(!from_enc || *from_enc == 0)
+       if( !from_enc || *from_enc == 0 ||
+           !strcmp(from_enc,"UTF8") || !strcmp(from_enc, "US-ASCII") )
                from_enc = "UTF-8";
 
-       if(!to_enc || *to_enc == 0)
+       if( !to_enc || *to_enc == 0 ||
+           !strcmp(to_enc,"UTF8") || !strcmp(to_enc, "US-ASCII") )
                to_enc = "UTF-8";
 
-       if(input_length < 0)
-               inbytes = strlen(input);
-       else
-               inbytes = input_length;
-
-       if(strcmp(from_enc, to_enc) && inbytes)
-       {
-               if((cd = iconv_open(to_enc, from_enc)) == (iconv_t)-1)
-               {
+       iconv_t cd;
+       char *outbase = output;
+       size_t inbytes = input_length < 0 ? strlen(input) : input_length;
+       size_t outbytes = output_length;
+
+       if( inbytes && outbytes ) {
+               if( !strcmp(from_enc, to_enc) ) {
+                       if( inbytes > outbytes ) inbytes = outbytes;
+                       memcpy(output,  input, inbytes);
+                       output += inbytes;
+                       outbytes -= inbytes;
+               }
+               else if( !strcmp(from_enc, "UTF-8") && !strcmp(to_enc,"UTF32LE") ) {
+                       utf8conv uc(0,0, input,inbytes);
+                       uint32_t *op = (uint32_t *)output;
+                       uint32_t *ep = (uint32_t *)(output+output_length);
+                       for( int wch; op<ep && (wch=uc.wnext())>=0; *op++=wch );
+                       output = (char *)op;
+                       outbytes = (char*)ep - output;
+               }
+               else if( !strcmp(from_enc, "UTF32LE") && !strcmp(to_enc,"UTF-8") ) {
+                       utf8conv uc(output,output_length, 0,0);
+                       uint32_t *ip = (uint32_t *)input;
+                       uint32_t *ep = (uint32_t *)(input+inbytes);
+                       for( ; ip<ep && uc.wnext(*ip)>=0; ++ip );
+                       output += uc.olen();
+                       outbytes -= uc.olen();
+               }
+               else if( (cd = iconv_open(to_enc, from_enc)) != (iconv_t)-1 ) {
+                       iconv(cd, &input, &inbytes, &output, &outbytes);
+                       iconv_close(cd);
+               }
+               else {
                        printf(_("Conversion from %s to %s is not available\n"),
                                from_enc, to_enc);
-                       return 0;
                }
-
-               outbytes = output_length - 1;
-
-               iconv(cd, &input, &inbytes, &output, &outbytes);
-
-               iconv_close(cd);
-               inbytes = output - outbase;
        }
-       else if(inbytes)
-       {
-               memcpy(output,  input, inbytes);
-               outbytes -= inbytes;
-       }
-       for(int i = 0; i < 4; i++)
-       {
+       if( outbytes > sizeof(uint32_t) )
+               outbytes = sizeof(uint32_t);
+       for( uint32_t i = 0; i < outbytes; i++)
                output[i] = 0;
-               if(outbytes-- == 0)
-                       break;
-       }
-       return inbytes;
+       return output - outbase;
 }
 
 void BC_Resources::encode_to_utf8(char *buffer, int buflen)
@@ -1618,15 +1888,15 @@ int BC_Resources::find_font_by_char(FT_ULong char_code, char *path_new, const FT
        if(char_code < ' ')
                return 0;
 
-       if( (ofont = FcFreeTypeQueryFace(oldface, (const FcChar8*)"", 4097, 0)) != 0 ) {
+       if( (ofont = fcFreeTypeQueryFace(oldface, (const FcChar8*)"", 4097, 0)) != 0 ) {
                if( (font = find_similar_font(char_code, ofont)) != 0 ) {
-                       if(FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
+                       if(fcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
                                strcpy(path_new, (char*)file);
                                result = 1;
                        }
-                       FcPatternDestroy(font);
+                       fcPatternDestroy(font);
                }
-               FcPatternDestroy(ofont);
+               fcPatternDestroy(ofont);
        }
        return result;
 }
@@ -1644,43 +1914,43 @@ FcPattern* BC_Resources::find_similar_font(FT_ULong char_code, FcPattern *oldfon
                return 0;
 
        fontconfig_lock.lock("BC_Resources::find_similar_font");
-       pat = FcPatternCreate();
-       os = FcObjectSetBuild(FC_FILE, FC_CHARSET, FC_SCALABLE, FC_FAMILY,
+       pat = fcPatternCreate();
+       os = fcObjectSetBuild(FC_FILE, FC_CHARSET, FC_SCALABLE, FC_FAMILY,
                FC_SLANT, FC_WEIGHT, FC_WIDTH, (char *)0);
 
-       FcPatternAddBool(pat, FC_SCALABLE, true);
-       fcs = FcCharSetCreate();
-       if(FcCharSetAddChar(fcs, char_code))
-               FcPatternAddCharSet(pat, FC_CHARSET, fcs);
-       FcCharSetDestroy(fcs);
+       fcPatternAddBool(pat, FC_SCALABLE, true);
+       fcs = fcCharSetCreate();
+       if(fcCharSetAddChar(fcs, char_code))
+               fcPatternAddCharSet(pat, FC_CHARSET, fcs);
+       fcCharSetDestroy(fcs);
        for( int i=0; i<(int)LEN_FCPROP; ++i ) {
-               if(FcPatternGetInteger(oldfont, fc_properties[i], 0, &ival) == FcResultMatch)
-                       FcPatternAddInteger(pat, fc_properties[i], ival);
+               if(fcPatternGetInteger(oldfont, fc_properties[i], 0, &ival) == FcResultMatch)
+                       fcPatternAddInteger(pat, fc_properties[i], ival);
        }
-       fs = FcFontList(0, pat, os);
+       fs = fcFontList(0, pat, os);
        for( int i=LEN_FCPROP; --i>=0 && !fs->nfont; ) {
-               FcFontSetDestroy(fs);
-               FcPatternDel(pat, fc_properties[i]);
-               fs = FcFontList(0, pat, os);
+               fcFontSetDestroy(fs);
+               fcPatternDel(pat, fc_properties[i]);
+               fs = fcFontList(0, pat, os);
        }
-       FcPatternDestroy(pat);
-       FcObjectSetDestroy(os);
+       fcPatternDestroy(pat);
+       fcObjectSetDestroy(os);
 
        pat = 0;
 
        for (int i = 0; i < fs->nfont; i++)
        {
                font = fs->fonts[i];
-               if(FcPatternGetCharSet(font, FC_CHARSET, 0, &fcs) == FcResultMatch)
+               if(fcPatternGetCharSet(font, FC_CHARSET, 0, &fcs) == FcResultMatch)
                {
-                       if(FcCharSetHasChar(fcs, char_code))
+                       if(fcCharSetHasChar(fcs, char_code))
                        {
-                               pat =  FcPatternDuplicate(font);
+                               pat =  fcPatternDuplicate(font);
                                break;
                        }
                }
        }
-       FcFontSetDestroy(fs);
+       fcFontSetDestroy(fs);
        fontconfig_lock.unlock();
 
        return pat;
@@ -1688,13 +1958,16 @@ FcPattern* BC_Resources::find_similar_font(FT_ULong char_code, FcPattern *oldfon
 
 void BC_Resources::dump_fonts(FILE *fp)
 {
-       for( int i=0; i<fontlist->total; ++i ) {
-               BC_FontEntry *ep = fontlist->values[i];
-               fprintf(fp,"%s = %s\n",ep->displayname,ep->path);
-               fprintf(fp,"  %s:%s:%s:%s:%s:%s:%d:%d:%d:%d:%d:%s:%d:%s:%s:%d\n",
-                       ep->foundry, ep->family, ep->weight, ep->slant, ep->swidth, ep->adstyle,
-                       ep->pixelsize, ep->pointsize, ep->xres, ep->yres, ep->style, ep->spacing,
-                       ep->avg_width, ep->registry, ep->encoding, ep->fixed_style);
-       }
+       for( int i=0; i<fontlist->total; ++i )
+               dump_font_entry(fp, "", fontlist->values[i]);
+}
+
+void BC_Resources::dump_font_entry(FILE *fp, const char *cp,  BC_FontEntry *ep)
+{
+       fprintf(fp,"%s%s = %s\n",cp,ep->displayname,ep->path);
+       fprintf(fp,"  %s:%s:%s:%s:%s:%s:%d:%d:%d:%d:%d:%s:%d:%s:%s:%d\n",
+               ep->foundry, ep->family, ep->weight, ep->slant, ep->swidth, ep->adstyle,
+               ep->pixelsize, ep->pointsize, ep->xres, ep->yres, ep->style, ep->spacing,
+               ep->avg_width, ep->registry, ep->encoding, ep->fixed_style);
 }