Branch: Tag:

2001-11-14

2001-11-14 13:36:09 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Added support for the new available_fonts() API.

Rev: server/font_handlers/freetype.pike:1.16
Rev: server/font_handlers/ttf.pike:1.11

4: Inside #if !constant(Image.FreeType.Face) and #if constant(has_Image_TTF)
  #if !constant(Image.FreeType.Face)   #if constant(has_Image_TTF)   #include <config.h> - constant cvs_version = "$Id: ttf.pike,v 1.10 2001/09/27 21:51:23 per Exp $"; + constant cvs_version = "$Id: ttf.pike,v 1.11 2001/11/14 13:36:09 grubba Exp $";      constant name = "TTF fonts";   constant doc = "True Type font loader. Uses freetype to render text.";
42: Inside #if !constant(Image.FreeType.Face)
  static void build_font_names_cache( )   {    mapping ttf_done = ([ ]); -  ttf_font_names_cache=([]); +  mapping new_ttf_font_names_cache=([]);    void traverse_font_dir( string dir )    {    foreach(r_get_dir( dir )||({}), string fname)
66: Inside #if !constant(Image.FreeType.Face)
   {    mapping n = ttf->names();    string f = lower_case(trimttfname(n->family)); -  if(!ttf_font_names_cache[f]) -  ttf_font_names_cache[f] = ([]); -  ttf_font_names_cache[f][ translate_ttf_style(n->style) ] -  = combine_path(dir+"/",fname); +  if(!new_ttf_font_names_cache[f]) +  new_ttf_font_names_cache[f] = ([]); +  new_ttf_font_names_cache[f][ translate_ttf_style(n->style) ] = +  combine_path(dir+"/",fname);    }    }    }    };    map( roxen->query("font_dirs"), traverse_font_dir ); -  +  +  ttf_font_names_cache = new_ttf_font_names_cache;   }      
186: Inside #if !constant(Image.FreeType.Face)
  Thread.Mutex lock = Thread.Mutex();   #endif    - array available_fonts() + array available_fonts(int(0..1)|void force_reload)   {   #ifdef THREADS    object key = lock->lock();   #endif -  if( !ttf_font_names_cache ) build_font_names_cache( ); +  if( !ttf_font_names_cache || force_reload ) build_font_names_cache( );    return indices( ttf_font_names_cache );   }   
215: Inside #if !constant(Image.FreeType.Face)
   return ({ res });   }    - array(string) has_font( string name, int size ) + array(string) has_font( string name, int size, int(0..1) force )   {   #ifdef THREADS    object key = lock->lock();
224: Inside #if !constant(Image.FreeType.Face)
   build_font_names_cache( );    if( ttf_font_names_cache[ name ] )    return indices(ttf_font_names_cache[ name ]); +  if (force) { +  build_font_names_cache(); +  if( ttf_font_names_cache[ name ] ) +  return indices(ttf_font_names_cache[ name ]);    } -  + }      Font open(string f, int size, int bold, int italic )   {
239: Inside #if !constant(Image.FreeType.Face)
   return 0;    }    +  if (!ttf_font_names_cache) { +  build_font_names_cache(); +  } +     if(ttf_font_names_cache[ lower_case(f) ])    {    f = lower_case(f);