25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

font.c 2.9 KiB

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