source: libcaca/trunk/test/font2tga.c @ 1294

Last change on this file since 1294 was 1294, checked in by Sam Hocevar, 14 years ago
  • Use cucul_get_font_blocks() instead of hardcoding the glyph list.
  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1/*
2 *  font2tga      libcucul font test program
3 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: font2tga.c 1294 2006-11-06 11:04:37Z sam $
7 *
8 *  This program is free software; you can redistribute it and/or
9 *  modify it under the terms of the Do What The Fuck You Want To
10 *  Public License, Version 2, as published by Sam Hocevar. See
11 *  http://sam.zoy.org/wtfpl/COPYING for more details.
12 */
13
14#include "config.h"
15#include "common.h"
16
17#if !defined(__KERNEL__)
18#   if defined(HAVE_INTTYPES_H)
19#      include <inttypes.h>
20#   endif
21#   include <stdio.h>
22#   include <stdlib.h>
23#endif
24
25#include "cucul.h"
26
27#define WIDTH 64
28
29int main(int argc, char *argv[])
30{
31    unsigned long int const *blocks;
32    cucul_font_t *f;
33    char const * const * fonts;
34    cucul_canvas_t *cv;
35    cucul_buffer_t *buffer;
36    unsigned int i, j, x, y, glyphs;
37
38    fonts = cucul_get_font_list();
39    f = cucul_load_font(fonts[0], 0);
40    blocks = cucul_get_font_blocks(f);
41
42    for(i = 0, glyphs = 0; blocks[i + 1]; i += 2)
43        glyphs += blocks[i + 1] - blocks[i];
44
45    /* Create a canvas */
46    cv = cucul_create_canvas(WIDTH, (glyphs + WIDTH - 1) / WIDTH);
47    cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
48
49    /* Put all glyphs on the canvas */
50    x = y = 0;
51
52    for(i = 0; blocks[i + 1]; i += 2)
53    {
54        for(j = blocks[i]; j < blocks[i + 1]; j++)
55        {
56            cucul_putchar(cv, x, y, j);
57
58            if(++x == WIDTH)
59            {
60                x = 0;
61                y++;
62            }
63        }
64    }
65
66    cucul_free_font(f);
67
68    buffer = cucul_export_canvas(cv, "tga");
69    fwrite(cucul_get_buffer_data(buffer),
70           cucul_get_buffer_size(buffer), 1, stdout);
71    cucul_free_buffer(buffer);
72
73    /* Free everything */
74    cucul_free_canvas(cv);
75
76    return 0;
77}
78
Note: See TracBrowser for help on using the repository browser.