b824672000-09-03Martin Nilsson // This file is part of Roxen WebServer. // Copyright © 1996 - 2000, Roxen IS. #include <config.h>
bea6382001-05-04Jonas Wallden constant cvs_version = "$Id: old.pike,v 1.10 2001/05/04 14:26:14 jonasw Exp $";
c6fd2e2000-09-03Per Hedbor  constant name = "Compatibility bitmap fonts";
0bd4d92000-09-04Per Hedbor constant doc = "Compatibility (bitmapped) fonts for Roxen 1.3 and earlier."
c6239d2000-09-04Per Hedbor " Compact image file fonts are preferable to this format, since they are " "almost always smaller, and easier to create.";
c6fd2e2000-09-03Per Hedbor  inherit FontHandler; array available_fonts() { array res = ({}); foreach(roxen->query("font_dirs"), string dir) { dir+="32/"; if(array d = r_get_dir(dir)) { foreach(d,string f) { if(f=="CVS") continue; Stat a; if((a=r_file_stat(dir+f)) && (a[1]==-2)) { array d=r_get_dir(dir+f); foreach( ({ "nn", "ni", "li", "ln", "Bi", "Bn", "bi", "bn" }), string style) if(has_value(d, style)) { res |= ({ replace(f,"_", " ") }); break; } } } } } return res; }
b824672000-09-03Martin Nilsson array(mapping) font_information( string fnt )
c6fd2e2000-09-03Per Hedbor {
a6bf1d2000-09-04Per Hedbor  string ofnt = fnt; fnt = replace(lower_case( fnt ), " ", "_");
b824672000-09-03Martin Nilsson  array font_infos=({});
c6fd2e2000-09-03Per Hedbor  foreach(roxen->query("font_dirs"), string dir) { dir+="32/"; if( r_file_stat( dir+fnt ) )
d3a6822000-09-03Martin Nilsson  // the font file exists in this dir..
c6fd2e2000-09-03Per Hedbor  { array d = r_get_dir(dir+fnt); foreach( ({ "nn", "ni", "li", "ln", "Bi", "Bn", "bi", "bn" }), string style) if(has_value(d, style)) {
b824672000-09-03Martin Nilsson  mapping font_info = ([ "name":fnt,
a6bf1d2000-09-04Per Hedbor  "family":ofnt,
b824672000-09-03Martin Nilsson  "path":dir+fnt,
a6bf1d2000-09-04Per Hedbor  "style":"",
b824672000-09-03Martin Nilsson  "format":"bitmap dump" ]); switch(style[0]) {
a6bf1d2000-09-04Per Hedbor  case 'l': font_info->style+="light"; break; case 'b': font_info->style+="bold"; break; case 'B': font_info->style+="black"; break;
b824672000-09-03Martin Nilsson  }
a6bf1d2000-09-04Per Hedbor  if(style[1]=='i') font_info->style+="italic"; if(style[1]=='I') font_info->style+="oblique";
b824672000-09-03Martin Nilsson  font_infos+=({ font_info });
c6fd2e2000-09-03Per Hedbor  } } }
b824672000-09-03Martin Nilsson  return font_infos;
c6fd2e2000-09-03Per Hedbor } string fix_name( string what ) { return replace( lower_case(what), " ", "_" ); } array has_font( string name, int size ) { string base_dir;
bea6382001-05-04Jonas Wallden  array available, fallback_available;
6dea542001-03-23Per Hedbor  if( String.width( name ) > 8 ) return 0;
c6fd2e2000-09-03Per Hedbor  foreach(roxen->query("font_dirs"), string dir) { base_dir = dir+size+"/"+fix_name(name);
bea6382001-05-04Jonas Wallden  if (available = r_get_dir(base_dir)) break; if (!fallback_available) { base_dir=dir+"/32/"+fix_name(name); fallback_available = r_get_dir(base_dir); }
c6fd2e2000-09-03Per Hedbor  }
bea6382001-05-04Jonas Wallden  if(!available && !fallback_available) return 0; return (available ? available : fallback_available) - ({ "CVS" });
c6fd2e2000-09-03Per Hedbor }
11b6b72001-02-02Martin Nilsson class MyFont { inherit Image.Font; void set_x_spacing(int|float delta) { if(intp(delta)) ::set_x_spacing( (100.0+delta)/100.0 ); else ::set_x_spacing( delta ); } void set_y_spacing(int|float delta) { if(intp(delta)) ::set_y_spacing( (100.0+delta)/100.0 ); else ::set_y_spacing( (float)delta ); } }
c6fd2e2000-09-03Per Hedbor Font open( string name, int size, int bold, int italic ) {
6dea542001-03-23Per Hedbor  if( String.width( name ) > 8 ) return 0;
c6fd2e2000-09-03Per Hedbor  string f = make_font_name( name, size, bold, italic );
11b6b72001-02-02Martin Nilsson  Image.Font fn = MyFont();
c6fd2e2000-09-03Per Hedbor  foreach( roxen->query( "font_dirs"), string dir ) foreach( ({ size, 32 }), int sz ) { if( r_file_stat( dir+"/"+sz+"/"+f ) ) { if( fn->load( roxen_path( dir+"/"+sz+"/"+f ) ) ) return fn; } } }