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 2304 2008-04-19 19:25:47Z 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 | |
---|
17 | #if !defined(__KERNEL__) |
---|
18 | # include <stdio.h> |
---|
19 | # include <stdlib.h> |
---|
20 | #endif |
---|
21 | |
---|
22 | #include "cucul.h" |
---|
23 | |
---|
24 | int main(int argc, char *argv[]) |
---|
25 | { |
---|
26 | uint32_t const *blocks; |
---|
27 | cucul_font_t *f; |
---|
28 | char const * const * fonts; |
---|
29 | cucul_canvas_t *cv; |
---|
30 | void *buffer; |
---|
31 | size_t len; |
---|
32 | unsigned int i, j, x, y, cells, width; |
---|
33 | |
---|
34 | fonts = cucul_get_font_list(); |
---|
35 | f = cucul_load_font(fonts[0], 0); |
---|
36 | blocks = cucul_get_font_blocks(f); |
---|
37 | |
---|
38 | for(i = 0, cells = 0; blocks[i + 1]; i += 2) |
---|
39 | { |
---|
40 | cells += blocks[i + 1] - blocks[i]; |
---|
41 | for(j = blocks[i]; j < blocks[i + 1]; j++) |
---|
42 | if(cucul_utf32_is_fullwidth(j)) |
---|
43 | cells++; |
---|
44 | } |
---|
45 | |
---|
46 | for(width = 64; width * width < cells; width *= 2) |
---|
47 | ; |
---|
48 | |
---|
49 | /* Create a canvas */ |
---|
50 | cv = cucul_create_canvas(width, (cells + width - 1) / (width - 1)); |
---|
51 | cucul_set_color_ansi(cv, CUCUL_RED, CUCUL_RED); |
---|
52 | cucul_clear_canvas(cv); |
---|
53 | cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE); |
---|
54 | |
---|
55 | /* Put all glyphs on the canvas */ |
---|
56 | x = y = 0; |
---|
57 | |
---|
58 | for(i = 0; blocks[i + 1]; i += 2) |
---|
59 | { |
---|
60 | for(j = blocks[i]; j < blocks[i + 1]; j++) |
---|
61 | { |
---|
62 | cucul_put_char(cv, x, y, j); |
---|
63 | |
---|
64 | if(cucul_utf32_is_fullwidth(j)) |
---|
65 | ++x; |
---|
66 | |
---|
67 | if(++x >= width - 1) |
---|
68 | { |
---|
69 | x = 0; |
---|
70 | y++; |
---|
71 | } |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | cucul_free_font(f); |
---|
76 | |
---|
77 | buffer = cucul_export_memory(cv, "tga", &len); |
---|
78 | fwrite(buffer, len, 1, stdout); |
---|
79 | free(buffer); |
---|
80 | |
---|
81 | /* Free everything */ |
---|
82 | cucul_free_canvas(cv); |
---|
83 | |
---|
84 | return 0; |
---|
85 | } |
---|
86 | |
---|