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.36 1997/02/27 04:38:20 per Exp $"; + string cvs_version="$Id: graphic_text.pike,v 1.37 1997/03/01 13:03:14 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   #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:141:    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 {    if(justification=="right") fnt->right();    if(justification=="center") fnt->center(); -  fnt->set_x_spacing((100.0+(float)xs)/100.0); -  fnt->set_y_spacing((100.0+(float)ys)/100.0); +  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))      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){ +  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;   }    - string fix_relative(string file, object got) + string fix_relative(string file, object id)   { -  string other; -  if(file != "" && file[0] == '/') +  if(file != "" && file[0] == '/') return file; +  file = combine_path(dirname(id->not_query) + "/", file);    return file; -  other=got->not_query; -  if(file != "" && file[0] == '#') -  file = got->not_query+ file; -  else -  file = dirname(got->not_query) + "/" + file; -  return simplify_path(replace(file, ({ "//", "..."}), ({"./..", "//"}))); +    }    - object last_image; + object last_image; // Cache the last image for a while.   string last_image_name;   object (image) load_image(string f,object id)   {    if(last_image_name==f) return last_image;    string data;    object file;    object img = image();    -  if(file=open(f,"r")) -  { -  if(!(data=file->read(0x7fffffff))) +  if(!(data=roxen->try_get_file(fix_relative(f, id),id))) +  if(!(file=open(f,"r")) || (!(data=file->read(0x7fffffff))))    return 0; -  } else { -  f = fix_relative(f, id); -  if(!(data=roxen->try_get_file(f,id))) -  return 0; -  } +        if(!img->frompnm(data) && !img->fromgif(data)) return 0;    - // last_image_name=f; - // last_image=img; - //call_out(lambda(){last_image=last_image_name=0;}, 10); -  return img/*->copy()*/; +  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 (image) 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;
Roxen.git/server/modules/graphics/graphic_text.pike:377:       if(args->background)    {    background = load_image(args->background,id);    xsize = background->xsize();    ysize = background->ysize();    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(xsize, ysize, @bgcolor);       if(args->border)
Roxen.git/server/modules/graphics/graphic_text.pike:713:      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(defines->font && !arg->font) arg->font=defines->font||QUERY(default_font); -  if(!arg->font) arg->font = QUERY(default_font); +  if(!arg->font) arg->font=defines->font||QUERY(default_font);       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:793:    if(arg->href)    {    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->font && !arg->font) arg->font=defines->font||QUERY(default_font); -  if(!arg->font) arg->font = QUERY(default_font); +  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])    {    arg->scale = 1.0 / ((float)i*0.6);    m_delete(arg, (string)i); -  +  break;    }       // Support for <gh1> like things.    if(sscanf(t, "%s%d", t, i)==2)    if(i > 1) arg->scale = 1.0 / ((float)i*0.6);       string na = arg->name, al=arg->align;    m_delete(arg, "name"); m_delete(arg, "align");       // Now the 'args' mapping is modified enough..
Roxen.git/server/modules/graphics/graphic_text.pike:835:    string word;    array res = ({});    string pre = query_location()+num+"/";       if(lp) res+=({ lp });       gt=replace(gt, "\n", " ");       foreach(gt/" "-({""}), word)    { -  array size = write_text(num,word,1,0); +  array size = write_text(num,word,1,id);    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>" });    return res*"";    }       switch(t)
Roxen.git/server/modules/graphics/graphic_text.pike:859:    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;    }    -  array size = write_text(num,gt,1,0); +  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    arg->glow = arg->fg;    }    arg->fg = defines->alink||"#ff0000";    if(arg->bevel) arg->pressed=1;       int num2 = find_or_insert(arg); -  array size = write_text(num2,gt,1,0); +  array size = write_text(num2,gt,1,id);       if(!defines->magic_java) res = magic_javascript_header(id);    defines->magic_java="yes";       return res +    magic_image(url||"", size[0], size[1], "i"+(defines->mi++),    query_location()+num+"/"+quote(gt),    query_location()+num2+"/"+quote(gt),    replace(gt, "\"","'"),(magic=="magic"?0:magic),    id,input?na||"submit":0,ea);