Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: xfa/fwl/basewidget/fxmath_barcodeimp.cpp

Issue 2073793002: Rename fxmath_barcodeimp to cfx_barcode (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Review feedback Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fwl/basewidget/fxmath_barcodeimp.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
7 #include "xfa/fwl/basewidget/fxmath_barcodeimp.h"
8
9 #include "xfa/fxbarcode/cbc_codabar.h"
10 #include "xfa/fxbarcode/cbc_code128.h"
11 #include "xfa/fxbarcode/cbc_code39.h"
12 #include "xfa/fxbarcode/cbc_codebase.h"
13 #include "xfa/fxbarcode/cbc_datamatrix.h"
14 #include "xfa/fxbarcode/cbc_ean13.h"
15 #include "xfa/fxbarcode/cbc_ean8.h"
16 #include "xfa/fxbarcode/cbc_pdf417i.h"
17 #include "xfa/fxbarcode/cbc_qrcode.h"
18 #include "xfa/fxbarcode/cbc_upca.h"
19 #include "xfa/fxbarcode/utils.h"
20
21 static CBC_CodeBase* FX_Barcode_CreateBarCodeEngineObject(BC_TYPE type) {
22 switch (type) {
23 case BC_CODE39:
24 return new CBC_Code39();
25 case BC_CODABAR:
26 return new CBC_Codabar();
27 case BC_CODE128:
28 return new CBC_Code128(BC_CODE128_B);
29 case BC_CODE128_B:
30 return new CBC_Code128(BC_CODE128_B);
31 case BC_CODE128_C:
32 return new CBC_Code128(BC_CODE128_C);
33 case BC_EAN8:
34 return new CBC_EAN8();
35 case BC_UPCA:
36 return new CBC_UPCA();
37 case BC_EAN13:
38 return new CBC_EAN13();
39 case BC_QR_CODE:
40 return new CBC_QRCode();
41 case BC_PDF417:
42 return new CBC_PDF417I();
43 case BC_DATAMATRIX:
44 return new CBC_DataMatrix();
45 case BC_UNKNOWN:
46 default:
47 return NULL;
48 }
49 }
50
51 CFX_Barcode::CFX_Barcode() {}
52
53 CFX_Barcode::~CFX_Barcode() {
54 delete m_pBCEngine;
55 }
56
57 FX_BOOL CFX_Barcode::Create(BC_TYPE type) {
58 m_pBCEngine = FX_Barcode_CreateBarCodeEngineObject(type);
59 return m_pBCEngine != NULL;
60 }
61 BC_TYPE CFX_Barcode::GetType() {
62 return m_pBCEngine ? m_pBCEngine->GetType() : BC_UNKNOWN;
63 }
64 FX_BOOL CFX_Barcode::SetCharEncoding(BC_CHAR_ENCODING encoding) {
65 return m_pBCEngine ? m_pBCEngine->SetCharEncoding(encoding) : FALSE;
66 }
67 FX_BOOL CFX_Barcode::SetModuleHeight(int32_t moduleHeight) {
68 return m_pBCEngine ? m_pBCEngine->SetModuleHeight(moduleHeight) : FALSE;
69 }
70 FX_BOOL CFX_Barcode::SetModuleWidth(int32_t moduleWidth) {
71 return m_pBCEngine ? m_pBCEngine->SetModuleWidth(moduleWidth) : FALSE;
72 }
73 FX_BOOL CFX_Barcode::SetHeight(int32_t height) {
74 return m_pBCEngine ? m_pBCEngine->SetHeight(height) : FALSE;
75 }
76 FX_BOOL CFX_Barcode::SetWidth(int32_t width) {
77 return m_pBCEngine ? m_pBCEngine->SetWidth(width) : FALSE;
78 }
79 FX_BOOL CFX_Barcode::CheckContentValidity(const CFX_WideStringC& contents) {
80 switch (GetType()) {
81 case BC_CODE39:
82 case BC_CODABAR:
83 case BC_CODE128:
84 case BC_CODE128_B:
85 case BC_CODE128_C:
86 case BC_EAN8:
87 case BC_EAN13:
88 case BC_UPCA:
89 return m_pBCEngine
90 ? static_cast<CBC_OneCode*>(m_pBCEngine)
91 ->CheckContentValidity(contents)
92 : TRUE;
93 default:
94 return TRUE;
95 }
96 }
97 FX_BOOL CFX_Barcode::SetPrintChecksum(FX_BOOL checksum) {
98 switch (GetType()) {
99 case BC_CODE39:
100 case BC_CODABAR:
101 case BC_CODE128:
102 case BC_CODE128_B:
103 case BC_CODE128_C:
104 case BC_EAN8:
105 case BC_EAN13:
106 case BC_UPCA:
107 return m_pBCEngine ? (static_cast<CBC_OneCode*>(m_pBCEngine)
108 ->SetPrintChecksum(checksum),
109 TRUE)
110 : FALSE;
111 default:
112 return FALSE;
113 }
114 }
115 FX_BOOL CFX_Barcode::SetDataLength(int32_t length) {
116 switch (GetType()) {
117 case BC_CODE39:
118 case BC_CODABAR:
119 case BC_CODE128:
120 case BC_CODE128_B:
121 case BC_CODE128_C:
122 case BC_EAN8:
123 case BC_EAN13:
124 case BC_UPCA:
125 return m_pBCEngine ? (static_cast<CBC_OneCode*>(m_pBCEngine)
126 ->SetDataLength(length),
127 TRUE)
128 : FALSE;
129 default:
130 return FALSE;
131 }
132 }
133 FX_BOOL CFX_Barcode::SetCalChecksum(int32_t state) {
134 switch (GetType()) {
135 case BC_CODE39:
136 case BC_CODABAR:
137 case BC_CODE128:
138 case BC_CODE128_B:
139 case BC_CODE128_C:
140 case BC_EAN8:
141 case BC_EAN13:
142 case BC_UPCA:
143 return m_pBCEngine ? (static_cast<CBC_OneCode*>(m_pBCEngine)
144 ->SetCalChecksum(state),
145 TRUE)
146 : FALSE;
147 default:
148 return FALSE;
149 }
150 }
151 FX_BOOL CFX_Barcode::SetFont(CFX_Font* pFont) {
152 switch (GetType()) {
153 case BC_CODE39:
154 case BC_CODABAR:
155 case BC_CODE128:
156 case BC_CODE128_B:
157 case BC_CODE128_C:
158 case BC_EAN8:
159 case BC_EAN13:
160 case BC_UPCA:
161 return m_pBCEngine
162 ? static_cast<CBC_OneCode*>(m_pBCEngine)->SetFont(pFont)
163 : FALSE;
164 default:
165 return FALSE;
166 }
167 }
168 FX_BOOL CFX_Barcode::SetFontSize(FX_FLOAT size) {
169 switch (GetType()) {
170 case BC_CODE39:
171 case BC_CODABAR:
172 case BC_CODE128:
173 case BC_CODE128_B:
174 case BC_CODE128_C:
175 case BC_EAN8:
176 case BC_EAN13:
177 case BC_UPCA:
178 return m_pBCEngine
179 ? (static_cast<CBC_OneCode*>(m_pBCEngine)->SetFontSize(size),
180 TRUE)
181 : FALSE;
182 default:
183 return FALSE;
184 }
185 }
186 FX_BOOL CFX_Barcode::SetFontStyle(int32_t style) {
187 switch (GetType()) {
188 case BC_CODE39:
189 case BC_CODABAR:
190 case BC_CODE128:
191 case BC_CODE128_B:
192 case BC_CODE128_C:
193 case BC_EAN8:
194 case BC_EAN13:
195 case BC_UPCA:
196 return m_pBCEngine
197 ? (static_cast<CBC_OneCode*>(m_pBCEngine)->SetFontStyle(style),
198 TRUE)
199 : FALSE;
200 default:
201 return FALSE;
202 }
203 }
204 FX_BOOL CFX_Barcode::SetFontColor(FX_ARGB color) {
205 switch (GetType()) {
206 case BC_CODE39:
207 case BC_CODABAR:
208 case BC_CODE128:
209 case BC_CODE128_B:
210 case BC_CODE128_C:
211 case BC_EAN8:
212 case BC_EAN13:
213 case BC_UPCA:
214 return m_pBCEngine
215 ? (static_cast<CBC_OneCode*>(m_pBCEngine)->SetFontColor(color),
216 TRUE)
217 : FALSE;
218 default:
219 return FALSE;
220 }
221 }
222 FX_BOOL CFX_Barcode::SetTextLocation(BC_TEXT_LOC location) {
223 typedef FX_BOOL (CBC_CodeBase::*memptrtype)(BC_TEXT_LOC);
224 memptrtype memptr = NULL;
225 switch (GetType()) {
226 case BC_CODE39:
227 memptr = (memptrtype)&CBC_Code39::SetTextLocation;
228 break;
229 case BC_CODABAR:
230 memptr = (memptrtype)&CBC_Codabar::SetTextLocation;
231 break;
232 case BC_CODE128:
233 case BC_CODE128_B:
234 case BC_CODE128_C:
235 memptr = (memptrtype)&CBC_Code128::SetTextLocation;
236 break;
237 default:
238 break;
239 }
240 return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(location) : FALSE;
241 }
242 FX_BOOL CFX_Barcode::SetWideNarrowRatio(int32_t ratio) {
243 typedef FX_BOOL (CBC_CodeBase::*memptrtype)(int32_t);
244 memptrtype memptr = NULL;
245 switch (GetType()) {
246 case BC_CODE39:
247 memptr = (memptrtype)&CBC_Code39::SetWideNarrowRatio;
248 break;
249 case BC_CODABAR:
250 memptr = (memptrtype)&CBC_Codabar::SetWideNarrowRatio;
251 break;
252 default:
253 break;
254 }
255 return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(ratio) : FALSE;
256 }
257 FX_BOOL CFX_Barcode::SetStartChar(FX_CHAR start) {
258 typedef FX_BOOL (CBC_CodeBase::*memptrtype)(FX_CHAR);
259 memptrtype memptr = NULL;
260 switch (GetType()) {
261 case BC_CODABAR:
262 memptr = (memptrtype)&CBC_Codabar::SetStartChar;
263 break;
264 default:
265 break;
266 }
267 return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(start) : FALSE;
268 }
269 FX_BOOL CFX_Barcode::SetEndChar(FX_CHAR end) {
270 typedef FX_BOOL (CBC_CodeBase::*memptrtype)(FX_CHAR);
271 memptrtype memptr = NULL;
272 switch (GetType()) {
273 case BC_CODABAR:
274 memptr = (memptrtype)&CBC_Codabar::SetEndChar;
275 break;
276 default:
277 break;
278 }
279 return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(end) : FALSE;
280 }
281 FX_BOOL CFX_Barcode::SetVersion(int32_t version) {
282 typedef FX_BOOL (CBC_CodeBase::*memptrtype)(int32_t);
283 memptrtype memptr = NULL;
284 switch (GetType()) {
285 case BC_QR_CODE:
286 memptr = (memptrtype)&CBC_QRCode::SetVersion;
287 break;
288 default:
289 break;
290 }
291 return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(version) : FALSE;
292 }
293 FX_BOOL CFX_Barcode::SetErrorCorrectionLevel(int32_t level) {
294 typedef FX_BOOL (CBC_CodeBase::*memptrtype)(int32_t);
295 memptrtype memptr = NULL;
296 switch (GetType()) {
297 case BC_QR_CODE:
298 memptr = (memptrtype)&CBC_QRCode::SetErrorCorrectionLevel;
299 break;
300 case BC_PDF417:
301 memptr = (memptrtype)&CBC_PDF417I::SetErrorCorrectionLevel;
302 break;
303 default:
304 return FALSE;
305 }
306 return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(level) : FALSE;
307 }
308 FX_BOOL CFX_Barcode::SetTruncated(FX_BOOL truncated) {
309 typedef void (CBC_CodeBase::*memptrtype)(FX_BOOL);
310 memptrtype memptr = NULL;
311 switch (GetType()) {
312 case BC_PDF417:
313 memptr = (memptrtype)&CBC_PDF417I::SetTruncated;
314 break;
315 default:
316 break;
317 }
318 return m_pBCEngine && memptr ? ((m_pBCEngine->*memptr)(truncated), TRUE)
319 : FALSE;
320 }
321
322 FX_BOOL CFX_Barcode::Encode(const CFX_WideStringC& contents,
323 FX_BOOL isDevice,
324 int32_t& e) {
325 if (!m_pBCEngine) {
326 return FALSE;
327 }
328 return m_pBCEngine->Encode(contents, isDevice, e);
329 }
330 FX_BOOL CFX_Barcode::RenderDevice(CFX_RenderDevice* device,
331 const CFX_Matrix* matrix,
332 int32_t& e) {
333 if (!m_pBCEngine) {
334 return FALSE;
335 }
336 return m_pBCEngine->RenderDevice(device, matrix, e);
337 }
338 FX_BOOL CFX_Barcode::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
339 if (!m_pBCEngine) {
340 return FALSE;
341 }
342 return m_pBCEngine->RenderBitmap(pOutBitmap, e);
343 }
344
345 CFX_WideString CFX_Barcode::Decode(uint8_t* buf,
346 int32_t width,
347 int32_t height,
348 int32_t& errorCode) {
349 for (BC_TYPE t = BC_CODE39; t <= BC_DATAMATRIX;
350 t = (BC_TYPE)((int32_t)t + 1)) {
351 CBC_CodeBase* pTmpEngine = FX_Barcode_CreateBarCodeEngineObject(t);
352 if (!pTmpEngine) {
353 continue;
354 }
355 CFX_WideString ret = pTmpEngine->Decode(buf, width, height, errorCode);
356 if (errorCode == BCExceptionNO) {
357 return ret;
358 }
359 }
360 errorCode = BCExceptionUnSupportedBarcode;
361 return CFX_WideString();
362 }
363 CFX_WideString CFX_Barcode::Decode(CFX_DIBitmap* pBitmap, int32_t& errorCode) {
364 for (BC_TYPE t = BC_CODE39; t <= BC_DATAMATRIX;
365 t = (BC_TYPE)((int32_t)t + 1)) {
366 CBC_CodeBase* pTmpEngine = FX_Barcode_CreateBarCodeEngineObject(t);
367 if (!pTmpEngine) {
368 continue;
369 }
370 CFX_WideString ret = pTmpEngine->Decode(pBitmap, errorCode);
371 if (errorCode == BCExceptionNO) {
372 return ret;
373 }
374 }
375 errorCode = BCExceptionUnSupportedBarcode;
376 return CFX_WideString();
377 }
OLDNEW
« no previous file with comments | « xfa/fwl/basewidget/fxmath_barcodeimp.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698