zebu_pdf.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * zebu_pdf.c
  3. *
  4. * This code uses Zint to encode data into a PDF417 and then outputs
  5. * the symbol as text suitable for use with Code PDF417 font by
  6. * Grand Zebu.
  7. *
  8. * This code can be compiled with:
  9. *
  10. * gcc -o zebu_pdf zebu_pdf.c -lzint
  11. *
  12. * Grand Zebu's font can be downloaded from:
  13. *
  14. * https://grandzebu.net/informatique/codbar-en/pdf417.htm
  15. *
  16. */
  17. #include <stdio.h>
  18. #include <zint.h>
  19. #include <string.h>
  20. int main(int argc, char **argv)
  21. {
  22. struct zint_symbol *my_symbol;
  23. int error = 0;
  24. int x, y, sub, glyph, group;
  25. my_symbol = ZBarcode_Create();
  26. my_symbol->symbology = BARCODE_PDF417;
  27. my_symbol->output_options = OUT_BUFFER_INTERMEDIATE;
  28. error = ZBarcode_Encode(my_symbol, argv[1], strlen(argv[1]));
  29. if (error != 0)
  30. {
  31. printf("%s\n", my_symbol->errtxt);
  32. }
  33. if (error >= ZINT_ERROR_TOO_LONG)
  34. {
  35. ZBarcode_Delete(my_symbol);
  36. return 1;
  37. }
  38. for (y = 0; y < my_symbol->rows; y++) {
  39. printf("+*");
  40. sub = 0;
  41. glyph = 0;
  42. group = 0;
  43. for (x = 18; x < my_symbol->width - 19; x++) {
  44. glyph *= 2;
  45. if ((my_symbol->encoded_data[y][x / 8] >> (x % 8)) & 1) {
  46. glyph++;
  47. }
  48. sub++;
  49. if (sub == 5) {
  50. if (glyph <= 5) {
  51. printf("%c", glyph + 'A');
  52. } else {
  53. printf("%c", (glyph - 6) + 'a');
  54. }
  55. glyph = 0;
  56. sub = 0;
  57. group++;
  58. }
  59. if (group == 3) {
  60. printf("*");
  61. x += 2;
  62. group = 0;
  63. }
  64. }
  65. printf("-\n");
  66. }
  67. ZBarcode_Delete(my_symbol);
  68. return 0;
  69. }