Esempio n. 1
0
bool de_init()
{
    WRootWin *rootwin;
    DEStyle *style;
    
    if(!de_register_exports())
        return FALSE;
    
    if(!gr_register_engine("de", (GrGetBrushFn*)&de_get_brush))
        goto fail;
    
    /* Create fallback brushes */
    FOR_ALL_ROOTWINS(rootwin){
        style=de_create_style(rootwin, "*");
        if(style!=NULL){
            style->is_fallback=TRUE;
            de_load_font_for_style(style, de_default_fontname());
        }
    }
    
    return TRUE;
    
fail:
    de_unregister_exports();
    return FALSE;
}
Esempio n. 2
0
File: font.c Progetto: raboof/notion
DEFont *de_load_font(const char *fontname)
{
    DEFont *fnt;
    const char *default_fontname=de_default_fontname();
#ifdef HAVE_X11_XFT
    XftFont *font=NULL;
#endif
#ifdef HAVE_X11_BMF
    XFontSet fontset=NULL;
    XFontStruct *fontstruct=NULL;
#endif

    assert(fontname!=NULL);

    /* There shouldn't be that many fonts... */
    for(fnt=fonts; fnt!=NULL; fnt=fnt->next){
        if(strcmp(fnt->pattern, fontname)==0){
            fnt->refcount++;
            return fnt;
        }
    }

#ifdef HAVE_X11_XFT
    LOG(DEBUG, FONT, "Loading font %s via XFT", fontname);
    if(strncmp(fontname, "xft:", 4)==0){
        font=XftFontOpenName(ioncore_g.dpy, DefaultScreen(ioncore_g.dpy), fontname+4);
    }else{
#ifdef HAVE_X11_BMF
        goto bitmap_font;
#else
        font=XftFontOpenXlfd(ioncore_g.dpy, DefaultScreen(ioncore_g.dpy), fontname);
#endif
    }

    if(font==NULL){
        if(strcmp(fontname, default_fontname)!=0){
            warn(TR("Could not load font \"%s\", trying \"%s\""),
                fontname, default_fontname);
            fnt=de_load_font(default_fontname);
            if(fnt==NULL)
                LOG(WARN, FONT, TR("Failed to load fallback font."));
            return fnt;
        }
        return NULL;
    }else{
        FcPatternPrint(font->pattern);
    }
#endif /* HAVE_X11_XFT */

#ifdef HAVE_X11_BMF
#ifdef HAVE_X11_XFT
bitmap_font:
#endif
    if(ioncore_g.use_mb && !(ioncore_g.enc_utf8 && iso10646_font(fontname))){
        LOG(DEBUG, FONT, "Loading fontset %s", fontname);
        fontset=de_create_font_set(fontname);
        if(fontset!=NULL){
            if(XContextDependentDrawing(fontset)){
                warn(TR("Fontset for font pattern '%s' implements context "
                        "dependent drawing, which is unsupported. Expect "
                        "clutter."), fontname);
            }
        }
    }else{
        LOG(DEBUG, FONT, "Loading fontstruct %s", fontname);
        fontstruct=XLoadQueryFont(ioncore_g.dpy, fontname);
    }

    if(fontstruct==NULL && fontset==NULL){
        if(strcmp(fontname, default_fontname)!=0){
            DEFont *fnt;
            LOG(WARN, FONT, TR("Could not load font \"%s\", trying \"%s\""),
                 fontname, default_fontname);
            fnt=de_load_font(default_fontname);
            if(fnt==NULL)
                LOG(WARN, FONT, TR("Failed to load fallback font."));
            return fnt;
        }
        return NULL;
    }
#endif /* HAVE_X11_BMF */

    fnt=ALLOC(DEFont);

    if(fnt==NULL)
        return NULL;

#ifdef HAVE_X11_XFT
    fnt->font=font;
#endif
#ifdef HAVE_X11_BMF
    fnt->fontset=fontset;
    fnt->fontstruct=fontstruct;
#endif
    fnt->pattern=scopy(fontname);
    fnt->next=NULL;
    fnt->prev=NULL;
    fnt->refcount=1;

    LINK_ITEM(fonts, fnt, next, prev);

    return fnt;
}
Esempio n. 3
0
/*EXTL_DOC
 * Define a style for the root window \var{rootwin}. 
 */
EXTL_EXPORT
bool de_defstyle_rootwin(WRootWin *rootwin, const char *name, ExtlTab tab)
{
    DEStyle *style, *based_on=NULL;
    char *fnt, *bss;

    if(name==NULL)
        return FALSE;
    
    style=de_create_style(rootwin, name);
    
    if(style==NULL)
        return FALSE;
    
    if(extl_table_gets_s(tab, "based_on", &bss)){
        GrStyleSpec bs;
        
        gr_stylespec_load(&bs, bss);
        
        based_on=de_get_style(rootwin, &bs);
        
        gr_stylespec_unalloc(&bs);
        free(bss);
    }else{
        based_on=de_get_style(rootwin, &style->spec);
    }
    
    if(based_on!=NULL){
        style->based_on=based_on;
        based_on->usecount++;
    }
    
    de_get_nonfont(rootwin, style, tab);

    if(extl_table_gets_s(tab, "font", &fnt)){
        de_load_font_for_style(style, fnt);
        free(fnt);
    }else if(based_on!=NULL && based_on->font!=NULL){
        de_set_font_for_style(style, based_on->font);
    }
    
    if(style->font==NULL)
        de_load_font_for_style(style, de_default_fontname());
    
    if(based_on!=NULL && 
       gr_stylespec_equals(&based_on->spec, &style->spec)){
       
        /* The new style replaces based_on, so it may be dumped. */
        if(!based_on->is_fallback)
            destyle_dump(based_on);
        
        if(based_on->usecount==1){
            uint nb=based_on->n_extra_cgrps;
            uint ns=style->n_extra_cgrps;
            /* Nothing else is using based_on: optimise and move
             * extra colour groups here, so that based_on can be freed.
             */
            
            if(nb>0){
                DEColourGroup *cgs=ALLOC_N(DEColourGroup, nb+ns);
                
                if(cgs!=NULL){
                    memcpy(cgs, based_on->extra_cgrps, sizeof(DEColourGroup)*nb);
                    memcpy(cgs+nb, style->extra_cgrps, sizeof(DEColourGroup)*ns);
                
                    free(style->extra_cgrps);
                    style->extra_cgrps=cgs;
                    style->n_extra_cgrps=nb+ns;
                
                    free(based_on->extra_cgrps);
                    based_on->extra_cgrps=NULL;
                    based_on->n_extra_cgrps=0;
                    
                }
            }
            
            /* style->extras_table should be none still */
            style->extras_table=based_on->extras_table;
            based_on->extras_table=extl_table_none();
            
            style->based_on=based_on->based_on;
            based_on->based_on=NULL;
            
            destyle_unref(based_on);
        }
        
    }
    
    filter_extras(&style->extras_table, tab);
    
    destyle_add(style);
    
    return TRUE;
}
Esempio n. 4
0
DEFont *de_load_font(const char *fontname)
{
    DEFont *fnt;
    XFontSet fontset=NULL;
    XFontStruct *fontstruct=NULL;
    const char *default_fontname=de_default_fontname();
    
    assert(fontname!=NULL);
    
    /* There shouldn't be that many fonts... */
    for(fnt=fonts; fnt!=NULL; fnt=fnt->next){
        if(strcmp(fnt->pattern, fontname)==0){
            fnt->refcount++;
            return fnt;
        }
    }
    
    if(ioncore_g.use_mb && !(ioncore_g.enc_utf8 && iso10646_font(fontname))){
        LOG(DEBUG, FONT, "Loading fontset %s", fontname); 
        fontset=de_create_font_set(fontname);
        if(fontset!=NULL){
            if(XContextDependentDrawing(fontset)){
                warn(TR("Fontset for font pattern '%s' implements context "
                        "dependent drawing, which is unsupported. Expect "
                        "clutter."), fontname);
            }
        }
    }else{
        LOG(DEBUG, FONT, "Loading fontstruct %s", fontname); 
        fontstruct=XLoadQueryFont(ioncore_g.dpy, fontname);
    }
    
    if(fontstruct==NULL && fontset==NULL){
        if(strcmp(fontname, default_fontname)!=0){
            DEFont *fnt;
            LOG(WARN, FONT, TR("Could not load font \"%s\", trying \"%s\""),
                 fontname, default_fontname);
            fnt=de_load_font(default_fontname);
            if(fnt==NULL)
                LOG(WARN, FONT, TR("Failed to load fallback font."));
            return fnt;
        }
        return NULL;
    }
    
    fnt=ALLOC(DEFont);
    
    if(fnt==NULL)
        return NULL;
    
    fnt->fontset=fontset;
    fnt->fontstruct=fontstruct;
    fnt->pattern=scopy(fontname);
    fnt->next=NULL;
    fnt->prev=NULL;
    fnt->refcount=1;
    
    LINK_ITEM(fonts, fnt, next, prev);
    
    return fnt;
}