Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

85 righe
2.0 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. char const * const * fonts;
  32. /* Create a canvas */
  33. qq = cucul_create(8, 2);
  34. /* Draw stuff on our canvas */
  35. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
  36. cucul_putstr(qq, 0, 0, "ABcde\\o/");
  37. cucul_putstr(qq, 0, 1, "&$âøÿ░▒█");
  38. /* Load a libcucul internal font */
  39. fonts = cucul_get_font_list();
  40. if(fonts[0] == NULL)
  41. {
  42. fprintf(stderr, "error: libcucul was compiled without any fonts\n");
  43. return -1;
  44. }
  45. f = cucul_load_font(fonts[0], 0);
  46. /* Create our bitmap buffer (32-bit ARGB) */
  47. w = cucul_get_width(qq) * cucul_get_font_width(f);
  48. h = cucul_get_height(qq) * cucul_get_font_height(f);
  49. buf = malloc(4 * w * h);
  50. /* Render the canvas onto our image buffer */
  51. cucul_render_canvas(qq, f, buf, w, h, 4 * w);
  52. /* Just for fun, output the image on the terminal using ASCII art */
  53. for(y = 0; y < h; y++)
  54. {
  55. for(x = 0; x < w; x++)
  56. {
  57. static const char list[] = {
  58. ' ', '.', ':', 't', 'S', 'R', '#', '@'
  59. };
  60. printf("%c", list[buf[4 * (y * w + x) + 3] / 0x20]);
  61. }
  62. printf("\n");
  63. }
  64. /* Free everything */
  65. free(buf);
  66. cucul_free_font(f);
  67. cucul_free(qq);
  68. return 0;
  69. }