| 1 |
/* lfont.cxx |
| 2 |
$Id: lfont.cxx,v 1.5 1997/10/18 04:57:35 elf Exp $ |
| 3 |
|
| 4 |
written by Marc Singer |
| 5 |
10 May 1997 |
| 6 |
|
| 7 |
This file is part of the project XO. See the file README for |
| 8 |
more information. |
| 9 |
|
| 10 |
Copyright (C) 1997 Marc Singer |
| 11 |
|
| 12 |
This program is free software; you can redistribute it and/or |
| 13 |
modify it under the terms of the GNU General Public License as |
| 14 |
published by the Free Software Foundation; either version 2 of the |
| 15 |
License, or (at your option) any later version. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but |
| 18 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 |
General Public License for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License |
| 23 |
in a file called COPYING along with this program; if not, write to |
| 24 |
the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA |
| 25 |
02139, USA. |
| 26 |
|
| 27 |
----------- |
| 28 |
DESCRIPTION |
| 29 |
----------- |
| 30 |
|
| 31 |
*/ |
| 32 |
|
| 33 |
#include "standard.h" |
| 34 |
#include "ldisplay.h" |
| 35 |
#include "lfont.h" |
| 36 |
|
| 37 |
void LFontCache::init (LDisplay* pDisplay) |
| 38 |
{ |
| 39 |
release_this (); // Just in case we are doing something stupid |
| 40 |
m_pDisplay = pDisplay; |
| 41 |
m_hashFontName.init (sizeof (XFontStruct*), 101); |
| 42 |
m_hashFontID.init (sizeof (XFontStruct*), 101); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
XFontStruct* LFontCache::find (char* szFont) |
| 47 |
{ |
| 48 |
HashKey key = LHashTable::make_case_string_key (szFont); |
| 49 |
XFontStruct* pFont = NULL; |
| 50 |
m_hashFontName.find (key, &pFont); |
| 51 |
if (pFont) |
| 52 |
return pFont; |
| 53 |
pFont = XLoadQueryFont (m_pDisplay->display (), szFont); |
| 54 |
if (pFont) { |
| 55 |
m_hashFontName.add (key, &pFont); |
| 56 |
m_hashFontID.add (HashKey (pFont->fid), &pFont); |
| 57 |
} |
| 58 |
return pFont; |
| 59 |
} |
| 60 |
|
| 61 |
XFontStruct* LFontCache::find (Font fid) |
| 62 |
{ |
| 63 |
XFontStruct* pFont = NULL; |
| 64 |
m_hashFontID.find (HashKey (fid), &pFont); |
| 65 |
return pFont; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
void LFontCache::release_this (void) |
| 70 |
{ |
| 71 |
if (!m_pDisplay) |
| 72 |
return; |
| 73 |
HashKey key; |
| 74 |
XFontStruct** ppFont; |
| 75 |
for (unsigned32 index = 0; |
| 76 |
index = m_hashFontName.enumerate_reverse (index, &key, |
| 77 |
(const void**) &ppFont); ) { |
| 78 |
m_hashFontID.remove (HashKey ((*ppFont)->fid)); |
| 79 |
XUnloadFont (m_pDisplay->display (), (*ppFont)->fid); |
| 80 |
XFreeFontInfo (NULL, *ppFont, 1); |
| 81 |
m_hashFontName.remove (key); |
| 82 |
} |
| 83 |
} |