summaryrefslogtreecommitdiff
path: root/font.c
blob: 29fd5dfe6422e999de999a0e4cbf60d8115664e1 (plain)
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
53
54
55
56
57
58
59
60
61
62
/*
 * font.c: 'EnigmaNG' skin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * Taken from GraphTFT 
 */

#include "common.h"

#include "font.h"
#include <iconv.h>
#include <stdio.h>

cGraphtftFont::cGraphtftFont()
{
}

cGraphtftFont::~cGraphtftFont()
{
	Clear();
}

const cFont* cGraphtftFont::GetFont(const char *Filename, int Size, int Width)
{
  if (Filename == NULL)
    return NULL;

	if (Size < MINFONTSIZE)
		Size = MINFONTSIZE;
	if (Width == 0)
		Width = 100;

  char *cachename = NULL;
  if (-1 != asprintf(&cachename, "%s_%d_%d", Filename, Size, Width)) {
    string CacheName = cachename;
    free(cachename);
    cachename = NULL;

    if (_cache.find(CacheName) != _cache.end())
      return _cache[CacheName];

    debug("cGraphtftFont::Load() CREATING FONT %s size=%d width=%d", Filename, Size, Width);
    cFont *newFont = cFont::CreateFont(Filename, Size, Width > 0 ? (Size * Width / 100) : 0);
    if (newFont) {
      _cache[CacheName] = newFont;
      return newFont;
    }
  }

  error("ERROR: EnigmaNG: Couldn't load font %s:%d", Filename, Size);

  return NULL;
}

void cGraphtftFont::Clear()
{
	cache_map::iterator it = _cache.begin();
	for (; it != _cache.end(); ++it)
		delete((*it).second);
	_cache.clear();
}