blob: 12b8cab35a158d04e7303a5a7582f2b5b414450b [file] [log] [blame]
Dan Sinclair1770c022016-03-14 14:14:16 -04001// 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 Sinclaire7786682017-03-29 15:18:41 -04007#ifndef FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_
8#define FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_
Dan Sinclair1770c022016-03-14 14:14:16 -04009
tsepez988599c2016-12-13 12:45:56 -080010#include <vector>
11
Dan Sinclaire7786682017-03-29 15:18:41 -040012#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040013
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
21class CBC_HighLevelEncoder : public CBC_SymbolShapeHint {
22 public:
23 CBC_HighLevelEncoder();
weili29b8ad02016-06-14 18:20:04 -070024 ~CBC_HighLevelEncoder() override;
25
Tom Sepez8b6186f2017-03-28 12:06:45 -070026 std::vector<uint8_t>& getBytesForMessage(CFX_WideString msg);
Dan Sinclair1770c022016-03-14 14:14:16 -040027 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 Sinclair812e96c2017-03-13 16:43:37 -040039 static bool isDigit(wchar_t ch);
40 static bool isExtendedASCII(wchar_t ch);
Dan Sinclair1770c022016-03-14 14:14:16 -040041 static int32_t determineConsecutiveDigitCount(CFX_WideString msg,
42 int32_t startpos);
Dan Sinclair1770c022016-03-14 14:14:16 -040043
44 public:
Dan Sinclair812e96c2017-03-13 16:43:37 -040045 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 Sinclair1770c022016-03-14 14:14:16 -040053
54 private:
Dan Sinclair812e96c2017-03-13 16:43:37 -040055 static wchar_t PAD;
56 static wchar_t MACRO_05;
57 static wchar_t MACRO_06;
Dan Sinclair1770c022016-03-14 14:14:16 -040058 static const wchar_t* MACRO_05_HEADER;
59 static const wchar_t* MACRO_06_HEADER;
60 static const wchar_t MACRO_TRAILER;
Tom Sepez8b6186f2017-03-28 12:06:45 -070061 std::vector<uint8_t> m_bytearray;
Dan Sinclair1770c022016-03-14 14:14:16 -040062
63 private:
Dan Sinclair812e96c2017-03-13 16:43:37 -040064 static wchar_t randomize253State(wchar_t ch, int32_t codewordPosition);
Dan Sinclair05df0752017-03-14 14:43:42 -040065 static int32_t findMinimums(std::vector<float>& charCounts,
Tom Sepez8b6186f2017-03-28 12:06:45 -070066 std::vector<int32_t>& intCharCounts,
Dan Sinclair1770c022016-03-14 14:14:16 -040067 int32_t min,
Tom Sepez8b6186f2017-03-28 12:06:45 -070068 std::vector<uint8_t>& mins);
69 static int32_t getMinimumCount(std::vector<uint8_t>& mins);
Dan Sinclair812e96c2017-03-13 16:43:37 -040070 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 Sinclair1770c022016-03-14 14:14:16 -040076};
77
Dan Sinclaire7786682017-03-29 15:18:41 -040078#endif // FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_