From 8320ee28f24615d1d619a5db1b7c235ea6f91dde Mon Sep 17 00:00:00 2001 From: dsinclair Date: Thu, 16 Jun 2016 11:01:19 -0700 Subject: Rename fxmath_barcodeimp to cfx_barcode Renames the files to make their contents clearer. Review-Url: https://codereview.chromium.org/2073793002 --- BUILD.gn | 4 +- xfa.gyp | 4 +- xfa/fwl/basewidget/cfx_barcode.cpp | 377 +++++++++++++++++++++++++++++++ xfa/fwl/basewidget/cfx_barcode.h | 63 ++++++ xfa/fwl/basewidget/fwl_barcodeimp.cpp | 2 +- xfa/fwl/basewidget/fxmath_barcodeimp.cpp | 377 ------------------------------- xfa/fwl/basewidget/fxmath_barcodeimp.h | 63 ------ 7 files changed, 445 insertions(+), 445 deletions(-) create mode 100644 xfa/fwl/basewidget/cfx_barcode.cpp create mode 100644 xfa/fwl/basewidget/cfx_barcode.h delete mode 100644 xfa/fwl/basewidget/fxmath_barcodeimp.cpp delete mode 100644 xfa/fwl/basewidget/fxmath_barcodeimp.h diff --git a/BUILD.gn b/BUILD.gn index dd927c0367..5446fc5b90 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -990,6 +990,8 @@ if (pdf_enable_xfa) { "xfa/fgas/localization/fgas_locale.cpp", "xfa/fgas/localization/fgas_locale.h", "xfa/fgas/localization/fgas_localeimp.h", + "xfa/fwl/basewidget/cfx_barcode.cpp", + "xfa/fwl/basewidget/cfx_barcode.h", "xfa/fwl/basewidget/fwl_barcodeimp.cpp", "xfa/fwl/basewidget/fwl_barcodeimp.h", "xfa/fwl/basewidget/fwl_caretimp.cpp", @@ -1018,8 +1020,6 @@ if (pdf_enable_xfa) { "xfa/fwl/basewidget/fwl_spinbuttonimp.h", "xfa/fwl/basewidget/fwl_tooltipctrlimp.cpp", "xfa/fwl/basewidget/fwl_tooltipctrlimp.h", - "xfa/fwl/basewidget/fxmath_barcodeimp.cpp", - "xfa/fwl/basewidget/fxmath_barcodeimp.h", "xfa/fwl/basewidget/ifwl_barcode.h", "xfa/fwl/basewidget/ifwl_caret.h", "xfa/fwl/basewidget/ifwl_checkbox.h", diff --git a/xfa.gyp b/xfa.gyp index 5683ab0cbc..133d65ecee 100644 --- a/xfa.gyp +++ b/xfa.gyp @@ -144,6 +144,8 @@ "xfa/fgas/localization/fgas_locale.cpp", "xfa/fgas/localization/fgas_locale.h", "xfa/fgas/localization/fgas_localeimp.h", + "xfa/fwl/basewidget/cfx_barcode.cpp", + "xfa/fwl/basewidget/cfx_barcode.h", "xfa/fwl/basewidget/fwl_barcodeimp.cpp", "xfa/fwl/basewidget/fwl_barcodeimp.h", "xfa/fwl/basewidget/fwl_caretimp.cpp", @@ -172,8 +174,6 @@ "xfa/fwl/basewidget/fwl_spinbuttonimp.h", "xfa/fwl/basewidget/fwl_tooltipctrlimp.cpp", "xfa/fwl/basewidget/fwl_tooltipctrlimp.h", - "xfa/fwl/basewidget/fxmath_barcodeimp.cpp", - "xfa/fwl/basewidget/fxmath_barcodeimp.h", "xfa/fwl/basewidget/ifwl_barcode.h", "xfa/fwl/basewidget/ifwl_caret.h", "xfa/fwl/basewidget/ifwl_checkbox.h", diff --git a/xfa/fwl/basewidget/cfx_barcode.cpp b/xfa/fwl/basewidget/cfx_barcode.cpp new file mode 100644 index 0000000000..795c834181 --- /dev/null +++ b/xfa/fwl/basewidget/cfx_barcode.cpp @@ -0,0 +1,377 @@ +// 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 + +#include "xfa/fwl/basewidget/cfx_barcode.h" + +#include "xfa/fxbarcode/cbc_codabar.h" +#include "xfa/fxbarcode/cbc_code128.h" +#include "xfa/fxbarcode/cbc_code39.h" +#include "xfa/fxbarcode/cbc_codebase.h" +#include "xfa/fxbarcode/cbc_datamatrix.h" +#include "xfa/fxbarcode/cbc_ean13.h" +#include "xfa/fxbarcode/cbc_ean8.h" +#include "xfa/fxbarcode/cbc_pdf417i.h" +#include "xfa/fxbarcode/cbc_qrcode.h" +#include "xfa/fxbarcode/cbc_upca.h" +#include "xfa/fxbarcode/utils.h" + +static CBC_CodeBase* FX_Barcode_CreateBarCodeEngineObject(BC_TYPE type) { + switch (type) { + case BC_CODE39: + return new CBC_Code39(); + case BC_CODABAR: + return new CBC_Codabar(); + case BC_CODE128: + return new CBC_Code128(BC_CODE128_B); + case BC_CODE128_B: + return new CBC_Code128(BC_CODE128_B); + case BC_CODE128_C: + return new CBC_Code128(BC_CODE128_C); + case BC_EAN8: + return new CBC_EAN8(); + case BC_UPCA: + return new CBC_UPCA(); + case BC_EAN13: + return new CBC_EAN13(); + case BC_QR_CODE: + return new CBC_QRCode(); + case BC_PDF417: + return new CBC_PDF417I(); + case BC_DATAMATRIX: + return new CBC_DataMatrix(); + case BC_UNKNOWN: + default: + return NULL; + } +} + +CFX_Barcode::CFX_Barcode() {} + +CFX_Barcode::~CFX_Barcode() { + delete m_pBCEngine; +} + +FX_BOOL CFX_Barcode::Create(BC_TYPE type) { + m_pBCEngine = FX_Barcode_CreateBarCodeEngineObject(type); + return m_pBCEngine != NULL; +} +BC_TYPE CFX_Barcode::GetType() { + return m_pBCEngine ? m_pBCEngine->GetType() : BC_UNKNOWN; +} +FX_BOOL CFX_Barcode::SetCharEncoding(BC_CHAR_ENCODING encoding) { + return m_pBCEngine ? m_pBCEngine->SetCharEncoding(encoding) : FALSE; +} +FX_BOOL CFX_Barcode::SetModuleHeight(int32_t moduleHeight) { + return m_pBCEngine ? m_pBCEngine->SetModuleHeight(moduleHeight) : FALSE; +} +FX_BOOL CFX_Barcode::SetModuleWidth(int32_t moduleWidth) { + return m_pBCEngine ? m_pBCEngine->SetModuleWidth(moduleWidth) : FALSE; +} +FX_BOOL CFX_Barcode::SetHeight(int32_t height) { + return m_pBCEngine ? m_pBCEngine->SetHeight(height) : FALSE; +} +FX_BOOL CFX_Barcode::SetWidth(int32_t width) { + return m_pBCEngine ? m_pBCEngine->SetWidth(width) : FALSE; +} +FX_BOOL CFX_Barcode::CheckContentValidity(const CFX_WideStringC& contents) { + switch (GetType()) { + case BC_CODE39: + case BC_CODABAR: + case BC_CODE128: + case BC_CODE128_B: + case BC_CODE128_C: + case BC_EAN8: + case BC_EAN13: + case BC_UPCA: + return m_pBCEngine + ? static_cast(m_pBCEngine) + ->CheckContentValidity(contents) + : TRUE; + default: + return TRUE; + } +} +FX_BOOL CFX_Barcode::SetPrintChecksum(FX_BOOL checksum) { + switch (GetType()) { + case BC_CODE39: + case BC_CODABAR: + case BC_CODE128: + case BC_CODE128_B: + case BC_CODE128_C: + case BC_EAN8: + case BC_EAN13: + case BC_UPCA: + return m_pBCEngine ? (static_cast(m_pBCEngine) + ->SetPrintChecksum(checksum), + TRUE) + : FALSE; + default: + return FALSE; + } +} +FX_BOOL CFX_Barcode::SetDataLength(int32_t length) { + switch (GetType()) { + case BC_CODE39: + case BC_CODABAR: + case BC_CODE128: + case BC_CODE128_B: + case BC_CODE128_C: + case BC_EAN8: + case BC_EAN13: + case BC_UPCA: + return m_pBCEngine ? (static_cast(m_pBCEngine) + ->SetDataLength(length), + TRUE) + : FALSE; + default: + return FALSE; + } +} +FX_BOOL CFX_Barcode::SetCalChecksum(int32_t state) { + switch (GetType()) { + case BC_CODE39: + case BC_CODABAR: + case BC_CODE128: + case BC_CODE128_B: + case BC_CODE128_C: + case BC_EAN8: + case BC_EAN13: + case BC_UPCA: + return m_pBCEngine ? (static_cast(m_pBCEngine) + ->SetCalChecksum(state), + TRUE) + : FALSE; + default: + return FALSE; + } +} +FX_BOOL CFX_Barcode::SetFont(CFX_Font* pFont) { + switch (GetType()) { + case BC_CODE39: + case BC_CODABAR: + case BC_CODE128: + case BC_CODE128_B: + case BC_CODE128_C: + case BC_EAN8: + case BC_EAN13: + case BC_UPCA: + return m_pBCEngine + ? static_cast(m_pBCEngine)->SetFont(pFont) + : FALSE; + default: + return FALSE; + } +} +FX_BOOL CFX_Barcode::SetFontSize(FX_FLOAT size) { + switch (GetType()) { + case BC_CODE39: + case BC_CODABAR: + case BC_CODE128: + case BC_CODE128_B: + case BC_CODE128_C: + case BC_EAN8: + case BC_EAN13: + case BC_UPCA: + return m_pBCEngine + ? (static_cast(m_pBCEngine)->SetFontSize(size), + TRUE) + : FALSE; + default: + return FALSE; + } +} +FX_BOOL CFX_Barcode::SetFontStyle(int32_t style) { + switch (GetType()) { + case BC_CODE39: + case BC_CODABAR: + case BC_CODE128: + case BC_CODE128_B: + case BC_CODE128_C: + case BC_EAN8: + case BC_EAN13: + case BC_UPCA: + return m_pBCEngine + ? (static_cast(m_pBCEngine)->SetFontStyle(style), + TRUE) + : FALSE; + default: + return FALSE; + } +} +FX_BOOL CFX_Barcode::SetFontColor(FX_ARGB color) { + switch (GetType()) { + case BC_CODE39: + case BC_CODABAR: + case BC_CODE128: + case BC_CODE128_B: + case BC_CODE128_C: + case BC_EAN8: + case BC_EAN13: + case BC_UPCA: + return m_pBCEngine + ? (static_cast(m_pBCEngine)->SetFontColor(color), + TRUE) + : FALSE; + default: + return FALSE; + } +} +FX_BOOL CFX_Barcode::SetTextLocation(BC_TEXT_LOC location) { + typedef FX_BOOL (CBC_CodeBase::*memptrtype)(BC_TEXT_LOC); + memptrtype memptr = NULL; + switch (GetType()) { + case BC_CODE39: + memptr = (memptrtype)&CBC_Code39::SetTextLocation; + break; + case BC_CODABAR: + memptr = (memptrtype)&CBC_Codabar::SetTextLocation; + break; + case BC_CODE128: + case BC_CODE128_B: + case BC_CODE128_C: + memptr = (memptrtype)&CBC_Code128::SetTextLocation; + break; + default: + break; + } + return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(location) : FALSE; +} +FX_BOOL CFX_Barcode::SetWideNarrowRatio(int32_t ratio) { + typedef FX_BOOL (CBC_CodeBase::*memptrtype)(int32_t); + memptrtype memptr = NULL; + switch (GetType()) { + case BC_CODE39: + memptr = (memptrtype)&CBC_Code39::SetWideNarrowRatio; + break; + case BC_CODABAR: + memptr = (memptrtype)&CBC_Codabar::SetWideNarrowRatio; + break; + default: + break; + } + return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(ratio) : FALSE; +} +FX_BOOL CFX_Barcode::SetStartChar(FX_CHAR start) { + typedef FX_BOOL (CBC_CodeBase::*memptrtype)(FX_CHAR); + memptrtype memptr = NULL; + switch (GetType()) { + case BC_CODABAR: + memptr = (memptrtype)&CBC_Codabar::SetStartChar; + break; + default: + break; + } + return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(start) : FALSE; +} +FX_BOOL CFX_Barcode::SetEndChar(FX_CHAR end) { + typedef FX_BOOL (CBC_CodeBase::*memptrtype)(FX_CHAR); + memptrtype memptr = NULL; + switch (GetType()) { + case BC_CODABAR: + memptr = (memptrtype)&CBC_Codabar::SetEndChar; + break; + default: + break; + } + return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(end) : FALSE; +} +FX_BOOL CFX_Barcode::SetVersion(int32_t version) { + typedef FX_BOOL (CBC_CodeBase::*memptrtype)(int32_t); + memptrtype memptr = NULL; + switch (GetType()) { + case BC_QR_CODE: + memptr = (memptrtype)&CBC_QRCode::SetVersion; + break; + default: + break; + } + return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(version) : FALSE; +} +FX_BOOL CFX_Barcode::SetErrorCorrectionLevel(int32_t level) { + typedef FX_BOOL (CBC_CodeBase::*memptrtype)(int32_t); + memptrtype memptr = NULL; + switch (GetType()) { + case BC_QR_CODE: + memptr = (memptrtype)&CBC_QRCode::SetErrorCorrectionLevel; + break; + case BC_PDF417: + memptr = (memptrtype)&CBC_PDF417I::SetErrorCorrectionLevel; + break; + default: + return FALSE; + } + return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(level) : FALSE; +} +FX_BOOL CFX_Barcode::SetTruncated(FX_BOOL truncated) { + typedef void (CBC_CodeBase::*memptrtype)(FX_BOOL); + memptrtype memptr = NULL; + switch (GetType()) { + case BC_PDF417: + memptr = (memptrtype)&CBC_PDF417I::SetTruncated; + break; + default: + break; + } + return m_pBCEngine && memptr ? ((m_pBCEngine->*memptr)(truncated), TRUE) + : FALSE; +} + +FX_BOOL CFX_Barcode::Encode(const CFX_WideStringC& contents, + FX_BOOL isDevice, + int32_t& e) { + if (!m_pBCEngine) { + return FALSE; + } + return m_pBCEngine->Encode(contents, isDevice, e); +} +FX_BOOL CFX_Barcode::RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matrix, + int32_t& e) { + if (!m_pBCEngine) { + return FALSE; + } + return m_pBCEngine->RenderDevice(device, matrix, e); +} +FX_BOOL CFX_Barcode::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { + if (!m_pBCEngine) { + return FALSE; + } + return m_pBCEngine->RenderBitmap(pOutBitmap, e); +} + +CFX_WideString CFX_Barcode::Decode(uint8_t* buf, + int32_t width, + int32_t height, + int32_t& errorCode) { + for (BC_TYPE t = BC_CODE39; t <= BC_DATAMATRIX; + t = (BC_TYPE)((int32_t)t + 1)) { + CBC_CodeBase* pTmpEngine = FX_Barcode_CreateBarCodeEngineObject(t); + if (!pTmpEngine) { + continue; + } + CFX_WideString ret = pTmpEngine->Decode(buf, width, height, errorCode); + if (errorCode == BCExceptionNO) { + return ret; + } + } + errorCode = BCExceptionUnSupportedBarcode; + return CFX_WideString(); +} +CFX_WideString CFX_Barcode::Decode(CFX_DIBitmap* pBitmap, int32_t& errorCode) { + for (BC_TYPE t = BC_CODE39; t <= BC_DATAMATRIX; + t = (BC_TYPE)((int32_t)t + 1)) { + CBC_CodeBase* pTmpEngine = FX_Barcode_CreateBarCodeEngineObject(t); + if (!pTmpEngine) { + continue; + } + CFX_WideString ret = pTmpEngine->Decode(pBitmap, errorCode); + if (errorCode == BCExceptionNO) { + return ret; + } + } + errorCode = BCExceptionUnSupportedBarcode; + return CFX_WideString(); +} diff --git a/xfa/fwl/basewidget/cfx_barcode.h b/xfa/fwl/basewidget/cfx_barcode.h new file mode 100644 index 0000000000..fbe16306bd --- /dev/null +++ b/xfa/fwl/basewidget/cfx_barcode.h @@ -0,0 +1,63 @@ +// 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 + +#ifndef XFA_FWL_BASEWIDGET_CFX_BARCODE_H_ +#define XFA_FWL_BASEWIDGET_CFX_BARCODE_H_ + +#include "core/fxcrt/include/fx_coordinates.h" +#include "core/fxcrt/include/fx_string.h" +#include "core/fxcrt/include/fx_system.h" +#include "core/fxge/include/fx_dib.h" +#include "xfa/fxbarcode/include/BC_Library.h" + +class CBC_CodeBase; +class CFX_Font; +class CFX_RenderDevice; +class CFX_Matrix; + +class CFX_Barcode { + public: + CFX_Barcode(); + ~CFX_Barcode(); + + FX_BOOL Create(BC_TYPE type); + BC_TYPE GetType(); + FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); + FX_BOOL RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matrix, + int32_t& e); + FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); + CFX_WideString Decode(uint8_t* buf, + int32_t width, + int32_t height, + int32_t& errorCode); + CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& errorCode); + FX_BOOL SetCharEncoding(BC_CHAR_ENCODING encoding); + FX_BOOL SetModuleHeight(int32_t moduleHeight); + FX_BOOL SetModuleWidth(int32_t moduleWidth); + FX_BOOL SetHeight(int32_t height); + FX_BOOL SetWidth(int32_t width); + FX_BOOL CheckContentValidity(const CFX_WideStringC& contents); + FX_BOOL SetPrintChecksum(FX_BOOL checksum); + FX_BOOL SetDataLength(int32_t length); + FX_BOOL SetCalChecksum(int32_t state); + FX_BOOL SetFont(CFX_Font* pFont); + FX_BOOL SetFontSize(FX_FLOAT size); + FX_BOOL SetFontStyle(int32_t style); + FX_BOOL SetFontColor(FX_ARGB color); + FX_BOOL SetTextLocation(BC_TEXT_LOC location); + FX_BOOL SetWideNarrowRatio(int32_t ratio); + FX_BOOL SetStartChar(FX_CHAR start); + FX_BOOL SetEndChar(FX_CHAR end); + FX_BOOL SetVersion(int32_t version); + FX_BOOL SetErrorCorrectionLevel(int32_t level); + FX_BOOL SetTruncated(FX_BOOL truncated); + + protected: + CBC_CodeBase* m_pBCEngine; +}; + +#endif // XFA_FWL_BASEWIDGET_CFX_BARCODE_H_ diff --git a/xfa/fwl/basewidget/fwl_barcodeimp.cpp b/xfa/fwl/basewidget/fwl_barcodeimp.cpp index 1789f9f075..70f5c73c3a 100644 --- a/xfa/fwl/basewidget/fwl_barcodeimp.cpp +++ b/xfa/fwl/basewidget/fwl_barcodeimp.cpp @@ -7,8 +7,8 @@ #include "xfa/fwl/basewidget/fwl_barcodeimp.h" #include "xfa/fgas/font/fgas_gefont.h" +#include "xfa/fwl/basewidget/cfx_barcode.h" #include "xfa/fwl/basewidget/fwl_editimp.h" -#include "xfa/fwl/basewidget/fxmath_barcodeimp.h" #include "xfa/fwl/core/cfwl_themepart.h" #include "xfa/fwl/core/fwl_noteimp.h" #include "xfa/fwl/core/fwl_widgetimp.h" diff --git a/xfa/fwl/basewidget/fxmath_barcodeimp.cpp b/xfa/fwl/basewidget/fxmath_barcodeimp.cpp deleted file mode 100644 index 1dc8afbaef..0000000000 --- a/xfa/fwl/basewidget/fxmath_barcodeimp.cpp +++ /dev/null @@ -1,377 +0,0 @@ -// 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 - -#include "xfa/fwl/basewidget/fxmath_barcodeimp.h" - -#include "xfa/fxbarcode/cbc_codabar.h" -#include "xfa/fxbarcode/cbc_code128.h" -#include "xfa/fxbarcode/cbc_code39.h" -#include "xfa/fxbarcode/cbc_codebase.h" -#include "xfa/fxbarcode/cbc_datamatrix.h" -#include "xfa/fxbarcode/cbc_ean13.h" -#include "xfa/fxbarcode/cbc_ean8.h" -#include "xfa/fxbarcode/cbc_pdf417i.h" -#include "xfa/fxbarcode/cbc_qrcode.h" -#include "xfa/fxbarcode/cbc_upca.h" -#include "xfa/fxbarcode/utils.h" - -static CBC_CodeBase* FX_Barcode_CreateBarCodeEngineObject(BC_TYPE type) { - switch (type) { - case BC_CODE39: - return new CBC_Code39(); - case BC_CODABAR: - return new CBC_Codabar(); - case BC_CODE128: - return new CBC_Code128(BC_CODE128_B); - case BC_CODE128_B: - return new CBC_Code128(BC_CODE128_B); - case BC_CODE128_C: - return new CBC_Code128(BC_CODE128_C); - case BC_EAN8: - return new CBC_EAN8(); - case BC_UPCA: - return new CBC_UPCA(); - case BC_EAN13: - return new CBC_EAN13(); - case BC_QR_CODE: - return new CBC_QRCode(); - case BC_PDF417: - return new CBC_PDF417I(); - case BC_DATAMATRIX: - return new CBC_DataMatrix(); - case BC_UNKNOWN: - default: - return NULL; - } -} - -CFX_Barcode::CFX_Barcode() {} - -CFX_Barcode::~CFX_Barcode() { - delete m_pBCEngine; -} - -FX_BOOL CFX_Barcode::Create(BC_TYPE type) { - m_pBCEngine = FX_Barcode_CreateBarCodeEngineObject(type); - return m_pBCEngine != NULL; -} -BC_TYPE CFX_Barcode::GetType() { - return m_pBCEngine ? m_pBCEngine->GetType() : BC_UNKNOWN; -} -FX_BOOL CFX_Barcode::SetCharEncoding(BC_CHAR_ENCODING encoding) { - return m_pBCEngine ? m_pBCEngine->SetCharEncoding(encoding) : FALSE; -} -FX_BOOL CFX_Barcode::SetModuleHeight(int32_t moduleHeight) { - return m_pBCEngine ? m_pBCEngine->SetModuleHeight(moduleHeight) : FALSE; -} -FX_BOOL CFX_Barcode::SetModuleWidth(int32_t moduleWidth) { - return m_pBCEngine ? m_pBCEngine->SetModuleWidth(moduleWidth) : FALSE; -} -FX_BOOL CFX_Barcode::SetHeight(int32_t height) { - return m_pBCEngine ? m_pBCEngine->SetHeight(height) : FALSE; -} -FX_BOOL CFX_Barcode::SetWidth(int32_t width) { - return m_pBCEngine ? m_pBCEngine->SetWidth(width) : FALSE; -} -FX_BOOL CFX_Barcode::CheckContentValidity(const CFX_WideStringC& contents) { - switch (GetType()) { - case BC_CODE39: - case BC_CODABAR: - case BC_CODE128: - case BC_CODE128_B: - case BC_CODE128_C: - case BC_EAN8: - case BC_EAN13: - case BC_UPCA: - return m_pBCEngine - ? static_cast(m_pBCEngine) - ->CheckContentValidity(contents) - : TRUE; - default: - return TRUE; - } -} -FX_BOOL CFX_Barcode::SetPrintChecksum(FX_BOOL checksum) { - switch (GetType()) { - case BC_CODE39: - case BC_CODABAR: - case BC_CODE128: - case BC_CODE128_B: - case BC_CODE128_C: - case BC_EAN8: - case BC_EAN13: - case BC_UPCA: - return m_pBCEngine ? (static_cast(m_pBCEngine) - ->SetPrintChecksum(checksum), - TRUE) - : FALSE; - default: - return FALSE; - } -} -FX_BOOL CFX_Barcode::SetDataLength(int32_t length) { - switch (GetType()) { - case BC_CODE39: - case BC_CODABAR: - case BC_CODE128: - case BC_CODE128_B: - case BC_CODE128_C: - case BC_EAN8: - case BC_EAN13: - case BC_UPCA: - return m_pBCEngine ? (static_cast(m_pBCEngine) - ->SetDataLength(length), - TRUE) - : FALSE; - default: - return FALSE; - } -} -FX_BOOL CFX_Barcode::SetCalChecksum(int32_t state) { - switch (GetType()) { - case BC_CODE39: - case BC_CODABAR: - case BC_CODE128: - case BC_CODE128_B: - case BC_CODE128_C: - case BC_EAN8: - case BC_EAN13: - case BC_UPCA: - return m_pBCEngine ? (static_cast(m_pBCEngine) - ->SetCalChecksum(state), - TRUE) - : FALSE; - default: - return FALSE; - } -} -FX_BOOL CFX_Barcode::SetFont(CFX_Font* pFont) { - switch (GetType()) { - case BC_CODE39: - case BC_CODABAR: - case BC_CODE128: - case BC_CODE128_B: - case BC_CODE128_C: - case BC_EAN8: - case BC_EAN13: - case BC_UPCA: - return m_pBCEngine - ? static_cast(m_pBCEngine)->SetFont(pFont) - : FALSE; - default: - return FALSE; - } -} -FX_BOOL CFX_Barcode::SetFontSize(FX_FLOAT size) { - switch (GetType()) { - case BC_CODE39: - case BC_CODABAR: - case BC_CODE128: - case BC_CODE128_B: - case BC_CODE128_C: - case BC_EAN8: - case BC_EAN13: - case BC_UPCA: - return m_pBCEngine - ? (static_cast(m_pBCEngine)->SetFontSize(size), - TRUE) - : FALSE; - default: - return FALSE; - } -} -FX_BOOL CFX_Barcode::SetFontStyle(int32_t style) { - switch (GetType()) { - case BC_CODE39: - case BC_CODABAR: - case BC_CODE128: - case BC_CODE128_B: - case BC_CODE128_C: - case BC_EAN8: - case BC_EAN13: - case BC_UPCA: - return m_pBCEngine - ? (static_cast(m_pBCEngine)->SetFontStyle(style), - TRUE) - : FALSE; - default: - return FALSE; - } -} -FX_BOOL CFX_Barcode::SetFontColor(FX_ARGB color) { - switch (GetType()) { - case BC_CODE39: - case BC_CODABAR: - case BC_CODE128: - case BC_CODE128_B: - case BC_CODE128_C: - case BC_EAN8: - case BC_EAN13: - case BC_UPCA: - return m_pBCEngine - ? (static_cast(m_pBCEngine)->SetFontColor(color), - TRUE) - : FALSE; - default: - return FALSE; - } -} -FX_BOOL CFX_Barcode::SetTextLocation(BC_TEXT_LOC location) { - typedef FX_BOOL (CBC_CodeBase::*memptrtype)(BC_TEXT_LOC); - memptrtype memptr = NULL; - switch (GetType()) { - case BC_CODE39: - memptr = (memptrtype)&CBC_Code39::SetTextLocation; - break; - case BC_CODABAR: - memptr = (memptrtype)&CBC_Codabar::SetTextLocation; - break; - case BC_CODE128: - case BC_CODE128_B: - case BC_CODE128_C: - memptr = (memptrtype)&CBC_Code128::SetTextLocation; - break; - default: - break; - } - return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(location) : FALSE; -} -FX_BOOL CFX_Barcode::SetWideNarrowRatio(int32_t ratio) { - typedef FX_BOOL (CBC_CodeBase::*memptrtype)(int32_t); - memptrtype memptr = NULL; - switch (GetType()) { - case BC_CODE39: - memptr = (memptrtype)&CBC_Code39::SetWideNarrowRatio; - break; - case BC_CODABAR: - memptr = (memptrtype)&CBC_Codabar::SetWideNarrowRatio; - break; - default: - break; - } - return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(ratio) : FALSE; -} -FX_BOOL CFX_Barcode::SetStartChar(FX_CHAR start) { - typedef FX_BOOL (CBC_CodeBase::*memptrtype)(FX_CHAR); - memptrtype memptr = NULL; - switch (GetType()) { - case BC_CODABAR: - memptr = (memptrtype)&CBC_Codabar::SetStartChar; - break; - default: - break; - } - return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(start) : FALSE; -} -FX_BOOL CFX_Barcode::SetEndChar(FX_CHAR end) { - typedef FX_BOOL (CBC_CodeBase::*memptrtype)(FX_CHAR); - memptrtype memptr = NULL; - switch (GetType()) { - case BC_CODABAR: - memptr = (memptrtype)&CBC_Codabar::SetEndChar; - break; - default: - break; - } - return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(end) : FALSE; -} -FX_BOOL CFX_Barcode::SetVersion(int32_t version) { - typedef FX_BOOL (CBC_CodeBase::*memptrtype)(int32_t); - memptrtype memptr = NULL; - switch (GetType()) { - case BC_QR_CODE: - memptr = (memptrtype)&CBC_QRCode::SetVersion; - break; - default: - break; - } - return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(version) : FALSE; -} -FX_BOOL CFX_Barcode::SetErrorCorrectionLevel(int32_t level) { - typedef FX_BOOL (CBC_CodeBase::*memptrtype)(int32_t); - memptrtype memptr = NULL; - switch (GetType()) { - case BC_QR_CODE: - memptr = (memptrtype)&CBC_QRCode::SetErrorCorrectionLevel; - break; - case BC_PDF417: - memptr = (memptrtype)&CBC_PDF417I::SetErrorCorrectionLevel; - break; - default: - return FALSE; - } - return m_pBCEngine && memptr ? (m_pBCEngine->*memptr)(level) : FALSE; -} -FX_BOOL CFX_Barcode::SetTruncated(FX_BOOL truncated) { - typedef void (CBC_CodeBase::*memptrtype)(FX_BOOL); - memptrtype memptr = NULL; - switch (GetType()) { - case BC_PDF417: - memptr = (memptrtype)&CBC_PDF417I::SetTruncated; - break; - default: - break; - } - return m_pBCEngine && memptr ? ((m_pBCEngine->*memptr)(truncated), TRUE) - : FALSE; -} - -FX_BOOL CFX_Barcode::Encode(const CFX_WideStringC& contents, - FX_BOOL isDevice, - int32_t& e) { - if (!m_pBCEngine) { - return FALSE; - } - return m_pBCEngine->Encode(contents, isDevice, e); -} -FX_BOOL CFX_Barcode::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) { - if (!m_pBCEngine) { - return FALSE; - } - return m_pBCEngine->RenderDevice(device, matrix, e); -} -FX_BOOL CFX_Barcode::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { - if (!m_pBCEngine) { - return FALSE; - } - return m_pBCEngine->RenderBitmap(pOutBitmap, e); -} - -CFX_WideString CFX_Barcode::Decode(uint8_t* buf, - int32_t width, - int32_t height, - int32_t& errorCode) { - for (BC_TYPE t = BC_CODE39; t <= BC_DATAMATRIX; - t = (BC_TYPE)((int32_t)t + 1)) { - CBC_CodeBase* pTmpEngine = FX_Barcode_CreateBarCodeEngineObject(t); - if (!pTmpEngine) { - continue; - } - CFX_WideString ret = pTmpEngine->Decode(buf, width, height, errorCode); - if (errorCode == BCExceptionNO) { - return ret; - } - } - errorCode = BCExceptionUnSupportedBarcode; - return CFX_WideString(); -} -CFX_WideString CFX_Barcode::Decode(CFX_DIBitmap* pBitmap, int32_t& errorCode) { - for (BC_TYPE t = BC_CODE39; t <= BC_DATAMATRIX; - t = (BC_TYPE)((int32_t)t + 1)) { - CBC_CodeBase* pTmpEngine = FX_Barcode_CreateBarCodeEngineObject(t); - if (!pTmpEngine) { - continue; - } - CFX_WideString ret = pTmpEngine->Decode(pBitmap, errorCode); - if (errorCode == BCExceptionNO) { - return ret; - } - } - errorCode = BCExceptionUnSupportedBarcode; - return CFX_WideString(); -} diff --git a/xfa/fwl/basewidget/fxmath_barcodeimp.h b/xfa/fwl/basewidget/fxmath_barcodeimp.h deleted file mode 100644 index 3a2c4b5434..0000000000 --- a/xfa/fwl/basewidget/fxmath_barcodeimp.h +++ /dev/null @@ -1,63 +0,0 @@ -// 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 - -#ifndef XFA_FWL_BASEWIDGET_FXMATH_BARCODEIMP_H_ -#define XFA_FWL_BASEWIDGET_FXMATH_BARCODEIMP_H_ - -#include "core/fxcrt/include/fx_coordinates.h" -#include "core/fxcrt/include/fx_string.h" -#include "core/fxcrt/include/fx_system.h" -#include "core/fxge/include/fx_dib.h" -#include "xfa/fxbarcode/include/BC_Library.h" - -class CBC_CodeBase; -class CFX_Font; -class CFX_RenderDevice; -class CFX_Matrix; - -class CFX_Barcode { - public: - CFX_Barcode(); - ~CFX_Barcode(); - - FX_BOOL Create(BC_TYPE type); - BC_TYPE GetType(); - FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); - FX_BOOL RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e); - FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); - CFX_WideString Decode(uint8_t* buf, - int32_t width, - int32_t height, - int32_t& errorCode); - CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& errorCode); - FX_BOOL SetCharEncoding(BC_CHAR_ENCODING encoding); - FX_BOOL SetModuleHeight(int32_t moduleHeight); - FX_BOOL SetModuleWidth(int32_t moduleWidth); - FX_BOOL SetHeight(int32_t height); - FX_BOOL SetWidth(int32_t width); - FX_BOOL CheckContentValidity(const CFX_WideStringC& contents); - FX_BOOL SetPrintChecksum(FX_BOOL checksum); - FX_BOOL SetDataLength(int32_t length); - FX_BOOL SetCalChecksum(int32_t state); - FX_BOOL SetFont(CFX_Font* pFont); - FX_BOOL SetFontSize(FX_FLOAT size); - FX_BOOL SetFontStyle(int32_t style); - FX_BOOL SetFontColor(FX_ARGB color); - FX_BOOL SetTextLocation(BC_TEXT_LOC location); - FX_BOOL SetWideNarrowRatio(int32_t ratio); - FX_BOOL SetStartChar(FX_CHAR start); - FX_BOOL SetEndChar(FX_CHAR end); - FX_BOOL SetVersion(int32_t version); - FX_BOOL SetErrorCorrectionLevel(int32_t level); - FX_BOOL SetTruncated(FX_BOOL truncated); - - protected: - CBC_CodeBase* m_pBCEngine; -}; - -#endif // XFA_FWL_BASEWIDGET_FXMATH_BARCODEIMP_H_ -- cgit v1.2.3