utf8_basic.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include <utf8.h>
  19. #define STB_IMAGE_WRITE_IMPLEMENTATION
  20. #include "stb_image_write.h"
  21. #include <utf8.h>
  22. static int create_utf8_bmp_glyph() {
  23. int sun = 0x2600;
  24. char *fontfile = "../ttf/dejavu.ttf";
  25. lc_fontBuffer *font = lc_create_font(fontfile);
  26. lc_bmpGlyph *glyph;
  27. if (!font) {
  28. perror("lc_create_font()");
  29. return 1;
  30. }
  31. glyph = lc_create_glyph(font, sun, 320);
  32. if (!glyph) {
  33. puts("lc_create_glyph()");
  34. return 1;
  35. }
  36. /* stbi_write_png("/tmp/glyph.png", glyph->w, glyph->h, 1, glyph->buffer, glyph->w);*/
  37. lc_free(glyph);
  38. lc_free(font);
  39. return 0;
  40. }
  41. static int utf8_iter_test() {
  42. char * simpl = "😒 hello";
  43. int i = 0, counter = 0;
  44. uint32_t c;
  45. while((c = u8_nextchar(simpl, &i))) {
  46. counter++;
  47. }
  48. assert(counter == 7);
  49. return 0;
  50. }
  51. static int create_utf8_arr_glyph() {
  52. char * str = "😒test";
  53. char * fontfile = "../ttf/dejavu.ttf";
  54. lc_fontBuffer *font = lc_create_font(fontfile);
  55. lc_arrGlyph *arr;
  56. if (!font) {
  57. perror("lc_create_font()");
  58. return 1;
  59. }
  60. arr = lc_str_to_arr(font, str, 38, 0);
  61. lc_free(arr);
  62. lc_free(font);
  63. return 0;
  64. }
  65. static int create_utf8_image() {
  66. return 0;
  67. }
  68. int main() {
  69. assert(!utf8_iter_test());
  70. assert(!create_utf8_bmp_glyph());
  71. assert(!create_utf8_arr_glyph());
  72. assert(!create_utf8_image());
  73. return 0;
  74. }