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

Last change on this file since 1267 was 1267, checked in by Sam Hocevar, 14 years ago
  • Got rid of cucul_ansi_to_attr() and cucul_argb_to_attr() and restored cucul_set_color() and cucul_set_truecolor() under the new names cucul_set_color_ansi() and cucul_set_color_argb().
  • Renamed cucul_get_color_name() into cucul_ansi_to_str().
  • Property svn:keywords set to Id
File size: 2.4 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 1267 2006-10-31 13:29:48Z 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
29/* Copied from makefont.c */
30static unsigned int const blocklist[] =
31{
32    0x0000, 0x0080, /* Basic latin: A, B, C, a, b, c */
33    0x0080, 0x0100, /* Latin-1 Supplement: Ä, Ç, å, ß */
34    0x0100, 0x0180, /* Latin Extended-A: Ā č Ō œ */
35    0x0180, 0x0250, /* Latin Extended-B: Ǝ Ƹ */
36    0x0250, 0x02b0, /* IPA Extensions: ɐ ɔ ɘ ʌ ʍ */
37    0x0370, 0x0400, /* Greek and Coptic: Λ α β */
38    0x0400, 0x0500, /* Cyrillic: И Я */
39    0x0530, 0x0590, /* Armenian: Ո */
40    0x1d00, 0x1d80, /* Phonetic Extensions: ᴉ ᵷ */
41    0x2000, 0x2070, /* General Punctuation: ‘’ “” */
42    0x2100, 0x2150, /* Letterlike Symbols: Ⅎ */
43    0x2200, 0x2300, /* Mathematical Operators: √ ∞ ∙ */
44    0x2300, 0x2400, /* Miscellaneous Technical: ⌐ ⌂ ⌠ ⌡ */
45    0x2500, 0x2580, /* Box Drawing: ═ ║ ╗ ╔ ╩ */
46    0x2580, 0x25a0, /* Block Elements: ▛ ▞ ░ ▒ ▓ */
47    0, 0
48};
49
50int main(int argc, char *argv[])
51{
52    cucul_canvas_t *cv;
53    cucul_buffer_t *buffer;
54    unsigned int i, j, x, y, glyphs;
55
56    for(i = 0, glyphs = 0; blocklist[i + 1]; i += 2)
57        glyphs += blocklist[i + 1] - blocklist[i];
58
59    /* Create a canvas */
60    cv = cucul_create_canvas(WIDTH, (glyphs + WIDTH - 1) / WIDTH);
61    cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
62
63    /* Put all glyphs on the canvas */
64    x = y = 0;
65
66    for(i = 0; blocklist[i + 1]; i += 2)
67    {
68        for(j = blocklist[i]; j < blocklist[i + 1]; j++)
69        {
70            cucul_putchar(cv, x, y, j);
71
72            if(++x == WIDTH)
73            {
74                x = 0;
75                y++;
76            }
77        }
78    }
79
80    buffer = cucul_export_canvas(cv, "tga");
81    fwrite(cucul_get_buffer_data(buffer),
82           cucul_get_buffer_size(buffer), 1, stdout);
83    cucul_free_buffer(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.