a5c21b | 1999-05-18 | Peter Bortas | | constant cvs_version="$Id: graphic_text.pike,v 1.170 1999/05/18 02:32:56 peter Exp $";
|
85e832 | 1997-08-31 | Peter Bortas | | constant thread_safe=1;
|
ebf60d | 1997-03-08 | Henrik Grubbström (Grubba) | |
|
059509 | 1999-03-12 | Martin Stjernholm | | #include <config.h>
|
d47cbf | 1996-12-02 | Per Hedbor | | #include <module.h>
|
e5bad2 | 1998-02-10 | Per Hedbor | | #include <stat.h>
|
d47cbf | 1996-12-02 | Per Hedbor | | inherit "module";
inherit "roxenlib";
|
3992de | 1997-09-28 | Henrik Grubbström (Grubba) | | #ifndef VAR_MORE
#define VAR_MORE 0
#endif /* VAR_MORE */
|
610bf9 | 1998-03-07 | Fredrik Noring | | static private int loaded;
|
a5c21b | 1999-05-18 | Peter Bortas | | int args_restored = 0;
|
610bf9 | 1998-03-07 | Fredrik Noring | |
static private string doc()
{
return !loaded?"":replace(Stdio.read_bytes("modules/tags/doc/graphic_text")
||"", ({ "{", "}" }), ({ "<", ">" }));
}
|
d47cbf | 1996-12-02 | Per Hedbor | | array register_module()
{
return ({ MODULE_LOCATION | MODULE_PARSER,
|
567055 | 1998-06-09 | Peter Bortas | | "Graphics text",
"Generates graphical texts.<p>"
"See <tt><gtext help></gtext></tt> for "
"more information.\n<p>"+doc(),
0, 1
|
a5c21b | 1999-05-18 | Peter Bortas | | });
|
0a76aa | 1998-03-27 | David Hedbor | | }
array (string) list_fonts()
{
array fnts;
catch(fnts = get_dir("fonts/32/") - ({".",".."}));
if(!fnts)
{
return ({});
}
return fnts;
|
d47cbf | 1996-12-02 | Per Hedbor | | }
void create()
{
|
8afc81 | 1998-02-04 | Per Hedbor | | defvar("cache_dir", "../gtext_cache", "Cache directory for gtext images",
|
20ca2b | 1998-01-26 | Per Hedbor | | TYPE_DIR,
"The gtext tag saves images when they are calculated in this "
|
0fa8b2 | 1998-07-04 | Peter Bortas | | "directory.");
|
20ca2b | 1998-01-26 | Per Hedbor | |
|
e5bad2 | 1998-02-10 | Per Hedbor | | defvar("cache_age", 48, "Cache max age",
|
0a76aa | 1998-03-27 | David Hedbor | |
|
e5bad2 | 1998-02-10 | Per Hedbor | | TYPE_INT,
|
0a76aa | 1998-03-27 | David Hedbor | |
|
e5bad2 | 1998-02-10 | Per Hedbor | | "If the images in the cache have not been accessed for this "
"number of hours they are removed.");
|
c97c42 | 1998-08-20 | Per Hedbor | |
|
39af1a | 1998-08-26 | Per Hedbor | | defvar("colorparse", 1, "Parse tags for document colors", TYPE_FLAG,
"If set, parse the specified tags for document colors.");
|
c97c42 | 1998-08-20 | Per Hedbor | | 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 "
|
39af1a | 1998-08-26 | Per Hedbor | | "roxen for changes of this variable to take effect.", 0,
lambda(){return !query("colorparse");});
|
c97c42 | 1998-08-20 | Per Hedbor | |
defvar("colormode", 1, "Normalize colors in parsed tags", TYPE_FLAG,
"If set, replace 'roxen' colors (@c,m,y,k etc) with "
|
39af1a | 1998-08-26 | Per Hedbor | | "'netscape' colors (#rrggbb). Setting this to off will lessen the "
|
c97c42 | 1998-08-20 | Per Hedbor | | "performance impact of the 'Tags to parse for color' option quite"
|
39af1a | 1998-08-26 | Per Hedbor | | " dramatically. You can try this out with the <gauge> tag.",
0, lambda(){return !query("colorparse");});
|
c97c42 | 1998-08-20 | Per Hedbor | |
|
9b9f70 | 1997-08-12 | Per Hedbor | | defvar("deflen", 300, "Default maximum text-length", TYPE_INT|VAR_MORE,
|
bfc707 | 1997-01-13 | Per Hedbor | | "The module will, per default, not try to render texts "
"longer than this. This is a safeguard for things like "
"<gh1></gh>, which would otherwise parse the"
" whole document. This can be overrided with maxlen=... in the "
"tag.");
|
9b9f70 | 1997-08-12 | Per Hedbor | | defvar("location", "/gtext/", "Mountpoint", TYPE_LOCATION|VAR_MORE,
|
f6d62d | 1997-03-26 | Per Hedbor | | "The URL-prefix for the graphic characters.");
|
d47cbf | 1996-12-02 | Per Hedbor | |
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 }));
|
8e727d | 1997-03-11 | Per Hedbor | |
|
974b2a | 1997-10-02 | Peter Bortas | | defvar("gif", 0, "Append .gif to all images", TYPE_FLAG|VAR_MORE,
"Append .gif to all images made by gtext. Normally this will "
"only waste bandwidth");
|
a5c21b | 1999-05-18 | Peter Bortas | |
#ifdef TYPE_FONT
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);
#else
defvar("default_size", 32, "Default font size", TYPE_INT_LIST,
"The default size for the font. This is used for the 'base' size, "
"and can be scaled up or down in the tags.",
({ 16, 32, 64 }));
defvar("default_font", "urw_itc_avant_garde-demi-r", "Default font",
TYPE_STRING_LIST,
"The default font. The 'font dir' will be prepended to the path",
list_fonts());
#endif
}
string query_location() { return query("location"); }
object load_font(string name, string justification, int xs, int ys)
{
object fnt = Image.font();
if ((!name)||(name == ""))
{
return get_font("default",32,0,0,lower_case(justification||"left"),
(float)xs, (float)ys);
} else if(sscanf(name, "%*s/%*s") != 2) {
name=QUERY(default_size)+"/"+name;
}
name = "fonts/" + name;
if(!fnt->load( name ))
{
report_debug("Failed to load the compatibility font "+name+
", using the default font.\n");
return get_font("default",32,0,0,lower_case(justification||"left"),
(float)xs, (float)ys);
}
catch
{
if(justification=="right") fnt->right();
if(justification=="center") fnt->center();
if(xs)fnt->set_x_spacing((100.0+(float)xs)/100.0);
if(ys)fnt->set_y_spacing((100.0+(float)ys)/100.0);
};
return fnt;
|
d47cbf | 1996-12-02 | Per Hedbor | | }
|
a5c21b | 1999-05-18 | Peter Bortas | | static private mapping cached_args = ([ ]);
|
0a76aa | 1998-03-27 | David Hedbor | | #define MAX(a,b) ((a)<(b)?(b):(a))
|
a5c21b | 1999-05-18 | Peter Bortas | | #if !efun(make_matrix)
static private mapping (int:array(array(int))) matrixes = ([]);
|
0a76aa | 1998-03-27 | David Hedbor | | array (array(int)) make_matrix(int size)
{
|
a5c21b | 1999-05-18 | Peter Bortas | | if(matrixes[size]) return matrixes[size];
|
0a76aa | 1998-03-27 | David Hedbor | | array res;
int i;
int j;
res = Array.map(allocate(size), lambda(int s, int size){
return allocate(size); }, size);
for(i=0; i<size; i++)
for(j=0; j<size; j++)
res[i][j] = (int)MAX((float)size/2.0-sqrt((size/2-i)*(size/2-i) + (size/2-j)*(size/2-j)),0);
|
a5c21b | 1999-05-18 | Peter Bortas | | return matrixes[size] = res;
|
0a76aa | 1998-03-27 | David Hedbor | | }
|
a5c21b | 1999-05-18 | Peter Bortas | | #endif
|
0a76aa | 1998-03-27 | David Hedbor | |
|
a5c21b | 1999-05-18 | Peter Bortas | | object blur(object img, int amnt)
|
0a76aa | 1998-03-27 | David Hedbor | | {
img->setcolor(0,0,0);
img = img->autocrop(amnt, 0,0,0,0, 0,0,0);
for(int i=0; i<amnt; i++)
|
a5c21b | 1999-05-18 | Peter Bortas | | img = img->apply_matrix( make_matrix((int)sqrt(img->ysize()+20)));
|
0a76aa | 1998-03-27 | David Hedbor | | return img;
}
|
a5c21b | 1999-05-18 | Peter Bortas | | object outline(object on, object with,
array (int) color, int radie, int x, int y)
|
0a76aa | 1998-03-27 | David Hedbor | | {
int steps=10;
for(int j=0; j<=steps; j++)
on->paste_alpha_color(with, @color,
(int)(0.5+x-(sin((float)j/steps*3.145*2)*radie)),
(int)(0.5+y-(cos((float)j/steps*3.145*2)*radie)));
return on;
}
|
a5c21b | 1999-05-18 | Peter Bortas | | array white = ({ 255,255,255 });
array lgrey = ({ 200,200,200 });
array grey = ({ 128,128,128 });
array black = ({ 0,0,0 });
|
0a76aa | 1998-03-27 | David Hedbor | |
|
a5c21b | 1999-05-18 | Peter Bortas | | array wwwb = ({ lgrey,lgrey,grey,black });
object bevel(object in, int width, int|void invert)
|
0a76aa | 1998-03-27 | David Hedbor | | {
int h=in->ysize();
int w=in->xsize();
object corner = Image.image(width+1,width+1);
object corner2 = Image.image(width+1,width+1);
object pix = Image.image(1,1);
for(int i=-1; i<=width; i++) {
corner->line(i,width-i,i,-1, @white);
corner2->setpixel(width-i, width-i, @white);
in->paste_alpha(pix, 185, w - width + i+1, h - width + i+1);
}
if(!invert)
{
in->paste_alpha(Image.image(width,h-width*2,@white), 160, 0, width);
in->paste_alpha(Image.image(width,h-width*2,@black), 128, in->xsize()-width, width);
in->paste_alpha(Image.image(w-width,width,@white), 160, 0, 0);
in->paste_alpha(Image.image(w-width,width,@black), 128, width, in->ysize()-width);
} else {
corner=corner->invert();
corner2=corner2->invert();
in->paste_alpha(Image.image(width,h-width*2,@black), 160, 0, width);
in->paste_alpha(Image.image(width,h-width*2,@white), 128, in->xsize()-width, width);
in->paste_alpha(Image.image(w-width,width,@black), 160, 0, 0);
in->paste_alpha(Image.image(w-width,width,@white), 128, width, in->ysize()-width);
}
in->paste_mask(corner, corner->color(95,95,95), in->xsize()-width,-1);
in->paste_mask(corner, corner->invert()->color(128,128,128),
in->xsize()-width,-1);
in->paste_mask(corner, corner->color(95,95,95), -1, in->ysize()-width);
in->paste_mask(corner, corner->invert()->color(128,128,128),
-1, in->ysize()-width);
corner=0;
in->paste_mask(corner2, corner2->color(70,70,70), -1, -1);
corner2 = pix = 0;
return in;
}
object make_text_image(mapping args, object font, string text,object id)
{
|
a5c21b | 1999-05-18 | Peter Bortas | | object text_alpha=font->write(@(text/"\n"));
|
0a76aa | 1998-03-27 | David Hedbor | | int xoffset=0, yoffset=0;
if(!text_alpha->xsize() || !text_alpha->ysize())
text_alpha = Image.image(10,10, 0,0,0);
if(int op=((((int)args->opaque)*255)/100))
text_alpha=text_alpha->color(op,op,op);
int txsize=text_alpha->xsize();
int tysize=text_alpha->ysize();
int xsize=txsize;
int ysize=tysize;
if(args->bevel)
{
xoffset += (int)args->bevel;
yoffset += (int)args->bevel;
xsize += ((int)args->bevel)*2;
ysize += ((int)args->bevel)*2;
}
if(args->spacing)
{
xoffset += (int)args->spacing;
yoffset += (int)args->spacing;
xsize += ((int)args->spacing)*2;
ysize += ((int)args->spacing)*2;
}
if(args->yspacing)
{
yoffset += (int)args->yspacing;
ysize += ((int)args->yspacing)*2;
}
if(args->shadow)
{
xsize+=((int)(args->shadow/",")[-1])+2;
ysize+=((int)(args->shadow/",")[-1])+2;
}
if(args->bshadow)
{
xsize+=(int)args->bshadow+3;
ysize+=(int)args->bshadow+3;
}
if(args->fadein)
{
xsize+=6;
ysize+=6;
xoffset+=3;
yoffset+=3;
}
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;
}
|
a5c21b | 1999-05-18 | Peter Bortas | | if(args->xspacing)
{
xoffset += (int)args->xspacing;
xsize += ((int)args->xspacing)*2;
}
|
0a76aa | 1998-03-27 | David Hedbor | | if(args->border)
{
xoffset += (int)args->border;
yoffset += (int)args->border;
xsize += ((int)args->border)*2;
ysize += ((int)args->border)*2;
}
array (int) bgcolor = parse_color(args->bg);
array (int) fgcolor = parse_color(args->fg);
object background,foreground;
|
a5c21b | 1999-05-18 | Peter Bortas | | if(args->texture)
{
object t = roxen.load_image(args->texture,id);
if( t )
|
0a76aa | 1998-03-27 | David Hedbor | | {
|
a5c21b | 1999-05-18 | Peter Bortas | | foreground = t;
if(args->tile)
|
0a76aa | 1998-03-27 | David Hedbor | | {
|
a5c21b | 1999-05-18 | Peter Bortas | | object b2 = Image.image(xsize,ysize);
for(int x=0; x<xsize; x+=foreground->xsize())
for(int y=0; y<ysize; y+=foreground->ysize())
|
0a76aa | 1998-03-27 | David Hedbor | | b2->paste(foreground, x, y);
|
a5c21b | 1999-05-18 | Peter Bortas | | foreground = b2;
} else if(args->mirrortile) {
object b2 = Image.image(xsize,ysize);
object b3 = Image.image(foreground->xsize()*2,foreground->ysize()*2);
b3->paste(foreground,0,0);
b3->paste(foreground->mirrorx(),foreground->xsize(),0);
b3->paste(foreground->mirrory(),0,foreground->ysize());
b3->paste(foreground->mirrorx()->mirrory(),foreground->xsize(),
foreground->ysize());
foreground = b3;
for(int x=0; x<xsize; x+=foreground->xsize())
{
for(int y=0; y<ysize; y+=foreground->ysize())
if(y%2)
b2->paste(foreground->mirrory(), x, y);
else
b2->paste(foreground, x, y);
foreground = foreground->mirrorx();
}
foreground = b2;
|
0a76aa | 1998-03-27 | David Hedbor | | }
|
a5c21b | 1999-05-18 | Peter Bortas | | } else
werror("Failed to load image for "+args->texture+"\n");
|
0a76aa | 1998-03-27 | David Hedbor | | }
|
7b15a6 | 1998-08-10 | Johan Schön | | int background_is_color;
if(args->background &&
|
a22f6f | 1999-05-12 | Per Hedbor | | ((background = roxen.load_image(args->background, id)) ||
|
a5c21b | 1999-05-18 | Peter Bortas | | (sizeof(args->background)>1 &&
(background=Image.image(xsize,ysize, @(parse_color(args->background[1..]))))
|
7b15a6 | 1998-08-10 | Johan Schön | | && (background_is_color=1))))
{
object alpha;
|
a22f6f | 1999-05-12 | Per Hedbor | | if(args->alpha && (alpha = roxen.load_image(args->alpha,id)) && background_is_color)
|
7b15a6 | 1998-08-10 | Johan Schön | | {
xsize=MAX(xsize,alpha->xsize());
ysize=MAX(ysize,alpha->ysize());
|
a5c21b | 1999-05-18 | Peter Bortas | | if((float)args->scale)
|
17bb76 | 1998-08-28 | Marcus Wellhardh | | alpha=alpha->scale(1/(float)args->scale);
|
a5c21b | 1999-05-18 | Peter Bortas | | background=Image.image(xsize,ysize, @(parse_color(args->background[1..])));
|
7b15a6 | 1998-08-10 | Johan Schön | | }
|
a5c21b | 1999-05-18 | Peter Bortas | | if((float)args->scale >= 0.1 && !alpha)
|
0a76aa | 1998-03-27 | David Hedbor | | background = background->scale(1.0/(float)args->scale);
|
7b15a6 | 1998-08-10 | Johan Schön | |
|
0a76aa | 1998-03-27 | David Hedbor | | if(args->tile)
{
object b2 = Image.image(xsize,ysize);
for(int x=0; x<xsize; x+=background->xsize())
for(int y=0; y<ysize; y+=background->ysize())
b2->paste(background, x, y);
background = b2;
} else if(args->mirrortile) {
object b2 = Image.image(xsize,ysize);
object b3 = Image.image(background->xsize()*2,background->ysize()*2);
b3->paste(background,0,0);
b3->paste(background->mirrorx(),background->xsize(),0);
b3->paste(background->mirrory(),0,background->ysize());
b3->paste(background->mirrorx()->mirrory(),background->xsize(),
background->ysize());
background = b3;
for(int x=0; x<xsize; x+=background->xsize())
{
for(int y=0; y<ysize; y+=background->ysize())
if(y%2)
b2->paste(background->mirrory(), x, y);
else
b2->paste(background, x, y);
background = background->mirrorx();
}
background = b2;
}
|
7b15a6 | 1998-08-10 | Johan Schön | | xsize = MAX(xsize,background->xsize());
ysize = MAX(ysize,background->ysize());
|
7d9223 | 1998-08-10 | Johan Schön | |
|
7b15a6 | 1998-08-10 | Johan Schön | | if(alpha)
|
a5c21b | 1999-05-18 | Peter Bortas | | background->paste_alpha_color(alpha->invert(),@bgcolor);
|
0a76aa | 1998-03-27 | David Hedbor | |
switch(lower_case(args->talign||"left")) {
case "center":
xoffset = (xsize/2 - txsize/2);
yoffset = (ysize/2 - tysize/2);
break;
case "right":
xoffset = (xsize - txsize);
break;
case "left":
}
} else
background = Image.image(xsize, ysize, @bgcolor);
if(args->border)
{
int b = (int)args->border;
background->setcolor(@parse_color((args->border/",")[-1]));
for(--b;b>=0;b--)
{
background->line(b,b, xsize-b-1, b);
background->line(b,ysize-b-1, xsize-b-1, ysize-b-1);
background->line(b,b, b, ysize-b-1);
background->line(xsize-b-1,b, xsize-b-1, ysize-b-1);
}
}
background->setcolor(@bgcolor);
if(args->size || args->xsize || args->ysize)
{
int xs=background->xsize(), ys=background->ysize();
if(args->size) { xs=(int)args->size; ys=(int)(args->size/",")[-1]; }
if(args->xsize) xs=(int)args->xsize;
if(args->ysize) ys=(int)args->ysize;
|
0fa8b2 | 1998-07-04 | Peter Bortas | | if(!args->rescale)
background = background->copy(0,0,xs-1,ys-1);
else
background = background->scale(xs, ys);
|
0a76aa | 1998-03-27 | David Hedbor | | }
if(args->turbulence)
{
array (float|array(int)) arg=({});
foreach((args->turbulence/";"), string s)
{
array q= s/",";
if(sizeof(q)<2) args+=({ ((float)s)||0.2, ({ 255,255,255 }) });
arg+=({ ((float)q[0])||0.2, parse_color(q[1]) });
}
background=background->turbulence(arg);
}
if(args->bevel)
background = bevel(background,(int)args->bevel,!!args->pressed);
if(args->textbox)
{
int alpha,border;
string bg;
sscanf(args->textbox, "%d,%s", alpha, bg);
sscanf(bg,"%s,%d", bg,border);
background->paste_alpha(Image.image(txsize+border*2,tysize+border*2,
@parse_color(bg)),
255-(alpha*255/100),xoffset-border,yoffset-border);
}
if(args->ghost)
{
|
0eb6a6 | 1999-01-25 | Henrik Grubbström (Grubba) | | array(string) a = (args->ghost/",");
if (sizeof(a) < 2) {
} else {
int sdist = (int)(a[0]);
int bl=(int)(a[1]);
array(int)clr=parse_color(a[-1]);
int j;
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_alpha_color(ta,@clr,xoffset+sdist,yoffset+sdist);
fgcolor=bgcolor;
}
|
0a76aa | 1998-03-27 | David Hedbor | | }
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);
array sc = parse_color(args->scolor||"black");
background->paste_alpha_color(ta,sc[0],sc[1],sc[2],
xoffset+sdist,yoffset+sdist);
}
#define MIN(x,y) ((x)<(y)?(x):(y))
if(args->bshadow)
{
int sdist = (int)(args->bshadow)+1;
int xs,ys;
xs = text_alpha->xsize()+sdist*2+4;
ys = text_alpha->ysize()+sdist*2+4;
object ta = Image.image(xs+sdist*2,ys+sdist*2);
array sc = parse_color(args->scolor||"black");
ta->paste_alpha_color(text_alpha,255,255,255,sdist,sdist);
|
a5c21b | 1999-05-18 | Peter Bortas | | ta = blur(ta, MIN((sdist/2),1))->color(256,256,256);
|
0a76aa | 1998-03-27 | David Hedbor | |
background->paste_alpha_color(ta,sc[0],sc[1],sc[2],
xoffset+sdist,yoffset+sdist);
}
if(args->glow)
{
int amnt = (int)(args->glow/",")[-1]+2;
array (int) blurc = parse_color((args->glow/",")[0]);
background->paste_alpha_color(blur(text_alpha, amnt),@blurc,
xoffset-amnt, yoffset-amnt);
}
if(args->chisel)
foreground=text_alpha->apply_matrix(({ ({8,1,0}),
({1,0,-1}),
({0,-1,-8}) }),
128,128,128, 15 )
->color(@fgcolor);
if(!foreground) foreground=Image.image(txsize, tysize, @fgcolor);
if(args->textscale)
{
string c1="black",c2="black",c3="black",c4="black";
sscanf(args->textscale, "%s,%s,%s,%s", c1, c2, c3, c4);
foreground->tuned_box(0,0, txsize,tysize,
({parse_color(c1),parse_color(c2),parse_color(c3),
parse_color(c4)}));
}
if(args->outline)
outline(background, text_alpha, parse_color((args->outline/",")[0]),
((int)(args->outline/",")[-1])+1, xoffset, yoffset);
|
0fa8b2 | 1998-07-04 | Peter Bortas | | if(args->textbelow)
{
array color = parse_color(args->textbelow);
background->setcolor( @color );
int oby = background->ysize();
background = background->copy(0,0,
max(background->xsize()-1,
foreground->xsize()-1),
background->ysize()-1
+foreground->ysize());
background->paste_mask( foreground, text_alpha,
(background->xsize()-foreground->xsize())/2,
oby );
} else
background->paste_mask(foreground, text_alpha, xoffset, yoffset);
|
0a76aa | 1998-03-27 | David Hedbor | |
|
0fa8b2 | 1998-07-04 | Peter Bortas | | if((float)args->scale>0.0)
|
0a76aa | 1998-03-27 | David Hedbor | | if((float)args->scale <= 2.0)
background = background->scale((float)args->scale);
foreground = text_alpha = 0;
if(args->rotate)
{
string c;
if(sscanf(args->rotate, "%*d,%s", c)==2)
background->setcolor(@parse_color(c));
else
background->setcolor(@bgcolor);
background = background->rotate((float)args->rotate);
}
if(args->crop) background = background->autocrop();
return background;
}
|
2468b2 | 1997-07-06 | Henrik Grubbström (Grubba) | | string base_key;
|
fe21a7 | 1997-08-25 | Per Hedbor | | object mc;
|
2468b2 | 1997-07-06 | Henrik Grubbström (Grubba) | |
|
e5bad2 | 1998-02-10 | Per Hedbor | |
array to_clean = ({});
void clean_cache_dir()
{
if(!sizeof(to_clean))
|
835ed4 | 1998-06-02 | Henrik Grubbström (Grubba) | | to_clean = get_dir(query("cache_dir"))||({});
|
e5bad2 | 1998-02-10 | Per Hedbor | | if(!sizeof(to_clean)) return;
|
a6ff25 | 1998-04-17 | Henrik Grubbström (Grubba) | | array st = file_stat(query("cache_dir")+to_clean[0]);
int md;
if (st) {
md = st[ST_ATIME];
}
|
e5bad2 | 1998-02-10 | Per Hedbor | | if((time() - md) > (query("cache_age")*3600))
rm(query("cache_dir")+to_clean[0]);
to_clean = to_clean[1..];
if(sizeof(to_clean))
call_out(clean_cache_dir, 0.1);
else
call_out(clean_cache_dir, 3600);
}
|
08df12 | 1997-08-19 | Henrik Grubbström (Grubba) | | void start(int|void val, object|void conf)
|
2468b2 | 1997-07-06 | Henrik Grubbström (Grubba) | | {
|
610bf9 | 1998-03-07 | Fredrik Noring | | loaded = 1;
|
fe21a7 | 1997-08-25 | Per Hedbor | | if(conf)
{
|
eb0b9a | 1998-03-10 | Henrik Grubbström (Grubba) | | mkdirhier( query( "cache_dir" )+"/.foo" );
|
e5bad2 | 1998-02-10 | Per Hedbor | | remove_call_out(clean_cache_dir);
call_out(clean_cache_dir, 10);
|
fe21a7 | 1997-08-25 | Per Hedbor | | mc = conf;
|
a5c21b | 1999-05-18 | Peter Bortas | | base_key = "gtext:"+(conf?conf->name:roxen->current_configuration->name);
|
fe21a7 | 1997-08-25 | Per Hedbor | | }
|
2468b2 | 1997-07-06 | Henrik Grubbström (Grubba) | | }
|
c3655b | 1997-01-27 | Per Hedbor | |
|
0a76aa | 1998-03-27 | David Hedbor | | #ifdef QUANT_DEBUG
void print_colors(array from)
{
|
a5c21b | 1999-05-18 | Peter Bortas | | #if efun(color_name)
|
0a76aa | 1998-03-27 | David Hedbor | | for(int i=0; i<sizeof(from); i++)
perror("%d: %s\n", i, color_name(from[i]));
|
a5c21b | 1999-05-18 | Peter Bortas | | #endif
|
0a76aa | 1998-03-27 | David Hedbor | | }
#endif
|
68e030 | 1997-08-19 | Per Hedbor | | int number=0;
|
0a76aa | 1998-03-27 | David Hedbor | |
|
1fc233 | 1999-02-12 | Henrik Grubbström (Grubba) | | #ifdef THREADS
|
059509 | 1999-03-12 | Martin Stjernholm | | object number_lock = Thread.Mutex();
|
a5c21b | 1999-05-18 | Peter Bortas | | #define NUMBER_LOCK() do { object __key = number_lock->lock()
#define NUMBER_UNLOCK() if (__key) destruct(__key); } while(0)
|
1fc233 | 1999-02-12 | Henrik Grubbström (Grubba) | | #else /* !THREADS */
#define NUMBER_LOCK()
#define NUMBER_UNLOCK()
#endif /* THREADS */
|
a5c21b | 1999-05-18 | Peter Bortas | | mapping find_cached_args(int num);
#if !constant(iso88591)
constant iso88591
=([ " ": " ", "¡": "¡", "¢": "¢", "£": "£",
"¤": "¤", "¥": "¥", "¦": "¦", "§": "§",
"¨": "¨", "©": "©", "ª": "ª", "«": "«",
"¬": "¬", "­": "", "®": "®", "¯": "¯",
"°": "°", "±": "±", "²": "²", "³": "³",
"´": "´", "µ": "µ", "¶": "¶", "·": "·",
"¸": "¸", "¹": "¹", "º": "º", "»": "»",
"¼": "¼", "½": "½", "¾": "¾", "¿": "¿",
"À": "À", "Á": "Á", "Â": "Â", "Ã": "Ã",
"Ä": "Ä", "Å": "Å", "Æ": "Æ", "Ç": "Ç",
"È": "È", "É": "É", "Ê": "Ê", "Ë": "Ë",
"Ì": "Ì", "Í": "Í", "Î": "Î", "Ï": "Ï",
"Ð": "Ð", "Ñ": "Ñ", "Ò": "Ò", "Ó": "Ó",
"Ô": "Ô", "Õ": "Õ", "Ö": "Ö", "×": "×",
"Ø": "Ø", "Ù": "Ù", "Ú": "Ú", "Û": "Û",
"Ü": "Ü", "Ý": "Ý", "Þ": "Þ", "ß": "ß",
"à": "à", "á": "á", "â": "â", "ã": "ã",
"ä": "ä", "å": "å", "æ": "æ", "ç": "ç",
"è": "è", "é": "é", "ê": "ê", "ë": "ë",
"ì": "ì", "í": "í", "î": "î", "ï": "ï",
"ð": "ð", "ñ": "ñ", "ò": "ò", "ó": "ó",
"ô": "ô", "õ": "õ", "ö": "ö", "÷": "÷",
"ø": "ø", "ù": "ù", "ú": "ú", "û": "û",
"ü": "ü", "ý": "ý", "þ": "þ", "ÿ": "ÿ",
]);
#endif
|
b1ab8d | 1997-12-23 | Per Hedbor | | constant nbsp = iso88591[" "];
|
0a76aa | 1998-03-27 | David Hedbor | |
|
b1ab8d | 1997-12-23 | Per Hedbor | | constant replace_from = indices( iso88591 )+ ({"&ss;","<",">","&",});
constant replace_to = values( iso88591 ) + ({ nbsp, "<", ">", "&", });
#define simplify_text( from ) replace(from,replace_from,replace_to)
|
06583f | 1997-09-03 | Per Hedbor | |
|
c97c42 | 1998-08-20 | Per Hedbor | | #define CACHE_SIZE 2048
|
a5c21b | 1999-05-18 | Peter Bortas | | #define FNAME(a,b) (query("cache_dir")+sprintf("%x",hash(reverse(a[6..])))+sprintf("%x",hash(b))+sprintf("%x",hash(reverse(b-" ")))+sprintf("%x",hash(b[12..])))
|
20ca2b | 1998-01-26 | Per Hedbor | |
array get_cache_file(string a, string b)
{
|
8afc81 | 1998-02-04 | Per Hedbor | | object fd = open(FNAME(a,b), "r");
|
20ca2b | 1998-01-26 | Per Hedbor | | if(!fd) return 0;
|
34107f | 1998-12-30 | Johan Schön | | catch {
array r = decode_value(fd->read());
if(r[0]==a && r[1]==b) return r[2];
};
|
20ca2b | 1998-01-26 | Per Hedbor | | }
void store_cache_file(string a, string b, array data)
{
|
8afc81 | 1998-02-04 | Per Hedbor | | object fd = open(FNAME(a,b), "wct");
|
20ca2b | 1998-01-26 | Per Hedbor | | if(!fd) return;
fd->write(encode_value(({a,b,data})));
destruct(fd);
}
|
a5c21b | 1999-05-18 | Peter Bortas | | array(int)|string write_text(int _args, string text, int size, object id)
|
d47cbf | 1996-12-02 | Per Hedbor | | {
|
a5c21b | 1999-05-18 | Peter Bortas | | string key = base_key+_args;
|
7faa95 | 1997-09-01 | Per Hedbor | | array err;
|
420fd9 | 1998-02-27 | Per Hedbor | | string orig_text = text;
mixed data;
|
a5c21b | 1999-05-18 | Peter Bortas | | mapping args = find_cached_args(_args) || ([]);
|
86352a | 1998-03-01 | Per Hedbor | |
|
a5c21b | 1999-05-18 | Peter Bortas | | if(data = cache_lookup(key, text))
|
420fd9 | 1998-02-27 | Per Hedbor | | {
if(args->nocache)
cache_remove(key, text);
if(size) return data[1];
return data[0];
} else if(data = get_cache_file( key, text )) {
cache_set(key, text, data);
if(size) return data[1];
|
86352a | 1998-03-01 | Per Hedbor | | return data[0];
|
420fd9 | 1998-02-27 | Per Hedbor | | }
|
a5c21b | 1999-05-18 | Peter Bortas | |
|
86352a | 1998-03-01 | Per Hedbor | |
|
a5c21b | 1999-05-18 | Peter Bortas | |
|
0a76aa | 1998-03-27 | David Hedbor | | err = catch
|
ba73a2 | 1996-12-10 | Per Hedbor | | {
|
0a76aa | 1998-03-27 | David Hedbor | | object img;
|
c5253a | 1998-08-18 | David Hedbor | |
if(!sizeof(args))
|
0a76aa | 1998-03-27 | David Hedbor | | {
|
91641c | 1998-09-14 | David Hedbor | | args=(["fg":"black","bg":"white","notrans":"1","nocache":"1"]);
|
0a76aa | 1998-03-27 | David Hedbor | | text="Please reload this page";
}
if(!args->verbatim)
|
06583f | 1997-09-03 | Per Hedbor | | {
|
0a76aa | 1998-03-27 | David Hedbor | | text = replace(text, nbsp, " ");
text = simplify_text( text );
string res="",nspace="",cspace="";
foreach(text/"\n", string line)
|
06583f | 1997-09-03 | Per Hedbor | | {
|
0a76aa | 1998-03-27 | David Hedbor | | cspace="";nspace="";
foreach(line/" ", string word)
{
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) &&
(upper_case(word) == word)) {
word=((word/"")*nbsp);
}
} else if(cspace!="") {
cspace=" ";
|
4b6447 | 1997-09-04 | Henrik Grubbström (Grubba) | | }
|
0a76aa | 1998-03-27 | David Hedbor | | res+=(nspace==cspace?nspace:" ")+word;
|
1cd5eb | 1998-03-20 | Per Hedbor | |
|
0a76aa | 1998-03-27 | David Hedbor | | if(cspace!="") nspace=cspace;
else nspace=" ";
}
res+="\n";
|
06583f | 1997-09-03 | Per Hedbor | | }
|
0a76aa | 1998-03-27 | David Hedbor | | text = replace(res[..strlen(res)-2], ({ "!","?",": " }), ({ nbsp+"!",nbsp+"?",nbsp+": " }));
text = replace(replace(replace(text,({". ",". "+nbsp}), ({"\000","\001"})),".","."+nbsp+nbsp),({"\000","\001"}),({". ","."+nbsp}));
|
06583f | 1997-09-03 | Per Hedbor | | }
|
20ca2b | 1998-01-26 | Per Hedbor | |
|
420fd9 | 1998-02-27 | Per Hedbor | |
|
b551e1 | 1996-12-10 | Per Hedbor | |
|
a5c21b | 1999-05-18 | Peter Bortas | | #if efun(resolve_font)
|
814db5 | 1998-09-12 | Per Hedbor | | if(args->afont)
{
|
a5c21b | 1999-05-18 | Peter Bortas | | data = resolve_font(args->afont);
}
else
#endif
if(args->nfont)
{
|
0a76aa | 1998-03-27 | David Hedbor | | int bold, italic;
if(args->bold) bold=1;
if(args->light) bold=-1;
|
a5c21b | 1999-05-18 | Peter Bortas | | if(args->italic) italic=1;
|
0a76aa | 1998-03-27 | David Hedbor | | if(args->black) bold=2;
|
a5c21b | 1999-05-18 | Peter Bortas | | data = get_font(args->nfont,(int)args->font_size||32,bold,italic,
lower_case(args->talign||"left"),
(float)(int)args->xpad, (float)(int)args->ypad);
}
else if(args->font)
{
data = resolve_font(args->font);
if(!data)
data = load_font(args->font, lower_case(args->talign||"left"),
(int)args->xpad,(int)args->ypad);
} else {
int bold, italic;
if(args->bold) bold=1;
if(args->light) bold=-1;
|
0a76aa | 1998-03-27 | David Hedbor | | if(args->italic) italic=1;
|
a5c21b | 1999-05-18 | Peter Bortas | | if(args->black) bold=2;
data = get_font(roxen->QUERY(default_font),32,bold,italic,
|
0a76aa | 1998-03-27 | David Hedbor | | lower_case(args->talign||"left"),
(float)(int)args->xpad, (float)(int)args->ypad);
|
a5c21b | 1999-05-18 | Peter Bortas | | }
|
dbcf85 | 1997-09-05 | Henrik Grubbström (Grubba) | |
|
a5c21b | 1999-05-18 | Peter Bortas | | if (!data) {
|
0a76aa | 1998-03-27 | David Hedbor | | roxen_perror("gtext: No font!\n");
return(0);
}
|
d47cbf | 1996-12-02 | Per Hedbor | |
|
0a76aa | 1998-03-27 | David Hedbor | |
img = make_text_image(args,data,text,id);
if(!img) {
return 0;
}
|
1cd5eb | 1998-03-20 | Per Hedbor | |
|
a5c21b | 1999-05-18 | Peter Bortas | | int q = (int)args->quant||(args->background||args->texture?250:QUERY(cols));
|
0a76aa | 1998-03-27 | David Hedbor | |
|
7faa95 | 1997-09-01 | Per Hedbor | | if(q>255) q=255;
if(q<3) q=3;
|
c3655b | 1997-01-27 | Per Hedbor | |
|
a5c21b | 1999-05-18 | Peter Bortas | |
|
b796b5 | 1998-11-18 | Per Hedbor | | if(!args->fs)
|
a5c21b | 1999-05-18 | Peter Bortas | | {
#ifdef QUANT_DEBUG
print_colors(img->select_colors(q-1)+({parse_color(args->bg)}));
#endif
img = img->map_closest(img->select_colors(q-1)+({parse_color(args->bg)}));
}
|
0a76aa | 1998-03-27 | David Hedbor | |
if(!args->scroll)
if(args->fadein)
|
e8c29c | 1997-09-12 | Johan Schön | | {
|
0a76aa | 1998-03-27 | David Hedbor | | int amount=2, steps=10, delay=10, initialdelay=0, ox;
string res = img->gif_begin();
|
a5c21b | 1999-05-18 | Peter Bortas | | sscanf(args->fadein, "%d,%d,%d,%d", amount, steps, delay, initialdelay);
|
0a76aa | 1998-03-27 | David Hedbor | | if(initialdelay)
{
object foo=Image.image(img->xsize(),img->ysize(),@parse_color(args->bg));
res += foo->gif_add(0,0,initialdelay);
}
for(int i = 0; i<(steps-1); i++)
{
object foo=img->clone();
foo = foo->apply_matrix(make_matrix(( (int)((steps-i)*amount))));
res += foo->gif_add(0,0,delay);
}
res+= img->gif_add(0,0,delay);
res += img->gif_end();
data = ({ res, ({ img->xsize(), img->ysize() }) });
|
1cd5eb | 1998-03-20 | Per Hedbor | | }
else
|
0a76aa | 1998-03-27 | David Hedbor | | {
if(args->fs)
data=({ img->togif_fs(@(args->notrans?({}):parse_color(args->bg))),
({img->xsize(),img->ysize()})});
else
data=({ img->togif(@(args->notrans?({}):parse_color(args->bg))),
({img->xsize(),img->ysize()})});
img=0;
|
a5c21b | 1999-05-18 | Peter Bortas | | } else {
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(),
@parse_color(args->bg))->gif_add(0,0,delay);
}
res += img->gif_end();
data = ({ res, ({ len, img->ysize() }) });
|
1cd5eb | 1998-03-20 | Per Hedbor | | }
|
e8c29c | 1997-09-12 | Johan Schön | |
|
0a76aa | 1998-03-27 | David Hedbor | |
|
a5c21b | 1999-05-18 | Peter Bortas | | if(!args->nocache)
|
0a76aa | 1998-03-27 | David Hedbor | | store_cache_file( key, orig_text, data );
cache_set(key, orig_text, data);
|
a5c21b | 1999-05-18 | Peter Bortas | |
|
0a76aa | 1998-03-27 | David Hedbor | | if(size) return data[1];
return data[0];
};
cache_set(key, text, 0);
throw(err);
|
d47cbf | 1996-12-02 | Per Hedbor | | }
|
f3a6b1 | 1998-02-22 | David Hedbor | | mapping find_file(string f, object rid);
void restore_cached_args();
|
41d0f9 | 1998-02-20 | Per Hedbor | | array stat_file(string f, object rid)
{
if(f[-1]=='/') f = f[..strlen(f)-2];
if(sizeof(f/"/")==1) return ({ 509,-3,time(),time(),time(),0,0 });
int len=4711;
catch(len= strlen(find_file(f,rid)->data));
return ({ 33204,len,time(),time(),time(),0,0 });
}
array find_dir(string f, object rid)
{
|
a5c21b | 1999-05-18 | Peter Bortas | | if(!strlen(f))
{
if(!args_restored) restore_cached_args();
return Array.map(indices(cached_args), lambda(mixed m){return (string)m;});
}
return ({"Example"});
|
41d0f9 | 1998-02-20 | Per Hedbor | | }
|
a5c21b | 1999-05-18 | Peter Bortas | |
|
d47cbf | 1996-12-02 | Per Hedbor | | mapping find_file(string f, object rid)
{
|
a5c21b | 1999-05-18 | Peter Bortas | | int id;
#if constant(Gz)
object g;
#endif
|
9558e3 | 1998-07-04 | Per Hedbor | |
|
a5c21b | 1999-05-18 | Peter Bortas | | if((rid->method != "GET")
|| (sscanf(f,"%d/%s", id, f) != 2))
|
9558e3 | 1998-07-04 | Per Hedbor | | return 0;
|
974b2a | 1997-10-02 | Peter Bortas | |
|
9558e3 | 1998-07-04 | Per Hedbor | | if( query("gif") && f[strlen(f)-4..]==".gif")
|
974b2a | 1997-10-02 | Peter Bortas | | f = f[..strlen(f)-5];
|
1a6758 | 1997-09-26 | Henrik Grubbström (Grubba) | |
|
9558e3 | 1998-07-04 | Per Hedbor | | if(!sizeof(f))
return 0;
|
a5c21b | 1999-05-18 | Peter Bortas | | if (f[0] == '$')
f = f[1..];
#if constant(Gz)
else if (sizeof(indices(g=Gz)))
catch(f = g->inflate()->inflate(MIME.decode_base64(f)));
#endif
else
catch(f = MIME.decode_base64(f));
|
51266a | 1999-05-12 | Per Hedbor | |
return http_string_answer(write_text(id,f,0,rid), "image/gif");
|
68e030 | 1997-08-19 | Per Hedbor | | }
|
a5c21b | 1999-05-18 | Peter Bortas | | mapping url_cache = ([]);
|
51266a | 1999-05-12 | Per Hedbor | | string quote(string in)
|
68e030 | 1997-08-19 | Per Hedbor | | {
|
a5c21b | 1999-05-18 | Peter Bortas | | string option;
if(option = url_cache[in]) return option;
object g;
if (sizeof(indices(g=Gz))) {
option=MIME.encode_base64(g->deflate()->deflate(in));
} else {
option=MIME.encode_base64(in);
}
if(search(in,"/")!=-1) return url_cache[in]=option;
string res="$";
for(int i=0; i<strlen(in); i++)
switch(in[i])
{
case 'a'..'z':
case 'A'..'Z':
case '0'..'9':
case '.': case ',': case '!':
res += in[i..i];
break;
default:
res += sprintf("%%%02x", in[i]);
}
if(strlen(res) < strlen(option)) return url_cache[in]=res;
return url_cache[in]=option;
}
#define ARGHASH query("cache_dir")+"ARGS_"+hash(mc->name)
int last_argstat;
void restore_cached_args()
{
args_restored = 1;
array a = file_stat(ARGHASH);
if(a && (a[ST_MTIME] > last_argstat))
{
last_argstat = a[ST_MTIME];
object o = open(ARGHASH, "r");
if(o)
{
string data = o->read();
catch {
object q;
if(sizeof(indices(q=Gz)))
data=q->inflate()->inflate(data);
};
catch {
cached_args |= decode_value(data);
};
}
NUMBER_LOCK();
if (cached_args && sizeof(cached_args)) {
number = sort(indices(cached_args))[-1]+1;
} else {
cached_args = ([]);
number = 0;
}
NUMBER_UNLOCK();
}
}
void save_cached_args()
{
restore_cached_args();
object o = open(ARGHASH, "wct");
if(o)
{
string data=encode_value(cached_args);
catch {
object q;
if(sizeof(indices(q=Gz)))
data=q->deflate()->deflate(data);
};
o->write(data);
}
}
mapping find_cached_args(int num)
{
if(!args_restored) restore_cached_args();
if(cached_args[num]) return cached_args[num];
restore_cached_args();
if(cached_args[num]) return cached_args[num];
return 0;
|
68e030 | 1997-08-19 | Per Hedbor | | }
|
a5c21b | 1999-05-18 | Peter Bortas | |
int find_or_insert(mapping find)
{
mapping f2 = copy_value(find);
int res;
string q;
foreach(glob("magic_*", indices(f2)), q)
m_delete(f2,q);
if(!args_restored)
restore_cached_args( );
array a=indices(f2),b=values(f2);
sort(a,b);
q = a*""+Array.map(b, lambda(mixed x) { return (string)x; })*"";
if(res = cached_args[ q ])
return res;
restore_cached_args();
if(res = cached_args[ q ])
return res;
int n;
NUMBER_LOCK();
cached_args[ number ] = f2;
cached_args[ q ] = number;
n = number++;
NUMBER_UNLOCK();
remove_call_out(save_cached_args);
call_out(save_cached_args, 10);
return n;
}
|
d47cbf | 1996-12-02 | Per Hedbor | | string magic_javascript_header(object id)
{
|
273a9a | 1997-10-17 | Johan Schön | | if(!id->supports->netscape_javascript || !id->supports->images) return "";
|
d47cbf | 1996-12-02 | Per Hedbor | | return
|
094371 | 1997-02-25 | Per Hedbor | | ("\n<script>\n"
|
e8790b | 1998-02-19 | Per Hedbor | | "function i(ri,hi,txt)\n"
|
d47cbf | 1996-12-02 | Per Hedbor | | "{\n"
|
094371 | 1997-02-25 | Per Hedbor | | " document.images[ri].src = hi.src;\n"
" setTimeout(\"top.window.status = '\"+txt+\"'\", 100);\n"
|
d47cbf | 1996-12-02 | Per Hedbor | | "}\n"
"</script>\n");
|
a5c21b | 1999-05-18 | Peter Bortas | |
|
d47cbf | 1996-12-02 | Per Hedbor | | }
string magic_image(string url, int xs, int ys, string sn,
string image_1, string image_2, string alt,
|
a5c21b | 1999-05-18 | Peter Bortas | | string mess,object id,string input,string extra_args,string lp)
|
d47cbf | 1996-12-02 | Per Hedbor | | {
|
dd8da8 | 1998-09-21 | Johan Schön | | if(!id->supports->images) return (lp?lp:"")+alt+(lp?"</a>":"");
|
273a9a | 1997-10-17 | Johan Schön | | if(!id->supports->netscape_javascript)
|
38dca8 | 1996-12-10 | Per Hedbor | | return (!input)?
|
c97c42 | 1998-08-20 | Per Hedbor | | ("<a "+extra_args+"href=\""+url+"\"><img src=\""+image_1+"\" name="+sn+" border=0 "+
|
704c36 | 1998-08-28 | Johan Schön | | "alt=\""+alt+"\"></a>"):
|
a5c21b | 1999-05-18 | Peter Bortas | | ("<input type=image "+extra_args+" src=\""+image_1+"\" name="+input+">");
|
d47cbf | 1996-12-02 | Per Hedbor | |
return
("<script>\n"
|
7f79ee | 1998-08-02 | Peter Bortas | | " "+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"+
|
ca0f08 | 1997-02-22 | Per Hedbor | | ("<a "+extra_args+"href=\""+url+"\" "+
(input?"onClick='document.forms[0].submit();' ":"")
|
a5c21b | 1999-05-18 | Peter Bortas | | +"onMouseover=\"i('"+sn+"',"+sn+"h,'"+(mess||url)+"'); return true;\"\n"
|
bf6620 | 1998-09-20 | David Hedbor | | "onMouseout=\"top.window.status='';document.images['"+sn+"'].src = "+sn+"l.src;\"><img "
|
41d0f9 | 1998-02-20 | Per Hedbor | | "width="+xs+" height="+ys+" src=\""+image_1+"\" name="+sn+
|
704c36 | 1998-08-28 | Johan Schön | | " border=0 alt=\""+alt+"\" ></a>"));
|
d47cbf | 1996-12-02 | Per Hedbor | | }
|
b91fd5 | 1996-12-10 | Per Hedbor | |
string extra_args(mapping in)
{
string s="";
foreach(indices(in), string i)
{
switch(i)
{
case "target":
|
bfc707 | 1997-01-13 | Per Hedbor | | case "hspace":
case "vspace":
case "onclick":
|
b7ee57 | 1998-04-19 | Peter Bortas | | case "class":
case "id":
|
80739c | 1996-12-10 | Per Hedbor | | s+=i+"='"+in[i]+"' ";
|
b91fd5 | 1996-12-10 | Per Hedbor | | m_delete(in, i);
break;
}
}
return s;
}
|
07969c | 1997-02-25 | Per Hedbor | | string tag_gtext_id(string t, mapping arg,
object id, object foo, mapping defines)
{
int short=!!arg->short;
|
fc5752 | 1998-03-06 | Per Hedbor | | if(arg->help) return "Arguments are identical to the argumets to <gtext>. This tag returns a url-prefix that can be used to generate gtexts.";
|
07969c | 1997-02-25 | Per Hedbor | | 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;
|
814db5 | 1998-09-12 | Per Hedbor | | if(defines->nfont && !arg->nfont) arg->nfont=defines->nfont;
if(defines->afont && !arg->afont) arg->afont=defines->afont;
|
a5c21b | 1999-05-18 | Peter Bortas | | if(defines->font && !arg->font) arg->font=defines->font;
|
3a4d7e | 1997-09-03 | Per Hedbor | |
|
c97c42 | 1998-08-20 | Per Hedbor | | if(arg->background)
arg->background = fix_relative(arg->background,id);
if(arg->texture)
arg->texture = fix_relative(arg->texture,id);
if(arg->magic_texture)
arg->magic_texture=fix_relative(arg->magic_texture,id);
if(arg->magic_background)
arg->magic_background=fix_relative(arg->magic_background,id);
if(arg->magicbg)
arg->magicbg = fix_relative(arg->magicbg,id);
if(arg->alpha)
arg->alpha = fix_relative(arg->alpha,id);
|
a5c21b | 1999-05-18 | Peter Bortas | | int num = find_or_insert( arg );
|
07969c | 1997-02-25 | Per Hedbor | |
if(!short)
|
a5c21b | 1999-05-18 | Peter Bortas | | return query_location()+num+"/";
|
07969c | 1997-02-25 | Per Hedbor | | else
|
a5c21b | 1999-05-18 | Peter Bortas | | return (string)num;
|
07969c | 1997-02-25 | Per Hedbor | | }
|
62d8c4 | 1997-10-16 | Per Hedbor | | string tag_graphicstext(string t, mapping arg, string contents,
object id, object foo, mapping defines)
{
|
0d19e0 | 1998-07-06 | Peter Bortas | | if((contents-" ")=="")
return "";
|
62d8c4 | 1997-10-16 | Per Hedbor | |
|
704c36 | 1998-08-28 | Johan Schön | | if(arg->nowhitespace)
{
sscanf(contents,"%*[ \n\r\t]%s",contents);
sscanf(reverse(contents),"%*[ \n\r\t]%s",contents);
contents=reverse(contents);
}
|
a5c21b | 1999-05-18 | Peter Bortas | | if(t=="gtext" && arg->help)
return doc();
else if(arg->help)
|
fc5752 | 1998-03-06 | Per Hedbor | | return "This tag calls <gtext> with different default values.";
|
41d0f9 | 1998-02-20 | Per Hedbor | | if(arg->background)
arg->background = fix_relative(arg->background,id);
if(arg->texture)
arg->texture = fix_relative(arg->texture,id);
if(arg->magic_texture)
arg->magic_texture=fix_relative(arg->magic_texture,id);
if(arg->magic_background)
arg->magic_background=fix_relative(arg->magic_background,id);
if(arg->magicbg)
arg->magicbg = fix_relative(arg->magicbg,id);
|
7b15a6 | 1998-08-10 | Johan Schön | | if(arg->alpha)
arg->alpha = fix_relative(arg->alpha,id);
|
41d0f9 | 1998-02-20 | Per Hedbor | |
|
974b2a | 1997-10-02 | Peter Bortas | | string gif="";
|
62d8c4 | 1997-10-16 | Per Hedbor | | if(query("gif")) gif=".gif";
|
974b2a | 1997-10-02 | Peter Bortas | |
|
a5c21b | 1999-05-18 | Peter Bortas | | #if efun(_static_modules)
|
033c7e | 1997-02-27 | Per Hedbor | | contents = parse_rxml(contents, id, foo, defines);
|
a5c21b | 1999-05-18 | Peter Bortas | | #else
contents = parse_rxml(contents, id, foo);
#endif
|
033c7e | 1997-02-27 | Per Hedbor | |
|
62d8c4 | 1997-10-16 | Per Hedbor | | string lp, url, ea;
|
d47cbf | 1996-12-02 | Per Hedbor | | string pre, post, defalign, gt, rest, magic;
|
1bd5c9 | 1997-09-26 | Henrik Grubbström (Grubba) | | int i;
string split;
|
d47cbf | 1996-12-02 | Per Hedbor | |
|
bfc707 | 1997-01-13 | Per Hedbor | | contents = contents[..((int)arg->maxlen||QUERY(deflen))];
m_delete(arg, "maxlen");
|
d47cbf | 1996-12-02 | Per Hedbor | | if(arg->magic)
{
|
d23e42 | 1997-05-08 | Per Hedbor | | magic=replace(arg->magic,"'","`");
|
d47cbf | 1996-12-02 | Per Hedbor | | m_delete(arg,"magic");
}
|
38dca8 | 1996-12-10 | Per Hedbor | |
int input;
if(arg->submit)
{
input=1;
m_delete(arg,"submit");
}
|
d47cbf | 1996-12-02 | Per Hedbor | |
|
bfc707 | 1997-01-13 | Per Hedbor | |
|
80739c | 1996-12-10 | Per Hedbor | | ea = extra_args(arg);
|
bfc707 | 1997-01-13 | Per Hedbor | |
|
094371 | 1997-02-25 | Per Hedbor | |
|
d47cbf | 1996-12-02 | Per Hedbor | | if(arg->href)
{
url = arg->href;
|
80739c | 1996-12-10 | Per Hedbor | | lp = "<a href=\""+arg->href+"\" "+ea+">";
|
d47cbf | 1996-12-02 | Per Hedbor | | if(!arg->fg) arg->fg=defines->link||"#0000ff";
|
094371 | 1997-02-25 | Per Hedbor | | m_delete(arg, "href");
|
d47cbf | 1996-12-02 | Per Hedbor | | }
if(defines->fg && !arg->fg) arg->fg=defines->fg;
if(defines->bg && !arg->bg) arg->bg=defines->bg;
|
814db5 | 1998-09-12 | Per Hedbor | | if(defines->nfont && !arg->nfont) arg->nfont=defines->nfont;
if(defines->afont && !arg->afont) arg->afont=defines->afont;
|
a5c21b | 1999-05-18 | Peter Bortas | | if(defines->font && !arg->font) arg->font=defines->font;
|
814db5 | 1998-09-12 | Per Hedbor | | if(defines->bold && !arg->bold) arg->bold=defines->bold;
if(defines->italic && !arg->italic) arg->italic=defines->italic;
if(defines->black && !arg->black) arg->black=defines->black;
if(defines->narrow && !arg->narrow) arg->narrow=defines->narrow;
|
d47cbf | 1996-12-02 | Per Hedbor | |
if(arg->split)
{
|
f1be80 | 1998-02-22 | Per Hedbor | | if (sizeof(split=arg->split) != 1)
|
1bd5c9 | 1997-09-26 | Henrik Grubbström (Grubba) | | split = " ";
|
d47cbf | 1996-12-02 | Per Hedbor | | m_delete(arg,"split");
}
for(i=2; i<10; i++)
if(arg[(string)i])
{
arg->scale = 1.0 / ((float)i*0.6);
m_delete(arg, (string)i);
|
9d16ce | 1997-03-01 | Per Hedbor | | break;
|
d47cbf | 1996-12-02 | Per Hedbor | | }
if(sscanf(t, "%s%d", t, i)==2)
if(i > 1) arg->scale = 1.0 / ((float)i*0.6);
|
094371 | 1997-02-25 | Per Hedbor | | string na = arg->name, al=arg->align;
m_delete(arg, "name"); m_delete(arg, "align");
|
d47cbf | 1996-12-02 | Per Hedbor | |
|
a5c21b | 1999-05-18 | Peter Bortas | |
int num = find_or_insert( arg );
|
d47cbf | 1996-12-02 | Per Hedbor | |
gt=contents;
rest="";
|
f6d62d | 1997-03-26 | Per Hedbor | | 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;
}
|
d47cbf | 1996-12-02 | Per Hedbor | | if(split)
{
string word;
|
bfb80b | 1997-09-26 | Henrik Grubbström (Grubba) | | array res = ({ pre });
string pre = query_location() + num + "/";
|
d47cbf | 1996-12-02 | Per Hedbor | |
if(lp) res+=({ lp });
gt=replace(gt, "\n", " ");
foreach(gt/" "-({""}), word)
{
|
1bd5c9 | 1997-09-26 | Henrik Grubbström (Grubba) | | if (split != " ") {
array arr = word/split;
int i;
|
f1be80 | 1998-02-22 | Per Hedbor | | for (i = sizeof(arr)-1; i--;)
|
1bd5c9 | 1997-09-26 | Henrik Grubbström (Grubba) | | arr[i] += split;
|
f1be80 | 1998-02-22 | Per Hedbor | | if (arr[-1] == "")
|
1bd5c9 | 1997-09-26 | Henrik Grubbström (Grubba) | | arr = arr[..sizeof(arr)-2];
foreach (arr, word) {
array size = write_text(num,word,1,id);
|
41d0f9 | 1998-02-20 | Per Hedbor | | res += ({ "<img border=0 alt=\"" +
|
bfb80b | 1997-09-26 | Henrik Grubbström (Grubba) | | replace(arg->alt || word, "\"", "'") +
|
974b2a | 1997-10-02 | Peter Bortas | | "\" src=\"" + pre + quote(word) + gif + "\" width=" +
|
bfb80b | 1997-09-26 | Henrik Grubbström (Grubba) | | size[0] + " height=" + size[1] + " " + ea + ">"
|
1bd5c9 | 1997-09-26 | Henrik Grubbström (Grubba) | | });
}
|
bfb80b | 1997-09-26 | Henrik Grubbström (Grubba) | | res += ({"\n"});
|
1bd5c9 | 1997-09-26 | Henrik Grubbström (Grubba) | | } else {
array size = write_text(num,word,1,id);
|
a5c21b | 1999-05-18 | Peter Bortas | | res += ({ "<img border=0 alt=\"" +
|
bfb80b | 1997-09-26 | Henrik Grubbström (Grubba) | | replace(arg->alt || word, "\"", "'") +
|
974b2a | 1997-10-02 | Peter Bortas | | "\" src=\"" + pre + quote(word) + gif + "\" width=" +
|
354b6c | 1998-11-22 | Per Hedbor | | size[0] + " height=" + size[1] + " " + ea + ">\n"
|
a5c21b | 1999-05-18 | Peter Bortas | | });
|
1bd5c9 | 1997-09-26 | Henrik Grubbström (Grubba) | | }
|
d47cbf | 1996-12-02 | Per Hedbor | | }
|
bfb80b | 1997-09-26 | Henrik Grubbström (Grubba) | | if(lp) res += ({ "</a>"+post });
|
d47cbf | 1996-12-02 | Per Hedbor | | return res*"";
}
|
9d16ce | 1997-03-01 | Per Hedbor | | array size = write_text(num,gt,1,id);
|
f1be80 | 1998-02-22 | Per Hedbor | | if(!size)
|
f7d981 | 1997-09-12 | Per Hedbor | | return ("<font size=+1><b>Missing font or other similar error -- "
"failed to render text</b></font>");
|
f1be80 | 1998-02-22 | Per Hedbor | |
|
d47cbf | 1996-12-02 | Per Hedbor | | if(magic)
{
string res = "";
|
bfc707 | 1997-01-13 | Per Hedbor | | if(!arg->fg) arg->fg=defines->link||"#0000ff";
|
d47cbf | 1996-12-02 | Per Hedbor | | arg = mkmapping(indices(arg), values(arg));
|
bfc707 | 1997-01-13 | Per Hedbor | | if(arg->fuzz)
if(arg->fuzz != "fuzz")
arg->glow = arg->fuzz;
else
arg->glow = arg->fg;
|
d47cbf | 1996-12-02 | Per Hedbor | | arg->fg = defines->alink||"#ff0000";
|
9f67f3 | 1997-10-27 | Per Hedbor | | if(arg->magicbg) arg->background = arg->magicbg;
|
38dca8 | 1996-12-10 | Per Hedbor | | if(arg->bevel) arg->pressed=1;
|
094371 | 1997-02-25 | Per Hedbor | |
|
20ca2b | 1998-01-26 | Per Hedbor | | foreach(glob("magic_*", indices(arg)), string q)
{
arg[q[6..]]=arg[q];
m_delete(arg, q);
}
|
a5c21b | 1999-05-18 | Peter Bortas | | int num2 = find_or_insert(arg);
|
9d16ce | 1997-03-01 | Per Hedbor | | array size = write_text(num2,gt,1,id);
|
094371 | 1997-02-25 | Per Hedbor | |
|
38dca8 | 1996-12-10 | Per Hedbor | | if(!defines->magic_java) res = magic_javascript_header(id);
|
d47cbf | 1996-12-02 | Per Hedbor | | defines->magic_java="yes";
|
094371 | 1997-02-25 | Per Hedbor | |
|
e8790b | 1998-02-19 | Per Hedbor | | return replace(res +
magic_image(url||"", size[0], size[1], "i"+(defines->mi++),
query_location()+num+"/"+quote(gt)+gif,
query_location()+num2+"/"+quote(gt)+gif,
(arg->alt?arg->alt:replace(gt, "\"","'")),
(magic=="magic"?0:magic),
|
dd8da8 | 1998-09-21 | Johan Schön | | id,input?na||"submit":0,ea,lp),
|
e8790b | 1998-02-19 | Per Hedbor | | "</script>\n<script>","");
|
d47cbf | 1996-12-02 | Per Hedbor | | }
|
ca0f08 | 1997-02-22 | Per Hedbor | | if(input)
|
094371 | 1997-02-25 | Per Hedbor | | return (pre+"<input type=image name=\""+na+"\" border=0 alt=\""+
|
eab422 | 1997-09-19 | Johan Schön | | (arg->alt?arg->alt:replace(gt,"\"","'"))+
|
974b2a | 1997-10-02 | Peter Bortas | | "\" src="+query_location()+num+"/"+quote(gt)+gif
|
094371 | 1997-02-25 | Per Hedbor | | +" align="+(al || defalign)+ea+
|
38dca8 | 1996-12-10 | Per Hedbor | | " width="+size[0]+" height="+size[1]+">"+rest+post);
|
974b2a | 1997-10-02 | Peter Bortas | |
return (pre+(lp?lp:"")
|
41d0f9 | 1998-02-20 | Per Hedbor | | + "<img border=0 alt=\""
|
219eec | 1998-02-02 | Jens Utbult | | + (arg->alt?arg->alt:replace(gt,"\"","'"))
|
974b2a | 1997-10-02 | Peter Bortas | | + "\" src=\""
+ query_location()+num+"/"+quote(gt)+gif+"\" "+ea
+ " align="+(al || defalign)
+ " width="+size[0]+" height="+size[1]+">"+rest+(lp?"</a>":"")+post);
|
d47cbf | 1996-12-02 | Per Hedbor | | }
|
bfc707 | 1997-01-13 | Per 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]);
}
string make_args(mapping in)
{
array a=indices(in), b=values(in);
for(int i=0; i<sizeof(a); i++)
if(lower_case(b[i])!=a[i])
if(search(b,"\"")==-1)
a[i]+="=\""+b[i]+"\"";
else
a[i]+="='"+b[i]+"'";
return a*" ";
}
|
fc5752 | 1998-03-06 | Per Hedbor | | string|array (string) tag_body(string t, mapping args, object id, object file,
mapping defines)
|
d47cbf | 1996-12-02 | Per Hedbor | | {
|
bfc707 | 1997-01-13 | Per Hedbor | | int cols,changed;
|
fc5752 | 1998-03-06 | Per Hedbor | | if(args->help) return "This tag is parsed by <gtext> to get the document colors.";
|
bfc707 | 1997-01-13 | Per Hedbor | | if(args->bgcolor||args->text||args->link||args->alink
||args->background||args->vlink)
cols=1;
|
a5c21b | 1999-05-18 | Peter Bortas | | #define FIX(Y,Z,X) do{if(!args->Y || args->Y==""){if(cols){defines->X=Z;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)
|
bfc707 | 1997-01-13 | Per Hedbor | |
|
2ce370 | 1998-03-29 | Henrik Grubbström (Grubba) | | if(!search((id->client||({}))*"","Mosaic"))
|
0ee085 | 1997-02-08 | Per Hedbor | | {
FIX(bgcolor,"#bfbfbf",bg);
FIX(text, "#000000",fg);
FIX(link, "#0000b0",link);
FIX(alink, "#3f0f7b",alink);
FIX(vlink, "#ff0000",vlink);
} else {
FIX(bgcolor,"#c0c0c0",bg);
FIX(text, "#000000",fg);
FIX(link, "#0000ee",link);
FIX(alink, "#ff0000",alink);
FIX(vlink, "#551a8b",vlink);
}
|
c97c42 | 1998-08-20 | Per Hedbor | | if(changed && QUERY(colormode))
return ({make_tag("body", args) });
|
d47cbf | 1996-12-02 | Per Hedbor | | }
|
196dac | 1997-02-22 | Per Hedbor | |
|
fc5752 | 1998-03-06 | Per Hedbor | | string|array(string) tag_fix_color(string tagname, mapping args, object id,
object file, mapping defines)
|
bfc707 | 1997-01-13 | Per Hedbor | | {
int changed;
|
196dac | 1997-02-22 | Per Hedbor | |
|
fc5752 | 1998-03-06 | Per Hedbor | | if(args->help) return "This tag is parsed by <gtext> to get the document colors.";
|
196dac | 1997-02-22 | Per Hedbor | | if(!id->misc->colors)
|
5f0d91 | 1997-02-27 | Per Hedbor | | id->misc->colors = ({ ({ defines->fg, defines->bg, tagname }) });
|
196dac | 1997-02-22 | Per Hedbor | | else
|
5f0d91 | 1997-02-27 | Per Hedbor | | id->misc->colors += ({ ({ defines->fg, defines->bg, tagname }) });
|
f7d981 | 1997-09-12 | Per Hedbor | | #undef FIX
|
c97c42 | 1998-08-20 | Per Hedbor | | #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;}}
|
bfc707 | 1997-01-13 | Per Hedbor | |
FIX(bgcolor,bg);
FIX(text,fg);
FIX(color,fg);
|
c97c42 | 1998-08-20 | Per Hedbor | | #undef FIX
|
22846b | 1998-05-15 | Per Hedbor | |
|
c97c42 | 1998-08-20 | Per Hedbor | | if(changed && QUERY(colormode))
return ({ make_tag(tagname, args) });
|
bfc707 | 1997-01-13 | Per Hedbor | | return 0;
}
|
d47cbf | 1996-12-02 | Per Hedbor | |
|
fc5752 | 1998-03-06 | Per Hedbor | | string|void pop_color(string tagname,mapping args,object id,object file,
|
a5c21b | 1999-05-18 | Peter Bortas | | mapping defines)
|
196dac | 1997-02-22 | Per Hedbor | | {
|
a5c21b | 1999-05-18 | Peter Bortas | | if(args->help) return "This end-tag is parsed by <gtext> to get the document colors.";
|
c97c42 | 1998-08-20 | Per Hedbor | | array c = id->misc->colors;
|
0a76aa | 1998-03-27 | David Hedbor | | if(!c ||!sizeof(c))
return;
|
df8d71 | 1998-02-27 | Per Hedbor | | int i;
tagname = tagname[1..];
for(i=0;i<sizeof(c);i++)
if(c[-i-1][2]==tagname)
|
5f0d91 | 1997-02-27 | Per Hedbor | | {
|
df8d71 | 1998-02-27 | Per Hedbor | | defines->fg = c[-i-1][0];
defines->bg = c[-i-1][1];
|
5f0d91 | 1997-02-27 | Per Hedbor | | break;
}
|
a5c21b | 1999-05-18 | Peter Bortas | | c = c[..sizeof(c)-i-2];
id->misc->colors = c;
|
196dac | 1997-02-22 | Per Hedbor | | }
|
bfc707 | 1997-01-13 | Per Hedbor | | mapping query_tag_callers()
|
d47cbf | 1996-12-02 | Per Hedbor | | {
|
c97c42 | 1998-08-20 | Per Hedbor | | mapping tags = ([ "gtext-id":tag_gtext_id]);
|
39af1a | 1998-08-26 | Per Hedbor | | if(query("colorparse"))
foreach(query("colorparsing"), string t)
|
c97c42 | 1998-08-20 | Per Hedbor | | {
|
39af1a | 1998-08-26 | Per Hedbor | | switch(t)
{
case "body":
tags[t] = tag_body;
break;
default:
tags[t] = tag_fix_color;
tags["/"+t]=pop_color;
}
|
c97c42 | 1998-08-20 | Per Hedbor | | }
return tags;
|
d47cbf | 1996-12-02 | Per Hedbor | | }
mapping query_container_callers()
{
return ([ "anfang":tag_graphicstext,
"gh":tag_graphicstext,
|
bfc707 | 1997-01-13 | Per Hedbor | | "gh1":tag_graphicstext, "gh2":tag_graphicstext,
"gh3":tag_graphicstext, "gh4":tag_graphicstext,
"gh5":tag_graphicstext, "gh6":tag_graphicstext,
|
d47cbf | 1996-12-02 | Per Hedbor | | "gtext":tag_graphicstext, ]);
}
|