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 _BC_QRCODERENCODER_H_
8 #define _BC_QRCODERENCODER_H_
9 class Make_Pair;
10 class CBC_QRCoder;
11 class CBC_QRCoderErrorCorrectionLevel;
12 class CBC_QRCoderMode;
13 class CBC_QRCoderBitVector;
14 class CBC_CommonByteArray;
15 class CBC_CommonByteMatrix;
16 class CBC_QRCoderEncoder;
17 class CBC_QRCoderEncoder {
18  private:
19   const static int32_t m_alphaNumbericTable[96];
20 
21  public:
22   CBC_QRCoderEncoder();
23   virtual ~CBC_QRCoderEncoder();
24 
25   static void Encode(const CFX_ByteString& content,
26                      CBC_QRCoderErrorCorrectionLevel* ecLevel,
27                      CBC_QRCoder* qrCode,
28                      int32_t& e,
29                      int32_t versionSpecify = 0);
30   static void Encode(const CFX_WideString& content,
31                      CBC_QRCoderErrorCorrectionLevel* ecLevel,
32                      CBC_QRCoder* qrCode,
33                      int32_t& e);
34   static void EncodeWithSpecifyVersion(const CFX_ByteString& content,
35                                        CBC_QRCoderErrorCorrectionLevel* ecLevel,
36                                        CBC_QRCoder* qrCode,
37                                        int32_t versionSpecify,
38                                        int32_t& e);
39   static void EncodeWithAutoVersion(const CFX_ByteString& content,
40                                     CBC_QRCoderErrorCorrectionLevel* ecLevel,
41                                     CBC_QRCoder* qrCode,
42                                     int32_t& e);
43   static CBC_QRCoderMode* ChooseMode(const CFX_ByteString& content,
44                                      CFX_ByteString encoding);
45   static int32_t GetAlphaNumericCode(int32_t code);
46   static void AppendECI(CBC_QRCoderBitVector* bits);
47   static void AppendBytes(const CFX_ByteString& content,
48                           CBC_QRCoderMode* mode,
49                           CBC_QRCoderBitVector* bits,
50                           CFX_ByteString encoding,
51                           int32_t& e);
52   static void AppendNumericBytes(const CFX_ByteString& content,
53                                  CBC_QRCoderBitVector* bits,
54                                  int32_t& e);
55   static void AppendAlphaNumericBytes(const CFX_ByteString& content,
56                                       CBC_QRCoderBitVector* bits,
57                                       int32_t& e);
58   static void Append8BitBytes(const CFX_ByteString& content,
59                               CBC_QRCoderBitVector* bits,
60                               CFX_ByteString encoding,
61                               int32_t& e);
62   static void Append8BitBytes(CFX_ByteArray& bytes,
63                               CBC_QRCoderBitVector* bits,
64                               int32_t& e);
65   static void AppendKanjiBytes(const CFX_ByteString& content,
66                                CBC_QRCoderBitVector* bits,
67                                int32_t& e);
68   static void AppendGBKBytes(const CFX_ByteString& content,
69                              CBC_QRCoderBitVector* bits,
70                              int32_t& e);
71   static void InitQRCode(int32_t numInputBytes,
72                          int32_t versionNumber,
73                          CBC_QRCoderErrorCorrectionLevel* ecLevel,
74                          CBC_QRCoderMode* mode,
75                          CBC_QRCoder* qrCode,
76                          int32_t& e);
77   static void InitQRCode(int32_t numInputBytes,
78                          CBC_QRCoderErrorCorrectionLevel* ecLevel,
79                          CBC_QRCoderMode* mode,
80                          CBC_QRCoder* qrCode,
81                          int32_t& e);
82   static void AppendModeInfo(CBC_QRCoderMode* mode,
83                              CBC_QRCoderBitVector* bits,
84                              int32_t& e);
85   static void AppendLengthInfo(int32_t numLetters,
86                                int32_t version,
87                                CBC_QRCoderMode* mode,
88                                CBC_QRCoderBitVector* bits,
89                                int32_t& e);
90 
91   static void InterleaveWithECBytes(CBC_QRCoderBitVector* bits,
92                                     int32_t numTotalBytes,
93                                     int32_t numDataBytes,
94                                     int32_t numRSBlocks,
95                                     CBC_QRCoderBitVector* result,
96                                     int32_t& e);
97   static void GetNumDataBytesAndNumECBytesForBlockID(
98       int32_t numTotalBytes,
99       int32_t numDataBytes,
100       int32_t numRSBlocks,
101       int32_t blockID,
102       int32_t& numDataBytesInBlock,
103       int32_t& numECBytesInBlocks);
104   static CBC_CommonByteArray* GenerateECBytes(CBC_CommonByteArray* dataBytes,
105                                               int32_t numEcBytesInBlock,
106                                               int32_t& e);
107   static int32_t ChooseMaskPattern(CBC_QRCoderBitVector* bits,
108                                    CBC_QRCoderErrorCorrectionLevel* ecLevel,
109                                    int32_t version,
110                                    CBC_CommonByteMatrix* matrix,
111                                    int32_t& e);
112   static int32_t CalculateMaskPenalty(CBC_CommonByteMatrix* matrix);
113   static void TerminateBits(int32_t numDataBytes,
114                             CBC_QRCoderBitVector* bits,
115                             int32_t& e);
116   static int32_t GetSpanByVersion(CBC_QRCoderMode* modeFirst,
117                                   CBC_QRCoderMode* modeSecond,
118                                   int32_t versionNum,
119                                   int32_t& e);
120   static void MergeString(CFX_PtrArray& result, int32_t versionNum, int32_t& e);
121   static void SplitString(const CFX_ByteString& content, CFX_PtrArray& result);
122   static void AppendDataModeLenghInfo(CFX_PtrArray& splitResult,
123                                       CBC_QRCoderBitVector& headerAndDataBits,
124                                       CBC_QRCoderMode* tempMode,
125                                       CBC_QRCoder* qrCode,
126                                       CFX_ByteString& encoding,
127                                       int32_t& e);
128 };
129 #endif
130