00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "mmsgui/mmsfontmanager.h"
00034
00035 MMSFontManager::MMSFontManager() {
00036 }
00037
00038 MMSFontManager::~MMSFontManager() {
00039
00040 for(vector<MMSFM_DESC>::iterator it = this->fonts.begin(); it != this->fonts.end(); ++it) {
00041 if(it->font) {
00042 delete it->font;
00043 break;
00044 }
00045 }
00046
00047 this->fonts.clear();
00048 }
00049
00050 MMSFBFont *MMSFontManager::getFont(string path, string filename, unsigned int size) {
00051 string fontfile;
00052 MMSFM_DESC fm_desc;
00053
00054
00055 if((path.empty() && filename.empty()) || size == 0) {
00056 return NULL;
00057 }
00058
00059 if(path.empty()) {
00060 fontfile = filename;
00061 } else {
00062 fontfile = path +"/" + filename;
00063 }
00064
00065
00066 this->lock.lock();
00067
00068
00069 for(vector<MMSFM_DESC>::iterator it = this->fonts.begin(); it != this->fonts.end(); ++it) {
00070 if((it->fontfile == fontfile) && (it->size == size)) {
00071 it->refcnt++;
00072 this->lock.unlock();
00073 return it->font;
00074 }
00075 }
00076
00077
00078 fm_desc.font = NULL;
00079 if (!loadFont(&(fm_desc.font), "", fontfile, 0, size)) {
00080 DEBUGMSG("MMSGUI", "cannot load font file '%s'", fontfile.c_str());
00081 this->lock.unlock();
00082 return NULL;
00083 }
00084 fm_desc.fontfile = fontfile;
00085 fm_desc.size = size;
00086 fm_desc.refcnt = 0;
00087
00088
00089 this->fonts.push_back(fm_desc);
00090 this->lock.unlock();
00091 return fm_desc.font;
00092 }
00093
00094 void MMSFontManager::releaseFont(string path, string filename, unsigned int size) {
00095
00096 }
00097
00098 void MMSFontManager::releaseFont(MMSFBFont *font) {
00099 if(font) {
00100 this->lock.lock();
00101 for(vector<MMSFM_DESC>::iterator it = this->fonts.begin(); it != this->fonts.end(); ++it) {
00102 if(it->font == font) {
00103 if(--it->refcnt == 0) {
00104 this->fonts.erase(it);
00105 delete font;
00106 }
00107 break;
00108 }
00109 }
00110 this->lock.unlock();
00111 }
00112 }
00113