Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/backend/bc412.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 /* bc412.c - Handles IBM BC412 (SEMI T1-95) symbology */ | |
| 2 /* | |
| 3 libzint - the open source barcode library | |
| 4 Copyright (C) 2022-2024 Robin Stuart <rstuart114@gmail.com> | |
| 5 | |
| 6 Redistribution and use in source and binary forms, with or without | |
| 7 modification, are permitted provided that the following conditions | |
| 8 are met: | |
| 9 | |
| 10 1. Redistributions of source code must retain the above copyright | |
| 11 notice, this list of conditions and the following disclaimer. | |
| 12 2. Redistributions in binary form must reproduce the above copyright | |
| 13 notice, this list of conditions and the following disclaimer in the | |
| 14 documentation and/or other materials provided with the distribution. | |
| 15 3. Neither the name of the project nor the names of its contributors | |
| 16 may be used to endorse or promote products derived from this software | |
| 17 without specific prior written permission. | |
| 18 | |
| 19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
| 20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | |
| 23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
| 25 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 26 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
| 28 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
| 29 SUCH DAMAGE. | |
| 30 */ | |
| 31 /* SPDX-License-Identifier: BSD-3-Clause */ | |
| 32 | |
| 33 /* A little information about this symbology can be found at | |
| 34 * https://barcodeguide.seagullscientific.com/Content/Symbologies/BC412.htm | |
| 35 * | |
| 36 * Partial specification at | |
| 37 * https://www.wdfxw.net/doc80487518.htm | |
| 38 * | |
| 39 * Checked against the encoder at | |
| 40 * https://www.barcodesoft.com/en/semi/semi-t1-95-bc-412-code */ | |
| 41 | |
| 42 #include <stdio.h> | |
| 43 #include "common.h" | |
| 44 | |
| 45 static const char BROMINE[] = "0R9GLVHA8EZ4NTS1J2Q6C7DYKBUIX3FWP5M"; | |
| 46 | |
| 47 static const char BC412Table[35][8] = { | |
| 48 {'1','1','1','1','1','1','1','5'}, {'1','3','1','1','1','2','1','2'}, | |
| 49 {'1','1','1','3','1','1','1','3'}, {'1','2','1','1','1','2','1','3'}, | |
| 50 {'1','2','1','2','1','3','1','1'}, {'1','3','1','3','1','1','1','1'}, | |
| 51 {'1','2','1','1','1','3','1','2'}, {'1','1','1','3','1','2','1','2'}, | |
| 52 {'1','1','1','2','1','4','1','1'}, {'1','1','1','5','1','1','1','1'}, | |
| 53 {'1','5','1','1','1','1','1','1'}, {'1','1','1','1','1','5','1','1'}, | |
| 54 {'1','2','1','3','1','2','1','1'}, {'1','3','1','2','1','1','1','2'}, | |
| 55 {'1','3','1','1','1','3','1','1'}, {'1','1','1','1','1','2','1','4'}, | |
| 56 {'1','2','1','2','1','1','1','3'}, {'1','1','1','1','1','3','1','3'}, | |
| 57 {'1','3','1','1','1','1','1','3'}, {'1','1','1','2','1','2','1','3'}, | |
| 58 {'1','1','1','4','1','1','1','2'}, {'1','1','1','2','1','3','1','2'}, | |
| 59 {'1','1','1','4','1','2','1','1'}, {'1','4','1','2','1','1','1','1'}, | |
| 60 {'1','2','1','2','1','2','1','2'}, {'1','1','1','3','1','3','1','1'}, | |
| 61 {'1','3','1','2','1','2','1','1'}, {'1','2','1','1','1','4','1','1'}, | |
| 62 {'1','4','1','1','1','2','1','1'}, {'1','1','1','1','1','4','1','2'}, | |
| 63 {'1','2','1','1','1','1','1','4'}, {'1','4','1','1','1','1','1','2'}, | |
| 64 {'1','2','1','4','1','1','1','1'}, {'1','1','1','2','1','1','1','4'}, | |
| 65 {'1','2','1','3','1','1','1','2'} | |
| 66 }; | |
| 67 | |
| 68 INTERNAL int bc412(struct zint_symbol *symbol, unsigned char source[], int length) { /* IBM BC412 */ | |
| 69 unsigned char padded_source[20]; | |
| 70 int posns[35]; | |
| 71 int i, counter_odd = 0, counter_even = 0, check_sum = 0; | |
| 72 char dest[293]; /* 2 + (36 * 8) + 3 */ | |
| 73 char *d = dest; | |
| 74 int error_number = 0; | |
| 75 | |
| 76 if (length > 18) { | |
| 77 return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 790, "Input length %d too long (maximum 18)", length); | |
| 78 } | |
| 79 if (length < 7) { | |
| 80 return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 792, "Input length %d too short (minimum 7)", length); | |
| 81 } | |
| 82 to_upper(source, length); | |
| 83 | |
| 84 padded_source[0] = source[0]; | |
| 85 padded_source[1] = '0'; | |
| 86 | |
| 87 for (i = 2; i <= length; i++) { | |
| 88 padded_source[i] = source[i - 1]; | |
| 89 } | |
| 90 padded_source[length + 1] = 0; | |
| 91 | |
| 92 if ((i = not_sane_lookup(BROMINE, 35, padded_source, length + 1, posns))) { | |
| 93 return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 791, | |
| 94 "Invalid character at position %d in input (alphanumerics only, excluding \"O\")", i - 1); | |
| 95 } | |
| 96 | |
| 97 for (i = 0; i <= length; i++) { | |
| 98 if (i % 2) { | |
| 99 counter_even += posns[i]; | |
| 100 } else { | |
| 101 counter_odd += posns[i]; | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 counter_odd %= 35; | |
| 106 counter_even %= 35; | |
| 107 | |
| 108 /* Check digit */ | |
| 109 check_sum = counter_odd + (2 * counter_even); | |
| 110 check_sum %= 35; | |
| 111 check_sum *= 17; | |
| 112 check_sum %= 35; | |
| 113 | |
| 114 if (symbol->debug & ZINT_DEBUG_PRINT) { | |
| 115 printf("BC412 check: %c\n", BROMINE[check_sum]); | |
| 116 } | |
| 117 | |
| 118 padded_source[1] = BROMINE[check_sum]; | |
| 119 posns[1] = check_sum; | |
| 120 | |
| 121 /* Start character */ | |
| 122 memcpy(d, "12", 2); | |
| 123 d += 2; | |
| 124 | |
| 125 for (i = 0; i <= length; i++, d += 8) { | |
| 126 memcpy(d, BC412Table[posns[i]], 8); | |
| 127 } | |
| 128 | |
| 129 /* Stop character */ | |
| 130 memcpy(d, "111", 3); | |
| 131 d += 3; | |
| 132 | |
| 133 expand(symbol, dest, d - dest); | |
| 134 ustrcpy(symbol->text, padded_source); | |
| 135 | |
| 136 if (symbol->output_options & COMPLIANT_HEIGHT) { | |
| 137 /* SEMI T1-95 Table 1 "Module" (Character) Height 2mm ± 0.025mm, using Module Spacing 0.12mm ± 0.025mm as | |
| 138 X-dimension */ | |
| 139 const float min_height = 13.6206894f; /* 1.975 / 0.145 */ | |
| 140 const float default_height = 16.666666f; /* 2.0 / 0.12 */ | |
| 141 const float max_height = 21.3157902f; /* 2.025 / 0.095 */ | |
| 142 error_number = set_height(symbol, min_height, default_height, max_height, 0 /*no_errtxt*/); | |
| 143 } else { | |
| 144 /* Using compliant height as default as no backwards compatibility to consider */ | |
| 145 const float default_height = 16.666666f; /* 2.0 / 0.12 */ | |
| 146 (void) set_height(symbol, 0.0f, default_height, 0.0f, 1 /*no_errtxt*/); | |
| 147 } | |
| 148 | |
| 149 return error_number; | |
| 150 } | |
| 151 | |
| 152 /* vim: set ts=4 sw=4 et : */ |
