font.h

Go to the documentation of this file.
00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00015  */
00016 
00017 #ifndef FONT_H
00018 #define FONT_H
00019 
00020 #include "hash_utils.h"
00021 
00022 class Image_buffer8;
00023 class Shape_file;
00024 class DataSource;
00025 
00026 /*
00027  *  A single font:
00028  */
00029 class Font
00030 {
00031 private:
00032   int hor_lead;
00033   int ver_lead;
00034   Shape_file *font_shapes;
00035   DataSource *font_data;
00036   char *font_buf;
00037   char *orig_font_buf;
00038   int  highest, lowest;
00039 
00040   void calc_highlow();
00041 public:
00042   Font();
00043   Font(const char *fname, int index, int hlead=0, int vlead=1);
00044   ~Font();
00045   int load(const char *fname, int index, int hlead=0, int vlead=1);
00046           // Text rendering:
00047   int paint_text_box(Image_buffer8 *win,  
00048     const char *text, int x, int y, int w, 
00049     int h, int vert_lead = 0, int pbreak = 0);
00050   int paint_text(Image_buffer8 *win,  
00051     const char *text, int xoff, int yoff);
00052   int paint_text(Image_buffer8 *win,  
00053     const char *text, int textlen, int xoff, int yoff);
00054   int paint_text_box_fixedwidth(Image_buffer8 *win,  
00055     const char *text, int x, int y, int w, 
00056     int h, int char_width, int vert_lead = 0, int pbreak = 0);
00057   int paint_text_fixedwidth(Image_buffer8 *win,  
00058     const char *text, int xoff, int yoff, int width);
00059   int paint_text_fixedwidth(Image_buffer8 *win,  
00060     const char *text, int textlen, int xoff, int yoff, int width);
00061           // Get text width.
00062   int get_text_width(const char *text);
00063   int get_text_width(const char *text, int textlen);
00064           // Get text height, baseline.
00065   int get_text_height();
00066   int get_text_baseline();
00067 
00068   int draw_text(Image_buffer8 *win, int x, int y, const char *s)
00069     { return paint_text(win, s, x, y); }
00070   int draw_text_box(Image_buffer8 *win, 
00071         int x, int y, int w, int h, const char *s)
00072     { return paint_text_box(win, s, x, y, w, h, 0, 0); }
00073   int center_text(Image_buffer8 *iwin, int x, int y, const char *s);
00074 };
00075 
00076 /*
00077  *  Manage a list of fonts by name.
00078  */
00079 class FontManager
00080 {
00081 private:
00082 #ifndef DONT_HAVE_HASH_MAP
00083   hash_map<const char*, Font*, hashstr, eqstr> fonts;
00084 #else
00085   std::map<const char*, Font*, ltstr> fonts;
00086 #endif
00087 public:
00088   FontManager();
00089   ~FontManager();
00090   void add_font(const char *name, const char *archive, int index, int hlead=0, int vlead=1);
00091   void remove_font(const char *name);
00092   Font *get_font(const char *name);
00093 
00094   void reset();
00095 };
00096 
00097 extern FontManager fontManager;
00098 
00099 #endif

Generated on Mon Jul 9 14:42:50 2007 for ExultEngine by  doxygen 1.5.1