00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
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         
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 }