25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

112 satır
3.0 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_canvas_t *cv;
  32. caca_display_t *dp;
  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. cv = cucul_create_canvas(8, 2);
  41. /* Draw stuff on our canvas */
  42. cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
  43. cucul_putstr(cv, 0, 0, "ABcde");
  44. cucul_set_color(cv, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_BLACK);
  45. cucul_putstr(cv, 5, 0, "\\o/");
  46. cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
  47. cucul_putstr(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. #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(cv, 0, 0, cucul_get_canvas_width(cv),
  83. cucul_get_canvas_height(cv), d, buf);
  84. caca_refresh_display(dp);
  85. caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
  86. /* Free everything */
  87. caca_free_display(dp);
  88. free(buf);
  89. cucul_free_dither(d);
  90. cucul_free_font(f);
  91. cucul_free_canvas(cv);
  92. return 0;
  93. }