• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Original code is licensed as follows:
7 /*
8  * Copyright 2007 ZXing authors
9  *
10  * Licensed under the Apache License, Version 2.0 (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
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include "fxbarcode/qrcode/BC_QRCoderMode.h"
24 
25 #include <utility>
26 
27 #include "core/fxcrt/fx_system.h"
28 
29 CBC_QRCoderMode* CBC_QRCoderMode::sBYTE = nullptr;
30 CBC_QRCoderMode* CBC_QRCoderMode::sNUMERIC = nullptr;
31 CBC_QRCoderMode* CBC_QRCoderMode::sALPHANUMERIC = nullptr;
32 CBC_QRCoderMode* CBC_QRCoderMode::sKANJI = nullptr;
33 CBC_QRCoderMode* CBC_QRCoderMode::sECI = nullptr;
34 CBC_QRCoderMode* CBC_QRCoderMode::sGBK = nullptr;
35 CBC_QRCoderMode* CBC_QRCoderMode::sTERMINATOR = nullptr;
36 CBC_QRCoderMode* CBC_QRCoderMode::sFNC1_FIRST_POSITION = nullptr;
37 CBC_QRCoderMode* CBC_QRCoderMode::sFNC1_SECOND_POSITION = nullptr;
38 CBC_QRCoderMode* CBC_QRCoderMode::sSTRUCTURED_APPEND = nullptr;
39 
CBC_QRCoderMode(std::vector<int32_t> charCountBits,int32_t bits)40 CBC_QRCoderMode::CBC_QRCoderMode(std::vector<int32_t> charCountBits,
41                                  int32_t bits)
42     : m_characterCountBitsForVersions(std::move(charCountBits)), m_bits(bits) {}
43 
44 CBC_QRCoderMode::~CBC_QRCoderMode() = default;
45 
Initialize()46 void CBC_QRCoderMode::Initialize() {
47   sBYTE = new CBC_QRCoderMode({8, 16, 16}, 0x4);
48   sALPHANUMERIC = new CBC_QRCoderMode({9, 11, 13}, 0x2);
49   sECI = new CBC_QRCoderMode(std::vector<int32_t>(), 0x7);
50   sKANJI = new CBC_QRCoderMode({8, 10, 12}, 0x8);
51   sNUMERIC = new CBC_QRCoderMode({10, 12, 14}, 0x1);
52   sGBK = new CBC_QRCoderMode({8, 10, 12}, 0x0D);
53   sTERMINATOR = new CBC_QRCoderMode(std::vector<int32_t>(), 0x00);
54   sFNC1_FIRST_POSITION = new CBC_QRCoderMode(std::vector<int32_t>(), 0x05);
55   sFNC1_SECOND_POSITION = new CBC_QRCoderMode(std::vector<int32_t>(), 0x09);
56   sSTRUCTURED_APPEND = new CBC_QRCoderMode(std::vector<int32_t>(), 0x03);
57 }
58 
Finalize()59 void CBC_QRCoderMode::Finalize() {
60   delete sBYTE;
61   sBYTE = nullptr;
62   delete sALPHANUMERIC;
63   sALPHANUMERIC = nullptr;
64   delete sECI;
65   sECI = nullptr;
66   delete sKANJI;
67   sKANJI = nullptr;
68   delete sNUMERIC;
69   sNUMERIC = nullptr;
70   delete sGBK;
71   sGBK = nullptr;
72   delete sTERMINATOR;
73   sTERMINATOR = nullptr;
74   delete sFNC1_FIRST_POSITION;
75   sFNC1_FIRST_POSITION = nullptr;
76   delete sFNC1_SECOND_POSITION;
77   sFNC1_SECOND_POSITION = nullptr;
78   delete sSTRUCTURED_APPEND;
79   sSTRUCTURED_APPEND = nullptr;
80 }
81 
GetBits() const82 int32_t CBC_QRCoderMode::GetBits() const {
83   return m_bits;
84 }
85 
GetCharacterCountBits(int32_t number) const86 int32_t CBC_QRCoderMode::GetCharacterCountBits(int32_t number) const {
87   if (m_characterCountBitsForVersions.empty())
88     return 0;
89 
90   int32_t offset;
91   if (number <= 9)
92     offset = 0;
93   else if (number <= 26)
94     offset = 1;
95   else
96     offset = 2;
97 
98   int32_t result = m_characterCountBitsForVersions[offset];
99   ASSERT(result != 0);
100   return result;
101 }
102