Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmsfontmanager.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2012 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
00031  **************************************************************************/
00032 
00033 #include "mmsgui/mmsfontmanager.h"
00034 
00035 MMSFontManager::MMSFontManager() {
00036 }
00037 
00038 MMSFontManager::~MMSFontManager() {
00039     /* free all fonts */
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     /* build filename */
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     // lock threads
00066     this->lock.lock();
00067 
00068     /* search within fonts list */
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     /* load font */
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     /* add to fonts list and return the font */
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     /*TODO*/
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 

Generated by doxygen