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