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.110 1998/02/27 05:46:07 per Exp $"; + constant cvs_version="$Id: graphic_text.pike,v 1.111 1998/02/27 07:10:03 per Exp $";   constant thread_safe=1;      #include <module.h>   #include <stat.h>   inherit "module";   inherit "roxenlib";      #ifndef VAR_MORE   #define VAR_MORE 0   #endif /* VAR_MORE */
Roxen.git/server/modules/graphics/graphic_text.pike:799:    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)   {    string key = base_key+_args;    array err; +  string orig_text = text; +  mixed data; +  mapping args = find_cached_args(_args); +  if(data = cache_lookup(key, text)) +  { +  if(args->nocache) // Remove from cache. Very useful for access counters +  cache_remove(key, text); +  if(size) return data[1]; +  return data[0]; +  } else if(data = get_cache_file( key, text )) { +  cache_set(key, text, data); +  if(size) return data[1]; +  return err[0]; +  } +     err = catch    {    object img; -  mapping args = find_cached_args(_args); +     if(!args)    { -  args=(["fg":"black","bg":"white"]); +  args=(["fg":"black","bg":"white","notrans":"1"]);    text="Please reload this page";    }       if(!args->verbatim)    {    text = replace(text, nbsp, " ");    text = simplify_text( text );    string res="",nspace="",cspace="";    foreach(text/"\n", string line)    {
Roxen.git/server/modules/graphics/graphic_text.pike:842:    res+=(nspace==cspace?nspace:" ")+word;       if(cspace!="") nspace=cspace;    else nspace=" ";    }    res+="\n";    }    text = replace(res[..strlen(res)-2], ({ "!","?",": " }), ({ nbsp+"!",nbsp+"?",nbsp+": " }));    text = replace(replace(replace(text,({". ",". "+nbsp}), ({"\000","\001"})),".","."+nbsp+nbsp),({"\000","\001"}),({". ","."+nbsp}));    } -  // Check the cache first.. -  mixed data; -  while(data = cache_lookup(key, text)) -  { -  if(data == "rendering") -  { - // werror("rendering of "+_args+" <"+text+"> already in progress\n"); -  sleep(0.1); -  continue; -  } - // werror("rendering of "+_args+" <"+text+">: memory cache hit\n"); -  if(args->nocache) // Remove from cache. Very useful for access counters -  cache_remove(key, text); -  if(size) return data[1]; -  return data[0]; -  } - // werror("rendering of "+_args+" <"+text+"> started\n"); +     -  // Nothing found in the cache. Generate a new image. - // cache_set(key, text, "rendering"); + // cache_set(key, text, "rendering");    -  if(!args->nocache && (err = get_cache_file( key, text ))) -  { -  cache_set(key, text, err); - // werror("found < "+_args+" <"+text+"> in persistant cache\n"); -  if(size) return err[1]; -  return err[0]; -  } -  +    #if efun(get_font)    if(args->nfont)    {    int bold, italic;    if(args->bold) bold=1;    if(args->light) bold=-1;    if(args->italic) italic=1;    if(args->black) bold=2;    data = get_font(args->nfont,(int)args->font_size||32,bold,italic,    lower_case(args->talign||"left"),    (float)(int)args->xpad, (float)(int)args->ypad);    }    else if(args->font)    {   #endif    string fkey = args->font+"/"+args->talign+"/"+args->xpad+"/"+args->ypad; -  data = cache_lookup("fonts", fkey); -  if(!data) -  { + // data = cache_lookup("fonts", fkey); + // if(!data) + // {    data = load_font(args->font, lower_case(args->talign||"left"),    (int)args->xpad,(int)args->ypad); -  cache_set("fonts", fkey, data); -  } + // cache_set("fonts", fkey, data); + // }   #if efun(get_font)    } else {    int bold, italic;    if(args->bold) bold=1;    if(args->light) bold=-1;    if(args->italic) italic=1;    if(args->black) bold=2;    data = get_font(roxen->QUERY(default_font),32,bold,italic,    lower_case(args->talign||"left"),    (float)(int)args->xpad, (float)(int)args->ypad);    }   #endif       if (!data) {    roxen_perror("gtext: No font!\n");   // werror("no font found! < "+_args+" <"+text+">\n"); -  cache_set(key, text, 0); + // cache_set(key, orig_text, 0);    return(0);    }       // Fonts and such are now initialized.    img = make_text_image(args,data,text,id);       // Now we have the image in 'img', or nothing.    if(!img) {   // werror("error while drawing image? (no image) < "+_args+" <"+text+">\n"); -  cache_set(key, text, 0); + // cache_set(key, orig_text, 0);    return 0;    }       int q = (int)args->quant||(args->background||args->texture?250:QUERY(cols));       if(q>255) q=255;    if(q<3) q=3;      // Quantify    if(!args->fs)    {   #ifdef QUANT_DEBUG    print_colors(img->select_colors(q-1)+({parse_color(args->bg)}));   #endif    img = img->map_closest(img->select_colors(q-1)+({parse_color(args->bg)}));    }    - // place in cache, as a gif image. -  +     if(!args->scroll)    if(args->fadein)    {    int amount=2, steps=10, delay=10, initialdelay=0, ox;    string res = img->gif_begin();    sscanf(args->fadein, "%d,%d,%d,%d", amount, steps, delay, initialdelay);    if(initialdelay)    {    object foo=Image.image(img->xsize(),img->ysize(),@parse_color(args->bg));    res += foo->gif_add(0,0,initialdelay);
Roxen.git/server/modules/graphics/graphic_text.pike:986:    for(int i = 0; i<steps; i++)    {    int xp = i*ox/steps;    res += img->copy(xp, 0, xp+len, img->ysize(),    @parse_color(args->bg))->gif_add(0,0,delay);    }    res += img->gif_end();    data = ({ res, ({ len, img->ysize() }) });    }    -  -  if(!args->nocache && store_cache_file( key, text, data )) - // werror("done! < "+_args+" <"+text+">\n"); -  cache_set(key, text, data); + // place in caches, as a gif image. +  if(!args->nocache) +  store_cache_file( key, orig_text, data ); +  cache_set(key, orig_text, data);    if(size) return data[1];    return data[0];    };   // werror("Got error < "+_args+" <"+text+">\n");    cache_set(key, text, 0);    throw(err);   }      mapping find_file(string f, object rid); // Pike 0.5...   void restore_cached_args(); // Pike 0.5...
Roxen.git/server/modules/graphics/graphic_text.pike:1125:    if(sizeof(indices(q=Gz)))    data=q->deflate()->deflate(data);    };    o->write(data);   }      mapping find_cached_args(int num)   {    if(!args_restored) restore_cached_args();    if(cached_args[num]) return cached_args[num]; -  -  // This is a very unlikely event... +     restore_cached_args();    if(cached_args[num]) return cached_args[num];    return 0;   }            int find_or_insert(mapping find)   {    mapping f2 = copy_value(find);