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

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