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 rivejä
1.8 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. cucul_buffer_t *buffer;
  31. unsigned int i, j, x, y, glyphs;
  32. fonts = cucul_get_font_list();
  33. f = cucul_load_font(fonts[0], 0);
  34. blocks = cucul_get_font_blocks(f);
  35. for(i = 0, glyphs = 0; blocks[i + 1]; i += 2)
  36. glyphs += blocks[i + 1] - blocks[i];
  37. /* Create a canvas */
  38. cv = cucul_create_canvas(WIDTH, (glyphs + WIDTH - 1) / WIDTH);
  39. cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
  40. /* Put all glyphs on the canvas */
  41. x = y = 0;
  42. for(i = 0; blocks[i + 1]; i += 2)
  43. {
  44. for(j = blocks[i]; j < blocks[i + 1]; j++)
  45. {
  46. cucul_putchar(cv, x, y, j);
  47. if(++x == WIDTH)
  48. {
  49. x = 0;
  50. y++;
  51. }
  52. }
  53. }
  54. cucul_free_font(f);
  55. buffer = cucul_export_canvas(cv, "tga");
  56. fwrite(cucul_get_buffer_data(buffer),
  57. cucul_get_buffer_size(buffer), 1, stdout);
  58. cucul_free_buffer(buffer);
  59. /* Free everything */
  60. cucul_free_canvas(cv);
  61. return 0;
  62. }