Misc.cpp 1.85 KB
Newer Older
1
2
3
4
5
6
// Dummy Keymap functions that don't actually map anything,
// just to fix the SDL build.

#include <string.h>
#include "../Misc.h"

7
#include <stdlib.h>
Gargaj's avatar
Gargaj committed
8
#include <unistd.h>
9
10
11
#include <limits.h>

#include <fontconfig/fontconfig.h>
Gargaj's avatar
Gargaj committed
12
13
14
15
16
17
18
19
20
21
22

void Misc::PlatformStartup()
{
}

void Misc::PlatformShutdown()
{
}

void Misc::InitKeymaps()
{
23
  return;
24
25
}

Gargaj's avatar
Gargaj committed
26
27
void Misc::GetKeymapName(char* sz)
{
28
  strncpy(sz,"<native>",7);
29
}
30

Marco Foco's avatar
Marco Foco committed
31
bool Misc::ExecuteCommand( const char * cmd, const char * param )
32
{
33
  return false;
34
}
Gargaj's avatar
Gargaj committed
35
36
37
38
39
40
41
42

bool Misc::FileExists(const char * path)
{
  return access(path, R_OK) != -1;
}

const char * Misc::GetDefaultFontPath()
{
43
44
45
46
47
48
49
50
51
52
  static char ret[PATH_MAX] = { 0 };
  FcPattern *pat;
  FcFontSet *fs;
  FcObjectSet *os;
  FcChar8 *file = NULL;
  FcConfig *config;
  FcBool result;
  int i;

  const char *familyNames[] =
Gargaj's avatar
Gargaj committed
53
  {
54
55
56
57
58
    "DejaVu Sans Mono",
    "FreeMono",
    "Liberation Mono",
    "Bitstream Vera Sans Mono",
    "Ubuntu Mono",
Gargaj's avatar
Gargaj committed
59
60
    NULL
  };
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

  result = FcInit();
  config = FcConfigGetCurrent();
  FcConfigSetRescanInterval(config, 0);

  pat = FcPatternCreate();
  os = FcObjectSetBuild (FC_FAMILY, FC_FILE, (char *) 0);
  FcPatternAddInteger(pat, FC_SPACING, FC_MONO);
  FcPatternAddInteger(pat, FC_WEIGHT, FC_WEIGHT_REGULAR);
  FcPatternAddInteger(pat, FC_SLANT, FC_SLANT_ROMAN);
  fs = FcFontList(config, pat, os);

  for (i=0; fs && i < fs->nfont; i++) {
    FcChar8 *family;
    FcPattern *font = fs->fonts[i];
    if (FcPatternGetString(font, FC_FAMILY, 0, &family) == FcResultMatch) {
      for (int i = 0; familyNames[i] != NULL; i++) {
        if (strcmp((const char *)family, familyNames[i]) == 0) {
          if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
            strcpy(ret, (const char *)file);
            goto out;
          }
        }
      }
Gargaj's avatar
Gargaj committed
85
86
    }
  }
87
88
89
90
91
92

out:
  FcFontSetDestroy(fs);
  FcObjectSetDestroy(os);
  FcPatternDestroy(pat);
  return ret;
93
}