1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
// Original code is licensed as follows:
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "barcode.h"
#include "include/BC_QRCoderVersion.h"
#include "include/BC_QRCoderMode.h"
CBC_QRCoderMode* CBC_QRCoderMode::sBYTE = NULL;
CBC_QRCoderMode* CBC_QRCoderMode::sNUMERIC = NULL;
CBC_QRCoderMode* CBC_QRCoderMode::sALPHANUMERIC = NULL;
CBC_QRCoderMode* CBC_QRCoderMode::sKANJI = NULL;
CBC_QRCoderMode* CBC_QRCoderMode::sECI = NULL;
CBC_QRCoderMode* CBC_QRCoderMode::sGBK = NULL;
CBC_QRCoderMode* CBC_QRCoderMode::sTERMINATOR = NULL;
CBC_QRCoderMode* CBC_QRCoderMode::sFNC1_FIRST_POSITION = NULL;
CBC_QRCoderMode* CBC_QRCoderMode::sFNC1_SECOND_POSITION = NULL;
CBC_QRCoderMode* CBC_QRCoderMode::sSTRUCTURED_APPEND = NULL;
CBC_QRCoderMode::CBC_QRCoderMode(FX_INT32 *characterCountBitsForVersions,
FX_INT32 x1, FX_INT32 x2, FX_INT32 x3,
FX_INT32 bits, CFX_ByteString name)
{
m_characterCountBitsForVersions = characterCountBitsForVersions;
if (m_characterCountBitsForVersions != NULL) {
m_characterCountBitsForVersions[0] = x1;
m_characterCountBitsForVersions[1] = x2;
m_characterCountBitsForVersions[2] = x3;
}
m_name += name;
m_bits = bits;
}
CBC_QRCoderMode::~CBC_QRCoderMode()
{
if(m_characterCountBitsForVersions != NULL) {
FX_Free(m_characterCountBitsForVersions);
}
}
void CBC_QRCoderMode::Initialize()
{
sBYTE = FX_NEW CBC_QRCoderMode(FX_Alloc(FX_INT32, 3), 8, 16, 16, 0x4, "BYTE");
sALPHANUMERIC = FX_NEW CBC_QRCoderMode(FX_Alloc(FX_INT32, 3), 9, 11, 13, 0x2, "ALPHANUMERIC");
sECI = FX_NEW CBC_QRCoderMode(NULL, 0, 0, 0, 0x7, "ECI");
sKANJI = FX_NEW CBC_QRCoderMode(FX_Alloc(FX_INT32, 3), 8, 10, 12, 0x8, "KANJI");
sNUMERIC = FX_NEW CBC_QRCoderMode(FX_Alloc(FX_INT32, 3), 10, 12, 14, 0x1, "NUMERIC");
sGBK = FX_NEW CBC_QRCoderMode(FX_Alloc(FX_INT32, 3), 8, 10, 12, 0x0D, "GBK");
sTERMINATOR = FX_NEW CBC_QRCoderMode(FX_Alloc(FX_INT32, 3), 0, 0, 0, 0x00, "TERMINATOR");
sFNC1_FIRST_POSITION = FX_NEW CBC_QRCoderMode(NULL, 0, 0, 0, 0x05, "FNC1_FIRST_POSITION");
sFNC1_SECOND_POSITION = FX_NEW CBC_QRCoderMode(NULL, 0, 0, 0, 0x09, "FNC1_SECOND_POSITION");
sSTRUCTURED_APPEND = FX_NEW CBC_QRCoderMode(FX_Alloc(FX_INT32, 3), 0, 0, 0, 0x03, "STRUCTURED_APPEND");
}
void CBC_QRCoderMode::Finalize()
{
delete sBYTE;
delete sALPHANUMERIC;
delete sECI;
delete sKANJI;
delete sNUMERIC;
delete sGBK;
delete sTERMINATOR;
delete sFNC1_FIRST_POSITION;
delete sFNC1_SECOND_POSITION;
delete sSTRUCTURED_APPEND;
}
CBC_QRCoderMode* CBC_QRCoderMode::ForBits(FX_INT32 bits, FX_INT32 &e)
{
switch (bits) {
case 0x0:
return sTERMINATOR;
case 0x1:
return sNUMERIC;
case 0x2:
return sALPHANUMERIC;
case 0x3:
return sSTRUCTURED_APPEND;
case 0x4:
return sBYTE;
case 0x5:
return sFNC1_FIRST_POSITION;
case 0x7:
return sECI;
case 0x8:
return sKANJI;
case 0x9:
return sFNC1_SECOND_POSITION;
case 0x0D:
return sGBK;
default: {
e = BCExceptionUnsupportedMode;
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
}
}
return NULL;
}
FX_INT32 CBC_QRCoderMode::GetBits()
{
return m_bits;
}
CFX_ByteString CBC_QRCoderMode::GetName()
{
return m_name;
}
FX_INT32 CBC_QRCoderMode::GetCharacterCountBits(CBC_QRCoderVersion* version, FX_INT32 &e)
{
if(m_characterCountBitsForVersions == NULL) {
e = BCExceptionCharacterNotThisMode;
BC_EXCEPTION_CHECK_ReturnValue(e, 0);
}
FX_INT32 number = version->GetVersionNumber();
FX_INT32 offset;
if(number <= 9) {
offset = 0;
} else if(number <= 26) {
offset = 1;
} else {
offset = 2;
}
return m_characterCountBitsForVersions[offset];
}
void CBC_QRCoderMode::Destroy()
{
if(sBYTE) {
delete CBC_QRCoderMode::sBYTE;
sBYTE = NULL;
}
if(sNUMERIC) {
delete CBC_QRCoderMode::sNUMERIC;
sNUMERIC = NULL;
}
if(sALPHANUMERIC) {
delete CBC_QRCoderMode::sALPHANUMERIC;
sALPHANUMERIC = NULL;
}
if(sKANJI) {
delete CBC_QRCoderMode::sKANJI;
sKANJI = NULL;
}
if(sECI) {
delete CBC_QRCoderMode::sECI;
sECI = NULL;
}
if(sGBK) {
delete CBC_QRCoderMode::sGBK;
sGBK = NULL;
}
if(sTERMINATOR) {
delete CBC_QRCoderMode::sTERMINATOR;
sTERMINATOR = NULL;
}
if(sFNC1_FIRST_POSITION) {
delete CBC_QRCoderMode::sFNC1_FIRST_POSITION;
sFNC1_FIRST_POSITION = NULL;
}
if(sFNC1_SECOND_POSITION) {
delete CBC_QRCoderMode::sFNC1_SECOND_POSITION;
sFNC1_SECOND_POSITION = NULL;
}
if(sSTRUCTURED_APPEND) {
delete CBC_QRCoderMode::sSTRUCTURED_APPEND;
sSTRUCTURED_APPEND = NULL;
}
}
|