2009-11-23 04:38:15 +13:00
|
|
|
/* library.c - external functions of libzint
|
|
|
|
|
|
|
|
libzint - the open source barcode library
|
2018-06-10 20:16:18 +12:00
|
|
|
Copyright (C) 2009-2018 Robin Stuart <rstuart114@gmail.com>
|
2009-11-23 04:38:15 +13:00
|
|
|
|
2013-05-17 05:26:38 +12:00
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
2017-10-24 08:37:52 +13:00
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
2013-05-17 05:26:38 +12:00
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
2017-10-24 08:37:52 +13:00
|
|
|
documentation and/or other materials provided with the distribution.
|
2013-05-17 05:26:38 +12:00
|
|
|
3. Neither the name of the project nor the names of its contributors
|
|
|
|
may be used to endorse or promote products derived from this software
|
2017-10-24 08:37:52 +13:00
|
|
|
without specific prior written permission.
|
2013-05-17 05:26:38 +12:00
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
|
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
2017-10-24 08:37:52 +13:00
|
|
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
2013-05-17 05:26:38 +12:00
|
|
|
SUCH DAMAGE.
|
2016-02-20 23:50:15 +13:00
|
|
|
*/
|
2009-11-23 04:38:15 +13:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#ifdef _MSC_VER
|
2017-10-24 08:37:52 +13:00
|
|
|
#include <malloc.h>
|
2009-11-23 04:38:15 +13:00
|
|
|
#endif
|
|
|
|
#include "common.h"
|
|
|
|
#include "gs1.h"
|
|
|
|
|
|
|
|
#define TECHNETIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
struct zint_symbol *ZBarcode_Create() {
|
|
|
|
struct zint_symbol *symbol;
|
|
|
|
|
|
|
|
symbol = (struct zint_symbol*) malloc(sizeof (*symbol));
|
|
|
|
if (!symbol) return NULL;
|
|
|
|
|
|
|
|
memset(symbol, 0, sizeof (*symbol));
|
|
|
|
symbol->symbology = BARCODE_CODE128;
|
2016-10-27 21:32:12 +13:00
|
|
|
symbol->height = 50;
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->whitespace_width = 0;
|
|
|
|
symbol->border_width = 0;
|
|
|
|
symbol->output_options = 0;
|
|
|
|
symbol->rows = 0;
|
|
|
|
symbol->width = 0;
|
|
|
|
strcpy(symbol->fgcolour, "000000");
|
|
|
|
strcpy(symbol->bgcolour, "ffffff");
|
2017-10-22 00:45:50 +13:00
|
|
|
strcpy(symbol->outfile, "out.png");
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->scale = 1.0;
|
|
|
|
symbol->option_1 = -1;
|
|
|
|
symbol->option_2 = 0;
|
|
|
|
symbol->option_3 = 928; // PDF_MAX
|
|
|
|
symbol->show_hrt = 1; // Show human readable text
|
2018-02-11 22:55:28 +13:00
|
|
|
symbol->fontsize = 8;
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->input_mode = DATA_MODE;
|
|
|
|
strcpy(symbol->primary, "");
|
|
|
|
memset(&(symbol->encoded_data[0][0]), 0, sizeof (symbol->encoded_data));
|
2016-10-28 08:52:58 +13:00
|
|
|
memset(&(symbol->row_height[0]), 0, sizeof (symbol->row_height));
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->bitmap = NULL;
|
|
|
|
symbol->bitmap_width = 0;
|
|
|
|
symbol->bitmap_height = 0;
|
2016-08-16 23:43:41 +12:00
|
|
|
symbol->eci = 3;
|
2016-09-19 01:09:58 +12:00
|
|
|
symbol->dot_size = 4.0 / 5.0;
|
2017-04-11 21:05:38 +12:00
|
|
|
symbol->debug = 0;
|
2016-02-20 23:50:15 +13:00
|
|
|
return symbol;
|
2009-11-23 04:38:15 +13:00
|
|
|
}
|
|
|
|
|
2017-10-16 20:49:44 +13:00
|
|
|
extern void render_free(struct zint_symbol *symbol); /* Free render structures */
|
2018-06-10 20:16:18 +12:00
|
|
|
extern void vector_free(struct zint_symbol *symbol); /* Free vector structures */
|
2017-10-16 20:49:44 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
void ZBarcode_Clear(struct zint_symbol *symbol) {
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < symbol->rows; i++) {
|
|
|
|
for (j = 0; j < symbol->width; j++) {
|
|
|
|
unset_module(symbol, i, j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
symbol->rows = 0;
|
|
|
|
symbol->width = 0;
|
2016-10-28 08:55:26 +13:00
|
|
|
memset(symbol->text, 0, sizeof(symbol->text));
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->errtxt[0] = '\0';
|
|
|
|
if (symbol->bitmap != NULL) {
|
|
|
|
free(symbol->bitmap);
|
|
|
|
symbol->bitmap = NULL;
|
|
|
|
}
|
|
|
|
symbol->bitmap_width = 0;
|
|
|
|
symbol->bitmap_height = 0;
|
2017-10-16 20:49:44 +13:00
|
|
|
|
|
|
|
// If there is a rendered version, ensure its memory is released
|
|
|
|
render_free(symbol);
|
2018-06-10 20:16:18 +12:00
|
|
|
vector_free(symbol);
|
2009-12-02 22:09:45 +13:00
|
|
|
}
|
2009-11-23 04:38:15 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
void ZBarcode_Delete(struct zint_symbol *symbol) {
|
|
|
|
if (symbol->bitmap != NULL)
|
|
|
|
free(symbol->bitmap);
|
|
|
|
|
|
|
|
// If there is a rendered version, ensure its memory is released
|
2017-10-16 20:49:44 +13:00
|
|
|
render_free(symbol);
|
2018-06-10 20:16:18 +12:00
|
|
|
vector_free(symbol);
|
2016-09-06 09:06:50 +12:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
free(symbol);
|
2009-11-23 04:38:15 +13:00
|
|
|
}
|
|
|
|
|
2017-06-14 07:05:35 +12:00
|
|
|
extern int get_best_eci(unsigned char source[], size_t length); /* Calculate suitable ECI mode */
|
|
|
|
extern int utf_to_eci(const int eci, const unsigned char source[], unsigned char dest[], size_t *length); /* Convert Unicode to other encodings */
|
|
|
|
|
2016-08-16 23:43:41 +12:00
|
|
|
|
2009-11-23 04:38:15 +13:00
|
|
|
extern int eanx(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN system barcodes */
|
2016-09-06 09:06:50 +12:00
|
|
|
extern int c39(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* Code 3 from 9 (or Code 39) */
|
2009-11-23 04:38:15 +13:00
|
|
|
extern int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmazentral Nummer (PZN) */
|
|
|
|
extern int ec39(struct zint_symbol *symbol, unsigned char source[], int length); /* Extended Code 3 from 9 (or Code 39+) */
|
|
|
|
extern int codabar(struct zint_symbol *symbol, unsigned char source[], int length); /* Codabar - a simple substitution cipher */
|
|
|
|
extern int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Standard (& Matrix) */
|
|
|
|
extern int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Industrial */
|
|
|
|
extern int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 IATA */
|
2016-09-06 09:06:50 +12:00
|
|
|
extern int interleaved_two_of_five(struct zint_symbol *symbol, const unsigned char source[], size_t length); /* Code 2 of 5 Interleaved */
|
2009-11-23 04:38:15 +13:00
|
|
|
extern int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Data Logic */
|
|
|
|
extern int itf14(struct zint_symbol *symbol, unsigned char source[], int length); /* ITF-14 */
|
|
|
|
extern int dpleit(struct zint_symbol *symbol, unsigned char source[], int length); /* Deutsche Post Leitcode */
|
|
|
|
extern int dpident(struct zint_symbol *symbol, unsigned char source[], int length); /* Deutsche Post Identcode */
|
|
|
|
extern int c93(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 93 - a re-working of Code 39+, generates 2 check digits */
|
2017-05-29 21:43:47 +12:00
|
|
|
extern int code_128(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* Code 128 and NVE-18 */
|
2016-09-06 09:06:50 +12:00
|
|
|
extern int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* EAN-128 (GS1-128) */
|
2009-11-23 04:38:15 +13:00
|
|
|
extern int code_11(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 11 */
|
|
|
|
extern int msi_handle(struct zint_symbol *symbol, unsigned char source[], int length); /* MSI Plessey */
|
2017-05-29 21:43:47 +12:00
|
|
|
extern int telepen(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* Telepen ASCII */
|
|
|
|
extern int telepen_num(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* Telepen Numeric */
|
|
|
|
extern int plessey(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* Plessey Code */
|
2009-11-23 04:38:15 +13:00
|
|
|
extern int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmacode One Track */
|
|
|
|
extern int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length); /* Flattermarken */
|
|
|
|
extern int fim(struct zint_symbol *symbol, unsigned char source[], int length); /* Facing Identification Mark */
|
|
|
|
extern int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmacode Two Track */
|
|
|
|
extern int post_plot(struct zint_symbol *symbol, unsigned char source[], int length); /* Postnet */
|
|
|
|
extern int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length); /* PLANET */
|
|
|
|
extern int imail(struct zint_symbol *symbol, unsigned char source[], int length); /* Intelligent Mail (aka USPS OneCode) */
|
|
|
|
extern int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length); /* RM4SCC */
|
|
|
|
extern int australia_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Australia Post 4-state */
|
2017-05-29 21:43:47 +12:00
|
|
|
extern int code16k(struct zint_symbol *symbol, unsigned char source[],const size_t length); /* Code 16k */
|
|
|
|
extern int pdf417enc(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* PDF417 */
|
|
|
|
extern int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size_t length); /* Micro PDF417 */
|
2009-11-23 04:38:15 +13:00
|
|
|
extern int maxicode(struct zint_symbol *symbol, unsigned char source[], int length); /* Maxicode */
|
|
|
|
extern int rss14(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS-14 */
|
|
|
|
extern int rsslimited(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS Limited */
|
|
|
|
extern int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS Expanded */
|
|
|
|
extern int composite(struct zint_symbol *symbol, unsigned char source[], int length); /* Composite Symbology */
|
|
|
|
extern int kix_code(struct zint_symbol *symbol, unsigned char source[], int length); /* TNT KIX Code */
|
2017-05-29 21:43:47 +12:00
|
|
|
extern int aztec(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* Aztec Code */
|
2009-11-23 04:38:15 +13:00
|
|
|
extern int code32(struct zint_symbol *symbol, unsigned char source[], int length); /* Italian Pharmacode */
|
|
|
|
extern int daft_code(struct zint_symbol *symbol, unsigned char source[], int length); /* DAFT Code */
|
|
|
|
extern int ean_14(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN-14 */
|
|
|
|
extern int nve_18(struct zint_symbol *symbol, unsigned char source[], int length); /* NVE-18 */
|
2017-05-29 21:43:47 +12:00
|
|
|
extern int microqr(struct zint_symbol *symbol, const unsigned char source[], size_t length); /* Micro QR Code */
|
2009-11-23 04:38:15 +13:00
|
|
|
extern int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length); /* Aztec Runes */
|
|
|
|
extern int korea_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Korea Post */
|
|
|
|
extern int japan_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Japanese Post */
|
2016-03-01 08:42:32 +13:00
|
|
|
extern int code_49(struct zint_symbol *symbol, unsigned char source[], const int length); /* Code 49 */
|
2009-11-23 04:38:15 +13:00
|
|
|
extern int channel_code(struct zint_symbol *symbol, unsigned char source[], int length); /* Channel Code */
|
|
|
|
extern int code_one(struct zint_symbol *symbol, unsigned char source[], int length); /* Code One */
|
2017-05-29 21:43:47 +12:00
|
|
|
extern int grid_matrix(struct zint_symbol *symbol, const unsigned char source[], size_t length); /* Grid Matrix */
|
|
|
|
extern int han_xin(struct zint_symbol * symbol, const unsigned char source[], size_t length); /* Han Xin */
|
2016-07-26 09:52:29 +12:00
|
|
|
extern int dotcode(struct zint_symbol * symbol, const unsigned char source[], int length); /* DotCode */
|
2017-05-29 21:43:47 +12:00
|
|
|
extern int codablock(struct zint_symbol * symbol, const unsigned char source[], const size_t length); /* Codablock */
|
2017-06-14 07:05:35 +12:00
|
|
|
extern int upnqr(struct zint_symbol *symbol, const unsigned char source[], size_t length); /* UPNQR */
|
2018-02-04 07:44:01 +13:00
|
|
|
extern int qr_code(struct zint_symbol *symbol, const unsigned char source[], size_t length); /* QR Code */
|
|
|
|
extern int dmatrix(struct zint_symbol *symbol, const unsigned char source[], const size_t in_length); /* Data Matrix (IEC16022) */
|
|
|
|
extern int vin(struct zint_symbol *symbol, const unsigned char source[], const size_t in_length); /* VIN Code (Vehicle Identification Number) */
|
2018-02-07 09:57:01 +13:00
|
|
|
extern int mailmark(struct zint_symbol *symbol, const unsigned char source[], const size_t in_length); /* Royal Mail 4-state Mailmark */
|
2019-03-21 22:14:24 +13:00
|
|
|
extern int ultracode(struct zint_symbol *symbol, const unsigned char source[], const size_t in_length); /* Ultracode */
|
2009-11-23 04:38:15 +13:00
|
|
|
|
2016-07-26 09:52:29 +12:00
|
|
|
extern int plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to PNG/BMP/PCX */
|
2018-06-18 13:36:40 +12:00
|
|
|
extern int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to EPS/EMF/SVG */
|
|
|
|
|
2016-07-20 10:02:39 +12:00
|
|
|
extern int render_plot(struct zint_symbol *symbol, float width, float height); /* Plot to gLabels */
|
2018-06-18 13:36:40 +12:00
|
|
|
|
2018-06-10 20:16:18 +12:00
|
|
|
//extern int ps_plot(struct zint_symbol *symbol); /* Plot to EPS */
|
|
|
|
//extern int svg_plot(struct zint_symbol *symbol); /* Plot to SVG */
|
2018-06-18 13:36:40 +12:00
|
|
|
//extern int emf_plot(struct zint_symbol *symbol); /* Plot to Metafile */
|
2009-11-23 04:38:15 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
void error_tag(char error_string[], int error_number) {
|
2013-01-01 02:41:59 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
if (error_number != 0) {
|
2017-09-11 03:03:09 +12:00
|
|
|
char error_buffer[100];
|
2016-02-20 23:50:15 +13:00
|
|
|
strcpy(error_buffer, error_string);
|
2013-01-01 02:41:59 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
if (error_number > 4) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(error_string, "Error ");
|
2016-02-20 23:50:15 +13:00
|
|
|
} else {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(error_string, "Warning ");
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
2013-01-01 02:41:59 +13:00
|
|
|
|
2016-03-03 10:12:38 +13:00
|
|
|
strcat(error_string, error_buffer);
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
2009-11-23 04:38:15 +13:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
/* Output a hexadecimal representation of the rendered symbol */
|
|
|
|
int dump_plot(struct zint_symbol *symbol) {
|
|
|
|
FILE *f;
|
|
|
|
int i, r;
|
|
|
|
char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8',
|
|
|
|
'9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
|
|
|
int space = 0;
|
2016-09-06 09:06:50 +12:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
if (symbol->output_options & BARCODE_STDOUT) {
|
|
|
|
f = stdout;
|
|
|
|
} else {
|
|
|
|
f = fopen(symbol->outfile, "w");
|
|
|
|
if (!f) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "201: Could not open output file");
|
2016-02-20 23:50:15 +13:00
|
|
|
return ZINT_ERROR_FILE_ACCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (r = 0; r < symbol->rows; r++) {
|
2017-09-11 03:03:09 +12:00
|
|
|
int byt = 0;
|
2016-02-20 23:50:15 +13:00
|
|
|
for (i = 0; i < symbol->width; i++) {
|
|
|
|
byt = byt << 1;
|
|
|
|
if (module_is_set(symbol, r, i)) {
|
|
|
|
byt += 1;
|
|
|
|
}
|
|
|
|
if (((i + 1) % 4) == 0) {
|
|
|
|
fputc(hex[byt], f);
|
|
|
|
space++;
|
2016-02-19 12:23:31 +13:00
|
|
|
byt = 0;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
if (space == 2) {
|
|
|
|
fputc(' ', f);
|
2016-02-19 12:23:31 +13:00
|
|
|
space = 0;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
}
|
2010-09-13 01:52:44 +12:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
if ((symbol->width % 4) != 0) {
|
|
|
|
byt = byt << (4 - (symbol->width % 4));
|
|
|
|
fputc(hex[byt], f);
|
|
|
|
}
|
|
|
|
fputs("\n", f);
|
|
|
|
space = 0;
|
|
|
|
}
|
2010-09-13 01:52:44 +12:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
if (symbol->output_options & BARCODE_STDOUT) {
|
|
|
|
fflush(f);
|
|
|
|
} else {
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2010-09-13 01:52:44 +12:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
/* Process health industry bar code data */
|
2016-09-06 09:06:50 +12:00
|
|
|
static int hibc(struct zint_symbol *symbol, unsigned char source[], size_t length) {
|
2017-05-29 21:43:47 +12:00
|
|
|
size_t i;
|
|
|
|
int counter, error_number;
|
2016-10-27 06:34:21 +13:00
|
|
|
char to_process[113], temp[2], check_digit;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
2016-10-27 06:34:21 +13:00
|
|
|
/* without "+" and check: max 110 characters in HIBC 2.6 */
|
|
|
|
if (length > 110) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "202: Data too long for HIBC LIC");
|
2016-02-20 23:50:15 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
|
|
|
to_upper(source);
|
|
|
|
error_number = is_sane(TECHNETIUM, source, length);
|
|
|
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "203: Invalid characters in data");
|
2016-02-20 23:50:15 +13:00
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(to_process, "+");
|
|
|
|
counter = 41;
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
counter += posn(TECHNETIUM, source[i]);
|
|
|
|
}
|
|
|
|
counter = counter % 43;
|
|
|
|
|
|
|
|
if (counter < 10) {
|
|
|
|
check_digit = itoc(counter);
|
|
|
|
} else {
|
|
|
|
if (counter < 36) {
|
|
|
|
check_digit = (counter - 10) + 'A';
|
|
|
|
} else {
|
|
|
|
switch (counter) {
|
|
|
|
case 36: check_digit = '-';
|
|
|
|
break;
|
|
|
|
case 37: check_digit = '.';
|
|
|
|
break;
|
|
|
|
case 38: check_digit = ' ';
|
|
|
|
break;
|
|
|
|
case 39: check_digit = '$';
|
|
|
|
break;
|
|
|
|
case 40: check_digit = '/';
|
|
|
|
break;
|
|
|
|
case 41: check_digit = '+';
|
|
|
|
break;
|
|
|
|
case 42: check_digit = '%';
|
|
|
|
break;
|
|
|
|
default: check_digit = ' ';
|
|
|
|
break; /* Keep compiler happy */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
temp[0] = check_digit;
|
|
|
|
temp[1] = '\0';
|
|
|
|
|
2016-03-03 10:12:38 +13:00
|
|
|
strcat(to_process, (char *) source);
|
|
|
|
strcat(to_process, temp);
|
2016-02-20 23:50:15 +13:00
|
|
|
length = strlen(to_process);
|
|
|
|
|
|
|
|
switch (symbol->symbology) {
|
|
|
|
case BARCODE_HIBC_128:
|
|
|
|
error_number = code_128(symbol, (unsigned char *) to_process, length);
|
|
|
|
ustrcpy(symbol->text, (unsigned char*) "*");
|
2016-03-03 10:12:38 +13:00
|
|
|
strcat((char*) symbol->text, to_process);
|
|
|
|
strcat((char*) symbol->text, "*");
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
|
|
|
case BARCODE_HIBC_39:
|
|
|
|
symbol->option_2 = 0;
|
|
|
|
error_number = c39(symbol, (unsigned char *) to_process, length);
|
|
|
|
ustrcpy(symbol->text, (unsigned char*) "*");
|
2016-03-03 10:12:38 +13:00
|
|
|
strcat((char*) symbol->text, to_process);
|
|
|
|
strcat((char*) symbol->text, "*");
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
|
|
|
case BARCODE_HIBC_DM:
|
|
|
|
error_number = dmatrix(symbol, (unsigned char *) to_process, length);
|
|
|
|
break;
|
|
|
|
case BARCODE_HIBC_QR:
|
|
|
|
error_number = qr_code(symbol, (unsigned char *) to_process, length);
|
|
|
|
break;
|
|
|
|
case BARCODE_HIBC_PDF:
|
|
|
|
error_number = pdf417enc(symbol, (unsigned char *) to_process, length);
|
|
|
|
break;
|
|
|
|
case BARCODE_HIBC_MICPDF:
|
|
|
|
error_number = micro_pdf417(symbol, (unsigned char *) to_process, length);
|
|
|
|
break;
|
|
|
|
case BARCODE_HIBC_AZTEC:
|
|
|
|
error_number = aztec(symbol, (unsigned char *) to_process, length);
|
|
|
|
break;
|
2016-08-25 06:37:49 +12:00
|
|
|
case BARCODE_HIBC_BLOCKF:
|
|
|
|
error_number = codablock(symbol, (unsigned char *) to_process, length);
|
|
|
|
break;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
return error_number;
|
2009-11-23 04:38:15 +13:00
|
|
|
}
|
|
|
|
|
2016-09-15 09:34:59 +12:00
|
|
|
static void check_row_heights(struct zint_symbol *symbol) {
|
|
|
|
/* Check that rows with undefined heights are never less than 5x */
|
2016-09-17 22:39:01 +12:00
|
|
|
int large_bar_count = 0;
|
2016-09-15 09:34:59 +12:00
|
|
|
int i;
|
2016-09-17 22:39:01 +12:00
|
|
|
int preset_height = 0;
|
|
|
|
int large_bar_height = 0;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-09-15 09:34:59 +12:00
|
|
|
for (i = 0; i < symbol->rows; i++) {
|
|
|
|
preset_height += symbol->row_height[i];
|
|
|
|
if (symbol->row_height[i] == 0) {
|
|
|
|
large_bar_count++;
|
|
|
|
}
|
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-09-15 09:34:59 +12:00
|
|
|
if (large_bar_count == 0) {
|
|
|
|
symbol->height = preset_height;
|
2016-09-17 22:39:01 +12:00
|
|
|
} else {
|
|
|
|
large_bar_height = (symbol->height - preset_height) / large_bar_count;
|
2016-09-15 09:34:59 +12:00
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-09-15 09:34:59 +12:00
|
|
|
if (large_bar_height < 5) {
|
|
|
|
for (i = 0; i < symbol->rows; i++) {
|
|
|
|
if (symbol->row_height[i] == 0) {
|
|
|
|
symbol->row_height[i] = 5;
|
|
|
|
preset_height += 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
symbol->height = preset_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-01 08:42:32 +13:00
|
|
|
static int gs1_compliant(const int symbology) {
|
2016-02-20 23:50:15 +13:00
|
|
|
/* Returns 1 if symbology supports GS1 data */
|
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
switch (symbology) {
|
|
|
|
case BARCODE_EAN128:
|
|
|
|
case BARCODE_RSS_EXP:
|
|
|
|
case BARCODE_RSS_EXPSTACK:
|
|
|
|
case BARCODE_EANX_CC:
|
|
|
|
case BARCODE_EAN128_CC:
|
|
|
|
case BARCODE_RSS14_CC:
|
|
|
|
case BARCODE_RSS_LTD_CC:
|
|
|
|
case BARCODE_RSS_EXP_CC:
|
|
|
|
case BARCODE_UPCA_CC:
|
|
|
|
case BARCODE_UPCE_CC:
|
|
|
|
case BARCODE_RSS14STACK_CC:
|
|
|
|
case BARCODE_RSS14_OMNI_CC:
|
|
|
|
case BARCODE_RSS_EXPSTACK_CC:
|
|
|
|
case BARCODE_CODE16K:
|
|
|
|
case BARCODE_AZTEC:
|
|
|
|
case BARCODE_DATAMATRIX:
|
|
|
|
case BARCODE_CODEONE:
|
|
|
|
case BARCODE_CODE49:
|
|
|
|
case BARCODE_QRCODE:
|
2016-07-26 09:52:29 +12:00
|
|
|
case BARCODE_DOTCODE:
|
2016-02-20 23:50:15 +13:00
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2009-11-23 04:38:15 +13:00
|
|
|
}
|
|
|
|
|
2016-08-13 06:30:46 +12:00
|
|
|
static int is_matrix(const int symbology) {
|
|
|
|
/* Returns 1 if symbology is a matrix design */
|
2016-09-06 09:06:50 +12:00
|
|
|
|
2016-08-13 06:30:46 +12:00
|
|
|
int result = 0;
|
2016-09-06 09:06:50 +12:00
|
|
|
|
2016-08-13 06:30:46 +12:00
|
|
|
switch (symbology) {
|
|
|
|
case BARCODE_QRCODE:
|
|
|
|
case BARCODE_DATAMATRIX:
|
|
|
|
case BARCODE_MICROQR:
|
|
|
|
case BARCODE_HIBC_DM:
|
|
|
|
case BARCODE_AZTEC:
|
|
|
|
case BARCODE_HIBC_QR:
|
|
|
|
case BARCODE_HIBC_AZTEC:
|
|
|
|
case BARCODE_AZRUNE:
|
|
|
|
case BARCODE_CODEONE:
|
|
|
|
case BARCODE_GRIDMATRIX:
|
|
|
|
case BARCODE_HANXIN:
|
|
|
|
case BARCODE_DOTCODE:
|
2017-05-21 10:37:50 +12:00
|
|
|
case BARCODE_UPNQR:
|
2016-08-13 06:30:46 +12:00
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
}
|
2016-09-06 09:06:50 +12:00
|
|
|
|
2016-08-13 06:30:46 +12:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-08-16 23:43:41 +12:00
|
|
|
static int supports_eci(const int symbology) {
|
|
|
|
/* Returns 1 if symbology can encode the ECI character */
|
2016-09-06 09:06:50 +12:00
|
|
|
|
2016-08-16 23:43:41 +12:00
|
|
|
int result = 0;
|
2016-09-06 09:06:50 +12:00
|
|
|
|
2016-08-16 23:43:41 +12:00
|
|
|
switch (symbology) {
|
|
|
|
case BARCODE_AZTEC:
|
|
|
|
case BARCODE_DATAMATRIX:
|
|
|
|
case BARCODE_MAXICODE:
|
|
|
|
case BARCODE_MICROPDF417:
|
|
|
|
case BARCODE_PDF417:
|
|
|
|
case BARCODE_PDF417TRUNC:
|
|
|
|
case BARCODE_QRCODE:
|
|
|
|
case BARCODE_DOTCODE:
|
|
|
|
case BARCODE_GRIDMATRIX:
|
|
|
|
case BARCODE_HANXIN:
|
2019-03-21 22:14:24 +13:00
|
|
|
case BARCODE_ULTRA:
|
2016-08-16 23:43:41 +12:00
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
}
|
2016-09-06 09:06:50 +12:00
|
|
|
|
2016-08-16 23:43:41 +12:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
int ZBarcode_ValidID(int symbol_id) {
|
|
|
|
/* Checks whether a symbology is supported */
|
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
switch (symbol_id) {
|
|
|
|
case BARCODE_CODE11:
|
|
|
|
case BARCODE_C25MATRIX:
|
|
|
|
case BARCODE_C25INTER:
|
|
|
|
case BARCODE_C25IATA:
|
|
|
|
case BARCODE_C25LOGIC:
|
|
|
|
case BARCODE_C25IND:
|
|
|
|
case BARCODE_CODE39:
|
|
|
|
case BARCODE_EXCODE39:
|
|
|
|
case BARCODE_EANX:
|
2016-10-29 07:43:08 +13:00
|
|
|
case BARCODE_EANX_CHK:
|
2016-02-20 23:50:15 +13:00
|
|
|
case BARCODE_EAN128:
|
|
|
|
case BARCODE_CODABAR:
|
|
|
|
case BARCODE_CODE128:
|
|
|
|
case BARCODE_DPLEIT:
|
|
|
|
case BARCODE_DPIDENT:
|
|
|
|
case BARCODE_CODE16K:
|
|
|
|
case BARCODE_CODE49:
|
|
|
|
case BARCODE_CODE93:
|
|
|
|
case BARCODE_FLAT:
|
|
|
|
case BARCODE_RSS14:
|
|
|
|
case BARCODE_RSS_LTD:
|
|
|
|
case BARCODE_RSS_EXP:
|
|
|
|
case BARCODE_TELEPEN:
|
|
|
|
case BARCODE_UPCA:
|
2016-10-29 07:43:08 +13:00
|
|
|
case BARCODE_UPCA_CHK:
|
2016-02-20 23:50:15 +13:00
|
|
|
case BARCODE_UPCE:
|
2016-10-29 07:43:08 +13:00
|
|
|
case BARCODE_UPCE_CHK:
|
2016-02-20 23:50:15 +13:00
|
|
|
case BARCODE_POSTNET:
|
|
|
|
case BARCODE_MSI_PLESSEY:
|
|
|
|
case BARCODE_FIM:
|
|
|
|
case BARCODE_LOGMARS:
|
|
|
|
case BARCODE_PHARMA:
|
|
|
|
case BARCODE_PZN:
|
|
|
|
case BARCODE_PHARMA_TWO:
|
|
|
|
case BARCODE_PDF417:
|
|
|
|
case BARCODE_PDF417TRUNC:
|
|
|
|
case BARCODE_MAXICODE:
|
|
|
|
case BARCODE_QRCODE:
|
|
|
|
case BARCODE_CODE128B:
|
|
|
|
case BARCODE_AUSPOST:
|
|
|
|
case BARCODE_AUSREPLY:
|
|
|
|
case BARCODE_AUSROUTE:
|
|
|
|
case BARCODE_AUSREDIRECT:
|
|
|
|
case BARCODE_ISBNX:
|
|
|
|
case BARCODE_RM4SCC:
|
|
|
|
case BARCODE_DATAMATRIX:
|
|
|
|
case BARCODE_EAN14:
|
|
|
|
case BARCODE_NVE18:
|
|
|
|
case BARCODE_JAPANPOST:
|
|
|
|
case BARCODE_KOREAPOST:
|
|
|
|
case BARCODE_RSS14STACK:
|
|
|
|
case BARCODE_RSS14STACK_OMNI:
|
|
|
|
case BARCODE_RSS_EXPSTACK:
|
|
|
|
case BARCODE_PLANET:
|
|
|
|
case BARCODE_MICROPDF417:
|
|
|
|
case BARCODE_ONECODE:
|
|
|
|
case BARCODE_PLESSEY:
|
|
|
|
case BARCODE_TELEPEN_NUM:
|
|
|
|
case BARCODE_ITF14:
|
|
|
|
case BARCODE_KIX:
|
|
|
|
case BARCODE_AZTEC:
|
|
|
|
case BARCODE_DAFT:
|
|
|
|
case BARCODE_MICROQR:
|
|
|
|
case BARCODE_HIBC_128:
|
|
|
|
case BARCODE_HIBC_39:
|
|
|
|
case BARCODE_HIBC_DM:
|
|
|
|
case BARCODE_HIBC_QR:
|
|
|
|
case BARCODE_HIBC_PDF:
|
|
|
|
case BARCODE_HIBC_MICPDF:
|
|
|
|
case BARCODE_HIBC_AZTEC:
|
2016-08-25 06:37:49 +12:00
|
|
|
case BARCODE_HIBC_BLOCKF:
|
2016-02-20 23:50:15 +13:00
|
|
|
case BARCODE_AZRUNE:
|
|
|
|
case BARCODE_CODE32:
|
|
|
|
case BARCODE_EANX_CC:
|
|
|
|
case BARCODE_EAN128_CC:
|
|
|
|
case BARCODE_RSS14_CC:
|
|
|
|
case BARCODE_RSS_LTD_CC:
|
|
|
|
case BARCODE_RSS_EXP_CC:
|
|
|
|
case BARCODE_UPCA_CC:
|
|
|
|
case BARCODE_UPCE_CC:
|
|
|
|
case BARCODE_RSS14STACK_CC:
|
|
|
|
case BARCODE_RSS14_OMNI_CC:
|
|
|
|
case BARCODE_RSS_EXPSTACK_CC:
|
|
|
|
case BARCODE_CHANNEL:
|
|
|
|
case BARCODE_CODEONE:
|
|
|
|
case BARCODE_GRIDMATRIX:
|
2016-04-08 04:13:43 +12:00
|
|
|
case BARCODE_HANXIN:
|
2016-07-26 09:52:29 +12:00
|
|
|
case BARCODE_DOTCODE:
|
2016-09-13 08:47:40 +12:00
|
|
|
case BARCODE_CODABLOCKF:
|
2017-05-21 10:37:50 +12:00
|
|
|
case BARCODE_UPNQR:
|
2018-02-04 07:44:01 +13:00
|
|
|
case BARCODE_VIN:
|
2018-02-07 09:57:01 +13:00
|
|
|
case BARCODE_MAILMARK:
|
2019-03-21 22:14:24 +13:00
|
|
|
case BARCODE_ULTRA:
|
2016-02-20 23:50:15 +13:00
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2009-11-23 04:38:15 +13:00
|
|
|
}
|
|
|
|
|
2016-03-01 08:42:32 +13:00
|
|
|
static int extended_charset(struct zint_symbol *symbol, const unsigned char *source, const int length) {
|
2016-02-20 23:50:15 +13:00
|
|
|
int error_number = 0;
|
2018-04-23 01:25:39 +12:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
/* These are the "elite" standards which can support multiple character sets */
|
|
|
|
switch (symbol->symbology) {
|
|
|
|
case BARCODE_QRCODE: error_number = qr_code(symbol, source, length);
|
|
|
|
break;
|
|
|
|
case BARCODE_MICROQR: error_number = microqr(symbol, source, length);
|
|
|
|
break;
|
|
|
|
case BARCODE_GRIDMATRIX: error_number = grid_matrix(symbol, source, length);
|
|
|
|
break;
|
2016-04-08 04:13:43 +12:00
|
|
|
case BARCODE_HANXIN: error_number = han_xin(symbol, source, length);
|
|
|
|
break;
|
2017-05-21 10:37:50 +12:00
|
|
|
case BARCODE_UPNQR: error_number = upnqr(symbol, source, length);
|
|
|
|
break;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
2009-11-23 04:38:15 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
return error_number;
|
2009-11-23 04:38:15 +13:00
|
|
|
}
|
|
|
|
|
2017-06-14 07:05:35 +12:00
|
|
|
static int reduced_charset(struct zint_symbol *symbol, const unsigned char *source, size_t in_length) {
|
2016-02-20 23:50:15 +13:00
|
|
|
/* These are the "norm" standards which only support Latin-1 at most */
|
|
|
|
int error_number = 0;
|
|
|
|
|
2009-11-23 04:38:15 +13:00
|
|
|
#ifndef _MSC_VER
|
2016-09-06 09:06:50 +12:00
|
|
|
unsigned char preprocessed[in_length + 1];
|
2009-11-23 04:38:15 +13:00
|
|
|
#else
|
2016-09-06 09:06:50 +12:00
|
|
|
unsigned char* preprocessed = (unsigned char*) _alloca(in_length + 1);
|
2009-11-23 04:38:15 +13:00
|
|
|
#endif
|
2018-04-23 01:25:39 +12:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
if (symbol->symbology == BARCODE_CODE16K) {
|
|
|
|
symbol->whitespace_width = 16;
|
|
|
|
symbol->border_width = 2;
|
2016-08-27 02:13:40 +12:00
|
|
|
if (!(symbol->output_options & BARCODE_BIND)) {
|
|
|
|
symbol->output_options += BARCODE_BIND;
|
|
|
|
}
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
2016-09-06 09:06:50 +12:00
|
|
|
else
|
|
|
|
if (symbol->symbology == BARCODE_ITF14) {
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->whitespace_width = 20;
|
|
|
|
symbol->border_width = 8;
|
2016-08-27 02:13:40 +12:00
|
|
|
if (!(symbol->output_options & BARCODE_BOX)) {
|
|
|
|
symbol->output_options += BARCODE_BOX;
|
|
|
|
}
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
2018-04-23 01:25:39 +12:00
|
|
|
|
|
|
|
switch (symbol->input_mode & 0x07) {
|
2016-02-20 23:50:15 +13:00
|
|
|
case DATA_MODE:
|
|
|
|
case GS1_MODE:
|
2016-09-06 09:06:50 +12:00
|
|
|
memcpy(preprocessed, source, in_length);
|
|
|
|
preprocessed[in_length] = '\0';
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
|
|
|
case UNICODE_MODE:
|
2016-09-06 09:06:50 +12:00
|
|
|
error_number = utf_to_eci(symbol->eci, source, preprocessed, &in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
if (error_number != 0) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "204: Invalid characters in input data");
|
2016-02-20 23:50:15 +13:00
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-04-23 01:25:39 +12:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
switch (symbol->symbology) {
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_C25MATRIX: error_number = matrix_two_of_five(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_C25IND: error_number = industrial_two_of_five(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_C25INTER: error_number = interleaved_two_of_five(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_C25IATA: error_number = iata_two_of_five(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_C25LOGIC: error_number = logic_two_of_five(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_DPLEIT: error_number = dpleit(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_DPIDENT: error_number = dpident(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2017-10-24 08:37:52 +13:00
|
|
|
case BARCODE_UPCA:
|
2016-10-29 07:43:08 +13:00
|
|
|
case BARCODE_UPCA_CHK:
|
2017-10-24 08:37:52 +13:00
|
|
|
case BARCODE_UPCE:
|
2016-10-29 07:43:08 +13:00
|
|
|
case BARCODE_UPCE_CHK:
|
2017-10-24 08:37:52 +13:00
|
|
|
case BARCODE_EANX:
|
2016-10-29 07:43:08 +13:00
|
|
|
case BARCODE_EANX_CHK:
|
|
|
|
error_number = eanx(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_EAN128: error_number = ean_128(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_CODE39: error_number = c39(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_PZN: error_number = pharmazentral(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_EXCODE39: error_number = ec39(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_CODABAR: error_number = codabar(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_CODE93: error_number = c93(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_LOGMARS: error_number = c39(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-10-29 07:43:08 +13:00
|
|
|
case BARCODE_CODE128:
|
2017-10-24 08:37:52 +13:00
|
|
|
case BARCODE_CODE128B:
|
2016-10-29 07:43:08 +13:00
|
|
|
error_number = code_128(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_NVE18: error_number = nve_18(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_CODE11: error_number = code_11(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_MSI_PLESSEY: error_number = msi_handle(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_TELEPEN: error_number = telepen(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_TELEPEN_NUM: error_number = telepen_num(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_PHARMA: error_number = pharma_one(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_PLESSEY: error_number = plessey(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_ITF14: error_number = itf14(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_FLAT: error_number = flattermarken(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_FIM: error_number = fim(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_POSTNET: error_number = post_plot(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_PLANET: error_number = planet_plot(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_RM4SCC: error_number = royal_plot(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-10-29 07:43:08 +13:00
|
|
|
case BARCODE_AUSPOST:
|
2017-10-24 08:37:52 +13:00
|
|
|
case BARCODE_AUSREPLY:
|
2016-10-29 07:43:08 +13:00
|
|
|
case BARCODE_AUSROUTE:
|
|
|
|
case BARCODE_AUSREDIRECT:
|
|
|
|
error_number = australia_post(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_CODE16K: error_number = code16k(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_PHARMA_TWO: error_number = pharma_two(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_ONECODE: error_number = imail(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_ISBNX: error_number = eanx(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-10-29 07:43:08 +13:00
|
|
|
case BARCODE_RSS14:
|
2017-10-24 08:37:52 +13:00
|
|
|
case BARCODE_RSS14STACK:
|
|
|
|
case BARCODE_RSS14STACK_OMNI:
|
2016-10-29 07:43:08 +13:00
|
|
|
error_number = rss14(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_RSS_LTD: error_number = rsslimited(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2017-10-24 08:37:52 +13:00
|
|
|
case BARCODE_RSS_EXP:
|
|
|
|
case BARCODE_RSS_EXPSTACK:
|
2016-10-29 07:43:08 +13:00
|
|
|
error_number = rssexpanded(symbol, preprocessed, in_length);
|
|
|
|
break;
|
2017-10-24 08:37:52 +13:00
|
|
|
case BARCODE_EANX_CC:
|
|
|
|
case BARCODE_EAN128_CC:
|
|
|
|
case BARCODE_RSS14_CC:
|
|
|
|
case BARCODE_RSS_LTD_CC:
|
|
|
|
case BARCODE_RSS_EXP_CC:
|
|
|
|
case BARCODE_UPCA_CC:
|
|
|
|
case BARCODE_UPCE_CC:
|
|
|
|
case BARCODE_RSS14STACK_CC:
|
|
|
|
case BARCODE_RSS14_OMNI_CC:
|
|
|
|
case BARCODE_RSS_EXPSTACK_CC:
|
2016-10-29 07:43:08 +13:00
|
|
|
error_number = composite(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_KIX: error_number = kix_code(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_CODE32: error_number = code32(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_DAFT: error_number = daft_code(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-10-29 07:43:08 +13:00
|
|
|
case BARCODE_EAN14:
|
|
|
|
error_number = ean_14(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_AZRUNE: error_number = aztec_runes(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_KOREAPOST: error_number = korea_post(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2017-10-24 08:37:52 +13:00
|
|
|
case BARCODE_HIBC_128:
|
|
|
|
case BARCODE_HIBC_39:
|
|
|
|
case BARCODE_HIBC_DM:
|
|
|
|
case BARCODE_HIBC_QR:
|
|
|
|
case BARCODE_HIBC_PDF:
|
|
|
|
case BARCODE_HIBC_MICPDF:
|
|
|
|
case BARCODE_HIBC_AZTEC:
|
|
|
|
case BARCODE_HIBC_BLOCKF:
|
2016-10-29 07:43:08 +13:00
|
|
|
error_number = hibc(symbol, preprocessed, in_length);
|
2016-08-25 06:37:49 +12:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_JAPANPOST: error_number = japan_post(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_CODE49: error_number = code_49(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_CHANNEL: error_number = channel_code(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_CODEONE: error_number = code_one(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_DATAMATRIX: error_number = dmatrix(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2017-10-24 08:37:52 +13:00
|
|
|
case BARCODE_PDF417:
|
|
|
|
case BARCODE_PDF417TRUNC:
|
2016-10-29 07:43:08 +13:00
|
|
|
error_number = pdf417enc(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_MICROPDF417: error_number = micro_pdf417(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_MAXICODE: error_number = maxicode(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_AZTEC: error_number = aztec(symbol, preprocessed, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2016-09-06 09:06:50 +12:00
|
|
|
case BARCODE_DOTCODE: error_number = dotcode(symbol, preprocessed, in_length);
|
2016-07-26 09:52:29 +12:00
|
|
|
break;
|
2016-09-13 08:47:40 +12:00
|
|
|
case BARCODE_CODABLOCKF: error_number = codablock(symbol, preprocessed, in_length);
|
2016-08-25 06:37:49 +12:00
|
|
|
break;
|
2018-02-04 07:44:01 +13:00
|
|
|
case BARCODE_VIN: error_number = vin(symbol, preprocessed, in_length);
|
|
|
|
break;
|
2018-02-07 09:57:01 +13:00
|
|
|
case BARCODE_MAILMARK: error_number = mailmark(symbol, preprocessed, in_length);
|
|
|
|
break;
|
2019-03-21 22:14:24 +13:00
|
|
|
case BARCODE_ULTRA: error_number = ultracode(symbol, preprocessed, in_length);
|
|
|
|
break;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
return error_number;
|
2009-11-23 04:38:15 +13:00
|
|
|
}
|
|
|
|
|
2017-10-10 07:59:02 +13:00
|
|
|
void strip_bom(unsigned char *source, int *input_length) {
|
|
|
|
int i;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2017-10-10 07:59:02 +13:00
|
|
|
if (*input_length > 3) {
|
|
|
|
if((source[0] == 0xef) && (source[1] == 0xbb) && (source[2] == 0xbf)) {
|
|
|
|
/* BOM at start of input data, strip in accordance with RFC 3629 */
|
|
|
|
for (i = 3; i < *input_length; i++) {
|
|
|
|
source[i - 3] = source[i];
|
|
|
|
}
|
2017-10-18 20:25:09 +13:00
|
|
|
*input_length -= 3;
|
2017-10-10 07:59:02 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-22 00:45:50 +13:00
|
|
|
int escape_char_process(struct zint_symbol *symbol, unsigned char *input_string, int *length) {
|
|
|
|
int error_number;
|
|
|
|
int in_posn, out_posn;
|
|
|
|
int hex1, hex2;
|
|
|
|
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
unsigned char escaped_string[*length + 1];
|
|
|
|
#else
|
2018-01-15 05:47:02 +13:00
|
|
|
unsigned char* escaped_string = (unsigned char*) _alloca(*length + 1);
|
2017-10-22 00:45:50 +13:00
|
|
|
#endif
|
|
|
|
|
|
|
|
in_posn = 0;
|
|
|
|
out_posn = 0;
|
2018-04-23 01:25:39 +12:00
|
|
|
|
2017-10-22 00:45:50 +13:00
|
|
|
do {
|
|
|
|
if (input_string[in_posn] == '\\') {
|
|
|
|
switch (input_string[in_posn + 1]) {
|
|
|
|
case '0': escaped_string[out_posn] = 0x00; /* Null */
|
|
|
|
in_posn += 2;
|
|
|
|
break;
|
|
|
|
case 'E': escaped_string[out_posn] = 0x04; /* End of Transmission */
|
|
|
|
in_posn += 2;
|
|
|
|
break;
|
|
|
|
case 'a': escaped_string[out_posn] = 0x07; /* Bell */
|
|
|
|
in_posn += 2;
|
|
|
|
break;
|
|
|
|
case 'b': escaped_string[out_posn] = 0x08; /* Backspace */
|
|
|
|
in_posn += 2;
|
|
|
|
break;
|
|
|
|
case 't': escaped_string[out_posn] = 0x09; /* Horizontal tab */
|
|
|
|
in_posn += 2;
|
|
|
|
break;
|
|
|
|
case 'n': escaped_string[out_posn] = 0x0a; /* Line feed */
|
|
|
|
in_posn += 2;
|
|
|
|
break;
|
|
|
|
case 'v': escaped_string[out_posn] = 0x0b; /* Vertical tab */
|
|
|
|
in_posn += 2;
|
|
|
|
break;
|
|
|
|
case 'f': escaped_string[out_posn] = 0x0c; /* Form feed */
|
|
|
|
in_posn += 2;
|
|
|
|
break;
|
|
|
|
case 'r': escaped_string[out_posn] = 0x0d; /* Carriage return */
|
|
|
|
in_posn += 2;
|
|
|
|
break;
|
|
|
|
case 'e': escaped_string[out_posn] = 0x1b; /* Escape */
|
|
|
|
in_posn += 2;
|
|
|
|
break;
|
|
|
|
case 'G': escaped_string[out_posn] = 0x1d; /* Group Separator */
|
|
|
|
in_posn += 2;
|
|
|
|
break;
|
|
|
|
case 'R': escaped_string[out_posn] = 0x1e; /* Record Separator */
|
|
|
|
in_posn += 2;
|
|
|
|
break;
|
|
|
|
case 'x': if (in_posn + 4 > *length) {
|
|
|
|
strcpy(symbol->errtxt, "232: Incomplete escape character in input data");
|
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
hex1 = ctoi(input_string[in_posn + 2]);
|
|
|
|
hex2 = ctoi(input_string[in_posn + 3]);
|
|
|
|
if ((hex1 >= 0) && (hex2 >= 0)) {
|
2018-04-23 01:25:39 +12:00
|
|
|
if (hex1 > 7 && (symbol->input_mode & UNICODE_MODE) != 0) {
|
|
|
|
// Convert to UTF-8
|
|
|
|
escaped_string[out_posn] = 0xc0 + (hex1 >> 2);
|
|
|
|
out_posn++;
|
|
|
|
escaped_string[out_posn] = 0x80 + ((hex1 & 0x03) << 4) + hex2;
|
|
|
|
} else {
|
|
|
|
escaped_string[out_posn] = (hex1 << 4) + hex2;
|
|
|
|
}
|
2017-10-22 00:45:50 +13:00
|
|
|
in_posn += 4;
|
|
|
|
} else {
|
|
|
|
strcpy(symbol->errtxt, "233: Corrupt escape character in input data");
|
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '\\': escaped_string[out_posn] = '\\';
|
|
|
|
in_posn += 2;
|
|
|
|
break;
|
|
|
|
default: strcpy(symbol->errtxt, "234: Unrecognised escape character in input data");
|
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
escaped_string[out_posn] = input_string[in_posn];
|
|
|
|
in_posn++;
|
|
|
|
}
|
|
|
|
out_posn++;
|
|
|
|
} while (in_posn < *length);
|
2018-04-23 01:25:39 +12:00
|
|
|
|
2017-10-22 00:45:50 +13:00
|
|
|
memcpy(input_string, escaped_string, out_posn);
|
2018-01-14 04:45:26 +13:00
|
|
|
input_string[out_posn] = '\0';
|
2017-10-22 00:45:50 +13:00
|
|
|
*length = out_posn;
|
2018-04-23 01:25:39 +12:00
|
|
|
|
2017-10-22 00:45:50 +13:00
|
|
|
error_number = 0;
|
|
|
|
|
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int in_length) {
|
2016-02-20 23:50:15 +13:00
|
|
|
int error_number, error_buffer, i;
|
2018-03-30 23:40:44 +13:00
|
|
|
int input_mode = symbol->input_mode;
|
2015-08-18 23:50:42 +12:00
|
|
|
#ifdef _MSC_VER
|
2016-02-20 23:50:15 +13:00
|
|
|
unsigned char* local_source;
|
2015-08-18 23:50:42 +12:00
|
|
|
#endif
|
2016-02-20 23:50:15 +13:00
|
|
|
error_number = 0;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2019-09-02 07:23:15 +12:00
|
|
|
if (in_length <= 0) {
|
2017-05-29 21:43:47 +12:00
|
|
|
in_length = (int)ustrlen(source);
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
2019-09-02 07:23:15 +12:00
|
|
|
if (in_length <= 0) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "205: No input data");
|
2016-02-20 23:50:15 +13:00
|
|
|
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_DATA);
|
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(symbol->outfile, "") == 0) {
|
2016-08-26 22:44:02 +12:00
|
|
|
#ifdef NO_PNG
|
|
|
|
strcpy(symbol->outfile, "out.gif");
|
2017-10-24 08:37:52 +13:00
|
|
|
#else
|
2016-02-20 23:50:15 +13:00
|
|
|
strcpy(symbol->outfile, "out.png");
|
2016-08-26 22:44:02 +12:00
|
|
|
#endif
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
2009-11-23 04:38:15 +13:00
|
|
|
#ifndef _MSC_VER
|
2017-05-29 21:43:47 +12:00
|
|
|
unsigned char local_source[in_length + 1];
|
2009-11-23 04:38:15 +13:00
|
|
|
#else
|
2017-05-29 21:43:47 +12:00
|
|
|
local_source = (unsigned char*) _alloca(in_length + 1);
|
2009-11-23 04:38:15 +13:00
|
|
|
#endif
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
/* First check the symbology field */
|
|
|
|
if (symbol->symbology < 1) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "206: Symbology out of range, using Code 128");
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->symbology = BARCODE_CODE128;
|
|
|
|
error_number = ZINT_WARN_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* symbol->symbologys 1 to 86 are defined by tbarcode */
|
|
|
|
if (symbol->symbology == 5) {
|
|
|
|
symbol->symbology = BARCODE_C25MATRIX;
|
|
|
|
}
|
|
|
|
if ((symbol->symbology >= 10) && (symbol->symbology <= 12)) {
|
|
|
|
symbol->symbology = BARCODE_EANX;
|
|
|
|
}
|
2016-10-29 07:43:08 +13:00
|
|
|
if (symbol->symbology == 15) {
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->symbology = BARCODE_EANX;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 17) {
|
|
|
|
symbol->symbology = BARCODE_UPCA;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 19) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "207: Codabar 18 not supported, using Codabar");
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->symbology = BARCODE_CODABAR;
|
|
|
|
error_number = ZINT_WARN_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 26) {
|
|
|
|
symbol->symbology = BARCODE_UPCA;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 27) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "208: UPCD1 not supported");
|
2016-02-20 23:50:15 +13:00
|
|
|
error_number = ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 33) {
|
|
|
|
symbol->symbology = BARCODE_EAN128;
|
|
|
|
}
|
2016-10-29 07:43:08 +13:00
|
|
|
if (symbol->symbology == 36) {
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->symbology = BARCODE_UPCA;
|
|
|
|
}
|
|
|
|
if ((symbol->symbology >= 41) && (symbol->symbology <= 45)) {
|
|
|
|
symbol->symbology = BARCODE_POSTNET;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 46) {
|
|
|
|
symbol->symbology = BARCODE_PLESSEY;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 48) {
|
|
|
|
symbol->symbology = BARCODE_NVE18;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 54) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "210: General Parcel Code not supported, using Code 128");
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->symbology = BARCODE_CODE128;
|
|
|
|
error_number = ZINT_WARN_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
if ((symbol->symbology == 59) || (symbol->symbology == 61)) {
|
|
|
|
symbol->symbology = BARCODE_CODE128;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 62) {
|
|
|
|
symbol->symbology = BARCODE_CODE93;
|
|
|
|
}
|
|
|
|
if ((symbol->symbology == 64) || (symbol->symbology == 65)) {
|
|
|
|
symbol->symbology = BARCODE_AUSPOST;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 78) {
|
|
|
|
symbol->symbology = BARCODE_RSS14;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 83) {
|
|
|
|
symbol->symbology = BARCODE_PLANET;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 88) {
|
|
|
|
symbol->symbology = BARCODE_EAN128;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 91) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "212: Symbology out of range, using Code 128");
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->symbology = BARCODE_CODE128;
|
|
|
|
error_number = ZINT_WARN_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
if ((symbol->symbology >= 94) && (symbol->symbology <= 96)) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "213: Symbology out of range, using Code 128");
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->symbology = BARCODE_CODE128;
|
|
|
|
error_number = ZINT_WARN_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 100) {
|
|
|
|
symbol->symbology = BARCODE_HIBC_128;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 101) {
|
|
|
|
symbol->symbology = BARCODE_HIBC_39;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 103) {
|
|
|
|
symbol->symbology = BARCODE_HIBC_DM;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 105) {
|
|
|
|
symbol->symbology = BARCODE_HIBC_QR;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 107) {
|
|
|
|
symbol->symbology = BARCODE_HIBC_PDF;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 109) {
|
|
|
|
symbol->symbology = BARCODE_HIBC_MICPDF;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 111) {
|
|
|
|
symbol->symbology = BARCODE_HIBC_BLOCKF;
|
|
|
|
}
|
2016-04-08 04:13:43 +12:00
|
|
|
if ((symbol->symbology == 113) || (symbol->symbology == 114)) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "214: Symbology out of range, using Code 128");
|
2016-04-08 04:13:43 +12:00
|
|
|
symbol->symbology = BARCODE_CODE128;
|
|
|
|
error_number = ZINT_WARN_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
if (symbol->symbology == 115) {
|
2016-07-26 09:52:29 +12:00
|
|
|
symbol->symbology = BARCODE_DOTCODE;
|
2016-04-08 04:13:43 +12:00
|
|
|
}
|
|
|
|
if ((symbol->symbology >= 117) && (symbol->symbology <= 127)) {
|
2018-02-07 09:57:01 +13:00
|
|
|
if (symbol->symbology != 121) {
|
|
|
|
strcpy(symbol->errtxt, "215: Symbology out of range, using Code 128");
|
|
|
|
symbol->symbology = BARCODE_CODE128;
|
|
|
|
error_number = ZINT_WARN_INVALID_OPTION;
|
|
|
|
}
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
/* Everything from 128 up is Zint-specific */
|
2019-03-21 22:14:24 +13:00
|
|
|
if (symbol->symbology >= 145) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "216: Symbology out of range, using Code 128");
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->symbology = BARCODE_CODE128;
|
|
|
|
error_number = ZINT_WARN_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error_number > 4) {
|
|
|
|
error_tag(symbol->errtxt, error_number);
|
|
|
|
return error_number;
|
|
|
|
} else {
|
|
|
|
error_buffer = error_number;
|
|
|
|
}
|
2016-09-06 09:06:50 +12:00
|
|
|
|
2016-08-16 23:43:41 +12:00
|
|
|
if ((!(supports_eci(symbol->symbology))) && (symbol->eci != 3)) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "217: Symbology does not support ECI switching");
|
2016-08-16 23:43:41 +12:00
|
|
|
error_number = ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
2016-09-06 09:06:50 +12:00
|
|
|
|
2017-07-01 20:06:47 +12:00
|
|
|
if ((symbol->eci < 3) || (symbol->eci > 999999)) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "218: Invalid ECI mode");
|
2016-08-16 23:43:41 +12:00
|
|
|
error_number = ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
2016-02-20 23:50:15 +13:00
|
|
|
|
2017-10-22 00:45:50 +13:00
|
|
|
/* Start acting on input mode */
|
2018-03-30 23:40:44 +13:00
|
|
|
if (input_mode == GS1_MODE) {
|
2017-05-29 21:43:47 +12:00
|
|
|
for (i = 0; i < in_length; i++) {
|
2016-02-20 23:50:15 +13:00
|
|
|
if (source[i] == '\0') {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "219: NULL characters not permitted in GS1 mode");
|
2018-01-22 03:33:54 +13:00
|
|
|
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_DATA);
|
2016-02-20 23:50:15 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gs1_compliant(symbol->symbology) == 1) {
|
2017-05-29 21:43:47 +12:00
|
|
|
error_number = ugs1_verify(symbol, source, in_length, local_source);
|
2016-02-20 23:50:15 +13:00
|
|
|
if (error_number != 0) {
|
|
|
|
return error_number;
|
|
|
|
}
|
2017-05-29 21:43:47 +12:00
|
|
|
in_length =(int)ustrlen(local_source);
|
2016-02-20 23:50:15 +13:00
|
|
|
} else {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "220: Selected symbology does not support GS1 mode");
|
2018-01-22 03:33:54 +13:00
|
|
|
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION);
|
2016-02-20 23:50:15 +13:00
|
|
|
return ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
} else {
|
2017-05-29 21:43:47 +12:00
|
|
|
memcpy(local_source, source, in_length);
|
|
|
|
local_source[in_length] = '\0';
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2018-03-30 23:40:44 +13:00
|
|
|
if (input_mode & ESCAPE_MODE) {
|
2017-10-22 00:45:50 +13:00
|
|
|
error_number = escape_char_process(symbol, local_source, &in_length);
|
|
|
|
if (error_number != 0) {
|
2018-01-22 03:33:54 +13:00
|
|
|
error_tag(symbol->errtxt, error_number);
|
2017-10-22 00:45:50 +13:00
|
|
|
return error_number;
|
|
|
|
}
|
2018-03-30 23:40:44 +13:00
|
|
|
input_mode -= ESCAPE_MODE;
|
2017-10-22 00:45:50 +13:00
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2018-03-30 23:40:44 +13:00
|
|
|
if ((input_mode < 0) || (input_mode > 2)) {
|
|
|
|
input_mode = DATA_MODE;
|
2017-10-22 00:45:50 +13:00
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2017-10-22 00:45:50 +13:00
|
|
|
if ((symbol->eci != 3) && (symbol->eci != 26)) {
|
2018-03-30 23:40:44 +13:00
|
|
|
input_mode = DATA_MODE;
|
2017-10-22 00:45:50 +13:00
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2018-03-30 23:40:44 +13:00
|
|
|
if (input_mode == UNICODE_MODE) {
|
2017-10-10 07:59:02 +13:00
|
|
|
strip_bom(local_source, &in_length);
|
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-09-19 01:09:58 +12:00
|
|
|
if ((symbol->dot_size < 0.01) || (symbol->dot_size > 20.0)) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "221: Invalid dot size");
|
2018-01-22 03:33:54 +13:00
|
|
|
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION);
|
2016-09-19 01:09:58 +12:00
|
|
|
return ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
2018-04-23 01:25:39 +12:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
switch (symbol->symbology) {
|
|
|
|
case BARCODE_QRCODE:
|
|
|
|
case BARCODE_MICROQR:
|
|
|
|
case BARCODE_GRIDMATRIX:
|
2016-04-08 04:13:43 +12:00
|
|
|
case BARCODE_HANXIN:
|
2017-05-21 10:37:50 +12:00
|
|
|
case BARCODE_UPNQR:
|
2017-05-29 21:43:47 +12:00
|
|
|
error_number = extended_charset(symbol, local_source, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
|
|
|
default:
|
2017-05-29 21:43:47 +12:00
|
|
|
error_number = reduced_charset(symbol, local_source, in_length);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-08-16 23:43:41 +12:00
|
|
|
if ((error_number == ZINT_ERROR_INVALID_DATA) && (supports_eci(symbol->symbology)
|
2018-03-30 23:40:44 +13:00
|
|
|
&& (input_mode == UNICODE_MODE))) {
|
2016-08-16 23:43:41 +12:00
|
|
|
/* Try another ECI mode */
|
2017-05-29 21:43:47 +12:00
|
|
|
symbol->eci = get_best_eci(local_source, in_length);
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-09-15 09:34:59 +12:00
|
|
|
switch (symbol->symbology) {
|
|
|
|
case BARCODE_QRCODE:
|
|
|
|
case BARCODE_MICROQR:
|
|
|
|
case BARCODE_GRIDMATRIX:
|
|
|
|
case BARCODE_HANXIN:
|
2019-09-02 07:23:15 +12:00
|
|
|
{
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
unsigned char temp[in_length + 1];
|
|
|
|
#else
|
|
|
|
unsigned char *temp = (unsigned char*) _alloca(in_length + 1);
|
|
|
|
#endif
|
|
|
|
size_t temp_len = in_length;
|
|
|
|
memcpy(temp, local_source, temp_len);
|
|
|
|
temp[temp_len] = '\0';
|
|
|
|
error_number = utf_to_eci(symbol->eci, local_source, temp, &temp_len);
|
|
|
|
if (error_number == 0) {
|
|
|
|
in_length = (int) temp_len;
|
|
|
|
memcpy(local_source, temp, in_length);
|
|
|
|
local_source[in_length] = '\0';
|
|
|
|
error_number = extended_charset(symbol, local_source, in_length);
|
|
|
|
}
|
|
|
|
}
|
2016-09-15 09:34:59 +12:00
|
|
|
break;
|
|
|
|
default:
|
2017-05-29 21:43:47 +12:00
|
|
|
error_number = reduced_charset(symbol, local_source, in_length);
|
2016-09-15 09:34:59 +12:00
|
|
|
break;
|
2016-08-16 23:43:41 +12:00
|
|
|
}
|
2018-01-22 03:33:54 +13:00
|
|
|
|
|
|
|
if (error_number == 0) {
|
|
|
|
error_number = ZINT_WARN_USES_ECI;
|
|
|
|
strcpy(symbol->errtxt, "222: Encoded data includes ECI");
|
|
|
|
if (symbol->debug) printf("Data ECI %d\n", symbol->eci);
|
|
|
|
}
|
2016-08-16 23:43:41 +12:00
|
|
|
}
|
2016-02-20 23:50:15 +13:00
|
|
|
|
2017-07-26 22:44:47 +12:00
|
|
|
if (error_number == 0) {
|
|
|
|
if ((symbol->symbology == BARCODE_CODE128) || (symbol->symbology == BARCODE_CODE128B)) {
|
|
|
|
for (i = 0; i < in_length; i++) {
|
|
|
|
if (local_source[i] == '\0') {
|
|
|
|
symbol->text[i] = ' ';
|
|
|
|
} else {
|
|
|
|
symbol->text[i] = local_source[i];
|
|
|
|
}
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
error_number = error_buffer;
|
|
|
|
}
|
|
|
|
error_tag(symbol->errtxt, error_number);
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-09-15 09:34:59 +12:00
|
|
|
if (error_number <= 5) {
|
|
|
|
check_row_heights(symbol);
|
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
return error_number;
|
2009-11-23 04:38:15 +13:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) {
|
|
|
|
int error_number;
|
|
|
|
|
|
|
|
switch (rotate_angle) {
|
|
|
|
case 0:
|
|
|
|
case 90:
|
|
|
|
case 180:
|
|
|
|
case 270:
|
|
|
|
break;
|
|
|
|
default:
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "223: Invalid rotation angle");
|
2018-01-22 03:33:54 +13:00
|
|
|
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION);
|
2016-02-20 23:50:15 +13:00
|
|
|
return ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
|
2016-08-26 23:15:54 +12:00
|
|
|
if (symbol->output_options & BARCODE_DOTTY_MODE) {
|
2016-08-13 06:30:46 +12:00
|
|
|
if (!(is_matrix(symbol->symbology))) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "224: Selected symbology cannot be rendered as dots");
|
2018-01-22 03:33:54 +13:00
|
|
|
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION);
|
2016-08-13 06:30:46 +12:00
|
|
|
return ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
}
|
2016-09-06 09:06:50 +12:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
if (strlen(symbol->outfile) > 3) {
|
2017-09-11 03:03:09 +12:00
|
|
|
char output[4];
|
2016-02-20 23:50:15 +13:00
|
|
|
output[0] = symbol->outfile[strlen(symbol->outfile) - 3];
|
|
|
|
output[1] = symbol->outfile[strlen(symbol->outfile) - 2];
|
|
|
|
output[2] = symbol->outfile[strlen(symbol->outfile) - 1];
|
|
|
|
output[3] = '\0';
|
|
|
|
to_upper((unsigned char*) output);
|
2009-11-23 04:38:15 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
if (!(strcmp(output, "PNG"))) {
|
|
|
|
if (symbol->scale < 1.0) {
|
|
|
|
symbol->text[0] = '\0';
|
|
|
|
}
|
2016-07-20 10:02:39 +12:00
|
|
|
error_number = plot_raster(symbol, rotate_angle, OUT_PNG_FILE);
|
|
|
|
} else
|
|
|
|
if (!(strcmp(output, "BMP"))) {
|
|
|
|
if (symbol->scale < 1.0) {
|
|
|
|
symbol->text[0] = '\0';
|
|
|
|
}
|
|
|
|
error_number = plot_raster(symbol, rotate_angle, OUT_BMP_FILE);
|
2016-07-24 02:08:55 +12:00
|
|
|
} else
|
|
|
|
if (!(strcmp(output, "PCX"))) {
|
|
|
|
if (symbol->scale < 1.0) {
|
|
|
|
symbol->text[0] = '\0';
|
|
|
|
}
|
2016-09-06 09:06:50 +12:00
|
|
|
error_number = plot_raster(symbol, rotate_angle, OUT_PCX_FILE);
|
2016-07-29 06:58:33 +12:00
|
|
|
} else
|
|
|
|
if (!(strcmp(output, "GIF"))) {
|
|
|
|
if (symbol->scale < 1.0) {
|
|
|
|
symbol->text[0] = '\0';
|
|
|
|
}
|
|
|
|
error_number = plot_raster(symbol, rotate_angle, OUT_GIF_FILE);
|
2016-12-31 09:25:58 +13:00
|
|
|
} else
|
|
|
|
if (!(strcmp(output, "TIF"))) {
|
|
|
|
if (symbol->scale < 1.0) {
|
|
|
|
symbol->text[0] = '\0';
|
|
|
|
}
|
|
|
|
error_number = plot_raster(symbol, rotate_angle, OUT_TIF_FILE);
|
2016-02-20 23:50:15 +13:00
|
|
|
} else
|
|
|
|
if (!(strcmp(output, "TXT"))) {
|
|
|
|
error_number = dump_plot(symbol);
|
|
|
|
} else
|
|
|
|
if (!(strcmp(output, "EPS"))) {
|
2018-06-18 13:36:40 +12:00
|
|
|
error_number = plot_vector(symbol, rotate_angle, OUT_EPS_FILE);
|
2016-02-20 23:50:15 +13:00
|
|
|
} else
|
|
|
|
if (!(strcmp(output, "SVG"))) {
|
2018-06-18 13:36:40 +12:00
|
|
|
error_number = plot_vector(symbol, rotate_angle, OUT_SVG_FILE);
|
2016-12-24 05:48:03 +13:00
|
|
|
} else
|
|
|
|
if (!(strcmp(output, "EMF"))) {
|
2018-06-18 13:36:40 +12:00
|
|
|
error_number = plot_vector(symbol, rotate_angle, OUT_EMF_FILE);
|
2016-02-20 23:50:15 +13:00
|
|
|
} else {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "225: Unknown output format");
|
2016-02-20 23:50:15 +13:00
|
|
|
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION);
|
|
|
|
return ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
} else {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "226: Unknown output format");
|
2016-02-20 23:50:15 +13:00
|
|
|
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION);
|
|
|
|
return ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_tag(symbol->errtxt, error_number);
|
|
|
|
return error_number;
|
2009-11-23 04:38:15 +13:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle) {
|
|
|
|
int error_number;
|
|
|
|
|
|
|
|
switch (rotate_angle) {
|
|
|
|
case 0:
|
|
|
|
case 90:
|
|
|
|
case 180:
|
|
|
|
case 270:
|
|
|
|
break;
|
|
|
|
default:
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "228: Invalid rotation angle");
|
2018-01-22 03:33:54 +13:00
|
|
|
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION);
|
2016-02-20 23:50:15 +13:00
|
|
|
return ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
|
2016-10-02 22:45:47 +13:00
|
|
|
error_number = plot_raster(symbol, rotate_angle, OUT_BUFFER);
|
2016-02-20 23:50:15 +13:00
|
|
|
error_tag(symbol->errtxt, error_number);
|
|
|
|
return error_number;
|
2009-11-23 04:38:15 +13:00
|
|
|
}
|
|
|
|
|
2018-06-18 13:36:40 +12:00
|
|
|
int ZBarcode_Buffer_Vector(struct zint_symbol *symbol, int rotate_angle) {
|
|
|
|
int error_number;
|
|
|
|
|
|
|
|
switch (rotate_angle) {
|
|
|
|
case 0:
|
|
|
|
case 90:
|
|
|
|
case 180:
|
|
|
|
case 270:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strcpy(symbol->errtxt, "228: Invalid rotation angle");
|
|
|
|
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION);
|
|
|
|
return ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_number = plot_vector(symbol, rotate_angle, OUT_BUFFER);
|
|
|
|
error_tag(symbol->errtxt, error_number);
|
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle) {
|
|
|
|
int error_number;
|
2018-01-22 07:10:42 +13:00
|
|
|
int first_err;
|
2013-01-01 02:41:59 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
error_number = ZBarcode_Encode(symbol, input, length);
|
2018-01-22 07:10:42 +13:00
|
|
|
if (error_number >= 5) {
|
2016-02-20 23:50:15 +13:00
|
|
|
return error_number;
|
|
|
|
}
|
2009-11-23 04:38:15 +13:00
|
|
|
|
2018-01-22 07:10:42 +13:00
|
|
|
first_err = error_number;
|
2016-02-20 23:50:15 +13:00
|
|
|
error_number = ZBarcode_Print(symbol, rotate_angle);
|
2018-01-22 07:10:42 +13:00
|
|
|
if (error_number == 0) {
|
|
|
|
error_number = first_err;
|
|
|
|
}
|
2016-02-20 23:50:15 +13:00
|
|
|
return error_number;
|
2009-11-23 04:38:15 +13:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle) {
|
|
|
|
int error_number;
|
2018-01-22 07:10:42 +13:00
|
|
|
int first_err;
|
2013-01-01 02:41:59 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
error_number = ZBarcode_Encode(symbol, input, length);
|
2018-01-22 07:10:42 +13:00
|
|
|
if (error_number >= 5) {
|
2016-02-20 23:50:15 +13:00
|
|
|
return error_number;
|
|
|
|
}
|
2009-11-23 04:38:15 +13:00
|
|
|
|
2018-01-22 07:10:42 +13:00
|
|
|
first_err = error_number;
|
2016-02-20 23:50:15 +13:00
|
|
|
error_number = ZBarcode_Buffer(symbol, rotate_angle);
|
2018-01-22 07:10:42 +13:00
|
|
|
if (error_number == 0) {
|
|
|
|
error_number = first_err;
|
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
return error_number;
|
2009-11-23 04:38:15 +13:00
|
|
|
}
|
|
|
|
|
2018-06-18 13:36:40 +12:00
|
|
|
int ZBarcode_Encode_and_Buffer_Vector(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle) {
|
|
|
|
int error_number;
|
|
|
|
int first_err;
|
|
|
|
|
|
|
|
error_number = ZBarcode_Encode(symbol, input, length);
|
|
|
|
if (error_number >= 5) {
|
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
|
|
|
first_err = error_number;
|
|
|
|
error_number = ZBarcode_Buffer_Vector(symbol, rotate_angle);
|
|
|
|
if (error_number == 0) {
|
|
|
|
error_number = first_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) {
|
|
|
|
FILE *file;
|
|
|
|
unsigned char *buffer;
|
|
|
|
unsigned long fileLen;
|
|
|
|
unsigned int nRead = 0, n = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!strcmp(filename, "-")) {
|
|
|
|
file = stdin;
|
|
|
|
fileLen = 7100;
|
|
|
|
} else {
|
|
|
|
file = fopen(filename, "rb");
|
|
|
|
if (!file) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "229: Unable to read input file");
|
2018-01-22 03:33:54 +13:00
|
|
|
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION);
|
2016-02-20 23:50:15 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get file length */
|
|
|
|
fseek(file, 0, SEEK_END);
|
|
|
|
fileLen = ftell(file);
|
|
|
|
fseek(file, 0, SEEK_SET);
|
|
|
|
|
|
|
|
if (fileLen > 7100) {
|
|
|
|
/* The largest amount of data that can be encoded is 7089 numeric digits in QR Code */
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "230: Input file too long");
|
2018-01-22 03:33:54 +13:00
|
|
|
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_DATA);
|
2016-02-20 23:50:15 +13:00
|
|
|
fclose(file);
|
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate memory */
|
|
|
|
buffer = (unsigned char *) malloc(fileLen * sizeof (unsigned char));
|
|
|
|
if (!buffer) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "231: Internal memory error");
|
2018-01-22 03:33:54 +13:00
|
|
|
error_tag(symbol->errtxt, ZINT_ERROR_MEMORY);
|
2012-12-30 07:37:03 +13:00
|
|
|
if (strcmp(filename, "-"))
|
2016-02-20 23:50:15 +13:00
|
|
|
fclose(file);
|
|
|
|
return ZINT_ERROR_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read file contents into buffer */
|
|
|
|
|
|
|
|
do {
|
|
|
|
n = fread(buffer + nRead, 1, fileLen - nRead, file);
|
|
|
|
if (ferror(file)) {
|
|
|
|
strcpy(symbol->errtxt, strerror(errno));
|
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
nRead += n;
|
|
|
|
} while (!feof(file) && (0 < n) && (nRead < fileLen));
|
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
ret = ZBarcode_Encode(symbol, buffer, nRead);
|
|
|
|
free(buffer);
|
|
|
|
return ret;
|
2009-11-23 04:38:15 +13:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, char *filename, int rotate_angle) {
|
|
|
|
int error_number;
|
2018-01-22 07:10:42 +13:00
|
|
|
int first_err;
|
2013-01-01 02:41:59 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
error_number = ZBarcode_Encode_File(symbol, filename);
|
2018-01-22 07:10:42 +13:00
|
|
|
if (error_number >= 5) {
|
2016-02-20 23:50:15 +13:00
|
|
|
return error_number;
|
|
|
|
}
|
2018-01-22 07:10:42 +13:00
|
|
|
|
|
|
|
first_err = error_number;
|
|
|
|
error_number = ZBarcode_Print(symbol, rotate_angle);
|
|
|
|
if (error_number == 0) {
|
|
|
|
error_number = first_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error_number;
|
2009-11-23 04:38:15 +13:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
int ZBarcode_Encode_File_and_Buffer(struct zint_symbol *symbol, char *filename, int rotate_angle) {
|
|
|
|
int error_number;
|
2018-01-22 07:10:42 +13:00
|
|
|
int first_err;
|
2013-01-01 02:41:59 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
error_number = ZBarcode_Encode_File(symbol, filename);
|
2018-01-22 07:10:42 +13:00
|
|
|
if (error_number >= 5) {
|
2016-02-20 23:50:15 +13:00
|
|
|
return error_number;
|
|
|
|
}
|
2018-01-22 07:10:42 +13:00
|
|
|
|
|
|
|
first_err = error_number;
|
|
|
|
error_number = ZBarcode_Buffer(symbol, rotate_angle);
|
|
|
|
if (error_number == 0) {
|
|
|
|
error_number = first_err;
|
|
|
|
}
|
2013-01-01 02:41:59 +13:00
|
|
|
|
2018-01-22 07:10:42 +13:00
|
|
|
return error_number;
|
2009-11-23 04:38:15 +13:00
|
|
|
}
|
2010-05-31 05:25:24 +12:00
|
|
|
|
2018-06-18 13:36:40 +12:00
|
|
|
int ZBarcode_Encode_File_and_Buffer_Vector(struct zint_symbol *symbol, char *filename, int rotate_angle) {
|
|
|
|
int error_number;
|
|
|
|
int first_err;
|
|
|
|
|
|
|
|
error_number = ZBarcode_Encode_File(symbol, filename);
|
|
|
|
if (error_number >= 5) {
|
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
|
|
|
first_err = error_number;
|
|
|
|
error_number = ZBarcode_Buffer_Vector(symbol, rotate_angle);
|
|
|
|
if (error_number == 0) {
|
|
|
|
error_number = first_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
2010-05-31 05:25:24 +12:00
|
|
|
/*
|
|
|
|
* Rendering support, initially added by Sam Lown.
|
|
|
|
*
|
|
|
|
* Converts encoded data into an intermediate format to be interpreted
|
|
|
|
* in other applications using this library.
|
2010-06-12 05:42:51 +12:00
|
|
|
*
|
|
|
|
* If the width and height are not set to zero, the barcode will be resized to those
|
|
|
|
* dimensions. The symbol->scale and symbol->height values are totally ignored in this case.
|
|
|
|
*
|
2010-05-31 05:25:24 +12:00
|
|
|
*/
|
2016-04-07 08:55:14 +12:00
|
|
|
int ZBarcode_Render(struct zint_symbol *symbol, const float width, const float height) {
|
2016-02-20 23:50:15 +13:00
|
|
|
// Send the request to the render_plot method
|
|
|
|
return render_plot(symbol, width, height);
|
2010-05-31 05:25:24 +12:00
|
|
|
}
|
2017-07-01 20:06:47 +12:00
|
|
|
|
|
|
|
int ZBarcode_Version() {
|
|
|
|
return (ZINT_VERSION_MAJOR * 10000) + (ZINT_VERSION_MINOR * 100) + ZINT_VERSION_RELEASE;
|
2017-06-14 07:05:35 +12:00
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|