comparison mupdf-source/thirdparty/zint/extras/daft.c @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
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
22 #include <stdio.h>
23 #include <zint.h>
24 #include <string.h>
25 int main(int argc, char **argv)
26 {
27 struct zint_symbol *my_symbol;
28 int error = 0;
29 int x, y, glyph;
30
31 my_symbol = ZBarcode_Create();
32
33 my_symbol->symbology = BARCODE_USPS_IMAIL; // Change symbology here
34 my_symbol->output_options = OUT_BUFFER_INTERMEDIATE;
35
36 error = ZBarcode_Encode(my_symbol, argv[1], strlen(argv[1]));
37 if (error != 0)
38 {
39 printf("%s\n", my_symbol->errtxt);
40 }
41 if (error >= ZINT_ERROR_TOO_LONG)
42 {
43 ZBarcode_Delete(my_symbol);
44 return 1;
45 }
46
47 for (x = 0; x < my_symbol->width; x+= 2) {
48 glyph = 0;
49 if ((my_symbol->encoded_data[2][x / 8] >> (x % 8)) & 1) {
50 glyph += 1;
51 }
52 if ((my_symbol->encoded_data[0][x / 8] >> (x % 8)) & 1) {
53 glyph += 2;
54 }
55
56 switch (glyph) {
57 case 0: printf("T"); break;
58 case 1: printf("D"); break;
59 case 2: printf("A"); break;
60 case 3: printf("F"); break;
61 }
62 glyph = 0;
63 }
64 printf("\n");
65
66 ZBarcode_Delete(my_symbol);
67 return 0;
68 }