Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

119 рядки
3.1 KiB

  1. /*
  2. * font 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. # if defined(HAVE_ENDIAN_H)
  21. # include <endian.h>
  22. # endif
  23. # include <stdio.h>
  24. # include <stdlib.h>
  25. # include <string.h>
  26. #endif
  27. #include "cucul.h"
  28. #include "caca.h"
  29. int main(int argc, char *argv[])
  30. {
  31. cucul_canvas_t *cv;
  32. caca_display_t *dp;
  33. cucul_font_t *f;
  34. cucul_dither_t *d;
  35. unsigned char *buf;
  36. unsigned int w, h;
  37. char const * const * fonts;
  38. /* Create a canvas */
  39. cv = cucul_create_canvas(8, 2);
  40. if(cv == NULL)
  41. {
  42. printf("Can't create canvas\n");
  43. return -1;
  44. }
  45. /* Draw stuff on our canvas */
  46. cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
  47. cucul_put_str(cv, 0, 0, "ABcde");
  48. cucul_set_color_ansi(cv, CUCUL_LIGHTRED, CUCUL_BLACK);
  49. cucul_put_str(cv, 5, 0, "\\o/");
  50. cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
  51. cucul_put_str(cv, 0, 1, "&$âøÿØ?!");
  52. /* Load a libcucul internal font */
  53. fonts = cucul_get_font_list();
  54. if(fonts[0] == NULL)
  55. {
  56. fprintf(stderr, "error: libcucul was compiled without any fonts\n");
  57. return -1;
  58. }
  59. f = cucul_load_font(fonts[0], 0);
  60. if(f == NULL)
  61. {
  62. fprintf(stderr, "error: could not load font \"%s\"\n", fonts[0]);
  63. return -1;
  64. }
  65. /* Create our bitmap buffer (32-bit ARGB) */
  66. w = cucul_get_canvas_width(cv) * cucul_get_font_width(f);
  67. h = cucul_get_canvas_height(cv) * cucul_get_font_height(f);
  68. buf = malloc(4 * w * h);
  69. /* Render the canvas onto our image buffer */
  70. cucul_render_canvas(cv, f, buf, w, h, 4 * w);
  71. /* Just for fun, render the image using libcaca */
  72. cucul_set_canvas_size(cv, 80, 32);
  73. dp = caca_create_display(cv);
  74. {
  75. #if defined(HAVE_ENDIAN_H)
  76. if(__BYTE_ORDER == __BIG_ENDIAN)
  77. #else
  78. /* This is compile-time optimised with at least -O1 or -Os */
  79. uint32_t const tmp = 0x12345678;
  80. if(*(uint8_t const *)&tmp == 0x12)
  81. #endif
  82. d = cucul_create_dither(32, w, h, 4 * w,
  83. 0xff0000, 0xff00, 0xff, 0xff000000);
  84. else
  85. d = cucul_create_dither(32, w, h, 4 * w,
  86. 0xff00, 0xff0000, 0xff000000, 0xff);
  87. }
  88. cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
  89. cucul_get_canvas_height(cv), d, buf);
  90. caca_refresh_display(dp);
  91. caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
  92. /* Free everything */
  93. caca_free_display(dp);
  94. free(buf);
  95. cucul_free_dither(d);
  96. cucul_free_font(f);
  97. cucul_free_canvas(cv);
  98. return 0;
  99. }