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.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #include "common.h"
  16. #if !defined(__KERNEL__)
  17. # if defined(HAVE_INTTYPES_H)
  18. # include <inttypes.h>
  19. # endif
  20. # include <stdio.h>
  21. # include <stdlib.h>
  22. #endif
  23. #include "cucul.h"
  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, cells, width;
  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, cells = 0; blocks[i + 1]; i += 2)
  37. {
  38. cells += blocks[i + 1] - blocks[i];
  39. for(j = blocks[i]; j < blocks[i + 1]; j++)
  40. if(cucul_utf32_is_fullwidth(j))
  41. cells++;
  42. }
  43. for(width = 64; width * width < cells; width *= 2)
  44. ;
  45. /* Create a canvas */
  46. cv = cucul_create_canvas(width, (cells + width - 1) / (width - 1));
  47. cucul_set_color_ansi(cv, CUCUL_RED, CUCUL_RED);
  48. cucul_clear_canvas(cv);
  49. cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
  50. /* Put all glyphs on the canvas */
  51. x = y = 0;
  52. for(i = 0; blocks[i + 1]; i += 2)
  53. {
  54. for(j = blocks[i]; j < blocks[i + 1]; j++)
  55. {
  56. cucul_put_char(cv, x, y, j);
  57. if(cucul_utf32_is_fullwidth(j))
  58. ++x;
  59. if(++x >= width - 1)
  60. {
  61. x = 0;
  62. y++;
  63. }
  64. }
  65. }
  66. cucul_free_font(f);
  67. buffer = cucul_export_memory(cv, "tga", &len);
  68. fwrite(buffer, len, 1, stdout);
  69. free(buffer);
  70. /* Free everything */
  71. cucul_free_canvas(cv);
  72. return 0;
  73. }