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.154 1998/11/02 07:00:39 per Exp $"; + constant cvs_version="$Id: graphic_text.pike,v 1.155 1998/11/06 15:22:50 per Exp $";   constant thread_safe=1;      #include <module.h>   #include <stat.h>   inherit "module";   inherit "roxenlib";      #ifndef VAR_MORE   #define VAR_MORE 0   #endif /* VAR_MORE */
Roxen.git/server/modules/graphics/graphic_text.pike:176:    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 && last_image) return last_image->copy();    string data;    object file; -  object img - #if !constant(Image.PNM) -  =Image.image() - #endif -  ; +  object img;       if(!(data=roxen->try_get_file(fix_relative(f, id),id)))    if(!(file=open(f,"r")) || (!(data=file->read())))    return 0;   //werror("Read "+strlen(data)+" bytes.\n");   #if constant(Image.GIF.decode)    catch { if(!img) img = Image.GIF.decode( data ); };   #endif   #if constant(Image.JPEG.decode)    catch { if(!img) img = Image.JPEG.decode( data ); };   #endif   #if constant(Image.PNG.decode)    catch { if(!img) img = Image.PNG.decode( data ); };   #endif   #if constant(Image.PNM.decode)    catch { if(!img) img = Image.PNM.decode( data ); };   #endif - #if !constant(Image.PNM.decode) -  if (catch { if(!img->frompnm(data)) return 0;}) return 0; - #endif +     if(!img) return 0;    last_image = img; last_image_name = f;    return img->copy();   }    - object blur(object img, int amnt) + object 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))); +  img = img->apply_matrix( ({ ({ 0, 1, 0 }), +  ({ 1, 2, 1 }), +  ({ 0, 1, 0 }) }) );    return img;   }      object outline(object on, object 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 }); + constant white = ({ 255,255,255 }); + constant lgrey = ({ 200,200,200 }); + constant grey = ({ 128,128,128 }); + constant black = ({ 0,0,0 });    - array 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);       for(int i=-1; i<=width; i++) {
Roxen.git/server/modules/graphics/graphic_text.pike:279:    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(@( - #if constant(Locale.Charset) -  args->encoding? +  object text_alpha= +  font->write(@(args->encoding?    Array.map(text/"\n",    lambda(string s, object d) {    return d->feed(s)->drain();    }, -  Locale.Charset.decoder(args->encoding)) : - #endif -  text/"\n")); +  Locale.Charset.decoder(args->encoding)) +  :text/"\n"));    int xoffset=0, yoffset=0;       if(!text_alpha->xsize() || !text_alpha->ysize())    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);   
Roxen.git/server/modules/graphics/graphic_text.pike:329:    xsize += ((int)args->spacing)*2;    ysize += ((int)args->spacing)*2;    }       if(args->yspacing)    {    yoffset += (int)args->yspacing;    ysize += ((int)args->yspacing)*2;    }    +  if(args->xspacing) +  { +  xoffset += (int)args->xspacing; +  xsize += ((int)args->xspacing)*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;
Roxen.git/server/modules/graphics/graphic_text.pike:365:    }       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;    xsize += ((int)args->border)*2;    ysize += ((int)args->border)*2;    }          array (int) bgcolor = parse_color(args->bg);
Roxen.git/server/modules/graphics/graphic_text.pike:419:    else    b2->paste(foreground, x, y);    foreground = foreground->mirrorx();    }    foreground = b2;    }    }    int background_is_color;    if(args->background &&    ((background = 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))))    && (background_is_color=1))))    {    object alpha;    if(args->alpha && (alpha = load_image(args->alpha,id)) && background_is_color)    {    xsize=MAX(xsize,alpha->xsize());    ysize=MAX(ysize,alpha->ysize()); -  if((float)args->scale) +  if((float)args->scale && (float)args->scale != 1.0)    alpha=alpha->scale(1/(float)args->scale); -  background=Image.image(xsize,ysize, @(parse_color(args->background[1..]))); +     }    -  if((float)args->scale >= 0.1 && !alpha) +  if(!args->nobgscale && (float)args->scale >= 0.1)    background = background->scale(1.0/(float)args->scale);       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) {
Roxen.git/server/modules/graphics/graphic_text.pike:467:    else    b2->paste(background, x, y);    background = background->mirrorx();    }    background = b2;    }    xsize = MAX(xsize,background->xsize());    ysize = MAX(ysize,background->ysize());       if(alpha) -  background->paste_alpha_color(alpha->invert(),@bgcolor); +  background = background->paste_alpha_color(alpha->invert(),@bgcolor);       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->bgscale) +  { +  string c1="black",c2="black",c3="black",c4="black"; +  sscanf(args->bgscale, "%s,%s,%s,%s", c1, c2, c3, c4); +  background->tuned_box(0,0, xsize,ysize, +  ({parse_color(c1),parse_color(c2),parse_color(c3), +  parse_color(c4)})); +  } +  +  +     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:582:    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); -  ta = blur(ta, MIN((sdist/2),1))->color(256,256,256); +  ta = blur(ta, MIN((sdist/2),1))->color(255,255,255);       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,
Roxen.git/server/modules/graphics/graphic_text.pike:613:       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);       if(args->textbelow)    {    array color = parse_color(args->textbelow);   // foreground = foreground->autocrop();   // text_alpha = text_alpha->autocrop();   
Roxen.git/server/modules/graphics/graphic_text.pike:709:    remove_call_out(clean_cache_dir);    call_out(clean_cache_dir, 10);    mc = conf;    base_key = "gtext:"+(conf?conf->name:roxen->current_configuration->name);    }   }      #ifdef QUANT_DEBUG   void print_colors(array from)   { - #if efun(color_name) +     for(int i=0; i<sizeof(from); i++)    perror("%d: %s\n", i, color_name(from[i])); - #endif +    }   #endif      int number=0;      mapping find_cached_args(int num);       - #if !constant(iso88591) - constant iso88591 - =([ "&nbsp;": " ", "&iexcl;": "¡", "&cent;": "¢", "&pound;": "£", -  "&curren;": "¤", "&yen;": "¥", "&brvbar;": "¦", "&sect;": "§", -  "&uml;": "¨", "&copy;": "©", "&ordf;": "ª", "&laquo;": "«", -  "&not;": "¬", "&shy;": "­", "&reg;": "®", "&macr;": "¯", -  "&deg;": "°", "&plusmn;": "±", "&sup2;": "²", "&sup3;": "³", -  "&acute;": "´", "&micro;": "µ", "&para;": "¶", "&middot;": "·", -  "&cedil;": "¸", "&sup1;": "¹", "&ordm;": "º", "&raquo;": "»", -  "&frac14;": "¼", "&frac12;": "½", "&frac34;": "¾", "&iquest;": "¿", -  "&Agrave;": "À", "&Aacute;": "Á", "&Acirc;": "Â", "&Atilde;": "Ã", -  "&Auml;": "Ä", "&Aring;": "Å", "&AElig;": "Æ", "&Ccedil;": "Ç", -  "&Egrave;": "È", "&Eacute;": "É", "&Ecirc;": "Ê", "&Euml;": "Ë", -  "&Igrave;": "Ì", "&Iacute;": "Í", "&Icirc;": "Î", "&Iuml;": "Ï", -  "&ETH;": "Ð", "&Ntilde;": "Ñ", "&Ograve;": "Ò", "&Oacute;": "Ó", -  "&Ocirc;": "Ô", "&Otilde;": "Õ", "&Ouml;": "Ö", "&times;": "×", -  "&Oslash;": "Ø", "&Ugrave;": "Ù", "&Uacute;": "Ú", "&Ucirc;": "Û", -  "&Uuml;": "Ü", "&Yacute;": "Ý", "&THORN;": "Þ", "&szlig;": "ß", -  "&agrave;": "à", "&aacute;": "á", "&acirc;": "â", "&atilde;": "ã", -  "&auml;": "ä", "&aring;": "å", "&aelig;": "æ", "&ccedil;": "ç", -  "&egrave;": "è", "&eacute;": "é", "&ecirc;": "ê", "&euml;": "ë", -  "&igrave;": "ì", "&iacute;": "í", "&icirc;": "î", "&iuml;": "ï", -  "&eth;": "ð", "&ntilde;": "ñ", "&ograve;": "ò", "&oacute;": "ó", -  "&ocirc;": "ô", "&otilde;": "õ", "&ouml;": "ö", "&divide;": "÷", -  "&oslash;": "ø", "&ugrave;": "ù", "&uacute;": "ú", "&ucirc;": "û", -  "&uuml;": "ü", "&yacute;": "ý", "&thorn;": "þ", "&yuml;": "ÿ", - ]); - #endif +     -  -  +    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)      #define CACHE_SIZE 2048      #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..])))
Roxen.git/server/modules/graphics/graphic_text.pike:855:    else nspace=" ";    }    res+="\n";    }    text = replace(res[..strlen(res)-2], ({ "!","?",": " }), ({ nbsp+"!",nbsp+"?",nbsp+": " }));    text = replace(replace(replace(text,({". ",". "+nbsp}), ({"\000","\001"})),".","."+nbsp+nbsp),({"\000","\001"}),({". ","."+nbsp}));    }      // cache_set(key, text, "rendering");    - #if efun(resolve_font) +     if(args->afont) -  { -  data = resolve_font(args->afont); -  } +  data = resolve_font(args->afont+" "+(args->font_size||32));    else - #endif -  if(args->nfont) +     { -  +  if(!args->nfont) args->nfont = args->font;    int bold, italic;    if(args->bold) bold=1;    if(args->light) bold=-1; -  if(args->italic) italic=1; +     if(args->black) bold=2; -  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; +     if(args->italic) italic=1; -  if(args->black) bold=2; -  data = get_font(roxen->QUERY(default_font),32,bold,italic, +  data = get_font(args->nfont||"default", +  (int)args->font_size||32,bold,italic,    lower_case(args->talign||"left"),    (float)(int)args->xpad, (float)(int)args->ypad);    }    -  if (!data) { +  if (!data) +  {    roxen_perror("gtext: No font!\n");   // werror("no font found! < "+_args+" <"+text+">\n");   // cache_set(key, orig_text, 0);    return(0);    }       // Fonts and such are now initialized.    img = make_text_image(args,data,text,id);       // Now we have the image in 'img', or nothing.    if(!img) {   // werror("error while drawing image? (no image) < "+_args+" <"+text+">\n");   // cache_set(key, orig_text, 0);    return 0;    }    -  + // Quantify    int q = (int)args->quant||(args->background||args->texture?250:QUERY(cols));       if(q>255) q=255;    if(q<3) q=3;    - // Quantify -  if(!args->fs) -  { - #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)})); -  } + // if(!args->fs) + // img = img->map_closest(img->select_colors(q-1)+ + // ({parse_color(args->bg)}));       if(!args->scroll)    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); +  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));    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);
Roxen.git/server/modules/graphics/graphic_text.pike:951:    }    else    {    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; -  } else { +  } +  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);
Roxen.git/server/modules/graphics/graphic_text.pike:1237:   {    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; -  if(defines->font && !arg->font) arg->font=defines->font; +        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)
Roxen.git/server/modules/graphics/graphic_text.pike:1293:    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=".gif";    - #if efun(_static_modules) +     contents = parse_rxml(contents, id, foo, defines); - #else -  contents = parse_rxml(contents, id, foo); - #endif +        string lp, url, ea;    string pre, post, defalign, gt, rest, magic;    int i;    string split;       contents = contents[..((int)arg->maxlen||QUERY(deflen))];    m_delete(arg, "maxlen");       if(arg->magic)
Roxen.git/server/modules/graphics/graphic_text.pike:1336:    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(defines->nfont && !arg->nfont) arg->nfont=defines->nfont;    if(defines->afont && !arg->afont) arg->afont=defines->afont; -  if(defines->font && !arg->font) arg->font=defines->font; +  if(defines->font && !arg->nfont) arg->font=defines->font;    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;       if(arg->split)    {    if (sizeof(split=arg->split) != 1)    split = " ";    m_delete(arg,"split");