| 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 #include "xfa/fxbarcode/qrcode/BC_QRCoderVersion.h" | 24 #include "xfa/fxbarcode/qrcode/BC_QRCoderVersion.h" |
| 25 #include "xfa/fxbarcode/utils.h" | 25 #include "xfa/fxbarcode/utils.h" |
| 26 | 26 |
| 27 CBC_QRCoderMode* CBC_QRCoderMode::sBYTE = NULL; | 27 CBC_QRCoderMode* CBC_QRCoderMode::sBYTE = nullptr; |
| 28 CBC_QRCoderMode* CBC_QRCoderMode::sNUMERIC = NULL; | 28 CBC_QRCoderMode* CBC_QRCoderMode::sNUMERIC = nullptr; |
| 29 CBC_QRCoderMode* CBC_QRCoderMode::sALPHANUMERIC = NULL; | 29 CBC_QRCoderMode* CBC_QRCoderMode::sALPHANUMERIC = nullptr; |
| 30 CBC_QRCoderMode* CBC_QRCoderMode::sKANJI = NULL; | 30 CBC_QRCoderMode* CBC_QRCoderMode::sKANJI = nullptr; |
| 31 CBC_QRCoderMode* CBC_QRCoderMode::sECI = NULL; | 31 CBC_QRCoderMode* CBC_QRCoderMode::sECI = nullptr; |
| 32 CBC_QRCoderMode* CBC_QRCoderMode::sGBK = NULL; | 32 CBC_QRCoderMode* CBC_QRCoderMode::sGBK = nullptr; |
| 33 CBC_QRCoderMode* CBC_QRCoderMode::sTERMINATOR = NULL; | 33 CBC_QRCoderMode* CBC_QRCoderMode::sTERMINATOR = nullptr; |
| 34 CBC_QRCoderMode* CBC_QRCoderMode::sFNC1_FIRST_POSITION = NULL; | 34 CBC_QRCoderMode* CBC_QRCoderMode::sFNC1_FIRST_POSITION = nullptr; |
| 35 CBC_QRCoderMode* CBC_QRCoderMode::sFNC1_SECOND_POSITION = NULL; | 35 CBC_QRCoderMode* CBC_QRCoderMode::sFNC1_SECOND_POSITION = nullptr; |
| 36 CBC_QRCoderMode* CBC_QRCoderMode::sSTRUCTURED_APPEND = NULL; | 36 CBC_QRCoderMode* CBC_QRCoderMode::sSTRUCTURED_APPEND = nullptr; |
| 37 | 37 |
| 38 CBC_QRCoderMode::CBC_QRCoderMode(int32_t* characterCountBitsForVersions, | 38 CBC_QRCoderMode::CBC_QRCoderMode(int32_t* characterCountBitsForVersions, |
| 39 int32_t x1, | 39 int32_t x1, |
| 40 int32_t x2, | 40 int32_t x2, |
| 41 int32_t x3, | 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 = characterCountBitsForVersions; |
| 45 if (m_characterCountBitsForVersions) { | 45 if (m_characterCountBitsForVersions) { |
| 46 m_characterCountBitsForVersions[0] = x1; | 46 m_characterCountBitsForVersions[0] = x1; |
| 47 m_characterCountBitsForVersions[1] = x2; | 47 m_characterCountBitsForVersions[1] = x2; |
| 48 m_characterCountBitsForVersions[2] = x3; | 48 m_characterCountBitsForVersions[2] = x3; |
| 49 } | 49 } |
| 50 m_name += name; | 50 m_name += name; |
| 51 m_bits = bits; | 51 m_bits = bits; |
| 52 } | 52 } |
| 53 CBC_QRCoderMode::~CBC_QRCoderMode() { | 53 CBC_QRCoderMode::~CBC_QRCoderMode() { |
| 54 FX_Free(m_characterCountBitsForVersions); | 54 FX_Free(m_characterCountBitsForVersions); |
| 55 } | 55 } |
| 56 void CBC_QRCoderMode::Initialize() { | 56 void CBC_QRCoderMode::Initialize() { |
| 57 sBYTE = new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 8, 16, 16, 0x4, "BYTE"); | 57 sBYTE = new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 8, 16, 16, 0x4, "BYTE"); |
| 58 sALPHANUMERIC = | 58 sALPHANUMERIC = |
| 59 new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 9, 11, 13, 0x2, "ALPHANUMERIC"); | 59 new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 9, 11, 13, 0x2, "ALPHANUMERIC"); |
| 60 sECI = new CBC_QRCoderMode(NULL, 0, 0, 0, 0x7, "ECI"); | 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"); | 61 sKANJI = new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 8, 10, 12, 0x8, "KANJI"); |
| 62 sNUMERIC = | 62 sNUMERIC = |
| 63 new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 10, 12, 14, 0x1, "NUMERIC"); | 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"); | 64 sGBK = new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 8, 10, 12, 0x0D, "GBK"); |
| 65 sTERMINATOR = | 65 sTERMINATOR = |
| 66 new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 0, 0, 0, 0x00, "TERMINATOR"); | 66 new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 0, 0, 0, 0x00, "TERMINATOR"); |
| 67 sFNC1_FIRST_POSITION = | 67 sFNC1_FIRST_POSITION = |
| 68 new CBC_QRCoderMode(NULL, 0, 0, 0, 0x05, "FNC1_FIRST_POSITION"); | 68 new CBC_QRCoderMode(nullptr, 0, 0, 0, 0x05, "FNC1_FIRST_POSITION"); |
| 69 sFNC1_SECOND_POSITION = | 69 sFNC1_SECOND_POSITION = |
| 70 new CBC_QRCoderMode(NULL, 0, 0, 0, 0x09, "FNC1_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, | 71 sSTRUCTURED_APPEND = new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 0, 0, 0, 0x03, |
| 72 "STRUCTURED_APPEND"); | 72 "STRUCTURED_APPEND"); |
| 73 } | 73 } |
| 74 void CBC_QRCoderMode::Finalize() { | 74 void CBC_QRCoderMode::Finalize() { |
| 75 delete sBYTE; | 75 delete sBYTE; |
| 76 delete sALPHANUMERIC; | 76 delete sALPHANUMERIC; |
| 77 delete sECI; | 77 delete sECI; |
| 78 delete sKANJI; | 78 delete sKANJI; |
| 79 delete sNUMERIC; | 79 delete sNUMERIC; |
| 80 delete sGBK; | 80 delete sGBK; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 100 case 0x7: | 100 case 0x7: |
| 101 return sECI; | 101 return sECI; |
| 102 case 0x8: | 102 case 0x8: |
| 103 return sKANJI; | 103 return sKANJI; |
| 104 case 0x9: | 104 case 0x9: |
| 105 return sFNC1_SECOND_POSITION; | 105 return sFNC1_SECOND_POSITION; |
| 106 case 0x0D: | 106 case 0x0D: |
| 107 return sGBK; | 107 return sGBK; |
| 108 default: { | 108 default: { |
| 109 e = BCExceptionUnsupportedMode; | 109 e = BCExceptionUnsupportedMode; |
| 110 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 110 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 return NULL; | 113 return nullptr; |
| 114 } | 114 } |
| 115 int32_t CBC_QRCoderMode::GetBits() { | 115 int32_t CBC_QRCoderMode::GetBits() { |
| 116 return m_bits; | 116 return m_bits; |
| 117 } | 117 } |
| 118 CFX_ByteString CBC_QRCoderMode::GetName() { | 118 CFX_ByteString CBC_QRCoderMode::GetName() { |
| 119 return m_name; | 119 return m_name; |
| 120 } | 120 } |
| 121 int32_t CBC_QRCoderMode::GetCharacterCountBits(CBC_QRCoderVersion* version, | 121 int32_t CBC_QRCoderMode::GetCharacterCountBits(CBC_QRCoderVersion* version, |
| 122 int32_t& e) { | 122 int32_t& e) { |
| 123 if (m_characterCountBitsForVersions == NULL) { | 123 if (!m_characterCountBitsForVersions) { |
| 124 e = BCExceptionCharacterNotThisMode; | 124 e = BCExceptionCharacterNotThisMode; |
| 125 BC_EXCEPTION_CHECK_ReturnValue(e, 0); | 125 BC_EXCEPTION_CHECK_ReturnValue(e, 0); |
| 126 } | 126 } |
| 127 int32_t number = version->GetVersionNumber(); | 127 int32_t number = version->GetVersionNumber(); |
| 128 int32_t offset; | 128 int32_t offset; |
| 129 if (number <= 9) { | 129 if (number <= 9) { |
| 130 offset = 0; | 130 offset = 0; |
| 131 } else if (number <= 26) { | 131 } else if (number <= 26) { |
| 132 offset = 1; | 132 offset = 1; |
| 133 } else { | 133 } else { |
| 134 offset = 2; | 134 offset = 2; |
| 135 } | 135 } |
| 136 return m_characterCountBitsForVersions[offset]; | 136 return m_characterCountBitsForVersions[offset]; |
| 137 } | 137 } |
| 138 void CBC_QRCoderMode::Destroy() { | 138 void CBC_QRCoderMode::Destroy() { |
| 139 if (sBYTE) { | 139 if (sBYTE) { |
| 140 delete CBC_QRCoderMode::sBYTE; | 140 delete CBC_QRCoderMode::sBYTE; |
| 141 sBYTE = NULL; | 141 sBYTE = nullptr; |
| 142 } | 142 } |
| 143 if (sNUMERIC) { | 143 if (sNUMERIC) { |
| 144 delete CBC_QRCoderMode::sNUMERIC; | 144 delete CBC_QRCoderMode::sNUMERIC; |
| 145 sNUMERIC = NULL; | 145 sNUMERIC = nullptr; |
| 146 } | 146 } |
| 147 if (sALPHANUMERIC) { | 147 if (sALPHANUMERIC) { |
| 148 delete CBC_QRCoderMode::sALPHANUMERIC; | 148 delete CBC_QRCoderMode::sALPHANUMERIC; |
| 149 sALPHANUMERIC = NULL; | 149 sALPHANUMERIC = nullptr; |
| 150 } | 150 } |
| 151 if (sKANJI) { | 151 if (sKANJI) { |
| 152 delete CBC_QRCoderMode::sKANJI; | 152 delete CBC_QRCoderMode::sKANJI; |
| 153 sKANJI = NULL; | 153 sKANJI = nullptr; |
| 154 } | 154 } |
| 155 if (sECI) { | 155 if (sECI) { |
| 156 delete CBC_QRCoderMode::sECI; | 156 delete CBC_QRCoderMode::sECI; |
| 157 sECI = NULL; | 157 sECI = nullptr; |
| 158 } | 158 } |
| 159 if (sGBK) { | 159 if (sGBK) { |
| 160 delete CBC_QRCoderMode::sGBK; | 160 delete CBC_QRCoderMode::sGBK; |
| 161 sGBK = NULL; | 161 sGBK = nullptr; |
| 162 } | 162 } |
| 163 if (sTERMINATOR) { | 163 if (sTERMINATOR) { |
| 164 delete CBC_QRCoderMode::sTERMINATOR; | 164 delete CBC_QRCoderMode::sTERMINATOR; |
| 165 sTERMINATOR = NULL; | 165 sTERMINATOR = nullptr; |
| 166 } | 166 } |
| 167 if (sFNC1_FIRST_POSITION) { | 167 if (sFNC1_FIRST_POSITION) { |
| 168 delete CBC_QRCoderMode::sFNC1_FIRST_POSITION; | 168 delete CBC_QRCoderMode::sFNC1_FIRST_POSITION; |
| 169 sFNC1_FIRST_POSITION = NULL; | 169 sFNC1_FIRST_POSITION = nullptr; |
| 170 } | 170 } |
| 171 if (sFNC1_SECOND_POSITION) { | 171 if (sFNC1_SECOND_POSITION) { |
| 172 delete CBC_QRCoderMode::sFNC1_SECOND_POSITION; | 172 delete CBC_QRCoderMode::sFNC1_SECOND_POSITION; |
| 173 sFNC1_SECOND_POSITION = NULL; | 173 sFNC1_SECOND_POSITION = nullptr; |
| 174 } | 174 } |
| 175 if (sSTRUCTURED_APPEND) { | 175 if (sSTRUCTURED_APPEND) { |
| 176 delete CBC_QRCoderMode::sSTRUCTURED_APPEND; | 176 delete CBC_QRCoderMode::sSTRUCTURED_APPEND; |
| 177 sSTRUCTURED_APPEND = NULL; | 177 sSTRUCTURED_APPEND = nullptr; |
| 178 } | 178 } |
| 179 } | 179 } |
| OLD | NEW |