Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

117 linhas
3.1 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. 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. #include "config.h"
  15. #include "common.h"
  16. #if !defined(__KERNEL__)
  17. # if defined(HAVE_INTTYPES_H)
  18. # include <inttypes.h>
  19. # endif
  20. # if defined(HAVE_ENDIAN_H)
  21. # include <endian.h>
  22. # endif
  23. # include <stdio.h>
  24. # include <stdlib.h>
  25. # include <string.h>
  26. #endif
  27. #include "cucul.h"
  28. #include "caca.h"
  29. int main(int argc, char *argv[])
  30. {
  31. cucul_canvas_t *cv;
  32. caca_display_t *dp;
  33. cucul_font_t *f;
  34. cucul_dither_t *d;
  35. unsigned char *buf;
  36. unsigned int w, h;
  37. char const * const * fonts;
  38. /* Create a canvas */
  39. cv = cucul_create_canvas(8, 2);
  40. if(cv == NULL)
  41. {
  42. printf("Can't create canvas\n");
  43. return -1;
  44. }
  45. /* Draw stuff on our canvas */
  46. cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
  47. cucul_put_str(cv, 0, 0, "ABcde");
  48. cucul_set_color_ansi(cv, CUCUL_LIGHTRED, CUCUL_BLACK);
  49. cucul_put_str(cv, 5, 0, "\\o/");
  50. cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
  51. cucul_put_str(cv, 0, 1, "&$âøÿØ?!");
  52. /* Load a libcucul internal font */
  53. fonts = cucul_get_font_list();
  54. if(fonts[0] == NULL)
  55. {
  56. fprintf(stderr, "error: libcucul was compiled without any fonts\n");
  57. return -1;
  58. }
  59. f = cucul_load_font(fonts[0], 0);
  60. if(f == NULL)
  61. {
  62. fprintf(stderr, "error: could not load font \"%s\"\n", fonts[0]);
  63. return -1;
  64. }
  65. /* Create our bitmap buffer (32-bit ARGB) */
  66. w = cucul_get_canvas_width(cv) * cucul_get_font_width(f);
  67. h = cucul_get_canvas_height(cv) * cucul_get_font_height(f);
  68. buf = malloc(4 * w * h);
  69. /* Render the canvas onto our image buffer */
  70. cucul_render_canvas(cv, f, buf, w, h, 4 * w);
  71. /* Just for fun, render the image using libcaca */
  72. cucul_set_canvas_size(cv, 80, 32);
  73. dp = caca_create_display(cv);
  74. #if defined(HAVE_ENDIAN_H)
  75. if(__BYTE_ORDER == __BIG_ENDIAN)
  76. #else
  77. /* This is compile-time optimised with at least -O1 or -Os */
  78. uint32_t const tmp = 0x12345678;
  79. if(*(uint8_t const *)&tmp == 0x12)
  80. #endif
  81. d = cucul_create_dither(32, w, h, 4 * w,
  82. 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
  83. else
  84. d = cucul_create_dither(32, w, h, 4 * w,
  85. 0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff);
  86. cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
  87. cucul_get_canvas_height(cv), d, buf);
  88. caca_refresh_display(dp);
  89. caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
  90. /* Free everything */
  91. caca_free_display(dp);
  92. free(buf);
  93. cucul_free_dither(d);
  94. cucul_free_font(f);
  95. cucul_free_canvas(cv);
  96. return 0;
  97. }