Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

font2tga.c 2.0 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. int main(int argc, char *argv[])
  24. {
  25. unsigned long int const *blocks;
  26. cucul_font_t *f;
  27. char const * const * fonts;
  28. cucul_canvas_t *cv;
  29. void *buffer;
  30. unsigned long int len;
  31. unsigned int i, j, x, y, cells, width;
  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, cells = 0; blocks[i + 1]; i += 2)
  36. {
  37. cells += blocks[i + 1] - blocks[i];
  38. for(j = blocks[i]; j < blocks[i + 1]; j++)
  39. if(cucul_utf32_is_fullwidth(j))
  40. cells++;
  41. }
  42. for(width = 64; width * width < cells; width *= 2)
  43. ;
  44. /* Create a canvas */
  45. cv = cucul_create_canvas(width, (cells + width - 1) / (width - 1));
  46. cucul_set_color_ansi(cv, CUCUL_RED, CUCUL_RED);
  47. cucul_clear_canvas(cv);
  48. cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
  49. /* Put all glyphs on the canvas */
  50. x = y = 0;
  51. for(i = 0; blocks[i + 1]; i += 2)
  52. {
  53. for(j = blocks[i]; j < blocks[i + 1]; j++)
  54. {
  55. cucul_put_char(cv, x, y, j);
  56. if(cucul_utf32_is_fullwidth(j))
  57. ++x;
  58. if(++x >= width - 1)
  59. {
  60. x = 0;
  61. y++;
  62. }
  63. }
  64. }
  65. cucul_free_font(f);
  66. buffer = cucul_export_memory(cv, "tga", &len);
  67. fwrite(buffer, len, 1, stdout);
  68. free(buffer);
  69. /* Free everything */
  70. cucul_free_canvas(cv);
  71. return 0;
  72. }