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.39 1997/03/26 05:54:13 per Exp $"; + string cvs_version="$Id: graphic_text.pike,v 1.40 1997/04/05 01:26:10 per Exp $"; +    #include <module.h>   inherit "module";   inherit "roxenlib";      #if efun(_static_modules)   # define map_array Array.map   import Image;   #else   # define image Image   # define font Font
Roxen.git/server/modules/graphics/graphic_text.pike:13:      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"    "<b>&lt;gtext&gt;:</b> Graphical text<br>\n" -  "<b>&lt;anfang&gt;:</b> Make the first character to a graphical one. Not all that usefull, really.<br>\n" +  "<b>&lt;anfang&gt;:</b> Make the first character to a " +  "graphical one. Not all that usefull, really.<br>\n"    "<br>\n"    "<b>Common arguments:</b>\n <pre>"    " bg=color Use this background, default taken from the\n"    " &lt;body&gt; tag, if any\n"    " fg=color Use this foreground, default taken from the\n"    " &lt;body&gt; tag, if any\n"    " font=fnt Use this font. The fonts can be found in the\n"    " directory specified in the configuration\n"    " interface.\n"    " If no font is specified, the one from the\n"
Roxen.git/server/modules/graphics/graphic_text.pike:99:    if(!fnts)    {    report_error("Failed to find any fonts in 'fonts/32/'. No default font.\n");    return ({});    }    return fnts;   }      void create()   { -  +     defvar("deflen", 300, "Default maximum text-length", TYPE_INT,    "The module will, per default, not try to render texts "    "longer than this. This is a safeguard for things like "    "&lt;gh1&gt;&lt;/gh&gt;, which would otherwise parse the"    " whole document. This can be overrided with maxlen=... in the "    "tag.");       defvar("location", "/gtext/", "Mountpoint", TYPE_LOCATION,    "The URL-prefix for the graphic characters.");       defvar("cols", 16, "Default number of colors per image", TYPE_INT_LIST,    "The default number of colors to use. 16 seems to be enough. "    "The size of the image depends on the number of colors",    ({ 1,2,3,4,5,6,7,8,10,16,32,64,128,256 }));       -  + #ifdef TYPE_FONT    // compatibility variables...    defvar("default_size", 32, 0, TYPE_INT,0,0,1);    defvar("default_font", "urw_itc_avant_garde-demi-r",0,TYPE_STRING,0,0,1); -  + #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"); }      mapping (string:object) fonts = ([]);      object(font) load_font(string name, string justification, int xs, int ys)   {    object fnt = font();    -  if(!name) name="foo"; -  if(sscanf(name, "%*s/%*s") != 2) +  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 ))    {    perror("Failed to load the font "+name+", using the default font.\n");    if(!fnt->load("fonts/"+QUERY(default_size) +"/"+ QUERY(default_font)))    error("Failed to load the default font\n");    }    catch {
Roxen.git/server/modules/graphics/graphic_text.pike:154:    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;   }      static private mapping (int:mapping(string:mixed)) cached_args = ([ ]);      #define MAX(a,b) ((a)<(b)?(b):(a))    + #if !efun(make_matrix)   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 = map_array(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);    return matrixes[size] = res;   } -  + #endif      string fix_relative(string file, object id)   {    if(file != "" && file[0] == '/') return file;    file = combine_path(dirname(id->not_query) + "/", file);    return file;   }      object last_image; // Cache the last image for a while.   string last_image_name;
Roxen.git/server/modules/graphics/graphic_text.pike:211:    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,    array (int) color, int radie, int x, int y)   { -  object foo = image(with->xsize(), with->ysize(), @color); -  +     int steps=10;    for(int j=0; j<=steps; j++) -  on->paste_mask(foo, with,(int)(0.5+x-(sin((float)j/steps*3.145*2)*radie)), +  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))); -  foo=0; +     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)
Roxen.git/server/modules/graphics/graphic_text.pike:263:    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);    -  corner = corner2 = pix = 0; -  +  corner2 = pix = 0;    return in;   }         object (image) make_text_image(mapping args, object font, string text,object id)   {    object (image) text_alpha=font->write(@(text/"\n"));    int xoffset=0, yoffset=0;       if(!text_alpha->xsize() || !text_alpha->ysize())
Roxen.git/server/modules/graphics/graphic_text.pike:342:    }       if(args->ghost)    {    int howmuch=(int)args->ghost;    xsize+=howmuch*2+10;    xoffset += 3;    ysize+=howmuch*2+10;    }    -  +     if(args->xspacing)    {    xoffset += (int)args->xspacing;    xsize += ((int)args->xspacing)*2;    }       if(args->border)    {    xoffset += (int)args->border;    yoffset += (int)args->border;
Roxen.git/server/modules/graphics/graphic_text.pike:366:          array (int) bgcolor = parse_color(args->bg);    array (int) fgcolor = parse_color(args->fg);       object background,foreground;          if(args->texture) foreground = load_image(args->texture,id);    -  if(args->background) -  { -  background = load_image(args->background,id); +  if((args->background) && (background = load_image(args->background, id))) {    xsize = background->xsize();    ysize = background->ysize(); -  switch(lower_case(args->talign||"left")) -  { +  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
Roxen.git/server/modules/graphics/graphic_text.pike:450:    @parse_color(bg)),    255-(alpha*255/100),xoffset-border,yoffset-border);    }       if(args->ghost)    { // Francesco..    int sdist = (int)args->ghost;    int bl=(int)(args->ghost/",")[1];    array(int)clr=parse_color((args->ghost/",")[-1]);    int j; -  object base = image(xsize,ysize,@clr)->invert(); +     object ta = text_alpha->copy();    for (j=0;j<bl;j++)    ta=ta->apply_matrix(({    ({6,7,7,7,6}),({7,8,8,8,7}),({7,8,8,8,7}),({7,8,8,8,7}),({6,7,7,7,6})    })); -  background->paste_mask(base->invert(),ta,xoffset+sdist,yoffset+sdist); +  background->paste_alpha_color(ta,@clr,xoffset+sdist,yoffset+sdist);    fgcolor=bgcolor;    }          if(args->shadow)    {    int sd = ((int)args->shadow+10)*2;    int sdist = ((int)(args->shadow/",")[-1])+2;    object ta = text_alpha->copy();    ta = ta->color(256-sd,256-sd,256-sd); -  background->paste_mask(image(txsize,tysize),ta,xoffset+sdist, yoffset+sdist); +  background->paste_alpha_color(ta,0,0,0,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(xs,ys);    ta->paste(text_alpha,sdist,sdist);    ta = blur(ta, MIN((sdist/2),1))->color(256,256,256); -  background->paste_mask(image(xs,ys),ta,xoffset, yoffset); +  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_mask(image(txsize+amnt*2,tysize*2, @blurc), -  blur(text_alpha, amnt), +  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);      
Roxen.git/server/modules/graphics/graphic_text.pike:572:    if(mixed data = cache_lookup(key, text))    {    if(args->nocache) // Remove from cache. Very usable for access counters    cache_remove(key, text);    if(size) return data[1];    return data[0];    }    // Nothing found in the cache. Generate a new image.       + #if efun(get_font)    if(args->nfont)    {    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,bold,italic,    lower_case(args->talign||"left"),    (float)(int)args->xpad, (float)(int)args->ypad); -  } else { +  } +  else + #endif +  {    string fkey = args->font+"/"+args->talign+"/"+args->xpad+"/"+args->ypad;    data = cache_lookup("fonts", fkey);    if(!data)    {    data = load_font(args->font, lower_case(args->talign||"left"),    (int)args->xpad,(int)args->ypad);    cache_set("fonts", fkey, data);    }    }   
Roxen.git/server/modules/graphics/graphic_text.pike:739:      string tag_gtext_id(string t, mapping arg,    object id, object foo, mapping defines)   {    int short=!!arg->short;    m_delete(arg, "short"); m_delete(arg, "maxlen");    m_delete(arg,"magic"); m_delete(arg,"submit");    extra_args(arg); m_delete(arg,"split");    if(defines->fg && !arg->fg) arg->fg=defines->fg;    if(defines->bg && !arg->bg) arg->bg=defines->bg; - // if(!arg->font) arg->font=defines->font||QUERY(default_font); +  if(!arg->font) arg->font=defines->font||QUERY(default_font); + #if efun(get_font)    if(!arg->nfont) arg->nfont=defines->nfont; -  + #endif       int num = find_or_insert( arg );       if(!short)    return query_location()+num+"/";    else    return (string)num;   }      string tag_graphicstext(string t, mapping arg, string contents,
Roxen.git/server/modules/graphics/graphic_text.pike:820:    {    url = arg->href;    lp = "<a href=\""+arg->href+"\" "+ea+">";    if(!arg->fg) arg->fg=defines->link||"#0000ff";    m_delete(arg, "href");    }       if(defines->fg && !arg->fg) arg->fg=defines->fg;    if(defines->bg && !arg->bg) arg->bg=defines->bg;   // if(!arg->font) arg->font=defines->font||QUERY(default_font); + #if efun(get_font)    if(!arg->nfont) arg->nfont=defines->nfont; -  + #endif    if(!arg->bold) arg->bold=defines->bold;    if(!arg->italic) arg->italic=defines->italic;    if(!arg->black) arg->black=defines->black;    if(!arg->narrow) arg->narrow=defines->narrow; -  +  if(!arg->font) arg->font=defines->font||QUERY(default_font);       if(arg->split)    {    split=1;    m_delete(arg,"split");    }       // Support for <gh 2> like things.    for(i=2; i<10; i++)    if(arg[(string)i])
Roxen.git/server/modules/graphics/graphic_text.pike:891:    res += ({ "<img _parsed=1 border=0 alt=\""+replace(word,"\"","'")    +"\" src=\""+pre+quote(word)+"\" width="+    size[0]+" height="+size[1]+" "+ea+">\n"    });    }    if(lp) res+=({ "</a>"+post });    return res*"";    }       array size = write_text(num,gt,1,id); -  +     if(magic)    {    string res = "";    if(!arg->fg) arg->fg=defines->link||"#0000ff";    arg = mkmapping(indices(arg), values(arg));    if(arg->fuzz)    {    if(arg->fuzz != "fuzz")    arg->glow = arg->fuzz;    else