File indexing completed on 2024-05-19 15:27:49
0001 /* This file is part of KGraphViewer. 0002 Copyright (C) 2005-2007 Gael de Chalendar <kleag@free.fr> 0003 0004 KGraphViewer is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public 0006 License as published by the Free Software Foundation, version 2. 0007 0008 This program is distributed in the hope that it will be useful, 0009 but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 General Public License for more details. 0012 0013 You should have received a copy of the GNU General Public License 0014 along with this program; if not, write to the Free Software 0015 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0016 02110-1301, USA 0017 */ 0018 0019 #include "FontsCache.h" 0020 0021 #include "dot2qtconsts.h" 0022 0023 FontsCache::~FontsCache() 0024 { 0025 FontsCache::iterator it, it_end; 0026 it = begin(); 0027 it_end = end(); 0028 for (; it != it_end; it++) { 0029 delete (*it); 0030 } 0031 } 0032 0033 QFont *FontsCache::cachedFont(const QFont &font) 0034 { 0035 if (find(font.key()) == end()) { 0036 (*this)[font.key()] = new QFont(font); 0037 } 0038 return (*this)[font.key()]; 0039 } 0040 0041 QFont *FontsCache::fromName(const QString &fontName) 0042 { 0043 if (m_namesToFonts.find(fontName) == m_namesToFonts.end()) { 0044 QFont font(Dot2QtConsts::componentData().qtFont(fontName)); 0045 m_namesToFonts[fontName] = cachedFont(font); 0046 } 0047 return m_namesToFonts[fontName]; 0048 }