Commit 8b460274 authored by Tomas Heran's avatar Tomas Heran Committed by Gargaj
Browse files

Use fontconfig on Linux to find appropriate default font.

parent 2278d99c
...@@ -17,11 +17,11 @@ before_install: ...@@ -17,11 +17,11 @@ before_install:
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then - if [ "$TRAVIS_OS_NAME" = "linux" ]; then
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 3B4FE6ACC0B21F32 40976EAF437D05B5; sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 3B4FE6ACC0B21F32 40976EAF437D05B5;
sudo apt-get update; sudo apt-get update;
sudo apt-get install -q -y xorg-dev; sudo apt-get install -q -y xorg-dev libfontconfig1-dev;
fi fi
script: script:
- cmake . && cmake --build . - cmake . && cmake --build .
notifications: notifications:
email: false email: false
\ No newline at end of file
...@@ -443,7 +443,7 @@ if (APPLE) ...@@ -443,7 +443,7 @@ if (APPLE)
mark_as_advanced(COCOA_FRAMEWORK OPENGL_FRAMEWORK CARBON_FRAMEWORK COREAUDIO_FRAMEWORK AVFOUNDATION_FRAMEWORK) mark_as_advanced(COCOA_FRAMEWORK OPENGL_FRAMEWORK CARBON_FRAMEWORK COREAUDIO_FRAMEWORK AVFOUNDATION_FRAMEWORK)
set(PLATFORM_LIBS ${COCOA_FRAMEWORK} ${OPENGL_FRAMEWORK} ${CARBON_FRAMEWORK} ${COREAUDIO_FRAMEWORK} ${AVFOUNDATION_FRAMEWORK}) set(PLATFORM_LIBS ${COCOA_FRAMEWORK} ${OPENGL_FRAMEWORK} ${CARBON_FRAMEWORK} ${COREAUDIO_FRAMEWORK} ${AVFOUNDATION_FRAMEWORK})
elseif (UNIX) elseif (UNIX)
set(PLATFORM_LIBS GL) set(PLATFORM_LIBS GL fontconfig)
elseif (WIN32) elseif (WIN32)
if (${BONZOMATIC_WINDOWS_FLAVOR} MATCHES "DX11") if (${BONZOMATIC_WINDOWS_FLAVOR} MATCHES "DX11")
set(PLATFORM_LIBS d3d11 d3dcompiler dxguid DXGI winmm shlwapi) set(PLATFORM_LIBS d3d11 d3dcompiler dxguid DXGI winmm shlwapi)
......
...@@ -4,7 +4,11 @@ ...@@ -4,7 +4,11 @@
#include <string.h> #include <string.h>
#include "../Misc.h" #include "../Misc.h"
#include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h>
#include <fontconfig/fontconfig.h>
void Misc::PlatformStartup() void Misc::PlatformStartup()
{ {
...@@ -16,17 +20,17 @@ void Misc::PlatformShutdown() ...@@ -16,17 +20,17 @@ void Misc::PlatformShutdown()
void Misc::InitKeymaps() void Misc::InitKeymaps()
{ {
return; return;
} }
void Misc::GetKeymapName(char* sz) void Misc::GetKeymapName(char* sz)
{ {
strncpy(sz,"<native>",7); strncpy(sz,"<native>",7);
} }
bool Misc::ExecuteCommand( const char * cmd, const char * param ) bool Misc::ExecuteCommand( const char * cmd, const char * param )
{ {
return false; return false;
} }
bool Misc::FileExists(const char * path) bool Misc::FileExists(const char * path)
...@@ -36,28 +40,54 @@ bool Misc::FileExists(const char * path) ...@@ -36,28 +40,54 @@ bool Misc::FileExists(const char * path)
const char * Misc::GetDefaultFontPath() const char * Misc::GetDefaultFontPath()
{ {
// Linux case static char ret[PATH_MAX] = { 0 };
// TODO: use fonts.conf(5) or X resources or something like that FcPattern *pat;
const char* fontPaths[] = FcFontSet *fs;
FcObjectSet *os;
FcChar8 *file = NULL;
FcConfig *config;
FcBool result;
int i;
const char *familyNames[] =
{ {
"/usr/share/fonts/TTF/DejaVuSansMono.ttf", "DejaVu Sans Mono",
"/usr/share/fonts/TTF/FreeMono.ttf", "FreeMono",
"/usr/share/fonts/TTF/LiberationMono-Regular.ttf", "Liberation Mono",
"/usr/share/fonts/TTF/VeraMono.ttf", "Bitstream Vera Sans Mono",
"/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", "Ubuntu Mono",
"/usr/share/fonts/truetype/freefont/FreeMono.ttf",
"/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf",
"/usr/share/fonts/truetype/msttcorefonts/cour.ttf",
"/usr/share/fonts/truetype/ubuntu-font-family/UbuntuMono-R.ttf",
"/usr/share/fonts/corefonts/cour.ttf",
NULL NULL
}; };
for (int i = 0; fontPaths[i]; ++i)
{ result = FcInit();
if (FileExists(fontPaths[i])) config = FcConfigGetCurrent();
{ FcConfigSetRescanInterval(config, 0);
return fontPaths[i];
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;
}
}
}
} }
} }
return NULL;
out:
FcFontSetDestroy(fs);
FcObjectSetDestroy(os);
FcPatternDestroy(pat);
return ret;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment