You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

78 lines
1.8 KiB

  1. /*
  2. * font libcucul font test program
  3. * Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  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. #include "config.h"
  14. #if defined(HAVE_INTTYPES_H)
  15. # include <inttypes.h>
  16. #else
  17. typedef unsigned char uint8_t;
  18. typedef unsigned short uint16_t;
  19. typedef unsigned int uint32_t;
  20. #endif
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include "cucul.h"
  25. int main(int argc, char *argv[])
  26. {
  27. cucul_t *qq;
  28. struct cucul_font *f;
  29. unsigned char *buf;
  30. unsigned int x, y, w, h;
  31. /* Create a canvas */
  32. qq = cucul_create(8, 2);
  33. /* Draw stuff on our canvas */
  34. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
  35. cucul_putstr(qq, 0, 0, "ABcde\\o/");
  36. cucul_putstr(qq, 0, 1, "&$âøÿ░▒█");
  37. /* Load a libcucul internal font */
  38. f = cucul_load_font("Monospace 9", 0);
  39. /* Create our bitmap buffer (32-bit ARGB) */
  40. w = cucul_get_width(qq) * cucul_get_font_width(f);
  41. h = cucul_get_height(qq) * cucul_get_font_height(f);
  42. buf = malloc(4 * w * h);
  43. /* Render the canvas onto our image buffer */
  44. cucul_render_canvas(qq, f, buf, w, h, 4 * w);
  45. /* Just for fun, output the image on the terminal using ASCII art */
  46. for(y = 0; y < h; y++)
  47. {
  48. for(x = 0; x < w; x++)
  49. {
  50. static const char list[] = {
  51. ' ', '.', ':', 't', 'S', 'R', '#', '@'
  52. };
  53. printf("%c", list[buf[4 * (y * w + x) + 3] / 0x20]);
  54. }
  55. printf("\n");
  56. }
  57. /* Free everything */
  58. free(buf);
  59. cucul_free_font(f);
  60. cucul_free(qq);
  61. return 0;
  62. }