blob: 77de6e5e40b92ffd49038944c2fb071521fb483a [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
7#ifndef XFA_FXBARCODE_QRCODE_BC_QRCODERENCODER_H_
8#define XFA_FXBARCODE_QRCODE_BC_QRCODERENCODER_H_
9
tsepezfff400a2017-01-04 06:34:19 -080010#include <utility>
11#include <vector>
12
dsinclaira52ab742016-09-29 13:59:29 -070013#include "core/fxcrt/fx_basic.h"
14#include "core/fxcrt/fx_string.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040015
16class CBC_QRCoder;
17class CBC_QRCoderErrorCorrectionLevel;
18class CBC_QRCoderMode;
19class CBC_QRCoderBitVector;
20class CBC_CommonByteArray;
21class CBC_CommonByteMatrix;
22
23class CBC_QRCoderEncoder {
Dan Sinclair1770c022016-03-14 14:14:16 -040024 public:
25 CBC_QRCoderEncoder();
26 virtual ~CBC_QRCoderEncoder();
27
28 static void Encode(const CFX_ByteString& content,
29 CBC_QRCoderErrorCorrectionLevel* ecLevel,
30 CBC_QRCoder* qrCode,
31 int32_t& e,
32 int32_t versionSpecify = 0);
33 static void Encode(const CFX_WideString& content,
34 CBC_QRCoderErrorCorrectionLevel* ecLevel,
35 CBC_QRCoder* qrCode,
36 int32_t& e);
37 static void EncodeWithSpecifyVersion(const CFX_ByteString& content,
38 CBC_QRCoderErrorCorrectionLevel* ecLevel,
39 CBC_QRCoder* qrCode,
40 int32_t versionSpecify,
41 int32_t& e);
42 static void EncodeWithAutoVersion(const CFX_ByteString& content,
43 CBC_QRCoderErrorCorrectionLevel* ecLevel,
44 CBC_QRCoder* qrCode,
45 int32_t& e);
46 static CBC_QRCoderMode* ChooseMode(const CFX_ByteString& content,
47 CFX_ByteString encoding);
48 static int32_t GetAlphaNumericCode(int32_t code);
49 static void AppendECI(CBC_QRCoderBitVector* bits);
50 static void AppendBytes(const CFX_ByteString& content,
51 CBC_QRCoderMode* mode,
52 CBC_QRCoderBitVector* bits,
53 CFX_ByteString encoding,
54 int32_t& e);
55 static void AppendNumericBytes(const CFX_ByteString& content,
56 CBC_QRCoderBitVector* bits,
57 int32_t& e);
58 static void AppendAlphaNumericBytes(const CFX_ByteString& content,
59 CBC_QRCoderBitVector* bits,
60 int32_t& e);
61 static void Append8BitBytes(const CFX_ByteString& content,
62 CBC_QRCoderBitVector* bits,
63 CFX_ByteString encoding,
64 int32_t& e);
Tom Sepez8b6186f2017-03-28 12:06:45 -070065 static void Append8BitBytes(std::vector<uint8_t>& bytes,
Dan Sinclair1770c022016-03-14 14:14:16 -040066 CBC_QRCoderBitVector* bits,
67 int32_t& e);
68 static void AppendKanjiBytes(const CFX_ByteString& content,
69 CBC_QRCoderBitVector* bits,
70 int32_t& e);
71 static void AppendGBKBytes(const CFX_ByteString& content,
72 CBC_QRCoderBitVector* bits,
73 int32_t& e);
74 static void InitQRCode(int32_t numInputBytes,
75 int32_t versionNumber,
76 CBC_QRCoderErrorCorrectionLevel* ecLevel,
77 CBC_QRCoderMode* mode,
78 CBC_QRCoder* qrCode,
79 int32_t& e);
80 static void InitQRCode(int32_t numInputBytes,
81 CBC_QRCoderErrorCorrectionLevel* ecLevel,
82 CBC_QRCoderMode* mode,
83 CBC_QRCoder* qrCode,
84 int32_t& e);
85 static void AppendModeInfo(CBC_QRCoderMode* mode,
86 CBC_QRCoderBitVector* bits,
87 int32_t& e);
88 static void AppendLengthInfo(int32_t numLetters,
89 int32_t version,
90 CBC_QRCoderMode* mode,
91 CBC_QRCoderBitVector* bits,
92 int32_t& e);
93
94 static void InterleaveWithECBytes(CBC_QRCoderBitVector* bits,
95 int32_t numTotalBytes,
96 int32_t numDataBytes,
97 int32_t numRSBlocks,
98 CBC_QRCoderBitVector* result,
99 int32_t& e);
100 static void GetNumDataBytesAndNumECBytesForBlockID(
101 int32_t numTotalBytes,
102 int32_t numDataBytes,
103 int32_t numRSBlocks,
104 int32_t blockID,
105 int32_t& numDataBytesInBlock,
106 int32_t& numECBytesInBlocks);
107 static CBC_CommonByteArray* GenerateECBytes(CBC_CommonByteArray* dataBytes,
108 int32_t numEcBytesInBlock,
109 int32_t& e);
110 static int32_t ChooseMaskPattern(CBC_QRCoderBitVector* bits,
111 CBC_QRCoderErrorCorrectionLevel* ecLevel,
112 int32_t version,
113 CBC_CommonByteMatrix* matrix,
114 int32_t& e);
115 static int32_t CalculateMaskPenalty(CBC_CommonByteMatrix* matrix);
116 static void TerminateBits(int32_t numDataBytes,
117 CBC_QRCoderBitVector* bits,
118 int32_t& e);
119 static int32_t GetSpanByVersion(CBC_QRCoderMode* modeFirst,
120 CBC_QRCoderMode* modeSecond,
121 int32_t versionNum,
122 int32_t& e);
tsepezfff400a2017-01-04 06:34:19 -0800123 static void MergeString(
124 std::vector<std::pair<CBC_QRCoderMode*, CFX_ByteString>>* result,
125 int32_t versionNum,
126 int32_t& e);
127 static void SplitString(
128 const CFX_ByteString& content,
129 std::vector<std::pair<CBC_QRCoderMode*, CFX_ByteString>>* result);
tsepez6020e452016-05-02 13:47:17 -0700130 static void AppendDataModeLenghInfo(
tsepezfff400a2017-01-04 06:34:19 -0800131 const std::vector<std::pair<CBC_QRCoderMode*, CFX_ByteString>>&
132 splitResult,
tsepez6020e452016-05-02 13:47:17 -0700133 CBC_QRCoderBitVector& headerAndDataBits,
134 CBC_QRCoderMode* tempMode,
135 CBC_QRCoder* qrCode,
136 CFX_ByteString& encoding,
137 int32_t& e);
Dan Sinclair1770c022016-03-14 14:14:16 -0400138};
139
140#endif // XFA_FXBARCODE_QRCODE_BC_QRCODERENCODER_H_