fixes and upgrades to guicast
[goodguy/history.git] / cinelerra-5.0 / guicast / bcresources.C
index 5e1e4e6265928b13673231c11cbf5c831f0acc02..58d3c5879cfc0b08a29f4038254cacdb69e43b68 100644 (file)
@@ -209,12 +209,7 @@ BC_Resources::BC_Resources()
 {
        synchronous = 0;
        vframe_shm = 0;
-
-       display_info = new BC_DisplayInfo("", 0);
-       int display_w = display_info->get_root_w();
-       int display_h = display_info->get_root_h();
-       int display_size = display_h < display_w ? display_h : display_w;
-       double default_scale = display_size/1000.;
+       double default_scale = 1.0; // display_size/1000.;
        char *env = getenv("BC_FONT_SCALE");
        font_scale = env ? atof(env) : default_scale;
        if( font_scale <= 0 ) font_scale = 1;
@@ -786,30 +781,6 @@ void BC_Resources::set_synchronous(BC_Synchronous *synchronous)
 
 
 
-
-
-
-int BC_Resources::get_top_border()
-{
-       return display_info->get_top_border();
-}
-
-int BC_Resources::get_left_border()
-{
-       return display_info->get_left_border();
-}
-
-int BC_Resources::get_right_border()
-{
-       return display_info->get_right_border();
-}
-
-int BC_Resources::get_bottom_border()
-{
-       return display_info->get_bottom_border();
-}
-
-
 int BC_Resources::get_bg_color() { return bg_color; }
 
 int BC_Resources::get_bg_shadow1() { return bg_shadow1; }
@@ -1430,13 +1401,20 @@ int BC_Resources::init_fontconfig(const char *search_path)
        return 0;
 }
 
-BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style, int mask)
+#define STYLE_MATCH(fst, stl, msk) ((fst) & (msk) & (stl)) && \
+       !((fst) & ~(style) & (msk))
+
+BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style,
+       int mask, int preferred)
 {
-       BC_FontEntry *entry, *style_match, *displayname_match;
+       BC_FontEntry *entry, *style_match, *preferred_match;
 
        if(!fontlist)
                return 0;
 
+       style_match = 0;
+       preferred_match = 0;
+
        if(displayname)
        {
                for(int i = 0; i < fontlist->total; i++)
@@ -1444,34 +1422,49 @@ BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style, i
                        entry = fontlist->values[i];
 
                        if(strcmp(entry->displayname, displayname) == 0 &&
-                                       (entry->style & mask) == style)
-                               return entry;
+                                       STYLE_MATCH(entry->style, style, mask))
+                       {
+                               if(!style_match)
+                                       style_match = entry;
+                               if(!preferred_match && (entry->style & preferred))
+                                       preferred_match = entry;
+                       }
                }
+               if(preferred_match)
+                       return preferred_match;
+
+               if(style_match)
+                       return style_match;
        }
+
 // No exact match - assume normal width font
        style |= FL_WIDTH_NORMAL;
        mask |= FL_WIDTH_MASK;
-       style_match = 0;  displayname_match = 0;
+       style_match = 0;
+       preferred_match = 0;
+
        for(int i = 0; i < fontlist->total; i++)
        {
                entry = fontlist->values[i];
 
-               if(!strncasecmp(displayname, entry->family,
-                               strlen(entry->family)))
-               {
-                       if((entry->style & mask) == style)
-                               return entry;
-                       if(!displayname_match)
-                               displayname_match = entry;
-               }
-
-               if((entry->style & mask) == style)
+               if(STYLE_MATCH(entry->style, style, mask))
                {
                        if(!style_match)
                                style_match = entry;
+
+                       if(!preferred_match && (entry->style & preferred))
+                               preferred_match = entry;
+
+                       if(!strncasecmp(displayname, entry->family,
+                                       strlen(entry->family)))
+                       return entry;
                }
        }
-       return displayname_match ? displayname_match : style_match;
+
+       if(preferred_match)
+               return preferred_match;
+
+       return style_match;
 }
 
 size_t BC_Resources::encode(const char *from_enc, const char *to_enc,
@@ -1522,6 +1515,14 @@ size_t BC_Resources::encode(const char *from_enc, const char *to_enc,
        return inbytes;
 }
 
+void BC_Resources::encode_to_utf8(char *buffer, int buflen)
+{
+        if(BC_Resources::locale_utf8) return;
+       char lbuf[buflen];
+       encode(encoding, 0, buffer, buflen, lbuf, buflen);
+       strcpy(buffer, lbuf);
+}
+
 int BC_Resources::find_font_by_char(FT_ULong char_code, char *path_new, const FT_Face oldface)
 {
        FcPattern *font, *ofont;