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.168 1999/05/12 08:00:35 per Exp $"; + constant cvs_version="$Id: graphic_text.pike,v 1.169 1999/05/12 09:59:51 per Exp $";   constant thread_safe=1;      #include <config.h>   #include <module.h>   #include <stat.h>   inherit "module";   inherit "roxenlib";      #ifndef VAR_MORE   #define VAR_MORE 0   #endif /* VAR_MORE */    -  - roxen.Configuration.ArgCache argcache; -  -  +    static private int loaded;      static private string doc()   {    return !loaded?"":replace(Stdio.read_bytes("modules/tags/doc/graphic_text")    ||"", ({ "{", "}" }), ({ "&lt;", "&gt;" }));   }      array register_module()   {
Roxen.git/server/modules/graphics/graphic_text.pike:99:    "The URL-prefix for the graphic characters.");       defvar("cols", 16, "Default number of colors per image", TYPE_INT_LIST,    "The default number of colors to use. 16 seems to be enough. "    "The size of the image depends on the number of colors",    ({ 1,2,3,4,5,6,7,8,10,16,32,64,128,256 }));       defvar("gif", 0, "Append .gif to all images", TYPE_FLAG|VAR_MORE,    "Append .gif to all images made by gtext. Normally this will "    "only waste bandwidth"); -  -  -  defvar("cacheindb", 0, -  "Store the arguments and text cache in a mysql database", -  TYPE_FLAG|VAR_MORE, -  "If set, store the argument cache (and text cache) in a mysql " -  "database. This is very useful for load balancing using multiple " -  "roxen servers, since the mysql database handles synchronization"); -  -  defvar( "dbpath", "mysql://localhost/gtextcache", -  "Database URL to use", -  TYPE_STRING|VAR_MORE, -  "The database to use to store the argument cache", -  0, -  lambda(){ return !query("cacheindb"); }); +    }    - string query_location() { return query("location"); } -  - static private mapping cached_args = ([ ]); -  +    #define MAX(a,b) ((a)<(b)?(b):(a))    - #if !efun(make_matrix) - static private mapping (int:array(array(int))) matrixes = ([]); +    array (array(int)) make_matrix(int size)   { -  if(matrixes[size]) return matrixes[size]; +     array res;    int i;    int j;    res = Array.map(allocate(size), lambda(int s, int size){    return allocate(size); }, size);       for(i=0; i<size; i++)    for(j=0; j<size; j++)    res[i][j] = (int)MAX((float)size/2.0-sqrt((size/2-i)*(size/2-i) + (size/2-j)*(size/2-j)),0); -  return matrixes[size] = res; +  return res;   } - #endif +       string fix_relative(string file, object id)   {    if(file != "" && file[0] == '/') return file;    file = combine_path(dirname(id->not_query) + "/", file);    return file;   }    - object last_image; // Cache the last image for a while. - string last_image_name; - object load_image(string f,object id) - { -  if(last_image_name == f && last_image) return last_image->copy(); -  string data; -  object file; -  object img; -  -  if(!(data=id->conf->try_get_file(f, id))) -  if(!(file=open(f,"r")) || (!(data=file->read()))) -  return 0; -  if(file) destruct(file); - #if constant(Image.GIF.decode) -  catch { if(!img) img = Image.GIF.decode( data ); }; - #endif - #if constant(Image.JPEG.decode) -  catch { if(!img) img = Image.JPEG.decode( data ); }; - #endif - #if constant(Image.PNG.decode) -  catch { if(!img) img = Image.PNG.decode( data ); }; - #endif -  catch { if(!img) img = Image.PNM.decode( data ); }; -  if(!img) return 0; -  last_image = img; last_image_name = f; -  return img->copy(); - } -  +    object blur(object img, int amnt)   {    img->setcolor(0,0,0);    img = img->autocrop(amnt, 0,0,0,0, 0,0,0);       for(int i=0; i<amnt; i++)    img = img->apply_matrix( ({ ({ 0, 1, 0 }),    ({ 1, 2, 1 }),    ({ 0, 1, 0 }) }) );    return img;
Roxen.git/server/modules/graphics/graphic_text.pike:351:    }          array (int) bgcolor = parse_color(args->bg);    array (int) fgcolor = parse_color(args->fg);       object background,foreground;          if(args->texture) { -  foreground = load_image(args->texture,id); +  foreground = roxen.load_image(args->texture,id);    if(args->tile)    {    object b2 = Image.image(xsize,ysize);    for(int x=0; x<xsize; x+=foreground->xsize())    for(int y=0; y<ysize; y+=foreground->ysize())    b2->paste(foreground, x, y);    foreground = b2;    } else if(args->mirrortile) {    object b2 = Image.image(xsize,ysize);    object b3 = Image.image(foreground->xsize()*2,foreground->ysize()*2);
Roxen.git/server/modules/graphics/graphic_text.pike:382:    b2->paste(foreground->mirrory(), x, y);    else    b2->paste(foreground, x, y);    foreground = foreground->mirrorx();    }    foreground = b2;    }    }    int background_is_color;    if(args->background && -  ((background = load_image(args->background, id)) || +  ((background = roxen.load_image(args->background, id)) ||    ((background=Image.image(xsize,ysize,    @(parse_color(args->background))))    && (background_is_color=1))))    {    object alpha; -  if(args->alpha && (alpha = load_image(args->alpha,id)) && background_is_color) +  if(args->alpha && (alpha = roxen.load_image(args->alpha,id)) && background_is_color)    {    xsize=MAX(xsize,alpha->xsize());    ysize=MAX(ysize,alpha->ysize());    if((float)args->scale && (float)args->scale != 1.0)    alpha=alpha->scale(1/(float)args->scale);    }       if(!args->nobgscale && (float)args->scale >= 0.1)    background = background->scale(1.0/(float)args->scale);   
Roxen.git/server/modules/graphics/graphic_text.pike:676:   string error_status;   void start(int|void val, object|void conf)   {    loaded = 1;       if(conf)    {    int id;    string cp = query( "cache_dir" ), na = "args";    mkdirhier( query( "cache_dir" )+"/.foo" ); -  if( query("cacheindb") ) -  { -  id = 1; -  cp = query("dbpath"); -  na = "gtext_arguments"; -  } -  mixed e; -  e = catch { -  argcache = conf->ArgCache( na, cp, id ); -  }; -  if( e ) -  { -  error_status = "Failed to initialize the GTEXT argument cache:\n" -  + (describe_backtrace( e )/"\n")[0]+"\n"; -  report_error( error_status ); -  werror( describe_backtrace( e ) ); -  error_status = "<font color=red size=+2>"+ -  html_encode_string(error_status)+"</font>"; -  } else -  error_status = 0; +     remove_call_out(clean_cache_dir);    call_out(clean_cache_dir, 10);    mc = conf;    base_key = "gtext:";    }   }    - mixed status() - { -  return error_status; - } -  +    #ifdef QUANT_DEBUG   void print_colors(array from)   {    for(int i=0; i<sizeof(from); i++)    perror("%d: %s\n", i, color_name(from[i]));   }   #endif      int number=0;   
Roxen.git/server/modules/graphics/graphic_text.pike:775:   }         array(int)|string write_text(string _args, string text, int size, object id)   {    string key = base_key+(cvs_version/" ")[2]+_args;    array err;    string orig_text = text;    mixed data;    int elapsed; -  mapping args = argcache->lookup( _args ) || ([]); +  mapping args = roxen.argcache.lookup( _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];
Roxen.git/server/modules/graphics/graphic_text.pike:975:    return 0;       if( query("gif") && f[strlen(f)-4..]==".gif") // Remove .gif    f = f[..strlen(f)-5];       if(!sizeof(f)) // No string to write.    return 0;       if(f[0] != '^')    { -  mapping t = argcache->lookup( f ); +  mapping t = roxen.argcache.lookup( f );    if(!t)    error("Invalid text identifier. Aborting\n");    f = t->t;    } else {    if(QUERY(allowgenericurls))    f = f[1..];    }    // Generate the image.    return http_string_answer(write_text(id,f,0,rid), "image/gif");   }      string quote(string in)   { -  return argcache->store( ([ "t":in ]) ); +  string id; +  werror("quote "+in+" -> "); +  id = roxen.argcache.store( ([ "t":in ]) ); +  werror("'"+id+"'\n"); +  return id;   }      string magic_javascript_header(object id)   {    if(!id->supports->netscape_javascript || !id->supports->images) return "";    return    ("\n<script>\n"    "function i(ri,hi,txt)\n"    "{\n"    " document.images[ri].src = hi.src;\n"
Roxen.git/server/modules/graphics/graphic_text.pike:1083:    arg->texture = fix_relative(arg->texture,id);    if(arg->magic_texture)    arg->magic_texture=fix_relative(arg->magic_texture,id);    if(arg->magic_background)    arg->magic_background=fix_relative(arg->magic_background,id);    if(arg->magicbg)    arg->magicbg = fix_relative(arg->magicbg,id);    if(arg->alpha)    arg->alpha = fix_relative(arg->alpha,id);    -  string id = argcache->store( arg ); +  string id = roxen.argcache.store( arg );       if(!short)    return query_location()+id+"/^";    else    return id;   }      string tag_graphicstext(string t, mapping arg, string contents,    object id, object foo, mapping defines)   {
Roxen.git/server/modules/graphics/graphic_text.pike:1203:    }       // Support for <gh1> like things.    if(sscanf(t, "%s%d", t, i)==2)    if(i > 1) arg->scale = 1.0 / ((float)i*0.6);       string na = arg->name, al=arg->align;    m_delete(arg, "name"); m_delete(arg, "align");       // Now the 'arg' mapping is modified enough.. -  string num = argcache->store( arg ); +  string num = roxen.argcache.store( arg );       gt=contents;    rest="";       switch(t)    {    case "gh1": case "gh2": case "gh3": case "gh4":    case "gh5": case "gh6": case "gh7":    case "gh": pre="<p>"; post="<br>"; defalign="top"; break;    case "gtext":
Roxen.git/server/modules/graphics/graphic_text.pike:1295:    arg->fg = defines->alink||"#ff0000";    if(arg->magicbg) arg->background = arg->magicbg;    if(arg->bevel) arg->pressed=1;       foreach(glob("magic_*", indices(arg)), string q)    {    arg[q[6..]]=arg[q];    m_delete(arg, q);    }    -  string num2 = argcache->store( arg ); +  string num2 = roxen.argcache.store( arg );    array size = write_text(num2,gt,1,id);       if(!defines->magic_java) res = magic_javascript_header(id);    defines->magic_java="yes";       return replace(res +    magic_image(url||"", size[0], size[1], "i"+(defines->mi++),    query_location()+num+"/"+quote(gt)+gif,    query_location()+num2+"/"+quote(gt)+gif,    (arg->alt?arg->alt:replace(gt, "\"","'")),