FontShapeArchive.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003-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 
00021 #include "FontShapeArchive.h"
00022 #include "util.h"
00023 #include "ShapeFont.h"
00024 #include "ConfigFileManager.h"
00025 
00026 DEFINE_RUNTIME_CLASSTYPE_CODE(FontShapeArchive,ShapeArchive);
00027 
00028 ShapeFont* FontShapeArchive::getFont(uint32 fontnum)
00029 {
00030         return p_dynamic_cast<ShapeFont*>(getShape(fontnum));
00031 }
00032 
00033 void FontShapeArchive::cache(uint32 shapenum)
00034 {
00035         if (shapenum >= count) return;
00036         if (shapes.empty()) shapes.resize(count);
00037 
00038         if (shapes[shapenum]) return;
00039 
00040         uint32 shpsize;
00041         uint8 *data = getRawObject(shapenum, &shpsize);
00042 
00043         if (!data || shpsize == 0) return;
00044 
00045         // Auto detect format
00046         if (!format) format = Shape::DetectShapeFormat(data,shpsize);
00047         
00048         if (!format)
00049         {
00050                 delete [] data;
00051                 perr << "Error: Unable to detect shape format for flex." << std::endl;
00052                 return;
00053         }
00054 
00055         Shape* shape = new ShapeFont(data, shpsize, format, id, shapenum);
00056         if (palette) shape->setPalette(palette);
00057 
00058         shapes[shapenum] = shape;
00059 }
00060 
00061 void FontShapeArchive::setHVLeads()
00062 {
00063         ConfigFileManager* config = ConfigFileManager::get_instance();
00064 
00065         std::map<Pentagram::istring, std::string> leadkeyvals;
00066 
00067         leadkeyvals = config->listKeyValues("game/fontleads");
00068         std::map<Pentagram::istring, std::string>::iterator iter;
00069         for (iter = leadkeyvals.begin(); iter != leadkeyvals.end(); ++iter)
00070         {
00071                 int fontnum = std::atoi(iter->first.c_str());
00072                 std::string leaddesc = iter->second;
00073 
00074                 std::vector<std::string> vals;
00075                 Pentagram::SplitString(leaddesc, ',', vals);
00076                 if (vals.size() != 2) {
00077                         perr << "Invalid hlead/vlead description: " << leaddesc
00078                                  << std::endl;
00079                         continue;
00080                 }
00081 
00082                 int hlead = std::atoi(vals[0].c_str());
00083                 int vlead = std::atoi(vals[1].c_str());
00084 
00085                 ShapeFont* font = getFont(fontnum);
00086                 if (font) {
00087                         font->setHLead(hlead);
00088                         font->setVLead(vlead);
00089                 }
00090         }
00091 }

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