• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 XFA_FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_
8 #define XFA_FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_
9 
10 #include <vector>
11 
12 #include "xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.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 : public CBC_SymbolShapeHint {
22  public:
23   CBC_HighLevelEncoder();
24   ~CBC_HighLevelEncoder() override;
25 
26   CFX_ArrayTemplate<uint8_t>& getBytesForMessage(CFX_WideString msg);
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);
39   static bool isDigit(FX_WCHAR ch);
40   static bool isExtendedASCII(FX_WCHAR ch);
41   static int32_t determineConsecutiveDigitCount(CFX_WideString msg,
42                                                 int32_t startpos);
43   static void illegalCharacter(FX_WCHAR c, int32_t& e);
44 
45  public:
46   static FX_WCHAR LATCH_TO_C40;
47   static FX_WCHAR LATCH_TO_BASE256;
48   static FX_WCHAR UPPER_SHIFT;
49   static FX_WCHAR LATCH_TO_ANSIX12;
50   static FX_WCHAR LATCH_TO_TEXT;
51   static FX_WCHAR LATCH_TO_EDIFACT;
52   static FX_WCHAR C40_UNLATCH;
53   static FX_WCHAR X12_UNLATCH;
54 
55  private:
56   static FX_WCHAR PAD;
57   static FX_WCHAR MACRO_05;
58   static FX_WCHAR MACRO_06;
59   static const wchar_t* MACRO_05_HEADER;
60   static const wchar_t* MACRO_06_HEADER;
61   static const wchar_t MACRO_TRAILER;
62   CFX_ArrayTemplate<uint8_t> m_bytearray;
63 
64  private:
65   static FX_WCHAR randomize253State(FX_WCHAR ch, int32_t codewordPosition);
66   static int32_t findMinimums(std::vector<FX_FLOAT>& charCounts,
67                               CFX_ArrayTemplate<int32_t>& intCharCounts,
68                               int32_t min,
69                               CFX_ArrayTemplate<uint8_t>& mins);
70   static int32_t getMinimumCount(CFX_ArrayTemplate<uint8_t>& mins);
71   static bool isNativeC40(FX_WCHAR ch);
72   static bool isNativeText(FX_WCHAR ch);
73   static bool isNativeX12(FX_WCHAR ch);
74   static bool isX12TermSep(FX_WCHAR ch);
75   static bool isNativeEDIFACT(FX_WCHAR ch);
76   static bool isSpecialB256(FX_WCHAR ch);
77 };
78 
79 #endif  // XFA_FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_
80