mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Brand new Data Matrix encoding engine!
This commit is contained in:
parent
f1a60e5e51
commit
f7060fc642
1338
backend/dm200.c
1338
backend/dm200.c
File diff suppressed because it is too large
Load Diff
121
backend/dm200.h
121
backend/dm200.h
@ -1,47 +1,92 @@
|
||||
/**
|
||||
*
|
||||
* IEC16022 bar code generation
|
||||
* Adrian Kennard, Andrews & Arnold Ltd
|
||||
* with help from Cliff Hones on the RS coding
|
||||
*
|
||||
* (c) 2004 Adrian Kennard, Andrews & Arnold Ltd
|
||||
* (c) 2006 Stefan Schmidt <stefan@datenfreihafen.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*
|
||||
* Main encoding function
|
||||
* Returns the grid (malloced) containing the matrix. L corner at 0,0.
|
||||
* Takes suggested size in *Wptr, *Hptr, or 0,0. Fills in actual size.
|
||||
* Takes barcodelen and barcode to be encoded
|
||||
* Note, if *encodingptr is null, then fills with auto picked (malloced)
|
||||
* encoding.
|
||||
* If lenp not null, then the length of encoded data before any final unlatch
|
||||
* or pad is stored.
|
||||
* If maxp not null, then the max storage of this size code is stored
|
||||
* If eccp not null, then the number of ecc bytes used in this size is stored
|
||||
* Returns 0 on error (writes to stderr with details).
|
||||
*
|
||||
*/
|
||||
/* dm200.h - Handles Data Matrix ECC 200 */
|
||||
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#ifndef __IEC16022ECC200_H
|
||||
#define __IEC16022ECC200_H
|
||||
|
||||
int iec16022ecc200(unsigned char *barcode, int barcodelen, struct zint_symbol *symbol);
|
||||
int data_matrix_200(struct zint_symbol *symbol, unsigned char source[]);
|
||||
#define MAXBARCODE 3116
|
||||
|
||||
#define DM_ASCII 1
|
||||
#define DM_C40 2
|
||||
#define DM_TEXT 3
|
||||
#define DM_X12 4
|
||||
#define DM_EDIFACT 5
|
||||
#define DM_BASE256 6
|
||||
|
||||
static int c40_shift[] = {
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };
|
||||
|
||||
static int c40_value[] = {
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
|
||||
3,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,4,5,6,7,8,9,10,11,12,13,
|
||||
15,16,17,18,19,20,21,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
|
||||
22,23,24,25,26,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 };
|
||||
|
||||
static int text_shift[] = {
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
2, 2, 2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3 };
|
||||
|
||||
static int text_value[] = {
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
|
||||
3,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,4,5,6,7,8,9,10,11,12,13,
|
||||
15,16,17,18,19,20,21,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,
|
||||
22,23,24,25,26,0,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,27,28,29,30,31 };
|
||||
|
||||
static int intsymbol[] = {
|
||||
0,1,3,5,7,8,10,12,13,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,2,4,6,9,11,14 };
|
||||
|
||||
static int matrixH[] = {
|
||||
10, 12, 8, 14, 8, 16, 12, 18, 20, 12, 22, 16, 24, 26, 16, 32, 36, 40, 44, 48,
|
||||
52, 64, 72, 80, 88, 96, 104, 120, 132, 144 };
|
||||
|
||||
static int matrixW[] = {
|
||||
10, 12, 18, 14, 32, 16, 26, 18, 20, 36, 22, 36, 24, 26, 48, 32, 36, 40, 44,
|
||||
48, 52, 64, 72, 80, 88, 96, 104, 120, 132, 144 };
|
||||
|
||||
static int matrixFH[] = {
|
||||
10, 12, 8, 14, 8, 16, 12, 18, 20, 12, 22, 16, 24, 26, 16, 16, 18, 20, 22, 24,
|
||||
26, 16, 18, 20, 22, 24, 26, 20, 22, 24 };
|
||||
|
||||
static int matrixFW[] = {
|
||||
10, 12, 18, 14, 16, 16, 26, 18, 20, 18, 22, 18, 24, 26, 24, 16, 18, 20, 22,
|
||||
24, 26, 16, 18, 20, 22, 24, 26, 20, 22, 24 };
|
||||
|
||||
static int matrixbytes[] = {
|
||||
3, 5, 5, 8, 10, 12, 16, 18, 22, 22, 30, 32, 36, 44, 49, 62, 86, 114, 144,
|
||||
174, 204, 280, 368, 456, 576, 696, 816, 1050, 1304, 1558 };
|
||||
|
||||
static int matrixdatablock[] = {
|
||||
3, 5, 5, 8, 10, 12, 16, 18, 22, 22, 30, 32, 36, 44, 49, 62, 86, 114, 144,
|
||||
174, 102, 140, 92, 114, 144, 174, 136, 175, 163, 156 };
|
||||
|
||||
static int matrixrsblock[] = {
|
||||
5, 7, 7, 10, 11, 12, 14, 14, 18, 18, 20, 24, 24, 28, 28, 36, 42, 48, 56, 68,
|
||||
42, 56, 36, 48, 56, 68, 56, 68, 62, 62 };
|
||||
|
||||
#endif /* __IEC16022ECC200_H */
|
||||
|
@ -21,10 +21,11 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "dm200.h"
|
||||
#include "dmatrix.h"
|
||||
#include "common.h"
|
||||
|
||||
int data_matrix_200(struct zint_symbol *symbol, unsigned char source[]);
|
||||
|
||||
#define B11SET " 0123456789"
|
||||
#define B27SET " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
#define B37SET " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
@ -1289,30 +1290,11 @@ int matrix89(struct zint_symbol *symbol, unsigned char source[])
|
||||
|
||||
int dmatrix(struct zint_symbol *symbol, unsigned char source[])
|
||||
{
|
||||
int barcodelen;
|
||||
int error_number;
|
||||
|
||||
barcodelen = ustrlen(source);
|
||||
if((symbol->option_1 < 1) || (symbol->option_1 > 6)) {
|
||||
symbol->option_1 = 1;
|
||||
}
|
||||
|
||||
if(symbol->option_1 == 1) {
|
||||
if(symbol->option_1 <= 1) {
|
||||
/* ECC 200 */
|
||||
error_number = iec16022ecc200(source, barcodelen, symbol);
|
||||
if((error_number != 0) && (symbol->option_2 != 0)) {
|
||||
if(strcmp(symbol->errtxt, "Cannot make barcode fit") == 0) {
|
||||
/* Can't fit data in the symbol size specified -
|
||||
use automatic symbol sizing instead */
|
||||
symbol->option_2 = 0;
|
||||
error_number = iec16022ecc200(source, barcodelen, symbol);
|
||||
if(error_number == 0) {
|
||||
/* It worked! */
|
||||
strcpy(symbol->errtxt, "Unable to fit data in specified symbol size");
|
||||
error_number = WARN_INVALID_OPTION;
|
||||
}
|
||||
}
|
||||
}
|
||||
error_number = data_matrix_200(symbol, source);
|
||||
} else {
|
||||
/* ECC 000 - 140 */
|
||||
error_number = matrix89(symbol, source);
|
||||
|
Loading…
Reference in New Issue
Block a user