OLD | NEW |
---|---|
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 // Original code is licensed as follows: | 6 // Original code is licensed as follows: |
7 /* | 7 /* |
8 * Copyright 2008 ZXing authors | 8 * Copyright 2008 ZXing authors |
9 * | 9 * |
10 * Licensed under the Apache License, Version 2.0 (the "License"); | 10 * Licensed under the Apache License, Version 2.0 (the "License"); |
(...skipping 22 matching lines...) Expand all Loading... | |
33 #include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" | 33 #include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" |
34 #include "xfa/fxbarcode/qrcode/BC_QRCoder.h" | 34 #include "xfa/fxbarcode/qrcode/BC_QRCoder.h" |
35 #include "xfa/fxbarcode/qrcode/BC_QRCoderBitVector.h" | 35 #include "xfa/fxbarcode/qrcode/BC_QRCoderBitVector.h" |
36 #include "xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h" | 36 #include "xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h" |
37 #include "xfa/fxbarcode/qrcode/BC_QRCoderECBlocks.h" | 37 #include "xfa/fxbarcode/qrcode/BC_QRCoderECBlocks.h" |
38 #include "xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.h" | 38 #include "xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.h" |
39 #include "xfa/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h" | 39 #include "xfa/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h" |
40 #include "xfa/fxbarcode/qrcode/BC_QRCoderMode.h" | 40 #include "xfa/fxbarcode/qrcode/BC_QRCoderMode.h" |
41 #include "xfa/fxbarcode/qrcode/BC_QRCoderVersion.h" | 41 #include "xfa/fxbarcode/qrcode/BC_QRCoderVersion.h" |
42 | 42 |
43 const int32_t CBC_QRCoderEncoder::m_alphaNumbericTable[] = { | 43 namespace { |
44 | |
45 const int8_t g_alphaNumericTable[] = { | |
44 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | 46 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
45 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | 47 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
46 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, | 48 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
47 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, | 49 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
48 -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, | 50 -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
49 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1}; | 51 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1}; |
50 | 52 |
53 } // namespace | |
54 | |
51 CBC_QRCoderEncoder::CBC_QRCoderEncoder() {} | 55 CBC_QRCoderEncoder::CBC_QRCoderEncoder() {} |
52 | 56 |
53 CBC_QRCoderEncoder::~CBC_QRCoderEncoder() {} | 57 CBC_QRCoderEncoder::~CBC_QRCoderEncoder() {} |
54 | 58 |
55 class Make_Pair { | |
56 public: | |
57 CBC_QRCoderMode* m_mode; | |
58 CFX_ByteString m_string; | |
59 | |
60 private: | |
61 Make_Pair(const Make_Pair& mode_string) {} | |
62 Make_Pair& operator=(Make_Pair& mode_string) { | |
63 if (this == &mode_string) { | |
64 return *this; | |
65 } | |
66 m_mode = mode_string.m_mode; | |
67 m_string = mode_string.m_string; | |
68 return *this; | |
69 } | |
70 | |
71 public: | |
72 Make_Pair(CBC_QRCoderMode* mode, const CFX_ByteString& str) | |
73 : m_mode(mode), m_string(str) {} | |
74 ~Make_Pair() {} | |
75 }; | |
76 void CBC_QRCoderEncoder::Encode(const CFX_ByteString& content, | 59 void CBC_QRCoderEncoder::Encode(const CFX_ByteString& content, |
77 CBC_QRCoderErrorCorrectionLevel* ecLevel, | 60 CBC_QRCoderErrorCorrectionLevel* ecLevel, |
78 CBC_QRCoder* qrCode, | 61 CBC_QRCoder* qrCode, |
79 int32_t& e, | 62 int32_t& e, |
80 int32_t versionSpecify) { | 63 int32_t versionSpecify) { |
81 if (versionSpecify == 0) { | 64 if (versionSpecify == 0) { |
82 EncodeWithAutoVersion(content, ecLevel, qrCode, e); | 65 EncodeWithAutoVersion(content, ecLevel, qrCode, e); |
83 BC_EXCEPTION_CHECK_ReturnVoid(e) | 66 BC_EXCEPTION_CHECK_ReturnVoid(e) |
84 } else if (versionSpecify > 0 && versionSpecify <= 40) { | 67 } else if (versionSpecify > 0 && versionSpecify <= 40) { |
85 EncodeWithSpecifyVersion(content, ecLevel, qrCode, versionSpecify, e); | 68 EncodeWithSpecifyVersion(content, ecLevel, qrCode, versionSpecify, e); |
86 BC_EXCEPTION_CHECK_ReturnVoid(e); | 69 BC_EXCEPTION_CHECK_ReturnVoid(e); |
87 } else { | 70 } else { |
88 e = BCExceptionVersionMust1_40; | 71 e = BCExceptionVersionMust1_40; |
89 BC_EXCEPTION_CHECK_ReturnVoid(e); | 72 BC_EXCEPTION_CHECK_ReturnVoid(e); |
90 } | 73 } |
91 } | 74 } |
92 | 75 |
93 void CBC_QRCoderEncoder::AppendECI(CBC_QRCoderBitVector* bits) {} | 76 void CBC_QRCoderEncoder::AppendECI(CBC_QRCoderBitVector* bits) {} |
94 | 77 |
95 void CBC_QRCoderEncoder::AppendDataModeLenghInfo( | 78 void CBC_QRCoderEncoder::AppendDataModeLenghInfo( |
96 const CFX_ArrayTemplate<Make_Pair*>& splitResult, | 79 const std::vector<std::pair<CBC_QRCoderMode*, CFX_ByteString>>& |
80 splitResults, | |
97 CBC_QRCoderBitVector& headerAndDataBits, | 81 CBC_QRCoderBitVector& headerAndDataBits, |
98 CBC_QRCoderMode* tempMode, | 82 CBC_QRCoderMode* tempMode, |
99 CBC_QRCoder* qrCode, | 83 CBC_QRCoder* qrCode, |
100 CFX_ByteString& encoding, | 84 CFX_ByteString& encoding, |
101 int32_t& e) { | 85 int32_t& e) { |
102 for (int32_t i = 0; i < splitResult.GetSize(); i++) { | 86 for (const auto& splitResult : splitResults) { |
103 tempMode = splitResult[i]->m_mode; | 87 tempMode = splitResult.first; |
104 if (tempMode == CBC_QRCoderMode::sGBK) { | 88 if (tempMode == CBC_QRCoderMode::sGBK) { |
105 AppendModeInfo(tempMode, &headerAndDataBits, e); | 89 AppendModeInfo(tempMode, &headerAndDataBits, e); |
106 BC_EXCEPTION_CHECK_ReturnVoid(e); | 90 BC_EXCEPTION_CHECK_ReturnVoid(e); |
107 AppendLengthInfo(splitResult[i]->m_string.GetLength(), | 91 AppendLengthInfo(splitResult.second.GetLength(), qrCode->GetVersion(), |
dsinclair
2017/01/02 18:06:17
Is it worth making a tempString = splitResults.sec
Tom Sepez
2017/01/03 22:25:59
Prolly not, the type of splitResults is explicit o
| |
108 qrCode->GetVersion(), tempMode, &headerAndDataBits, e); | 92 tempMode, &headerAndDataBits, e); |
109 BC_EXCEPTION_CHECK_ReturnVoid(e); | 93 BC_EXCEPTION_CHECK_ReturnVoid(e); |
110 AppendBytes(splitResult[i]->m_string, tempMode, &headerAndDataBits, | 94 AppendBytes(splitResult.second, tempMode, &headerAndDataBits, encoding, |
111 encoding, e); | 95 e); |
112 BC_EXCEPTION_CHECK_ReturnVoid(e); | 96 BC_EXCEPTION_CHECK_ReturnVoid(e); |
113 } else if (tempMode == CBC_QRCoderMode::sBYTE) { | 97 } else if (tempMode == CBC_QRCoderMode::sBYTE) { |
114 CFX_ByteArray bytes; | 98 CFX_ByteArray bytes; |
115 CBC_UtilCodingConvert::LocaleToUtf8(splitResult[i]->m_string, bytes); | 99 CBC_UtilCodingConvert::LocaleToUtf8(splitResult.second, bytes); |
116 AppendModeInfo(tempMode, &headerAndDataBits, e); | 100 AppendModeInfo(tempMode, &headerAndDataBits, e); |
117 BC_EXCEPTION_CHECK_ReturnVoid(e); | 101 BC_EXCEPTION_CHECK_ReturnVoid(e); |
118 AppendLengthInfo(bytes.GetSize(), qrCode->GetVersion(), tempMode, | 102 AppendLengthInfo(bytes.GetSize(), qrCode->GetVersion(), tempMode, |
119 &headerAndDataBits, e); | 103 &headerAndDataBits, e); |
120 BC_EXCEPTION_CHECK_ReturnVoid(e); | 104 BC_EXCEPTION_CHECK_ReturnVoid(e); |
121 Append8BitBytes(bytes, &headerAndDataBits, e); | 105 Append8BitBytes(bytes, &headerAndDataBits, e); |
122 BC_EXCEPTION_CHECK_ReturnVoid(e); | 106 BC_EXCEPTION_CHECK_ReturnVoid(e); |
123 } else if (tempMode == CBC_QRCoderMode::sALPHANUMERIC) { | 107 } else if (tempMode == CBC_QRCoderMode::sALPHANUMERIC) { |
124 AppendModeInfo(tempMode, &headerAndDataBits, e); | 108 AppendModeInfo(tempMode, &headerAndDataBits, e); |
125 BC_EXCEPTION_CHECK_ReturnVoid(e); | 109 BC_EXCEPTION_CHECK_ReturnVoid(e); |
126 AppendLengthInfo(splitResult[i]->m_string.GetLength(), | 110 AppendLengthInfo(splitResult.second.GetLength(), qrCode->GetVersion(), |
127 qrCode->GetVersion(), tempMode, &headerAndDataBits, e); | 111 tempMode, &headerAndDataBits, e); |
128 BC_EXCEPTION_CHECK_ReturnVoid(e); | 112 BC_EXCEPTION_CHECK_ReturnVoid(e); |
129 AppendBytes(splitResult[i]->m_string, tempMode, &headerAndDataBits, | 113 AppendBytes(splitResult.second, tempMode, &headerAndDataBits, encoding, |
130 encoding, e); | 114 e); |
131 BC_EXCEPTION_CHECK_ReturnVoid(e); | 115 BC_EXCEPTION_CHECK_ReturnVoid(e); |
132 } else if (tempMode == CBC_QRCoderMode::sNUMERIC) { | 116 } else if (tempMode == CBC_QRCoderMode::sNUMERIC) { |
133 AppendModeInfo(tempMode, &headerAndDataBits, e); | 117 AppendModeInfo(tempMode, &headerAndDataBits, e); |
134 BC_EXCEPTION_CHECK_ReturnVoid(e); | 118 BC_EXCEPTION_CHECK_ReturnVoid(e); |
135 AppendLengthInfo(splitResult[i]->m_string.GetLength(), | 119 AppendLengthInfo(splitResult.second.GetLength(), qrCode->GetVersion(), |
136 qrCode->GetVersion(), tempMode, &headerAndDataBits, e); | 120 tempMode, &headerAndDataBits, e); |
137 BC_EXCEPTION_CHECK_ReturnVoid(e); | 121 BC_EXCEPTION_CHECK_ReturnVoid(e); |
138 AppendBytes(splitResult[i]->m_string, tempMode, &headerAndDataBits, | 122 AppendBytes(splitResult.second, tempMode, &headerAndDataBits, encoding, |
139 encoding, e); | 123 e); |
140 BC_EXCEPTION_CHECK_ReturnVoid(e); | 124 BC_EXCEPTION_CHECK_ReturnVoid(e); |
141 } else { | 125 } else { |
142 e = BCExceptionUnknown; | 126 e = BCExceptionUnknown; |
143 BC_EXCEPTION_CHECK_ReturnVoid(e); | 127 BC_EXCEPTION_CHECK_ReturnVoid(e); |
144 } | 128 } |
145 } | 129 } |
146 } | 130 } |
147 | 131 |
148 void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content, | 132 void CBC_QRCoderEncoder::SplitString( |
149 CFX_ArrayTemplate<Make_Pair*>* result) { | 133 const CFX_ByteString& content, |
134 std::vector<std::pair<CBC_QRCoderMode*, CFX_ByteString>>* result) { | |
150 int32_t index = 0, flag = 0; | 135 int32_t index = 0, flag = 0; |
151 while ( | 136 while ( |
152 (((uint8_t)content[index] >= 0xA1 && (uint8_t)content[index] <= 0xAA) || | 137 (((uint8_t)content[index] >= 0xA1 && (uint8_t)content[index] <= 0xAA) || |
153 ((uint8_t)content[index] >= 0xB0 && (uint8_t)content[index] <= 0xFA)) && | 138 ((uint8_t)content[index] >= 0xB0 && (uint8_t)content[index] <= 0xFA)) && |
154 (index < content.GetLength())) { | 139 (index < content.GetLength())) { |
155 index += 2; | 140 index += 2; |
156 } | 141 } |
157 if (index != flag) { | 142 if (index != flag) { |
158 result->Add( | 143 result->push_back({CBC_QRCoderMode::sGBK, content.Mid(flag, index - flag)}); |
159 new Make_Pair(CBC_QRCoderMode::sGBK, content.Mid(flag, index - flag))); | |
160 } | 144 } |
161 flag = index; | 145 flag = index; |
162 if (index >= content.GetLength()) { | 146 if (index >= content.GetLength()) { |
163 return; | 147 return; |
164 } | 148 } |
165 while ( | 149 while ( |
166 GetAlphaNumericCode((uint8_t)content[index]) == -1 && | 150 GetAlphaNumericCode((uint8_t)content[index]) == -1 && |
167 !(((uint8_t)content[index] >= 0xA1 && (uint8_t)content[index] <= 0xAA) || | 151 !(((uint8_t)content[index] >= 0xA1 && (uint8_t)content[index] <= 0xAA) || |
168 ((uint8_t)content[index] >= 0xB0 && (uint8_t)content[index] <= 0xFA)) && | 152 ((uint8_t)content[index] >= 0xB0 && (uint8_t)content[index] <= 0xFA)) && |
169 (index < content.GetLength())) { | 153 (index < content.GetLength())) { |
170 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 154 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
171 if (IsDBCSLeadByte((uint8_t)content[index])) | 155 if (IsDBCSLeadByte((uint8_t)content[index])) |
172 #else | 156 #else |
173 if ((uint8_t)content[index] > 127) | 157 if ((uint8_t)content[index] > 127) |
174 #endif | 158 #endif |
175 { | 159 { |
176 index += 2; | 160 index += 2; |
177 } else { | 161 } else { |
178 index++; | 162 index++; |
179 } | 163 } |
180 } | 164 } |
181 if (index != flag) { | 165 if (index != flag) { |
182 result->Add( | 166 result->push_back( |
183 new Make_Pair(CBC_QRCoderMode::sBYTE, content.Mid(flag, index - flag))); | 167 {CBC_QRCoderMode::sBYTE, content.Mid(flag, index - flag)}); |
184 } | 168 } |
185 flag = index; | 169 flag = index; |
186 if (index >= content.GetLength()) { | 170 if (index >= content.GetLength()) { |
187 return; | 171 return; |
188 } | 172 } |
189 while (FXSYS_Isdigit((uint8_t)content[index]) && | 173 while (FXSYS_Isdigit((uint8_t)content[index]) && |
190 (index < content.GetLength())) { | 174 (index < content.GetLength())) { |
191 index++; | 175 index++; |
192 } | 176 } |
193 if (index != flag) { | 177 if (index != flag) { |
194 result->Add(new Make_Pair(CBC_QRCoderMode::sNUMERIC, | 178 result->push_back( |
195 content.Mid(flag, index - flag))); | 179 {CBC_QRCoderMode::sNUMERIC, content.Mid(flag, index - flag)}); |
196 } | 180 } |
197 flag = index; | 181 flag = index; |
198 if (index >= content.GetLength()) { | 182 if (index >= content.GetLength()) { |
199 return; | 183 return; |
200 } | 184 } |
201 while (GetAlphaNumericCode((uint8_t)content[index]) != -1 && | 185 while (GetAlphaNumericCode((uint8_t)content[index]) != -1 && |
202 (index < content.GetLength())) { | 186 (index < content.GetLength())) { |
203 index++; | 187 index++; |
204 } | 188 } |
205 if (index != flag) { | 189 if (index != flag) { |
206 result->Add(new Make_Pair(CBC_QRCoderMode::sALPHANUMERIC, | 190 result->push_back( |
207 content.Mid(flag, index - flag))); | 191 {CBC_QRCoderMode::sALPHANUMERIC, content.Mid(flag, index - flag)}); |
208 } | 192 } |
209 flag = index; | 193 flag = index; |
210 if (index < content.GetLength()) | 194 if (index < content.GetLength()) |
211 SplitString(content.Mid(index, content.GetLength() - index), result); | 195 SplitString(content.Mid(index, content.GetLength() - index), result); |
212 } | 196 } |
213 | 197 |
214 int32_t CBC_QRCoderEncoder::GetSpanByVersion(CBC_QRCoderMode* modeFirst, | 198 int32_t CBC_QRCoderEncoder::GetSpanByVersion(CBC_QRCoderMode* modeFirst, |
215 CBC_QRCoderMode* modeSecond, | 199 CBC_QRCoderMode* modeSecond, |
216 int32_t versionNum, | 200 int32_t versionNum, |
217 int32_t& e) { | 201 int32_t& e) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 } else if (versionNum >= 27 && versionNum <= 40) { | 235 } else if (versionNum >= 27 && versionNum <= 40) { |
252 return 9; | 236 return 9; |
253 } else { | 237 } else { |
254 e = BCExceptionNoSuchVersion; | 238 e = BCExceptionNoSuchVersion; |
255 BC_EXCEPTION_CHECK_ReturnValue(e, 0); | 239 BC_EXCEPTION_CHECK_ReturnValue(e, 0); |
256 } | 240 } |
257 } | 241 } |
258 return -1; | 242 return -1; |
259 } | 243 } |
260 | 244 |
261 void CBC_QRCoderEncoder::MergeString(CFX_ArrayTemplate<Make_Pair*>* result, | 245 void CBC_QRCoderEncoder::MergeString( |
262 int32_t versionNum, | 246 std::vector<std::pair<CBC_QRCoderMode*, CFX_ByteString>>* result, |
263 int32_t& e) { | 247 int32_t versionNum, |
264 Make_Pair* first = nullptr; | 248 int32_t& e) { |
265 Make_Pair* second = nullptr; | |
266 size_t mergeNum = 0; | 249 size_t mergeNum = 0; |
267 int32_t i; | 250 for (size_t i = 0; i + 1 < result->size(); i++) { |
268 for (i = 0; ((i < result->GetSize()) && (i + 1 < result->GetSize())); i++) { | 251 auto element1 = &(*result)[i]; |
269 first = (*result)[i]; | 252 auto element2 = &(*result)[i + 1]; |
270 second = (*result)[i + 1]; | 253 if (element1->first == CBC_QRCoderMode::sALPHANUMERIC) { |
271 if (first->m_mode == CBC_QRCoderMode::sALPHANUMERIC) { | |
272 int32_t tmp = GetSpanByVersion(CBC_QRCoderMode::sALPHANUMERIC, | 254 int32_t tmp = GetSpanByVersion(CBC_QRCoderMode::sALPHANUMERIC, |
273 CBC_QRCoderMode::sBYTE, versionNum, e); | 255 CBC_QRCoderMode::sBYTE, versionNum, e); |
274 BC_EXCEPTION_CHECK_ReturnVoid(e); | 256 BC_EXCEPTION_CHECK_ReturnVoid(e); |
275 if ((second->m_mode == CBC_QRCoderMode::sBYTE) && | 257 if (element2->first == CBC_QRCoderMode::sBYTE && |
276 (first->m_string.GetLength() < tmp)) { | 258 element1->second.GetLength() < tmp) { |
277 CFX_ByteString str = first->m_string + second->m_string; | 259 element2->second = element1->second + element2->second; |
278 second->m_string = str; | 260 result->erase(result->begin() + i); |
279 delete first; | |
280 result->RemoveAt(i); | |
281 i--; | 261 i--; |
282 mergeNum++; | 262 mergeNum++; |
283 } | 263 } |
284 } else if (first->m_mode == CBC_QRCoderMode::sBYTE) { | 264 } else if (element1->first == CBC_QRCoderMode::sBYTE) { |
285 if (second->m_mode == CBC_QRCoderMode::sBYTE) { | 265 if (element2->first == CBC_QRCoderMode::sBYTE) { |
286 first->m_string += second->m_string; | 266 element1->second += element2->second; |
287 delete second; | 267 result->erase(result->begin() + i + 1); |
288 result->RemoveAt(i + 1); | |
289 i--; | 268 i--; |
290 mergeNum++; | 269 mergeNum++; |
291 } | 270 } |
292 } else if (first->m_mode == CBC_QRCoderMode::sNUMERIC) { | 271 } else if (element1->first == CBC_QRCoderMode::sNUMERIC) { |
293 int32_t tmp = GetSpanByVersion(CBC_QRCoderMode::sNUMERIC, | 272 int32_t tmp = GetSpanByVersion(CBC_QRCoderMode::sNUMERIC, |
294 CBC_QRCoderMode::sBYTE, versionNum, e); | 273 CBC_QRCoderMode::sBYTE, versionNum, e); |
295 BC_EXCEPTION_CHECK_ReturnVoid(e); | 274 BC_EXCEPTION_CHECK_ReturnVoid(e); |
296 if ((second->m_mode == CBC_QRCoderMode::sBYTE) && | 275 if (element2->first == CBC_QRCoderMode::sBYTE && |
297 (first->m_string.GetLength() < tmp)) { | 276 element1->second.GetLength() < tmp) { |
298 CFX_ByteString str = first->m_string + second->m_string; | 277 element2->second = element1->second + element2->second; |
299 second->m_string = str; | 278 result->erase(result->begin() + i); |
300 delete first; | |
301 result->RemoveAt(i); | |
302 i--; | 279 i--; |
303 mergeNum++; | 280 mergeNum++; |
304 } | 281 } |
305 tmp = GetSpanByVersion(CBC_QRCoderMode::sNUMERIC, | 282 tmp = GetSpanByVersion(CBC_QRCoderMode::sNUMERIC, |
306 CBC_QRCoderMode::sALPHANUMERIC, versionNum, e); | 283 CBC_QRCoderMode::sALPHANUMERIC, versionNum, e); |
307 BC_EXCEPTION_CHECK_ReturnVoid(e); | 284 BC_EXCEPTION_CHECK_ReturnVoid(e); |
308 if ((second->m_mode == CBC_QRCoderMode::sALPHANUMERIC) && | 285 if (element2->first == CBC_QRCoderMode::sALPHANUMERIC && |
309 (first->m_string.GetLength() < tmp)) { | 286 element1->second.GetLength() < tmp) { |
310 CFX_ByteString str = first->m_string + second->m_string; | 287 element2->second = element1->second + element2->second; |
311 second->m_string = str; | 288 result->erase(result->begin() + i); |
312 delete first; | |
313 result->RemoveAt(i); | |
314 i--; | 289 i--; |
315 mergeNum++; | 290 mergeNum++; |
316 } | 291 } |
317 } | 292 } |
318 } | 293 } |
319 if (mergeNum == 0) { | 294 if (mergeNum == 0) { |
320 return; | 295 return; |
321 } | 296 } |
322 MergeString(result, versionNum, e); | 297 MergeString(result, versionNum, e); |
323 BC_EXCEPTION_CHECK_ReturnVoid(e); | 298 BC_EXCEPTION_CHECK_ReturnVoid(e); |
(...skipping 29 matching lines...) Expand all Loading... | |
353 } | 328 } |
354 | 329 |
355 void CBC_QRCoderEncoder::EncodeWithSpecifyVersion( | 330 void CBC_QRCoderEncoder::EncodeWithSpecifyVersion( |
356 const CFX_ByteString& content, | 331 const CFX_ByteString& content, |
357 CBC_QRCoderErrorCorrectionLevel* ecLevel, | 332 CBC_QRCoderErrorCorrectionLevel* ecLevel, |
358 CBC_QRCoder* qrCode, | 333 CBC_QRCoder* qrCode, |
359 int32_t versionSpecify, | 334 int32_t versionSpecify, |
360 int32_t& e) { | 335 int32_t& e) { |
361 CFX_ByteString encoding = "utf8"; | 336 CFX_ByteString encoding = "utf8"; |
362 CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; | 337 CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; |
363 CFX_ArrayTemplate<Make_Pair*> splitResult; | 338 std::vector<std::pair<CBC_QRCoderMode*, CFX_ByteString>> splitResult; |
364 CBC_QRCoderBitVector dataBits; | 339 CBC_QRCoderBitVector dataBits; |
365 dataBits.Init(); | 340 dataBits.Init(); |
366 SplitString(content, &splitResult); | 341 SplitString(content, &splitResult); |
367 MergeString(&splitResult, versionSpecify, e); | 342 MergeString(&splitResult, versionSpecify, e); |
368 BC_EXCEPTION_CHECK_ReturnVoid(e) CBC_QRCoderMode* tempMode = nullptr; | 343 BC_EXCEPTION_CHECK_ReturnVoid(e) CBC_QRCoderMode* tempMode = nullptr; |
369 for (int32_t i = 0; i < splitResult.GetSize(); i++) { | 344 for (const auto& result : splitResult) { |
370 AppendBytes(splitResult[i]->m_string, splitResult[i]->m_mode, &dataBits, | 345 AppendBytes(result.second, result.first, &dataBits, encoding, e); |
371 encoding, e); | 346 if (e != BCExceptionNO) |
372 if (e != BCExceptionNO) { | |
373 for (int32_t y = 0; y < splitResult.GetSize(); y++) | |
374 delete splitResult[y]; | |
375 return; | 347 return; |
376 } | |
377 } | 348 } |
378 int32_t numInputBytes = dataBits.sizeInBytes(); | 349 int32_t numInputBytes = dataBits.sizeInBytes(); |
379 CBC_QRCoderBitVector headerAndDataBits; | 350 CBC_QRCoderBitVector headerAndDataBits; |
380 headerAndDataBits.Init(); | 351 headerAndDataBits.Init(); |
381 InitQRCode(numInputBytes, versionSpecify, ecLevel, mode, qrCode, e); | 352 InitQRCode(numInputBytes, versionSpecify, ecLevel, mode, qrCode, e); |
382 if (e != BCExceptionNO) { | |
383 for (int32_t k = 0; k < splitResult.GetSize(); k++) | |
384 delete splitResult[k]; | |
385 return; | |
386 } | |
387 AppendDataModeLenghInfo(splitResult, headerAndDataBits, tempMode, qrCode, | |
388 encoding, e); | |
389 if (e != BCExceptionNO) { | |
390 for (int32_t k = 0; k < splitResult.GetSize(); k++) | |
391 delete splitResult[k]; | |
392 return; | |
393 } | |
394 numInputBytes = headerAndDataBits.sizeInBytes(); | |
395 TerminateBits(qrCode->GetNumDataBytes(), &headerAndDataBits, e); | |
396 for (int32_t j = 0; j < splitResult.GetSize(); j++) { | |
397 delete splitResult[j]; | |
398 } | |
399 if (e != BCExceptionNO) | 353 if (e != BCExceptionNO) |
400 return; | 354 return; |
401 | 355 |
356 AppendDataModeLenghInfo(splitResult, headerAndDataBits, tempMode, qrCode, | |
357 encoding, e); | |
358 if (e != BCExceptionNO) | |
359 return; | |
360 | |
361 numInputBytes = headerAndDataBits.sizeInBytes(); | |
362 TerminateBits(qrCode->GetNumDataBytes(), &headerAndDataBits, e); | |
363 if (e != BCExceptionNO) | |
364 return; | |
365 | |
402 CBC_QRCoderBitVector finalBits; | 366 CBC_QRCoderBitVector finalBits; |
403 finalBits.Init(); | 367 finalBits.Init(); |
404 InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), | 368 InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), |
405 qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(), | 369 qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(), |
406 &finalBits, e); | 370 &finalBits, e); |
407 BC_EXCEPTION_CHECK_ReturnVoid(e); | 371 BC_EXCEPTION_CHECK_ReturnVoid(e); |
408 std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix( | 372 std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix( |
409 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); | 373 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); |
410 matrix->Init(); | 374 matrix->Init(); |
411 int32_t maskPattern = ChooseMaskPattern( | 375 int32_t maskPattern = ChooseMaskPattern( |
(...skipping 11 matching lines...) Expand all Loading... | |
423 } | 387 } |
424 } | 388 } |
425 | 389 |
426 void CBC_QRCoderEncoder::EncodeWithAutoVersion( | 390 void CBC_QRCoderEncoder::EncodeWithAutoVersion( |
427 const CFX_ByteString& content, | 391 const CFX_ByteString& content, |
428 CBC_QRCoderErrorCorrectionLevel* ecLevel, | 392 CBC_QRCoderErrorCorrectionLevel* ecLevel, |
429 CBC_QRCoder* qrCode, | 393 CBC_QRCoder* qrCode, |
430 int32_t& e) { | 394 int32_t& e) { |
431 CFX_ByteString encoding = "utf8"; | 395 CFX_ByteString encoding = "utf8"; |
432 CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; | 396 CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; |
433 CFX_ArrayTemplate<Make_Pair*> splitResult; | 397 std::vector<std::pair<CBC_QRCoderMode*, CFX_ByteString>> splitResult; |
434 CBC_QRCoderBitVector dataBits; | 398 CBC_QRCoderBitVector dataBits; |
435 dataBits.Init(); | 399 dataBits.Init(); |
436 SplitString(content, &splitResult); | 400 SplitString(content, &splitResult); |
437 MergeString(&splitResult, 8, e); | 401 MergeString(&splitResult, 8, e); |
438 BC_EXCEPTION_CHECK_ReturnVoid(e); | 402 BC_EXCEPTION_CHECK_ReturnVoid(e); |
439 CBC_QRCoderMode* tempMode = nullptr; | 403 CBC_QRCoderMode* tempMode = nullptr; |
440 for (int32_t i = 0; i < splitResult.GetSize(); i++) { | 404 for (const auto& result : splitResult) { |
441 AppendBytes(splitResult[i]->m_string, splitResult[i]->m_mode, &dataBits, | 405 AppendBytes(result.second, result.first, &dataBits, encoding, e); |
442 encoding, e); | 406 if (e != BCExceptionNO) |
443 if (e != BCExceptionNO) { | |
444 for (int32_t l = 0; l < splitResult.GetSize(); l++) | |
445 delete splitResult[l]; | |
446 return; | 407 return; |
447 } | |
448 } | 408 } |
449 int32_t numInputBytes = dataBits.sizeInBytes(); | 409 int32_t numInputBytes = dataBits.sizeInBytes(); |
450 InitQRCode(numInputBytes, ecLevel, mode, qrCode, e); | 410 InitQRCode(numInputBytes, ecLevel, mode, qrCode, e); |
451 BC_EXCEPTION_CHECK_ReturnVoid(e) CBC_QRCoderBitVector headerAndDataBits; | 411 BC_EXCEPTION_CHECK_ReturnVoid(e) CBC_QRCoderBitVector headerAndDataBits; |
452 headerAndDataBits.Init(); | 412 headerAndDataBits.Init(); |
453 tempMode = nullptr; | 413 tempMode = nullptr; |
454 int32_t versionNum = qrCode->GetVersion(); | 414 int32_t versionNum = qrCode->GetVersion(); |
455 sign: | 415 sign: |
456 AppendDataModeLenghInfo(splitResult, headerAndDataBits, tempMode, qrCode, | 416 AppendDataModeLenghInfo(splitResult, headerAndDataBits, tempMode, qrCode, |
457 encoding, e); | 417 encoding, e); |
(...skipping 12 matching lines...) Expand all Loading... | |
470 if (e1 != BCExceptionNO) { | 430 if (e1 != BCExceptionNO) { |
471 e = e1; | 431 e = e1; |
472 return; | 432 return; |
473 } | 433 } |
474 versionNum++; | 434 versionNum++; |
475 if (versionNum <= 40) { | 435 if (versionNum <= 40) { |
476 headerAndDataBits.Clear(); | 436 headerAndDataBits.Clear(); |
477 e = BCExceptionNO; | 437 e = BCExceptionNO; |
478 goto sign; | 438 goto sign; |
479 } else { | 439 } else { |
480 for (int32_t j = 0; j < splitResult.GetSize(); j++) | |
481 delete splitResult[j]; | |
482 return; | 440 return; |
483 } | 441 } |
484 } | 442 } |
485 for (int32_t k = 0; k < splitResult.GetSize(); k++) | |
486 delete splitResult[k]; | |
487 | 443 |
488 CBC_QRCoderBitVector finalBits; | 444 CBC_QRCoderBitVector finalBits; |
489 finalBits.Init(); | 445 finalBits.Init(); |
490 InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), | 446 InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), |
491 qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(), | 447 qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(), |
492 &finalBits, e); | 448 &finalBits, e); |
493 BC_EXCEPTION_CHECK_ReturnVoid(e); | 449 BC_EXCEPTION_CHECK_ReturnVoid(e); |
494 std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix( | 450 std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix( |
495 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); | 451 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); |
496 matrix->Init(); | 452 matrix->Init(); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
648 } | 604 } |
649 if (hasAlphaNumeric) { | 605 if (hasAlphaNumeric) { |
650 return CBC_QRCoderMode::sALPHANUMERIC; | 606 return CBC_QRCoderMode::sALPHANUMERIC; |
651 } else if (hasNumeric) { | 607 } else if (hasNumeric) { |
652 return CBC_QRCoderMode::sNUMERIC; | 608 return CBC_QRCoderMode::sNUMERIC; |
653 } | 609 } |
654 return CBC_QRCoderMode::sBYTE; | 610 return CBC_QRCoderMode::sBYTE; |
655 } | 611 } |
656 | 612 |
657 int32_t CBC_QRCoderEncoder::GetAlphaNumericCode(int32_t code) { | 613 int32_t CBC_QRCoderEncoder::GetAlphaNumericCode(int32_t code) { |
658 if (code < 96 && code >= 0) { | 614 return (code >= 0 && code < 96) ? g_alphaNumericTable[code] : -1; |
659 return m_alphaNumbericTable[code]; | |
660 } | |
661 return -1; | |
662 } | 615 } |
663 | 616 |
664 void CBC_QRCoderEncoder::AppendBytes(const CFX_ByteString& content, | 617 void CBC_QRCoderEncoder::AppendBytes(const CFX_ByteString& content, |
665 CBC_QRCoderMode* mode, | 618 CBC_QRCoderMode* mode, |
666 CBC_QRCoderBitVector* bits, | 619 CBC_QRCoderBitVector* bits, |
667 CFX_ByteString encoding, | 620 CFX_ByteString encoding, |
668 int32_t& e) { | 621 int32_t& e) { |
669 if (mode == CBC_QRCoderMode::sNUMERIC) { | 622 if (mode == CBC_QRCoderMode::sNUMERIC) { |
670 AppendNumericBytes(content, bits, e); | 623 AppendNumericBytes(content, bits, e); |
671 BC_EXCEPTION_CHECK_ReturnVoid(e); | 624 BC_EXCEPTION_CHECK_ReturnVoid(e); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
962 CBC_ReedSolomonEncoder encode(CBC_ReedSolomonGF256::QRCodeField); | 915 CBC_ReedSolomonEncoder encode(CBC_ReedSolomonGF256::QRCodeField); |
963 encode.Init(); | 916 encode.Init(); |
964 encode.Encode(&toEncode, numEcBytesInBlock, e); | 917 encode.Encode(&toEncode, numEcBytesInBlock, e); |
965 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); | 918 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
966 CBC_CommonByteArray* ecBytes = new CBC_CommonByteArray(numEcBytesInBlock); | 919 CBC_CommonByteArray* ecBytes = new CBC_CommonByteArray(numEcBytesInBlock); |
967 for (int32_t j = 0; j < numEcBytesInBlock; j++) { | 920 for (int32_t j = 0; j < numEcBytesInBlock; j++) { |
968 ecBytes->Set(j, toEncode[numDataBytes + j]); | 921 ecBytes->Set(j, toEncode[numDataBytes + j]); |
969 } | 922 } |
970 return ecBytes; | 923 return ecBytes; |
971 } | 924 } |
OLD | NEW |