0
0
mirror of https://github.com/fralx/LimeReport.git synced 2025-07-01 17:23:46 +03:00

Merge tag '1.6.4' into develop

Finish 1.6.4
This commit is contained in:
Alexander Arin 2022-01-26 20:15:32 +03:00
commit 936377e652
633 changed files with 304130 additions and 67938 deletions

View File

@ -1,5 +1,5 @@
ZINT_PATH = $$PWD/zint-2.6.1
ZINT_VERSION = 2.6.1
ZINT_PATH = $$PWD/zint-2.10.0
ZINT_VERSION = 2.10.0
INCLUDEPATH += $${ZINT_PATH}/backend $${ZINT_PATH}/backend_qt
DEPENDPATH += $${ZINT_PATH}/backend $${ZINT_PATH}/backend_qt
include($${ZINT_PATH}/backend_qt/backend_qt.pro)

View File

@ -3,57 +3,63 @@
find_package(PNG)
set(ZINT_FILES
zint-2.6.1/backend/2of5.c
zint-2.6.1/backend/auspost.c
zint-2.6.1/backend/aztec.c
zint-2.6.1/backend/bmp.c
zint-2.6.1/backend/codablock.c
zint-2.6.1/backend/code.c
zint-2.6.1/backend/code1.c
zint-2.6.1/backend/code128.c
zint-2.6.1/backend/code16k.c
zint-2.6.1/backend/code49.c
zint-2.6.1/backend/common.c
zint-2.6.1/backend/composite.c
zint-2.6.1/backend/dllversion.c
zint-2.6.1/backend/dmatrix.c
zint-2.6.1/backend/dotcode.c
zint-2.6.1/backend/eci.c
zint-2.6.1/backend/emf.c
zint-2.6.1/backend/gif.c
zint-2.6.1/backend/gridmtx.c
zint-2.6.1/backend/gs1.c
zint-2.6.1/backend/hanxin.c
zint-2.6.1/backend/imail.c
zint-2.6.1/backend/large.c
zint-2.6.1/backend/library.c
zint-2.6.1/backend/libzint.rc
zint-2.6.1/backend/maxicode.c
zint-2.6.1/backend/medical.c
zint-2.6.1/backend/pcx.c
zint-2.6.1/backend/pdf417.c
zint-2.6.1/backend/plessey.c
zint-2.6.1/backend/png.c
zint-2.6.1/backend/postal.c
zint-2.6.1/backend/ps.c
zint-2.6.1/backend/qr.c
zint-2.6.1/backend/raster.c
zint-2.6.1/backend/reedsol.c
zint-2.6.1/backend/render.c
zint-2.6.1/backend/rss.c
zint-2.6.1/backend/svg.c
zint-2.6.1/backend/telepen.c
zint-2.6.1/backend/tif.c
zint-2.6.1/backend/upcean.c
zint-2.6.1/backend_qt/qzint.cpp
zint-2.10.0/backend/2of5.c \
zint-2.10.0/backend/auspost.c \
zint-2.10.0/backend/aztec.c \
zint-2.10.0/backend/bmp.c \
zint-2.10.0/backend/codablock.c \
zint-2.10.0/backend/code.c \
zint-2.10.0/backend/code1.c \
zint-2.10.0/backend/code128.c \
zint-2.10.0/backend/code16k.c \
zint-2.10.0/backend/code49.c \
zint-2.10.0/backend/common.c \
zint-2.10.0/backend/composite.c \
zint-2.10.0/backend/dmatrix.c \
zint-2.10.0/backend/dotcode.c \
zint-2.10.0/backend/eci.c \
zint-2.10.0/backend/emf.c \
zint-2.10.0/backend/gb18030.c \
zint-2.10.0/backend/gb2312.c \
zint-2.10.0/backend/general_field.c \
zint-2.10.0/backend/gif.c \
zint-2.10.0/backend/gridmtx.c \
zint-2.10.0/backend/gs1.c \
zint-2.10.0/backend/hanxin.c \
zint-2.10.0/backend/imail.c \
zint-2.10.0/backend/large.c \
zint-2.10.0/backend/library.c \
zint-2.10.0/backend/mailmark.c \
zint-2.10.0/backend/maxicode.c \
zint-2.10.0/backend/medical.c \
zint-2.10.0/backend/output.c \
zint-2.10.0/backend/pcx.c \
zint-2.10.0/backend/pdf417.c \
zint-2.10.0/backend/plessey.c \
zint-2.10.0/backend/png.c \
zint-2.10.0/backend/postal.c \
zint-2.10.0/backend/ps.c \
zint-2.10.0/backend/qr.c \
zint-2.10.0/backend/raster.c \
zint-2.10.0/backend/reedsol.c \
zint-2.10.0/backend/rss.c \
zint-2.10.0/backend/sjis.c \
zint-2.10.0/backend/svg.c \
zint-2.10.0/backend/telepen.c \
zint-2.10.0/backend/tif.c \
zint-2.10.0/backend/ultra.c \
zint-2.10.0/backend/upcean.c \
zint-2.10.0/backend/vector.c \
zint-2.10.0/backend/dllversion.c \
zint-2.10.0/backend_qt/qzint.cpp
)
if (ENABLE_ZINT)
add_library(QZint STATIC ${ZINT_FILES})
target_include_directories(QZint PUBLIC zint-2.6.1/backend)
target_include_directories(QZint PUBLIC zint-2.6.1/backend_qt)
target_include_directories(QZint PUBLIC zint-2.10.0/backend)
target_include_directories(QZint PUBLIC zint-2.10.0/backend_qt)
target_link_libraries(QZint PUBLIC
Qt${QT_VERSION_MAJOR}::Core

6
3rdparty/zint-2.10.0/.editorconfig vendored Normal file
View File

@ -0,0 +1,6 @@
root=true
[*]
end_of_line = lf
indent_style = space
indent_size = 4

19
3rdparty/zint-2.10.0/.gitignore vendored Normal file
View File

@ -0,0 +1,19 @@
build/
*~
*.[ao]
*.swp
*.swo
*.suo
*.pro.user
.directory
CMakeLists.txt.user*
Makefile
backend/Makefile
frontend/Makefile
build-*
win32/*.VC.opendb
win32/*.VC.db
win32/Debug
win32/Release
win32/x64
extern/*

196
3rdparty/zint-2.10.0/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,196 @@
# Copyright (C) 2008 by BogDan Vatra < bogdan@licentia.eu >
# Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com>
# vim: set ts=4 sw=4 et :
cmake_minimum_required(VERSION 3.5)
project(zint-package)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(ZINT_VERSION_MAJOR 2)
set(ZINT_VERSION_MINOR 10)
set(ZINT_VERSION_RELEASE 0)
set(ZINT_VERSION_BUILD 0) # Set to 0 before release, set to 9 after release
set(ZINT_VERSION "${ZINT_VERSION_MAJOR}.${ZINT_VERSION_MINOR}.${ZINT_VERSION_RELEASE}.${ZINT_VERSION_BUILD}")
add_definitions(-DZINT_VERSION=\"${ZINT_VERSION}\")
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
option(ZINT_DEBUG "Set debug compile flags" OFF)
option(ZINT_SANITIZE "Set sanitize compile/link flags" OFF)
option(ZINT_TEST "Set test compile flag" OFF)
option(ZINT_COVERAGE "Set code coverage flags" OFF)
option(ZINT_STATIC "Build static library" OFF)
option(ZINT_USE_PNG "Build with PNG support" ON)
option(ZINT_USE_QT "Build with QT support" ON)
include(SetPaths.cmake)
include(CheckCXXCompilerFlag)
include(CheckFunctionExists)
if(NOT MSVC) # Use default warnings if MSVC otherwise inundated
check_cxx_compiler_flag("-Wall" CXX_COMPILER_FLAG_WALL)
if(CXX_COMPILER_FLAG_WALL)
add_compile_options("-Wall")
endif()
check_cxx_compiler_flag("-Wextra" CXX_COMPILER_FLAG_WEXTRA)
if(CXX_COMPILER_FLAG_WEXTRA)
add_compile_options("-Wextra")
endif()
check_cxx_compiler_flag("-Wpedantic" CXX_COMPILER_FLAG_WPEDANTIC)
if(CXX_COMPILER_FLAG_WPEDANTIC)
add_compile_options("-Wpedantic")
endif()
endif()
if(ZINT_DEBUG)
check_cxx_compiler_flag("-g" CXX_COMPILER_FLAG_G)
if(CXX_COMPILER_FLAG_G)
add_compile_options("-g")
endif()
check_cxx_compiler_flag("-O0" CXX_COMPILER_FLAG_O0)
if(CXX_COMPILER_FLAG_O0)
add_compile_options("-O0")
endif()
endif()
if(ZINT_TEST)
enable_testing()
endif()
if(ZINT_COVERAGE)
set(CMAKE_REQUIRED_LIBRARIES -fprofile-arcs)
check_cxx_compiler_flag(--coverage CXX_COMPILER_FLAG_COVERAGE)
unset(CMAKE_REQUIRED_LIBRARIES)
if(CXX_COMPILER_FLAG_COVERAGE)
add_compile_options(--coverage)
link_libraries(-fprofile-arcs)
check_cxx_compiler_flag(-O0 CXX_COMPILER_FLAG_O0)
if(CXX_COMPILER_FLAG_O0)
add_compile_options(-O0)
endif()
endif()
endif()
if(ZINT_SANITIZE)
if(MSVC)
if(MSVC_VERSION GREATER_EQUAL 1920)
add_compile_options(-fsanitize=address)
message(STATUS "ZINT_SANITIZE: setting -fsanitize=address for MSVC 2019")
else()
message(STATUS "ZINT_SANITIZE: ignoring for MSVC < 2019")
endif()
else()
set(SANITIZERS address undefined)
foreach(sanitizer IN ITEMS ${SANITIZERS})
set(CMAKE_REQUIRED_LIBRARIES -fsanitize=${sanitizer})
check_cxx_compiler_flag(-fsanitize=${sanitizer} CXX_COMPILER_FLAG_FSANITIZE_${sanitizer})
if(CXX_COMPILER_FLAG_FSANITIZE_${sanitizer})
add_compile_options(-fsanitize=${sanitizer})
link_libraries(-fsanitize=${sanitizer})
endif()
unset(CMAKE_REQUIRED_LIBRARIES)
endforeach()
if(NOT ZINT_DEBUG AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# Gives warning on MainWindow::setupUI() and retries (& takes forever) if var-tracking-assignments enabled
add_compile_options(-fno-var-tracking-assignments)
endif()
endif()
endif()
if(APPLE)
if(UNIVERSAL) # TODO: make universal binary
if(NOT ZINT_HAS_BEEN_RUN_BEFORE)
if(EXISTS /Developer/SDKs/MacOSX10.5.sdk OR EXISTS /SDKs/MacOSX10.5.sdk)
set(CMAKE_OSX_ARCHITECTURES "ppc;i386;ppc64;x86_64" CACHE STRING "Build architectures for OSX" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden -Wl -single_module " CACHE STRING
"Flags used by the compiler during all build types." FORCE)
elseif(EXISTS /Developer/SDKs/MacOSX10.4u.sdk OR EXISTS /SDKs/MacOSX10.4u.sdk)
set(CMAKE_OSX_ARCHITECTURES "ppc;i386" CACHE STRING "Build architectures for OSX" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden -Wl -single_module " CACHE STRING
"Flags used by the compiler during all build types." FORCE)
endif()
message("Build architectures for OSX:${CMAKE_OSX_ARCHITECTURES}")
endif()
else()
set(CMAKE_OSX_SYSROOT "/")
endif()
endif()
check_function_exists(getopt HAVE_GETOPT)
if(NOT HAVE_GETOPT)
add_subdirectory(getopt)
endif()
add_subdirectory(backend)
add_subdirectory(frontend)
if(NOT ZINT_USE_QT)
message(STATUS "Qt support was disabled for this build")
elseif($ENV{CMAKE_PREFIX_PATH} MATCHES "6[.][0-9][.][0-9]")
set(USE_QT6 TRUE)
message(STATUS "Using Qt6")
cmake_policy(SET CMP0012 NEW) # Recognize constants in if()
cmake_policy(SET CMP0072 NEW) # Choose OpenGL over legacy GL
find_package(Qt6Widgets)
find_package(Qt6Gui)
find_package(Qt6UiTools)
find_package(Qt6Xml)
if(Qt6Widgets_FOUND AND Qt6Gui_FOUND AND Qt6UiTools_FOUND AND Qt6Xml_FOUND)
message(STATUS "Qt version: " ${Qt6Core_VERSION_MAJOR}.${Qt6Core_VERSION_MINOR}.${Qt6Core_VERSION_PATCH})
add_subdirectory(backend_qt)
add_subdirectory(frontend_qt)
else()
message(STATUS "Could NOT find Qt6")
endif()
else()
message(STATUS "Using Qt5")
find_package(Qt5Widgets)
find_package(Qt5Gui)
find_package(Qt5UiTools)
find_package(Qt5Xml)
if(Qt5Widgets_FOUND AND Qt5Gui_FOUND AND Qt5UiTools_FOUND AND Qt5Xml_FOUND)
message(STATUS "Qt version: " ${Qt5Core_VERSION_STRING})
# Old Qt does not provide QT_VERSION_MAJOR
if (NOT QT_VERSION_MAJOR)
string(SUBSTRING ${Qt5Core_VERSION_STRING} 0 1 QT_VERSION_MAJOR)
endif()
add_subdirectory(backend_qt)
add_subdirectory(frontend_qt)
else()
message(STATUS "Could NOT find Qt5")
endif()
endif()
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
# staniek: don't install
if(DATA_INSTALL_DIR)
set(CMAKE_MODULES_INSTALL_PATH ${DATA_INSTALL_DIR}/cmake/modules)
else()
set(CMAKE_MODULES_INSTALL_PATH ${CMAKE_ROOT}/Modules)
endif()
install(FILES cmake/modules/FindZint.cmake DESTINATION ${CMAKE_MODULES_INSTALL_PATH} COMPONENT Devel)
# This needs to be run very last so other parts of the scripts can take
# advantage of this.
if(NOT ZINT_HAS_BEEN_RUN_BEFORE)
set(ZINT_HAS_BEEN_RUN_BEFORE 1 CACHE INTERNAL
"Flag to track whether this is the first time running CMake or if CMake has been configured before")
endif()

675
3rdparty/zint-2.10.0/ChangeLog vendored Normal file
View File

@ -0,0 +1,675 @@
Version 2.10.0 2021-08-14
=========================
**Incompatible changes**
------------------------
- Add halign (horizontal align) to struct zint_vector_string
NOTE: backward incompatible text drawing for UPC/EAN
- Change height and row_height array to floats
NOTE: may cause changes in heights
Changes
-------
- Move project history/version from manual.txt and backend/README into this file
- Command line switches -d or -i for code data may now be at any position.
- Add rotation for vector formats
- Change double to float for performance in many internal places
- Ticket 197: optimize raster scaling for 0.5 substeps;
ignore raster scaling < 0.5 as pixels lost.
- Ticket 197: add output option to bypass time-intensive buffer_plot()
(OUT_BUFFER_INTERMEDIATE)
- Reduce BMP size by using 1 bit per pixel (except Ultracode)
- New warn_level field, WARN_FAIL_ALL
- Add GS1NOCHECK_MODE to input_mode (note was ZPL compatibility mode
WARN_ZPL_COMPAT to warn_level)
- Remove version info from zint.h and put in zintconfig.h via zintconfig.h.in
- Add ZBarcode_Cap()
- Add GUI symbology filter, separate settings for each symbology
- Require cmake 3.5, use PNG::PNG and add Qt6 build option
- Make library fully stack-based so reentrant apart from file operations
- Performance improvements (large data) for AZTEC/HANXIN/GRIDMATRIX/PDF417/QR
- Option scmvv for MaxiCode #212; postcode needn't be space-filled
- eci: Add support for all ECIs (Big5, Korean, UCS-2BE)
- CLI: Handle UTF-8 args on Windows; -b <barcode name>
- DATAMATRIX: make EOD encodation strictly ISO 16022 compliant
- png.c: Use palette for file size savings
- tif.c: Use palette/bilevel/LZW to reduce file size, alpha/CMYK support
- Option gs1parens (GS1PARENS_MODE)
- MAXICODE: Rejig raster output to more closely match ISO 16023:2000
- C25STANDARD/C25INTER/C25IATA/C25LOGIC/C25IND: add check digit option (#216)
- Use zint-64.svg for smoother icons, props frhun
- Add whitespace_height to zint_symbol (vertical whitespace)
- AZTEC: optimize populate_map (good for small data) - avoids MSVC bug also
- Various workarounds for other MSVC bugs
- CMake: Windows compatible, backend/tests & frontend/tests now subprojects
using new zint_add_test.cmake file, static build, new ZINT_USE_PNG and
ZINT_USE_QT options, getopt moved to subproject and getopt detection,
sanitizer flag detection, and many other improvements, props Alonso Schaich
- PLESSEY: add options NCR weighted mod-10, hide check digit(s) in HRT
- Fuller error messages; more comments zint.h
- CMake: simplication and modernization, Qt5/6 version, props Null Void
- POSTNET/PLANET: allow up to 38 chars (ZINT_WARN_NONCOMPLIANT) (see [d7ac9c])
- RMQR: update to new draft ISO/IEC JTC1/SC31N000 (Draft 2019-6-24)
- ULTRA: update max size and min cols based on BWIPP 2021-07-14 update
Bugs
----
- Code16k selects GS1 mode by default in GUI
- Ultracode: use white pixels instead background for white modules.
- EMF: fix Ultracode colours.
- Ultracode: fix count of codewords when using reader init mode
- Databar Limited: add 5 right guard spaces (ISO/IEC 24723:2010 6.2 (e))
- Data Matrix: avoid unnecessary latch in X12 mode at end of data, #208
- Data Matrix: fix eod shift -> 0 pad
- POSTNET/PLANET: remove extra 1 module space
- Aztec: fix bit-stuffing (again!) and Aztec Rune: fix for data >= 128
- EAN composite: allow for check digit + buffer overflow for too long add-on
- Han Xin fix 0xFFE terminator
- GUI: Use UTF-8 for QSettings (non-ASCII was getting garbled on restore)
- DOTCODE: Fix best_mask -> high_score prime test
- CODEONE: various fixes, ECI support
- #218 Prevent buffer overflow in ean_leading_zeroes by checking max lengths
- MAXICODE: fix mask typos for ECI 3/4 bytes
- Fix UPCEAN small font ignored/disabled (introduced [1adba1])
- get_best_eci: check UTF-8 before returning 26
- MAXICODE: fix shifting from sets C/D/E to A/B (only latch available)
- EAN14, NVE18: fix checksum calc for zero-filled input
- png: ULTRA: allow for fgcolour if bind/box (MR #111)
- DOTCODE: allow for max 200 cols in CLI, GUI, Tcl
- CODEONE/DATAMATRIX/MAILMARK/PLESSEY: fix some 32-bit/portability bugs
- CODABAR: fix CALCIUM define address use, props Alonso Schaich
- DATAMATRIX/CODEONE: Use LCM in look ahead tests to avoid floats (#228)
- raster/output: use new isfintf() to test floats integral (CodeQL)
- ZBarcode_Encode: don't reinit symbol->outfile, props Alonso Schaich
- CODEONE: is_last_single_ascii() out-of-bounds, #232 CI-Fuzz, props Jan Schrewe
- library: compat symbology 39 fix; ISBN: "X" check
- backend/CMakeLists.txt: output dir for zintconfig.h, props Andre Maute (#238)
- UPCE/UPCE_CC: allow check digit (same as UPCA/UPCA_CC) so selecting composite
doesn't give error
- bmp/emf/ps.c: allow for foreground colour in ULTRA
- bmp/gif/pcx.c: allow for BARCODE_STDOUT (fflush/fclose)
- ps.c: fix buffer overflow on colour_to_pscolor() CMYK
- composite: fix buffer overflow for large linear and small composite
- composite: clear errtxt when bumping from CC-A -> CC-B -> CC-C
- CODABLOCKF: prevent cols > 62; fix pTestList buffer overflow
- RMQR: allow for righthand vertical timing pattern in populate_grid()
Version 2.9.1 2020-08-04
========================
Changes
-------
- Ticket 122: Implement transparency support
- Ticket 129: -nobackground option added
- -fg and -bg may contain an alpha channel
- structure zint_symbol may now contain an alpha channel as output
- Added DPD Symbology
- Add support for Unicode escape characters
Bugs
----
- EMF text colour does not change
- Fix QPainterPath dependency for Visual Studio
Version 2.9.0 2020-07-31
========================
Changes
-------
- Dotcode: adapt to AIM DOC Revision 4
- New option "-separator=" for zint to specify the separator height of stacked
symbologies.
- make internal routines invisible by a static function definition.
- CODE11: make adding check digits an option, selectable to 2 (default as now),
1 or none
- LOGMARS restrict max length to 30 per MIL-STD-1189 Rev. B; make check digit
optional
- CODE39/EXCODE39: max length now 85
- VIN code extended to international licence plates
- CODABAR: 3 data characters minimum (plus start/stop), check digit option added
- Channel Code: performance improvement
- QT GUI:
- GRIDMATRIX/HX/MQR/QRCODE/RMQR: allow separate selection of size/ECC
- add DAFT and VIN Symbologies
- Separarator option for DATAMATRIX
- Ticket 162: parse escape sequences
- gui element reassigments
- UPC/EAN/ITF-14 Composite: Ticket 72: new option --addongap (default:9) to set
the gap between code and composite.
- TCL Backend: The following symbology names were renamed:
- Matrix2of5 -> Standard2of5
- PDF417Trunc -> PDF417Compact
- RSS14Stacked -> GS1DataBarStacked
- RSS14Stacked -> GS1DataBarStacked
- RSS14StackedOmni -> GS1DataBarSstackedOmni
- RSS14ExpandedStacked -> GS1DataBarExpandedStacked
- OneCode -> USPSIntelligentMail
- EAN128-CC -> GS1-128-CC
- RSS14-CC -> GS1DataBarOmni-CC
- RSSLimited-CC -> GS1DataBarLimited-CC
- RSSExpandedStacked-CC -> GS1DataBarExpanded-CC
- RSSEXPanded-CC -> GS1DataBarExpanded-CC
- RSS14Stacked-CC -> GS1DataBarStacked-CC
- RSS14Omni-CC -> GS1DataBarStackedOmni-CC
- RSSExpandedStacked-CC -> GS1DataBarExpandedStacked-CC
** Potential incompatibility **
- API Symbol names changed but old names preserved in zint.h
- BARCODE_C25MATRIX -> BARCODE_C25STANDARD
- BARCODE_EAB128_CC -> BARCODE_GS1_128
- BARCODE_RSS14 -> BARCODE_DBAR_OMN
- BARCODE_RSS_LTD -> BARCODE_DBAR_LTD
- BARCODE_RSS_EXP -> BARCODE_DBAR_EXP
- BARCODE_PDF417TRUNC -> BARCODE_PDF417COMP
- BARCODE_RSS14STACK -> BARCODE_DBAR_STK
- BARCODE_RSS14STACK_OMNI -> BARCODE_DBAR_OMNSTK
- BARCODE_RSS_EXPSTACK -> BARCODE_DBAR_EXPSTK
- BARCODE_ONECODE -> BARCODE_USPS_IMAIL
- BARCODE_EAN128_CC -> BARCODE_GS1_128_CC
- BARCODE_RSS14_CC -> BARCODE_DBAR_OMN_CC
- BARCODE_RSS_LTD_CC -> BARCODE_DBAR_LTD_CC
- BARCODE_RSS_EXP_CC -> BARCODE_DBAR_EXP_CC
- BARCODE_RSS14STACK_CC -> BARCODE_DBAR_STK_CC
- BARCODE_RSS_EXPSTACK_CC -> BARCODE_DBAR_EXPSTK_CC
Bugs
----
- Ticket 185 EMF export corrections
- fine scaling by the use of float arithmetic
- full header (extension1&2) with correct size field
- Ticket 190: Aztec buffer overrun fixed
- Ticket 191 suppress clang-tidy warnings: raster.c, composite.c, qr.c
- Ultracode internal encoding bugs, ECI 899
- GS1 data: exclude DEL character
- Ticket 192: missing malloc.h include for Windows compilers.
- Correct GS1 AI 253 & 255 length from 14 to 13
- Codablock F changes:
- FNC4 may not be split over rows.
- Use Code128 routine for one line Codablock FIM
- Correct column range to 9 ... 62
- allow new options: row count and column count, border_width and HIBC mode
- pad correctly empty and last row
- separator length correction
- Code128 changes:
- Correctly encode CodeA charset with control-character only data
- Improve coding of Extended ASCII (FNC4)
- Checksum calculation overflow protection
- EAN128 may reduce length
- Check for incomplete escape sequences on data specification: "\" without
following character.
- Code16K fixes: remove extended ASCII latch, pad character
- Restructuring to have common code centralized:
- Code128 routines for Codablock&Code16K
- output.c has common routines from raster.c and symbologies.
- HIBC_39: restrict max length to 68 otherwise to avoid overrun
- Code One: protect agains overrun
- Telepen: allow DEL
- GS1 Databar/ GS1-128 Composite:
- Separator bar corrections
- Ticket 200: spurious additional row
- Correct names in GUI
- Compact PDF417:
- Add missing stop pattern.
- Rename in GUI: "PDF417 Truncated" to "Compact PDF417".
- PDF417: Optimize text compaction mode switch.
- Human readable representation: Code128, Code39, Code93 special characters
are shown by a blank.
- ITF14: Ticket 201: allow bind option
Version 2.8.0 2020-04-10
========================
Changes
-------
(New) Tests for auspost, codablock, composite, dotcode, general, telepen,
upcean, all output formats
- QR, Han Xin, Grid Matrix: the multi byte compaction schemes (ex: Kanji)
are used by some decoders as codepage information (Ex: GB2312) and output
may be translated to UTF-8. This may destroy the data in a not controlable
manner.
In consequence, multibyte compaction schemes are disabled by default.
The new option --fullmultibyte (option_3 = ZINT_FULL_MULTIBYTE) enables this
optimisation.
- Add new symbology "Ultra Code" with the ability to output colour codes.
Bugs
----
- Ticket 181 penetration test found many bugs:
- Auspost: null bytes in content caused segfault
- Codablock: data 0x1a..0x1f caused segfault
- Dotcode: overrun in binary mode, overrun in codeword_array buffer
Correct encoding of HT/FS/GS/RS when shifting to code set B
- empty or unreadable input file
- telepen: buffer overflow
- EANUCC: buffer overflow on multiple + (multiple extension bars)
- Maxicode: index overrun on numeric compaction
- CodeOne: Simple i indexing not sp + i in C1_ASCII numeric latch loop.
- Aztec: free memory
- Ticket 183: Databar stacked separator correction
- Ticket 182: Output bitmap type was char, where some targets assigned 0
if pixel colour >127 (e.g. negative). API change to use unsigned char.
- HanXin: wrong codepage, gb2312 instead gb18030.
- PDF417: corrected alloced sizes to max characters
- Ticket 189: FNC1 encodation fixed (FLG(0) missing after FLG(n))
- PCX format: added missing bytes_per_line if bitmap width is odd.
Version 2.7.1 2020-02-01
========================
Changes
-------
- QR encoding optimized to get smaller code matrix results
- PDF417: remove obsolete codeword number option in qzint.
Option removed in qtzint.
- Removed annex B (3 digit country codes) and annex C (GS1 General
Specification) from the manual. This material may be found elsewhere.
- MAC homebrew remark added to the documentation
- Correct cmake file to match BSD-3-clause licence
Bugs
----
- Correct uninitialized warning in gridmatrix.call
- do not export internal functions
- raster painting of UPC-A bound check
- pdf417 documentation corrected: change flag -security to -secure
- Dot Code encoding ECI number corrected
- Corrected postscript plotting error
- Datamatrix: corrected possible buffer overrun in 3 characters to 2 byte
encodings.
- In 2.7.0 removed interface "ZBarcode_Render" still declared
- vc6 make was missing (trivial) resource.h
Version 2.7.0 2019-12-05
========================
Changes
-------
- Automatic height option added to qzint
- DotCode in line with new specification
- New GS1 AIs 7240, 235, 417, 7040, 8026, updated checks for 7007, 8008
- New Symbology rMQR
- QR and Qridmatrix optimisation for GB2312
- removed depreciated interface for gLabels program. Please use current
interface.
Fixed bugs
----------
- Many improvements in composite codes
- SVG output corrected for messages containing "<" and "&".
- GS1-128 and RSS may only be used with GS1 contents
- Han Xin chinese character handling
Version 2.6.7 2019-10-07
========================
Changes
-------
Ticket 127: Allow to code ECI 3 if explicitly given for debug purposes.
**Incompatible change**
"--eci 3" now leads to included ECI information.
"--eci 0" may now be used to not include any ECI information.
The default of the parameter changed from 3 to 0.
Fixed bugs
----------
Ticket 146, 165: fix wrong encoding of RSS composite codes
Version 2.6.6 2019-09-18
========================
Fixed bugs
----------
Ticket 161: PDF row size may be set
Ticket 155: PDF numeric compaction
Ticket 164: crash due to call of svg_plot withnull vector
Ticket 119: Crash on bullseye raster drawing
qtzint: Micro-QR version option choice corrected (+1 missing).
Datamatrix: code corruption when ECI was encoded and base256 encoding was
automatically chosen.
Version 2.6.5 2019-09-02
========================
Fixed bugs
----------
backend/main.c was missing
Maxicode bullseye rastering for scale = 0.5
Crash in utf to eci.
eci ISO 8859-16 table missing data line
upce check for 7 digit input (causes crash) and BARCODE_UPCE_CHK -> BARCODE_UPCE
mapping removed
US imail check for invalid barcode identifier and allow 0/5/9/11 length zip
maxicode code set correction
cmake flags for debugging and sanitize options
unit tests for the changes, with a simple test suite based on qrencode/tests
Version 2.6.4 2019-08-30
========================
Fixed bugs: EMF output, maxicode plot/content
Datamatrix DMRE updated to the ISO/IEC29158 version. This is incompatible in the
way that the old -vers numbers for DMRE are re-assigned.
The separator of GS1-datamatrix may be switched from FNC1 to GS.
GS1 field length check AI 8009 and 7230 to 7239 currected.
Version 2.6.3 2018-02-15
========================
New symbology Royal Mail 4-state Mailmark. Added North America VIN verification.
Bugfixes for TIF and EMF output and escape character handling.
Version 2.6.2 2017-10-22
========================
Further bugfixes in Aztec and DotCode. Expand escape sequence support
to API and GUI. Handle UTF BOM. Bugfix raster images of Maxicode.
Version 2.6.1 2017-08-27
========================
Library bugfixes: EDIFACT unlatch in Data Matrix, Add UPNQR, Improved Aztec
data compression, Detect Code 128 data too long, Make error codes consistent.
GUI improvements: Additional clipboard options, remove border width bug,
remove changing background colour bug, remember more settings and make GUI
more consistent with user expectations. All windows now resizable and more
information given when batch processing.
Version 2.6.0 2017-05-12
========================
Update front end to Qt5. Output to EMF and TIF. Copy to clipboard. Update
to latest draft of DMRE. Usual bugfixes.
Version 2.5.1 2017-04-03
========================
Numerous bugfixes, especially with Data Matrix thanks to extensive testing
by brunt@SF
Version 2.5 2016-11-13
======================
Support for DotCode and Han Xin code. ECI code processing. Output to BMP, GIF
and PCX. Added bold and small text options. Reintroduction of Codablock-F.
Many minor fixes and improvements.
Version 2.4.3 2011-05-16
========================
Includes minor bugfixes
Version 2.4.1 2011-04-19 & 2.4.2 2011-05-04
===========================================
A whole host of bugfixes including correction of ECC routines
for Code-1 and addition of batch processing at the command line.
Version 2.4 2010-09-13
======================
Built extensions to the API for integrating with glabels with thanks to
Sam Lown and Jim Evins. Added code optimisation and input from stdin thanks to
Ismael Luceno. Reinstated escape character input. Simplification of Barcode
Studio.
Version 2.3.2 2010-05-29
========================
Corrected many bugs in GS1 DataBar Extended thanks to the careful
study of the code by Pablo Orduña at the PIRAmIDE project. Similarly corrected
some bugs in Maxicode thanks to Monica Swanson at Source Technologies. Also
minor bugfixes for ISBN and Aztec Code, and added some small features like a
--square option in the CLI.
Version 2.3.1 2010-04-07
========================
Removed Codablock-F. Redesigned scale function so that human readable
text and Maxicode symbols can be scaled consistently. Corrected encoding bugs
with Code 128/Code 16k and Data Matrix ECC200 ECC 050. Added --notext option to
CLI.
Version 2.3 2009-11-23
======================
Fixed problems with Micro QR Code and rebuilt QR Code support removing
dependence on libqrencode. Improved Kanji character support for QR Code and
Micro QR Code which now auto-detects and automatically converts to Shift-JIS.
Added Grid Matrix symbology with Kanji character support and automatic
conversion to GB 2312. Removed no_qr compile option. Advanced Barcode Studio
version number to match library version number.
Version 2.2.2 2009-09-29
========================
A beta release previewing the new API structure. Better NULL character
support with "nullchar" value removed. Added loading from file and sequence
dialogs in Barcode Studio.
Version 2.2.1 2009-08-06
========================
Data encoding bugfixes for Aztec Code, Data Matrix ECC200, USPS One
Code and PDF417. Symbol plotting bugfixes for MicroPDF417 and 2D components of
composite symbols. Text formatting bugfix for Qt renderer and a couple of
compiler fixes for MSVC PNG image output.
Version 2.2 2009-07-18
======================
Added Code One and GS1 support in Code 49. Changed GUI binary name to
zint-qt and brought GUI up to version 1.0. Made some minor bugfixes to Code 39,
ITF-14, Aztec Code, Code 128 and Code 16K. Added 'rest' button to GUI. Included
.spec file from Radist.
Version 2.1.4 2009-06-19
========================
Many stability improvements including removal of buffer overruns in
Code 39, LOGMARS, PZN, Aztec Code and Composite CC-A. Addition of files for
compiling on MS Windows platform - tested successfully on XP and Vista.
Version 2.1.3 2009-05-19
========================
Many improvements to the QZint GUI which is now renamed "Zint Barcode
Studio 0.2". Added Japanese Postal Barcode, Code 49 and Channel Code and made
corrections to Data Matrix ECC200 (Binary mode data compression terminates too
soon), Aztec Code (Bug when automatically resizing after removing "all 0" and
"all 1" codewords) and Code 128 (Extended ASCII characters become corrupt).
Version 2.1.2 2009-03-01
========================
Added SVG output option. Improved Japanese character support including
Unicode > Shift-JIS capability. Bugfixes for Data Matrix ECC200 (missing
characters at end of string) and Codablock-F (K1/K2 check digit and row
indicators above row 6).
Version 2.1.1 2009-02-10
========================
Minor Data Matrix ECC200 bugfix and added HIBC options.
Version 2.1 2009-01-31
======================
Reinstated Korea Post barcodes, harmonised bind and box options, moved
Unicode handling into backend and added input_mode option, added size options
to Data Matrix ECC200, added NULL character handling for Codablock-F, Code 128,
Code 16k, Extended Code 39, Code 93, Telepen, Maxicode, Data Matrix ECC200 ECC
200, PDF417 and MicroPDF417. Added GS1 support for Code 16k, Codablock-F and
Aztec Code. Added scale and direct to stdout options. Rebult Data Matrix ECC200
ECC 200 encoding algorithms to support NULL encoding and GS1 data encoding.
Version 2.0 2008-11-18
======================
Made corrections to Aztec Code and tested output with bcTester. Added
Aztec Runes, Micro QR Code and Data Matrix ECC200 ECC 000-140. Updated e-mail
information.
Version 2.0 beta r2 2008-10-19
==============================
Many corrections and bugfixes. (Code 11, Code 128, EAN-128,
Aztec Code, Codablock-F, Code 16k, POSTNET, PLANET, NVE-18, PZN, Data Matrix
ECC200, Maxicode and QR Code)
Version 2.0 beta 2008-09-29
===========================
Added support for Aztec Code, Codablock-F, Code 32, EAN-14 and DAFT
Code. Rearranged symbology numbers to match Tbarcode v8. Corrected a never
ending loop bug in EAN-128.
Version 1.6.2 2008-07-28
========================
Added KIX Code support and PNG image rotation. Corrected a bug
affecting extended ASCII support in Code 128 and Code 16k.
Version 1.6.1 2008-07-08
========================
Major restructuring of PNG generating code: Now draws UPCA and EAN
symbols properly and puts human readable text into the image. Also corrected
some nasty 'never ending loop' bugs in Code 128 and check digit bugs in PostNet
and Planet.
Version 1.6 2008-04-22
======================
Data Matrix ECC200, Maxicode and Australia Post now use common
Reed-Solomon functions this also fixes a bug in Maxicode error correction and
replaces the last of the Lien code. Added PNG output for Maxicode symbols.
Removed some useless code. Updated QR support for libqrencode v2.0.0.
Version 1.5.5 2008-03-09
========================
Added composite symbology support. Corrected errors with GS1-128 and
PDF417/MicroPDF417 byte processing. Transferred licence to GPL version 3.
Version 1.5.4 2007-11-26
========================
Added GS1 DataBar (Reduced Space Symbology) support.
Version 1.5.3 2007-10-10
========================
Made huge corrections to Maxicode support by removing and re-writing
much of John's code. Maxicode now supports extended ASCII and modes 4, 5 and 6.
Version 1.5.2 2007-09-26
========================
Added extended ASCII support to Code 16k. Corrected Code 128 error.
Added Maxicode support by integrating code by John Lien.
Version 1.5.1 2007-09-03
========================
Added formatting code to EPS output of EAN and UPC symbols according
to EN 797:1996. Checked against and, where appropriate, altered or corrected to
comply with ISO 16388 and ISO 15417 including Latin-1 support. Altered default
image settings, added automatic ITF border. Corrected error with USPS OneCode.
Tidied up Code 39 quite a bit, added Mod 43 options.
Version 1.5 2007-08-12
======================
Pulled everything together to make an API. Corrected errors with EAN-13,
PDF417 and LOGMARS. Added EPS output. Added QR Code support using libqrencode.
Corrected ISBN verification error. Re-compiled documentation in HTML form. Put
in place proper error handling routines. --font option removed. Encoding is now
done with a restructured zint_symbol structure. Added make install option and
optional QR Code support to Makefile. Corrected minor problem with 4-State
Codes. Restructured code into fewer source code files. Added MicroPDF417
support.
Version 1.4 2007-06-20
======================
Added NVE-18 support. Corrected some problems with compilation and input
verification. Command line option handling now uses getopt(), and all the
switches have changed. Added font option.
Version 1.3 2007-06-13
======================
Supports USPS OneCode and LOGMARS. Brought all usage information into
one User Manual document.
Version 1.2 2007-05-28
======================
Supports Data Matrix ECC200 (by absorption of IEC16022 code by Stefan
Schmidt et al). Added reverse colours, FIM, MSI/Plessey Modulo 11 and Modulo
11/10. Corrected Code 16k check digit calculation.
Version 1.1 2007-04-26
======================
Added more derivatives (Code 2 of 5 Matrix, IATA and Data Logic,
Truncated PDF417, Deutsche Post Leitcode and Identcode, Pharmazentralnummer,
Planet) and Flattermarken. Tidied up 2 of 5 code.
Version 1.0 2007-04-20
======================
Corrected problem with escape character codes. Supports PDF417. This
completes the list of features I originally wanted (plus a few more), hence
skip to version 1.0.
Version 0.6 2007-04-01
======================
Added Plessey and some derivative codes (EAN-128, Code 128 subset B,
Auspost Reply, Auspost Routing, Auspost Redirect, ITF-14). Tidied up code
again: separated symbologies into more files and put all lookup tables into
arrays (much reducing the amount of code, especially for Code 39e and Code 93).
Errors now output to stderr. Added proper input verification. Distribution now
packs with HTML pages instead of separate README. Outputs to PNG. Outputs
colour. User variable whitespace and border width. Box option. Fixed EAN add-on
bug. Added whitespace and height options. Project name changed to Zint to avoid
conflict with extant trade name. Added escape character input.
Version 0.5 2007-02-28
======================
Added Australia Post 4-State Barcodes and Pharmacode (1 and 2 track).
4-state codes now draw with correct height/width ratio.
Version 0.4 2007-01-15
======================
Added barcode stacking (now stacks up to 16 barcodes) and Code16k (stub).
Version 0.3 2006-12-30
======================
Added MSI/Plessey Mod 10 check and 2 x Mod 10 check options, Telepen
ASCII and Telepen numeric, Postnet, RM4SCC. Code has been tidied up quite a
bit. Bind option added.
Version 0.2 2006-12-12
======================
Added Code 128 (which is now the default), Code 11, Code 2 of 5, Add-on
codes EAN-2 and EAN-5 parity and MSI/Plessey without check digit.
Version 0.1 (as Zebar) 2006-11-13
=================================
Draws UPC-A. UPC-E, EAN-8, EAN-13, Interlaced 2 of 5,
Codabar, Code 39, Extended Code 39 and Code 93 barcodes and Add-on codes EAN-2
and EAN-5 without parity.

65
3rdparty/zint-2.10.0/README vendored Normal file
View File

@ -0,0 +1,65 @@
Zint and libzint
----------------
Zint is a suite of programs to allow easy encoding of data in any of the
wide range of public domain barcode standards and to allow integration of
this capability into your own programs.
Zint is able to encode data in the following formats:
Code 11, Standard Code 2 of 5, IATA Code 2 of 5, Industrial Code 2 of 5,
Interleaved Code 2 of 5, Code 2 of 5 Data Logic, ITF-14, Deutshe Post Leitcode,
Deutshe Post Identcode, UPC-A, UPC-E, EAN-2, EAN-5, EAN-8, EAN-13, ISBN, UK
Plessey, MSI Plessey, Telepen Alpha, Telepen Numeric, Code 39, Extended Code 39,
Code 93, PZN, Code 32, LOGMARS, Codabar, Pharmacode, Code 128, GS1-128, NVE-18,
Code 16k, PDF417, MicroPDF417, Two-Track Pharmacode, POSTNET, PLANET, Australia
Post 4-State Symbols, RM4SCC, Dutch Post KIX, USPS Intelligent Mail, GS1 DataBar
Omnidirectional, GS1 DataBar Limited, GS1 DataBar Expanded, GS1 DataBar Stacked,
Composite Symbology, Data Matrix, QR Code, MaxiCode, Aztec Code, Aztec Runes,
EAN-14, Micro QR, Korea Post Barcode, HIBC Code 128, HIBC Code 39, HIBC Data
Matrix, HIBC PDF417, HIBC MicroPDF417, HIBC QR Code, HIBC Codablock-F, HIBC
Aztec Code, Japanese Postal Code, Code 49, Channel Code, Code One, Grid Matrix,
DAFT, FIM and Flattermarken, Codablock-F, DotCode, Han Xin Code, rMQR,
Ultracode, UPNQR, VIN, and DPD Code.
Output can be saved as BMP, EPS, GIF, PCX, TIF, EMF, PNG or SVG.
PROJECT HISTORY
---------------
Please see "ChangeLog" in the project root directory.
CONTACT US
----------
The home of Zint is:
<http://www.sourceforge.net/projects/zint>
The code is now also mirrored at:
<https://github.com/woo-j/zint>
For feature requests or bug reports please either join the mailing list at
<https://lists.sourceforge.net/lists/listinfo/zint-barcode>
or add a ticket on the project's SourceForge.
BEFORE POSTING TO THE LIST
--------------------------
Please note the following points...
* Zint is primarily developed for Linux. While we have some experience of
using Zint on Windows we may be unable to resolve problems if they are
specific to other operating systems. We cannot provide support for using
Zint with commercial packages such as MS Office or Crystal Reports.
* Always ensure you are using the latest version of Zint before posting bug
reports - the bug you are reporting may have been fixed already.
* Please remember to state what operating system you are using and include
enough information to allow us to reproduce the error - including input
data if appropriate.
* Please DO NOT post messages asking for us to change the license
arrangements. You will be ignored.
* Please remember that Zint is developed by volunteers. While we attempt to
answer all messages within a week, this is highly dependant on external
circumstances.

273
3rdparty/zint-2.10.0/SetPaths.cmake vendored Normal file
View File

@ -0,0 +1,273 @@
# - Find include and library dirs, and define a some macros
#
# This module defines a bunch of variables used as locations for install directories.
# They can be relative (to CMAKE_INSTALL_PREFIX) or absolute.
# Under Windows they are always relative.
#
# BIN_INSTALL_DIR - the directory where executables will be installed (default is prefix/bin)
# BUNDLE_INSTALL_DIR - Mac only: the directory where application bundles will be installed (default is /Applications/KDE4 )
# SBIN_INSTALL_DIR - the directory where system executables will be installed (default is prefix/sbin)
# LIB_INSTALL_DIR - the directory where libraries will be installed (default is prefix/lib)
# CONFIG_INSTALL_DIR - the config file install dir
# DATA_INSTALL_DIR - the parent directory where applications can install their data
# HTML_INSTALL_DIR - the HTML install dir for documentation
# ICON_INSTALL_DIR - the icon install dir (default prefix/share/icons/)
# INFO_INSTALL_DIR - the kde info install dir (default prefix/info)
# KCFG_INSTALL_DIR - the install dir for kconfig files
# LOCALE_INSTALL_DIR - the install dir for translations
# MAN_INSTALL_DIR - the kde man page install dir (default prefix/man/)
# MIME_INSTALL_DIR - the install dir for the mimetype desktop files
# PLUGIN_INSTALL_DIR - the subdirectory relative to the install prefix where plugins will be installed (default is ${KDE4_LIB_INSTALL_DIR}/kde4)
# SERVICES_INSTALL_DIR - the install dir for service (desktop, protocol, ...) files
# SERVICETYPES_INSTALL_DIR - the install dir for servicestypes desktop files
# SOUND_INSTALL_DIR - the install dir for sound files
# TEMPLATES_INSTALL_DIR - the install dir for templates (Create new file...)
# WALLPAPER_INSTALL_DIR - the install dir for wallpapers
# DEMO_INSTALL_DIR - the install dir for demos
# KCONF_UPDATE_INSTALL_DIR - the kconf_update install dir
# XDG_APPS_INSTALL_DIR - the XDG apps dir
# XDG_DIRECTORY_INSTALL_DIR- the XDG directory
# XDG_MIME_INSTALL_DIR - the XDG mimetypes install dir
# DBUS_INTERFACES_INSTALL_DIR - the directory where dbus interfaces be installed (default is prefix/share/dbus-1/interfaces)
# DBUS_SERVICES_INSTALL_DIR - the directory where dbus services be installed (default is prefix/share/dbus-1/services )
#
# A note on the possible values for CMAKE_BUILD_TYPE and how KDE handles
# the flags for those buildtypes. FindKDE4Internal supports the values
# Debug, Release, Relwithdebinfo, Profile and Debugfull
#
# Release
# optimised for speed, qDebug/kDebug turned off, no debug symbols
# Release with debug info
# optimised for speed, debugging symbols on (-g)
# Debug
# optimised but debuggable, debugging on (-g)
# (-fno-reorder-blocks -fno-schedule-insns -fno-inline)
# DebugFull
# no optimisation, full debugging on (-g3)
# Profile
# DebugFull + -ftest-coverage -fprofile-arcs
#
# It is expected that the "Debug" build type be still debuggable with gdb
# without going all over the place, but still produce better performance.
# It's also important to note that gcc cannot detect all warning conditions
# unless the optimiser is active.
#
# Copyright (c) 2006-2008, Alexander Neundorf <neundorf@kde.org>
# Copyright (c) 2006, Laurent Montel, <montel@kde.org>
# Copyright (c) 2008, BogDan Vatra, <bogdan@licentia.eu>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
########## the following are directories where stuff will be installed to ###########
#
# this has to be after find_xxx() block above
if (WIN32)
# use relative install prefix to avoid hardcoded install paths in cmake_install.cmake files
set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" ) # The subdirectory relative to the install prefix where libraries will be installed (default is ${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX})
set(EXEC_INSTALL_PREFIX "" ) # Base directory for executables and libraries
set(SHARE_INSTALL_PREFIX "share" ) # Base directory for files which go to share/
set(BIN_INSTALL_DIR "bin" ) # The install dir for executables (default ${EXEC_INSTALL_PREFIX}/bin)
set(SBIN_INSTALL_DIR "sbin" ) # The install dir for system executables (default ${EXEC_INSTALL_PREFIX}/sbin)
set(LIBEXEC_INSTALL_DIR "${BIN_INSTALL_DIR}" ) # The subdirectory relative to the install prefix where libraries will be installed (default is ${BIN_INSTALL_DIR})
set(INCLUDE_INSTALL_DIR "include" ) # The subdirectory to the header prefix
set(PLUGIN_INSTALL_DIR "lib${LIB_SUFFIX}/kde4" ) # "The subdirectory relative to the install prefix where plugins will be installed (default is ${LIB_INSTALL_DIR}/kde4)
set(CONFIG_INSTALL_DIR "share/config" ) # The config file install dir
set(DATA_INSTALL_DIR "share/apps" ) # The parent directory where applications can install their data
set(HTML_INSTALL_DIR "share/doc/HTML" ) # The HTML install dir for documentation
set(ICON_INSTALL_DIR "share/icons" ) # The icon install dir (default ${SHARE_INSTALL_PREFIX}/share/icons/)
set(KCFG_INSTALL_DIR "share/config.kcfg" ) # The install dir for kconfig files
set(LOCALE_INSTALL_DIR "share/locale" ) # The install dir for translations
set(MIME_INSTALL_DIR "share/mimelnk" ) # The install dir for the mimetype desktop files
set(SERVICES_INSTALL_DIR "share/kde4/services" ) # The install dir for service (desktop, protocol, ...) files
set(SERVICETYPES_INSTALL_DIR "share/kde4/servicetypes" ) # The install dir for servicestypes desktop files
set(SOUND_INSTALL_DIR "share/sounds" ) # The install dir for sound files
set(TEMPLATES_INSTALL_DIR "share/templates" ) # The install dir for templates (Create new file...)
set(WALLPAPER_INSTALL_DIR "share/wallpapers" ) # The install dir for wallpapers
set(DEMO_INSTALL_DIR "share/demos" ) # The install dir for demos
set(KCONF_UPDATE_INSTALL_DIR "share/apps/kconf_update" ) # The kconf_update install dir
set(AUTOSTART_INSTALL_DIR "share/autostart" ) # The install dir for autostart files
set(XDG_APPS_INSTALL_DIR "share/applications/kde4" ) # The XDG apps dir
set(XDG_DIRECTORY_INSTALL_DIR "share/desktop-directories" ) # The XDG directory
set(XDG_MIME_INSTALL_DIR "share/mime/packages" ) # The install dir for the xdg mimetypes
set(SYSCONF_INSTALL_DIR "etc" ) # The kde sysconfig install dir (default /etc)
set(MAN_INSTALL_DIR "share/man" ) # The kde man install dir (default ${SHARE_INSTALL_PREFIX}/man/)
set(INFO_INSTALL_DIR "share/info" ) # The kde info install dir (default ${SHARE_INSTALL_PREFIX}/info)")
set(DBUS_INTERFACES_INSTALL_DIR "share/dbus-1/interfaces" ) # The kde dbus interfaces install dir (default ${SHARE_INSTALL_PREFIX}/dbus-1/interfaces)")
set(DBUS_SERVICES_INSTALL_DIR "share/dbus-1/services" ) # The kde dbus services install dir (default ${SHARE_INSTALL_PREFIX}/dbus-1/services)")
else (WIN32)
# This macro implements some very special logic how to deal with the cache.
# By default the various install locations inherit their value from their "parent" variable
# so if you set CMAKE_INSTALL_PREFIX, then EXEC_INSTALL_PREFIX, PLUGIN_INSTALL_DIR will
# calculate their value by appending subdirs to CMAKE_INSTALL_PREFIX .
# This would work completely without using the cache.
# But if somebody wants e.g. a different EXEC_INSTALL_PREFIX this value has to go into
# the cache, otherwise it will be forgotten on the next cmake run.
# Once a variable is in the cache, it doesn't depend on its "parent" variables
# anymore and you can only change it by editing it directly.
# this macro helps in this regard, because as long as you don't set one of the
# variables explicitely to some location, it will always calculate its value from its
# parents. So modifying CMAKE_INSTALL_PREFIX later on will have the desired effect.
# But once you decide to set e.g. EXEC_INSTALL_PREFIX to some special location
# this will go into the cache and it will no longer depend on CMAKE_INSTALL_PREFIX.
#
# additionally if installing to the same location as kdelibs, the other install
# directories are reused from the installed kdelibs
macro(_SET_FANCY _var _value _comment)
set(predefinedvalue "${_value}")
if (NOT DEFINED ${_var})
set(${_var} ${predefinedvalue})
else (NOT DEFINED ${_var})
set(${_var} "${${_var}}" CACHE PATH "${_comment}")
endif (NOT DEFINED ${_var})
endmacro(_SET_FANCY)
if(APPLE)
set(BUNDLE_INSTALL_DIR "/Applications/KDE4" CACHE PATH "Directory where application bundles will be installed to on OSX" )
endif(APPLE)
_set_fancy(EXEC_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" "Base directory for executables and libraries")
_set_fancy(SHARE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/share" "Base directory for files which go to share/")
_set_fancy(BIN_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/bin" "The install dir for executables (default ${EXEC_INSTALL_PREFIX}/bin)")
_set_fancy(SBIN_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/sbin" "The install dir for system executables (default ${EXEC_INSTALL_PREFIX}/sbin)")
_set_fancy(LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX}" "The subdirectory relative to the install prefix where libraries will be installed (default is ${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX})")
_set_fancy(LIBEXEC_INSTALL_DIR "${LIB_INSTALL_DIR}/kde4/libexec" "The subdirectory relative to the install prefix where libraries will be installed (default is ${LIB_INSTALL_DIR}/kde4/libexec)")
_set_fancy(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" "The subdirectory to the header prefix")
_set_fancy(PLUGIN_INSTALL_DIR "${LIB_INSTALL_DIR}/kde4" "The subdirectory relative to the install prefix where plugins will be installed (default is ${LIB_INSTALL_DIR}/kde4)")
_set_fancy(CONFIG_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/config" "The config file install dir")
_set_fancy(DATA_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/apps" "The parent directory where applications can install their data")
_set_fancy(HTML_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/doc/HTML" "The HTML install dir for documentation")
_set_fancy(ICON_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/icons" "The icon install dir (default ${SHARE_INSTALL_PREFIX}/share/icons/)")
_set_fancy(KCFG_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/config.kcfg" "The install dir for kconfig files")
_set_fancy(LOCALE_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/locale" "The install dir for translations")
_set_fancy(MIME_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/mimelnk" "The install dir for the mimetype desktop files")
_set_fancy(SERVICES_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/kde4/services" "The install dir for service (desktop, protocol, ...) files")
_set_fancy(SERVICETYPES_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/kde4/servicetypes" "The install dir for servicestypes desktop files")
_set_fancy(SOUND_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/sounds" "The install dir for sound files")
_set_fancy(TEMPLATES_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/templates" "The install dir for templates (Create new file...)")
_set_fancy(WALLPAPER_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/wallpapers" "The install dir for wallpapers")
_set_fancy(DEMO_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/demos" "The install dir for demos")
_set_fancy(KCONF_UPDATE_INSTALL_DIR "${DATA_INSTALL_DIR}/kconf_update" "The kconf_update install dir")
_set_fancy(AUTOSTART_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/autostart" "The install dir for autostart files")
_set_fancy(XDG_APPS_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/applications/kde4" "The XDG apps dir")
_set_fancy(XDG_DIRECTORY_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/desktop-directories" "The XDG directory")
_set_fancy(XDG_MIME_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/mime/packages" "The install dir for the xdg mimetypes")
_set_fancy(SYSCONF_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/etc" "The kde sysconfig install dir (default ${CMAKE_INSTALL_PREFIX}/etc)")
_set_fancy(MAN_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/man" "The kde man install dir (default ${SHARE_INSTALL_PREFIX}/man/)")
_set_fancy(INFO_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/info" "The kde info install dir (default ${SHARE_INSTALL_PREFIX}/info)")
_set_fancy(DBUS_INTERFACES_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/dbus-1/interfaces" "The kde dbus interfaces install dir (default ${SHARE_INSTALL_PREFIX}/dbus-1/interfaces)")
_set_fancy(DBUS_SERVICES_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/dbus-1/services" "The kde dbus services install dir (default ${SHARE_INSTALL_PREFIX}/dbus-1/services)")
endif (WIN32)
# The INSTALL_TARGETS_DEFAULT_ARGS variable should be used when libraries are installed.
# The arguments are also ok for regular executables, i.e. executables which don't go
# into sbin/ or libexec/, but for installing executables the basic syntax
# INSTALL(TARGETS kate DESTINATION "${BIN_INSTALL_DIR}")
# is enough, so using this variable there doesn't help a lot.
# The variable must not be used for installing plugins.
# Usage is like this:
# install(TARGETS kdecore kdeui ${INSTALL_TARGETS_DEFAULT_ARGS} )
#
# This will install libraries correctly under UNIX, OSX and Windows (i.e. dll's go
# into bin/.
# Later on it will be possible to extend this for installing OSX frameworks
# The COMPONENT Devel argument has the effect that static libraries belong to the
# "Devel" install component. If we use this also for all install() commands
# for header files, it will be possible to install
# -everything: make install OR cmake -P cmake_install.cmake
# -only the development files: cmake -DCOMPONENT=Devel -P cmake_install.cmake
# -everything except the development files: cmake -DCOMPONENT=Unspecified -P cmake_install.cmake
# This can then also be used for packaging with cpack.
set(INSTALL_TARGETS_DEFAULT_ARGS RUNTIME DESTINATION "${BIN_INSTALL_DIR}"
LIBRARY DESTINATION "${LIB_INSTALL_DIR}"
ARCHIVE DESTINATION "${LIB_INSTALL_DIR}" COMPONENT Devel )
# on the Mac support an extra install directory for application bundles starting with cmake 2.6
if(APPLE)
set(INSTALL_TARGETS_DEFAULT_ARGS ${INSTALL_TARGETS_DEFAULT_ARGS}
BUNDLE DESTINATION "${BUNDLE_INSTALL_DIR}" )
endif(APPLE)
set(CMAKE_SYSTEM_INCLUDE_PATH ${CMAKE_SYSTEM_INCLUDE_PATH}
"${INCLUDE_INSTALL_DIR}")
set(CMAKE_SYSTEM_PROGRAM_PATH ${CMAKE_SYSTEM_PROGRAM_PATH}
"${BIN_INSTALL_DIR}" )
set(CMAKE_SYSTEM_LIBRARY_PATH ${CMAKE_SYSTEM_LIBRARY_PATH}
"${LIB_INSTALL_DIR}" )
# under Windows dlls may be also installed in bin/
if(WIN32)
set(CMAKE_SYSTEM_LIBRARY_PATH ${CMAKE_SYSTEM_LIBRARY_PATH}
"${_CMAKE_INSTALL_DIR}/bin"
"${CMAKE_INSTALL_PREFIX}/bin" )
endif(WIN32)
######################################################
# and now the platform specific stuff
######################################################
# Set a default build type for single-configuration
# CMake generators if no build type is set.
if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
# setup default RPATH/install_name handling, may be overridden by KDE4_HANDLE_RPATH_FOR_[LIBRARY|EXECUTABLE]
# default is to build with RPATH for the install dir, so it doesn't need to relink
if (UNIX)
if (APPLE)
set(CMAKE_INSTALL_NAME_DIR ${LIB_INSTALL_DIR})
else (APPLE)
# add our LIB_INSTALL_DIR to the RPATH and use the RPATH figured out by cmake when compiling
set(CMAKE_INSTALL_RPATH ${LIB_INSTALL_DIR} )
set(CMAKE_SKIP_BUILD_RPATH TRUE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif (APPLE)
endif (UNIX)

24
3rdparty/zint-2.10.0/TODO vendored Normal file
View File

@ -0,0 +1,24 @@
If you are interested in improving this package then here are a few ideas.
Backend
-------
* Create filters for more output file formats.
* The code was developed to be easy to understand rather than efficient so may
benefit from some memory optimisation for embedded systems.
* Support for Super Code and Data Strip desirable, and any other
industry symbologies not currently included.
GUI Frontend
------------
* Allow dragging and dropping to external apps.
Packaging
---------
Binary packages are needed for distribution in the following formats:
* RPMs for various Linux distros (.spec file now available thanks to Radist).
* Install binaries for Mac OSX.
Translations
------------
Documentation is currently only in English. If you have the knowledge and the
time please consider translating into other languages.

352
3rdparty/zint-2.10.0/backend/2of5.c vendored Normal file
View File

@ -0,0 +1,352 @@
/* 2of5.c - Handles Code 2 of 5 barcodes */
/*
libzint - the open source barcode library
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include <stdio.h>
#include "common.h"
#include "gs1.h"
static const char *C25MatrixTable[10] = {
"113311", "311131", "131131", "331111", "113131",
"313111", "133111", "111331", "311311", "131311"
};
static const char *C25MatrixStartStop[2] = { "411111", "41111" };
static const char *C25IndustTable[10] = {
"1111313111", "3111111131", "1131111131", "3131111111", "1111311131",
"3111311111", "1131311111", "1111113131", "3111113111", "1131113111"
};
static const char *C25IndustStartStop[2] = { "313111", "31113" };
static const char *C25IataLogicStartStop[2] = { "1111", "311" };
static const char *C25InterTable[10] = {
"11331", "31113", "13113", "33111", "11313",
"31311", "13311", "11133", "31131", "13131"
};
static char check_digit(const unsigned int count) {
return itoc((10 - (count % 10)) % 10);
}
/* Common to Standard (Matrix), Industrial, IATA, and Data Logic */
static int c25_common(struct zint_symbol *symbol, const unsigned char source[], int length, const int max,
const char *table[10], const char *start_stop[2], const int error_base) {
int i, error_number;
char dest[512]; /* Largest destination 6 + (80 + 1) * 6 + 5 + 1 = 498 */
unsigned char temp[80 + 1 + 1]; /* Largest maximum 80 */
int have_checkdigit = symbol->option_2 == 1 || symbol->option_2 == 2;
if (length > max) {
sprintf(symbol->errtxt, "%d: Input too long (%d character maximum)", error_base, max);
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
sprintf(symbol->errtxt, "%d: Invalid character in data (digits only)", error_base + 1);
return error_number;
}
ustrcpy(temp, source);
if (have_checkdigit) {
/* Add standard GS1 check digit */
temp[length] = gs1_check_digit(source, length);
temp[++length] = '\0';
}
/* start character */
strcpy(dest, start_stop[0]);
for (i = 0; i < length; i++) {
lookup(NEON, table, temp[i], dest);
}
/* Stop character */
strcat(dest, start_stop[1]);
expand(symbol, dest);
ustrcpy(symbol->text, temp);
if (symbol->option_2 == 2) {
/* Remove check digit from HRT */
symbol->text[length - 1] = '\0';
}
return error_number;
}
/* Code 2 of 5 Standard (Code 2 of 5 Matrix) */
INTERNAL int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
return c25_common(symbol, source, length, 80, C25MatrixTable, C25MatrixStartStop, 301);
}
/* Code 2 of 5 Industrial */
INTERNAL int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
return c25_common(symbol, source, length, 45, C25IndustTable, C25IndustStartStop, 303);
}
/* Code 2 of 5 IATA */
INTERNAL int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
return c25_common(symbol, source, length, 45, C25IndustTable, C25IataLogicStartStop, 305);
}
/* Code 2 of 5 Data Logic */
INTERNAL int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
return c25_common(symbol, source, length, 80, C25MatrixTable, C25IataLogicStartStop, 307);
}
/* Common to Interleaved, ITF-14, DP Leitcode, DP Identcode */
static int c25inter_common(struct zint_symbol *symbol, unsigned char source[], int length,
const int dont_set_height) {
int i, j, error_number;
char bars[7], spaces[7], mixed[14], dest[512]; /* 4 + (90 + 2) * 5 + 3 + 1 = 468 */
unsigned char temp[90 + 2 + 1];
int have_checkdigit = symbol->option_2 == 1 || symbol->option_2 == 2;
float height;
if (length > 90) {
strcpy(symbol->errtxt, "309: Input too long (90 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "310: Invalid character in data (digits only)");
return error_number;
}
temp[0] = '\0';
/* Input must be an even number of characters for Interlaced 2 of 5 to work:
if an odd number of characters has been entered and no check digit or an even number and have check digit
then add a leading zero */
if (((length & 1) && !have_checkdigit) || (!(length & 1) && have_checkdigit)) {
ustrcpy(temp, "0");
length++;
}
ustrncat(temp, source, length);
if (have_checkdigit) {
/* Add standard GS1 check digit */
temp[length] = gs1_check_digit(temp, length);
temp[++length] = '\0';
}
/* start character */
strcpy(dest, "1111");
for (i = 0; i < length; i += 2) {
int k = 0;
/* look up the bars and the spaces and put them in two strings */
bars[0] = '\0';
lookup(NEON, C25InterTable, temp[i], bars);
spaces[0] = '\0';
lookup(NEON, C25InterTable, temp[i + 1], spaces);
/* then merge (interlace) the strings together */
for (j = 0; j <= 4; j++) {
mixed[k] = bars[j];
k++;
mixed[k] = spaces[j];
k++;
}
mixed[k] = '\0';
strcat(dest, mixed);
}
/* Stop character */
strcat(dest, "311");
expand(symbol, dest);
ustrcpy(symbol->text, temp);
if (symbol->option_2 == 2) {
/* Remove check digit from HRT */
symbol->text[length - 1] = '\0';
}
if (!dont_set_height) {
#ifdef COMPLIANT_HEIGHTS
/* ISO/IEC 16390:2007 Section 4.4 min height 5mm or 15% of symbol width whichever greater where
(P = character pairs, N = wide/narrow ratio = 3) width = (P(4N + 6) + N + 6)X = (length / 2) * 18 + 9 */
height = (float) ((18.0 * (length / 2) + 9.0) * 0.15);
if (height < (float) (5.0 / 0.33)) { /* Taking X = 0.330mm from Annex D.3.1 (application specification) */
height = (float) (5.0 / 0.33);
}
/* Using 50 as default as none recommended */
error_number = set_height(symbol, height, height > 50.0f ? height : 50.0f, 0.0f, 0 /*no_errtxt*/);
#else
height = 50.0f;
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
#endif
}
return error_number;
}
/* Code 2 of 5 Interleaved ISO/IEC 16390:2007 */
INTERNAL int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
return c25inter_common(symbol, source, length, 0 /*dont_set_height*/);
}
/* Interleaved 2-of-5 (ITF-14) */
INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number, warn_number = 0, zeroes;
unsigned char localstr[16] = {0};
if (length > 13) {
strcpy(symbol->errtxt, "311: Input too long (13 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "312: Invalid character in data (digits only)");
return error_number;
}
/* Add leading zeros as required */
zeroes = 13 - length;
for (i = 0; i < zeroes; i++) {
localstr[i] = '0';
}
ustrcpy(localstr + zeroes, source);
/* Calculate the check digit - the same method used for EAN-13 */
localstr[13] = gs1_check_digit(localstr, 13);
localstr[14] = '\0';
error_number = c25inter_common(symbol, localstr, 14, 1 /*dont_set_height*/);
ustrcpy(symbol->text, localstr);
if (!((symbol->output_options & BARCODE_BOX) || (symbol->output_options & BARCODE_BIND))) {
// If no option has been selected then uses default box option
symbol->output_options |= BARCODE_BOX;
if (symbol->border_width == 0) { /* Allow override if non-zero */
/* GS1 General Specifications 21.0.1 Sections 5.3.2.4 & 5.3.6 (4.83 / 1.016 ~ 4.75) */
symbol->border_width = 5; /* Note change from previous value 8 */
}
}
if (error_number < ZINT_ERROR) {
#ifdef COMPLIANT_HEIGHTS
/* GS1 General Specifications 21.0.1 5.12.3.2 table 2, including footnote (**): (note bind/box additional to
symbol->height), same as GS1-128: "in case of further space constraints"
height 5.8mm / 1.016mm (X max) ~ 5.7; default 31.75mm / 0.495mm ~ 64.14 */
warn_number = set_height(symbol, (float) (5.8 / 1.016), (float) (31.75 / 0.495), 0.0f, 0 /*no_errtxt*/);
#else
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
#endif
}
return error_number ? error_number : warn_number;
}
/* Deutshe Post Leitcode */
INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number;
unsigned int count;
unsigned char localstr[16] = {0};
int zeroes;
count = 0;
if (length > 13) {
strcpy(symbol->errtxt, "313: Input wrong length (13 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "314: Invalid character in data (digits only)");
return error_number;
}
zeroes = 13 - length;
for (i = 0; i < zeroes; i++)
localstr[i] = '0';
ustrcpy(localstr + zeroes, source);
for (i = 12; i >= 0; i--) {
count += 4 * ctoi(localstr[i]);
if (i & 1) {
count += 5 * ctoi(localstr[i]);
}
}
localstr[13] = check_digit(count);
localstr[14] = '\0';
error_number = c25inter_common(symbol, localstr, 14, 1 /*dont_set_height*/);
ustrcpy(symbol->text, localstr);
// TODO: Find documentation on BARCODE_DPLEIT dimensions/height
return error_number;
}
/* Deutsche Post Identcode */
INTERNAL int dpident(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number, zeroes;
unsigned int count;
unsigned char localstr[16] = {0};
count = 0;
if (length > 11) {
strcpy(symbol->errtxt, "315: Input wrong length (11 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "316: Invalid character in data (digits only)");
return error_number;
}
zeroes = 11 - length;
for (i = 0; i < zeroes; i++)
localstr[i] = '0';
ustrcpy(localstr + zeroes, source);
for (i = 10; i >= 0; i--) {
count += 4 * ctoi(localstr[i]);
if (i & 1) {
count += 5 * ctoi(localstr[i]);
}
}
localstr[11] = check_digit(count);
localstr[12] = '\0';
error_number = c25inter_common(symbol, localstr, 12, 1 /*dont_set_height*/);
ustrcpy(symbol->text, localstr);
// TODO: Find documentation on BARCODE_DPIDENT dimensions/height
return error_number;
}

View File

@ -0,0 +1,70 @@
# Copyright (C) 2008 by BogDan Vatra < bogdan@licentia.eu >
# Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com>
# vim: set ts=4 sw=4 et :
project(zint)
configure_file(zintconfig.h.in ${CMAKE_CURRENT_SOURCE_DIR}/zintconfig.h)
set(zint_COMMON_SRCS common.c library.c large.c reedsol.c gs1.c eci.c general_field.c sjis.c gb2312.c gb18030.c)
set(zint_ONEDIM_SRCS code.c code128.c 2of5.c upcean.c telepen.c medical.c plessey.c rss.c)
set(zint_POSTAL_SRCS postal.c auspost.c imail.c mailmark.c)
set(zint_TWODIM_SRCS code16k.c codablock.c dmatrix.c pdf417.c qr.c maxicode.c composite.c aztec.c code49.c code1.c gridmtx.c hanxin.c dotcode.c ultra.c)
set(zint_OUTPUT_SRCS vector.c ps.c svg.c emf.c bmp.c pcx.c gif.c png.c tif.c raster.c output.c)
set(zint_SRCS ${zint_OUTPUT_SRCS} ${zint_COMMON_SRCS} ${zint_ONEDIM_SRCS} ${zint_POSTAL_SRCS} ${zint_TWODIM_SRCS})
add_library(zint SHARED ${zint_SRCS})
if(ZINT_STATIC)
add_library(zint-static STATIC ${zint_SRCS})
endif()
function(zint_target_link_libraries library)
target_link_libraries(zint ${library})
if(ZINT_STATIC)
target_link_libraries(zint-static ${library})
endif()
endfunction()
function(zint_target_compile_definitions scope definition)
target_compile_definitions(zint ${scope} ${definition})
if(ZINT_STATIC)
target_compile_definitions(zint-static ${scope} ${definition})
endif()
endfunction()
set_target_properties(zint PROPERTIES SOVERSION "${ZINT_VERSION_MAJOR}.${ZINT_VERSION_MINOR}"
VERSION ${ZINT_VERSION})
if(ZINT_USE_PNG)
find_package(PNG)
endif()
if(ZINT_USE_PNG AND PNG_FOUND)
zint_target_link_libraries(PNG::PNG)
else()
zint_target_compile_definitions(PUBLIC NO_PNG)
endif()
if(ZINT_TEST)
zint_target_compile_definitions(PUBLIC ZINT_TEST)
endif()
if(NOT MSVC)
# Link with standard C math library.
zint_target_link_libraries(m)
endif()
if(MSVC)
target_compile_definitions(zint PRIVATE DLL_EXPORT)
endif()
install(TARGETS zint ${INSTALL_TARGETS_DEFAULT_ARGS})
if(ZINT_STATIC)
install(TARGETS zint-static ${INSTALL_TARGETS_DEFAULT_ARGS})
endif()
install(FILES zint.h DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel)
if(ZINT_TEST)
add_subdirectory(tests)
endif()

View File

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -29,6 +29,7 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#define GDSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #"
@ -54,47 +55,40 @@ static const char *AusBarTable[64] = {
"332", "333"
};
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "common.h"
#include "reedsol.h"
#ifdef _MSC_VER
#define inline _inline
#endif
static inline char convert_pattern(char data, int shift) {
static char convert_pattern(char data, int shift) {
return (data - '0') << shift;
}
/* Adds Reed-Solomon error correction to auspost */
void rs_error(char data_pattern[]) {
size_t reader, triple_writer = 0;
char triple[31], inv_triple[31];
static void rs_error(char data_pattern[]) {
int reader, len, triple_writer = 0;
unsigned char triple[31];
unsigned char result[5];
rs_t rs;
for (reader = 2; reader < strlen(data_pattern); reader += 3, triple_writer++) {
for (reader = 2, len = (int) strlen(data_pattern); reader < len; reader += 3, triple_writer++) {
triple[triple_writer] = convert_pattern(data_pattern[reader], 4)
+ convert_pattern(data_pattern[reader + 1], 2)
+ convert_pattern(data_pattern[reader + 2], 0);
}
for (reader = 0; reader < triple_writer; reader++) {
inv_triple[reader] = triple[(triple_writer - 1) - reader];
}
rs_init_gf(0x43);
rs_init_code(4, 1);
rs_encode(triple_writer, (unsigned char*) inv_triple, result);
rs_init_gf(&rs, 0x43);
rs_init_code(&rs, 4, 1);
rs_encode(&rs, triple_writer, triple, result);
for (reader = 4; reader > 0; reader--) {
strcat(data_pattern, AusBarTable[(int) result[reader - 1]]);
}
rs_free();
}
INTERNAL int daft_set_height(struct zint_symbol *symbol, float min_height, float max_height);
/* Handles Australia Posts's 4 State Codes */
int australia_post(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int australia_post(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Customer Standard Barcode, Barcode 2 or Barcode 3 system determined automatically
(i.e. the FCC doesn't need to be specified by the user) dependent
on the length of the input string */
@ -104,16 +98,21 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
1 = Tracker and Ascender
2 = Tracker and Descender
3 = Tracker only */
int error_number, zeroes;
int error_number;
int writer;
unsigned int loopey, reader;
size_t h;
int loopey, reader;
int h;
char data_pattern[200];
char fcc[3] = {0, 0, 0}, dpid[10];
char localstr[30];
error_number = 0;
/* Check input immediately to catch nuls */
error_number = is_sane(GDSET, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "404: Invalid character in data (alphanumerics, space and \"#\" only)");
return error_number;
}
strcpy(localstr, "");
/* Do all of the length checking first to avoid stack smashing */
@ -138,16 +137,17 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
error_number = is_sane(NEON, source, length);
break;
default:
strcpy(symbol->errtxt, "401: Auspost input is wrong length");
strcpy(symbol->errtxt, "401: Auspost input is wrong length (8, 13, 16, 18 or 23 characters only)");
return ZINT_ERROR_TOO_LONG;
}
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "402: Invalid characters in data");
strcpy(symbol->errtxt, "402: Invalid character in data (digits only for lengths 16 and 23)");
return error_number;
}
} else {
int zeroes;
if (length > 8) {
strcpy(symbol->errtxt, "403: Auspost input is too long");
strcpy(symbol->errtxt, "403: Auspost input is too long (8 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
switch (symbol->symbology) {
@ -162,23 +162,21 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
/* Add leading zeros as required */
zeroes = 8 - length;
memset(localstr, '0', zeroes);
localstr[8] = '\0';
localstr[zeroes] = '\0';
}
strcat(localstr, (char*) source);
h = strlen(localstr);
error_number = is_sane(GDSET, (unsigned char *) localstr, h);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "404: Invalid characters in data");
return error_number;
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("AUSPOST FCC: %s\n", fcc);
}
/* Verifiy that the first 8 characters are numbers */
ustrncat(localstr, source, length);
h = (int) strlen(localstr);
/* Verify that the first 8 characters are numbers */
memcpy(dpid, localstr, 8);
dpid[8] = '\0';
error_number = is_sane(NEON, (unsigned char *) dpid, strlen(dpid));
error_number = is_sane(NEON, (unsigned char *) dpid, 8);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "405: Invalid characters in DPID");
strcpy(symbol->errtxt, "405: Invalid character in DPID (first 8 characters) (digits only)");
return error_number;
}
@ -190,8 +188,6 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
lookup(NEON, AusNTable, fcc[reader], data_pattern);
}
/* printf("AUSPOST FCC: %s ", fcc); */
/* Delivery Point Identifier (DPID) */
for (reader = 0; reader < 8; reader++) {
lookup(NEON, AusNTable, dpid[reader], data_pattern);
@ -211,7 +207,7 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
}
/* Filler bar */
h = strlen(data_pattern);
h = (int) strlen(data_pattern);
switch (h) {
case 22:
case 37:
@ -230,7 +226,7 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
/* Turn the symbol into a bar pattern ready for plotting */
writer = 0;
h = strlen(data_pattern);
h = (int) strlen(data_pattern);
for (loopey = 0; loopey < h; loopey++) {
if ((data_pattern[loopey] == '1') || (data_pattern[loopey] == '0')) {
set_module(symbol, 0, writer);
@ -242,13 +238,23 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
writer += 2;
}
symbol->row_height[0] = 3;
symbol->row_height[1] = 2;
symbol->row_height[2] = 3;
#ifdef COMPLIANT_HEIGHTS
/* Australia Post Customer Barcoding Technical Specifications (Revised Aug 2012) Dimensions, placement and
printing p.12
https://auspost.com.au/content/dam/auspost_corp/media/documents/customer-barcode-technical-specifications-aug2012.pdf
X 0.5mm (average of 0.4mm - 0.6mm), min height 4.2mm / 0.6mm (X max) = 7, max 5.6mm / 0.4mm (X min) = 14
Tracker 1.3mm (average of 1mm - 1.6mm), Ascender/Descender 3.15mm (average of 2.6mm - 3.7mm) less T = 1.85mm
*/
symbol->row_height[0] = 1.85f / 0.5f; /* 3.7 */
symbol->row_height[1] = 1.3f / 0.5f; /* 2.6 */
error_number = daft_set_height(symbol, 7.0f, 14.0f); /* Note using max X for minimum and min X for maximum */
#else
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
error_number = daft_set_height(symbol, 0.0f, 0.0f);
#endif
symbol->rows = 3;
symbol->width = writer - 1;
return error_number;
}

File diff suppressed because it is too large Load Diff

167
3rdparty/zint-2.10.0/backend/aztec.h vendored Normal file
View File

@ -0,0 +1,167 @@
/* aztec.h - Handles Aztec 2D Symbols */
/*
libzint - the open source barcode library
Copyright (C) 2008-2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#ifndef __AZTEC_H
#define __AZTEC_H
static const short CompactAztecMap[] = {
/* 27 x 27 data grid */
609, 608, 411, 413, 415, 417, 419, 421, 423, 425, 427, 429, 431, 433, 435, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, // 0
607, 606, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 444, 446, 448, 450, 452, 454, 456, 458, // 1
605, 604, 409, 408, 243, 245, 247, 249, 251, 253, 255, 257, 259, 261, 263, 265, 267, 269, 271, 273, 275, 277, 279, 281, 283, 460, 461, // 2
603, 602, 407, 406, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 462, 463, // 3
601, 600, 405, 404, 241, 240, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 284, 285, 464, 465, // 4
599, 598, 403, 402, 239, 238, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 286, 287, 466, 467, // 5
597, 596, 401, 400, 237, 236, 105, 104, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 140, 141, 288, 289, 468, 469, // 6
595, 594, 399, 398, 235, 234, 103, 102, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 142, 143, 290, 291, 470, 471, // 7
593, 592, 397, 396, 233, 232, 101, 100, 1, 1, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 0, 1, 28, 29, 144, 145, 292, 293, 472, 473, // 8
591, 590, 395, 394, 231, 230, 99, 98, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 30, 31, 146, 147, 294, 295, 474, 475, // 9
589, 588, 393, 392, 229, 228, 97, 96, 2027, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2007, 32, 33, 148, 149, 296, 297, 476, 477, // 10
587, 586, 391, 390, 227, 226, 95, 94, 2026, 1, 0, 1, 1, 1, 1, 1, 0, 1, 2008, 34, 35, 150, 151, 298, 299, 478, 479, // 11
585, 584, 389, 388, 225, 224, 93, 92, 2025, 1, 0, 1, 0, 0, 0, 1, 0, 1, 2009, 36, 37, 152, 153, 300, 301, 480, 481, // 12
583, 582, 387, 386, 223, 222, 91, 90, 2024, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2010, 38, 39, 154, 155, 302, 303, 482, 483, // 13
581, 580, 385, 384, 221, 220, 89, 88, 2023, 1, 0, 1, 0, 0, 0, 1, 0, 1, 2011, 40, 41, 156, 157, 304, 305, 484, 485, // 14
579, 578, 383, 382, 219, 218, 87, 86, 2022, 1, 0, 1, 1, 1, 1, 1, 0, 1, 2012, 42, 43, 158, 159, 306, 307, 486, 487, // 15
577, 576, 381, 380, 217, 216, 85, 84, 2021, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2013, 44, 45, 160, 161, 308, 309, 488, 489, // 16
575, 574, 379, 378, 215, 214, 83, 82, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 46, 47, 162, 163, 310, 311, 490, 491, // 17
573, 572, 377, 376, 213, 212, 81, 80, 0, 0, 2020, 2019, 2018, 2017, 2016, 2015, 2014, 0, 0, 48, 49, 164, 165, 312, 313, 492, 493, // 18
571, 570, 375, 374, 211, 210, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 50, 51, 166, 167, 314, 315, 494, 495, // 19
569, 568, 373, 372, 209, 208, 79, 77, 75, 73, 71, 69, 67, 65, 63, 61, 59, 57, 55, 52, 53, 168, 169, 316, 317, 496, 497, // 20
567, 566, 371, 370, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 170, 171, 318, 319, 498, 499, // 21
565, 564, 369, 368, 207, 205, 203, 201, 199, 197, 195, 193, 191, 189, 187, 185, 183, 181, 179, 177, 175, 172, 173, 320, 321, 500, 501, // 22
563, 562, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 322, 323, 502, 503, // 23
561, 560, 367, 365, 363, 361, 359, 357, 355, 353, 351, 349, 347, 345, 343, 341, 339, 337, 335, 333, 331, 329, 327, 324, 325, 504, 505, // 24
558, 556, 554, 552, 550, 548, 546, 544, 542, 540, 538, 536, 534, 532, 530, 528, 526, 524, 522, 520, 518, 516, 514, 512, 510, 506, 507, // 25
559, 557, 555, 553, 551, 549, 547, 545, 543, 541, 539, 537, 535, 533, 531, 529, 527, 525, 523, 521, 519, 517, 515, 513, 511, 508, 509, // 26
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
};
/* Pre-calculated finder, descriptor, orientation mappings for full-range symbol */
static const short AztecMapCore[15][15] = {
{ 1, 1, 20000, 20001, 20002, 20003, 20004, 0, 20005, 20006, 20007, 20008, 20009, 0, 1, },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, },
{ 20039, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 20010, },
{ 20038, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 20011, },
{ 20037, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 20012, },
{ 20036, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 20013, },
{ 20035, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 20014, },
{ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
{ 20034, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 20015, },
{ 20033, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 20016, },
{ 20032, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 20017, },
{ 20031, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 20018, },
{ 20030, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 20019, },
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, },
{ 0, 0, 20029, 20028, 20027, 20026, 20025, 0, 20024, 20023, 20022, 20021, 20020, 0, 0, },
};
static const char AztecSymbolChar[128] = {
/* From Table 2 */
0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 19, 1, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 0, 18, 0, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 21, 22,
23, 24, 25, 26, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 27, 21, 28, 22, 23, 24, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 29, 25, 30, 26, 27
};
static const char AztecModes[129] = "BMMMMMMMMMMMMXBBBBBBBBBBBBBMMMMMXPPPPPPPPPPPXPXPDDDDDDDDDDPPPPPPMUUUUUUUUUUUUUUUUUUUUUUUUUUPMPMMMLLLLLLLLLLLLLLLLLLLLLLLLLLPMPMM";
static const short AztecSizes[32] = {
/* Codewords per symbol */
21, 48, 60, 88, 120, 156, 196, 240, 230, 272, 316, 364, 416, 470, 528, 588, 652, 720, 790,
864, 940, 1020, 920, 992, 1066, 1144, 1224, 1306, 1392, 1480, 1570, 1664
};
static const short AztecCompactSizes[4] = {
17, 40, 51, 76
};
static const short Aztec10DataSizes[32] = {
/* Data bits per symbol maximum with 10% error correction */
96, 246, 408, 616, 840, 1104, 1392, 1704, 2040, 2420, 2820, 3250, 3720, 4200, 4730,
5270, 5840, 6450, 7080, 7750, 8430, 9150, 9900, 10680, 11484, 12324, 13188, 14076,
15000, 15948, 16920, 17940
};
static const short Aztec23DataSizes[32] = {
/* Data bits per symbol maximum with 23% error correction */
84, 204, 352, 520, 720, 944, 1184, 1456, 1750, 2070, 2410, 2780, 3180, 3590, 4040,
4500, 5000, 5520, 6060, 6630, 7210, 7830, 8472, 9132, 9816, 10536, 11280, 12036,
12828, 13644, 14472, 15348
};
static const short Aztec36DataSizes[32] = {
/* Data bits per symbol maximum with 36% error correction */
66, 168, 288, 432, 592, 776, 984, 1208, 1450, 1720, 2000, 2300, 2640, 2980, 3350,
3740, 4150, 4580, 5030, 5500, 5990, 6500, 7032, 7584, 8160, 8760, 9372, 9996, 10656,
11340, 12024, 12744
};
static const short Aztec50DataSizes[32] = {
/* Data bits per symbol maximum with 50% error correction */
48, 126, 216, 328, 456, 600, 760, 936, 1120, 1330, 1550, 1790, 2050, 2320, 2610,
2910, 3230, 3570, 3920, 4290, 4670, 5070, 5484, 5916, 6360, 6828, 7308, 7800, 8316,
8844, 9384, 9948
};
static const short AztecCompact10DataSizes[4] = {
78, 198, 336, 520
};
static const short AztecCompact23DataSizes[4] = {
66, 168, 288, 440
};
static const short AztecCompact36DataSizes[4] = {
48, 138, 232, 360
};
static const short AztecCompact50DataSizes[4] = {
36, 102, 176, 280
};
static const char AztecOffset[32] = {
66, 64, 62, 60, 57, 55, 53, 51, 49, 47, 45, 42, 40, 38, 36, 34, 32, 30, 28, 25, 23, 21,
19, 17, 15, 13, 10, 8, 6, 4, 2, 0
};
static const char AztecCompactOffset[4] = {
6, 4, 2, 0
};
static const short AztecMapGridYOffsets[] = {
27, 43, 59, 75, 91, 107, 123, 139
};
#endif /* __AZTEC_H */

2320
3rdparty/zint-2.10.0/backend/big5.h vendored Normal file

File diff suppressed because it is too large Load Diff

215
3rdparty/zint-2.10.0/backend/bmp.c vendored Normal file
View File

@ -0,0 +1,215 @@
/* bmp.c - Handles output to Windows Bitmap file */
/*
libzint - the open source barcode library
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include <errno.h>
#include <stdio.h>
#include "common.h"
#include "bmp.h" /* Bitmap header structure */
#ifdef _MSC_VER
#include <io.h>
#include <fcntl.h>
#endif
INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) {
int i, row, column;
int row_size;
int bits_per_pixel;
int colour_count;
unsigned int data_offset, data_size, file_size;
unsigned char *bitmap_file_start, *bmp_posn;
unsigned char *bitmap;
FILE *bmp_file;
bitmap_file_header_t file_header;
bitmap_info_header_t info_header;
color_ref_t bg_color_ref;
color_ref_t fg_color_ref;
color_ref_t ultra_color_ref[8];
int ultra_fg_index = 9;
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT; /* Suppress gcc -fanalyzer warning */
fg_color_ref.red = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
fg_color_ref.green = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]);
fg_color_ref.blue = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
fg_color_ref.reserved = 0x00;
bg_color_ref.red = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]);
bg_color_ref.green = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
bg_color_ref.blue = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
bg_color_ref.reserved = 0x00;
if (symbol->symbology == BARCODE_ULTRA) {
for (i = 0; i < 8; i++) {
ultra_color_ref[i].red = colour_to_red(i + 1);
ultra_color_ref[i].green = colour_to_green(i + 1);
ultra_color_ref[i].blue = colour_to_blue(i + 1);
ultra_color_ref[i].reserved = 0x00;
if (memcmp(&ultra_color_ref[i], &fg_color_ref, sizeof(fg_color_ref)) == 0) {
ultra_fg_index = i + 1;
}
}
bits_per_pixel = 4;
colour_count = ultra_fg_index == 9 ? 10 : 9;
} else {
bits_per_pixel = 1;
colour_count = 2;
}
row_size = 4 * ((bits_per_pixel * symbol->bitmap_width + 31) / 32);
data_size = symbol->bitmap_height * row_size;
data_offset = sizeof(bitmap_file_header_t) + sizeof(bitmap_info_header_t);
data_offset += colour_count * sizeof(color_ref_t);
file_size = data_offset + data_size;
bitmap_file_start = (unsigned char *) malloc(file_size);
if (bitmap_file_start == NULL) {
strcpy(symbol->errtxt, "602: Insufficient memory for BMP file buffer");
return ZINT_ERROR_MEMORY;
}
memset(bitmap_file_start, 0, file_size); /* Not required but keeps padding bytes consistent */
bitmap = bitmap_file_start + data_offset;
/* Pixel Plotting */
if (symbol->symbology == BARCODE_ULTRA) {
for (row = 0; row < symbol->bitmap_height; row++) {
for (column = 0; column < symbol->bitmap_width; column++) {
i = (column / 2) + (row * row_size);
switch (*(pixelbuf + (symbol->bitmap_width * (symbol->bitmap_height - row - 1)) + column)) {
case 'C': // Cyan
bitmap[i] += 1 << (4 * (1 - (column % 2)));
break;
case 'B': // Blue
bitmap[i] += 2 << (4 * (1 - (column % 2)));
break;
case 'M': // Magenta
bitmap[i] += 3 << (4 * (1 - (column % 2)));
break;
case 'R': // Red
bitmap[i] += 4 << (4 * (1 - (column % 2)));
break;
case 'Y': // Yellow
bitmap[i] += 5 << (4 * (1 - (column % 2)));
break;
case 'G': // Green
bitmap[i] += 6 << (4 * (1 - (column % 2)));
break;
case 'K': // Black
bitmap[i] += 7 << (4 * (1 - (column % 2)));
break;
case 'W': // White
bitmap[i] += 8 << (4 * (1 - (column % 2)));
break;
case '1': // Foreground
bitmap[i] += ultra_fg_index << (4 * (1 - (column % 2)));
break;
}
}
}
} else {
for (row = 0; row < symbol->bitmap_height; row++) {
for (column = 0; column < symbol->bitmap_width; column++) {
i = (column / 8) + (row * row_size);
if ((*(pixelbuf + (symbol->bitmap_width * (symbol->bitmap_height - row - 1)) + column)) == '1') {
bitmap[i] += (0x01 << (7 - (column % 8)));
}
}
}
}
symbol->bitmap_byte_length = data_size;
file_header.header_field = 0x4d42; // "BM"
file_header.file_size = file_size;
file_header.reserved = 0;
file_header.data_offset = data_offset;
info_header.header_size = sizeof(bitmap_info_header_t);
info_header.width = symbol->bitmap_width;
info_header.height = symbol->bitmap_height;
info_header.colour_planes = 1;
info_header.bits_per_pixel = bits_per_pixel;
info_header.compression_method = 0; // BI_RGB
info_header.image_size = 0;
info_header.horiz_res = 0;
info_header.vert_res = 0;
info_header.colours = colour_count;
info_header.important_colours = colour_count;
bmp_posn = bitmap_file_start;
memcpy(bitmap_file_start, &file_header, sizeof(bitmap_file_header_t));
bmp_posn += sizeof(bitmap_file_header_t);
memcpy(bmp_posn, &info_header, sizeof(bitmap_info_header_t));
bmp_posn += sizeof(bitmap_info_header_t);
memcpy(bmp_posn, &bg_color_ref, sizeof(color_ref_t));
if (symbol->symbology == BARCODE_ULTRA) {
for (i = 0; i < 8; i++) {
bmp_posn += sizeof(color_ref_t);
memcpy(bmp_posn, &ultra_color_ref[i], sizeof(color_ref_t));
}
if (ultra_fg_index == 9) {
bmp_posn += sizeof(color_ref_t);
memcpy(bmp_posn, &fg_color_ref, sizeof(color_ref_t));
}
} else {
bmp_posn += sizeof(color_ref_t);
memcpy(bmp_posn, &fg_color_ref, sizeof(color_ref_t));
}
/* Open output file in binary mode */
if (output_to_stdout) {
#ifdef _MSC_VER
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
sprintf(symbol->errtxt, "600: Could not set stdout to binary (%d: %.30s)", errno, strerror(errno));
free(bitmap_file_start);
return ZINT_ERROR_FILE_ACCESS;
}
#endif
bmp_file = stdout;
} else {
if (!(bmp_file = fopen(symbol->outfile, "wb"))) {
free(bitmap_file_start);
sprintf(symbol->errtxt, "601: Could not open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
}
fwrite(bitmap_file_start, file_header.file_size, 1, bmp_file);
if (output_to_stdout) {
fflush(bmp_file);
} else {
fclose(bmp_file);
}
free(bitmap_file_start);
return 0;
}

View File

@ -66,6 +66,13 @@ extern "C" {
uint32_t important_colours;
} bitmap_info_header_t;
typedef struct color_ref {
uint8_t blue;
uint8_t green;
uint8_t red;
uint8_t reserved;
} color_ref_t;
#pragma pack ()
#ifdef __cplusplus
@ -74,3 +81,4 @@ extern "C" {
#endif /* BMP_H */

View File

@ -0,0 +1,106 @@
/*
libzint - the open source barcode library
Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
/* Channel code precalculated values to avoid excessive looping */
/* To generate uncomment CHANNEL_GENERATE_PRECALCS define and run "./test_channel -f generate -g" */
/* Paste result below here */
static channel_precalc channel_precalcs7[] = {
{ 115338, { 1, 3, 1, 1, 1, 1, 5, 1, }, { 1, 1, 1, 2, 1, 2, 3, 3, }, { 1, 7, 5, 5, 5, 5, 5, }, { 1, 7, 7, 7, 6, 6, 5, }, },
{ 230676, { 1, 1, 2, 2, 4, 1, 1, 2, }, { 1, 2, 1, 3, 2, 1, 3, 1, }, { 1, 7, 7, 6, 5, 2, 2, }, { 1, 7, 6, 6, 4, 3, 3, }, },
{ 346014, { 1, 2, 3, 1, 1, 1, 3, 2, }, { 1, 2, 2, 1, 1, 3, 1, 3, }, { 1, 7, 6, 4, 4, 4, 4, }, { 1, 7, 6, 5, 5, 5, 3, }, },
{ 461352, { 1, 2, 1, 1, 1, 2, 2, 4, }, { 1, 3, 1, 1, 3, 2, 2, 1, }, { 1, 7, 6, 6, 6, 6, 5, }, { 1, 7, 5, 5, 5, 3, 2, }, },
};
static channel_precalc channel_precalcs8[] = {
{ 119121, { 2, 1, 3, 2, 1, 3, 2, 1, }, { 1, 1, 1, 4, 3, 2, 1, 2, }, { 8, 7, 7, 5, 4, 4, 2, }, { 8, 8, 8, 8, 5, 3, 2, }, },
{ 238242, { 2, 1, 1, 2, 2, 2, 1, 4, }, { 1, 1, 3, 1, 1, 2, 4, 2, }, { 8, 7, 7, 7, 6, 5, 4, }, { 8, 8, 8, 6, 6, 6, 5, }, },
{ 357363, { 2, 2, 1, 4, 1, 1, 1, 3, }, { 1, 1, 1, 1, 3, 2, 5, 1, }, { 8, 7, 6, 6, 3, 3, 3, }, { 8, 8, 8, 8, 8, 6, 5, }, },
{ 476484, { 2, 2, 1, 1, 3, 2, 3, 1, }, { 1, 1, 3, 1, 2, 2, 3, 2, }, { 8, 7, 6, 6, 6, 4, 3, }, { 8, 8, 8, 6, 6, 5, 4, }, },
{ 595605, { 2, 3, 3, 2, 1, 1, 1, 2, }, { 1, 1, 2, 1, 1, 1, 5, 3, }, { 8, 7, 5, 3, 2, 2, 2, }, { 8, 8, 8, 7, 7, 7, 7, }, },
{ 714726, { 2, 1, 1, 6, 1, 1, 2, 1, }, { 1, 2, 1, 3, 1, 4, 1, 2, }, { 8, 7, 7, 7, 2, 2, 2, }, { 8, 8, 7, 7, 5, 5, 2, }, },
{ 833847, { 2, 1, 1, 3, 1, 3, 3, 1, }, { 1, 2, 3, 1, 1, 3, 2, 2, }, { 8, 7, 7, 7, 5, 5, 3, }, { 8, 8, 7, 5, 5, 5, 3, }, },
{ 952968, { 2, 2, 2, 3, 2, 1, 2, 1, }, { 1, 2, 2, 1, 2, 2, 2, 3, }, { 8, 7, 6, 5, 3, 2, 2, }, { 8, 8, 7, 6, 6, 5, 4, }, },
{ 1072089, { 2, 5, 1, 1, 2, 2, 1, 1, }, { 1, 2, 1, 3, 1, 3, 3, 1, }, { 8, 7, 3, 3, 3, 2, 1, }, { 8, 8, 7, 7, 5, 5, 3, }, },
{ 1191210, { 2, 2, 1, 2, 1, 1, 3, 3, }, { 1, 3, 1, 1, 5, 1, 1, 2, }, { 8, 7, 6, 6, 5, 5, 5, }, { 8, 8, 6, 6, 6, 2, 2, }, },
{ 1310331, { 2, 1, 2, 1, 2, 3, 2, 2, }, { 1, 4, 1, 3, 1, 1, 2, 2, }, { 8, 7, 7, 6, 6, 5, 3, }, { 8, 8, 5, 5, 3, 3, 3, }, },
{ 1429452, { 2, 2, 1, 2, 2, 3, 2, 1, }, { 1, 5, 3, 1, 2, 1, 1, 1, }, { 8, 7, 6, 6, 5, 4, 2, }, { 8, 8, 4, 2, 2, 1, 1, }, },
{ 1548573, { 3, 1, 1, 2, 5, 1, 1, 1, }, { 1, 1, 2, 2, 1, 2, 5, 1, }, { 8, 6, 6, 6, 5, 1, 1, }, { 8, 8, 8, 7, 6, 6, 5, }, },
{ 1667694, { 3, 2, 2, 1, 1, 3, 2, 1, }, { 1, 1, 1, 1, 2, 4, 3, 2, }, { 8, 6, 5, 4, 4, 4, 2, }, { 8, 8, 8, 8, 8, 7, 4, }, },
{ 1786815, { 3, 4, 2, 1, 2, 1, 1, 1, }, { 1, 1, 2, 1, 1, 2, 1, 6, }, { 8, 6, 3, 2, 2, 1, 1, }, { 8, 8, 8, 7, 7, 7, 6, }, },
{ 1905936, { 3, 2, 1, 3, 1, 3, 1, 1, }, { 1, 2, 1, 1, 1, 4, 2, 3, }, { 8, 6, 5, 5, 3, 3, 1, }, { 8, 8, 7, 7, 7, 7, 4, }, },
{ 2025057, { 3, 1, 2, 2, 1, 1, 4, 1, }, { 1, 3, 2, 1, 1, 1, 5, 1, }, { 8, 6, 6, 5, 4, 4, 4, }, { 8, 8, 6, 5, 5, 5, 5, }, },
{ 2144178, { 3, 1, 2, 1, 2, 2, 2, 2, }, { 1, 5, 1, 1, 4, 1, 1, 1, }, { 8, 6, 6, 5, 5, 4, 3, }, { 8, 8, 4, 4, 4, 1, 1, }, },
{ 2263299, { 4, 2, 1, 2, 1, 1, 1, 3, }, { 1, 1, 1, 1, 3, 3, 3, 2, }, { 8, 5, 4, 4, 3, 3, 3, }, { 8, 8, 8, 8, 8, 6, 4, }, },
{ 2382420, { 4, 2, 1, 1, 1, 1, 4, 1, }, { 1, 2, 2, 2, 2, 2, 2, 2, }, { 8, 5, 4, 4, 4, 4, 4, }, { 8, 8, 7, 6, 5, 4, 3, }, },
{ 2501541, { 5, 1, 1, 2, 2, 1, 1, 2, }, { 1, 1, 2, 3, 3, 1, 1, 3, }, { 8, 4, 4, 4, 3, 2, 2, }, { 8, 8, 8, 7, 5, 3, 3, }, },
{ 2620662, { 6, 1, 1, 1, 2, 1, 1, 2, }, { 1, 2, 4, 1, 2, 3, 1, 1, }, { 8, 3, 3, 3, 3, 2, 2, }, { 8, 8, 7, 4, 4, 3, 1, }, },
{ 2739783, { 1, 1, 1, 1, 3, 3, 4, 1, }, { 2, 1, 2, 1, 6, 1, 1, 1, }, { 8, 8, 8, 8, 8, 6, 4, }, { 8, 7, 7, 6, 6, 1, 1, }, },
{ 2858904, { 1, 1, 2, 3, 3, 1, 3, 1, }, { 2, 1, 3, 1, 3, 1, 2, 2, }, { 8, 8, 8, 7, 5, 3, 3, }, { 8, 7, 7, 5, 5, 3, 3, }, },
{ 2978025, { 1, 2, 2, 4, 1, 2, 1, 2, }, { 2, 1, 1, 1, 1, 3, 4, 2, }, { 8, 8, 7, 6, 3, 3, 2, }, { 8, 7, 7, 7, 7, 7, 5, }, },
{ 3097146, { 1, 2, 2, 1, 3, 3, 2, 1, }, { 2, 1, 3, 3, 2, 2, 1, 1, }, { 8, 8, 7, 6, 6, 4, 2, }, { 8, 7, 7, 5, 3, 2, 1, }, },
{ 3216267, { 1, 3, 1, 1, 1, 3, 1, 4, }, { 2, 1, 3, 2, 3, 2, 1, 1, }, { 8, 8, 6, 6, 6, 6, 4, }, { 8, 7, 7, 5, 4, 2, 1, }, },
{ 3335388, { 1, 1, 1, 4, 4, 1, 2, 1, }, { 2, 2, 1, 1, 1, 1, 3, 4, }, { 8, 8, 8, 8, 5, 2, 2, }, { 8, 7, 6, 6, 6, 6, 6, }, },
{ 3454509, { 1, 1, 2, 4, 3, 1, 2, 1, }, { 2, 2, 2, 5, 1, 1, 1, 1, }, { 8, 8, 8, 7, 4, 2, 2, }, { 8, 7, 6, 5, 1, 1, 1, }, },
{ 3573630, { 1, 2, 1, 3, 1, 2, 3, 2, }, { 2, 2, 2, 1, 1, 4, 2, 1, }, { 8, 8, 7, 7, 5, 5, 4, }, { 8, 7, 6, 5, 5, 5, 2, }, },
{ 3692751, { 1, 4, 2, 3, 2, 1, 1, 1, }, { 2, 2, 1, 1, 2, 1, 2, 4, }, { 8, 8, 5, 4, 2, 1, 1, }, { 8, 7, 6, 6, 6, 5, 5, }, },
{ 3811872, { 1, 1, 2, 1, 3, 5, 1, 1, }, { 2, 3, 3, 2, 2, 1, 1, 1, }, { 8, 8, 8, 7, 7, 5, 1, }, { 8, 7, 5, 3, 2, 1, 1, }, },
{ 3930993, { 1, 1, 1, 1, 6, 2, 2, 1, }, { 2, 4, 1, 2, 1, 3, 1, 1, }, { 8, 8, 8, 8, 8, 3, 2, }, { 8, 7, 4, 4, 3, 3, 1, }, },
{ 4050114, { 1, 3, 3, 2, 2, 1, 2, 1, }, { 2, 6, 2, 1, 1, 1, 1, 1, }, { 8, 8, 6, 4, 3, 2, 2, }, { 8, 7, 2, 1, 1, 1, 1, }, },
{ 4169235, { 2, 1, 2, 2, 4, 2, 1, 1, }, { 2, 1, 2, 1, 1, 1, 4, 3, }, { 8, 7, 7, 6, 5, 2, 1, }, { 8, 7, 7, 6, 6, 6, 6, }, },
{ 4288356, { 2, 2, 2, 1, 1, 3, 3, 1, }, { 2, 1, 1, 4, 2, 1, 1, 3, }, { 8, 7, 6, 5, 5, 5, 3, }, { 8, 7, 7, 7, 4, 3, 3, }, },
{ 4407477, { 2, 3, 3, 1, 2, 1, 1, 2, }, { 2, 1, 3, 2, 4, 1, 1, 1, }, { 8, 7, 5, 3, 3, 2, 2, }, { 8, 7, 7, 5, 4, 1, 1, }, },
{ 4526598, { 2, 1, 4, 1, 4, 1, 1, 1, }, { 2, 2, 2, 1, 2, 3, 1, 2, }, { 8, 7, 7, 4, 4, 1, 1, }, { 8, 7, 6, 5, 5, 4, 2, }, },
{ 4645719, { 2, 4, 2, 1, 1, 2, 1, 2, }, { 2, 2, 1, 1, 3, 2, 3, 1, }, { 8, 7, 4, 3, 3, 3, 2, }, { 8, 7, 6, 6, 6, 4, 3, }, },
{ 4764840, { 2, 1, 1, 1, 2, 4, 1, 3, }, { 2, 4, 1, 2, 1, 3, 1, 1, }, { 8, 7, 7, 7, 7, 6, 3, }, { 8, 7, 4, 4, 3, 3, 1, }, },
{ 4883961, { 3, 1, 1, 3, 2, 2, 1, 2, }, { 2, 1, 2, 2, 2, 1, 2, 3, }, { 8, 6, 6, 6, 4, 3, 2, }, { 8, 7, 7, 6, 5, 4, 4, }, },
{ 5003082, { 3, 3, 3, 1, 1, 1, 2, 1, }, { 2, 1, 2, 1, 1, 3, 1, 4, }, { 8, 6, 4, 2, 2, 2, 2, }, { 8, 7, 7, 6, 6, 6, 4, }, },
{ 5122203, { 3, 1, 1, 2, 1, 2, 1, 4, }, { 2, 3, 1, 1, 1, 2, 4, 1, }, { 8, 6, 6, 6, 5, 5, 4, }, { 8, 7, 5, 5, 5, 5, 4, }, },
{ 5241324, { 4, 1, 1, 3, 1, 2, 2, 1, }, { 2, 1, 3, 1, 1, 3, 3, 1, }, { 8, 5, 5, 5, 3, 3, 2, }, { 8, 7, 7, 5, 5, 5, 3, }, },
{ 5360445, { 4, 3, 1, 1, 2, 1, 1, 2, }, { 2, 4, 1, 3, 2, 1, 1, 1, }, { 8, 5, 3, 3, 3, 2, 2, }, { 8, 7, 4, 4, 2, 1, 1, }, },
{ 5479566, { 1, 1, 3, 1, 3, 2, 1, 3, }, { 3, 1, 1, 2, 1, 2, 1, 4, }, { 8, 8, 8, 6, 6, 4, 3, }, { 8, 6, 6, 6, 5, 5, 4, }, },
{ 5598687, { 1, 2, 1, 1, 5, 1, 3, 1, }, { 3, 1, 1, 1, 1, 3, 1, 4, }, { 8, 8, 7, 7, 7, 3, 3, }, { 8, 6, 6, 6, 6, 6, 4, }, },
{ 5717808, { 1, 3, 1, 2, 1, 3, 1, 3, }, { 3, 1, 1, 2, 4, 1, 1, 2, }, { 8, 8, 6, 6, 5, 5, 3, }, { 8, 6, 6, 6, 5, 2, 2, }, },
{ 5836929, { 1, 1, 2, 3, 1, 2, 3, 2, }, { 3, 2, 1, 1, 1, 1, 2, 4, }, { 8, 8, 8, 7, 5, 5, 4, }, { 8, 6, 5, 5, 5, 5, 5, }, },
{ 5956050, { 1, 2, 3, 3, 2, 2, 1, 1, }, { 3, 2, 3, 1, 1, 1, 1, 3, }, { 8, 8, 7, 5, 3, 2, 1, }, { 8, 6, 5, 3, 3, 3, 3, }, },
{ 6075171, { 1, 3, 1, 1, 3, 3, 2, 1, }, { 3, 3, 1, 1, 3, 1, 2, 1, }, { 8, 8, 6, 6, 6, 4, 2, }, { 8, 6, 4, 4, 4, 2, 2, }, },
{ 6194292, { 2, 1, 1, 3, 4, 1, 2, 1, }, { 3, 1, 2, 1, 3, 1, 3, 1, }, { 8, 7, 7, 7, 5, 2, 2, }, { 8, 6, 6, 5, 5, 3, 3, }, },
{ 6313413, { 2, 3, 2, 2, 1, 2, 2, 1, }, { 3, 1, 1, 2, 1, 3, 2, 2, }, { 8, 7, 5, 4, 3, 3, 2, }, { 8, 6, 6, 6, 5, 5, 3, }, },
{ 6432534, { 2, 3, 1, 1, 2, 2, 3, 1, }, { 3, 2, 1, 2, 3, 1, 2, 1, }, { 8, 7, 5, 5, 5, 4, 3, }, { 8, 6, 5, 5, 4, 2, 2, }, },
{ 6551655, { 3, 1, 1, 2, 1, 4, 1, 2, }, { 3, 1, 2, 3, 1, 1, 3, 1, }, { 8, 6, 6, 6, 5, 5, 2, }, { 8, 6, 6, 5, 3, 3, 3, }, },
{ 6670776, { 3, 1, 1, 1, 1, 3, 4, 1, }, { 3, 3, 1, 2, 1, 1, 3, 1, }, { 8, 6, 6, 6, 6, 6, 4, }, { 8, 6, 4, 4, 3, 3, 3, }, },
{ 6789897, { 5, 2, 1, 1, 2, 1, 2, 1, }, { 3, 1, 1, 1, 2, 2, 3, 2, }, { 8, 4, 3, 3, 3, 2, 2, }, { 8, 6, 6, 6, 6, 5, 4, }, },
{ 6909018, { 1, 2, 2, 2, 2, 1, 4, 1, }, { 4, 1, 1, 2, 1, 2, 1, 3, }, { 8, 8, 7, 6, 5, 4, 4, }, { 8, 5, 5, 5, 4, 4, 3, }, },
{ 7028139, { 1, 1, 3, 2, 2, 2, 1, 3, }, { 4, 2, 2, 1, 2, 2, 1, 1, }, { 8, 8, 8, 6, 5, 4, 3, }, { 8, 5, 4, 3, 3, 2, 1, }, },
{ 7147260, { 2, 1, 4, 3, 2, 1, 1, 1, }, { 4, 1, 1, 1, 4, 1, 1, 2, }, { 8, 7, 7, 4, 2, 1, 1, }, { 8, 5, 5, 5, 5, 2, 2, }, },
{ 7266381, { 2, 4, 1, 3, 2, 1, 1, 1, }, { 4, 2, 1, 1, 1, 2, 1, 3, }, { 8, 7, 4, 4, 2, 1, 1, }, { 8, 5, 4, 4, 4, 4, 3, }, },
{ 7385502, { 4, 2, 1, 3, 1, 2, 1, 1, }, { 4, 1, 1, 4, 2, 1, 1, 1, }, { 8, 5, 4, 4, 2, 2, 1, }, { 8, 5, 5, 5, 2, 1, 1, }, },
{ 7504623, { 1, 1, 3, 4, 3, 1, 1, 1, }, { 5, 2, 1, 1, 1, 1, 1, 3, }, { 8, 8, 8, 6, 3, 1, 1, }, { 8, 4, 3, 3, 3, 3, 3, }, },
{ 7623744, { 3, 1, 1, 2, 2, 1, 2, 3, }, { 5, 2, 1, 1, 1, 2, 1, 2, }, { 8, 6, 6, 6, 5, 4, 4, }, { 8, 4, 3, 3, 3, 3, 2, }, },
};

View File

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2016 Harald Oehlmann
Copyright (C) 2016 - 2021 Harald Oehlmann
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -29,16 +29,17 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include <assert.h>
#include "common.h"
#include "gs1.h"
INTERNAL int code_128(struct zint_symbol *symbol, unsigned char source[], int length);
#define uchar unsigned char
@ -50,6 +51,7 @@
#define CShift 16
#define CFill 32
#define CodeFNC1 64
#define CodeFNC4 128
#define ZTNum (CodeA+CodeB+CodeC)
#define ZTFNC1 (CodeA+CodeB+CodeC+CodeFNC1)
@ -90,32 +92,34 @@ typedef struct sCharacterSetTable
} CharacterSetTable;
/* Find the possible Code-128 Character sets for a character
* The result is an or of CodeA,CodeB,CodeC,CodeFNC1 in dependency of the
* The result is an or of CodeA, CodeB, CodeC, CodeFNC1, CodeFNC4 depending on the
* possible Code 128 character sets.
*/
int GetPossibleCharacterSet(unsigned char C)
static int GetPossibleCharacterSet(unsigned char C)
{
if (C<='\x19') /* Dec:31 */
if (C<='\x1f') /* Control chars */
return CodeA;
if (C>='0' && C<='9')
return ZTNum; /* ZTNum=CodeA+CodeB+CodeC */
if (C==aFNC1)
return ZTFNC1; /* ZTFNC1=CodeA+CodeB+CodeC+CodeFNC1 */
if (C==aFNC1) /* FNC1s (GS1) not used */
return ZTFNC1; /* ZTFNC1=CodeA+CodeB+CodeC+CodeFNC1 */ /* Not reached */
if (C==aFNC4)
return (CodeA | CodeB | CodeFNC4);
if (C>='\x60' && C<='\x7f') /* 60 to 127 */
return CodeB;
return CodeA+CodeB;
}
/* Create a Table with the following information for each Data character:
* int CharacterSet is an or of CodeA,CodeB,CodeC,CodeFNC1, in
* dependency which character set is applicable.
* int CharacterSet is an or of CodeA, CodeB, CodeC, CodeFNC1, CodeFNC4,
* depending on which character set is applicable.
* (Result of GetPossibleCharacterSet)
* int AFollowing,BFollowing The number of source characters you still may encode
* in this character set.
* int CFollowing The number of characters encodable in CodeC if we
* start here.
*/
static void CreateCharacterSetTable(CharacterSetTable T[], unsigned char *data,const size_t dataLength)
static void CreateCharacterSetTable(CharacterSetTable T[], unsigned char *data, const int dataLength)
{
int charCur;
int runChar;
@ -146,11 +150,11 @@ static void CreateCharacterSetTable(CharacterSetTable T[], unsigned char *data,c
/* CodeC possible */
runChar=charCur;
do{
/* Wether this is FNC1 wether next is */
/* Whether this is FNC1, whether next is */
/* numeric */
if (T[runChar].CharacterSet==ZTFNC1)
if (T[runChar].CharacterSet==ZTFNC1) /* FNC1s (GS1) not used */
/* FNC1 */
++(T[charCur].CFollowing);
++(T[charCur].CFollowing); /* Not reached */
else
{
++runChar;
@ -172,7 +176,7 @@ static void CreateCharacterSetTable(CharacterSetTable T[], unsigned char *data,c
* one bundle into the line (up to here). This is calculated online because
* it depends on the space in the line.
*/
int RemainingDigits(CharacterSetTable *T, int charCur,int emptyColumns)
static int RemainingDigits(CharacterSetTable *T, int charCur,int emptyColumns)
{
int digitCount; /* Numerical digits fitting in the line */
int runChar;
@ -193,49 +197,41 @@ int RemainingDigits(CharacterSetTable *T, int charCur,int emptyColumns)
}
/* Find the Character distribution at a given column count.
* If to many rows (>44) are requested the columns is extended.
* A oneLigner may be choosen if shorter.
* If too many rows (>44) are requested the columns are extended.
* Parameters :
* T Pointer on the Characters which fit in the row
* If a different count is calculated it is corrected
* in the callers workspace.
* pFillings Output of filling characters
* pSet Output of the character sets used, allocated by me.
* Data The Data string to encode, exceptionnally not an out
* Return value Resulting row count
*/
static int Columns2Rows(CharacterSetTable *T, unsigned char *data, const size_t dataLength,
static int Columns2Rows(struct zint_symbol *symbol, CharacterSetTable *T, const int dataLength,
int * pRows, int * pUseColumns, int * pSet, int * pFillings)
{
int useColumns; /* Usable Characters per line */
int fillings; /* Number of filling characters */
int fillings = 0; /* Number of filling characters */
int rowsCur;
int charCur;
int runChar;
int emptyColumns; /* Number of codes still empty in line. */
int emptyColumns2; /* Alternative emptyColumns to compare */
int fOneLiner; /* Flag if One Liner */
int CPaires; /* Number of digit pairs which may fit in the line */
int characterSetCur; /* Current Character Set */
int isFNC4; /* Set if current character FNC4 */
useColumns=*pUseColumns;
if (useColumns<3)
useColumns=3;
/* >>> Loop until rowsCur<44 */
/* >>> Loop until rowsCur <= 44 */
do {
int charCur=0;
memset(pSet,0,dataLength*sizeof(int));
charCur=0;
rowsCur=0;
fOneLiner=1; /* First try one-Liner */
/* >>> Line and OneLiner-try Loop */
/* >>> Line Loop */
do{
/* >> Start Character */
emptyColumns=useColumns; /* Remained place in Line */
if (fOneLiner)
emptyColumns+=2;
/* >>Choose in Set A or B */
/* (C is changed as an option later on) */
@ -255,9 +251,9 @@ static int Columns2Rows(CharacterSetTable *T, unsigned char *data, const size_t
/* Test if numeric after one isn't better.*/
runChar=charCur;
emptyColumns2=emptyColumns;
while (T[runChar].CharacterSet==ZTFNC1)
while (T[runChar].CharacterSet==ZTFNC1) /* FNC1s (GS1) not used */
{
++runChar;
++runChar; /* Not reached */
--emptyColumns2;
}
if (CPaires>=RemainingDigits(T,runChar+1,emptyColumns2-1))
@ -265,7 +261,7 @@ static int Columns2Rows(CharacterSetTable *T, unsigned char *data, const size_t
/* Start odd is not better */
/* We start in C */
pSet[charCur]=characterSetCur=CodeC;
/* Inkrement charCur */
/* Increment charCur */
if (T[charCur].CharacterSet!=ZTFNC1)
++charCur; /* 2 Num.Digits */
}
@ -276,6 +272,7 @@ static int Columns2Rows(CharacterSetTable *T, unsigned char *data, const size_t
/* >> Following characters */
while(emptyColumns>0 && charCur<dataLength)
{
isFNC4 = (T[charCur].CharacterSet & CodeFNC4);
switch(characterSetCur){
case CodeA:
case CodeB:
@ -295,18 +292,24 @@ static int Columns2Rows(CharacterSetTable *T, unsigned char *data, const size_t
emptyColumns-=2; /* <SwitchC>12 */
} else if (characterSetCur==CodeA)
{
if(T[charCur].AFollowing==0)
if (T[charCur].AFollowing == 0 || (isFNC4 && T[charCur].AFollowing == 1))
{
/* Must change to B */
if (emptyColumns==1)
if (emptyColumns == 1 || (isFNC4 && emptyColumns == 2))
{
/* Can't switch: */
pSet[charCur-1]|=CEnd+CFill;
emptyColumns=0;
}else{
/* <Shift> or <switchB>? */
if (T[charCur].BFollowing==1)
if (T[charCur].BFollowing == 1 || (isFNC4 && T[charCur].BFollowing == 2))
{
/* Note using order "FNC4 shift char" (same as CODE128) not "shift FNC4 char" as
given in Table B.1 and Table B.2 */
if (isFNC4) { /* So skip FNC4 and shift value instead */
--emptyColumns;
++charCur;
}
pSet[charCur]|=CShift;
} else {
pSet[charCur]|=CodeB;
@ -315,23 +318,33 @@ static int Columns2Rows(CharacterSetTable *T, unsigned char *data, const size_t
emptyColumns-=2;
++charCur;
}
} else if (isFNC4 && emptyColumns == 1) {
/* Can't fit extended ASCII on same line */
pSet[charCur-1]|=CEnd+CFill;
emptyColumns=0;
}else{
--emptyColumns;
++charCur;
}
} else { /* Last possibility : CodeB */
if(T[charCur].BFollowing==0)
if (T[charCur].BFollowing == 0 || (isFNC4 && T[charCur].BFollowing == 1))
{
/* Must change to A */
if (emptyColumns==1)
if (emptyColumns == 1 || (isFNC4 && emptyColumns == 2))
{
/* Can't switch: */
pSet[charCur-1]|=CEnd+CFill;
emptyColumns=0;
} else {
/* <Shift> or <switchA>? */
if (T[charCur].AFollowing==1)
if (T[charCur].AFollowing == 1 || (isFNC4 && T[charCur].AFollowing == 2))
{
/* Note using order "FNC4 shift char" (same as CODE128) not "shift FNC4 char" as
given in Table B.1 and Table B.2 */
if (isFNC4) { /* So skip FNC4 and shift value instead */
--emptyColumns;
++charCur;
}
pSet[charCur]|=CShift;
} else {
pSet[charCur]|=CodeA;
@ -340,6 +353,10 @@ static int Columns2Rows(CharacterSetTable *T, unsigned char *data, const size_t
emptyColumns-=2;
++charCur;
}
} else if (isFNC4 && emptyColumns == 1) {
/* Can't fit extended ASCII on same line */
pSet[charCur-1]|=CEnd+CFill;
emptyColumns=0;
}else{
--emptyColumns;
++charCur;
@ -374,32 +391,13 @@ static int Columns2Rows(CharacterSetTable *T, unsigned char *data, const size_t
/* > End of Codeline */
pSet[charCur-1]|=CEnd;
++rowsCur;
if ( fOneLiner)
{
if (charCur<dataLength)
{
/* One line not sufficiant */
fOneLiner=0;
/* Reset and Start again */
charCur=0;
rowsCur=0;
memset(pSet,0,dataLength*sizeof(int));
}else{
/* Calculate real Length of OneLiner */
/* This is -2 BASED !!! */
useColumns-=emptyColumns;
}
}
} while (charCur<dataLength); /* <= Data.Len-1 */
/* Place check characters C1,C2 */
if (fOneLiner)
fillings=0;
else{
/* Allow for check characters K1, K2 */
switch (emptyColumns) {
case 1:
pSet[charCur-1]|=CFill;
/* Glide in following block without break */
/* fall through */
case 0:
++rowsCur;
fillings=useColumns-2+emptyColumns;
@ -411,40 +409,39 @@ static int Columns2Rows(CharacterSetTable *T, unsigned char *data, const size_t
pSet[charCur-1]|=CFill;
fillings=emptyColumns-2;
}
}
if (rowsCur>44) {
++useColumns;
if (useColumns > 62) {
return ZINT_ERROR_TOO_LONG;
}
} else if (rowsCur == 1) {
rowsCur = 2;
fillings += useColumns;
}
} while(rowsCur>44);
#ifdef _DEBUG
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf(" -> out: rowsCur <%i>, useColumns <%i>, fillings <%i>\n",rowsCur,useColumns,fillings);
#endif
}
*pUseColumns=useColumns;
*pRows=rowsCur;
*pFillings=fillings;
return 0;
}
/* Find columns if row count is given.
*/
static int Rows2Columns(CharacterSetTable *T, unsigned char *data, const size_t dataLength,
static int Rows2Columns(struct zint_symbol *symbol, CharacterSetTable *T, const int dataLength,
int * pRows, int * pUseColumns, int * pSet, int * pFillings)
{
int errorCur;
int rowsCur;
int rowsRequested; /* Number of requested rows */
int backupRows = 0;
int columnsRequested; /* Number of requested columns (if any) */
int fillings;
int backupFillings = 0;
int useColumns;
int testColumns; /* To enter into Width2Rows */
int backupColumns = 0;
int fBackupOk = 0; /* The memorysed set is o.k. */
int testListSize = 0;
int pTestList[62];
int pTestList[62 + 1];
#ifndef _MSC_VER
int *pBackupSet[dataLength];
#else
@ -452,34 +449,35 @@ static int Rows2Columns(CharacterSetTable *T, unsigned char *data, const size_t
#endif
rowsRequested=*pRows;
columnsRequested = *pUseColumns >= 4 ? *pUseColumns : 0;
#ifdef _DEBUG
fprintf(stderr,"Optimizer : Searching <%i> rows\n",rowsRequested);
#endif
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Optimizer : Searching <%i> rows\n", rowsRequested);
}
if (rowsRequested==1)
/* OneLiners are self-calibrating */
testColumns=32767;
else {
if (columnsRequested) {
testColumns = columnsRequested;
} else {
/* First guess */
testColumns=dataLength/rowsRequested;
if (testColumns > 62)
testColumns = 62;
else if (testColumns < 1)
testColumns = 1;
else if (testColumns < 4)
testColumns = 4;
}
for (;;) {
int errorCur;
pTestList[testListSize] = testColumns;
testListSize++;
useColumns=testColumns; /* Make a copy because it may be modified */
errorCur = Columns2Rows(T, data, dataLength, &rowsCur, &useColumns, pSet, &fillings);
errorCur = Columns2Rows(symbol, T, dataLength, &rowsCur, &useColumns, pSet, &fillings);
if (errorCur != 0)
return errorCur;
if (rowsCur<=rowsRequested) {
/* Less or exactly line number found */
/* check if column count below already tested or Count = 1*/
int fInTestList = (rowsCur == 1 || testColumns == 1);
/* check if column count below already tested or at smallest/requested */
int fInTestList = (rowsCur == 2 || testColumns == 4 || testColumns == columnsRequested);
int posCur;
for (posCur = 0; posCur < testListSize && ! fInTestList; posCur++) {
if ( pTestList[posCur] == testColumns-1 )
@ -487,69 +485,41 @@ static int Rows2Columns(CharacterSetTable *T, unsigned char *data, const size_t
}
if (fInTestList) {
/* >> Smaller Width already tested
* if rowsCur=rowsRequested->Exit
* if rowsCur<rowsRequested and fillings>0
* -> New search for rowsRequested:=rowsCur
*/
if ( rowsCur == rowsRequested || fillings == 0 || testColumns == 1 ) {
if (rowsCur < rowsRequested) {
fillings += useColumns * (rowsRequested - rowsCur);
rowsCur = rowsRequested;
}
/* Exit with actual */
*pFillings=fillings;
*pRows=rowsCur;
*pUseColumns = useColumns;
return 0;
}
/* Search again for smaller Line number */
rowsRequested=rowsCur;
pTestList[0] = testColumns;
testListSize = 1;
}
/* > Test more rows (shorter CDB) */
fBackupOk=(rowsCur==rowsRequested);
memcpy(pBackupSet,pSet,dataLength*sizeof(int));
backupFillings=fillings;
backupColumns=useColumns;
backupRows=rowsCur;
--testColumns;
} else {
/* > To many rows */
int fInTestList = fBackupOk;
int posCur;
for (posCur = 0; posCur < testListSize && ! fInTestList; posCur++) {
if ( pTestList[posCur] == testColumns+1 )
fInTestList = 1;
}
if (fInTestList) {
/* The next less-rows (larger) code was
* already tested. So give the larger
* back.
*/
memcpy(pSet,pBackupSet,dataLength*sizeof(int));
*pFillings=backupFillings;
*pRows=backupRows;
*pUseColumns=backupColumns;
return 0;
}
/* > Too many rows */
/* > Test less rows (longer code) */
backupRows=rowsCur;
memcpy(pBackupSet,pSet,dataLength*sizeof(int));
backupFillings=fillings;
backupColumns=useColumns;
fBackupOk=0;
++testColumns;
if (++testColumns > 62) {
return ZINT_ERROR_TOO_LONG;
}
}
}
}
/* Print a character in character set A
*/
void A2C128_A(uchar **ppOutPos,uchar c)
static void A2C128_A(uchar **ppOutPos,uchar c)
{
uchar * pOutPos = *ppOutPos;
switch(c){
case aCodeB: *pOutPos=100; break;
case aFNC4: *pOutPos=101; break;
case aFNC1: *pOutPos=102; break;
case aFNC2: *pOutPos=97; break;
case aFNC1: *pOutPos=102; break; /* FNC1s (GS1) not used */ /* Not reached */
case aFNC2: *pOutPos=97; break; /* FNC2s (Message Append) not used */ /* Not reached */
case aFNC3: *pOutPos=96; break;
case aCodeC: *pOutPos=99; break;
case aShift: *pOutPos=98; break;
@ -563,14 +533,15 @@ void A2C128_A(uchar **ppOutPos,uchar c)
}
(*ppOutPos)++;
}
/* Output c in Set B
*/
void A2C128_B(uchar **ppOutPos,uchar c)
static void A2C128_B(uchar **ppOutPos,uchar c)
{
uchar * pOutPos = *ppOutPos;
switch(c){
case aFNC1: *pOutPos=102; break;
case aFNC2: *pOutPos=97; break;
case aFNC1: *pOutPos=102; break; /* FNC1s (GS1) not used */ /* Not reached */
case aFNC2: *pOutPos=97; break; /* FNC2s (Message Append) not used */ /* Not reached */
case aFNC3: *pOutPos=96; break;
case aFNC4: *pOutPos=100; break;
case aCodeA: *pOutPos=101; break;
@ -580,22 +551,24 @@ void A2C128_B(uchar **ppOutPos,uchar c)
}
++(*ppOutPos);
}
/* Output c1, c2 in Set C
*/
void A2C128_C(uchar **ppOutPos,uchar c1,uchar c2)
static void A2C128_C(uchar **ppOutPos,uchar c1,uchar c2)
{
uchar * pOutPos = *ppOutPos;
switch(c1){
case aFNC1: *pOutPos=102; break;
case aFNC1: *pOutPos=102; break; /* FNC1s (GS1) not used */ /* Not reached */
case aCodeB: *pOutPos=100; break;
case aCodeA: *pOutPos=101; break;
default: *pOutPos=(char)(10 * (c1- '0') + (c2 - '0'));break;
}
(*ppOutPos)++;
}
/* Output a character in Characterset
*/
void ASCIIZ128(uchar **ppOutPos, int CharacterSet,uchar c1, uchar c2)
static void ASCIIZ128(uchar **ppOutPos, int CharacterSet,uchar c1, uchar c2)
{
if (CharacterSet==CodeA)
A2C128_A(ppOutPos,c1);
@ -604,14 +577,13 @@ void ASCIIZ128(uchar **ppOutPos, int CharacterSet,uchar c1, uchar c2)
else
A2C128_C(ppOutPos,c1,c2);
}
/* XLate Table A of Codablock-F Specification and call output
/* XLate Tables D.2, D.3 and F.1 of Codablock-F Specification and call output
*/
void SumASCII(uchar **ppOutPos, int Sum, int CharacterSet)
static void SumASCII(uchar **ppOutPos, int Sum, int CharacterSet)
{
switch (CharacterSet){
case CodeA:
A2C128_A(ppOutPos, (uchar)Sum);
break;
case CodeA: /* Row # Indicators and Data Check Characters K1/K2 for CodeA and CodeB are the same */
case CodeB:
if (Sum<=31)
A2C128_B(ppOutPos, (uchar)(Sum+96));
@ -629,9 +601,9 @@ void SumASCII(uchar **ppOutPos, int Sum, int CharacterSet)
/* Main function called by zint framework
*/
int codablock(struct zint_symbol *symbol,const unsigned char source[], const size_t length) {
size_t charCur,dataLength;
int Error;
INTERNAL int codablock(struct zint_symbol *symbol, unsigned char source[], int length) {
int charCur, dataLength;
int error_number;
int rows, columns, useColumns;
int fillings;
int Sum1,Sum2;
@ -641,31 +613,48 @@ int codablock(struct zint_symbol *symbol,const unsigned char source[], const siz
int emptyColumns;
char dest[1000];
int r, c;
float min_row_height = 0.0f;
#ifdef _MSC_VER
CharacterSetTable *T;
unsigned char *data;
int *pSet;
uchar * pOutput;
#endif
/* Suppresses clang-analyzer-core.VLASize warning */
assert(length > 0);
/* Parameter check */
/* option1: rows 0: automatic, 1..44 */
/* option1: rows <= 0: automatic, 1..44 */
rows = symbol->option_1;
if (rows == 1) {
error_number = code_128(symbol, source, length); /* Only returns errors, not warnings */
if (error_number < ZINT_ERROR) {
symbol->output_options |= BARCODE_BIND;
if (symbol->border_width == 0) { /* Allow override if non-zero */
symbol->border_width = 1; /* AIM ISS-X-24 Section 4.6.1 b) (note change from previous default 2) */
}
symbol->text[0] = '\0'; /* Disable HRT for compatibility with CODABLOCKF */
#ifdef COMPLIANT_HEIGHTS
/* AIM ISS-X-24 Section 4.5.1 minimum row height 8 (for compatibility with CODABLOCKF, not specced for
CODE128) */
error_number = set_height(symbol, 8.0f, 10.0f, 0.0f, 0 /*no_errtxt*/);
#else
(void) set_height(symbol, 0.0f, 5.0f, 0.0f, 1 /*no_errtxt*/);
#endif
}
return error_number;
}
if (rows > 44) {
strcpy(symbol->errtxt, "410: Row parameter not in 0..44");
strcpy(symbol->errtxt, "410: Rows parameter not in 0..44");
return ZINT_ERROR_INVALID_OPTION;
}
/* option_2: (usable data) columns: 0: automatic, 6..66 */
/* option_2: (usable data) columns: <= 0: automatic, 9..67 (min 9 == 4 data, max 67 == 62 data) */
columns = symbol->option_2;
if ( ! (columns <= 0 || (columns >= 6 && columns <=66)) ) {
strcpy(symbol->errtxt, "411: Columns parameter not in 0,6..66");
return ZINT_ERROR_INVALID_OPTION;
}
/* GS1 not implemented */
if (symbol->input_mode == GS1_MODE) {
strcpy(symbol->errtxt, "412: GS1 mode not supported");
if ( ! (columns <= 0 || (columns >= 9 && columns <= 67)) ) {
strcpy(symbol->errtxt, "411: Columns parameter not in 0, 9..67");
return ZINT_ERROR_INVALID_OPTION;
}
#ifndef _MSC_VER
unsigned char data[length*2+1];
#else
@ -701,51 +690,46 @@ int codablock(struct zint_symbol *symbol,const unsigned char source[], const siz
/* Find final row and column count */
/* nor row nor column count given */
if ( rows <= 0 && columns <= 5 ) {
/* Use Code128 until reasonable size */
if (dataLength < 9) {
rows = 1;
} else {
if (rows <= 0 && columns <= 0) {
/* use 1/1 aspect/ratio Codablock */
columns = ((int)floor(sqrt(1.0*dataLength))+5);
if (columns > 64)
columns = 64;
#ifdef _DEBUG
columns = (int) floor(sqrt(dataLength)) + 5;
if (columns > 67) {
columns = 67;
} else if (columns < 9) {
columns = 9;
}
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Auto column count for %d characters:%d\n", dataLength, columns);
#endif
}
}
/* There are 5 Codewords for Organisation Start(2),row(1),CheckSum,Stop */
useColumns = columns - 5;
if ( rows > 0 ) {
/* row count given */
Error=Rows2Columns(T,data,dataLength,&rows,&useColumns,pSet,&fillings);
error_number = Rows2Columns(symbol, T, dataLength, &rows, &useColumns, pSet, &fillings);
} else {
/* column count given */
Error=Columns2Rows(T,data,dataLength,&rows,&useColumns,pSet,&fillings);
error_number = Columns2Rows(symbol, T, dataLength, &rows, &useColumns, pSet, &fillings);
}
if (Error != 0) {
strcpy(symbol->errtxt, "413: Data string to long");
return Error;
if (error_number != 0) {
strcpy(symbol->errtxt, "413: Data string too long");
return error_number;
}
/* Checksum */
/* Suppresses clang-analyzer-core.VLASize warning */
assert(rows >= 2 && useColumns >= 4);
/* Data Check Characters K1 and K2, Annex F */
Sum1 = Sum2 = 0;
if (rows>1)
{
size_t charCur;
for (charCur=0 ; charCur<dataLength ; charCur++) {
Sum1=(Sum1 + (charCur%86+1)*data[charCur])%86;
Sum2=(Sum2 + (charCur%86)*data[charCur])%86;
}
for (charCur = 0; charCur < length; charCur++) {
Sum1 = (Sum1 + (charCur + 1) * source[charCur]) % 86; /* Mod as we go along to avoid overflow */
Sum2 = (Sum2 + charCur * source[charCur]) % 86;
}
#ifdef _DEBUG
{ /* start a new level of local variables */
if (symbol->debug & ZINT_DEBUG_PRINT) { /* start a new level of local variables */
int DPos;
printf("\nData:");
for (DPos=0 ; DPos< dataLength ; DPos++)
fputc(data[DPos],stdout);
printf("\n Set:");
for (DPos=0 ; DPos< dataLength ; DPos++) {
switch (pSet[DPos]&(CodeA+CodeB+CodeC)) {
@ -768,8 +752,8 @@ int codablock(struct zint_symbol *symbol,const unsigned char source[], const siz
for (DPos=0 ; DPos< dataLength ; DPos++)
fputc((pSet[DPos]&CFill)==0?'.':'X',stdout);
fputc('\n',stdout);
printf("K1 %d, K2 %d\n", Sum1, Sum2);
}
#endif
columns = useColumns + 5;
@ -778,7 +762,7 @@ int codablock(struct zint_symbol *symbol,const unsigned char source[], const siz
#ifndef _MSC_VER
uchar pOutput[columns * rows];
#else
pOutput = (unsigned char *)_alloca(columns * rows * sizeof(char));
pOutput = (unsigned char *) _alloca(columns * rows);
#endif
pOutPos = pOutput;
charCur=0;
@ -786,15 +770,17 @@ int codablock(struct zint_symbol *symbol,const unsigned char source[], const siz
for (rowCur=0 ; rowCur<rows ; rowCur++) {
if (charCur>=dataLength)
{
/* >> Empty line with StartCCodeBCodeC */
characterSetCur=CodeC;
/* CDB Start C*/
/* >> Empty line with StartA, aCodeB, row #, and then filler aCodeC aCodeB etc */
*pOutPos='\x67';
pOutPos++;
*pOutPos='\x63';
*pOutPos = 100; /* aCodeB */
pOutPos++;
SumASCII(&pOutPos,rowCur+42,CodeC);
emptyColumns=useColumns-2;
characterSetCur = CodeB;
SumASCII(&pOutPos, rowCur + 42, characterSetCur); /* Row # */
emptyColumns = useColumns;
if (rowCur == rows - 1) {
emptyColumns -= 2;
}
while (emptyColumns>0)
{
if(characterSetCur==CodeC)
@ -814,60 +800,36 @@ int codablock(struct zint_symbol *symbol,const unsigned char source[], const siz
case CodeA:
*pOutPos = '\x67';
pOutPos++;
if (rows>1) {
*pOutPos = '\x62';
pOutPos++;
}
characterSetCur=CodeA;
break;
case CodeB:
if (rows==1) {
*pOutPos = '\x68';
pOutPos++;
} else {
*pOutPos = '\x67';
pOutPos++;
*pOutPos = '\x64';
pOutPos++;
}
characterSetCur=CodeB;
break;
case CodeC:
default:
if (rows==1) {
*pOutPos = '\x69';
pOutPos++;
} else {
*pOutPos = '\x67';
pOutPos++;
*pOutPos = '\x63';
pOutPos++;
}
characterSetCur=CodeC;
break;
}
if (rows>1)
{
/* > Set F1 */
/* In first line : # of rows */
/* In Case of CodeA we shifted to CodeB */
SumASCII(&pOutPos
,(rowCur==0)?rows-2:rowCur+42
,(characterSetCur==CodeA)?CodeB:characterSetCur
);
}
SumASCII(&pOutPos, rowCur == 0 ? rows - 2 : rowCur + 42, characterSetCur);
/* >>> Data */
emptyColumns=useColumns;
/* +++ One liner don't have start/stop code */
if (rows == 1)
emptyColumns +=2;
/* >> Character loop */
while (emptyColumns>0)
while (emptyColumns > 0 && charCur < dataLength)
{
/* ? Change character set */
/* not at first possition (It was then the start set) */
/* +++ special case for one-ligner */
if (emptyColumns<useColumns || (rows == 1 && charCur!=0) )
if (emptyColumns < useColumns)
{
if ((pSet[charCur]&CodeA)!=0)
{
@ -901,11 +863,12 @@ int codablock(struct zint_symbol *symbol,const unsigned char source[], const siz
/* Normal Character */
if (characterSetCur==CodeC)
{
if (data[charCur]==aFNC1)
A2C128_C(&pOutPos,aFNC1,'\0');
if (data[charCur]==aFNC1) /* FNC1s (GS1) not used */
A2C128_C(&pOutPos,aFNC1,'\0'); /* Not reached */
else
{
A2C128_C(&pOutPos,data[charCur],data[charCur+1]);
A2C128_C(&pOutPos, data[charCur],
(uchar) (charCur + 1 < dataLength ? data[charCur + 1] : 0));
++charCur;
/* We need this here to get the good index */
/* for the termination flags in Set. */
@ -915,11 +878,12 @@ int codablock(struct zint_symbol *symbol,const unsigned char source[], const siz
--emptyColumns;
}
/* >> End Criteria */
if ((pSet[charCur] & CFill)!=0)
if ((pSet[charCur] & CFill) || (pSet[charCur] & CEnd))
{
/* Fill Line but leave space for checks in last line */
if(rowCur==rows-1 && emptyColumns>=2)
if (rowCur == rows - 1) {
emptyColumns -= 2;
}
while(emptyColumns>0)
{
switch(characterSetCur){
@ -939,27 +903,23 @@ int codablock(struct zint_symbol *symbol,const unsigned char source[], const siz
--emptyColumns;
}
}
if ((pSet[charCur] & CEnd)!=0)
emptyColumns=0;
++charCur;
} /* Loop over characters */
} /* if filling-Line / normal */
/* Add checksum in last line */
if(rows>1 && rowCur==rows-1)
if (rowCur == rows - 1)
{
SumASCII(&pOutPos,Sum1,characterSetCur);
SumASCII(&pOutPos,Sum2,characterSetCur);
}
/* Add Code 128 checksum */
{
int Sum=0;
int Pos=0;
int Sum = pOutput[columns * rowCur] % 103;
int Pos = 1;
for ( ; Pos < useColumns+3 ; Pos++)
{
Sum = (Sum +
((Pos==0?1:Pos) * pOutput[columns*rowCur+Pos]) % 103
) % 103;
Sum = (Sum + pOutput[columns * rowCur + Pos] * Pos) % 103;
}
*pOutPos=(uchar)Sum;
pOutPos++;
@ -969,7 +929,7 @@ int codablock(struct zint_symbol *symbol,const unsigned char source[], const siz
pOutPos++;
} /* End Lineloop */
#ifdef _DEBUG
if (symbol->debug & ZINT_DEBUG_PRINT) {
/* Dump the output to the screen
*/
printf("\nCode 128 Code Numbers:\n");
@ -985,6 +945,11 @@ int codablock(struct zint_symbol *symbol,const unsigned char source[], const siz
}
}
printf("rows=%i columns=%i fillings=%i\n", rows, columns, fillings);
}
#ifdef ZINT_TEST
if (symbol->debug & ZINT_DEBUG_TEST) {
debug_test_codeword_dump(symbol, pOutput, rows * columns);
}
#endif
/* Paint the C128 patterns */
@ -994,15 +959,25 @@ int codablock(struct zint_symbol *symbol,const unsigned char source[], const siz
strcat(dest, C128Table[pOutput[r * columns + c]]);
}
expand(symbol, dest);
symbol->row_height[r] = 10;
}
if (!(symbol->output_options & BARCODE_BIND)) {
symbol->output_options += BARCODE_BIND;
#ifdef COMPLIANT_HEIGHTS
/* AIM ISS-X-24 Section 4.6.1 minimum row height; use 10 * rows as default for back-compatibility */
min_row_height = (float) (0.55 * useColumns + 3.0);
if (min_row_height < 8.0f) {
min_row_height = 8.0f;
}
error_number = set_height(symbol, min_row_height, (min_row_height > 10.0f ? min_row_height : 10.0f) * rows, 0.0f,
0 /*no_errtxt*/);
#else
(void) set_height(symbol, min_row_height, 10.0f * rows, 0.0f, 1 /*no_errtxt*/);
#endif
symbol->output_options |= BARCODE_BIND;
if (symbol->border_width == 0) { /* Allow override if non-zero */
symbol->border_width = 1; /* AIM ISS-X-24 Section 4.6.1 b) (note change from previous default 2) */
}
if (symbol->border_width < 2) {
symbol->border_width = 2;
}
return 0;
return error_number;
}

837
3rdparty/zint-2.10.0/backend/code.c vendored Normal file
View File

@ -0,0 +1,837 @@
/* code.c - Handles Code 11, 39, 39+, 93, PZN, Channel and VIN */
/* LOGMARS MIL-STD-1189 Rev. B https://apps.dtic.mil/dtic/tr/fulltext/u2/a473534.pdf */
/* PZN https://www.ifaffm.de/mandanten/1/documents/04_ifa_coding_system/IFA_Info_Code_39_EN.pdf */
/* PZN https://www.ifaffm.de/mandanten/1/documents/04_ifa_coding_system/IFA-Info_Check_Digit_Calculations_PZN_PPN_UDI_EN.pdf */
/*
libzint - the open source barcode library
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
/* In version 0.5 this file was 1,553 lines long! */
#include <stdio.h>
#include <assert.h>
#include "common.h"
#define SODIUM "0123456789-"
#define SILVER "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%abcd"
#define ARSENIC "0123456789ABCDEFGHJKLMNPRSTUVWXYZ"
static const char *C11Table[11] = {
"111121", "211121", "121121", "221111", "112121", "212111", "122111",
"111221", "211211", "211111", "112111"
};
/* Code 39 tables checked against ISO/IEC 16388:2007 */
/* Incorporates Table A1 */
static const char *C39Table[43] = {
/* Code 39 character assignments (Table 1) */
"1112212111", "2112111121", "1122111121", "2122111111", "1112211121",
"2112211111", "1122211111", "1112112121", "2112112111", "1122112111", "2111121121",
"1121121121", "2121121111", "1111221121", "2111221111", "1121221111", "1111122121",
"2111122111", "1121122111", "1111222111", "2111111221", "1121111221", "2121111211",
"1111211221", "2111211211", "1121211211", "1111112221", "2111112211", "1121112211",
"1111212211", "2211111121", "1221111121", "2221111111", "1211211121", "2211211111",
"1221211111", "1211112121", "2211112111", "1221112111", "1212121111", "1212111211",
"1211121211", "1112121211"
};
static const char *EC39Ctrl[128] = {
/* Encoding the full ASCII character set in Code 39 (Table A2) */
"%U", "$A", "$B", "$C", "$D", "$E", "$F", "$G", "$H", "$I", "$J", "$K",
"$L", "$M", "$N", "$O", "$P", "$Q", "$R", "$S", "$T", "$U", "$V", "$W", "$X", "$Y", "$Z",
"%A", "%B", "%C", "%D", "%E", " ", "/A", "/B", "/C", "/D", "/E", "/F", "/G", "/H", "/I", "/J",
"/K", "/L", "-", ".", "/O", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "/Z", "%F",
"%G", "%H", "%I", "%J", "%V", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "%K", "%L", "%M", "%N", "%O",
"%W", "+A", "+B", "+C", "+D", "+E", "+F", "+G", "+H", "+I", "+J", "+K", "+L", "+M", "+N", "+O",
"+P", "+Q", "+R", "+S", "+T", "+U", "+V", "+W", "+X", "+Y", "+Z", "%P", "%Q", "%R", "%S", "%T"
};
static const char *C93Ctrl[128] = {
"bU", "aA", "aB", "aC", "aD", "aE", "aF", "aG", "aH", "aI", "aJ", "aK",
"aL", "aM", "aN", "aO", "aP", "aQ", "aR", "aS", "aT", "aU", "aV", "aW", "aX", "aY", "aZ",
"bA", "bB", "bC", "bD", "bE", " ", "cA", "cB", "cC", "$", "%", "cF", "cG", "cH", "cI", "cJ",
"+", "cL", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "cZ", "bF",
"bG", "bH", "bI", "bJ", "bV", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bK", "bL", "bM", "bN", "bO",
"bW", "dA", "dB", "dC", "dD", "dE", "dF", "dG", "dH", "dI", "dJ", "dK", "dL", "dM", "dN", "dO",
"dP", "dQ", "dR", "dS", "dT", "dU", "dV", "dW", "dX", "dY", "dZ", "bP", "bQ", "bR", "bS", "bT"
};
static const char *C93Table[47] = {
"131112", "111213", "111312", "111411", "121113", "121212", "121311",
"111114", "131211", "141111", "211113", "211212", "211311", "221112", "221211", "231111",
"112113", "112212", "112311", "122112", "132111", "111123", "111222", "111321", "121122",
"131121", "212112", "212211", "211122", "211221", "221121", "222111", "112122", "112221",
"122121", "123111", "121131", "311112", "311211", "321111", "112131", "113121", "211131",
"121221", "312111", "311121", "122211"
};
/* *********************** CODE 11 ******************** */
INTERNAL int code_11(struct zint_symbol *symbol, unsigned char source[], int length) { /* Code 11 */
int i;
int h, c_digit, c_weight, c_count, k_digit, k_weight, k_count;
int weight[122], error_number;
char dest[750]; /* 6 + 121 * 6 + 2 * 6 + 5 + 1 == 750 */
char checkstr[3];
int num_check_digits;
/* Suppresses clang-tidy clang-analyzer-core.UndefinedBinaryOperatorResult warning */
assert(length > 0);
if (length > 121) {
strcpy(symbol->errtxt, "320: Input too long (121 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(SODIUM, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "321: Invalid character in data (digits and \"-\" only)");
return error_number;
}
if (symbol->option_2 < 0 || symbol->option_2 > 2) {
strcpy(symbol->errtxt, "339: Invalid check digit version (1, 2 only)");
return ZINT_ERROR_INVALID_OPTION;
}
if (symbol->option_2 == 2) {
num_check_digits = 0;
} else if (symbol->option_2 == 1) {
num_check_digits = 1;
} else {
num_check_digits = 2;
}
c_weight = 1;
c_count = 0;
k_weight = 1;
k_count = 0;
/* start character */
strcpy(dest, "112211");
/* Draw main body of barcode */
for (i = 0; i < length; i++) {
lookup(SODIUM, C11Table, source[i], dest);
if (source[i] == '-')
weight[i] = 10;
else
weight[i] = ctoi(source[i]);
}
if (num_check_digits) {
/* Calculate C checksum */
for (h = length - 1; h >= 0; h--) {
c_count += (c_weight * weight[h]);
c_weight++;
if (c_weight > 10) {
c_weight = 1;
}
}
c_digit = c_count % 11;
if (num_check_digits == 1) {
checkstr[0] = itoc(c_digit);
if (checkstr[0] == 'A') {
checkstr[0] = '-';
}
checkstr[1] = '\0';
lookup(SODIUM, C11Table, checkstr[0], dest);
} else {
weight[length] = c_digit;
/* Calculate K checksum */
for (h = length; h >= 0; h--) {
k_count += (k_weight * weight[h]);
k_weight++;
if (k_weight > 9) {
k_weight = 1;
}
}
k_digit = k_count % 11;
checkstr[0] = itoc(c_digit);
checkstr[1] = itoc(k_digit);
if (checkstr[0] == 'A') {
checkstr[0] = '-';
}
if (checkstr[1] == 'A') {
checkstr[1] = '-';
}
checkstr[2] = '\0';
lookup(SODIUM, C11Table, checkstr[0], dest);
lookup(SODIUM, C11Table, checkstr[1], dest);
}
}
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Check digit (%d): %s\n", num_check_digits, num_check_digits ? checkstr : "<none>");
}
/* Stop character */
strcat(dest, "11221");
expand(symbol, dest);
// TODO: Find documentation on BARCODE_CODE11 dimensions/height
ustrcpy(symbol->text, source);
if (num_check_digits) {
ustrcat(symbol->text, checkstr);
}
return error_number;
}
/* Code 39 */
INTERNAL int c39(struct zint_symbol *symbol, unsigned char source[], int length) {
int i;
int counter;
int error_number;
char dest[880]; /* 10 (Start) + 85 * 10 + 10 (Check) + 9 (Stop) + 1 = 880 */
char localstr[2] = {0};
float height;
counter = 0;
if ((symbol->option_2 < 0) || (symbol->option_2 > 1)) {
symbol->option_2 = 0;
}
if ((symbol->symbology == BARCODE_LOGMARS) && (length > 30)) { /* MIL-STD-1189 Rev. B Section 5.2.6.2 */
strcpy(symbol->errtxt, "322: Input too long (30 character maximum)");
return ZINT_ERROR_TOO_LONG;
/* Prevent encoded_data out-of-bounds >= 143 for BARCODE_HIBC_39 due to wider 'wide' bars */
} else if ((symbol->symbology == BARCODE_HIBC_39) && (length > 69)) {
/* Note use 319 (2of5 range) as 340 taken by CODE128 */
strcpy(symbol->errtxt, "319: Input too long (67 character maximum)"); /* 69 less '+' and check */
return ZINT_ERROR_TOO_LONG;
} else if (length > 85) {
strcpy(symbol->errtxt, "323: Input too long (85 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
to_upper(source);
error_number = is_sane(SILVER, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "324: Invalid character in data (alphanumerics, space and \"-.$/+%\" only)");
return error_number;
}
/* Start character */
strcpy(dest, "1211212111");
for (i = 0; i < length; i++) {
lookup(SILVER, C39Table, source[i], dest);
counter += posn(SILVER, source[i]);
}
if (symbol->option_2 == 1) {
char check_digit;
counter %= 43;
check_digit = SILVER[counter];
lookup(SILVER, C39Table, check_digit, dest);
/* Display a space check digit as _, otherwise it looks like an error */
if (check_digit == ' ') {
check_digit = '_';
}
localstr[0] = check_digit;
localstr[1] = '\0';
}
/* Stop character */
strcat(dest, "121121211");
if ((symbol->symbology == BARCODE_LOGMARS) || (symbol->symbology == BARCODE_HIBC_39)) {
/* LOGMARS uses wider 'wide' bars than normal Code 39 */
counter = (int) strlen(dest);
for (i = 0; i < counter; i++) {
if (dest[i] == '2') {
dest[i] = '3';
}
}
}
if (symbol->debug) {
printf("Barspaces: %s\n", dest);
}
expand(symbol, dest);
#ifdef COMPLIANT_HEIGHTS
if (symbol->symbology == BARCODE_LOGMARS) {
/* MIL-STD-1189 Rev. B Section 5.2
Min height 0.25" / 0.04" (X max) = 6.25
Default height 0.625" (average of 0.375" - 0.875") / 0.01375" (average of 0.0075" - 0.02") ~ 45.45 */
height = (float) (0.625 / 0.01375);
error_number = set_height(symbol, 6.25f, height, (float) (0.875 / 0.0075), 0 /*no_errtxt*/);
} else if (symbol->symbology == BARCODE_CODE39 || symbol->symbology == BARCODE_EXCODE39
|| symbol->symbology == BARCODE_HIBC_39) {
/* ISO/IEC 16388:2007 4.4 (e) recommended min height 5.0mm or 15% of width excluding quiet zones;
as X left to application specification use
width = (C + 2) * (3 * N + 6) * X + (C + 1) * I = (C + 2) * 9 + C + 1) * X = (10 * C + 19) */
height = (float) ((10.0 * (symbol->option_2 == 1 ? length + 1 : length) + 19.0) * 0.15);
/* Using 50 as default as none recommended */
error_number = set_height(symbol, height, height > 50.0f ? height : 50.0f, 0.0f, 0 /*no_errtxt*/);
}
#else
height = 50.0f;
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->symbology == BARCODE_CODE39) {
ustrcpy(symbol->text, "*");
ustrncat(symbol->text, source, length);
ustrcat(symbol->text, localstr);
ustrcat(symbol->text, "*");
} else {
ustrcpy(symbol->text, source);
ustrcat(symbol->text, localstr);
}
return error_number;
}
/* Pharmazentral Nummer (PZN) */
INTERNAL int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number, zeroes;
unsigned int count, check_digit;
char localstr[11];
if (length > 7) {
strcpy(symbol->errtxt, "325: Input wrong length (7 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "326: Invalid character in data (digits only)");
return error_number;
}
localstr[0] = '-';
zeroes = 7 - length + 1;
for (i = 1; i < zeroes; i++)
localstr[i] = '0';
ustrcpy(localstr + zeroes, source);
count = 0;
for (i = 1; i < 8; i++) {
count += i * ctoi(localstr[i]);
}
check_digit = count % 11;
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("PZN: %s, check digit %d\n", localstr, (int) check_digit);
}
if (check_digit == 10) {
strcpy(symbol->errtxt, "327: Invalid PZN, check digit is '10'");
return ZINT_ERROR_INVALID_DATA;
}
localstr[8] = itoc(check_digit);
localstr[9] = '\0';
error_number = c39(symbol, (unsigned char *) localstr, 9);
ustrcpy(symbol->text, "PZN ");
ustrcat(symbol->text, localstr);
#ifdef COMPLIANT_HEIGHTS
/* Technical Information regarding PZN Coding V 2.1 (25 Feb 2019) Code size
https://www.ifaffm.de/mandanten/1/documents/04_ifa_coding_system/IFA_Info_Code_39_EN.pdf
"normal" X 0.25mm (0.187mm - 0.45mm), height 8mm - 20mm for 0.25mm X, 10mm mentioned so use that as default,
10mm / 0.25mm = 40 */
if (error_number < ZINT_ERROR) {
error_number = set_height(symbol, (float) (8.0 / 0.45), 40.0f, (float) (20.0 / 0.187), 0 /*no_errtxt*/);
}
#else
if (error_number < ZINT_ERROR) {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
#endif
return error_number;
}
/* Extended Code 39 - ISO/IEC 16388:2007 Annex A */
INTERNAL int ec39(struct zint_symbol *symbol, unsigned char source[], int length) {
unsigned char buffer[85 * 2 + 1] = {0};
int i;
int error_number;
if (length > 85) {
strcpy(symbol->errtxt, "328: Input too long (85 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
/* Creates a buffer string and places control characters into it */
for (i = 0; i < length; i++) {
if (source[i] > 127) {
/* Cannot encode extended ASCII */
strcpy(symbol->errtxt, "329: Invalid character in data, extended ASCII not allowed");
return ZINT_ERROR_INVALID_DATA;
}
ustrcat(buffer, EC39Ctrl[source[i]]);
}
/* Then sends the buffer to the C39 function */
error_number = c39(symbol, buffer, (int) ustrlen(buffer));
for (i = 0; i < length; i++)
symbol->text[i] = source[i] >= ' ' && source[i] != 0x7F ? source[i] : ' ';
symbol->text[length] = '\0';
return error_number;
}
/* Code 93 is an advancement on Code 39 and the definition is a lot tighter */
INTERNAL int c93(struct zint_symbol *symbol, unsigned char source[], int length) {
/* SILVER includes the extra characters a, b, c and d to represent Code 93 specific
shift characters 1, 2, 3 and 4 respectively. These characters are never used by
c39() and ec39() */
int i;
int h, weight, c, k, values[128], error_number = 0;
char buffer[220];
char dest[670];
char set_copy[] = SILVER;
float height;
strcpy(buffer, "");
if (length > 107) {
strcpy(symbol->errtxt, "330: Input too long (107 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
/* Message Content */
for (i = 0; i < length; i++) {
if (source[i] > 127) {
/* Cannot encode extended ASCII */
strcpy(symbol->errtxt, "331: Invalid character in data, extended ASCII not allowed");
return ZINT_ERROR_INVALID_DATA;
}
strcat(buffer, C93Ctrl[source[i]]);
symbol->text[i] = source[i] >= ' ' && source[i] != 0x7F ? source[i] : ' ';
}
/* Now we can check the true length of the barcode */
h = (int) strlen(buffer);
if (h > 107) {
strcpy(symbol->errtxt, "332: Input too long"); // TODO: Better error message
return ZINT_ERROR_TOO_LONG;
}
for (i = 0; i < h; i++) {
values[i] = posn(SILVER, buffer[i]);
}
/* Putting the data into dest[] is not done until after check digits are calculated */
/* Check digit C */
c = 0;
weight = 1;
for (i = h - 1; i >= 0; i--) {
c += values[i] * weight;
weight++;
if (weight == 21)
weight = 1;
}
c = c % 47;
values[h] = c;
buffer[h] = set_copy[c];
/* Check digit K */
k = 0;
weight = 1;
for (i = h; i >= 0; i--) {
k += values[i] * weight;
weight++;
if (weight == 16)
weight = 1;
}
k = k % 47;
buffer[++h] = set_copy[k];
buffer[++h] = '\0';
/* Start character */
strcpy(dest, "111141");
for (i = 0; i < h; i++) {
lookup(SILVER, C93Table, buffer[i], dest);
}
/* Stop character */
strcat(dest, "1111411");
expand(symbol, dest);
#ifdef COMPLIANT_HEIGHTS
/* ANSI/AIM BC5-1995 Section 2.6 minimum height 0.2" or 15% of symbol length, whichever is greater
0.2" / 0.0075" (min X) = ~26.66; symbol length = (9 * (C + 4) + 1) * X + 2 * Q = symbol->width + 20 */
height = (float) ((symbol->width + 20) * 0.15);
if (height < 0.2f / 0.0075f) {
height = 0.2f / 0.0075f;
}
/* Using 50 as default for back-compatibility */
error_number = set_height(symbol, height, height > 50.0f ? height : 50.0f, 0.0f, 0 /*no_errtxt*/);
#else
height = 50.0f;
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
#endif
symbol->text[length] = set_copy[c];
symbol->text[length + 1] = set_copy[k];
symbol->text[length + 2] = '\0';
return error_number;
}
typedef const struct s_channel_precalc {
long value; unsigned char B[8]; unsigned char S[8]; unsigned char bmax[7]; unsigned char smax[7];
} channel_precalc;
//#define CHANNEL_GENERATE_PRECALCS
#ifdef CHANNEL_GENERATE_PRECALCS
/* To generate precalc tables uncomment CHANNEL_GENERATE_PRECALCS define and run "./test_channel -f generate -g" and
place result in "channel_precalcs.h" */
static void channel_generate_precalc(int channels, long value, int mod, int last, int B[8], int S[8], int bmax[7],
int smax[7]) {
int i;
if (value == mod) printf("static channel_precalc channel_precalcs%d[] = {\n", channels);
printf(" { %7ld, {", value); for (i = 0; i < 8; i++) printf(" %d,", B[i]); printf(" },");
printf(" {"); for (i = 0; i < 8; i++) printf(" %d,", S[i]); printf(" },");
printf(" {"); for (i = 0; i < 7; i++) printf(" %d,", bmax[i]); printf(" },");
printf(" {"); for (i = 0; i < 7; i++) printf(" %d,", smax[i]); printf(" }, },\n");
if (value == last) printf("};\n");
}
#else
#include "channel_precalcs.h"
#endif
static long channel_copy_precalc(channel_precalc precalc, int B[8], int S[8], int bmax[7], int smax[7]) {
int i;
for (i = 0; i < 7; i++) {
B[i] = precalc.B[i];
S[i] = precalc.S[i];
bmax[i] = precalc.bmax[i];
smax[i] = precalc.smax[i];
}
B[7] = precalc.B[7];
S[7] = precalc.S[7];
return precalc.value;
}
/* CHNCHR is adapted from ANSI/AIM BC12-1998 Annex D Figure D5 and is Copyright (c) AIM 1997 */
/* It is used here on the understanding that it forms part of the specification
for Channel Code and therefore its use is permitted under the following terms
set out in that document:
"It is the intent and understanding of AIM [t]hat the symbology presented in this
specification is entirely in the public domain and free of all use restrictions,
licenses and fees. AIM USA, its member companies, or individual officers
assume no liability for the use of this document." */
static void CHNCHR(int channels, long target_value, int B[8], int S[8]) {
/* Use of initial pre-calculations taken from Barcode Writer in Pure PostScript (BWIPP)
* Copyright (c) 2004-2020 Terry Burton (MIT/X-Consortium license) */
static channel_precalc initial_precalcs[6] = {
{ 0, { 1, 1, 1, 1, 1, 2, 1, 2, }, { 1, 1, 1, 1, 1, 1, 1, 3, }, { 1, 1, 1, 1, 1, 3, 2, }, { 1, 1, 1, 1, 1, 3, 3, }, },
{ 0, { 1, 1, 1, 1, 2, 1, 1, 3, }, { 1, 1, 1, 1, 1, 1, 1, 4, }, { 1, 1, 1, 1, 4, 3, 3, }, { 1, 1, 1, 1, 4, 4, 4, }, },
{ 0, { 1, 1, 1, 2, 1, 1, 2, 3, }, { 1, 1, 1, 1, 1, 1, 1, 5, }, { 1, 1, 1, 5, 4, 4, 4, }, { 1, 1, 1, 5, 5, 5, 5, }, },
{ 0, { 1, 1, 2, 1, 1, 2, 1, 4, }, { 1, 1, 1, 1, 1, 1, 1, 6, }, { 1, 1, 6, 5, 5, 5, 4, }, { 1, 1, 6, 6, 6, 6, 6, }, },
{ 0, { 1, 2, 1, 1, 2, 1, 1, 5, }, { 1, 1, 1, 1, 1, 1, 1, 7, }, { 1, 7, 6, 6, 6, 5, 5, }, { 1, 7, 7, 7, 7, 7, 7, }, },
{ 0, { 2, 1, 1, 2, 1, 1, 2, 5, }, { 1, 1, 1, 1, 1, 1, 1, 8, }, { 8, 7, 7, 7, 6, 6, 6, }, { 8, 8, 8, 8, 8, 8, 8, }, },
};
int bmax[7], smax[7];
long value = 0;
channel_copy_precalc(initial_precalcs[channels - 3], B, S, bmax, smax);
#ifndef CHANNEL_GENERATE_PRECALCS
if (channels == 7 && target_value >= channel_precalcs7[0].value) {
value = channel_copy_precalc(channel_precalcs7[(target_value / channel_precalcs7[0].value) - 1], B, S, bmax,
smax);
} else if (channels == 8 && target_value >= channel_precalcs8[0].value) {
value = channel_copy_precalc(channel_precalcs8[(target_value / channel_precalcs8[0].value) - 1], B, S, bmax,
smax);
}
#endif
goto chkchr;
ls0:smax[1] = smax[0] + 1 - S[0]; B[0] = 1;
if (S[0] == 1) goto nb0;
lb0: bmax[1] = bmax[0] + 1 - B[0]; S[1] = 1;
ls1: smax[2] = smax[1] + 1 - S[1]; B[1] = 1;
if (S[0] + B[0] + S[1] == 3) goto nb1;
lb1: bmax[2] = bmax[1] + 1 - B[1]; S[2] = 1;
ls2: smax[3] = smax[2] + 1 - S[2]; B[2] = 1;
if (B[0] + S[1] + B[1] + S[2] == 4) goto nb2;
lb2: bmax[3] = bmax[2] + 1 - B[2]; S[3] = 1;
ls3: smax[4] = smax[3] + 1 - S[3]; B[3] = 1;
if (B[1] + S[2] + B[2] + S[3] == 4) goto nb3;
lb3: bmax[4] = bmax[3] + 1 - B[3]; S[4] = 1;
ls4: smax[5] = smax[4] + 1 - S[4]; B[4] = 1;
if (B[2] + S[3] + B[3] + S[4] == 4) goto nb4;
lb4: bmax[5] = bmax[4] + 1 - B[4]; S[5] = 1;
ls5: smax[6] = smax[5] + 1 - S[5]; B[5] = 1;
if (B[3] + S[4] + B[4] + S[5] == 4) goto nb5;
lb5: bmax[6] = bmax[5] + 1 - B[5]; S[6] = 1;
ls6: S[7] = smax[6] + 1 - S[6]; B[6] = 1;
if (B[4] + S[5] + B[5] + S[6] == 4) goto nb6;
lb6: B[7] = bmax[6] + 1 - B[6];
if (B[5] + S[6] + B[6] + S[7] + B[7] == 5) goto nb6;
chkchr:
#ifdef CHANNEL_GENERATE_PRECALCS
/* 115338 == (576688 + 2) / 5 */
if (channels == 7 && value && value % 115338 == 0) {
channel_generate_precalc(channels, value, 115338,
115338 * (5 - 1), B, S, bmax, smax);
/* 119121 == (7742862 + 3) / 65 */
} else if (channels == 8 && value && value % 119121 == 0) {
channel_generate_precalc(channels, value, 119121,
119121 * (65 - 1), B, S, bmax, smax);
}
#endif
if (value == target_value) return;
value++;
nb6: if (++B[6] <= bmax[6]) goto lb6;
if (++S[6] <= smax[6]) goto ls6;
nb5: if (++B[5] <= bmax[5]) goto lb5;
if (++S[5] <= smax[5]) goto ls5;
nb4: if (++B[4] <= bmax[4]) goto lb4;
if (++S[4] <= smax[4]) goto ls4;
nb3: if (++B[3] <= bmax[3]) goto lb3;
if (++S[3] <= smax[3]) goto ls3;
nb2: if (++B[2] <= bmax[2]) goto lb2;
if (++S[2] <= smax[2]) goto ls2;
nb1: if (++B[1] <= bmax[1]) goto lb1;
if (++S[1] <= smax[1]) goto ls1;
nb0: if (++B[0] <= bmax[0]) goto lb0;
if (++S[0] <= smax[0]) goto ls0;
}
/* Channel Code - According to ANSI/AIM BC12-1998 */
INTERNAL int channel_code(struct zint_symbol *symbol, unsigned char source[], int length) {
static int max_ranges[] = { -1, -1, -1, 26, 292, 3493, 44072, 576688, 7742862 };
int S[8] = {0}, B[8] = {0};
long target_value = 0;
char pattern[30];
int channels, i;
int error_number, zeroes;
char hrt[9];
float height;
if (length > 7) {
strcpy(symbol->errtxt, "333: Input too long (7 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "334: Invalid character in data (digits only)");
return error_number;
}
if ((symbol->option_2 < 3) || (symbol->option_2 > 8)) {
channels = 0;
} else {
channels = symbol->option_2;
}
for (i = 0; i < length; i++) {
target_value *= 10;
target_value += ctoi((char) source[i]);
}
if (channels == 0) {
channels = length + 1;
if (target_value > 576688 && channels < 8) {
channels = 8;
} else if (target_value > 44072 && channels < 7) {
channels = 7;
} else if (target_value > 3493 && channels < 6) {
channels = 6;
} else if (target_value > 292 && channels < 5) {
channels = 5;
} else if (target_value > 26 && channels < 4) {
channels = 4;
}
}
if (channels == 2) {
channels = 3;
}
if (target_value > max_ranges[channels]) {
if (channels == 8) {
sprintf(symbol->errtxt, "305: Value out of range (0 to %d)", max_ranges[channels]);
} else {
sprintf(symbol->errtxt, "335: Value out of range (0 to %d) for %d channels",
max_ranges[channels], channels);
}
return ZINT_ERROR_INVALID_DATA;
}
CHNCHR(channels, target_value, B, S);
strcpy(pattern, "111111111"); /* Finder pattern */
for (i = 8 - channels; i < 8; i++) {
char part[3];
part[0] = itoc(S[i]);
part[1] = itoc(B[i]);
part[2] = '\0';
strcat(pattern, part);
}
zeroes = channels - 1 - length;
if (zeroes < 0) {
zeroes = 0;
}
memset(hrt, '0', zeroes);
ustrcpy(hrt + zeroes, source);
ustrcpy(symbol->text, hrt);
expand(symbol, pattern);
#ifdef COMPLIANT_HEIGHTS
/* ANSI/AIM BC12-1998 gives min height as 5mm or 15% of length but X left as application specification so use
15% of length where
length = (3 (quiet zones) + 9 (finder) + 4 * channels - 2) * X */
height = (float) ((10 + 4 * channels) * 0.15);
/* Using 50 as default for back-compatibility */
error_number = set_height(symbol, height > 50.0f ? height : 50.0f, height, 0.0f, 0 /*no_errtxt*/);
#else
height = 50.0f;
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
#endif
return error_number;
}
/* Vehicle Identification Number (VIN) */
INTERNAL int vin(struct zint_symbol *symbol, unsigned char source[], int length) {
/* This code verifies the check digit present in North American VIN codes */
char local_source[18];
char dest[200]; /* 10 + 10 + 17 * 10 + 9 + 1 = 200 */
char input_check;
char output_check;
int value[17];
int weight[17] = {8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2};
int sum;
int i;
// Check length
if (length != 17) {
strcpy(symbol->errtxt, "336: Input wrong length (17 characters required)");
return ZINT_ERROR_TOO_LONG;
}
// Check input characters, I, O and Q are not allowed
if (is_sane(ARSENIC, source, length) == ZINT_ERROR_INVALID_DATA) {
sprintf(symbol->errtxt, "337: Invalid character in data (\"%s\" only)", ARSENIC);
return ZINT_ERROR_INVALID_DATA;
}
ustrcpy(local_source, source);
to_upper((unsigned char *) local_source);
// Check digit only valid for North America
if (local_source[0] >= '1' && local_source[0] <= '5') {
input_check = local_source[8];
for (i = 0; i < 17; i++) {
if ((local_source[i] >= '0') && (local_source[i] <= '9')) {
value[i] = local_source[i] - '0';
} else if ((local_source[i] >= 'A') && (local_source[i] <= 'I')) {
value[i] = (local_source[i] - 'A') + 1;
} else if ((local_source[i] >= 'J') && (local_source[i] <= 'R')) {
value[i] = (local_source[i] - 'J') + 1;
} else if ((local_source[i] >= 'S') && (local_source[i] <= 'Z')) {
value[i] = (local_source[i] - 'S') + 2;
}
}
sum = 0;
for (i = 0; i < 17; i++) {
sum += value[i] * weight[i];
}
output_check = '0' + (sum % 11);
if (output_check == ':') {
// Check digit was 10
output_check = 'X';
}
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Producing VIN code: %s\n", local_source);
printf("Input check was %c, calculated check is %c\n", input_check, output_check);
}
if (input_check != output_check) {
sprintf(symbol->errtxt, "338: Invalid check digit '%c', expecting '%c'", input_check, output_check);
return ZINT_ERROR_INVALID_CHECK;
}
}
/* Start character */
strcpy(dest, "1211212111");
/* Import character 'I' prefix? */
if (symbol->option_2 & 1) {
strcat(dest, "1121122111");
}
// Copy glyphs to symbol
for (i = 0; i < 17; i++) {
lookup(SILVER, C39Table, local_source[i], dest);
}
strcat(dest, "121121211");
ustrcpy(symbol->text, local_source);
expand(symbol, dest);
/* Specification of dimensions/height for BARCODE_VIN unlikely */
return 0;
}

1472
3rdparty/zint-2.10.0/backend/code1.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,6 @@
/* large.h - Handles binary manipulation of large numbers */
/*
libzint - the open source barcode library
Copyright (C) 2008-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -29,22 +27,33 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#ifndef __LARGE_H
#define __LARGE_H
/* vim: set ts=4 sw=4 et : */
#ifndef CODE128_H
#define CODE128_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
extern void binary_load(short int reg[], char data[], const size_t src_len);
extern void binary_add(short int accumulator[], short int input_buffer[]);
extern void binary_subtract(short int accumulator[], short int input_buffer[]);
extern void shiftdown(short int buffer[]);
extern void shiftup(short int buffer[]);
extern short int islarger(short int accum[], short int reg[]);
#define C128_MAX 160
#define SHIFTA 90
#define LATCHA 91
#define SHIFTB 92
#define LATCHB 93
#define SHIFTC 94
#define LATCHC 95
#define AORB 96
#define ABORC 97
#define KRSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
INTERNAL int parunmodd(const unsigned char llyth);
INTERNAL void dxsmooth(int list[2][C128_MAX], int *indexliste);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __LARGE_H */
#endif /* CODE128_H */

View File

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -29,32 +29,16 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
/* Updated to comply with BS EN 12323:2005 */
/* Code 16k can hold up to 77 characters or 154 numbers */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "common.h"
#define TRUE 1
#define FALSE 0
#define SHIFTA 90
#define LATCHA 91
#define SHIFTB 92
#define LATCHB 93
#define SHIFTC 94
#define LATCHC 95
#define AORB 96
#define ABORC 97
#define CANDB 98
#define CANDBB 99
extern int parunmodd(const unsigned char llyth);
static int list[2][170];
#include "code128.h"
static const char *C16KTable[107] = {
/* EN 12323 Table 1 - "Code 16K" character encodations */
@ -88,141 +72,7 @@ static const int C16KStopValues[16] = {
0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3
};
static void grwp16(unsigned int *indexliste) {
int i, j;
/* bring together same type blocks */
if (*(indexliste) > 1) {
i = 1;
while(i < (int)*(indexliste)) {
if (list[1][i - 1] == list[1][i]) {
/* bring together */
list[0][i - 1] = list[0][i - 1] + list[0][i];
j = i + 1;
/* decreace the list */
while(j < (int)*(indexliste)) {
list[0][j - 1] = list[0][j];
list[1][j - 1] = list[1][j];
j++;
}
*(indexliste) = *(indexliste) - 1;
i--;
}
i++;
}
}
}
/* Implements rules from ISO 15417 Annex E */
static void dxsmooth16(unsigned int *indexliste) {
int i, current, last, next, length;
for(i = 0; i < (int)*(indexliste); i++) {
current = list[1][i];
length = list[0][i];
if (i != 0) {
last = list[1][i - 1];
} else {
last = FALSE;
}
if (i != *(indexliste) - 1) {
next = list[1][i + 1];
} else {
next = FALSE;
}
if (i == 0) {
/* first block */
if ((*(indexliste) == 1) && ((length == 2) && (current == ABORC))) {
/* Rule 1a */
list[1][i] = LATCHC;
}
if (current == ABORC) {
if (length >= 4) {
/* Rule 1b */
list[1][i] = LATCHC;
} else {
list[1][i] = AORB;
current = AORB;
}
}
if (current == SHIFTA) {
/* Rule 1c */
list[1][i] = LATCHA;
}
if ((current == AORB) && (next == SHIFTA)) {
/* Rule 1c */
list[1][i] = LATCHA;
current = LATCHA;
}
if (current == AORB) {
/* Rule 1d */
list[1][i] = LATCHB;
}
} else {
if ((current == ABORC) && (length >= 4)) {
/* Rule 3 */
list[1][i] = LATCHC;
current = LATCHC;
}
if (current == ABORC) {
list[1][i] = AORB;
current = AORB;
}
if ((current == AORB) && (last == LATCHA)) {
list[1][i] = LATCHA;
current = LATCHA;
}
if ((current == AORB) && (last == LATCHB)) {
list[1][i] = LATCHB;
current = LATCHB;
}
if ((current == AORB) && (next == SHIFTA)) {
list[1][i] = LATCHA;
current = LATCHA;
}
if ((current == AORB) && (next == SHIFTB)) {
list[1][i] = LATCHB;
current = LATCHB;
}
if (current == AORB) {
list[1][i] = LATCHB;
current = LATCHB;
}
if ((current == SHIFTA) && (length > 1)) {
/* Rule 4 */
list[1][i] = LATCHA;
current = LATCHA;
}
if ((current == SHIFTB) && (length > 1)) {
/* Rule 5 */
list[1][i] = LATCHB;
current = LATCHB;
}
if ((current == SHIFTA) && (last == LATCHA)) {
list[1][i] = LATCHA;
current = LATCHA;
}
if ((current == SHIFTB) && (last == LATCHB)) {
list[1][i] = LATCHB;
current = LATCHB;
}
if ((current == SHIFTA) && (last == LATCHC)) {
list[1][i] = LATCHA;
current = LATCHA;
}
if ((current == SHIFTB) && (last == LATCHC)) {
list[1][i] = LATCHB;
current = LATCHB;
}
} /* Rule 2 is implimented elsewhere, Rule 6 is implied */
}
grwp16(indexliste);
}
static void c16k_set_a(const unsigned char source, unsigned int values[], unsigned int *bar_chars) {
static void c16k_set_a(const unsigned char source, int values[], int *bar_chars) {
if (source > 127) {
if (source < 160) {
values[(*bar_chars)] = source + 64 - 128;
@ -239,7 +89,7 @@ static void c16k_set_a(const unsigned char source, unsigned int values[], unsign
(*bar_chars)++;
}
static void c16k_set_b(const unsigned char source, unsigned int values[], unsigned int *bar_chars) {
static void c16k_set_b(const unsigned char source, int values[], int *bar_chars) {
if (source > 127) {
values[(*bar_chars)] = source - 32 - 128;
} else {
@ -248,7 +98,7 @@ static void c16k_set_b(const unsigned char source, unsigned int values[], unsign
(*bar_chars)++;
}
static void c16k_set_c(const unsigned char source_a, unsigned char source_b, unsigned int values[], unsigned int *bar_chars) {
static void c16k_set_c(const unsigned char source_a, unsigned char source_b, int values[], int *bar_chars) {
int weight;
weight = (10 * ctoi(source_a)) + ctoi(source_b);
@ -256,30 +106,35 @@ static void c16k_set_c(const unsigned char source_a, unsigned char source_b, uns
(*bar_chars)++;
}
int code16k(struct zint_symbol *symbol, unsigned char source[], const size_t length) {
INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int length) {
char width_pattern[100];
int current_row, rows_needed, flip_flop, looper, first_check, second_check;
int indexchaine, f_state;
char set[160] = {' '}, fset[160] = {' '}, mode, last_set, current_set;
unsigned int pads_needed, indexliste, i, j, k, m, read, mx_reader, writer;
unsigned int values[160] = {0};
unsigned int bar_characters;
int current_row, rows, looper, first_check, second_check;
int indexchaine;
int list[2][C128_MAX] = {{0}};
char set[C128_MAX] = {0}, fset[C128_MAX], mode, last_set, current_set;
int pads_needed, indexliste, i, j, m, read, mx_reader;
int values[C128_MAX] = {0};
int bar_characters;
float glyph_count;
int errornum, first_sum, second_sum;
size_t input_length;
int error_number = 0, first_sum, second_sum;
int input_length;
int gs1, c_count;
int separator;
float min_row_height = 0.0f;
/* Suppresses clang-analyzer-core.UndefinedBinaryOperatorResult warning on fset which is fully set */
assert(length > 0);
errornum = 0;
strcpy(width_pattern, "");
input_length = length;
if (symbol->input_mode == GS1_MODE) {
if ((symbol->input_mode & 0x07) == GS1_MODE) {
gs1 = 1;
} else {
gs1 = 0;
}
if (input_length > 157) {
if (input_length > C128_MAX) {
strcpy(symbol->errtxt, "420: Input too long");
return ZINT_ERROR_TOO_LONG;
}
@ -287,61 +142,25 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], const size_t len
bar_characters = 0;
/* Detect extended ASCII characters */
for (i = 0; i < (unsigned int) input_length; i++) {
if (source[i] >= 128) {
fset[i] = 'f';
for (i = 0; i < input_length; i++) {
fset[i] = source[i] >= 128 ? 'f' : ' ';
}
}
fset[i] = '\0';
/* Note to be safe not using extended ASCII latch as not mentioned in BS EN 12323:2005 */
/* Decide when to latch to extended mode */
for (i = 0; i < (unsigned int) input_length; i++) {
j = 0;
if (fset[i] == 'f') {
do {
j++;
} while (fset[i + j] == 'f');
if ((j >= 5) || ((j >= 3) && ((i + j) == (input_length - 1)))) {
for (k = 0; k <= j; k++) {
fset[i + k] = 'F';
}
}
}
}
/* Decide if it is worth reverting to 646 encodation for a few characters */
if (input_length > 1) {
for (i = 1; i < (unsigned int) input_length; i++) {
if ((fset[i - 1] == 'F') && (fset[i] == ' ')) {
/* Detected a change from 8859-1 to 646 - count how long for */
for (j = 0; (fset[i + j] == ' ') && ((i + j) < (unsigned int) input_length); j++);
if ((j < 5) || ((j < 3) && ((i + j) == (input_length - 1)))) {
/* Change to shifting back rather than latching back */
for (k = 0; k < j; k++) {
fset[i + k] = 'n';
}
}
}
}
}
/* Detect mode A, B and C characters */
indexliste = 0;
indexchaine = 0;
mode = parunmodd(source[indexchaine]);
if ((gs1) && (source[indexchaine] == '[')) {
mode = ABORC;
} /* FNC1 */
for (i = 0; i < 160; i++) {
list[0][i] = 0;
}
do {
list[1][indexliste] = mode;
while ((list[1][indexliste] == mode) && (indexchaine < input_length)) {
list[0][indexliste]++;
indexchaine++;
if (indexchaine == input_length) {
break;
}
mode = parunmodd(source[indexchaine]);
if ((gs1) && (source[indexchaine] == '[')) {
mode = ABORC;
@ -350,7 +169,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], const size_t len
indexliste++;
} while (indexchaine < input_length);
dxsmooth16(&indexliste);
dxsmooth(list, &indexliste);
/* Put set data into set[] */
read = 0;
@ -372,23 +191,6 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], const size_t len
}
}
/* Adjust for strings which start with shift characters - make them latch instead */
if (set[0] == 'a') {
i = 0;
do {
set[i] = 'A';
i++;
} while (set[i] == 'a');
}
if (set[0] == 'b') {
i = 0;
do {
set[i] = 'B';
i++;
} while (set[i] == 'b');
}
/* Watch out for odd-length Mode C blocks */
c_count = 0;
for (i = 0; i < read; i++) {
@ -429,47 +231,43 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], const size_t len
}
}
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Data: %.*s\n", input_length, source);
printf(" Set: %.*s\n", input_length, set);
printf("FSet: %.*s\n", input_length, fset);
}
/* Make sure the data will fit in the symbol */
last_set = ' ';
glyph_count = 0.0;
last_set = set[0];
glyph_count = 0.0f;
for (i = 0; i < input_length; i++) {
if ((set[i] == 'a') || (set[i] == 'b')) {
glyph_count = glyph_count + 1.0;
glyph_count = glyph_count + 1.0f;
}
if ((fset[i] == 'f') || (fset[i] == 'n')) {
glyph_count = glyph_count + 1.0;
if (fset[i] == 'f') {
glyph_count = glyph_count + 1.0f;
}
if (((set[i] == 'A') || (set[i] == 'B')) || (set[i] == 'C')) {
if (set[i] != last_set) {
last_set = set[i];
glyph_count = glyph_count + 1.0;
glyph_count = glyph_count + 1.0f;
}
}
if (i == 0) {
if ((set[i] == 'B') && (set[1] == 'C')) {
glyph_count = glyph_count - 1.0;
glyph_count = glyph_count - 1.0f;
}
if ((set[i] == 'B') && (set[1] == 'B')) {
if (set[2] == 'C') {
glyph_count = glyph_count - 1.0;
glyph_count = glyph_count - 1.0f;
}
}
if (fset[i] == 'F') {
glyph_count = glyph_count + 2.0;
}
} else {
if ((fset[i] == 'F') && (fset[i - 1] != 'F')) {
glyph_count = glyph_count + 2.0;
}
if ((fset[i] != 'F') && (fset[i - 1] == 'F')) {
glyph_count = glyph_count + 2.0;
}
}
if ((set[i] == 'C') && (!((gs1) && (source[i] == '[')))) {
glyph_count = glyph_count + 0.5;
glyph_count = glyph_count + 0.5f;
} else {
glyph_count = glyph_count + 1.0;
glyph_count = glyph_count + 1.0f;
}
}
@ -478,21 +276,21 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], const size_t len
glyph_count--;
}
if (glyph_count > 77.0) {
if (glyph_count > 77.0f) {
strcpy(symbol->errtxt, "421: Input too long");
return ZINT_ERROR_TOO_LONG;
}
/* Calculate how tall the symbol will be */
glyph_count = glyph_count + 2.0;
glyph_count = glyph_count + 2.0f;
i = (int)glyph_count;
rows_needed = (i / 5);
rows = (i / 5);
if (i % 5 > 0) {
rows_needed++;
rows++;
}
if (rows_needed == 1) {
rows_needed = 2;
if (rows == 1) {
rows = 2;
}
/* start with the mode character - Table 2 */
@ -518,7 +316,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], const size_t len
m = 6;
}
}
values[bar_characters] = (7 * (rows_needed - 2)) + m; /* see 4.3.4.2 */
values[bar_characters] = (7 * (rows - 2)) + m; /* see 4.3.4.2 */
values[bar_characters + 1] = 96; /* FNC3 */
bar_characters += 2;
} else {
@ -538,29 +336,11 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], const size_t len
m = 6;
}
}
values[bar_characters] = (7 * (rows_needed - 2)) + m; /* see 4.3.4.2 */
values[bar_characters] = (7 * (rows - 2)) + m; /* see 4.3.4.2 */
bar_characters++;
}
current_set = set[0];
f_state = 0;
/* f_state remembers if we are in Extended ASCII mode (value 1) or
in ISO/IEC 646 mode (value 0) */
if (fset[0] == 'F') {
switch (current_set) {
case 'A':
values[bar_characters] = 101;
values[bar_characters + 1] = 101;
break;
case 'B':
values[bar_characters] = 100;
values[bar_characters + 1] = 100;
break;
}
bar_characters += 2;
f_state = 1;
}
read = 0;
/* Encode the data */
@ -593,40 +373,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], const size_t len
}
}
if (read != 0) {
if ((fset[read] == 'F') && (f_state == 0)) {
/* Latch beginning of extended mode */
switch (current_set) {
case 'A':
values[bar_characters] = 101;
values[bar_characters + 1] = 101;
break;
case 'B':
values[bar_characters] = 100;
values[bar_characters + 1] = 100;
break;
}
bar_characters += 2;
f_state = 1;
}
if ((fset[read] == ' ') && (f_state == 1)) {
/* Latch end of extended mode */
switch (current_set) {
case 'A':
values[bar_characters] = 101;
values[bar_characters + 1] = 101;
break;
case 'B':
values[bar_characters] = 100;
values[bar_characters + 1] = 100;
break;
}
bar_characters += 2;
f_state = 0;
}
}
if ((fset[i] == 'f') || (fset[i] == 'n')) {
if (fset[read] == 'f') {
/* Shift extended mode */
switch (current_set) {
case 'A':
@ -639,7 +386,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], const size_t len
bar_characters++;
}
if ((set[i] == 'a') || (set[i] == 'b')) {
if ((set[read] == 'a') || (set[read] == 'b')) {
/* Insert shift character */
values[bar_characters] = 98;
bar_characters++;
@ -666,7 +413,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], const size_t len
bar_characters++;
read++;
}
} while (read < ustrlen(source));
} while (read < input_length);
pads_needed = 5 - ((bar_characters + 2) % 5);
if (pads_needed == 5) {
@ -676,7 +423,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], const size_t len
pads_needed += 8 - (bar_characters + pads_needed);
}
for (i = 0; i < pads_needed; i++) {
values[bar_characters] = 106;
values[bar_characters] = 103;
bar_characters++;
}
@ -694,7 +441,23 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], const size_t len
values[bar_characters + 1] = second_check;
bar_characters += 2;
for (current_row = 0; current_row < rows_needed; current_row++) {
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Codewords:");
for (i = 0; i < bar_characters; i++) {
printf(" %d", values[i]);
}
printf("\n");
}
#ifdef ZINT_TEST
if (symbol->debug & ZINT_DEBUG_TEST) {
debug_test_codeword_dump_int(symbol, values, bar_characters); /* Missing row start/stop */
}
#endif
for (current_row = 0; current_row < rows; current_row++) {
int writer;
int flip_flop;
int len;
strcpy(width_pattern, "");
strcat(width_pattern, C16KStartStop[C16KStartValues[current_row]]);
@ -707,7 +470,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], const size_t len
/* Write the information into the symbol */
writer = 0;
flip_flop = 1;
for (mx_reader = 0; mx_reader < strlen(width_pattern); mx_reader++) {
for (mx_reader = 0, len = (int) strlen(width_pattern); mx_reader < len; mx_reader++) {
for (looper = 0; looper < ctoi(width_pattern[mx_reader]); looper++) {
if (flip_flop == 1) {
set_module(symbol, current_row, writer);
@ -722,12 +485,27 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], const size_t len
flip_flop = 0;
}
}
symbol->row_height[current_row] = 10;
}
symbol->rows = rows_needed;
symbol->rows = rows;
symbol->width = 70;
return errornum;
#ifdef COMPLIANT_HEIGHTS
separator = symbol->option_3 >= 1 && symbol->option_3 <= 4 ? symbol->option_3 : 1;
/* BS EN 12323:2005 Section 4.5 (d) minimum 8X; use 10 * rows as default for back-compatibility */
min_row_height = 8.0f + separator;
error_number = set_height(symbol, min_row_height, (min_row_height > 10.0f ? min_row_height : 10.0f) * rows, 0.0f,
0 /*no_errtxt*/);
#else
(void)&separator;
(void) set_height(symbol, min_row_height, 10.0f * rows, 0.0f, 1 /*no_errtxt*/);
#endif
symbol->output_options |= BARCODE_BIND;
if (symbol->border_width == 0) { /* Allow override if non-zero */
symbol->border_width = 1; /* BS EN 12323:2005 Section 4.3.7 minimum (note change from previous default 2) */
}
return error_number;
}

View File

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2009-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -29,10 +29,9 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "common.h"
#include "code49.h"
@ -40,7 +39,7 @@
/* "!" represents Shift 1 and "&" represents Shift 2, "*" represents FNC1 */
int code_49(struct zint_symbol *symbol, unsigned char source[], const int length) {
INTERNAL int code_49(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, j, rows, M, x_count, y_count, z_count, posn_val, local_value;
char intermediate[170] = "";
int codewords[170], codeword_count;
@ -49,13 +48,16 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], const int length
int pad_count = 0;
char pattern[80];
int gs1;
size_t h;
int h, len;
int separator;
float min_row_height = 0.0f;
int error_number = 0;
if (length > 81) {
strcpy(symbol->errtxt, "430: Input too long");
strcpy(symbol->errtxt, "430: Input too long (81 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
if (symbol->input_mode == GS1_MODE) {
if ((symbol->input_mode & 0x07) == GS1_MODE) {
gs1 = 1;
strcpy(intermediate, "*"); /* FNC1 */
} else {
@ -64,7 +66,7 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], const int length
for (i = 0; i < length; i++) {
if (source[i] > 127) {
strcpy(symbol->errtxt, "431: Invalid characters in input data");
strcpy(symbol->errtxt, "431: Invalid character in input data, extended ASCII not allowed");
return ZINT_ERROR_INVALID_DATA;
}
if (gs1 && (source[i] == '['))
@ -75,7 +77,7 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], const int length
codeword_count = 0;
i = 0;
h = strlen(intermediate);
h = (int) strlen(intermediate);
do {
if ((intermediate[i] >= '0') && (intermediate[i] <= '9')) {
/* Numeric data */
@ -298,6 +300,21 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], const int length
}
c_grid[rows - 1][7] = j % 49;
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Codewords:\n");
for (i = 0; i < rows; i++) {
for (j = 0; j < 8; j++) {
printf(" %2d", c_grid[i][j]);
}
printf("\n");
}
}
#ifdef ZINT_TEST
if (symbol->debug & ZINT_DEBUG_TEST) {
debug_test_codeword_dump_int(symbol, (int *)c_grid, rows * 8);
}
#endif
/* Transfer data to symbol character array (w grid) */
for (i = 0; i < rows; i++) {
for (j = 0; j < 4; j++) {
@ -324,9 +341,7 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], const int length
strcat(pattern, "1111"); /* Stop character */
/* Expand into symbol */
symbol->row_height[i] = 10;
for (j = 0; j < strlen(pattern); j++) {
for (j = 0, len = (int) strlen(pattern); j < len; j++) {
if (pattern[j] == '1') {
set_module(symbol, i, j);
}
@ -334,12 +349,24 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], const int length
}
symbol->rows = rows;
symbol->width = strlen(pattern);
symbol->whitespace_width = 10;
if (!(symbol->output_options & BARCODE_BIND)) {
symbol->output_options += BARCODE_BIND;
}
symbol->border_width = 2;
symbol->width = (int) strlen(pattern);
return 0;
#ifdef COMPLIANT_HEIGHTS
separator = symbol->option_3 >= 1 && symbol->option_3 <= 4 ? symbol->option_3 : 1;
/* ANSI/AIM BC6-2000 Section 2.6 minimum 8X; use 10 * rows as default for back-compatibility */
min_row_height = 8.0f + separator;
error_number = set_height(symbol, min_row_height, (min_row_height > 10.0f ? min_row_height : 10.0f) * rows, 0.0f,
0 /*no_errtxt*/);
#else
(void)&separator;
(void) set_height(symbol, min_row_height, 10.0f * rows, 0.0f, 1 /*no_errtxt*/);
#endif
symbol->output_options |= BARCODE_BIND;
if (symbol->border_width == 0) { /* Allow override if non-zero */
symbol->border_width = 1; /* ANSI/AIM BC6-2000 Section 2.1 (note change from previous default 2) */
}
return error_number;
}

518
3rdparty/zint-2.10.0/backend/common.c vendored Normal file
View File

@ -0,0 +1,518 @@
/* common.c - Contains functions needed for a number of barcodes */
/*
libzint - the open source barcode library
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#ifdef ZINT_TEST
#include <stdio.h>
#endif
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h"
/* Converts a character 0-9, A-F to its equivalent integer value */
INTERNAL int ctoi(const char source) {
if ((source >= '0') && (source <= '9'))
return (source - '0');
if ((source >= 'A') && (source <= 'F'))
return (source - 'A' + 10);
if ((source >= 'a') && (source <= 'f'))
return (source - 'a' + 10);
return -1;
}
/* Converts an integer value to its hexadecimal character */
INTERNAL char itoc(const int source) {
if ((source >= 0) && (source <= 9)) {
return ('0' + source);
} else {
return ('A' + (source - 10));
}
}
/* Converts decimal string of length <= 9 to integer value. Returns -1 if not numeric */
INTERNAL int to_int(const unsigned char source[], const int length) {
int val = 0;
int i;
for (i = 0; i < length; i++) {
if (source[i] < '0' || source[i] > '9') {
return -1;
}
val *= 10;
val += source[i] - '0';
}
return val;
}
/* Converts lower case characters to upper case in a string source[] */
INTERNAL void to_upper(unsigned char source[]) {
int i, src_len = (int) ustrlen(source);
for (i = 0; i < src_len; i++) {
if ((source[i] >= 'a') && (source[i] <= 'z')) {
source[i] = (source[i] - 'a') + 'A';
}
}
}
/* Returns the number of times a character occurs in a string */
INTERNAL int chr_cnt(const unsigned char string[], const int length, const unsigned char c) {
int count = 0;
int i;
for (i = 0; i < length; i++) {
if (string[i] == c) {
count++;
}
}
return count;
}
/* Verifies that a string only uses valid characters */
INTERNAL int is_sane(const char test_string[], const unsigned char source[], const int length) {
int i, j, lt = (int) strlen(test_string);
for (i = 0; i < length; i++) {
unsigned int latch = FALSE;
for (j = 0; j < lt; j++) {
if (source[i] == test_string[j]) {
latch = TRUE;
break;
}
}
if (!(latch)) {
return ZINT_ERROR_INVALID_DATA;
}
}
return 0;
}
/* Replaces huge switch statements for looking up in tables */
INTERNAL void lookup(const char set_string[], const char *table[], const char data, char dest[]) {
int i, n = (int) strlen(set_string);
for (i = 0; i < n; i++) {
if (data == set_string[i]) {
strcat(dest, table[i]);
break;
}
}
}
/* Convert an integer value to a string representing its binary equivalent */
INTERNAL void bin_append(const int arg, const int length, char *binary) {
int bin_posn = (int) strlen(binary);
bin_append_posn(arg, length, binary, bin_posn);
binary[bin_posn + length] = '\0';
}
/* Convert an integer value to a string representing its binary equivalent at a set position */
INTERNAL int bin_append_posn(const int arg, const int length, char *binary, const int bin_posn) {
int i;
int start;
start = 0x01 << (length - 1);
for (i = 0; i < length; i++) {
if (arg & (start >> i)) {
binary[bin_posn + i] = '1';
} else {
binary[bin_posn + i] = '0';
}
}
return bin_posn + length;
}
/* Returns the position of data in set_string */
INTERNAL int posn(const char set_string[], const char data) {
int i, n = (int) strlen(set_string);
for (i = 0; i < n; i++) {
if (data == set_string[i]) {
return i;
}
}
return -1;
}
#ifndef COMMON_INLINE
/* Return true (1) if a module is dark/black, otherwise false (0) */
INTERNAL int module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord) {
return (symbol->encoded_data[y_coord][x_coord >> 3] >> (x_coord & 0x07)) & 1;
}
/* Set a module to dark/black */
INTERNAL void set_module(struct zint_symbol *symbol, const int y_coord, const int x_coord) {
symbol->encoded_data[y_coord][x_coord >> 3] |= 1 << (x_coord & 0x07);
}
/* Return true (1-8) if a module is colour, otherwise false (0) */
INTERNAL int module_colour_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord) {
return symbol->encoded_data[y_coord][x_coord];
}
/* Set a module to a colour */
INTERNAL void set_module_colour(struct zint_symbol *symbol, const int y_coord, const int x_coord, const int colour) {
symbol->encoded_data[y_coord][x_coord] = colour;
}
#endif
/* Set a dark/black module to white (i.e. unset) */
INTERNAL void unset_module(struct zint_symbol *symbol, const int y_coord, const int x_coord) {
symbol->encoded_data[y_coord][x_coord >> 3] &= ~(1 << (x_coord & 0x07));
}
/* Expands from a width pattern to a bit pattern */
INTERNAL void expand(struct zint_symbol *symbol, const char data[]) {
int reader, n = (int) strlen(data);
int writer, i;
int latch, num;
writer = 0;
latch = 1;
for (reader = 0; reader < n; reader++) {
num = ctoi(data[reader]);
for (i = 0; i < num; i++) {
if (latch) {
set_module(symbol, symbol->rows, writer);
}
writer++;
}
latch = !latch;
}
if (symbol->symbology != BARCODE_PHARMA) {
if (writer > symbol->width) {
symbol->width = writer;
}
} else {
/* Pharmacode One ends with a space - adjust for this */
if (writer > symbol->width + 2) {
symbol->width = writer - 2;
}
}
symbol->rows = symbol->rows + 1;
}
/* Indicates which symbologies can have row binding */
INTERNAL int is_stackable(const int symbology) {
if (symbology < BARCODE_PHARMA_TWO && symbology != BARCODE_POSTNET) {
return 1;
}
switch (symbology) {
case BARCODE_CODE128B:
case BARCODE_ISBNX:
case BARCODE_EAN14:
case BARCODE_NVE18:
case BARCODE_KOREAPOST:
case BARCODE_PLESSEY:
case BARCODE_TELEPEN_NUM:
case BARCODE_ITF14:
case BARCODE_CODE32:
case BARCODE_CODABLOCKF:
case BARCODE_HIBC_BLOCKF:
return 1;
break;
}
return 0;
}
/* Indicates which symbols can have addon (EAN-2 and EAN-5) */
INTERNAL int is_extendable(const int symbology) {
switch (symbology) {
case BARCODE_EANX:
case BARCODE_EANX_CHK:
case BARCODE_UPCA:
case BARCODE_UPCA_CHK:
case BARCODE_UPCE:
case BARCODE_UPCE_CHK:
case BARCODE_ISBNX:
case BARCODE_EANX_CC:
case BARCODE_UPCA_CC:
case BARCODE_UPCE_CC:
return 1;
break;
}
return 0;
}
/* Indicates which symbols can have composite 2D component data */
INTERNAL int is_composite(const int symbology) {
return symbology >= BARCODE_EANX_CC && symbology <= BARCODE_DBAR_EXPSTK_CC;
}
/* Whether next two characters are digits */
INTERNAL int istwodigits(const unsigned char source[], const int length, const int position) {
if ((position + 1 < length) && (source[position] >= '0') && (source[position] <= '9')
&& (source[position + 1] >= '0') && (source[position + 1] <= '9')) {
return 1;
}
return 0;
}
/* State machine to decode UTF-8 to Unicode codepoints (state 0 means done, state 12 means error) */
INTERNAL unsigned int decode_utf8(unsigned int *state, unsigned int *codep, const unsigned char byte) {
/*
Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without
limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
See https://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
*/
static const unsigned char utf8d[] = {
/* The first part of the table maps bytes to character classes that
* reduce the size of the transition table and create bitmasks. */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8,
/* The second part is a transition table that maps a combination
* of a state of the automaton and a character class to a state. */
0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12,
12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12,
12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
12,36,12,12,12,12,12,12,12,12,12,12,
};
unsigned int type = utf8d[byte];
*codep = *state != 0 ? (byte & 0x3fu) | (*codep << 6) : (0xff >> type) & byte;
*state = utf8d[256 + *state + type];
return *state;
}
/* Is string valid UTF-8? */
INTERNAL int is_valid_utf8(const unsigned char source[], const int length) {
int i;
unsigned int codepoint, state = 0;
for (i = 0; i < length; i++) {
if (decode_utf8(&state, &codepoint, source[i]) == 12) {
return 0;
}
}
return state == 0;
}
/* Convert UTF-8 to Unicode. If `disallow_4byte` unset, allow all values (UTF-32). If `disallow_4byte` set,
* only allow codepoints <= U+FFFF (ie four-byte sequences not allowed) (UTF-16, no surrogates) */
INTERNAL int utf8_to_unicode(struct zint_symbol *symbol, const unsigned char source[], unsigned int vals[],
int *length, const int disallow_4byte) {
int bpos;
int jpos;
unsigned int codepoint, state = 0;
bpos = 0;
jpos = 0;
while (bpos < *length) {
do {
decode_utf8(&state, &codepoint, source[bpos++]);
} while (bpos < *length && state != 0 && state != 12);
if (state != 0) {
strcpy(symbol->errtxt, "240: Corrupt Unicode data");
return ZINT_ERROR_INVALID_DATA;
}
if (disallow_4byte && codepoint > 0xffff) {
strcpy(symbol->errtxt, "242: Unicode sequences of more than 3 bytes not supported");
return ZINT_ERROR_INVALID_DATA;
}
vals[jpos] = codepoint;
jpos++;
}
*length = jpos;
return 0;
}
/* Set symbol height, returning a warning if not within minimum and/or maximum if given.
`default_height` does not include height of fixed-height rows (i.e. separators/composite data) */
INTERNAL int set_height(struct zint_symbol *symbol, const float min_row_height, const float default_height,
const float max_height, const int no_errtxt) {
int error_number = 0;
float fixed_height = 0.0f;
int zero_count = 0;
float row_height;
int i;
int rows = symbol->rows ? symbol->rows : 1; /* Sometimes called before expand() */
for (i = 0; i < rows; i++) {
if (symbol->row_height[i]) {
fixed_height += symbol->row_height[i];
} else {
zero_count++;
}
}
if (zero_count) {
if (symbol->height) {
row_height = (symbol->height - fixed_height) / zero_count;
} else if (default_height) {
row_height = default_height / zero_count;
} else {
row_height = min_row_height;
}
if (row_height < 0.5f) { /* Absolute minimum */
row_height = 0.5f;
}
if (min_row_height && row_height < min_row_height) {
error_number = ZINT_WARN_NONCOMPLIANT;
if (!no_errtxt) {
strcpy(symbol->errtxt, "247: Height not compliant with standards");
}
}
symbol->height = row_height * zero_count + fixed_height;
} else {
symbol->height = fixed_height; /* Ignore any given height */
}
if (max_height && symbol->height > max_height) {
error_number = ZINT_WARN_NONCOMPLIANT;
if (!no_errtxt) {
strcpy(symbol->errtxt, "248: Height not compliant with standards");
}
}
return error_number;
}
/* Returns red component if any of ultra colour indexing "0CBMRYGKW" */
INTERNAL int colour_to_red(const int colour) {
int return_val = 0;
switch (colour) {
case 8: // White
case 3: // Magenta
case 4: // Red
case 5: // Yellow
return_val = 255;
break;
}
return return_val;
}
/* Returns green component if any of ultra colour indexing "0CBMRYGKW" */
INTERNAL int colour_to_green(const int colour) {
int return_val = 0;
switch (colour) {
case 8: // White
case 1: // Cyan
case 5: // Yellow
case 6: // Green
return_val = 255;
break;
}
return return_val;
}
/* Returns blue component if any of ultra colour indexing "0CBMRYGKW" */
INTERNAL int colour_to_blue(const int colour) {
int return_val = 0;
switch (colour) {
case 8: // White
case 1: // Cyan
case 2: // Blue
case 3: // Magenta
return_val = 255;
break;
}
return return_val;
}
#ifdef ZINT_TEST
/* Dumps hex-formatted codewords in symbol->errtxt (for use in testing) */
void debug_test_codeword_dump(struct zint_symbol *symbol, const unsigned char *codewords, const int length) {
int i, max = length, cnt_len = 0;
if (length > 30) { /* 30*3 < errtxt 92 (100 - "Warning ") chars */
sprintf(symbol->errtxt, "(%d) ", length); /* Place the number of codewords at the front */
cnt_len = (int) strlen(symbol->errtxt);
max = 30 - (cnt_len + 2) / 3;
}
for (i = 0; i < max; i++) {
sprintf(symbol->errtxt + cnt_len + i * 3, "%02X ", codewords[i]);
}
symbol->errtxt[strlen(symbol->errtxt) - 1] = '\0'; /* Zap last space */
}
/* Dumps decimal-formatted codewords in symbol->errtxt (for use in testing) */
void debug_test_codeword_dump_int(struct zint_symbol *symbol, const int *codewords, const int length) {
int i, max = 0, cnt_len, errtxt_len;
char temp[20];
errtxt_len = sprintf(symbol->errtxt, "(%d) ", length); /* Place the number of codewords at the front */
for (i = 0, cnt_len = errtxt_len; i < length; i++) {
cnt_len += sprintf(temp, "%d ", codewords[i]);
if (cnt_len > 92) {
break;
}
max++;
}
for (i = 0; i < max; i++) {
errtxt_len += sprintf(symbol->errtxt + errtxt_len, "%d ", codewords[i]);
}
symbol->errtxt[strlen(symbol->errtxt) - 1] = '\0'; /* Zap last space */
}
#endif

156
3rdparty/zint-2.10.0/backend/common.h vendored Normal file
View File

@ -0,0 +1,156 @@
/* common.h - Header for all common functions in common.c */
/*
libzint - the open source barcode library
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#ifndef __COMMON_H
#define __COMMON_H
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
/* The most commonly used set */
#define NEON "0123456789"
#include "zint.h"
#include "zintconfig.h"
#include <stdlib.h>
#include <string.h>
/* Helpers to cast away char pointer signedness */
#define ustrlen(source) strlen((const char *) (source))
#define ustrcpy(target, source) strcpy((char *) (target), (const char *) (source))
#define ustrcat(target, source) strcat((char *) (target), (const char *) (source))
#define ustrncat(target, source, count) strncat((char *) (target), (const char *) (source), (count))
#ifdef _MSC_VER
# if _MSC_VER == 1200 /* VC6 */
# define ceilf (float) ceil
# define floorf (float) floor
# define fmodf (float) fmod
# endif
# if _MSC_VER < 1800 /* round (C99) not before MSVC 2013 (C++ 12.0) */
# define round(arg) floor((arg) + 0.5)
# define roundf(arg) floorf((arg) + 0.5f)
# endif
# pragma warning(disable: 4244) /* conversion from int to float */
# if _MSC_VER != 1200 /* VC6 */
# pragma warning(disable: 4996) /* function or variable may be unsafe */
# endif
#endif
/* Is float integral value? (https://stackoverflow.com/a/40404149/664741) */
#define isfintf(arg) (fmodf(arg, 1.0f) == 0.0f)
#if (defined(__GNUC__) || defined(__clang__)) && !defined(ZINT_TEST) && !defined(__MINGW32__)
# define INTERNAL __attribute__ ((visibility ("hidden")))
#elif defined(ZINT_TEST)
# define INTERNAL ZINT_EXTERN /* The test suite references INTERNAL functions, so they need to be exported */
#else
# define INTERNAL
#endif
#ifdef ZINT_TEST
#define STATIC_UNLESS_ZINT_TEST INTERNAL
#else
#define STATIC_UNLESS_ZINT_TEST static
#endif
#define COMMON_INLINE 1
#ifdef COMMON_INLINE
/* Return true (1) if a module is dark/black, otherwise false (0) */
# define module_is_set(s, y, x) (((s)->encoded_data[(y)][(x) >> 3] >> ((x) & 0x07)) & 1)
/* Set a module to dark/black */
# define set_module(s, y, x) do { (s)->encoded_data[(y)][(x) >> 3] |= 1 << ((x) & 0x07); } while (0)
/* Return true (1-8) if a module is colour, otherwise false (0) */
# define module_colour_is_set(s, y, x) ((s)->encoded_data[(y)][(x)])
/* Set a module to a colour */
# define set_module_colour(s, y, x, c) do { (s)->encoded_data[(y)][(x)] = (c); } while (0)
#endif
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
INTERNAL int ctoi(const char source);
INTERNAL char itoc(const int source);
INTERNAL int to_int(const unsigned char source[], const int length);
INTERNAL void to_upper(unsigned char source[]);
INTERNAL int chr_cnt(const unsigned char string[], const int length, const unsigned char c);
INTERNAL int is_sane(const char test_string[], const unsigned char source[], const int length);
INTERNAL void lookup(const char set_string[], const char *table[], const char data, char dest[]);
INTERNAL void bin_append(const int arg, const int length, char *binary);
INTERNAL int bin_append_posn(const int arg, const int length, char *binary, const int bin_posn);
INTERNAL int posn(const char set_string[], const char data);
#ifndef COMMON_INLINE
INTERNAL int module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord);
INTERNAL void set_module(struct zint_symbol *symbol, const int y_coord, const int x_coord);
INTERNAL int module_colour_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord);
INTERNAL void set_module_colour(struct zint_symbol *symbol, const int y_coord, const int x_coord,
const int colour);
#endif
INTERNAL void unset_module(struct zint_symbol *symbol, const int y_coord, const int x_coord);
INTERNAL void expand(struct zint_symbol *symbol, const char data[]);
INTERNAL int is_stackable(const int symbology);
INTERNAL int is_extendable(const int symbology);
INTERNAL int is_composite(const int symbology);
INTERNAL int istwodigits(const unsigned char source[], const int length, const int position);
INTERNAL unsigned int decode_utf8(unsigned int *state, unsigned int *codep, const unsigned char byte);
INTERNAL int is_valid_utf8(const unsigned char source[], const int length);
INTERNAL int utf8_to_unicode(struct zint_symbol *symbol, const unsigned char source[], unsigned int vals[],
int *length, const int disallow_4byte);
INTERNAL int set_height(struct zint_symbol *symbol, const float min_row_height, const float default_height,
const float max_height, const int set_errtxt);
INTERNAL int colour_to_red(const int colour);
INTERNAL int colour_to_green(const int colour);
INTERNAL int colour_to_blue(const int colour);
#ifdef ZINT_TEST
INTERNAL void debug_test_codeword_dump(struct zint_symbol *symbol, const unsigned char *codewords,
const int length);
INTERNAL void debug_test_codeword_dump_int(struct zint_symbol *symbol, const int *codewords, const int length);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __COMMON_H */

1631
3rdparty/zint-2.10.0/backend/composite.c vendored Normal file

File diff suppressed because it is too large Load Diff

140
3rdparty/zint-2.10.0/backend/composite.h vendored Normal file
View File

@ -0,0 +1,140 @@
/* composite.c - Tables for UCC.EAN Composite Symbols */
/*
libzint - the open source barcode library
Copyright (C) 2008 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
/* CC-A component coefficients from ISO/IEC 24728:2006 Annex F */
static const unsigned short int ccaCoeffs[30] = {
/* k = 4 */
522, 568, 723, 809,
/* k = 5 */
427, 919, 460, 155, 566,
/* k = 6 */
861, 285, 19, 803, 17, 766,
/* k = 7 */
76, 925, 537, 597, 784, 691, 437,
/* k = 8 */
237, 308, 436, 284, 646, 653, 428, 379
};
/* rows, error codewords, k-offset of valid CC-A sizes from ISO/IEC 24723:2006 Table 9 */
static const char ccaVariants[51] = {
5, 6, 7, 8, 9, 10, 12, 4, 5, 6, 7, 8, 3, 4, 5, 6, 7,
4, 4, 5, 5, 6, 6, 7, 4, 5, 6, 7, 7, 4, 5, 6, 7, 8,
0, 0, 4, 4, 9, 9, 15, 0, 4, 9, 15, 15, 0, 4, 9, 15, 22
};
/* following is Left RAP, Centre RAP, Right RAP and Start Cluster from ISO/IEC 24723:2006 tables 10 and 11 */
static const char aRAPTable[68] = {
39, 1, 32, 8, 14, 43, 20, 11, 1, 5, 15, 21, 40, 43, 46, 34, 29,
0, 0, 0, 0, 0, 0, 0, 43, 33, 37, 47, 1, 20, 23, 26, 14, 9,
19, 33, 12, 40, 46, 23, 52, 23, 13, 17, 27, 33, 52, 3, 6, 46, 41,
6, 0, 3, 3, 3, 0, 3, 3, 0, 3, 6, 6, 0, 0, 0, 0, 3
};
/* Row Address Patterns are as defined in pdf417.h */
/* Generated by tools/gen_pwr928_table.php */
static const UINT pwr928[69][7] = {
{ 0, 0, 0, 0, 0, 0, 1, },
{ 0, 0, 0, 0, 0, 0, 2, },
{ 0, 0, 0, 0, 0, 0, 4, },
{ 0, 0, 0, 0, 0, 0, 8, },
{ 0, 0, 0, 0, 0, 0, 16, },
{ 0, 0, 0, 0, 0, 0, 32, },
{ 0, 0, 0, 0, 0, 0, 64, },
{ 0, 0, 0, 0, 0, 0, 128, },
{ 0, 0, 0, 0, 0, 0, 256, },
{ 0, 0, 0, 0, 0, 0, 512, },
{ 0, 0, 0, 0, 0, 1, 96, },
{ 0, 0, 0, 0, 0, 2, 192, },
{ 0, 0, 0, 0, 0, 4, 384, },
{ 0, 0, 0, 0, 0, 8, 768, },
{ 0, 0, 0, 0, 0, 17, 608, },
{ 0, 0, 0, 0, 0, 35, 288, },
{ 0, 0, 0, 0, 0, 70, 576, },
{ 0, 0, 0, 0, 0, 141, 224, },
{ 0, 0, 0, 0, 0, 282, 448, },
{ 0, 0, 0, 0, 0, 564, 896, },
{ 0, 0, 0, 0, 1, 201, 864, },
{ 0, 0, 0, 0, 2, 403, 800, },
{ 0, 0, 0, 0, 4, 807, 672, },
{ 0, 0, 0, 0, 9, 687, 416, },
{ 0, 0, 0, 0, 19, 446, 832, },
{ 0, 0, 0, 0, 38, 893, 736, },
{ 0, 0, 0, 0, 77, 859, 544, },
{ 0, 0, 0, 0, 155, 791, 160, },
{ 0, 0, 0, 0, 311, 654, 320, },
{ 0, 0, 0, 0, 623, 380, 640, },
{ 0, 0, 0, 1, 318, 761, 352, },
{ 0, 0, 0, 2, 637, 594, 704, },
{ 0, 0, 0, 5, 347, 261, 480, },
{ 0, 0, 0, 10, 694, 523, 32, },
{ 0, 0, 0, 21, 461, 118, 64, },
{ 0, 0, 0, 42, 922, 236, 128, },
{ 0, 0, 0, 85, 916, 472, 256, },
{ 0, 0, 0, 171, 905, 16, 512, },
{ 0, 0, 0, 343, 882, 33, 96, },
{ 0, 0, 0, 687, 836, 66, 192, },
{ 0, 0, 1, 447, 744, 132, 384, },
{ 0, 0, 2, 895, 560, 264, 768, },
{ 0, 0, 5, 863, 192, 529, 608, },
{ 0, 0, 11, 798, 385, 131, 288, },
{ 0, 0, 23, 668, 770, 262, 576, },
{ 0, 0, 47, 409, 612, 525, 224, },
{ 0, 0, 94, 819, 297, 122, 448, },
{ 0, 0, 189, 710, 594, 244, 896, },
{ 0, 0, 379, 493, 260, 489, 864, },
{ 0, 0, 759, 58, 521, 51, 800, },
{ 0, 1, 590, 117, 114, 103, 672, },
{ 0, 3, 252, 234, 228, 207, 416, },
{ 0, 6, 504, 468, 456, 414, 832, },
{ 0, 13, 81, 8, 912, 829, 736, },
{ 0, 26, 162, 17, 897, 731, 544, },
{ 0, 52, 324, 35, 867, 535, 160, },
{ 0, 104, 648, 71, 807, 142, 320, },
{ 0, 209, 368, 143, 686, 284, 640, },
{ 0, 418, 736, 287, 444, 569, 352, },
{ 0, 837, 544, 574, 889, 210, 704, },
{ 1, 747, 161, 221, 850, 421, 480, },
{ 3, 566, 322, 443, 772, 843, 32, },
{ 7, 204, 644, 887, 617, 758, 64, },
{ 14, 409, 361, 847, 307, 588, 128, },
{ 28, 818, 723, 766, 615, 248, 256, },
{ 57, 709, 519, 605, 302, 496, 512, },
{ 115, 491, 111, 282, 605, 65, 96, },
{ 231, 54, 222, 565, 282, 130, 192, },
{ 462, 108, 445, 202, 564, 260, 384, },
};

View File

@ -2,6 +2,7 @@
#if defined (_WIN32) && (defined(_USRDLL) || defined(DLL_EXPORT) || defined(PIC))
#include <windows.h>
#include <shlwapi.h>
#include "zintconfig.h"
#ifdef __cplusplus
extern "C"
@ -19,12 +20,12 @@ HRESULT DllGetVersion (DLLVERSIONINFO2* pdvi)
if (!pdvi || (sizeof(*pdvi) != pdvi->info1.cbSize))
return (E_INVALIDARG);
pdvi->info1.dwMajorVersion = 2;
pdvi->info1.dwMinorVersion = 2;
pdvi->info1.dwBuildNumber = 1;
pdvi->info1.dwMajorVersion = ZINT_VERSION_MAJOR;
pdvi->info1.dwMinorVersion = ZINT_VERSION_MINOR;
pdvi->info1.dwBuildNumber = ZINT_VERSION_RELEASE;
pdvi->info1.dwPlatformID = DLLVER_PLATFORM_WINDOWS;
if (sizeof(DLLVERSIONINFO2) == pdvi->info1.cbSize)
pdvi->ullVersion = MAKEDLLVERULL(2, 2, 1, 0);
pdvi->ullVersion = MAKEDLLVERULL(ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE, ZINT_VERSION_BUILD);
return S_OK;
}

1222
3rdparty/zint-2.10.0/backend/dmatrix.c vendored Normal file

File diff suppressed because it is too large Load Diff

245
3rdparty/zint-2.10.0/backend/dmatrix.h vendored Normal file
View File

@ -0,0 +1,245 @@
/* dmatrix.h - Handles Data Matrix ECC 200 */
/*
libzint - the open source barcode library
Copyright (C) 2009 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
/*
Containes Extended Rectangular Data Matrix (DMRE)
See http://www.dmre.info for information
Contact: harald.oehlmann@eurodatacouncil.org
*/
#ifndef __DMATRIX_H
#define __DMATRIX_H
#define DM_NULL 0
#define DM_ASCII 1
#define DM_C40 2
#define DM_TEXT 3
#define DM_X12 4
#define DM_EDIFACT 5
#define DM_BASE256 6
static const char c40_shift[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
};
static const char c40_value[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
15, 16, 17, 18, 19, 20, 21, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
22, 23, 24, 25, 26, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
};
static const char text_shift[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2, 2, 2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3
};
static const char text_value[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
15, 16, 17, 18, 19, 20, 21, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
22, 23, 24, 25, 26, 0, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 27, 28, 29, 30, 31
};
// Position in option array [symbol option value - 1]
// The position in the option array is by increasing total data codewords with square first
// The last comment value is the total data codewords value.
// The index of this array is the --vers parameter value -1 and is given as first comment value
static const unsigned short int intsymbol[] = {
/* Standard DM */
0, /* 1: 10x10 , 3*/ 1, /* 2: 12x12 , 5*/ 3, /* 3: 14x14 , 8*/ 5, /* 4: 16x16 , 12*/
7, /* 5: 18x18 , 18*/ 9, /* 6: 20x20 , 22*/ 12, /* 7: 22x22 , 30*/ 15, /* 8: 24x24 , 36*/
18, /* 9: 26x26 , 44*/ 23, /* 10: 32x32 , 62*/ 31, /* 11: 36x36 , 86*/ 34, /* 12: 40x40 ,114*/
36, /* 13: 44x44 ,144*/ 37, /* 14: 48x48 ,174*/ 38, /* 15: 52x52 ,204*/ 39, /* 16: 64x64 ,280*/
40, /* 17: 72x72 ,368*/ 41, /* 18: 80x80 ,456*/ 42, /* 19: 88x88 ,576*/ 43, /* 20: 96x96 ,696*/
44, /* 21:104x104,816*/ 45, /* 22:120x120,1050*/46, /* 23:132x132,1304*/47, /* 24:144x144,1558*/
2, /* 25: 8x18 , 5*/ 4, /* 26: 8x32 , 10*/ 6, /* 27: 12x26 , 16*/ 10, /* 28: 12x36 , 22*/
13, /* 29: 16x36 , 32*/ 20, /* 30: 16x48 , 49*/
/* DMRE */
8, /* 31: 8x48 , 18*/ 11, /* 32: 8x64 , 24*/ 14, /* 33: 8x80 , 32*/ 16, /* 34: 8x96 , 38*/
21, /* 35: 8x120, 49*/ 25, /* 36: 8x144, 63*/ 17, /* 37: 12x64 , 43*/ 26, /* 38: 12x88 , 64*/
24, /* 39: 16x64 , 62*/ 19, /* 40: 20x36 , 44*/ 22, /* 41: 20x44 , 56*/ 30, /* 42: 20x64 , 84*/
28, /* 43: 22x48 , 72*/ 29, /* 44: 24x48 , 80*/ 33, /* 45: 24x64 ,108*/ 27, /* 46: 26x40 , 70*/
32, /* 47: 26x48 , 90*/ 35, /* 48: 26x64 ,118*/
};
// Number of DM Sizes
#define DMSIZESCOUNT 48
// Number of 144x144 for special interlace
#define INTSYMBOL144 47
// Is the current code a DMRE code ?
// This is the case, if intsymbol index >= 30
static const char isDMRE[] = {
/* 0*/ 0, /* 10x10, 3*/ 0, /* 12x12 , 5*/ 0, /* 8x18 , 5*/ 0, /* 14x14 , 8*/
/* 4*/ 0, /* 8x32 , 10*/ 0, /* 16x16 , 12*/ 0, /* 12x26 , 16*/ 0, /* 18x18 , 18*/
/* 8*/ 1, /* 8x48 , 18*/ 0, /* 20x20 , 22*/ 0, /* 12x36 , 22*/ 1, /* 8x64 , 24*/
/*12*/ 0, /* 22x22 , 30*/ 0, /* 16x36 , 32*/ 1, /* 8x80 , 32*/ 0, /* 24x24 , 36*/
/*16*/ 1, /* 8x96 , 38*/ 1, /* 12x64 , 43*/ 0, /* 26x26 , 44*/ 1, /* 20x36 , 44*/
/*20*/ 0, /* 16x48 , 49*/ 1, /* 8x120, 49*/ 1, /* 20x44 , 56*/ 0, /* 32x32 , 62*/
/*24*/ 1, /* 16x64 , 62*/ 1, /* 8x144, 63*/ 1, /* 12x88 , 64*/ 1, /* 26x40 , 70*/
/*28*/ 1, /* 22x48 , 72*/ 1, /* 24x48 , 80*/ 1, /* 20x64 , 84*/ 0, /* 36x36 , 86*/
/*32*/ 1, /* 26x48 , 90*/ 1, /* 24x64 ,108*/ 0, /* 40x40 ,114*/ 1, /* 26x64 ,118*/
/*36*/ 0, /* 44x44 ,144*/ 0, /* 48x48 ,174*/ 0, /* 52x52 ,204*/ 0, /* 64x64 ,280*/
/*40*/ 0, /* 72x72 ,368*/ 0, /* 80x80 ,456*/ 0, /* 88x88 ,576*/ 0, /* 96x96 ,696*/
/*44*/ 0, /*104x104,816*/ 0, /*120x120,1050*/0, /*132x132,1304*/0 /*144x144,1558*/
};
// Horizontal matrix size
static const unsigned short int matrixH[] = {
/* 0*/ 10, /* 10x10 , 3*/ 12, /* 12x12 , 5 */ 8, /* 8x18 , 5*/ 14, /* 14x14 , 8*/
/* 4*/ 8, /* 8x32 , 10*/ 16, /* 16x16 , 12*/ 12, /* 12x26 , 16*/ 18, /* 18x18 , 18*/
/* 8*/ 8, /* 8x48 , 18*/ 20, /* 20x20 , 22*/ 12, /* 12x36 , 22*/ 8, /* 8x64 , 24*/
/*12*/ 22, /* 22x22 , 30*/ 16, /* 16x36 , 32*/ 8, /* 8x80 , 32*/ 24, /* 24x24 , 36*/
/*16*/ 8, /* 8x96 , 38*/ 12, /* 12x64 , 43*/ 26, /* 26x26 , 44*/ 20, /* 20x36 , 44*/
/*20*/ 16, /* 16x48 , 49*/ 8, /* 8x120, 49*/ 20, /* 20x44 , 56*/ 32, /* 32x32 , 62*/
/*24*/ 16, /* 16x64 , 62*/ 8, /* 8x144, 63*/ 12, /* 12x88 , 64*/ 26, /* 26x40 , 70*/
/*28*/ 22, /* 22x48 , 72*/ 24, /* 24x48 , 80*/ 20, /* 20x64 , 84*/ 36, /* 36x36 , 86*/
/*32*/ 26, /* 26x48 , 90*/ 24, /* 24x64 ,108*/ 40, /* 40x40 ,114*/ 26, /* 26x64 ,118*/
/*36*/ 44, /* 44x44 ,144*/ 48, /* 48x48 ,174*/ 52, /* 52x52 ,204*/ 64, /* 64x64 ,280*/
/*40*/ 72, /* 72x72 ,368*/ 80, /* 80x80 ,456*/ 88, /* 88x88 ,576*/ 96, /* 96x96 ,696*/
/*44*/104, /*104x104,816*/ 120,/*120x120,1050*/132,/*132x132,1304*/144 /*144x144,1558*/
};
// Vertical matrix sizes
static const unsigned short int matrixW[] = {
/* 0*/ 10, /* 10x10 */ 12, /* 12x12 */ 18, /* 8x18 */ 14, /* 14x14 */
/* 4*/ 32, /* 8x32 */ 16, /* 16x16 */ 26, /* 12x26 */ 18, /* 18x18 */
/* 8*/ 48, /* 8x48 */ 20, /* 20x20 */ 36, /* 12x36 */ 64, /* 8x64 */
/*12*/ 22, /* 22x22 */ 36, /* 16x36 */ 80, /* 8x80 */ 24, /* 24x24 */
/*16*/ 96, /* 8x96 */ 64, /* 12x64 */ 26, /* 26x26 */ 36, /* 20x36 */
/*20*/ 48, /* 16x48 */120, /* 8x120*/ 44, /* 20x44 */ 32, /* 32x32 */
/*24*/ 64, /* 16x64 */144, /* 8x144*/ 88, /* 12x88 */ 40, /* 26x40 */
/*28*/ 48, /* 22x48 */ 48, /* 24x48 */ 64, /* 20x64 */ 36, /* 36x36 */
/*32*/ 48, /* 26x48 */ 64, /* 24x64 */ 40, /* 40x40 */ 64, /* 26x64 */
/*36*/ 44, /* 44x44 */ 48, /* 48x48 */ 52, /* 52x52 */ 64, /* 64x64 */
/*40*/ 72, /* 72x72 */ 80, /* 80x80 */ 88, /* 88x88 */ 96, /* 96x96 */
/*44*/104, /*104x104*/120, /*120x120*/ 132, /*132x132*/144 /*144x144*/
};
// Horizontal submodule size (including subfinder)
static const unsigned short int matrixFH[] = {
/* 0*/ 10, /* 10x10 */ 12, /* 12x12 */ 8, /* 8x18 */ 14, /* 14x14 */
/* 4*/ 8, /* 8x32 */ 16, /* 16x16 */ 12, /* 12x26 */ 18, /* 18x18 */
/* 8*/ 8, /* 8x48 */ 20, /* 20x20 */ 12, /* 12x36 */ 8, /* 8x64 */
/*12*/ 22, /* 22x22 */ 16, /* 16x36 */ 8, /* 8x80 */ 24, /* 24x24 */
/*16*/ 8, /* 8x96 */ 12, /* 12x64 */ 26, /* 26x26 */ 20, /* 20x36 */
/*20*/ 16, /* 16x48 */ 8, /* 8x120*/ 20, /* 20x44 */ 16, /* 32x32 */
/*24*/ 16, /* 16x64 */ 8, /* 8x144*/ 12, /* 12x88 */ 26, /* 26x40 */
/*28*/ 22, /* 22x48 */ 24, /* 24x48 */ 20, /* 20x64 */ 18, /* 36x36 */
/*32*/ 26, /* 26x48 */ 24, /* 24x64 */ 20, /* 40x40 */ 26, /* 26x64 */
/*36*/ 22, /* 44x44 */ 24, /* 48x48 */ 26, /* 52x52 */ 16, /* 64x64 */
/*40*/ 18, /* 72x72 */ 20, /* 80x80 */ 22, /* 88x88 */ 24, /* 96x96 */
/*44*/ 26, /*104x104*/ 20, /*120x120*/ 22, /*132x132*/ 24 /*144x144*/
};
// Vertical submodule size (including subfinder)
static const unsigned short int matrixFW[] = {
/* 0*/ 10, /* 10x10 */ 12, /* 12x12 */ 18, /* 8x18 */ 14, /* 14x14 */
/* 4*/ 16, /* 8x32 */ 16, /* 16x16 */ 26, /* 12x26 */ 18, /* 18x18 */
/* 8*/ 24, /* 8x48 */ 20, /* 20x20 */ 18, /* 12x36 */ 16, /* 8x64 */
/*12*/ 22, /* 22x22 */ 18, /* 16x36 */ 20, /* 8x80 */ 24, /* 24x24 */
/*16*/ 24, /* 8x96 */ 16, /* 12x64 */ 26, /* 26x26 */ 18, /* 20x36 */
/*20*/ 24, /* 16x48 */ 20, /* 8x120*/ 22, /* 20x44 */ 16, /* 32x32 */
/*24*/ 16, /* 16x64 */ 24, /* 8x144*/ 22, /* 12x88 */ 20, /* 26x40 */
/*28*/ 24, /* 22x48 */ 24, /* 24x48 */ 16, /* 20x64 */ 18, /* 36x36 */
/*32*/ 24, /* 26x48 */ 16, /* 24x64 */ 20, /* 40x40 */ 16, /* 26x64 */
/*36*/ 22, /* 44x44 */ 24, /* 48x48 */ 26, /* 52x52 */ 16, /* 64x64 */
/*40*/ 18, /* 72x72 */ 20, /* 80x80 */ 22, /* 88x88 */ 24, /* 96x96 */
/*44*/ 26, /*104x104*/ 20, /*120x120*/ 22, /*132x132*/ 24 /*144x144*/
};
// Total Data Codewords
static const unsigned short int matrixbytes[] = {
/* 0*/ 3, /* 10x10 */ 5, /* 12x12 */ 5, /* 8x18 */ 8, /* 14x14 */
/* 4*/ 10, /* 8x32 */ 12, /* 16x16 */ 16, /* 12x26 */ 18, /* 18x18 */
/* 8*/ 18, /* 8x48 */ 22, /* 20x20 */ 22, /* 12x36 */ 24, /* 8x64 */
/*12*/ 30, /* 22x22 */ 32, /* 16x36 */ 32, /* 8x80 */ 36, /* 24x24 */
/*16*/ 38, /* 8x96 */ 43, /* 12x64 */ 44, /* 26x26 */ 44, /* 20x36 */
/*20*/ 49, /* 16x48 */ 49, /* 8x120*/ 56, /* 20x44 */ 62, /* 32x32 */
/*24*/ 62, /* 16x64 */ 63, /* 8x144*/ 64, /* 12x88 */ 70, /* 26x40 */
/*28*/ 72, /* 22x48 */ 80, /* 24x48 */ 84, /* 20x64 */ 86, /* 36x36 */
/*32*/ 90, /* 26x48 */ 108, /* 24x64 */ 114, /* 40x40 */ 118, /* 26x64 */
/*36*/ 144, /* 44x44 */ 174, /* 48x48 */ 204, /* 52x52 */ 280, /* 64x64 */
/*40*/ 368, /* 72x72 */ 456, /* 80x80 */ 576, /* 88x88 */ 696, /* 96x96 */
/*44*/ 816, /*104x104*/1050, /*120x120*/1304, /*132x132*/1558 /*144x144*/
};
// Data Codewords per RS-Block
static const unsigned short int matrixdatablock[] = {
/* 0*/ 3, /* 10x10 */ 5, /* 12x12 */ 5, /* 8x18 */ 8, /* 14x14 */
/* 4*/ 10, /* 8x32 */ 12, /* 16x16 */ 16, /* 12x26 */ 18, /* 18x18 */
/* 8*/ 18, /* 8x48 */ 22, /* 20x20 */ 22, /* 12x36 */ 24, /* 8x64 */
/*12*/ 30, /* 22x22 */ 32, /* 16x36 */ 32, /* 8x80 */ 36, /* 24x24 */
/*16*/ 38, /* 8x96 */ 43, /* 12x64 */ 44, /* 26x26 */ 44, /* 20x36 */
/*20*/ 49, /* 16x48 */ 49, /* 8x120*/ 56, /* 20x44 */ 62, /* 32x32 */
/*24*/ 62, /* 16x64 */ 63, /* 8x144*/ 64, /* 12x88 */ 70, /* 26x40 */
/*28*/ 72, /* 22x48 */ 80, /* 24x48 */ 84, /* 20x64 */ 86, /* 36x36 */
/*32*/ 90, /* 26x48 */ 108, /* 24x64 */ 114, /* 40x40 */ 118, /* 26x64 */
/*36*/ 144, /* 44x44 */ 174, /* 48x48 */ 102, /* 52x52 */ 140, /* 64x64 */
/*40*/ 92, /* 72x72 */ 114, /* 80x80 */ 144, /* 88x88 */ 174, /* 96x96 */
/*44*/ 136, /*104x104*/ 175, /*120x120*/ 163, /*132x132*/ 156 /* 144x144*/
};
// ECC Codewords per RS-Block
static const unsigned short int matrixrsblock[] = {
/* 0*/ 5, /* 10x10 */ 7, /* 12x12 */ 7, /* 8x18 */ 10, /* 14x14 */
/* 4*/ 11, /* 8x32 */ 12, /* 16x16 */ 14, /* 12x26 */ 14, /* 18x18 */
/* 8*/ 15, /* 8x48 */ 18, /* 20x20 */ 18, /* 12x36 */ 18, /* 8x64 */
/*12*/ 20, /* 22x22 */ 24, /* 16x36 */ 22, /* 8x80 */ 24, /* 24x24 */
/*16*/ 28, /* 8x96 */ 27, /* 12x64 */ 28, /* 26x26 */ 28, /* 20x36 */
/*20*/ 28, /* 16x48 */ 32, /* 8x120*/ 34, /* 20x44 */ 36, /* 32x32 */
/*24*/ 36, /* 16x64 */ 36, /* 8x144*/ 36, /* 12x88 */ 38, /* 26x40 */
/*28*/ 38, /* 22x48 */ 41, /* 24x48 */ 42, /* 20x64 */ 42, /* 36x36 */
/*32*/ 42, /* 26x48 */ 46, /* 24x64 */ 48, /* 40x40 */ 50, /* 26x64 */
/*36*/ 56, /* 44x44 */ 68, /* 48x48 */ 42, /* 52x52 */ 56, /* 64x64 */
/*40*/ 36, /* 72x72 */ 48, /* 80x80 */ 56, /* 88x88 */ 68, /* 96x96 */
/*44*/ 56, /*104x104*/ 68, /*120x120*/ 62, /*132x132*/ 62 /*144x144*/
};
#endif /* __DMATRIX_H */

279
3rdparty/zint-2.10.0/backend/eci.c vendored Normal file
View File

@ -0,0 +1,279 @@
/* eci.c - Extended Channel Interpretations
libzint - the open source barcode library
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h"
#include "eci.h"
#include "eci_sb.h"
#include "sjis.h"
#include "big5.h"
#include "gb2312.h"
#include "ksx1001.h"
/* ECI 20 Shift JIS */
static int sjis_wctomb(unsigned char *r, const unsigned int wc) {
int ret;
unsigned int c;
ret = sjis_wctomb_zint(&c, wc);
if (ret == 0) {
return 0;
}
if (ret == 2) {
r[0] = (unsigned char) (c >> 8);
r[1] = (unsigned char) (c & 0xff);
} else {
*r = (unsigned char) c;
}
return ret;
}
/* ECI 27 ASCII (ISO/IEC 646:1991 IRV (US)) */
static int ascii_wctosb(unsigned char *r, const unsigned int wc) {
if (wc < 0x80) {
*r = (unsigned char) wc;
return 1;
}
return 0;
}
/* ECI 170 ASCII subset (ISO/IEC 646:1991 Invariant, excludes chars that historically had national variants) */
static int ascii_invariant_wctosb(unsigned char *r, const unsigned int wc) {
if (wc == 0x7f || (wc <= 'z' && wc != '#' && wc != '$' && wc != '@' && (wc <= 'Z' || wc == '_' || wc >= 'a'))) {
*r = (unsigned char) wc;
return 1;
}
return 0;
}
/* ECI 28 Big5 Chinese (Taiwan) */
static int big5_wctomb(unsigned char *r, const unsigned int wc) {
unsigned int c;
if (wc < 0x80) {
*r = (unsigned char) wc;
return 1;
}
if (big5_wctomb_zint(&c, wc)) {
r[0] = (unsigned char) (c >> 8);
r[1] = (unsigned char) (c & 0xff);
return 2;
}
return 0;
}
/* ECI 29 GB 2312 Chinese (PRC) */
static int gb2312_wctomb(unsigned char *r, const unsigned int wc) {
unsigned int c;
if (wc < 0x80) {
*r = (unsigned char) wc;
return 1;
}
if (gb2312_wctomb_zint(&c, wc)) {
r[0] = (unsigned char) (c >> 8);
r[1] = (unsigned char) (c & 0xff);
return 2;
}
return 0;
}
/* ECI 30 EUC-KR (KS X 1001, formerly KS C 5601) Korean
* See euc_kr_wctomb() in libiconv-1.16/lib/euc_kr.h */
static int euc_kr_wctomb(unsigned char *r, const unsigned int wc) {
unsigned int c;
if (wc < 0x80) {
*r = (unsigned char) wc;
return 1;
}
if (ksx1001_wctomb_zint(&c, wc)) {
r[0] = (unsigned char) ((c >> 8) + 0x80);
r[1] = (unsigned char) ((c & 0xff) + 0x80);
return 2;
}
return 0;
}
/* Helper to count the number of chars in a string within a range */
static int chr_range_cnt(const unsigned char string[], const int length, const unsigned char c1,
const unsigned char c2) {
int count = 0;
int i;
if (c1) {
for (i = 0; i < length; i++) {
if (string[i] >= c1 && string[i] <= c2) {
count++;
}
}
} else {
for (i = 0; i < length; i++) {
if (string[i] <= c2) {
count++;
}
}
}
return count;
}
/* Is ECI convertible from UTF-8? */
INTERNAL int is_eci_convertible(const int eci) {
if (eci == 26 || (eci > 30 && eci != 170)) { /* Exclude ECI 170 - ASCII Invariant */
/* UTF-8 (26) or 8-bit binary data (899) or undefined (> 30 and < 899) or not character set (> 899) */
return 0;
}
return 1;
}
/* Calculate length required to convert UTF-8 to (double-byte) encoding */
INTERNAL int get_eci_length(const int eci, const unsigned char source[], int length) {
if (eci == 20) { /* Shift JIS */
/* Only ASCII backslash (reverse solidus) exceeds UTF-8 length */
length += chr_cnt(source, length, '\\');
} else if (eci == 25) { /* UCS-2BE */
/* All ASCII chars take 2 bytes */
length += chr_range_cnt(source, length, 0, 0x7F);
} else if (eci == 29) { /* GB 2312 (and GB 18030 if Han Xin) */
/* Not needed for GB 2312 but allow for GB 18030 4 byters */
length *= 2;
}
/* Big5 and EUC-KR fit in UTF-8 length */
return length;
}
/* Convert UTF-8 Unicode to other character encodings */
INTERNAL int utf8_to_eci(const int eci, const unsigned char source[], unsigned char dest[], int *p_length) {
typedef int (*eci_func_t)(unsigned char *r, const unsigned int wc);
static const eci_func_t eci_funcs[31] = {
NULL, NULL, NULL, NULL, iso8859_2_wctosb,
iso8859_3_wctosb, iso8859_4_wctosb, iso8859_5_wctosb, iso8859_6_wctosb, iso8859_7_wctosb,
iso8859_8_wctosb, iso8859_9_wctosb, iso8859_10_wctosb, iso8859_11_wctosb, NULL,
iso8859_13_wctosb, iso8859_14_wctosb, iso8859_15_wctosb, iso8859_16_wctosb, NULL,
sjis_wctomb, cp1250_wctosb, cp1251_wctosb, cp1252_wctosb, cp1256_wctosb,
ucs2be_wctomb, NULL, ascii_wctosb, big5_wctomb, gb2312_wctomb,
euc_kr_wctomb,
};
eci_func_t eci_func;
unsigned int codepoint, state;
int in_posn;
int out_posn;
int length = *p_length;
in_posn = 0;
out_posn = 0;
/* Special case ISO/IEC 8859-1 */
if (eci == 0 || eci == 3) { /* Default ECI 0 to ISO/IEC 8859-1 */
state = 0;
while (in_posn < length) {
do {
decode_utf8(&state, &codepoint, source[in_posn++]);
} while (in_posn < length && state != 0 && state != 12);
if (state != 0) {
return ZINT_ERROR_INVALID_DATA;
}
if (codepoint >= 0x80 && (codepoint < 0x00a0 || codepoint >= 0x0100)) {
return ZINT_ERROR_INVALID_DATA;
}
dest[out_posn++] = (unsigned char) codepoint;
}
dest[out_posn] = '\0';
*p_length = out_posn;
return 0;
}
if (eci == 170) { /* ASCII Invariant (archaic subset) */
eci_func = ascii_invariant_wctosb;
} else {
eci_func = eci_funcs[eci];
if (eci_func == NULL) {
return ZINT_ERROR_INVALID_DATA;
}
}
state = 0;
while (in_posn < length) {
int incr;
do {
decode_utf8(&state, &codepoint, source[in_posn++]);
} while (in_posn < length && state != 0 && state != 12);
if (state != 0) {
return ZINT_ERROR_INVALID_DATA;
}
incr = (*eci_func)(dest + out_posn, codepoint);
if (incr == 0) {
return ZINT_ERROR_INVALID_DATA;
}
out_posn += incr;
}
dest[out_posn] = '\0';
*p_length = out_posn;
return 0;
}
/* Find the lowest single-byte ECI mode which will encode a given set of Unicode text */
INTERNAL int get_best_eci(const unsigned char source[], int length) {
int eci = 3;
/* Note: attempting single-byte conversions only, so get_eci_length() unnecessary */
#ifndef _MSC_VER
unsigned char local_source[length + 1];
#else
unsigned char *local_source = (unsigned char *) _alloca(length + 1);
#endif
do {
if (eci == 14) { /* Reserved */
eci = 15;
} else if (eci == 19) { /* Reserved */
eci = 21; /* Skip 20 Shift JIS */
}
if (utf8_to_eci(eci, source, local_source, &length) == 0) {
return eci;
}
eci++;
} while (eci < 25);
if (!is_valid_utf8(source, length)) {
return 0;
}
return 26; // If all of these fail, use Unicode!
}

49
3rdparty/zint-2.10.0/backend/eci.h vendored Normal file
View File

@ -0,0 +1,49 @@
/* eci.c - Extended Channel Interpretations to Unicode tables
libzint - the open source barcode library
Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#ifndef ECI_H
#define ECI_H
#ifdef __cplusplus
extern "C" {
#endif
INTERNAL int is_eci_convertible(const int eci);
INTERNAL int get_eci_length(const int eci, const unsigned char source[], int length);
INTERNAL int utf8_to_eci(const int eci, const unsigned char source[], unsigned char dest[], int *p_length);
INTERNAL int get_best_eci(const unsigned char source[], int length);
#ifdef __cplusplus
}
#endif
#endif /* ECI_H */

1132
3rdparty/zint-2.10.0/backend/eci_sb.h vendored Normal file

File diff suppressed because it is too large Load Diff

802
3rdparty/zint-2.10.0/backend/emf.c vendored Normal file
View File

@ -0,0 +1,802 @@
/* emf.c - Support for Microsoft Enhanced Metafile Format
libzint - the open source barcode library
Copyright (C) 2016 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
/* Developed according to [MS-EMF] - v20160714, Released July 14, 2016
* and [MS-WMF] - v20160714, Released July 14, 2016 */
#include <errno.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#ifdef _MSC_VER
#include <io.h>
#include <fcntl.h>
#include <malloc.h>
#endif
#include "common.h"
#include "emf.h"
static int count_rectangles(struct zint_symbol *symbol) {
int rectangles = 0;
struct zint_vector_rect *rect;
rect = symbol->vector->rectangles;
while (rect) {
rectangles++;
rect = rect->next;
}
return rectangles;
}
static int count_circles(struct zint_symbol *symbol) {
int circles = 0;
struct zint_vector_circle *circ;
circ = symbol->vector->circles;
while (circ) {
circles++;
circ = circ->next;
}
return circles;
}
static int count_hexagons(struct zint_symbol *symbol) {
int hexagons = 0;
struct zint_vector_hexagon *hex;
hex = symbol->vector->hexagons;
while (hex) {
hexagons++;
hex = hex->next;
}
return hexagons;
}
static int count_strings(struct zint_symbol *symbol, float *fsize, float *fsize2, int *halign, int *halign1,
int *halign2) {
int strings = 0;
struct zint_vector_string *str;
*fsize = *fsize2 = 0.0f;
*halign = *halign1 = *halign2 = 0;
str = symbol->vector->strings;
while (str) {
/* Allow 2 font sizes */
if (*fsize == 0.0f) {
*fsize = str->fsize;
} else if (str->fsize != *fsize && *fsize2 == 0.0f) {
*fsize2 = str->fsize;
}
/* Only 3 haligns possible */
if (str->halign) {
if (str->halign == 1) {
*halign1 = str->halign;
} else {
*halign2 = str->halign;
}
}
strings++;
str = str->next;
}
return strings;
}
static void utfle_copy(unsigned char *output, unsigned char *input, int length) {
int i;
int o;
/* Convert UTF-8 to UTF-16LE - only needs to handle characters <= U+00FF */
i = 0;
o = 0;
do {
if (input[i] <= 0x7f) {
/* 1 byte mode (7-bit ASCII) */
output[o] = input[i];
output[o + 1] = 0x00;
o += 2;
i++;
} else {
/* 2 byte mode */
output[o] = ((input[i] & 0x1f) << 6) + (input[i + 1] & 0x3f);
output[o + 1] = 0x00;
o += 2;
i += 2;
}
} while (i < length);
}
static int bump_up(int input) {
/* Strings length must be a multiple of 4 bytes */
if ((input & 1) == 1) {
input++;
}
return input;
}
static int utfle_length(unsigned char *input, int length) {
int result = 0;
int i;
for (i = 0; i < length; i++) {
result++;
if (input[i] >= 0x80) { /* 2 byte UTF-8 counts as one UTF-16LE character */
i++;
}
}
return result;
}
INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
int i;
FILE *emf_file;
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
int error_number = 0;
int rectangle_count, this_rectangle;
int circle_count, this_circle;
int hexagon_count, this_hexagon;
int string_count, this_text;
int bytecount, recordcount;
float previous_diameter;
float radius, half_radius, half_sqrt3_radius;
int colours_used = 0;
int rectangle_bycolour[9] = {0};
int width, height;
int draw_background = 1;
int bold;
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT;
struct zint_vector_rect *rect;
struct zint_vector_circle *circ;
struct zint_vector_hexagon *hex;
struct zint_vector_string *str;
/* Allow for up to 6 strings (current max 3 for UPC/EAN) */
unsigned char *this_string[6];
emr_exttextoutw_t text[6];
float text_fsizes[6];
int text_haligns[6];
emr_header_t emr_header;
emr_eof_t emr_eof;
emr_mapmode_t emr_mapmode;
emr_setworldtransform_t emr_setworldtransform;
emr_createbrushindirect_t emr_createbrushindirect_fg;
emr_createbrushindirect_t emr_createbrushindirect_bg;
emr_createbrushindirect_t emr_createbrushindirect_colour[9]; // Used for colour symbols only
emr_selectobject_t emr_selectobject_fgbrush;
emr_selectobject_t emr_selectobject_bgbrush;
emr_selectobject_t emr_selectobject_colour[9]; // Used for colour symbols only
emr_createpen_t emr_createpen;
emr_selectobject_t emr_selectobject_pen;
emr_rectangle_t background;
emr_settextcolor_t emr_settextcolor;
float fsize;
emr_extcreatefontindirectw_t emr_extcreatefontindirectw;
emr_selectobject_t emr_selectobject_font;
float fsize2;
emr_extcreatefontindirectw_t emr_extcreatefontindirectw2;
emr_selectobject_t emr_selectobject_font2;
int halign;
emr_settextalign_t emr_settextalign;
int halign1;
emr_settextalign_t emr_settextalign1;
int halign2;
emr_settextalign_t emr_settextalign2;
float current_fsize;
int current_halign;
#ifdef _MSC_VER
emr_rectangle_t *rectangle;
emr_ellipse_t *circle;
emr_polygon_t *hexagon;
#endif
if (symbol->vector == NULL) {
strcpy(symbol->errtxt, "643: Vector header NULL");
return ZINT_ERROR_INVALID_DATA;
}
fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]);
fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]);
bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
if (strlen(symbol->bgcolour) > 6) {
if ((ctoi(symbol->bgcolour[6]) == 0) && (ctoi(symbol->bgcolour[7]) == 0)) {
draw_background = 0;
}
}
rectangle_count = count_rectangles(symbol);
circle_count = count_circles(symbol);
hexagon_count = count_hexagons(symbol);
string_count = count_strings(symbol, &fsize, &fsize2, &halign, &halign1, &halign2);
#ifndef _MSC_VER
// Avoid sanitize runtime error by making always non-zero
emr_rectangle_t rectangle[rectangle_count ? rectangle_count : 1];
emr_ellipse_t circle[circle_count ? circle_count : 1];
emr_polygon_t hexagon[hexagon_count ? hexagon_count : 1];
#else
rectangle = (emr_rectangle_t*) _alloca(rectangle_count * sizeof(emr_rectangle_t));
circle = (emr_ellipse_t*) _alloca(circle_count * sizeof(emr_ellipse_t));
hexagon = (emr_polygon_t*) _alloca(hexagon_count * sizeof(emr_polygon_t));
#endif
// Calculate how many coloured rectangles
if (symbol->symbology == BARCODE_ULTRA) {
rect = symbol->vector->rectangles;
while (rect) {
if (rect->colour == -1) { /* Foreground colour */
if (rectangle_bycolour[0] == 0) {
colours_used++;
rectangle_bycolour[0] = 1;
}
} else {
if (rectangle_bycolour[rect->colour] == 0) {
colours_used++;
rectangle_bycolour[rect->colour] = 1;
}
}
rect = rect->next;
}
}
width = (int) ceilf(symbol->vector->width);
height = (int) ceilf(symbol->vector->height);
/* Header */
emr_header.type = 0x00000001; // EMR_HEADER
emr_header.size = 108; // Including extensions
emr_header.emf_header.bounds.left = 0;
emr_header.emf_header.bounds.right = rotate_angle == 90 || rotate_angle == 270 ? height : width;
emr_header.emf_header.bounds.bottom = rotate_angle == 90 || rotate_angle == 270 ? width : height;
emr_header.emf_header.bounds.top = 0;
emr_header.emf_header.frame.left = 0;
emr_header.emf_header.frame.right = emr_header.emf_header.bounds.right * 30;
emr_header.emf_header.frame.top = 0;
emr_header.emf_header.frame.bottom = emr_header.emf_header.bounds.bottom * 30;
emr_header.emf_header.record_signature = 0x464d4520; // ENHMETA_SIGNATURE
emr_header.emf_header.version = 0x00010000;
if (symbol->symbology == BARCODE_ULTRA) {
emr_header.emf_header.handles = 12; // Number of graphics objects
} else {
emr_header.emf_header.handles = fsize2 != 0.0f ? 5 : 4;
}
emr_header.emf_header.reserved = 0x0000;
emr_header.emf_header.n_description = 0;
emr_header.emf_header.off_description = 0;
emr_header.emf_header.n_pal_entries = 0;
emr_header.emf_header.device.cx = 1000;
emr_header.emf_header.device.cy = 1000;
emr_header.emf_header.millimeters.cx = 300;
emr_header.emf_header.millimeters.cy = 300;
/* HeaderExtension1 */
emr_header.emf_header.cb_pixel_format = 0x0000; // None set
emr_header.emf_header.off_pixel_format = 0x0000; // None set
emr_header.emf_header.b_open_gl = 0x0000; // OpenGL not present
/* HeaderExtension2 */
emr_header.emf_header.micrometers.cx = 0;
emr_header.emf_header.micrometers.cy = 0;
bytecount = 108;
recordcount = 1;
emr_mapmode.type = 0x00000011; // EMR_SETMAPMODE
emr_mapmode.size = 12;
emr_mapmode.mapmode = 0x01; // MM_TEXT
bytecount += 12;
recordcount++;
if (rotate_angle) {
emr_setworldtransform.type = 0x00000023; // EMR_SETWORLDTRANSFORM
emr_setworldtransform.size = 32;
emr_setworldtransform.m11 = rotate_angle == 90 ? 0.0f : rotate_angle == 180 ? -1.0f : 0.0f;
emr_setworldtransform.m12 = rotate_angle == 90 ? 1.0f : rotate_angle == 180 ? 0.0f : -1.0f;
emr_setworldtransform.m21 = rotate_angle == 90 ? -1.0f : rotate_angle == 180 ? 0.0f : 1.0f;
emr_setworldtransform.m22 = rotate_angle == 90 ? 0.0f : rotate_angle == 180 ? -1.0f : 0.0f;
emr_setworldtransform.dx = rotate_angle == 90 ? height : rotate_angle == 180 ? width : 0.0f;
emr_setworldtransform.dy = rotate_angle == 90 ? 0.0f : rotate_angle == 180 ? height : width;
bytecount += 32;
recordcount++;
}
/* Create Brushes */
emr_createbrushindirect_bg.type = 0x00000027; // EMR_CREATEBRUSHINDIRECT
emr_createbrushindirect_bg.size = 24;
emr_createbrushindirect_bg.ih_brush = 1;
emr_createbrushindirect_bg.log_brush.brush_style = 0x0000; // BS_SOLID
emr_createbrushindirect_bg.log_brush.color.red = bgred;
emr_createbrushindirect_bg.log_brush.color.green = bggrn;
emr_createbrushindirect_bg.log_brush.color.blue = bgblu;
emr_createbrushindirect_bg.log_brush.color.reserved = 0;
emr_createbrushindirect_bg.log_brush.brush_hatch = 0x0006; // HS_SOLIDCLR
bytecount += 24;
recordcount++;
if (symbol->symbology == BARCODE_ULTRA) {
for (i = 0; i < 9; i++) {
emr_createbrushindirect_colour[i].type = 0x00000027; // EMR_CREATEBRUSHINDIRECT
emr_createbrushindirect_colour[i].size = 24;
emr_createbrushindirect_colour[i].ih_brush = 2 + i;
emr_createbrushindirect_colour[i].log_brush.brush_style = 0x0000; // BS_SOLID
if (i == 0) {
emr_createbrushindirect_colour[i].log_brush.color.red = fgred;
emr_createbrushindirect_colour[i].log_brush.color.green = fggrn;
emr_createbrushindirect_colour[i].log_brush.color.blue = fgblu;
} else {
emr_createbrushindirect_colour[i].log_brush.color.red = colour_to_red(i);
emr_createbrushindirect_colour[i].log_brush.color.green = colour_to_green(i);
emr_createbrushindirect_colour[i].log_brush.color.blue = colour_to_blue(i);
}
emr_createbrushindirect_colour[i].log_brush.color.reserved = 0;
emr_createbrushindirect_colour[i].log_brush.brush_hatch = 0x0006; // HS_SOLIDCLR
}
bytecount += colours_used * 24;
recordcount += colours_used;
} else {
emr_createbrushindirect_fg.type = 0x00000027; // EMR_CREATEBRUSHINDIRECT
emr_createbrushindirect_fg.size = 24;
emr_createbrushindirect_fg.ih_brush = 2;
emr_createbrushindirect_fg.log_brush.brush_style = 0x0000; // BS_SOLID
emr_createbrushindirect_fg.log_brush.color.red = fgred;
emr_createbrushindirect_fg.log_brush.color.green = fggrn;
emr_createbrushindirect_fg.log_brush.color.blue = fgblu;
emr_createbrushindirect_fg.log_brush.color.reserved = 0;
emr_createbrushindirect_fg.log_brush.brush_hatch = 0x0006; // HS_SOLIDCLR
bytecount += 24;
recordcount++;
}
emr_selectobject_bgbrush.type = 0x00000025; // EMR_SELECTOBJECT
emr_selectobject_bgbrush.size = 12;
emr_selectobject_bgbrush.ih_object = 1;
bytecount += 12;
recordcount++;
if (symbol->symbology == BARCODE_ULTRA) {
for (i = 0; i < 9; i++) {
emr_selectobject_colour[i].type = 0x00000025; // EMR_SELECTOBJECT
emr_selectobject_colour[i].size = 12;
emr_selectobject_colour[i].ih_object = 2 + i;
}
bytecount += colours_used * 12;
recordcount += colours_used;
} else {
emr_selectobject_fgbrush.type = 0x00000025; // EMR_SELECTOBJECT
emr_selectobject_fgbrush.size = 12;
emr_selectobject_fgbrush.ih_object = 2;
bytecount += 12;
recordcount++;
}
/* Create Pens */
emr_createpen.type = 0x00000026; // EMR_CREATEPEN
emr_createpen.size = 28;
emr_createpen.ih_pen = 11;
emr_createpen.log_pen.pen_style = 0x00000005; // PS_NULL
emr_createpen.log_pen.width.x = 1;
emr_createpen.log_pen.width.y = 0; // ignored
emr_createpen.log_pen.color_ref.red = 0;
emr_createpen.log_pen.color_ref.green = 0;
emr_createpen.log_pen.color_ref.blue = 0;
emr_createpen.log_pen.color_ref.reserved = 0;
bytecount += 28;
recordcount++;
emr_selectobject_pen.type = 0x00000025; // EMR_SELECTOBJECT
emr_selectobject_pen.size = 12;
emr_selectobject_pen.ih_object = 11;
bytecount += 12;
recordcount++;
if (draw_background) {
/* Make background from a rectangle */
background.type = 0x0000002b; // EMR_RECTANGLE
background.size = 24;
background.box.top = 0;
background.box.left = 0;
background.box.right = emr_header.emf_header.bounds.right;
background.box.bottom = emr_header.emf_header.bounds.bottom;
bytecount += 24;
recordcount++;
}
// Rectangles
rect = symbol->vector->rectangles;
this_rectangle = 0;
while (rect) {
rectangle[this_rectangle].type = 0x0000002b; // EMR_RECTANGLE
rectangle[this_rectangle].size = 24;
rectangle[this_rectangle].box.top = (int32_t) rect->y;
rectangle[this_rectangle].box.bottom = (int32_t) (rect->y + rect->height);
rectangle[this_rectangle].box.left = (int32_t) rect->x;
rectangle[this_rectangle].box.right = (int32_t) (rect->x + rect->width);
this_rectangle++;
bytecount += 24;
recordcount++;
rect = rect->next;
}
// Circles
previous_diameter = radius = 0.0f;
circ = symbol->vector->circles;
this_circle = 0;
while (circ) {
if (previous_diameter != circ->diameter) {
previous_diameter = circ->diameter;
radius = (float) (0.5 * previous_diameter);
}
circle[this_circle].type = 0x0000002a; // EMR_ELLIPSE
circle[this_circle].size = 24;
circle[this_circle].box.top = (int32_t) (circ->y - radius);
circle[this_circle].box.bottom = (int32_t) (circ->y + radius);
circle[this_circle].box.left = (int32_t) (circ->x - radius);
circle[this_circle].box.right = (int32_t) (circ->x + radius);
this_circle++;
bytecount += 24;
recordcount++;
circ = circ->next;
}
// Hexagons
previous_diameter = radius = half_radius = half_sqrt3_radius = 0.0f;
hex = symbol->vector->hexagons;
this_hexagon = 0;
while (hex) {
hexagon[this_hexagon].type = 0x00000003; // EMR_POLYGON
hexagon[this_hexagon].size = 76;
hexagon[this_hexagon].count = 6;
if (previous_diameter != hex->diameter) {
previous_diameter = hex->diameter;
radius = (float) (0.5 * previous_diameter);
half_radius = (float) (0.25 * previous_diameter);
half_sqrt3_radius = (float) (0.43301270189221932338 * previous_diameter);
}
/* Note rotation done via world transform */
hexagon[this_hexagon].a_points_a.x = (int32_t) (hex->x);
hexagon[this_hexagon].a_points_a.y = (int32_t) (hex->y + radius);
hexagon[this_hexagon].a_points_b.x = (int32_t) (hex->x + half_sqrt3_radius);
hexagon[this_hexagon].a_points_b.y = (int32_t) (hex->y + half_radius);
hexagon[this_hexagon].a_points_c.x = (int32_t) (hex->x + half_sqrt3_radius);
hexagon[this_hexagon].a_points_c.y = (int32_t) (hex->y - half_radius);
hexagon[this_hexagon].a_points_d.x = (int32_t) (hex->x);
hexagon[this_hexagon].a_points_d.y = (int32_t) (hex->y - radius);
hexagon[this_hexagon].a_points_e.x = (int32_t) (hex->x - half_sqrt3_radius);
hexagon[this_hexagon].a_points_e.y = (int32_t) (hex->y - half_radius);
hexagon[this_hexagon].a_points_f.x = (int32_t) (hex->x - half_sqrt3_radius);
hexagon[this_hexagon].a_points_f.y = (int32_t) (hex->y + half_radius);
hexagon[this_hexagon].bounds.top = hexagon[this_hexagon].a_points_d.y;
hexagon[this_hexagon].bounds.bottom = hexagon[this_hexagon].a_points_a.y;
hexagon[this_hexagon].bounds.left = hexagon[this_hexagon].a_points_e.x;
hexagon[this_hexagon].bounds.right = hexagon[this_hexagon].a_points_c.x;
this_hexagon++;
bytecount += 76;
recordcount++;
hex = hex->next;
}
/* Create font records, alignment records and text color */
if (symbol->vector->strings) {
bold = (symbol->output_options & BOLD_TEXT) &&
(!is_extendable(symbol->symbology) || (symbol->output_options & SMALL_TEXT));
memset(&emr_extcreatefontindirectw, 0, sizeof(emr_extcreatefontindirectw));
emr_extcreatefontindirectw.type = 0x00000052; // EMR_EXTCREATEFONTINDIRECTW
emr_extcreatefontindirectw.size = 104;
emr_extcreatefontindirectw.ih_fonts = 12;
emr_extcreatefontindirectw.elw.height = (int32_t) fsize;
emr_extcreatefontindirectw.elw.width = 0; // automatic
emr_extcreatefontindirectw.elw.weight = bold ? 700 : 400;
emr_extcreatefontindirectw.elw.char_set = 0x00; // ANSI_CHARSET
emr_extcreatefontindirectw.elw.out_precision = 0x00; // OUT_DEFAULT_PRECIS
emr_extcreatefontindirectw.elw.clip_precision = 0x00; // CLIP_DEFAULT_PRECIS
emr_extcreatefontindirectw.elw.pitch_and_family = 0x02 | (0x02 << 6); // FF_SWISS | VARIABLE_PITCH
utfle_copy(emr_extcreatefontindirectw.elw.facename, (unsigned char *) "sans-serif", 10);
bytecount += 104;
recordcount++;
emr_selectobject_font.type = 0x00000025; // EMR_SELECTOBJECT
emr_selectobject_font.size = 12;
emr_selectobject_font.ih_object = 12;
bytecount += 12;
recordcount++;
if (fsize2) {
memcpy(&emr_extcreatefontindirectw2, &emr_extcreatefontindirectw, sizeof(emr_extcreatefontindirectw));
emr_extcreatefontindirectw2.ih_fonts = 13;
emr_extcreatefontindirectw2.elw.height = (int32_t) fsize2;
bytecount += 104;
recordcount++;
emr_selectobject_font2.type = 0x00000025; // EMR_SELECTOBJECT
emr_selectobject_font2.size = 12;
emr_selectobject_font2.ih_object = 13;
bytecount += 12;
recordcount++;
}
/* Note select aligns counted below in strings loop */
emr_settextalign.type = 0x00000016; // EMR_SETTEXTALIGN
emr_settextalign.size = 12;
emr_settextalign.text_alignment_mode = 0x0006 | 0x0018; // TA_CENTER | TA_BASELINE
if (halign1) {
emr_settextalign1.type = 0x00000016; // EMR_SETTEXTALIGN
emr_settextalign1.size = 12;
emr_settextalign1.text_alignment_mode = 0x0000 | 0x0018; // TA_LEFT | TA_BASELINE
}
if (halign2) {
emr_settextalign2.type = 0x00000016; // EMR_SETTEXTALIGN
emr_settextalign2.size = 12;
emr_settextalign2.text_alignment_mode = 0x0002 | 0x0018; // TA_RIGHT | TA_BASELINE
}
emr_settextcolor.type = 0x0000018; // EMR_SETTEXTCOLOR
emr_settextcolor.size = 12;
emr_settextcolor.color.red = fgred;
emr_settextcolor.color.green = fggrn;
emr_settextcolor.color.blue = fgblu;
emr_settextcolor.color.reserved = 0;
bytecount += 12;
recordcount++;
}
// Text
this_text = 0;
// Loop over font sizes so that they're grouped together, so only have to select font twice at most
for (i = 0, current_fsize = fsize; i < 2 && current_fsize; i++, current_fsize = fsize2) {
str = symbol->vector->strings;
current_halign = -1;
while (str) {
int utfle_len;
int bumped_len;
if (str->fsize != current_fsize) {
str = str->next;
continue;
}
text_fsizes[this_text] = str->fsize;
text_haligns[this_text] = str->halign;
if (text_haligns[this_text] != current_halign) {
current_halign = text_haligns[this_text];
bytecount += 12;
recordcount++;
}
assert(str->length > 0);
utfle_len = utfle_length(str->text, str->length);
bumped_len = bump_up(utfle_len) * 2;
if (!(this_string[this_text] = (unsigned char *) malloc(bumped_len))) {
for (i = 0; i < this_text; i++) {
free(this_string[i]);
}
strcpy(symbol->errtxt, "641: Insufficient memory for EMF string buffer");
return ZINT_ERROR_MEMORY;
}
memset(this_string[this_text], 0, bumped_len);
text[this_text].type = 0x00000054; // EMR_EXTTEXTOUTW
text[this_text].size = 76 + bumped_len;
text[this_text].bounds.top = 0; // ignored
text[this_text].bounds.left = 0; // ignored
text[this_text].bounds.right = 0xffffffff; // ignored
text[this_text].bounds.bottom = 0xffffffff; // ignored
text[this_text].i_graphics_mode = 0x00000002; // GM_ADVANCED
text[this_text].ex_scale = 1.0f;
text[this_text].ey_scale = 1.0f;
text[this_text].w_emr_text.reference.x = (int32_t) str->x;
text[this_text].w_emr_text.reference.y = (int32_t) str->y;
text[this_text].w_emr_text.chars = utfle_len;
text[this_text].w_emr_text.off_string = 76;
text[this_text].w_emr_text.options = 0;
text[this_text].w_emr_text.rectangle.top = 0;
text[this_text].w_emr_text.rectangle.left = 0;
text[this_text].w_emr_text.rectangle.right = 0xffffffff;
text[this_text].w_emr_text.rectangle.bottom = 0xffffffff;
text[this_text].w_emr_text.off_dx = 0;
utfle_copy(this_string[this_text], str->text, str->length);
bytecount += 76 + bumped_len;
recordcount++;
this_text++;
str = str->next;
}
}
/* Suppress clang-tidy clang-analyzer-core.UndefinedBinaryOperatorResult warning */
assert(this_text == string_count);
/* Create EOF record */
emr_eof.type = 0x0000000e; // EMR_EOF
emr_eof.size = 20; // Assuming no palette entries
emr_eof.n_pal_entries = 0;
emr_eof.off_pal_entries = 0;
emr_eof.size_last = emr_eof.size;
bytecount += 20;
recordcount++;
if (symbol->symbology == BARCODE_MAXICODE) {
bytecount += 5 * sizeof(emr_selectobject_t);
recordcount += 5;
}
/* Put final counts in header */
emr_header.emf_header.bytes = bytecount;
emr_header.emf_header.records = recordcount;
/* Send EMF data to file */
if (output_to_stdout) {
#ifdef _MSC_VER
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
sprintf(symbol->errtxt, "642: Could not set stdout to binary (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
#endif
emf_file = stdout;
} else {
if (!(emf_file = fopen(symbol->outfile, "wb"))) {
sprintf(symbol->errtxt, "640: Could not open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
}
fwrite(&emr_header, sizeof(emr_header_t), 1, emf_file);
fwrite(&emr_mapmode, sizeof(emr_mapmode_t), 1, emf_file);
if (rotate_angle) {
fwrite(&emr_setworldtransform, sizeof(emr_setworldtransform_t), 1, emf_file);
}
fwrite(&emr_createbrushindirect_bg, sizeof(emr_createbrushindirect_t), 1, emf_file);
if (symbol->symbology == BARCODE_ULTRA) {
for (i = 0; i < 9; i++) {
if (rectangle_bycolour[i]) {
fwrite(&emr_createbrushindirect_colour[i], sizeof(emr_createbrushindirect_t), 1, emf_file);
}
}
} else {
fwrite(&emr_createbrushindirect_fg, sizeof(emr_createbrushindirect_t), 1, emf_file);
}
fwrite(&emr_createpen, sizeof(emr_createpen_t), 1, emf_file);
if (symbol->vector->strings) {
fwrite(&emr_extcreatefontindirectw, sizeof(emr_extcreatefontindirectw_t), 1, emf_file);
if (fsize2) {
fwrite(&emr_extcreatefontindirectw2, sizeof(emr_extcreatefontindirectw_t), 1, emf_file);
}
}
fwrite(&emr_selectobject_bgbrush, sizeof(emr_selectobject_t), 1, emf_file);
fwrite(&emr_selectobject_pen, sizeof(emr_selectobject_t), 1, emf_file);
if (draw_background) {
fwrite(&background, sizeof(emr_rectangle_t), 1, emf_file);
}
if (symbol->symbology == BARCODE_ULTRA) {
for (i = 0; i < 9; i++) {
if (rectangle_bycolour[i]) {
fwrite(&emr_selectobject_colour[i], sizeof(emr_selectobject_t), 1, emf_file);
rect = symbol->vector->rectangles;
this_rectangle = 0;
while (rect) {
if ((i == 0 && rect->colour == -1) || rect->colour == i) {
fwrite(&rectangle[this_rectangle], sizeof(emr_rectangle_t), 1, emf_file);
}
this_rectangle++;
rect = rect->next;
}
}
}
} else {
fwrite(&emr_selectobject_fgbrush, sizeof(emr_selectobject_t), 1, emf_file);
// Rectangles
for (i = 0; i < rectangle_count; i++) {
fwrite(&rectangle[i], sizeof(emr_rectangle_t), 1, emf_file);
}
}
// Hexagons
for (i = 0; i < hexagon_count; i++) {
fwrite(&hexagon[i], sizeof(emr_polygon_t), 1, emf_file);
}
// Circles
if (symbol->symbology == BARCODE_MAXICODE) {
// Bullseye needed
for (i = 0; i < circle_count; i++) {
fwrite(&circle[i], sizeof(emr_ellipse_t), 1, emf_file);
if (i < circle_count - 1) {
if (i % 2) {
fwrite(&emr_selectobject_fgbrush, sizeof(emr_selectobject_t), 1, emf_file);
} else {
fwrite(&emr_selectobject_bgbrush, sizeof(emr_selectobject_t), 1, emf_file);
}
}
}
} else {
for (i = 0; i < circle_count; i++) {
fwrite(&circle[i], sizeof(emr_ellipse_t), 1, emf_file);
}
}
// Text
if (string_count > 0) {
fwrite(&emr_selectobject_font, sizeof(emr_selectobject_t), 1, emf_file);
fwrite(&emr_settextcolor, sizeof(emr_settextcolor_t), 1, emf_file);
}
current_fsize = fsize;
current_halign = -1;
for (i = 0; i < string_count; i++) {
if (text_fsizes[i] != current_fsize) {
current_fsize = text_fsizes[i];
fwrite(&emr_selectobject_font2, sizeof(emr_selectobject_t), 1, emf_file);
}
if (text_haligns[i] != current_halign) {
current_halign = text_haligns[i];
if (current_halign == 0) {
fwrite(&emr_settextalign, sizeof(emr_settextalign_t), 1, emf_file);
} else if (current_halign == 1) {
fwrite(&emr_settextalign1, sizeof(emr_settextalign_t), 1, emf_file);
} else {
fwrite(&emr_settextalign2, sizeof(emr_settextalign_t), 1, emf_file);
}
}
fwrite(&text[i], sizeof(emr_exttextoutw_t), 1, emf_file);
fwrite(this_string[i], bump_up(text[i].w_emr_text.chars) * 2, 1, emf_file);
free(this_string[i]);
}
fwrite(&emr_eof, sizeof(emr_eof_t), 1, emf_file);
if (output_to_stdout) {
fflush(emf_file);
} else {
fclose(emf_file);
}
return error_number;
}

View File

@ -121,6 +121,12 @@ extern "C" {
uint32_t n_pal_entries;
size_l_t device;
size_l_t millimeters;
// HeaderExtension1 Object
uint32_t cb_pixel_format;
uint32_t off_pixel_format;
uint32_t b_open_gl;
// HeaderExtension2 Object
size_l_t micrometers;
} emf_header_t;
typedef struct emr_header {
@ -129,6 +135,23 @@ extern "C" {
emf_header_t emf_header;
} emr_header_t;
typedef struct emr_mapmode {
uint32_t type;
uint32_t size;
uint32_t mapmode;
} emr_mapmode_t;
typedef struct emr_setworldtransform {
uint32_t type;
uint32_t size;
float m11;
float m12;
float m21;
float m22;
float dx;
float dy;
} emr_setworldtransform_t;
typedef struct emr_createbrushindirect {
uint32_t type;
uint32_t size;
@ -181,6 +204,18 @@ extern "C" {
log_font_t elw;
} emr_extcreatefontindirectw_t;
typedef struct emr_settextalign {
uint32_t type;
uint32_t size;
uint32_t text_alignment_mode;
} emr_settextalign_t;
typedef struct emr_settextcolor {
uint32_t type;
uint32_t size;
color_ref_t color;
} emr_settextcolor_t;
typedef struct emr_exttextoutw {
uint32_t type;
uint32_t size;
@ -214,3 +249,4 @@ extern "C" {
#endif /* EMF_H */

View File

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -29,8 +29,17 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
static const char ascii_font[] = {
#ifndef FONT_H
#define FONT_H
typedef const unsigned short font_item;
#define NORMAL_FONT_WIDTH 7
#define NORMAL_FONT_HEIGHT 14
static font_item ascii_font[] = {
/* Each character is 7 x 14 pixels */
0, 0, 8, 8, 8, 8, 8, 8, 8, 0, 8, 8, 0, 0, /* ! */
0, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* " */
@ -126,7 +135,6 @@ static const char ascii_font[] = {
0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, /* | */
0, 48, 8, 8, 8, 8, 8, 4, 8, 8, 8, 8, 8, 48, /* } */
0, 32, 82, 74, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ~ */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*  */
0, 0, 8, 8, 0, 8, 8, 8, 8, 8, 8, 8, 0, 0, /* ¡ */
0, 0, 0, 0, 16, 60, 82, 80, 80, 80, 82, 60, 16, 0, /* ¢ */
0, 0, 0, 12, 18, 16, 16, 60, 16, 16, 60, 18, 0, 0, /* £ */
@ -224,7 +232,10 @@ static const char ascii_font[] = {
0, 0, 0, 36, 0, 66, 66, 34, 36, 20, 28, 8, 72, 48, /* ÿ */
};
static const char small_font[] = {
#define SMALL_FONT_WIDTH 5
#define SMALL_FONT_HEIGHT 9
static font_item small_font[] = {
/* Each character is 5 x 9 pixels */
0, 2, 2, 2, 2, 0, 2, 0, 0, /* ! */
0, 5, 5, 5, 0, 0, 0, 0, 0, /* " */
@ -320,7 +331,6 @@ static const char small_font[] = {
0, 2, 2, 2, 2, 2, 2, 0, 0, /* | */
0, 4, 2, 3, 2, 2, 4, 0, 0, /* } */
0, 5, 10, 0, 0, 0, 0, 0, 0, /* ~ */
0, 0, 0, 0, 0, 0, 0, 0, 0, /*  */
0, 2, 0, 2, 2, 2, 2, 0, 0, /* ¡ */
0, 0, 2, 7, 10, 10, 7, 2, 0, /* ¢ */
0, 0, 3, 4, 14, 4, 11, 0, 0, /* £ */
@ -417,3 +427,63 @@ static const char small_font[] = {
0, 0, 8, 14, 9, 9, 14, 8, 0, /* þ */
0, 5, 0, 9, 9, 5, 2, 4, 0, /* ÿ */
};
/* Adapted from OCR-B font version 0.2 Matthew Skala
* https://tsukurimashou.osdn.jp/ocr.php.en
*
* Copyright Matthew Skala (2011); based on code by Norbert Schwarz (1986, 2011)
*
* "The version in this package descends from a set of Metafont
* definitions by Norbert Schwarz of Ruhr-Universitaet Bochum,
* bearing dates ranging from 1986 to 2010. He originally
* distributed it under a "non-commercial use only"
* restriction but has since released it for unrestricted use
* and distribution. See the README file for more details."
*
* The README states (http://mirrors.ctan.org/fonts/ocr-b.zip)
*
* "As far as the digitization in METAFONT input which I have
* developed, you may freely use, modify, and/or distribute any of
* these files or the resulting fonts, without limitation. A previous
* release of ocr-b only granted rights for non-commercial use; that
* restriction is now lifted."
*
* Used OCRB.otf with FontForge to create OCRB-18.bdf (normal) and OCRB-16.bdf (small) and then touched up using gbdfed
* Note there's no bold version of OCR-B.
*/
#define UPCEAN_FONT_WIDTH 9
#define UPCEAN_FONT_HEIGHT 14
/* Each character is 9 x 14 pixels */
static font_item upcean_font[] = {
/*30*/ 0x007C, 0x00FE, 0x00C6, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x00C6, 0x00FE, 0x007C, /* 0 */
/*31*/ 0x000C, 0x001C, 0x003C, 0x006C, 0x004C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, /* 1 */
/*32*/ 0x007C, 0x00FE, 0x0183, 0x0003, 0x0007, 0x000E, 0x001C, 0x0038, 0x0070, 0x00E0, 0x01C0, 0x0180, 0x01FE, 0x00FF, /* 2 */
/*33*/ 0x01FE, 0x01FE, 0x0006, 0x000C, 0x0018, 0x0038, 0x003C, 0x0006, 0x0003, 0x0003, 0x0003, 0x0006, 0x01FE, 0x00F8, /* 3 */
/*34*/ 0x0018, 0x0018, 0x0030, 0x0030, 0x0060, 0x0060, 0x00C4, 0x00CC, 0x018C, 0x01FF, 0x01FF, 0x000C, 0x000C, 0x000C, /* 4 */
/*35*/ 0x00FE, 0x00FE, 0x00C0, 0x00C0, 0x00C0, 0x00F8, 0x00FC, 0x0006, 0x0006, 0x0006, 0x0006, 0x000C, 0x01FC, 0x00F8, /* 5 */
/*36*/ 0x000C, 0x001C, 0x0038, 0x0030, 0x0060, 0x00F8, 0x00FE, 0x01C7, 0x0183, 0x0183, 0x0183, 0x01C3, 0x00FE, 0x007C, /* 6 */
/*37*/ 0x01FF, 0x01FF, 0x0003, 0x0006, 0x000E, 0x000C, 0x0018, 0x0030, 0x0030, 0x0030, 0x0060, 0x0060, 0x0060, 0x0060, /* 7 */
/*38*/ 0x007C, 0x00FE, 0x00C6, 0x0082, 0x00C6, 0x007C, 0x007C, 0x00EE, 0x01C7, 0x0183, 0x0183, 0x0183, 0x00FE, 0x007C, /* 8 */
/*39*/ 0x007C, 0x00FE, 0x00C7, 0x0183, 0x0183, 0x0183, 0x01C3, 0x00FE, 0x007E, 0x000C, 0x000C, 0x0018, 0x0030, 0x0060, /* 9 */
};
#define UPCEAN_SMALL_FONT_WIDTH 8
#define UPCEAN_SMALL_FONT_HEIGHT 13
/* Each character is 8 x 13 pixels */
static font_item upcean_small_font[] = {
/*30*/ 0x3C, 0x7E, 0x66, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0x66, 0x7E, 0x3C, /* 0 */
/*31*/ 0x00, 0x0E, 0x1E, 0x36, 0x26, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, /* 1 */
/*32*/ 0x38, 0x7C, 0xC6, 0x02, 0x02, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0xFC, 0x7E, /* 2 */
/*33*/ 0x00, 0xFE, 0xFE, 0x06, 0x1C, 0x38, 0x3E, 0x07, 0x03, 0x03, 0x06, 0xFC, 0x78, /* 3 */
/*34*/ 0x00, 0x18, 0x18, 0x30, 0x30, 0x60, 0x64, 0xCC, 0xCC, 0xFF, 0xFF, 0x0C, 0x0C, /* 4 */
/*35*/ 0x00, 0x7E, 0x7E, 0x40, 0x40, 0x78, 0x7C, 0x06, 0x02, 0x02, 0x06, 0xFC, 0x78, /* 5 */
/*36*/ 0x00, 0x0C, 0x1C, 0x30, 0x30, 0x7C, 0xFE, 0xC7, 0xC3, 0xC3, 0xC3, 0x7E, 0x3C, /* 6 */
/*37*/ 0x00, 0xFF, 0xFF, 0x03, 0x06, 0x0C, 0x18, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, /* 7 */
/*38*/ 0x3C, 0x7E, 0x66, 0x42, 0x66, 0x3C, 0x3C, 0x66, 0xC3, 0xC3, 0xC3, 0x7E, 0x3C, /* 8 */
/*39*/ 0x3C, 0x7E, 0xE7, 0xC3, 0xC3, 0xC3, 0xE3, 0x7E, 0x1E, 0x0C, 0x18, 0x30, 0x60, /* 9 */
};
#endif /* FONT_H */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

2975
3rdparty/zint-2.10.0/backend/gb18030.c vendored Normal file

File diff suppressed because it is too large Load Diff

52
3rdparty/zint-2.10.0/backend/gb18030.h vendored Normal file
View File

@ -0,0 +1,52 @@
/* gb18030.h - Unicode to GB 18030
libzint - the open source barcode library
Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#ifndef GB18030_H
#define GB18030_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
INTERNAL int gb18030_wctomb_zint(unsigned int *r1, unsigned int *r2, const unsigned int wc);
INTERNAL int gb18030_utf8(struct zint_symbol *symbol, const unsigned char source[], int *p_length,
unsigned int *gbdata);
INTERNAL int gb18030_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *gbdata,
const int full_multibyte);
INTERNAL void gb18030_cpy(const unsigned char source[], int *p_length, unsigned int *gbdata,
const int full_multibyte);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* GB18030_H */

1632
3rdparty/zint-2.10.0/backend/gb2312.c vendored Normal file

File diff suppressed because it is too large Load Diff

52
3rdparty/zint-2.10.0/backend/gb2312.h vendored Normal file
View File

@ -0,0 +1,52 @@
/* gb2312.h - Unicode to GB 2312-1980 (EUC-CN)
libzint - the open source barcode library
Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#ifndef GB2312_H
#define GB2312_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
INTERNAL int gb2312_wctomb_zint(unsigned int *r, const unsigned int wc);
INTERNAL int gb2312_utf8(struct zint_symbol *symbol, const unsigned char source[], int *p_length,
unsigned int *gbdata);
INTERNAL int gb2312_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *gbdata,
const int full_multibyte);
INTERNAL void gb2312_cpy(const unsigned char source[], int *p_length, unsigned int *gbdata,
const int full_multibyte);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* GB2312_H */

View File

@ -0,0 +1,206 @@
/* general_field.c - Handles general field compaction (GS1 DataBar and composites) */
/*
libzint - the open source barcode library
Copyright (C) 2019 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include "common.h"
#include "general_field.h"
static const char alphanum_puncs[] = "*,-./";
static const char isoiec_puncs[] = "!\"%&'()*+,-./:;<=>?_ "; /* Note contains space, not in cset82 */
/* Returns type of char at `i`. FNC1 counted as NUMERIC. Returns 0 if invalid char */
static int general_field_type(const char *general_field, const int i) {
if (general_field[i] == '[' || (general_field[i] >= '0' && general_field[i] <= '9')) {
return NUMERIC;
}
if ((general_field[i] >= 'A' && general_field[i] <= 'Z') || strchr(alphanum_puncs, general_field[i])) {
return ALPHANUMERIC;
}
if ((general_field[i] >= 'a' && general_field[i] <= 'z') || strchr(isoiec_puncs, general_field[i])) {
return ISOIEC;
}
return 0;
}
/* Returns true if next (including `i`) `num` chars of type `type`, or if given (non-zero), `type2` */
static int general_field_next(const char *general_field, int i, const int general_field_len, int num, const int type,
const int type2) {
if (i + num > general_field_len) {
return 0;
}
for (; i < general_field_len && num; i++, num--) {
int type_i = general_field_type(general_field, i);
if ((type_i != type && !type2) || (type_i != type && type_i != type2)) {
return 0;
}
}
return num == 0;
}
/* Returns true if next (including `i`) `num` up to `max_num` chars of type `type` and occur at end */
static int general_field_next_terminate(const char *general_field, int i, const int general_field_len, int num,
const int max_num, const int type) {
if (i + max_num < general_field_len) {
return 0;
}
for (; i < general_field_len; i++, num--) {
if (general_field_type(general_field, i) != type) {
return 0;
}
}
return i == general_field_len && num <= 0;
}
/* Returns true if none of the next (including `i`) `num` chars (or end occurs) of type `type` */
static int general_field_next_none(const char *general_field, int i, const int general_field_len, int num,
const int type) {
for (; i < general_field_len && num; i++, num--) {
if (general_field_type(general_field, i) == type) {
return 0;
}
}
return num == 0 || i == general_field_len;
}
/* Attempts to apply encoding rules from sections 7.2.5.5.1 to 7.2.5.5.3
* of ISO/IEC 24724:2011 (same as sections 5.4.1 to 5.4.3 of ISO/IEC 24723:2010) */
INTERNAL int general_field_encode(const char *general_field, const int general_field_len, int *p_mode,
char *p_last_digit, char binary_string[], int *p_bp) {
int i, d1, d2;
int mode = *p_mode;
char last_digit = '\0'; /* Set to odd remaining digit at end if any */
int bp = *p_bp;
for (i = 0; i < general_field_len; ) {
int type = general_field_type(general_field, i);
if (!type) {
return 0;
}
switch (mode) {
case NUMERIC:
if (i < general_field_len - 1) { /* If at least 2 characters remain */
if (type != NUMERIC || general_field_type(general_field, i + 1) != NUMERIC) {
/* 7.2.5.5.1/5.4.1 a) */
bp = bin_append_posn(0, 4, binary_string, bp); /* Alphanumeric latch "0000" */
mode = ALPHANUMERIC;
} else {
d1 = general_field[i] == '[' ? 10 : ctoi(general_field[i]);
d2 = general_field[i + 1] == '[' ? 10 : ctoi(general_field[i + 1]);
bp = bin_append_posn((11 * d1) + d2 + 8, 7, binary_string, bp);
i += 2;
}
} else { /* If 1 character remains */
if (type != NUMERIC) {
/* 7.2.5.5.1/5.4.1 b) */
bp = bin_append_posn(0, 4, binary_string, bp); /* Alphanumeric latch "0000" */
mode = ALPHANUMERIC;
} else {
/* Ending with single digit.
* 7.2.5.5.1 c) and 5.4.1 c) dealt with separately outside this procedure */
last_digit = general_field[i];
i++;
}
}
break;
case ALPHANUMERIC:
if (general_field[i] == '[') {
/* 7.2.5.5.2/5.4.2 a) */
bp = bin_append_posn(15, 5, binary_string, bp); /* "01111" */
mode = NUMERIC;
i++;
} else if (type == ISOIEC) {
/* 7.2.5.5.2/5.4.2 b) */
bp = bin_append_posn(4, 5, binary_string, bp); /* ISO/IEC 646 latch "00100" */
mode = ISOIEC;
} else if (general_field_next(general_field, i, general_field_len, 6, NUMERIC, 0)) {
/* 7.2.5.5.2/5.4.2 c) */
bp = bin_append_posn(0, 3, binary_string, bp); /* Numeric latch "000" */
mode = NUMERIC;
} else if (general_field_next_terminate(general_field, i, general_field_len, 4,
5 /*Can limit to 5 max due to above*/, NUMERIC)) {
/* 7.2.5.5.2/5.4.2 d) */
bp = bin_append_posn(0, 3, binary_string, bp); /* Numeric latch "000" */
mode = NUMERIC;
} else if ((general_field[i] >= '0') && (general_field[i] <= '9')) {
bp = bin_append_posn(general_field[i] - 43, 5, binary_string, bp);
i++;
} else if ((general_field[i] >= 'A') && (general_field[i] <= 'Z')) {
bp = bin_append_posn(general_field[i] - 33, 6, binary_string, bp);
i++;
} else {
bp = bin_append_posn(posn(alphanum_puncs, general_field[i]) + 58, 6, binary_string, bp);
i++;
}
break;
case ISOIEC:
if (general_field[i] == '[') {
/* 7.2.5.5.3/5.4.3 a) */
bp = bin_append_posn(15, 5, binary_string, bp); /* "01111" */
mode = NUMERIC;
i++;
} else {
int next_10_not_isoiec = general_field_next_none(general_field, i, general_field_len, 10, ISOIEC);
if (next_10_not_isoiec && general_field_next(general_field, i, general_field_len, 4,
NUMERIC, 0)) {
/* 7.2.5.5.3/5.4.3 b) */
bp = bin_append_posn(0, 3, binary_string, bp); /* Numeric latch "000" */
mode = NUMERIC;
} else if (next_10_not_isoiec && general_field_next(general_field, i, general_field_len, 5,
ALPHANUMERIC, NUMERIC)) {
/* 7.2.5.5.3/5.4.3 c) */
/* Note this rule can produce longer bitstreams if most of the alphanumerics are numeric */
bp = bin_append_posn(4, 5, binary_string, bp); /* Alphanumeric latch "00100" */
mode = ALPHANUMERIC;
} else if ((general_field[i] >= '0') && (general_field[i] <= '9')) {
bp = bin_append_posn(general_field[i] - 43, 5, binary_string, bp);
i++;
} else if ((general_field[i] >= 'A') && (general_field[i] <= 'Z')) {
bp = bin_append_posn(general_field[i] - 1, 7, binary_string, bp);
i++;
} else if ((general_field[i] >= 'a') && (general_field[i] <= 'z')) {
bp = bin_append_posn(general_field[i] - 7, 7, binary_string, bp);
i++;
} else {
bp = bin_append_posn(posn(isoiec_puncs, general_field[i]) + 232, 8, binary_string, bp);
i++;
}
}
break;
}
}
*p_mode = mode;
*p_last_digit = last_digit;
*p_bp = bp;
return 1;
}

View File

@ -1,7 +1,6 @@
/*
This is a simple Reed-Solomon encoder
(C) Cliff Hones 2004
libzint - the open source barcode library
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -27,24 +26,25 @@
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#ifndef __REEDSOL_H
#define __REEDSOL_H
#ifndef __GENERAL_FIELD_H
#define __GENERAL_FIELD_H
#define NUMERIC 110
#define ALPHANUMERIC 97
#define ISOIEC 105
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
extern void rs_init_gf(const int poly);
extern void rs_init_code(const int nsym,int index);
extern void rs_encode(const size_t len,const unsigned char *data, unsigned char *res);
extern void rs_encode_long(const int len,const unsigned int *data, unsigned int *res);
extern void rs_free(void);
INTERNAL int general_field_encode(const char *general_field, const int general_field_len, int *p_mode,
char *p_last_digit, char binary_string[], int *p_bp);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __REEDSOL_H */
#endif /* __GENERAL_FIELD_H */

608
3rdparty/zint-2.10.0/backend/gif.c vendored Normal file
View File

@ -0,0 +1,608 @@
/* gif.c - Handles output to gif file */
/*
libzint - the open source barcode library
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include <errno.h>
#include <stdio.h>
#include "common.h"
#include <math.h>
#ifdef _MSC_VER
#include <io.h>
#include <fcntl.h>
#include <malloc.h>
#endif
#define SSET "0123456789ABCDEF"
typedef struct s_statestruct {
unsigned char *pOut;
unsigned char *pIn;
unsigned int InLen;
unsigned int OutLength;
unsigned int OutPosCur;
unsigned int OutByteCountPos;
unsigned short ClearCode;
unsigned short FreeCode;
char fByteCountByteSet;
unsigned char OutBitsFree;
unsigned short NodeAxon[4096];
unsigned short NodeNext[4096];
unsigned char NodePix[4096];
unsigned char colourCode[10];
unsigned char colourPaletteIndex[10];
int colourCount;
} statestruct;
/* Transform a Pixel to a lzw colourmap index and move to next pixel.
* All colour values are listed in colourCode with corresponding palette index
*/
static unsigned char NextPaletteIndex(statestruct *pState)
{
unsigned char pixelColour;
int colourIndex;
pixelColour = *(pState->pIn);
(pState->pIn)++;
(pState->InLen)--;
for (colourIndex = 0; colourIndex < pState->colourCount; colourIndex++) {
if (pixelColour == pState->colourCode[colourIndex])
return pState->colourPaletteIndex[colourIndex];
}
return 0; /* Not reached */
}
static int BufferNextByte(statestruct *pState) {
(pState->OutPosCur)++;
/* Check if this position is a byte count position
* fg_f_bytecountbyte_set indicates, if byte count position bytes should be
* inserted in general.
* If this is true, and the distance to the last byte count position is 256
* (e.g. 255 bytes in between), a byte count byte is inserted, and the value
* of the last one is set to 255.
* */
if (pState->fByteCountByteSet && (pState->OutByteCountPos + 256 == pState->OutPosCur)) {
(pState->pOut)[pState->OutByteCountPos] = 255;
pState->OutByteCountPos = pState->OutPosCur;
(pState->OutPosCur)++;
}
if (pState->OutPosCur >= pState->OutLength)
return 1;
(pState->pOut)[pState->OutPosCur] = 0x00;
return 0;
}
static int AddCodeToBuffer(statestruct *pState, unsigned short CodeIn, unsigned char CodeBits) {
/* Check, if we may fill up the current byte completely */
if (CodeBits >= pState->OutBitsFree) {
(pState->pOut)[pState->OutPosCur] |= (unsigned char) (CodeIn << (8 - pState->OutBitsFree));
if (BufferNextByte(pState))
return -1;
CodeIn = (unsigned short) (CodeIn >> pState->OutBitsFree);
CodeBits -= pState->OutBitsFree;
pState->OutBitsFree = 8;
/* Write a full byte if there are at least 8 code bits left */
if (CodeBits >= pState->OutBitsFree) {
(pState->pOut)[pState->OutPosCur] = (unsigned char) CodeIn;
if (BufferNextByte(pState))
return -1;
CodeIn = (unsigned short) (CodeIn >> 8);
CodeBits -= 8;
}
}
/* The remaining bits of CodeIn fit in the current byte. */
if (CodeBits > 0) {
(pState->pOut)[pState->OutPosCur] |= (unsigned char) (CodeIn << (8 - pState->OutBitsFree));
pState->OutBitsFree -= CodeBits;
}
return 0;
}
static void FlushStringTable(statestruct *pState) {
unsigned short Pos;
for (Pos = 0; Pos < pState->ClearCode; Pos++) {
(pState->NodeAxon)[Pos] = 0;
}
}
static unsigned short FindPixelOutlet(statestruct *pState, unsigned short HeadNode, unsigned char Byte) {
unsigned short Outlet;
Outlet = (pState->NodeAxon)[HeadNode];
while (Outlet) {
if ((pState->NodePix)[Outlet] == Byte)
return Outlet;
Outlet = (pState->NodeNext)[Outlet];
}
return 0;
}
static int NextCode(statestruct *pState, unsigned char *pPixelValueCur, unsigned char CodeBits) {
unsigned short UpNode;
unsigned short DownNode;
/* start with the root node for last pixel chain */
UpNode = *pPixelValueCur;
if ((pState->InLen) == 0)
return AddCodeToBuffer(pState, UpNode, CodeBits);
*pPixelValueCur = NextPaletteIndex(pState);
/* Follow the string table and the data stream to the end of the longest string that has a code */
while (0 != (DownNode = FindPixelOutlet(pState, UpNode, *pPixelValueCur))) {
UpNode = DownNode;
if ((pState->InLen) == 0)
return AddCodeToBuffer(pState, UpNode, CodeBits);
*pPixelValueCur = NextPaletteIndex(pState);
}
/* Submit 'UpNode' which is the code of the longest string */
if (AddCodeToBuffer(pState, UpNode, CodeBits))
return -1;
/* ... and extend the string by appending 'PixelValueCur' */
/* Create a successor node for 'PixelValueCur' whose code is 'freecode' */
(pState->NodePix)[pState->FreeCode] = *pPixelValueCur;
(pState->NodeAxon)[pState->FreeCode] = (pState->NodeNext)[pState->FreeCode] = 0;
/* ...and link it to the end of the chain emanating from fg_axon[UpNode]. */
DownNode = (pState->NodeAxon)[UpNode];
if (!DownNode) {
(pState->NodeAxon)[UpNode] = pState->FreeCode;
} else {
while ((pState->NodeNext)[DownNode]) {
DownNode = (pState->NodeNext)[DownNode];
}
(pState->NodeNext)[DownNode] = pState->FreeCode;
}
return 1;
}
static int gif_lzw(statestruct *pState, int paletteBitSize) {
unsigned char PixelValueCur;
unsigned char CodeBits;
unsigned short Pos;
// > Get first data byte
if (pState->InLen == 0)
return 0;
PixelValueCur = NextPaletteIndex(pState);
/* Number of bits per data item (=pixel)
* We need at least a value of 2, otherwise the cc and eoi code consumes
* the whole string table
*/
if (paletteBitSize == 1)
paletteBitSize = 2;
/* initial size of compression codes */
CodeBits = paletteBitSize + 1;
pState->ClearCode = (1 << paletteBitSize);
pState->FreeCode = pState->ClearCode + 2;
pState->OutBitsFree = 8;
pState->OutPosCur = -1;
pState->fByteCountByteSet = 0;
if (BufferNextByte(pState))
return 0;
for (Pos = 0; Pos < pState->ClearCode; Pos++)
(pState->NodePix)[Pos] = (unsigned char) Pos;
FlushStringTable(pState);
/* Write what the GIF specification calls the "code size". */
(pState->pOut)[pState->OutPosCur] = paletteBitSize;
/* Reserve first bytecount byte */
if (BufferNextByte(pState))
return 0;
pState->OutByteCountPos = pState->OutPosCur;
if (BufferNextByte(pState))
return 0;
pState->fByteCountByteSet = 1;
/* Submit one 'ClearCode' as the first code */
if (AddCodeToBuffer(pState, pState->ClearCode, CodeBits))
return 0;
for (;;) {
int Res;
/* generate and save the next code, which may consist of multiple input pixels. */
Res = NextCode(pState, &PixelValueCur, CodeBits);
if (Res < 0)
return 0;
//* Check for end of data stream */
if (!Res) {
/* submit 'eoi' as the last item of the code stream */
if (AddCodeToBuffer(pState, (unsigned short) (pState->ClearCode + 1), CodeBits))
return 0;
pState->fByteCountByteSet = 0;
if (pState->OutBitsFree < 8) {
if (BufferNextByte(pState))
return 0;
}
// > Update last bytecount byte;
if (pState->OutByteCountPos < pState->OutPosCur) {
(pState->pOut)[pState->OutByteCountPos]
= (unsigned char) (pState->OutPosCur - pState->OutByteCountPos - 1);
}
pState->OutPosCur++;
return pState->OutPosCur;
}
/* Check for currently last code */
if (pState->FreeCode == (1U << CodeBits))
CodeBits++;
pState->FreeCode++;
/* Check for full stringtable */
if (pState->FreeCode == 0xfff) {
FlushStringTable(pState);
if (AddCodeToBuffer(pState, pState->ClearCode, CodeBits))
return 0;
CodeBits = (unsigned char) (1 + paletteBitSize);
pState->FreeCode = (unsigned short) (pState->ClearCode + 2);
}
}
}
/*
* Called function to save in gif format
*/
INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) {
unsigned char outbuf[10];
FILE *gif_file;
unsigned short usTemp;
int byte_out;
int colourCount;
unsigned char paletteRGB[10][3];
int paletteCount, paletteCountCur, paletteIndex;
unsigned int pixelIndex;
int paletteBitSize;
int paletteSize;
statestruct State;
int transparent_index;
int bgindex = -1, fgindex = -1;
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT;
unsigned char backgroundColourIndex;
unsigned char RGBCur[3];
unsigned char RGBUnused[3] = {0,0,0};
int colourIndex;
int fFound;
unsigned char pixelColour;
unsigned int bitmapSize = symbol->bitmap_height * symbol->bitmap_width;
/* Allow for overhead of 4 == code size + byte count + overflow byte + zero terminator */
unsigned int lzoutbufSize = bitmapSize + 4;
#ifdef _MSC_VER
char *lzwoutbuf;
#endif
#ifndef _MSC_VER
char lzwoutbuf[lzoutbufSize];
#else
lzwoutbuf = (char *) _alloca(lzoutbufSize);
#endif /* _MSC_VER */
/*
* Build a table of the used palette items.
* Currently, there are the following 10 colour codes:
* '0': standard background
* '1': standard foreground
* 'W': white
* 'C': cyan
* 'B': blue
* 'M': magenta
* 'R': red
* 'Y': yellow
* 'G': green
* 'K': black
* '0' and '1' may be identical to one of the other values
*
* A data structure is set up as follows:
* state.colourCode: list of colour codes
* paletteIndex: palette index of the corresponding colour code
* There are colourCount entries in the upper lists.
* paletteRGB: RGB value at the palette position
* There are paletteCount entries.
* This value is smaller to colourCount, if multiple colour codes have the
* same RGB value and point to the same palette value.
* Example:
* 0 1 W K are present. 0 is equal to white, while 1 is blue
* The resulting tables are:
* paletteItem: ['0']=0 (white), ['1']=1 (blue), ['W']=0 (white),
* ['K']=2 (black)
* Thus, there are 4 colour codes and 3 palette entries.
*/
colourCount = 0;
paletteCount = 0;
/* loop over all pixels */
for (pixelIndex = 0; pixelIndex < bitmapSize; pixelIndex++) {
fFound = 0;
/* get pixel colour code */
pixelColour = pixelbuf[pixelIndex];
/* look, if colour code is already in colour list */
for (colourIndex = 0; colourIndex < colourCount; colourIndex++) {
if ((State.colourCode)[colourIndex] == pixelColour) {
fFound = 1;
break;
}
}
/* If colour is already present, go to next colour code */
if (fFound)
continue;
/* Colour code not present - add colour code */
/* Get RGB value */
switch (pixelColour) {
case '0': /* standard background */
RGBCur[0] = (unsigned char) (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]);
RGBCur[1] = (unsigned char) (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
RGBCur[2] = (unsigned char) (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
break;
case '1': /* standard foreground */
RGBCur[0] = (unsigned char) (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
RGBCur[1] = (unsigned char) (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]);
RGBCur[2] = (unsigned char) (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
break;
case 'W': /* white */
RGBCur[0] = 255; RGBCur[1] = 255; RGBCur[2] = 255;
break;
case 'C': /* cyan */
RGBCur[0] = 0; RGBCur[1] = 255; RGBCur[2] = 255;
break;
case 'B': /* blue */
RGBCur[0] = 0; RGBCur[1] = 0; RGBCur[2] = 255;
break;
case 'M': /* magenta */
RGBCur[0] = 255; RGBCur[1] = 0; RGBCur[2] = 255;
break;
case 'R': /* red */
RGBCur[0] = 255; RGBCur[1] = 0; RGBCur[2] = 0;
break;
case 'Y': /* yellow */
RGBCur[0] = 255; RGBCur[1] = 255; RGBCur[2] = 0;
break;
case 'G': /* green */
RGBCur[0] = 0; RGBCur[1] = 255; RGBCur[2] = 0;
break;
case 'K': /* black */
RGBCur[0] = 0; RGBCur[1] = 0; RGBCur[2] = 0;
break;
default: /* error case - return */
strcpy(symbol->errtxt, "612: unknown pixel colour");
return ZINT_ERROR_INVALID_DATA;
}
/* Search, if RGB value is already present */
fFound = 0;
for (paletteIndex = 0; paletteIndex < paletteCount; paletteIndex++) {
if (RGBCur[0] == paletteRGB[paletteIndex][0]
&& RGBCur[1] == paletteRGB[paletteIndex][1]
&& RGBCur[2] == paletteRGB[paletteIndex][2])
{
fFound = 1;
break;
}
}
/* RGB not present, add it */
if (!fFound) {
paletteIndex = paletteCount;
paletteRGB[paletteIndex][0] = RGBCur[0];
paletteRGB[paletteIndex][1] = RGBCur[1];
paletteRGB[paletteIndex][2] = RGBCur[2];
paletteCount++;
if (pixelColour == '0') bgindex = paletteIndex;
if (pixelColour == '1') fgindex = paletteIndex;
}
/* Add palette index to current colour code */
(State.colourCode)[colourCount] = pixelColour;
(State.colourPaletteIndex)[colourCount] = paletteIndex;
colourCount++;
}
State.colourCount = colourCount;
/* Set transparency */
/* Note: does not allow both transparent foreground and background -
* background takes priority */
transparent_index = -1;
if (strlen(symbol->fgcolour) > 6) {
if ((symbol->fgcolour[6] == '0') && (symbol->fgcolour[7] == '0')) {
// Transparent foreground
transparent_index = fgindex;
}
}
if (strlen(symbol->bgcolour) > 6) {
if ((symbol->bgcolour[6] == '0') && (symbol->bgcolour[7] == '0')) {
// Transparent background
transparent_index = bgindex;
}
}
/* find palette bit size from palette size*/
/* 1,2 -> 1, 3,4 ->2, 5,6,7,8->3 */
paletteBitSize = 0;
paletteCountCur = paletteCount - 1;
while (paletteCountCur != 0) {
paletteBitSize++;
paletteCountCur >>= 1;
}
/* Minimum is 1 */
if (paletteBitSize == 0)
paletteBitSize = 1;
/* palette size 2 ^ bit size */
paletteSize = 1 << paletteBitSize;
/* Open output file in binary mode */
if (output_to_stdout) {
#ifdef _MSC_VER
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
sprintf(symbol->errtxt, "610: Could not set stdout to binary (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
#endif
gif_file = stdout;
} else {
if (!(gif_file = fopen(symbol->outfile, "wb"))) {
sprintf(symbol->errtxt, "611: Could not open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
}
/* GIF signature (6) */
memcpy(outbuf, "GIF87a", 6);
if (transparent_index != -1)
outbuf[4] = '9';
fwrite(outbuf, 6, 1, gif_file);
/* Screen Descriptor (7) */
/* Screen Width */
usTemp = (unsigned short) symbol->bitmap_width;
outbuf[0] = (unsigned char) (0xff & usTemp);
outbuf[1] = (unsigned char) ((0xff00 & usTemp) / 0x100);
/* Screen Height */
usTemp = (unsigned short) symbol->bitmap_height;
outbuf[2] = (unsigned char) (0xff & usTemp);
outbuf[3] = (unsigned char) ((0xff00 & usTemp) / 0x100);
/* write ImageBits-1 to the three least significant bits of byte 5 of
* the Screen Descriptor
* Bits 76543210
* 1 : Global colour map
* 111 : 8 bit colour depth of the palette
* 0 : Not ordered in decreasing importance
* xxx : palette bit zize - 1
*/
outbuf[4] = (unsigned char) (0xf0 | (0x7 & (paletteBitSize - 1)));
/*
* Background colour index
* Default to 0. If colour code 0 or K is present, it is used as index
*/
backgroundColourIndex = 0;
for (colourIndex = 0; colourIndex < colourCount; colourIndex++) {
if ((State.colourCode)[colourIndex] == '0' || (State.colourCode)[colourIndex] == 'W') {
backgroundColourIndex = (State.colourPaletteIndex)[colourIndex];
break;
}
}
outbuf[5] = backgroundColourIndex;
/* Byte 7 must be 0x00 */
outbuf[6] = 0x00;
fwrite(outbuf, 7, 1, gif_file);
/* Global Color Table (paletteSize*3) */
fwrite(paletteRGB, 3*paletteCount, 1, gif_file);
/* add unused palette items to fill palette size */
for (paletteIndex = paletteCount; paletteIndex < paletteSize; paletteIndex++) {
fwrite(RGBUnused, 3, 1, gif_file);
}
/* Graphic control extension (8) */
/* A graphic control extension block is used for overlay gifs.
* This is necessary to define a transparent color.
*/
if (transparent_index != -1) {
/* Extension Introducer = '!' */
outbuf[0] = '\x21';
/* Graphic Control Label */
outbuf[1] = '\xf9';
/* Block Size */
outbuf[2] = 4;
/* Packet fields:
* 3 Reserved
* 3 Disposal Method: 0 No Action, 1 No Dispose, 2: Background, 3: Prev.
* 1 User Input Flag: 0: no user input, 1: user input
* 1 Transparent Color Flag: 0: No Transparency, 1: Transparency index
*/
outbuf[3] = 1;
/* Delay Time */
outbuf[4] = 0;
outbuf[5] = 0;
/* Transparent Color Index */
outbuf[6] = (unsigned char) transparent_index;
/* Block Terminator */
outbuf[7] = 0;
fwrite(outbuf, 8, 1, gif_file);
}
/* Image Descriptor */
/* Image separator character = ',' */
outbuf[0] = 0x2c;
/* "Image Left" */
outbuf[1] = 0x00;
outbuf[2] = 0x00;
/* "Image Top" */
outbuf[3] = 0x00;
outbuf[4] = 0x00;
/* Image Width (low byte first) */
outbuf[5] = (unsigned char) (0xff & symbol->bitmap_width);
outbuf[6] = (unsigned char) ((0xff00 & symbol->bitmap_width) / 0x100);
/* Image Height */
outbuf[7] = (unsigned char) (0xff & symbol->bitmap_height);
outbuf[8] = (unsigned char) ((0xff00 & symbol->bitmap_height) / 0x100);
/* Byte 10 contains the interlaced flag and
* information on the local color table.
* There is no local color table if its most significant bit is reset.
*/
outbuf[9] = 0x00;
fwrite(outbuf, 10, 1, gif_file);
/* prepare state array */
State.pIn = pixelbuf;
State.InLen = bitmapSize;
State.pOut = (unsigned char *) lzwoutbuf;
State.OutLength = lzoutbufSize;
/* call lzw encoding */
byte_out = gif_lzw(&State, paletteBitSize);
if (byte_out <= 0) {
if (!output_to_stdout) {
fclose(gif_file);
}
strcpy(symbol->errtxt, "613: Insufficient memory for LZW buffer");
return ZINT_ERROR_MEMORY;
}
fwrite(lzwoutbuf, byte_out, 1, gif_file);
/* GIF terminator */
fputc('\x3b', gif_file);
if (output_to_stdout) {
fflush(gif_file);
} else {
fclose(gif_file);
}
return 0;
}

1196
3rdparty/zint-2.10.0/backend/gridmtx.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -28,14 +28,7 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#define GM_NUMBER 1
#define GM_LOWER 2
#define GM_UPPER 3
#define GM_MIXED 4
#define GM_CONTROL 5
#define GM_BYTE 6
#define GM_CHINESE 7
/* vim: set ts=4 sw=4 et : */
#define EUROPIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz "
@ -182,3 +175,4 @@ static const unsigned short int gm_macro_matrix[] = {
703, 600, 599, 598, 597, 596, 595, 594, 593, 592, 591, 590, 589, 588, 587, 586, 585, 584, 583, 582, 581, 580, 579, 578, 577, 576, 675,
702, 701, 700, 699, 698, 697, 696, 695, 694, 693, 692, 691, 690, 689, 688, 687, 686, 685, 684, 683, 682, 681, 680, 679, 678, 677, 676,
};

1400
3rdparty/zint-2.10.0/backend/gs1.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2009-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -29,6 +29,7 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#ifndef __GS1_H
#define __GS1_H
@ -36,8 +37,9 @@
extern "C" {
#endif /* __cplusplus */
extern int gs1_verify(struct zint_symbol *symbol, const unsigned char source[], const size_t src_len, char reduced[]);
extern int ugs1_verify(struct zint_symbol *symbol, const unsigned char source[], const unsigned int src_len, unsigned char reduced[]);
INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[], const int src_len,
unsigned char reduced[]);
INTERNAL char gs1_check_digit(const unsigned char source[], const int src_len);
#ifdef __cplusplus
}

843
3rdparty/zint-2.10.0/backend/gs1_lint.h vendored Normal file
View File

@ -0,0 +1,843 @@
/*
* GS1 AI checker generated by "backend/tools/gen_gs1_lint.php" from
* https://raw.githubusercontent.com/bwipp/postscriptbarcode/master/contrib/development/gs1-format-spec.txt
*/
/*
libzint - the open source barcode library
Copyright (C) 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#ifndef GS1_LINT_H
#define GS1_LINT_H
/* N18,csum,key (Used by SSCC) */
static int n18_csum_key(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 18
&& csum(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg)
&& csum(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 0)
&& key(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 0);
}
/* N14,csum,key (Used by GTIN, CONTENT) */
static int n14_csum_key(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 14
&& csum(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg)
&& csum(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 0)
&& key(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 0);
}
/* X1..20 (Used by BATCH/LOT, SERIAL, CPV, PCN...) */
static int x1__20(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 20
&& cset82(data, data_len, 0, 1, 20, p_err_no, p_err_posn, err_msg);
}
/* N6,yymmd0 (Used by PROD DATE, DUE DATE, PACK DATE, BEST BEFORE or BEST BY...) */
static int n6_yymmd0(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 6
&& yymmd0(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg)
&& yymmd0(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 0);
}
/* N2 (Used by VARIANT) */
static int n2(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 2
&& numeric(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg);
}
/* X1..28 (Used by TPX) */
static int x1__28(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 28
&& cset82(data, data_len, 0, 1, 28, p_err_no, p_err_posn, err_msg);
}
/* X1..30 (Used by ADDITIONAL ID, CUST. PART NO., SECONDARY SERIAL, REF. TO SOURCE...) */
static int x1__30(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 30
&& cset82(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg);
}
/* N1..6 (Used by MTO VARIANT) */
static int n1__6(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 6
&& numeric(data, data_len, 0, 1, 6, p_err_no, p_err_posn, err_msg);
}
/* N13,csum,key X0..17 (Used by GDTI) */
static int n13_csum_key_x0__17(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 13 && data_len <= 30
&& csum(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg)
&& csum(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 0)
&& key(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 0)
&& cset82(data, data_len, 13, 0, 17, p_err_no, p_err_posn, err_msg);
}
/* N13,csum,key N0..12 (Used by GCN) */
static int n13_csum_key_n0__12(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 13 && data_len <= 25
&& csum(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg)
&& csum(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 0)
&& key(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 13, 0, 12, p_err_no, p_err_posn, err_msg);
}
/* N1..8 (Used by VAR. COUNT, COUNT) */
static int n1__8(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 8
&& numeric(data, data_len, 0, 1, 8, p_err_no, p_err_posn, err_msg);
}
/* N6 (Used by NET WEIGHT (kg), LENGTH (m), WIDTH (m), HEIGHT (m)...) */
static int n6(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 6
&& numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg);
}
/* N1..15 (Used by AMOUNT, PRICE) */
static int n1__15(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 15
&& numeric(data, data_len, 0, 1, 15, p_err_no, p_err_posn, err_msg);
}
/* N3,iso4217 N1..15 (Used by AMOUNT, PRICE) */
static int n3_iso4217_n1__15(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 4 && data_len <= 18
&& iso4217(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg)
&& iso4217(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 3, 1, 15, p_err_no, p_err_posn, err_msg);
}
/* N4 (Used by PRCNT OFF, POINTS) */
static int n4(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 4
&& numeric(data, data_len, 0, 4, 4, p_err_no, p_err_posn, err_msg);
}
/* X1..30,key (Used by GINC, GIAI - ASSEMBLY, GIAI) */
static int x1__30_key(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 30
&& key(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg)
&& key(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg, 0);
}
/* N17,csum,key (Used by GSIN) */
static int n17_csum_key(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 17
&& csum(data, data_len, 0, 17, 17, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 17, 17, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 17, 17, p_err_no, p_err_posn, err_msg)
&& csum(data, data_len, 0, 17, 17, p_err_no, p_err_posn, err_msg, 0)
&& key(data, data_len, 0, 17, 17, p_err_no, p_err_posn, err_msg, 0);
}
/* N13,csum,key (Used by SHIP TO LOC, BILL TO, PURCHASE FROM, SHIP FOR LOC...) */
static int n13_csum_key(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 13
&& csum(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg)
&& csum(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 0)
&& key(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 0);
}
/* N3,iso3166 X1..9 (Used by SHIP TO POST) */
static int n3_iso3166_x1__9(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 4 && data_len <= 12
&& iso3166(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg)
&& iso3166(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 0)
&& cset82(data, data_len, 3, 1, 9, p_err_no, p_err_posn, err_msg);
}
/* N3,iso3166 (Used by ORIGIN, COUNTRY - PROCESS, COUNTRY - FULL PROCESS) */
static int n3_iso3166(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 3
&& iso3166(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg)
&& iso3166(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 0);
}
/* N3..15,iso3166list (Used by COUNTRY - INITIAL PROCESS, COUNTRY - DISASSEMBLY) */
static int n3__15_iso3166list(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 3 && data_len <= 15
&& iso3166list(data, data_len, 0, 3, 15, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 3, 15, p_err_no, p_err_posn, err_msg)
&& iso3166list(data, data_len, 0, 3, 15, p_err_no, p_err_posn, err_msg, 0);
}
/* X1..3 (Used by ORIGIN SUBDIVISION, AQUATIC SPECIES) */
static int x1__3(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 3
&& cset82(data, data_len, 0, 1, 3, p_err_no, p_err_posn, err_msg);
}
/* X1..35,pcenc (Used by SHIP TO COMP, SHIP TO NAME, RTN TO COMP, RTN TO NAME...) */
static int x1__35_pcenc(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 35
&& pcenc(data, data_len, 0, 1, 35, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 1, 35, p_err_no, p_err_posn, err_msg)
&& pcenc(data, data_len, 0, 1, 35, p_err_no, p_err_posn, err_msg, 0);
}
/* X1..70,pcenc (Used by SHIP TO ADD1, SHIP TO ADD2, SHIP TO SUB, SHIP TO LOC...) */
static int x1__70_pcenc(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 70
&& pcenc(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg)
&& pcenc(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg, 0);
}
/* X2,iso3166alpha2 (Used by SHIP TO COUNTRY, RTN TO COUNTRY) */
static int x2_iso3166alpha2(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 2
&& iso3166alpha2(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg)
&& iso3166alpha2(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg, 0);
}
/* N1,yesno (Used by DANGEROUS GOODS, AUTH LEAVE, SIG REQUIRED) */
static int n1_yesno(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 1
&& yesno(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg)
&& yesno(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg, 0);
}
/* N6,yymmd0 N4,hhmm (Used by NBEF DEL DT., NAFT DEL DT.) */
static int n6_yymmd0_n4_hhmm(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 10
&& yymmd0(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& hhmm(data, data_len, 6, 4, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg)
&& yymmd0(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 6, 4, 4, p_err_no, p_err_posn, err_msg)
&& hhmm(data, data_len, 6, 4, 4, p_err_no, p_err_posn, err_msg, 0);
}
/* N6,yymmdd (Used by REL DATE, FIRST FREEZE DATE) */
static int n6_yymmdd(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 6
&& yymmdd(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg)
&& yymmdd(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 0);
}
/* N13 (Used by NSN) */
static int n13(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 13
&& numeric(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg);
}
/* N6,yymmdd N4,hhmm (Used by EXPIRY TIME) */
static int n6_yymmdd_n4_hhmm(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 10
&& yymmdd(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& hhmm(data, data_len, 6, 4, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg)
&& yymmdd(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 6, 4, 4, p_err_no, p_err_posn, err_msg)
&& hhmm(data, data_len, 6, 4, 4, p_err_no, p_err_posn, err_msg, 0);
}
/* N1..4 (Used by ACTIVE POTENCY) */
static int n1__4(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 4
&& numeric(data, data_len, 0, 1, 4, p_err_no, p_err_posn, err_msg);
}
/* X1..12 (Used by CATCH AREA) */
static int x1__12(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 12
&& cset82(data, data_len, 0, 1, 12, p_err_no, p_err_posn, err_msg);
}
/* N6,yymmdd N0..6,yymmdd (Used by HARVEST DATE) */
static int n6_yymmdd_n0__6_yymmdd(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 6 && data_len <= 12
&& yymmdd(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& yymmdd(data, data_len, 6, 0, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg)
&& yymmdd(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 6, 0, 6, p_err_no, p_err_posn, err_msg)
&& yymmdd(data, data_len, 6, 0, 6, p_err_no, p_err_posn, err_msg, 0);
}
/* X1..10 (Used by FISHING GEAR TYPE) */
static int x1__10(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 10
&& cset82(data, data_len, 0, 1, 10, p_err_no, p_err_posn, err_msg);
}
/* X1..2 (Used by PROD METHOD) */
static int x1__2(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 2
&& cset82(data, data_len, 0, 1, 2, p_err_no, p_err_posn, err_msg);
}
/* N3,iso3166999 X1..27 (Used by PROCESSOR # s) */
static int n3_iso3166999_x1__27(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 4 && data_len <= 30
&& iso3166999(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg)
&& iso3166999(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 0)
&& cset82(data, data_len, 3, 1, 27, p_err_no, p_err_posn, err_msg);
}
/* N1 X1 X1 X1,importeridx (Used by UIC+EXT) */
static int n1_x1_x1_x1_importeridx(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 4
&& importeridx(data, data_len, 3, 1, 1, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg)
&& cset82(data, data_len, 1, 1, 1, p_err_no, p_err_posn, err_msg)
&& cset82(data, data_len, 2, 1, 1, p_err_no, p_err_posn, err_msg)
&& cset82(data, data_len, 3, 1, 1, p_err_no, p_err_posn, err_msg)
&& importeridx(data, data_len, 3, 1, 1, p_err_no, p_err_posn, err_msg, 0);
}
/* X2 X1..28 (Used by CERT # s) */
static int x2_x1__28(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 3 && data_len <= 30
&& cset82(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg)
&& cset82(data, data_len, 2, 1, 28, p_err_no, p_err_posn, err_msg);
}
/* N4,nonzero N5,nonzero N3,nonzero N1,winding N1 (Used by DIMENSIONS) */
static int n4_nonzero_n5_nonzero_n3_nonzero_n1_winding_n1(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 14
&& nonzero(data, data_len, 0, 4, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& nonzero(data, data_len, 4, 5, 5, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& nonzero(data, data_len, 9, 3, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& winding(data, data_len, 12, 1, 1, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 4, 4, p_err_no, p_err_posn, err_msg)
&& nonzero(data, data_len, 0, 4, 4, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 4, 5, 5, p_err_no, p_err_posn, err_msg)
&& nonzero(data, data_len, 4, 5, 5, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 9, 3, 3, p_err_no, p_err_posn, err_msg)
&& nonzero(data, data_len, 9, 3, 3, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 12, 1, 1, p_err_no, p_err_posn, err_msg)
&& winding(data, data_len, 12, 1, 1, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 13, 1, 1, p_err_no, p_err_posn, err_msg);
}
/* N1,zero N13,csum,key X0..16 (Used by GRAI) */
static int n1_zero_n13_csum_key_x0__16(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 14 && data_len <= 30
&& zero(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& csum(data, data_len, 1, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 1, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg)
&& zero(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 1, 13, 13, p_err_no, p_err_posn, err_msg)
&& csum(data, data_len, 1, 13, 13, p_err_no, p_err_posn, err_msg, 0)
&& key(data, data_len, 1, 13, 13, p_err_no, p_err_posn, err_msg, 0)
&& cset82(data, data_len, 14, 0, 16, p_err_no, p_err_posn, err_msg);
}
/* N14,csum N4,pieceoftotal (Used by ITIP, ITIP CONTENT) */
static int n14_csum_n4_pieceoftotal(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 18
&& csum(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& pieceoftotal(data, data_len, 14, 4, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg)
&& csum(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 14, 4, 4, p_err_no, p_err_posn, err_msg)
&& pieceoftotal(data, data_len, 14, 4, 4, p_err_no, p_err_posn, err_msg, 0);
}
/* X1..34,iban (Used by IBAN) */
static int x1__34_iban(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 34
&& iban(data, data_len, 0, 1, 34, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 1, 34, p_err_no, p_err_posn, err_msg)
&& iban(data, data_len, 0, 1, 34, p_err_no, p_err_posn, err_msg, 0);
}
/* N8,yymmddhh N0..4,mmoptss (Used by PROD TIME) */
static int n8_yymmddhh_n0__4_mmoptss(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 8 && data_len <= 12
&& yymmddhh(data, data_len, 0, 8, 8, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& mmoptss(data, data_len, 8, 0, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 8, 8, p_err_no, p_err_posn, err_msg)
&& yymmddhh(data, data_len, 0, 8, 8, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 8, 0, 4, p_err_no, p_err_posn, err_msg)
&& mmoptss(data, data_len, 8, 0, 4, p_err_no, p_err_posn, err_msg, 0);
}
/* X1..50 (Used by OPTSEN) */
static int x1__50(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 50
&& cset82(data, data_len, 0, 1, 50, p_err_no, p_err_posn, err_msg);
}
/* C1..30,key (Used by CPID) */
static int c1__30_key(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 30
&& key(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset39(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg)
&& key(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg, 0);
}
/* N1..12,nozeroprefix (Used by CPID SERIAL) */
static int n1__12_nozeroprefix(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 12
&& nozeroprefix(data, data_len, 0, 1, 12, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 1, 12, p_err_no, p_err_posn, err_msg)
&& nozeroprefix(data, data_len, 0, 1, 12, p_err_no, p_err_posn, err_msg, 0);
}
/* X1..25,csumalpha,key (Used by GMN) */
static int x1__25_csumalpha_key(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 25
&& csumalpha(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg)
&& csumalpha(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 0)
&& key(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 0);
}
/* N18,csum (Used by GSRN - PROVIDER, GSRN - RECIPIENT) */
static int n18_csum(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 18
&& csum(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg)
&& csum(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 0);
}
/* N1..10 (Used by SRIN) */
static int n1__10(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 10
&& numeric(data, data_len, 0, 1, 10, p_err_no, p_err_posn, err_msg);
}
/* X1..25 (Used by REF NO.) */
static int x1__25(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 25
&& cset82(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg);
}
/* X1..70,couponcode */
static int x1__70_couponcode(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 70
&& couponcode(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg)
&& couponcode(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg, 0);
}
/* X1..70,couponposoffer */
static int x1__70_couponposoffer(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 70
&& couponposoffer(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg)
&& couponposoffer(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg, 0);
}
/* X1..70 (Used by PRODUCT URL) */
static int x1__70(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 70
&& cset82(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg);
}
/* X1..90 (Used by INTERNAL) */
static int x1__90(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 90
&& cset82(data, data_len, 0, 1, 90, p_err_no, p_err_posn, err_msg);
}
/* Entry point. Returns 1 on success, 0 on failure: `*p_err_no` set to 1 if unknown AI, 2 if bad data length */
static int gs1_lint(const int ai, const unsigned char *data, const int data_len, int *p_err_no, int *p_err_posn,
char err_msg[50]) {
/* Assume data length failure */
*p_err_no = 2;
if (ai < 100) {
if (ai == 0) {
return n18_csum_key(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 1 || ai == 2) {
return n14_csum_key(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 10 || ai == 21 || ai == 22) {
return x1__20(data, data_len, p_err_no, p_err_posn, err_msg);
}
if ((ai >= 11 && ai <= 13) || (ai >= 15 && ai <= 17)) {
return n6_yymmd0(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 20) {
return n2(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 30 || ai == 37) {
return n1__8(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 90) {
return x1__30(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai >= 91) {
return x1__90(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 300) {
if (ai == 235) {
return x1__28(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 240 || ai == 241 || ai == 250 || ai == 251) {
return x1__30(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 242) {
return n1__6(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 243 || ai == 254) {
return x1__20(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 253) {
return n13_csum_key_x0__17(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 255) {
return n13_csum_key_n0__12(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 500) {
if (ai == 400 || ai == 403) {
return x1__30(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 401) {
return x1__30_key(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 402) {
return n17_csum_key(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai >= 410 && ai <= 417) {
return n13_csum_key(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 420) {
return x1__20(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 421) {
return n3_iso3166_x1__9(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 422 || ai == 424 || ai == 426) {
return n3_iso3166(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 423 || ai == 425) {
return n3__15_iso3166list(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 427) {
return x1__3(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 800) {
if (ai >= 710 && ai <= 714) {
return x1__20(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 3200) {
if ((ai >= 3100 && ai <= 3105) || (ai >= 3110 && ai <= 3115) || (ai >= 3120 && ai <= 3125)
|| (ai >= 3130 && ai <= 3135) || (ai >= 3140 && ai <= 3145) || (ai >= 3150 && ai <= 3155)
|| (ai >= 3160 && ai <= 3165)) {
return n6(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 3300) {
if (ai <= 3205 || (ai >= 3210 && ai <= 3215) || (ai >= 3220 && ai <= 3225) || (ai >= 3230 && ai <= 3235)
|| (ai >= 3240 && ai <= 3245) || (ai >= 3250 && ai <= 3255) || (ai >= 3260 && ai <= 3265)
|| (ai >= 3270 && ai <= 3275) || (ai >= 3280 && ai <= 3285) || (ai >= 3290 && ai <= 3295)) {
return n6(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 3400) {
if (ai <= 3305 || (ai >= 3310 && ai <= 3315) || (ai >= 3320 && ai <= 3325) || (ai >= 3330 && ai <= 3335)
|| (ai >= 3340 && ai <= 3345) || (ai >= 3350 && ai <= 3355) || (ai >= 3360 && ai <= 3365)
|| (ai >= 3370 && ai <= 3375)) {
return n6(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 3500) {
if (ai <= 3405 || (ai >= 3410 && ai <= 3415) || (ai >= 3420 && ai <= 3425) || (ai >= 3430 && ai <= 3435)
|| (ai >= 3440 && ai <= 3445) || (ai >= 3450 && ai <= 3455) || (ai >= 3460 && ai <= 3465)
|| (ai >= 3470 && ai <= 3475) || (ai >= 3480 && ai <= 3485) || (ai >= 3490 && ai <= 3495)) {
return n6(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 3600) {
if (ai <= 3505 || (ai >= 3510 && ai <= 3515) || (ai >= 3520 && ai <= 3525) || (ai >= 3530 && ai <= 3535)
|| (ai >= 3540 && ai <= 3545) || (ai >= 3550 && ai <= 3555) || (ai >= 3560 && ai <= 3565)
|| (ai >= 3570 && ai <= 3575)) {
return n6(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 3700) {
if (ai <= 3605 || (ai >= 3610 && ai <= 3615) || (ai >= 3620 && ai <= 3625) || (ai >= 3630 && ai <= 3635)
|| (ai >= 3640 && ai <= 3645) || (ai >= 3650 && ai <= 3655) || (ai >= 3660 && ai <= 3665)
|| (ai >= 3670 && ai <= 3675) || (ai >= 3680 && ai <= 3685) || (ai >= 3690 && ai <= 3695)) {
return n6(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 4000) {
if ((ai >= 3900 && ai <= 3909) || (ai >= 3920 && ai <= 3929)) {
return n1__15(data, data_len, p_err_no, p_err_posn, err_msg);
}
if ((ai >= 3910 && ai <= 3919) || (ai >= 3930 && ai <= 3939)) {
return n3_iso4217_n1__15(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai >= 3940 && ai <= 3943) {
return n4(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai >= 3950 && ai <= 3955) {
return n6(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 4400) {
if (ai == 4300 || ai == 4301 || ai == 4310 || ai == 4311 || ai == 4320) {
return x1__35_pcenc(data, data_len, p_err_no, p_err_posn, err_msg);
}
if ((ai >= 4302 && ai <= 4306) || (ai >= 4312 && ai <= 4316)) {
return x1__70_pcenc(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 4307 || ai == 4317) {
return x2_iso3166alpha2(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 4308 || ai == 4319) {
return x1__30(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 4318) {
return x1__20(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai >= 4321 && ai <= 4323) {
return n1_yesno(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 4324 || ai == 4325) {
return n6_yymmd0_n4_hhmm(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 4326) {
return n6_yymmdd(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 7100) {
if (ai == 7001) {
return n13(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 7002) {
return x1__30(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 7003) {
return n6_yymmdd_n4_hhmm(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 7004) {
return n1__4(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 7005) {
return x1__12(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 7006) {
return n6_yymmdd(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 7007) {
return n6_yymmdd_n0__6_yymmdd(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 7008) {
return x1__3(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 7009) {
return x1__10(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 7010) {
return x1__2(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai >= 7020 && ai <= 7022) {
return x1__20(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 7023) {
return x1__30_key(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai >= 7030 && ai <= 7039) {
return n3_iso3166999_x1__27(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 7040) {
return n1_x1_x1_x1_importeridx(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 7300) {
if (ai >= 7230 && ai <= 7239) {
return x2_x1__28(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 7240) {
return x1__20(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 8100) {
if (ai == 8001) {
return n4_nonzero_n5_nonzero_n3_nonzero_n1_winding_n1(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8002 || ai == 8012) {
return x1__20(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8003) {
return n1_zero_n13_csum_key_x0__16(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8004) {
return x1__30_key(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8005) {
return n6(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8006 || ai == 8026) {
return n14_csum_n4_pieceoftotal(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8007) {
return x1__34_iban(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8008) {
return n8_yymmddhh_n0__4_mmoptss(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8009) {
return x1__50(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8010) {
return c1__30_key(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8011) {
return n1__12_nozeroprefix(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8013) {
return x1__25_csumalpha_key(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8017 || ai == 8018) {
return n18_csum(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8019) {
return n1__10(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8020) {
return x1__25(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 8200) {
if (ai == 8110) {
return x1__70_couponcode(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8111) {
return n4(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8112) {
return x1__70_couponposoffer(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 8300) {
if (ai == 8200) {
return x1__70(data, data_len, p_err_no, p_err_posn, err_msg);
}
}
/* Unknown AI */
*p_err_no = 1;
return 0;
}
#endif /* GS1_LINT_H */

1671
3rdparty/zint-2.10.0/backend/hanxin.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -29,12 +29,11 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
/* The function "USPS_MSB_Math_CRC11GenerateFrameCheckSequence"
is Copyright (C) 2006 United States Postal Service */
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "common.h"
#include "large.h"
@ -202,14 +201,14 @@ static const unsigned short int AppxD_IV[130] = {
** USPS_MSB_Math_CRC11GenerateFrameCheckSequence
**
** Inputs:
** ByteAttayPtr is the address of a 13 byte array holding 102 bytes which
** ByteAttayPtr is the address of a 13 byte array holding 102 bits which
** are right justified - ie: the leftmost 2 bits of the first byte do not
** hold data and must be set to zero.
**
** Outputs:
** return unsigned short - 11 bit Frame Check Sequence (right justified)
***************************************************************************/
extern unsigned short USPS_MSB_Math_CRC11GenerateFrameCheckSequence(unsigned char *ByteArrayPtr) {
static unsigned short USPS_MSB_Math_CRC11GenerateFrameCheckSequence(unsigned char *ByteArrayPtr) {
unsigned short GeneratorPolynomial = 0x0F35;
unsigned short FrameCheckSequence = 0x07FF;
unsigned short Data;
@ -243,27 +242,29 @@ extern unsigned short USPS_MSB_Math_CRC11GenerateFrameCheckSequence(unsigned cha
return FrameCheckSequence;
}
int imail(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int daft_set_height(struct zint_symbol *symbol, float min_height, float max_height);
INTERNAL int imail(struct zint_symbol *symbol, unsigned char source[], int length) {
char data_pattern[200];
int error_number;
int i, j, read;
char zip[35], tracker[35], zip_adder[11], temp[2];
short int accum[112], x_reg[112], y_reg[112];
char zip[35], tracker[35], temp[2];
large_int accum;
large_int byte_array_reg;
unsigned char byte_array[13];
unsigned short usps_crc;
int codeword[10];
unsigned int codeword[10];
unsigned short characters[10];
short int bar_map[130];
error_number = 0;
int zip_len, len;
if (length > 32) {
strcpy(symbol->errtxt, "450: Input too long");
strcpy(symbol->errtxt, "450: Input too long (32 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(SODIUM, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "451: Invalid characters in data");
strcpy(symbol->errtxt, "451: Invalid character in data (digits and \"-\" only)");
return error_number;
}
@ -298,11 +299,17 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) {
}
if (strlen(tracker) != 20) {
strcpy(symbol->errtxt, "452: Invalid length tracking code");
strcpy(symbol->errtxt, "452: Invalid length for tracking code (20 characters required)");
return ZINT_ERROR_INVALID_DATA;
}
if (strlen(zip) > 11) {
strcpy(symbol->errtxt, "453: Invalid ZIP code");
if (tracker[1] > '4') {
strcpy(symbol->errtxt, "454: Barcode Identifier (second character) out of range (0 to 4)");
return ZINT_ERROR_INVALID_DATA;
}
zip_len = (int) strlen(zip);
if (zip_len != 0 && zip_len != 5 && zip_len != 9 && zip_len != 11) {
strcpy(symbol->errtxt, "453: Invalid length for ZIP code (5, 9 or 11 characters required)");
return ZINT_ERROR_INVALID_DATA;
}
@ -310,230 +317,62 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Routing code first */
for (i = 0; i < 112; i++) {
accum[i] = 0;
}
for (read = 0; read < strlen(zip); read++) {
for (i = 0; i < 112; i++) {
x_reg[i] = accum[i];
}
for (i = 0; i < 9; i++) {
binary_add(accum, x_reg);
}
for (i = 0; i < 112; i++) {
x_reg[i] = 0;
}
for (i = 0; i < 4; i++) {
if (ctoi(zip[read]) & (0x01 << i)) x_reg[i] = 1;
}
binary_add(accum, x_reg);
}
large_load_str_u64(&accum, (unsigned char *) zip, zip_len);
/* add weight to routing code */
for (i = 0; i < 112; i++) {
x_reg[i] = accum[i];
if (zip_len > 9) {
large_add_u64(&accum, 1000100001);
} else if (zip_len > 5) {
large_add_u64(&accum, 100001);
} else if (zip_len > 0) {
large_add_u64(&accum, 1);
}
if (strlen(zip) > 9) {
strcpy(zip_adder, "1000100001");
} else {
if (strlen(zip) > 5) {
strcpy(zip_adder, "100001");
} else {
if (strlen(zip) > 0) {
strcpy(zip_adder, "1");
} else {
strcpy(zip_adder, "0");
}
}
}
for (i = 0; i < 112; i++) {
accum[i] = 0;
}
for (read = 0; read < strlen(zip_adder); read++) {
for (i = 0; i < 112; i++) {
y_reg[i] = accum[i];
}
for (i = 0; i < 9; i++) {
binary_add(accum, y_reg);
}
for (i = 0; i < 112; i++) {
y_reg[i] = 0;
}
for (i = 0; i < 4; i++) {
if (ctoi(zip_adder[read]) & (0x01 << i)) y_reg[i] = 1;
}
binary_add(accum, y_reg);
}
binary_add(accum, x_reg);
/* tracking code */
/* multiply by 10 */
for (i = 0; i < 112; i++) {
y_reg[i] = accum[i];
}
for (i = 0; i < 9; i++) {
binary_add(accum, y_reg);
}
for (i = 0; i < 112; i++) {
y_reg[i] = 0;
}
large_mul_u64(&accum, 10);
/* add first digit of tracker */
for (i = 0; i < 4; i++) {
if (ctoi(tracker[0]) & (0x01 << i)) y_reg[i] = 1;
}
binary_add(accum, y_reg);
large_add_u64(&accum, ctoi(tracker[0]));
/* multiply by 5 */
for (i = 0; i < 112; i++) {
y_reg[i] = accum[i];
}
for (i = 0; i < 4; i++) {
binary_add(accum, y_reg);
}
for (i = 0; i < 112; i++) {
y_reg[i] = 0;
}
large_mul_u64(&accum, 5);
/* add second digit */
for (i = 0; i < 4; i++) {
if (ctoi(tracker[1]) & (0x01 << i)) y_reg[i] = 1;
}
binary_add(accum, y_reg);
large_add_u64(&accum, ctoi(tracker[1]));
/* and then the rest */
for (read = 2; read < strlen(tracker); read++) {
for (read = 2, len = (int) strlen(tracker); read < len; read++) {
for (i = 0; i < 112; i++) {
y_reg[i] = accum[i];
}
for (i = 0; i < 9; i++) {
binary_add(accum, y_reg);
}
for (i = 0; i < 112; i++) {
y_reg[i] = 0;
}
for (i = 0; i < 4; i++) {
if (ctoi(tracker[read]) & (0x01 << i)) y_reg[i] = 1;
}
binary_add(accum, y_reg);
large_mul_u64(&accum, 10);
large_add_u64(&accum, ctoi(tracker[read]));
}
/* *** Step 2 - Generation of 11-bit CRC on Binary Data *** */
accum[103] = 0;
accum[102] = 0;
large_load(&byte_array_reg, &accum);
memset(byte_array, 0, 13);
for (j = 0; j < 13; j++) {
i = 96 - (8 * j);
byte_array[j] = 0;
byte_array[j] += accum[i];
byte_array[j] += 2 * accum[i + 1];
byte_array[j] += 4 * accum[i + 2];
byte_array[j] += 8 * accum[i + 3];
byte_array[j] += 16 * accum[i + 4];
byte_array[j] += 32 * accum[i + 5];
byte_array[j] += 64 * accum[i + 6];
byte_array[j] += 128 * accum[i + 7];
}
large_unset_bit(&byte_array_reg, 102);
large_unset_bit(&byte_array_reg, 103);
large_uchar_array(&byte_array_reg, byte_array, 13, 8 /*bits*/);
usps_crc = USPS_MSB_Math_CRC11GenerateFrameCheckSequence(byte_array);
/* *** Step 3 - Conversion from Binary Data to Codewords *** */
/* start with codeword J which is base 636 */
for (i = 0; i < 112; i++) {
x_reg[i] = 0;
y_reg[i] = 0;
}
x_reg[101] = 1;
x_reg[98] = 1;
x_reg[97] = 1;
x_reg[96] = 1;
x_reg[95] = 1;
x_reg[94] = 1;
for (i = 92; i >= 0; i--) {
y_reg[i] = islarger(accum, x_reg);
if (y_reg[i] == 1) {
binary_subtract(accum, x_reg);
}
shiftdown(x_reg);
}
codeword[9] = (accum[9] * 512) + (accum[8] * 256) + (accum[7] * 128) + (accum[6] * 64) +
(accum[5] * 32) + (accum[4] * 16) + (accum[3] * 8) + (accum[2] * 4) +
(accum[1] * 2) + accum[0];
codeword[9] = (unsigned int) large_div_u64(&accum, 636);
/* then codewords I to B with base 1365 */
for (j = 8; j > 0; j--) {
for (i = 0; i < 112; i++) {
accum[i] = y_reg[i];
y_reg[i] = 0;
x_reg[i] = 0;
}
x_reg[101] = 1;
x_reg[99] = 1;
x_reg[97] = 1;
x_reg[95] = 1;
x_reg[93] = 1;
x_reg[91] = 1;
for (i = 91; i >= 0; i--) {
y_reg[i] = islarger(accum, x_reg);
if (y_reg[i] == 1) {
binary_subtract(accum, x_reg);
}
shiftdown(x_reg);
codeword[j] = (unsigned int) large_div_u64(&accum, 1365);
}
codeword[j] = (accum[10] * 1024) + (accum[9] * 512) + (accum[8] * 256) +
(accum[7] * 128) + (accum[6] * 64) + (accum[5] * 32) +
(accum[4] * 16) + (accum[3] * 8) + (accum[2] * 4) +
(accum[1] * 2) + accum[0];
}
codeword[0] = (y_reg[10] * 1024) + (y_reg[9] * 512) + (y_reg[8] * 256) +
(y_reg[7] * 128) + (y_reg[6] * 64) + (y_reg[5] * 32) +
(y_reg[4] * 16) + (y_reg[3] * 8) + (y_reg[2] * 4) +
(y_reg[1] * 2) + y_reg[0];
for (i = 0; i < 8; i++) {
if (codeword[i] == 1365) {
codeword[i] = 0;
codeword[i + 1]++;
}
}
codeword[0] = (unsigned int) large_lo(&accum);
/* *** Step 4 - Inserting Additional Information into Codewords *** */
@ -584,7 +423,7 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Translate 4-state data pattern to symbol */
read = 0;
for (i = 0; i < strlen(data_pattern); i++) {
for (i = 0, len = (int) strlen(data_pattern); i < len; i++) {
if ((data_pattern[i] == '1') || (data_pattern[i] == '0')) {
set_module(symbol, 0, read);
}
@ -595,10 +434,22 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) {
read += 2;
}
symbol->row_height[0] = 3;
symbol->row_height[1] = 2;
symbol->row_height[2] = 3;
#ifdef COMPLIANT_HEIGHTS
/* USPS-B-3200 Section 2.3.1
Using bar pitch as X (1" / 43) ~ 0.023" based on 22 bars + 21 spaces per inch (bar width 0.015" - 0.025"),
height 0.125" - 0.165"
Tracker 0.048" (average of 0.039" - 0.057")
Ascender/descender 0.0965" (average of 0.082" - 0.111") less T = 0.0485"
*/
symbol->row_height[0] = 0.0485f * 43; /* 2.0855 */
symbol->row_height[1] = 0.048f * 43; /* 2.064 */
/* Note using max X for minimum and min X for maximum */
error_number = daft_set_height(symbol, 0.125f * 39 /*4.875*/, 0.165f * 47 /*7.755*/);
#else
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
daft_set_height(symbol, 0.0f, 0.0f);
#endif
symbol->rows = 3;
symbol->width = read - 1;
return error_number;

88
3rdparty/zint-2.10.0/backend/iso3166.h vendored Normal file
View File

@ -0,0 +1,88 @@
/*
* ISO 3166 country codes generated by "backend/tools/gen_iso3166_h.php"
*/
/*
libzint - the open source barcode library
Copyright (C) 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#ifndef ISO3166_H
#define ISO3166_H
/* Whether ISO 3166-1 numeric */
static int iso3166_numeric(int cc) {
static const unsigned char codes[112] = {
0x10, 0x15, 0x11, 0x91, 0x11, 0x11, 0x1D, 0x11,
0x51, 0x15, 0x50, 0x14, 0x11, 0x11, 0x11, 0x11,
0x10, 0x11, 0x11, 0x51, 0x44, 0xC4, 0x14, 0x91,
0x11, 0x18, 0x51, 0x44, 0x84, 0xC7, 0x44, 0x45,
0x54, 0x54, 0x18, 0x00, 0x11, 0x11, 0x11, 0x11,
0x11, 0x51, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x41, 0x11, 0x45, 0x46, 0x54, 0x44, 0x45,
0x44, 0x44, 0x44, 0x44, 0x11, 0x10, 0x1D, 0x11,
0x11, 0x11, 0xE9, 0x10, 0x10, 0x44, 0x44, 0x44,
0xB4, 0x87, 0x40, 0x11, 0x11, 0x11, 0x45, 0x44,
0x4C, 0x50, 0xD8, 0x44, 0x44, 0x44, 0x45, 0xC0,
0x47, 0x10, 0x10, 0x13, 0x10, 0x11, 0x11, 0x15,
0x11, 0x11, 0x11, 0x59, 0x91, 0x00, 0x04, 0x84,
0x07, 0x01, 0x44, 0x54, 0x00, 0x10, 0x84, 0x40,
};
int b = cc >> 3;
if (b < 0 || b >= 112) {
return 0;
}
return codes[b] & (1 << (cc & 0x7)) ? 1 : 0;
}
/* Whether ISO 3166-1 alpha2 */
static int iso3166_alpha2(const char *cc) {
static const unsigned char codes[85] = {
0x78, 0x59, 0xDF, 0xEE, 0xEF, 0xBD, 0xDD, 0xDE,
0x27, 0x3F, 0x84, 0x15, 0x80, 0xD4, 0x00, 0x0E,
0x00, 0x5C, 0x09, 0xB0, 0x9F, 0xFB, 0x15, 0x00,
0x8D, 0x06, 0x18, 0x78, 0x0F, 0x40, 0x40, 0x03,
0x00, 0x1D, 0x2B, 0xF4, 0x41, 0x81, 0x4F, 0xFD,
0xFC, 0xFF, 0xD7, 0x25, 0x4B, 0x08, 0x00, 0x01,
0x40, 0x3C, 0x8F, 0x53, 0x01, 0x00, 0x00, 0x40,
0x00, 0x51, 0xF1, 0xFD, 0xE7, 0x3A, 0xBB, 0x9F,
0x9A, 0x41, 0x10, 0x04, 0x57, 0x85, 0x40, 0x00,
0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
0x08, 0x04, 0x40, 0x00, 0x01,
};
int cc_int;
if (cc[0] < 'A' || cc[0] > 'Z' || cc[1] < 'A' || cc[1] > 'Z') {
return 0;
}
cc_int = (cc[0] - 'A') * 26 + (cc[1] - 'A');
return codes[cc_int >> 3] & (1 << (cc_int & 0x7)) ? 1 : 0;
}
#endif /* ISO3166_H */

View File

@ -1,8 +1,9 @@
/* composite.c - Tables for UCC.EAN Composite Symbols */
/*
* ISO 4217 currency codes generated by "backend/tools/gen_iso4217_h.php"
*/
/*
libzint - the open source barcode library
Copyright (C) 2008-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -30,44 +31,35 @@
SUCH DAMAGE.
*/
#define NUMERIC 110
#define ALPHA 97
#define ISOIEC 105
#define INVALID_CHAR 100
#define ANY_ENC 120
#define ALPHA_OR_ISO 121
#ifndef ISO4217_H
#define ISO4217_H
/* CC-A component coefficients from ISO/IEC 24728:2006 Annex F */
static const unsigned short int ccaCoeffs[30] = {
/* k = 4 */
522, 568, 723, 809,
/* k = 5 */
427, 919, 460, 155, 566,
/* k = 6 */
861, 285, 19, 803, 17, 766,
/* k = 7 */
76, 925, 537, 597, 784, 691, 437,
/* k = 8 */
237, 308, 436, 284, 646, 653, 428, 379
/* Whether ISO 4217-1 numeric */
static int iso4217_numeric(int cc) {
static const unsigned char codes[125] = {
0x00, 0x11, 0x00, 0x00, 0x11, 0x10, 0x1D, 0x10,
0x11, 0x01, 0x10, 0x04, 0x01, 0x11, 0x10, 0x10,
0x10, 0x01, 0x01, 0x11, 0x00, 0x44, 0x00, 0x90,
0x01, 0x08, 0x41, 0x40, 0x40, 0x41, 0x04, 0x00,
0x40, 0x40, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x11, 0x11, 0x10, 0x11, 0x11, 0x11, 0x01, 0x01,
0x10, 0x41, 0x11, 0x45, 0x46, 0x44, 0x04, 0x40,
0x40, 0x44, 0x00, 0x00, 0x11, 0x00, 0x05, 0x01,
0x11, 0x10, 0x30, 0x00, 0x10, 0x44, 0x40, 0x00,
0x04, 0x44, 0x40, 0x11, 0x01, 0x00, 0x00, 0x04,
0x48, 0x40, 0x00, 0x00, 0x00, 0x04, 0x44, 0x40,
0x45, 0x00, 0x00, 0x01, 0x00, 0x10, 0x11, 0x11,
0x00, 0x11, 0x11, 0x00, 0x81, 0x00, 0x04, 0x04,
0x04, 0x01, 0x00, 0x14, 0x00, 0x00, 0x44, 0x00,
0x20, 0x00, 0x00, 0x80, 0x7F, 0xB5, 0xFD, 0xFB,
0xBF, 0xBF, 0x3F, 0x47, 0xA4,
};
int b = cc >> 3;
/* rows, error codewords, k-offset of valid CC-A sizes from ISO/IEC 24723:2006 Table 9 */
static const char ccaVariants[51] = {
5, 6, 7, 8, 9, 10, 12, 4, 5, 6, 7, 8, 3, 4, 5, 6, 7,
4, 4, 5, 5, 6, 6, 7, 4, 5, 6, 7, 7, 4, 5, 6, 7, 8,
0, 0, 4, 4, 9, 9, 15, 0, 4, 9, 15, 15, 0, 4, 9, 15, 22
};
if (b < 0 || b >= 125) {
return 0;
}
return codes[b] & (1 << (cc & 0x7)) ? 1 : 0;
}
/* following is Left RAP, Centre RAP, Right RAP and Start Cluster from ISO/IEC 24723:2006 tables 10 and 11 */
static const char aRAPTable[68] = {
39, 1, 32, 8, 14, 43, 20, 11, 1, 5, 15, 21, 40, 43, 46, 34, 29,
0, 0, 0, 0, 0, 0, 0, 43, 33, 37, 47, 1, 20, 23, 26, 14, 9,
19, 33, 12, 40, 46, 23, 52, 23, 13, 17, 27, 33, 52, 3, 6, 46, 41,
6, 0, 3, 3, 3, 0, 3, 3, 0, 3, 6, 6, 0, 0, 0, 0, 3
};
/* Row Address Patterns are as defined in pdf417.h */
#endif /* ISO4217_H */

1863
3rdparty/zint-2.10.0/backend/ksx1001.h vendored Normal file

File diff suppressed because it is too large Load Diff

319
3rdparty/zint-2.10.0/backend/large.c vendored Normal file
View File

@ -0,0 +1,319 @@
/* large.c - Handles binary manipulation of large numbers */
/*
libzint - the open source barcode library
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
/* `large_mul_u64()` and `large_div_u64()` are adapted from articles by F. W. Jacob
* https://www.codeproject.com/Tips/618570/UInt-Multiplication-Squaring
* "This article, along with any associated source code and files, is licensed under The BSD License"
* http://www.codeproject.com/Tips/785014/UInt-Division-Modulus
* "This article, along with any associated source code and files, is licensed under The BSD License"
*
* These in turn are based on Hacker's Delight (2nd Edition, 2012) by Henry S. Warren, Jr.
* "You are free to use, copy, and distribute any of the code on this web site, whether modified by you or not."
* https://web.archive.org/web/20190716204559/http://www.hackersdelight.org/permissions.htm
*
* `clz_u64()` and other bits and pieces are adapted from r128.h by Alan Hickman (fahickman)
* https://github.com/fahickman/r128/blob/master/r128.h
* "R128 is released into the public domain. See LICENSE for details." LICENSE is The Unlicense.
*/
#include <stdio.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h"
#include "large.h"
#define MASK32 0xFFFFFFFF
/* Convert decimal string `s` of (at most) length `length` to 64-bit and place in 128-bit `t` */
INTERNAL void large_load_str_u64(large_int *t, const unsigned char *s, const int length) {
uint64_t val = 0;
const unsigned char *se = s + length;
for (; s < se && *s >= '0' && *s <= '9'; s++) {
val *= 10;
val += *s - '0';
}
t->lo = val;
t->hi = 0;
}
/* Add 128-bit `s` to 128-bit `t` */
INTERNAL void large_add(large_int *t, const large_int *s) {
t->lo += s->lo;
t->hi += s->hi + (t->lo < s->lo);
}
/* Add 64-bit `s` to 128-bit `t` */
INTERNAL void large_add_u64(large_int *t, const uint64_t s) {
t->lo += s;
if (t->lo < s) {
t->hi++;
}
}
/* Subtract 64-bit `s` from 128-bit `t` */
INTERNAL void large_sub_u64(large_int *t, const uint64_t s) {
uint64_t r = t->lo - s;
if (r > t->lo) {
t->hi--;
}
t->lo = r;
}
/* Multiply 128-bit `t` by 64-bit `s`
* See Jacob `mult64to128()` and Warren Section 8-2
* Note '0' denotes low 32-bits, '1' high 32-bits
* if p00 == s0 * tlo0
* k00 == carry of p00
* p01 == s0 * tlo1
* k01 == carry of (p01 + k00)
* p10 == s1 * tlo0
* k10 == carry of p10
* p11 == s1 * tlo1 (unmasked, i.e. including unshifted carry if any)
* then t->lo == (p01 + p10 + k00) << 32 + p00
* and t->hi == p11 + k10 + k01 + thi * s
*
* (thi) tlo1 tlo0
* x s1 s0
* -------------------------
* p00
* k01 p01 + k00
* p10
* p11 + k10
*/
INTERNAL void large_mul_u64(large_int *t, const uint64_t s) {
uint64_t thi = t->hi;
uint64_t tlo0 = t->lo & MASK32;
uint64_t tlo1 = t->lo >> 32;
uint64_t s0 = s & MASK32;
uint64_t s1 = s >> 32;
uint64_t tmp = s0 * tlo0; /* p00 (unmasked) */
uint64_t p00 = tmp & MASK32;
uint64_t k10;
tmp = (s1 * tlo0) + (tmp >> 32); /* (p10 + k00) (p10 unmasked) */
k10 = tmp >> 32;
tmp = (s0 * tlo1) + (tmp & MASK32); /* (p01 + p10 + k00) (p01 unmasked) */
t->lo = (tmp << 32) + p00; /* (p01 + p10 + k00) << 32 + p00 (note any carry from unmasked p01 shifted out) */
t->hi = (s1 * tlo1) + k10 + (tmp >> 32) + thi * s; /* p11 + k10 + k01 + thi * s */
}
/* Count leading zeroes. See Hickman `r128__clz64()` */
STATIC_UNLESS_ZINT_TEST int clz_u64(uint64_t x) {
uint64_t n = 64, y;
y = x >> 32; if (y) { n -= 32; x = y; }
y = x >> 16; if (y) { n -= 16; x = y; }
y = x >> 8; if (y) { n -= 8; x = y; }
y = x >> 4; if (y) { n -= 4; x = y; }
y = x >> 2; if (y) { n -= 2; x = y; }
y = x >> 1; if (y) { n -= 1; x = y; }
return (int) (n - x);
}
/* Divide 128-bit dividend `t` by 64-bit divisor `v`
* See Jacob `divmod128by128/64()` and Warren Section 92 (divmu64.c.txt)
* Note digits are 32-bit parts */
INTERNAL uint64_t large_div_u64(large_int *t, uint64_t v) {
const uint64_t b = 0x100000000; /* Number base (2**32) */
uint64_t qhi = 0; /* High digit of returned quotient */
uint64_t tnhi, tnlo, tnlo1, tnlo0, vn1, vn0; /* Normalized forms of (parts of) t and v */
uint64_t rnhilo1; /* Remainder after dividing 1st 3 digits of t by v */
uint64_t qhat1, qhat0; /* Estimated quotient digits */
uint64_t rhat; /* Remainder of estimated quotient digit */
uint64_t tmp;
int norm_shift;
/* Deal with single-digit (i.e. 32-bit) divisor here */
if (v < b) {
qhi = t->hi / v;
tmp = ((t->hi - qhi * v) << 32) + (t->lo >> 32); /* k * b + tlo1 */
qhat1 = tmp / v;
tmp = ((tmp - qhat1 * v) << 32) + (t->lo & MASK32); /* k * b + tlo0 */
qhat0 = tmp / v;
t->lo = (qhat1 << 32) | qhat0;
t->hi = qhi;
return tmp - qhat0 * v;
}
/* Main algorithm requires t->hi < v */
if (t->hi >= v) {
qhi = t->hi / v;
t->hi %= v;
}
/* Normalize by shifting v left just enough so that its high-order
* bit is on, and shift t left the same amount. Note don't need extra
* high-end digit for dividend as t->hi < v */
norm_shift = clz_u64(v);
v <<= norm_shift;
vn1 = v >> 32;
vn0 = v & MASK32;
if (norm_shift > 0) {
tnhi = (t->hi << norm_shift) | (t->lo >> (64 - norm_shift));
tnlo = t->lo << norm_shift;
} else {
tnhi = t->hi;
tnlo = t->lo;
}
tnlo1 = tnlo >> 32;
tnlo0 = tnlo & MASK32;
/* Compute qhat1 estimate */
qhat1 = tnhi / vn1; /* Divide first digit of v into first 2 digits of t */
rhat = tnhi % vn1;
/* Loop until qhat1 one digit and <= (rhat * b + 3rd digit of t) / vn0 */
for (tmp = qhat1 * vn0; qhat1 >= b || tmp > (rhat << 32) + tnlo1; tmp -= vn0) {
--qhat1;
rhat += vn1;
if (rhat >= b) { /* Must check here as (rhat << 32) would overflow */
break; /* qhat1 * vn0 < b * b (since vn0 < b) */
}
}
/* Note qhat1 will be exact as have fully divided by 2-digit divisor
* (can only be too high by 1 (and require "add back" step) if divisor at least 3 digits) */
/* Note high digit (if any) of both tnhi and (qhat1 * v) shifted out */
rnhilo1 = (tnhi << 32) + tnlo1 - (qhat1 * v);
/* Compute qhat0 estimate */
qhat0 = rnhilo1 / vn1; /* Divide first digit of v into 2-digit remains of first 3 digits of t */
rhat = rnhilo1 % vn1;
/* Loop until qhat0 one digit and <= (rhat * b + 4th digit of t) / vn0 */
for (tmp = qhat0 * vn0; qhat0 >= b || tmp > (rhat << 32) + tnlo0; tmp -= vn0) {
--qhat0;
rhat += vn1;
if (rhat >= b) {
break;
}
}
/* Similarly qhat0 will be exact */
t->lo = (qhat1 << 32) | qhat0;
t->hi = qhi;
/* Unnormalize remainder */
return ((rnhilo1 << 32) + tnlo0 - (qhat0 * v)) >> norm_shift;
}
/* Unset a bit (zero-based) */
INTERNAL void large_unset_bit(large_int *t, const int bit) {
if (bit < 64) {
t->lo &= ~(((uint64_t) 1) << bit);
} else if (bit < 128) {
t->hi &= ~(((uint64_t) 1) << (bit - 64));
}
}
/* Output large_int into an unsigned int array of size `size`, each element containing `bits` bits */
INTERNAL void large_uint_array(const large_int *t, unsigned int *uint_array, const int size, int bits) {
int i, j;
uint64_t mask;
if (bits <= 0) {
bits = 8;
} else if (bits > 32) {
bits = 32;
}
mask = ~(((uint64_t) -1) << bits);
for (i = 0, j = 0; i < size && j < 64; i++, j += bits) {
uint_array[size - 1 - i] = (unsigned int) ((t->lo >> j) & mask); /* Little-endian order */
}
if (i < size) {
if (j != 64) {
j -= 64;
/* (first j bits of t->hi) << (bits - j) | (last (bits - j) bits of t->lo) */
uint_array[size - i] = (unsigned int) (((t->hi & ~((((uint64_t) -1) << j))) << (bits - j))
| (t->lo >> (64 - (bits - j)) & mask));
} else {
j = 0;
}
for (; i < size && j < 64; i++, j += bits) {
uint_array[size - 1 - i] = (unsigned int) ((t->hi >> j) & mask);
}
if (i < size) {
memset(uint_array, 0, sizeof(unsigned int) * (size - i));
}
}
}
/* As `large_uint_array()` above, except output to unsigned char array */
INTERNAL void large_uchar_array(const large_int *t, unsigned char *uchar_array, const int size, int bits) {
int i;
#ifndef _MSC_VER
unsigned int uint_array[size ? size : 1]; /* Avoid run-time warning if size is 0 */
#else
unsigned int *uint_array = (unsigned int *) _alloca(sizeof(unsigned int) * (size ? size : 1));
#endif
large_uint_array(t, uint_array, size, bits);
for (i = 0; i < size; i++) {
uchar_array[i] = (unsigned char) uint_array[i];
}
}
/* Output formatted large_int to stdout */
INTERNAL void large_print(const large_int *t) {
char buf[35]; /* 2 (0x) + 32 (hex) + 1 */
puts(large_dump(t, buf));
}
/* Format large_int into buffer, which should be at least 35 chars in size */
INTERNAL char *large_dump(const large_int *t, char *buf) {
unsigned int tlo1 = (unsigned int) (large_lo(t) >> 32);
unsigned int tlo0 = (unsigned int) (large_lo(t) & MASK32);
unsigned int thi1 = (unsigned int) (large_hi(t) >> 32);
unsigned int thi0 = (unsigned int) (large_hi(t) & MASK32);
if (thi1) {
sprintf(buf, "0x%X%08X%08X%08X", thi1, thi0, tlo1, tlo0);
} else if (thi0) {
sprintf(buf, "0x%X%08X%08X", thi0, tlo1, tlo0);
} else if (tlo1) {
sprintf(buf, "0x%X%08X", tlo1, tlo0);
} else {
sprintf(buf, "0x%X", tlo0);
}
return buf;
}

80
3rdparty/zint-2.10.0/backend/large.h vendored Normal file
View File

@ -0,0 +1,80 @@
/* large.h - Handles binary manipulation of large numbers */
/*
libzint - the open source barcode library
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#ifndef __LARGE_H
#define __LARGE_H
#ifndef _MSC_VER
#include <stdint.h>
#else
#include "ms_stdint.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct { uint64_t lo; uint64_t hi; } large_int;
#define large_lo(s) ((s)->lo)
#define large_hi(s) ((s)->hi)
/* Set 128-bit `t` from 128-bit `s` */
#define large_load(t, s) do { (t)->lo = (s)->lo; (t)->hi = (s)->hi; } while (0)
/* Set 128-bit `t` from 64-bit `s` */
#define large_load_u64(t, s) do { (t)->lo = (s); (t)->hi = 0; } while (0)
INTERNAL void large_load_str_u64(large_int *t, const unsigned char *s, const int length);
INTERNAL void large_add(large_int *t, const large_int *s);
INTERNAL void large_add_u64(large_int *t, const uint64_t s);
INTERNAL void large_sub_u64(large_int *t, const uint64_t s);
INTERNAL void large_mul_u64(large_int *t, const uint64_t s);
INTERNAL uint64_t large_div_u64(large_int *t, uint64_t v);
INTERNAL void large_unset_bit(large_int *t, const int bit);
INTERNAL void large_uint_array(const large_int *t, unsigned int *uint_array, const int size, int bits);
INTERNAL void large_uchar_array(const large_int *t, unsigned char *uchar_array, const int size, int bits);
INTERNAL void large_print(const large_int *t);
INTERNAL char *large_dump(const large_int *t, char *buf);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __LARGE_H */

1575
3rdparty/zint-2.10.0/backend/library.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,13 +2,16 @@
#include <windows.h>
#include <winver.h>
#define VER_FILEVERSION 2,10,0,0
#define VER_FILEVERSION_STR "2,10,0,0\0"
#ifdef GCC_WINDRES
VS_VERSION_INFO VERSIONINFO
#else
VS_VERSION_INFO VERSIONINFO
#endif
FILEVERSION 2,6,0,0
PRODUCTVERSION 2,6,0,0
FILEVERSION VER_FILEVERSION
PRODUCTVERSION VER_FILEVERSION
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
@ -25,14 +28,14 @@ BEGIN
//language ID = U.S. English, char set = Windows, Multilingual
BEGIN
VALUE "FileDescription", "libzint barcode library\0"
VALUE "FileVersion", "2.6.0.0\0"
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "InternalName", "zint.dll\0"
VALUE "LegalCopyright", "Copyright © 2017 Robin Stuart & BogDan Vatra\0"
VALUE "LegalCopyright", "Copyright © 2021 Robin Stuart & BogDan Vatra\0"
VALUE "OriginalFilename", "zint.dll\0"
VALUE "ProductName", "libzint\0"
VALUE "ProductVersion", "2.6.0.0\0"
VALUE "ProductVersion", VER_FILEVERSION_STR
VALUE "License", "BSD License version 3\0"
VALUE "WWW", "http://www.sourceforge.net/projects/zint"
VALUE "WWW", "http://www.sourceforge.net/projects/zint\0"
END
END
BLOCK "VarFileInfo"

510
3rdparty/zint-2.10.0/backend/mailmark.c vendored Normal file
View File

@ -0,0 +1,510 @@
/* mailmark.c - Royal Mail 4-state Mailmark barcodes */
/*
libzint - the open source barcode library
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
/*
* Developed in accordance with "Royal Mail Mailmark barcode C encoding and deconding instructions"
* (https://www.royalmail.com/sites/default/files/Mailmark-4-state-barcode-C-encoding-and-decoding-instructions-Sept-2015.pdf)
* and "Royal Mail Mailmark barcode L encoding and decoding"
* (https://www.royalmail.com/sites/default/files/Mailmark-4-state-barcode-L-encoding-and-decoding-instructions-Sept-2015.pdf)
*
*/
#include <stdio.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h"
#include "large.h"
#include "reedsol.h"
#define RUBIDIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ "
// Allowed character values from Table 3
#define SET_F "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define SET_L "ABDEFGHJLNPQRSTUWXYZ"
#define SET_N "0123456789"
#define SET_S " "
static const char *postcode_format[6] = {
"FNFNLLNLS", "FFNNLLNLS", "FFNNNLLNL", "FFNFNLLNL", "FNNLLNLSS", "FNNNLLNLS"
};
// Data/Check Symbols from Table 5
static const unsigned char data_symbol_odd[32] = {
0x01, 0x02, 0x04, 0x07, 0x08, 0x0B, 0x0D, 0x0E, 0x10, 0x13, 0x15, 0x16,
0x19, 0x1A, 0x1C, 0x1F, 0x20, 0x23, 0x25, 0x26, 0x29, 0x2A, 0x2C, 0x2F,
0x31, 0x32, 0x34, 0x37, 0x38, 0x3B, 0x3D, 0x3E
};
static const unsigned char data_symbol_even[30] = {
0x03, 0x05, 0x06, 0x09, 0x0A, 0x0C, 0x0F, 0x11, 0x12, 0x14, 0x17, 0x18,
0x1B, 0x1D, 0x1E, 0x21, 0x22, 0x24, 0x27, 0x28, 0x2B, 0x2D, 0x2E, 0x30,
0x33, 0x35, 0x36, 0x39, 0x3A, 0x3C
};
static const unsigned short extender_group_c[22] = {
3, 5, 7, 11, 13, 14, 16, 17, 19, 0, 1, 2, 4, 6, 8, 9, 10, 12, 15, 18, 20, 21
};
static const unsigned short extender_group_l[26] = {
2, 5, 7, 8, 13, 14, 15, 16, 21, 22, 23, 0, 1, 3, 4, 6, 9, 10, 11, 12, 17, 18, 19, 20, 24, 25
};
static int verify_character(char input, char type) {
int val = 0;
switch (type) {
case 'F':
val = posn(SET_F, input);
break;
case 'L':
val = posn(SET_L, input);
break;
case 'N':
val = posn(SET_N, input);
break;
case 'S':
val = posn(SET_S, input);
break;
}
if (val == -1) {
return 0;
} else {
return 1;
}
}
static int verify_postcode(char *postcode, int type) {
int i;
char pattern[11];
strcpy(pattern, postcode_format[type - 1]);
for (i = 0; i < 9; i++) {
if (!(verify_character(postcode[i], pattern[i]))) {
return 1;
}
}
return 0;
}
INTERNAL int daft_set_height(struct zint_symbol *symbol, float min_height, float max_height);
/* Royal Mail Mailmark */
INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) {
char local_source[28];
int format;
int version_id;
int mail_class;
int supply_chain_id;
unsigned int item_id;
char postcode[10];
int postcode_type;
char pattern[10];
large_int destination_postcode;
large_int b;
large_int cdv;
unsigned char data[26];
int data_top, data_step;
unsigned char check[7];
unsigned int extender[27];
char bar[80];
int check_count;
int i, j, len;
rs_t rs;
int error_number = 0;
if (length > 26) {
strcpy(symbol->errtxt, "580: Input too long (26 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
ustrcpy(local_source, source);
if (length < 22) {
for (i = length; i <= 22; i++) {
strcat(local_source, " ");
}
length = 22;
}
if ((length > 22) && (length < 26)) {
for (i = length; i <= 26; i++) {
strcat(local_source, " ");
}
length = 26;
}
to_upper((unsigned char *) local_source);
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Producing Mailmark %s\n", local_source);
}
if (is_sane(RUBIDIUM, (unsigned char *) local_source, length) != 0) {
strcpy(symbol->errtxt, "581: Invalid character in data (alphanumerics and space only)");
return ZINT_ERROR_INVALID_DATA;
}
// Format is in the range 0-4
format = ctoi(local_source[0]);
if ((format < 0) || (format > 4)) {
strcpy(symbol->errtxt, "582: Format out of range (0 to 4)");
return ZINT_ERROR_INVALID_DATA;
}
// Version ID is in the range 1-4
version_id = ctoi(local_source[1]) - 1;
if ((version_id < 0) || (version_id > 3)) {
strcpy(symbol->errtxt, "583: Version ID out of range (1 to 4)");
return ZINT_ERROR_INVALID_DATA;
}
// Class is in the range 0-9,A-E
mail_class = ctoi(local_source[2]);
if ((mail_class < 0) || (mail_class > 14)) {
strcpy(symbol->errtxt, "584: Class out of range (0 to 9 and A to E)");
return ZINT_ERROR_INVALID_DATA;
}
// Supply Chain ID is 2 digits for barcode C and 6 digits for barcode L
supply_chain_id = 0;
for (i = 3; i < (length - 17); i++) {
if ((local_source[i] >= '0') && (local_source[i] <= '9')) {
supply_chain_id *= 10;
supply_chain_id += ctoi(local_source[i]);
} else {
strcpy(symbol->errtxt, "585: Invalid Supply Chain ID (digits only)");
return ZINT_ERROR_INVALID_DATA;
}
}
// Item ID is 8 digits
item_id = 0;
for (i = length - 17; i < (length - 9); i++) {
if ((local_source[i] >= '0') && (local_source[i] <= '9')) {
item_id *= 10;
item_id += ctoi(local_source[i]);
} else {
strcpy(symbol->errtxt, "586: Invalid Item ID (digits only)");
return ZINT_ERROR_INVALID_DATA;
}
}
// Separate Destination Post Code plus DPS field
for (i = 0; i < 9; i++) {
postcode[i] = local_source[(length - 9) + i];
}
postcode[9] = '\0';
// Detect postcode type
/* postcode_type is used to select which format of postcode
*
* 1 = FNFNLLNLS
* 2 = FFNNLLNLS
* 3 = FFNNNLLNL
* 4 = FFNFNLLNL
* 5 = FNNLLNLSS
* 6 = FNNNLLNLS
* 7 = International designation
*/
if (strcmp(postcode, "XY11 ") == 0) {
postcode_type = 7;
} else {
if (postcode[7] == ' ') {
postcode_type = 5;
} else {
if (postcode[8] == ' ') {
// Types 1, 2 and 6
if ((postcode[1] >= '0') && (postcode[1] <= '9')) {
if ((postcode[2] >= '0') && (postcode[2] <= '9')) {
postcode_type = 6;
} else {
postcode_type = 1;
}
} else {
postcode_type = 2;
}
} else {
// Types 3 and 4
if ((postcode[3] >= '0') && (postcode[3] <= '9')) {
postcode_type = 3;
} else {
postcode_type = 4;
}
}
}
}
// Verify postcode type
if (postcode_type != 7) {
if (verify_postcode(postcode, postcode_type) != 0) {
strcpy(symbol->errtxt, "587: Invalid postcode");
return ZINT_ERROR_INVALID_DATA;
}
}
// Convert postcode to internal user field
large_load_u64(&destination_postcode, 0);
if (postcode_type != 7) {
strcpy(pattern, postcode_format[postcode_type - 1]);
large_load_u64(&b, 0);
for (i = 0; i < 9; i++) {
switch (pattern[i]) {
case 'F':
large_mul_u64(&b, 26);
large_add_u64(&b, posn(SET_F, postcode[i]));
break;
case 'L':
large_mul_u64(&b, 20);
large_add_u64(&b, posn(SET_L, postcode[i]));
break;
case 'N':
large_mul_u64(&b, 10);
large_add_u64(&b, posn(SET_N, postcode[i]));
break;
// case 'S' ignored as value is 0
}
}
large_load(&destination_postcode, &b);
// destination_postcode = a + b
large_load_u64(&b, 1);
if (postcode_type == 1) {
large_add(&destination_postcode, &b);
}
large_add_u64(&b, 5408000000);
if (postcode_type == 2) {
large_add(&destination_postcode, &b);
}
large_add_u64(&b, 5408000000);
if (postcode_type == 3) {
large_add(&destination_postcode, &b);
}
large_add_u64(&b, 54080000000);
if (postcode_type == 4) {
large_add(&destination_postcode, &b);
}
large_add_u64(&b, 140608000000);
if (postcode_type == 5) {
large_add(&destination_postcode, &b);
}
large_add_u64(&b, 208000000);
if (postcode_type == 6) {
large_add(&destination_postcode, &b);
}
}
// Conversion from Internal User Fields to Consolidated Data Value
// Set CDV to 0
large_load_u64(&cdv, 0);
// Add Destination Post Code plus DPS
large_add(&cdv, &destination_postcode);
// Multiply by 100,000,000
large_mul_u64(&cdv, 100000000);
// Add Item ID
large_add_u64(&cdv, item_id);
if (length == 22) {
// Barcode C - Multiply by 100
large_mul_u64(&cdv, 100);
} else {
// Barcode L - Multiply by 1,000,000
large_mul_u64(&cdv, 1000000);
}
// Add Supply Chain ID
large_add_u64(&cdv, supply_chain_id);
// Multiply by 15
large_mul_u64(&cdv, 15);
// Add Class
large_add_u64(&cdv, mail_class);
// Multiply by 5
large_mul_u64(&cdv, 5);
// Add Format
large_add_u64(&cdv, format);
// Multiply by 4
large_mul_u64(&cdv, 4);
// Add Version ID
large_add_u64(&cdv, version_id);
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("DPC type %d\n", postcode_type);
printf("CDV: ");
large_print(&cdv);
}
if (length == 22) {
data_top = 15;
data_step = 8;
check_count = 6;
} else {
data_top = 18;
data_step = 10;
check_count = 7;
}
// Conversion from Consolidated Data Value to Data Numbers
for (j = data_top; j >= (data_step + 1); j--) {
data[j] = (unsigned char) large_div_u64(&cdv, 32);
}
for (j = data_step; j >= 0; j--) {
data[j] = (unsigned char) large_div_u64(&cdv, 30);
}
// Generation of Reed-Solomon Check Numbers
rs_init_gf(&rs, 0x25);
rs_init_code(&rs, check_count, 1);
rs_encode(&rs, (data_top + 1), data, check);
// Append check digits to data
for (i = 1; i <= check_count; i++) {
data[data_top + i] = check[check_count - i];
}
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Codewords: ");
for (i = 0; i <= data_top + check_count; i++) {
printf("%d ", (int) data[i]);
}
printf("\n");
}
// Conversion from Data Numbers and Check Numbers to Data Symbols and Check Symbols
for (i = 0; i <= data_step; i++) {
data[i] = data_symbol_even[data[i]];
}
for (i = data_step + 1; i <= (data_top + check_count); i++) {
data[i] = data_symbol_odd[data[i]];
}
// Conversion from Data Symbols and Check Symbols to Extender Groups
for (i = 0; i < length; i++) {
if (length == 22) {
extender[extender_group_c[i]] = data[i];
} else {
extender[extender_group_l[i]] = data[i];
}
}
// Conversion from Extender Groups to Bar Identifiers
strcpy(bar, "");
for (i = 0; i < length; i++) {
for (j = 0; j < 3; j++) {
switch (extender[i] & 0x24) {
case 0x24:
strcat(bar, "F");
break;
case 0x20:
if (i % 2) {
strcat(bar, "D");
} else {
strcat(bar, "A");
}
break;
case 0x04:
if (i % 2) {
strcat(bar, "A");
} else {
strcat(bar, "D");
}
break;
default:
strcat(bar, "T");
break;
}
extender[i] = extender[i] << 1;
}
}
bar[(length * 3)] = '\0';
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Bar pattern: %s\n", bar);
}
/* Translate 4-state data pattern to symbol */
j = 0;
for (i = 0, len = (int) strlen(bar); i < len; i++) {
if ((bar[i] == 'F') || (bar[i] == 'A')) {
set_module(symbol, 0, j);
}
set_module(symbol, 1, j);
if ((bar[i] == 'F') || (bar[i] == 'D')) {
set_module(symbol, 2, j);
}
j += 2;
}
#ifdef COMPLIANT_HEIGHTS
/* Royal Mail Mailmark Barcode Definition Document (15 Sept 2015) Section 3.5.1
https://www.royalmail.com/sites/default/files/Royal-Mail-Mailmark-barcode-definition-document-September-2015.pdf
Using bar pitch as X (25.4mm / 42.3) ~ 0.6mm based on 21.2 bars + 21.1 spaces per 25.4mm (bar width 0.38-63mm)
Using recommended 1.9mm and 1.3mm heights for Ascender/Descenders and Trackers resp. as defaults
Min height 4.22mm * 39 (max pitch) / 25.4mm ~ 6.47, max height 5.84mm * 47 (min pitch) / 25.4mm ~ 10.8
*/
symbol->row_height[0] = (float) ((1.9 * 42.3) / 25.4); /* ~3.16 */
symbol->row_height[1] = (float) ((1.3 * 42.3) / 25.4); /* ~2.16 */
/* Note using max X for minimum and min X for maximum */
error_number = daft_set_height(symbol, (float) ((4.22 * 39) / 25.4), (float) ((5.84 * 47) / 25.4));
#else
symbol->row_height[0] = 4.0f;
symbol->row_height[1] = 2.0f;
daft_set_height(symbol, 0.0f, 0.0f);
#endif
symbol->rows = 3;
symbol->width = j - 1;
return error_number;
}

700
3rdparty/zint-2.10.0/backend/maxicode.c vendored Normal file
View File

@ -0,0 +1,700 @@
/* maxicode.c - Handles Maxicode */
/*
libzint - the open source barcode library
Copyright (C) 2010-2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
/* Includes corrections thanks to Monica Swanson @ Source Technologies */
#include <stdio.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h"
#include "maxicode.h"
#include "reedsol.h"
/* Handles error correction of primary message */
static void maxi_do_primary_check(unsigned char maxi_codeword[144]) {
unsigned char results[15];
int j;
int datalen = 10;
int ecclen = 10;
rs_t rs;
rs_init_gf(&rs, 0x43);
rs_init_code(&rs, ecclen, 1);
rs_encode(&rs, datalen, maxi_codeword, results);
for (j = 0; j < ecclen; j += 1)
maxi_codeword[ datalen + j] = results[ecclen - 1 - j];
}
/* Handles error correction of odd characters in secondary */
static void maxi_do_secondary_chk_odd(unsigned char maxi_codeword[144], const int ecclen) {
unsigned char data[100];
unsigned char results[30];
int j;
int datalen = 68;
rs_t rs;
rs_init_gf(&rs, 0x43);
rs_init_code(&rs, ecclen, 1);
if (ecclen == 20)
datalen = 84;
for (j = 1; j < datalen; j += 2)
data[(j - 1) / 2] = maxi_codeword[j + 20];
rs_encode(&rs, datalen / 2, data, results);
for (j = 0; j < (ecclen); j += 1)
maxi_codeword[ datalen + (2 * j) + 1 + 20 ] = results[ecclen - 1 - j];
}
/* Handles error correction of even characters in secondary */
static void maxi_do_secondary_chk_even(unsigned char maxi_codeword[144], const int ecclen) {
unsigned char data[100];
unsigned char results[30];
int j;
int datalen = 68;
rs_t rs;
if (ecclen == 20)
datalen = 84;
rs_init_gf(&rs, 0x43);
rs_init_code(&rs, ecclen, 1);
for (j = 0; j < datalen + 1; j += 2)
data[j / 2] = maxi_codeword[j + 20];
rs_encode(&rs, datalen / 2, data, results);
for (j = 0; j < (ecclen); j += 1)
maxi_codeword[ datalen + (2 * j) + 20] = results[ecclen - 1 - j];
}
/* Moves everything up so that a shift or latch can be inserted */
static void maxi_bump(unsigned char set[], unsigned char character[], const int bump_posn, int *p_length) {
if (bump_posn < 143) {
memmove(set + bump_posn + 1, set + bump_posn, 143 - bump_posn);
memmove(character + bump_posn + 1, character + bump_posn, 143 - bump_posn);
}
(*p_length)++; /* Increment length regardless to make sure too long always triggered */
}
/* If the value is present in array, return the value, else return badvalue */
static int value_in_array(const unsigned char val, const unsigned char arr[], const int badvalue,
const int arrLength) {
int i;
for (i = 0; i < arrLength; i++) {
if (arr[i] == val) return val;
}
return badvalue;
}
/* Choose the best set from previous and next set in the range of the setval array, if no value can be found we
* return setval[0] */
static int bestSurroundingSet(const int index, const int length, const unsigned char set[],
const unsigned char setval[], const int setLength) {
int badValue = -1;
int option1 = value_in_array(set[index - 1], setval, badValue, setLength);
if (index + 1 < length) {
// we have two options to check (previous & next)
int option2 = value_in_array(set[index + 1], setval, badValue, setLength);
if (option2 != badValue && option1 > option2) {
return option2;
}
}
if (option1 != badValue) {
return option1;
}
return setval[0];
}
/* Format text according to Appendix A */
static int maxi_text_process(unsigned char maxi_codeword[144], const int mode, const unsigned char in_source[],
int length, const int eci, const int scm_vv, const int debug_print) {
unsigned char set[144], character[144] = {0};
int i, count, current_set, padding_set;
static const unsigned char set15[2] = { 1, 5 };
static const unsigned char set12[2] = { 1, 2 };
static const unsigned char set12345[5] = { 1, 2, 3, 4, 5 };
const unsigned char *source = in_source;
#ifndef _MSC_VER
unsigned char source_buf[length + 9]; /* For prefixing 9-character SCM sequence */
#else
unsigned char *source_buf = (unsigned char *) _alloca(length + 9);
#endif
if (length > 144) {
return ZINT_ERROR_TOO_LONG;
}
if (scm_vv != -1) { /* Add SCM prefix */
if (length > 135) {
return ZINT_ERROR_TOO_LONG;
}
sprintf((char *) source_buf, "[)>\03601\035%02d", scm_vv); /* [)>\R01\Gvv */
memcpy(source_buf + 9, in_source, length);
source = source_buf;
length += 9;
}
memset(set, 255, 144);
for (i = 0; i < length; i++) {
/* Look up characters in table from Appendix A - this gives
value and code set for most characters */
set[i] = maxiCodeSet[source[i]];
character[i] = maxiSymbolChar[source[i]];
}
/* If a character can be represented in more than one code set,
pick which version to use */
if (set[0] == 0) {
if (character[0] == 13) {
character[0] = 0;
}
set[0] = 1;
}
for (i = 1; i < length; i++) {
if (set[i] == 0) {
/* Special character */
if (character[i] == 13) {
/* Carriage Return */
set[i] = bestSurroundingSet(i, length, set, set15, 2);
if (set[i] == 5) {
character[i] = 13;
} else {
character[i] = 0;
}
} else if (character[i] == 28) {
/* FS */
set[i] = bestSurroundingSet(i, length, set, set12345, 5);
if (set[i] == 5) {
character[i] = 32;
}
} else if (character[i] == 29) {
/* GS */
set[i] = bestSurroundingSet(i, length, set, set12345, 5);
if (set[i] == 5) {
character[i] = 33;
}
} else if (character[i] == 30) {
/* RS */
set[i] = bestSurroundingSet(i, length, set, set12345, 5);
if (set[i] == 5) {
character[i] = 34;
}
} else if (character[i] == 32) {
/* Space */
set[i] = bestSurroundingSet(i, length, set, set12345, 5);
if (set[i] == 1) {
character[i] = 32;
} else if (set[i] == 2) {
character[i] = 47;
} else {
character[i] = 59;
}
} else if (character[i] == 44) {
/* Comma */
set[i] = bestSurroundingSet(i, length, set, set12, 2);
if (set[i] == 2) {
character[i] = 48;
}
} else if (character[i] == 46) {
/* Full Stop */
set[i] = bestSurroundingSet(i, length, set, set12, 2);
if (set[i] == 2) {
character[i] = 49;
}
} else if (character[i] == 47) {
/* Slash */
set[i] = bestSurroundingSet(i, length, set, set12, 2);
if (set[i] == 2) {
character[i] = 50;
}
} else if (character[i] == 58) {
/* Colon */
set[i] = bestSurroundingSet(i, length, set, set12, 2);
if (set[i] == 2) {
character[i] = 51;
}
}
}
}
padding_set = set[length - 1] == 2 ? 2 : 1;
for (i = length; i < 144; i++) {
/* Add the padding */
set[i] = padding_set;
character[i] = 33;
}
/* Find candidates for number compression */
/* Note the prohibition on number compression in the primary message in ISO/IEC 16023:2000 B.1 (1)
applies to modes 2 & 3 only */
count = 0;
for (i = 0; i < 144; i++) {
if ((set[i] == 1) && ((character[i] >= 48) && (character[i] <= 57))) {
/* Character is a number */
count++;
if (count == 9) {
/* Nine digits in a row can be compressed */
memset(set + i - 8, 6, 9); /* Set set of nine digits to 6 */
count = 0;
}
} else {
count = 0;
}
}
/* Add shift and latch characters */
current_set = 1;
i = 0;
do {
if ((set[i] != current_set) && (set[i] != 6)) {
switch (set[i]) {
case 1:
if (current_set == 2) { /* Set B */
if (i + 1 < 144 && set[i + 1] == 1) {
if (i + 2 < 144 && set[i + 2] == 1) {
if (i + 3 < 144 && set[i + 3] == 1) {
/* Latch A */
maxi_bump(set, character, i, &length);
character[i] = 63; /* Set B Latch A */
current_set = 1;
i += 3; /* Next 3 Set A so skip over */
if (debug_print) printf("LCHA ");
} else {
/* 3 Shift A */
maxi_bump(set, character, i, &length);
character[i] = 57; /* Set B triple shift A */
i += 2; /* Next 2 Set A so skip over */
if (debug_print) printf("3SHA ");
}
} else {
/* 2 Shift A */
maxi_bump(set, character, i, &length);
character[i] = 56; /* Set B double shift A */
i++; /* Next Set A so skip over */
if (debug_print) printf("2SHA ");
}
} else {
/* Shift A */
maxi_bump(set, character, i, &length);
character[i] = 59; /* Set A Shift B */
if (debug_print) printf("SHA ");
}
} else { /* All sets other than B only have latch */
/* Latch A */
maxi_bump(set, character, i, &length);
character[i] = 58; /* Sets C,D,E Latch A */
current_set = 1;
if (debug_print) printf("LCHA ");
}
break;
case 2: /* Set B */
if (current_set != 1 || (i + 1 < 144 && set[i + 1] == 2)) { /* If not Set A or next Set B */
/* Latch B */
maxi_bump(set, character, i, &length);
character[i] = 63; /* Sets A,C,D,E Latch B */
current_set = 2;
if (debug_print) printf("LCHB ");
} else { /* Only available from Set A */
/* Shift B */
maxi_bump(set, character, i, &length);
character[i] = 59; /* Set B Shift A */
if (debug_print) printf("SHB ");
}
break;
case 3: /* Set C */
case 4: /* Set D */
case 5: /* Set E */
/* If first and next 3 same set, or not first and previous and next 2 same set */
if ((i == 0 && i + 3 < 144 && set[i + 1] == set[i] && set[i + 2] == set[i]
&& set[i + 3] == set[i])
|| (i > 0 && set[i - 1] == set[i] && i + 2 < 144 && set[i + 1] == set[i]
&& set[i + 2] == set[i])) {
/* Lock in C/D/E */
if (i == 0) {
maxi_bump(set, character, i, &length);
character[i] = 60 + set[i] - 3;
i++; /* Extra bump */
maxi_bump(set, character, i, &length);
character[i] = 60 + set[i] - 3;
i += 3; /* Next 3 same set so skip over */
} else {
/* Add single Shift to previous Shift */
maxi_bump(set, character, i - 1, &length);
character[i - 1] = 60 + set[i] - 3;
i += 2; /* Next 2 same set so skip over */
}
current_set = set[i];
if (debug_print) printf("LCK%c ", 'C' + set[i] - 3);
} else {
/* Shift C/D/E */
maxi_bump(set, character, i, &length);
character[i] = 60 + set[i] - 3;
if (debug_print) printf("SH%c ", 'C' + set[i] - 3);
}
break;
}
i++; /* Allow for bump */
}
i++;
} while (i < 144);
if (debug_print) printf("\n");
/* Number compression has not been forgotten! - It's handled below */
i = 0;
do {
if (set[i] == 6) {
/* Number compression */
int value = to_int(character + i, 9);
character[i] = 31; /* NS */
character[i + 1] = (value & 0x3f000000) >> 24;
character[i + 2] = (value & 0xfc0000) >> 18;
character[i + 3] = (value & 0x3f000) >> 12;
character[i + 4] = (value & 0xfc0) >> 6;
character[i + 5] = (value & 0x3f);
i += 6;
memmove(set + i, set + i + 3, 141 - i);
memmove(character + i, character + i + 3, 141 - i);
length -= 3;
} else {
i++;
}
} while (i <= 135); /* 144 - 9 */
/* Insert ECI at the beginning of message if needed */
/* Encode ECI assignment numbers according to table 3 */
if (eci != 0) {
maxi_bump(set, character, 0, &length);
character[0] = 27; // ECI
if (eci <= 31) {
maxi_bump(set, character, 1, &length);
character[1] = eci;
} else if (eci <= 1023) {
maxi_bump(set, character, 1, &length);
maxi_bump(set, character, 1, &length);
character[1] = 0x20 | ((eci >> 6) & 0x0F);
character[2] = eci & 0x3F;
} else if (eci <= 32767) {
maxi_bump(set, character, 1, &length);
maxi_bump(set, character, 1, &length);
maxi_bump(set, character, 1, &length);
character[1] = 0x30 | ((eci >> 12) & 0x07);
character[2] = (eci >> 6) & 0x3F;
character[3] = eci & 0x3F;
} else {
maxi_bump(set, character, 1, &length);
maxi_bump(set, character, 1, &length);
maxi_bump(set, character, 1, &length);
maxi_bump(set, character, 1, &length);
character[1] = 0x38 | ((eci >> 18) & 0x03);
character[2] = (eci >> 12) & 0x3F;
character[3] = (eci >> 6) & 0x3F;
character[4] = eci & 0x3F;
}
}
if (debug_print) printf("Length: %d\n", length);
if (((mode == 2) || (mode == 3)) && (length > 84)) {
return ZINT_ERROR_TOO_LONG;
} else if (((mode == 4) || (mode == 6)) && (length > 93)) {
return ZINT_ERROR_TOO_LONG;
} else if ((mode == 5) && (length > 77)) {
return ZINT_ERROR_TOO_LONG;
}
/* Copy the encoded text into the codeword array */
if ((mode == 2) || (mode == 3)) {
for (i = 0; i < 84; i++) { /* secondary only */
maxi_codeword[i + 20] = character[i];
}
} else if ((mode == 4) || (mode == 6)) {
for (i = 0; i < 9; i++) { /* primary */
maxi_codeword[i + 1] = character[i];
}
for (i = 0; i < 84; i++) { /* secondary */
maxi_codeword[i + 20] = character[i + 9];
}
} else { /* Mode 5 */
for (i = 0; i < 9; i++) { /* primary */
maxi_codeword[i + 1] = character[i];
}
for (i = 0; i < 68; i++) { /* secondary */
maxi_codeword[i + 20] = character[i + 9];
}
}
return 0;
}
/* Format structured primary for Mode 2 */
static void maxi_do_primary_2(unsigned char maxi_codeword[144], const unsigned char postcode[],
const int postcode_length, const int country, const int service) {
int postcode_num;
postcode_num = atoi((const char *) postcode);
maxi_codeword[0] = ((postcode_num & 0x03) << 4) | 2;
maxi_codeword[1] = ((postcode_num & 0xfc) >> 2);
maxi_codeword[2] = ((postcode_num & 0x3f00) >> 8);
maxi_codeword[3] = ((postcode_num & 0xfc000) >> 14);
maxi_codeword[4] = ((postcode_num & 0x3f00000) >> 20);
maxi_codeword[5] = ((postcode_num & 0x3c000000) >> 26) | ((postcode_length & 0x3) << 4);
maxi_codeword[6] = ((postcode_length & 0x3c) >> 2) | ((country & 0x3) << 4);
maxi_codeword[7] = (country & 0xfc) >> 2;
maxi_codeword[8] = ((country & 0x300) >> 8) | ((service & 0xf) << 2);
maxi_codeword[9] = ((service & 0x3f0) >> 4);
}
/* Format structured primary for Mode 3 */
static void maxi_do_primary_3(unsigned char maxi_codeword[144], unsigned char postcode[], const int country,
const int service) {
int i;
/* Convert to Code Set A */
for (i = 0; i < 6; i++) {
postcode[i] = maxiSymbolChar[postcode[i]];
}
maxi_codeword[0] = ((postcode[5] & 0x03) << 4) | 3;
maxi_codeword[1] = ((postcode[4] & 0x03) << 4) | ((postcode[5] & 0x3c) >> 2);
maxi_codeword[2] = ((postcode[3] & 0x03) << 4) | ((postcode[4] & 0x3c) >> 2);
maxi_codeword[3] = ((postcode[2] & 0x03) << 4) | ((postcode[3] & 0x3c) >> 2);
maxi_codeword[4] = ((postcode[1] & 0x03) << 4) | ((postcode[2] & 0x3c) >> 2);
maxi_codeword[5] = ((postcode[0] & 0x03) << 4) | ((postcode[1] & 0x3c) >> 2);
maxi_codeword[6] = ((postcode[0] & 0x3c) >> 2) | ((country & 0x3) << 4);
maxi_codeword[7] = (country & 0xfc) >> 2;
maxi_codeword[8] = ((country & 0x300) >> 8) | ((service & 0xf) << 2);
maxi_codeword[9] = ((service & 0x3f0) >> 4);
}
INTERNAL int maxicode(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, j, block, shift, mode, lp = 0;
int error_number = 0, eclen;
unsigned char maxi_codeword[144] = {0};
int scm_vv = -1;
mode = symbol->option_1;
if (mode <= 0) { /* If mode is unspecified (-1) or to be auto-determined (0) between 2 and 3 */
lp = (int) strlen(symbol->primary);
if (lp == 0) {
if (mode == 0) { /* Require primary message to auto-determine between 2 and 3 */
strcpy(symbol->errtxt, "554: Primary Message empty");
return ZINT_ERROR_INVALID_DATA;
}
mode = 4;
} else {
mode = 2;
for (i = 0; i < lp - 6; i++) {
if (((symbol->primary[i] < '0') || (symbol->primary[i] > '9')) && (symbol->primary[i] != ' ')) {
mode = 3;
break;
}
}
}
}
if ((mode < 2) || (mode > 6)) { /* Only codes 2 to 6 supported */
strcpy(symbol->errtxt, "550: Invalid MaxiCode Mode");
return ZINT_ERROR_INVALID_OPTION;
}
if ((mode == 2) || (mode == 3)) { /* Modes 2 and 3 need data in symbol->primary */
unsigned char postcode[10];
int countrycode;
int service;
int postcode_len;
if (lp == 0) { /* Mode set manually means lp doesn't get set */
lp = (int) strlen(symbol->primary);
}
if (lp < 7 || lp > 15) { /* 1 to 9 character postcode + 3 digit country code + 3 digit service class */
strcpy(symbol->errtxt, "551: Invalid length for Primary Message");
return ZINT_ERROR_INVALID_DATA;
}
postcode_len = lp - 6;
countrycode = to_int((const unsigned char *) (symbol->primary + postcode_len), 3);
service = to_int((const unsigned char *) (symbol->primary + postcode_len + 3), 3);
if (countrycode == -1 || service == -1) { /* check that country code and service are numeric */
strcpy(symbol->errtxt, "552: Non-numeric country code or service class in Primary Message");
return ZINT_ERROR_INVALID_DATA;
}
memcpy(postcode, symbol->primary, postcode_len);
postcode[postcode_len] = '\0';
if (mode == 2) {
for (i = 0; i < postcode_len; i++) {
if (postcode[i] == ' ') {
postcode[i] = '\0';
postcode_len = i;
break;
} else if (postcode[i] < '0' || postcode[i] > '9') {
strcpy(symbol->errtxt, "555: Non-numeric postcode in Primary Message");
return ZINT_ERROR_INVALID_DATA;
}
}
maxi_do_primary_2(maxi_codeword, postcode, postcode_len, countrycode, service);
} else {
/* Just truncate and space-pad */
postcode[6] = '\0';
for (i = postcode_len; i < 6; i++) {
postcode[i] = ' ';
}
/* Upper-case and check for Code Set A characters only */
to_upper(postcode);
for (i = 0; i < 6; i++) {
/* Don't allow Code Set A control characters CR, RS, GS and RS */
if (postcode[i] < ' ' || maxiCodeSet[postcode[i]] > 1) {
strcpy(symbol->errtxt, "556: Invalid character in postcode in Primary Message");
return ZINT_ERROR_INVALID_DATA;
}
}
maxi_do_primary_3(maxi_codeword, postcode, countrycode, service);
}
if (symbol->option_2) { /* Check for option_2 = vv + 1, where vv is version of SCM prefix "[)>\R01\Gvv" */
if (symbol->option_2 < 0 || symbol->option_2 > 100) {
strcpy(symbol->errtxt, "557: Invalid SCM prefix version");
return ZINT_ERROR_INVALID_OPTION;
}
scm_vv = symbol->option_2 - 1;
}
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Postcode: %s, Country Code: %d, Service Class: %d\n", postcode, countrycode, service);
}
} else {
maxi_codeword[0] = mode;
}
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Mode: %d\n", mode);
}
i = maxi_text_process(maxi_codeword, mode, source, length, symbol->eci, scm_vv, symbol->debug & ZINT_DEBUG_PRINT);
if (i == ZINT_ERROR_TOO_LONG) {
strcpy(symbol->errtxt, "553: Input data too long");
return i;
}
/* All the data is sorted - now do error correction */
maxi_do_primary_check(maxi_codeword); /* always EEC */
if (mode == 5)
eclen = 56; // 68 data codewords , 56 error corrections
else
eclen = 40; // 84 data codewords, 40 error corrections
maxi_do_secondary_chk_even(maxi_codeword, eclen / 2); // do error correction of even
maxi_do_secondary_chk_odd(maxi_codeword, eclen / 2); // do error correction of odd
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Codewords:");
for (i = 0; i < 144; i++) printf(" %d", maxi_codeword[i]);
printf("\n");
}
#ifdef ZINT_TEST
if (symbol->debug & ZINT_DEBUG_TEST) {
debug_test_codeword_dump(symbol, maxi_codeword, 144);
}
#endif
/* Copy data into symbol grid */
for (i = 0; i < 33; i++) {
for (j = 0; j < 30; j++) {
block = (MaxiGrid[(i * 30) + j] + 5) / 6;
if (block != 0) {
shift = 5 - ((MaxiGrid[(i * 30) + j] + 5) % 6);
if ((maxi_codeword[block - 1] >> shift) & 0x1) {
set_module(symbol, i, j);
}
}
}
}
/* Add orientation markings */
set_module(symbol, 0, 28); // Top right filler
set_module(symbol, 0, 29);
set_module(symbol, 9, 10); // Top left marker
set_module(symbol, 9, 11);
set_module(symbol, 10, 11);
set_module(symbol, 15, 7); // Left hand marker
set_module(symbol, 16, 8);
set_module(symbol, 16, 20); // Right hand marker
set_module(symbol, 17, 20);
set_module(symbol, 22, 10); // Bottom left marker
set_module(symbol, 23, 10);
set_module(symbol, 22, 17); // Bottom right marker
set_module(symbol, 23, 17);
symbol->width = 30;
symbol->rows = 33;
/* Note MaxiCode fixed size so symbol height ignored but set anyway */
(void) set_height(symbol, 5.0f, 0.0f, 0.0f, 1 /*no_errtxt*/);
return error_number;
}

View File

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -29,16 +29,17 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "common.h"
extern int c39(struct zint_symbol *symbol, unsigned char source[], const size_t length);
INTERNAL int c39(struct zint_symbol *symbol, unsigned char source[], int length);
/* Codabar table checked against EN 798:1995 */
#define CALCIUM "0123456789-$:/.+ABCD"
#define CALCIUM_INNER "0123456789-$:/.+"
static const char *CodaTable[20] = {
"11111221", "11112211", "11121121", "22111111", "11211211", "21111211",
@ -46,7 +47,7 @@ static const char *CodaTable[20] = {
"21212111", "11212121", "11221211", "12121121", "11121221", "11122211"
};
int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length) {
/* "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
@ -57,7 +58,8 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length) {
- http://en.wikipedia.org/wiki/Pharmacode */
/* This code uses the One Track Pharamacode calculating algorithm as recommended by
the specification at http://www.laetus.com/laetus.php?request=file&id=69 */
the specification at http://www.laetus.com/laetus.php?request=file&id=69
(http://www.gomaro.ch/ftproot/Laetus_PHARMA-CODE.pdf) */
unsigned long int tester;
int counter, error_number, h;
@ -65,19 +67,19 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length) {
char dest[64]; /* 17 * 2 + 1 */
if (length > 6) {
strcpy(symbol->errtxt, "350: Input too long");
strcpy(symbol->errtxt, "350: Input too long (6 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "351: Invalid characters in data");
strcpy(symbol->errtxt, "351: Invalid character in data (digits only)");
return error_number;
}
tester = atoi((char *) source);
if ((tester < 3) || (tester > 131070)) {
strcpy(symbol->errtxt, "352: Data out of range");
strcpy(symbol->errtxt, "352: Data out of range (3 to 131070)");
return ZINT_ERROR_INVALID_DATA;
}
@ -91,7 +93,7 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length) {
}
} while (tester != 0);
h = strlen(inter) - 1;
h = (int) strlen(inter) - 1;
*dest = '\0';
for (counter = h; counter >= 0; counter--) {
if (inter[counter] == 'W') {
@ -103,10 +105,17 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length) {
expand(symbol, dest);
#ifdef COMPLIANT_HEIGHTS
/* 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*/);
#endif
return error_number;
}
int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
static int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
/* 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
@ -120,7 +129,7 @@ int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char des
tester = atoi((char *) source);
if ((tester < 4) || (tester > 64570080)) {
strcpy(symbol->errtxt, "353: Data out of range");
strcpy(symbol->errtxt, "353: Data out of range (4 to 64570080)");
return ZINT_ERROR_INVALID_DATA;
}
error_number = 0;
@ -142,7 +151,7 @@ int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char des
}
} while (tester != 0);
h = strlen(inter) - 1;
h = (int) strlen(inter) - 1;
for (counter = h; counter >= 0; counter--) {
dest[h - counter] = inter[counter];
}
@ -151,21 +160,22 @@ int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char des
return error_number;
}
int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Draws the patterns for two track pharmacode */
char height_pattern[200];
unsigned int loopey, h;
int writer;
int error_number = 0;
int error_number;
strcpy(height_pattern, "");
if (length > 8) {
strcpy(symbol->errtxt, "354: Input too long");
strcpy(symbol->errtxt, "354: Input too long (8 character maximum");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "355: Invalid characters in data");
strcpy(symbol->errtxt, "355: Invalid character in data (digits only)");
return error_number;
}
error_number = pharma_two_calc(symbol, source, height_pattern);
@ -174,7 +184,7 @@ int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length) {
}
writer = 0;
h = strlen(height_pattern);
h = (int) strlen(height_pattern);
for (loopey = 0; loopey < h; loopey++) {
if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '3')) {
set_module(symbol, 0, writer);
@ -187,77 +197,134 @@ int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length) {
symbol->rows = 2;
symbol->width = writer - 1;
#ifdef COMPLIANT_HEIGHTS
/* Laetus Pharmacode Guide 1.4
Two-track height min 8mm / 2mm (X max) = 4, standard 8mm / 1mm = 8, max 12mm / 0.8mm (X min) = 15 */
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*/);
#endif
return error_number;
}
/* The Codabar system consisting of simple substitution */
int codabar(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int codabar(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number;
char dest[512];
int add_checksum, count = 0, checksum;
int d_chars = 0;
float height;
strcpy(dest, "");
if (length > 60) { /* No stack smashing please */
strcpy(symbol->errtxt, "356: Input too long");
strcpy(symbol->errtxt, "356: Input too long (60 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
/* BS EN 798:1995 4.2 "'Codabar' symbols shall consist of ... b) start character;
c) one or more symbol characters representing data ... d) stop character ..." */
if (length < 3) {
strcpy(symbol->errtxt, "362: Input too short (3 character minimum)");
return ZINT_ERROR_TOO_LONG;
}
to_upper(source);
error_number = is_sane(CALCIUM, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "357: Invalid characters in data");
return error_number;
}
/* Codabar must begin and end with the characters A, B, C or D */
if ((source[0] != 'A') && (source[0] != 'B') && (source[0] != 'C')
&& (source[0] != 'D')) {
strcpy(symbol->errtxt, "358: Invalid characters in data");
strcpy(symbol->errtxt, "358: Does not begin with \"A\", \"B\", \"C\" or \"D\"");
return ZINT_ERROR_INVALID_DATA;
}
if ((source[length - 1] != 'A') && (source[length - 1] != 'B') &&
(source[length - 1] != 'C') && (source[length - 1] != 'D')) {
strcpy(symbol->errtxt, "359: Invalid characters in data");
strcpy(symbol->errtxt, "359: Does not end with \"A\", \"B\", \"C\" or \"D\"");
return ZINT_ERROR_INVALID_DATA;
}
/* And must not use A, B, C or D otherwise (BS EN 798:1995 4.3.2) */
error_number = is_sane(CALCIUM_INNER, source + 1, length - 2);
if (error_number) {
if (is_sane(CALCIUM, source + 1, length - 2) == 0) {
strcpy(symbol->errtxt, "363: Cannot contain \"A\", \"B\", \"C\" or \"D\"");
} else {
sprintf(symbol->errtxt, "357: Invalid character in data (\"%s\" only)", CALCIUM);
}
return error_number;
}
add_checksum = symbol->option_2 == 1;
for (i = 0; i < length; i++) {
lookup(CALCIUM, CodaTable, source[i], dest);
static const char calcium[] = CALCIUM;
if (add_checksum) {
count += strchr(calcium, source[i]) - calcium;
if (i + 1 == length) {
checksum = count % 16;
if (checksum) {
checksum = 16 - checksum;
}
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Codabar: %s, count %d, checksum %d\n", source, count, checksum);
}
strcat(dest, CodaTable[checksum]);
}
}
lookup(calcium, CodaTable, source[i], dest);
if (source[i] == '/' || source[i] == ':' || source[i] == '.' || source[i] == '+') { /* Wide data characters */
d_chars++;
}
}
expand(symbol, dest);
#ifdef COMPLIANT_HEIGHTS
/* BS EN 798:1995 4.4.1 (d) max of 5mm / 0.191mm (X) ~ 26.178 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) + 2Q
= ((4 + 5) * C + (D + 2) + C - 1 + 2 * 10) * X = (10 * C + D + 21) * X
Length (C) includes start/stop chars */
height = (float) ((10.0 * ((add_checksum ? length + 1 : length) + 2.0) + d_chars + 21.0) * 0.15);
if (height < (float) (5.0 / 0.191)) {
height = (float) (5.0 / 0.191);
}
/* Using 50 as default as none recommended */
error_number = set_height(symbol, height, height > 50.0f ? height : 50.0f, 0.0f, 0 /*no_errtxt*/);
#else
height = 50.0f;
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
#endif
ustrcpy(symbol->text, source);
return error_number;
}
/* Italian Pharmacode */
int code32(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, zeroes, error_number, checksum, checkpart, checkdigit;
INTERNAL int code32(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, zeroes, error_number = 0, checksum, checkpart, checkdigit;
char localstr[10], risultante[7];
long int pharmacode, remainder, devisor;
long int pharmacode, devisor;
int codeword[6];
char tabella[34];
/* Validate the input */
if (length > 8) {
strcpy(symbol->errtxt, "360: Input too long");
strcpy(symbol->errtxt, "360: Input too long (8 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "361: Invalid characters in data");
strcpy(symbol->errtxt, "361: Invalid character in data (digits only)");
return error_number;
}
/* Add leading zeros as required */
zeroes = 8 - length;
memset(localstr, '0', zeroes);
strcpy(localstr + zeroes, (char*) source);
ustrcpy(localstr + zeroes, source);
/* Calculate the check digit */
checksum = 0;
checkpart = 0;
for (i = 0; i < 4; i++) {
checkpart = ctoi(localstr[i * 2]);
checksum += checkpart;
@ -280,6 +347,7 @@ int code32(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Convert from decimal to base-32 */
devisor = 33554432;
for (i = 5; i >= 0; i--) {
long int remainder;
codeword[i] = pharmacode / devisor;
remainder = pharmacode % devisor;
pharmacode = remainder;
@ -293,14 +361,24 @@ int code32(struct zint_symbol *symbol, unsigned char source[], int length) {
}
risultante[6] = '\0';
/* Plot the barcode using Code 39 */
error_number = c39(symbol, (unsigned char*) risultante, strlen(risultante));
if (error_number != 0) {
return error_number;
error_number = c39(symbol, (unsigned char *) risultante, (int) strlen(risultante));
if (error_number != 0) { /* Should never happen */
return error_number; /* Not reached */
}
#ifdef COMPLIANT_HEIGHTS
/* 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=14A05668&art.num=1&art.tiposerie=SG
X given as 0.250mm; height (and quiet zones) left to ISO/IEC 16388:2007 (Code 39)
So min height 5mm = 5mm / 0.25mm = 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*/);
#endif
/* Override the normal text output with the Pharmacode number */
strcpy((char*) symbol->text, "A");
strcat((char*) symbol->text, (char*) localstr);
ustrcpy(symbol->text, "A");
ustrcat(symbol->text, localstr);
return error_number;
}

View File

@ -232,3 +232,4 @@ typedef uint64_t uintmax_t;
#endif // _MSC_STDINT_H_ ]

639
3rdparty/zint-2.10.0/backend/output.c vendored Normal file
View File

@ -0,0 +1,639 @@
/* output.c - Common routines for raster/vector
libzint - the open source barcode library
Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include <math.h>
#include "common.h"
#include "output.h"
#include "font.h"
#define SSET "0123456789ABCDEF"
/* Check colour options are good. Note: using raster.c error nos 651-654 */
INTERNAL int output_check_colour_options(struct zint_symbol *symbol) {
int error_number;
if ((strlen(symbol->fgcolour) != 6) && (strlen(symbol->fgcolour) != 8)) {
strcpy(symbol->errtxt, "651: Malformed foreground colour target");
return ZINT_ERROR_INVALID_OPTION;
}
if ((strlen(symbol->bgcolour) != 6) && (strlen(symbol->bgcolour) != 8)) {
strcpy(symbol->errtxt, "652: Malformed background colour target");
return ZINT_ERROR_INVALID_OPTION;
}
to_upper((unsigned char *) symbol->fgcolour);
to_upper((unsigned char *) symbol->bgcolour);
error_number = is_sane(SSET, (unsigned char *) symbol->fgcolour, (int) strlen(symbol->fgcolour));
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "653: Malformed foreground colour target");
return ZINT_ERROR_INVALID_OPTION;
}
error_number = is_sane(SSET, (unsigned char *) symbol->bgcolour, (int) strlen(symbol->bgcolour));
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "654: Malformed background colour target");
return ZINT_ERROR_INVALID_OPTION;
}
return 0;
}
/* Return minimum quiet zones for each symbology */
static int quiet_zones(struct zint_symbol *symbol, float *left, float *right, float *top, float *bottom) {
int done = 0;
*left = *right = *top = *bottom = 0.0f;
/* These always have quiet zones set (previously used whitespace_width) */
switch (symbol->symbology) {
case BARCODE_CODE16K:
/* BS EN 12323:2005 Section 4.5 (c) */
*left = 10.0f;
*right = 1.0f;
done = 1;
break;
case BARCODE_CODE49:
/* ANSI/AIM BC6-2000 Section 2.4 */
*left = 10.0f;
*right = 1.0f;
done = 1;
break;
case BARCODE_CODABLOCKF:
case BARCODE_HIBC_BLOCKF:
/* AIM ISS-X-24 Section 4.6.1 */
*left = *right = 10.0f;
done = 1;
break;
case BARCODE_ITF14:
/* GS1 General Specifications 21.0.1 Section 5.3.2.2 */
*left = *right = 10.0f;
done = 1;
break;
case BARCODE_EANX:
case BARCODE_EANX_CHK:
case BARCODE_EANX_CC:
case BARCODE_ISBNX:
/* GS1 General Specifications 21.0.1 Section 5.2.3.4 */
switch (ustrlen(symbol->text)) {
case 13: /* EAN-13 */
*left = 11.0f;
*right = 7.0f;
break;
case 16: /* EAN-13/ISBN + 2 digit addon */
case 19: /* EAN-13/ISBN + 5 digit addon */
*left = 11.0f;
*right = 5.0f;
break;
case 5: /* EAN-5 addon */
case 2: /* EAN-2 addon */
*left = 7.0f;
*right = 5.0f;
break;
default: /* EAN-8 (+/- 2/5 digit addon) */
*left = *right = 7.0f;
break;
}
done = 1;
break;
case BARCODE_UPCA:
case BARCODE_UPCA_CHK:
case BARCODE_UPCA_CC:
/* GS1 General Specifications 21.0.1 Section 5.2.3.4 */
*left = 9.0f;
if (ustrlen(symbol->text) > 12) { /* UPC-A + addon */
*right = 5.0f;
} else {
*right = 9.0f;
}
done = 1;
break;
case BARCODE_UPCE:
case BARCODE_UPCE_CHK:
case BARCODE_UPCE_CC:
/* GS1 General Specifications 21.0.1 Section 5.2.3.4 */
*left = 9.0f;
if (ustrlen(symbol->text) > 8) { /* UPC-E + addon */
*right = 5.0f;
} else {
*right = 7.0f;
}
done = 1;
break;
}
if (done) {
return done;
}
/* Only do others if flag set TODO: finish */
#if 0
if (!(symbol->output_options & BARCODE_QUIET_ZONES)) {
return done;
}
#else
return done;
#endif
switch (symbol->symbology) {
case BARCODE_CODE11:
/* No known standard. Following ITF-14, set to 10X */
*left = *right = 10.0f;
done = 1;
break;
case BARCODE_C25INTER:
/* ISO/IEC 16390:2007 Section 4.4 10X */
*left = *right = 10.0f;
done = 1;
break;
case BARCODE_C25STANDARD:
case BARCODE_C25IATA:
case BARCODE_C25LOGIC:
case BARCODE_C25IND:
/* No known standards. Following C25INTER, set to 10X */
*left = *right = 10.0f;
done = 1;
break;
case BARCODE_CODE39:
case BARCODE_EXCODE39:
case BARCODE_LOGMARS:
case BARCODE_PZN:
case BARCODE_VIN:
case BARCODE_HIBC_39:
case BARCODE_CODE32:
/* ISO/IEC 16388:2007 Section 4.4 (d) */
*left = *right = 10.0f;
done = 1;
break;
case BARCODE_GS1_128: /* GS1-128 */
case BARCODE_GS1_128_CC:
case BARCODE_EAN14:
/* GS1 General Specifications 21.0.1 Section 5.4.4.2 */
*left = *right = 10.0f;
done = 1;
break;
case BARCODE_CODABAR:
/* BS EN 798:1995 Section 4.4.1 (d) */
*left = *right = 10.0f;
done = 1;
break;
case BARCODE_CODE128:
case BARCODE_CODE128B:
case BARCODE_HIBC_128:
case BARCODE_NVE18:
/* ISO/IEC 15417:2007 4.4.2 */
*left = *right = 10.0f;
done = 1;
break;
case BARCODE_DPLEIT:
case BARCODE_DPIDENT:
/* Using CODE39 values TODO: Find doc */
*left = *right = 10.0f;
done = 1;
break;
case BARCODE_CODE93:
/* ANSI/AIM BC5-1995 Section 2.4 */
*left = *right = 10.0f;
done = 1;
break;
case BARCODE_FLAT:
/* TODO */
break;
case BARCODE_DBAR_OMN: /* GS1 Databar Omnidirectional */
case BARCODE_DBAR_LTD: /* GS1 Databar Limited */
case BARCODE_DBAR_EXP: /* GS1 Databar Expanded */
case BARCODE_DBAR_STK: /* GS1 DataBar Stacked */
case BARCODE_DBAR_OMNSTK: /* GS1 DataBar Stacked Omnidirectional */
case BARCODE_DBAR_EXPSTK: /* GS1 Databar Expanded Stacked */
/* GS1 General Specifications 21.0.1 Section 5.5.1.1 - Quiet Zones: None required */
done = 1;
break;
case BARCODE_DBAR_OMN_CC:
case BARCODE_DBAR_LTD_CC:
case BARCODE_DBAR_EXP_CC:
case BARCODE_DBAR_STK_CC:
case BARCODE_DBAR_OMNSTK_CC:
case BARCODE_DBAR_EXPSTK_CC:
/* GS1 General Specifications 21.0.1 Sections 5.11.2.1 (CC-A) & 5.11.2.2 (CC-B) */
*left = *right = 1.0f;
done = 1;
break;
case BARCODE_TELEPEN:
case BARCODE_TELEPEN_NUM:
/* TODO */
break;
case BARCODE_POSTNET:
case BARCODE_PLANET:
/* USPS DMM 300 2006 (2011) 5.7 Barcode in Address Block
left/right 0.125" / 0.025" (X max) = 5, top/bottom 0.04" / 0.025" (X max) = 1.6 */
*left = *right = 5.0f;
*top = *bottom = 1.6f;
done = 1;
break;
case BARCODE_MSI_PLESSEY:
/* TODO */
break;
case BARCODE_FIM:
/* USPS DMM 300 2006 (2011) 708.9.3 (top/bottom zero)
right 0.125" (min) / 0.03925" (X max) ~ 3.18, left 1.25" - 0.66725" (max width of barcode)
- 0.375 (max right) = 0.20775" / 0.03925" (X max) ~ 5.29 */
*right = (float) (0.125 / 0.03925);
*left = (float) (0.20775 / 0.03925);
done = 1;
break;
case BARCODE_PHARMA:
case BARCODE_PHARMA_TWO:
/* Laetus Pharmacode Guide 2.2 from 6mm depending on context, 6mm / 1mm (Pharma Two X) = 6 */
*left = *right = 6.0f;
done = 1;
break;
case BARCODE_PDF417:
case BARCODE_PDF417COMP:
case BARCODE_HIBC_PDF:
/* ISO/IEC 15438:2015 Section 5.8.3 */
*left = *right = *top = *bottom = 2.0f;
done = 1;
break;
case BARCODE_MICROPDF417:
case BARCODE_HIBC_MICPDF:
/* ISO/IEC 24728:2006 Section 5.8.3 */
*left = *right = *top = *bottom = 1.0f;
done = 1;
break;
case BARCODE_MAXICODE:
/* ISO/IEC 16023:2000 Section 4.11.5 */
*left = *right = *top = *bottom = 1.0f;
done = 1;
break;
case BARCODE_QRCODE:
case BARCODE_UPNQR:
case BARCODE_HIBC_QR:
/* ISO/IEC 18004:2015 Section 9.1 */
*left = *right = *top = *bottom = 4.0f;
done = 1;
break;
case BARCODE_DPD:
/* Specification DPD and primetime Parcel Despatch 4.0.2 Section 5.5.1 5mm / 0.4mm (X max) = 12.5 */
*left = *right = 12.5f;
done = 1;
break;
case BARCODE_MICROQR:
/* ISO/IEC 18004:2015 Section 9.1 */
*left = *right = *top = *bottom = 2.0f;
done = 1;
break;
case BARCODE_RMQR:
/* ISO/IEC JTC1/SC31N000 Section 6.3.10 */
*left = *right = *top = *bottom = 2.0f;
done = 1;
break;
case BARCODE_AUSPOST:
case BARCODE_AUSREPLY:
case BARCODE_AUSROUTE:
case BARCODE_AUSREDIRECT:
/* Customer Barcode Technical Specifications (2012) left/right 6mm / 0.6mm = 10,
top/bottom 2mm / 0.6mm ~ 3.33 (X max) */
*left = *right = 10.0f;
*top = *bottom = (float) (2.0 / 0.6);
done = 1;
break;
case BARCODE_RM4SCC:
/* Royal Mail Know How User's Manual Appendix C: using CBC, same as MAILMARK, 2mm all round,
use X max (25.4mm / 39) i.e. 20 bars per 25.4mm */
*left = *right = *top = *bottom = (float) ((2.0 * 39.0) / 25.4); /* ~ 3.07 */
done = 1;
break;
case BARCODE_DATAMATRIX:
case BARCODE_HIBC_DM:
/* ISO/IEC 16022:2006 Section 7.1 */
*left = *right = *top = *bottom = 1.0f;
done = 1;
break;
case BARCODE_JAPANPOST:
/* Japan Post Zip/Barcode Manual p.13 2mm all round, X 0.6mm, 2mm / 0.6mm ~ 3.33 */
*left = *right = *top = *bottom = (float) (2.0 / 0.6);
done = 1;
break;
case BARCODE_KOREAPOST:
/* TODO */
break;
case BARCODE_USPS_IMAIL:
/* USPS-B-3200 (2015) Section 2.3.2 left/right 0.125", top/bottom 0.026", use X max (1 / 39)
i.e. 20 bars per inch */
*left = *right = 0.125f * 39.0f; /* 4.875 */
*top = *bottom = 0.026f * 39.0f; /* 1.014 */
done = 1;
break;
case BARCODE_PLESSEY:
/* TODO */
break;
case BARCODE_KIX:
/* Handleiding KIX code brochure - same as RM4SCC/MAILMARK */
*left = *right = *top = *bottom = (float) ((2.0 * 39.0) / 25.4); /* ~ 3.07 */
done = 1;
break;
case BARCODE_AZTEC:
case BARCODE_HIBC_AZTEC:
case BARCODE_AZRUNE:
/* ISO/IEC 24778:2008 Section 4.1 (c) & Annex A.1 (Rune) - no quiet zone required */
done = 1;
break;
case BARCODE_DAFT:
/* Generic so unlikely to be defined */
done = 1;
break;
case BARCODE_DOTCODE:
/* ISS DotCode Rev. 4.0 Section 4.1 (3) (c) */
*left = *right = *top = *bottom = 3.0f;
done = 1;
break;
case BARCODE_HANXIN:
/* ISO/IEC DIS 20830:2019 Section 4.2.8 (also Section 6.2) */
*left = *right = *top = *bottom = 3.0f;
done = 1;
break;
case BARCODE_MAILMARK:
/* Royal Mail Mailmark Barcode Definition Document Section 3.5.2, 2mm all round, use X max (25.4mm / 39)
i.e. 20 bars per 25.4mm */
*left = *right = *top = *bottom = (float) ((2.0 * 39.0) / 25.4); /* ~ 3.07 */
done = 1;
break;
case BARCODE_CHANNEL:
/* ANSI/AIM BC12-1998 Section 4.4 (c) */
*left = 1.0f;
*right = 2.0f;
done = 1;
break;
case BARCODE_CODEONE:
/* TODO */
break;
case BARCODE_GRIDMATRIX:
/* AIMD014 (v 1.63) Section 7.1 */
*left = *right = *top = *bottom = 6.0f;
done = 1;
break;
case BARCODE_ULTRA:
/* AIMD/TSC15032-43 (v 0.99c) Section 9.2 */
*left = *right = *top = *bottom = 1.0f;
done = 1;
break;
}
return done; /* For self-checking */
}
/* Set left (x), top (y), right and bottom offsets for whitespace */
INTERNAL void output_set_whitespace_offsets(struct zint_symbol *symbol, float *xoffset, float *yoffset,
float *roffset, float *boffset) {
float qz_left, qz_right, qz_top, qz_bottom;
quiet_zones(symbol, &qz_left, &qz_right, &qz_top, &qz_bottom);
*xoffset = symbol->whitespace_width + qz_left;
*roffset = symbol->whitespace_width + qz_right;
if (symbol->output_options & BARCODE_BOX) {
*xoffset += symbol->border_width;
*roffset += symbol->border_width;
}
*yoffset = symbol->whitespace_height + qz_top;
*boffset = symbol->whitespace_height + qz_bottom;
if (symbol->output_options & (BARCODE_BOX | BARCODE_BIND)) {
*yoffset += symbol->border_width;
*boffset += symbol->border_width;
}
}
/* Set composite offset and main width excluding addon (for start of addon calc) and addon text, returning
UPC/EAN type */
INTERNAL int output_process_upcean(struct zint_symbol *symbol, int *p_main_width, int *p_comp_offset,
unsigned char addon[6], int *p_addon_gap) {
int main_width; /* Width of main linear symbol, excluding addon */
int comp_offset; /* Whitespace offset (if any) of main linear symbol due to having composite */
int upceanflag; /* UPC/EAN type flag */
int i, j, latch;
int text_length = (int) ustrlen(symbol->text);
latch = 0;
j = 0;
/* Isolate add-on text */
for (i = 6; i < text_length && j < 5; i++) {
if (latch == 1) {
addon[j] = symbol->show_hrt ? symbol->text[i] : ' '; /* Use dummy space-filled addon if no hrt */
j++;
} else if (symbol->text[i] == '+') {
latch = 1;
}
}
addon[j] = '\0';
if (latch) {
if (symbol->symbology == BARCODE_UPCA || symbol->symbology == BARCODE_UPCA_CHK
|| symbol->symbology == BARCODE_UPCA_CC) {
*p_addon_gap = symbol->option_2 >= 9 && symbol->option_2 <= 12 ? symbol->option_2 : 9;
} else {
*p_addon_gap = symbol->option_2 >= 7 && symbol->option_2 <= 12 ? symbol->option_2 : 7;
}
}
/* Calculate composite offset */
comp_offset = 0;
if (is_composite(symbol->symbology)) {
while (!(module_is_set(symbol, symbol->rows - 1, comp_offset))) {
comp_offset++;
}
}
upceanflag = 0;
main_width = symbol->width;
if ((symbol->symbology == BARCODE_EANX) || (symbol->symbology == BARCODE_EANX_CHK)
|| (symbol->symbology == BARCODE_EANX_CC) || (symbol->symbology == BARCODE_ISBNX)) {
switch (text_length) {
case 13: /* EAN-13 */
case 16: /* EAN-13 + EAN-2 */
case 19: /* EAN-13 + EAN-5 */
main_width = 95 + comp_offset; /* EAN-13 main symbol 95 modules wide */
upceanflag = 13;
break;
case 2:
/* EAN-2 can't have addon or be composite */
upceanflag = 2;
break;
case 5:
/* EAN-5 can't have addon or be composite */
upceanflag = 5;
break;
default:
main_width = 68 + comp_offset; /* EAN-8 main symbol 68 modules wide */
upceanflag = 8;
break;
}
} else if ((symbol->symbology == BARCODE_UPCA) || (symbol->symbology == BARCODE_UPCA_CHK)
|| (symbol->symbology == BARCODE_UPCA_CC)) {
main_width = 95 + comp_offset; /* UPC-A main symbol 95 modules wide */
upceanflag = 12;
} else if ((symbol->symbology == BARCODE_UPCE) || (symbol->symbology == BARCODE_UPCE_CHK)
|| (symbol->symbology == BARCODE_UPCE_CC)) {
main_width = 51 + comp_offset; /* UPC-E main symbol 51 modules wide */
upceanflag = 6;
}
*p_comp_offset = comp_offset;
*p_main_width = main_width;
return upceanflag;
}
/* Calculate large bar height i.e. linear bars with zero row height that respond to the symbol height.
If scaler `si` non-zero (raster), then large_bar_height if non-zero or else row heights will be rounded to nearest
pixel and symbol height adjusted */
INTERNAL float output_large_bar_height(struct zint_symbol *symbol, int si) {
float fixed_height = 0.0f;
int zero_count = 0;
int round_rows = 0;
int i;
float large_bar_height;
for (i = 0; i < symbol->rows; i++) {
if (symbol->row_height[i]) {
fixed_height += symbol->row_height[i];
if (!round_rows && si && !isfintf(symbol->row_height[i] * si)) {
round_rows = 1;
}
} else {
zero_count++;
}
}
if (zero_count) {
large_bar_height = (symbol->height - fixed_height) / zero_count;
if (large_bar_height <= 0.0f) { /* Shouldn't happen but protect against memory access violations */
large_bar_height = 0.01f; /* Token positive value */
symbol->height = large_bar_height * zero_count + fixed_height;
}
if (si && !isfintf(large_bar_height * si)) {
large_bar_height = roundf(large_bar_height * si) / si;
symbol->height = large_bar_height * zero_count + fixed_height;
}
/* Note should never happen that have both zero_count and round_rows */
} else {
large_bar_height = 0.0f; /* Not used if zero_count zero */
if (round_rows) {
fixed_height = 0.0f;
for (i = 0; i < symbol->rows; i++) {
if (!isfintf(symbol->row_height[i] * si)) {
symbol->row_height[i] = roundf(symbol->row_height[i] * si) / si;
}
fixed_height += symbol->row_height[i];
}
symbol->height = fixed_height;
}
}
return large_bar_height;
}
/* Split UPC/EAN add-on text into various constituents */
INTERNAL void output_upcean_split_text(int upceanflag, unsigned char text[],
unsigned char textpart1[5], unsigned char textpart2[7], unsigned char textpart3[7],
unsigned char textpart4[2]) {
int i;
if (upceanflag == 6) { /* UPC-E */
textpart1[0] = text[0];
textpart1[1] = '\0';
for (i = 0; i < 6; i++) {
textpart2[i] = text[i + 1];
}
textpart2[6] = '\0';
textpart3[0] = text[7];
textpart3[1] = '\0';
} else if (upceanflag == 8) { /* EAN-8 */
for (i = 0; i < 4; i++) {
textpart1[i] = text[i];
}
textpart1[4] = '\0';
for (i = 0; i < 4; i++) {
textpart2[i] = text[i + 4];
}
textpart2[4] = '\0';
} else if (upceanflag == 12) { /* UPC-A */
textpart1[0] = text[0];
textpart1[1] = '\0';
for (i = 0; i < 5; i++) {
textpart2[i] = text[i + 1];
}
textpart2[5] = '\0';
for (i = 0; i < 5; i++) {
textpart3[i] = text[i + 6];
}
textpart3[5] = '\0';
textpart4[0] = text[11];
textpart4[1] = '\0';
} else if (upceanflag == 13) { /* EAN-13 */
textpart1[0] = text[0];
textpart1[1] = '\0';
for (i = 0; i < 6; i++) {
textpart2[i] = text[i + 1];
}
textpart2[6] = '\0';
for (i = 0; i < 6; i++) {
textpart3[i] = text[i + 7];
}
textpart3[6] = '\0';
}
}

54
3rdparty/zint-2.10.0/backend/output.h vendored Normal file
View File

@ -0,0 +1,54 @@
/* output.h - Common routines for raster/vector
libzint - the open source barcode library
Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#ifndef OUTPUT_H
#define OUTPUT_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
INTERNAL int output_check_colour_options(struct zint_symbol *symbol);
INTERNAL void output_set_whitespace_offsets(struct zint_symbol *symbol, float *xoffset, float *yoffset,
float *roffset, float *boffset);
INTERNAL int output_process_upcean(struct zint_symbol *symbol, int *p_main_width, int *p_comp_offset,
unsigned char addon[6], int *p_addon_gap);
INTERNAL float output_large_bar_height(struct zint_symbol *symbol, int si);
INTERNAL void output_upcean_split_text(int upceanflag, unsigned char text[],
unsigned char textpart1[5], unsigned char textpart2[7], unsigned char textpart3[7],
unsigned char textpart4[2]);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* OUTPUT_H */

226
3rdparty/zint-2.10.0/backend/pcx.c vendored Normal file
View File

@ -0,0 +1,226 @@
/* pcx.c - Handles output to ZSoft PCX file */
/* ZSoft PCX File Format Technical Reference Manual http://bespin.org/~qz/pc-gpe/pcx.txt */
/*
libzint - the open source barcode library
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include <errno.h>
#include <stdio.h>
#include "common.h"
#include "pcx.h" /* PCX header structure */
#include <math.h>
#ifdef _MSC_VER
#include <io.h>
#include <fcntl.h>
#include <malloc.h>
#endif
INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) {
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
int row, column, i, colour;
int run_count;
FILE *pcx_file;
pcx_header_t header;
int bytes_per_line = symbol->bitmap_width + (symbol->bitmap_width & 1); // Must be even
unsigned char previous;
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT; /* Suppress gcc -fanalyzer warning */
#ifdef _MSC_VER
unsigned char *rle_row;
#endif
#ifndef _MSC_VER
unsigned char rle_row[bytes_per_line];
#else
rle_row = (unsigned char *) _alloca(bytes_per_line);
#endif /* _MSC_VER */
rle_row[bytes_per_line - 1] = 0; // Will remain zero if bitmap_width odd
fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]);
fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]);
bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
header.manufacturer = 10; // ZSoft
header.version = 5; // Version 3.0
header.encoding = 1; // Run length encoding
header.bits_per_pixel = 8;
header.window_xmin = 0;
header.window_ymin = 0;
header.window_xmax = symbol->bitmap_width - 1;
header.window_ymax = symbol->bitmap_height - 1;
header.horiz_dpi = 300;
header.vert_dpi = 300;
for (i = 0; i < 48; i++) {
header.colourmap[i] = 0x00;
}
header.reserved = 0;
header.number_of_planes = 3;
header.bytes_per_line = bytes_per_line;
header.palette_info = 1; // Colour
header.horiz_screen_size = 0;
header.vert_screen_size = 0;
for (i = 0; i < 54; i++) {
header.filler[i] = 0x00;
}
/* Open output file in binary mode */
if (output_to_stdout) {
#ifdef _MSC_VER
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
sprintf(symbol->errtxt, "620: Could not set stdout to binary (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
#endif
pcx_file = stdout;
} else {
if (!(pcx_file = fopen(symbol->outfile, "wb"))) {
sprintf(symbol->errtxt, "621: Could not open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
}
fwrite(&header, sizeof(pcx_header_t), 1, pcx_file);
for (row = 0; row < symbol->bitmap_height; row++) {
for (colour = 0; colour < 3; colour++) {
for (column = 0; column < symbol->bitmap_width; column++) {
switch (colour) {
case 0:
switch (pixelbuf[(row * symbol->bitmap_width) + column]) {
case 'W': // White
case 'M': // Magenta
case 'R': // Red
case 'Y': // Yellow
rle_row[column] = 255;
break;
case 'C': // Cyan
case 'B': // Blue
case 'G': // Green
case 'K': // Black
rle_row[column] = 0;
break;
case '1':
rle_row[column] = fgred;
break;
default:
rle_row[column] = bgred;
break;
}
break;
case 1:
switch (pixelbuf[(row * symbol->bitmap_width) + column]) {
case 'W': // White
case 'C': // Cyan
case 'Y': // Yellow
case 'G': // Green
rle_row[column] = 255;
break;
case 'B': // Blue
case 'M': // Magenta
case 'R': // Red
case 'K': // Black
rle_row[column] = 0;
break;
case '1':
rle_row[column] = fggrn;
break;
default:
rle_row[column] = bggrn;
break;
}
break;
case 2:
switch (pixelbuf[(row * symbol->bitmap_width) + column]) {
case 'W': // White
case 'C': // Cyan
case 'B': // Blue
case 'M': // Magenta
rle_row[column] = 255;
break;
case 'R': // Red
case 'Y': // Yellow
case 'G': // Green
case 'K': // Black
rle_row[column] = 0;
break;
case '1':
rle_row[column] = fgblu;
break;
default:
rle_row[column] = bgblu;
break;
}
break;
}
}
/* Based on ImageMagick/coders/pcx.c PCXWritePixels()
* Copyright 1999-2020 ImageMagick Studio LLC */
previous = rle_row[0];
run_count = 1;
for (column = 1; column < bytes_per_line; column++) { // Note going up to bytes_per_line
if ((previous == rle_row[column]) && (run_count < 63)) {
run_count++;
} else {
if (run_count > 1 || (previous & 0xc0) == 0xc0) {
run_count += 0xc0;
fputc(run_count, pcx_file);
}
fputc(previous, pcx_file);
previous = rle_row[column];
run_count = 1;
}
}
if (run_count > 1 || (previous & 0xc0) == 0xc0) {
run_count += 0xc0;
fputc(run_count, pcx_file);
}
fputc(previous, pcx_file);
}
}
if (output_to_stdout) {
fflush(pcx_file);
} else {
fclose(pcx_file);
}
return 0;
}

View File

@ -74,3 +74,4 @@ extern "C" {
#endif /* PCX_H */

View File

@ -34,11 +34,8 @@
/* this file contains the character table, the pre-calculated coefficients and the
codeword patterns taken from lines 416 to 454 of pdf417.frm */
#define TRUE 1
#define FALSE 0
#define TEX 900
#define BYT 901
#define NUM 902
#ifndef __PDF417_H
#define __PDF417_H
/* PDF417 error correction coefficients from Grand Zebu */
static const unsigned short int coefrs[1022] = {
@ -511,4 +508,7 @@ static const unsigned short int rap_centre[52] = {
0x2DC, 0x2DE
};
void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start, int length, int block);
INTERNAL void byteprocess(int *chainemc, int *mclength, const unsigned char chaine[], int start, const int length,
const int debug);
#endif /* __PDF417_H */

345
3rdparty/zint-2.10.0/backend/plessey.c vendored Normal file
View File

@ -0,0 +1,345 @@
/* plessey.c - Handles Plessey and MSI Plessey */
/*
libzint - the open source barcode library
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include <stdio.h>
#include "common.h"
#define SSET "0123456789ABCDEF"
static const char *PlessTable[16] = {
"13131313", "31131313", "13311313", "31311313",
"13133113", "31133113", "13313113", "31313113",
"13131331", "31131331", "13311331", "31311331",
"13133131", "31133131", "13313131", "31313131"
};
static const char *MSITable[10] = {
"12121212", "12121221", "12122112", "12122121", "12211212",
"12211221", "12212112", "12212121", "21121212", "21121221"
};
/* Not MSI/Plessey but the older Plessey standard */
INTERNAL int plessey(struct zint_symbol *symbol, unsigned char source[], int length) {
int i;
unsigned char *checkptr;
static const char grid[9] = {1, 1, 1, 1, 0, 1, 0, 0, 1};
char dest[554]; /* 8 + 65 * 8 + 8 * 2 + 9 + 1 = 554 */
int error_number;
if (length > 65) {
strcpy(symbol->errtxt, "370: Input too long (65 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(SSET, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "371: Invalid character in data (digits and \"ABCDEF\" only)");
return error_number;
}
if (!(checkptr = (unsigned char *) calloc(1, length * 4 + 8))) {
strcpy(symbol->errtxt, "373: Insufficient memory for check digit CRC buffer");
return ZINT_ERROR_MEMORY;
}
/* Start character */
strcpy(dest, "31311331");
/* Data area */
for (i = 0; i < length; i++) {
unsigned int check = posn(SSET, source[i]);
lookup(SSET, PlessTable, source[i], dest);
checkptr[4 * i] = check & 1;
checkptr[4 * i + 1] = (check >> 1) & 1;
checkptr[4 * i + 2] = (check >> 2) & 1;
checkptr[4 * i + 3] = (check >> 3) & 1;
}
/* CRC check digit code adapted from code by Leonid A. Broukhis
used in GNU Barcode */
for (i = 0; i < (4 * length); i++) {
if (checkptr[i]) {
int j;
for (j = 0; j < 9; j++)
checkptr[i + j] ^= grid[j];
}
}
for (i = 0; i < 8; i++) {
switch (checkptr[length * 4 + i]) {
case 0: strcat(dest, "13");
break;
case 1: strcat(dest, "31");
break;
}
}
/* Stop character */
strcat(dest, "331311313");
expand(symbol, dest);
// TODO: Find documentation on BARCODE_PLESSEY dimensions/height
symbol->text[0] = '\0';
ustrncat(symbol->text, source, length);
free(checkptr);
return error_number;
}
/* Modulo 10 check digit - Luhn algorithm
See https://en.wikipedia.org/wiki/Luhn_algorithm */
static char msi_check_digit_mod10(const unsigned char source[], const int length) {
static const int vals[2][10] = {
{ 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 }, /* Doubled and digits summed */
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, /* Single */
};
int i, x = 0, undoubled = 0;
for (i = length - 1; i >= 0; i--) {
/* Note overflow impossible for max length 65 * max weight 9 * max val 15 == 8775 */
x += vals[undoubled][ctoi(source[i])];
undoubled = !undoubled;
}
return itoc((10 - x % 10) % 10);
}
/* Modulo 11 check digit - IBM weight system wrap = 7, NCR system wrap = 9
See https://en.wikipedia.org/wiki/MSI_Barcode */
static char msi_check_digit_mod11(const unsigned char source[], const int length, const int wrap) {
int i, x = 0, weight = 2;
for (i = length - 1; i >= 0; i--) {
/* Note overflow impossible for max length 65 * max weight 9 * max val 15 == 8775 */
x += weight * ctoi(source[i]);
weight++;
if (weight > wrap) {
weight = 2;
}
}
return itoc((11 - x % 11) % 11); /* Will return 'A' for 10 */
}
/* Plain MSI Plessey - does not calculate any check character */
static void msi_plessey(struct zint_symbol *symbol, const unsigned char source[], const int length, char dest[]) {
int i;
for (i = 0; i < length; i++) {
lookup(NEON, MSITable, source[i], dest);
}
symbol->text[0] = '\0';
ustrncat(symbol->text, source, length);
}
/* MSI Plessey with Modulo 10 check digit */
static void msi_plessey_mod10(struct zint_symbol *symbol, const unsigned char source[], const int length,
const int no_checktext, char dest[]) {
int i;
char check_digit;
/* draw data section */
for (i = 0; i < length; i++) {
lookup(NEON, MSITable, source[i], dest);
}
/* calculate check digit */
check_digit = msi_check_digit_mod10(source, length);
/* draw check digit */
lookup(NEON, MSITable, check_digit, dest);
symbol->text[0] = '\0';
ustrncat(symbol->text, source, length);
if (!no_checktext) {
symbol->text[length] = check_digit;
symbol->text[length + 1] = '\0';
}
}
/* MSI Plessey with two Modulo 10 check digits */
static void msi_plessey_mod1010(struct zint_symbol *symbol, const unsigned char source[], const int length,
const int no_checktext, char dest[]) {
int i;
unsigned char temp[65 + 2 + 1];
/* Append check digits */
temp[0] = '\0';
ustrncat(temp, source, length);
temp[length] = msi_check_digit_mod10(source, length);
temp[length + 1] = msi_check_digit_mod10(temp, length + 1);
temp[length + 2] = '\0';
/* draw data section */
for (i = 0; i < length + 2; i++) {
lookup(NEON, MSITable, temp[i], dest);
}
if (no_checktext) {
symbol->text[0] = '\0';
ustrncat(symbol->text, source, length);
} else {
ustrcpy(symbol->text, temp);
}
}
/* MSI Plessey with Modulo 11 check digit */
static void msi_plessey_mod11(struct zint_symbol *symbol, const unsigned char source[], const int length,
const int no_checktext, const int wrap, char dest[]) {
/* Uses the IBM weight system if wrap = 7, and the NCR system if wrap = 9 */
int i;
char check_digit;
/* draw data section */
for (i = 0; i < length; i++) {
lookup(NEON, MSITable, source[i], dest);
}
/* Append check digit */
check_digit = msi_check_digit_mod11(source, length, wrap);
if (check_digit == 'A') {
lookup(NEON, MSITable, '1', dest);
lookup(NEON, MSITable, '0', dest);
} else {
lookup(NEON, MSITable, check_digit, dest);
}
symbol->text[0] = '\0';
ustrncat(symbol->text, source, length);
if (!no_checktext) {
if (check_digit == 'A') {
ustrcat(symbol->text, "10");
} else {
symbol->text[length] = check_digit;
symbol->text[length + 1] = '\0';
}
}
}
/* MSI Plessey with Modulo 11 check digit and Modulo 10 check digit */
static void msi_plessey_mod1110(struct zint_symbol *symbol, const unsigned char source[], const int length,
const int no_checktext, const int wrap, char dest[]) {
/* Uses the IBM weight system if wrap = 7, and the NCR system if wrap = 9 */
int i;
char check_digit;
unsigned char temp[65 + 3 + 1];
int temp_len = length;
temp[0] = '\0';
ustrncat(temp, source, length);
/* Append first (mod 11) digit */
check_digit = msi_check_digit_mod11(source, length, wrap);
if (check_digit == 'A') {
temp[temp_len++] = '1';
temp[temp_len++] = '0';
} else {
temp[temp_len++] = check_digit;
}
/* Append second (mod 10) check digit */
temp[temp_len] = msi_check_digit_mod10(temp, temp_len);
temp[++temp_len] = '\0';
/* draw data section */
for (i = 0; i < temp_len; i++) {
lookup(NEON, MSITable, temp[i], dest);
}
if (no_checktext) {
symbol->text[0] = '\0';
ustrncat(symbol->text, source, length);
} else {
ustrcpy(symbol->text, temp);
}
}
INTERNAL int msi_handle(struct zint_symbol *symbol, unsigned char source[], int length) {
int error_number;
char dest[550]; /* 2 + 65 * 8 + 3 * 8 + 3 + 1 = 550 */
int check_option = symbol->option_2;
int no_checktext = 0;
if (length > 65) {
strcpy(symbol->errtxt, "372: Input too long (65 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number != 0) {
strcpy(symbol->errtxt, "377: Invalid character in data (digits only)");
return ZINT_ERROR_INVALID_DATA;
}
if (check_option >= 11 && check_option <= 16) { /* +10 means don't print check digits in HRT */
check_option -= 10;
no_checktext = 1;
}
if ((check_option < 0) || (check_option > 6)) {
check_option = 0;
}
/* Start character */
strcpy(dest, "21");
switch (check_option) {
case 0: msi_plessey(symbol, source, length, dest);
break;
case 1: msi_plessey_mod10(symbol, source, length, no_checktext, dest);
break;
case 2: msi_plessey_mod1010(symbol, source, length, no_checktext, dest);
break;
case 3: msi_plessey_mod11(symbol, source, length, no_checktext, 7 /*IBM wrap*/, dest);
break;
case 4: msi_plessey_mod1110(symbol, source, length, no_checktext, 7 /*IBM wrap*/, dest);
break;
case 5: msi_plessey_mod11(symbol, source, length, no_checktext, 9 /*NCR wrap*/, dest);
break;
case 6: msi_plessey_mod1110(symbol, source, length, no_checktext, 9 /*NCR wrap*/, dest);
break;
}
/* Stop character */
strcat(dest, "121");
expand(symbol, dest);
// TODO: Find documentation on BARCODE_MSI_PLESSEY dimensions/height
return error_number;
}

344
3rdparty/zint-2.10.0/backend/png.c vendored Normal file
View File

@ -0,0 +1,344 @@
/* png.c - Handles output to PNG file */
/*
libzint - the open source barcode library
Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#ifndef NO_PNG
#include <errno.h>
#include <stdio.h>
#ifdef _MSC_VER
#include <fcntl.h>
#include <io.h>
#include <malloc.h>
#endif
#include "common.h"
#include <png.h>
#include <zlib.h>
#include <setjmp.h>
#define SSET "0123456789ABCDEF"
/* Note if change this need to change "backend/tests/test_png.c" definition also */
struct wpng_error_type {
struct zint_symbol *symbol;
jmp_buf jmpbuf;
};
STATIC_UNLESS_ZINT_TEST void wpng_error_handler(png_structp png_ptr, png_const_charp msg) {
struct wpng_error_type *wpng_error_ptr;
wpng_error_ptr = (struct wpng_error_type *) png_get_error_ptr(png_ptr);
if (wpng_error_ptr == NULL) {
/* we are completely hosed now */
fprintf(stderr, "Error 636: libpng error: %s\n", msg ? msg : "<NULL>");
fprintf(stderr, "Error 637: jmpbuf not recoverable, terminating\n");
fflush(stderr);
return; /* libpng will call abort() */
}
sprintf(wpng_error_ptr->symbol->errtxt, "635: libpng error: %.60s", msg ? msg : "<NULL>");
longjmp(wpng_error_ptr->jmpbuf, 1);
}
/* Guestimate best compression strategy */
static int guess_compression_strategy(struct zint_symbol *symbol, unsigned char *pixelbuf) {
(void)pixelbuf;
/* TODO: Do properly */
/* It seems the best choice for typical barcode pngs is one of Z_DEFAULT_STRATEGY and Z_FILTERED */
/* Some guesses */
if (symbol->symbology == BARCODE_MAXICODE) {
return Z_DEFAULT_STRATEGY;
}
if (symbol->symbology == BARCODE_AZTEC && symbol->bitmap_width <= 30) {
return Z_DEFAULT_STRATEGY;
}
/* Z_FILTERED seems to work better for slightly more barcodes+data so default to that */
return Z_FILTERED;
}
INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) {
struct wpng_error_type wpng_error;
FILE *outfile;
png_structp png_ptr;
png_infop info_ptr;
int i;
int row, column;
png_color bg, fg;
unsigned char bg_alpha, fg_alpha;
unsigned char map[128];
png_color palette[32];
int num_palette;
unsigned char trans_alpha[32];
int num_trans;
int bit_depth;
int compression_strategy;
unsigned char *pb;
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT;
#ifndef _MSC_VER
unsigned char outdata[symbol->bitmap_width];
#else
unsigned char *outdata = (unsigned char *) _alloca(symbol->bitmap_width);
#endif
wpng_error.symbol = symbol;
fg.red = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
fg.green = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]);
fg.blue = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
bg.red = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]);
bg.green = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
bg.blue = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
if (strlen(symbol->fgcolour) > 6) {
fg_alpha = (16 * ctoi(symbol->fgcolour[6])) + ctoi(symbol->fgcolour[7]);
} else {
fg_alpha = 0xff;
}
if (strlen(symbol->bgcolour) > 6) {
bg_alpha = (16 * ctoi(symbol->bgcolour[6])) + ctoi(symbol->bgcolour[7]);
} else {
bg_alpha = 0xff;
}
num_trans = 0;
if (symbol->symbology == BARCODE_ULTRA) {
static const int ultra_chars[8] = { 'W', 'C', 'B', 'M', 'R', 'Y', 'G', 'K' };
static const png_color ultra_colours[8] = {
{ 0xff, 0xff, 0xff, }, /* White */
{ 0, 0xff, 0xff, }, /* Cyan */
{ 0, 0, 0xff, }, /* Blue */
{ 0xff, 0, 0xff, }, /* Magenta */
{ 0xff, 0, 0, }, /* Red */
{ 0xff, 0xff, 0, }, /* Yellow */
{ 0, 0xff, 0, }, /* Green */
{ 0, 0, 0, }, /* Black */
};
for (i = 0; i < 8; i++) {
map[ultra_chars[i]] = i;
palette[i] = ultra_colours[i];
if (fg_alpha != 0xff) {
trans_alpha[i] = fg_alpha;
}
}
num_palette = 8;
if (fg_alpha != 0xff) {
num_trans = 8;
}
/* For Ultracode, have foreground only if have bind/box */
if (symbol->border_width > 0 && (symbol->output_options & (BARCODE_BIND | BARCODE_BOX))) {
/* Check whether can re-use black */
if (fg.red == 0 && fg.green == 0 && fg.blue == 0) {
map['1'] = 7; /* Re-use black */
} else {
map['1'] = num_palette;
palette[num_palette++] = fg;
if (fg_alpha != 0xff) {
trans_alpha[num_trans++] = fg_alpha;
}
}
}
/* For Ultracode, have background only if have whitespace/quiet zones */
if (symbol->whitespace_width > 0 || symbol->whitespace_height > 0) { /* TODO: BARCODE_QUIET_ZONES also */
/* Check whether can re-use white */
if (bg.red == 0xff && bg.green == 0xff && bg.blue == 0xff && bg_alpha == fg_alpha) {
map['0'] = 0; /* Re-use white */
} else {
if (bg_alpha == 0xff || fg_alpha != 0xff) {
/* No alpha or have foreground alpha - add to end */
map['0'] = num_palette;
palette[num_palette++] = bg;
} else {
/* Alpha and no foreground alpha - add to front & move white to end */
map['0'] = 0;
palette[0] = bg;
map['W'] = num_palette;
palette[num_palette++] = ultra_colours[0];
}
if (bg_alpha != 0xff) {
trans_alpha[num_trans++] = bg_alpha;
}
}
}
} else {
int bg_idx = 0, fg_idx = 1;
/* Do alphas first so can swop indexes if background not alpha */
if (bg_alpha != 0xff) {
trans_alpha[num_trans++] = bg_alpha;
}
if (fg_alpha != 0xff) {
trans_alpha[num_trans++] = fg_alpha;
if (num_trans == 1) {
/* Only foreground has alpha so swop indexes - saves a byte! */
bg_idx = 1;
fg_idx = 0;
}
}
map['0'] = bg_idx;
palette[bg_idx] = bg;
map['1'] = fg_idx;
palette[fg_idx] = fg;
num_palette = 2;
}
if (num_palette <= 2) {
bit_depth = 1;
} else {
bit_depth = 4;
}
/* Open output file in binary mode */
if (output_to_stdout) {
#ifdef _MSC_VER
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
sprintf(symbol->errtxt, "631: Could not set stdout to binary (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
#endif
outfile = stdout;
} else {
if (!(outfile = fopen(symbol->outfile, "wb"))) {
sprintf(symbol->errtxt, "632: Could not open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
}
/* Set up error handling routine as proc() above */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, &wpng_error, wpng_error_handler, NULL);
if (!png_ptr) {
strcpy(symbol->errtxt, "633: Insufficient memory for PNG write structure buffer");
if (!output_to_stdout) {
fclose(outfile);
}
return ZINT_ERROR_MEMORY;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr, NULL);
strcpy(symbol->errtxt, "634: Insufficient memory for PNG info structure buffer");
if (!output_to_stdout) {
fclose(outfile);
}
return ZINT_ERROR_MEMORY;
}
/* catch jumping here */
if (setjmp(wpng_error.jmpbuf)) {
png_destroy_write_struct(&png_ptr, &info_ptr);
if (!output_to_stdout) {
fclose(outfile);
}
return ZINT_ERROR_MEMORY;
}
/* open output file with libpng */
png_init_io(png_ptr, outfile);
/* set compression */
png_set_compression_level(png_ptr, 9);
/* Compression strategy can make a difference */
compression_strategy = guess_compression_strategy(symbol, pixelbuf);
if (compression_strategy != Z_DEFAULT_STRATEGY) {
png_set_compression_strategy(png_ptr, compression_strategy);
}
/* set Header block */
png_set_IHDR(png_ptr, info_ptr, symbol->bitmap_width, symbol->bitmap_height,
bit_depth, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_set_PLTE(png_ptr, info_ptr, palette, num_palette);
if (num_trans) {
png_set_tRNS(png_ptr, info_ptr, trans_alpha, num_trans, NULL);
}
/* write all chunks up to (but not including) first IDAT */
png_write_info(png_ptr, info_ptr);
/* Pixel Plotting */
pb = pixelbuf;
if (bit_depth == 1) {
for (row = 0; row < symbol->bitmap_height; row++) {
unsigned char *image_data = outdata;
for (column = 0; column < symbol->bitmap_width; column += 8, image_data++) {
unsigned char byte = 0;
for (i = 0; i < 8 && column + i < symbol->bitmap_width; i++, pb++) {
byte |= map[*pb] << (7 - i);
}
*image_data = byte;
}
/* write row contents to file */
png_write_row(png_ptr, outdata);
}
} else { /* Bit depth 4 */
for (row = 0; row < symbol->bitmap_height; row++) {
unsigned char *image_data = outdata;
for (column = 0; column < symbol->bitmap_width; column += 2, image_data++) {
unsigned char byte = map[*pb++] << 4;
if (column + 1 < symbol->bitmap_width) {
byte |= map[*pb++];
}
*image_data = byte;
}
/* write row contents to file */
png_write_row(png_ptr, outdata);
}
}
/* End the file */
png_write_end(png_ptr, NULL);
/* make sure we have disengaged */
png_destroy_write_struct(&png_ptr, &info_ptr);
if (output_to_stdout) {
fflush(outfile);
} else {
fclose(outfile);
}
return 0;
}
#else
/* https://stackoverflow.com/a/26541331/664741 Suppresses gcc warning ISO C forbids an empty translation unit */
typedef int make_iso_compilers_happy;
#endif /* NO_PNG */

View File

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Including bug fixes by Bryan Hatton
Redistribution and use in source and binary forms, with or without
@ -30,9 +30,8 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef _MSC_VER
#include <malloc.h>
@ -84,21 +83,67 @@ static const char *JapanTable[19] = {
"414", "324", "342", "234", "432", "243", "423", "441", "111"
};
/* Handles the PostNet system used for Zip codes in the US */
int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) {
unsigned int i, sum, check_digit;
int error_number;
/* Set height for POSTNET/PLANET codes, maintaining ratio */
static int usps_set_height(struct zint_symbol *symbol, const int no_errtxt) {
/* USPS Domestic Mail Manual (USPS DMM 300) Jan 8, 2006 (updated 2011) 708.4.2.5 POSTNET Barcode Dimensions and
Spacing
http://web.archive.org/web/20061113174253/http://pe.usps.com/cpim/ftp/manuals/dmm300/full/mailingStandards.pdf
Using bar pitch as X (1" / 43) ~ 0.023" based on 22 bars + 21 spaces per inch (bar width 0.015" - 0.025")
Half bar height 0.05" +- 0.01; 0.040" (min) / 0.025" (X max) = 1.6 min, 0.060" (max) / 0.015" (X min) = 4 max
Full bar height 0.125" +- 0.01; 0.115" (min) / 0.025" (X max) = 4.6 min, 0.135" (max) / 0.015" (X min) = 9 max
*/
int error_number = 0;
float h_ratio; /* Half ratio */
error_number = 0;
#ifdef COMPLIANT_HEIGHTS
symbol->row_height[0] = 0.075f * 43; /* 3.225 */
symbol->row_height[1] = 0.05f * 43; /* 2.15 */
#else
symbol->row_height[0] = 6.0f;
symbol->row_height[1] = 6.0f;
#endif
if (symbol->height) {
h_ratio = symbol->row_height[1] / (symbol->row_height[0] + symbol->row_height[1]); /* 0.4 */
symbol->row_height[1] = symbol->height * h_ratio;
if (symbol->row_height[1] < 0.5f) { /* Absolute minimum */
symbol->row_height[1] = 0.5f;
symbol->row_height[0] = 0.5f / h_ratio - 0.5f; /* 0.75 */
} else {
symbol->row_height[0] = symbol->height - symbol->row_height[1];
}
}
symbol->height = symbol->row_height[0] + symbol->row_height[1];
#ifdef COMPLIANT_HEIGHTS
if (symbol->height < 4.6f || symbol->height > 9.0f) {
error_number = ZINT_WARN_NONCOMPLIANT;
if (!no_errtxt) {
strcpy(symbol->errtxt, "498: Height not compliant with standards");
}
}
#else
(void)&no_errtxt;
#endif
return error_number;
}
/* Handles the PostNet system used for Zip codes in the US */
static int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) {
int i, sum, check_digit;
int error_number = 0;
if (length > 38) {
strcpy(symbol->errtxt, "480: Input too long");
strcpy(symbol->errtxt, "480: Input too long (38 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "481: Invalid characters in data");
return error_number;
if (length != 5 && length != 9 && length != 11) {
strcpy(symbol->errtxt, "479: Input length is not standard (5, 9 or 11 characters)");
error_number = ZINT_WARN_NONCOMPLIANT;
}
if (is_sane(NEON, source, length) == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "481: Invalid character in data (digits only)");
return ZINT_ERROR_INVALID_DATA;
}
sum = 0;
@ -120,51 +165,49 @@ int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int
}
/* Puts PostNet barcodes into the pattern matrix */
int post_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 ~ 256 */
INTERNAL int post_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 = 206 */
unsigned int loopey, h;
int writer;
int error_number;
error_number = 0;
int error_number, warn_number;
error_number = postnet(symbol, source, height_pattern, length);
if (error_number != 0) {
if (error_number >= ZINT_ERROR) {
return error_number;
}
writer = 0;
h = strlen(height_pattern);
h = (int) strlen(height_pattern);
for (loopey = 0; loopey < h; loopey++) {
if (height_pattern[loopey] == 'L') {
set_module(symbol, 0, writer);
}
set_module(symbol, 1, writer);
writer += 3;
writer += 2;
}
symbol->row_height[0] = 6;
symbol->row_height[1] = 6;
warn_number = usps_set_height(symbol, error_number /*no_errtxt*/);
symbol->rows = 2;
symbol->width = writer - 1;
return error_number;
return error_number ? error_number : warn_number;
}
/* Handles the PLANET system used for item tracking in the US */
int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) {
unsigned int i, sum, check_digit;
int error_number;
error_number = 0;
static int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) {
int i, sum, check_digit;
int error_number = 0;
if (length > 38) {
strcpy(symbol->errtxt, "482: Input too long");
strcpy(symbol->errtxt, "482: Input too long (38 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "483: Invalid characters in data");
return error_number;
if (length != 11 && length != 13) {
strcpy(symbol->errtxt, "478: Input length is not standard (11 or 13 characters)");
error_number = ZINT_WARN_NONCOMPLIANT;
}
if (is_sane(NEON, source, length) == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "483: Invalid character in data (digits only)");
return ZINT_ERROR_INVALID_DATA;
}
sum = 0;
@ -186,53 +229,50 @@ int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int
}
/* Puts PLANET barcodes into the pattern matrix */
int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 ~ 256 */
INTERNAL int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 = 206 */
unsigned int loopey, h;
int writer;
int error_number;
error_number = 0;
int error_number, warn_number;
error_number = planet(symbol, source, height_pattern, length);
if (error_number != 0) {
if (error_number >= ZINT_ERROR) {
return error_number;
}
writer = 0;
h = strlen(height_pattern);
h = (int) strlen(height_pattern);
for (loopey = 0; loopey < h; loopey++) {
if (height_pattern[loopey] == 'L') {
set_module(symbol, 0, writer);
}
set_module(symbol, 1, writer);
writer += 3;
writer += 2;
}
symbol->row_height[0] = 6;
symbol->row_height[1] = 6;
warn_number = usps_set_height(symbol, error_number /*no_errtxt*/);
symbol->rows = 2;
symbol->width = writer - 1;
return error_number;
return error_number ? error_number : warn_number;
}
/* Korean Postal Authority */
int korea_post(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int korea_post(struct zint_symbol *symbol, unsigned char source[], int length) {
int total, loop, check, zeroes, error_number;
char localstr[8], dest[80];
error_number = 0;
if (length > 6) {
strcpy(symbol->errtxt, "484: Input too long");
strcpy(symbol->errtxt, "484: Input too long (6 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "485: Invalid characters in data");
strcpy(symbol->errtxt, "485: Invalid character in data (digits only)");
return error_number;
}
zeroes = 6 - length;
memset(localstr, '0', zeroes);
strcpy(localstr + zeroes, (char *) source);
ustrcpy(localstr + zeroes, source);
total = 0;
for (loop = 0; loop < 6; loop++) {
@ -250,19 +290,21 @@ int korea_post(struct zint_symbol *symbol, unsigned char source[], int length) {
}
lookup(NEON, KoreaTable, localstr[6], dest);
expand(symbol, dest);
ustrcpy(symbol->text, (unsigned char*) localstr);
ustrcpy(symbol->text, localstr);
// TODO: Find documentation on BARCODE_KOREAPOST dimensions/height
return error_number;
}
/* The simplest barcode symbology ever! Supported by MS Word, so here it is!
glyphs from http://en.wikipedia.org/wiki/Facing_Identification_Mark */
int fim(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int fim(struct zint_symbol *symbol, unsigned char source[], int length) {
int error_number = 0;
char dest[16] = {0};
if (length > 1) {
strcpy(symbol->errtxt, "486: Input too long");
strcpy(symbol->errtxt, "486: Input too long (1 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
@ -284,18 +326,63 @@ int fim(struct zint_symbol *symbol, unsigned char source[], int length) {
strcpy(dest, "1111131311111");
break;
default:
strcpy(symbol->errtxt, "487: Invalid characters in data");
strcpy(symbol->errtxt, "487: Invalid character in data (\"A\", \"B\", \"C\" or \"D\" only)");
return ZINT_ERROR_INVALID_DATA;
break;
}
expand(symbol, dest);
return 0;
#ifdef COMPLIANT_HEIGHTS
/* USPS Domestic Mail Manual (USPS DMM 300) Jan 8, 2006 (updated 2011) 708.9.3
X 0.03125" (1/32) +- 0.008" so X max 0.03925", height 0.625" (5/8) +- 0.125" (1/8) */
error_number = set_height(symbol, (float) (0.5 / 0.03925), 20.0f /*0.625 / 0.03125*/, (float) (0.75 / 0.02415),
0 /*no_errtxt*/);
#else
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
#endif
return error_number;
}
/* Set height for DAFT-type codes, maintaining ratio. Expects row_height[0] & row_height[1] to be set */
/* Used by auspost.c also */
INTERNAL int daft_set_height(struct zint_symbol *symbol, float min_height, float max_height) {
int error_number = 0;
float t_ratio; /* Tracker ratio */
if (symbol->height) {
t_ratio = symbol->row_height[1] / (symbol->row_height[0] * 2 + symbol->row_height[1]);
symbol->row_height[1] = symbol->height * t_ratio;
if (symbol->row_height[1] < 0.5f) { /* Absolute minimum */
symbol->row_height[1] = 0.5f;
symbol->row_height[0] = 0.25f / t_ratio - 0.25f;
} else {
symbol->row_height[0] = (symbol->height - symbol->row_height[1]) / 2.0f;
}
if (symbol->row_height[0] < 0.5f) {
symbol->row_height[0] = 0.5f;
symbol->row_height[1] = t_ratio / (1.0f - t_ratio);
}
}
symbol->row_height[2] = symbol->row_height[0];
symbol->height = symbol->row_height[0] + symbol->row_height[1] + symbol->row_height[2];
#ifdef COMPLIANT_HEIGHTS
if ((min_height && symbol->height < min_height) || (max_height && symbol->height > max_height)) {
error_number = ZINT_WARN_NONCOMPLIANT;
strcpy(symbol->errtxt, "499: Height not compliant with standards");
}
#else
(void)min_height; (void)max_height;
#endif
return error_number;
}
/* Handles the 4 State barcodes used in the UK by Royal Mail */
char rm4scc(char source[], unsigned char dest[], int length) {
unsigned int i;
static char rm4scc(unsigned char source[], char dest[], int length) {
int i;
int top, bottom, row, column, check_digit;
char values[3], set_copy[] = KRSET;
@ -303,10 +390,10 @@ char rm4scc(char source[], unsigned char dest[], int length) {
bottom = 0;
/* start character */
strcpy((char*) dest, "1");
strcpy(dest, "1");
for (i = 0; i < length; i++) {
lookup(KRSET, RoyalTable, source[i], (char*) dest);
lookup(KRSET, RoyalTable, source[i], dest);
strcpy(values, RoyalValues[posn(KRSET, source[i])]);
top += ctoi(values[0]);
bottom += ctoi(values[1]);
@ -322,38 +409,36 @@ char rm4scc(char source[], unsigned char dest[], int length) {
column = 5;
}
check_digit = (6 * row) + column;
strcat((char*) dest, RoyalTable[check_digit]);
strcat(dest, RoyalTable[check_digit]);
/* stop character */
strcat((char*) dest, "0");
strcat(dest, "0");
return set_copy[check_digit];
}
/* Puts RM4SCC into the data matrix */
int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
char height_pattern[210];
unsigned int loopey, h;
int loopey, h;
int writer;
int error_number;
strcpy(height_pattern, "");
error_number = 0;
if (length > 50) {
strcpy(symbol->errtxt, "488: Input too long");
strcpy(symbol->errtxt, "488: Input too long (50 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
to_upper(source);
error_number = is_sane(KRSET, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "489: Invalid characters in data");
strcpy(symbol->errtxt, "489: Invalid character in data (alphanumerics only)");
return error_number;
}
/*check = */rm4scc((char*) source, (unsigned char*) height_pattern, length);
/*check = */rm4scc(source, height_pattern, length);
writer = 0;
h = strlen(height_pattern);
h = (int) strlen(height_pattern);
for (loopey = 0; loopey < h; loopey++) {
if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) {
set_module(symbol, 0, writer);
@ -365,9 +450,21 @@ int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
writer += 2;
}
symbol->row_height[0] = 3;
symbol->row_height[1] = 2;
symbol->row_height[2] = 3;
#ifdef COMPLIANT_HEIGHTS
/* Royal Mail Know How User's Manual Appendix C: using CBC
https://web.archive.org/web/20120120060743/http://www.royalmail.com/sites/default/files/docs/pdf/Know How 2006 PIP vs 1.6a Accepted Changes.pdf
Bar pitch and min/maxes same as Mailmark, so using recommendations from Royal Mail Mailmark Barcode Definition
Document (15 Sept 2015) Section 3.5.1
*/
symbol->row_height[0] = (float) ((1.9 * 42.3) / 25.4); /* ~3.16 */
symbol->row_height[1] = (float) ((1.3 * 42.3) / 25.4); /* ~2.16 */
/* Note using max X for minimum and min X for maximum */
error_number = daft_set_height(symbol, (float) ((4.22 * 39) / 25.4), (float) ((5.84 * 47) / 25.4));
#else
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
error_number = daft_set_height(symbol, 0.0f, 0.0f);
#endif
symbol->rows = 3;
symbol->width = writer - 1;
@ -377,27 +474,25 @@ int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Handles Dutch Post TNT KIX symbols
The same as RM4SCC but without check digit
Specification at http://www.tntpost.nl/zakelijk/klantenservice/downloads/kIX_code/download.aspx */
int kix_code(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int kix_code(struct zint_symbol *symbol, unsigned char source[], int length) {
char height_pattern[75], localstr[20];
unsigned int loopey;
int loopey;
int writer, i, h;
int error_number; /* zeroes; */
int error_number;
strcpy(height_pattern, "");
error_number = 0;
if (length > 18) {
strcpy(symbol->errtxt, "490: Input too long");
strcpy(symbol->errtxt, "490: Input too long (18 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
to_upper(source);
error_number = is_sane(KRSET, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "491: Invalid characters in data");
strcpy(symbol->errtxt, "491: Invalid character in data (alphanumerics only)");
return error_number;
}
strcpy(localstr, (char *) source);
ustrcpy(localstr, source);
/* Encode data */
for (i = 0; i < length; i++) {
@ -405,7 +500,7 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[], int length) {
}
writer = 0;
h = strlen(height_pattern);
h = (int) strlen(height_pattern);
for (loopey = 0; loopey < h; loopey++) {
if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) {
set_module(symbol, 0, writer);
@ -417,9 +512,17 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[], int length) {
writer += 2;
}
symbol->row_height[0] = 3;
symbol->row_height[1] = 2;
symbol->row_height[2] = 3;
#ifdef COMPLIANT_HEIGHTS
/* Dimensions same as RM4SCC */
symbol->row_height[0] = (float) ((1.9 * 42.3) / 25.4); /* ~3.16 */
symbol->row_height[1] = (float) ((1.3 * 42.3) / 25.4); /* ~2.16 */
/* Note using max X for minimum and min X for maximum */
error_number = daft_set_height(symbol, (float) ((4.22 * 39) / 25.4), (float) ((5.84 * 47) / 25.4));
#else
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
error_number = daft_set_height(symbol, 0.0f, 0.0f);
#endif
symbol->rows = 3;
symbol->width = writer - 1;
@ -427,22 +530,21 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[], int length) {
}
/* Handles DAFT Code symbols */
int daft_code(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int daft_code(struct zint_symbol *symbol, unsigned char source[], int length) {
char height_pattern[100];
unsigned int loopey, h;
int writer, i, error_number;
strcpy(height_pattern, "");
error_number = 0;
if (length > 50) {
strcpy(symbol->errtxt, "492: Input too long");
strcpy(symbol->errtxt, "492: Input too long (50 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
to_upper((unsigned char*) source);
error_number = is_sane(DAFTSET, (unsigned char*) source, length);
to_upper(source);
error_number = is_sane(DAFTSET, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "493: Invalid characters in data");
strcpy(symbol->errtxt, "493: Invalid character in data (\"D\", \"A\", \"F\" and \"T\" only)");
return error_number;
}
@ -462,7 +564,7 @@ int daft_code(struct zint_symbol *symbol, unsigned char source[], int length) {
}
writer = 0;
h = strlen(height_pattern);
h = (int) strlen(height_pattern);
for (loopey = 0; loopey < h; loopey++) {
if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) {
set_module(symbol, 0, writer);
@ -474,9 +576,21 @@ int daft_code(struct zint_symbol *symbol, unsigned char source[], int length) {
writer += 2;
}
symbol->row_height[0] = 3;
symbol->row_height[1] = 2;
symbol->row_height[2] = 3;
/* Allow ratio of tracker to be specified in thousandths */
if (symbol->option_2 >= 50 && symbol->option_2 <= 900) {
float t_ratio = symbol->option_2 / 1000.0f;
if (symbol->height < 0.5f) {
symbol->height = 8.0f;
}
symbol->row_height[1] = symbol->height * t_ratio;
symbol->row_height[0] = (float) ((symbol->height - symbol->row_height[1]) / 2.0);
} else {
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
}
/* DAFT generic barcode so no dimensions/height specification */
(void) daft_set_height(symbol, 0.0f, 0.0f);
symbol->rows = 3;
symbol->width = writer - 1;
@ -484,19 +598,17 @@ int daft_code(struct zint_symbol *symbol, unsigned char source[], int length) {
}
/* Flattermarken - Not really a barcode symbology! */
int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length) {
int loop, error_number;
char dest[512]; /* 90 * 4 + 1 ~ */
error_number = 0;
if (length > 90) {
strcpy(symbol->errtxt, "494: Input too long");
strcpy(symbol->errtxt, "494: Input too long (90 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "495: Invalid characters in data");
strcpy(symbol->errtxt, "495: Invalid character in data (digits only)");
return error_number;
}
*dest = '\0';
@ -505,11 +617,14 @@ int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length
}
expand(symbol, dest);
// TODO: Find documentation on BARCODE_FLAT dimensions/height
return error_number;
}
/* Japanese Postal Code (Kasutama Barcode) */
int japan_post(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int japan_post(struct zint_symbol *symbol, unsigned char source[], int length) {
int error_number, h;
char pattern[69];
int writer, loopey, inter_posn, i, sum, check;
@ -517,29 +632,22 @@ int japan_post(struct zint_symbol *symbol, unsigned char source[], int length) {
char inter[23];
#ifndef _MSC_VER
char local_source[length + 1];
unsigned char local_source[length + 1];
#else
char* local_source = (char*) _alloca(length + 1);
unsigned char *local_source = (unsigned char *) _alloca(length + 1);
#endif
if (length > 20) {
strcpy(symbol->errtxt, "496: Input too long");
strcpy(symbol->errtxt, "496: Input too long (20 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
inter_posn = 0;
error_number = 0;
ustrcpy(local_source, source);
to_upper(local_source);
strcpy(local_source, (char*) source);
for (i = 0; i < length; i++) {
local_source[i] = source[i];
}
to_upper((unsigned char*) local_source);
error_number = is_sane(SHKASUTSET, (unsigned char*) local_source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "497: Invalid characters in data");
return error_number;
if (is_sane(SHKASUTSET, local_source, length) == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "497: Invalid character in data (alphanumerics and \"-\" only)");
return ZINT_ERROR_INVALID_DATA;
}
memset(inter, 'd', 20); /* Pad character CC4 */
inter[20] = '\0';
@ -586,20 +694,20 @@ int japan_post(struct zint_symbol *symbol, unsigned char source[], int length) {
}
if (check <= 9) {
check_char = check + '0';
}
if (check == 10) {
} else if (check == 10) {
check_char = '-';
}
if (check >= 11) {
} else {
check_char = (check - 11) + 'a';
}
strcat(pattern, JapanTable[posn(KASUTSET, check_char)]);
if (symbol->debug & ZINT_DEBUG_PRINT) printf("Check: %d, char: %c\n", check, check_char);
strcat(pattern, "31"); /* Stop */
/* Resolve pattern to 4-state symbols */
writer = 0;
h = strlen(pattern);
h = (int) strlen(pattern);
for (loopey = 0; loopey < h; loopey++) {
if ((pattern[loopey] == '2') || (pattern[loopey] == '1')) {
set_module(symbol, 0, writer);
@ -611,11 +719,22 @@ int japan_post(struct zint_symbol *symbol, unsigned char source[], int length) {
writer += 2;
}
symbol->row_height[0] = 3;
symbol->row_height[1] = 2;
symbol->row_height[2] = 3;
symbol->rows = 3;
symbol->width = writer - 1;
#ifdef COMPLIANT_HEIGHTS
/* Japan Post Zip/Barcode Manual pp.11-12 https://www.post.japanpost.jp/zipcode/zipmanual/p11.html
X 0.6mm (0.5mm - 0.7mm)
Tracker height 1.2mm (1.05mm - 1.35mm) / 0.6mm = 2,
Ascender/descender = 1.2mm (Full 3.6mm (3.4mm - 3.6mm, max preferred) less T divided by 2) / 0.6mm = 2 */
symbol->row_height[0] = 2.0f;
symbol->row_height[1] = 2.0f;
error_number = daft_set_height(symbol, (float) (3.4 / 0.7) /*~4.857*/, 3.6f / 0.5f /*7.2*/);
#else
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
error_number = daft_set_height(symbol, 0.0f, 0.0f);
#endif
return error_number;
}

494
3rdparty/zint-2.10.0/backend/ps.c vendored Normal file
View File

@ -0,0 +1,494 @@
/* ps.c - Post Script output */
/*
libzint - the open source barcode library
Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <math.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h"
static void colour_to_pscolor(int option, int colour, char *output) {
*output = '\0';
if ((option & CMYK_COLOUR) == 0) {
// Use RGB colour space
switch (colour) {
case 1: // Cyan
strcat(output, "0.00 1.00 1.00");
break;
case 2: // Blue
strcat(output, "0.00 0.00 1.00");
break;
case 3: // Magenta
strcat(output, "1.00 0.00 1.00");
break;
case 4: // Red
strcat(output, "1.00 0.00 0.00");
break;
case 5: // Yellow
strcat(output, "1.00 1.00 0.00");
break;
case 6: // Green
strcat(output, "0.00 1.00 0.00");
break;
case 8: // White
strcat(output, "1.00 1.00 1.00");
break;
default: // Black
strcat(output, "0.00 0.00 0.00");
break;
}
strcat(output, " setrgbcolor");
} else {
// Use CMYK colour space
switch (colour) {
case 1: // Cyan
strcat(output, "1.00 0.00 0.00 0.00");
break;
case 2: // Blue
strcat(output, "1.00 1.00 0.00 0.00");
break;
case 3: // Magenta
strcat(output, "0.00 1.00 0.00 0.00");
break;
case 4: // Red
strcat(output, "0.00 1.00 1.00 0.00");
break;
case 5: // Yellow
strcat(output, "0.00 0.00 1.00 0.00");
break;
case 6: // Green
strcat(output, "1.00 0.00 1.00 0.00");
break;
case 8: // White
strcat(output, "0.00 0.00 0.00 0.00");
break;
default: // Black
strcat(output, "0.00 0.00 0.00 1.00");
break;
}
strcat(output, " setcmykcolor");
}
}
STATIC_UNLESS_ZINT_TEST void ps_convert(const unsigned char *string, unsigned char *ps_string) {
const unsigned char *s;
unsigned char *p = ps_string;
for (s = string; *s; s++) {
switch (*s) {
case '(':
case ')':
case '\\':
*p++ = '\\';
*p++ = *s;
break;
case 0xC2: /* See `to_iso8859_1()` in raster.c */
*p++ = *++s;
break;
case 0xC3:
*p++ = *++s + 64;
break;
default:
if (*s < 0x80) {
*p++ = *s;
}
break;
}
}
*p = '\0';
}
INTERNAL int ps_plot(struct zint_symbol *symbol) {
FILE *feps;
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
float red_ink, green_ink, blue_ink, red_paper, green_paper, blue_paper;
float cyan_ink, magenta_ink, yellow_ink, black_ink;
float cyan_paper, magenta_paper, yellow_paper, black_paper;
int error_number = 0;
float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy;
float previous_diameter;
float radius, half_radius, half_sqrt3_radius;
int colour_index, colour_rect_flag;
char ps_color[33]; /* max "1.00 0.00 0.00 0.00 setcmykcolor" = 32 + 1 */
int draw_background = 1;
struct zint_vector_rect *rect;
struct zint_vector_hexagon *hex;
struct zint_vector_circle *circle;
struct zint_vector_string *string;
const char *locale = NULL;
const char *font;
int i, len;
int ps_len = 0;
int iso_latin1 = 0;
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT;
#ifdef _MSC_VER
unsigned char *ps_string;
#endif
if (symbol->vector == NULL) {
strcpy(symbol->errtxt, "646: Vector header NULL");
return ZINT_ERROR_INVALID_DATA;
}
if (strlen(symbol->bgcolour) > 6) {
if ((ctoi(symbol->bgcolour[6]) == 0) && (ctoi(symbol->bgcolour[7]) == 0)) {
draw_background = 0;
}
}
if (output_to_stdout) {
feps = stdout;
} else {
if (!(feps = fopen(symbol->outfile, "w"))) {
sprintf(symbol->errtxt, "645: Could not open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
}
locale = setlocale(LC_ALL, "C");
fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]);
fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]);
bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
red_ink = (float) (fgred / 256.0);
green_ink = (float) (fggrn / 256.0);
blue_ink = (float) (fgblu / 256.0);
red_paper = (float) (bgred / 256.0);
green_paper = (float) (bggrn / 256.0);
blue_paper = (float) (bgblu / 256.0);
/* Convert RGB to CMYK */
if (red_ink > green_ink) {
if (blue_ink > red_ink) {
black_ink = 1.0f - blue_ink;
} else {
black_ink = 1.0f - red_ink;
}
} else {
if (blue_ink > red_ink) {
black_ink = 1.0f - blue_ink;
} else {
black_ink = 1.0f - green_ink;
}
}
if (black_ink < 1.0f) {
cyan_ink = (1.0f - red_ink - black_ink) / (1.0f - black_ink);
magenta_ink = (1.0f - green_ink - black_ink) / (1.0f - black_ink);
yellow_ink = (1.0f - blue_ink - black_ink) / (1.0f - black_ink);
} else {
cyan_ink = 0.0f;
magenta_ink = 0.0f;
yellow_ink = 0.0f;
}
if (red_paper > green_paper) {
if (blue_paper > red_paper) {
black_paper = 1.0f - blue_paper;
} else {
black_paper = 1.0f - red_paper;
}
} else {
if (blue_paper > red_paper) {
black_paper = 1.0f - blue_paper;
} else {
black_paper = 1.0f - green_paper;
}
}
if (black_paper < 1.0f) {
cyan_paper = (1.0f - red_paper - black_paper) / (1.0f - black_paper);
magenta_paper = (1.0f - green_paper - black_paper) / (1.0f - black_paper);
yellow_paper = (1.0f - blue_paper - black_paper) / (1.0f - black_paper);
} else {
cyan_paper = 0.0f;
magenta_paper = 0.0f;
yellow_paper = 0.0f;
}
for (i = 0, len = (int) ustrlen(symbol->text); i < len; i++) {
switch (symbol->text[i]) {
case '(':
case ')':
case '\\':
ps_len += 2;
break;
default:
if (!iso_latin1 && symbol->text[i] >= 0x80) {
iso_latin1 = 1;
}
ps_len++; /* Will overcount 2 byte UTF-8 chars */
break;
}
}
#ifndef _MSC_VER
unsigned char ps_string[ps_len + 1];
#else
ps_string = (unsigned char *) _alloca(ps_len + 1);
#endif
/* Start writing the header */
fprintf(feps, "%%!PS-Adobe-3.0 EPSF-3.0\n");
if (ZINT_VERSION_BUILD) {
fprintf(feps, "%%%%Creator: Zint %d.%d.%d.%d\n",
ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE, ZINT_VERSION_BUILD);
} else {
fprintf(feps, "%%%%Creator: Zint %d.%d.%d\n", ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE);
}
fprintf(feps, "%%%%Title: Zint Generated Symbol\n");
fprintf(feps, "%%%%Pages: 0\n");
fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n",
(int) ceilf(symbol->vector->width), (int) ceilf(symbol->vector->height));
fprintf(feps, "%%%%EndComments\n");
/* Definitions */
fprintf(feps, "/TL { setlinewidth moveto lineto stroke } bind def\n");
fprintf(feps, "/TD { newpath 0 360 arc fill } bind def\n");
fprintf(feps, "/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def\n");
fprintf(feps, "/TB { 2 copy } bind def\n");
fprintf(feps, "/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def\n");
fprintf(feps, "/TE { pop pop } bind def\n");
fprintf(feps, "newpath\n");
/* Now the actual representation */
// Background
if (draw_background) {
if ((symbol->output_options & CMYK_COLOUR) == 0) {
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_paper, green_paper, blue_paper);
} else {
fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n", cyan_paper, magenta_paper, yellow_paper, black_paper);
}
fprintf(feps, "%.2f 0.00 TB 0.00 %.2f TR\n", symbol->vector->height, symbol->vector->width);
fprintf(feps, "TE\n");
}
if (symbol->symbology != BARCODE_ULTRA) {
if ((symbol->output_options & CMYK_COLOUR) == 0) {
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
} else {
fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n", cyan_ink, magenta_ink, yellow_ink, black_ink);
}
}
// Rectangles
if (symbol->symbology == BARCODE_ULTRA) {
colour_rect_flag = 0;
rect = symbol->vector->rectangles;
while (rect) {
if (rect->colour == -1) { // Foreground
if (colour_rect_flag == 0) {
// Set foreground colour
if ((symbol->output_options & CMYK_COLOUR) == 0) {
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
} else {
fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n",
cyan_ink, magenta_ink, yellow_ink, black_ink);
}
colour_rect_flag = 1;
}
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n",
rect->height, (symbol->vector->height - rect->y) - rect->height, rect->x, rect->width);
fprintf(feps, "TE\n");
}
rect = rect->next;
}
for (colour_index = 1; colour_index <= 8; colour_index++) {
colour_rect_flag = 0;
rect = symbol->vector->rectangles;
while (rect) {
if (rect->colour == colour_index) {
if (colour_rect_flag == 0) {
// Set new colour
colour_to_pscolor(symbol->output_options, colour_index, ps_color);
fprintf(feps, "%s\n", ps_color);
colour_rect_flag = 1;
}
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n",
rect->height, (symbol->vector->height - rect->y) - rect->height, rect->x, rect->width);
fprintf(feps, "TE\n");
}
rect = rect->next;
}
}
} else {
rect = symbol->vector->rectangles;
while (rect) {
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n",
rect->height, (symbol->vector->height - rect->y) - rect->height, rect->x, rect->width);
fprintf(feps, "TE\n");
rect = rect->next;
}
}
// Hexagons
previous_diameter = radius = half_radius = half_sqrt3_radius = 0.0f;
hex = symbol->vector->hexagons;
while (hex) {
if (previous_diameter != hex->diameter) {
previous_diameter = hex->diameter;
radius = (float) (0.5 * previous_diameter);
half_radius = (float) (0.25 * previous_diameter);
half_sqrt3_radius = (float) (0.43301270189221932338 * previous_diameter);
}
if ((hex->rotation == 0) || (hex->rotation == 180)) {
ay = (symbol->vector->height - hex->y) + radius;
by = (symbol->vector->height - hex->y) + half_radius;
cy = (symbol->vector->height - hex->y) - half_radius;
dy = (symbol->vector->height - hex->y) - radius;
ey = (symbol->vector->height - hex->y) - half_radius;
fy = (symbol->vector->height - hex->y) + half_radius;
ax = hex->x;
bx = hex->x + half_sqrt3_radius;
cx = hex->x + half_sqrt3_radius;
dx = hex->x;
ex = hex->x - half_sqrt3_radius;
fx = hex->x - half_sqrt3_radius;
} else {
ay = (symbol->vector->height - hex->y);
by = (symbol->vector->height - hex->y) + half_sqrt3_radius;
cy = (symbol->vector->height - hex->y) + half_sqrt3_radius;
dy = (symbol->vector->height - hex->y);
ey = (symbol->vector->height - hex->y) - half_sqrt3_radius;
fy = (symbol->vector->height - hex->y) - half_sqrt3_radius;
ax = hex->x - radius;
bx = hex->x - half_radius;
cx = hex->x + half_radius;
dx = hex->x + radius;
ex = hex->x + half_radius;
fx = hex->x - half_radius;
}
fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TH\n",
ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy);
hex = hex->next;
}
// Circles
previous_diameter = radius = 0.0f;
circle = symbol->vector->circles;
while (circle) {
if (previous_diameter != circle->diameter) {
previous_diameter = circle->diameter;
radius = (float) (0.5 * previous_diameter);
}
if (circle->colour) {
// A 'white' circle
if ((symbol->output_options & CMYK_COLOUR) == 0) {
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_paper, green_paper, blue_paper);
} else {
fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n",
cyan_paper, magenta_paper, yellow_paper, black_paper);
}
fprintf(feps, "%.2f %.2f %.2f TD\n", circle->x, (symbol->vector->height - circle->y), radius);
if (circle->next) {
if ((symbol->output_options & CMYK_COLOUR) == 0) {
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
} else {
fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n", cyan_ink, magenta_ink, yellow_ink, black_ink);
}
}
} else {
// A 'black' circle
fprintf(feps, "%.2f %.2f %.2f TD\n", circle->x, (symbol->vector->height - circle->y), radius);
}
circle = circle->next;
}
// Text
string = symbol->vector->strings;
if (string) {
if ((symbol->output_options & BOLD_TEXT)
&& (!is_extendable(symbol->symbology) || (symbol->output_options & SMALL_TEXT))) {
font = "Helvetica-Bold";
} else {
font = "Helvetica";
}
if (iso_latin1) {
/* Change encoding to ISO 8859-1, see Postscript Language Reference Manual 2nd Edition Example 5.6 */
fprintf(feps, "/%s findfont\n", font);
fprintf(feps, "dup length dict begin\n");
fprintf(feps, "{1 index /FID ne {def} {pop pop} ifelse} forall\n");
fprintf(feps, "/Encoding ISOLatin1Encoding def\n");
fprintf(feps, "currentdict\n");
fprintf(feps, "end\n");
fprintf(feps, "/Helvetica-ISOLatin1 exch definefont pop\n");
font = "Helvetica-ISOLatin1";
}
do {
ps_convert(string->text, ps_string);
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/%s findfont\n", font);
fprintf(feps, "%.2f scalefont setfont\n", string->fsize);
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n",
string->x, (symbol->vector->height - string->y));
if (string->halign == 0 || string->halign == 2) { /* Need width for middle or right align */
fprintf(feps, " (%s) stringwidth\n", ps_string);
}
if (string->rotation != 0) {
fprintf(feps, "gsave\n");
fprintf(feps, "%d rotate\n", 360 - string->rotation);
}
if (string->halign == 0 || string->halign == 2) {
fprintf(feps, "pop\n");
fprintf(feps, "%s 0 rmoveto\n", string->halign == 2 ? "neg" : "-2 div");
}
fprintf(feps, " (%s) show\n", ps_string);
if (string->rotation != 0) {
fprintf(feps, "grestore\n");
}
fprintf(feps, "setmatrix\n");
string = string->next;
} while (string);
}
if (output_to_stdout) {
fflush(feps);
} else {
fclose(feps);
}
if (locale)
setlocale(LC_ALL, locale);
return error_number;
}

3141
3rdparty/zint-2.10.0/backend/qr.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,7 @@
/* qr.h Data for QR Code */
/* qr.h Data for QR Code, Micro QR Code and rMQR
/*
libzint - the open source barcode library
Copyright (C) 2008-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2006 Kentaro Fukuchi <fukuchi@megaui.net>
Redistribution and use in source and binary forms, with or without
@ -30,15 +29,17 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#define LEVEL_L 1
#define LEVEL_M 2
#define LEVEL_Q 3
#define LEVEL_H 4
/* From ISO/IEC 18004:2015 Table 5 Encoding/decoding table for Alphanumeric mode */
static const char qr_alphanumeric[59] = {
36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, /* SP-/ */
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, /* 0-? */
-1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, /* @-O */
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 /* P-Z */
};
#define RHODIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"
/* From ISO/IEC 18004:2006 Table 7 */
/* From ISO/IEC 18004:2015 Table 7 */
static const unsigned short int qr_data_codewords_L[] = {
19, 34, 55, 80, 108, 136, 156, 194, 232, 274, 324, 370, 428, 461, 523, 589, 647,
721, 795, 861, 932, 1006, 1094, 1174, 1276, 1370, 1468, 1531, 1631,
@ -69,6 +70,92 @@ static const unsigned short int qr_total_codewords[] = {
2185, 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706
};
static const unsigned short int rmqr_height[] = {
7, 7, 7, 7, 7,
9, 9, 9, 9, 9,
11, 11, 11, 11, 11, 11,
13, 13, 13, 13, 13, 13,
15, 15, 15, 15, 15,
17, 17, 17, 17, 17
};
static const unsigned short int rmqr_width[] = {
43, 59, 77, 99, 139,
43, 59, 77, 99, 139,
27, 43, 59, 77, 99, 139,
27, 43, 59, 77, 99, 139,
43, 59, 77, 99, 139,
43, 59, 77, 99, 139
};
static const unsigned short int rmqr_data_codewords_M[] = {
6, 12, 20, 28, 44, // R7x
12, 21, 31, 42, 63, // R9x
7, 19, 31, 43, 57, 84, // R11x
12, 27, 38, 53, 73, 106, // R13x
33, 48, 67, 88, 127, // R15x
39, 56, 78, 100, 152 // R17x
};
static const unsigned short int rmqr_data_codewords_H[] = {
3, 7, 10, 14, 24, // R7x
7, 11, 17, 22, 33, // R9x
5, 11, 15, 23, 29, 42, // R11x
7, 13, 20, 29, 35, 54, // R13x
15, 26, 31, 48, 69, // R15x
21, 28, 38, 56, 76 // R17x
};
static const short int rmqr_fixed_height_upper_bound[] = {
-1, 4, 9, 15, 21, 26, 31
};
static const unsigned short int rmqr_total_codewords[] = {
13, 21, 32, 44, 68, // R7x
21, 33, 49, 66, 99, // R9x
15, 31, 47, 67, 89, 132, // R11x
21, 41, 60, 85, 113, 166, // R13x
51, 74, 103, 136, 199, // R15x
61, 88, 122, 160, 232 // R17x
};
static const unsigned short int rmqr_numeric_cci[] = {
4, 5, 6, 7, 7,
5, 6, 7, 7, 8,
4, 6, 7, 7, 8, 8,
5, 6, 7, 8, 8, 8, // Note R13x77 (4th) 8 bits but max numerics 124 (7 bits)
7, 7, 8, 8, 9,
7, 8, 8, 8, 9
};
static const unsigned short int rmqr_alphanum_cci[] = {
3, 5, 5, 6, 6,
5, 5, 6, 6, 7,
4, 5, 6, 6, 7, 7,
5, 6, 6, 7, 7, 8,
6, 7, 7, 7, 8,
6, 7, 7, 8, 8
};
static const unsigned short int rmqr_byte_cci[] = {
3, 4, 5, 5, 6,
4, 5, 5, 6, 6,
3, 5, 5, 6, 6, 7,
4, 5, 6, 6, 7, 7,
6, 6, 7, 7, 7,
6, 6, 7, 7, 8
};
static const unsigned short int rmqr_kanji_cci[] = {
2, 3, 4, 5, 5,
3, 4, 5, 5, 6,
2, 4, 5, 5, 6, 6,
3, 5, 5, 6, 6, 7,
5, 5, 6, 6, 7,
5, 6, 6, 6, 7
};
static const char qr_blocks_L[] = {
1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12,
12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25
@ -89,6 +176,24 @@ static const char qr_blocks_H[] = {
32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81
};
static const char rmqr_blocks_M[] = {
1, 1, 1, 1, 1, // R7x
1, 1, 1, 1, 2, // R9x
1, 1, 1, 1, 2, 2, // R11x
1, 1, 1, 2, 2, 3, // R13x
1, 1, 2, 2, 3, // R15x
1, 2, 2, 3, 4 // R17x
};
static const char rmqr_blocks_H[] = {
1, 1, 1, 1, 2, // R7x
1, 1, 2, 2, 3, // R9x
1, 1, 2, 2, 2, 3, // R11x
1, 1, 2, 2, 3, 4, // R13x
2, 2, 3, 4, 5, // R15x
2, 2, 3, 4, 6 // R17x
};
static const unsigned short int qr_sizes[] = {
21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97,
101, 105, 109, 113, 117, 121, 125, 129, 133, 137, 141, 145, 149, 153, 157, 161, 165, 169, 173, 177
@ -102,6 +207,7 @@ static const char qr_align_loopsize[] = {
0, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7
};
// Table E1 - Row/column coordinates of center module of alignment patterns
static const unsigned short int qr_table_e1[] = {
6, 18, 0, 0, 0, 0, 0,
6, 22, 0, 0, 0, 0, 0,
@ -144,6 +250,15 @@ static const unsigned short int qr_table_e1[] = {
6, 30, 58, 86, 114, 142, 170
};
// Table D1 - Column coordinates of centre module of alignment patterns
static const unsigned short int rmqr_table_d1[] = {
21, 0, 0, 0,
19, 39, 0, 0,
25, 51, 0, 0,
23, 49, 75, 0,
27, 55, 83, 111
};
static const unsigned int qr_annex_c[] = {
/* Format information bit sequences */
0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0, 0x77c4, 0x72f3, 0x7daa, 0x789d,
@ -165,3 +280,25 @@ static const unsigned int qr_annex_c1[] = {
0x7c16, 0x7921, 0x06de, 0x03e9, 0x0cb0, 0x0987, 0x1735, 0x1202, 0x1d5b, 0x186c, 0x2508, 0x203f, 0x2f66, 0x2a51, 0x34e3,
0x31d4, 0x3e8d, 0x3bba
};
static const unsigned int rmqr_format_info_left[] = {
/* rMQR format information for finder pattern side */
0x1FAB2, 0x1E597, 0x1DBDD, 0x1C4F8, 0x1B86C, 0x1A749, 0x19903, 0x18626, 0x17F0E, 0x1602B,
0x15E61, 0x14144, 0x13DD0, 0x122F5, 0x11CBF, 0x1039A, 0x0F1CA, 0x0EEEF, 0x0D0A5, 0x0CF80,
0x0B314, 0x0AC31, 0x0927B, 0x08D5E, 0x07476, 0x06B53, 0x05519, 0x04A3C, 0x036A8, 0x0298D,
0x017C7, 0x008E2, 0x3F367, 0x3EC42, 0x3D208, 0x3CD2D, 0x3B1B9, 0x3AE9C, 0x390D6, 0x38FF3,
0x376DB, 0x369FE, 0x357B4, 0x34891, 0x33405, 0x32B20, 0x3156A, 0x30A4F, 0x2F81F, 0x2E73A,
0x2D970, 0x2C655, 0x2BAC1, 0x2A5E4, 0x29BAE, 0x2848B, 0x27DA3, 0x26286, 0x25CCC, 0x243E9,
0x23F7D, 0x22058, 0x21E12, 0x20137
};
static const unsigned int rmqr_format_info_right[] = {
/* rMQR format information for subfinder pattern side */
0x20A7B, 0x2155E, 0x22B14, 0x23431, 0x248A5, 0x25780, 0x269CA, 0x276EF, 0x28FC7, 0x290E2,
0x2AEA8, 0x2B18D, 0x2CD19, 0x2D23C, 0x2EC76, 0x2F353, 0x30103, 0x31E26, 0x3206C, 0x33F49,
0x343DD, 0x35CF8, 0x362B2, 0x37D97, 0x384BF, 0x39B9A, 0x3A5D0, 0x3BAF5, 0x3C661, 0x3D944,
0x3E70E, 0x3F82B, 0x003AE, 0x01C8B, 0x022C1, 0x03DE4, 0x04170, 0x05E55, 0x0601F, 0x07F3A,
0x08612, 0x09937, 0x0A77D, 0x0B858, 0x0C4CC, 0x0DBE9, 0x0E5A3, 0x0FA86, 0x108D6, 0x117F3,
0x129B9, 0x1369C, 0x14A08, 0x1552D, 0x16B67, 0x17442, 0x18D6A, 0x1924F, 0x1AC05, 0x1B320,
0x1CFB4, 0x1D091, 0x1EEDB, 0x1F1FE
};

1382
3rdparty/zint-2.10.0/backend/raster.c vendored Normal file

File diff suppressed because it is too large Load Diff

287
3rdparty/zint-2.10.0/backend/reedsol.c vendored Normal file
View File

@ -0,0 +1,287 @@
/**
This is a simple Reed-Solomon encoder
(C) Cliff Hones 2004
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
// It is not written with high efficiency in mind, so is probably
// not suitable for real-time encoding. The aim was to keep it
// simple, general and clear.
//
// <Some notes on the theory and implementation need to be added here>
// Usage:
// First call rs_init_gf(&rs, prime_poly) to set up the Galois Field parameters.
// Then call rs_init_code(&rs, nsym, index) to set the encoding size
// Then call rs_encode(&rs, datalen, data, out) to encode the data.
//
// These can be called repeatedly as required - but note that
// rs_init_code must be called following any rs_init_gf call.
//
// If the parameters are fixed, some of the statics below can be
// replaced with constants in the obvious way, and additionally
// malloc/free can be avoided by using static arrays of a suitable
// size.
// Note: use of statics has been done for (up to) 8-bit tables.
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h"
#include "reedsol.h"
#include "reedsol_logs.h"
// rs_init_gf(&rs, prime_poly) initialises the parameters for the Galois Field.
// The symbol size is determined from the highest bit set in poly
// This implementation will support sizes up to 8 bits (see rs_uint_init_gf()
// for sizes > 8 bits and <= 30 bits) - bit sizes of 8 or 4 are typical
//
// The poly is the bit pattern representing the GF characteristic
// polynomial. e.g. for ECC200 (8-bit symbols) the polynomial is
// a**8 + a**5 + a**3 + a**2 + 1, which translates to 0x12d.
INTERNAL void rs_init_gf(rs_t *rs, const unsigned int prime_poly) {
struct item {
const unsigned char *logt;
const unsigned char *alog;
};
/* To add a new prime poly of degree <= 8 add its details to this table and to the table in `test_generate()`
* in "backend/tests/test_reedsol.c" and regenerate the log tables by running "./test_reedsol -f generate -g".
* Paste the result in "reedsol_logs.h" */
static const struct item data[] = {
{ logt_0x13, alog_0x13 }, /* 0 000- */
{ logt_0x25, alog_0x25 }, /* 0 001- */
{ logt_0x43, alog_0x43 }, /* 0 010- */
{ NULL, NULL },
{ logt_0x89, alog_0x89 }, /* 0 100- */
{ NULL, NULL },
{ NULL, NULL },
{ NULL, NULL },
{ logt_0x11d, alog_0x11d }, /* 1 000- */
{ logt_0x12d, alog_0x12d }, /* 1 001- */
{ NULL, NULL },
{ logt_0x163, alog_0x163 }, /* 1 011- */
};
/* Using bits 9-6 as hash to save a few cycles */
/* Alter this hash or just iterate if new prime poly added that doesn't fit */
unsigned int hash = prime_poly >> 5;
rs->logt = data[hash].logt;
rs->alog = data[hash].alog;
}
// rs_init_code(&rs, nsym, index) initialises the Reed-Solomon encoder
// nsym is the number of symbols to be generated (to be appended
// to the input data). index is usually 1 - it is the index of
// the constant in the first term (i) of the RS generator polynomial:
// (x + 2**i)*(x + 2**(i+1))*... [nsym terms]
// For ECC200, index is 1.
INTERNAL void rs_init_code(rs_t *rs, const int nsym, int index) {
int i, k;
const unsigned char *logt = rs->logt;
const unsigned char *alog = rs->alog;
unsigned char *rspoly = rs->rspoly;
rs->nsym = nsym;
rspoly[0] = 1;
for (i = 1; i <= nsym; i++) {
rspoly[i] = 1;
for (k = i - 1; k > 0; k--) {
if (rspoly[k])
rspoly[k] = alog[logt[rspoly[k]] + index]; /* Multiply coeff by 2**index */
rspoly[k] ^= rspoly[k - 1]; /* Add coeff of x**(k-1) * x */
}
rspoly[0] = alog[logt[rspoly[0]] + index]; /* 2**(i + (i+1) + ... + index) */
index++;
}
}
/* rs_encode(&rs, datalen, data, res) generates nsym Reed-Solomon codes (nsym as given in rs_init_code())
* and places them in reverse order in res */
INTERNAL void rs_encode(const rs_t *rs, const int datalen, const unsigned char *data, unsigned char *res) {
int i, k;
const unsigned char *logt = rs->logt;
const unsigned char *alog = rs->alog;
const unsigned char *rspoly = rs->rspoly;
const int nsym = rs->nsym;
memset(res, 0, nsym);
for (i = 0; i < datalen; i++) {
unsigned int m = res[nsym - 1] ^ data[i];
if (m) {
unsigned int log_m = logt[m];
for (k = nsym - 1; k > 0; k--) {
if (rspoly[k])
res[k] = (unsigned char) (res[k - 1] ^ alog[log_m + logt[rspoly[k]]]);
else
res[k] = res[k - 1];
}
res[0] = alog[log_m + logt[rspoly[0]]]; /* rspoly[0] can't be zero */
} else {
memmove(res + 1, res, nsym - 1);
res[0] = 0;
}
}
}
/* The same as above but for unsigned int data and result - Aztec code compatible */
INTERNAL void rs_encode_uint(const rs_t *rs, const int datalen, const unsigned int *data, unsigned int *res) {
int i, k;
const unsigned char *logt = rs->logt;
const unsigned char *alog = rs->alog;
const unsigned char *rspoly = rs->rspoly;
const int nsym = rs->nsym;
memset(res, 0, sizeof(unsigned int) * nsym);
for (i = 0; i < datalen; i++) {
unsigned int m = res[nsym - 1] ^ data[i];
if (m) {
unsigned int log_m = logt[m];
for (k = nsym - 1; k > 0; k--) {
if (rspoly[k])
res[k] = res[k - 1] ^ alog[log_m + logt[rspoly[k]]];
else
res[k] = res[k - 1];
}
res[0] = alog[log_m + logt[rspoly[0]]];
} else {
memmove(res + 1, res, sizeof(unsigned int) * (nsym - 1));
res[0] = 0;
}
}
}
/* Versions of the above for bitlengths > 8 and <= 30 and unsigned int data and results - Aztec code compatible */
// Usage:
// First call rs_uint_init_gf(&rs_uint, prime_poly, logmod) to set up the Galois Field parameters.
// Then call rs_uint_init_code(&rs_uint, nsym, index) to set the encoding size
// Then call rs_uint_encode(&rs_uint, datalen, data, out) to encode the data.
// Then call rs_uint_free(&rs_uint) to free the log tables.
/* `logmod` (field characteristic) will be 2**bitlength - 1, eg 1023 for bitlength 10, 4095 for bitlength 12 */
INTERNAL int rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly, const int logmod) {
int b, p, v;
unsigned int *logt, *alog;
b = logmod + 1;
rs_uint->logt = NULL;
rs_uint->alog = NULL;
if (!(logt = (unsigned int *) calloc(b, sizeof(unsigned int)))) {
return 0;
}
if (!(alog = (unsigned int *) calloc(b * 2, sizeof(unsigned int)))) {
free(logt);
return 0;
}
// Calculate the log/alog tables
for (p = 1, v = 0; v < logmod; v++) {
alog[v] = p;
alog[logmod + v] = p; /* Double up, avoids mod */
logt[p] = v;
p <<= 1;
if (p & b) /* If overflow */
p ^= prime_poly; /* Subtract prime poly */
}
rs_uint->logt = logt;
rs_uint->alog = alog;
return 1;
}
INTERNAL void rs_uint_init_code(rs_uint_t *rs_uint, const int nsym, int index) {
int i, k;
const unsigned int *logt = rs_uint->logt;
const unsigned int *alog = rs_uint->alog;
unsigned short *rspoly = rs_uint->rspoly;
if (logt == NULL || alog == NULL) {
return;
}
rs_uint->nsym = nsym;
rspoly[0] = 1;
for (i = 1; i <= nsym; i++) {
rspoly[i] = 1;
for (k = i - 1; k > 0; k--) {
if (rspoly[k])
rspoly[k] = alog[(logt[rspoly[k]] + index)];
rspoly[k] ^= rspoly[k - 1];
}
rspoly[0] = alog[(logt[rspoly[0]] + index)];
index++;
}
}
INTERNAL void rs_uint_encode(const rs_uint_t *rs_uint, const int datalen, const unsigned int *data,
unsigned int *res) {
int i, k;
const unsigned int *logt = rs_uint->logt;
const unsigned int *alog = rs_uint->alog;
const unsigned short *rspoly = rs_uint->rspoly;
const int nsym = rs_uint->nsym;
memset(res, 0, sizeof(unsigned int) * nsym);
if (logt == NULL || alog == NULL) {
return;
}
for (i = 0; i < datalen; i++) {
unsigned int m = res[nsym - 1] ^ data[i];
if (m) {
unsigned int log_m = logt[m];
for (k = nsym - 1; k > 0; k--) {
if (rspoly[k])
res[k] = res[k - 1] ^ alog[log_m + logt[rspoly[k]]];
else
res[k] = res[k - 1];
}
res[0] = alog[log_m + logt[rspoly[0]]];
} else {
memmove(res + 1, res, sizeof(unsigned int) * (nsym - 1));
res[0] = 0;
}
}
}
INTERNAL void rs_uint_free(rs_uint_t *rs_uint) {
if (rs_uint->logt) {
free(rs_uint->logt);
rs_uint->logt = NULL;
}
if (rs_uint->alog) {
free(rs_uint->alog);
rs_uint->alog = NULL;
}
}

71
3rdparty/zint-2.10.0/backend/reedsol.h vendored Normal file
View File

@ -0,0 +1,71 @@
/*
This is a simple Reed-Solomon encoder
(C) Cliff Hones 2004
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#ifndef __REEDSOL_H
#define __REEDSOL_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct {
const unsigned char *logt; /* These are static */
const unsigned char *alog;
unsigned char rspoly[256];
int nsym;
} rs_t;
typedef struct {
unsigned int *logt; /* These are malloced */
unsigned int *alog;
unsigned short rspoly[4096]; /* 12-bit max - needs to be enlarged if > 12-bit used */
int nsym;
} rs_uint_t;
INTERNAL void rs_init_gf(rs_t *rs, const unsigned int prime_poly);
INTERNAL void rs_init_code(rs_t *rs, const int nsym, int index);
INTERNAL void rs_encode(const rs_t *rs, const int datalen, const unsigned char *data, unsigned char *res);
INTERNAL void rs_encode_uint(const rs_t *rs, const int datalen, const unsigned int *data, unsigned int *res);
/* No free needed as log tables static */
INTERNAL int rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly, const int logmod);
INTERNAL void rs_uint_init_code(rs_uint_t *rs_uint, const int nsym, int index);
INTERNAL void rs_uint_encode(const rs_uint_t *rs_uint, const int datalen, const unsigned int *data,
unsigned int *res);
INTERNAL void rs_uint_free(rs_uint_t *rs_uint);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __REEDSOL_H */

View File

@ -0,0 +1,264 @@
/* reedsol_logs.h - Log and antilog tables for Reed-Solomon
libzint - the open source barcode library
Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#ifndef REEDSOL_LOGS_H
#define REEDSOL_LOGS_H
/* Static log/antilog tables for prime polys of up to degree 8 (> 8 too large so generated at runtime instead).
* Antilog tables doubled to avoid mod. */
/* Paste output of "./test_reedsol -f generate -g" here */
static const unsigned char logt_0x13[16] = {
0x00, 0x00, 0x01, 0x04, 0x02, 0x08, 0x05, 0x0A, 0x03, 0x0E, 0x09, 0x07, 0x06, 0x0D, 0x0B, 0x0C,
};
static const unsigned char alog_0x13[30] = {
0x01, 0x02, 0x04, 0x08, 0x03, 0x06, 0x0C, 0x0B, 0x05, 0x0A, 0x07, 0x0E, 0x0F, 0x0D, 0x09,
0x01, 0x02, 0x04, 0x08, 0x03, 0x06, 0x0C, 0x0B, 0x05, 0x0A, 0x07, 0x0E, 0x0F, 0x0D, 0x09,
};
static const unsigned char logt_0x25[32] = {
0x00, 0x00, 0x01, 0x12, 0x02, 0x05, 0x13, 0x0B, 0x03, 0x1D, 0x06, 0x1B, 0x14, 0x08, 0x0C, 0x17,
0x04, 0x0A, 0x1E, 0x11, 0x07, 0x16, 0x1C, 0x1A, 0x15, 0x19, 0x09, 0x10, 0x0D, 0x0E, 0x18, 0x0F,
};
static const unsigned char alog_0x25[62] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x05, 0x0A, 0x14, 0x0D, 0x1A, 0x11, 0x07, 0x0E, 0x1C, 0x1D, 0x1F,
0x1B, 0x13, 0x03, 0x06, 0x0C, 0x18, 0x15, 0x0F, 0x1E, 0x19, 0x17, 0x0B, 0x16, 0x09, 0x12,
0x01, 0x02, 0x04, 0x08, 0x10, 0x05, 0x0A, 0x14, 0x0D, 0x1A, 0x11, 0x07, 0x0E, 0x1C, 0x1D, 0x1F,
0x1B, 0x13, 0x03, 0x06, 0x0C, 0x18, 0x15, 0x0F, 0x1E, 0x19, 0x17, 0x0B, 0x16, 0x09, 0x12,
};
static const unsigned char logt_0x43[64] = {
0x00, 0x00, 0x01, 0x06, 0x02, 0x0C, 0x07, 0x1A, 0x03, 0x20, 0x0D, 0x23, 0x08, 0x30, 0x1B, 0x12,
0x04, 0x18, 0x21, 0x10, 0x0E, 0x34, 0x24, 0x36, 0x09, 0x2D, 0x31, 0x26, 0x1C, 0x29, 0x13, 0x38,
0x05, 0x3E, 0x19, 0x0B, 0x22, 0x1F, 0x11, 0x2F, 0x0F, 0x17, 0x35, 0x33, 0x25, 0x2C, 0x37, 0x28,
0x0A, 0x3D, 0x2E, 0x1E, 0x32, 0x16, 0x27, 0x2B, 0x1D, 0x3C, 0x2A, 0x15, 0x14, 0x3B, 0x39, 0x3A,
};
static const unsigned char alog_0x43[126] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x03, 0x06, 0x0C, 0x18, 0x30, 0x23, 0x05, 0x0A, 0x14, 0x28,
0x13, 0x26, 0x0F, 0x1E, 0x3C, 0x3B, 0x35, 0x29, 0x11, 0x22, 0x07, 0x0E, 0x1C, 0x38, 0x33, 0x25,
0x09, 0x12, 0x24, 0x0B, 0x16, 0x2C, 0x1B, 0x36, 0x2F, 0x1D, 0x3A, 0x37, 0x2D, 0x19, 0x32, 0x27,
0x0D, 0x1A, 0x34, 0x2B, 0x15, 0x2A, 0x17, 0x2E, 0x1F, 0x3E, 0x3F, 0x3D, 0x39, 0x31, 0x21,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x03, 0x06, 0x0C, 0x18, 0x30, 0x23, 0x05, 0x0A, 0x14, 0x28,
0x13, 0x26, 0x0F, 0x1E, 0x3C, 0x3B, 0x35, 0x29, 0x11, 0x22, 0x07, 0x0E, 0x1C, 0x38, 0x33, 0x25,
0x09, 0x12, 0x24, 0x0B, 0x16, 0x2C, 0x1B, 0x36, 0x2F, 0x1D, 0x3A, 0x37, 0x2D, 0x19, 0x32, 0x27,
0x0D, 0x1A, 0x34, 0x2B, 0x15, 0x2A, 0x17, 0x2E, 0x1F, 0x3E, 0x3F, 0x3D, 0x39, 0x31, 0x21,
};
static const unsigned char logt_0x89[128] = {
0x00, 0x00, 0x01, 0x1F, 0x02, 0x3E, 0x20, 0x67, 0x03, 0x07, 0x3F, 0x0F, 0x21, 0x54, 0x68, 0x5D,
0x04, 0x7C, 0x08, 0x79, 0x40, 0x4F, 0x10, 0x73, 0x22, 0x0B, 0x55, 0x26, 0x69, 0x2E, 0x5E, 0x33,
0x05, 0x52, 0x7D, 0x3C, 0x09, 0x2C, 0x7A, 0x4D, 0x41, 0x43, 0x50, 0x2A, 0x11, 0x45, 0x74, 0x17,
0x23, 0x76, 0x0C, 0x1C, 0x56, 0x19, 0x27, 0x39, 0x6A, 0x13, 0x2F, 0x59, 0x5F, 0x47, 0x34, 0x6E,
0x06, 0x0E, 0x53, 0x5C, 0x7E, 0x1E, 0x3D, 0x66, 0x0A, 0x25, 0x2D, 0x32, 0x7B, 0x78, 0x4E, 0x72,
0x42, 0x29, 0x44, 0x16, 0x51, 0x3B, 0x2B, 0x4C, 0x12, 0x58, 0x46, 0x6D, 0x75, 0x1B, 0x18, 0x38,
0x24, 0x31, 0x77, 0x71, 0x0D, 0x5B, 0x1D, 0x65, 0x57, 0x6C, 0x1A, 0x37, 0x28, 0x15, 0x3A, 0x4B,
0x6B, 0x36, 0x14, 0x4A, 0x30, 0x70, 0x5A, 0x64, 0x60, 0x61, 0x48, 0x62, 0x35, 0x49, 0x6F, 0x63,
};
static const unsigned char alog_0x89[254] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x09, 0x12, 0x24, 0x48, 0x19, 0x32, 0x64, 0x41, 0x0B,
0x16, 0x2C, 0x58, 0x39, 0x72, 0x6D, 0x53, 0x2F, 0x5E, 0x35, 0x6A, 0x5D, 0x33, 0x66, 0x45, 0x03,
0x06, 0x0C, 0x18, 0x30, 0x60, 0x49, 0x1B, 0x36, 0x6C, 0x51, 0x2B, 0x56, 0x25, 0x4A, 0x1D, 0x3A,
0x74, 0x61, 0x4B, 0x1F, 0x3E, 0x7C, 0x71, 0x6B, 0x5F, 0x37, 0x6E, 0x55, 0x23, 0x46, 0x05, 0x0A,
0x14, 0x28, 0x50, 0x29, 0x52, 0x2D, 0x5A, 0x3D, 0x7A, 0x7D, 0x73, 0x6F, 0x57, 0x27, 0x4E, 0x15,
0x2A, 0x54, 0x21, 0x42, 0x0D, 0x1A, 0x34, 0x68, 0x59, 0x3B, 0x76, 0x65, 0x43, 0x0F, 0x1E, 0x3C,
0x78, 0x79, 0x7B, 0x7F, 0x77, 0x67, 0x47, 0x07, 0x0E, 0x1C, 0x38, 0x70, 0x69, 0x5B, 0x3F, 0x7E,
0x75, 0x63, 0x4F, 0x17, 0x2E, 0x5C, 0x31, 0x62, 0x4D, 0x13, 0x26, 0x4C, 0x11, 0x22, 0x44,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x09, 0x12, 0x24, 0x48, 0x19, 0x32, 0x64, 0x41, 0x0B,
0x16, 0x2C, 0x58, 0x39, 0x72, 0x6D, 0x53, 0x2F, 0x5E, 0x35, 0x6A, 0x5D, 0x33, 0x66, 0x45, 0x03,
0x06, 0x0C, 0x18, 0x30, 0x60, 0x49, 0x1B, 0x36, 0x6C, 0x51, 0x2B, 0x56, 0x25, 0x4A, 0x1D, 0x3A,
0x74, 0x61, 0x4B, 0x1F, 0x3E, 0x7C, 0x71, 0x6B, 0x5F, 0x37, 0x6E, 0x55, 0x23, 0x46, 0x05, 0x0A,
0x14, 0x28, 0x50, 0x29, 0x52, 0x2D, 0x5A, 0x3D, 0x7A, 0x7D, 0x73, 0x6F, 0x57, 0x27, 0x4E, 0x15,
0x2A, 0x54, 0x21, 0x42, 0x0D, 0x1A, 0x34, 0x68, 0x59, 0x3B, 0x76, 0x65, 0x43, 0x0F, 0x1E, 0x3C,
0x78, 0x79, 0x7B, 0x7F, 0x77, 0x67, 0x47, 0x07, 0x0E, 0x1C, 0x38, 0x70, 0x69, 0x5B, 0x3F, 0x7E,
0x75, 0x63, 0x4F, 0x17, 0x2E, 0x5C, 0x31, 0x62, 0x4D, 0x13, 0x26, 0x4C, 0x11, 0x22, 0x44,
};
static const unsigned char logt_0x11d[256] = {
0x00, 0x00, 0x01, 0x19, 0x02, 0x32, 0x1A, 0xC6, 0x03, 0xDF, 0x33, 0xEE, 0x1B, 0x68, 0xC7, 0x4B,
0x04, 0x64, 0xE0, 0x0E, 0x34, 0x8D, 0xEF, 0x81, 0x1C, 0xC1, 0x69, 0xF8, 0xC8, 0x08, 0x4C, 0x71,
0x05, 0x8A, 0x65, 0x2F, 0xE1, 0x24, 0x0F, 0x21, 0x35, 0x93, 0x8E, 0xDA, 0xF0, 0x12, 0x82, 0x45,
0x1D, 0xB5, 0xC2, 0x7D, 0x6A, 0x27, 0xF9, 0xB9, 0xC9, 0x9A, 0x09, 0x78, 0x4D, 0xE4, 0x72, 0xA6,
0x06, 0xBF, 0x8B, 0x62, 0x66, 0xDD, 0x30, 0xFD, 0xE2, 0x98, 0x25, 0xB3, 0x10, 0x91, 0x22, 0x88,
0x36, 0xD0, 0x94, 0xCE, 0x8F, 0x96, 0xDB, 0xBD, 0xF1, 0xD2, 0x13, 0x5C, 0x83, 0x38, 0x46, 0x40,
0x1E, 0x42, 0xB6, 0xA3, 0xC3, 0x48, 0x7E, 0x6E, 0x6B, 0x3A, 0x28, 0x54, 0xFA, 0x85, 0xBA, 0x3D,
0xCA, 0x5E, 0x9B, 0x9F, 0x0A, 0x15, 0x79, 0x2B, 0x4E, 0xD4, 0xE5, 0xAC, 0x73, 0xF3, 0xA7, 0x57,
0x07, 0x70, 0xC0, 0xF7, 0x8C, 0x80, 0x63, 0x0D, 0x67, 0x4A, 0xDE, 0xED, 0x31, 0xC5, 0xFE, 0x18,
0xE3, 0xA5, 0x99, 0x77, 0x26, 0xB8, 0xB4, 0x7C, 0x11, 0x44, 0x92, 0xD9, 0x23, 0x20, 0x89, 0x2E,
0x37, 0x3F, 0xD1, 0x5B, 0x95, 0xBC, 0xCF, 0xCD, 0x90, 0x87, 0x97, 0xB2, 0xDC, 0xFC, 0xBE, 0x61,
0xF2, 0x56, 0xD3, 0xAB, 0x14, 0x2A, 0x5D, 0x9E, 0x84, 0x3C, 0x39, 0x53, 0x47, 0x6D, 0x41, 0xA2,
0x1F, 0x2D, 0x43, 0xD8, 0xB7, 0x7B, 0xA4, 0x76, 0xC4, 0x17, 0x49, 0xEC, 0x7F, 0x0C, 0x6F, 0xF6,
0x6C, 0xA1, 0x3B, 0x52, 0x29, 0x9D, 0x55, 0xAA, 0xFB, 0x60, 0x86, 0xB1, 0xBB, 0xCC, 0x3E, 0x5A,
0xCB, 0x59, 0x5F, 0xB0, 0x9C, 0xA9, 0xA0, 0x51, 0x0B, 0xF5, 0x16, 0xEB, 0x7A, 0x75, 0x2C, 0xD7,
0x4F, 0xAE, 0xD5, 0xE9, 0xE6, 0xE7, 0xAD, 0xE8, 0x74, 0xD6, 0xF4, 0xEA, 0xA8, 0x50, 0x58, 0xAF,
};
static const unsigned char alog_0x11d[510] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1D, 0x3A, 0x74, 0xE8, 0xCD, 0x87, 0x13, 0x26,
0x4C, 0x98, 0x2D, 0x5A, 0xB4, 0x75, 0xEA, 0xC9, 0x8F, 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0,
0x9D, 0x27, 0x4E, 0x9C, 0x25, 0x4A, 0x94, 0x35, 0x6A, 0xD4, 0xB5, 0x77, 0xEE, 0xC1, 0x9F, 0x23,
0x46, 0x8C, 0x05, 0x0A, 0x14, 0x28, 0x50, 0xA0, 0x5D, 0xBA, 0x69, 0xD2, 0xB9, 0x6F, 0xDE, 0xA1,
0x5F, 0xBE, 0x61, 0xC2, 0x99, 0x2F, 0x5E, 0xBC, 0x65, 0xCA, 0x89, 0x0F, 0x1E, 0x3C, 0x78, 0xF0,
0xFD, 0xE7, 0xD3, 0xBB, 0x6B, 0xD6, 0xB1, 0x7F, 0xFE, 0xE1, 0xDF, 0xA3, 0x5B, 0xB6, 0x71, 0xE2,
0xD9, 0xAF, 0x43, 0x86, 0x11, 0x22, 0x44, 0x88, 0x0D, 0x1A, 0x34, 0x68, 0xD0, 0xBD, 0x67, 0xCE,
0x81, 0x1F, 0x3E, 0x7C, 0xF8, 0xED, 0xC7, 0x93, 0x3B, 0x76, 0xEC, 0xC5, 0x97, 0x33, 0x66, 0xCC,
0x85, 0x17, 0x2E, 0x5C, 0xB8, 0x6D, 0xDA, 0xA9, 0x4F, 0x9E, 0x21, 0x42, 0x84, 0x15, 0x2A, 0x54,
0xA8, 0x4D, 0x9A, 0x29, 0x52, 0xA4, 0x55, 0xAA, 0x49, 0x92, 0x39, 0x72, 0xE4, 0xD5, 0xB7, 0x73,
0xE6, 0xD1, 0xBF, 0x63, 0xC6, 0x91, 0x3F, 0x7E, 0xFC, 0xE5, 0xD7, 0xB3, 0x7B, 0xF6, 0xF1, 0xFF,
0xE3, 0xDB, 0xAB, 0x4B, 0x96, 0x31, 0x62, 0xC4, 0x95, 0x37, 0x6E, 0xDC, 0xA5, 0x57, 0xAE, 0x41,
0x82, 0x19, 0x32, 0x64, 0xC8, 0x8D, 0x07, 0x0E, 0x1C, 0x38, 0x70, 0xE0, 0xDD, 0xA7, 0x53, 0xA6,
0x51, 0xA2, 0x59, 0xB2, 0x79, 0xF2, 0xF9, 0xEF, 0xC3, 0x9B, 0x2B, 0x56, 0xAC, 0x45, 0x8A, 0x09,
0x12, 0x24, 0x48, 0x90, 0x3D, 0x7A, 0xF4, 0xF5, 0xF7, 0xF3, 0xFB, 0xEB, 0xCB, 0x8B, 0x0B, 0x16,
0x2C, 0x58, 0xB0, 0x7D, 0xFA, 0xE9, 0xCF, 0x83, 0x1B, 0x36, 0x6C, 0xD8, 0xAD, 0x47, 0x8E,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1D, 0x3A, 0x74, 0xE8, 0xCD, 0x87, 0x13, 0x26,
0x4C, 0x98, 0x2D, 0x5A, 0xB4, 0x75, 0xEA, 0xC9, 0x8F, 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0,
0x9D, 0x27, 0x4E, 0x9C, 0x25, 0x4A, 0x94, 0x35, 0x6A, 0xD4, 0xB5, 0x77, 0xEE, 0xC1, 0x9F, 0x23,
0x46, 0x8C, 0x05, 0x0A, 0x14, 0x28, 0x50, 0xA0, 0x5D, 0xBA, 0x69, 0xD2, 0xB9, 0x6F, 0xDE, 0xA1,
0x5F, 0xBE, 0x61, 0xC2, 0x99, 0x2F, 0x5E, 0xBC, 0x65, 0xCA, 0x89, 0x0F, 0x1E, 0x3C, 0x78, 0xF0,
0xFD, 0xE7, 0xD3, 0xBB, 0x6B, 0xD6, 0xB1, 0x7F, 0xFE, 0xE1, 0xDF, 0xA3, 0x5B, 0xB6, 0x71, 0xE2,
0xD9, 0xAF, 0x43, 0x86, 0x11, 0x22, 0x44, 0x88, 0x0D, 0x1A, 0x34, 0x68, 0xD0, 0xBD, 0x67, 0xCE,
0x81, 0x1F, 0x3E, 0x7C, 0xF8, 0xED, 0xC7, 0x93, 0x3B, 0x76, 0xEC, 0xC5, 0x97, 0x33, 0x66, 0xCC,
0x85, 0x17, 0x2E, 0x5C, 0xB8, 0x6D, 0xDA, 0xA9, 0x4F, 0x9E, 0x21, 0x42, 0x84, 0x15, 0x2A, 0x54,
0xA8, 0x4D, 0x9A, 0x29, 0x52, 0xA4, 0x55, 0xAA, 0x49, 0x92, 0x39, 0x72, 0xE4, 0xD5, 0xB7, 0x73,
0xE6, 0xD1, 0xBF, 0x63, 0xC6, 0x91, 0x3F, 0x7E, 0xFC, 0xE5, 0xD7, 0xB3, 0x7B, 0xF6, 0xF1, 0xFF,
0xE3, 0xDB, 0xAB, 0x4B, 0x96, 0x31, 0x62, 0xC4, 0x95, 0x37, 0x6E, 0xDC, 0xA5, 0x57, 0xAE, 0x41,
0x82, 0x19, 0x32, 0x64, 0xC8, 0x8D, 0x07, 0x0E, 0x1C, 0x38, 0x70, 0xE0, 0xDD, 0xA7, 0x53, 0xA6,
0x51, 0xA2, 0x59, 0xB2, 0x79, 0xF2, 0xF9, 0xEF, 0xC3, 0x9B, 0x2B, 0x56, 0xAC, 0x45, 0x8A, 0x09,
0x12, 0x24, 0x48, 0x90, 0x3D, 0x7A, 0xF4, 0xF5, 0xF7, 0xF3, 0xFB, 0xEB, 0xCB, 0x8B, 0x0B, 0x16,
0x2C, 0x58, 0xB0, 0x7D, 0xFA, 0xE9, 0xCF, 0x83, 0x1B, 0x36, 0x6C, 0xD8, 0xAD, 0x47, 0x8E,
};
static const unsigned char logt_0x12d[256] = {
0x00, 0x00, 0x01, 0xF0, 0x02, 0xE1, 0xF1, 0x35, 0x03, 0x26, 0xE2, 0x85, 0xF2, 0x2B, 0x36, 0xD2,
0x04, 0xC3, 0x27, 0x72, 0xE3, 0x6A, 0x86, 0x1C, 0xF3, 0x8C, 0x2C, 0x17, 0x37, 0x76, 0xD3, 0xEA,
0x05, 0xDB, 0xC4, 0x60, 0x28, 0xDE, 0x73, 0x67, 0xE4, 0x4E, 0x6B, 0x7D, 0x87, 0x08, 0x1D, 0xA2,
0xF4, 0xBA, 0x8D, 0xB4, 0x2D, 0x63, 0x18, 0x31, 0x38, 0x0D, 0x77, 0x99, 0xD4, 0xC7, 0xEB, 0x5B,
0x06, 0x4C, 0xDC, 0xD9, 0xC5, 0x0B, 0x61, 0xB8, 0x29, 0x24, 0xDF, 0xFD, 0x74, 0x8A, 0x68, 0xC1,
0xE5, 0x56, 0x4F, 0xAB, 0x6C, 0xA5, 0x7E, 0x91, 0x88, 0x22, 0x09, 0x4A, 0x1E, 0x20, 0xA3, 0x54,
0xF5, 0xAD, 0xBB, 0xCC, 0x8E, 0x51, 0xB5, 0xBE, 0x2E, 0x58, 0x64, 0x9F, 0x19, 0xE7, 0x32, 0xCF,
0x39, 0x93, 0x0E, 0x43, 0x78, 0x80, 0x9A, 0xF8, 0xD5, 0xA7, 0xC8, 0x3F, 0xEC, 0x6E, 0x5C, 0xB0,
0x07, 0xA1, 0x4D, 0x7C, 0xDD, 0x66, 0xDA, 0x5F, 0xC6, 0x5A, 0x0C, 0x98, 0x62, 0x30, 0xB9, 0xB3,
0x2A, 0xD1, 0x25, 0x84, 0xE0, 0x34, 0xFE, 0xEF, 0x75, 0xE9, 0x8B, 0x16, 0x69, 0x1B, 0xC2, 0x71,
0xE6, 0xCE, 0x57, 0x9E, 0x50, 0xBD, 0xAC, 0xCB, 0x6D, 0xAF, 0xA6, 0x3E, 0x7F, 0xF7, 0x92, 0x42,
0x89, 0xC0, 0x23, 0xFC, 0x0A, 0xB7, 0x4B, 0xD8, 0x1F, 0x53, 0x21, 0x49, 0xA4, 0x90, 0x55, 0xAA,
0xF6, 0x41, 0xAE, 0x3D, 0xBC, 0xCA, 0xCD, 0x9D, 0x8F, 0xA9, 0x52, 0x48, 0xB6, 0xD7, 0xBF, 0xFB,
0x2F, 0xB2, 0x59, 0x97, 0x65, 0x5E, 0xA0, 0x7B, 0x1A, 0x70, 0xE8, 0x15, 0x33, 0xEE, 0xD0, 0x83,
0x3A, 0x45, 0x94, 0x12, 0x0F, 0x10, 0x44, 0x11, 0x79, 0x95, 0x81, 0x13, 0x9B, 0x3B, 0xF9, 0x46,
0xD6, 0xFA, 0xA8, 0x47, 0xC9, 0x9C, 0x40, 0x3C, 0xED, 0x82, 0x6F, 0x14, 0x5D, 0x7A, 0xB1, 0x96,
};
static const unsigned char alog_0x12d[510] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x2D, 0x5A, 0xB4, 0x45, 0x8A, 0x39, 0x72, 0xE4,
0xE5, 0xE7, 0xE3, 0xEB, 0xFB, 0xDB, 0x9B, 0x1B, 0x36, 0x6C, 0xD8, 0x9D, 0x17, 0x2E, 0x5C, 0xB8,
0x5D, 0xBA, 0x59, 0xB2, 0x49, 0x92, 0x09, 0x12, 0x24, 0x48, 0x90, 0x0D, 0x1A, 0x34, 0x68, 0xD0,
0x8D, 0x37, 0x6E, 0xDC, 0x95, 0x07, 0x0E, 0x1C, 0x38, 0x70, 0xE0, 0xED, 0xF7, 0xC3, 0xAB, 0x7B,
0xF6, 0xC1, 0xAF, 0x73, 0xE6, 0xE1, 0xEF, 0xF3, 0xCB, 0xBB, 0x5B, 0xB6, 0x41, 0x82, 0x29, 0x52,
0xA4, 0x65, 0xCA, 0xB9, 0x5F, 0xBE, 0x51, 0xA2, 0x69, 0xD2, 0x89, 0x3F, 0x7E, 0xFC, 0xD5, 0x87,
0x23, 0x46, 0x8C, 0x35, 0x6A, 0xD4, 0x85, 0x27, 0x4E, 0x9C, 0x15, 0x2A, 0x54, 0xA8, 0x7D, 0xFA,
0xD9, 0x9F, 0x13, 0x26, 0x4C, 0x98, 0x1D, 0x3A, 0x74, 0xE8, 0xFD, 0xD7, 0x83, 0x2B, 0x56, 0xAC,
0x75, 0xEA, 0xF9, 0xDF, 0x93, 0x0B, 0x16, 0x2C, 0x58, 0xB0, 0x4D, 0x9A, 0x19, 0x32, 0x64, 0xC8,
0xBD, 0x57, 0xAE, 0x71, 0xE2, 0xE9, 0xFF, 0xD3, 0x8B, 0x3B, 0x76, 0xEC, 0xF5, 0xC7, 0xA3, 0x6B,
0xD6, 0x81, 0x2F, 0x5E, 0xBC, 0x55, 0xAA, 0x79, 0xF2, 0xC9, 0xBF, 0x53, 0xA6, 0x61, 0xC2, 0xA9,
0x7F, 0xFE, 0xD1, 0x8F, 0x33, 0x66, 0xCC, 0xB5, 0x47, 0x8E, 0x31, 0x62, 0xC4, 0xA5, 0x67, 0xCE,
0xB1, 0x4F, 0x9E, 0x11, 0x22, 0x44, 0x88, 0x3D, 0x7A, 0xF4, 0xC5, 0xA7, 0x63, 0xC6, 0xA1, 0x6F,
0xDE, 0x91, 0x0F, 0x1E, 0x3C, 0x78, 0xF0, 0xCD, 0xB7, 0x43, 0x86, 0x21, 0x42, 0x84, 0x25, 0x4A,
0x94, 0x05, 0x0A, 0x14, 0x28, 0x50, 0xA0, 0x6D, 0xDA, 0x99, 0x1F, 0x3E, 0x7C, 0xF8, 0xDD, 0x97,
0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0xAD, 0x77, 0xEE, 0xF1, 0xCF, 0xB3, 0x4B, 0x96,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x2D, 0x5A, 0xB4, 0x45, 0x8A, 0x39, 0x72, 0xE4,
0xE5, 0xE7, 0xE3, 0xEB, 0xFB, 0xDB, 0x9B, 0x1B, 0x36, 0x6C, 0xD8, 0x9D, 0x17, 0x2E, 0x5C, 0xB8,
0x5D, 0xBA, 0x59, 0xB2, 0x49, 0x92, 0x09, 0x12, 0x24, 0x48, 0x90, 0x0D, 0x1A, 0x34, 0x68, 0xD0,
0x8D, 0x37, 0x6E, 0xDC, 0x95, 0x07, 0x0E, 0x1C, 0x38, 0x70, 0xE0, 0xED, 0xF7, 0xC3, 0xAB, 0x7B,
0xF6, 0xC1, 0xAF, 0x73, 0xE6, 0xE1, 0xEF, 0xF3, 0xCB, 0xBB, 0x5B, 0xB6, 0x41, 0x82, 0x29, 0x52,
0xA4, 0x65, 0xCA, 0xB9, 0x5F, 0xBE, 0x51, 0xA2, 0x69, 0xD2, 0x89, 0x3F, 0x7E, 0xFC, 0xD5, 0x87,
0x23, 0x46, 0x8C, 0x35, 0x6A, 0xD4, 0x85, 0x27, 0x4E, 0x9C, 0x15, 0x2A, 0x54, 0xA8, 0x7D, 0xFA,
0xD9, 0x9F, 0x13, 0x26, 0x4C, 0x98, 0x1D, 0x3A, 0x74, 0xE8, 0xFD, 0xD7, 0x83, 0x2B, 0x56, 0xAC,
0x75, 0xEA, 0xF9, 0xDF, 0x93, 0x0B, 0x16, 0x2C, 0x58, 0xB0, 0x4D, 0x9A, 0x19, 0x32, 0x64, 0xC8,
0xBD, 0x57, 0xAE, 0x71, 0xE2, 0xE9, 0xFF, 0xD3, 0x8B, 0x3B, 0x76, 0xEC, 0xF5, 0xC7, 0xA3, 0x6B,
0xD6, 0x81, 0x2F, 0x5E, 0xBC, 0x55, 0xAA, 0x79, 0xF2, 0xC9, 0xBF, 0x53, 0xA6, 0x61, 0xC2, 0xA9,
0x7F, 0xFE, 0xD1, 0x8F, 0x33, 0x66, 0xCC, 0xB5, 0x47, 0x8E, 0x31, 0x62, 0xC4, 0xA5, 0x67, 0xCE,
0xB1, 0x4F, 0x9E, 0x11, 0x22, 0x44, 0x88, 0x3D, 0x7A, 0xF4, 0xC5, 0xA7, 0x63, 0xC6, 0xA1, 0x6F,
0xDE, 0x91, 0x0F, 0x1E, 0x3C, 0x78, 0xF0, 0xCD, 0xB7, 0x43, 0x86, 0x21, 0x42, 0x84, 0x25, 0x4A,
0x94, 0x05, 0x0A, 0x14, 0x28, 0x50, 0xA0, 0x6D, 0xDA, 0x99, 0x1F, 0x3E, 0x7C, 0xF8, 0xDD, 0x97,
0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0xAD, 0x77, 0xEE, 0xF1, 0xCF, 0xB3, 0x4B, 0x96,
};
static const unsigned char logt_0x163[256] = {
0x00, 0x00, 0x01, 0xC5, 0x02, 0x8B, 0xC6, 0x6C, 0x03, 0x32, 0x8C, 0xC0, 0xC7, 0x25, 0x6D, 0x51,
0x04, 0x17, 0x33, 0xEE, 0x8D, 0xD8, 0xC1, 0xEA, 0xC8, 0x0C, 0x26, 0xF7, 0x6E, 0x86, 0x52, 0x7C,
0x05, 0x42, 0x18, 0x91, 0x34, 0x73, 0xEF, 0x4C, 0x8E, 0xCE, 0xD9, 0xD1, 0xC2, 0xBD, 0xEB, 0xF4,
0xC9, 0x2D, 0x0D, 0xDC, 0x27, 0xB4, 0xF8, 0xA4, 0x6F, 0xB0, 0x87, 0xD4, 0x53, 0x1E, 0x7D, 0x9E,
0x06, 0x64, 0x43, 0x37, 0x19, 0x81, 0x92, 0xE3, 0x35, 0xE1, 0x74, 0x76, 0xF0, 0x9A, 0x4D, 0x78,
0x8F, 0x4A, 0xCF, 0xF2, 0xDA, 0xA2, 0xD2, 0x9C, 0xC3, 0x6A, 0xBE, 0x4F, 0xEC, 0xE8, 0xF5, 0x7A,
0xCA, 0xAC, 0x2E, 0x08, 0x0E, 0x57, 0xDD, 0x66, 0x28, 0x12, 0xB5, 0x45, 0xF9, 0x5E, 0xA5, 0x39,
0x70, 0xBA, 0xB1, 0x1B, 0x88, 0x22, 0xD5, 0x83, 0x54, 0x5B, 0x1F, 0x94, 0x7E, 0x97, 0x9F, 0xE5,
0x07, 0xAB, 0x65, 0x56, 0x44, 0x11, 0x38, 0x5D, 0x1A, 0xB9, 0x82, 0x21, 0x93, 0x5A, 0xE4, 0x96,
0x36, 0x63, 0xE2, 0x80, 0x75, 0xE0, 0x77, 0x99, 0xF1, 0x49, 0x9B, 0xA1, 0x4E, 0x69, 0x79, 0xE7,
0x90, 0x41, 0x4B, 0x72, 0xD0, 0xCD, 0xF3, 0xBC, 0xDB, 0x2C, 0xA3, 0xB3, 0xD3, 0xAF, 0x9D, 0x1D,
0xC4, 0xFE, 0x6B, 0x8A, 0xBF, 0x31, 0x50, 0x24, 0xED, 0x16, 0xE9, 0xD7, 0xF6, 0x0B, 0x7B, 0x85,
0xCB, 0x3F, 0xAD, 0x2A, 0x2F, 0xFC, 0x09, 0x14, 0x0F, 0xA9, 0x58, 0xB7, 0xDE, 0x61, 0x67, 0x47,
0x29, 0x3E, 0x13, 0xFB, 0xB6, 0xA8, 0x46, 0x60, 0xFA, 0x3D, 0x5F, 0xA7, 0xA6, 0x3C, 0x3A, 0x3B,
0x71, 0x40, 0xBB, 0xCC, 0xB2, 0x2B, 0x1C, 0xAE, 0x89, 0xFD, 0x23, 0x30, 0xD6, 0x15, 0x84, 0x0A,
0x55, 0xAA, 0x5C, 0x10, 0x20, 0xB8, 0x95, 0x59, 0x7F, 0x62, 0x98, 0xDF, 0xA0, 0x48, 0xE6, 0x68,
};
static const unsigned char alog_0x163[510] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x63, 0xC6, 0xEF, 0xBD, 0x19, 0x32, 0x64, 0xC8,
0xF3, 0x85, 0x69, 0xD2, 0xC7, 0xED, 0xB9, 0x11, 0x22, 0x44, 0x88, 0x73, 0xE6, 0xAF, 0x3D, 0x7A,
0xF4, 0x8B, 0x75, 0xEA, 0xB7, 0x0D, 0x1A, 0x34, 0x68, 0xD0, 0xC3, 0xE5, 0xA9, 0x31, 0x62, 0xC4,
0xEB, 0xB5, 0x09, 0x12, 0x24, 0x48, 0x90, 0x43, 0x86, 0x6F, 0xDE, 0xDF, 0xDD, 0xD9, 0xD1, 0xC1,
0xE1, 0xA1, 0x21, 0x42, 0x84, 0x6B, 0xD6, 0xCF, 0xFD, 0x99, 0x51, 0xA2, 0x27, 0x4E, 0x9C, 0x5B,
0xB6, 0x0F, 0x1E, 0x3C, 0x78, 0xF0, 0x83, 0x65, 0xCA, 0xF7, 0x8D, 0x79, 0xF2, 0x87, 0x6D, 0xDA,
0xD7, 0xCD, 0xF9, 0x91, 0x41, 0x82, 0x67, 0xCE, 0xFF, 0x9D, 0x59, 0xB2, 0x07, 0x0E, 0x1C, 0x38,
0x70, 0xE0, 0xA3, 0x25, 0x4A, 0x94, 0x4B, 0x96, 0x4F, 0x9E, 0x5F, 0xBE, 0x1F, 0x3E, 0x7C, 0xF8,
0x93, 0x45, 0x8A, 0x77, 0xEE, 0xBF, 0x1D, 0x3A, 0x74, 0xE8, 0xB3, 0x05, 0x0A, 0x14, 0x28, 0x50,
0xA0, 0x23, 0x46, 0x8C, 0x7B, 0xF6, 0x8F, 0x7D, 0xFA, 0x97, 0x4D, 0x9A, 0x57, 0xAE, 0x3F, 0x7E,
0xFC, 0x9B, 0x55, 0xAA, 0x37, 0x6E, 0xDC, 0xDB, 0xD5, 0xC9, 0xF1, 0x81, 0x61, 0xC2, 0xE7, 0xAD,
0x39, 0x72, 0xE4, 0xAB, 0x35, 0x6A, 0xD4, 0xCB, 0xF5, 0x89, 0x71, 0xE2, 0xA7, 0x2D, 0x5A, 0xB4,
0x0B, 0x16, 0x2C, 0x58, 0xB0, 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0xE3, 0xA5, 0x29, 0x52,
0xA4, 0x2B, 0x56, 0xAC, 0x3B, 0x76, 0xEC, 0xBB, 0x15, 0x2A, 0x54, 0xA8, 0x33, 0x66, 0xCC, 0xFB,
0x95, 0x49, 0x92, 0x47, 0x8E, 0x7F, 0xFE, 0x9F, 0x5D, 0xBA, 0x17, 0x2E, 0x5C, 0xB8, 0x13, 0x26,
0x4C, 0x98, 0x53, 0xA6, 0x2F, 0x5E, 0xBC, 0x1B, 0x36, 0x6C, 0xD8, 0xD3, 0xC5, 0xE9, 0xB1,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x63, 0xC6, 0xEF, 0xBD, 0x19, 0x32, 0x64, 0xC8,
0xF3, 0x85, 0x69, 0xD2, 0xC7, 0xED, 0xB9, 0x11, 0x22, 0x44, 0x88, 0x73, 0xE6, 0xAF, 0x3D, 0x7A,
0xF4, 0x8B, 0x75, 0xEA, 0xB7, 0x0D, 0x1A, 0x34, 0x68, 0xD0, 0xC3, 0xE5, 0xA9, 0x31, 0x62, 0xC4,
0xEB, 0xB5, 0x09, 0x12, 0x24, 0x48, 0x90, 0x43, 0x86, 0x6F, 0xDE, 0xDF, 0xDD, 0xD9, 0xD1, 0xC1,
0xE1, 0xA1, 0x21, 0x42, 0x84, 0x6B, 0xD6, 0xCF, 0xFD, 0x99, 0x51, 0xA2, 0x27, 0x4E, 0x9C, 0x5B,
0xB6, 0x0F, 0x1E, 0x3C, 0x78, 0xF0, 0x83, 0x65, 0xCA, 0xF7, 0x8D, 0x79, 0xF2, 0x87, 0x6D, 0xDA,
0xD7, 0xCD, 0xF9, 0x91, 0x41, 0x82, 0x67, 0xCE, 0xFF, 0x9D, 0x59, 0xB2, 0x07, 0x0E, 0x1C, 0x38,
0x70, 0xE0, 0xA3, 0x25, 0x4A, 0x94, 0x4B, 0x96, 0x4F, 0x9E, 0x5F, 0xBE, 0x1F, 0x3E, 0x7C, 0xF8,
0x93, 0x45, 0x8A, 0x77, 0xEE, 0xBF, 0x1D, 0x3A, 0x74, 0xE8, 0xB3, 0x05, 0x0A, 0x14, 0x28, 0x50,
0xA0, 0x23, 0x46, 0x8C, 0x7B, 0xF6, 0x8F, 0x7D, 0xFA, 0x97, 0x4D, 0x9A, 0x57, 0xAE, 0x3F, 0x7E,
0xFC, 0x9B, 0x55, 0xAA, 0x37, 0x6E, 0xDC, 0xDB, 0xD5, 0xC9, 0xF1, 0x81, 0x61, 0xC2, 0xE7, 0xAD,
0x39, 0x72, 0xE4, 0xAB, 0x35, 0x6A, 0xD4, 0xCB, 0xF5, 0x89, 0x71, 0xE2, 0xA7, 0x2D, 0x5A, 0xB4,
0x0B, 0x16, 0x2C, 0x58, 0xB0, 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0xE3, 0xA5, 0x29, 0x52,
0xA4, 0x2B, 0x56, 0xAC, 0x3B, 0x76, 0xEC, 0xBB, 0x15, 0x2A, 0x54, 0xA8, 0x33, 0x66, 0xCC, 0xFB,
0x95, 0x49, 0x92, 0x47, 0x8E, 0x7F, 0xFE, 0x9F, 0x5D, 0xBA, 0x17, 0x2E, 0x5C, 0xB8, 0x13, 0x26,
0x4C, 0x98, 0x53, 0xA6, 0x2F, 0x5E, 0xBC, 0x1B, 0x36, 0x6C, 0xD8, 0xD3, 0xC5, 0xE9, 0xB1,
};
#endif /* REEDSOL_LOGS_H */

1598
3rdparty/zint-2.10.0/backend/rss.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2007-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2007 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -29,13 +29,7 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#define NUMERIC 110
#define ALPHA 97
#define ISOIEC 105
#define INVALID_CHAR 100
#define ANY_ENC 120
#define ALPHA_OR_ISO 121
/* vim: set ts=4 sw=4 et : */
/* RSS-14 Tables */
static const unsigned short int g_sum_table[9] = {
@ -62,7 +56,6 @@ static const char widest_even[9] = {
1, 3, 5, 6, 8, 7, 5, 3, 1
};
static int widths[8];
static const char finder_pattern[45] = {
3, 8, 2, 1, 1,
3, 5, 5, 1, 1,
@ -296,3 +289,4 @@ static const char weight_rows[210] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 17, 18, 19, 20, 21, 22, 0, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 13, 14, 11, 12, 17, 18, 15, 16, 21, 22, 19, 20
};

1599
3rdparty/zint-2.10.0/backend/sjis.c vendored Normal file

File diff suppressed because it is too large Load Diff

51
3rdparty/zint-2.10.0/backend/sjis.h vendored Normal file
View File

@ -0,0 +1,51 @@
/* sjis.h - Unicode to Shift JIS
libzint - the open source barcode library
Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#ifndef SJIS_H
#define SJIS_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
INTERNAL int sjis_wctomb_zint(unsigned int *r, const unsigned int wc);
INTERNAL int sjis_utf8(struct zint_symbol *symbol, const unsigned char source[], int *p_length,
unsigned int *jisdata);
INTERNAL int sjis_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *jisdata,
const int full_multibyte);
INTERNAL void sjis_cpy(const unsigned char source[], int *p_length, unsigned int *jisdata, const int full_multibyte);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* SJIS_H */

View File

@ -50,3 +50,5 @@ typedef INT32 int32_t;
#endif /* __cplusplus */
#endif /* STDINT_MSVC_H */

344
3rdparty/zint-2.10.0/backend/svg.c vendored Normal file
View File

@ -0,0 +1,344 @@
/* svg.c - Scalable Vector Graphics */
/*
libzint - the open source barcode library
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
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
without specific prior written permission.
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
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <math.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h"
static void pick_colour(int colour, char colour_code[]) {
switch (colour) {
case 1: // Cyan
strcpy(colour_code, "00ffff");
break;
case 2: // Blue
strcpy(colour_code, "0000ff");
break;
case 3: // Magenta
strcpy(colour_code, "ff00ff");
break;
case 4: // Red
strcpy(colour_code, "ff0000");
break;
case 5: // Yellow
strcpy(colour_code, "ffff00");
break;
case 6: // Green
strcpy(colour_code, "00ff00");
break;
case 8: // White
strcpy(colour_code, "ffffff");
break;
default: // Black
strcpy(colour_code, "000000");
break;
}
}
static void make_html_friendly(unsigned char *string, char *html_version) {
/* Converts text to use HTML entity codes */
int i, len, html_pos;
html_pos = 0;
html_version[html_pos] = '\0';
len = (int) ustrlen(string);
for (i = 0; i < len; i++) {
switch (string[i]) {
case '>':
strcat(html_version, "&gt;");
html_pos += 4;
break;
case '<':
strcat(html_version, "&lt;");
html_pos += 4;
break;
case '&':
strcat(html_version, "&amp;");
html_pos += 5;
break;
case '"':
strcat(html_version, "&quot;");
html_pos += 6;
break;
case '\'':
strcat(html_version, "&apos;");
html_pos += 6;
break;
default:
html_version[html_pos] = string[i];
html_pos++;
html_version[html_pos] = '\0';
break;
}
}
}
INTERNAL int svg_plot(struct zint_symbol *symbol) {
FILE *fsvg;
int error_number = 0;
const char *locale = NULL;
float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy;
float previous_diameter;
float radius, half_radius, half_sqrt3_radius;
int i;
char fgcolour_string[7];
char bgcolour_string[7];
int bg_alpha = 0xff;
int fg_alpha = 0xff;
float fg_alpha_opacity = 0.0f, bg_alpha_opacity = 0.0f;
const char *font_family = "Helvetica, sans-serif";
int bold;
struct zint_vector_rect *rect;
struct zint_vector_hexagon *hex;
struct zint_vector_circle *circle;
struct zint_vector_string *string;
char colour_code[7];
int len, html_len;
#ifdef _MSC_VER
char *html_string;
#endif
for (i = 0; i < 6; i++) {
fgcolour_string[i] = symbol->fgcolour[i];
bgcolour_string[i] = symbol->bgcolour[i];
}
fgcolour_string[6] = '\0';
bgcolour_string[6] = '\0';
if (strlen(symbol->fgcolour) > 6) {
fg_alpha = (16 * ctoi(symbol->fgcolour[6])) + ctoi(symbol->fgcolour[7]);
if (fg_alpha != 0xff) {
fg_alpha_opacity = (float) (fg_alpha / 255.0);
}
}
if (strlen(symbol->bgcolour) > 6) {
bg_alpha = (16 * ctoi(symbol->bgcolour[6])) + ctoi(symbol->bgcolour[7]);
if (bg_alpha != 0xff) {
bg_alpha_opacity = (float) (bg_alpha / 255.0);
}
}
len = (int) ustrlen(symbol->text);
html_len = len + 1;
for (i = 0; i < len; i++) {
switch (symbol->text[i]) {
case '>':
case '<':
case '"':
case '&':
case '\'':
html_len += 6;
break;
}
}
#ifndef _MSC_VER
char html_string[html_len];
#else
html_string = (char *) _alloca(html_len);
#endif
/* Check for no created vector set */
/* E-Mail Christian Schmitz 2019-09-10: reason unknown Ticket #164*/
if (symbol->vector == NULL) {
strcpy(symbol->errtxt, "681: Vector header NULL");
return ZINT_ERROR_INVALID_DATA;
}
if (symbol->output_options & BARCODE_STDOUT) {
fsvg = stdout;
} else {
if (!(fsvg = fopen(symbol->outfile, "w"))) {
sprintf(symbol->errtxt, "680: Could not open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
}
locale = setlocale(LC_ALL, "C");
/* Start writing the header */
fprintf(fsvg, "<?xml version=\"1.0\" standalone=\"no\"?>\n");
fprintf(fsvg, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n");
fprintf(fsvg, " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
fprintf(fsvg, "<svg width=\"%d\" height=\"%d\" version=\"1.1\"\n",
(int) ceilf(symbol->vector->width), (int) ceilf(symbol->vector->height));
fprintf(fsvg, " xmlns=\"http://www.w3.org/2000/svg\">\n");
fprintf(fsvg, " <desc>Zint Generated Symbol\n");
fprintf(fsvg, " </desc>\n");
fprintf(fsvg, "\n <g id=\"barcode\" fill=\"#%s\">\n", fgcolour_string);
if (bg_alpha != 0) {
fprintf(fsvg, " <rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" fill=\"#%s\"",
(int) ceilf(symbol->vector->width), (int) ceilf(symbol->vector->height), bgcolour_string);
if (bg_alpha != 0xff) {
fprintf(fsvg, " opacity=\"%.3f\"", bg_alpha_opacity);
}
fprintf(fsvg, " />\n");
}
rect = symbol->vector->rectangles;
while (rect) {
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\"",
rect->x, rect->y, rect->width, rect->height);
if (rect->colour != -1) {
pick_colour(rect->colour, colour_code);
fprintf(fsvg, " fill=\"#%s\"", colour_code);
}
if (fg_alpha != 0xff) {
fprintf(fsvg, " opacity=\"%.3f\"", fg_alpha_opacity);
}
fprintf(fsvg, " />\n");
rect = rect->next;
}
previous_diameter = radius = half_radius = half_sqrt3_radius = 0.0f;
hex = symbol->vector->hexagons;
while (hex) {
if (previous_diameter != hex->diameter) {
previous_diameter = hex->diameter;
radius = (float) (0.5 * previous_diameter);
half_radius = (float) (0.25 * previous_diameter);
half_sqrt3_radius = (float) (0.43301270189221932338 * previous_diameter);
}
if ((hex->rotation == 0) || (hex->rotation == 180)) {
ay = hex->y + radius;
by = hex->y + half_radius;
cy = hex->y - half_radius;
dy = hex->y - radius;
ey = hex->y - half_radius;
fy = hex->y + half_radius;
ax = hex->x;
bx = hex->x + half_sqrt3_radius;
cx = hex->x + half_sqrt3_radius;
dx = hex->x;
ex = hex->x - half_sqrt3_radius;
fx = hex->x - half_sqrt3_radius;
} else {
ay = hex->y;
by = hex->y + half_sqrt3_radius;
cy = hex->y + half_sqrt3_radius;
dy = hex->y;
ey = hex->y - half_sqrt3_radius;
fy = hex->y - half_sqrt3_radius;
ax = hex->x - radius;
bx = hex->x - half_radius;
cx = hex->x + half_radius;
dx = hex->x + radius;
ex = hex->x + half_radius;
fx = hex->x - half_radius;
}
fprintf(fsvg, " <path d=\"M %.2f %.2f L %.2f %.2f L %.2f %.2f L %.2f %.2f L %.2f %.2f L %.2f %.2f Z\"",
ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy);
if (fg_alpha != 0xff) {
fprintf(fsvg, " opacity=\"%.3f\"", fg_alpha_opacity);
}
fprintf(fsvg, " />\n");
hex = hex->next;
}
previous_diameter = radius = 0.0f;
circle = symbol->vector->circles;
while (circle) {
if (previous_diameter != circle->diameter) {
previous_diameter = circle->diameter;
radius = (float) (0.5 * previous_diameter);
}
fprintf(fsvg, " <circle cx=\"%.2f\" cy=\"%.2f\" r=\"%.2f\"", circle->x, circle->y, radius);
if (circle->colour) {
fprintf(fsvg, " fill=\"#%s\"", bgcolour_string);
if (bg_alpha != 0xff) {
// This doesn't work how the user is likely to expect - more work needed!
fprintf(fsvg, " opacity=\"%.3f\"", bg_alpha_opacity);
}
} else {
if (fg_alpha != 0xff) {
fprintf(fsvg, " opacity=\"%.3f\"", fg_alpha_opacity);
}
}
fprintf(fsvg, " />\n");
circle = circle->next;
}
bold = (symbol->output_options & BOLD_TEXT)
&& (!is_extendable(symbol->symbology) || (symbol->output_options & SMALL_TEXT));
string = symbol->vector->strings;
while (string) {
const char *halign = string->halign == 2 ? "end" : string->halign == 1 ? "start" : "middle";
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"%s\"\n", string->x, string->y, halign);
fprintf(fsvg, " font-family=\"%s\" font-size=\"%.1f\"", font_family, string->fsize);
if (bold) {
fprintf(fsvg, " font-weight=\"bold\"");
}
if (fg_alpha != 0xff) {
fprintf(fsvg, " opacity=\"%.3f\"", fg_alpha_opacity);
}
if (string->rotation != 0) {
fprintf(fsvg, " transform=\"rotate(%d,%.2f,%.2f)\"", string->rotation, string->x, string->y);
}
fprintf(fsvg, " >\n");
make_html_friendly(string->text, html_string);
fprintf(fsvg, " %s\n", html_string);
fprintf(fsvg, " </text>\n");
string = string->next;
}
fprintf(fsvg, " </g>\n");
fprintf(fsvg, "</svg>\n");
if (symbol->output_options & BARCODE_STDOUT) {
fflush(fsvg);
} else {
fclose(fsvg);
}
if (locale)
setlocale(LC_ALL, locale);
return error_number;
}

View File

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008-2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -29,16 +29,18 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
/* Telepen Barcode Symbology information and History (BSiH)
https://telepen.co.uk/wp-content/uploads/2018/10/Barcode-Symbology-information-and-History.pdf */
#define SODIUM "0123456789X"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "common.h"
static char *TeleTable[] = {
"1111111111111111", "1131313111", "33313111", "1111313131", "3111313111", "11333131", "13133131", "111111313111",
"31313131", "1131313111", "33313111", "1111313131", "3111313111", "11333131", "13133131", "111111313111",
"31333111", "1131113131", "33113131", "1111333111", "3111113131", "1113133111", "1311133111", "111111113131",
"3131113111", "11313331", "333331", "111131113111", "31113331", "1133113111", "1313113111", "1111113331",
"31131331", "113111113111", "3311113111", "1111131331", "311111113111", "1113111331", "1311111331", "11111111113111",
@ -53,29 +55,29 @@ static char *TeleTable[] = {
"31311313", "113131111111", "3331111111", "1111311313", "311131111111", "11331313", "13131313", "11111131111111",
"3133111111", "1131111313", "33111313", "111133111111", "3111111313", "111313111111", "131113111111", "111111111313",
"313111111111", "1131131113", "33131113", "11113111111111", "3111131113", "113311111111", "131311111111", "111111131113",
"3113111113", "11311111111111", "331111111111", "111113111113", "31111111111111", "111311111113", "131111111113"
"3113111113", "11311111111111", "331111111111", "111113111113", "31111111111111", "111311111113", "131111111113", "1111111111111111",
};
int telepen(struct zint_symbol *symbol, unsigned char source[], const size_t src_len) {
unsigned int i, count, check_digit;
INTERNAL int telepen(struct zint_symbol *symbol, unsigned char source[], int src_len) {
int i, count, check_digit;
int error_number;
char dest[512]; /*14 + 30 * 14 + 14 + 14 + 1 ~ 512 */
char dest[521]; /* 12 (start) + 30 * 16 (max for DELs) + 16 (check digit) + 12 (stop) + 1 = 521 */
error_number = 0;
count = 0;
if (src_len > 30) {
strcpy(symbol->errtxt, "390: Input too long");
strcpy(symbol->errtxt, "390: Input too long (30 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
/* Start character */
strcpy(dest, TeleTable['_']);
for (i = 0; i < src_len; i++) {
if (source[i] > 126) {
if (source[i] > 127) {
/* Cannot encode extended ASCII */
strcpy(symbol->errtxt, "391: Invalid characters in input data");
strcpy(symbol->errtxt, "391: Invalid character in input data, extended ASCII not allowed");
return ZINT_ERROR_INVALID_DATA;
}
strcat(dest, TeleTable[source[i]]);
@ -88,10 +90,21 @@ int telepen(struct zint_symbol *symbol, unsigned char source[], const size_t src
}
strcat(dest, TeleTable[check_digit]);
if (symbol->debug & ZINT_DEBUG_PRINT) printf("Check digit: %d\n", check_digit);
/* Stop character */
strcat(dest, TeleTable['z']);
expand(symbol, dest);
#ifdef COMPLIANT_HEIGHTS
/* Default height from various Telepen docs is based on default 26pt at X 0.01125" (average of 0.01" - 0.0125")
= (26 / 72) / 0.01125 ~ 32; no min height specified */
(void) set_height(symbol, 0.0f, 32.0f, 0, 1 /*no_errtxt*/);
#else
(void) set_height(symbol, 0.0f, 50.0f, 0, 1 /*no_errtxt*/);
#endif
for (i = 0; i < src_len; i++) {
if (source[i] == '\0') {
symbol->text[i] = ' ';
@ -103,39 +116,39 @@ int telepen(struct zint_symbol *symbol, unsigned char source[], const size_t src
return error_number;
}
int telepen_num(struct zint_symbol *symbol, unsigned char source[], const size_t src_len) {
unsigned int count, check_digit, glyph;
INTERNAL int telepen_num(struct zint_symbol *symbol, unsigned char source[], int src_len) {
int count, check_digit, glyph;
int error_number;
size_t i,temp_length = src_len;
char dest[1024]; /* 14 + 60 * 14 + 14 + 14 + 1 ~ 1024 */
int i;
char dest[521]; /* 12 (start) + 30 * 16 (max for DELs) + 16 (check digit) + 12 (stop) + 1 = 521 */
unsigned char temp[64];
count = 0;
if (temp_length > 60) {
strcpy(symbol->errtxt, "392: Input too long");
if (src_len > 60) {
strcpy(symbol->errtxt, "392: Input too long (60 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
ustrcpy(temp, source);
to_upper(temp);
error_number = is_sane(SODIUM, temp, temp_length);
error_number = is_sane(SODIUM, temp, src_len);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "393: Invalid characters in data");
strcpy(symbol->errtxt, "393: Invalid character in data (digits and \"X\" only)");
return error_number;
}
/* Add a leading zero if required */
if (temp_length & 1) {
memmove(temp + 1, temp, temp_length);
if (src_len & 1) {
memmove(temp + 1, temp, src_len);
temp[0] = '0';
temp[++temp_length] = '\0';
temp[++src_len] = '\0';
}
/* Start character */
strcpy(dest, TeleTable['_']);
for (i = 0; i < temp_length; i += 2) {
for (i = 0; i < src_len; i += 2) {
if (temp[i] == 'X') {
strcpy(symbol->errtxt, "394: Invalid position of X in Telepen data");
return ZINT_ERROR_INVALID_DATA;
@ -158,10 +171,19 @@ int telepen_num(struct zint_symbol *symbol, unsigned char source[], const size_t
}
strcat(dest, TeleTable[check_digit]);
if (symbol->debug & ZINT_DEBUG_PRINT) printf("Check digit: %d\n", check_digit);
/* Stop character */
strcat(dest, TeleTable['z']);
expand(symbol, dest);
#ifdef COMPLIANT_HEIGHTS
(void) set_height(symbol, 0.0f, 32.0f, 0, 1 /*no_errtxt*/); /* Same as alphanumeric Telepen */
#else
(void) set_height(symbol, 0.0f, 50.0f, 0, 1 /*no_errtxt*/);
#endif
ustrcpy(symbol->text, temp);
return error_number;
}

View File

@ -0,0 +1,92 @@
# Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com>
# Adapted from qrencode/tests/CMakeLists.txt
# Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
# vim: set ts=4 sw=4 et :
cmake_minimum_required(VERSION 3.5)
project(zint_backend_tests)
enable_testing()
include(${zint-package_SOURCE_DIR}/cmake/zint_add_test.cmake)
set(BWIPP_TAR ${CMAKE_CURRENT_SOURCE_DIR}/tools/bwipp_dump.ps.tar.xz)
set(BWIPP_PS ${CMAKE_CURRENT_BINARY_DIR}/tools/bwipp_dump.ps)
if(NOT EXISTS ${BWIPP_PS})
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tools)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xf ${BWIPP_TAR}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tools)
endif()
set(testcommon_SRCS testcommon.c testcommon.h)
add_library(testcommon ${testcommon_SRCS})
target_link_libraries(testcommon zint)
target_include_directories(testcommon PUBLIC ${zint_backend_tests_SOURCE_DIR})
if(NOT HAVE_GETOPT)
target_link_libraries(testcommon zint_bundled_getopt)
endif()
if(ZINT_STATIC)
add_library(testcommon-static ${testcommon_SRCS})
target_link_libraries(testcommon-static zint-static)
target_include_directories(testcommon-static PUBLIC ${zint_backend_tests_SOURCE_DIR})
if(NOT HAVE_GETOPT)
target_link_libraries(testcommon-static zint_bundled_getopt)
endif()
endif()
zint_add_test(2of5 test_2of5)
zint_add_test(auspost test_auspost)
zint_add_test(aztec test_aztec)
zint_add_test(big5 test_big5)
zint_add_test(bmp test_bmp)
zint_add_test(channel test_channel)
zint_add_test(codablock test_codablock)
zint_add_test(code test_code)
zint_add_test(code1 test_code1)
zint_add_test(code128 test_code128)
zint_add_test(code16k test_code16k)
zint_add_test(code49 test_code49)
zint_add_test(common test_common)
zint_add_test(composite test_composite)
zint_add_test(dmatrix test_dmatrix)
zint_add_test(dotcode test_dotcode)
zint_add_test(eci test_eci)
zint_add_test(emf test_emf)
zint_add_test(gb18030 test_gb18030)
zint_add_test(gb2312 test_gb2312)
zint_add_test(gif test_gif)
zint_add_test(gridmtx test_gridmtx)
zint_add_test(gs1 test_gs1)
zint_add_test(hanxin test_hanxin)
zint_add_test(imail test_imail)
zint_add_test(iso3166 test_iso3166)
zint_add_test(iso4217 test_iso4217)
zint_add_test(ksx1001 test_ksx1001)
zint_add_test(large test_large)
zint_add_test(library test_library)
zint_add_test(mailmark test_mailmark)
zint_add_test(maxicode test_maxicode)
zint_add_test(medical test_medical)
zint_add_test(pcx test_pcx)
zint_add_test(pdf417 test_pdf417)
zint_add_test(plessey test_plessey)
if(ZINT_USE_PNG AND PNG_FOUND)
zint_add_test(png test_png)
endif()
zint_add_test(postal test_postal)
zint_add_test(print test_print)
zint_add_test(ps test_ps)
zint_add_test(qr test_qr)
zint_add_test(raster test_raster)
zint_add_test(reedsol test_reedsol)
zint_add_test(rss test_rss)
zint_add_test(sjis test_sjis)
zint_add_test(svg test_svg)
zint_add_test(telepen test_telepen)
zint_add_test(tif test_tif)
zint_add_test(ultra test_ultra)
zint_add_test(upcean test_upcean)
zint_add_test(vector test_vector)

View File

@ -0,0 +1,106 @@
Zint backend test suite
-----------------------
In order to build the zint test suite, zint has to be compiled with the
ZINT_TEST option enabled:
cd <project-dir>
mkdir build
cd build
cmake -DZINT_TEST=ON ..
make
------------------------------------------------------------------------------
In order to run the test suite, the path of the zint library may need to be
communicated to the runtime linker. On UNIX-like systems, this is done by
exporting LD_LIBRARY_PATH to the path containing the zint library, which is
<build-dir>/backend:
cd <project-dir>
cd build
export LD_LIBRARY_PATH=$(pwd)/backend
Setting LD_LIBRARY_PATH is not required if the zint library to be tested is
installed into a system library path ( /usr/lib for example ) prior to running
the tests.
To run all tests (within <build-dir>):
ctest
For various useful options, e.g. matching (-R) and excluding (-E) tests, see
https://cmake.org/cmake/help/latest/manual/ctest.1.html#options
Tests can also be run individually, eg:
backend/tests/test_common
backend/tests/test_vector
To run a single test function within an individual test, use '-f <func-name>':
backend/tests/test_common -f utf8_to_unicode
backend/tests/test_dotcode -f input
To run a single dataset item in a single test function, use '-i <index>':
backend/tests/test_dotcode -f input -i 2
To show debug info (if any), use '-d <flag>':
backend/tests/test_dotcode -f input -i 2 -d 1
(for other flags see <project-dir>/backend/tests/testcommon.h)
To generate test data, use '-g':
backend/tests/test_dotcode -f encode -g
To run a test against BWIPP (if any), use '-d 128':
backend/tests/test_composite -d 128
(see also <project-dir>/backend/tests/tools/run_bwipp_tests.sh)
------------------------------------------------------------------------------
If the zint library was built with static linkage support, i.e. ZINT_STATIC
is ON, an additional test executable, which uses the zint-static library, will
be built. The static variant of each test shares the test name, but has a
"-static" suffix. For example,
backend/tests/test_dotcode
would run the dotcode test that uses the shared zint library, while
backend/tests/test_dotcode-static
runs the same test built against the zint-static library.
------------------------------------------------------------------------------
To make with gcc sanitize, first set for libzint and make:
cd <project-dir>
cd build
cmake -DZINT_SANITIZE=ON ..
make && sudo make install
Similarly to make with gcc debug:
cd <project-dir>
cd build
cmake -DZINT_DEBUG=ON ..
make && sudo make install
To undo sanitize/debug, remake each after setting:
cmake -DZINT_SANITIZE=OFF ..
cmake -DZINT_DEBUG=OFF ..
To get a clean libzint, set the above and also:
cmake -DZINT_TEST=OFF ..
(The tests will now fail to link.)

View File

@ -0,0 +1,53 @@
# - Try to find the Zint barcode library
# Once done this will define
#
# LIBZINT_FOUND - System has Zint barcode
# LIBZINT_INCLUDE_DIRS - The Zint barcode include directory
# LIBZINT_LIBRARIES - The libraries needed to use Zint barcode
# LIBZINT_DEFINITIONS - Definitions needed to use Zint barcode
# LIBZINT_VERSION_STRING - the version of Zint barcode found
set (LIBZINT_DEFINITIONS "")
find_path (LIBZINT_INCLUDE_DIR NAMES zint.h)
find_library (LIBZINT_LIBRARY NAMES zint )
if (LIBZINT_LIBRARY AND LIBZINT_INCLUDE_DIR)
set (LIBZINT_INCLUDE_DIRS ${LIBZINT_INCLUDE_DIR})
set (LIBZINT_LIBRARIES ${LIBZINT_LIBRARY})
set (LIBZINT_DEFINITIONS "")
if (NOT TARGET ZINT::ZINT)
add_library (ZINT::ZINT UNKNOWN IMPORTED)
set_target_properties (ZINT::ZINT PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "${LIBZINT_DEFINITIONS}"
INTERFACE_INCLUDE_DIRECTORIES "${LIBZINT_INCLUDE_DIRS}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${LIBZINT_LIBRARY}"
)
endif ()
endif ()
if (LIBZINT_INCLUDE_DIR AND EXISTS "${LIBZINT_INCLUDE_DIR}/zintconfig.h")
file (STRINGS "${LIBZINT_INCLUDE_DIR}/zintconfig.h" ZINT_MAJOR_H REGEX "^#define ZINT_VERSION_MAJOR *[0-9]*")
file (STRINGS "${LIBZINT_INCLUDE_DIR}/zintconfig.h" ZINT_MINOR_H REGEX "^#define ZINT_VERSION_MINOR *[0-9]*")
file (STRINGS "${LIBZINT_INCLUDE_DIR}/zintconfig.h" ZINT_MICRO_H REGEX "^#define ZINT_VERSION_RELEASE *[0-9]*")
string (REGEX REPLACE "^.*VERSION_MAJOR *([0-9]*)" "\\1" ZINT_MAJOR ${ZINT_MAJOR_H})
string (REGEX REPLACE "^.*VERSION_MINOR *([0-9]*)" "\\1" ZINT_MINOR ${ZINT_MINOR_H})
string (REGEX REPLACE "^.*VERSION_RELEASE *([0-9]*)" "\\1" ZINT_MICRO ${ZINT_MICRO_H})
set (LIBZINT_VERSION_STRING ${ZINT_MAJOR}.${ZINT_MINOR}.${ZINT_MICRO})
endif()
# handle the QUIETLY and REQUIRED arguments and set LIBZINT_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibZint
REQUIRED_VARS LIBZINT_LIBRARY LIBZINT_INCLUDE_DIR
VERSION_VAR LIBZINT_VERSION_STRING)
mark_as_advanced(LIBZINT_INCLUDE_DIR LIBZINT_LIBRARY)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Some files were not shown because too many files have changed in this diff Show More