bsd lang segv fix, enable bsd lv2, lv2 gui enable fix, proxy/ffmpeg toggle resize...
[goodguy/history.git] / cinelerra-5.1 / guicast / bcresources.C
index e4443c8895786a8c09b4eedb1ae1635d0c60e889..1e92730379e96aae5b810ab70134a23607208bac 100644 (file)
@@ -544,31 +544,31 @@ new_vframes(3,default_filebox_reload_images,
        new VFramePng(file_reload_hi_png),
        new VFramePng(file_reload_dn_png));
 
        new VFramePng(file_reload_hi_png),
        new VFramePng(file_reload_dn_png));
 
-#include "images/file_size_capb_dn_png.h"
-#include "images/file_size_capb_hi_png.h"
 #include "images/file_size_capb_up_png.h"
 #include "images/file_size_capb_up_png.h"
-#include "images/file_size_lwrb_dn_png.h"
-#include "images/file_size_lwrb_hi_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_up_png.h"
-#include "images/file_size_semi_dn_png.h"
-#include "images/file_size_semi_hi_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_up_png.h"
-#include "images/file_size_zero_dn_png.h"
-#include "images/file_size_zero_hi_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_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_vframes(12,default_filebox_szfmt_images,
-       new VFramePng(file_size_zero_dn_png),
-       new VFramePng(file_size_zero_hi_png),
        new VFramePng(file_size_zero_up_png),
        new VFramePng(file_size_zero_up_png),
-       new VFramePng(file_size_lwrb_dn_png),
-       new VFramePng(file_size_lwrb_hi_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_up_png),
-       new VFramePng(file_size_capb_dn_png),
-       new VFramePng(file_size_capb_hi_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_up_png),
-       new VFramePng(file_size_semi_dn_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_hi_png),
-       new VFramePng(file_size_semi_up_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_dn_png.h"
 #include "images/listbox_button_hi_png.h"
@@ -759,6 +759,7 @@ new_vframes(20,default_medium_7segment,
        text_default = BLACK;
        highlight_inverse = WHITE ^ BLUE;
        text_background = WHITE;
        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;
        text_background_hi = LTYELLOW;
        text_background_noborder_hi = LTGREY;
        text_background_noborder = -1;
@@ -888,7 +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_rename_images, 3);
        del_vframes(default_filebox_delete_images, 3);
        del_vframes(default_filebox_reload_images, 3);
-       del_vframes(default_filebox_szfmt_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);
        del_vframes(default_listbox_button, 4);
        delete default_listbox_bg;
        del_vframes(default_listbox_expand, 5);
@@ -1375,7 +1376,7 @@ int BC_Resources::init_fontconfig(const char *search_path)
                entry->registry = cstrdup("utf");
                entry->encoding = cstrdup("8");
 
                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
                        force_style = 0;
 
                // If font has a style unmanaged by titler plugin, force style to be displayed on name
@@ -1680,52 +1681,140 @@ BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style,
        return style_match;
 }
 
        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 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";
 
                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";
 
                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);
                        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;
                output[i] = 0;
-               if(outbytes-- == 0)
-                       break;
-       }
-       return inbytes;
+       return output - outbase;
 }
 
 void BC_Resources::encode_to_utf8(char *buffer, int buflen)
 }
 
 void BC_Resources::encode_to_utf8(char *buffer, int buflen)