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

version» Context lines:

Roxen.git/server/modules/graphics/graphic_text.pike:1:   // This is a roxen module. Copyright © 1996 - 2000, Idonex AB.   //    - constant cvs_version="$Id: graphic_text.pike,v 1.199 2000/01/02 01:36:28 nilsson Exp $"; - constant thread_safe=1; + constant cvs_version="$Id: graphic_text.pike,v 1.200 2000/01/05 22:35:40 nilsson Exp $";    - #include <config.h> +    #include <module.h> - #include <stat.h> +    inherit "module";   inherit "roxenlib";         // ------------------- Module registration ---------------------    - array register_module() - { -  return ({ MODULE_PARSER, -  "Graphics text", -  "Generates graphical texts.", -  0, 1 -  }); - } + constant module_type = MODULE_PARSER; + constant module_name = "Graphics text"; + constant module_doc = "Generates graphical texts."; + constant module_unique = 1; + constant thread_safe = 1;      void create()   {    defvar("colorparse", 1, "Parse tags for document colors", TYPE_FLAG,    "If set, parse the specified tags for document colors.");    -  defvar("colorparsing", ({"body", "td", "layer", "ilayer", "table"}), -  "Tags to parse for color", -  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 " -  "roxen for changes of this variable to take effect.", 0, -  lambda(){return !query("colorparse");}); -  -  defvar("colormode", 1, "Normalize colors in parsed tags", TYPE_FLAG, -  "If set, replace 'roxen' colors (@c,m,y,k etc) with " -  "'netscape' colors (#rrggbb). Setting this to off will lessen the " -  "performance impact of the 'Tags to parse for color' option quite" -  " dramatically. You can try this out with the &lt;gauge&gt; tag.", -  0, lambda(){return !query("colorparse");}); -  +     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 "    "&lt;gh1&gt;&lt;/gh&gt;, which would otherwise parse the"    " whole document. This can be overrided with maxlen=... in the "    "tag.");       defvar("ext", 0, "Append .fmt (gif, jpeg etc) to all images",    TYPE_FLAG|VAR_MORE,    "Append .gif, .png, .gif etc to all images made by gtext. "
Roxen.git/server/modules/graphics/graphic_text.pike:77:   // -------------------- Image cache functions --------------------      roxen.ImageCache image_cache;      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]));   }    - void start() + void start(int num, Configuration conf)   {    image_cache = roxen.ImageCache( "gtext", draw_callback ); -  +  if(query("colorparse")) module_dependencies(conf, ({ "wiretap" }) );   }      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)      mixed draw_callback(mapping args, string text, RequestID id)   {
Roxen.git/server/modules/graphics/graphic_text.pike:300:    "turbulence",    "verbatim",    "xpad",    "xsize",    "xspacing",    "ypad",    "ysize",    "yspacing"   });    + constant theme=({"fgcolor","bgcolor","font"}); +    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);    }   
Roxen.git/server/modules/graphics/graphic_text.pike:321:    p->border=arg->border;    m_delete(arg,"border");    }       foreach(textarg, string tmp)    if(arg[tmp]) {    p[tmp]=arg[tmp],id;    m_delete(arg,tmp);    }    -  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; +  foreach(theme, string tmp) +  if( (id->misc->defines[tmp] || id->misc->defines["theme_"+tmp]) && !p[tmp]) +  p[tmp]=id->misc->defines["theme_"+tmp] || id->misc->defines[tmp];    -  +  if(id->misc->defines->nfont && !p->nfont) p->nfont=id->misc->gtext_nfont; +  if(id->misc->defines->afont && !p->afont) p->afont=id->misc->gtext_afont; +  if(id->misc->defines->bold && !p->bold) p->bold=id->misc->gtext_bold; +  if(id->misc->defines->italic && !p->italic) p->italic=id->misc->gtext_italic; +  if(id->misc->defines->black && !p->black) p->black=id->misc->gtext_black; +  if(id->misc->defines->narrow && !p->narrow) p->narrow=id->misc->gtext_narrow; +     return p;   }      string fix_text(string c, mapping m, RequestID id) {       if(m->nowhitespace)    {    sscanf(c,"%*[ \n\r\t]%s",c);    sscanf(reverse(c),"%*[ \n\r\t]%s",c);    c=reverse(c);
Roxen.git/server/modules/graphics/graphic_text.pike:438:    }    return sprintf(lp,res);    }       string num = image_cache->store( ({ p, c }), id );    mapping size = image_cache->metadata( num, id, 1 );    if(!arg->alt) arg->alt=replace(c,"\"","'");       arg->src=query_internal_location()+num+ext;    if(size) { -  arg->width=size->xsize; -  arg->height=size->ysize; +  arg->width=(string)size->xsize; +  arg->height=(string)size->ysize;    }       if(arg->magic)    {    string magic=replace(arg->magic,"'","`");    m_delete(arg,"magic");    -  if(!arg->fgcolor) p->fgcolor=id->misc->gtext_alink||"#ff0000"; +  if(!arg->fgcolor) p->fgcolor=id->misc->defines->theme_alink|| +  id->misc->defines->alink||"#ff0000";    if(p->bevel) p->pressed=1;       foreach(glob("magic-*", indices(arg)), string q)    {    p[q[6..]]=arg[q];    m_delete(arg, q);    }       string num2 = image_cache->store( ({ p, c }),id );    size = image_cache->metadata( num2, id );    if(size) { -  arg->width=max(arg->xsize,size->xsize); -  arg->height=max(arg->ysize,size->ysize); +  arg->width=(string)max(arg->xsize,size->xsize); +  arg->height=(string)max(arg->ysize,size->ysize);    }       if(!id->supports->images) return sprintf(lp,arg->alt);       string sn="i"+id->misc->gtext_mi++;    if(!id->supports->netscape_javascript) {    return (!input)?    ("<a "+ea+"href=\""+url+"\">"+make_tag("img",arg+(["name":sn]))+"</a>"):    make_tag("input",arg+(["type":"image"]));    }
Roxen.git/server/modules/graphics/graphic_text.pike:515:    if(!m->valign) m->valign="top";    return ({ "<p>"+container_gtext("",m,c,id)+"<br>" });   }      array(string) container_anfang(string t, mapping m, string c, RequestID id) {    if(!m->align) m->align="left";    return ({ "<br clear=\"left\">"+container_gtext("",m,c[0..0],id)+c[1..] });   }       - // ------------ Wiretap code to find HTML-colours --------------------- -  - 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]); - } -  - int|array (string) tag_body(string t, mapping args, RequestID id) - { -  int changed=0; -  int cols=(args->bgcolor||args->text||args->link||args->alink||args->vlink); -  - #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) -  -  if(!search((id->client||({}))*"","Mosaic")) -  { -  FIX(bgcolor,"#bfbfbf","bgcolor"); -  FIX(text, "#000000","fgcolor"); -  FIX(link, "#0000b0","link"); -  FIX(alink, "#3f0f7b","alink"); -  FIX(vlink, "#ff0000","vlink"); -  } else { -  FIX(bgcolor,"#c0c0c0","bgcolor"); -  FIX(text, "#000000","fgcolor"); -  FIX(link, "#0000ee","link"); -  FIX(alink, "#ff0000","alink"); -  FIX(vlink, "#551a8b","vlink"); -  } -  -  if(changed && QUERY(colormode)) -  return ({make_tag("body", args) }); -  return 0; - } -  - string|array(string) tag_fix_color(string tagname, mapping args, RequestID id) - { -  int changed; -  -  if(!id->misc->gtext_colors) -  id->misc->gtext_colors = ({ ({ id->misc->gtext_fgcolor, id->misc->gtext_bgcolor, tagname }) }); -  else -  id->misc->gtext_colors += ({ ({ id->misc->gtext_fgcolor, id->misc->gtext_bgcolor, tagname }) }); -  - #undef FIX - #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; \ -  } \ - } -  -  FIX(bgcolor,"bgcolor"); -  FIX(color,"fgcolor"); -  FIX(text,"fgcolor"); - #undef FIX -  -  if(changed && QUERY(colormode)) -  return ({ make_tag(tagname, args) }); -  return 0; - } -  - string|void tag_pop_color(string tagname, mapping args, RequestID id) - { -  array c = id->misc->gtext_colors; -  if(!c ||!sizeof(c)) -  return; -  -  int i; -  tagname = tagname[1..]; -  -  for(i=0; i<sizeof(c); i++) -  if(c[-i-1][2]==tagname) -  { -  id->misc->gtext_fgcolor = c[-i-1][0]; -  id->misc->gtext_bgcolor = c[-i-1][1]; -  break; -  } -  -  id->misc->gtext_colors = c[..sizeof(c)-i-2]; - } -  -  +    // --------------- tag and container registration ----------------------      mapping query_tag_callers()   { -  mapping tags = ([ "gtext-id":tag_gtext_id ]); -  if(query("colorparse")) -  foreach(query("colorparsing"), string t) -  { -  switch(t) -  { -  case "body": -  tags[t] = tag_body; -  break; -  default: -  tags[t] = tag_fix_color; -  tags["/"+t]=tag_pop_color; +  return ([ "gtext-id":tag_gtext_id ]);   } -  } -  return tags; - } +       mapping query_container_callers()   {    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 ]);   }