Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | e778668 | 2017-03-29 15:18:41 -0400 | [diff] [blame] | 7 | #ifndef FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_ |
| 8 | #define FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_ |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 9 | |
tsepez | 988599c | 2016-12-13 12:45:56 -0800 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
Dan Sinclair | e778668 | 2017-03-29 15:18:41 -0400 | [diff] [blame] | 12 | #include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 13 | |
| 14 | #define ASCII_ENCODATION 0 |
| 15 | #define C40_ENCODATION 1 |
| 16 | #define TEXT_ENCODATION 2 |
| 17 | #define X12_ENCODATION 3 |
| 18 | #define EDIFACT_ENCODATION 4 |
| 19 | #define BASE256_ENCODATION 5 |
| 20 | |
| 21 | class CBC_HighLevelEncoder : public CBC_SymbolShapeHint { |
| 22 | public: |
| 23 | CBC_HighLevelEncoder(); |
weili | 29b8ad0 | 2016-06-14 18:20:04 -0700 | [diff] [blame] | 24 | ~CBC_HighLevelEncoder() override; |
| 25 | |
Tom Sepez | 8b6186f | 2017-03-28 12:06:45 -0700 | [diff] [blame] | 26 | std::vector<uint8_t>& getBytesForMessage(CFX_WideString msg); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 27 | static CFX_WideString encodeHighLevel(CFX_WideString msg, |
| 28 | CFX_WideString ecLevel, |
| 29 | int32_t& e); |
| 30 | static CFX_WideString encodeHighLevel(CFX_WideString msg, |
| 31 | CFX_WideString ecLevel, |
| 32 | SymbolShapeHint shape, |
| 33 | CBC_Dimension* minSize, |
| 34 | CBC_Dimension* maxSize, |
| 35 | int32_t& e); |
| 36 | static int32_t lookAheadTest(CFX_WideString msg, |
| 37 | int32_t startpos, |
| 38 | int32_t currentMode); |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 39 | static bool isDigit(wchar_t ch); |
| 40 | static bool isExtendedASCII(wchar_t ch); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 41 | static int32_t determineConsecutiveDigitCount(CFX_WideString msg, |
| 42 | int32_t startpos); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 43 | |
| 44 | public: |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 45 | static wchar_t LATCH_TO_C40; |
| 46 | static wchar_t LATCH_TO_BASE256; |
| 47 | static wchar_t UPPER_SHIFT; |
| 48 | static wchar_t LATCH_TO_ANSIX12; |
| 49 | static wchar_t LATCH_TO_TEXT; |
| 50 | static wchar_t LATCH_TO_EDIFACT; |
| 51 | static wchar_t C40_UNLATCH; |
| 52 | static wchar_t X12_UNLATCH; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 53 | |
| 54 | private: |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 55 | static wchar_t PAD; |
| 56 | static wchar_t MACRO_05; |
| 57 | static wchar_t MACRO_06; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 58 | static const wchar_t* MACRO_05_HEADER; |
| 59 | static const wchar_t* MACRO_06_HEADER; |
| 60 | static const wchar_t MACRO_TRAILER; |
Tom Sepez | 8b6186f | 2017-03-28 12:06:45 -0700 | [diff] [blame] | 61 | std::vector<uint8_t> m_bytearray; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 62 | |
| 63 | private: |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 64 | static wchar_t randomize253State(wchar_t ch, int32_t codewordPosition); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 65 | static int32_t findMinimums(std::vector<float>& charCounts, |
Tom Sepez | 8b6186f | 2017-03-28 12:06:45 -0700 | [diff] [blame] | 66 | std::vector<int32_t>& intCharCounts, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 67 | int32_t min, |
Tom Sepez | 8b6186f | 2017-03-28 12:06:45 -0700 | [diff] [blame] | 68 | std::vector<uint8_t>& mins); |
| 69 | static int32_t getMinimumCount(std::vector<uint8_t>& mins); |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 70 | static bool isNativeC40(wchar_t ch); |
| 71 | static bool isNativeText(wchar_t ch); |
| 72 | static bool isNativeX12(wchar_t ch); |
| 73 | static bool isX12TermSep(wchar_t ch); |
| 74 | static bool isNativeEDIFACT(wchar_t ch); |
| 75 | static bool isSpecialB256(wchar_t ch); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 76 | }; |
| 77 | |
Dan Sinclair | e778668 | 2017-03-29 15:18:41 -0400 | [diff] [blame] | 78 | #endif // FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_ |