OLD | NEW |
| (Empty) |
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 2006 Jeremias Maerki | |
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 "xfa/src/fxbarcode/BC_Dimension.h" | |
24 #include "xfa/src/fxbarcode/common/BC_CommonBitMatrix.h" | |
25 #include "xfa/src/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h" | |
26 #include "xfa/src/fxbarcode/datamatrix/BC_Encoder.h" | |
27 #include "xfa/src/fxbarcode/datamatrix/BC_SymbolInfo.h" | |
28 #include "xfa/src/fxbarcode/datamatrix/BC_SymbolShapeHint.h" | |
29 | |
30 #define SYMBOLS_COUNT 30 | |
31 | |
32 CBC_SymbolInfo* CBC_SymbolInfo::m_PROD_SYMBOLS[30] = { | |
33 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
34 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
35 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; | |
36 CBC_SymbolInfo* CBC_SymbolInfo::m_symbols[30] = { | |
37 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
38 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
39 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; | |
40 void CBC_SymbolInfo::Initialize() { | |
41 m_PROD_SYMBOLS[0] = new CBC_SymbolInfo(FALSE, 3, 5, 8, 8, 1); | |
42 m_PROD_SYMBOLS[1] = new CBC_SymbolInfo(FALSE, 5, 7, 10, 10, 1); | |
43 m_PROD_SYMBOLS[2] = new CBC_SymbolInfo(TRUE, 5, 7, 16, 6, 1); | |
44 m_PROD_SYMBOLS[3] = new CBC_SymbolInfo(FALSE, 8, 10, 12, 12, 1); | |
45 m_PROD_SYMBOLS[4] = new CBC_SymbolInfo(TRUE, 10, 11, 14, 6, 2); | |
46 m_PROD_SYMBOLS[5] = new CBC_SymbolInfo(FALSE, 12, 12, 14, 14, 1); | |
47 m_PROD_SYMBOLS[6] = new CBC_SymbolInfo(TRUE, 16, 14, 24, 10, 1); | |
48 m_PROD_SYMBOLS[7] = new CBC_SymbolInfo(FALSE, 18, 14, 16, 16, 1); | |
49 m_PROD_SYMBOLS[8] = new CBC_SymbolInfo(FALSE, 22, 18, 18, 18, 1); | |
50 m_PROD_SYMBOLS[9] = new CBC_SymbolInfo(TRUE, 22, 18, 16, 10, 2); | |
51 m_PROD_SYMBOLS[10] = new CBC_SymbolInfo(FALSE, 30, 20, 20, 20, 1); | |
52 m_PROD_SYMBOLS[11] = new CBC_SymbolInfo(TRUE, 32, 24, 16, 14, 2); | |
53 m_PROD_SYMBOLS[12] = new CBC_SymbolInfo(FALSE, 36, 24, 22, 22, 1); | |
54 m_PROD_SYMBOLS[13] = new CBC_SymbolInfo(FALSE, 44, 28, 24, 24, 1); | |
55 m_PROD_SYMBOLS[14] = new CBC_SymbolInfo(TRUE, 49, 28, 22, 14, 2); | |
56 m_PROD_SYMBOLS[15] = new CBC_SymbolInfo(FALSE, 62, 36, 14, 14, 4); | |
57 m_PROD_SYMBOLS[16] = new CBC_SymbolInfo(FALSE, 86, 42, 16, 16, 4); | |
58 m_PROD_SYMBOLS[17] = new CBC_SymbolInfo(FALSE, 114, 48, 18, 18, 4); | |
59 m_PROD_SYMBOLS[18] = new CBC_SymbolInfo(FALSE, 144, 56, 20, 20, 4); | |
60 m_PROD_SYMBOLS[19] = new CBC_SymbolInfo(FALSE, 174, 68, 22, 22, 4); | |
61 m_PROD_SYMBOLS[20] = new CBC_SymbolInfo(FALSE, 204, 84, 24, 24, 4, 102, 42); | |
62 m_PROD_SYMBOLS[21] = new CBC_SymbolInfo(FALSE, 280, 112, 14, 14, 16, 140, 56); | |
63 m_PROD_SYMBOLS[22] = new CBC_SymbolInfo(FALSE, 368, 144, 16, 16, 16, 92, 36); | |
64 m_PROD_SYMBOLS[23] = new CBC_SymbolInfo(FALSE, 456, 192, 18, 18, 16, 114, 48); | |
65 m_PROD_SYMBOLS[24] = new CBC_SymbolInfo(FALSE, 576, 224, 20, 20, 16, 144, 56); | |
66 m_PROD_SYMBOLS[25] = new CBC_SymbolInfo(FALSE, 696, 272, 22, 22, 16, 174, 68); | |
67 m_PROD_SYMBOLS[26] = new CBC_SymbolInfo(FALSE, 816, 336, 24, 24, 16, 136, 56); | |
68 m_PROD_SYMBOLS[27] = | |
69 new CBC_SymbolInfo(FALSE, 1050, 408, 18, 18, 36, 175, 68); | |
70 m_PROD_SYMBOLS[28] = | |
71 new CBC_SymbolInfo(FALSE, 1304, 496, 20, 20, 36, 163, 62); | |
72 m_PROD_SYMBOLS[29] = new CBC_DataMatrixSymbolInfo144(); | |
73 for (int32_t i = 0; i < SYMBOLS_COUNT; i++) { | |
74 m_symbols[i] = m_PROD_SYMBOLS[i]; | |
75 } | |
76 } | |
77 void CBC_SymbolInfo::Finalize() { | |
78 for (int32_t i = 0; i < SYMBOLS_COUNT; i++) { | |
79 delete m_PROD_SYMBOLS[i]; | |
80 m_PROD_SYMBOLS[i] = NULL; | |
81 m_symbols[i] = NULL; | |
82 } | |
83 } | |
84 CBC_SymbolInfo::CBC_SymbolInfo(FX_BOOL rectangular, | |
85 int32_t dataCapacity, | |
86 int32_t errorCodewords, | |
87 int32_t matrixWidth, | |
88 int32_t matrixHeight, | |
89 int32_t dataRegions) { | |
90 m_rectangular = rectangular; | |
91 m_dataCapacity = dataCapacity; | |
92 m_errorCodewords = errorCodewords; | |
93 m_matrixWidth = matrixWidth; | |
94 m_matrixHeight = matrixHeight; | |
95 m_dataRegions = dataRegions; | |
96 m_rsBlockData = dataCapacity; | |
97 m_rsBlockError = errorCodewords; | |
98 } | |
99 CBC_SymbolInfo::CBC_SymbolInfo(FX_BOOL rectangular, | |
100 int32_t dataCapacity, | |
101 int32_t errorCodewords, | |
102 int32_t matrixWidth, | |
103 int32_t matrixHeight, | |
104 int32_t dataRegions, | |
105 int32_t rsBlockData, | |
106 int32_t rsBlockError) { | |
107 m_rectangular = rectangular; | |
108 m_dataCapacity = dataCapacity; | |
109 m_errorCodewords = errorCodewords; | |
110 m_matrixWidth = matrixWidth; | |
111 m_matrixHeight = matrixHeight; | |
112 m_dataRegions = dataRegions; | |
113 m_rsBlockData = rsBlockData; | |
114 m_rsBlockError = rsBlockError; | |
115 } | |
116 CBC_SymbolInfo::~CBC_SymbolInfo() {} | |
117 | |
118 CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, int32_t& e) { | |
119 return lookup(dataCodewords, FORCE_NONE, TRUE, e); | |
120 } | |
121 CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, | |
122 SymbolShapeHint shape, | |
123 int32_t& e) { | |
124 return lookup(dataCodewords, shape, TRUE, e); | |
125 } | |
126 CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, | |
127 FX_BOOL allowRectangular, | |
128 FX_BOOL fail, | |
129 int32_t& e) { | |
130 SymbolShapeHint shape = allowRectangular ? FORCE_NONE : FORCE_SQUARE; | |
131 return lookup(dataCodewords, shape, fail, e); | |
132 } | |
133 CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, | |
134 SymbolShapeHint shape, | |
135 FX_BOOL fail, | |
136 int32_t& e) { | |
137 return lookup(dataCodewords, shape, NULL, NULL, fail, e); | |
138 } | |
139 CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, | |
140 SymbolShapeHint shape, | |
141 CBC_Dimension* minSize, | |
142 CBC_Dimension* maxSize, | |
143 FX_BOOL fail, | |
144 int32_t& e) { | |
145 for (int32_t i = 0; i < SYMBOLS_COUNT; i++) { | |
146 CBC_SymbolInfo* symbol = m_symbols[i]; | |
147 if (shape == FORCE_SQUARE && symbol->m_rectangular) { | |
148 continue; | |
149 } | |
150 if (shape == FORCE_RECTANGLE && !symbol->m_rectangular) { | |
151 continue; | |
152 } | |
153 if (minSize && (symbol->getSymbolWidth(e) < minSize->getWidth() || | |
154 symbol->getSymbolHeight(e) < minSize->getHeight())) { | |
155 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | |
156 continue; | |
157 } | |
158 if (maxSize && (symbol->getSymbolWidth(e) > maxSize->getWidth() || | |
159 symbol->getSymbolHeight(e) > maxSize->getHeight())) { | |
160 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | |
161 continue; | |
162 } | |
163 if (dataCodewords <= symbol->m_dataCapacity) { | |
164 return symbol; | |
165 } | |
166 } | |
167 if (fail) { | |
168 e = BCExceptionIllegalDataCodewords; | |
169 return NULL; | |
170 } | |
171 return NULL; | |
172 } | |
173 int32_t CBC_SymbolInfo::getHorizontalDataRegions(int32_t& e) { | |
174 switch (m_dataRegions) { | |
175 case 1: | |
176 return 1; | |
177 case 2: | |
178 return 2; | |
179 case 4: | |
180 return 2; | |
181 case 16: | |
182 return 4; | |
183 case 36: | |
184 return 6; | |
185 default: | |
186 e = BCExceptionCannotHandleThisNumberOfDataRegions; | |
187 return 0; | |
188 } | |
189 } | |
190 int32_t CBC_SymbolInfo::getVerticalDataRegions(int32_t& e) { | |
191 switch (m_dataRegions) { | |
192 case 1: | |
193 return 1; | |
194 case 2: | |
195 return 1; | |
196 case 4: | |
197 return 2; | |
198 case 16: | |
199 return 4; | |
200 case 36: | |
201 return 6; | |
202 default: | |
203 e = BCExceptionCannotHandleThisNumberOfDataRegions; | |
204 return 0; | |
205 } | |
206 } | |
207 int32_t CBC_SymbolInfo::getSymbolDataWidth(int32_t& e) { | |
208 return getHorizontalDataRegions(e) * m_matrixWidth; | |
209 } | |
210 int32_t CBC_SymbolInfo::getSymbolDataHeight(int32_t& e) { | |
211 return getVerticalDataRegions(e) * m_matrixHeight; | |
212 } | |
213 int32_t CBC_SymbolInfo::getSymbolWidth(int32_t& e) { | |
214 return getSymbolDataWidth(e) + (getHorizontalDataRegions(e) * 2); | |
215 } | |
216 int32_t CBC_SymbolInfo::getSymbolHeight(int32_t& e) { | |
217 return getSymbolDataHeight(e) + (getVerticalDataRegions(e) * 2); | |
218 } | |
219 int32_t CBC_SymbolInfo::getCodewordCount() { | |
220 return m_dataCapacity + m_errorCodewords; | |
221 } | |
222 int32_t CBC_SymbolInfo::getInterleavedBlockCount() { | |
223 return m_dataCapacity / m_rsBlockData; | |
224 } | |
225 int32_t CBC_SymbolInfo::getDataLengthForInterleavedBlock(int32_t index) { | |
226 return m_rsBlockData; | |
227 } | |
228 int32_t CBC_SymbolInfo::getErrorLengthForInterleavedBlock(int32_t index) { | |
229 return m_rsBlockError; | |
230 } | |
231 CFX_WideString CBC_SymbolInfo::toString(int32_t& e) { | |
232 CFX_WideString sb; | |
233 sb += (FX_WCHAR*)(m_rectangular ? "Rectangular Symbol:" : "Square Symbol:"); | |
234 sb += (FX_WCHAR*)" data region "; | |
235 sb += m_matrixWidth; | |
236 sb += (FX_WCHAR)'x'; | |
237 sb += m_matrixHeight; | |
238 sb += (FX_WCHAR*)", symbol size "; | |
239 sb += getSymbolWidth(e); | |
240 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)""); | |
241 sb += (FX_WCHAR)'x'; | |
242 sb += getSymbolHeight(e); | |
243 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)""); | |
244 sb += (FX_WCHAR*)", symbol data size "; | |
245 sb += getSymbolDataWidth(e); | |
246 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)""); | |
247 sb += (FX_WCHAR)'x'; | |
248 sb += getSymbolDataHeight(e); | |
249 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)""); | |
250 sb += (FX_WCHAR*)", codewords "; | |
251 sb += m_dataCapacity; | |
252 sb += (FX_WCHAR)'+'; | |
253 sb += m_errorCodewords; | |
254 return sb; | |
255 } | |
OLD | NEW |