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.96 1998/01/17 02:57:24 grubba Exp $"; + constant cvs_version="$Id: graphic_text.pike,v 1.97 1998/01/26 08:22:08 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
Roxen.git/server/modules/graphics/graphic_text.pike:57:    " split=char Split the string also at CHAR\n"    " href=url Link the image to the specified URL\n"    " The 'link' color of the document will be\n"    " used as the default foreground of the text\n"    " alt=message Sets the 'alt' attribute.\n"    " Use alt=\"\" if no alternate message is wanted.\n"    " quant=cols Use this number of colors\n"    " magic[=message] Modifier to href, more flashy links\n"    " Does <b>not</b> work with 'split'\n"    " magicbg=bg As background, but for the 'magic' image\n" +  " magic_X same as X, where X is any other argument,\n" +  " but for the 'magic' image.\n"    " fuzz[=color] Apply the 'glow' effect to the result\n"    " fs Use floyd-steinberg dithering\n"    " border=int,col. Draw an border (width is the first argument\n"    " in the specified color\n"    " spacing=int Add this amount of spacing around the text\n"    " xspacing=int like spacing, but only horizontal\n"    " yspacing=int like spacing, but only vertical\n"    " size=int,int Use this (absolute) size\n"    " xsize=int Use this (absolute) size\n"    " ysize=int Use this (absolute) size\n"
Roxen.git/server/modules/graphics/graphic_text.pike:121:    catch(fnts = get_dir("fonts/32/") - ({".",".."}));    if(!fnts)    {    return ({});    }    return fnts;   }      void create()   { +  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;");       defvar("deflen", 300, "Default maximum text-length", TYPE_INT|VAR_MORE,    "The module will, per default, not try to render texts "    "longer than this. This is a safeguard for things like "
Roxen.git/server/modules/graphics/graphic_text.pike:603:    return background;   }      string base_key;   object mc;      void start(int|void val, object|void conf)   {    if(conf)    { +  mkdirhier( query( "cache_dir" )+".foo" );    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++)    perror("%d: %s\n", i, color_name(from[i]));   #endif   }   #endif      int number=0;      mapping find_cached_args(int num);    -  +  + #if !constant(iso88591) + constant iso88591 + =([ "&nbsp;": " ", "&iexcl;": "¡", "&cent;": "¢", "&pound;": "£", +  "&curren;": "¤", "&yen;": "¥", "&brvbar;": "¦", "&sect;": "§", +  "&uml;": "¨", "&copy;": "©", "&ordf;": "ª", "&laquo;": "«", +  "&not;": "¬", "&shy;": "­", "&reg;": "®", "&macr;": "¯", +  "&deg;": "°", "&plusmn;": "±", "&sup2;": "²", "&sup3;": "³", +  "&acute;": "´", "&micro;": "µ", "&para;": "¶", "&middot;": "·", +  "&cedil;": "¸", "&sup1;": "¹", "&ordm;": "º", "&raquo;": "»", +  "&frac14;": "¼", "&frac12;": "½", "&frac34;": "¾", "&iquest;": "¿", +  "&Agrave;": "À", "&Aacute;": "Á", "&Acirc;": "Â", "&Atilde;": "Ã", +  "&Auml;": "Ä", "&Aring;": "Å", "&AElig;": "Æ", "&Ccedil;": "Ç", +  "&Egrave;": "È", "&Eacute;": "É", "&Ecirc;": "Ê", "&Euml;": "Ë", +  "&Igrave;": "Ì", "&Iacute;": "Í", "&Icirc;": "Î", "&Iuml;": "Ï", +  "&ETH;": "Ð", "&Ntilde;": "Ñ", "&Ograve;": "Ò", "&Oacute;": "Ó", +  "&Ocirc;": "Ô", "&Otilde;": "Õ", "&Ouml;": "Ö", "&times;": "×", +  "&Oslash;": "Ø", "&Ugrave;": "Ù", "&Uacute;": "Ú", "&Ucirc;": "Û", +  "&Uuml;": "Ü", "&Yacute;": "Ý", "&THORN;": "Þ", "&szlig;": "ß", +  "&agrave;": "à", "&aacute;": "á", "&acirc;": "â", "&atilde;": "ã", +  "&auml;": "ä", "&aring;": "å", "&aelig;": "æ", "&ccedil;": "ç", +  "&egrave;": "è", "&eacute;": "é", "&ecirc;": "ê", "&euml;": "ë", +  "&igrave;": "ì", "&iacute;": "í", "&icirc;": "î", "&iuml;": "ï", +  "&eth;": "ð", "&ntilde;": "ñ", "&ograve;": "ò", "&oacute;": "ó", +  "&ocirc;": "ô", "&otilde;": "õ", "&ouml;": "ö", "&divide;": "÷", +  "&oslash;": "ø", "&ugrave;": "ù", "&uacute;": "ú", "&ucirc;": "û", +  "&uuml;": "ü", "&yacute;": "ý", "&thorn;": "þ", "&yuml;": "ÿ", + ]); + #endif +  +  +    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)    -  +  + array get_cache_file(string a, string b) + { +  object fd = open(query("cache_dir")+ +  sprintf("%x",hash(reverse(a)))+sprintf("%x",hash(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"); +  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;    err = catch    {    object img;    mapping args = find_cached_args(_args);    if(!args)
Roxen.git/server/modules/graphics/graphic_text.pike:683:    }    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;    } -  if(args->nocache) // Remove from cache. Very usable for access counters + // 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"),
Roxen.git/server/modules/graphics/graphic_text.pike:732: Inside #if efun(get_font)
   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);    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) return 0; +  if(!img) { + // werror("error while drawing image? (no image) < "+_args+" <"+text+">\n"); +  cache_set(key, 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
Roxen.git/server/modules/graphics/graphic_text.pike:804:    {    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);    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)   {    int id;    sscanf(f,"%d/%s", id, f);   
Roxen.git/server/modules/graphics/graphic_text.pike:1080:    contents = parse_rxml(contents, id, foo, defines);   #else    contents = parse_rxml(contents, id, foo);   #endif       string lp, url, ea;    string pre, post, defalign, gt, rest, magic;    int i;    string split;    -  if(arg->alternatives) -  { -  mapping arg_list = (["list":({})]); -  parse_html(contents,(["on":internal_tag_on]), -  (["text":internal_tag_text, ]), arg_list, id, defines); + // if(arg->alternatives) + // { + // mapping arg_list = (["list":({})]); + // parse_html(contents,(["on":internal_tag_on]), + // (["text":internal_tag_text, ]), arg_list, id, defines);    -  string js = "", href=""; -  mapping img_tag_args = ([]); -  array(int) nums = ({}); -  foreach(arg_list->list, mapping q) -  { -  mapping w = copy_value(q); -  m_delete(w, "text"); m_delete(w, "type"); m_delete(w, "delay"); -  m_delete(w, "href"); m_delete(w, "name"); m_delete(w, "align"); -  nums += ({ find_or_insert( w ) }); -  if(q->align) img_tag_args->align = q->align; -  if(q->name) img_tag_args->name = q->name; -  if(q->href) href = make_tag("a", (["href":q->href, "name":q->name])); -  } -  } + // string js = "", href=""; + // mapping img_tag_args = ([]); + // array(int) nums = ({}); + // foreach(arg_list->list, mapping q) + // { + // mapping w = copy_value(q); + // m_delete(w, "text"); m_delete(w, "type"); m_delete(w, "delay"); + // m_delete(w, "href"); m_delete(w, "name"); m_delete(w, "align"); + // nums += ({ find_or_insert( w ) }); + // if(q->align) img_tag_args->align = q->align; + // if(q->name) img_tag_args->name = q->name; + // if(q->href) href = make_tag("a", (["href":q->href, "name":q->name])); + // } + // }       // No images here, let's generate an alternative..    if(!id->supports->images || id->prestate->noimages)    {    if(!arg->split) contents=replace(contents,"\n", "\n<br>\n");    if(arg->submit) return "<input type=submit name=\""+(arg->name+".x")    + "\" value=\""+contents+"\">";    switch(t)    {    case "gtext":
Roxen.git/server/modules/graphics/graphic_text.pike:1277:    {    if(arg->fuzz != "fuzz")    arg->glow = arg->fuzz;    else    arg->glow = arg->fg;    }    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); +  } +     int num2 = find_or_insert(arg);    array size = write_text(num2,gt,1,id);       if(!defines->magic_java) res = magic_javascript_header(id);    defines->magic_java="yes";       return res +    magic_image(url||"", size[0], size[1], "i"+(defines->mi++),    query_location()+num+"/"+quote(gt)+gif,    query_location()+num2+"/"+quote(gt)+gif,