1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
/*
* font libcucul font test program
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id: font.c 1026 2006-11-11 16:29:39Z sam $
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Do What The Fuck You Want To
* Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/
#include "config.h"
#include "common.h"
#if !defined(__KERNEL__)
# if defined(HAVE_INTTYPES_H)
# include <inttypes.h>
# endif
# if defined(HAVE_ENDIAN_H)
# include <endian.h>
# endif
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
#endif
#include "cucul.h"
#include "caca.h"
int main(int argc, char *argv[])
{
cucul_canvas_t *cv;
caca_display_t *dp;
cucul_font_t *f;
cucul_dither_t *d;
unsigned char *buf;
unsigned int w, h;
char const * const * fonts;
/* Create a canvas */
cv = cucul_create_canvas(8, 2);
/* Draw stuff on our canvas */
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
cucul_put_str(cv, 0, 0, "ABcde");
cucul_set_color_ansi(cv, CUCUL_LIGHTRED, CUCUL_BLACK);
cucul_put_str(cv, 5, 0, "\\o/");
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
cucul_put_str(cv, 0, 1, "&$âøÿØ?!");
/* Load a libcucul internal font */
fonts = cucul_get_font_list();
if(fonts[0] == NULL)
{
fprintf(stderr, "error: libcucul was compiled without any fonts\n");
return -1;
}
f = cucul_load_font(fonts[0], 0);
if(f == NULL)
{
fprintf(stderr, "error: could not load font \"%s\"\n", fonts[0]);
return -1;
}
/* Create our bitmap buffer (32-bit ARGB) */
w = cucul_get_canvas_width(cv) * cucul_get_font_width(f);
h = cucul_get_canvas_height(cv) * cucul_get_font_height(f);
buf = malloc(4 * w * h);
/* Render the canvas onto our image buffer */
cucul_render_canvas(cv, f, buf, w, h, 4 * w);
/* Just for fun, render the image using libcaca */
cucul_set_canvas_size(cv, 80, 32);
dp = caca_create_display(cv);
#if defined(HAVE_ENDIAN_H)
if(__BYTE_ORDER == __BIG_ENDIAN)
#else
/* This is compile-time optimised with at least -O1 or -Os */
uint32_t const tmp = 0x12345678;
if(*(uint8_t const *)&tmp == 0x12)
#endif
d = cucul_create_dither(32, w, h, 4 * w,
0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
else
d = cucul_create_dither(32, w, h, 4 * w,
0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff);
cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
cucul_get_canvas_height(cv), d, buf);
caca_refresh_display(dp);
caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
/* Free everything */
caca_free_display(dp);
free(buf);
cucul_free_dither(d);
cucul_free_font(f);
cucul_free_canvas(cv);
return 0;
}
|