summaryrefslogtreecommitdiffstats
path: root/src/video/fonts.c
blob: e2b46ebf73b832bf2f53142d210300d2f0d5ae0d (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
#include "video/video.h"
#include "filesystem/path.h"
#include "Nebu_filesystem.h"

void initFonts(void) {
  char *path;
  file_handle file;
  char buf[100];
  char gamefont[100];
  char guifont[100];
  char *game = NULL, *gui = NULL;

  if(gameFtx != NULL) ftxUnloadFont(gameFtx);
  if(guiFtx != NULL) ftxUnloadFont(guiFtx);

  path = getPath(PATH_DATA, "fonts.txt");
  if(path != NULL) {
    file = file_open(path, "r");
    while(file_gets(file, buf, sizeof(buf)) != NULL) {
      if(sscanf(buf, "game: %s ", gamefont) == 1)
	game = gamefont;
      else if(sscanf(buf, "menu: %s ", guifont) == 1)
	gui = guifont;
    }
    file_close(file);
    free(path);
  } else {
    fprintf(stderr, "can't load fonts.txt\n");
    exit(1); /* OK: critical, installation corrupt */
  }

  if(game == NULL || gui == NULL) {
    fprintf(stderr, "incomplete font definition in fonts.txt\n");
    exit(1); /* OK: critical, installation corrupt */
  }

  gameFtx = ftxLoadFont(game);
  guiFtx = ftxLoadFont(gui);

  if(gameFtx == NULL) {
    fprintf(stderr, "can't load font %s\n", game);
    exit(1); /* OK: critical, installation corrupt */
  }

  if(guiFtx == NULL) {
    fprintf(stderr, "can't load font %s\n", gui);
    exit(1); /* OK: critical, installation corrupt */
  }
}

void deleteFonts(void) {
  if(gameFtx != NULL)
    ftxUnloadFont(gameFtx);
  gameFtx = NULL;
  if(guiFtx != NULL)
    ftxUnloadFont(guiFtx);
  guiFtx = NULL;
}