source: libcaca/trunk/examples/font2tga.c @ 2101

Last change on this file since 2101 was 2101, checked in by Sam Hocevar, 12 years ago
  • Rename "test" to "examples". The former will become a real testsuite.
  • Autodetect zzuf in the configure step. It might become handy.
  • Property svn:keywords set to Id
File size: 2.1 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 2101 2007-11-30 23:48:39Z 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#include "config.h"
16#include "common.h"
17
18#if !defined(__KERNEL__)
19#   if defined(HAVE_INTTYPES_H)
20#      include <inttypes.h>
21#   endif
22#   include <stdio.h>
23#   include <stdlib.h>
24#endif
25
26#include "cucul.h"
27
28int main(int argc, char *argv[])
29{
30    unsigned long int const *blocks;
31    cucul_font_t *f;
32    char const * const * fonts;
33    cucul_canvas_t *cv;
34    void *buffer;
35    unsigned long int len;
36    unsigned int i, j, x, y, cells, width;
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, cells = 0; blocks[i + 1]; i += 2)
43    {
44        cells += blocks[i + 1] - blocks[i];
45        for(j = blocks[i]; j < blocks[i + 1]; j++)
46            if(cucul_utf32_is_fullwidth(j))
47                cells++;
48    }
49
50    for(width = 64; width * width < cells; width *= 2)
51        ;
52
53    /* Create a canvas */
54    cv = cucul_create_canvas(width, (cells + width - 1) / (width - 1));
55    cucul_set_color_ansi(cv, CUCUL_RED, CUCUL_RED);
56    cucul_clear_canvas(cv);
57    cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
58
59    /* Put all glyphs on the canvas */
60    x = y = 0;
61
62    for(i = 0; blocks[i + 1]; i += 2)
63    {
64        for(j = blocks[i]; j < blocks[i + 1]; j++)
65        {
66            cucul_put_char(cv, x, y, j);
67
68            if(cucul_utf32_is_fullwidth(j))
69                ++x;
70
71            if(++x >= width - 1)
72            {
73                x = 0;
74                y++;
75            }
76        }
77    }
78
79    cucul_free_font(f);
80
81    buffer = cucul_export_memory(cv, "tga", &len);
82    fwrite(buffer, len, 1, stdout);
83    free(buffer);
84
85    /* Free everything */
86    cucul_free_canvas(cv);
87
88    return 0;
89}
90
Note: See TracBrowser for help on using the repository browser.