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 7 #ifndef FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_ 8 #define FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_ 9 10 #include <vector> 11 12 #include "core/fxcrt/widestring.h" 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 { 22 public: 23 CBC_HighLevelEncoder(); 24 ~CBC_HighLevelEncoder(); 25 26 std::vector<uint8_t>& getBytesForMessage(WideString msg); 27 28 static WideString encodeHighLevel(WideString msg, 29 WideString ecLevel, 30 bool allowRectangular, 31 int32_t& e); 32 static int32_t lookAheadTest(WideString msg, 33 int32_t startpos, 34 int32_t currentMode); 35 static bool isDigit(wchar_t ch); 36 static bool isExtendedASCII(wchar_t ch); 37 static int32_t determineConsecutiveDigitCount(WideString msg, 38 int32_t startpos); 39 40 static const wchar_t LATCH_TO_C40; 41 static const wchar_t LATCH_TO_BASE256; 42 static const wchar_t UPPER_SHIFT; 43 static const wchar_t LATCH_TO_ANSIX12; 44 static const wchar_t LATCH_TO_TEXT; 45 static const wchar_t LATCH_TO_EDIFACT; 46 static const wchar_t C40_UNLATCH; 47 static const wchar_t X12_UNLATCH; 48 49 private: 50 static wchar_t randomize253State(wchar_t ch, int32_t codewordPosition); 51 static int32_t findMinimums(std::vector<float>& charCounts, 52 std::vector<int32_t>& intCharCounts, 53 int32_t min, 54 std::vector<uint8_t>& mins); 55 static int32_t getMinimumCount(std::vector<uint8_t>& mins); 56 static bool isNativeC40(wchar_t ch); 57 static bool isNativeText(wchar_t ch); 58 static bool isNativeX12(wchar_t ch); 59 static bool isX12TermSep(wchar_t ch); 60 static bool isNativeEDIFACT(wchar_t ch); 61 62 static const wchar_t PAD; 63 static const wchar_t MACRO_05; 64 static const wchar_t MACRO_06; 65 static const wchar_t MACRO_05_HEADER[]; 66 static const wchar_t MACRO_06_HEADER[]; 67 static const wchar_t MACRO_TRAILER; 68 69 std::vector<uint8_t> m_bytearray; 70 }; 71 72 #endif // FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_ 73