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

version» Context lines:

Roxen.git/server/modules/graphics/graphic_text.pike:1: - string cvs_version="$Id: graphic_text.pike,v 1.38 1997/03/11 01:19:34 per Exp $"; + string cvs_version="$Id: graphic_text.pike,v 1.39 1997/03/26 05:54:13 per Exp $";   #include <module.h>   inherit "module";   inherit "roxenlib";      #if efun(_static_modules)   # define map_array Array.map   import Image;   #else   # define image Image   # define font Font
Roxen.git/server/modules/graphics/graphic_text.pike:57:    " ysize=int Use this (absolute) size\n"    " bevel=int Draw a bevel box (width is the argument)\n"    " pressed Invert the \"direction\" of the bevel box\n"    " talign=dir Justify the text to the left, right, or center\n"    " textbox=al,col. Use 'al' as opaque value to draw a box below\n"    " the text with the specified color.\n"    " xpad=X% Increase padding between characters with X%\n"    " xpad=Y% Increase padding between lines with Y%\n"    " shadow=int,dist Draw a drop-shadow (variable distance/intensity)\n"    " bshadow=dist Draw a blured drop-shadow (variable distance)\n" +  " ghost=dist,blur,col\n" +  " Do a 'ghost text'. Do NOT use together with " +  " 'shadow'. Magic coloring won't work with it."    " glow=color Draw a 'glow' outline around the text.\n"    " opaque=0-100% Draw with more or less opaque text (100%\n"    " is default)\n"    " rotate=ang(deg.)Rotate the finished image\n"    " background=file Use the specifed file as a background\n"    " texture=file Use the specified file as text texture\n"    " turbulence=args args is: frequency,color;freq,col;freq,col\n"    " Apply a turbulence filter, and use this as the\n"    " background.\n"    " maxlen=arg The maximum length of the rendered text will be\n"
Roxen.git/server/modules/graphics/graphic_text.pike:105:   {       defvar("deflen", 300, "Default maximum text-length", TYPE_INT,    "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("location", "/gtext/", "Mountpoint", TYPE_LOCATION, -  "The URL-prefix for the anfang characters."); +  "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 }));          // compatibility variables...    defvar("default_size", 32, 0, TYPE_INT,0,0,1);    defvar("default_font", "urw_itc_avant_garde-demi-r",0,TYPE_STRING,0,0,1);   }      string query_location() { return query("location"); }      mapping (string:object) fonts = ([]);      object(font) load_font(string name, string justification, int xs, int ys)   {    object fnt = font();    -  if(!name) name=""; +  if(!name) name="foo";    if(sscanf(name, "%*s/%*s") != 2)    name=QUERY(default_size)+"/"+name;       name = "fonts/" + name;       if(!fnt->load( name ))    {    perror("Failed to load the font "+name+", using the default font.\n");    if(!fnt->load("fonts/"+QUERY(default_size) +"/"+ QUERY(default_font)))    error("Failed to load the default font\n");
Roxen.git/server/modules/graphics/graphic_text.pike:331:    }       if(args->move)    {    int dx,dy;    sscanf(args->move, "%d,%d", dx, dy);    xoffset += dx;    yoffset += dy;    }    +  if(args->ghost) +  { +  int howmuch=(int)args->ghost; +  xsize+=howmuch*2+10; +  xoffset += 3; +  ysize+=howmuch*2+10; +  } +  +     if(args->xspacing)    {    xoffset += (int)args->xspacing;    xsize += ((int)args->xspacing)*2;    }       if(args->border)    {    xoffset += (int)args->border;    yoffset += (int)args->border;
Roxen.git/server/modules/graphics/graphic_text.pike:432:    {    int alpha,border;    string bg;    sscanf(args->textbox, "%d,%s", alpha, bg);    sscanf(bg,"%s,%d", bg,border);    background->paste_alpha(image(txsize+border*2,tysize+border*2,    @parse_color(bg)),    255-(alpha*255/100),xoffset-border,yoffset-border);    }    +  if(args->ghost) +  { // Francesco.. +  int sdist = (int)args->ghost; +  int bl=(int)(args->ghost/",")[1]; +  array(int)clr=parse_color((args->ghost/",")[-1]); +  int j; +  object base = image(xsize,ysize,@clr)->invert(); +  object ta = text_alpha->copy(); +  for (j=0;j<bl;j++) +  ta=ta->apply_matrix(({ +  ({6,7,7,7,6}),({7,8,8,8,7}),({7,8,8,8,7}),({7,8,8,8,7}),({6,7,7,7,6}) +  })); +  background->paste_mask(base->invert(),ta,xoffset+sdist,yoffset+sdist); +  fgcolor=bgcolor; +  }    -  +     if(args->shadow)    {    int sd = ((int)args->shadow+10)*2;    int sdist = ((int)(args->shadow/",")[-1])+2;    object ta = text_alpha->copy();    ta = ta->color(256-sd,256-sd,256-sd);    background->paste_mask(image(txsize,tysize),ta,xoffset+sdist, yoffset+sdist);    }      #define MIN(x,y) ((x)<(y)?(x):(y))
Roxen.git/server/modules/graphics/graphic_text.pike:601:    img=0;       cache_set(key, text, data);    if(size) return data[1];    return data[0];   }         mapping find_file(string f, object rid)   { -  string id; +  int id;    sscanf(f,"%d/%s", id, f); -  return http_string_answer(write_text((int)id,f,0,rid), "image/gif"); +  return http_string_answer(write_text(id,f,0,rid), "image/gif");   }      string quote(string in)   {    string res="";    for(int i=0; i<strlen(in); i++)    switch(in[i])    {    case 'a'..'z':    case 'A'..'Z':
Roxen.git/server/modules/graphics/graphic_text.pike:666:   }         string magic_image(string url, int xs, int ys, string sn,    string image_1, string image_2, string alt,    string mess,object id,string input,string extra_args)   {    if(!id->supports->images) return alt;    if(!id->supports->javascript)    return (!input)? -  ("<a "+extra_args+"href=\""+url+"\"><img _parsed=1 src="+image_1+" name="+ -  sn+" border=0 alt=\""+alt+"\" ></a>\n"): -  ("<input type=image "+extra_args+" src="+image_1+" name="+input+">"); +  ("<a "+extra_args+"href=\""+url+"\"><img _parsed=1 src=\""+image_1+"\" name="+sn+" border=0 alt=\""+alt+"\" ></a>\n"): +  ("<input type=image "+extra_args+" src=\""+image_1+"\" name="+input+">");       return    ("<script>\n"    " "+sn+"l = new Image("+xs+", "+ys+");"+sn+"l.src = \""+image_1+"\";\n"    " "+sn+"h = new Image("+xs+", "+ys+");"+sn+"h.src = \""+image_2+"\";\n"    "</script>\n"+    ("<a "+extra_args+"href=\""+url+"\" "+    (input?"onClick='document.forms[0].submit();' ":"")    +"onMouseover=\"img_act('"+sn+"',"+sn+"h,'"+(mess||url)+"');\"\n"    "onMouseout='document.images[\""+sn+"\"].src = "+sn+"l.src;'><img " -  "_parsed=1 width="+xs+" height="+ys+" src="+image_1+" name="+sn+ +  "_parsed=1 width="+xs+" height="+ys+" src=\""+image_1+"\" name="+sn+    " border=0 alt=\""+alt+"\" ></a>\n"));   }         string extra_args(mapping in)   {    string s="";    foreach(indices(in), string i)    {    switch(i)
Roxen.git/server/modules/graphics/graphic_text.pike:712:      string tag_gtext_id(string t, mapping arg,    object id, object foo, mapping defines)   {    int short=!!arg->short;    m_delete(arg, "short"); m_delete(arg, "maxlen");    m_delete(arg,"magic"); m_delete(arg,"submit");    extra_args(arg); m_delete(arg,"split");    if(defines->fg && !arg->fg) arg->fg=defines->fg;    if(defines->bg && !arg->bg) arg->bg=defines->bg; -  if(!arg->font) arg->font=defines->font||QUERY(default_font); + // if(!arg->font) arg->font=defines->font||QUERY(default_font); +  if(!arg->nfont) arg->nfont=defines->nfont;       int num = find_or_insert( arg );       if(!short)    return query_location()+num+"/";    else    return (string)num;   }      string tag_graphicstext(string t, mapping arg, string contents,
Roxen.git/server/modules/graphics/graphic_text.pike:791:    if(arg->href)    {    url = arg->href;    lp = "<a href=\""+arg->href+"\" "+ea+">";    if(!arg->fg) arg->fg=defines->link||"#0000ff";    m_delete(arg, "href");    }       if(defines->fg && !arg->fg) arg->fg=defines->fg;    if(defines->bg && !arg->bg) arg->bg=defines->bg; -  if(!arg->font) arg->font=defines->font||QUERY(default_font); + // if(!arg->font) arg->font=defines->font||QUERY(default_font); +  if(!arg->nfont) arg->nfont=defines->nfont; +  if(!arg->bold) arg->bold=defines->bold; +  if(!arg->italic) arg->italic=defines->italic; +  if(!arg->black) arg->black=defines->black; +  if(!arg->narrow) arg->narrow=defines->narrow;       if(arg->split)    {    split=1;    m_delete(arg,"split");    }       // Support for <gh 2> like things.    for(i=2; i<10; i++)    if(arg[(string)i])
Roxen.git/server/modules/graphics/graphic_text.pike:821:       string na = arg->name, al=arg->align;    m_delete(arg, "name"); m_delete(arg, "align");       // Now the 'args' mapping is modified enough..    int num = find_or_insert( 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": +  pre=""; post=""; defalign="bottom"; +  break; +  case "anfang": +  gt=contents[0..0]; rest=contents[1..]; +  pre="<br clear=left>"; post=""; defalign="left"; +  break; +  } +     if(split)    {    string word; -  array res = ({}); +  array res = ({pre});    string pre = query_location()+num+"/";       if(lp) res+=({ lp });       gt=replace(gt, "\n", " ");       foreach(gt/" "-({""}), word)    {    array size = write_text(num,word,1,id);    res += ({ "<img _parsed=1 border=0 alt=\""+replace(word,"\"","'") -  +"\" src=\'"+pre+quote(word)+"\' width="+ +  +"\" src=\""+pre+quote(word)+"\" width="+    size[0]+" height="+size[1]+" "+ea+">\n"    });    } -  if(lp) res+=({ "</a>" }); +  if(lp) res+=({ "</a>"+post });    return res*"";    }    -  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": -  pre=""; post=""; defalign="bottom"; -  break; -  case "anfang": -  gt=contents[0..0]; rest=contents[1..]; -  pre="<br clear=left>"; post=""; defalign="left"; -  break; -  } -  +     array size = write_text(num,gt,1,id);       if(magic)    {    string res = "";    if(!arg->fg) arg->fg=defines->link||"#0000ff";    arg = mkmapping(indices(arg), values(arg));    if(arg->fuzz)    {    if(arg->fuzz != "fuzz")
Roxen.git/server/modules/graphics/graphic_text.pike:893:    query_location()+num2+"/"+quote(gt),    replace(gt, "\"","'"),(magic=="magic"?0:magic),    id,input?na||"submit":0,ea);    }    if(input)    return (pre+"<input type=image name=\""+na+"\" border=0 alt=\""+    replace(gt,"\"","'")+"\" src="+query_location()+num+"/"+quote(gt)    +" align="+(al || defalign)+ea+    " width="+size[0]+" height="+size[1]+">"+rest+post);    return (pre+(lp?lp:"")+ -  "<img _parsed=1 border=0 alt=\""+replace(gt,"\"","'")+"\" src="+ -  query_location()+num+"/"+quote(gt)+" "+ea +  "<img _parsed=1 border=0 alt=\""+replace(gt,"\"","'")+"\" src=\""+ +  query_location()+num+"/"+quote(gt)+"\" "+ea    +" align="+(al || defalign)+    " width="+size[0]+" height="+size[1]+">"+rest+(lp?"</a>":"")+post);   }      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]);   }