source: toilet/trunk/src/figlet.c @ 4138

Last change on this file since 4138 was 4138, checked in by Sam Hocevar, 12 years ago

Fix a crash with multiline input caused by losing the figfont information.

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1/*
2 *  TOIlet        The Other Implementation’s letters
3 *  Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
4 *                All Rights Reserved
5 *
6 *  $Id: figlet.c 4138 2009-12-16 19:20:26Z sam $
7 *
8 *  This program is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15/*
16 * This file contains functions for handling FIGlet fonts.
17 */
18
19#include "config.h"
20
21#if defined(HAVE_INTTYPES_H)
22#   include <inttypes.h>
23#endif
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <caca.h>
28
29#include "toilet.h"
30#include "render.h"
31
32#define STD_GLYPHS (127 - 32)
33#define EXT_GLYPHS (STD_GLYPHS + 7)
34
35static int feed_figlet(context_t *, uint32_t, uint32_t);
36static int flush_figlet(context_t *);
37static int end_figlet(context_t *);
38
39int init_figlet(context_t *cx)
40{
41    char path[2048];
42
43    snprintf(path, 2047, "%s/%s", cx->dir, cx->font);
44    if(caca_canvas_set_figfont(cx->cv, path))
45        return -1;
46
47    cx->feed = feed_figlet;
48    cx->flush = flush_figlet;
49    cx->end = end_figlet;
50
51    return 0;
52}
53
54static int feed_figlet(context_t *cx, uint32_t ch, uint32_t attr)
55{
56    return caca_put_figchar(cx->cv, ch);
57}
58
59static int flush_figlet(context_t *cx)
60{
61    /* We copy cx->cv into cx->torender instead of swapping pointers
62     * because that would lose the figfont information. */
63    /* FIXME: use caca_copy_canvas() or whatever when it's implemented. */
64    int ret = caca_flush_figlet(cx->cv);
65    cx->torender = caca_create_canvas(caca_get_canvas_width(cx->cv),
66                                      caca_get_canvas_height(cx->cv));
67    caca_blit(cx->torender, 0, 0, cx->cv, NULL);
68    caca_set_canvas_size(cx->cv, 0, 0);
69    return ret;
70}
71
72static int end_figlet(context_t *cx)
73{
74    return caca_canvas_set_figfont(cx->cv, NULL);
75}
76
Note: See TracBrowser for help on using the repository browser.