daft.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * daft.c
  3. *
  4. * This code uses Zint to encode data into a USPS Intelligent
  5. * Mail symbol, and then converts the output to "DAFT code"
  6. * which is used by commercial fonts to display this and
  7. * similar 4-state symbologies.
  8. *
  9. * This code can be compiled with:
  10. *
  11. * gcc -o daft daft.c -lzint
  12. *
  13. * The output characters are:
  14. *
  15. * D = Descender
  16. * A = Ascender
  17. * F = Full
  18. * T = Tracker
  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;
  29. my_symbol = ZBarcode_Create();
  30. my_symbol->symbology = BARCODE_USPS_IMAIL; // 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. for (x = 0; x < my_symbol->width; x+= 2) {
  43. glyph = 0;
  44. if ((my_symbol->encoded_data[2][x / 8] >> (x % 8)) & 1) {
  45. glyph += 1;
  46. }
  47. if ((my_symbol->encoded_data[0][x / 8] >> (x % 8)) & 1) {
  48. glyph += 2;
  49. }
  50. switch (glyph) {
  51. case 0: printf("T"); break;
  52. case 1: printf("D"); break;
  53. case 2: printf("A"); break;
  54. case 3: printf("F"); break;
  55. }
  56. glyph = 0;
  57. }
  58. printf("\n");
  59. ZBarcode_Delete(my_symbol);
  60. return 0;
  61. }