Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

font.c 3.0 KiB

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