Ignore:
Timestamp:
Sep 30, 2006, 1:06:20 PM (15 years ago)
Author:
Sam Hocevar
Message:
  • Better error checking in the figlet renderer.
  • Allow to open fonts that have Unicode data (requires libcucul 0.99.beta6 which is not yet released).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • toilet/trunk/src/figlet.c

    r1113 r1143  
    2626#include <cucul.h>
    2727
     28#include "toilet.h"
    2829#include "figlet.h"
    2930
     
    4142};
    4243
    43 static struct figfont *open_font(char const *);
     44static struct figfont *open_font(void);
    4445static void free_font(struct figfont *);
    4546
    46 cucul_canvas_t *render_figlet(uint32_t const *string, unsigned int length,
    47                               char const *fontname)
     47cucul_canvas_t *render_figlet(uint32_t const *string, unsigned int length)
    4848{
    4949    cucul_canvas_t *cv;
     
    5151    unsigned int x, i, c;
    5252
    53     font = open_font(fontname);
     53    font = open_font();
     54
     55    if(!font)
     56        return NULL;
    5457
    5558    cv = cucul_create_canvas(length * font->max_length, font->height);
     
    7679}
    7780
    78 static struct figfont *open_font(char const *fontname)
     81static struct figfont *open_font(void)
    7982{
    8083    char *data = NULL;
     
    8588    unsigned int i, j, size, comment_lines;
    8689
    87     /* Open font */
    88     snprintf(path, 2047, "/usr/share/figlet/%s.flf", fontname);
     90    /* Open font: try .tlf, then .flf */
     91    snprintf(path, 2047, "%s/%s.tlf", toilet_dir, toilet_font);
    8992    path[2047] = '\0';
    9093    f = fopen(path, "r");
    9194    if(!f)
    9295    {
    93         fprintf(stderr, "font `%s' not found\n", path);
    94         return NULL;
     96        snprintf(path, 2047, "%s/%s.flf", toilet_dir, toilet_font);
     97        path[2047] = '\0';
     98        f = fopen(path, "r");
     99        if(!f)
     100        {
     101            fprintf(stderr, "font `%s' not found\n", path);
     102            return NULL;
     103        }
    95104    }
    96105
     
    101110    font->full_layout = 0;
    102111    font->codetag_count = 0;
    103     if(fscanf(f, "flf2a%c %u %u %u %i %u %u %u %u\n", &font->hardblank,
     112    if(fscanf(f, "%*[ft]lf2a%c %u %u %u %i %u %u %u %u\n", &font->hardblank,
    104113              &font->height, &font->baseline, &font->max_length,
    105114              &font->old_layout, &comment_lines, &font->print_direction,
     
    169178    /* Import buffer into canvas */
    170179    b = cucul_load_memory(data, i);
    171     font->image = cucul_import_canvas(b, "ansi");
     180    font->image = cucul_import_canvas(b, "utf8");
    172181    cucul_free_buffer(b);
    173182    free(data);
Note: See TracChangeset for help on using the changeset viewer.