Adonthell  0.4
win_font.cc
1 /*
2  (C) Copyright 2000 Joel Vennin
3  Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5  Adonthell is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  Adonthell is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Adonthell. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "win_font.h"
20 
21 win_font::win_font()
22 {
23  cursor=NULL;
24 }
25 
26 win_font::win_font(char * fic)
27 {
28  cursor=NULL;
29  load(fic);
30 }
31 
32 win_font::win_font(win_font & tmpfont)
33 {
34  *this=tmpfont;
35 }
36 
37 win_font::~win_font()
38 {
39  erase();
40 }
41 void win_font::erase()
42 {
43  if(cursor)
44  {
45  delete cursor;
46  cursor = NULL;
47  }
48  for(hash_map<u_int16, image*>::iterator i = glyphs.begin(); i != glyphs.end(); i++)
49  {
50  delete i->second;
51  }
52  glyphs.clear ();
53 }
54 
55 
56 void win_font::load(char * rep)
57 {
58  erase();
59 
60  //file which contains font information and cursor
61  igzstream f;
62 
63  //path where is the file
64  string path = WIN_DIRECTORY;
65 
66  //add win font directory path
67  path += WIN_FONT_DIRECTORY;
68 
69  //add theme pass
70  path += string (rep) + "/";
71 
72  //add font filename
73  path += WIN_FONT_FILE;
74 
75  //open gzfile
76  if (!f.open (path))
77  {
78  cout << path << " not found !\n";
79  exit(1);
80  }
81 
82  //create image wich contain the main font image
83  image *font=new image();
84  font->get(f);
85 
86  //get the cursor
87  cursor=new image();
88  cursor->get(f);
89 
90  char i;
91  u_int16 pos,tl;
92 
93  while(!f.eof())
94  {
95 
96  i << f;
97  pos << f;
98  tl << f;
99  if(i>0 && i<WIN_NB_TABLE_CHAR)
100  {
101  image *glph = new image (tl + 1,font->height()-1);
102  font->draw (0, 0, pos, 0, tl + 1, font->height () -1, NULL, glph);
103  glyphs[i] = glph;
104  }
105  }
106 
107  height_=font->height()-1;
108 
109  length_=glyphs[' ']->length();
110 
111  if(font)delete font;
112 
113  f.close ();
114 }
115 
116 
117 bool win_font::in_table(u_int16 tmp)
118 {
119  if (glyphs.find (tmp) != glyphs.end ()) return true;
120  else return false;
121 }
122 
123 image & win_font::operator[](u_int16 i)
124 {
125  if (in_table (i)) return *(glyphs[i]);
126  else return *(glyphs[' ']);
127 }
128 
bool eof()
Returns whether the file is at it&#39;s end or not.
Definition: fileops.h:111
u_int16 height() const
Returns the height of the drawable.
Definition: drawable.h:91
Class to read data from a Gzip compressed file.
Definition: fileops.h:135
#define u_int16
16 bits long unsigned integer
Definition: types.h:38
Image manipulation class.
Definition: image.h:45
bool open(const string &fname)
Opens a file for read access.
Definition: fileops.cc:81
A* pathfinding algorithm implementation class.
Definition: path.h:52
s_int8 get(igzstream &file)
Loads an image from an opened file, saved in game internal format, with alpha and mask values...
Definition: image.cc:73
void draw(s_int16 x, s_int16 y, const drawing_area *da_opt=NULL, surface *target=NULL) const
Draw the surface.
Definition: surface.h:191