stroke.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * stroke.c
  3. *
  4. * This code uses Zint to encode data in QR Code and then output in
  5. * the correct format to use StrokeScribe 2D font. This can be adapted
  6. * to encode any matrix symbology using this font.
  7. *
  8. * The same code can also be used to resolve PDF417 symbols with the
  9. * StrokeScribe 417 font and linear symbols with the StrokeScribe 1D
  10. * font, all of which are available from the same souce.
  11. *
  12. * This code can be compiled with:
  13. *
  14. * gcc -o stroke stroke.c -lzint
  15. *
  16. * The fonts are available from:
  17. *
  18. * https://strokescribe.com/en/free-version-barcode-truetype-fonts.html
  19. *
  20. */
  21. #include <stdio.h>
  22. #include <zint.h>
  23. #include <string.h>
  24. int main(int argc, char **argv)
  25. {
  26. struct zint_symbol *my_symbol;
  27. int error = 0;
  28. int x, y, glyph, sub;
  29. my_symbol = ZBarcode_Create();
  30. my_symbol->symbology = BARCODE_QRCODE; // Change symbology here
  31. my_symbol->output_options = OUT_BUFFER_INTERMEDIATE;
  32. error = ZBarcode_Encode(my_symbol, argv[1], strlen(argv[1]));
  33. if (error != 0)
  34. {
  35. printf("%s\n", my_symbol->errtxt);
  36. }
  37. if (error >= ZINT_ERROR_TOO_LONG)
  38. {
  39. ZBarcode_Delete(my_symbol);
  40. return 1;
  41. }
  42. sub = 0;
  43. glyph = 0;
  44. for (y = 0; y < my_symbol->rows; y++) {
  45. for (x = 0; x < my_symbol->width; x++) {
  46. glyph *= 2;
  47. if ((my_symbol->encoded_data[y][x / 8] >> (x % 8)) & 1) {
  48. glyph += 1;
  49. }
  50. sub++;
  51. if (sub == 5) {
  52. if (glyph <= 25) {
  53. printf("%c", glyph + 'A');
  54. } else {
  55. printf("%c", (glyph - 26) + 'a');
  56. }
  57. sub = 0;
  58. glyph = 0;
  59. }
  60. }
  61. if (sub == 4) {
  62. printf("%c", glyph + 'g');
  63. }
  64. if (sub == 3) {
  65. if (glyph <= 3) {
  66. printf("%c", glyph + 'w');
  67. } else {
  68. printf("%c", (glyph - 4) + '0');
  69. }
  70. }
  71. if (sub == 2) {
  72. printf("%c", glyph + '4');
  73. }
  74. if (sub == 1) {
  75. printf("%c", glyph + '8');
  76. }
  77. printf("\n");
  78. sub = 0;
  79. glyph = 0;
  80. }
  81. ZBarcode_Delete(my_symbol);
  82. return 0;
  83. }