FixedWidthFont.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2005 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #include "pent_include.h"
00020 #include "FixedWidthFont.h"
00021 
00022 #include "Texture.h"
00023 #include "IDataSource.h"
00024 #include "ConfigFileManager.h"
00025 #include "FileSystem.h"
00026 
00027 FixedWidthFont * FixedWidthFont::Create(std::string iniroot)
00028 {
00029         ConfigFileManager *config = ConfigFileManager::get_instance();
00030         FileSystem *filesys = FileSystem::get_instance();
00031 
00032         std::string     filename;
00033         if (!config->get(iniroot + "/font/path",filename)) {
00034                 perr << "Error: 'path' key not found in font ini" << std::endl;
00035                 return 0;
00036         }
00037 
00038         IDataSource *ds = filesys->ReadFile(filename);
00039 
00040         if (!ds) {
00041                 perr << "Error: Unable to open file " << filename << std::endl;
00042                 return 0;
00043         }
00044 
00045         Texture *fonttex = Texture::Create(ds, filename.c_str());
00046 
00047         if (!fonttex)
00048         {
00049                 perr << "Error: Unable to read texture " << filename << std::endl;
00050                 return 0;
00051         }
00052 
00053         delete ds;
00054 
00055         FixedWidthFont *fwf = new FixedWidthFont;
00056 
00057         fwf->tex = fonttex;
00058 
00059         if (!config->get(iniroot + "/font/width",fwf->width)) {
00060                 fwf->width = fwf->tex->width / 16;
00061         }
00062         
00063         if (!config->get(iniroot + "/font/height",fwf->height)) {
00064                 fwf->height = fwf->tex->height / 16;
00065         }
00066 
00067         if (!config->get(iniroot + "/font/align_x",fwf->align_x)) {
00068                 for (int i = 0; i < 32; i++) {
00069                         if (fwf->width <= (1 << i)) {
00070                                 fwf->align_x = 1 << i;
00071                                 break;
00072                         }
00073                 }
00074         }
00075 
00076         if (!config->get(iniroot + "/font/align_y",fwf->align_y)) {
00077                 for (int i = 0; i < 32; i++) {
00078                         if (fwf->height <= (1 << i)) {
00079                                 fwf->align_y = 1 << i;
00080                                 break;
00081                         }
00082                 }
00083         }
00084 
00085         return fwf;
00086 }

Generated on Fri Jul 27 22:27:14 2007 for pentagram by  doxygen 1.4.7