primitives.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License
  4. * as published by the Free Software Foundation; either version 2
  5. * of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. * Author: g0tsu
  12. * Email: g0tsu at dnmx.0rg
  13. */
  14. #include <stdio.h>
  15. #include <assert.h>
  16. #include <libcaptcha.h>
  17. #include <errno.h>
  18. static int load_incorrect_file() {
  19. char *fontfile = "nofile.found";
  20. lc_fontBuffer *font = lc_create_font(fontfile);
  21. if (font != NULL) {
  22. return 1;
  23. }
  24. lc_free(font);
  25. return 0;
  26. }
  27. static int load_font_test() {
  28. char *fontfile = "../ttf/cmunrm/cmunrm.ttf";
  29. lc_fontBuffer *font = lc_create_font(fontfile);
  30. if (!font) {
  31. perror("lc_create_font()");
  32. return 1;
  33. }
  34. lc_free(font);
  35. return 0;
  36. }
  37. static int create_bmp_glyph() {
  38. char *fontfile = "../ttf/cmunrm/cmunrm.ttf";
  39. lc_fontBuffer *font = lc_create_font(fontfile);
  40. lc_bmpGlyph *glyph;
  41. if (!font) {
  42. perror("lc_create_font()");
  43. return 1;
  44. }
  45. glyph = lc_create_glyph(font, 'g', 22);
  46. if (!glyph) {
  47. puts("lc_create_glyph()");
  48. return 1;
  49. }
  50. printf("glyph g is %dx%d\n", glyph->w, glyph->h);
  51. /* stbi_write_png("/tmp/glyph.png", glyph->w, glyph->h, 1, glyph->buffer, glyph->w);*/
  52. lc_free(glyph);
  53. lc_free(font);
  54. return 0;
  55. }
  56. static int random_stuff() {
  57. char bytes[4];
  58. lc_random_bytes(&bytes, 4);
  59. for (int i = 0; i < 4; i++) {
  60. printf("%x ", bytes[i] % 20);
  61. }
  62. return 0;
  63. }
  64. int main() {
  65. assert((2 + 2) == 4);
  66. assert(!load_incorrect_file());
  67. assert(!load_font_test());
  68. assert(!create_bmp_glyph());
  69. assert(!random_stuff());
  70. return 0;
  71. }