[1101] | 1 | /* |
---|
| 2 | * TOIlet The Other Implementation’s letters |
---|
| 3 | * Copyright (c) 2006 Sam Hocevar <sam@zoy.org> |
---|
| 4 | * All Rights Reserved |
---|
| 5 | * |
---|
| 6 | * $Id: figlet.c 2988 2008-10-18 21:36:17Z sam $ |
---|
| 7 | * |
---|
[1461] | 8 | * This program is free software. It comes without any warranty, to |
---|
[1451] | 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 |
---|
[1101] | 12 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
| 13 | */ |
---|
| 14 | |
---|
[1102] | 15 | /* |
---|
| 16 | * This file contains functions for handling FIGlet fonts. |
---|
| 17 | */ |
---|
| 18 | |
---|
[1101] | 19 | #include "config.h" |
---|
| 20 | |
---|
| 21 | #if defined(HAVE_INTTYPES_H) |
---|
| 22 | # include <inttypes.h> |
---|
| 23 | #endif |
---|
[1106] | 24 | #include <stdio.h> |
---|
| 25 | #include <stdlib.h> |
---|
| 26 | #include <string.h> |
---|
[2988] | 27 | #include <caca.h> |
---|
[1101] | 28 | |
---|
[1143] | 29 | #include "toilet.h" |
---|
[1241] | 30 | #include "render.h" |
---|
[1101] | 31 | |
---|
[1150] | 32 | #define STD_GLYPHS (127 - 32) |
---|
| 33 | #define EXT_GLYPHS (STD_GLYPHS + 7) |
---|
| 34 | |
---|
[1385] | 35 | static int feed_figlet(context_t *, uint32_t, uint32_t); |
---|
[1241] | 36 | static int flush_figlet(context_t *); |
---|
[1196] | 37 | static int end_figlet(context_t *); |
---|
| 38 | |
---|
| 39 | int init_figlet(context_t *cx) |
---|
[1106] | 40 | { |
---|
[2414] | 41 | char path[2048]; |
---|
| 42 | |
---|
| 43 | snprintf(path, 2047, "%s/%s", cx->dir, cx->font); |
---|
[2988] | 44 | if(caca_canvas_set_figfont(cx->cv, path)) |
---|
[1196] | 45 | return -1; |
---|
[1106] | 46 | |
---|
[1196] | 47 | cx->feed = feed_figlet; |
---|
[1241] | 48 | cx->flush = flush_figlet; |
---|
[1196] | 49 | cx->end = end_figlet; |
---|
[1106] | 50 | |
---|
[1196] | 51 | return 0; |
---|
| 52 | } |
---|
| 53 | |
---|
[1385] | 54 | static int feed_figlet(context_t *cx, uint32_t ch, uint32_t attr) |
---|
[1101] | 55 | { |
---|
[2988] | 56 | return caca_put_figchar(cx->cv, ch); |
---|
[1196] | 57 | } |
---|
[1106] | 58 | |
---|
[1241] | 59 | static int flush_figlet(context_t *cx) |
---|
| 60 | { |
---|
[2988] | 61 | int ret = caca_flush_figlet(cx->cv); |
---|
[2419] | 62 | cx->torender = cx->cv; |
---|
[2988] | 63 | cx->cv = caca_create_canvas(0, 0); |
---|
[2419] | 64 | return ret; |
---|
[1241] | 65 | } |
---|
| 66 | |
---|
[1196] | 67 | static int end_figlet(context_t *cx) |
---|
| 68 | { |
---|
[2988] | 69 | return caca_canvas_set_figfont(cx->cv, NULL); |
---|
[1101] | 70 | } |
---|
| 71 | |
---|