utf8_basic.c 2.0 KB

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