Roxen.git / server / modules / graphics / graphic_text.pike

version» Context lines:

Roxen.git/server/modules/graphics/graphic_text.pike:1: - constant cvs_version="$Id: graphic_text.pike,v 1.98 1998/02/02 09:40:43 jens Exp $"; + constant cvs_version="$Id: graphic_text.pike,v 1.99 1998/02/04 16:10:44 per Exp $";   constant thread_safe=1;      #include <module.h>   inherit "module";   inherit "roxenlib";      #if efun(_static_modules)   # define map_array Array.map   import Image;   # define Image image   # define Font font   #endif    - #if !efun(Privs) - constant Privs=((program)"privs"); - #endif /* !efun(Privs) */ -  +    #ifndef VAR_MORE   #define VAR_MORE 0   #endif /* VAR_MORE */      array register_module()   {    return ({ MODULE_LOCATION | MODULE_PARSER,    "Graphics text",    "Defines a few new containers, which all render text to gifs "    "using the image module in pike.\n<p>"
Roxen.git/server/modules/graphics/graphic_text.pike:123:    catch(fnts = get_dir("fonts/32/") - ({".",".."}));    if(!fnts)    {    return ({});    }    return fnts;   }      void create()   { -  defvar("cache_dir", ".gtext_cache", "Cache directory for gtext images", +  defvar("cache_dir", "../gtext_cache", "Cache directory for gtext images",    TYPE_DIR,    "The gtext tag saves images when they are calculated in this "    "directory. We currently do not clean this directory.");       defvar("speedy", 0, "Avoid automatic detection of document colors",    TYPE_FLAG|VAR_MORE,    "If this flag is set, the tags 'body', 'tr', 'td', 'font' and 'th' "    " will <b>not</b> be parsed to automatically detect the colors of "    " a document. You will then have to specify all colors in all calls "    " to &lt;gtext&gt;");
Roxen.git/server/modules/graphics/graphic_text.pike:611:   }      string base_key;   object mc;      void start(int|void val, object|void conf)   {    if(conf)    {    mkdirhier( query( "cache_dir" )+".foo" ); + #if efun(chmod) +  chmod( query( "cache_dir" ), 0777 ); + #endif    mc = conf;    base_key = "gtext:"+(conf?conf->name:roxen->current_configuration->name);    }   }      #ifdef QUANT_DEBUG   void print_colors(array from)   {   #if efun(color_name)    for(int i=0; i<sizeof(from); i++)
Roxen.git/server/modules/graphics/graphic_text.pike:669:            constant nbsp = iso88591["&nbsp;"];      constant replace_from = indices( iso88591 )+ ({"&ss;","&lt;","&gt;","&amp",});   constant replace_to = values( iso88591 ) + ({ nbsp, "<", ">", "&", });      #define simplify_text( from ) replace(from,replace_from,replace_to)    + #define FNAME(a,b) (query("cache_dir")+sprintf("%x",hash(reverse(a[6..])))+sprintf("%x",hash(b))+sprintf("%x",hash(reverse(b-" ")))+sprintf("%x",hash(b[12..])))      array get_cache_file(string a, string b)   { -  object fd = open(query("cache_dir")+ -  sprintf("%x",hash(reverse(a)))+sprintf("%x",hash(b)), "r"); +  object fd = open(FNAME(a,b), "r");    if(!fd) return 0;    array r = decode_value(fd->read());    if(r[0]==a && r[1]==b) return r[2];   }      void store_cache_file(string a, string b, array data)   { -  object fd = open(query("cache_dir")+ -  sprintf("%x",hash(reverse(a)))+sprintf("%x",hash(b)), "wct"); +  object fd = open(FNAME(a,b), "wct"); + #if efun(chmod) +  chmod( FNAME(a,b), 0666 ); + #endif    if(!fd) return;    fd->write(encode_value(({a,b,data})));    destruct(fd);   }       - array(int)|string write_text(int _args, string text, int size, -  object id) + array(int)|string write_text(int _args, string text, int size, object id)   {    string key = base_key+_args;    array err;    err = catch    {    object img;    mapping args = find_cached_args(_args);    if(!args)    {    args=(["fg":"black","bg":"white"]);
Roxen.git/server/modules/graphics/graphic_text.pike:944:    case '.': case ',': case '!':    res += in[i..i];    break;    default:    res += sprintf("%%%02x", in[i]);    }    if(strlen(res) < strlen(option)) return url_cache[in]=res;    return url_cache[in]=option;   }    + #define ARGHASH query("cache_dir")+"ARGS_"+hash(mc->name) +    int args_restored = 0;   void restore_cached_args()   {    args_restored = 1; -  object privs = Privs("Reading gtext argument list"); -  object o = open(".gtext_args_"+hash(mc->name), "r"); -  privs = 0; +  object o = open(ARGHASH, "r");    if(o)    {    string data = o->read();    catch {    object q;    if(sizeof(indices(q=Gz)))    data=q->inflate()->inflate(data);    };    catch {    cached_args |= decode_value(data);
Roxen.git/server/modules/graphics/graphic_text.pike:977:    number = 0;    }   }      void save_cached_args()   {    int on;    on = number;    restore_cached_args();    if(on > number) number=on; -  object privs = Privs("Saving gtext argument list"); -  object o = open(".gtext_args_"+hash(mc->name), "wct"); -  privs = 0; +  object o = open(ARGHASH, "wct"); + #if efun(chmod) +  chmod( ARGHASH, 0666 ); + #endif    string data=encode_value(cached_args);    catch {    object q;    if(sizeof(indices(q=Gz)))    data=q->deflate()->deflate(data);    };    o->write(data);   }      mapping find_cached_args(int num)