Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

89 rindas
2.0 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, cells;
  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. /* Create a canvas */
  44. cv = cucul_create_canvas(WIDTH, (cells + WIDTH - 1) / (WIDTH - 1));
  45. cucul_set_color_ansi(cv, CUCUL_RED, CUCUL_RED);
  46. cucul_clear_canvas(cv);
  47. cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
  48. /* Put all glyphs on the canvas */
  49. x = y = 0;
  50. for(i = 0; blocks[i + 1]; i += 2)
  51. {
  52. for(j = blocks[i]; j < blocks[i + 1]; j++)
  53. {
  54. cucul_put_char(cv, x, y, j);
  55. if(cucul_utf32_is_fullwidth(j))
  56. ++x;
  57. if(++x >= WIDTH - 1)
  58. {
  59. x = 0;
  60. y++;
  61. }
  62. }
  63. }
  64. cucul_free_font(f);
  65. buffer = cucul_export_memory(cv, "tga", &len);
  66. fwrite(buffer, len, 1, stdout);
  67. free(buffer);
  68. /* Free everything */
  69. cucul_free_canvas(cv);
  70. return 0;
  71. }