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.
 
 
 
 
 
 

87 lines
2.0 KiB

  1. /*
  2. * font2tga libcaca font test program
  3. * Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
  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. #if !defined(__KERNEL__)
  16. # include <stdio.h>
  17. # include <stdlib.h>
  18. #endif
  19. #include "caca.h"
  20. int main(int argc, char *argv[])
  21. {
  22. uint32_t const *blocks;
  23. caca_font_t *f;
  24. char const * const * fonts;
  25. caca_canvas_t *cv;
  26. void *buffer;
  27. size_t len;
  28. unsigned int i, j, x, y, cells, width;
  29. fonts = caca_get_font_list();
  30. f = caca_load_font(fonts[0], 0);
  31. blocks = caca_get_font_blocks(f);
  32. for(i = 0, cells = 0; blocks[i + 1]; i += 2)
  33. {
  34. cells += blocks[i + 1] - blocks[i];
  35. for(j = blocks[i]; j < blocks[i + 1]; j++)
  36. if(caca_utf32_is_fullwidth(j))
  37. cells++;
  38. }
  39. for(width = 64; width * width < cells; width *= 2)
  40. ;
  41. /* Create a canvas */
  42. cv = caca_create_canvas(width, (cells + width - 1) / (width - 1));
  43. caca_set_color_ansi(cv, CACA_RED, CACA_RED);
  44. caca_clear_canvas(cv);
  45. caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE);
  46. /* Put all glyphs on the canvas */
  47. x = y = 0;
  48. for(i = 0; blocks[i + 1]; i += 2)
  49. {
  50. for(j = blocks[i]; j < blocks[i + 1]; j++)
  51. {
  52. caca_put_char(cv, x, y, j);
  53. if(caca_utf32_is_fullwidth(j))
  54. ++x;
  55. if(++x >= width - 1)
  56. {
  57. x = 0;
  58. y++;
  59. }
  60. }
  61. }
  62. caca_free_font(f);
  63. buffer = caca_export_canvas_to_memory(cv, "tga", &len);
  64. fwrite(buffer, len, 1, stdout);
  65. free(buffer);
  66. /* Free everything */
  67. caca_free_canvas(cv);
  68. return 0;
  69. }