Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/extras/cuecat.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 * cuecat.c | |
| 3 * | |
| 4 * This code creates barcodes as intended for use with the CueCat scheme (without the | |
| 5 * "cue" symbol which may still be trademarked). As the system was ultimately not | |
| 6 * successful this is now simply a curiosity. | |
| 7 * | |
| 8 * "The CueCat, styled :CueCat with a leading colon, is a cat-shaped handheld barcode | |
| 9 * reader that was released in 2000 by the now-defunct Digital Convergence Corporation. | |
| 10 * The CueCat enabled a user to open a link to an Internet URL by scanning a barcode — | |
| 11 * called a "cue" by Digital Convergence — appearing in an article or catalog or on | |
| 12 * some other printed matter." | |
| 13 * | |
| 14 * For more information: | |
| 15 * https://linas.org/banned/cuecat/www.fluent-access.com.wtpapers.cuecat.index.html | |
| 16 * | |
| 17 */ | |
| 18 | |
| 19 #include <stdio.h> | |
| 20 #include <stdlib.h> | |
| 21 #include <string.h> | |
| 22 #include <ctype.h> | |
| 23 | |
| 24 static const char *C128Table[107] = { | |
| 25 /* Code 128 character encodation */ | |
| 26 "212222", "222122", "222221", "121223", "121322", "131222", "122213", | |
| 27 "122312", "132212", "221213", "221312", "231212", "112232", "122132", "122231", "113222", | |
| 28 "123122", "123221", "223211", "221132", "221231", "213212", "223112", "312131", "311222", | |
| 29 "321122", "321221", "312212", "322112", "322211", "212123", "212321", "232121", "111323", | |
| 30 "131123", "131321", "112313", "132113", "132311", "211313", "231113", "231311", "112133", | |
| 31 "112331", "132131", "113123", "113321", "133121", "313121", "211331", "231131", "213113", | |
| 32 "213311", "213131", "311123", "311321", "331121", "312113", "312311", "332111", "314111", | |
| 33 "221411", "431111", "111224", "111422", "121124", "121421", "141122", "141221", "112214", | |
| 34 "112412", "122114", "122411", "142112", "142211", "241211", "221114", "413111", "241112", | |
| 35 "134111", "111242", "121142", "121241", "114212", "124112", "124211", "411212", "421112", | |
| 36 "421211", "212141", "214121", "412121", "111143", "111341", "131141", "114113", "114311", | |
| 37 "411113", "411311", "113141", "114131", "311141", "411131", "211412", "211214", "211232", | |
| 38 "2331112" | |
| 39 }; | |
| 40 | |
| 41 void print_head(char cat_number[]) { | |
| 42 printf("<?xml version=\"1.0\" standalone=\"no\"?>\n"); | |
| 43 printf("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n"); | |
| 44 printf(" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); | |
| 45 printf("<svg width=\"149.60\" height=\"36.00\" version=\"1.1\"\n"); | |
| 46 printf(" xmlns=\"http://www.w3.org/2000/svg\">\n"); | |
| 47 printf(" <desc>CueCat %s</desc>\n\n", cat_number); | |
| 48 printf(" <g id=\"cuecat\" fill = \"#000000\">\n"); | |
| 49 printf(" <rect x=\"0\" y=\"0\" width=\"149.60\" height=\"36.00\" fill=\"#ffffff\" />\n"); | |
| 50 } | |
| 51 | |
| 52 void print_cue() { | |
| 53 /* Just dots and triangles as the :C symbol may still be a trademark */ | |
| 54 printf(" <circle cx=\"7.00\" cy=\"12.50\" r=\"3.50\" fill=\"red\" />\n"); | |
| 55 printf(" <circle cx=\"7.00\" cy=\"23.50\" r=\"3.50\" fill=\"red\" />\n"); | |
| 56 printf(" <polygon points=\"14.00,4.00 14.00,32.00 25.60,32.00\" />\n"); | |
| 57 printf(" <polygon points=\"134.00,4.00 145.60,4.00 145.60,32.00\" />\n"); | |
| 58 } | |
| 59 | |
| 60 void print_data(char pattern[]) { | |
| 61 /* Output the lines of the barcode at an attractive 22.5 degree angle */ | |
| 62 double posn = 24; | |
| 63 int length = strlen(pattern); | |
| 64 int i; | |
| 65 | |
| 66 for (i = 0; i < length; i++) { | |
| 67 if ((i % 2) == 0) { | |
| 68 printf(" <polygon points=\"%.2f,4.00 %.2f,4.00 %.2f,32.00 %.2f,32.00\" />\n", | |
| 69 posn, posn + (pattern[i] - '0'), posn + (pattern[i] - '0') + 11.6, posn + 11.6); | |
| 70 } | |
| 71 posn += (pattern[i] - '0'); | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 void print_hrt(char cat_number[]) { | |
| 76 /* Put readable text at the bottom of the symbol */ | |
| 77 char hrt[25]; | |
| 78 int i, j; | |
| 79 | |
| 80 printf(" <rect x=\"57.00\" y=\"28.00\" width=\"61.00\" height=\"5.00\" fill=\"white\" />\n"); | |
| 81 | |
| 82 strcpy(hrt, "C "); | |
| 83 for (i = 0, j = 2; i < strlen(cat_number); i++) { | |
| 84 hrt[j] = cat_number[i]; | |
| 85 j++; | |
| 86 if ((i % 2) != 0) { | |
| 87 hrt[j] = ' '; | |
| 88 j++; | |
| 89 } | |
| 90 } | |
| 91 hrt[j] = '\0'; | |
| 92 printf(" <text x=\"58.00\" y=\"32.00\" font-family=\"Verdana\" font-size=\"5\">%s</text>\n", hrt); | |
| 93 } | |
| 94 | |
| 95 void print_foot() { | |
| 96 printf(" </g>\n"); | |
| 97 printf("</svg>\n"); | |
| 98 } | |
| 99 | |
| 100 int main(int argc, char** argv) { | |
| 101 int in_length; | |
| 102 char cat_number[16]; | |
| 103 char pattern[90]; | |
| 104 int cw[7]; | |
| 105 int i; | |
| 106 int total_sum; | |
| 107 | |
| 108 if (argc != 2) { | |
| 109 /* Only command line input should be the number to encode */ | |
| 110 printf("Usage: cuecat {number}\n"); | |
| 111 printf("Where {number} is the number to be encoded, up to 14 digits\n"); | |
| 112 return 0; | |
| 113 } else { | |
| 114 in_length = strlen(argv[1]); | |
| 115 if (in_length > 14) { | |
| 116 /* Check maximum length */ | |
| 117 printf("Input data too long\n"); | |
| 118 return 0; | |
| 119 } else { | |
| 120 /* Add padding if needed */ | |
| 121 strcpy(cat_number, ""); | |
| 122 for(i = in_length; i < 14; i++) { | |
| 123 strcat(cat_number, "0"); | |
| 124 } | |
| 125 strcat(cat_number, argv[1]); | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 /* Check input is numeric */ | |
| 130 for (i = 0; i < 10; i++) { | |
| 131 if (!(isdigit(cat_number[i]))) { | |
| 132 printf("Invalid character(s) in input data\n"); | |
| 133 return 0; | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 // There is no 'Start' character | |
| 138 | |
| 139 strcpy(pattern, ""); | |
| 140 for (i = 0; i < 7; i ++) { | |
| 141 cw[i] = (cat_number[i * 2] - '0') * 10; | |
| 142 cw[i] += cat_number[(i * 2) + 1] - '0'; | |
| 143 strcat(pattern, C128Table[cw[i]]); | |
| 144 | |
| 145 if (cw[i] >= 96) { | |
| 146 /* CueCat can't decode number pairs above 95 */ | |
| 147 printf("Invalid input data\n"); | |
| 148 return 0; | |
| 149 } | |
| 150 } | |
| 151 | |
| 152 | |
| 153 /* check digit calculation */ | |
| 154 total_sum = 0; | |
| 155 | |
| 156 for (i = 0; i < 7; i++) { | |
| 157 if (i > 0) { | |
| 158 cw[i] *= i; | |
| 159 } | |
| 160 total_sum += cw[i]; | |
| 161 } | |
| 162 strcat(pattern, C128Table[total_sum % 103]); | |
| 163 | |
| 164 strcat(pattern, C128Table[106]); // Stop | |
| 165 | |
| 166 /* Start ouputting SVG file */ | |
| 167 print_head(cat_number); | |
| 168 print_cue(); | |
| 169 print_data(pattern); | |
| 170 print_hrt(cat_number); | |
| 171 print_foot(); | |
| 172 } | |
| 173 |
