Adonthell  0.4
win_font.cc
00001 /*
00002   
00003    (C) Copyright 2000 Joel Vennin
00004    Part of the Adonthell Project http://adonthell.linuxgames.com
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License.
00008    This program is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY.
00010 
00011    See the COPYING file for more details
00012 */
00013 
00014 #include "win_font.h"
00015 
00016 win_font::win_font()
00017 {
00018   cursor=NULL;
00019 }
00020 
00021 win_font::win_font(char * fic)
00022 {
00023   cursor=NULL;
00024   load(fic);
00025 }
00026 
00027 win_font::win_font(win_font & tmpfont)
00028 {
00029   *this=tmpfont;
00030 }
00031 
00032 win_font::~win_font()
00033 {
00034   erase();
00035 }
00036 void win_font::erase()
00037 {
00038   if(cursor) delete cursor;
00039     glyphs.clear ();
00040 }
00041 
00042 
00043 void win_font::load(char * rep)
00044 {
00045   erase();
00046   
00047   //file which contains font information and cursor
00048   igzstream f; 
00049   
00050   //path where is the file
00051   string path = WIN_DIRECTORY; 
00052   
00053   //add win font directory path
00054   path += WIN_FONT_DIRECTORY; 
00055   
00056   //add theme pass
00057   path += string (rep) + "/"; 
00058   
00059   //add font filename 
00060   path += WIN_FONT_FILE; 
00061      
00062   //open gzfile 
00063   if (!f.open (path)) 
00064   {
00065     cout << path << " not found !\n";
00066     exit(1);
00067   } 
00068   
00069   //create image wich contain the main font image
00070   image *font=new image();
00071   font->get(f);
00072   
00073   //get the cursor
00074   cursor=new image();
00075   cursor->get(f);
00076 
00077   char i;
00078   u_int16 pos,tl;
00079   
00080   while(!f.eof())
00081     {
00082       
00083       i << f;
00084       pos << f;
00085       tl << f; 
00086       if(i>0 && i<WIN_NB_TABLE_CHAR)
00087     {
00088         image *glph = new image (tl + 1,font->height()-1);
00089         font->draw (0, 0, pos, 0, tl + 1, font->height () -1, NULL, glph);
00090         glyphs[i] = glph; 
00091     } 
00092     }
00093   
00094   height_=font->height()-1;
00095   
00096   length_=glyphs[' ']->length();
00097   
00098   if(font)delete font;
00099   
00100   f.close ();  
00101 }
00102 
00103 
00104 bool win_font::in_table(u_int16 tmp)
00105 {
00106     if (glyphs.find (tmp) != glyphs.end ()) return true;
00107     else return false;
00108 }
00109 
00110 image & win_font::operator[](u_int16 i)
00111 {
00112     if (in_table (i)) return *(glyphs[i]);
00113     else return *(glyphs[' ']);
00114 }
00115 
00116 
00117 /*
00118 win_font & win_font::operator=(win_font & tmpfont)
00119 {
00120   erase();
00121   table=new image[WIN_NB_TABLE_CHAR];
00122   cursor=new image();
00123   *cursor=*(tmpfont.cursor);
00124   for(u_int16 i=0;i<WIN_NB_TABLE_CHAR;i++)
00125     if(table_core[i]=tmpfont.in_table(i))
00126       table[i]=tmpfont.table[i];
00127   height_=tmpfont.height();
00128   length_=tmpfont.length();
00129   return * this;
00130 }
00131 */
00132