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-2013 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     MMSFM_DESC      fm_desc;
00052 
00053     /* build filename */
00054     if((path.empty() && filename.empty()) || size == 0) {
00055         return NULL;
00056     }
00057     
00058     if(path.empty()) {
00059         fm_desc.fontfile = filename;
00060     } else {
00061         fm_desc.fontfile = path +"/" + filename;
00062     }
00063     fixPathStr(fm_desc.fontfile);
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 == fm_desc.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), "", fm_desc.fontfile, 0, size)) {
00080         DEBUGMSG("MMSGUI", "cannot load font file '%s'", fm_desc.fontfile.c_str());
00081         this->lock.unlock();
00082         return NULL;
00083     }
00084     fm_desc.size = size;
00085     fm_desc.refcnt = 1;
00086 
00087     /* add to fonts list and return the font */
00088     this->fonts.push_back(fm_desc);
00089     this->lock.unlock();
00090     return fm_desc.font;
00091 }
00092 
00093 void MMSFontManager::releaseFont(string path, string filename, unsigned int size) {
00094     /*TODO*/
00095 }
00096 
00097 void MMSFontManager::releaseFont(MMSFBFont *font) {
00098     if(font) {
00099         this->lock.lock();
00100         for(vector<MMSFM_DESC>::iterator it = this->fonts.begin(); it != this->fonts.end(); ++it) {
00101             if(it->font == font) {
00102                 if(--it->refcnt == 0) {
00103                     this->fonts.erase(it);
00104                     delete font;
00105                 }
00106                 break;
00107             }
00108         }
00109         this->lock.unlock();
00110     }
00111 }
00112 

Generated by doxygen