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 2007 ZXing authors | 8 * Copyright 2007 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"); |
11 * you may not use this file except in compliance with the License. | 11 * you may not use this file except in compliance with the License. |
12 * You may obtain a copy of the License at | 12 * You may obtain a copy of the License at |
13 * | 13 * |
14 * http://www.apache.org/licenses/LICENSE-2.0 | 14 * http://www.apache.org/licenses/LICENSE-2.0 |
15 * | 15 * |
16 * Unless required by applicable law or agreed to in writing, software | 16 * Unless required by applicable law or agreed to in writing, software |
17 * distributed under the License is distributed on an "AS IS" BASIS, | 17 * distributed under the License is distributed on an "AS IS" BASIS, |
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
19 * See the License for the specific language governing permissions and | 19 * See the License for the specific language governing permissions and |
20 * limitations under the License. | 20 * limitations under the License. |
21 */ | 21 */ |
22 | 22 |
23 #include "xfa/fxbarcode/qrcode/BC_QRCoderMode.h" | 23 #include "xfa/fxbarcode/qrcode/BC_QRCoderMode.h" |
| 24 |
| 25 #include <utility> |
| 26 |
24 #include "xfa/fxbarcode/qrcode/BC_QRCoderVersion.h" | 27 #include "xfa/fxbarcode/qrcode/BC_QRCoderVersion.h" |
25 #include "xfa/fxbarcode/utils.h" | 28 #include "xfa/fxbarcode/utils.h" |
26 | 29 |
27 CBC_QRCoderMode* CBC_QRCoderMode::sBYTE = nullptr; | 30 CBC_QRCoderMode* CBC_QRCoderMode::sBYTE = nullptr; |
28 CBC_QRCoderMode* CBC_QRCoderMode::sNUMERIC = nullptr; | 31 CBC_QRCoderMode* CBC_QRCoderMode::sNUMERIC = nullptr; |
29 CBC_QRCoderMode* CBC_QRCoderMode::sALPHANUMERIC = nullptr; | 32 CBC_QRCoderMode* CBC_QRCoderMode::sALPHANUMERIC = nullptr; |
30 CBC_QRCoderMode* CBC_QRCoderMode::sKANJI = nullptr; | 33 CBC_QRCoderMode* CBC_QRCoderMode::sKANJI = nullptr; |
31 CBC_QRCoderMode* CBC_QRCoderMode::sECI = nullptr; | 34 CBC_QRCoderMode* CBC_QRCoderMode::sECI = nullptr; |
32 CBC_QRCoderMode* CBC_QRCoderMode::sGBK = nullptr; | 35 CBC_QRCoderMode* CBC_QRCoderMode::sGBK = nullptr; |
33 CBC_QRCoderMode* CBC_QRCoderMode::sTERMINATOR = nullptr; | 36 CBC_QRCoderMode* CBC_QRCoderMode::sTERMINATOR = nullptr; |
34 CBC_QRCoderMode* CBC_QRCoderMode::sFNC1_FIRST_POSITION = nullptr; | 37 CBC_QRCoderMode* CBC_QRCoderMode::sFNC1_FIRST_POSITION = nullptr; |
35 CBC_QRCoderMode* CBC_QRCoderMode::sFNC1_SECOND_POSITION = nullptr; | 38 CBC_QRCoderMode* CBC_QRCoderMode::sFNC1_SECOND_POSITION = nullptr; |
36 CBC_QRCoderMode* CBC_QRCoderMode::sSTRUCTURED_APPEND = nullptr; | 39 CBC_QRCoderMode* CBC_QRCoderMode::sSTRUCTURED_APPEND = nullptr; |
37 | 40 |
38 CBC_QRCoderMode::CBC_QRCoderMode(int32_t* characterCountBitsForVersions, | 41 CBC_QRCoderMode::CBC_QRCoderMode(std::vector<int32_t> charCountBits, |
39 int32_t x1, | |
40 int32_t x2, | |
41 int32_t x3, | |
42 int32_t bits, | 42 int32_t bits, |
43 CFX_ByteString name) { | 43 CFX_ByteString name) |
44 m_characterCountBitsForVersions = characterCountBitsForVersions; | 44 : m_characterCountBitsForVersions(std::move(charCountBits)), |
45 if (m_characterCountBitsForVersions) { | 45 m_bits(bits), |
46 m_characterCountBitsForVersions[0] = x1; | 46 m_name(name) {} |
47 m_characterCountBitsForVersions[1] = x2; | 47 |
48 m_characterCountBitsForVersions[2] = x3; | 48 CBC_QRCoderMode::~CBC_QRCoderMode() {} |
49 } | 49 |
50 m_name += name; | 50 void CBC_QRCoderMode::Initialize() { |
51 m_bits = bits; | 51 sBYTE = new CBC_QRCoderMode({8, 16, 16}, 0x4, "BYTE"); |
| 52 sALPHANUMERIC = new CBC_QRCoderMode({9, 11, 13}, 0x2, "ALPHANUMERIC"); |
| 53 sECI = new CBC_QRCoderMode(std::vector<int32_t>(), 0x7, "ECI"); |
| 54 sKANJI = new CBC_QRCoderMode({8, 10, 12}, 0x8, "KANJI"); |
| 55 sNUMERIC = new CBC_QRCoderMode({10, 12, 14}, 0x1, "NUMERIC"); |
| 56 sGBK = new CBC_QRCoderMode({8, 10, 12}, 0x0D, "GBK"); |
| 57 sTERMINATOR = new CBC_QRCoderMode(std::vector<int32_t>(), 0x00, "TERMINATOR"); |
| 58 sFNC1_FIRST_POSITION = |
| 59 new CBC_QRCoderMode(std::vector<int32_t>(), 0x05, "FNC1_FIRST_POSITION"); |
| 60 sFNC1_SECOND_POSITION = |
| 61 new CBC_QRCoderMode(std::vector<int32_t>(), 0x09, "FNC1_SECOND_POSITION"); |
| 62 sSTRUCTURED_APPEND = |
| 63 new CBC_QRCoderMode(std::vector<int32_t>(), 0x03, "STRUCTURED_APPEND"); |
52 } | 64 } |
53 CBC_QRCoderMode::~CBC_QRCoderMode() { | 65 |
54 FX_Free(m_characterCountBitsForVersions); | |
55 } | |
56 void CBC_QRCoderMode::Initialize() { | |
57 sBYTE = new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 8, 16, 16, 0x4, "BYTE"); | |
58 sALPHANUMERIC = | |
59 new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 9, 11, 13, 0x2, "ALPHANUMERIC"); | |
60 sECI = new CBC_QRCoderMode(nullptr, 0, 0, 0, 0x7, "ECI"); | |
61 sKANJI = new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 8, 10, 12, 0x8, "KANJI"); | |
62 sNUMERIC = | |
63 new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 10, 12, 14, 0x1, "NUMERIC"); | |
64 sGBK = new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 8, 10, 12, 0x0D, "GBK"); | |
65 sTERMINATOR = | |
66 new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 0, 0, 0, 0x00, "TERMINATOR"); | |
67 sFNC1_FIRST_POSITION = | |
68 new CBC_QRCoderMode(nullptr, 0, 0, 0, 0x05, "FNC1_FIRST_POSITION"); | |
69 sFNC1_SECOND_POSITION = | |
70 new CBC_QRCoderMode(nullptr, 0, 0, 0, 0x09, "FNC1_SECOND_POSITION"); | |
71 sSTRUCTURED_APPEND = new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 0, 0, 0, 0x03, | |
72 "STRUCTURED_APPEND"); | |
73 } | |
74 void CBC_QRCoderMode::Finalize() { | 66 void CBC_QRCoderMode::Finalize() { |
75 delete sBYTE; | 67 delete sBYTE; |
76 delete sALPHANUMERIC; | 68 delete sALPHANUMERIC; |
77 delete sECI; | 69 delete sECI; |
78 delete sKANJI; | 70 delete sKANJI; |
79 delete sNUMERIC; | 71 delete sNUMERIC; |
80 delete sGBK; | 72 delete sGBK; |
81 delete sTERMINATOR; | 73 delete sTERMINATOR; |
82 delete sFNC1_FIRST_POSITION; | 74 delete sFNC1_FIRST_POSITION; |
83 delete sFNC1_SECOND_POSITION; | 75 delete sFNC1_SECOND_POSITION; |
84 delete sSTRUCTURED_APPEND; | 76 delete sSTRUCTURED_APPEND; |
85 } | 77 } |
| 78 |
86 CBC_QRCoderMode* CBC_QRCoderMode::ForBits(int32_t bits, int32_t& e) { | 79 CBC_QRCoderMode* CBC_QRCoderMode::ForBits(int32_t bits, int32_t& e) { |
87 switch (bits) { | 80 switch (bits) { |
88 case 0x0: | 81 case 0x0: |
89 return sTERMINATOR; | 82 return sTERMINATOR; |
90 case 0x1: | 83 case 0x1: |
91 return sNUMERIC; | 84 return sNUMERIC; |
92 case 0x2: | 85 case 0x2: |
93 return sALPHANUMERIC; | 86 return sALPHANUMERIC; |
94 case 0x3: | 87 case 0x3: |
95 return sSTRUCTURED_APPEND; | 88 return sSTRUCTURED_APPEND; |
96 case 0x4: | 89 case 0x4: |
97 return sBYTE; | 90 return sBYTE; |
98 case 0x5: | 91 case 0x5: |
99 return sFNC1_FIRST_POSITION; | 92 return sFNC1_FIRST_POSITION; |
100 case 0x7: | 93 case 0x7: |
101 return sECI; | 94 return sECI; |
102 case 0x8: | 95 case 0x8: |
103 return sKANJI; | 96 return sKANJI; |
104 case 0x9: | 97 case 0x9: |
105 return sFNC1_SECOND_POSITION; | 98 return sFNC1_SECOND_POSITION; |
106 case 0x0D: | 99 case 0x0D: |
107 return sGBK; | 100 return sGBK; |
108 default: { | 101 default: { |
109 e = BCExceptionUnsupportedMode; | 102 e = BCExceptionUnsupportedMode; |
110 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); | 103 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
111 } | 104 } |
112 } | 105 } |
113 return nullptr; | 106 return nullptr; |
114 } | 107 } |
115 int32_t CBC_QRCoderMode::GetBits() { | 108 |
| 109 int32_t CBC_QRCoderMode::GetBits() const { |
116 return m_bits; | 110 return m_bits; |
117 } | 111 } |
118 CFX_ByteString CBC_QRCoderMode::GetName() { | 112 |
| 113 CFX_ByteString CBC_QRCoderMode::GetName() const { |
119 return m_name; | 114 return m_name; |
120 } | 115 } |
| 116 |
121 int32_t CBC_QRCoderMode::GetCharacterCountBits(CBC_QRCoderVersion* version, | 117 int32_t CBC_QRCoderMode::GetCharacterCountBits(CBC_QRCoderVersion* version, |
122 int32_t& e) { | 118 int32_t& e) const { |
123 if (!m_characterCountBitsForVersions) { | 119 if (m_characterCountBitsForVersions.empty()) { |
124 e = BCExceptionCharacterNotThisMode; | 120 e = BCExceptionCharacterNotThisMode; |
125 BC_EXCEPTION_CHECK_ReturnValue(e, 0); | 121 BC_EXCEPTION_CHECK_ReturnValue(e, 0); |
126 } | 122 } |
127 int32_t number = version->GetVersionNumber(); | 123 int32_t number = version->GetVersionNumber(); |
128 int32_t offset; | 124 int32_t offset; |
129 if (number <= 9) { | 125 if (number <= 9) { |
130 offset = 0; | 126 offset = 0; |
131 } else if (number <= 26) { | 127 } else if (number <= 26) { |
132 offset = 1; | 128 offset = 1; |
133 } else { | 129 } else { |
134 offset = 2; | 130 offset = 2; |
135 } | 131 } |
136 return m_characterCountBitsForVersions[offset]; | 132 return m_characterCountBitsForVersions[offset]; |
137 } | 133 } |
| 134 |
138 void CBC_QRCoderMode::Destroy() { | 135 void CBC_QRCoderMode::Destroy() { |
139 if (sBYTE) { | 136 if (sBYTE) { |
140 delete CBC_QRCoderMode::sBYTE; | 137 delete CBC_QRCoderMode::sBYTE; |
141 sBYTE = nullptr; | 138 sBYTE = nullptr; |
142 } | 139 } |
143 if (sNUMERIC) { | 140 if (sNUMERIC) { |
144 delete CBC_QRCoderMode::sNUMERIC; | 141 delete CBC_QRCoderMode::sNUMERIC; |
145 sNUMERIC = nullptr; | 142 sNUMERIC = nullptr; |
146 } | 143 } |
147 if (sALPHANUMERIC) { | 144 if (sALPHANUMERIC) { |
(...skipping 22 matching lines...) Expand all Loading... |
170 } | 167 } |
171 if (sFNC1_SECOND_POSITION) { | 168 if (sFNC1_SECOND_POSITION) { |
172 delete CBC_QRCoderMode::sFNC1_SECOND_POSITION; | 169 delete CBC_QRCoderMode::sFNC1_SECOND_POSITION; |
173 sFNC1_SECOND_POSITION = nullptr; | 170 sFNC1_SECOND_POSITION = nullptr; |
174 } | 171 } |
175 if (sSTRUCTURED_APPEND) { | 172 if (sSTRUCTURED_APPEND) { |
176 delete CBC_QRCoderMode::sSTRUCTURED_APPEND; | 173 delete CBC_QRCoderMode::sSTRUCTURED_APPEND; |
177 sSTRUCTURED_APPEND = nullptr; | 174 sSTRUCTURED_APPEND = nullptr; |
178 } | 175 } |
179 } | 176 } |
OLD | NEW |