diff options
author | dsinclair <dsinclair@chromium.org> | 2016-12-08 10:06:32 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-12-08 10:06:33 -0800 |
commit | 447b1f3ffc7e0df233d15300bbf8a85ce2bc7278 (patch) | |
tree | adbd5fa0a3b63a666575636b4c5af9462e2f9c0b /xfa/fwl/cfx_barcode.cpp | |
parent | 64f4e25304dfd93651ac5c9d5379ed2fffbb993f (diff) | |
download | pdfium-447b1f3ffc7e0df233d15300bbf8a85ce2bc7278.tar.xz |
Move xfa/fwl/core to xfa/fwl.
The core/ directory in FWL no-longer provides any context. This Cl moves all
of the core/ files up to the fwl/ folder.
As well, the CFWL_EvtFoo files are renamed CFWL_EventFoo and the CFWL_MsgFoo
files are renamed CFWL_MessageFoo. The event and message preceed the type in
order to keep the files sorted together and to make it clear that they're all
related.
Review-Url: https://codereview.chromium.org/2559173002
Diffstat (limited to 'xfa/fwl/cfx_barcode.cpp')
-rw-r--r-- | xfa/fwl/cfx_barcode.cpp | 316 |
1 files changed, 316 insertions, 0 deletions
diff --git a/xfa/fwl/cfx_barcode.cpp b/xfa/fwl/cfx_barcode.cpp new file mode 100644 index 0000000000..7af3aa1888 --- /dev/null +++ b/xfa/fwl/cfx_barcode.cpp @@ -0,0 +1,316 @@ +// 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/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" + +namespace { + +CBC_CodeBase* 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 nullptr; + } +} + +} // namespace + +CFX_Barcode::CFX_Barcode() {} + +CFX_Barcode::~CFX_Barcode() {} + +bool CFX_Barcode::Create(BC_TYPE type) { + m_pBCEngine.reset(CreateBarCodeEngineObject(type)); + return !!m_pBCEngine; +} + +BC_TYPE CFX_Barcode::GetType() { + return m_pBCEngine ? m_pBCEngine->GetType() : BC_UNKNOWN; +} + +bool CFX_Barcode::SetCharEncoding(BC_CHAR_ENCODING encoding) { + return m_pBCEngine ? m_pBCEngine->SetCharEncoding(encoding) : false; +} + +bool CFX_Barcode::SetModuleHeight(int32_t moduleHeight) { + return m_pBCEngine ? m_pBCEngine->SetModuleHeight(moduleHeight) : false; +} + +bool CFX_Barcode::SetModuleWidth(int32_t moduleWidth) { + return m_pBCEngine ? m_pBCEngine->SetModuleWidth(moduleWidth) : false; +} + +bool CFX_Barcode::SetHeight(int32_t height) { + return m_pBCEngine ? m_pBCEngine->SetHeight(height) : false; +} + +bool CFX_Barcode::SetWidth(int32_t width) { + return m_pBCEngine ? m_pBCEngine->SetWidth(width) : false; +} + +bool CFX_Barcode::SetPrintChecksum(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<CBC_OneCode*>(m_pBCEngine.get()) + ->SetPrintChecksum(checksum), + true) + : false; + default: + return false; + } +} + +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<CBC_OneCode*>(m_pBCEngine.get()) + ->SetDataLength(length), + true) + : false; + default: + return false; + } +} + +bool CFX_Barcode::SetCalChecksum(bool 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<CBC_OneCode*>(m_pBCEngine.get()) + ->SetCalChecksum(state), + true) + : false; + default: + return false; + } +} + +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<CBC_OneCode*>(m_pBCEngine.get())->SetFont(pFont) + : false; + default: + return false; + } +} + +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<CBC_OneCode*>(m_pBCEngine.get()) + ->SetFontSize(size), + true) + : false; + default: + return false; + } +} + +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<CBC_OneCode*>(m_pBCEngine.get()) + ->SetFontColor(color), + true) + : false; + default: + return false; + } +} + +bool CFX_Barcode::SetTextLocation(BC_TEXT_LOC location) { + typedef bool (CBC_CodeBase::*memptrtype)(BC_TEXT_LOC); + memptrtype memptr = nullptr; + 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.get()->*memptr)(location) : false; +} + +bool CFX_Barcode::SetWideNarrowRatio(int32_t ratio) { + typedef bool (CBC_CodeBase::*memptrtype)(int32_t); + memptrtype memptr = nullptr; + 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.get()->*memptr)(ratio) : false; +} + +bool CFX_Barcode::SetStartChar(FX_CHAR start) { + typedef bool (CBC_CodeBase::*memptrtype)(FX_CHAR); + memptrtype memptr = nullptr; + switch (GetType()) { + case BC_CODABAR: + memptr = (memptrtype)&CBC_Codabar::SetStartChar; + break; + default: + break; + } + return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(start) : false; +} + +bool CFX_Barcode::SetEndChar(FX_CHAR end) { + typedef bool (CBC_CodeBase::*memptrtype)(FX_CHAR); + memptrtype memptr = nullptr; + switch (GetType()) { + case BC_CODABAR: + memptr = (memptrtype)&CBC_Codabar::SetEndChar; + break; + default: + break; + } + return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(end) : false; +} + +bool CFX_Barcode::SetVersion(int32_t version) { + typedef bool (CBC_CodeBase::*memptrtype)(int32_t); + memptrtype memptr = nullptr; + switch (GetType()) { + case BC_QR_CODE: + memptr = (memptrtype)&CBC_QRCode::SetVersion; + break; + default: + break; + } + return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(version) : false; +} + +bool CFX_Barcode::SetErrorCorrectionLevel(int32_t level) { + typedef bool (CBC_CodeBase::*memptrtype)(int32_t); + memptrtype memptr = nullptr; + 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.get()->*memptr)(level) : false; +} +bool CFX_Barcode::SetTruncated(bool truncated) { + typedef void (CBC_CodeBase::*memptrtype)(bool); + memptrtype memptr = nullptr; + switch (GetType()) { + case BC_PDF417: + memptr = (memptrtype)&CBC_PDF417I::SetTruncated; + break; + default: + break; + } + return m_pBCEngine && memptr ? ((m_pBCEngine.get()->*memptr)(truncated), true) + : false; +} + +bool CFX_Barcode::Encode(const CFX_WideStringC& contents, + bool isDevice, + int32_t& e) { + return m_pBCEngine && m_pBCEngine->Encode(contents, isDevice, e); +} + +bool CFX_Barcode::RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matrix, + int32_t& e) { + return m_pBCEngine && m_pBCEngine->RenderDevice(device, matrix, e); +} |