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

Last change on this file since 1308 was 1308, checked in by Sam Hocevar, 16 years ago
  • Convert all programs and tests to the new import/export API.
  • Property svn:keywords set to Id
File size: 1.7 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 1308 2006-11-08 17:26:57Z 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    void *buffer;
36    unsigned long int len;
37    unsigned int i, j, x, y, glyphs;
38
39    fonts = cucul_get_font_list();
40    f = cucul_load_font(fonts[0], 0);
41    blocks = cucul_get_font_blocks(f);
42
43    for(i = 0, glyphs = 0; blocks[i + 1]; i += 2)
44        glyphs += blocks[i + 1] - blocks[i];
45
46    /* Create a canvas */
47    cv = cucul_create_canvas(WIDTH, (glyphs + WIDTH - 1) / WIDTH);
48    cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
49
50    /* Put all glyphs on the canvas */
51    x = y = 0;
52
53    for(i = 0; blocks[i + 1]; i += 2)
54    {
55        for(j = blocks[i]; j < blocks[i + 1]; j++)
56        {
57            cucul_putchar(cv, x, y, j);
58
59            if(++x == WIDTH)
60            {
61                x = 0;
62                y++;
63            }
64        }
65    }
66
67    cucul_free_font(f);
68
69    buffer = cucul_export_memory(cv, "tga", &len);
70    fwrite(buffer, len, 1, stdout);
71    free(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.