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