1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include "TtfUtil.h"
namespace gr
{
// used to allow table sharing between font copies
// TBD: should this be a real class or is it acceptable to
// make the attributes public
class FontTableCache
{
public:
FontTableCache()
: m_fontCount(1)
{
for (int i = 0; i<ktiLast; i++)
{
m_pTable[i] = NULL;
}
}
~FontTableCache()
{
Assert(m_fontCount == 0);
for (int i = 0; i<ktiLast; i++)
{
if (m_pTable[i]) delete[] m_pTable[i];
}
}
const int & getFontCount() { return m_fontCount; }
void incrementFontCount() { m_fontCount++; }
void decrementFontCount() { m_fontCount--; Assert(m_fontCount > -1); }
byte * getTable(TableId id) const { Assert(id < ktiLast); return m_pTable[id]; }
const long & getTableSize(TableId id) const
{
Assert(id < ktiLast);
return m_tableSize[id];
}
byte * allocateTable(TableId id, long size)
{
m_pTable[id] = new byte[size];
m_tableSize[id] = size;
return m_pTable[id];
}
private:
int m_fontCount;
byte * m_pTable[ktiLast];
long m_tableSize[ktiLast];
};
}
|