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 | 6 |
7 #include "xfa/fwl/basewidget/fxmath_barcodeimp.h" | 7 #include "xfa/fwl/basewidget/fxmath_barcodeimp.h" |
8 | 8 |
9 #include "xfa/fxbarcode/cbc_codabar.h" | 9 #include "xfa/fxbarcode/cbc_codabar.h" |
10 #include "xfa/fxbarcode/cbc_code128.h" | 10 #include "xfa/fxbarcode/cbc_code128.h" |
11 #include "xfa/fxbarcode/cbc_code39.h" | 11 #include "xfa/fxbarcode/cbc_code39.h" |
12 #include "xfa/fxbarcode/cbc_codebase.h" | 12 #include "xfa/fxbarcode/cbc_codebase.h" |
13 #include "xfa/fxbarcode/cbc_datamatrix.h" | 13 #include "xfa/fxbarcode/cbc_datamatrix.h" |
14 #include "xfa/fxbarcode/cbc_ean13.h" | 14 #include "xfa/fxbarcode/cbc_ean13.h" |
15 #include "xfa/fxbarcode/cbc_ean8.h" | 15 #include "xfa/fxbarcode/cbc_ean8.h" |
16 #include "xfa/fxbarcode/cbc_pdf417i.h" | 16 #include "xfa/fxbarcode/cbc_pdf417i.h" |
17 #include "xfa/fxbarcode/cbc_qrcode.h" | 17 #include "xfa/fxbarcode/cbc_qrcode.h" |
18 #include "xfa/fxbarcode/cbc_upca.h" | 18 #include "xfa/fxbarcode/cbc_upca.h" |
19 #include "xfa/fxbarcode/utils.h" | |
19 | 20 |
20 static CBC_CodeBase* FX_Barcode_CreateBarCodeEngineObject(BC_TYPE type) { | 21 static CBC_CodeBase* FX_Barcode_CreateBarCodeEngineObject(BC_TYPE type) { |
21 switch (type) { | 22 switch (type) { |
22 case BC_CODE39: | 23 case BC_CODE39: |
23 return new CBC_Code39(); | 24 return new CBC_Code39(); |
24 case BC_CODABAR: | 25 case BC_CODABAR: |
25 return new CBC_Codabar(); | 26 return new CBC_Codabar(); |
26 case BC_CODE128: | 27 case BC_CODE128: |
27 return new CBC_Code128(BC_CODE128_B); | 28 return new CBC_Code128(BC_CODE128_B); |
28 case BC_CODE128_B: | 29 case BC_CODE128_B: |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 switch (GetType()) { | 314 switch (GetType()) { |
314 case BC_PDF417: | 315 case BC_PDF417: |
315 memptr = (memptrtype)&CBC_PDF417I::SetTruncated; | 316 memptr = (memptrtype)&CBC_PDF417I::SetTruncated; |
316 break; | 317 break; |
317 default: | 318 default: |
318 break; | 319 break; |
319 } | 320 } |
320 return m_pBCEngine && memptr ? ((m_pBCEngine->*memptr)(truncated), TRUE) | 321 return m_pBCEngine && memptr ? ((m_pBCEngine->*memptr)(truncated), TRUE) |
321 : FALSE; | 322 : FALSE; |
322 } | 323 } |
323 #ifndef BCExceptionNO | 324 |
324 #define BCExceptionNO 0 | |
dsinclair
2016/05/16 18:04:24
These are all defined in fxbarcode/utils.h
| |
325 #endif | |
326 #ifndef BCExceptionFormatException | |
327 #define BCExceptionFormatException 8 | |
328 #endif | |
329 #ifndef BCExceptionUnSupportedBarcode | |
330 #define BCExceptionUnSupportedBarcode 18 | |
331 #endif | |
332 FX_BOOL CFX_Barcode::Encode(const CFX_WideStringC& contents, | 325 FX_BOOL CFX_Barcode::Encode(const CFX_WideStringC& contents, |
333 FX_BOOL isDevice, | 326 FX_BOOL isDevice, |
334 int32_t& e) { | 327 int32_t& e) { |
335 if (!m_pBCEngine) { | 328 if (!m_pBCEngine) { |
336 return FALSE; | 329 return FALSE; |
337 } | 330 } |
338 return m_pBCEngine->Encode(contents, isDevice, e); | 331 return m_pBCEngine->Encode(contents, isDevice, e); |
339 } | 332 } |
340 FX_BOOL CFX_Barcode::RenderDevice(CFX_RenderDevice* device, | 333 FX_BOOL CFX_Barcode::RenderDevice(CFX_RenderDevice* device, |
341 const CFX_Matrix* matrix, | 334 const CFX_Matrix* matrix, |
342 int32_t& e) { | 335 int32_t& e) { |
343 if (!m_pBCEngine) { | 336 if (!m_pBCEngine) { |
344 return FALSE; | 337 return FALSE; |
345 } | 338 } |
346 return m_pBCEngine->RenderDevice(device, matrix, e); | 339 return m_pBCEngine->RenderDevice(device, matrix, e); |
347 } | 340 } |
348 FX_BOOL CFX_Barcode::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { | 341 FX_BOOL CFX_Barcode::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { |
349 if (!m_pBCEngine) { | 342 if (!m_pBCEngine) { |
350 return FALSE; | 343 return FALSE; |
351 } | 344 } |
352 return m_pBCEngine->RenderBitmap(pOutBitmap, e); | 345 return m_pBCEngine->RenderBitmap(pOutBitmap, e); |
353 } | 346 } |
354 #define BC_TYPE_MIN BC_CODE39 | 347 |
355 #define BC_TYPE_MAX BC_DATAMATRIX | |
356 CFX_WideString CFX_Barcode::Decode(uint8_t* buf, | 348 CFX_WideString CFX_Barcode::Decode(uint8_t* buf, |
357 int32_t width, | 349 int32_t width, |
358 int32_t height, | 350 int32_t height, |
359 int32_t& errorCode) { | 351 int32_t& errorCode) { |
360 for (BC_TYPE t = BC_TYPE_MIN; t <= BC_TYPE_MAX; | 352 for (BC_TYPE t = BC_CODE39; t <= BC_DATAMATRIX; |
361 t = (BC_TYPE)((int32_t)t + 1)) { | 353 t = (BC_TYPE)((int32_t)t + 1)) { |
362 CBC_CodeBase* pTmpEngine = FX_Barcode_CreateBarCodeEngineObject(t); | 354 CBC_CodeBase* pTmpEngine = FX_Barcode_CreateBarCodeEngineObject(t); |
363 if (!pTmpEngine) { | 355 if (!pTmpEngine) { |
364 continue; | 356 continue; |
365 } | 357 } |
366 CFX_WideString ret = pTmpEngine->Decode(buf, width, height, errorCode); | 358 CFX_WideString ret = pTmpEngine->Decode(buf, width, height, errorCode); |
367 if (errorCode == BCExceptionNO) { | 359 if (errorCode == BCExceptionNO) { |
368 return ret; | 360 return ret; |
369 } | 361 } |
370 } | 362 } |
371 errorCode = BCExceptionUnSupportedBarcode; | 363 errorCode = BCExceptionUnSupportedBarcode; |
372 return CFX_WideString(); | 364 return CFX_WideString(); |
373 } | 365 } |
374 CFX_WideString CFX_Barcode::Decode(CFX_DIBitmap* pBitmap, int32_t& errorCode) { | 366 CFX_WideString CFX_Barcode::Decode(CFX_DIBitmap* pBitmap, int32_t& errorCode) { |
375 for (BC_TYPE t = BC_TYPE_MIN; t <= BC_TYPE_MAX; | 367 for (BC_TYPE t = BC_CODE39; t <= BC_DATAMATRIX; |
376 t = (BC_TYPE)((int32_t)t + 1)) { | 368 t = (BC_TYPE)((int32_t)t + 1)) { |
377 CBC_CodeBase* pTmpEngine = FX_Barcode_CreateBarCodeEngineObject(t); | 369 CBC_CodeBase* pTmpEngine = FX_Barcode_CreateBarCodeEngineObject(t); |
378 if (!pTmpEngine) { | 370 if (!pTmpEngine) { |
379 continue; | 371 continue; |
380 } | 372 } |
381 CFX_WideString ret = pTmpEngine->Decode(pBitmap, errorCode); | 373 CFX_WideString ret = pTmpEngine->Decode(pBitmap, errorCode); |
382 if (errorCode == BCExceptionNO) { | 374 if (errorCode == BCExceptionNO) { |
383 return ret; | 375 return ret; |
384 } | 376 } |
385 } | 377 } |
386 errorCode = BCExceptionUnSupportedBarcode; | 378 errorCode = BCExceptionUnSupportedBarcode; |
387 return CFX_WideString(); | 379 return CFX_WideString(); |
388 } | 380 } |
OLD | NEW |