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.41 1997/04/09 01:09:33 per Exp $"; + string cvs_version="$Id: graphic_text.pike,v 1.42 1997/05/07 23:07:43 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 + # define Image image + # define Font font   #endif      array register_module()   {    return ({ MODULE_LOCATION | MODULE_PARSER,    "Graphics text",    "Makes a few new tags, which render text to gifs "    "using the image module in pike. \n<p>"    "<b>&lt;gh1&gt;</b> to <b>&lt;gh6&gt;:</b> Headers<br>\n"    "<b>&lt;gh&gt;:</b> Header<br>\n"
Roxen.git/server/modules/graphics/graphic_text.pike:138:    TYPE_STRING_LIST,    "The default font. The 'font dir' will be prepended to the path",    list_fonts());   #endif   }      string query_location() { return query("location"); }      mapping (string:object) fonts = ([]);    - object(font) load_font(string name, string justification, int xs, int ys) + object(Font) load_font(string name, string justification, int xs, int ys)   { -  object fnt = font(); +  object fnt = Font();       if ((!name)||(name == "")) {    name = QUERY(default_size)+"/"+QUERY(default_font);    } else if(sscanf(name, "%*s/%*s") != 2) {    name=QUERY(default_size)+"/"+name;    }       name = "fonts/" + name;       if(!fnt->load( name ))
Roxen.git/server/modules/graphics/graphic_text.pike:201:    return file;   }      object last_image; // Cache the last image for a while.   string last_image_name;   object load_image(string f,object id)   {    if(last_image_name==f) return last_image;    string data;    object file; -  object img = image(); +  object img = Image();       if(!(data=roxen->try_get_file(fix_relative(f, id),id)))    if(!(file=open(f,"r")) || (!(data=file->read(0x7fffffff))))    return 0;       if(!img->frompnm(data) && !img->fromgif(data)) return 0;       last_image_name=f;    last_image=img;    call_out(lambda(){last_image=0;last_image_name=0;}, 0);    return img->copy();   }    - object (image) blur(object img, int amnt) + object (Image) blur(object img, int amnt)   {    img->setcolor(0,0,0);    img = img->autocrop(amnt, 0,0,0,0, 0,0,0);       for(int i=0; i<amnt; i++)    img = img->apply_matrix( make_matrix((int)sqrt(img->ysize()+20)));    return img;   }    - object (image) outline(object (image) on, object (image) with, + object (Image) outline(object (Image) on, object (Image) with,    array (int) color, int radie, int x, int y)   {    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;   }      array white = ({ 255,255,255 });   array lgrey = ({ 200,200,200 });   array grey = ({ 128,128,128 });   array black = ({ 0,0,0 });      array wwwb = ({ lgrey,lgrey,grey,black }); - object (image) bevel(object (image) in, int width, int|void invert) + object (Image) bevel(object (Image) in, int width, int|void invert)   {    int h=in->ysize();    int w=in->xsize();    -  object corner = image(width+1,width+1); -  object corner2 = image(width+1,width+1); -  object pix = image(1,1); +  object corner = Image(width+1,width+1); +  object corner2 = Image(width+1,width+1); +  object pix = 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(width,h-width*2,@white), 160, 0, width); -  in->paste_alpha(image(width,h-width*2,@black), 128, in->xsize()-width, width); -  in->paste_alpha(image(w-width,width,@white), 160, 0, 0); -  in->paste_alpha(image(w-width,width,@black), 128, width, in->ysize()-width); +  in->paste_alpha(Image(width,h-width*2,@white), 160, 0, width); +  in->paste_alpha(Image(width,h-width*2,@black), 128, in->xsize()-width, width); +  in->paste_alpha(Image(w-width,width,@white), 160, 0, 0); +  in->paste_alpha(Image(w-width,width,@black), 128, width, in->ysize()-width);    } else {    corner=corner->invert();    corner2=corner2->invert(); -  in->paste_alpha(image(width,h-width*2,@black), 160, 0, width); -  in->paste_alpha(image(width,h-width*2,@white), 128, in->xsize()-width, width); -  in->paste_alpha(image(w-width,width,@black), 160, 0, 0); -  in->paste_alpha(image(w-width,width,@white), 128, width, in->ysize()-width); +  in->paste_alpha(Image(width,h-width*2,@black), 160, 0, width); +  in->paste_alpha(Image(width,h-width*2,@white), 128, in->xsize()-width, width); +  in->paste_alpha(Image(w-width,width,@black), 160, 0, 0); +  in->paste_alpha(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 (image) make_text_image(mapping args, object font, string text,object id) + object (Image) make_text_image(mapping args, object font, string text,object id)   {    object text_alpha=font->write(@(text/"\n"));    int xoffset=0, yoffset=0;       if(!text_alpha->xsize() || !text_alpha->ysize()) -  text_alpha = image(10,10, 0,0,0); +  text_alpha = Image(10,10, 0,0,0);      // perror("Making image of '%s', args=%O\n", text, args);       if(int op=((((int)args->opaque)*255)/100)) // Transparent text...    text_alpha=text_alpha->color(op,op,op);       int txsize=text_alpha->xsize();    int tysize=text_alpha->ysize(); // Size of the text, in pixels.       int xsize=txsize; // image size, in pixels
Roxen.git/server/modules/graphics/graphic_text.pike:394:    case "center":    xoffset = (xsize/2 - txsize/2);    yoffset = (ysize/2 - tysize/2);    break;    case "right":    xoffset = (xsize - txsize);    break;    case "left":    }    } else -  background = image(xsize, ysize, @bgcolor); +  background = Image(xsize, ysize, @bgcolor);       if(args->border)    {    int b = (int)args->border;    background->setcolor(@parse_color((args->border/",")[-1]));       for(--b;b>=0;b--)    {    // upper left -- upper right    background->line(b,b, xsize-b-1, b);
Roxen.git/server/modules/graphics/graphic_text.pike:450:       if(args->bevel)    background = bevel(background,(int)args->bevel,!!args->pressed);       if(args->textbox) // Draw a text-box on the background.    {    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, +  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;
Roxen.git/server/modules/graphics/graphic_text.pike:488:    }      #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(xs,ys); +  object ta = Image(xs,ys);    ta->paste(text_alpha,sdist,sdist);    ta = blur(ta, MIN((sdist/2),1))->color(256,256,256);    background->paste_alpha_color(ta,0,0,0,xoffset,yoffset);    }       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,
Roxen.git/server/modules/graphics/graphic_text.pike:510:    }       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(txsize, tysize, @fgcolor); +  if(!foreground) foreground=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]),