Roxen.git / server / font_handlers / imagedir.pike

version» Context lines:

Roxen.git/server/font_handlers/imagedir.pike:1: + // This file is part of Roxen WebServer. + // Copyright © 2000 - 2009, Roxen IS. +    #include <config.h>   #include <stat.h> - constant cvs_version = "$Id: imagedir.pike,v 1.10 2001/01/04 10:00:12 nilsson Exp $"; + constant cvs_version = "$Id$";      constant name = "Image directory fonts";   constant doc = ("Handles a directory with images (in almost any format), each "    "named after the character they will represent. Characters "    "with codes larger than 127 or less than 48 are encoded like "    "0xHEX where HEX is the code in hexadecimal. There must be a "    "file named 'fontname' in the directory, the first line of "    "that file is used as the name of the font");      inherit FontHandler;      #ifdef THREADS   Thread.Mutex lock = Thread.Mutex();   #endif    - static mapping nullchar = ([ "image":Image.Image(1,1), + protected mapping nullchar = ([ "image":Image.Image(1,1),    "alpha":Image.Image(1,1) ]); - static mapping spacechar = ([ "image":Image.Image(10,1), + protected mapping spacechar = ([ "image":Image.Image(10,1),    "alpha":Image.Image(10,1) ]); - static mapping smallspacechar = ([ "image":Image.Image(2,1), + protected mapping smallspacechar = ([ "image":Image.Image(2,1),    "alpha":Image.Image(2,1) ]);   class myFont   {    inherit Font; -  static string path; -  static int size, rsize; -  static array files; +  protected string path; +  protected int size, rsize; +  protected array files;    -  -  static string _sprintf() +  string _sprintf()    {    return sprintf( "FontDir(%O,%d)", path, height() );    }    -  static string encode_char( string c ) +  protected string encode_char( string c )    {    int cc = c[0];    if( (cc < 48) || (cc > 127) ) return sprintf( "0x%x", cc );    return c;    }    -  static mapping(string:Image.Image) load_char( string c ) +  protected mapping(string:Image.Image) load_char( string c )    {    if( c[0] == 0x120 ) return smallspacechar;    if(!files)    files = get_dir( path ) - ({ "fontname" });       array possible = ({ encode_char(c) })+    glob(encode_char( c )+".*", files);    sort( map(possible,strlen), possible );    catch {    foreach( possible, string pf )    if( mapping r = Image._load( path+pf ) )    return r;    };    if( c == " " ) return spacechar;    return nullchar;    }    mapping(string:mapping(string:Image.Image)) char_cache = ([]); -  static mapping(string:Image.Image) write_char( string c ) +  protected mapping(string:Image.Image) write_char( string c )    {    if( char_cache[ c ] ) return char_cache[ c ];    return char_cache[ c ] = load_char( c );    }    -  static Image.Image write_row( string text ) +  protected Image.Image write_row( string text )    {    array(mapping(string:Image.Image)) res = map( text/"", write_char );       Image.Image rr;    if(floatp(x_spacing))    rr=Image.Image((int)abs(`+(0,@res->image->xsize())*x_spacing),    max(0,@res->image->ysize()));    else    rr=Image.Image(abs(`+(0,@res->image->xsize())+(sizeof(res)*x_spacing)),    max(0,@res->image->ysize()));
Roxen.git/server/font_handlers/imagedir.pike:148:    {    path = _path;    size = _size;    x_spacing = xpad;    y_spacing = ypad;    }   }      mapping font_list;   mapping meta_data; - static string font_name( string what ) + protected string font_name( string what )   {    if(!meta_data) meta_data=([]);    mapping _meta_data=([]);    Parser.HTML()->    add_containers( ([ "name":lambda(string t, mapping m, string c) {    what=c; return ""; },    "meta":lambda(string t, mapping m, string c) {    _meta_data[m->name]=c; },    "xpad":lambda(string t, mapping m, string c) {    _meta_data->xpad = (int)c; },
Roxen.git/server/font_handlers/imagedir.pike:173:    what=(lower_case( replace(what," ","_") )/"\n")[0]-"\r";    if(sizeof(_meta_data)) meta_data[what]=_meta_data;    return what;   }      void update_font_list()   {    font_list = ([]);    foreach(roxen->query("font_dirs"), string dir)    foreach( (get_dir( dir )||({})), string d ) -  if( file_stat( dir+d )[ ST_SIZE ] == -2 ) { // isdir +  if( Stdio.is_dir( dir+d ) ) {    if( file_stat( dir+d+"/fontinfo" ) )    font_list[font_name(Stdio.read_bytes(dir+d+"/fontinfo"))]=dir+d+"/";    else if( file_stat( dir+d+"/fontname" ) )    font_list[font_name(Stdio.read_bytes(dir+d+"/fontname"))]=dir+d+"/";    }   }      array available_fonts()   {   #ifdef THREADS