You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

112 lines
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. #if defined(HAVE_INTTYPES_H)
  15. # include <inttypes.h>
  16. #else
  17. typedef unsigned char uint8_t;
  18. typedef unsigned short uint16_t;
  19. typedef unsigned int uint32_t;
  20. #endif
  21. #if defined(HAVE_ENDIAN_H)
  22. # include <endian.h>
  23. #endif
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include "cucul.h"
  28. #include "caca.h"
  29. int main(int argc, char *argv[])
  30. {
  31. cucul_t *qq;
  32. caca_t *kk;
  33. cucul_font_t *f;
  34. cucul_dither_t *d;
  35. caca_event_t ev;
  36. unsigned char *buf;
  37. unsigned int w, h;
  38. char const * const * fonts;
  39. /* Create a canvas */
  40. qq = cucul_create(8, 2);
  41. /* Draw stuff on our canvas */
  42. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
  43. cucul_putstr(qq, 0, 0, "ABcde");
  44. cucul_set_color(qq, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_BLACK);
  45. cucul_putstr(qq, 5, 0, "\\o/");
  46. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
  47. cucul_putstr(qq, 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_width(qq) * cucul_get_font_width(f);
  63. h = cucul_get_height(qq) * cucul_get_font_height(f);
  64. buf = malloc(4 * w * h);
  65. /* Render the canvas onto our image buffer */
  66. cucul_render_canvas(qq, f, buf, w, h, 4 * w);
  67. /* Just for fun, render the image using libcaca */
  68. cucul_set_size(qq, 80, 32);
  69. kk = caca_attach(qq);
  70. #if defined(HAVE_ENDIAN_H)
  71. if(__BYTE_ORDER == __BIG_ENDIAN)
  72. #else
  73. /* This is compile-time optimised with at least -O1 or -Os */
  74. uint32_t const rmask = 0x12345678;
  75. if(*(uint8_t const *)&rmask == 0x12)
  76. #endif
  77. d = cucul_create_dither(32, w, h, 4 * w,
  78. 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
  79. else
  80. d = cucul_create_dither(32, w, h, 4 * w,
  81. 0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff);
  82. cucul_dither_bitmap(qq, 0, 0, cucul_get_width(qq) - 1,
  83. cucul_get_height(qq) - 1, d, buf);
  84. caca_display(kk);
  85. caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1);
  86. /* Free everything */
  87. caca_detach(kk);
  88. free(buf);
  89. cucul_free_dither(d);
  90. cucul_free_font(f);
  91. cucul_free(qq);
  92. return 0;
  93. }