Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

font2tga.c 2.0 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. 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 "cucul.h"
  20. int main(int argc, char *argv[])
  21. {
  22. unsigned long int const *blocks;
  23. cucul_font_t *f;
  24. char const * const * fonts;
  25. cucul_canvas_t *cv;
  26. void *buffer;
  27. unsigned long int len;
  28. unsigned int i, j, x, y, cells, width;
  29. fonts = cucul_get_font_list();
  30. f = cucul_load_font(fonts[0], 0);
  31. blocks = cucul_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(cucul_utf32_is_fullwidth(j))
  37. cells++;
  38. }
  39. for(width = 64; width * width < cells; width *= 2)
  40. ;
  41. /* Create a canvas */
  42. cv = cucul_create_canvas(width, (cells + width - 1) / (width - 1));
  43. cucul_set_color_ansi(cv, CUCUL_RED, CUCUL_RED);
  44. cucul_clear_canvas(cv);
  45. cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_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. cucul_put_char(cv, x, y, j);
  53. if(cucul_utf32_is_fullwidth(j))
  54. ++x;
  55. if(++x >= width - 1)
  56. {
  57. x = 0;
  58. y++;
  59. }
  60. }
  61. }
  62. cucul_free_font(f);
  63. buffer = cucul_export_memory(cv, "tga", &len);
  64. fwrite(buffer, len, 1, stdout);
  65. free(buffer);
  66. /* Free everything */
  67. cucul_free_canvas(cv);
  68. return 0;
  69. }