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.
 
 
 
 
 
 

79 lines
1.7 KiB

  1. /*
  2. * font2tga 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. #include "common.h"
  15. #if !defined(__KERNEL__)
  16. # if defined(HAVE_INTTYPES_H)
  17. # include <inttypes.h>
  18. # endif
  19. # include <stdio.h>
  20. # include <stdlib.h>
  21. #endif
  22. #include "cucul.h"
  23. #define WIDTH 64
  24. int main(int argc, char *argv[])
  25. {
  26. unsigned long int const *blocks;
  27. cucul_font_t *f;
  28. char const * const * fonts;
  29. cucul_canvas_t *cv;
  30. void *buffer;
  31. unsigned long int len;
  32. unsigned int i, j, x, y, glyphs;
  33. fonts = cucul_get_font_list();
  34. f = cucul_load_font(fonts[0], 0);
  35. blocks = cucul_get_font_blocks(f);
  36. for(i = 0, glyphs = 0; blocks[i + 1]; i += 2)
  37. glyphs += blocks[i + 1] - blocks[i];
  38. /* Create a canvas */
  39. cv = cucul_create_canvas(WIDTH, (glyphs + WIDTH - 1) / WIDTH);
  40. cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
  41. /* Put all glyphs on the canvas */
  42. x = y = 0;
  43. for(i = 0; blocks[i + 1]; i += 2)
  44. {
  45. for(j = blocks[i]; j < blocks[i + 1]; j++)
  46. {
  47. cucul_put_char(cv, x, y, j);
  48. if(++x == WIDTH)
  49. {
  50. x = 0;
  51. y++;
  52. }
  53. }
  54. }
  55. cucul_free_font(f);
  56. buffer = cucul_export_memory(cv, "tga", &len);
  57. fwrite(buffer, len, 1, stdout);
  58. free(buffer);
  59. /* Free everything */
  60. cucul_free_canvas(cv);
  61. return 0;
  62. }