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.197 1999/12/14 07:26:06 nilsson Exp $"; + // 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 $";   constant thread_safe=1;      #include <config.h>   #include <module.h>   #include <stat.h>   inherit "module";   inherit "roxenlib";         // ------------------- Module registration ---------------------
Roxen.git/server/modules/graphics/graphic_text.pike:68: Inside #if defined(manual)
   "gh4":"<desc cont></desc>"+gtextargs,    "gh5":"<desc cont></desc>"+gtextargs,    "gh6":"<desc cont></desc>"+gtextargs]);   #endif         // -------------------- 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()   {    image_cache = roxen.ImageCache( "gtext", draw_callback );   }      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)   {    array data;    Image.Font font;    Image.Image img; -  int elapsed; +        if( objectp( text ) )    {    if( !args->text )    error("Failed miserably to find a text to draw. That's not"    " good.\n");    id = (object)text;    text = args->text;    }   
Roxen.git/server/modules/graphics/graphic_text.pike:156:    lower_case(args->talign||"left"),    (float)(int)args->xpad, (float)(int)args->ypad);    }       if (!font)    error("gtext: No font!\n");       // Fonts and such are now initialized.    img = GText.make_text_image(args, font, text, id);    -  // Now we have the image in 'img', or nothing. +  // Now we have the image in 'img'.       if( !args->scroll && !args->fadein )    {    if(!args->notrans)    {    array (int) bgcolor = parse_color(args->bgcolor);    Image.Image alpha;    alpha = img->distancesq( @bgcolor );    alpha->gamma( 8 );    return ([ "img":img, "alpha":alpha ]);
Roxen.git/server/modules/graphics/graphic_text.pike:294:    "xpad",    "xsize",    "xspacing",    "ypad",    "ysize",    "yspacing"   });      mapping mk_gtext_arg(mapping arg, RequestID id) {    -  mapping defines=id->misc->defines; +     mapping p=([]); //Picture rendering arguments.       foreach(filearg, string tmp)    if(arg[tmp]) {    p[tmp]=fix_relative(arg[tmp],id);    m_delete(arg,tmp);    }       if(arg->border && search(arg->border,",")) {    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(defines->fgcolor && !p->fgcolor) p->fgcolor=defines->fgcolor; -  if(defines->bgcolor && !p->bgcolor) p->bgcolor=defines->bgcolor; -  if(defines->nfont && !p->nfont) p->nfont=defines->nfont; -  if(defines->afont && !p->afont) p->afont=defines->afont; -  if(defines->font && !p->font) p->font=defines->font; -  if(defines->bold && !p->bold) p->bold=defines->bold; -  if(defines->italic && !p->italic) p->italic=defines->italic; -  if(defines->black && !p->black) p->black=defines->black; -  if(defines->narrow && !p->narrow) p->narrow=defines->narrow; +  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;       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);
Roxen.git/server/modules/graphics/graphic_text.pike:356:       return c;   }         // ----------------- gtext tags and containers -------------------      string container_gtext_url(string t, mapping arg, string c, RequestID id) {    c=fix_text(c,arg,id);    mapping p=mk_gtext_arg(arg,id); -  if(arg->href && !p->fgcolor) p->fgcolor=id->misc->defines->link||"#0000ff"; +  if(arg->href && !p->fgcolor) p->fgcolor=id->misc->gtext_link||"#0000ff";    string ext="";    if(query("ext")) ext="."+(p->format || "gif");    if(!arg->short)    return query_internal_location()+image_cache->store( ({p,c}), id )+ext;    return "+"+image_cache->store( ({p,c}), id )+ext;   }      string tag_gtext_id(string t, mapping arg, RequestID id) {    mapping p=mk_gtext_arg(arg,id); -  if(arg->href && !p->fgcolor) p->fgcolor=id->misc->defines->link||"#0000ff"; +  if(arg->href && !p->fgcolor) p->fgcolor=id->misc->gtext_link||"#0000ff";    if(!arg->short)    return query_internal_location()+"$"+image_cache->store(p, id)+"/";    return "+"+image_cache->store(p, id )+"/foo";   }      string container_gtext(string t, mapping arg, string c, RequestID id)   { -  mapping defines=id->misc->defines; -  if((c-" ")=="") -  return ""; +  if((c-" ")=="") return "";       c=fix_text(c,arg,id);    mapping p=mk_gtext_arg(arg,id);       string ext="";    if(query("ext")) ext="."+(p->format || "gif");       string lp="%s", url="", ea="";    -  int input; +  int input=0;    if(arg->submit)    {    input=1;    m_delete(arg,"submit");    }       if(!arg->noxml) { arg["/"]="/"; m_delete(arg, "noxml"); }    if(!arg->border) arg->border=arg->border||"0";       if(arg->href)    {    url = arg->href;    lp = replace(make_tag("a",arg),"%","%%")+"%s</a>"; -  if(!p->fgcolor) p->fgcolor=defines->link||"#0000ff"; +  if(!p->fgcolor) p->fgcolor=id->misc->gtext_link||"#0000ff";    m_delete(arg, "href");    }       if(arg->split)    {    string res="",split=arg->split;    if(lower_case(split)=="split") split=" ";    m_delete(arg,"split");    c=replace(c, "\n", " ");    int setalt=!arg->alt;
Roxen.git/server/modules/graphics/graphic_text.pike:442:    if(size) {    arg->width=size->xsize;    arg->height=size->ysize;    }       if(arg->magic)    {    string magic=replace(arg->magic,"'","`");    m_delete(arg,"magic");    -  if(!arg->fgcolor) p->fgcolor=defines->alink||"#ff0000"; +  if(!arg->fgcolor) p->fgcolor=id->misc->gtext_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);    }       if(!id->supports->images) return sprintf(lp,arg->alt);    -  string sn="i"+defines->mi++; +  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"]));    }       arg->name=sn; -  string res="<script>\n"; -  if(!defines->magic_java) +  string res="\n<script>\n"; +  if(!id->misc->gtext_magic_java) {    res += "function i(ri,hi,txt)\n"    "{\n"    " document.images[ri].src = hi.src;\n"    " setTimeout(\"top.window.status = '\"+txt+\"'\", 100);\n"    "}\n"; -  defines->magic_java="yes"; +  } +  id->misc->gtext_magic_java="yes";       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" -  "</script>"+ +  "</script>\n"+    "<a "+ea+"href=\""+url+"\" "+    (input?"onClick='document.forms[0].submit();' ":"") -  +"onMouseover=\"i('"+sn+"',"+sn+"h,'"+(magic=="magic"?url:magic)+"'); return true;\"\n" +  +"onMouseover=\"i('"+sn+"',"+sn+"h,'"+(magic=="magic"?url:magic)+"'); return true;\" "    "onMouseout=\"top.window.status='';document.images['"+sn+"'].src = "+sn+"l.src;\">"    +make_tag("img",arg)+"</a>";    }       if(input)    return make_tag("input",arg+(["type":"image"]));       return sprintf(lp,make_tag("img",arg));   }   
Roxen.git/server/modules/graphics/graphic_text.pike:518:      // ------------ 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, Stdio.File file, -  mapping defines) + 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==""){defines->X=Z;if(cols){args->Y=Z;changed=1;}}else{defines->X=args->Y;if(QUERY(colormode)&&args->Y[0]!='#'){args->Y=ns_color(parse_color(args->Y));changed=1;}}}while(0) + #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); +  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); +  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, -  Stdio.File file, mapping defines) + string|array(string) tag_fix_color(string tagname, mapping args, RequestID id)   {    int changed;    -  if(!id->misc->colors) -  id->misc->colors = ({ ({ defines->fgcolor, defines->bgcolor, tagname }) }); +  if(!id->misc->gtext_colors) +  id->misc->gtext_colors = ({ ({ id->misc->gtext_fgcolor, id->misc->gtext_bgcolor, tagname }) });    else -  id->misc->colors += ({ ({ defines->fgcolor, defines->bgcolor, tagname }) }); +  id->misc->gtext_colors += ({ ({ id->misc->gtext_fgcolor, id->misc->gtext_bgcolor, tagname }) }); +    #undef FIX - #define FIX(X,Y) if(args->X && args->X!=""){defines->Y=args->X;if(QUERY(colormode) && args->X[0]!='#'){args->X=ns_color(parse_color(args->X));changed = 1;}} + #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); +  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, Stdio.File file, -  mapping defines) + string|void tag_pop_color(string tagname, mapping args, RequestID id)   { -  array c = id->misc->colors; +  array c = id->misc->gtext_colors;    if(!c ||!sizeof(c))    return;       int i;    tagname = tagname[1..];    -  for(i=0;i<sizeof(c);i++) +  for(i=0; i<sizeof(c); i++)    if(c[-i-1][2]==tagname)    { -  defines->fgcolor = c[-i-1][0]; -  defines->bgcolor = c[-i-1][1]; +  id->misc->gtext_fgcolor = c[-i-1][0]; +  id->misc->gtext_bgcolor = c[-i-1][1];    break;    } -  c = c[..sizeof(c)-i-2]; -  id->misc->colors = c; +  +  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)