general: split up some source files to lessen ZXing-C++ bloat

when `ZXING_USE_BUNDLED_ZINT` set
This commit is contained in:
gitlost 2025-01-19 13:44:43 +00:00
parent 62c54adb56
commit 5c08226700
26 changed files with 2554 additions and 1534 deletions

View file

@ -1,7 +1,7 @@
/* 2of5.c - Handles Code 2 of 5 barcodes */
/* 2of5.c - Handles non-interleaved Code 2 of 5 barcodes */
/*
libzint - the open source barcode library
Copyright (C) 2008-2024 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008-2025 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -34,7 +34,6 @@
#include "common.h"
#include "gs1.h"
/* First 5 of each entry Interleaved also */
static const char C25MatrixTable[10][6] = {
{'1','1','3','3','1','1'}, {'3','1','1','1','3','1'}, {'1','3','1','1','3','1'}, {'3','3','1','1','1','1'},
{'1','1','3','1','3','1'}, {'3','1','3','1','1','1'}, {'1','3','3','1','1','1'}, {'1','1','1','3','3','1'},
@ -138,248 +137,4 @@ INTERNAL int c25logic(struct zint_symbol *symbol, unsigned char source[], int le
return c25_common(symbol, source, length, 113, 1 /*is_matrix*/, C25IataLogicStartStop, 4, 307);
}
/* Common to Interleaved, ITF-14, DP Leitcode, DP Identcode */
static int c25_inter_common(struct zint_symbol *symbol, unsigned char source[], int length,
const int checkdigit_option, const int dont_set_height) {
int i, j, error_number = 0;
char dest[638]; /* 4 + (125 + 1) * 5 + 3 + 1 = 638 */
char *d = dest;
unsigned char temp[125 + 1 + 1];
const int have_checkdigit = checkdigit_option == 1 || checkdigit_option == 2;
if (length > 125) { /* 4 + (125 + 1) * 9 + 5 = 1143 */
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 309, "Input length %d too long (maximum 125)", length);
}
if ((i = not_sane(NEON_F, source, length))) {
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 310,
"Invalid character at position %d in input (digits only)", i);
}
/* Input must be an even number of characters for Interlaced 2 of 5 to work:
if an odd number of characters has been entered and no check digit or an even number and have check digit
then add a leading zero */
if (have_checkdigit == !(length & 1)) {
temp[0] = '0';
memcpy(temp + 1, source, length++);
} else {
memcpy(temp, source, length);
}
temp[length] = '\0';
if (have_checkdigit) {
/* Add standard GS1 check digit */
temp[length] = gs1_check_digit(temp, length);
temp[++length] = '\0';
}
/* Start character */
memcpy(d, "1111", 4);
d += 4;
for (i = 0; i < length; i += 2) {
/* Look up the bars and the spaces */
const char *const bars = C25MatrixTable[temp[i] - '0'];
const char *const spaces = C25MatrixTable[temp[i + 1] - '0'];
/* Then merge (interlace) the strings together */
for (j = 0; j < 5; j++) {
*d++ = bars[j];
*d++ = spaces[j];
}
}
/* Stop character */
memcpy(d, "311", 3);
d += 3;
expand(symbol, dest, d - dest);
ustrcpy(symbol->text, temp);
if (checkdigit_option == 2) {
/* Remove check digit from HRT */
symbol->text[length - 1] = '\0';
}
if (!dont_set_height) {
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* ISO/IEC 16390:2007 Section 4.4 min height 5mm or 15% of symbol width whichever greater where
(P = character pairs, N = wide/narrow ratio = 3)
width = (P(4N + 6) + N + 6)X = (length / 2) * 18 + 9 */
/* Taking min X = 0.330mm from Annex D.3.1 (application specification) */
const float min_height_min = 15.151515f; /* 5.0 / 0.33 */
float min_height = stripf((18.0f * (length / 2) + 9.0f) * 0.15f);
if (min_height < min_height_min) {
min_height = min_height_min;
}
/* Using 50 as default as none recommended */
error_number = set_height(symbol, min_height, min_height > 50.0f ? min_height : 50.0f, 0.0f,
0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
}
return error_number;
}
/* Code 2 of 5 Interleaved ISO/IEC 16390:2007 */
INTERNAL int c25inter(struct zint_symbol *symbol, unsigned char source[], int length) {
return c25_inter_common(symbol, source, length, symbol->option_2 /*checkdigit_option*/, 0 /*dont_set_height*/);
}
/* Interleaved 2-of-5 (ITF-14) */
INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number, zeroes;
unsigned char localstr[16] = {0};
if (length > 13) {
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 311, "Input length %d too long (maximum 13)", length);
}
if ((i = not_sane(NEON_F, source, length))) {
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 312,
"Invalid character at position %d in input (digits only)", i);
}
/* Add leading zeros as required */
zeroes = 13 - length;
for (i = 0; i < zeroes; i++) {
localstr[i] = '0';
}
ustrcpy(localstr + zeroes, source);
/* Calculate the check digit - the same method used for EAN-13 */
localstr[13] = gs1_check_digit(localstr, 13);
localstr[14] = '\0';
error_number = c25_inter_common(symbol, localstr, 14, 0 /*checkdigit_option*/, 1 /*dont_set_height*/);
ustrcpy(symbol->text, localstr);
if (error_number < ZINT_ERROR) {
if (!(symbol->output_options & (BARCODE_BOX | BARCODE_BIND | BARCODE_BIND_TOP))) {
/* If no option has been selected then uses default box option */
symbol->output_options |= BARCODE_BOX;
if (symbol->border_width == 0) { /* Allow override if non-zero */
/* GS1 General Specifications 21.0.1 Sections 5.3.2.4 & 5.3.6 (4.83 / 1.016 ~ 4.75) */
symbol->border_width = 5; /* Note change from previous value 8 */
}
}
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* GS1 General Specifications 21.0.1 5.12.3.2 table 2, including footnote (**): (note bind/box additional
to symbol->height), same as GS1-128: "in case of further space constraints"
height 5.8mm / 1.016mm (X max) ~ 5.7; default 31.75mm / 0.495mm ~ 64.14 */
const float min_height = 5.70866156f; /* 5.8 / 1.016 */
const float default_height = 64.1414108f; /* 31.75 / 0.495 */
error_number = set_height(symbol, min_height, default_height, 0.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
}
return error_number;
}
/* Deutsche Post check digit */
static char c25_dp_check_digit(const unsigned int count) {
return itoc((10 - (count % 10)) % 10);
}
/* Deutsche Post Leitcode */
/* Documentation (of a very incomplete and non-technical type):
https://www.deutschepost.de/content/dam/dpag/images/D_d/dialogpost-schwer/dp-dialogpost-schwer-broschuere-072021.pdf
*/
INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, j, error_number;
unsigned int count;
int factor;
unsigned char localstr[16] = {0};
int zeroes;
count = 0;
if (length > 13) {
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 313, "Input length %d too long (maximum 13)", length);
}
if ((i = not_sane(NEON_F, source, length))) {
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 314,
"Invalid character at position %d in input (digits only)", i);
}
zeroes = 13 - length;
for (i = 0; i < zeroes; i++)
localstr[i] = '0';
ustrcpy(localstr + zeroes, source);
factor = 4;
for (i = 12; i >= 0; i--) {
count += factor * ctoi(localstr[i]);
factor ^= 0x0D; /* Toggles 4 and 9 */
}
localstr[13] = c25_dp_check_digit(count);
localstr[14] = '\0';
error_number = c25_inter_common(symbol, localstr, 14, 0 /*checkdigit_option*/, 1 /*dont_set_height*/);
/* HRT formatting as per DIALOGPOST SCHWER brochure but TEC-IT differs as do examples at
https://www.philaseiten.de/cgi-bin/index.pl?ST=8615&CP=0&F=1#M147 */
for (i = 0, j = 0; i <= 14; i++) {
symbol->text[j++] = localstr[i];
if (i == 4 || i == 7 || i == 10) {
symbol->text[j++] = '.';
}
}
/* TODO: Find documentation on BARCODE_DPLEIT dimensions/height */
/* Based on eyeballing DIALOGPOST SCHWER, using 72X as default */
(void) set_height(symbol, 0.0f, 72.0f, 0.0f, 1 /*no_errtxt*/);
return error_number;
}
/* Deutsche Post Identcode */
/* See dpleit() for (sort of) documentation reference */
INTERNAL int dpident(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, j, error_number, zeroes;
unsigned int count;
int factor;
unsigned char localstr[16] = {0};
count = 0;
if (length > 11) {
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 315, "Input length %d too long (maximum 11)", length);
}
if ((i = not_sane(NEON_F, source, length))) {
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 316,
"Invalid character at position %d in input (digits only)", i);
}
zeroes = 11 - length;
for (i = 0; i < zeroes; i++)
localstr[i] = '0';
ustrcpy(localstr + zeroes, source);
factor = 4;
for (i = 10; i >= 0; i--) {
count += factor * ctoi(localstr[i]);
factor ^= 0x0D; /* Toggles 4 and 9 */
}
localstr[11] = c25_dp_check_digit(count);
localstr[12] = '\0';
error_number = c25_inter_common(symbol, localstr, 12, 0 /*checkdigit_option*/, 1 /*dont_set_height*/);
/* HRT formatting as per DIALOGPOST SCHWER brochure but TEC-IT differs as do other examples (see above) */
for (i = 0, j = 0; i <= 12; i++) {
symbol->text[j++] = localstr[i];
if (i == 1 || i == 4 || i == 7) {
symbol->text[j++] = '.';
} else if (i == 3 || i == 10) {
symbol->text[j++] = ' ';
}
}
/* TODO: Find documentation on BARCODE_DPIDENT dimensions/height */
/* Based on eyeballing DIALOGPOST SCHWER, using 72X as default */
(void) set_height(symbol, 0.0f, 72.0f, 0.0f, 1 /*no_errtxt*/);
return error_number;
}
/* vim: set ts=4 sw=4 et : */