bsd compatibility mods
[goodguy/history.git] / cinelerra-5.1 / guicast / bcresources.C
index e932af59411abeee197a8b2e7d415f4bb649d28b..e340060099810ba20429b593bceaca7ab9bd80e7 100644 (file)
@@ -59,6 +59,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*))
 
@@ -88,7 +89,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=16";             // 16
+static const char *def_clock_font_xft = "Sans:pixelsize=%.4f";           // 16
 
 #define default_font_xft2 "-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*"
 
@@ -136,8 +137,8 @@ void BC_Resources::init_font_defs(double scale)
        def_font(large_font2,      iround(scale*20));
        def_font(big_font,         iround(scale*160), iround(scale*160));
        def_font(big_font2,        iround(scale*16), iround(scale*16));
-       def_font(clock_font,       iround(scale*16), iround(scale*16));
-       def_font(clock_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));
@@ -151,7 +152,7 @@ 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));
+       def_font(clock_font_xft,   (scale*16.));
 
        set_font(small_font_xft2,  default_font_xft2);
        set_font(medium_font_xft2, default_font_xft2);
@@ -199,22 +200,34 @@ suffix_to_type_t BC_Resources::suffix_to_type[] =
     { "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 },
-    { "wmv", ICON_SOUND },
+    { "3gp", ICON_FILM },
     { "avi", ICON_FILM },
     { "bmp", ICON_FILM },
     { "cr2", ICON_FILM },
     { "dnxhd", ICON_FILM },
-    { "dvd", 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 },
@@ -224,15 +237,17 @@ suffix_to_type_t BC_Resources::suffix_to_type[] =
     { "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 },
-    { "ogg", ICON_FILM },
     { "ogv", ICON_FILM },
     { "pcm", ICON_FILM },
     { "pgm", ICON_FILM },
@@ -240,14 +255,17 @@ suffix_to_type_t BC_Resources::suffix_to_type[] =
     { "ppm", ICON_FILM },
     { "qt", ICON_FILM },
     { "rm", ICON_FILM },
+    { "rmvb", ICON_FILM },
+    { "rv", ICON_FILM },
     { "swf", ICON_FILM },
-    { "tiff", 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 },
@@ -329,6 +347,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, };
@@ -344,7 +363,9 @@ 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);
@@ -470,59 +491,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"
@@ -712,6 +759,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;
@@ -763,6 +811,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;
 
@@ -839,6 +889,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);
@@ -966,17 +1017,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 {} \\;");
@@ -1123,11 +1180,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;
@@ -1314,7 +1376,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
@@ -1335,6 +1397,8 @@ int BC_Resources::init_fontconfig(const char *search_path)
 
                }
                fontlist->append(entry);
+               if( font_debug )
+                       dump_font_entry(stdout, "font 1: ", entry);
        }
 
        FcFontSetDestroy(fs);
@@ -1544,6 +1608,8 @@ 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);
        return 0;
@@ -1753,13 +1819,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);
 }