Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

85 Zeilen
2.0 KiB

  1. /*
  2. * font2tga libcaca font test program
  3. * Copyright (c) 2006-2012 Sam Hocevar <sam@hocevar.net>
  4. * All Rights Reserved
  5. *
  6. * This program is free software. It comes without any warranty, to
  7. * the extent permitted by applicable law. You can redistribute it
  8. * and/or modify it under the terms of the Do What the Fuck You Want
  9. * to Public License, Version 2, as published by Sam Hocevar. See
  10. * http://www.wtfpl.net/ for more details.
  11. */
  12. #include "config.h"
  13. #if !defined(__KERNEL__)
  14. # include <stdio.h>
  15. # include <stdlib.h>
  16. #endif
  17. #include "caca.h"
  18. int main(int argc, char *argv[])
  19. {
  20. uint32_t const *blocks;
  21. caca_font_t *f;
  22. char const * const * fonts;
  23. caca_canvas_t *cv;
  24. void *buffer;
  25. size_t len;
  26. unsigned int i, j, x, y, cells, width;
  27. fonts = caca_get_font_list();
  28. f = caca_load_font(fonts[0], 0);
  29. blocks = caca_get_font_blocks(f);
  30. for(i = 0, cells = 0; blocks[i + 1]; i += 2)
  31. {
  32. cells += blocks[i + 1] - blocks[i];
  33. for(j = blocks[i]; j < blocks[i + 1]; j++)
  34. if(caca_utf32_is_fullwidth(j))
  35. cells++;
  36. }
  37. for(width = 64; width * width < cells; width *= 2)
  38. ;
  39. /* Create a canvas */
  40. cv = caca_create_canvas(width, (cells + width - 1) / (width - 1));
  41. caca_set_color_ansi(cv, CACA_RED, CACA_RED);
  42. caca_clear_canvas(cv);
  43. caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE);
  44. /* Put all glyphs on the canvas */
  45. x = y = 0;
  46. for(i = 0; blocks[i + 1]; i += 2)
  47. {
  48. for(j = blocks[i]; j < blocks[i + 1]; j++)
  49. {
  50. caca_put_char(cv, x, y, j);
  51. if(caca_utf32_is_fullwidth(j))
  52. ++x;
  53. if(++x >= width - 1)
  54. {
  55. x = 0;
  56. y++;
  57. }
  58. }
  59. }
  60. caca_free_font(f);
  61. buffer = caca_export_canvas_to_memory(cv, "tga", &len);
  62. fwrite(buffer, len, 1, stdout);
  63. free(buffer);
  64. /* Free everything */
  65. caca_free_canvas(cv);
  66. return 0;
  67. }