* Fixed font selection through cucul_font_load(). * Added a bigger 10x19 bold font.tags/v0.99.beta14
@@ -26,7 +26,8 @@ libcucul_la_SOURCES = \ | |||||
sprite.c \ | sprite.c \ | ||||
dither.c \ | dither.c \ | ||||
font.c \ | font.c \ | ||||
font_monospace9.h \ | |||||
font_mono9.h \ | |||||
font_monobold12.h \ | |||||
export_irc.c \ | export_irc.c \ | ||||
export_ansi.c \ | export_ansi.c \ | ||||
export_html.c \ | export_html.c \ | ||||
@@ -191,6 +191,7 @@ void cucul_free_dither(struct cucul_dither *); | |||||
* @{ */ | * @{ */ | ||||
struct cucul_font; | struct cucul_font; | ||||
struct cucul_font *cucul_load_font(void const *, unsigned int); | struct cucul_font *cucul_load_font(void const *, unsigned int); | ||||
char const * const * cucul_get_font_list(void); | |||||
unsigned int cucul_get_font_width(struct cucul_font *); | unsigned int cucul_get_font_width(struct cucul_font *); | ||||
unsigned int cucul_get_font_height(struct cucul_font *); | unsigned int cucul_get_font_height(struct cucul_font *); | ||||
void cucul_render_canvas(cucul_t *, struct cucul_font *, unsigned char *, | void cucul_render_canvas(cucul_t *, struct cucul_font *, unsigned char *, | ||||
@@ -33,10 +33,10 @@ | |||||
#include "cucul_internals.h" | #include "cucul_internals.h" | ||||
/* Internal fonts */ | /* Internal fonts */ | ||||
uint8_t const font_monospace9[] = | |||||
#include "font_monospace9.h" | |||||
; | |||||
#include "font_mono9.h" | |||||
#include "font_monobold12.h" | |||||
/* Helper structure for font loading */ | |||||
struct font_header | struct font_header | ||||
{ | { | ||||
uint32_t control_size, data_size; | uint32_t control_size, data_size; | ||||
@@ -111,7 +111,14 @@ struct cucul_font *cucul_load_font(void const *data, unsigned int size) | |||||
unsigned int i; | unsigned int i; | ||||
if(size == 0) | if(size == 0) | ||||
return cucul_load_font(font_monospace9, 150000); /* FIXME */ | |||||
{ | |||||
if(!strcasecmp(data, "Monospace 9")) | |||||
return cucul_load_font(mono9_data, mono9_size); | |||||
if(!strcasecmp(data, "Monospace Bold 12")) | |||||
return cucul_load_font(monobold12_data, monobold12_size); | |||||
return NULL; | |||||
} | |||||
f = malloc(sizeof(struct cucul_font)); | f = malloc(sizeof(struct cucul_font)); | ||||
f->private = (void *)(uintptr_t)data; | f->private = (void *)(uintptr_t)data; | ||||
@@ -155,6 +162,26 @@ struct cucul_font *cucul_load_font(void const *data, unsigned int size) | |||||
return f; | return f; | ||||
} | } | ||||
/** | |||||
* \brief Get available builtin fonts | |||||
* | |||||
* Return a list of available builtin fonts. The list is a NULL-terminated | |||||
* array of strings. | |||||
* | |||||
* \return An array of strings. | |||||
*/ | |||||
char const * const * cucul_get_font_list(void) | |||||
{ | |||||
static char const * const list[] = | |||||
{ | |||||
"Monospace 9", | |||||
"Monospace Bold 12", | |||||
NULL | |||||
}; | |||||
return list; | |||||
} | |||||
/** \brief Get a font's maximum glyph width. | /** \brief Get a font's maximum glyph width. | ||||
* | * | ||||
* This function returns the maximum value for the current font's glyphs | * This function returns the maximum value for the current font's glyphs | ||||
@@ -1,13 +1,17 @@ | |||||
/* libcucul font file | /* libcucul font file | ||||
* "Monospace 9": 96 dpi, 4 bpp, 7x15 glyphs | * "Monospace 9": 96 dpi, 4 bpp, 7x15 glyphs | ||||
* Automatically generated by tools/makefont.c */ | |||||
* Automatically generated by tools/makefont.c: | |||||
* tools/makefont mono9 "Monospace 9" 96 4 | |||||
*/ | |||||
static unsigned int const mono9_size = 98740; | |||||
static unsigned char const mono9_data[] = | |||||
/* file: */ | /* file: */ | ||||
"CACA" /* caca_header */ | "CACA" /* caca_header */ | ||||
"FONT" /* caca_file_type */ | "FONT" /* caca_file_type */ | ||||
/* font_header: */ | /* font_header: */ | ||||
"\0\0003\034" /* header_size */ | |||||
"\0\0003\034" /* control_size */ | |||||
"\0\001N\220" /* data_size */ | "\0\001N\220" /* data_size */ | ||||
"\0\001" /* version */ | "\0\001" /* version */ | ||||
"\0\013" /* blocks */ | "\0\013" /* blocks */ | ||||
@@ -3265,3 +3269,4 @@ | |||||
/* U+259D: "▝" */ "\0\006\377\360\000o\377\0\006\377\360\000o\377\0\006\377\360\000o\377\0\002f`\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | /* U+259D: "▝" */ "\0\006\377\360\000o\377\0\006\377\360\000o\377\0\006\377\360\000o\377\0\002f`\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
/* U+259E: "▞" */ "\0\006\377\360\000o\377\0\006\377\360\000o\377\0\006\377\360\000o\377\231\230fo\377\220\0\377\371\0\017\377\220\0\377\371\0\017\377\220\0\377\371\0\0\0\0\0\0\0\0\0" | /* U+259E: "▞" */ "\0\006\377\360\000o\377\0\006\377\360\000o\377\0\006\377\360\000o\377\231\230fo\377\220\0\377\371\0\017\377\220\0\377\371\0\017\377\220\0\377\371\0\0\0\0\0\0\0\0\0" | ||||
/* U+259F: "▟" */ "\0\006\377\360\000o\377\0\006\377\360\000o\377\0\006\377\360\000o\377\231\234\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\360\0\0\0\0\0\0\0" | /* U+259F: "▟" */ "\0\006\377\360\000o\377\0\006\377\360\000o\377\0\006\377\360\000o\377\231\234\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\360\0\0\0\0\0\0\0" | ||||
; |
@@ -33,6 +33,7 @@ int main(int argc, char *argv[]) | |||||
struct cucul_font *f; | struct cucul_font *f; | ||||
unsigned char *buf; | unsigned char *buf; | ||||
unsigned int x, y, w, h; | unsigned int x, y, w, h; | ||||
char const * const * fonts; | |||||
/* Create a canvas */ | /* Create a canvas */ | ||||
qq = cucul_create(8, 2); | qq = cucul_create(8, 2); | ||||
@@ -43,7 +44,13 @@ int main(int argc, char *argv[]) | |||||
cucul_putstr(qq, 0, 1, "&$âøÿ░▒█"); | cucul_putstr(qq, 0, 1, "&$âøÿ░▒█"); | ||||
/* Load a libcucul internal font */ | /* Load a libcucul internal font */ | ||||
f = cucul_load_font("Monospace 9", 0); | |||||
fonts = cucul_get_font_list(); | |||||
if(fonts[0] == NULL) | |||||
{ | |||||
fprintf(stderr, "error: libcucul was compiled without any fonts\n"); | |||||
return -1; | |||||
} | |||||
f = cucul_load_font(fonts[0], 0); | |||||
/* Create our bitmap buffer (32-bit ARGB) */ | /* Create our bitmap buffer (32-bit ARGB) */ | ||||
w = cucul_get_width(qq) * cucul_get_font_width(f); | w = cucul_get_width(qq) * cucul_get_font_width(f); | ||||