summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/font.c47
-rw-r--r--src/client/font.h2
-rw-r--r--src/client/fontConfig.c136
-rw-r--r--src/client/fontConfig.h17
-rw-r--r--src/client/game.c2
5 files changed, 191 insertions, 13 deletions
diff --git a/src/client/font.c b/src/client/font.c
index 52963b6..c701e3f 100644
--- a/src/client/font.c
+++ b/src/client/font.c
@@ -1,7 +1,9 @@
+
#include "main.h"
#include "interface.h"
#include "font.h"
#include "image.h"
+#include "fontConfig.h"
static TTF_Font *g_font;
static int fontSize;
@@ -13,30 +15,53 @@ bool_t isFontInicialized()
return isFontInit;
}
-void initFont(char *file, int size)
+void initFont()
{
- char str[STR_PATH_SIZE];
-
- assert(file != NULL);
- assert(size > 0);
+ char *arg[] = {":lang=he:outline=true:style=Book", "family", "style", "weight", "file", NULL};
+ char *font_file;
+ font_config_t *font_list;
+ int res;
assert(isInterfaceInicialized() == TRUE);
- sprintf(str, "%s", file);
+ res = fontconfig_init();
+
+ if( res != 0 )
+ {
+ return;
+ }
+
+ font_list = fontconfig_find(arg);
+/*
+ int i;
+ for(i = 0 ; font_list[i].path != NULL ; i++ )
+ {
+ printf("path[%d]=%s\nflag[%d]=%s\n\n", i, font_list[i].path, i, font_list[i].flag);
+ }
+*/
+ if( font_list == NULL )
+ {
+ fprintf(stderr, _("I do not find font\n"));
+ return;
+ }
+
+ font_file = strdup(font_list[0].path);
+ fontSize = FONT_SIZE;
+
+ fontconfig_del_list(font_list);
+ fontconfig_quit();
if (TTF_Init() == -1) {
fprintf(stderr, "%s\n", SDL_GetError());
return;
}
- accessExistFile(str);
+ accessExistFile(font_file);
- g_font = TTF_OpenFont(str, size);
+ g_font = TTF_OpenFont(font_file, fontSize);
TTF_SetFontStyle(g_font, TTF_STYLE_NORMAL);
- fontSize = size;
-
- DEBUG_MSG(_("Loading font: \"%s\"\n"), file);
+ DEBUG_MSG(_("Loading font: \"%s\"\n"), font_file);
isFontInit = TRUE;
}
diff --git a/src/client/font.h b/src/client/font.h
index f728e86..6f30a71 100644
--- a/src/client/font.h
+++ b/src/client/font.h
@@ -18,7 +18,7 @@
# define FONT_SIZE 16
extern bool_t isFontInicialized();
-extern void initFont(char *file, int size);
+extern void initFont();
extern void drawFont(char *s, int x, int y, int r, int g, int b);
extern void drawFontMaxSize(char *s, int x, int y, int w, int h, int r, int g,
int b);
diff --git a/src/client/fontConfig.c b/src/client/fontConfig.c
new file mode 100644
index 0000000..fcf77e2
--- /dev/null
+++ b/src/client/fontConfig.c
@@ -0,0 +1,136 @@
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fontconfig/fontconfig.h>
+
+#include "fontConfig.h"
+
+int fontconfig_init()
+{
+ int res;
+
+ res = FcInit();
+
+ if( res == 0 )
+ {
+ fprintf(stderr, "Can't init font config library\n");
+ return 1;
+ }
+
+ return 0;
+}
+
+font_config_t* fontconfig_find(char **arg)
+{
+ FcObjectSet *os;
+ FcFontSet *fs;
+ FcPattern *pat;
+ font_config_t *ret;
+ int i;
+
+ os = NULL;
+ ret = NULL;
+
+ for( i = 0 ; arg[i] != NULL ; i++ )
+ {
+ //printf("arg %s\n", arg[i]);
+
+ if( i == 0 )
+ {
+ pat = FcNameParse ((FcChar8 *) arg[i]);
+ }
+
+ if( os == NULL )
+ {
+ os = FcObjectSetCreate();
+ }
+
+ FcObjectSetAdd (os, arg[i]);
+ }
+
+ if( os == NULL )
+ {
+ os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, (char *) 0);
+ }
+
+ fs = FcFontList (0, pat, os);
+ FcObjectSetDestroy(os);
+
+ if( pat != NULL )
+ {
+ FcPatternDestroy(pat);
+ }
+
+ if( fs != NULL )
+ {
+ int j;
+
+ ret = malloc( (fs->nfont+1) * sizeof(font_config_t) );
+
+ for( j = 0; j < fs->nfont ; j++ )
+ {
+ FcChar8 *font;
+ FcChar8 *file;
+
+ font = FcNameUnparse(fs->fonts[j]);
+
+ if( FcPatternGetString(fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch )
+ {
+ ret[j].path = strdup((char *)file);
+ }
+
+ ret[j].flag = strdup((char *)font);
+ free(font);
+ }
+
+ ret[fs->nfont].path = NULL;
+ ret[fs->nfont].flag = NULL;
+
+ FcFontSetDestroy(fs);
+ }
+
+ return ret;
+}
+
+void fontconfig_del_list(font_config_t *list)
+{
+ int i;
+
+ for( i = 0 ; list[i].path != NULL ; i++ )
+ {
+ free(list[i].path);
+ free(list[i].flag);
+ }
+
+ free(list);
+}
+
+int fontconfig_quit()
+{
+ FcFini();
+ return 0;
+}
+
+int fc_test_main(int argc, char **argv)
+{
+ char *arg[] = {":lang=he:outline=true", "family", "style", "weight", "file", NULL};
+ font_config_t *res;
+ int i;
+
+ fontconfig_init();
+
+ res = fontconfig_find(arg);
+
+ for( i = 0 ; res[i].path != NULL ; i++ )
+ {
+ printf("path=%s\nflag=%s\n\n", res[i].path, res[i].flag);
+ }
+
+ fontconfig_del_list(res);
+
+ fontconfig_quit();
+
+ return 0;
+}
diff --git a/src/client/fontConfig.h b/src/client/fontConfig.h
new file mode 100644
index 0000000..ac2b0b4
--- /dev/null
+++ b/src/client/fontConfig.h
@@ -0,0 +1,17 @@
+
+#ifndef FONT_CONFIG_H
+
+#define FONT_CONFIG_H
+
+typedef struct font_config_struct
+{
+ char *path;
+ char *flag;
+} font_config_t;
+
+extern int fontconfig_init();
+extern font_config_t* fontconfig_find(char **arg);
+extern void fontconfig_del_list(font_config_t *list);
+extern int fontconfig_quit();
+
+#endif
diff --git a/src/client/game.c b/src/client/game.c
index 87676d5..310c45a 100644
--- a/src/client/game.c
+++ b/src/client/game.c
@@ -47,7 +47,7 @@ static void initGame()
createHomeDirector();
initSDL();
- initFont(FONT_FILE, FONT_SIZE);
+ initFont();
initLayer();
initImageData();
#ifndef NO_SOUND