Browse Source

* Implemented cucul_get_font_list() to retrieve the list of builtin fonts.

* Fixed font selection through cucul_font_load().
  * Added a bigger 10x19 bold font.
tags/v0.99.beta14
Sam Hocevar sam 18 years ago
parent
commit
ea780d5321
6 changed files with 3321 additions and 8 deletions
  1. +2
    -1
      cucul/Makefile.am
  2. +1
    -0
      cucul/cucul.h
  3. +31
    -4
      cucul/font.c
  4. +7
    -2
      cucul/font_mono9.h
  5. +3272
    -0
      cucul/font_monobold12.h
  6. +8
    -1
      test/font.c

+ 2
- 1
cucul/Makefile.am View File

@@ -26,7 +26,8 @@ libcucul_la_SOURCES = \
sprite.c \
dither.c \
font.c \
font_monospace9.h \
font_mono9.h \
font_monobold12.h \
export_irc.c \
export_ansi.c \
export_html.c \


+ 1
- 0
cucul/cucul.h View File

@@ -191,6 +191,7 @@ void cucul_free_dither(struct cucul_dither *);
* @{ */
struct cucul_font;
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_height(struct cucul_font *);
void cucul_render_canvas(cucul_t *, struct cucul_font *, unsigned char *,


+ 31
- 4
cucul/font.c View File

@@ -33,10 +33,10 @@
#include "cucul_internals.h"

/* 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
{
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;

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->private = (void *)(uintptr_t)data;
@@ -155,6 +162,26 @@ struct cucul_font *cucul_load_font(void const *data, unsigned int size)
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.
*
* This function returns the maximum value for the current font's glyphs


cucul/font_monospace9.h → cucul/font_mono9.h View File

@@ -1,13 +1,17 @@
/* libcucul font file
* "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: */
"CACA" /* caca_header */
"FONT" /* caca_file_type */

/* font_header: */
"\0\0003\034" /* header_size */
"\0\0003\034" /* control_size */
"\0\001N\220" /* data_size */
"\0\001" /* version */
"\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+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"
;

+ 3272
- 0
cucul/font_monobold12.h
File diff suppressed because it is too large
View File


+ 8
- 1
test/font.c View File

@@ -33,6 +33,7 @@ int main(int argc, char *argv[])
struct cucul_font *f;
unsigned char *buf;
unsigned int x, y, w, h;
char const * const * fonts;

/* Create a canvas */
qq = cucul_create(8, 2);
@@ -43,7 +44,13 @@ int main(int argc, char *argv[])
cucul_putstr(qq, 0, 1, "&$âøÿ░▒█");

/* 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) */
w = cucul_get_width(qq) * cucul_get_font_width(f);


Loading…
Cancel
Save