e954162000-01-02Martin Nilsson // This is a roxen module. Copyright © 1996 - 1999, Idonex AB. // constant cvs_version="$Id: graphic_text.pike,v 1.198 2000/01/02 01:29:21 nilsson Exp $";
85e8321997-08-31Peter Bortas constant thread_safe=1;
ebf60d1997-03-08Henrik Grubbström (Grubba) 
0595091999-03-12Martin Stjernholm #include <config.h>
d47cbf1996-12-02Per Hedbor #include <module.h>
e5bad21998-02-10Per Hedbor #include <stat.h>
d47cbf1996-12-02Per Hedbor inherit "module"; inherit "roxenlib";
a3dfd41999-11-28Martin Nilsson  // ------------------- Module registration ---------------------
654fca1999-10-04Martin Bähr 
d47cbf1996-12-02Per Hedbor array register_module() {
9374e61999-05-18Per Hedbor  return ({ MODULE_PARSER,
5670551998-06-09Peter Bortas  "Graphics text",
a3dfd41999-11-28Martin Nilsson  "Generates graphical texts.",
5670551998-06-09Peter Bortas  0, 1
a5c21b1999-05-18Peter Bortas  });
0a76aa1998-03-27David Hedbor }
d47cbf1996-12-02Per Hedbor void create() {
39af1a1998-08-26Per Hedbor  defvar("colorparse", 1, "Parse tags for document colors", TYPE_FLAG, "If set, parse the specified tags for document colors.");
a3dfd41999-11-28Martin Nilsson 
c97c421998-08-20Per Hedbor  defvar("colorparsing", ({"body", "td", "layer", "ilayer", "table"}),
a3dfd41999-11-28Martin Nilsson  "Tags to parse for color",
c97c421998-08-20Per Hedbor  TYPE_STRING_LIST, "Which tags should be parsed for document colors? " "This will affect documents without gtext as well as documents " "with it, the parsing time is relative to the number of parsed " "tags in a document. You have to reload this module or restart "
39af1a1998-08-26Per Hedbor  "roxen for changes of this variable to take effect.", 0, lambda(){return !query("colorparse");});
c97c421998-08-20Per Hedbor  defvar("colormode", 1, "Normalize colors in parsed tags", TYPE_FLAG, "If set, replace 'roxen' colors (@c,m,y,k etc) with "
39af1a1998-08-26Per Hedbor  "'netscape' colors (#rrggbb). Setting this to off will lessen the "
c97c421998-08-20Per Hedbor  "performance impact of the 'Tags to parse for color' option quite"
39af1a1998-08-26Per Hedbor  " dramatically. You can try this out with the &lt;gauge&gt; tag.", 0, lambda(){return !query("colorparse");});
a3dfd41999-11-28Martin Nilsson 
9b9f701997-08-12Per Hedbor  defvar("deflen", 300, "Default maximum text-length", TYPE_INT|VAR_MORE,
bfc7071997-01-13Per Hedbor  "The module will, per default, not try to render texts " "longer than this. This is a safeguard for things like " "&lt;gh1&gt;&lt;/gh&gt;, which would otherwise parse the" " whole document. This can be overrided with maxlen=... in the " "tag.");
a3dfd41999-11-28Martin Nilsson  defvar("ext", 0, "Append .fmt (gif, jpeg etc) to all images",
8b6ee51999-07-10Peter Bortas  TYPE_FLAG|VAR_MORE,
9374e61999-05-18Per Hedbor  "Append .gif, .png, .gif etc to all images made by gtext. " "Normally this will only waste bandwidth");
d47cbf1996-12-02Per Hedbor }
f02c0c1999-12-11Martin Nilsson TAGDOCUMENTATION;
2e0a351999-12-09Martin Nilsson #ifdef manual constant gtextargs=""; constant tagdoc=(["gtext":"<desc cont></desc>"+gtextargs, "gtext-id":"<desc tag></desc>"+gtextargs, "anfang":"<desc cont></desc>"+gtextargs, "gtext-url":"<desc cont></desc>"+gtextargs, "gh":"<desc cont></desc>"+gtextargs, "gh1":"<desc cont></desc>"+gtextargs, "gh2":"<desc cont></desc>"+gtextargs, "gh3":"<desc cont></desc>"+gtextargs, "gh4":"<desc cont></desc>"+gtextargs, "gh5":"<desc cont></desc>"+gtextargs, "gh6":"<desc cont></desc>"+gtextargs]); #endif
a3dfd41999-11-28Martin Nilsson  // -------------------- Image cache functions --------------------
9374e61999-05-18Per Hedbor roxen.ImageCache image_cache;
e5bad21998-02-10Per Hedbor 
e954162000-01-02Martin Nilsson string status() { array s=image_cache->status(); return sprintf("<b>Images in cache:</b> %d images<br>\n<b>Cache size:</b> %s", s[0]/2, sizetostring(s[1])); }
38569c1999-12-07Martin Nilsson void start()
2468b21997-07-06Henrik Grubbström (Grubba) {
9374e61999-05-18Per Hedbor  image_cache = roxen.ImageCache( "gtext", draw_callback );
2468b21997-07-06Henrik Grubbström (Grubba) }
c3655b1997-01-27Per Hedbor 
b1ab8d1997-12-23Per Hedbor constant nbsp = iso88591["&nbsp;"];
db46c81999-06-10Jonas Wallden constant replace_from = indices( iso88591 )+ ({"&ss;","&lt;","&gt;","&amp;",});
a3dfd41999-11-28Martin Nilsson constant replace_to = values( iso88591 ) + ({ nbsp, "<", ">", "&", });
b1ab8d1997-12-23Per Hedbor  #define simplify_text( from ) replace(from,replace_from,replace_to)
06583f1997-09-03Per Hedbor 
a3dfd41999-11-28Martin Nilsson mixed draw_callback(mapping args, string text, RequestID id)
20ca2b1998-01-26Per Hedbor {
f02c0c1999-12-11Martin Nilsson  array data; Image.Font font;
38569c1999-12-07Martin Nilsson  Image.Image img;
9374e61999-05-18Per Hedbor 
6a9b9d1999-06-25Per Hedbor  if( objectp( text ) ) { if( !args->text ) error("Failed miserably to find a text to draw. That's not"
8b6ee51999-07-10Peter Bortas  " good.\n");
6a9b9d1999-06-25Per Hedbor  id = (object)text; text = args->text; }
9374e61999-05-18Per Hedbor  if(!args->verbatim) // typographically correct...
ba73a21996-12-10Per Hedbor  {
9374e61999-05-18Per Hedbor  text = replace(text, nbsp, " "); text = simplify_text( text ); string res="",nspace="",cspace=""; foreach(text/"\n", string line)
a5c21b1999-05-18Peter Bortas  {
38569c1999-12-07Martin Nilsson  cspace=""; nspace="";
9374e61999-05-18Per Hedbor  foreach(line/" ", string word)
e8c29c1997-09-12Johan Schön  {
9374e61999-05-18Per Hedbor  string nonum; if(strlen(word) && (nonum = replace(word, ({"1","2","3","4","5","6","7","8","9","0","."}), ({"","","","","","","","","","",""}))) == "") { cspace=nbsp+nbsp; if((strlen(word)-strlen(nonum)<strlen(word)/2) &&
38569c1999-12-07Martin Nilsson  (upper_case(word) == word))
9374e61999-05-18Per Hedbor  word=((word/"")*nbsp); }
38569c1999-12-07Martin Nilsson  else if(cspace!="") cspace=" ";
9374e61999-05-18Per Hedbor  res+=(nspace==cspace?nspace:" ")+word;
38569c1999-12-07Martin Nilsson  if(cspace!="") nspace=cspace; else nspace=" ";
1cd5eb1998-03-20Per Hedbor  }
9374e61999-05-18Per Hedbor  res+="\n";
1cd5eb1998-03-20Per Hedbor  }
9374e61999-05-18Per Hedbor  text=replace(res[..strlen(res)-2], ({"!","?",": "}),({ nbsp+"!",nbsp+"?",nbsp+": "}));
a3dfd41999-11-28Martin Nilsson  text=replace(replace(replace(text,({". ",". "+nbsp}),
9374e61999-05-18Per Hedbor  ({"\000","\001"})),".","."+nbsp+nbsp), ({"\000","\001"}),({". ","."+nbsp})); }
e8c29c1997-09-12Johan Schön 
9374e61999-05-18Per Hedbor  if( args->afont )
f02c0c1999-12-11Martin Nilsson  font = resolve_font(args->afont+" "+(args->font_size||32));
9374e61999-05-18Per Hedbor  else
a5c21b1999-05-18Peter Bortas  {
9374e61999-05-18Per Hedbor  if(!args->nfont) args->nfont = args->font;
38569c1999-12-07Martin Nilsson  int bold=0, italic=0;
9374e61999-05-18Per Hedbor  if(args->bold) bold=1; if(args->light) bold=-1; if(args->black) bold=2; if(args->italic) italic=1;
f02c0c1999-12-11Martin Nilsson  font = get_font(args->nfont||"default",
9374e61999-05-18Per Hedbor  (int)args->font_size||32,bold,italic, lower_case(args->talign||"left"), (float)(int)args->xpad, (float)(int)args->ypad);
a5c21b1999-05-18Peter Bortas  }
974b2a1997-10-02Peter Bortas 
f02c0c1999-12-11Martin Nilsson  if (!font)
9374e61999-05-18Per Hedbor  error("gtext: No font!\n");
1a67581997-09-26Henrik Grubbström (Grubba) 
9374e61999-05-18Per Hedbor  // Fonts and such are now initialized.
742aab1999-12-14Martin Nilsson  img = GText.make_text_image(args, font, text, id);
9558e31998-07-04Per Hedbor 
e954162000-01-02Martin Nilsson  // Now we have the image in 'img'.
a5c21b1999-05-18Peter Bortas 
9374e61999-05-18Per Hedbor  if( !args->scroll && !args->fadein ) { if(!args->notrans)
a5c21b1999-05-18Peter Bortas  {
b89ccb1999-11-28Martin Nilsson  array (int) bgcolor = parse_color(args->bgcolor);
f02c0c1999-12-11Martin Nilsson  Image.Image alpha;
9374e61999-05-18Per Hedbor  alpha = img->distancesq( @bgcolor ); alpha->gamma( 8 ); return ([ "img":img, "alpha":alpha ]);
a5c21b1999-05-18Peter Bortas  }
9374e61999-05-18Per Hedbor  return img; }
a5c21b1999-05-18Peter Bortas 
9374e61999-05-18Per Hedbor  if(args->fadein)
a5c21b1999-05-18Peter Bortas  {
9374e61999-05-18Per Hedbor  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)
a5c21b1999-05-18Peter Bortas  {
f02c0c1999-12-11Martin Nilsson  Image.Image foo=Image.Image(img->xsize(),img->ysize(),@parse_color(args->bgcolor));
9374e61999-05-18Per Hedbor  res += foo->gif_add(0,0,initialdelay);
a5c21b1999-05-18Peter Bortas  }
9374e61999-05-18Per Hedbor  for(int i = 0; i<(steps-1); i++) {
f02c0c1999-12-11Martin Nilsson  Image.Image foo=img->clone();
742aab1999-12-14Martin Nilsson  foo = foo->apply_matrix(GText.make_matrix(( (int)((steps-i)*amount))));
9374e61999-05-18Per Hedbor  res += foo->gif_add(0,0,delay);
a5c21b1999-05-18Peter Bortas  }
f02c0c1999-12-11Martin Nilsson  res += img->gif_add(0,0,delay);
9374e61999-05-18Per Hedbor  res += img->gif_end(); data = ({ res, ({ img->xsize(), img->ysize() }) });
a5c21b1999-05-18Peter Bortas  }
a3dfd41999-11-28Martin Nilsson  else
a5c21b1999-05-18Peter Bortas  {
9374e61999-05-18Per Hedbor  int len=100, steps=30, delay=5, ox; string res = img->gif_begin() + img->gif_netscape_loop(); sscanf(args->scroll, "%d,%d,%d", len, steps, delay); img=img->copy(0,0,(ox=img->xsize())+len-1,img->ysize()-1); img->paste(img, ox, 0); for(int i = 0; i<steps; i++) { int xp = i*ox/steps; res += img->copy(xp, 0, xp+len, img->ysize(),
b89ccb1999-11-28Martin Nilsson  @parse_color(args->bgcolor))->gif_add(0,0,delay);
9374e61999-05-18Per Hedbor  } res += img->gif_end(); data = ({ res, ({ len, img->ysize() }) });
a5c21b1999-05-18Peter Bortas  }
a3dfd41999-11-28Martin Nilsson  return ([ "data":data[0],
df8c031999-05-25Per Hedbor  "meta":
9374e61999-05-18Per Hedbor  ([ "xsize":data[1][0], "ysize":data[1][1],
a3dfd41999-11-28Martin Nilsson  "type":(args->format?id->conf->type_from_filename("x."+args->format):"image/gif"),
9374e61999-05-18Per Hedbor  ]) ]);
68e0301997-08-19Per Hedbor }
f02c0c1999-12-11Martin Nilsson mapping find_internal(string f, RequestID id)
a5c21b1999-05-18Peter Bortas {
a3dfd41999-11-28Martin Nilsson  if( strlen(f)>4 && query("ext") && f[-4]=='.') // Remove .ext
9374e61999-05-18Per Hedbor  f = f[..strlen(f)-5];
0ee5ab1999-09-05Per Hedbor  if( strlen(f) && f[0]=='$' )
8b6ee51999-07-10Peter Bortas  { array id_text = f/"/"; if( sizeof(id_text)==2 ) { // It's a gtext-id
0ee5ab1999-09-05Per Hedbor  string second_key = roxen->argcache->store( (["":id_text[1]]) );
f02c0c1999-12-11Martin Nilsson  return image_cache->http_file_answer( id_text[0][1..] +"$"+ second_key, id );
8b6ee51999-07-10Peter Bortas  } }
f02c0c1999-12-11Martin Nilsson  return image_cache->http_file_answer( f, id );
a5c21b1999-05-18Peter Bortas }
d47cbf1996-12-02Per Hedbor 
a3dfd41999-11-28Martin Nilsson // -------------- helpfunctions to gtext tags and containers -----------------
b89ccb1999-11-28Martin Nilsson constant filearg=({"background","texture","alpha","magic-texture","magic-background","magic-alpha"});
a3dfd41999-11-28Martin Nilsson constant textarg=({"afont", "alpha", "bevel",
b89ccb1999-11-28Martin Nilsson  "bgcolor",
a3dfd41999-11-28Martin Nilsson  "black", "bold", "bshadow", "chisel", "crop", "encoding", "fadein",
b89ccb1999-11-28Martin Nilsson  "fgcolor",
a3dfd41999-11-28Martin Nilsson  "fs", "font", "font_size", "format", "ghost", "glow", "italic", "light", "mirrortile",
c3aacd1999-12-06Peter Bortas  "move",
a3dfd41999-11-28Martin Nilsson  "narrow", "nfont", "notrans", "opaque", "outline", "pressed", "quant", "rescale", "rotate", "scale", "scolor", "scroll", "shadow", "size", "spacing", "talign", "tile", "textbox", "textbelow", "textscale", "turbulence", "verbatim", "xpad", "xsize", "xspacing", "ypad", "ysize", "yspacing" }); mapping mk_gtext_arg(mapping arg, RequestID id) { mapping p=([]); //Picture rendering arguments. foreach(filearg, string tmp) if(arg[tmp]) { p[tmp]=fix_relative(arg[tmp],id); m_delete(arg,tmp); }
d47cbf1996-12-02Per Hedbor 
b89ccb1999-11-28Martin Nilsson  if(arg->border && search(arg->border,",")) { p->border=arg->border; m_delete(arg,"border"); }
a3dfd41999-11-28Martin Nilsson  foreach(textarg, string tmp) if(arg[tmp]) { p[tmp]=arg[tmp],id; m_delete(arg,tmp); }
d47cbf1996-12-02Per Hedbor 
e954162000-01-02Martin Nilsson  if(id->misc->gtext_fgcolor && !p->fgcolor) p->fgcolor=id->misc->gtext_fgcolor; if(id->misc->gtext_bgcolor && !p->bgcolor) p->bgcolor=id->misc->gtext_bgcolor; if(id->misc->gtext_nfont && !p->nfont) p->nfont=id->misc->gtext_nfont; if(id->misc->gtext_afont && !p->afont) p->afont=id->misc->gtext_afont; if(id->misc->gtext_font && !p->font) p->font=id->misc->gtext_font; if(id->misc->gtext_bold && !p->bold) p->bold=id->misc->gtext_bold; if(id->misc->gtext_italic && !p->italic) p->italic=id->misc->gtext_italic; if(id->misc->gtext_black && !p->black) p->black=id->misc->gtext_black; if(id->misc->gtext_narrow && !p->narrow) p->narrow=id->misc->gtext_narrow;
a3dfd41999-11-28Martin Nilsson  return p;
d47cbf1996-12-02Per Hedbor }
a3dfd41999-11-28Martin Nilsson string fix_text(string c, mapping m, RequestID id) {
b91fd51996-12-10Per Hedbor 
a3dfd41999-11-28Martin Nilsson  if(m->nowhitespace)
b91fd51996-12-10Per Hedbor  {
a3dfd41999-11-28Martin Nilsson  sscanf(c,"%*[ \n\r\t]%s",c); sscanf(reverse(c),"%*[ \n\r\t]%s",c); c=reverse(c); m_delete(m, "nowhitespace"); } if(!m->noparse && !m->preparse) c = parse_rxml(c, id); else { m_delete(m, "noparse"); m_delete(m, "preparse");
b91fd51996-12-10Per Hedbor  }
a3dfd41999-11-28Martin Nilsson  c = c[..(((int)m->maxlen||QUERY(deflen))-1)]; m_delete(m, "maxlen"); return c;
b91fd51996-12-10Per Hedbor }
a3dfd41999-11-28Martin Nilsson  // ----------------- gtext tags and containers -------------------
f02c0c1999-12-11Martin Nilsson string container_gtext_url(string t, mapping arg, string c, RequestID id) {
a3dfd41999-11-28Martin Nilsson  c=fix_text(c,arg,id); mapping p=mk_gtext_arg(arg,id);
e954162000-01-02Martin Nilsson  if(arg->href && !p->fgcolor) p->fgcolor=id->misc->gtext_link||"#0000ff";
a3dfd41999-11-28Martin Nilsson  string ext=""; if(query("ext")) ext="."+(p->format || "gif"); if(!arg->short) return query_internal_location()+image_cache->store( ({p,c}), id )+ext;
f02c0c1999-12-11Martin Nilsson  return "+"+image_cache->store( ({p,c}), id )+ext;
8b6ee51999-07-10Peter Bortas }
a3dfd41999-11-28Martin Nilsson string tag_gtext_id(string t, mapping arg, RequestID id) { mapping p=mk_gtext_arg(arg,id);
e954162000-01-02Martin Nilsson  if(arg->href && !p->fgcolor) p->fgcolor=id->misc->gtext_link||"#0000ff";
a3dfd41999-11-28Martin Nilsson  if(!arg->short) return query_internal_location()+"$"+image_cache->store(p, id)+"/";
f02c0c1999-12-11Martin Nilsson  return "+"+image_cache->store(p, id )+"/foo";
07969c1997-02-25Per Hedbor }
f02c0c1999-12-11Martin Nilsson string container_gtext(string t, mapping arg, string c, RequestID id)
62d8c41997-10-16Per Hedbor {
e954162000-01-02Martin Nilsson  if((c-" ")=="") return "";
033c7e1997-02-27Per Hedbor 
a3dfd41999-11-28Martin Nilsson  c=fix_text(c,arg,id); mapping p=mk_gtext_arg(arg,id);
d47cbf1996-12-02Per Hedbor 
a3dfd41999-11-28Martin Nilsson  string ext=""; if(query("ext")) ext="."+(p->format || "gif");
bfc7071997-01-13Per Hedbor 
a3dfd41999-11-28Martin Nilsson  string lp="%s", url="", ea="";
38dca81996-12-10Per Hedbor 
e954162000-01-02Martin Nilsson  int input=0;
38dca81996-12-10Per Hedbor  if(arg->submit) { input=1; m_delete(arg,"submit"); }
bfc7071997-01-13Per Hedbor 
a3dfd41999-11-28Martin Nilsson  if(!arg->noxml) { arg["/"]="/"; m_delete(arg, "noxml"); } if(!arg->border) arg->border=arg->border||"0";
bfc7071997-01-13Per Hedbor 
d47cbf1996-12-02Per Hedbor  if(arg->href) { url = arg->href;
b89ccb1999-11-28Martin Nilsson  lp = replace(make_tag("a",arg),"%","%%")+"%s</a>";
e954162000-01-02Martin Nilsson  if(!p->fgcolor) p->fgcolor=id->misc->gtext_link||"#0000ff";
0943711997-02-25Per Hedbor  m_delete(arg, "href");
d47cbf1996-12-02Per Hedbor  } if(arg->split) {
a3dfd41999-11-28Martin Nilsson  string res="",split=arg->split; if(lower_case(split)=="split") split=" ";
d47cbf1996-12-02Per Hedbor  m_delete(arg,"split");
a3dfd41999-11-28Martin Nilsson  c=replace(c, "\n", " "); int setalt=!arg->alt; foreach(c/split-({""}), string word)
d47cbf1996-12-02Per Hedbor  {
a3dfd41999-11-28Martin Nilsson  string fn = image_cache->store( ({ p, word }),id );
9374e61999-05-18Per Hedbor  mapping size = image_cache->metadata( fn, id, 1 );
a3dfd41999-11-28Martin Nilsson  if(setalt) arg->alt=word; arg->src=query_internal_location()+fn+ext;
9374e61999-05-18Per Hedbor  if( size ) {
a3dfd41999-11-28Martin Nilsson  arg->width = (string)size->xsize; arg->height = (string)size->ysize;
1bd5c91997-09-26Henrik Grubbström (Grubba)  }
a3dfd41999-11-28Martin Nilsson  res+=make_tag( "img", arg )+" ";
d47cbf1996-12-02Per Hedbor  }
a3dfd41999-11-28Martin Nilsson  return sprintf(lp,res);
d47cbf1996-12-02Per Hedbor  }
a3dfd41999-11-28Martin Nilsson  string num = image_cache->store( ({ p, c }), id );
6a9b9d1999-06-25Per Hedbor  mapping size = image_cache->metadata( num, id, 1 );
a3dfd41999-11-28Martin Nilsson  if(!arg->alt) arg->alt=replace(c,"\"","'");
f1be801998-02-22Per Hedbor 
a3dfd41999-11-28Martin Nilsson  arg->src=query_internal_location()+num+ext; if(size) { arg->width=size->xsize; arg->height=size->ysize; } if(arg->magic)
d47cbf1996-12-02Per Hedbor  {
a3dfd41999-11-28Martin Nilsson  string magic=replace(arg->magic,"'","`"); m_delete(arg,"magic");
e954162000-01-02Martin Nilsson  if(!arg->fgcolor) p->fgcolor=id->misc->gtext_alink||"#ff0000";
a3dfd41999-11-28Martin Nilsson  if(p->bevel) p->pressed=1; foreach(glob("magic-*", indices(arg)), string q)
20ca2b1998-01-26Per Hedbor  {
a3dfd41999-11-28Martin Nilsson  p[q[6..]]=arg[q];
20ca2b1998-01-26Per Hedbor  m_delete(arg, q); }
a3dfd41999-11-28Martin Nilsson  string num2 = image_cache->store( ({ p, c }),id );
6a9b9d1999-06-25Per Hedbor  size = image_cache->metadata( num2, id );
a3dfd41999-11-28Martin Nilsson  if(size) {
f02c0c1999-12-11Martin Nilsson  arg->width=max(arg->xsize,size->xsize); arg->height=max(arg->ysize,size->ysize);
a3dfd41999-11-28Martin Nilsson  } if(!id->supports->images) return sprintf(lp,arg->alt);
0943711997-02-25Per Hedbor 
e954162000-01-02Martin Nilsson  string sn="i"+id->misc->gtext_mi++;
a3dfd41999-11-28Martin Nilsson  if(!id->supports->netscape_javascript) { return (!input)? ("<a "+ea+"href=\""+url+"\">"+make_tag("img",arg+(["name":sn]))+"</a>"): make_tag("input",arg+(["type":"image"])); } arg->name=sn;
e954162000-01-02Martin Nilsson  string res="\n<script>\n"; if(!id->misc->gtext_magic_java) {
a3dfd41999-11-28Martin Nilsson  res += "function i(ri,hi,txt)\n" "{\n" " document.images[ri].src = hi.src;\n" " setTimeout(\"top.window.status = '\"+txt+\"'\", 100);\n" "}\n";
e954162000-01-02Martin Nilsson  } id->misc->gtext_magic_java="yes";
a3dfd41999-11-28Martin Nilsson  return res+ " "+sn+"l = new Image("+arg->width+", "+arg->height+");"+sn+"l.src = \""+arg->src+"\";\n" " "+sn+"h = new Image("+arg->width+", "+arg->height+");"+sn+"h.src = \""+query_internal_location()+num2+ext+"\";\n"
e954162000-01-02Martin Nilsson  "</script>\n"+
a3dfd41999-11-28Martin Nilsson  "<a "+ea+"href=\""+url+"\" "+ (input?"onClick='document.forms[0].submit();' ":"")
e954162000-01-02Martin Nilsson  +"onMouseover=\"i('"+sn+"',"+sn+"h,'"+(magic=="magic"?url:magic)+"'); return true;\" "
a3dfd41999-11-28Martin Nilsson  "onMouseout=\"top.window.status='';document.images['"+sn+"'].src = "+sn+"l.src;\">" +make_tag("img",arg)+"</a>";
d47cbf1996-12-02Per Hedbor  }
a3dfd41999-11-28Martin Nilsson 
ca0f081997-02-22Per Hedbor  if(input)
a3dfd41999-11-28Martin Nilsson  return make_tag("input",arg+(["type":"image"])); return sprintf(lp,make_tag("img",arg));
d47cbf1996-12-02Per Hedbor }
f02c0c1999-12-11Martin Nilsson array(string) container_gh(string t, mapping m, string c, RequestID id) {
a3dfd41999-11-28Martin Nilsson  int i; if(sscanf(t, "%s%d", t, i)==2 && i>1) m->scale = (string)(1.0 / ((float)i*0.6)); if(!m->valign) m->valign="top";
f02c0c1999-12-11Martin Nilsson  return ({ "<p>"+container_gtext("",m,c,id)+"<br>" });
a3dfd41999-11-28Martin Nilsson }
f02c0c1999-12-11Martin Nilsson array(string) container_anfang(string t, mapping m, string c, RequestID id) {
a3dfd41999-11-28Martin Nilsson  if(!m->align) m->align="left";
f02c0c1999-12-11Martin Nilsson  return ({ "<br clear=\"left\">"+container_gtext("",m,c[0..0],id)+c[1..] });
a3dfd41999-11-28Martin Nilsson } // ------------ Wiretap code to find HTML-colours ---------------------
bfc7071997-01-13Per Hedbor inline string ns_color(array (int) col) { if(!arrayp(col)||sizeof(col)!=3) return "#000000"; return sprintf("#%02x%02x%02x", col[0],col[1],col[2]); }
e954162000-01-02Martin Nilsson int|array (string) tag_body(string t, mapping args, RequestID id)
d47cbf1996-12-02Per Hedbor {
38569c1999-12-07Martin Nilsson  int changed=0; int cols=(args->bgcolor||args->text||args->link||args->alink||args->vlink);
bfc7071997-01-13Per Hedbor 
e954162000-01-02Martin Nilsson #define FIX(Y,Z,X) do{ \ if(!args->Y || args->Y==""){ \ id->misc["gtext_"+X]=Z; \ if(cols){ \ args->Y=Z; \ changed=1; \ } \ } \ else{ \ id->misc["gtext_"+X]=args->Y; \ if(QUERY(colormode)&&args->Y[0]!='#'){ \ args->Y=ns_color(parse_color(args->Y)); \ changed=1; \ } \ } \ }while(0)
bfc7071997-01-13Per Hedbor 
2ce3701998-03-29Henrik Grubbström (Grubba)  if(!search((id->client||({}))*"","Mosaic"))
0ee0851997-02-08Per Hedbor  {
e954162000-01-02Martin Nilsson  FIX(bgcolor,"#bfbfbf","bgcolor"); FIX(text, "#000000","fgcolor"); FIX(link, "#0000b0","link"); FIX(alink, "#3f0f7b","alink"); FIX(vlink, "#ff0000","vlink");
0ee0851997-02-08Per Hedbor  } else {
e954162000-01-02Martin Nilsson  FIX(bgcolor,"#c0c0c0","bgcolor"); FIX(text, "#000000","fgcolor"); FIX(link, "#0000ee","link"); FIX(alink, "#ff0000","alink"); FIX(vlink, "#551a8b","vlink");
0ee0851997-02-08Per Hedbor  }
e954162000-01-02Martin Nilsson 
c97c421998-08-20Per Hedbor  if(changed && QUERY(colormode)) return ({make_tag("body", args) });
38569c1999-12-07Martin Nilsson  return 0;
d47cbf1996-12-02Per Hedbor }
e954162000-01-02Martin Nilsson string|array(string) tag_fix_color(string tagname, mapping args, RequestID id)
bfc7071997-01-13Per Hedbor { int changed;
196dac1997-02-22Per Hedbor 
e954162000-01-02Martin Nilsson  if(!id->misc->gtext_colors) id->misc->gtext_colors = ({ ({ id->misc->gtext_fgcolor, id->misc->gtext_bgcolor, tagname }) });
196dac1997-02-22Per Hedbor  else
e954162000-01-02Martin Nilsson  id->misc->gtext_colors += ({ ({ id->misc->gtext_fgcolor, id->misc->gtext_bgcolor, tagname }) });
f7d9811997-09-12Per Hedbor #undef FIX
e954162000-01-02Martin Nilsson #define FIX(X,Y) if(args->X && args->X!=""){ \ id->misc["gtext_"+Y]=args->X; \ if(QUERY(colormode) && args->X[0]!='#'){ \ args->X=ns_color(parse_color(args->X)); \ changed = 1; \ } \ }
bfc7071997-01-13Per Hedbor 
e954162000-01-02Martin Nilsson  FIX(bgcolor,"bgcolor"); FIX(color,"fgcolor"); FIX(text,"fgcolor");
c97c421998-08-20Per Hedbor #undef FIX
22846b1998-05-15Per Hedbor 
c97c421998-08-20Per Hedbor  if(changed && QUERY(colormode)) return ({ make_tag(tagname, args) });
bfc7071997-01-13Per Hedbor  return 0; }
d47cbf1996-12-02Per Hedbor 
e954162000-01-02Martin Nilsson string|void tag_pop_color(string tagname, mapping args, RequestID id)
196dac1997-02-22Per Hedbor {
e954162000-01-02Martin Nilsson  array c = id->misc->gtext_colors;
a3dfd41999-11-28Martin Nilsson  if(!c ||!sizeof(c))
0a76aa1998-03-27David Hedbor  return;
df8d711998-02-27Per Hedbor  int i; tagname = tagname[1..];
e954162000-01-02Martin Nilsson  for(i=0; i<sizeof(c); i++)
df8d711998-02-27Per Hedbor  if(c[-i-1][2]==tagname)
5f0d911997-02-27Per Hedbor  {
e954162000-01-02Martin Nilsson  id->misc->gtext_fgcolor = c[-i-1][0]; id->misc->gtext_bgcolor = c[-i-1][1];
5f0d911997-02-27Per Hedbor  break; }
e954162000-01-02Martin Nilsson  id->misc->gtext_colors = c[..sizeof(c)-i-2];
196dac1997-02-22Per Hedbor }
a3dfd41999-11-28Martin Nilsson  // --------------- tag and container registration ----------------------
bfc7071997-01-13Per Hedbor mapping query_tag_callers()
d47cbf1996-12-02Per Hedbor {
8b6ee51999-07-10Peter Bortas  mapping tags = ([ "gtext-id":tag_gtext_id ]);
39af1a1998-08-26Per Hedbor  if(query("colorparse")) foreach(query("colorparsing"), string t)
c97c421998-08-20Per Hedbor  {
39af1a1998-08-26Per Hedbor  switch(t) { case "body": tags[t] = tag_body; break; default: tags[t] = tag_fix_color;
f02c0c1999-12-11Martin Nilsson  tags["/"+t]=tag_pop_color;
39af1a1998-08-26Per Hedbor  }
c97c421998-08-20Per Hedbor  } return tags;
d47cbf1996-12-02Per Hedbor } mapping query_container_callers() {
f02c0c1999-12-11Martin Nilsson  return ([ "anfang":container_anfang, "gtext-url":container_gtext_url, "gh":container_gh, "gh1":container_gh, "gh2":container_gh, "gh3":container_gh, "gh4":container_gh, "gh5":container_gh, "gh6":container_gh, "gtext":container_gtext ]);
d47cbf1996-12-02Per Hedbor }