2022-07-14 18:01:30 +03:00
/* upcean.c - Handles UPC, EAN and ISBN */
/*
2008-07-14 01:15:55 +04:00
libzint - the open source barcode library
2022-07-14 18:01:30 +03:00
Copyright ( C ) 2008 - 2022 Robin Stuart < rstuart114 @ gmail . com >
2008-07-14 01:15:55 +04:00
2013-05-16 21:26:38 +04:00
Redistribution and use in source and binary forms , with or without
modification , are permitted provided that the following conditions
are met :
2016-02-20 14:29:19 +03:00
1. Redistributions of source code must retain the above copyright
notice , this list of conditions and the following disclaimer .
2013-05-16 21:26:38 +04:00
2. Redistributions in binary form must reproduce the above copyright
notice , this list of conditions and the following disclaimer in the
2016-02-20 14:29:19 +03:00
documentation and / or other materials provided with the distribution .
2013-05-16 21:26:38 +04: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
2016-02-20 14:29:19 +03:00
without specific prior written permission .
2013-05-16 21:26:38 +04: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
2016-02-20 14:29:19 +03:00
OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF
2013-05-16 21:26:38 +04:00
SUCH DAMAGE .
2016-02-20 14:29:19 +03:00
*/
2022-07-14 18:01:30 +03:00
/* SPDX-License-Identifier: BSD-3-Clause */
2008-07-14 01:15:55 +04:00
2021-10-21 01:05:30 +03:00
# define SODIUM_PLS_F (IS_NUM_F | IS_PLS_F) /* SODIUM "0123456789+" */
# define ISBNX_SANE_F (IS_NUM_F | IS_UX__F) /* ISBNX_SANE "0123456789X" */
# define ISBNX_ADDON_SANE_F (IS_NUM_F | IS_UX__F | IS_LX__F | IS_PLS_F) /* ISBNX_ADDON_SANE "0123456789Xx+" */
2008-07-14 01:15:55 +04:00
# include <stdio.h>
# include "common.h"
2021-06-27 13:47:55 +03:00
# include "gs1.h"
2008-07-14 01:15:55 +04:00
/* UPC and EAN tables checked against EN 797:1996 */
2021-10-21 01:05:30 +03:00
static const char UPCParity0 [ 10 ] [ 6 ] = {
2016-02-20 14:29:19 +03:00
/* Number set for UPC-E symbol (EN Table 4) */
2021-10-21 01:05:30 +03:00
{ ' B ' , ' B ' , ' B ' , ' A ' , ' A ' , ' A ' } , { ' B ' , ' B ' , ' A ' , ' B ' , ' A ' , ' A ' } , { ' B ' , ' B ' , ' A ' , ' A ' , ' B ' , ' A ' } , { ' B ' , ' B ' , ' A ' , ' A ' , ' A ' , ' B ' } ,
{ ' B ' , ' A ' , ' B ' , ' B ' , ' A ' , ' A ' } , { ' B ' , ' A ' , ' A ' , ' B ' , ' B ' , ' A ' } , { ' B ' , ' A ' , ' A ' , ' A ' , ' B ' , ' B ' } , { ' B ' , ' A ' , ' B ' , ' A ' , ' B ' , ' A ' } ,
{ ' B ' , ' A ' , ' B ' , ' A ' , ' A ' , ' B ' } , { ' B ' , ' A ' , ' A ' , ' B ' , ' A ' , ' B ' }
2016-02-20 14:29:19 +03:00
} ;
2021-10-21 01:05:30 +03:00
static const char UPCParity1 [ 10 ] [ 6 ] = {
2016-02-20 14:29:19 +03:00
/* Not covered by BS EN 797:1995 */
2021-10-21 01:05:30 +03:00
{ ' A ' , ' A ' , ' A ' , ' B ' , ' B ' , ' B ' } , { ' A ' , ' A ' , ' B ' , ' A ' , ' B ' , ' B ' } , { ' A ' , ' A ' , ' B ' , ' B ' , ' A ' , ' B ' } , { ' A ' , ' A ' , ' B ' , ' B ' , ' B ' , ' A ' } ,
{ ' A ' , ' B ' , ' A ' , ' A ' , ' B ' , ' B ' } , { ' A ' , ' B ' , ' B ' , ' A ' , ' A ' , ' B ' } , { ' A ' , ' B ' , ' B ' , ' B ' , ' A ' , ' A ' } , { ' A ' , ' B ' , ' A ' , ' B ' , ' A ' , ' B ' } ,
{ ' A ' , ' B ' , ' A ' , ' B ' , ' B ' , ' A ' } , { ' A ' , ' B ' , ' B ' , ' A ' , ' B ' , ' A ' }
2016-03-03 00:12:38 +03:00
} ;
2016-02-20 14:29:19 +03:00
2021-10-21 01:05:30 +03:00
static const char EAN2Parity [ 4 ] [ 2 ] = {
2016-02-20 14:29:19 +03:00
/* Number sets for 2-digit add-on (EN Table 6) */
2021-10-21 01:05:30 +03:00
{ ' A ' , ' A ' } , { ' A ' , ' B ' } , { ' B ' , ' A ' } , { ' B ' , ' B ' }
2016-02-20 14:29:19 +03:00
} ;
2021-10-21 01:05:30 +03:00
static const char EAN5Parity [ 10 ] [ 5 ] = {
2016-02-20 14:29:19 +03:00
/* Number set for 5-digit add-on (EN Table 7) */
2021-10-21 01:05:30 +03:00
{ ' B ' , ' B ' , ' A ' , ' A ' , ' A ' } , { ' B ' , ' A ' , ' B ' , ' A ' , ' A ' } , { ' B ' , ' A ' , ' A ' , ' B ' , ' A ' } , { ' B ' , ' A ' , ' A ' , ' A ' , ' B ' } , { ' A ' , ' B ' , ' B ' , ' A ' , ' A ' } ,
{ ' A ' , ' A ' , ' B ' , ' B ' , ' A ' } , { ' A ' , ' A ' , ' A ' , ' B ' , ' B ' } , { ' A ' , ' B ' , ' A ' , ' B ' , ' A ' } , { ' A ' , ' B ' , ' A ' , ' A ' , ' B ' } , { ' A ' , ' A ' , ' B ' , ' A ' , ' B ' }
2016-02-20 14:29:19 +03:00
} ;
2021-10-21 01:05:30 +03:00
static const char EAN13Parity [ 10 ] [ 5 ] = {
2016-02-20 14:29:19 +03:00
/* Left hand of the EAN-13 symbol (EN Table 3) */
2021-10-21 01:05:30 +03:00
{ ' A ' , ' A ' , ' A ' , ' A ' , ' A ' } , { ' A ' , ' B ' , ' A ' , ' B ' , ' B ' } , { ' A ' , ' B ' , ' B ' , ' A ' , ' B ' } , { ' A ' , ' B ' , ' B ' , ' B ' , ' A ' } , { ' B ' , ' A ' , ' A ' , ' B ' , ' B ' } ,
{ ' B ' , ' B ' , ' A ' , ' A ' , ' B ' } , { ' B ' , ' B ' , ' B ' , ' A ' , ' A ' } , { ' B ' , ' A ' , ' B ' , ' A ' , ' B ' } , { ' B ' , ' A ' , ' B ' , ' B ' , ' A ' } , { ' B ' , ' B ' , ' A ' , ' B ' , ' A ' }
2016-02-20 14:29:19 +03:00
} ;
2021-10-21 01:05:30 +03:00
static const char EANsetA [ 10 ] [ 4 ] = {
2016-02-20 14:29:19 +03:00
/* Representation set A and C (EN Table 1) */
2021-10-21 01:05:30 +03:00
{ ' 3 ' , ' 2 ' , ' 1 ' , ' 1 ' } , { ' 2 ' , ' 2 ' , ' 2 ' , ' 1 ' } , { ' 2 ' , ' 1 ' , ' 2 ' , ' 2 ' } , { ' 1 ' , ' 4 ' , ' 1 ' , ' 1 ' } , { ' 1 ' , ' 1 ' , ' 3 ' , ' 2 ' } ,
{ ' 1 ' , ' 2 ' , ' 3 ' , ' 1 ' } , { ' 1 ' , ' 1 ' , ' 1 ' , ' 4 ' } , { ' 1 ' , ' 3 ' , ' 1 ' , ' 2 ' } , { ' 1 ' , ' 2 ' , ' 1 ' , ' 3 ' } , { ' 3 ' , ' 1 ' , ' 1 ' , ' 2 ' }
2016-02-20 14:29:19 +03:00
} ;
2021-10-21 01:05:30 +03:00
static const char EANsetB [ 10 ] [ 4 ] = {
2016-02-20 14:29:19 +03:00
/* Representation set B (EN Table 1) */
2021-10-21 01:05:30 +03:00
{ ' 1 ' , ' 1 ' , ' 2 ' , ' 3 ' } , { ' 1 ' , ' 2 ' , ' 2 ' , ' 2 ' } , { ' 2 ' , ' 2 ' , ' 1 ' , ' 2 ' } , { ' 1 ' , ' 1 ' , ' 4 ' , ' 1 ' } , { ' 2 ' , ' 3 ' , ' 1 ' , ' 1 ' } ,
{ ' 1 ' , ' 3 ' , ' 2 ' , ' 1 ' } , { ' 4 ' , ' 1 ' , ' 1 ' , ' 1 ' } , { ' 2 ' , ' 1 ' , ' 3 ' , ' 1 ' } , { ' 3 ' , ' 1 ' , ' 2 ' , ' 1 ' } , { ' 2 ' , ' 1 ' , ' 1 ' , ' 3 ' }
2016-03-03 00:12:38 +03:00
} ;
2016-02-20 14:29:19 +03:00
/* UPC A is usually used for 12 digit numbers, but this function takes a source of any length */
2021-10-21 01:05:30 +03:00
static void upca_draw ( const unsigned char source [ ] , const int length , char * d ) {
2020-12-21 22:30:07 +03:00
int i , half_way ;
2008-07-14 01:15:55 +04:00
2020-10-26 15:21:43 +03:00
half_way = length / 2 ;
2008-07-14 01:15:55 +04:00
2016-02-20 14:29:19 +03:00
/* start character */
2021-10-21 01:05:30 +03:00
memcpy ( d , " 111 " , 3 ) ;
d + = 3 ;
2008-07-14 01:15:55 +04:00
2021-10-21 01:05:30 +03:00
for ( i = 0 ; i < length ; i + + , d + = 4 ) {
2016-02-20 14:29:19 +03:00
if ( i = = half_way ) {
/* middle character - separates manufacturer no. from product no. */
/* also inverts right hand characters */
2021-10-21 01:05:30 +03:00
memcpy ( d , " 11111 " , 5 ) ;
d + = 5 ;
2016-02-20 14:29:19 +03:00
}
2008-07-14 01:15:55 +04:00
2021-10-21 01:05:30 +03:00
memcpy ( d , EANsetA [ source [ i ] - ' 0 ' ] , 4 ) ;
2016-02-20 14:29:19 +03:00
}
2008-07-14 01:15:55 +04:00
2016-02-20 14:29:19 +03:00
/* stop character */
2021-10-21 01:05:30 +03:00
strcpy ( d , " 111 " ) ;
2008-07-14 01:15:55 +04:00
}
2021-06-19 15:11:23 +03:00
/* Make a UPC-A barcode, allowing for composite if `cc_rows` set */
2021-06-27 13:47:55 +03:00
static int upca_cc ( struct zint_symbol * symbol , const unsigned char source [ ] , int length , char dest [ ] , int cc_rows ) {
2021-07-13 19:39:03 +03:00
unsigned char * gtin = symbol - > text ;
2020-09-30 14:19:12 +03:00
int error_number = 0 ;
2016-02-20 14:29:19 +03:00
2020-12-21 22:30:07 +03:00
ustrcpy ( gtin , source ) ;
2017-10-23 22:37:52 +03:00
2016-10-28 21:43:08 +03:00
if ( length = = 11 ) {
2021-06-27 13:47:55 +03:00
gtin [ length + + ] = gs1_check_digit ( gtin , 11 ) ;
2020-12-21 22:30:07 +03:00
gtin [ length ] = ' \0 ' ;
2016-10-28 21:43:08 +03:00
} else {
2021-06-27 13:47:55 +03:00
if ( source [ length - 1 ] ! = gs1_check_digit ( gtin , 11 ) ) {
sprintf ( symbol - > errtxt , " 270: Invalid check digit '%c', expecting '%c' " ,
source [ length - 1 ] , gs1_check_digit ( gtin , 11 ) ) ;
2019-09-01 22:23:15 +03:00
return ZINT_ERROR_INVALID_CHECK ;
2016-10-28 21:43:08 +03:00
}
}
2020-10-06 01:22:06 +03:00
if ( symbol - > debug & ZINT_DEBUG_PRINT ) {
2020-12-21 22:30:07 +03:00
printf ( " UPC-A: %s, gtin: %s, Check digit: %c \n " , source , gtin ,
length = = 11 ? gtin [ length ] : gtin [ length - 1 ] ) ;
2020-10-06 01:22:06 +03:00
}
2020-12-21 22:30:07 +03:00
upca_draw ( gtin , length , dest ) ;
2020-09-30 14:19:12 +03:00
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
if ( symbol - > output_options & COMPLIANT_HEIGHT ) {
/* BS EN 797:1996 4.5.1 Nominal dimensions 22.85mm / 0.33mm (X) ~ 69.24,
same as minimum GS1 General Specifications 21.0 .1 5.12 .3 .1 */
const float height = stripf ( 22.85f / 0.33f ) ;
if ( symbol - > symbology = = BARCODE_UPCA_CC ) {
symbol - > height = height ; /* Pass back min row == default height */
} else {
error_number = set_height ( symbol , height , height , 0.0f , 0 /*no_errtxt*/ ) ;
}
2021-06-19 15:11:23 +03:00
} else {
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
const float height = 50.0f ;
if ( symbol - > symbology = = BARCODE_UPCA_CC ) {
symbol - > height = height - cc_rows * 2 - 6.0f ;
} else {
( void ) set_height ( symbol , 0.0f , height , 0.0f , 1 /*no_errtxt*/ ) ;
}
2021-06-19 15:11:23 +03:00
}
2020-09-30 14:19:12 +03:00
return error_number ;
2008-07-14 01:15:55 +04:00
}
2021-06-19 15:11:23 +03:00
/* UPC-A */
2021-06-27 13:47:55 +03:00
static int upca ( struct zint_symbol * symbol , const unsigned char source [ ] , int length , char dest [ ] ) {
2021-06-19 15:11:23 +03:00
return upca_cc ( symbol , source , length , dest , 0 /*cc_rows*/ ) ;
}
/* UPC-E, allowing for composite if `cc_rows` set */
2021-10-21 01:05:30 +03:00
static int upce_cc ( struct zint_symbol * symbol , unsigned char source [ ] , int length , char * d , int cc_rows ) {
2020-12-21 22:30:07 +03:00
int i , num_system ;
2021-10-21 01:05:30 +03:00
char emode , check_digit ;
const char * parity ;
2021-07-13 00:27:16 +03:00
char src_check_digit = ' \0 ' ;
2021-06-27 13:47:55 +03:00
unsigned char equivalent [ 12 ] ;
2021-07-13 19:39:03 +03:00
unsigned char * hrt = symbol - > text ;
2020-09-30 14:19:12 +03:00
int error_number = 0 ;
2016-02-20 14:29:19 +03:00
2021-07-13 00:27:16 +03:00
if ( length = = 8 | | symbol - > symbology = = BARCODE_UPCE_CHK ) {
/* Will validate later */
src_check_digit = source [ - - length ] ;
}
2016-02-20 14:29:19 +03:00
/* Two number systems can be used - system 0 and system 1 */
2021-07-13 00:27:16 +03:00
hrt [ 0 ] = ' \0 ' ;
if ( length = = 7 ) {
2020-12-21 22:30:07 +03:00
switch ( source [ 0 ] ) {
case ' 0 ' : num_system = 0 ;
2021-07-13 00:27:16 +03:00
ustrncat ( hrt , source , length ) ;
2020-12-21 22:30:07 +03:00
break ;
case ' 1 ' : num_system = 1 ;
2021-07-13 00:27:16 +03:00
ustrncat ( hrt , source , length ) ;
2020-12-21 22:30:07 +03:00
break ;
default : num_system = 0 ;
/* First source char ignored */
2021-07-13 00:27:16 +03:00
ustrncat ( hrt , source , length ) ;
hrt [ 0 ] = ' 0 ' ; /* Overwrite HRT first char with '0' to correct TODO: error/warn in future */
2020-12-21 22:30:07 +03:00
break ;
2016-02-20 14:29:19 +03:00
}
2020-12-21 22:30:07 +03:00
for ( i = 1 ; i < = length ; i + + ) {
source [ i - 1 ] = hrt [ i ] ;
2016-10-28 21:43:08 +03:00
}
2020-12-21 22:30:07 +03:00
length - - ;
} else {
2021-07-13 00:27:16 +03:00
/* Length 6, insert leading zero */
2020-12-21 22:30:07 +03:00
num_system = 0 ;
hrt [ 0 ] = ' 0 ' ;
hrt [ 1 ] = ' \0 ' ;
ustrncat ( hrt , source , length ) ;
2016-02-20 14:29:19 +03:00
}
/* Expand the zero-compressed UPCE code to make a UPCA equivalent (EN Table 5) */
emode = source [ 5 ] ;
for ( i = 0 ; i < 11 ; i + + ) {
equivalent [ i ] = ' 0 ' ;
}
if ( num_system = = 1 ) {
2020-12-21 22:30:07 +03:00
equivalent [ 0 ] = hrt [ 0 ] ;
2016-02-20 14:29:19 +03:00
}
equivalent [ 1 ] = source [ 0 ] ;
equivalent [ 2 ] = source [ 1 ] ;
equivalent [ 11 ] = ' \0 ' ;
switch ( emode ) {
case ' 0 ' :
case ' 1 ' :
case ' 2 ' :
equivalent [ 3 ] = emode ;
equivalent [ 8 ] = source [ 2 ] ;
equivalent [ 9 ] = source [ 3 ] ;
equivalent [ 10 ] = source [ 4 ] ;
break ;
case ' 3 ' :
equivalent [ 3 ] = source [ 2 ] ;
equivalent [ 9 ] = source [ 3 ] ;
equivalent [ 10 ] = source [ 4 ] ;
if ( ( ( source [ 2 ] = = ' 0 ' ) | | ( source [ 2 ] = = ' 1 ' ) ) | | ( source [ 2 ] = = ' 2 ' ) ) {
/* Note 1 - "X3 shall not be equal to 0, 1 or 2" */
2022-07-14 18:01:30 +03:00
strcpy ( symbol - > errtxt , " 271: Invalid UPC-E data " ) ; /* TODO: Better error message */
2016-10-28 21:43:08 +03:00
return ZINT_ERROR_INVALID_DATA ;
2016-02-20 14:29:19 +03:00
}
break ;
case ' 4 ' :
equivalent [ 3 ] = source [ 2 ] ;
equivalent [ 4 ] = source [ 3 ] ;
equivalent [ 10 ] = source [ 4 ] ;
if ( source [ 3 ] = = ' 0 ' ) {
/* Note 2 - "X4 shall not be equal to 0" */
2022-07-14 18:01:30 +03:00
strcpy ( symbol - > errtxt , " 272: Invalid UPC-E data " ) ; /* TODO: Better error message */
2016-10-28 21:43:08 +03:00
return ZINT_ERROR_INVALID_DATA ;
2016-02-20 14:29:19 +03:00
}
break ;
case ' 5 ' :
case ' 6 ' :
case ' 7 ' :
case ' 8 ' :
case ' 9 ' :
equivalent [ 3 ] = source [ 2 ] ;
equivalent [ 4 ] = source [ 3 ] ;
equivalent [ 5 ] = source [ 4 ] ;
equivalent [ 10 ] = emode ;
if ( source [ 4 ] = = ' 0 ' ) {
/* Note 3 - "X5 shall not be equal to 0" */
2022-07-14 18:01:30 +03:00
strcpy ( symbol - > errtxt , " 273: Invalid UPC-E data " ) ; /* TODO: Better error message */
2016-10-28 21:43:08 +03:00
return ZINT_ERROR_INVALID_DATA ;
2016-02-20 14:29:19 +03:00
}
break ;
}
/* Get the check digit from the expanded UPCA code */
2021-06-27 13:47:55 +03:00
check_digit = gs1_check_digit ( equivalent , 11 ) ;
2016-02-20 14:29:19 +03:00
2021-07-13 00:27:16 +03:00
if ( src_check_digit & & src_check_digit ! = check_digit ) {
sprintf ( symbol - > errtxt , " 274: Invalid check digit '%c', expecting '%c' " , src_check_digit , check_digit ) ;
return ZINT_ERROR_INVALID_CHECK ;
}
2016-02-20 14:29:19 +03:00
/* Use the number system and check digit information to choose a parity scheme */
if ( num_system = = 1 ) {
2021-10-21 01:05:30 +03:00
parity = UPCParity1 [ ctoi ( check_digit ) ] ;
2016-02-20 14:29:19 +03:00
} else {
2021-10-21 01:05:30 +03:00
parity = UPCParity0 [ ctoi ( check_digit ) ] ;
2016-02-20 14:29:19 +03:00
}
/* Take all this information and make the barcode pattern */
/* start character */
2021-10-21 01:05:30 +03:00
memcpy ( d , " 111 " , 3 ) ;
d + = 3 ;
2016-02-20 14:29:19 +03:00
2021-10-21 01:05:30 +03:00
for ( i = 0 ; i < length ; i + + , d + = 4 ) {
2016-02-20 14:29:19 +03:00
switch ( parity [ i ] ) {
2021-10-21 01:05:30 +03:00
case ' A ' : memcpy ( d , EANsetA [ source [ i ] - ' 0 ' ] , 4 ) ;
2016-02-20 14:29:19 +03:00
break ;
2021-10-21 01:05:30 +03:00
case ' B ' : memcpy ( d , EANsetB [ source [ i ] - ' 0 ' ] , 4 ) ;
2016-02-20 14:29:19 +03:00
break ;
}
}
/* stop character */
2021-10-21 01:05:30 +03:00
strcpy ( d , " 111111 " ) ;
2016-02-20 14:29:19 +03:00
2021-07-13 00:27:16 +03:00
hrt [ 7 ] = check_digit ;
hrt [ 8 ] = ' \0 ' ;
2020-10-06 01:22:06 +03:00
if ( symbol - > debug & ZINT_DEBUG_PRINT ) {
printf ( " UPC-E: %s, equivalent: %s, hrt: %s, Check digit: %c \n " , source , equivalent , hrt , check_digit ) ;
}
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
if ( symbol - > output_options & COMPLIANT_HEIGHT ) {
/* BS EN 797:1996 4.5.1 Nominal dimensions 22.85mm / 0.33mm (X) ~ 69.24,
same as minimum GS1 General Specifications 21.0 .1 5.12 .3 .1 */
const float height = stripf ( 22.85f / 0.33f ) ;
if ( symbol - > symbology = = BARCODE_UPCE_CC ) {
symbol - > height = height ; /* Pass back min row == default height */
} else {
error_number = set_height ( symbol , height , height , 0.0f , 0 /*no_errtxt*/ ) ;
}
2021-06-19 15:11:23 +03:00
} else {
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
const float height = 50.0f ;
if ( symbol - > symbology = = BARCODE_UPCE_CC ) {
symbol - > height = height - cc_rows * 2 - 6.0f ;
} else {
( void ) set_height ( symbol , 0.0f , height , 0.0f , 1 /*no_errtxt*/ ) ;
}
2021-06-19 15:11:23 +03:00
}
2020-09-30 14:19:12 +03:00
return error_number ;
2008-07-14 01:15:55 +04:00
}
2021-06-19 15:11:23 +03:00
/* UPC-E is a zero-compressed version of UPC-A */
2021-06-27 13:47:55 +03:00
static int upce ( struct zint_symbol * symbol , unsigned char source [ ] , int length , char dest [ ] ) {
2021-06-19 15:11:23 +03:00
return upce_cc ( symbol , source , length , dest , 0 /*cc_rows*/ ) ;
}
2016-02-20 14:29:19 +03:00
/* EAN-2 and EAN-5 add-on codes */
2021-06-27 13:47:55 +03:00
static void ean_add_on ( const unsigned char source [ ] , const int length , char dest [ ] , const int addon_gap ) {
2021-10-21 01:05:30 +03:00
const char * parity ;
int i ;
char * d = dest + strlen ( dest ) ;
2016-02-20 14:29:19 +03:00
/* If an add-on then append with space */
2020-07-15 21:00:12 +03:00
if ( addon_gap ! = 0 ) {
2021-10-21 01:05:30 +03:00
* d + + = itoc ( addon_gap ) ;
2016-02-20 14:29:19 +03:00
}
/* Start character */
2021-10-21 01:05:30 +03:00
memcpy ( d , " 112 " , 3 ) ;
d + = 3 ;
2016-02-20 14:29:19 +03:00
2021-10-21 01:05:30 +03:00
/* Calculate parity */
if ( length = = 2 ) { /* EAN-2 */
2016-02-20 14:29:19 +03:00
int code_value , parity_bit ;
code_value = ( 10 * ctoi ( source [ 0 ] ) ) + ctoi ( source [ 1 ] ) ;
parity_bit = code_value % 4 ;
2021-10-21 01:05:30 +03:00
parity = EAN2Parity [ parity_bit ] ;
} else { /* EAN-5 */
2016-02-20 14:29:19 +03:00
int values [ 6 ] , parity_sum , parity_bit ;
for ( i = 0 ; i < 6 ; i + + ) {
values [ i ] = ctoi ( source [ i ] ) ;
}
parity_sum = ( 3 * ( values [ 0 ] + values [ 2 ] + values [ 4 ] ) ) ;
parity_sum + = ( 9 * ( values [ 1 ] + values [ 3 ] ) ) ;
parity_bit = parity_sum % 10 ;
2021-10-21 01:05:30 +03:00
parity = EAN5Parity [ parity_bit ] ;
2016-02-20 14:29:19 +03:00
}
2020-10-26 15:21:43 +03:00
for ( i = 0 ; i < length ; i + + ) {
2016-02-20 14:29:19 +03:00
switch ( parity [ i ] ) {
2021-10-21 01:05:30 +03:00
case ' A ' : memcpy ( d , EANsetA [ source [ i ] - ' 0 ' ] , 4 ) ;
d + = 4 ;
2016-02-20 14:29:19 +03:00
break ;
2021-10-21 01:05:30 +03:00
case ' B ' : memcpy ( d , EANsetB [ source [ i ] - ' 0 ' ] , 4 ) ;
d + = 4 ;
2016-02-20 14:29:19 +03:00
break ;
}
/* Glyph separator */
2020-12-21 22:30:07 +03:00
if ( i ! = ( length - 1 ) ) {
2021-10-21 01:05:30 +03:00
memcpy ( d , " 11 " , 2 ) ;
d + = 2 ;
2016-02-20 14:29:19 +03:00
}
}
2021-10-21 01:05:30 +03:00
* d = ' \0 ' ;
2008-07-14 01:15:55 +04:00
}
/* ************************ EAN-13 ****************** */
2016-03-03 00:12:38 +03:00
2021-10-21 01:05:30 +03:00
static int ean13_cc ( struct zint_symbol * symbol , const unsigned char source [ ] , int length , char * d ,
2021-06-19 15:11:23 +03:00
int cc_rows ) {
2020-12-21 22:30:07 +03:00
int i , half_way ;
2021-10-21 01:05:30 +03:00
const char * parity ;
2021-07-13 19:39:03 +03:00
unsigned char * gtin = symbol - > text ;
2020-09-30 14:19:12 +03:00
int error_number = 0 ;
2016-02-20 14:29:19 +03:00
2020-12-21 22:30:07 +03:00
ustrcpy ( gtin , source ) ;
2016-02-20 14:29:19 +03:00
/* Add the appropriate check digit */
2017-10-23 22:37:52 +03:00
2016-10-28 21:43:08 +03:00
if ( length = = 12 ) {
2021-06-27 13:47:55 +03:00
gtin [ length + + ] = gs1_check_digit ( gtin , 12 ) ;
2020-12-21 22:30:07 +03:00
gtin [ length ] = ' \0 ' ;
2016-10-28 21:43:08 +03:00
} else {
2021-06-27 13:47:55 +03:00
if ( source [ length - 1 ] ! = gs1_check_digit ( gtin , 12 ) ) {
sprintf ( symbol - > errtxt , " 275: Invalid check digit '%c', expecting '%c' " ,
source [ length - 1 ] , gs1_check_digit ( gtin , 12 ) ) ;
2020-10-06 01:22:06 +03:00
return ZINT_ERROR_INVALID_CHECK ;
2016-10-28 21:43:08 +03:00
}
}
2020-10-06 01:22:06 +03:00
if ( symbol - > debug & ZINT_DEBUG_PRINT ) {
2020-12-21 22:30:07 +03:00
printf ( " EAN-13: %s, gtin: %s, Check digit: %c \n " , source , gtin , gtin [ length - 1 ] ) ;
2020-10-06 01:22:06 +03:00
}
2016-02-20 14:29:19 +03:00
/* Get parity for first half of the symbol */
2021-10-21 01:05:30 +03:00
parity = EAN13Parity [ gtin [ 0 ] - ' 0 ' ] ;
2016-02-20 14:29:19 +03:00
/* Now get on with the cipher */
half_way = 7 ;
/* start character */
2021-10-21 01:05:30 +03:00
memcpy ( d , " 111 " , 3 ) ;
d + = 3 ;
for ( i = 1 ; i < length ; i + + , d + = 4 ) {
2016-02-20 14:29:19 +03:00
if ( i = = half_way ) {
/* middle character - separates manufacturer no. from product no. */
/* also inverses right hand characters */
2021-10-21 01:05:30 +03:00
memcpy ( d , " 11111 " , 5 ) ;
d + = 5 ;
2016-02-20 14:29:19 +03:00
}
if ( ( ( i > 1 ) & & ( i < 7 ) ) & & ( parity [ i - 2 ] = = ' B ' ) ) {
2021-10-21 01:05:30 +03:00
memcpy ( d , EANsetB [ gtin [ i ] - ' 0 ' ] , 4 ) ;
2016-02-20 14:29:19 +03:00
} else {
2021-10-21 01:05:30 +03:00
memcpy ( d , EANsetA [ gtin [ i ] - ' 0 ' ] , 4 ) ;
2016-02-20 14:29:19 +03:00
}
}
/* stop character */
2021-10-21 01:05:30 +03:00
strcpy ( d , " 111 " ) ;
2020-09-30 14:19:12 +03:00
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
if ( symbol - > output_options & COMPLIANT_HEIGHT ) {
/* BS EN 797:1996 4.5.1 Nominal dimensions 22.85mm / 0.33mm (X) ~ 69.24,
same as minimum GS1 General Specifications 21.0 .1 5.12 .3 .1 */
const float height = stripf ( 22.85f / 0.33f ) ;
if ( symbol - > symbology = = BARCODE_EANX_CC ) {
symbol - > height = height ; /* Pass back min row == default height */
} else {
error_number = set_height ( symbol , height , height , 0.0f , 0 /*no_errtxt*/ ) ;
}
2021-06-19 15:11:23 +03:00
} else {
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
const float height = 50.0f ;
if ( symbol - > symbology = = BARCODE_EANX_CC ) {
symbol - > height = height - cc_rows * 2 - 6.0f ;
} else {
( void ) set_height ( symbol , 0.0f , height , 0.0f , 1 /*no_errtxt*/ ) ;
}
2021-06-19 15:11:23 +03:00
}
2020-09-30 14:19:12 +03:00
return error_number ;
2008-07-14 01:15:55 +04:00
}
2021-06-27 13:47:55 +03:00
static int ean13 ( struct zint_symbol * symbol , const unsigned char source [ ] , int length , char dest [ ] ) {
2021-06-19 15:11:23 +03:00
return ean13_cc ( symbol , source , length , dest , 0 /*cc_rows*/ ) ;
}
2021-06-27 13:47:55 +03:00
static int ean8_cc ( struct zint_symbol * symbol , const unsigned char source [ ] , int length , char dest [ ] , int cc_rows ) {
2016-02-20 14:29:19 +03:00
/* EAN-8 is basically the same as UPC-A but with fewer digits */
2021-07-13 19:39:03 +03:00
unsigned char * gtin = symbol - > text ;
2020-09-30 14:19:12 +03:00
int error_number = 0 ;
2016-02-20 14:29:19 +03:00
2020-12-21 22:30:07 +03:00
ustrcpy ( gtin , source ) ;
2017-10-23 22:37:52 +03:00
2016-10-28 21:43:08 +03:00
if ( length = = 7 ) {
2021-06-27 13:47:55 +03:00
gtin [ length + + ] = gs1_check_digit ( gtin , 7 ) ;
2020-12-21 22:30:07 +03:00
gtin [ length ] = ' \0 ' ;
2016-10-28 21:43:08 +03:00
} else {
2021-06-27 13:47:55 +03:00
if ( source [ length - 1 ] ! = gs1_check_digit ( gtin , 7 ) ) {
sprintf ( symbol - > errtxt , " 276: Invalid check digit '%c', expecting '%c' " ,
source [ length - 1 ] , gs1_check_digit ( gtin , 7 ) ) ;
2020-10-06 01:22:06 +03:00
return ZINT_ERROR_INVALID_CHECK ;
2016-10-28 21:43:08 +03:00
}
}
2020-10-06 01:22:06 +03:00
if ( symbol - > debug & ZINT_DEBUG_PRINT ) {
2020-12-21 22:30:07 +03:00
printf ( " EAN-8: %s, gtin: %s, Check digit: %c \n " , source , gtin ,
length = = 7 ? gtin [ length ] : gtin [ length - 1 ] ) ;
2020-10-06 01:22:06 +03:00
}
2020-12-21 22:30:07 +03:00
upca_draw ( gtin , length , dest ) ;
2017-10-23 22:37:52 +03:00
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
if ( symbol - > output_options & COMPLIANT_HEIGHT ) {
/* BS EN 797:1996 4.5.1 Nominal dimensions 18.23mm / 0.33mm (X) ~ 55.24,
same as minimum GS1 General Specifications 21.0 .1 5.12 .3 .1 */
const float height = stripf ( 18.23f / 0.33f ) ;
if ( symbol - > symbology = = BARCODE_EANX_CC ) {
symbol - > height = height ; /* Pass back min row == default height */
} else {
error_number = set_height ( symbol , height , height , 0.0f , 0 /*no_errtxt*/ ) ;
}
2021-06-19 15:11:23 +03:00
} else {
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
const float height = 50.0f ;
if ( symbol - > symbology = = BARCODE_EANX_CC ) {
symbol - > height = height - cc_rows * 2 - 6.0f ;
} else {
( void ) set_height ( symbol , 0.0f , height , 0.0f , 1 /*no_errtxt*/ ) ;
}
2021-06-19 15:11:23 +03:00
}
2020-09-30 14:19:12 +03:00
return error_number ;
2008-07-14 01:15:55 +04:00
}
2021-06-19 15:11:23 +03:00
/* Make an EAN-8 barcode when we haven't been given the check digit */
2021-06-27 13:47:55 +03:00
static int ean8 ( struct zint_symbol * symbol , const unsigned char source [ ] , int length , char dest [ ] ) {
2021-06-19 15:11:23 +03:00
return ean8_cc ( symbol , source , length , dest , 0 /*cc_rows*/ ) ;
}
2016-02-20 14:29:19 +03:00
/* For ISBN(10) and SBN only */
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
static char isbnx_check ( const unsigned char source [ ] , const int length ) {
2020-12-21 22:30:07 +03:00
int i , weight , sum , check ;
2016-02-20 14:29:19 +03:00
char check_char ;
sum = 0 ;
weight = 1 ;
2020-12-21 22:30:07 +03:00
for ( i = 0 ; i < length ; i + + ) { /* Length will always be 9 */
2016-02-20 14:29:19 +03:00
sum + = ctoi ( source [ i ] ) * weight ;
weight + + ;
}
check = sum % 11 ;
check_char = itoc ( check ) ;
if ( check = = 10 ) {
check_char = ' X ' ;
}
return check_char ;
2008-07-14 01:15:55 +04:00
}
2016-02-20 14:29:19 +03:00
/* Make an EAN-13 barcode from an SBN or ISBN */
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
static int isbnx ( struct zint_symbol * symbol , unsigned char source [ ] , const int src_len , char dest [ ] ) {
int i ;
2016-02-20 14:29:19 +03:00
char check_digit ;
2021-10-21 01:05:30 +03:00
to_upper ( source , src_len ) ;
if ( ! is_sane ( ISBNX_SANE_F , source , src_len ) ) {
2021-07-06 21:53:31 +03:00
strcpy ( symbol - > errtxt , " 277: Invalid character in data (digits and \" X \" only) " ) ;
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
return ZINT_ERROR_INVALID_DATA ;
2016-02-20 14:29:19 +03:00
}
/* Input must be 9, 10 or 13 characters */
2019-09-01 22:23:15 +03:00
if ( src_len ! = 9 & & src_len ! = 10 & & src_len ! = 13 ) {
2021-06-27 13:47:55 +03:00
strcpy ( symbol - > errtxt , " 278: Input wrong length (9, 10, or 13 characters only) " ) ;
2016-02-20 14:29:19 +03:00
return ZINT_ERROR_TOO_LONG ;
}
if ( src_len = = 13 ) /* Using 13 character ISBN */ {
if ( ! ( ( ( source [ 0 ] = = ' 9 ' ) & & ( source [ 1 ] = = ' 7 ' ) ) & &
( ( source [ 2 ] = = ' 8 ' ) | | ( source [ 2 ] = = ' 9 ' ) ) ) ) {
2021-06-27 13:47:55 +03:00
strcpy ( symbol - > errtxt , " 279: Invalid ISBN (must begin with \" 978 \" or \" 979 \" ) " ) ;
2016-02-20 14:29:19 +03:00
return ZINT_ERROR_INVALID_DATA ;
}
2021-10-21 01:05:30 +03:00
/* "X" cannot occur */
if ( ! is_sane ( NEON_F , source , 13 ) ) {
strcpy ( symbol - > errtxt , " 282: Invalid character in data, \" X \" not allowed in ISBN-13 " ) ;
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
return ZINT_ERROR_INVALID_DATA ;
2021-07-06 21:53:31 +03:00
}
2021-06-27 13:47:55 +03:00
check_digit = gs1_check_digit ( source , 12 ) ;
2021-10-21 01:05:30 +03:00
if ( source [ 12 ] ! = check_digit ) {
sprintf ( symbol - > errtxt , " 280: Invalid ISBN check digit '%c', expecting '%c' " , source [ 12 ] , check_digit ) ;
2016-02-20 14:29:19 +03:00
return ZINT_ERROR_INVALID_CHECK ;
}
source [ 12 ] = ' \0 ' ;
2021-07-06 21:53:31 +03:00
} else { /* Using 10 digit ISBN or 9 digit SBN padded with leading zero */
if ( src_len = = 9 ) /* Using 9 digit SBN */ {
/* Add leading zero */
for ( i = 10 ; i > 0 ; i - - ) {
source [ i ] = source [ i - 1 ] ;
}
source [ 0 ] = ' 0 ' ;
}
/* "X" can only occur in last position */
2021-10-21 01:05:30 +03:00
if ( ! is_sane ( NEON_F , source , 9 ) ) {
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 23:42:44 +03:00
strcpy ( symbol - > errtxt , " 296: Invalid character in data, \" X \" allowed in last position only " ) ;
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
return ZINT_ERROR_INVALID_DATA ;
2016-02-20 14:29:19 +03:00
}
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
check_digit = isbnx_check ( source , 9 ) ;
2020-12-21 22:30:07 +03:00
if ( check_digit ! = source [ 9 ] ) {
2021-07-06 21:53:31 +03:00
sprintf ( symbol - > errtxt , " 281: Invalid %s check digit '%c', expecting '%c' " , src_len = = 9 ? " SBN " : " ISBN " ,
2021-06-27 13:47:55 +03:00
source [ 9 ] , check_digit ) ;
2016-02-20 14:29:19 +03:00
return ZINT_ERROR_INVALID_CHECK ;
}
2021-10-21 01:05:30 +03:00
for ( i = 11 ; i > 2 ; i - - ) { /* This drops the check digit */
2016-02-20 14:29:19 +03:00
source [ i ] = source [ i - 3 ] ;
}
source [ 0 ] = ' 9 ' ;
source [ 1 ] = ' 7 ' ;
source [ 2 ] = ' 8 ' ;
source [ 12 ] = ' \0 ' ;
}
2020-12-21 22:30:07 +03:00
return ean13 ( symbol , source , 12 , dest ) ;
2008-07-14 01:15:55 +04:00
}
2016-02-20 14:29:19 +03:00
/* Add leading zeroes to EAN and UPC strings */
2021-02-25 20:14:49 +03:00
INTERNAL int ean_leading_zeroes ( struct zint_symbol * symbol , const unsigned char source [ ] ,
2021-10-21 01:05:30 +03:00
unsigned char local_source [ ] , int * p_with_addon , unsigned char * zfirst_part ,
unsigned char * zsecond_part ) {
unsigned char first_part [ 14 ] , second_part [ 6 ] ;
2016-02-20 14:29:19 +03:00
int with_addon = 0 ;
int first_len = 0 , second_len = 0 , zfirst_len = 0 , zsecond_len = 0 , i , h ;
2020-12-21 22:30:07 +03:00
h = ( int ) ustrlen ( source ) ;
2016-02-20 14:29:19 +03:00
for ( i = 0 ; i < h ; i + + ) {
if ( source [ i ] = = ' + ' ) {
with_addon = 1 ;
} else {
if ( with_addon = = 0 ) {
first_len + + ;
} else {
second_len + + ;
}
}
}
2021-02-25 20:14:49 +03:00
if ( first_len > 13 | | second_len > 5 ) {
2021-07-06 21:53:31 +03:00
if ( p_with_addon ) {
* p_with_addon = second_len > 5 ? with_addon : 0 ;
}
2021-02-25 20:14:49 +03:00
return 0 ;
}
2016-02-20 14:29:19 +03:00
/* Split input into two strings */
for ( i = 0 ; i < first_len ; i + + ) {
first_part [ i ] = source [ i ] ;
}
2020-10-06 01:22:06 +03:00
first_part [ first_len ] = ' \0 ' ;
2016-02-20 14:29:19 +03:00
for ( i = 0 ; i < second_len ; i + + ) {
second_part [ i ] = source [ i + first_len + 1 ] ;
}
2020-10-06 01:22:06 +03:00
second_part [ second_len ] = ' \0 ' ;
2016-02-20 14:29:19 +03:00
/* Calculate target lengths */
if ( second_len = = 0 ) {
zsecond_len = 0 ;
2021-10-21 01:05:30 +03:00
} else if ( second_len < = 2 ) {
zsecond_len = 2 ;
2020-12-21 22:30:07 +03:00
} else {
2021-10-21 01:05:30 +03:00
zsecond_len = 5 ;
2016-02-20 14:29:19 +03:00
}
switch ( symbol - > symbology ) {
case BARCODE_EANX :
case BARCODE_EANX_CC :
if ( first_len < = 12 ) {
2020-12-21 22:30:07 +03:00
if ( first_len < = 7 ) {
zfirst_len = 7 ;
} else {
zfirst_len = 12 ;
}
2016-02-20 14:29:19 +03:00
}
2019-10-15 00:20:16 +03:00
if ( second_len = = 0 & & symbol - > symbology = = BARCODE_EANX ) { /* No composite EAN-2/5 */
2016-02-20 14:29:19 +03:00
if ( first_len < = 5 ) {
2020-12-21 22:30:07 +03:00
if ( first_len < = 2 ) {
zfirst_len = 2 ;
} else {
zfirst_len = 5 ;
}
2016-02-20 14:29:19 +03:00
}
}
break ;
2016-10-28 21:43:08 +03:00
case BARCODE_EANX_CHK :
if ( first_len < = 13 ) {
2020-12-21 22:30:07 +03:00
if ( first_len < = 8 ) {
zfirst_len = 8 ;
} else {
zfirst_len = 13 ;
}
2016-10-28 21:43:08 +03:00
}
if ( second_len = = 0 ) {
if ( first_len < = 5 ) {
2020-12-21 22:30:07 +03:00
if ( first_len < = 2 ) {
zfirst_len = 2 ;
} else {
zfirst_len = 5 ;
}
2016-10-28 21:43:08 +03:00
}
}
break ;
2016-02-20 14:29:19 +03:00
case BARCODE_UPCA :
case BARCODE_UPCA_CC :
zfirst_len = 11 ;
break ;
2016-10-28 21:43:08 +03:00
case BARCODE_UPCA_CHK :
zfirst_len = 12 ;
break ;
2016-02-20 14:29:19 +03:00
case BARCODE_UPCE :
case BARCODE_UPCE_CC :
if ( first_len = = 7 ) {
zfirst_len = 7 ;
2020-12-21 22:30:07 +03:00
} else if ( first_len < = 6 ) {
2016-02-20 14:29:19 +03:00
zfirst_len = 6 ;
}
break ;
2016-10-28 21:43:08 +03:00
case BARCODE_UPCE_CHK :
if ( first_len = = 8 ) {
zfirst_len = 8 ;
2020-12-21 22:30:07 +03:00
} else if ( first_len < = 7 ) {
2016-10-28 21:43:08 +03:00
zfirst_len = 7 ;
}
break ;
2016-02-20 14:29:19 +03:00
case BARCODE_ISBNX :
if ( first_len < = 9 ) {
zfirst_len = 9 ;
}
break ;
}
2021-10-21 01:05:30 +03:00
/* Copy adjusted data back to local_source */
2016-02-20 14:29:19 +03:00
/* Add leading zeroes */
for ( i = 0 ; i < ( zfirst_len - first_len ) ; i + + ) {
2021-10-21 01:05:30 +03:00
local_source [ i ] = ' 0 ' ;
2016-02-20 14:29:19 +03:00
}
2021-10-21 01:05:30 +03:00
ustrcpy ( local_source + i , first_part ) ;
if ( zfirst_part ) {
ustrcpy ( zfirst_part , local_source ) ;
2016-02-20 14:29:19 +03:00
}
2021-10-21 01:05:30 +03:00
if ( with_addon ) {
h = ( int ) ustrlen ( local_source ) ;
local_source [ h + + ] = ' + ' ;
for ( i = 0 ; i < ( zsecond_len - second_len ) ; i + + ) {
local_source [ h + i ] = ' 0 ' ;
}
ustrcpy ( local_source + h + i , second_part ) ;
if ( zsecond_part ) {
ustrcpy ( zsecond_part , local_source + h ) ;
}
} else if ( zsecond_part ) {
* zsecond_part = ' \0 ' ;
2016-02-20 14:29:19 +03:00
}
2020-10-06 01:22:06 +03:00
if ( p_with_addon ) {
* p_with_addon = with_addon ;
}
2021-02-25 20:14:49 +03:00
return 1 ; /* Success */
2009-05-27 13:06:28 +04:00
}
2021-06-19 15:11:23 +03:00
INTERNAL int eanx_cc ( struct zint_symbol * symbol , unsigned char source [ ] , int src_len , int cc_rows ) {
2021-10-21 01:05:30 +03:00
unsigned char first_part [ 14 ] , second_part [ 6 ] ;
unsigned char local_source [ 20 ] ; /* Allow 13 + "+" + 5 + 1 */
2021-06-27 13:47:55 +03:00
char dest [ 1000 ] = { 0 } ;
2020-10-06 01:22:06 +03:00
int with_addon ;
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
int error_number = 0 , i , plus_count ;
2020-07-15 21:00:12 +03:00
int addon_gap = 0 ;
2020-12-21 22:30:07 +03:00
int first_part_len , second_part_len ;
2016-02-20 14:29:19 +03:00
if ( src_len > 19 ) {
2021-07-06 21:53:31 +03:00
strcpy ( symbol - > errtxt , " 283: Input too long (19 character maximum) " ) ;
2016-02-20 14:29:19 +03:00
return ZINT_ERROR_TOO_LONG ;
}
if ( symbol - > symbology ! = BARCODE_ISBNX ) {
2021-07-06 21:53:31 +03:00
/* ISBN has its own sanity routine */
2021-10-21 01:05:30 +03:00
if ( ! is_sane ( SODIUM_PLS_F , source , src_len ) ) {
2021-07-06 21:53:31 +03:00
strcpy ( symbol - > errtxt , " 284: Invalid character in data (digits and \" + \" only) " ) ;
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
return ZINT_ERROR_INVALID_DATA ;
2016-02-20 14:29:19 +03:00
}
} else {
2021-10-21 01:05:30 +03:00
if ( ! is_sane ( ISBNX_ADDON_SANE_F , source , src_len ) ) {
2021-07-06 21:53:31 +03:00
strcpy ( symbol - > errtxt , " 285: Invalid character in data (digits, \" X \" and \" + \" only) " ) ;
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
return ZINT_ERROR_INVALID_DATA ;
2016-02-20 14:29:19 +03:00
}
2021-07-06 21:53:31 +03:00
/* Add-on will be checked separately to be numeric only below */
2016-02-20 14:29:19 +03:00
}
2021-06-19 15:11:23 +03:00
2020-02-16 00:28:40 +03:00
/* Check for multiple '+' characters */
plus_count = 0 ;
for ( i = 0 ; i < src_len ; i + + ) {
if ( source [ i ] = = ' + ' ) {
plus_count + + ;
2021-06-27 13:47:55 +03:00
if ( plus_count > 1 ) {
strcpy ( symbol - > errtxt , " 293: Invalid add-on data (one \" + \" only) " ) ;
return ZINT_ERROR_INVALID_DATA ;
}
2020-02-16 00:28:40 +03:00
}
}
2016-02-20 14:29:19 +03:00
2021-02-25 20:14:49 +03:00
/* Add leading zeroes, checking max lengths of parts */
2021-10-21 01:05:30 +03:00
if ( ! ean_leading_zeroes ( symbol , source , local_source , & with_addon , first_part , second_part ) ) {
2021-07-06 21:53:31 +03:00
sprintf ( symbol - > errtxt , " 294: Input too long (%s) " ,
with_addon ? " 5 character maximum for add-on " : " 13 character maximum " ) ;
2021-02-25 20:14:49 +03:00
return ZINT_ERROR_TOO_LONG ;
}
2016-02-20 14:29:19 +03:00
if ( with_addon ) {
2020-12-21 22:30:07 +03:00
if ( symbol - > symbology = = BARCODE_UPCA | | symbol - > symbology = = BARCODE_UPCA_CHK
| | symbol - > symbology = = BARCODE_UPCA_CC ) {
2020-07-15 21:00:12 +03:00
addon_gap = symbol - > option_2 > = 9 & & symbol - > option_2 < = 12 ? symbol - > option_2 : 9 ;
} else {
addon_gap = symbol - > option_2 > = 7 & & symbol - > option_2 < = 12 ? symbol - > option_2 : 7 ;
}
2016-02-20 14:29:19 +03:00
}
2020-12-21 22:30:07 +03:00
first_part_len = ( int ) ustrlen ( first_part ) ;
2016-02-20 14:29:19 +03:00
switch ( symbol - > symbology ) {
case BARCODE_EANX :
2016-10-28 21:43:08 +03:00
case BARCODE_EANX_CHK :
2020-12-21 22:30:07 +03:00
switch ( first_part_len ) {
2021-06-27 13:47:55 +03:00
case 2 : ean_add_on ( first_part , first_part_len , dest , 0 ) ;
2016-02-20 14:29:19 +03:00
ustrcpy ( symbol - > text , first_part ) ;
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
if ( symbol - > output_options & COMPLIANT_HEIGHT ) {
/* 21.9mm from GS1 General Specifications 5.2.6.6, Figure 5.2.6.6-5 */
const float height = stripf ( 21.9f / 0.33f ) ; /* 21.9mm / 0.33mm ~ 66.36 */
error_number = set_height ( symbol , height , height , 0.0f , 0 /*no_errtxt*/ ) ;
} else {
( void ) set_height ( symbol , 0.0f , 50.0f , 0.0f , 1 /*no_errtxt*/ ) ;
}
2016-02-20 14:29:19 +03:00
break ;
2021-06-27 13:47:55 +03:00
case 5 : ean_add_on ( first_part , first_part_len , dest , 0 ) ;
2016-02-20 14:29:19 +03:00
ustrcpy ( symbol - > text , first_part ) ;
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
if ( symbol - > output_options & COMPLIANT_HEIGHT ) {
/* 21.9mm from GS1 General Specifications 5.2.6.6, Figure 5.2.6.6-6 */
const float height = stripf ( 21.9f / 0.33f ) ; /* 21.9mm / 0.33mm ~ 66.36 */
error_number = set_height ( symbol , height , height , 0.0f , 0 /*no_errtxt*/ ) ;
} else {
( void ) set_height ( symbol , 0.0f , 50.0f , 0.0f , 1 /*no_errtxt*/ ) ;
}
2016-02-20 14:29:19 +03:00
break ;
2016-10-28 21:43:08 +03:00
case 7 :
2020-12-21 22:30:07 +03:00
case 8 : error_number = ean8 ( symbol , first_part , first_part_len , dest ) ;
2016-02-20 14:29:19 +03:00
break ;
2017-10-23 22:37:52 +03:00
case 12 :
2020-12-21 22:30:07 +03:00
case 13 : error_number = ean13 ( symbol , first_part , first_part_len , dest ) ;
2016-02-20 14:29:19 +03:00
break ;
2021-07-06 21:53:31 +03:00
default : strcpy ( symbol - > errtxt , " 286: Input wrong length (2, 5, 7, 8, 12 or 13 characters only) " ) ;
2016-02-20 14:29:19 +03:00
return ZINT_ERROR_TOO_LONG ;
}
break ;
case BARCODE_EANX_CC :
2020-12-21 22:30:07 +03:00
switch ( first_part_len ) { /* Adds vertical separator bars according to ISO/IEC 24723 section 11.4 */
2016-02-20 14:29:19 +03:00
case 7 : set_module ( symbol , symbol - > rows , 1 ) ;
set_module ( symbol , symbol - > rows , 67 ) ;
set_module ( symbol , symbol - > rows + 1 , 0 ) ;
set_module ( symbol , symbol - > rows + 1 , 68 ) ;
set_module ( symbol , symbol - > rows + 2 , 1 ) ;
2019-10-05 13:08:58 +03:00
set_module ( symbol , symbol - > rows + 2 , 67 ) ;
2016-02-20 14:29:19 +03:00
symbol - > row_height [ symbol - > rows ] = 2 ;
symbol - > row_height [ symbol - > rows + 1 ] = 2 ;
symbol - > row_height [ symbol - > rows + 2 ] = 2 ;
symbol - > rows + = 3 ;
2021-06-19 15:11:23 +03:00
error_number = ean8_cc ( symbol , first_part , first_part_len , dest , cc_rows ) ;
2016-02-20 14:29:19 +03:00
break ;
2020-10-06 01:22:06 +03:00
case 12 :
case 13 : set_module ( symbol , symbol - > rows , 1 ) ;
2016-02-20 14:29:19 +03:00
set_module ( symbol , symbol - > rows , 95 ) ;
set_module ( symbol , symbol - > rows + 1 , 0 ) ;
set_module ( symbol , symbol - > rows + 1 , 96 ) ;
set_module ( symbol , symbol - > rows + 2 , 1 ) ;
set_module ( symbol , symbol - > rows + 2 , 95 ) ;
symbol - > row_height [ symbol - > rows ] = 2 ;
symbol - > row_height [ symbol - > rows + 1 ] = 2 ;
symbol - > row_height [ symbol - > rows + 2 ] = 2 ;
symbol - > rows + = 3 ;
2021-06-19 15:11:23 +03:00
error_number = ean13_cc ( symbol , first_part , first_part_len , dest , cc_rows ) ;
2016-02-20 14:29:19 +03:00
break ;
2021-07-13 00:27:16 +03:00
default : strcpy ( symbol - > errtxt , " 287: Input wrong length (7, 12 or 13 characters only) " ) ;
2016-02-20 14:29:19 +03:00
return ZINT_ERROR_TOO_LONG ;
}
break ;
case BARCODE_UPCA :
2016-10-28 21:43:08 +03:00
case BARCODE_UPCA_CHK :
2020-12-21 22:30:07 +03:00
if ( ( first_part_len = = 11 ) | | ( first_part_len = = 12 ) ) {
error_number = upca ( symbol , first_part , first_part_len , dest ) ;
2016-02-20 14:29:19 +03:00
} else {
2021-07-13 00:27:16 +03:00
strcpy ( symbol - > errtxt , " 288: Input wrong length (12 character maximum) " ) ;
2016-02-20 14:29:19 +03:00
return ZINT_ERROR_TOO_LONG ;
}
break ;
case BARCODE_UPCA_CC :
2020-12-21 22:30:07 +03:00
if ( first_part_len = = 11 | | first_part_len = = 12 ) {
2016-02-20 14:29:19 +03:00
set_module ( symbol , symbol - > rows , 1 ) ;
set_module ( symbol , symbol - > rows , 95 ) ;
set_module ( symbol , symbol - > rows + 1 , 0 ) ;
set_module ( symbol , symbol - > rows + 1 , 96 ) ;
set_module ( symbol , symbol - > rows + 2 , 1 ) ;
set_module ( symbol , symbol - > rows + 2 , 95 ) ;
symbol - > row_height [ symbol - > rows ] = 2 ;
symbol - > row_height [ symbol - > rows + 1 ] = 2 ;
symbol - > row_height [ symbol - > rows + 2 ] = 2 ;
symbol - > rows + = 3 ;
2021-06-19 15:11:23 +03:00
error_number = upca_cc ( symbol , first_part , first_part_len , dest , cc_rows ) ;
2016-02-20 14:29:19 +03:00
} else {
2021-07-13 00:27:16 +03:00
strcpy ( symbol - > errtxt , " 289: Input wrong length (12 character maximum) " ) ;
2016-02-20 14:29:19 +03:00
return ZINT_ERROR_TOO_LONG ;
}
break ;
case BARCODE_UPCE :
2016-10-28 21:43:08 +03:00
case BARCODE_UPCE_CHK :
2021-07-13 00:27:16 +03:00
if ( ( first_part_len > = 6 ) & & ( first_part_len < = 8 ) ) {
2020-12-21 22:30:07 +03:00
error_number = upce ( symbol , first_part , first_part_len , dest ) ;
2016-02-20 14:29:19 +03:00
} else {
2021-07-13 00:27:16 +03:00
strcpy ( symbol - > errtxt , " 290: Input wrong length (8 character maximum) " ) ;
2016-02-20 14:29:19 +03:00
return ZINT_ERROR_TOO_LONG ;
}
break ;
case BARCODE_UPCE_CC :
2021-07-13 00:27:16 +03:00
if ( ( first_part_len > = 6 ) & & ( first_part_len < = 8 ) ) {
2016-02-20 14:29:19 +03:00
set_module ( symbol , symbol - > rows , 1 ) ;
set_module ( symbol , symbol - > rows , 51 ) ;
set_module ( symbol , symbol - > rows + 1 , 0 ) ;
set_module ( symbol , symbol - > rows + 1 , 52 ) ;
set_module ( symbol , symbol - > rows + 2 , 1 ) ;
set_module ( symbol , symbol - > rows + 2 , 51 ) ;
symbol - > row_height [ symbol - > rows ] = 2 ;
symbol - > row_height [ symbol - > rows + 1 ] = 2 ;
symbol - > row_height [ symbol - > rows + 2 ] = 2 ;
symbol - > rows + = 3 ;
2021-06-19 15:11:23 +03:00
error_number = upce_cc ( symbol , first_part , first_part_len , dest , cc_rows ) ;
2016-02-20 14:29:19 +03:00
} else {
2021-07-13 00:27:16 +03:00
strcpy ( symbol - > errtxt , " 291: Input wrong length (8 character maximum) " ) ;
2016-02-20 14:29:19 +03:00
return ZINT_ERROR_TOO_LONG ;
}
break ;
case BARCODE_ISBNX :
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
error_number = isbnx ( symbol , first_part , first_part_len , dest ) ;
2016-02-20 14:29:19 +03:00
break ;
}
2017-10-23 22:37:52 +03:00
2020-09-30 14:19:12 +03:00
if ( error_number > = ZINT_ERROR ) {
2016-10-28 21:43:08 +03:00
return error_number ;
}
2017-10-23 22:37:52 +03:00
2020-12-21 22:30:07 +03:00
second_part_len = ( int ) ustrlen ( second_part ) ;
2021-07-06 21:53:31 +03:00
if ( symbol - > symbology = = BARCODE_ISBNX ) { /* Need to further check that add-on numeric only */
2021-10-21 01:05:30 +03:00
if ( ! is_sane ( NEON_F , second_part , second_part_len ) ) {
2021-07-06 21:53:31 +03:00
strcpy ( symbol - > errtxt , " 295: Invalid add-on data (digits only) " ) ;
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 02:13:39 +03:00
return ZINT_ERROR_INVALID_DATA ;
2021-07-06 21:53:31 +03:00
}
}
2020-12-21 22:30:07 +03:00
switch ( second_part_len ) {
2016-02-20 14:29:19 +03:00
case 0 : break ;
case 2 :
2021-06-27 13:47:55 +03:00
ean_add_on ( second_part , second_part_len , dest , addon_gap ) ;
2020-12-21 22:30:07 +03:00
ustrcat ( symbol - > text , " + " ) ;
ustrcat ( symbol - > text , second_part ) ;
2016-02-20 14:29:19 +03:00
break ;
case 5 :
2021-06-27 13:47:55 +03:00
ean_add_on ( second_part , second_part_len , dest , addon_gap ) ;
2020-12-21 22:30:07 +03:00
ustrcat ( symbol - > text , " + " ) ;
ustrcat ( symbol - > text , second_part ) ;
2016-02-20 14:29:19 +03:00
break ;
default :
2021-07-06 21:53:31 +03:00
strcpy ( symbol - > errtxt , " 292: Add-on data wrong length (2 or 5 characters only) " ) ;
2016-02-20 14:29:19 +03:00
return ZINT_ERROR_TOO_LONG ;
}
2021-10-21 01:05:30 +03:00
expand ( symbol , dest , ( int ) strlen ( dest ) ) ;
2016-02-20 14:29:19 +03:00
switch ( symbol - > symbology ) {
case BARCODE_EANX_CC :
case BARCODE_UPCA_CC :
case BARCODE_UPCE_CC :
/* shift the symbol to the right one space to allow for separator bars */
for ( i = ( symbol - > width + 1 ) ; i > = 1 ; i - - ) {
if ( module_is_set ( symbol , symbol - > rows - 1 , i - 1 ) ) {
set_module ( symbol , symbol - > rows - 1 , i ) ;
} else {
unset_module ( symbol , symbol - > rows - 1 , i ) ;
}
}
unset_module ( symbol , symbol - > rows - 1 , 0 ) ;
symbol - > width + = 2 ;
break ;
}
2020-09-30 14:19:12 +03:00
return error_number ;
2008-07-14 01:15:55 +04:00
}
2021-06-19 15:11:23 +03:00
/* Handle UPC, EAN, ISBN */
INTERNAL int eanx ( struct zint_symbol * symbol , unsigned char source [ ] , int src_len ) {
return eanx_cc ( symbol , source , src_len , 0 /*cc_rows*/ ) ;
}
2022-07-14 18:01:30 +03:00
/* vim: set ts=4 sw=4 et : */