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.186 1999/08/09 15:09:44 nilsson Exp $"; + constant cvs_version="$Id: graphic_text.pike,v 1.187 1999/09/05 01:43:07 per Exp $";   constant thread_safe=1;      #include <config.h>   #include <module.h>   #include <stat.h>   inherit "module";   inherit "roxenlib";      #ifndef VAR_MORE   #define VAR_MORE 0
Roxen.git/server/modules/graphics/graphic_text.pike:62:      #define MAX(a,b) ((a)<(b)?(b):(a))      static private mapping (int:array(array(int))) matrixes = ([]);   array (array(int)) make_matrix(int size)   {    if(matrixes[size]) return matrixes[size];    array res;    int i;    int j; -  res = Array.map(allocate(size), lambda(int s, int size){ -  return allocate(size); }, size); -  +  res = 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);    return matrixes[size] = res;   }      object blur(object img, int amnt)   {    img->setcolor(0,0,0);    img = img->autocrop(amnt, 0,0,0,0, 0,0,0);
Roxen.git/server/modules/graphics/graphic_text.pike:103:   constant lgrey = ({ 200,200,200 });   constant grey = ({ 128,128,128 });   constant black = ({ 0,0,0 });   constant wwwb = ({ lgrey,lgrey,grey,black });      object bevel(object in, int width, int|void invert)   {    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); +  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); +  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_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)   {    // object text_alpha=font->write(@(text/"\n")); -  object text_alpha=font->write(@(args->encoding? -  (Locale.Charset.decoder(args->encoding)-> -  feed(text)->drain())/"\n" : -  text/"\n")); +  if( args->encoding ) +  text = roxen.decode_charset(args->encoding,text); +  object text_alpha=font->write(@(text/"\n"));    int xoffset=0, yoffset=0;       if(!text_alpha->xsize() || !text_alpha->ysize()) -  text_alpha = Image.image(10,10, 0,0,0); +  text_alpha = Image.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:254:          if(args->texture)    {    object t = roxen.load_image(args->texture,id);    if( t )    {    foreground = t;    if(args->tile)    { -  object b2 = Image.image(xsize,ysize); +  object b2 = Image.Image(xsize,ysize);    for(int x=0; x<xsize; x+=foreground->xsize())    for(int y=0; y<ysize; y+=foreground->ysize())    b2->paste(foreground, x, y);    foreground = b2;    } else if(args->mirrortile) { -  object b2 = Image.image(xsize,ysize); -  object b3 = Image.image(foreground->xsize()*2,foreground->ysize()*2); +  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)
Roxen.git/server/modules/graphics/graphic_text.pike:286:    }    foreground = b2;    }    } else    werror("Failed to load image for "+args->texture+"\n");    }    int background_is_color;    if(args->background &&    ((background = roxen.load_image(args->background, id)) ||    (sizeof(args->background)>1 && -  (background=Image.image(xsize,ysize, @(parse_color(args->background[1..])))) +  (background=Image.Image(xsize,ysize, +  @(parse_color(args->background[1..]))))    && (background_is_color=1))))    {    object alpha;    if(args->alpha && (alpha = roxen.load_image(args->alpha,id)) && background_is_color)    {    xsize=MAX(xsize,alpha->xsize());    ysize=MAX(ysize,alpha->ysize());    if((float)args->scale)    alpha=alpha->scale(1/(float)args->scale); -  background=Image.image(xsize,ysize, @(parse_color(args->background[1..]))); +  background=Image.Image(xsize,ysize, @(parse_color(args->background[1..])));    }       if((float)args->scale >= 0.1 && !alpha)    background = background->scale(1.0/(float)args->scale);       if(args->tile)    { -  object b2 = Image.image(xsize,ysize); +  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); +  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)
Roxen.git/server/modules/graphics/graphic_text.pike:346:    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); +  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--)    {    // upper left -- upper right    background->line(b,b, xsize-b-1, b); -  +     // lower left -- lower right    background->line(b,ysize-b-1, xsize-b-1, ysize-b-1); -  +     // upper left -- lower left    background->line(b,b, b, ysize-b-1);    // upper right -- lower right    background->line(xsize-b-1,b, xsize-b-1, ysize-b-1);    }    }       background->setcolor(@bgcolor);       int xs=background->xsize(), ys=background->ysize();
Roxen.git/server/modules/graphics/graphic_text.pike:415:    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;    alpha = (int)args->textbox;    sscanf(args->textbox, "%*[^,],%s", bg);    sscanf(bg,"%s,%d", bg,border); -  background->paste_alpha(Image.image(txsize+border*2,tysize+border*2, +  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)    { // Francesco..    array(string) a = (args->ghost/",");    if (sizeof(a) < 2) {    // Bad argument.    } else {
Roxen.git/server/modules/graphics/graphic_text.pike:460:    }      #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); +  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);    ta = blur(ta, MIN((sdist/2),1))->color(256,256,256);       background->paste_alpha_color(ta,sc[0],sc[1],sc[2],    xoffset+sdist,yoffset+sdist);    }       if(args->glow)
Roxen.git/server/modules/graphics/graphic_text.pike:486:    }       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(!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]),
Roxen.git/server/modules/graphics/graphic_text.pike:651:    return img;    }       if(args->fadein)    {    int amount=2, steps=10, delay=10, initialdelay=0, ox;    string res = img->gif_begin();    sscanf(args->fadein,"%d,%d,%d,%d", amount, steps, delay, initialdelay);    if(initialdelay)    { -  object foo=Image.image(img->xsize(),img->ysize(),@parse_color(args->bg)); +  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();
Roxen.git/server/modules/graphics/graphic_text.pike:698:    "type":"image/gif",    ])    ]);   }         mapping find_internal(string f, object rid)   {    if( strlen(f)>4 && query("gif") && f[-4]=='.') // Remove .ext    f = f[..strlen(f)-5]; -  if( strlen(f) && f[0..0]=="$" ) +  if( strlen(f) && f[0]=='$' )    {    array id_text = f/"/";    if( sizeof(id_text)==2 )    { // It's a gtext-id -  string second_key = roxen.argcache.store( (["":id_text[1]]) ); +  string second_key = roxen->argcache->store( (["":id_text[1]]) );    return image_cache->http_file_answer( id_text[0][1..] +"$"+ second_key, rid );    }    }    return image_cache->http_file_answer( f, rid );   }      string magic_javascript_header(object id)   {    if(!id->supports->netscape_javascript || !id->supports->images) return "";    return
Roxen.git/server/modules/graphics/graphic_text.pike:798:    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);    -  +     if(!short)    return query_internal_location()+image_cache->store( ({arg,ctn}), id )+    (query("gif")?".foo":"");    else    return image_cache->store( ({arg,ctn}), id )+(query("gif")?".foo":"");   }    - string tag_gtext_id(string t, mapping arg, object id, object foo, -  mapping defines) + string tag_gtext_id(string t, mapping arg, object id, +  object foo, mapping defines)   {    int short=!!arg->short;    if(arg->help) return "Arguments are identical to the argumets to &lt;gtext&gt;. This tag returns a url-prefix that can be used to generate gtexts.";    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(defines->nfont && !arg->nfont) arg->nfont=defines->nfont;    if(defines->afont && !arg->afont) arg->afont=defines->afont;
Roxen.git/server/modules/graphics/graphic_text.pike:868:    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);    -  +     string gif="";    if(query("gif")) gif="."+(arg->format?arg->format[..2]:"gif");       if( !arg->noparse && !arg->preparse )    contents = parse_rxml(contents, id);    else    {    m_delete( arg, "noparse" );    m_delete( arg, "preparse" );    }