2008-07-14 01:15:55 +04:00
/* medical.c - Handles 1 track and 2 track pharmacode and Codabar */
/*
libzint - the open source barcode library
2022-05-12 22:35:06 +03:00
Copyright ( C ) 2008 - 2022 Robin Stuart < rstuart114 @ gmail . com >
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 :
2017-10-23 22:37:52 +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
2017-10-23 22:37:52 +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
2017-10-23 22:37:52 +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
2017-10-23 22:37:52 +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 13:50:15 +03:00
*/
2022-09-13 23:16:31 +03:00
/* SPDX-License-Identifier: BSD-3-Clause */
2008-07-14 01:15:55 +04:00
2022-09-13 23:16:31 +03:00
# include <stdio.h>
2022-09-14 00:08:08 +03:00
# include "common.h"
2008-07-14 01:15:55 +04: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
INTERNAL int code39 ( struct zint_symbol * symbol , unsigned char source [ ] , int length ) ;
2019-12-19 03:37:55 +03:00
2021-10-21 01:05:30 +03:00
static const char CALCIUM [ ] = " 0123456789-$:/.+ABCD " ;
# define CALCIUM_INNER_F (IS_NUM_F | IS_MNS_F | IS_CLI_F | IS_PLS_F) /* CALCIUM_INNER "0123456789-$:/.+" */
2008-09-02 23:44:41 +04:00
2021-10-21 01:05:30 +03:00
/* Codabar table checked against EN 798:1995 */
static const char CodaTable [ 20 ] [ 8 ] = {
{ ' 1 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 2 ' , ' 2 ' , ' 1 ' } , { ' 1 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 2 ' , ' 2 ' , ' 1 ' , ' 1 ' } , { ' 1 ' , ' 1 ' , ' 1 ' , ' 2 ' , ' 1 ' , ' 1 ' , ' 2 ' , ' 1 ' } ,
{ ' 2 ' , ' 2 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 1 ' } , { ' 1 ' , ' 1 ' , ' 2 ' , ' 1 ' , ' 1 ' , ' 2 ' , ' 1 ' , ' 1 ' } , { ' 2 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 2 ' , ' 1 ' , ' 1 ' } ,
{ ' 1 ' , ' 2 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 2 ' , ' 1 ' } , { ' 1 ' , ' 2 ' , ' 1 ' , ' 1 ' , ' 2 ' , ' 1 ' , ' 1 ' , ' 1 ' } , { ' 1 ' , ' 2 ' , ' 2 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 1 ' } ,
{ ' 2 ' , ' 1 ' , ' 1 ' , ' 2 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 1 ' } , { ' 1 ' , ' 1 ' , ' 1 ' , ' 2 ' , ' 2 ' , ' 1 ' , ' 1 ' , ' 1 ' } , { ' 1 ' , ' 1 ' , ' 2 ' , ' 2 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 1 ' } ,
{ ' 2 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 2 ' , ' 1 ' , ' 2 ' , ' 1 ' } , { ' 2 ' , ' 1 ' , ' 2 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 2 ' , ' 1 ' } , { ' 2 ' , ' 1 ' , ' 2 ' , ' 1 ' , ' 2 ' , ' 1 ' , ' 1 ' , ' 1 ' } ,
{ ' 1 ' , ' 1 ' , ' 2 ' , ' 1 ' , ' 2 ' , ' 1 ' , ' 2 ' , ' 1 ' } , { ' 1 ' , ' 1 ' , ' 2 ' , ' 2 ' , ' 1 ' , ' 2 ' , ' 1 ' , ' 1 ' } , { ' 1 ' , ' 2 ' , ' 1 ' , ' 2 ' , ' 1 ' , ' 1 ' , ' 2 ' , ' 1 ' } ,
{ ' 1 ' , ' 1 ' , ' 1 ' , ' 2 ' , ' 1 ' , ' 2 ' , ' 2 ' , ' 1 ' } , { ' 1 ' , ' 1 ' , ' 1 ' , ' 2 ' , ' 2 ' , ' 2 ' , ' 1 ' , ' 1 ' }
2016-02-20 13:50:15 +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
INTERNAL int pharma ( struct zint_symbol * symbol , unsigned char source [ ] , int length ) {
2016-02-20 13:50:15 +03:00
/* "Pharmacode can represent only a single integer from 3 to 131070. Unlike other
commonly used one - dimensional barcode schemes , pharmacode does not store the data in a
form corresponding to the human - readable digits ; the number is encoded in binary , rather
than decimal . Pharmacode is read from right to left : with n as the bar position starting
2022-05-12 22:35:06 +03:00
at 0 on the right , each narrow bar adds 2 ^ n to the value and each wide bar adds 2 ( 2 ^ n ) .
2016-02-20 13:50:15 +03:00
The minimum barcode is 2 bars and the maximum 16 , so the smallest number that could
be encoded is 3 ( 2 narrow bars ) and the biggest is 131070 ( 16 wide bars ) . "
- http : //en.wikipedia.org/wiki/Pharmacode */
/* This code uses the One Track Pharamacode calculating algorithm as recommended by
2020-09-30 14:19:12 +03:00
the specification at http : //www.laetus.com/laetus.php?request=file&id=69
( http : //www.gomaro.ch/ftproot/Laetus_PHARMA-CODE.pdf) */
2016-02-20 13:50:15 +03:00
2021-10-21 01:05:30 +03:00
int tester ;
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 counter , error_number = 0 , h ;
2016-02-20 13:50:15 +03:00
char inter [ 18 ] = { 0 } ; /* 131070 -> 17 bits */
2021-10-21 01:05:30 +03:00
char * in = inter ;
2016-02-20 13:50:15 +03:00
char dest [ 64 ] ; /* 17 * 2 + 1 */
2021-10-21 01:05:30 +03:00
char * d = dest ;
2016-02-20 13:50:15 +03:00
if ( length > 6 ) {
2021-06-12 18:01:16 +03:00
strcpy ( symbol - > errtxt , " 350: Input too long (6 character maximum) " ) ;
2016-02-20 13:50:15 +03:00
return ZINT_ERROR_TOO_LONG ;
}
2021-10-21 01:05:30 +03:00
tester = to_int ( source , length ) ;
if ( tester = = - 1 ) {
2021-07-06 21:53:31 +03:00
strcpy ( symbol - > errtxt , " 351: Invalid character in 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 ;
2016-02-20 13:50:15 +03:00
}
if ( ( tester < 3 ) | | ( tester > 131070 ) ) {
2021-06-10 20:04:27 +03:00
strcpy ( symbol - > errtxt , " 352: Data out of range (3 to 131070) " ) ;
2016-02-20 13:50:15 +03:00
return ZINT_ERROR_INVALID_DATA ;
}
do {
if ( ! ( tester & 1 ) ) {
2021-10-21 01:05:30 +03:00
* in + + = ' W ' ;
2016-02-20 13:50:15 +03:00
tester = ( tester - 2 ) / 2 ;
} else {
2021-10-21 01:05:30 +03:00
* in + + = ' N ' ;
2016-02-20 13:50:15 +03:00
tester = ( tester - 1 ) / 2 ;
}
} while ( tester ! = 0 ) ;
2021-10-21 01:05:30 +03:00
h = in - inter ;
for ( counter = h - 1 ; counter > = 0 ; counter - - ) {
* d + + = inter [ counter ] = = ' W ' ? ' 3 ' : ' 1 ' ;
* d + + = ' 2 ' ;
2016-02-20 13:50:15 +03:00
}
2021-10-21 01:05:30 +03:00
* - - d = ' \0 ' ; /* Chop off final bar */
2016-02-20 13:50:15 +03:00
2021-10-21 01:05:30 +03:00
expand ( symbol , dest , d - dest ) ;
2016-02-20 13:50:15 +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 ) {
/* Laetus Pharmacode Guide 1.2 Standard one-track height 8mm / 0.5mm (X) */
error_number = set_height ( symbol , 16.0f , 0.0f , 0.0f , 0 /*no_errtxt*/ ) ;
} else {
( void ) set_height ( symbol , 0.0f , 50.0f , 0.0f , 1 /*no_errtxt*/ ) ;
}
2021-06-19 15:11:23 +03:00
2016-02-20 13:50:15 +03:00
return error_number ;
2008-07-14 01:15:55 +04:00
}
2021-10-21 01:05:30 +03:00
static int pharma_two_calc ( int tester , char * d ) {
2016-02-20 13:50:15 +03:00
/* This code uses the Two Track Pharamacode defined in the document at
http : //www.laetus.com/laetus.php?request=file&id=69 and using a modified
algorithm from the One Track system . This standard accepts integet values
from 4 to 64570080. */
int counter , h ;
char inter [ 17 ] ;
2021-10-21 01:05:30 +03:00
char * in = inter ;
2016-02-20 13:50:15 +03:00
do {
switch ( tester % 3 ) {
case 0 :
2021-10-21 01:05:30 +03:00
* in + + = ' 3 ' ;
2016-02-20 13:50:15 +03:00
tester = ( tester - 3 ) / 3 ;
break ;
case 1 :
2021-10-21 01:05:30 +03:00
* in + + = ' 1 ' ;
2016-02-20 13:50:15 +03:00
tester = ( tester - 1 ) / 3 ;
break ;
case 2 :
2021-10-21 01:05:30 +03:00
* in + + = ' 2 ' ;
2016-02-20 13:50:15 +03:00
tester = ( tester - 2 ) / 3 ;
break ;
}
} while ( tester ! = 0 ) ;
2021-10-21 01:05:30 +03:00
h = in - inter ;
for ( counter = h - 1 ; counter > = 0 ; counter - - ) {
* d + + = inter [ counter ] ;
2016-02-20 13:50:15 +03:00
}
2021-10-21 01:05:30 +03:00
* d = ' \0 ' ;
2016-02-20 13:50:15 +03:00
2021-10-21 01:05:30 +03:00
return h ;
2008-07-14 01:15:55 +04:00
}
2019-12-19 03:37:55 +03:00
INTERNAL int pharma_two ( struct zint_symbol * symbol , unsigned char source [ ] , int length ) {
2016-02-20 13:50:15 +03:00
/* Draws the patterns for two track pharmacode */
2021-10-21 01:05:30 +03:00
int tester ;
2016-02-20 13:50:15 +03:00
char height_pattern [ 200 ] ;
unsigned int loopey , h ;
int writer ;
2021-10-21 01:05:30 +03:00
int error_number = 0 ;
2016-02-20 13:50:15 +03:00
if ( length > 8 ) {
2021-06-10 20:04:27 +03:00
strcpy ( symbol - > errtxt , " 354: Input too long (8 character maximum " ) ;
2016-02-20 13:50:15 +03:00
return ZINT_ERROR_TOO_LONG ;
}
2021-10-21 01:05:30 +03:00
tester = to_int ( source , length ) ;
if ( tester = = - 1 ) {
2021-07-06 21:53:31 +03:00
strcpy ( symbol - > errtxt , " 355: Invalid character in 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 ;
2016-02-20 13:50:15 +03:00
}
2021-10-21 01:05:30 +03:00
if ( ( tester < 4 ) | | ( tester > 64570080 ) ) {
strcpy ( symbol - > errtxt , " 353: Data out of range (4 to 64570080) " ) ;
return ZINT_ERROR_INVALID_DATA ;
2016-02-20 13:50:15 +03:00
}
2021-10-21 01:05:30 +03:00
h = pharma_two_calc ( tester , height_pattern ) ;
2016-02-20 13:50:15 +03:00
writer = 0 ;
for ( loopey = 0 ; loopey < h ; loopey + + ) {
if ( ( height_pattern [ loopey ] = = ' 2 ' ) | | ( height_pattern [ loopey ] = = ' 3 ' ) ) {
set_module ( symbol , 0 , writer ) ;
}
if ( ( height_pattern [ loopey ] = = ' 1 ' ) | | ( height_pattern [ loopey ] = = ' 3 ' ) ) {
set_module ( symbol , 1 , writer ) ;
}
writer + = 2 ;
}
symbol - > rows = 2 ;
symbol - > width = writer - 1 ;
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 ) {
/* Laetus Pharmacode Guide 1.4
- API: add new zint_symbol `dpmm` field for output resolution (BMP/
EMF/PCX/PNG/TIF only, i.e. excluding EPS, GIF & SVG)
- Add support for specifying scale by X-dimension and resolution
with new option `--scalexdimdp` for CLI/Tcl & new API function
`ZBarcode_Scale_From_XdimDp()` (+ `ZBarcode_XdimDp_From_Scale()`
& `ZBarcode_Default_Xdim()`) and new GUI popup; manual: document
- BMP/EMF/PCX/PNG/TIF: use new `dpmm` resolution field (for EMF
following Inkscape)
- backend_qt: add `dpmm()`, `vectorWidth()`, `vectorHeight()`,
`noPng()`, `getVersion()`, `takesGS1AIData()`, & `XdimDp` stuff
incl. new `QZintXdimDp` struct for passing around scale vars &
use in `getAsCLI()`; add comments
- Raise `scale` limit to 200 (from 100) to allow for large dpmm
- output: create directories & subdirectories as necessary for
output path using new function `out_fopen()` and use in BMP/EMF/
EPS/GIF/PCX/PNG/SVG/TIF
- DPLEIT/DPIDENT: format HRT according to (incomplete)
documentation, and set default height to 72X (from 50X)
- CODE128B renamed to CODE128AB as can use subsets A and/or B
- CODABAR: fix minimum height calc
- EMF: fix indexing of handles (zero-based not 1-based)
- GUI: fix symbology zap (previous technique of clearing and
re-loading settings without doing a sync no longer works);
fix UPCEAN guard descent enable
- MAILMARK: better error message if input < 14 characters
- GUI: add "Default" button for DAFT tracker ratio & enable/disable
various default buttons; use new `takesGS1AIData()` to
enable/disable GS1-specific checkboxes
- CLI: use new `validate_float()` to parse float options (7
significant digits allowed only, no scientific notation)
- DATAMATRIX/GRIDMATRIX/PDF417/QR/ULTRA: micro-optimize structapp
ID parse
- library/CLI: fiddle with static asserts (make CHAR_BIT sensitive,
supposedly)
- win32/README: update building libpng (assembly removed)
- README.linux: document incompatibility of Qt6 >= 6.3
- manual: expand Barcode Studio waffle
- test suite: change range separator to hyphen and allow multiple
excludes
2022-12-03 00:39:01 +03:00
Two - track height min 8 mm / 2 mm ( X max ) = 4 X ( 2 X per row ) , standard 8 mm / 1 mm = 8 X ,
max 12 mm / 0.8 mm ( X min ) = 15 X */
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 = set_height ( symbol , 2.0f , 8.0f , 15.0f , 0 /*no_errtxt*/ ) ;
} else {
( void ) set_height ( symbol , 0.0f , 10.0f , 0.0f , 1 /*no_errtxt*/ ) ;
}
2016-02-20 13:50:15 +03:00
return error_number ;
2008-07-14 01:15:55 +04:00
}
2016-02-20 13:50:15 +03:00
/* The Codabar system consisting of simple substitution */
2019-12-19 03:37:55 +03:00
INTERNAL int codabar ( struct zint_symbol * symbol , unsigned char source [ ] , int length ) {
2016-02-20 13:50:15 +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
int i , error_number = 0 ;
2021-10-21 01:05:30 +03:00
int posns [ 60 ] ;
2016-02-20 13:50:15 +03:00
char dest [ 512 ] ;
2021-10-21 01:05:30 +03:00
char * d = dest ;
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 add_checksum , count = 0 , checksum = 0 ;
2021-06-19 15:11:23 +03:00
int d_chars = 0 ;
2016-02-20 13:50:15 +03:00
if ( length > 60 ) { /* No stack smashing please */
2021-06-10 20:04:27 +03:00
strcpy ( symbol - > errtxt , " 356: Input too long (60 character maximum) " ) ;
2016-02-20 13:50:15 +03:00
return ZINT_ERROR_TOO_LONG ;
}
2020-06-04 20:45:25 +03:00
/* BS EN 798:1995 4.2 "'Codabar' symbols shall consist of ... b) start character;
2021-06-19 15:11:23 +03:00
c ) one or more symbol characters representing data . . . d ) stop character . . . " */
2020-06-04 20:45:25 +03:00
if ( length < 3 ) {
2021-06-10 20:04:27 +03:00
strcpy ( symbol - > errtxt , " 362: Input too short (3 character minimum) " ) ;
2020-06-04 20:45:25 +03:00
return ZINT_ERROR_TOO_LONG ;
2016-02-20 13:50:15 +03:00
}
2021-10-21 01:05:30 +03:00
to_upper ( source , length ) ;
2020-06-04 20:45:25 +03:00
2016-02-20 13:50:15 +03:00
/* Codabar must begin and end with the characters A, B, C or D */
2016-03-03 00:12:38 +03:00
if ( ( source [ 0 ] ! = ' A ' ) & & ( source [ 0 ] ! = ' B ' ) & & ( source [ 0 ] ! = ' C ' )
2016-02-20 13:50:15 +03:00
& & ( source [ 0 ] ! = ' D ' ) ) {
2020-06-04 20:45:25 +03:00
strcpy ( symbol - > errtxt , " 358: Does not begin with \" A \" , \" B \" , \" C \" or \" D \" " ) ;
2016-02-20 13:50:15 +03:00
return ZINT_ERROR_INVALID_DATA ;
}
if ( ( source [ length - 1 ] ! = ' A ' ) & & ( source [ length - 1 ] ! = ' B ' ) & &
( source [ length - 1 ] ! = ' C ' ) & & ( source [ length - 1 ] ! = ' D ' ) ) {
2020-06-04 20:45:25 +03:00
strcpy ( symbol - > errtxt , " 359: Does not end with \" A \" , \" B \" , \" C \" or \" D \" " ) ;
2016-02-20 13:50:15 +03:00
return ZINT_ERROR_INVALID_DATA ;
}
2021-10-21 01:05:30 +03:00
if ( ! is_sane_lookup ( CALCIUM , sizeof ( CALCIUM ) - 1 , source , length , posns ) ) {
sprintf ( symbol - > errtxt , " 357: Invalid character in data ( \" %s \" only) " , CALCIUM ) ;
return ZINT_ERROR_INVALID_DATA ;
}
2020-06-04 20:45:25 +03:00
/* And must not use A, B, C or D otherwise (BS EN 798:1995 4.3.2) */
2021-10-21 01:05:30 +03:00
if ( ! is_sane ( CALCIUM_INNER_F , source + 1 , length - 2 ) ) {
strcpy ( symbol - > errtxt , " 363: Cannot contain \" A \" , \" B \" , \" C \" or \" D \" " ) ;
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 ;
2020-06-04 20:45:25 +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
/* Add check character: 1 don't show to HRT, 2 do show to HRT
( unfortunately to maintain back - compatibility , this is reverse of C25 ) */
add_checksum = symbol - > option_2 = = 1 | | symbol - > option_2 = = 2 ;
2020-06-04 20:45:25 +03:00
2021-10-21 01:05:30 +03:00
for ( i = 0 ; i < length ; i + + , d + = 8 ) {
2020-06-04 20:45:25 +03:00
if ( add_checksum ) {
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
/* BS EN 798:1995 A.3 suggests using ISO 7064 algorithm but leaves it application defined.
Following BWIPP and TEC - IT , use this simple mod - 16 algorithm ( not in ISO 7064 ) */
2021-10-21 01:05:30 +03:00
count + = posns [ i ] ;
2020-06-04 20:45:25 +03:00
if ( i + 1 = = length ) {
checksum = count % 16 ;
if ( checksum ) {
checksum = 16 - checksum ;
}
if ( symbol - > debug & ZINT_DEBUG_PRINT ) {
2021-10-21 01:05:30 +03:00
printf ( " Codabar: %s, count %d, checksum %d (%c) \n " , source , count , checksum , CALCIUM [ checksum ] ) ;
2020-06-04 20:45:25 +03:00
}
2021-10-21 01:05:30 +03:00
memcpy ( d , CodaTable [ checksum ] , 8 ) ;
d + = 8 ;
2020-06-04 20:45:25 +03:00
}
}
2021-10-21 01:05:30 +03:00
memcpy ( d , CodaTable [ posns [ i ] ] , 8 ) ;
2021-06-19 15:11:23 +03:00
if ( source [ i ] = = ' / ' | | source [ i ] = = ' : ' | | source [ i ] = = ' . ' | | source [ i ] = = ' + ' ) { /* Wide data characters */
d_chars + + ;
}
2016-02-20 13:50:15 +03:00
}
2021-10-21 01:05:30 +03:00
expand ( symbol , dest , d - dest ) ;
2021-06-19 15:11:23 +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 ) {
- API: add new zint_symbol `dpmm` field for output resolution (BMP/
EMF/PCX/PNG/TIF only, i.e. excluding EPS, GIF & SVG)
- Add support for specifying scale by X-dimension and resolution
with new option `--scalexdimdp` for CLI/Tcl & new API function
`ZBarcode_Scale_From_XdimDp()` (+ `ZBarcode_XdimDp_From_Scale()`
& `ZBarcode_Default_Xdim()`) and new GUI popup; manual: document
- BMP/EMF/PCX/PNG/TIF: use new `dpmm` resolution field (for EMF
following Inkscape)
- backend_qt: add `dpmm()`, `vectorWidth()`, `vectorHeight()`,
`noPng()`, `getVersion()`, `takesGS1AIData()`, & `XdimDp` stuff
incl. new `QZintXdimDp` struct for passing around scale vars &
use in `getAsCLI()`; add comments
- Raise `scale` limit to 200 (from 100) to allow for large dpmm
- output: create directories & subdirectories as necessary for
output path using new function `out_fopen()` and use in BMP/EMF/
EPS/GIF/PCX/PNG/SVG/TIF
- DPLEIT/DPIDENT: format HRT according to (incomplete)
documentation, and set default height to 72X (from 50X)
- CODE128B renamed to CODE128AB as can use subsets A and/or B
- CODABAR: fix minimum height calc
- EMF: fix indexing of handles (zero-based not 1-based)
- GUI: fix symbology zap (previous technique of clearing and
re-loading settings without doing a sync no longer works);
fix UPCEAN guard descent enable
- MAILMARK: better error message if input < 14 characters
- GUI: add "Default" button for DAFT tracker ratio & enable/disable
various default buttons; use new `takesGS1AIData()` to
enable/disable GS1-specific checkboxes
- CLI: use new `validate_float()` to parse float options (7
significant digits allowed only, no scientific notation)
- DATAMATRIX/GRIDMATRIX/PDF417/QR/ULTRA: micro-optimize structapp
ID parse
- library/CLI: fiddle with static asserts (make CHAR_BIT sensitive,
supposedly)
- win32/README: update building libpng (assembly removed)
- README.linux: document incompatibility of Qt6 >= 6.3
- manual: expand Barcode Studio waffle
- test suite: change range separator to hyphen and allow multiple
excludes
2022-12-03 00:39:01 +03:00
/* BS EN 798:1995 4.4.1 (d) max of 5mm / 0.43mm (X max) ~ 11.628 or 15% of width where (taking N =
narrow / wide ratio as 2 and I = X ) width = ( ( 2 * N + 5 ) * C + ( N – 1 ) * ( D + 2 ) ) * X + I * ( C – 1 ) + 2 Q
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
= ( ( 4 + 5 ) * C + ( D + 2 ) + C - 1 + 2 * 10 ) * X = ( 10 * C + D + 21 ) * X
Length ( C ) includes start / stop chars */
- API: add new zint_symbol `dpmm` field for output resolution (BMP/
EMF/PCX/PNG/TIF only, i.e. excluding EPS, GIF & SVG)
- Add support for specifying scale by X-dimension and resolution
with new option `--scalexdimdp` for CLI/Tcl & new API function
`ZBarcode_Scale_From_XdimDp()` (+ `ZBarcode_XdimDp_From_Scale()`
& `ZBarcode_Default_Xdim()`) and new GUI popup; manual: document
- BMP/EMF/PCX/PNG/TIF: use new `dpmm` resolution field (for EMF
following Inkscape)
- backend_qt: add `dpmm()`, `vectorWidth()`, `vectorHeight()`,
`noPng()`, `getVersion()`, `takesGS1AIData()`, & `XdimDp` stuff
incl. new `QZintXdimDp` struct for passing around scale vars &
use in `getAsCLI()`; add comments
- Raise `scale` limit to 200 (from 100) to allow for large dpmm
- output: create directories & subdirectories as necessary for
output path using new function `out_fopen()` and use in BMP/EMF/
EPS/GIF/PCX/PNG/SVG/TIF
- DPLEIT/DPIDENT: format HRT according to (incomplete)
documentation, and set default height to 72X (from 50X)
- CODE128B renamed to CODE128AB as can use subsets A and/or B
- CODABAR: fix minimum height calc
- EMF: fix indexing of handles (zero-based not 1-based)
- GUI: fix symbology zap (previous technique of clearing and
re-loading settings without doing a sync no longer works);
fix UPCEAN guard descent enable
- MAILMARK: better error message if input < 14 characters
- GUI: add "Default" button for DAFT tracker ratio & enable/disable
various default buttons; use new `takesGS1AIData()` to
enable/disable GS1-specific checkboxes
- CLI: use new `validate_float()` to parse float options (7
significant digits allowed only, no scientific notation)
- DATAMATRIX/GRIDMATRIX/PDF417/QR/ULTRA: micro-optimize structapp
ID parse
- library/CLI: fiddle with static asserts (make CHAR_BIT sensitive,
supposedly)
- win32/README: update building libpng (assembly removed)
- README.linux: document incompatibility of Qt6 >= 6.3
- manual: expand Barcode Studio waffle
- test suite: change range separator to hyphen and allow multiple
excludes
2022-12-03 00:39:01 +03:00
const float min_height_min = stripf ( 5.0f / 0.43f ) ;
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
float min_height = stripf ( ( 10.0f * ( ( add_checksum ? length + 1 : length ) + 2.0f ) + d_chars + 21.0f ) * 0.15f ) ;
if ( min_height < min_height_min ) {
min_height = min_height_min ;
}
/* Using 50 as default as none recommended */
error_number = set_height ( symbol , min_height , min_height > 50.0f ? min_height : 50.0f , 0.0f , 0 /*no_errtxt*/ ) ;
} else {
( void ) set_height ( symbol , 0.0f , 50.0f , 0.0f , 1 /*no_errtxt*/ ) ;
2021-06-19 15:11:23 +03:00
}
2016-02-20 13:50:15 +03:00
ustrcpy ( symbol - > text , source ) ;
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 - > option_2 = = 2 ) {
2021-10-21 01:05:30 +03:00
symbol - > text [ length - 1 ] = CALCIUM [ checksum ] ; /* Place before final A/B/C/D character (BS EN 798:1995 A.3) */
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
symbol - > text [ length ] = source [ length - 1 ] ;
symbol - > text [ length + 1 ] = ' \0 ' ;
}
2016-02-20 13:50:15 +03:00
return error_number ;
2008-09-02 23:44:41 +04:00
}
2016-02-20 13:50:15 +03:00
/* Italian Pharmacode */
2019-12-19 03:37:55 +03:00
INTERNAL int code32 ( struct zint_symbol * symbol , unsigned char source [ ] , int length ) {
2021-10-21 01:05:30 +03:00
static const char TABELLA [ ] = " 0123456789BCDFGHJKLMNPQRSTUVWXYZ " ;
2021-06-19 15:11:23 +03:00
int i , zeroes , error_number = 0 , checksum , checkpart , checkdigit ;
2016-02-20 13:50:15 +03:00
char localstr [ 10 ] , risultante [ 7 ] ;
2017-09-10 18:03:09 +03:00
long int pharmacode , devisor ;
2016-02-20 13:50:15 +03:00
int codeword [ 6 ] ;
/* Validate the input */
if ( length > 8 ) {
2021-06-10 20:04:27 +03:00
strcpy ( symbol - > errtxt , " 360: Input too long (8 character maximum) " ) ;
2016-02-20 13:50:15 +03:00
return ZINT_ERROR_TOO_LONG ;
}
2021-10-21 01:05:30 +03:00
if ( ! is_sane ( NEON_F , source , length ) ) {
2021-07-06 21:53:31 +03:00
strcpy ( symbol - > errtxt , " 361: Invalid character in 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 ;
2016-02-20 13:50:15 +03:00
}
/* Add leading zeros as required */
zeroes = 8 - length ;
memset ( localstr , ' 0 ' , zeroes ) ;
2020-06-04 20:45:25 +03:00
ustrcpy ( localstr + zeroes , source ) ;
2016-02-20 13:50:15 +03:00
/* Calculate the check digit */
checksum = 0 ;
for ( i = 0 ; i < 4 ; i + + ) {
checkpart = ctoi ( localstr [ i * 2 ] ) ;
checksum + = checkpart ;
checkpart = 2 * ( ctoi ( localstr [ ( i * 2 ) + 1 ] ) ) ;
if ( checkpart > = 10 ) {
checksum + = ( checkpart - 10 ) + 1 ;
} else {
checksum + = checkpart ;
}
}
/* Add check digit to data string */
checkdigit = checksum % 10 ;
localstr [ 8 ] = itoc ( checkdigit ) ;
localstr [ 9 ] = ' \0 ' ;
/* Convert string into an integer value */
pharmacode = atoi ( localstr ) ;
/* Convert from decimal to base-32 */
devisor = 33554432 ;
for ( i = 5 ; i > = 0 ; i - - ) {
2017-10-23 22:34:31 +03:00
long int remainder ;
2016-02-20 13:50:15 +03:00
codeword [ i ] = pharmacode / devisor ;
2017-10-16 20:26:54 +03:00
remainder = pharmacode % devisor ;
2016-02-20 13:50:15 +03:00
pharmacode = remainder ;
devisor / = 32 ;
}
/* Look up values in 'Tabella di conversione' */
for ( i = 5 ; i > = 0 ; i - - ) {
2021-10-21 01:05:30 +03:00
risultante [ 5 - i ] = TABELLA [ codeword [ i ] ] ;
2016-02-20 13:50:15 +03:00
}
risultante [ 6 ] = ' \0 ' ;
/* Plot the barcode using Code 39 */
2021-10-21 01:05:30 +03:00
error_number = code39 ( symbol , ( unsigned char * ) risultante , 6 ) ;
2021-08-05 18:34:45 +03:00
if ( error_number ! = 0 ) { /* Should never happen */
return error_number ; /* Not reached */
2016-02-20 13:50:15 +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 ) {
/* Allegato A Caratteristiche tecniche del bollino farmaceutico
( https : //www.gazzettaufficiale.it/do/atto/serie_generale/caricaPdf?cdimg=14A0566800100010110001
& dgu = 2014 - 07 - 18 & art . dataPubblicazioneGazzetta = 2014 - 07 - 18 & art . codiceRedazionale = 14 A05668 & art . num = 1
& art . tiposerie = SG )
X given as 0.250 mm ; height ( and quiet zones ) left to ISO / IEC 16388 : 2007 ( Code 39 )
So min height 5 mm = 5 mm / 0.25 mm = 20 > 15 % of width , i . e . ( 10 * 8 + 19 ) * 0.15 = 14.85 */
error_number = set_height ( symbol , 20.0f , 20.0f , 0.0f , 0 /*no_errtxt*/ ) ; /* Use as default also */
} else {
( void ) set_height ( symbol , 0.0f , 50.0f , 0.0f , 1 /*no_errtxt*/ ) ;
}
2021-06-19 15:11:23 +03:00
2016-02-20 13:50:15 +03:00
/* Override the normal text output with the Pharmacode number */
2020-06-04 20:45:25 +03:00
ustrcpy ( symbol - > text , " A " ) ;
ustrcat ( symbol - > text , localstr ) ;
2016-02-20 13:50:15 +03:00
return error_number ;
2008-07-14 01:15:55 +04:00
}
2022-05-12 22:35:06 +03:00
/* vim: set ts=4 sw=4 et : */