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

Last change on this file since 1361 was 1361, checked in by Sam Hocevar, 14 years ago
  • Add CJK punctuation to the default fonts.
  • Minor changes to the font2tga test program.
  • Property svn:keywords set to Id
File size: 2.0 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 1361 2006-11-12 14:42:58Z 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
27int main(int argc, char *argv[])
28{
29    unsigned long int const *blocks;
30    cucul_font_t *f;
31    char const * const * fonts;
32    cucul_canvas_t *cv;
33    void *buffer;
34    unsigned long int len;
35    unsigned int i, j, x, y, cells, width;
36
37    fonts = cucul_get_font_list();
38    f = cucul_load_font(fonts[0], 0);
39    blocks = cucul_get_font_blocks(f);
40
41    for(i = 0, cells = 0; blocks[i + 1]; i += 2)
42    {
43        cells += blocks[i + 1] - blocks[i];
44        for(j = blocks[i]; j < blocks[i + 1]; j++)
45            if(cucul_utf32_is_fullwidth(j))
46                cells++;
47    }
48
49    for(width = 64; width * width < cells; width *= 2)
50        ;
51
52    /* Create a canvas */
53    cv = cucul_create_canvas(width, (cells + width - 1) / (width - 1));
54    cucul_set_color_ansi(cv, CUCUL_RED, CUCUL_RED);
55    cucul_clear_canvas(cv);
56    cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
57
58    /* Put all glyphs on the canvas */
59    x = y = 0;
60
61    for(i = 0; blocks[i + 1]; i += 2)
62    {
63        for(j = blocks[i]; j < blocks[i + 1]; j++)
64        {
65            cucul_put_char(cv, x, y, j);
66
67            if(cucul_utf32_is_fullwidth(j))
68                ++x;
69
70            if(++x >= width - 1)
71            {
72                x = 0;
73                y++;
74            }
75        }
76    }
77
78    cucul_free_font(f);
79
80    buffer = cucul_export_memory(cv, "tga", &len);
81    fwrite(buffer, len, 1, stdout);
82    free(buffer);
83
84    /* Free everything */
85    cucul_free_canvas(cv);
86
87    return 0;
88}
89
Note: See TracBrowser for help on using the repository browser.