Commit 169493f7 authored by Romain Bignon's avatar Romain Bignon

-f parameter to set the fontpath

parent 486713e1
......@@ -45,7 +45,7 @@ static time_t reset_day(time_t ts)
return mktime(&lt);
}
int create_image(struct data* data, const char *filename, struct event* events, int quiet)
int create_image(struct data* data, const char *filename, const char *fontpath, struct event* events, int quiet)
{
const char *ext;
struct period *p;
......@@ -64,6 +64,10 @@ int create_image(struct data* data, const char *filename, struct event* events,
print_date("First", first);
}
const char *hardpath[] = { "/usr/share/fonts/dejavu",
"/usr/share/fonts/truetype/ttf-dejavu",
NULL
};
const int xgraph = 50;
const int ygraph = 100;
const int hgraph = 24*6;
......@@ -73,8 +77,19 @@ int create_image(struct data* data, const char *filename, struct event* events,
imlib_context_set_image(image);
imlib_add_path_to_font_path("/usr/share/fonts/dejavu");
/* Load font paths. */
imlib_add_path_to_font_path(fontpath);
for (i = 0; hardpath[i] != NULL; ++i)
imlib_add_path_to_font_path(hardpath[i]);
/* Try to load font. */
Imlib_Font font = imlib_load_font("DejaVuSans/10");
if (!font)
{
fprintf(stderr, "Unable to find 'DejaVuSans.ttf' in '%s'.\n", fontpath);
fprintf(stderr, "Please use the -f parameter.\n");
return 1;
}
imlib_context_set_font(font);
imlib_context_set_color(255, 0, 130, 255);
......
......@@ -31,6 +31,6 @@ struct event
struct event* next;
};
extern int create_image(struct data* data, const char *filename, struct event* events, int quiet);
extern int create_image(struct data* data, const char *filename, const char *fontpath, struct event* events, int quiet);
#endif /* _IMAGE_H */
......@@ -121,6 +121,7 @@ static void usage(const char* progname, int is_help)
fprintf(f, "\nOptions:\n");
fprintf(f, " -j, --jobs=N Number of simultaneous jobs.\n");
fprintf(f, " -o, --output=FILENAME Output filename (default=output.png).\n");
fprintf(f, " -f, --fontpath=PATH Path of DejaVuSans.ttf font (default=/usr/share/fonts/dejavu).\n");
fprintf(f, " -h, --help Print this message and exit.\n");
fprintf(f, " -q, --quiet Don't print anything.\n");
fprintf(f, " -n, --nickname NICKNAME Add a nickname.\n");
......@@ -148,6 +149,7 @@ int main(int argc, char **argv)
{
{ "jobs", 1, NULL, 'j' },
{ "output", 1, NULL, 'o' },
{ "fontpath", 1, NULL, 'f' },
{ "help", 1, NULL, 'h' },
{ "version", 1, NULL, 'v' },
{ "quiet", 1, NULL, 'q' },
......@@ -163,10 +165,11 @@ int main(int argc, char **argv)
fd_set fdset;
struct data data = {0};
char imagefile[100] = "output.png";
char fontpath[100] = "/usr/share/fonts/dejavu";
struct nick* nicks = NULL;
struct event* events = NULL;
while((i = getopt_long(argc, argv, "qo:j:vhn:e:", long_options, &option_index)) != -1)
while((i = getopt_long(argc, argv, "qo:f:j:vhn:e:", long_options, &option_index)) != -1)
switch(i)
{
case 'q':
......@@ -175,6 +178,9 @@ int main(int argc, char **argv)
case 'o':
strncpy(imagefile, optarg, sizeof(imagefile));
break;
case 'f':
strncpy(fontpath, optarg, sizeof(fontpath));
break;
case 'j':
nprocess = atoi(optarg);
break;
......@@ -326,7 +332,7 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
ret = create_image(&data, imagefile, events, quiet);
ret = create_image(&data, imagefile, fontpath, events, quiet);
cleanup(&data, nicks, events);
......
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