<commit_before>/*
 * ion/de/init.c
 *
 * Copyright (c) <NAME> 1999-2006. 
 *
 * Ion is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 */

#include <string.h>

#include <libextl/readconfig.h>
#include <libextl/extl.h>

#include <ioncore/common.h>
#include <ioncore/global.h>
#include <ioncore/rootwin.h>
#include <ioncore/extlconv.h>
#include <ioncore/ioncore.h>

#include "brush.h"
#include "font.h"
#include "colour.h"
#include "private.h"
#include "init.h"
#include "exports.h"


/*{{{ Borders */


#define CF_BORDER_VAL_SANITY_CHECK 16

void de_get_border_val(uint *val, ExtlTab tab, const char *what)
{
    int g;
    
    if(extl_table_gets_i(tab, what, &g)){
        if(g>CF_BORDER_VAL_SANITY_CHECK || g<0)
            warn(TR("Border attribute %s sanity check failed."), what);
        else
            *val=g;
    }
}


void de_get_border_style(uint *ret, ExtlTab tab)
{
    char *style=NULL;
    
    if(!extl_table_gets_s(tab, "border_style", &style))
        return;
    
    if(strcmp(style, "inlaid")==0)
        *ret=DEBORDER_INLAID;
    else if(strcmp(style, "elevated")==0)
        *ret=DEBORDER_ELEVATED;
    else if(strcmp(style, "groove")==0)
        *ret=DEBORDER_GROOVE;
    else if(strcmp(style, "ridge")==0)
        *ret=DEBORDER_RIDGE;
    else
        warn(TR("Unknown border style \"%s\"."), style);
    
    free(style);
}


void de_get_border(DEBorder *border, ExtlTab tab)
{
    de_get_border_val(&(border->sh), tab, "shadow_pixels");
    de_get_border_val(&(border->hl), tab, "highlight_pixels");
    de_get_border_val(&(border->pad), tab, "padding_pixels");
    de_get_border_style(&(border->style), tab);
}


/*}}}*/


/*{{{ Colours */


bool de_get_colour(WRootWin *rootwin, DEColour *ret, 
                   ExtlTab tab, DEStyle *based_on,
                   const char *what, DEColour substitute)
{
    char *name=NULL;
    bool ok=FALSE;
    
    if(extl_table_gets_s(tab, what, &name)){
        ok=de_alloc_colour(rootwin, ret, name);
    
        if(!ok)
            warn(TR("Unable to allocate colour \"%s\"."), name);

        free(name);
    }
    
    if(!ok && based_on!=NULL){
        return de_get_colour(rootwin, ret, based_on->data_table,
                             based_on->based_on, what, substitute);
    }else if(!ok){
        return de_duplicate_colour(rootwin, substitute, ret);
    }
    
    return ok;
}


void de_get_colour_group(WRootWin *rootwin, DEColourGroup *cg, 
                         ExtlTab tab, DEStyle *based_on)
{
    de_get_colour(rootwin, &(cg->hl), tab, based_on, "highlight_colour",
                  DE_WHITE(rootwin));
    de_get_colour(rootwin, &(cg->sh), tab, based_on, "shadow_colour",
                  DE_WHITE(rootwin));
    de_get_colour(rootwin, &(cg->bg), tab, based_on, "background_colour",
                  DE_BLACK(rootwin));
    de_get_colour(rootwin, &(cg->fg), tab, based_on, "foreground_colour",
                  DE_WHITE(rootwin));
    de_get_colour(rootwin, &(cg->pad), tab, based_on, "padding_colour", 
                  cg->bg);
}


void de_get_extra_cgrps(WRootWin *rootwin, DEStyle *style, ExtlTab tab)<commit_msg>Some drawing engine code tuning<commit_after>/*
 * ion/de/init.c
 *
 * Copyright (c) <NAME> 1999-2006. 
 *
 * Ion is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 */

#include <string.h>

#include <libextl/readconfig.h>
#include <libextl/extl.h>

#include <ioncore/common.h>
#include <ioncore/global.h>
#include <ioncore/rootwin.h>
#include <ioncore/extlconv.h>
#include <ioncore/ioncore.h>

#include "brush.h"
#include "font.h"
#include "colour.h"
#include "private.h"
#include "init.h"
#include "exports.h"


/*{{{ Borders */


#define CF_BORDER_VAL_SANITY_CHECK 16

void de_get_border_val(uint *val, ExtlTab tab, const char *what)
{
    int g;
    
    if(extl_table_gets_i(tab, what, &g)){
        if(g>CF_BORDER_VAL_SANITY_CHECK || g<0)
            warn(TR("Border attribute %s sanity check failed."), what);
        else
            *val=g;
    }
}


void de_get_border_style(uint *ret, ExtlTab tab)
{
    char *style=NULL;
    
    if(!extl_table_gets_s(tab, "border_style", &style))
        return;
    
    if(strcmp(style, "inlaid")==0)
        *ret=DEBORDER_INLAID;
    else if(strcmp(style, "elevated")==0)
        *ret=DEBORDER_ELEVATED;
    else if(strcmp(style, "groove")==0)
        *ret=DEBORDER_GROOVE;
    else if(strcmp(style, "ridge")==0)
        *ret=DEBORDER_RIDGE;
    else
        warn(TR("Unknown border style \"%s\"."), style);
    
    free(style);
}


void de_get_border(DEBorder *border, ExtlTab tab)
{
    de_get_border_val(&(border->sh), tab, "shadow_pixels");
    de_get_border_val(&(border->hl), tab, "highlight_pixels");
    de_get_border_val(&(border->pad), tab, "padding_pixels");
    de_get_border_style(&(border->style), tab);
}


/*}}}*/


/*{{{ Colours */


bool de_get_colour(WRootWin *rootwin, DEColour *ret, 
                   ExtlTab tab, DEStyle *based_on,
                   const char *what, DEColour substitute)
{
    char *name=NULL;
    bool ok=FALSE;
    
    if(extl_table_gets_s(tab, what, &name)){
        ok=de_alloc_colour(rootwin, ret, name);
    
        if(!ok)
            warn(TR("Unable to allocate colour \"%s\"."), name);

        free(name);
    }else if(based_on!=NULL){
        return de_get_colour(rootwin, ret, based_on->data_table,
                             based_on->based_on, what, substitute);
    }
    
    if(!ok)
        ok=de_duplicate_colour(rootwin, substitute, ret);
    
    return ok;
}


void de_get_colour_group(WRootWin *rootwin, DEColourGroup *cg, 
                         ExtlTab tab, DEStyle *based_on)
{
    de_get_colour(rootwin, &(cg->hl), tab, based_on, "highlight_colour",
                  DE_WHITE(rootwin));
    de_get_colour(rootwin, &(cg->sh), tab, based_on, "shadow_colour",
                  DE_WHITE(rootwin));
    de_get_colour(rootwin, &(cg->bg), tab, based_on, "background_colour",
                  DE_BLACK(rootwin));
    de_get_colour(rootwin, &(cg->fg), tab, based_on, "foreground_colour",
                  DE_WHITE(rootwin));
    de_get_colour(rootwin, &(cg->pad), tab, based_on, "padding_colour", 
                  cg->bg);
}


void de_get_extra_cgrps(WRootWin *rootwin, DEStyle *style, ExtlTab tab)
{'fraction_non_alphanumeric': 0.1429864253393665, 'fraction_numerical': 0.005128205128205128, 'mean_word_length': 2.9399881164587045, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5669240', 'n_tokens_mistral': 2484, 'n_tokens_neox': 2387, 'n_words': 497}