From a98600aeb8d815c297834aa5006f5c3ea20dde6d Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 21 Mar 2016 15:15:56 -0400 Subject: Move xfa/include/fxbarcode/BC_Barcode.h to xfa/fxbarcode. This CL splits apart the larger header into individual class headers in the xfa/fxbarcode directory. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1816133002 . --- BUILD.gn | 25 +- fpdfsdk/fpdfxfa/DEPS | 3 + fpdfsdk/fpdfxfa/fpdfxfa_app.cpp | 2 +- xfa.gyp | 25 +- xfa/fwl/basewidget/fxmath_barcodeimp.cpp | 15 +- xfa/fwl/basewidget/fxmath_barcodeimp.h | 8 +- xfa/fxbarcode/BC_BarCode.cpp | 877 ---------------------------- xfa/fxbarcode/BC_Library.cpp | 70 +-- xfa/fxbarcode/cbc_codabar.cpp | 121 ++++ xfa/fxbarcode/cbc_codabar.h | 40 ++ xfa/fxbarcode/cbc_code128.cpp | 106 ++++ xfa/fxbarcode/cbc_code128.h | 37 ++ xfa/fxbarcode/cbc_code39.cpp | 124 ++++ xfa/fxbarcode/cbc_code39.h | 39 ++ xfa/fxbarcode/cbc_codebase.cpp | 58 ++ xfa/fxbarcode/cbc_codebase.h | 52 ++ xfa/fxbarcode/cbc_datamatrix.cpp | 83 +++ xfa/fxbarcode/cbc_datamatrix.h | 32 + xfa/fxbarcode/cbc_ean13.cpp | 114 ++++ xfa/fxbarcode/cbc_ean13.h | 36 ++ xfa/fxbarcode/cbc_ean8.cpp | 113 ++++ xfa/fxbarcode/cbc_ean8.h | 36 ++ xfa/fxbarcode/cbc_onecode.cpp | 77 +++ xfa/fxbarcode/cbc_onecode.h | 52 ++ xfa/fxbarcode/cbc_pdf417i.cpp | 91 +++ xfa/fxbarcode/cbc_pdf417i.h | 35 ++ xfa/fxbarcode/cbc_qrcode.cpp | 101 ++++ xfa/fxbarcode/cbc_qrcode.h | 35 ++ xfa/fxbarcode/cbc_upca.cpp | 116 ++++ xfa/fxbarcode/cbc_upca.h | 33 ++ xfa/fxbarcode/include/BC_Library.h | 38 ++ xfa/fxbarcode/oned/BC_OneDimWriter.h | 35 +- xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h | 16 +- xfa/fxbarcode/oned/BC_OnedCode128Reader.h | 4 +- xfa/fxbarcode/oned/BC_OnedCode128Writer.cpp | 6 - xfa/fxbarcode/oned/BC_OnedCode128Writer.h | 21 +- xfa/fxbarcode/oned/BC_OnedCode39Reader.cpp | 1 - xfa/fxbarcode/oned/BC_OnedCode39Reader.h | 16 +- xfa/fxbarcode/oned/BC_OnedCode39Writer.h | 10 +- xfa/fxbarcode/oned/BC_OnedEAN13Reader.h | 13 +- xfa/fxbarcode/oned/BC_OnedEAN13Writer.h | 16 +- xfa/fxbarcode/oned/BC_OnedEAN8Reader.h | 5 +- xfa/fxbarcode/oned/BC_OnedEAN8Writer.h | 13 +- xfa/fxbarcode/oned/BC_OnedUPCAReader.h | 18 +- xfa/fxbarcode/oned/BC_OnedUPCAWriter.h | 18 +- xfa/fxbarcode/pdf417/BC_PDF417Reader.h | 6 +- xfa/fxbarcode/pdf417/BC_PDF417Writer.h | 6 +- xfa/fxfa/app/xfa_ffbarcode.h | 2 +- xfa/fxfa/parser/xfa_objectacc_imp.cpp | 2 +- xfa/include/fwl/basewidget/fwl_barcode.h | 5 +- xfa/include/fwl/basewidget/fxmath_barcode.h | 12 +- xfa/include/fwl/lightwidget/barcode.h | 1 - xfa/include/fxbarcode/BC_BarCode.h | 257 -------- 53 files changed, 1792 insertions(+), 1285 deletions(-) create mode 100644 fpdfsdk/fpdfxfa/DEPS delete mode 100644 xfa/fxbarcode/BC_BarCode.cpp create mode 100644 xfa/fxbarcode/cbc_codabar.cpp create mode 100644 xfa/fxbarcode/cbc_codabar.h create mode 100644 xfa/fxbarcode/cbc_code128.cpp create mode 100644 xfa/fxbarcode/cbc_code128.h create mode 100644 xfa/fxbarcode/cbc_code39.cpp create mode 100644 xfa/fxbarcode/cbc_code39.h create mode 100644 xfa/fxbarcode/cbc_codebase.cpp create mode 100644 xfa/fxbarcode/cbc_codebase.h create mode 100644 xfa/fxbarcode/cbc_datamatrix.cpp create mode 100644 xfa/fxbarcode/cbc_datamatrix.h create mode 100644 xfa/fxbarcode/cbc_ean13.cpp create mode 100644 xfa/fxbarcode/cbc_ean13.h create mode 100644 xfa/fxbarcode/cbc_ean8.cpp create mode 100644 xfa/fxbarcode/cbc_ean8.h create mode 100644 xfa/fxbarcode/cbc_onecode.cpp create mode 100644 xfa/fxbarcode/cbc_onecode.h create mode 100644 xfa/fxbarcode/cbc_pdf417i.cpp create mode 100644 xfa/fxbarcode/cbc_pdf417i.h create mode 100644 xfa/fxbarcode/cbc_qrcode.cpp create mode 100644 xfa/fxbarcode/cbc_qrcode.h create mode 100644 xfa/fxbarcode/cbc_upca.cpp create mode 100644 xfa/fxbarcode/cbc_upca.h create mode 100644 xfa/fxbarcode/include/BC_Library.h delete mode 100644 xfa/include/fxbarcode/BC_BarCode.h diff --git a/BUILD.gn b/BUILD.gn index 904dc6929f..10b600efb0 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1029,7 +1029,6 @@ if (pdf_enable_xfa) { "xfa/fwl/theme/pushbuttontp.cpp", "xfa/fwl/theme/scrollbartp.cpp", "xfa/fwl/theme/widgettp.cpp", - "xfa/fxbarcode/BC_BarCode.cpp", "xfa/fxbarcode/BC_Binarizer.cpp", "xfa/fxbarcode/BC_Binarizer.h", "xfa/fxbarcode/BC_BinaryBitmap.cpp", @@ -1472,7 +1471,29 @@ if (pdf_enable_xfa) { "xfa/include/fwl/theme/scrollbartp.h", "xfa/include/fwl/theme/utils.h", "xfa/include/fwl/theme/widgettp.h", - "xfa/include/fxbarcode/BC_BarCode.h", + "xfa/fxbarcode/include/BC_Library.h", + "xfa/fxbarcode/cbc_codebase.h", + "xfa/fxbarcode/cbc_codebase.cpp", + "xfa/fxbarcode/cbc_onecode.h", + "xfa/fxbarcode/cbc_onecode.cpp", + "xfa/fxbarcode/cbc_code39.h", + "xfa/fxbarcode/cbc_code39.cpp", + "xfa/fxbarcode/cbc_codabar.h", + "xfa/fxbarcode/cbc_ean13.h", + "xfa/fxbarcode/cbc_ean13.cpp", + "xfa/fxbarcode/cbc_upca.h", + "xfa/fxbarcode/cbc_upca.cpp", + "xfa/fxbarcode/cbc_qrcode.h", + "xfa/fxbarcode/cbc_qrcode.cpp", + "xfa/fxbarcode/cbc_pdf417i.h", + "xfa/fxbarcode/cbc_pdf417i.cpp", + "xfa/fxbarcode/cbc_datamatrix.h", + "xfa/fxbarcode/cbc_datamatrix.cpp", + "xfa/fxbarcode/cbc_codabar.cpp", + "xfa/fxbarcode/cbc_code128.h", + "xfa/fxbarcode/cbc_code128.cpp", + "xfa/fxbarcode/cbc_ean8.h", + "xfa/fxbarcode/cbc_ean8.cpp", "xfa/include/fxfa/fxfa.h", "xfa/include/fxfa/fxfa_basic.h", "xfa/include/fxfa/fxfa_objectacc.h", diff --git a/fpdfsdk/fpdfxfa/DEPS b/fpdfsdk/fpdfxfa/DEPS new file mode 100644 index 0000000000..7f85f28f8b --- /dev/null +++ b/fpdfsdk/fpdfxfa/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + '+xfa/fxbarcode/include', +] diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp index 910cdc511e..ea3a1c97c4 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp @@ -11,7 +11,7 @@ #include "fpdfsdk/include/fsdk_mgr.h" #include "fpdfsdk/include/javascript/IJavaScript.h" #include "public/fpdf_formfill.h" -#include "xfa/include/fxbarcode/BC_BarCode.h" +#include "xfa/fxbarcode/include/BC_Library.h" CPDFXFA_App* CPDFXFA_App::g_pApp = NULL; diff --git a/xfa.gyp b/xfa.gyp index 6e4c420049..2185d6e2ef 100644 --- a/xfa.gyp +++ b/xfa.gyp @@ -97,7 +97,6 @@ "xfa/include/fwl/theme/scrollbartp.h", "xfa/include/fwl/theme/utils.h", "xfa/include/fwl/theme/widgettp.h", - "xfa/include/fxbarcode/BC_BarCode.h", "xfa/include/fxfa/fxfa.h", "xfa/include/fxfa/fxfa_basic.h", "xfa/include/fxfa/fxfa_objectacc.h", @@ -270,6 +269,28 @@ "xfa/fwl/theme/pushbuttontp.cpp", "xfa/fwl/theme/scrollbartp.cpp", "xfa/fwl/theme/widgettp.cpp", + "xfa/fxbarcode/cbc_code128.cpp", + "xfa/fxbarcode/cbc_code128.h", + "xfa/fxbarcode/cbc_code39.cpp", + "xfa/fxbarcode/cbc_code39.h", + "xfa/fxbarcode/cbc_codabar.cpp", + "xfa/fxbarcode/cbc_codabar.h", + "xfa/fxbarcode/cbc_codebase.cpp", + "xfa/fxbarcode/cbc_codebase.h", + "xfa/fxbarcode/cbc_datamatrix.cpp", + "xfa/fxbarcode/cbc_datamatrix.h", + "xfa/fxbarcode/cbc_ean8.cpp", + "xfa/fxbarcode/cbc_ena8.h", + "xfa/fxbarcode/cbc_ean13.cpp", + "xfa/fxbarcode/cbc_ean13.h", + "xfa/fxbarcode/cbc_onecode.cpp", + "xfa/fxbarcode/cbc_onecode.h", + "xfa/fxbarcode/cbc_pdf417i.cpp", + "xfa/fxbarcode/cbc_pdf417i.h", + "xfa/fxbarcode/cbc_qrcode.cpp", + "xfa/fxbarcode/cbc_qrcode.h", + "xfa/fxbarcode/cbc_upca.cpp", + "xfa/fxbarcode/cbc_upca.h", "xfa/fxbarcode/common/BC_CommonBitArray.cpp", "xfa/fxbarcode/common/BC_CommonBitMatrix.cpp", "xfa/fxbarcode/common/BC_CommonBitSource.cpp", @@ -344,6 +365,7 @@ "xfa/fxbarcode/datamatrix/BC_DefaultPlacement.h", "xfa/fxbarcode/datamatrix/BC_Encoder.h", "xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.h", + "xfa/fxbarcode/include/BC_Library.h", "xfa/fxbarcode/oned/BC_OnedCodaBarReader.cpp", "xfa/fxbarcode/oned/BC_OnedCodaBarWriter.cpp", "xfa/fxbarcode/oned/BC_OnedCode128Reader.cpp", @@ -480,7 +502,6 @@ "xfa/fxbarcode/qrcode/BC_QRGridSampler.h", "xfa/fxbarcode/qrcode/BC_FinderPatternInfo.cpp", "xfa/fxbarcode/qrcode/BC_FinderPatternInfo.h", - "xfa/fxbarcode/BC_BarCode.cpp", "xfa/fxbarcode/BC_Binarizer.cpp", "xfa/fxbarcode/BC_BinaryBitmap.cpp", "xfa/fxbarcode/BC_BufferedImageLuminanceSource.cpp", diff --git a/xfa/fwl/basewidget/fxmath_barcodeimp.cpp b/xfa/fwl/basewidget/fxmath_barcodeimp.cpp index c27805ef83..9792c6f7cc 100644 --- a/xfa/fwl/basewidget/fxmath_barcodeimp.cpp +++ b/xfa/fwl/basewidget/fxmath_barcodeimp.cpp @@ -6,6 +6,17 @@ #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" + static CBC_CodeBase* FX_Barcode_CreateBarCodeEngineObject(BC_TYPE type) { switch (type) { case BC_CODE39: @@ -42,7 +53,7 @@ CFX_Barcode::~CFX_Barcode() { m_pBCEngine = NULL; } } -FX_BOOL CFX_Barcode::Crreate(BC_TYPE type) { +FX_BOOL CFX_Barcode::Create(BC_TYPE type) { m_pBCEngine = FX_Barcode_CreateBarCodeEngineObject(type); return m_pBCEngine != NULL; } @@ -377,7 +388,7 @@ CFX_WideString CFX_Barcode::Decode(CFX_DIBitmap* pBitmap, int32_t& errorCode) { } IFX_Barcode* FX_Barcode_Create(BC_TYPE type) { CFX_Barcode* pBarcode = new CFX_Barcode; - if (pBarcode->Crreate(type)) { + if (pBarcode->Create(type)) { return pBarcode; } pBarcode->Release(); diff --git a/xfa/fwl/basewidget/fxmath_barcodeimp.h b/xfa/fwl/basewidget/fxmath_barcodeimp.h index a26761e0d7..077aeea952 100644 --- a/xfa/fwl/basewidget/fxmath_barcodeimp.h +++ b/xfa/fwl/basewidget/fxmath_barcodeimp.h @@ -7,13 +7,19 @@ #ifndef XFA_FWL_BASEWIDGET_FXMATH_BARCODEIMP_H_ #define XFA_FWL_BASEWIDGET_FXMATH_BARCODEIMP_H_ +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "xfa/fxbarcode/include/BC_Library.h" #include "xfa/include/fwl/basewidget/fxmath_barcode.h" +class CBC_CodeBase; + class CFX_Barcode : public IFX_Barcode { public: CFX_Barcode(); ~CFX_Barcode(); - FX_BOOL Crreate(BC_TYPE type); + + FX_BOOL Create(BC_TYPE type); virtual void Release(); virtual BC_TYPE GetType(); virtual FX_BOOL Encode(const CFX_WideStringC& contents, diff --git a/xfa/fxbarcode/BC_BarCode.cpp b/xfa/fxbarcode/BC_BarCode.cpp deleted file mode 100644 index 11f47b5578..0000000000 --- a/xfa/fxbarcode/BC_BarCode.cpp +++ /dev/null @@ -1,877 +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 -// Original code is licensed as follows: -/* - * Copyright 2011 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "xfa/fxbarcode/BC_Binarizer.h" -#include "xfa/fxbarcode/BC_BinaryBitmap.h" -#include "xfa/fxbarcode/BC_BinaryBitmap.h" -#include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" -#include "xfa/fxbarcode/BC_DecoderResult.h" -#include "xfa/fxbarcode/BC_LuminanceSource.h" -#include "xfa/fxbarcode/BC_Reader.h" -#include "xfa/fxbarcode/BC_ResultPoint.h" -#include "xfa/fxbarcode/BC_TwoDimWriter.h" -#include "xfa/fxbarcode/BC_UtilCodingConvert.h" -#include "xfa/fxbarcode/BC_Writer.h" -#include "xfa/fxbarcode/common/BC_CommonBitArray.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/common/BC_CommonDecoderResult.h" -#include "xfa/fxbarcode/common/BC_GlobalHistogramBinarizer.h" -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixReader.h" -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.h" -#include "xfa/fxbarcode/oned/BC_OneDReader.h" -#include "xfa/fxbarcode/oned/BC_OneDimReader.h" -#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" -#include "xfa/fxbarcode/oned/BC_OnedCodaBarReader.h" -#include "xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h" -#include "xfa/fxbarcode/oned/BC_OnedCode128Reader.h" -#include "xfa/fxbarcode/oned/BC_OnedCode128Writer.h" -#include "xfa/fxbarcode/oned/BC_OnedCode39Reader.h" -#include "xfa/fxbarcode/oned/BC_OnedCode39Writer.h" -#include "xfa/fxbarcode/oned/BC_OnedEAN13Reader.h" -#include "xfa/fxbarcode/oned/BC_OnedEAN13Writer.h" -#include "xfa/fxbarcode/oned/BC_OnedEAN8Reader.h" -#include "xfa/fxbarcode/oned/BC_OnedEAN8Writer.h" -#include "xfa/fxbarcode/oned/BC_OnedUPCAReader.h" -#include "xfa/fxbarcode/oned/BC_OnedUPCAWriter.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417BarcodeMetadata.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417BarcodeValue.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417BoundingBox.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Codeword.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417CodewordDecoder.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Common.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Compaction.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417DecodedBitStreamParser.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417DecodedBitStreamParser.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417DecodedBitStreamParser.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417DetectionResult.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417DetectionResultColumn.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417DetectionResultRowIndicatorColumn.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Detector.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417DetectorResult.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417DetectorResult.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417ECErrorCorrection.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusGF.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Reader.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417ScanningDecoder.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Writer.h" -#include "xfa/fxbarcode/qrcode/BC_QRCodeReader.h" -#include "xfa/fxbarcode/qrcode/BC_QRCodeWriter.h" - -CBC_CodeBase::CBC_CodeBase() {} -CBC_CodeBase::~CBC_CodeBase() {} -FX_BOOL CBC_CodeBase::SetCharEncoding(int32_t encoding) { - if (m_pBCWriter) { - return m_pBCWriter->SetCharEncoding(encoding); - } - return FALSE; -} -FX_BOOL CBC_CodeBase::SetModuleHeight(int32_t moduleHeight) { - if (m_pBCWriter) { - return m_pBCWriter->SetModuleHeight(moduleHeight); - } - return FALSE; -} -FX_BOOL CBC_CodeBase::SetModuleWidth(int32_t moduleWidth) { - if (m_pBCWriter) { - return m_pBCWriter->SetModuleWidth(moduleWidth); - } - return FALSE; -} -FX_BOOL CBC_CodeBase::SetHeight(int32_t height) { - if (m_pBCWriter) { - return m_pBCWriter->SetHeight(height); - } - return FALSE; -} -FX_BOOL CBC_CodeBase::SetWidth(int32_t width) { - if (m_pBCWriter) { - return m_pBCWriter->SetWidth(width); - } - return FALSE; -} -void CBC_CodeBase::SetBackgroundColor(FX_ARGB backgroundColor) { - if (m_pBCWriter) { - m_pBCWriter->SetBackgroundColor(backgroundColor); - } -} -void CBC_CodeBase::SetBarcodeColor(FX_ARGB foregroundColor) { - if (m_pBCWriter) { - m_pBCWriter->SetBarcodeColor(foregroundColor); - } -} -CBC_OneCode::CBC_OneCode() {} -CBC_OneCode::~CBC_OneCode() {} -FX_BOOL CBC_OneCode::CheckContentValidity(const CFX_WideStringC& contents) { - if (m_pBCWriter) { - return ((CBC_OneDimWriter*)m_pBCWriter)->CheckContentValidity(contents); - } - return FALSE; -} -CFX_WideString CBC_OneCode::FilterContents(const CFX_WideStringC& contents) { - CFX_WideString tmp; - if (m_pBCWriter == NULL) { - return tmp; - } - return ((CBC_OneDimWriter*)m_pBCWriter)->FilterContents(contents); -} -void CBC_OneCode::SetPrintChecksum(FX_BOOL checksum) { - if (m_pBCWriter) { - ((CBC_OneDimWriter*)m_pBCWriter)->SetPrintChecksum(checksum); - } -} -void CBC_OneCode::SetDataLength(int32_t length) { - if (m_pBCWriter) { - ((CBC_OneDimWriter*)m_pBCWriter)->SetDataLength(length); - } -} -void CBC_OneCode::SetCalChecksum(FX_BOOL calc) { - if (m_pBCWriter) { - ((CBC_OneDimWriter*)m_pBCWriter)->SetCalcChecksum(calc); - } -} -FX_BOOL CBC_OneCode::SetFont(CFX_Font* cFont) { - if (m_pBCWriter) { - return ((CBC_OneDimWriter*)m_pBCWriter)->SetFont(cFont); - } - return FALSE; -} -void CBC_OneCode::SetFontSize(FX_FLOAT size) { - if (m_pBCWriter) { - ((CBC_OneDimWriter*)m_pBCWriter)->SetFontSize(size); - } -} -void CBC_OneCode::SetFontStyle(int32_t style) { - if (m_pBCWriter) { - ((CBC_OneDimWriter*)m_pBCWriter)->SetFontStyle(style); - } -} -void CBC_OneCode::SetFontColor(FX_ARGB color) { - if (m_pBCWriter) { - ((CBC_OneDimWriter*)m_pBCWriter)->SetFontColor(color); - } -} -CBC_Code39::CBC_Code39() { - m_pBCReader = (CBC_Reader*)new (CBC_OnedCode39Reader); - m_pBCWriter = (CBC_Writer*)new (CBC_OnedCode39Writer); -} -CBC_Code39::CBC_Code39(FX_BOOL usingCheckDigit) { - m_pBCReader = (CBC_Reader*)new CBC_OnedCode39Reader(usingCheckDigit); - m_pBCWriter = (CBC_Writer*)new CBC_OnedCode39Writer; -} -CBC_Code39::CBC_Code39(FX_BOOL usingCheckDigit, FX_BOOL extendedMode) { - m_pBCReader = - (CBC_Reader*)new CBC_OnedCode39Reader(usingCheckDigit, extendedMode); - m_pBCWriter = (CBC_Writer*)new CBC_OnedCode39Writer(extendedMode); -} -CBC_Code39::~CBC_Code39() { - if (m_pBCReader) { - delete (m_pBCReader); - m_pBCReader = NULL; - } - if (m_pBCWriter) { - delete (m_pBCWriter); - m_pBCWriter = NULL; - } -} -FX_BOOL CBC_Code39::Encode(const CFX_WideStringC& contents, - FX_BOOL isDevice, - int32_t& e) { - if (contents.IsEmpty()) { - e = BCExceptionNoContents; - return FALSE; - } - BCFORMAT format = BCFORMAT_CODE_39; - int32_t outWidth = 0; - int32_t outHeight = 0; - CFX_WideString filtercontents = - ((CBC_OnedCode39Writer*)m_pBCWriter)->FilterContents(contents); - CFX_WideString renderContents = - ((CBC_OnedCode39Writer*)m_pBCWriter)->RenderTextContents(contents); - m_renderContents = renderContents; - CFX_ByteString byteString = filtercontents.UTF8Encode(); - uint8_t* data = static_cast(m_pBCWriter) - ->Encode(byteString, format, outWidth, outHeight, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderResult(renderContents, data, outWidth, isDevice, e); - FX_Free(data); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -FX_BOOL CBC_Code39::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e) { - CFX_WideString renderCon = ((CBC_OnedCode39Writer*)m_pBCWriter) - ->encodedContents(m_renderContents, e); - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderDeviceResult(device, matirx, renderCon, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -FX_BOOL CBC_Code39::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { - CFX_WideString renderCon = ((CBC_OnedCode39Writer*)m_pBCWriter) - ->encodedContents(m_renderContents, e); - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderBitmapResult(pOutBitmap, renderCon, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -CFX_WideString CBC_Code39::Decode(uint8_t* buf, - int32_t width, - int32_t hight, - int32_t& e) { - CFX_WideString str; - return str; -} -CFX_WideString CBC_Code39::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { - CBC_BufferedImageLuminanceSource source(pBitmap); - CBC_GlobalHistogramBinarizer binarizer(&source); - CBC_BinaryBitmap bitmap(&binarizer); - CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); - return CFX_WideString::FromUTF8(str, str.GetLength()); -} -FX_BOOL CBC_Code39::SetTextLocation(BC_TEXT_LOC location) { - if (m_pBCWriter) { - return ((CBC_OnedCode39Writer*)m_pBCWriter)->SetTextLocation(location); - } - return FALSE; -} -FX_BOOL CBC_Code39::SetWideNarrowRatio(int32_t ratio) { - if (m_pBCWriter) { - return ((CBC_OnedCode39Writer*)m_pBCWriter)->SetWideNarrowRatio(ratio); - } - return FALSE; -} -CBC_Codabar::CBC_Codabar() { - m_pBCReader = (CBC_Reader*)new (CBC_OnedCodaBarReader); - m_pBCWriter = (CBC_Writer*)new (CBC_OnedCodaBarWriter); -} -CBC_Codabar::~CBC_Codabar() { - if (m_pBCReader) { - delete (m_pBCReader); - m_pBCReader = NULL; - } - if (m_pBCWriter) { - delete (m_pBCWriter); - m_pBCWriter = NULL; - } -} -FX_BOOL CBC_Codabar::SetStartChar(FX_CHAR start) { - if (m_pBCWriter) { - return ((CBC_OnedCodaBarWriter*)m_pBCWriter)->SetStartChar(start); - } - return FALSE; -} -FX_BOOL CBC_Codabar::SetEndChar(FX_CHAR end) { - if (m_pBCWriter) { - return ((CBC_OnedCodaBarWriter*)m_pBCWriter)->SetEndChar(end); - } - return FALSE; -} -FX_BOOL CBC_Codabar::SetTextLocation(BC_TEXT_LOC location) { - return ((CBC_OnedCodaBarWriter*)m_pBCWriter)->SetTextLocation(location); -} -FX_BOOL CBC_Codabar::SetWideNarrowRatio(int32_t ratio) { - if (m_pBCWriter) { - return ((CBC_OnedCodaBarWriter*)m_pBCWriter)->SetWideNarrowRatio(ratio); - } - return FALSE; -} -FX_BOOL CBC_Codabar::Encode(const CFX_WideStringC& contents, - FX_BOOL isDevice, - int32_t& e) { - if (contents.IsEmpty()) { - e = BCExceptionNoContents; - return FALSE; - } - BCFORMAT format = BCFORMAT_CODABAR; - int32_t outWidth = 0; - int32_t outHeight = 0; - CFX_WideString filtercontents = - ((CBC_OneDimWriter*)m_pBCWriter)->FilterContents(contents); - CFX_ByteString byteString = filtercontents.UTF8Encode(); - m_renderContents = filtercontents; - uint8_t* data = static_cast(m_pBCWriter) - ->Encode(byteString, format, outWidth, outHeight, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderResult(filtercontents, data, outWidth, isDevice, e); - FX_Free(data); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -FX_BOOL CBC_Codabar::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e) { - CFX_WideString renderCon = - ((CBC_OnedCodaBarWriter*)m_pBCWriter)->encodedContents(m_renderContents); - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderDeviceResult(device, matirx, renderCon, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -FX_BOOL CBC_Codabar::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { - CFX_WideString renderCon = - ((CBC_OnedCodaBarWriter*)m_pBCWriter)->encodedContents(m_renderContents); - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderBitmapResult(pOutBitmap, renderCon, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -CFX_WideString CBC_Codabar::Decode(uint8_t* buf, - int32_t width, - int32_t hight, - int32_t& e) { - CFX_WideString str; - return str; -} -CFX_WideString CBC_Codabar::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { - CBC_BufferedImageLuminanceSource source(pBitmap); - CBC_GlobalHistogramBinarizer binarizer(&source); - CBC_BinaryBitmap bitmap(&binarizer); - CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); - return CFX_WideString::FromUTF8(str, str.GetLength()); -} -CBC_Code128::CBC_Code128(BC_TYPE type) { - m_pBCReader = (CBC_Reader*)new (CBC_OnedCode128Reader); - m_pBCWriter = (CBC_Writer*)new CBC_OnedCode128Writer(type); -} -CBC_Code128::~CBC_Code128() { - if (m_pBCReader) { - delete (m_pBCReader); - m_pBCReader = NULL; - } - if (m_pBCWriter) { - delete (m_pBCWriter); - m_pBCWriter = NULL; - } -} -FX_BOOL CBC_Code128::SetTextLocation(BC_TEXT_LOC location) { - if (m_pBCWriter) { - return ((CBC_OnedCode128Writer*)m_pBCWriter)->SetTextLocation(location); - } - return FALSE; -} -FX_BOOL CBC_Code128::Encode(const CFX_WideStringC& contents, - FX_BOOL isDevice, - int32_t& e) { - if (contents.IsEmpty()) { - e = BCExceptionNoContents; - return FALSE; - } - BCFORMAT format = BCFORMAT_CODE_128; - int32_t outWidth = 0; - int32_t outHeight = 0; - CFX_WideString content = contents; - if (contents.GetLength() % 2 && - ((CBC_OnedCode128Writer*)m_pBCWriter)->GetType() == BC_CODE128_C) { - content += '0'; - } - CFX_WideString encodeContents = - ((CBC_OnedCode128Writer*)m_pBCWriter)->FilterContents(content); - m_renderContents = encodeContents; - CFX_ByteString byteString = encodeContents.UTF8Encode(); - uint8_t* data = static_cast(m_pBCWriter) - ->Encode(byteString, format, outWidth, outHeight, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderResult(encodeContents, data, outWidth, isDevice, e); - FX_Free(data); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -FX_BOOL CBC_Code128::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e) { - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderDeviceResult(device, matirx, m_renderContents, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -FX_BOOL CBC_Code128::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderBitmapResult(pOutBitmap, m_renderContents, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -CFX_WideString CBC_Code128::Decode(uint8_t* buf, - int32_t width, - int32_t hight, - int32_t& e) { - CFX_WideString str; - return str; -} -CFX_WideString CBC_Code128::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { - CBC_BufferedImageLuminanceSource source(pBitmap); - CBC_GlobalHistogramBinarizer binarizer(&source); - CBC_BinaryBitmap bitmap(&binarizer); - CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); - return CFX_WideString::FromUTF8(str, str.GetLength()); -} -CBC_EAN8::CBC_EAN8() { - m_pBCReader = (CBC_Reader*)new (CBC_OnedEAN8Reader); - m_pBCWriter = (CBC_Writer*)new (CBC_OnedEAN8Writer); -} -CBC_EAN8::~CBC_EAN8() { - if (m_pBCReader) { - delete (m_pBCReader); - m_pBCReader = NULL; - } - if (m_pBCWriter) { - delete (m_pBCWriter); - m_pBCWriter = NULL; - } -} -CFX_WideString CBC_EAN8::Preprocess(const CFX_WideStringC& contents) { - CFX_WideString encodeContents = - ((CBC_OnedEAN8Writer*)m_pBCWriter)->FilterContents(contents); - int32_t length = encodeContents.GetLength(); - if (length <= 7) { - for (int32_t i = 0; i < 7 - length; i++) { - encodeContents = FX_WCHAR('0') + encodeContents; - } - CFX_ByteString byteString = encodeContents.UTF8Encode(); - int32_t checksum = - ((CBC_OnedEAN8Writer*)m_pBCWriter)->CalcChecksum(byteString); - encodeContents += FX_WCHAR(checksum - 0 + '0'); - } - if (length > 8) { - encodeContents = encodeContents.Mid(0, 8); - } - return encodeContents; -} -FX_BOOL CBC_EAN8::Encode(const CFX_WideStringC& contents, - FX_BOOL isDevice, - int32_t& e) { - if (contents.IsEmpty()) { - e = BCExceptionNoContents; - return FALSE; - } - BCFORMAT format = BCFORMAT_EAN_8; - int32_t outWidth = 0; - int32_t outHeight = 0; - CFX_WideString encodeContents = Preprocess(contents); - CFX_ByteString byteString = encodeContents.UTF8Encode(); - m_renderContents = encodeContents; - uint8_t* data = static_cast(m_pBCWriter) - ->Encode(byteString, format, outWidth, outHeight, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderResult(encodeContents, data, outWidth, isDevice, e); - FX_Free(data); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -FX_BOOL CBC_EAN8::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e) { - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderDeviceResult(device, matirx, m_renderContents, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -FX_BOOL CBC_EAN8::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderBitmapResult(pOutBitmap, m_renderContents, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -CFX_WideString CBC_EAN8::Decode(uint8_t* buf, - int32_t width, - int32_t hight, - int32_t& e) { - CFX_WideString str; - return str; -} -CFX_WideString CBC_EAN8::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { - CBC_BufferedImageLuminanceSource source(pBitmap); - CBC_GlobalHistogramBinarizer binarizer(&source); - CBC_BinaryBitmap bitmap(&binarizer); - CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); - return CFX_WideString::FromUTF8(str, str.GetLength()); -} -CBC_EAN13::CBC_EAN13() { - m_pBCReader = (CBC_Reader*)new (CBC_OnedEAN13Reader); - m_pBCWriter = (CBC_Writer*)new (CBC_OnedEAN13Writer); -} -CBC_EAN13::~CBC_EAN13() { - if (m_pBCReader) { - delete (m_pBCReader); - m_pBCReader = NULL; - } - if (m_pBCWriter) { - delete (m_pBCWriter); - m_pBCWriter = NULL; - } -} -CFX_WideString CBC_EAN13::Preprocess(const CFX_WideStringC& contents) { - CFX_WideString encodeContents = - ((CBC_OnedEAN8Writer*)m_pBCWriter)->FilterContents(contents); - int32_t length = encodeContents.GetLength(); - if (length <= 12) { - for (int32_t i = 0; i < 12 - length; i++) { - encodeContents = FX_WCHAR('0') + encodeContents; - } - CFX_ByteString byteString = encodeContents.UTF8Encode(); - int32_t checksum = - ((CBC_OnedEAN13Writer*)m_pBCWriter)->CalcChecksum(byteString); - byteString += checksum - 0 + '0'; - encodeContents = byteString.UTF8Decode(); - } - if (length > 13) { - encodeContents = encodeContents.Mid(0, 13); - } - return encodeContents; -} -FX_BOOL CBC_EAN13::Encode(const CFX_WideStringC& contents, - FX_BOOL isDevice, - int32_t& e) { - if (contents.IsEmpty()) { - e = BCExceptionNoContents; - return FALSE; - } - BCFORMAT format = BCFORMAT_EAN_13; - int32_t outWidth = 0; - int32_t outHeight = 0; - CFX_WideString encodeContents = Preprocess(contents); - CFX_ByteString byteString = encodeContents.UTF8Encode(); - m_renderContents = encodeContents; - uint8_t* data = static_cast(m_pBCWriter) - ->Encode(byteString, format, outWidth, outHeight, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderResult(encodeContents, data, outWidth, isDevice, e); - FX_Free(data); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -FX_BOOL CBC_EAN13::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e) { - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderDeviceResult(device, matirx, m_renderContents, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -FX_BOOL CBC_EAN13::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderBitmapResult(pOutBitmap, m_renderContents, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -CFX_WideString CBC_EAN13::Decode(uint8_t* buf, - int32_t width, - int32_t hight, - int32_t& e) { - CFX_WideString str; - return str; -} -CFX_WideString CBC_EAN13::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { - CBC_BufferedImageLuminanceSource source(pBitmap); - CBC_GlobalHistogramBinarizer binarizer(&source); - CBC_BinaryBitmap bitmap(&binarizer); - CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); - return CFX_WideString::FromUTF8(str, str.GetLength()); -} -CBC_UPCA::CBC_UPCA() { - m_pBCReader = (CBC_Reader*)new (CBC_OnedUPCAReader); - ((CBC_OnedUPCAReader*)m_pBCReader)->Init(); - m_pBCWriter = (CBC_Writer*)new (CBC_OnedUPCAWriter); -} -CBC_UPCA::~CBC_UPCA() { - if (m_pBCReader) { - delete (m_pBCReader); - m_pBCReader = NULL; - } - if (m_pBCWriter) { - delete (m_pBCWriter); - m_pBCWriter = NULL; - } -} -CFX_WideString CBC_UPCA::Preprocess(const CFX_WideStringC& contents) { - CFX_WideString encodeContents = - ((CBC_OnedEAN8Writer*)m_pBCWriter)->FilterContents(contents); - int32_t length = encodeContents.GetLength(); - if (length <= 11) { - for (int32_t i = 0; i < 11 - length; i++) { - encodeContents = FX_WCHAR('0') + encodeContents; - } - CFX_ByteString byteString = encodeContents.UTF8Encode(); - int32_t checksum = - ((CBC_OnedUPCAWriter*)m_pBCWriter)->CalcChecksum(byteString); - byteString += checksum - 0 + '0'; - encodeContents = byteString.UTF8Decode(); - } - if (length > 12) { - encodeContents = encodeContents.Mid(0, 12); - } - return encodeContents; -} -FX_BOOL CBC_UPCA::Encode(const CFX_WideStringC& contents, - FX_BOOL isDevice, - int32_t& e) { - if (contents.IsEmpty()) { - e = BCExceptionNoContents; - return FALSE; - } - BCFORMAT format = BCFORMAT_UPC_A; - int32_t outWidth = 0; - int32_t outHeight = 0; - CFX_WideString encodeContents = Preprocess(contents); - CFX_ByteString byteString = encodeContents.UTF8Encode(); - m_renderContents = encodeContents; - ((CBC_OnedUPCAWriter*)m_pBCWriter)->Init(); - uint8_t* data = static_cast(m_pBCWriter) - ->Encode(byteString, format, outWidth, outHeight, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderResult(encodeContents, data, outWidth, isDevice, e); - FX_Free(data); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -FX_BOOL CBC_UPCA::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e) { - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderDeviceResult(device, matirx, m_renderContents, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -FX_BOOL CBC_UPCA::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { - ((CBC_OneDimWriter*)m_pBCWriter) - ->RenderBitmapResult(pOutBitmap, m_renderContents, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -CFX_WideString CBC_UPCA::Decode(uint8_t* buf, - int32_t width, - int32_t hight, - int32_t& e) { - CFX_WideString str; - return str; -} -CFX_WideString CBC_UPCA::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { - CBC_BufferedImageLuminanceSource source(pBitmap); - CBC_GlobalHistogramBinarizer binarizer(&source); - CBC_BinaryBitmap bitmap(&binarizer); - CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); - return CFX_WideString::FromUTF8(str, str.GetLength()); -} -CBC_QRCode::CBC_QRCode() { - m_pBCReader = (CBC_Reader*)new (CBC_QRCodeReader); - ((CBC_QRCodeReader*)m_pBCReader)->Init(); - m_pBCWriter = (CBC_Writer*)new (CBC_QRCodeWriter); -} -CBC_QRCode::~CBC_QRCode() { - if (m_pBCReader) { - delete (m_pBCReader); - m_pBCReader = NULL; - } - if (m_pBCWriter) { - delete (m_pBCWriter); - m_pBCWriter = NULL; - } -} -FX_BOOL CBC_QRCode::SetVersion(int32_t version) { - if (version < 0 || version > 40) { - return FALSE; - } - if (m_pBCWriter == NULL) { - return FALSE; - } - return ((CBC_QRCodeWriter*)m_pBCWriter)->SetVersion(version); -} -FX_BOOL CBC_QRCode::SetErrorCorrectionLevel(int32_t level) { - if (level < 0 || level > 3) { - return FALSE; - } - if (m_pBCWriter == NULL) { - return FALSE; - } - return ((CBC_TwoDimWriter*)m_pBCWriter)->SetErrorCorrectionLevel(level); -} -FX_BOOL CBC_QRCode::Encode(const CFX_WideStringC& contents, - FX_BOOL isDevice, - int32_t& e) { - int32_t outWidth = 0; - int32_t outHeight = 0; - uint8_t* data = ((CBC_QRCodeWriter*)m_pBCWriter) - ->Encode(contents, ((CBC_QRCodeWriter*)m_pBCWriter) - ->GetErrorCorrectionLevel(), - outWidth, outHeight, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - ((CBC_TwoDimWriter*)m_pBCWriter)->RenderResult(data, outWidth, outHeight, e); - FX_Free(data); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -FX_BOOL CBC_QRCode::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e) { - ((CBC_TwoDimWriter*)m_pBCWriter)->RenderDeviceResult(device, matirx); - return TRUE; -} -FX_BOOL CBC_QRCode::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { - ((CBC_TwoDimWriter*)m_pBCWriter)->RenderBitmapResult(pOutBitmap, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -CFX_WideString CBC_QRCode::Decode(uint8_t* buf, - int32_t width, - int32_t hight, - int32_t& e) { - CFX_WideString str; - return str; -} -CFX_WideString CBC_QRCode::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { - CBC_BufferedImageLuminanceSource source(pBitmap); - CBC_GlobalHistogramBinarizer binarizer(&source); - CBC_BinaryBitmap bitmap(&binarizer); - CFX_ByteString retStr = m_pBCReader->Decode(&bitmap, 0, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); - return CFX_WideString::FromUTF8(retStr, retStr.GetLength()); -} -CBC_PDF417I::CBC_PDF417I() { - m_pBCReader = (CBC_Reader*)new (CBC_PDF417Reader); - m_pBCWriter = (CBC_Writer*)new (CBC_PDF417Writer); -} -CBC_PDF417I::~CBC_PDF417I() { - if (m_pBCReader) { - delete (m_pBCReader); - m_pBCReader = NULL; - } - if (m_pBCWriter) { - delete (m_pBCWriter); - m_pBCWriter = NULL; - } -} -FX_BOOL CBC_PDF417I::SetErrorCorrectionLevel(int32_t level) { - ((CBC_PDF417Writer*)m_pBCWriter)->SetErrorCorrectionLevel(level); - return TRUE; -} -void CBC_PDF417I::SetTruncated(FX_BOOL truncated) { - ((CBC_PDF417Writer*)m_pBCWriter)->SetTruncated(truncated); -} -FX_BOOL CBC_PDF417I::Encode(const CFX_WideStringC& contents, - FX_BOOL isDevice, - int32_t& e) { - int32_t outWidth = 0; - int32_t outHeight = 0; - uint8_t* data = ((CBC_PDF417Writer*)m_pBCWriter) - ->Encode(contents, outWidth, outHeight, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - ((CBC_TwoDimWriter*)m_pBCWriter)->RenderResult(data, outWidth, outHeight, e); - FX_Free(data); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -FX_BOOL CBC_PDF417I::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e) { - ((CBC_TwoDimWriter*)m_pBCWriter)->RenderDeviceResult(device, matirx); - return TRUE; -} -FX_BOOL CBC_PDF417I::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { - ((CBC_TwoDimWriter*)m_pBCWriter)->RenderBitmapResult(pOutBitmap, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -CFX_WideString CBC_PDF417I::Decode(uint8_t* buf, - int32_t width, - int32_t hight, - int32_t& e) { - CFX_WideString str; - return str; -} -CFX_WideString CBC_PDF417I::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { - CBC_BufferedImageLuminanceSource source(pBitmap); - CBC_GlobalHistogramBinarizer binarizer(&source); - CBC_BinaryBitmap bitmap(&binarizer); - CFX_ByteString bytestring = m_pBCReader->Decode(&bitmap, 0, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); - return CFX_WideString::FromUTF8(bytestring, bytestring.GetLength()); -} -CBC_DataMatrix::CBC_DataMatrix() { - m_pBCReader = (CBC_Reader*)new (CBC_DataMatrixReader); - ((CBC_DataMatrixReader*)m_pBCReader)->Init(); - m_pBCWriter = (CBC_Writer*)new (CBC_DataMatrixWriter); -} -CBC_DataMatrix::~CBC_DataMatrix() { - if (m_pBCReader) { - delete (m_pBCReader); - m_pBCReader = NULL; - } - if (m_pBCWriter) { - delete (m_pBCWriter); - m_pBCWriter = NULL; - } -} -FX_BOOL CBC_DataMatrix::Encode(const CFX_WideStringC& contents, - FX_BOOL isDevice, - int32_t& e) { - int32_t outWidth = 0; - int32_t outHeight = 0; - uint8_t* data = ((CBC_DataMatrixWriter*)m_pBCWriter) - ->Encode(contents, outWidth, outHeight, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - ((CBC_TwoDimWriter*)m_pBCWriter)->RenderResult(data, outWidth, outHeight, e); - FX_Free(data); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -FX_BOOL CBC_DataMatrix::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e) { - ((CBC_TwoDimWriter*)m_pBCWriter)->RenderDeviceResult(device, matirx); - return TRUE; -} -FX_BOOL CBC_DataMatrix::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { - ((CBC_TwoDimWriter*)m_pBCWriter)->RenderBitmapResult(pOutBitmap, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); - return TRUE; -} -CFX_WideString CBC_DataMatrix::Decode(uint8_t* buf, - int32_t width, - int32_t hight, - int32_t& e) { - CFX_WideString str; - return str; -} -CFX_WideString CBC_DataMatrix::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { - CBC_BufferedImageLuminanceSource source(pBitmap); - CBC_GlobalHistogramBinarizer binarizer(&source); - CBC_BinaryBitmap bitmap(&binarizer); - CFX_ByteString retStr = m_pBCReader->Decode(&bitmap, 0, e); - BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); - return CFX_WideString::FromUTF8(retStr, retStr.GetLength()); -} diff --git a/xfa/fxbarcode/BC_Library.cpp b/xfa/fxbarcode/BC_Library.cpp index d6da15cd29..311dd511fd 100644 --- a/xfa/fxbarcode/BC_Library.cpp +++ b/xfa/fxbarcode/BC_Library.cpp @@ -4,87 +4,22 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxbarcode/BC_Binarizer.h" -#include "xfa/fxbarcode/BC_BinaryBitmap.h" -#include "xfa/fxbarcode/BC_BinaryBitmap.h" -#include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" -#include "xfa/fxbarcode/BC_DecoderResult.h" -#include "xfa/fxbarcode/BC_Dimension.h" -#include "xfa/fxbarcode/BC_LuminanceSource.h" -#include "xfa/fxbarcode/BC_Reader.h" -#include "xfa/fxbarcode/BC_ResultPoint.h" -#include "xfa/fxbarcode/BC_TwoDimWriter.h" -#include "xfa/fxbarcode/BC_UtilCodingConvert.h" -#include "xfa/fxbarcode/BC_UtilCodingConvert.h" -#include "xfa/fxbarcode/BC_Writer.h" -#include "xfa/fxbarcode/common/BC_CommonBitArray.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/common/BC_CommonByteMatrix.h" -#include "xfa/fxbarcode/common/BC_CommonDecoderResult.h" -#include "xfa/fxbarcode/common/BC_GlobalHistogramBinarizer.h" +#include + #include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" -#include "xfa/fxbarcode/datamatrix/BC_ASCIIEncoder.h" -#include "xfa/fxbarcode/datamatrix/BC_Base256Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_C40Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixReader.h" -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h" #include "xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h" -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.h" -#include "xfa/fxbarcode/datamatrix/BC_DefaultPlacement.h" -#include "xfa/fxbarcode/datamatrix/BC_EdifactEncoder.h" -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_EncoderContext.h" #include "xfa/fxbarcode/datamatrix/BC_ErrorCorrection.h" -#include "xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.h" #include "xfa/fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h" -#include "xfa/fxbarcode/datamatrix/BC_TextEncoder.h" -#include "xfa/fxbarcode/datamatrix/BC_X12Encoder.h" -#include "xfa/fxbarcode/oned/BC_OneDReader.h" -#include "xfa/fxbarcode/oned/BC_OneDimReader.h" -#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" -#include "xfa/fxbarcode/oned/BC_OnedCodaBarReader.h" -#include "xfa/fxbarcode/oned/BC_OnedCode128Reader.h" -#include "xfa/fxbarcode/oned/BC_OnedCode128Writer.h" -#include "xfa/fxbarcode/oned/BC_OnedCode39Reader.h" -#include "xfa/fxbarcode/oned/BC_OnedCode39Writer.h" -#include "xfa/fxbarcode/oned/BC_OnedEAN13Reader.h" -#include "xfa/fxbarcode/oned/BC_OnedEAN13Writer.h" -#include "xfa/fxbarcode/oned/BC_OnedEAN8Reader.h" -#include "xfa/fxbarcode/oned/BC_OnedEAN8Writer.h" -#include "xfa/fxbarcode/oned/BC_OnedUPCAReader.h" -#include "xfa/fxbarcode/oned/BC_OnedUPCAWriter.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417BarcodeMetadata.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417BarcodeValue.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417BoundingBox.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Codeword.h" #include "xfa/fxbarcode/pdf417/BC_PDF417CodewordDecoder.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Common.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Compaction.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417DecodedBitStreamParser.h" #include "xfa/fxbarcode/pdf417/BC_PDF417DecodedBitStreamParser.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417DecodedBitStreamParser.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417DetectionResult.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417DetectionResultColumn.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417DetectionResultRowIndicatorColumn.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Detector.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417DetectorResult.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417DetectorResult.h" #include "xfa/fxbarcode/pdf417/BC_PDF417ECErrorCorrection.h" #include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusGF.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.h" #include "xfa/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Reader.h" #include "xfa/fxbarcode/pdf417/BC_PDF417ScanningDecoder.h" -#include "xfa/fxbarcode/qrcode/BC_QRCodeReader.h" -#include "xfa/fxbarcode/qrcode/BC_QRCodeWriter.h" #include "xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h" #include "xfa/fxbarcode/qrcode/BC_QRCoderMode.h" #include "xfa/fxbarcode/qrcode/BC_QRCoderVersion.h" #include "xfa/fxbarcode/qrcode/BC_QRDataMask.h" -#include "xfa/fxbarcode/qrcode/BC_QRDecodedBitStreamParser.h" void BC_Library_Init() { CBC_QRCoderErrorCorrectionLevel::Initialize(); @@ -96,6 +31,7 @@ void BC_Library_Init() { CBC_SymbolInfo::Initialize(); CBC_ErrorCorrection::Initialize(); CBC_PDF417HighLevelEncoder::Initialize(); + int32_t e = 0; CBC_PDF417ECModulusGF::Initialize(e); CBC_DecodedBitStreamPaser::Initialize(); diff --git a/xfa/fxbarcode/cbc_codabar.cpp b/xfa/fxbarcode/cbc_codabar.cpp new file mode 100644 index 0000000000..a7310ba1fc --- /dev/null +++ b/xfa/fxbarcode/cbc_codabar.cpp @@ -0,0 +1,121 @@ +// Copyright 2016 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 +/* + * Copyright 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "xfa/fxbarcode/cbc_codabar.h" + +#include "xfa/fxbarcode/BC_BinaryBitmap.h" +#include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" +#include "xfa/fxbarcode/common/BC_GlobalHistogramBinarizer.h" +#include "xfa/fxbarcode/oned/BC_OnedCodaBarReader.h" +#include "xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h" + +CBC_Codabar::CBC_Codabar() { + m_pBCReader = (CBC_Reader*)new (CBC_OnedCodaBarReader); + m_pBCWriter = (CBC_Writer*)new (CBC_OnedCodaBarWriter); +} + +CBC_Codabar::~CBC_Codabar() { + delete (m_pBCReader); + delete (m_pBCWriter); +} + +FX_BOOL CBC_Codabar::SetStartChar(FX_CHAR start) { + if (m_pBCWriter) + return ((CBC_OnedCodaBarWriter*)m_pBCWriter)->SetStartChar(start); + return FALSE; +} + +FX_BOOL CBC_Codabar::SetEndChar(FX_CHAR end) { + if (m_pBCWriter) + return ((CBC_OnedCodaBarWriter*)m_pBCWriter)->SetEndChar(end); + return FALSE; +} + +FX_BOOL CBC_Codabar::SetTextLocation(BC_TEXT_LOC location) { + return ((CBC_OnedCodaBarWriter*)m_pBCWriter)->SetTextLocation(location); +} + +FX_BOOL CBC_Codabar::SetWideNarrowRatio(int32_t ratio) { + if (m_pBCWriter) + return ((CBC_OnedCodaBarWriter*)m_pBCWriter)->SetWideNarrowRatio(ratio); + return FALSE; +} + +FX_BOOL CBC_Codabar::Encode(const CFX_WideStringC& contents, + FX_BOOL isDevice, + int32_t& e) { + if (contents.IsEmpty()) { + e = BCExceptionNoContents; + return FALSE; + } + BCFORMAT format = BCFORMAT_CODABAR; + int32_t outWidth = 0; + int32_t outHeight = 0; + CFX_WideString filtercontents = + ((CBC_OneDimWriter*)m_pBCWriter)->FilterContents(contents); + CFX_ByteString byteString = filtercontents.UTF8Encode(); + m_renderContents = filtercontents; + uint8_t* data = static_cast(m_pBCWriter) + ->Encode(byteString, format, outWidth, outHeight, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderResult(filtercontents, data, outWidth, isDevice, e); + FX_Free(data); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +FX_BOOL CBC_Codabar::RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e) { + CFX_WideString renderCon = + ((CBC_OnedCodaBarWriter*)m_pBCWriter)->encodedContents(m_renderContents); + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderDeviceResult(device, matirx, renderCon, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +FX_BOOL CBC_Codabar::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { + CFX_WideString renderCon = + ((CBC_OnedCodaBarWriter*)m_pBCWriter)->encodedContents(m_renderContents); + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderBitmapResult(pOutBitmap, renderCon, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +CFX_WideString CBC_Codabar::Decode(uint8_t* buf, + int32_t width, + int32_t hight, + int32_t& e) { + CFX_WideString str; + return str; +} + +CFX_WideString CBC_Codabar::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { + CBC_BufferedImageLuminanceSource source(pBitmap); + CBC_GlobalHistogramBinarizer binarizer(&source); + CBC_BinaryBitmap bitmap(&binarizer); + CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); + return CFX_WideString::FromUTF8(str, str.GetLength()); +} diff --git a/xfa/fxbarcode/cbc_codabar.h b/xfa/fxbarcode/cbc_codabar.h new file mode 100644 index 0000000000..8da2383fc5 --- /dev/null +++ b/xfa/fxbarcode/cbc_codabar.h @@ -0,0 +1,40 @@ +// Copyright 2016 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_FXBARCODE_CBC_CODABAR_H_ +#define XFA_FXBARCODE_CBC_CODABAR_H_ + +#include "core/include/fxcrt/fx_coordinates.h" +#include "core/include/fxcrt/fx_system.h" +#include "core/include/fxge/fx_dib.h" +#include "xfa/fxbarcode/cbc_onecode.h" + +class CBC_Codabar : public CBC_OneCode { + public: + CBC_Codabar(); + ~CBC_Codabar() override; + + FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e) override; + CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e) override; + CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e) override; + + FX_BOOL RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e) override; + FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override; + + BC_TYPE GetType() override { return BC_CODABAR; } + + FX_BOOL SetStartChar(FX_CHAR start); + FX_BOOL SetEndChar(FX_CHAR end); + FX_BOOL SetTextLocation(BC_TEXT_LOC location); + FX_BOOL SetWideNarrowRatio(int32_t ratio); + + private: + CFX_WideString m_renderContents; +}; + +#endif // XFA_FXBARCODE_CBC_CODABAR_H_ diff --git a/xfa/fxbarcode/cbc_code128.cpp b/xfa/fxbarcode/cbc_code128.cpp new file mode 100644 index 0000000000..e585de302c --- /dev/null +++ b/xfa/fxbarcode/cbc_code128.cpp @@ -0,0 +1,106 @@ +// Copyright 2016 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 +/* + * Copyright 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "xfa/fxbarcode/cbc_code128.h" + +#include "xfa/fxbarcode/BC_BinaryBitmap.h" +#include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" +#include "xfa/fxbarcode/common/BC_GlobalHistogramBinarizer.h" +#include "xfa/fxbarcode/oned/BC_OnedCode128Reader.h" +#include "xfa/fxbarcode/oned/BC_OnedCode128Writer.h" + +CBC_Code128::CBC_Code128(BC_TYPE type) { + m_pBCReader = (CBC_Reader*)new (CBC_OnedCode128Reader); + m_pBCWriter = (CBC_Writer*)new CBC_OnedCode128Writer(type); +} + +CBC_Code128::~CBC_Code128() { + delete (m_pBCReader); + delete (m_pBCWriter); +} + +FX_BOOL CBC_Code128::SetTextLocation(BC_TEXT_LOC location) { + if (m_pBCWriter) + return ((CBC_OnedCode128Writer*)m_pBCWriter)->SetTextLocation(location); + return FALSE; +} + +FX_BOOL CBC_Code128::Encode(const CFX_WideStringC& contents, + FX_BOOL isDevice, + int32_t& e) { + if (contents.IsEmpty()) { + e = BCExceptionNoContents; + return FALSE; + } + BCFORMAT format = BCFORMAT_CODE_128; + int32_t outWidth = 0; + int32_t outHeight = 0; + CFX_WideString content = contents; + if (contents.GetLength() % 2 && + ((CBC_OnedCode128Writer*)m_pBCWriter)->GetType() == BC_CODE128_C) { + content += '0'; + } + CFX_WideString encodeContents = + ((CBC_OnedCode128Writer*)m_pBCWriter)->FilterContents(content); + m_renderContents = encodeContents; + CFX_ByteString byteString = encodeContents.UTF8Encode(); + uint8_t* data = static_cast(m_pBCWriter) + ->Encode(byteString, format, outWidth, outHeight, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderResult(encodeContents, data, outWidth, isDevice, e); + FX_Free(data); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +FX_BOOL CBC_Code128::RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e) { + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderDeviceResult(device, matirx, m_renderContents, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +FX_BOOL CBC_Code128::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderBitmapResult(pOutBitmap, m_renderContents, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +CFX_WideString CBC_Code128::Decode(uint8_t* buf, + int32_t width, + int32_t hight, + int32_t& e) { + CFX_WideString str; + return str; +} + +CFX_WideString CBC_Code128::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { + CBC_BufferedImageLuminanceSource source(pBitmap); + CBC_GlobalHistogramBinarizer binarizer(&source); + CBC_BinaryBitmap bitmap(&binarizer); + CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); + return CFX_WideString::FromUTF8(str, str.GetLength()); +} diff --git a/xfa/fxbarcode/cbc_code128.h b/xfa/fxbarcode/cbc_code128.h new file mode 100644 index 0000000000..3f12e1bc75 --- /dev/null +++ b/xfa/fxbarcode/cbc_code128.h @@ -0,0 +1,37 @@ +// Copyright 2016 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_FXBARCODE_CBC_CODE128_H_ +#define XFA_FXBARCODE_CBC_CODE128_H_ + +#include "core/include/fxcrt/fx_coordinates.h" +#include "core/include/fxcrt/fx_system.h" +#include "core/include/fxge/fx_dib.h" +#include "xfa/fxbarcode/cbc_onecode.h" + +class CBC_Code128 : public CBC_OneCode { + public: + explicit CBC_Code128(BC_TYPE type); + virtual ~CBC_Code128(); + + FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e) override; + CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e) override; + CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e) override; + + FX_BOOL RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e) override; + FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override; + + BC_TYPE GetType() override { return BC_CODE128; } + + FX_BOOL SetTextLocation(BC_TEXT_LOC loction); + + private: + CFX_WideString m_renderContents; +}; + +#endif // XFA_FXBARCODE_CBC_CODE128_H_ diff --git a/xfa/fxbarcode/cbc_code39.cpp b/xfa/fxbarcode/cbc_code39.cpp new file mode 100644 index 0000000000..a0e3d17fc1 --- /dev/null +++ b/xfa/fxbarcode/cbc_code39.cpp @@ -0,0 +1,124 @@ +// Copyright 2016 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 +/* + * Copyright 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "xfa/fxbarcode/cbc_code39.h" + +#include "xfa/fxbarcode/BC_BinaryBitmap.h" +#include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" +#include "xfa/fxbarcode/common/BC_GlobalHistogramBinarizer.h" +#include "xfa/fxbarcode/oned/BC_OnedCode39Reader.h" +#include "xfa/fxbarcode/oned/BC_OnedCode39Writer.h" + +CBC_Code39::CBC_Code39() { + m_pBCReader = (CBC_Reader*)new (CBC_OnedCode39Reader); + m_pBCWriter = (CBC_Writer*)new (CBC_OnedCode39Writer); +} + +CBC_Code39::CBC_Code39(FX_BOOL usingCheckDigit) { + m_pBCReader = (CBC_Reader*)new CBC_OnedCode39Reader(usingCheckDigit); + m_pBCWriter = (CBC_Writer*)new CBC_OnedCode39Writer; +} + +CBC_Code39::CBC_Code39(FX_BOOL usingCheckDigit, FX_BOOL extendedMode) { + m_pBCReader = + (CBC_Reader*)new CBC_OnedCode39Reader(usingCheckDigit, extendedMode); + m_pBCWriter = (CBC_Writer*)new CBC_OnedCode39Writer(extendedMode); +} + +CBC_Code39::~CBC_Code39() { + delete (m_pBCReader); + delete (m_pBCWriter); +} + +FX_BOOL CBC_Code39::Encode(const CFX_WideStringC& contents, + FX_BOOL isDevice, + int32_t& e) { + if (contents.IsEmpty()) { + e = BCExceptionNoContents; + return FALSE; + } + BCFORMAT format = BCFORMAT_CODE_39; + int32_t outWidth = 0; + int32_t outHeight = 0; + CFX_WideString filtercontents = + ((CBC_OnedCode39Writer*)m_pBCWriter)->FilterContents(contents); + CFX_WideString renderContents = + ((CBC_OnedCode39Writer*)m_pBCWriter)->RenderTextContents(contents); + m_renderContents = renderContents; + CFX_ByteString byteString = filtercontents.UTF8Encode(); + uint8_t* data = static_cast(m_pBCWriter) + ->Encode(byteString, format, outWidth, outHeight, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderResult(renderContents, data, outWidth, isDevice, e); + FX_Free(data); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +FX_BOOL CBC_Code39::RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e) { + CFX_WideString renderCon = ((CBC_OnedCode39Writer*)m_pBCWriter) + ->encodedContents(m_renderContents, e); + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderDeviceResult(device, matirx, renderCon, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +FX_BOOL CBC_Code39::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { + CFX_WideString renderCon = ((CBC_OnedCode39Writer*)m_pBCWriter) + ->encodedContents(m_renderContents, e); + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderBitmapResult(pOutBitmap, renderCon, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +CFX_WideString CBC_Code39::Decode(uint8_t* buf, + int32_t width, + int32_t hight, + int32_t& e) { + CFX_WideString str; + return str; +} + +CFX_WideString CBC_Code39::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { + CBC_BufferedImageLuminanceSource source(pBitmap); + CBC_GlobalHistogramBinarizer binarizer(&source); + CBC_BinaryBitmap bitmap(&binarizer); + CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); + return CFX_WideString::FromUTF8(str, str.GetLength()); +} + +FX_BOOL CBC_Code39::SetTextLocation(BC_TEXT_LOC location) { + if (m_pBCWriter) + return ((CBC_OnedCode39Writer*)m_pBCWriter)->SetTextLocation(location); + return FALSE; +} + +FX_BOOL CBC_Code39::SetWideNarrowRatio(int32_t ratio) { + if (m_pBCWriter) + return ((CBC_OnedCode39Writer*)m_pBCWriter)->SetWideNarrowRatio(ratio); + return FALSE; +} diff --git a/xfa/fxbarcode/cbc_code39.h b/xfa/fxbarcode/cbc_code39.h new file mode 100644 index 0000000000..9e296650a8 --- /dev/null +++ b/xfa/fxbarcode/cbc_code39.h @@ -0,0 +1,39 @@ +// Copyright 2016 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_FXBARCODE_CBC_CODE39_H_ +#define XFA_FXBARCODE_CBC_CODE39_H_ + +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "core/include/fxge/fx_dib.h" +#include "xfa/fxbarcode/cbc_onecode.h" + +class CBC_Code39 : public CBC_OneCode { + public: + CBC_Code39(); + explicit CBC_Code39(FX_BOOL usingCheckDigit); + CBC_Code39(FX_BOOL usingCheckDigit, FX_BOOL extendedMode); + virtual ~CBC_Code39(); + + FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); + CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); + CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); + + FX_BOOL RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e); + FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); + + BC_TYPE GetType() { return BC_CODE39; } + FX_BOOL SetTextLocation(BC_TEXT_LOC location); + FX_BOOL SetWideNarrowRatio(int32_t ratio); + + private: + CFX_WideString m_renderContents; +}; + +#endif // XFA_FXBARCODE_CBC_CODE39_H_ diff --git a/xfa/fxbarcode/cbc_codebase.cpp b/xfa/fxbarcode/cbc_codebase.cpp new file mode 100644 index 0000000000..64a358a038 --- /dev/null +++ b/xfa/fxbarcode/cbc_codebase.cpp @@ -0,0 +1,58 @@ +// Copyright 2016 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 +/* + * Copyright 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "xfa/fxbarcode/cbc_codebase.h" + +#include "xfa/fxbarcode/BC_Writer.h" + +CBC_CodeBase::CBC_CodeBase() {} + +CBC_CodeBase::~CBC_CodeBase() {} + +FX_BOOL CBC_CodeBase::SetCharEncoding(int32_t encoding) { + return m_pBCWriter && m_pBCWriter->SetCharEncoding(encoding); +} + +FX_BOOL CBC_CodeBase::SetModuleHeight(int32_t moduleHeight) { + return m_pBCWriter && m_pBCWriter->SetModuleHeight(moduleHeight); +} + +FX_BOOL CBC_CodeBase::SetModuleWidth(int32_t moduleWidth) { + return m_pBCWriter && m_pBCWriter->SetModuleWidth(moduleWidth); +} + +FX_BOOL CBC_CodeBase::SetHeight(int32_t height) { + return m_pBCWriter && m_pBCWriter->SetHeight(height); +} + +FX_BOOL CBC_CodeBase::SetWidth(int32_t width) { + return m_pBCWriter && m_pBCWriter->SetWidth(width); +} + +void CBC_CodeBase::SetBackgroundColor(FX_ARGB backgroundColor) { + if (m_pBCWriter) + m_pBCWriter->SetBackgroundColor(backgroundColor); +} + +void CBC_CodeBase::SetBarcodeColor(FX_ARGB foregroundColor) { + if (m_pBCWriter) + m_pBCWriter->SetBarcodeColor(foregroundColor); +} diff --git a/xfa/fxbarcode/cbc_codebase.h b/xfa/fxbarcode/cbc_codebase.h new file mode 100644 index 0000000000..20f25b58b0 --- /dev/null +++ b/xfa/fxbarcode/cbc_codebase.h @@ -0,0 +1,52 @@ +// Copyright 2016 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_FXBARCODE_CBC_CODEBASE_H_ +#define XFA_FXBARCODE_CBC_CODEBASE_H_ + +#include "core/include/fxcrt/fx_system.h" +#include "core/include/fxge/fx_dib.h" +#include "xfa/fxbarcode/include/BC_Library.h" + +class CBC_Writer; +class CBC_Reader; +class CFX_DIBitmap; +class CFX_RenderDevice; + +class CBC_CodeBase { + public: + CBC_CodeBase(); + virtual ~CBC_CodeBase(); + + virtual BC_TYPE GetType() = 0; + virtual FX_BOOL Encode(const CFX_WideStringC& contents, + FX_BOOL isDevice, + int32_t& e) = 0; + virtual FX_BOOL RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e) = 0; + virtual FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) = 0; + virtual CFX_WideString Decode(uint8_t* buf, + int32_t width, + int32_t hight, + int32_t& e) = 0; + virtual CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e) = 0; + + virtual FX_BOOL SetCharEncoding(int32_t encoding); + virtual FX_BOOL SetModuleHeight(int32_t moduleHeight); + virtual FX_BOOL SetModuleWidth(int32_t moduleWidth); + + virtual FX_BOOL SetHeight(int32_t height); + virtual FX_BOOL SetWidth(int32_t width); + virtual void SetBackgroundColor(FX_ARGB backgroundColor); + virtual void SetBarcodeColor(FX_ARGB foregroundColor); + + protected: + CBC_Writer* m_pBCWriter; + CBC_Reader* m_pBCReader; +}; + +#endif // XFA_FXBARCODE_CBC_CODEBASE_H_ diff --git a/xfa/fxbarcode/cbc_datamatrix.cpp b/xfa/fxbarcode/cbc_datamatrix.cpp new file mode 100644 index 0000000000..d3e1a073a5 --- /dev/null +++ b/xfa/fxbarcode/cbc_datamatrix.cpp @@ -0,0 +1,83 @@ +// Copyright 2016 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 +/* + * Copyright 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "xfa/fxbarcode/cbc_datamatrix.h" + +#include "xfa/fxbarcode/BC_BinaryBitmap.h" +#include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" +#include "xfa/fxbarcode/common/BC_GlobalHistogramBinarizer.h" +#include "xfa/fxbarcode/datamatrix/BC_DataMatrixReader.h" +#include "xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.h" + +CBC_DataMatrix::CBC_DataMatrix() { + m_pBCReader = (CBC_Reader*)new (CBC_DataMatrixReader); + ((CBC_DataMatrixReader*)m_pBCReader)->Init(); + m_pBCWriter = (CBC_Writer*)new (CBC_DataMatrixWriter); +} + +CBC_DataMatrix::~CBC_DataMatrix() { + delete (m_pBCReader); + delete (m_pBCWriter); +} + +FX_BOOL CBC_DataMatrix::Encode(const CFX_WideStringC& contents, + FX_BOOL isDevice, + int32_t& e) { + int32_t outWidth = 0; + int32_t outHeight = 0; + uint8_t* data = ((CBC_DataMatrixWriter*)m_pBCWriter) + ->Encode(contents, outWidth, outHeight, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + ((CBC_TwoDimWriter*)m_pBCWriter)->RenderResult(data, outWidth, outHeight, e); + FX_Free(data); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +FX_BOOL CBC_DataMatrix::RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e) { + ((CBC_TwoDimWriter*)m_pBCWriter)->RenderDeviceResult(device, matirx); + return TRUE; +} + +FX_BOOL CBC_DataMatrix::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { + ((CBC_TwoDimWriter*)m_pBCWriter)->RenderBitmapResult(pOutBitmap, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +CFX_WideString CBC_DataMatrix::Decode(uint8_t* buf, + int32_t width, + int32_t hight, + int32_t& e) { + CFX_WideString str; + return str; +} + +CFX_WideString CBC_DataMatrix::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { + CBC_BufferedImageLuminanceSource source(pBitmap); + CBC_GlobalHistogramBinarizer binarizer(&source); + CBC_BinaryBitmap bitmap(&binarizer); + CFX_ByteString retStr = m_pBCReader->Decode(&bitmap, 0, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); + return CFX_WideString::FromUTF8(retStr, retStr.GetLength()); +} diff --git a/xfa/fxbarcode/cbc_datamatrix.h b/xfa/fxbarcode/cbc_datamatrix.h new file mode 100644 index 0000000000..903d0b2472 --- /dev/null +++ b/xfa/fxbarcode/cbc_datamatrix.h @@ -0,0 +1,32 @@ +// Copyright 2016 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_FXBARCODE_CBC_DATAMATRIX_H_ +#define XFA_FXBARCODE_CBC_DATAMATRIX_H_ + +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "core/include/fxge/fx_dib.h" +#include "xfa/fxbarcode/cbc_codebase.h" + +class CBC_DataMatrix : public CBC_CodeBase { + public: + CBC_DataMatrix(); + virtual ~CBC_DataMatrix(); + + FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); + CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); + CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); + + FX_BOOL RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e); + FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); + + BC_TYPE GetType() { return BC_DATAMATRIX; } +}; + +#endif // XFA_FXBARCODE_CBC_DATAMATRIX_H_ diff --git a/xfa/fxbarcode/cbc_ean13.cpp b/xfa/fxbarcode/cbc_ean13.cpp new file mode 100644 index 0000000000..e764122e3c --- /dev/null +++ b/xfa/fxbarcode/cbc_ean13.cpp @@ -0,0 +1,114 @@ +// Copyright 2016 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 +/* + * Copyright 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "xfa/fxbarcode/cbc_ean13.h" + +#include "xfa/fxbarcode/BC_BinaryBitmap.h" +#include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" +#include "xfa/fxbarcode/common/BC_GlobalHistogramBinarizer.h" +#include "xfa/fxbarcode/oned/BC_OnedEAN13Reader.h" +#include "xfa/fxbarcode/oned/BC_OnedEAN13Writer.h" + +CBC_EAN13::CBC_EAN13() { + m_pBCReader = (CBC_Reader*)new (CBC_OnedEAN13Reader); + m_pBCWriter = (CBC_Writer*)new (CBC_OnedEAN13Writer); +} + +CBC_EAN13::~CBC_EAN13() { + delete (m_pBCReader); + delete (m_pBCWriter); +} + +CFX_WideString CBC_EAN13::Preprocess(const CFX_WideStringC& contents) { + CFX_WideString encodeContents = + ((CBC_OnedEAN13Writer*)m_pBCWriter)->FilterContents(contents); + int32_t length = encodeContents.GetLength(); + if (length <= 12) { + for (int32_t i = 0; i < 12 - length; i++) + encodeContents = FX_WCHAR('0') + encodeContents; + + CFX_ByteString byteString = encodeContents.UTF8Encode(); + int32_t checksum = + ((CBC_OnedEAN13Writer*)m_pBCWriter)->CalcChecksum(byteString); + byteString += checksum - 0 + '0'; + encodeContents = byteString.UTF8Decode(); + } + if (length > 13) + encodeContents = encodeContents.Mid(0, 13); + + return encodeContents; +} + +FX_BOOL CBC_EAN13::Encode(const CFX_WideStringC& contents, + FX_BOOL isDevice, + int32_t& e) { + if (contents.IsEmpty()) { + e = BCExceptionNoContents; + return FALSE; + } + BCFORMAT format = BCFORMAT_EAN_13; + int32_t outWidth = 0; + int32_t outHeight = 0; + CFX_WideString encodeContents = Preprocess(contents); + CFX_ByteString byteString = encodeContents.UTF8Encode(); + m_renderContents = encodeContents; + uint8_t* data = static_cast(m_pBCWriter) + ->Encode(byteString, format, outWidth, outHeight, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderResult(encodeContents, data, outWidth, isDevice, e); + FX_Free(data); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +FX_BOOL CBC_EAN13::RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e) { + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderDeviceResult(device, matirx, m_renderContents, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +FX_BOOL CBC_EAN13::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderBitmapResult(pOutBitmap, m_renderContents, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +CFX_WideString CBC_EAN13::Decode(uint8_t* buf, + int32_t width, + int32_t hight, + int32_t& e) { + CFX_WideString str; + return str; +} + +CFX_WideString CBC_EAN13::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { + CBC_BufferedImageLuminanceSource source(pBitmap); + CBC_GlobalHistogramBinarizer binarizer(&source); + CBC_BinaryBitmap bitmap(&binarizer); + CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); + return CFX_WideString::FromUTF8(str, str.GetLength()); +} diff --git a/xfa/fxbarcode/cbc_ean13.h b/xfa/fxbarcode/cbc_ean13.h new file mode 100644 index 0000000000..c9ecc90cd9 --- /dev/null +++ b/xfa/fxbarcode/cbc_ean13.h @@ -0,0 +1,36 @@ +// Copyright 2016 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_FXBARCODE_CBC_EAN13_H_ +#define XFA_FXBARCODE_CBC_EAN13_H_ + +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "core/include/fxge/fx_dib.h" +#include "xfa/fxbarcode/cbc_onecode.h" + +class CBC_EAN13 : public CBC_OneCode { + public: + CBC_EAN13(); + virtual ~CBC_EAN13(); + + FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); + CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); + CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); + + FX_BOOL RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e); + FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); + + BC_TYPE GetType() { return BC_EAN13; } + + private: + CFX_WideString Preprocess(const CFX_WideStringC& contents); + CFX_WideString m_renderContents; +}; + +#endif // XFA_FXBARCODE_CBC_EAN13_H_ diff --git a/xfa/fxbarcode/cbc_ean8.cpp b/xfa/fxbarcode/cbc_ean8.cpp new file mode 100644 index 0000000000..bc983b8c47 --- /dev/null +++ b/xfa/fxbarcode/cbc_ean8.cpp @@ -0,0 +1,113 @@ +// Copyright 2016 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 +/* + * Copyright 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "xfa/fxbarcode/cbc_ean8.h" + +#include "xfa/fxbarcode/BC_BinaryBitmap.h" +#include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" +#include "xfa/fxbarcode/common/BC_GlobalHistogramBinarizer.h" +#include "xfa/fxbarcode/oned/BC_OnedEAN8Reader.h" +#include "xfa/fxbarcode/oned/BC_OnedEAN8Writer.h" + +CBC_EAN8::CBC_EAN8() { + m_pBCReader = (CBC_Reader*)new (CBC_OnedEAN8Reader); + m_pBCWriter = (CBC_Writer*)new (CBC_OnedEAN8Writer); +} + +CBC_EAN8::~CBC_EAN8() { + delete (m_pBCReader); + delete (m_pBCWriter); +} + +CFX_WideString CBC_EAN8::Preprocess(const CFX_WideStringC& contents) { + CFX_WideString encodeContents = + ((CBC_OnedEAN8Writer*)m_pBCWriter)->FilterContents(contents); + int32_t length = encodeContents.GetLength(); + if (length <= 7) { + for (int32_t i = 0; i < 7 - length; i++) + encodeContents = FX_WCHAR('0') + encodeContents; + + CFX_ByteString byteString = encodeContents.UTF8Encode(); + int32_t checksum = + ((CBC_OnedEAN8Writer*)m_pBCWriter)->CalcChecksum(byteString); + encodeContents += FX_WCHAR(checksum - 0 + '0'); + } + if (length > 8) + encodeContents = encodeContents.Mid(0, 8); + + return encodeContents; +} + +FX_BOOL CBC_EAN8::Encode(const CFX_WideStringC& contents, + FX_BOOL isDevice, + int32_t& e) { + if (contents.IsEmpty()) { + e = BCExceptionNoContents; + return FALSE; + } + BCFORMAT format = BCFORMAT_EAN_8; + int32_t outWidth = 0; + int32_t outHeight = 0; + CFX_WideString encodeContents = Preprocess(contents); + CFX_ByteString byteString = encodeContents.UTF8Encode(); + m_renderContents = encodeContents; + uint8_t* data = static_cast(m_pBCWriter) + ->Encode(byteString, format, outWidth, outHeight, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderResult(encodeContents, data, outWidth, isDevice, e); + FX_Free(data); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +FX_BOOL CBC_EAN8::RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e) { + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderDeviceResult(device, matirx, m_renderContents, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +FX_BOOL CBC_EAN8::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderBitmapResult(pOutBitmap, m_renderContents, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +CFX_WideString CBC_EAN8::Decode(uint8_t* buf, + int32_t width, + int32_t hight, + int32_t& e) { + CFX_WideString str; + return str; +} + +CFX_WideString CBC_EAN8::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { + CBC_BufferedImageLuminanceSource source(pBitmap); + CBC_GlobalHistogramBinarizer binarizer(&source); + CBC_BinaryBitmap bitmap(&binarizer); + CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); + return CFX_WideString::FromUTF8(str, str.GetLength()); +} diff --git a/xfa/fxbarcode/cbc_ean8.h b/xfa/fxbarcode/cbc_ean8.h new file mode 100644 index 0000000000..95a61d2ab3 --- /dev/null +++ b/xfa/fxbarcode/cbc_ean8.h @@ -0,0 +1,36 @@ +// Copyright 2016 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_FXBARCODE_CBC_EAN8_H_ +#define XFA_FXBARCODE_CBC_EAN8_H_ + +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "core/include/fxge/fx_dib.h" +#include "xfa/fxbarcode/cbc_onecode.h" + +class CBC_EAN8 : public CBC_OneCode { + public: + CBC_EAN8(); + virtual ~CBC_EAN8(); + + FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); + CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); + CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); + + FX_BOOL RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e); + FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); + + BC_TYPE GetType() { return BC_EAN8; } + + private: + CFX_WideString Preprocess(const CFX_WideStringC& contents); + CFX_WideString m_renderContents; +}; + +#endif // XFA_FXBARCODE_CBC_EAN8_H_ diff --git a/xfa/fxbarcode/cbc_onecode.cpp b/xfa/fxbarcode/cbc_onecode.cpp new file mode 100644 index 0000000000..f5e1a3960a --- /dev/null +++ b/xfa/fxbarcode/cbc_onecode.cpp @@ -0,0 +1,77 @@ +// Copyright 2016 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 +/* + * Copyright 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "xfa/fxbarcode/cbc_onecode.h" + +#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" + +CBC_OneCode::CBC_OneCode() {} + +CBC_OneCode::~CBC_OneCode() {} + +FX_BOOL CBC_OneCode::CheckContentValidity(const CFX_WideStringC& contents) { + if (m_pBCWriter) + return ((CBC_OneDimWriter*)m_pBCWriter)->CheckContentValidity(contents); + return FALSE; +} + +CFX_WideString CBC_OneCode::FilterContents(const CFX_WideStringC& contents) { + CFX_WideString tmp; + if (!m_pBCWriter) + return tmp; + return ((CBC_OneDimWriter*)m_pBCWriter)->FilterContents(contents); +} + +void CBC_OneCode::SetPrintChecksum(FX_BOOL checksum) { + if (m_pBCWriter) + ((CBC_OneDimWriter*)m_pBCWriter)->SetPrintChecksum(checksum); +} + +void CBC_OneCode::SetDataLength(int32_t length) { + if (m_pBCWriter) + ((CBC_OneDimWriter*)m_pBCWriter)->SetDataLength(length); +} + +void CBC_OneCode::SetCalChecksum(FX_BOOL calc) { + if (m_pBCWriter) + ((CBC_OneDimWriter*)m_pBCWriter)->SetCalcChecksum(calc); +} + +FX_BOOL CBC_OneCode::SetFont(CFX_Font* cFont) { + if (m_pBCWriter) + return ((CBC_OneDimWriter*)m_pBCWriter)->SetFont(cFont); + return FALSE; +} + +void CBC_OneCode::SetFontSize(FX_FLOAT size) { + if (m_pBCWriter) + ((CBC_OneDimWriter*)m_pBCWriter)->SetFontSize(size); +} + +void CBC_OneCode::SetFontStyle(int32_t style) { + if (m_pBCWriter) + ((CBC_OneDimWriter*)m_pBCWriter)->SetFontStyle(style); +} + +void CBC_OneCode::SetFontColor(FX_ARGB color) { + if (m_pBCWriter) + ((CBC_OneDimWriter*)m_pBCWriter)->SetFontColor(color); +} diff --git a/xfa/fxbarcode/cbc_onecode.h b/xfa/fxbarcode/cbc_onecode.h new file mode 100644 index 0000000000..ac070a496c --- /dev/null +++ b/xfa/fxbarcode/cbc_onecode.h @@ -0,0 +1,52 @@ +// Copyright 2016 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_FXBARCODE_CBC_ONECODE_H_ +#define XFA_FXBARCODE_CBC_ONECODE_H_ + +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "xfa/fxbarcode/cbc_codebase.h" + +class CFX_DIBitmap; +class CFX_Font; +class CFX_RenderDevice; + +class CBC_OneCode : public CBC_CodeBase { + public: + CBC_OneCode(); + virtual ~CBC_OneCode(); + + virtual BC_TYPE GetType() = 0; + + virtual FX_BOOL Encode(const CFX_WideStringC& contents, + FX_BOOL isDevice, + int32_t& e) = 0; + virtual CFX_WideString Decode(uint8_t* buf, + int32_t width, + int32_t hight, + int32_t& e) = 0; + virtual CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e) = 0; + + virtual FX_BOOL RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e) = 0; + virtual FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) = 0; + + + virtual FX_BOOL CheckContentValidity(const CFX_WideStringC& contents); + virtual CFX_WideString FilterContents(const CFX_WideStringC& contents); + + virtual void SetPrintChecksum(FX_BOOL checksum); + virtual void SetDataLength(int32_t length); + virtual void SetCalChecksum(FX_BOOL calc); + virtual FX_BOOL SetFont(CFX_Font* cFont); + virtual void SetFontSize(FX_FLOAT size); + virtual void SetFontStyle(int32_t style); + virtual void SetFontColor(FX_ARGB color); +}; + +#endif // XFA_FXBARCODE_CBC_ONECODE_H_ diff --git a/xfa/fxbarcode/cbc_pdf417i.cpp b/xfa/fxbarcode/cbc_pdf417i.cpp new file mode 100644 index 0000000000..b27af1cefc --- /dev/null +++ b/xfa/fxbarcode/cbc_pdf417i.cpp @@ -0,0 +1,91 @@ +// Copyright 2016 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 +/* + * Copyright 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "xfa/fxbarcode/cbc_pdf417i.h" + +#include "xfa/fxbarcode/BC_BinaryBitmap.h" +#include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" +#include "xfa/fxbarcode/common/BC_GlobalHistogramBinarizer.h" +#include "xfa/fxbarcode/pdf417/BC_PDF417Reader.h" +#include "xfa/fxbarcode/pdf417/BC_PDF417Writer.h" + +CBC_PDF417I::CBC_PDF417I() { + m_pBCReader = (CBC_Reader*)new (CBC_PDF417Reader); + m_pBCWriter = (CBC_Writer*)new (CBC_PDF417Writer); +} + +CBC_PDF417I::~CBC_PDF417I() { + delete (m_pBCReader); + delete (m_pBCWriter); +} + +FX_BOOL CBC_PDF417I::SetErrorCorrectionLevel(int32_t level) { + ((CBC_PDF417Writer*)m_pBCWriter)->SetErrorCorrectionLevel(level); + return TRUE; +} + +void CBC_PDF417I::SetTruncated(FX_BOOL truncated) { + ((CBC_PDF417Writer*)m_pBCWriter)->SetTruncated(truncated); +} + +FX_BOOL CBC_PDF417I::Encode(const CFX_WideStringC& contents, + FX_BOOL isDevice, + int32_t& e) { + int32_t outWidth = 0; + int32_t outHeight = 0; + uint8_t* data = ((CBC_PDF417Writer*)m_pBCWriter) + ->Encode(contents, outWidth, outHeight, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + ((CBC_TwoDimWriter*)m_pBCWriter)->RenderResult(data, outWidth, outHeight, e); + FX_Free(data); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +FX_BOOL CBC_PDF417I::RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e) { + ((CBC_TwoDimWriter*)m_pBCWriter)->RenderDeviceResult(device, matirx); + return TRUE; +} + +FX_BOOL CBC_PDF417I::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { + ((CBC_TwoDimWriter*)m_pBCWriter)->RenderBitmapResult(pOutBitmap, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +CFX_WideString CBC_PDF417I::Decode(uint8_t* buf, + int32_t width, + int32_t hight, + int32_t& e) { + CFX_WideString str; + return str; +} + +CFX_WideString CBC_PDF417I::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { + CBC_BufferedImageLuminanceSource source(pBitmap); + CBC_GlobalHistogramBinarizer binarizer(&source); + CBC_BinaryBitmap bitmap(&binarizer); + CFX_ByteString bytestring = m_pBCReader->Decode(&bitmap, 0, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); + return CFX_WideString::FromUTF8(bytestring, bytestring.GetLength()); +} diff --git a/xfa/fxbarcode/cbc_pdf417i.h b/xfa/fxbarcode/cbc_pdf417i.h new file mode 100644 index 0000000000..b8f45fa098 --- /dev/null +++ b/xfa/fxbarcode/cbc_pdf417i.h @@ -0,0 +1,35 @@ +// Copyright 2016 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_FXBARCODE_CBC_PDF417I_H_ +#define XFA_FXBARCODE_CBC_PDF417I_H_ + +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "core/include/fxge/fx_dib.h" +#include "xfa/fxbarcode/cbc_codebase.h" + +class CBC_PDF417I : public CBC_CodeBase { + public: + CBC_PDF417I(); + virtual ~CBC_PDF417I(); + + FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); + CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); + CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); + + FX_BOOL RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e); + FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); + + BC_TYPE GetType() { return BC_PDF417; } + + FX_BOOL SetErrorCorrectionLevel(int32_t level); + void SetTruncated(FX_BOOL truncated); +}; + +#endif // XFA_FXBARCODE_CBC_PDF417I_H_ diff --git a/xfa/fxbarcode/cbc_qrcode.cpp b/xfa/fxbarcode/cbc_qrcode.cpp new file mode 100644 index 0000000000..4518594944 --- /dev/null +++ b/xfa/fxbarcode/cbc_qrcode.cpp @@ -0,0 +1,101 @@ +// Copyright 2016 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 +/* + * Copyright 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "xfa/fxbarcode/cbc_qrcode.h" + +#include "xfa/fxbarcode/BC_BinaryBitmap.h" +#include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" +#include "xfa/fxbarcode/common/BC_GlobalHistogramBinarizer.h" +#include "xfa/fxbarcode/qrcode/BC_QRCodeReader.h" +#include "xfa/fxbarcode/qrcode/BC_QRCodeWriter.h" + +CBC_QRCode::CBC_QRCode() { + m_pBCReader = (CBC_Reader*)new (CBC_QRCodeReader); + ((CBC_QRCodeReader*)m_pBCReader)->Init(); + m_pBCWriter = (CBC_Writer*)new (CBC_QRCodeWriter); +} + +CBC_QRCode::~CBC_QRCode() { + delete (m_pBCReader); + delete (m_pBCWriter); +} + +FX_BOOL CBC_QRCode::SetVersion(int32_t version) { + if (version < 0 || version > 40) + return FALSE; + if (!m_pBCWriter) + return FALSE; + return ((CBC_QRCodeWriter*)m_pBCWriter)->SetVersion(version); +} + +FX_BOOL CBC_QRCode::SetErrorCorrectionLevel(int32_t level) { + if (level < 0 || level > 3) + return FALSE; + if (!m_pBCWriter) + return FALSE; + return ((CBC_TwoDimWriter*)m_pBCWriter)->SetErrorCorrectionLevel(level); +} + +FX_BOOL CBC_QRCode::Encode(const CFX_WideStringC& contents, + FX_BOOL isDevice, + int32_t& e) { + int32_t outWidth = 0; + int32_t outHeight = 0; + uint8_t* data = ((CBC_QRCodeWriter*)m_pBCWriter) + ->Encode(contents, ((CBC_QRCodeWriter*)m_pBCWriter) + ->GetErrorCorrectionLevel(), + outWidth, outHeight, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + ((CBC_TwoDimWriter*)m_pBCWriter)->RenderResult(data, outWidth, outHeight, e); + FX_Free(data); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +FX_BOOL CBC_QRCode::RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e) { + ((CBC_TwoDimWriter*)m_pBCWriter)->RenderDeviceResult(device, matirx); + return TRUE; +} + +FX_BOOL CBC_QRCode::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { + ((CBC_TwoDimWriter*)m_pBCWriter)->RenderBitmapResult(pOutBitmap, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +CFX_WideString CBC_QRCode::Decode(uint8_t* buf, + int32_t width, + int32_t hight, + int32_t& e) { + CFX_WideString str; + return str; +} + +CFX_WideString CBC_QRCode::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { + CBC_BufferedImageLuminanceSource source(pBitmap); + CBC_GlobalHistogramBinarizer binarizer(&source); + CBC_BinaryBitmap bitmap(&binarizer); + CFX_ByteString retStr = m_pBCReader->Decode(&bitmap, 0, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); + return CFX_WideString::FromUTF8(retStr, retStr.GetLength()); +} diff --git a/xfa/fxbarcode/cbc_qrcode.h b/xfa/fxbarcode/cbc_qrcode.h new file mode 100644 index 0000000000..1198194b97 --- /dev/null +++ b/xfa/fxbarcode/cbc_qrcode.h @@ -0,0 +1,35 @@ +// Copyright 2016 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_FXBARCODE_CBC_QRCODE_H_ +#define XFA_FXBARCODE_CBC_QRCODE_H_ + +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "core/include/fxge/fx_dib.h" +#include "xfa/fxbarcode/cbc_codebase.h" + +class CBC_QRCode : public CBC_CodeBase { + public: + CBC_QRCode(); + virtual ~CBC_QRCode(); + + FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); + CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); + CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); + + FX_BOOL RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e); + FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); + + BC_TYPE GetType() { return BC_QR_CODE; } + + FX_BOOL SetVersion(int32_t version); + FX_BOOL SetErrorCorrectionLevel(int32_t level); +}; + +#endif // XFA_FXBARCODE_CBC_QRCODE_H_ diff --git a/xfa/fxbarcode/cbc_upca.cpp b/xfa/fxbarcode/cbc_upca.cpp new file mode 100644 index 0000000000..220b8fa2d8 --- /dev/null +++ b/xfa/fxbarcode/cbc_upca.cpp @@ -0,0 +1,116 @@ +// Copyright 2016 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 +/* + * Copyright 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "xfa/fxbarcode/cbc_upca.h" + +#include "xfa/fxbarcode/BC_BinaryBitmap.h" +#include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" +#include "xfa/fxbarcode/common/BC_GlobalHistogramBinarizer.h" +#include "xfa/fxbarcode/oned/BC_OnedUPCAReader.h" +#include "xfa/fxbarcode/oned/BC_OnedUPCAWriter.h" + +CBC_UPCA::CBC_UPCA() { + m_pBCReader = (CBC_Reader*)new (CBC_OnedUPCAReader); + ((CBC_OnedUPCAReader*)m_pBCReader)->Init(); + m_pBCWriter = (CBC_Writer*)new (CBC_OnedUPCAWriter); +} + +CBC_UPCA::~CBC_UPCA() { + delete (m_pBCReader); + delete (m_pBCWriter); +} + +CFX_WideString CBC_UPCA::Preprocess(const CFX_WideStringC& contents) { + CFX_WideString encodeContents = + ((CBC_OnedUPCAWriter*)m_pBCWriter)->FilterContents(contents); + int32_t length = encodeContents.GetLength(); + if (length <= 11) { + for (int32_t i = 0; i < 11 - length; i++) + encodeContents = FX_WCHAR('0') + encodeContents; + + CFX_ByteString byteString = encodeContents.UTF8Encode(); + int32_t checksum = + ((CBC_OnedUPCAWriter*)m_pBCWriter)->CalcChecksum(byteString); + byteString += checksum - 0 + '0'; + encodeContents = byteString.UTF8Decode(); + } + if (length > 12) + encodeContents = encodeContents.Mid(0, 12); + + return encodeContents; +} + +FX_BOOL CBC_UPCA::Encode(const CFX_WideStringC& contents, + FX_BOOL isDevice, + int32_t& e) { + if (contents.IsEmpty()) { + e = BCExceptionNoContents; + return FALSE; + } + BCFORMAT format = BCFORMAT_UPC_A; + int32_t outWidth = 0; + int32_t outHeight = 0; + CFX_WideString encodeContents = Preprocess(contents); + CFX_ByteString byteString = encodeContents.UTF8Encode(); + m_renderContents = encodeContents; + ((CBC_OnedUPCAWriter*)m_pBCWriter)->Init(); + uint8_t* data = static_cast(m_pBCWriter) + ->Encode(byteString, format, outWidth, outHeight, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderResult(encodeContents, data, outWidth, isDevice, e); + FX_Free(data); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +FX_BOOL CBC_UPCA::RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e) { + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderDeviceResult(device, matirx, m_renderContents, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +FX_BOOL CBC_UPCA::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { + ((CBC_OneDimWriter*)m_pBCWriter) + ->RenderBitmapResult(pOutBitmap, m_renderContents, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); + return TRUE; +} + +CFX_WideString CBC_UPCA::Decode(uint8_t* buf, + int32_t width, + int32_t hight, + int32_t& e) { + CFX_WideString str; + return str; +} + +CFX_WideString CBC_UPCA::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { + CBC_BufferedImageLuminanceSource source(pBitmap); + CBC_GlobalHistogramBinarizer binarizer(&source); + CBC_BinaryBitmap bitmap(&binarizer); + CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); + BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); + return CFX_WideString::FromUTF8(str, str.GetLength()); +} diff --git a/xfa/fxbarcode/cbc_upca.h b/xfa/fxbarcode/cbc_upca.h new file mode 100644 index 0000000000..ee4c31bee4 --- /dev/null +++ b/xfa/fxbarcode/cbc_upca.h @@ -0,0 +1,33 @@ +// Copyright 2016 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_FXBARCODE_CBC_UPCA_H_ +#define XFA_FXBARCODE_CBC_UPCA_H_ + +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "core/include/fxge/fx_dib.h" +#include "xfa/fxbarcode/cbc_onecode.h" + +class CBC_UPCA : public CBC_OneCode { + public: + CBC_UPCA(); + virtual ~CBC_UPCA(); + FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); + FX_BOOL RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matirx, + int32_t& e); + FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); + CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); + CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); + BC_TYPE GetType() { return BC_UPCA; } + + private: + CFX_WideString Preprocess(const CFX_WideStringC& contents); + CFX_WideString m_renderContents; +}; + +#endif // XFA_FXBARCODE_CBC_UPCA_H_ diff --git a/xfa/fxbarcode/include/BC_Library.h b/xfa/fxbarcode/include/BC_Library.h new file mode 100644 index 0000000000..d0bd85b118 --- /dev/null +++ b/xfa/fxbarcode/include/BC_Library.h @@ -0,0 +1,38 @@ +// Copyright 2016 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_FXBARCODE_INCLUDE_BC_LIBRARY_H_ +#define XFA_FXBARCODE_INCLUDE_BC_LIBRARY_H_ + +enum BC_TEXT_LOC { + BC_TEXT_LOC_NONE = 0, + BC_TEXT_LOC_ABOVE, + BC_TEXT_LOC_BELOW, + BC_TEXT_LOC_ABOVEEMBED, + BC_TEXT_LOC_BELOWEMBED +}; + +enum BC_CHAR_ENCODING { CHAR_ENCODING_UTF8 = 0, CHAR_ENCODING_UNICODE }; + +enum BC_TYPE { + BC_UNKNOWN = -1, + BC_CODE39 = 0, + BC_CODABAR, + BC_CODE128, + BC_CODE128_B, + BC_CODE128_C, + BC_EAN8, + BC_UPCA, + BC_EAN13, + BC_QR_CODE, + BC_PDF417, + BC_DATAMATRIX +}; + +void BC_Library_Init(); +void BC_Library_Destory(); + +#endif // XFA_FXBARCODE_INCLUDE_BC_LIBRARY_H_ diff --git a/xfa/fxbarcode/oned/BC_OneDimWriter.h b/xfa/fxbarcode/oned/BC_OneDimWriter.h index e91a9297e1..b015070968 100644 --- a/xfa/fxbarcode/oned/BC_OneDimWriter.h +++ b/xfa/fxbarcode/oned/BC_OneDimWriter.h @@ -9,7 +9,7 @@ #include "core/include/fxge/fx_ge.h" #include "xfa/fxbarcode/BC_Writer.h" -#include "xfa/include/fxbarcode/BC_BarCode.h" +#include "xfa/fxbarcode/include/BC_Library.h" class CBC_CommonBitMatrix; class CFX_Font; @@ -19,6 +19,7 @@ class CBC_OneDimWriter : public CBC_Writer { public: CBC_OneDimWriter(); virtual ~CBC_OneDimWriter(); + uint8_t* Encode(const CFX_ByteString& contents, BCFORMAT format, int32_t& outWidth, @@ -35,6 +36,7 @@ class CBC_OneDimWriter : public CBC_Writer { int32_t& e) { return NULL; } + virtual void RenderResult(const CFX_WideStringC& contents, uint8_t* code, int32_t codeLength, @@ -65,21 +67,6 @@ class CBC_OneDimWriter : public CBC_Writer { virtual FX_BOOL SetFont(CFX_Font* cFont); protected: - FX_BOOL m_bPrintChecksum; - int32_t m_iDataLenth; - FX_BOOL m_bCalcChecksum; - CFX_Font* m_pFont; - FX_FLOAT m_fFontSize; - int32_t m_iFontStyle; - FX_DWORD m_fontColor; - BC_TEXT_LOC m_locTextLoc; - int32_t m_iContentLen; - FX_BOOL m_bLeftPadding; - FX_BOOL m_bRightPadding; - CBC_CommonBitMatrix* m_output; - int32_t m_barWidth; - int32_t m_multiple; - FX_FLOAT m_outputHScale; void CalcTextInfo(const CFX_ByteString& text, FXTEXT_CHARPOS* charPos, CFX_Font* cFont, @@ -115,6 +102,22 @@ class CBC_OneDimWriter : public CBC_Writer { int32_t startColor, int32_t& e); FX_WCHAR Upper(FX_WCHAR ch); + + FX_BOOL m_bPrintChecksum; + int32_t m_iDataLenth; + FX_BOOL m_bCalcChecksum; + CFX_Font* m_pFont; + FX_FLOAT m_fFontSize; + int32_t m_iFontStyle; + FX_DWORD m_fontColor; + BC_TEXT_LOC m_locTextLoc; + int32_t m_iContentLen; + FX_BOOL m_bLeftPadding; + FX_BOOL m_bRightPadding; + CBC_CommonBitMatrix* m_output; + int32_t m_barWidth; + int32_t m_multiple; + FX_FLOAT m_outputHScale; }; #endif // XFA_FXBARCODE_ONED_BC_ONEDIMWRITER_H_ diff --git a/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h b/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h index 92a31bd989..53af246796 100644 --- a/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h +++ b/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h @@ -7,13 +7,16 @@ #ifndef XFA_FXBARCODE_ONED_BC_ONEDCODABARWRITER_H_ #define XFA_FXBARCODE_ONED_BC_ONEDCODABARWRITER_H_ -enum BC_TEXT_LOC; -class CBC_OneDimWriter; -class CBC_OnedCodaBarWriter; +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "xfa/fxbarcode/include/BC_Library.h" +#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" + class CBC_OnedCodaBarWriter : public CBC_OneDimWriter { public: CBC_OnedCodaBarWriter(); virtual ~CBC_OnedCodaBarWriter(); + uint8_t* Encode(const CFX_ByteString& contents, int32_t& outLength, int32_t& e); @@ -28,6 +31,7 @@ class CBC_OnedCodaBarWriter : public CBC_OneDimWriter { int32_t& outHeight, int32_t hints, int32_t& e); + CFX_WideString encodedContents(const CFX_WideStringC& contents); FX_BOOL CheckContentValidity(const CFX_WideStringC& contents); CFX_WideString FilterContents(const CFX_WideStringC& contents); @@ -39,13 +43,15 @@ class CBC_OnedCodaBarWriter : public CBC_OneDimWriter { FX_BOOL FindChar(FX_WCHAR ch, FX_BOOL isContent); private: + static const FX_CHAR START_END_CHARS[]; + static const FX_CHAR CONTENT_CHARS[]; + void RenderResult(const CFX_WideStringC& contents, uint8_t* code, int32_t codeLength, FX_BOOL isDevice, int32_t& e); - static const FX_CHAR START_END_CHARS[]; - static const FX_CHAR CONTENT_CHARS[]; + FX_CHAR m_chStart; FX_CHAR m_chEnd; int32_t m_iWideNarrRatio; diff --git a/xfa/fxbarcode/oned/BC_OnedCode128Reader.h b/xfa/fxbarcode/oned/BC_OnedCode128Reader.h index d9ac4853bf..df21d7a220 100644 --- a/xfa/fxbarcode/oned/BC_OnedCode128Reader.h +++ b/xfa/fxbarcode/oned/BC_OnedCode128Reader.h @@ -7,8 +7,10 @@ #ifndef XFA_FXBARCODE_ONED_BC_ONEDCODE128READER_H_ #define XFA_FXBARCODE_ONED_BC_ONEDCODE128READER_H_ -class CBC_OneDReader; +#include "xfa/fxbarcode/oned/BC_OneDReader.h" + class CBC_CommonBitArray; + class CBC_OnedCode128Reader : public CBC_OneDReader { public: CBC_OnedCode128Reader(); diff --git a/xfa/fxbarcode/oned/BC_OnedCode128Writer.cpp b/xfa/fxbarcode/oned/BC_OnedCode128Writer.cpp index 4d759b48a3..ac05e78910 100644 --- a/xfa/fxbarcode/oned/BC_OnedCode128Writer.cpp +++ b/xfa/fxbarcode/oned/BC_OnedCode128Writer.cpp @@ -27,12 +27,6 @@ #include "xfa/fxbarcode/oned/BC_OnedCode128Reader.h" #include "xfa/fxbarcode/oned/BC_OnedCode128Writer.h" -const int32_t CBC_OnedCode128Writer::CODE_CODE_B = 100; -const int32_t CBC_OnedCode128Writer::CODE_CODE_C = 99; -const int32_t CBC_OnedCode128Writer::CODE_START_B = 104; -const int32_t CBC_OnedCode128Writer::CODE_START_C = 105; -const int32_t CBC_OnedCode128Writer::CODE_STOP = 106; - CBC_OnedCode128Writer::CBC_OnedCode128Writer() { m_codeFormat = BC_CODE128_B; } diff --git a/xfa/fxbarcode/oned/BC_OnedCode128Writer.h b/xfa/fxbarcode/oned/BC_OnedCode128Writer.h index 9be05a19b0..5b68d5cd2e 100644 --- a/xfa/fxbarcode/oned/BC_OnedCode128Writer.h +++ b/xfa/fxbarcode/oned/BC_OnedCode128Writer.h @@ -7,12 +7,16 @@ #ifndef XFA_FXBARCODE_ONED_BC_ONEDCODE128WRITER_H_ #define XFA_FXBARCODE_ONED_BC_ONEDCODE128WRITER_H_ -class CBC_OneDimWriter; +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" + class CBC_OnedCode128Writer : public CBC_OneDimWriter { public: CBC_OnedCode128Writer(); - CBC_OnedCode128Writer(BC_TYPE type); + explicit CBC_OnedCode128Writer(BC_TYPE type); virtual ~CBC_OnedCode128Writer(); + uint8_t* Encode(const CFX_ByteString& contents, BCFORMAT format, int32_t& outWidth, @@ -27,23 +31,26 @@ class CBC_OnedCode128Writer : public CBC_OneDimWriter { uint8_t* Encode(const CFX_ByteString& contents, int32_t& outLength, int32_t& e); + FX_BOOL CheckContentValidity(const CFX_WideStringC& contents); CFX_WideString FilterContents(const CFX_WideStringC& contents); FX_BOOL SetTextLocation(BC_TEXT_LOC location); BC_TYPE GetType(); private: + static const int32_t CODE_CODE_B = 100; + static const int32_t CODE_CODE_C = 99; + static const int32_t CODE_START_B = 104; + static const int32_t CODE_START_C = 105; + static const int32_t CODE_STOP = 106; + FX_BOOL IsDigits(const CFX_ByteString& contents, int32_t start, int32_t length); int32_t Encode128B(const CFX_ByteString& contents, CFX_PtrArray& patterns); int32_t Encode128C(const CFX_ByteString& contents, CFX_PtrArray& patterns); + BC_TYPE m_codeFormat; - static const int32_t CODE_START_B; - static const int32_t CODE_START_C; - static const int32_t CODE_CODE_B; - static const int32_t CODE_CODE_C; - static const int32_t CODE_STOP; }; #endif // XFA_FXBARCODE_ONED_BC_ONEDCODE128WRITER_H_ diff --git a/xfa/fxbarcode/oned/BC_OnedCode39Reader.cpp b/xfa/fxbarcode/oned/BC_OnedCode39Reader.cpp index e2f88e7a79..0eb4c990b4 100644 --- a/xfa/fxbarcode/oned/BC_OnedCode39Reader.cpp +++ b/xfa/fxbarcode/oned/BC_OnedCode39Reader.cpp @@ -38,7 +38,6 @@ const int32_t CBC_OnedCode39Reader::CHARACTER_ENCODINGS[44] = { 0x04C, 0x01C, 0x103, 0x043, 0x142, 0x013, 0x112, 0x052, 0x007, 0x106, 0x046, 0x016, 0x181, 0x0C1, 0x1C0, 0x091, 0x190, 0x0D0, 0x085, 0x184, 0x0C4, 0x094, 0x0A8, 0x0A2, 0x08A, 0x02A}; -const int32_t CBC_OnedCode39Reader::ASTERISK_ENCODING = 0x094; CBC_OnedCode39Reader::CBC_OnedCode39Reader() : m_usingCheckDigit(FALSE), m_extendedMode(FALSE) {} diff --git a/xfa/fxbarcode/oned/BC_OnedCode39Reader.h b/xfa/fxbarcode/oned/BC_OnedCode39Reader.h index f1551e4761..315ffa6faf 100644 --- a/xfa/fxbarcode/oned/BC_OnedCode39Reader.h +++ b/xfa/fxbarcode/oned/BC_OnedCode39Reader.h @@ -7,30 +7,36 @@ #ifndef XFA_FXBARCODE_ONED_BC_ONEDCODE39READER_H_ #define XFA_FXBARCODE_ONED_BC_ONEDCODE39READER_H_ -class CBC_OneDReader; +#include "core/include/fxcrt/fx_system.h" +#include "xfa/fxbarcode/oned/BC_OneDReader.h" + class CBC_CommonBitArray; + class CBC_OnedCode39Reader : public CBC_OneDReader { public: static const FX_CHAR* ALPHABET_STRING; static const FX_CHAR* CHECKSUM_STRING; static const int32_t CHARACTER_ENCODINGS[44]; - static const int32_t ASTERISK_ENCODING; + static const int32_t ASTERISK_ENCODING = 0x094; + CBC_OnedCode39Reader(); - CBC_OnedCode39Reader(FX_BOOL usingCheckDigit); + explicit CBC_OnedCode39Reader(FX_BOOL usingCheckDigit); CBC_OnedCode39Reader(FX_BOOL usingCheckDigit, FX_BOOL extendedMode); virtual ~CBC_OnedCode39Reader(); + CFX_ByteString DecodeRow(int32_t rowNumber, CBC_CommonBitArray* row, int32_t hints, int32_t& e); private: - FX_BOOL m_usingCheckDigit; - FX_BOOL m_extendedMode; CFX_Int32Array* FindAsteriskPattern(CBC_CommonBitArray* row, int32_t& e); int32_t ToNarrowWidePattern(CFX_Int32Array* counters); FX_CHAR PatternToChar(int32_t pattern, int32_t& e); CFX_ByteString DecodeExtended(CFX_ByteString& encoded, int32_t& e); + + FX_BOOL m_usingCheckDigit; + FX_BOOL m_extendedMode; }; #endif // XFA_FXBARCODE_ONED_BC_ONEDCODE39READER_H_ diff --git a/xfa/fxbarcode/oned/BC_OnedCode39Writer.h b/xfa/fxbarcode/oned/BC_OnedCode39Writer.h index b438727130..f2c340b3fb 100644 --- a/xfa/fxbarcode/oned/BC_OnedCode39Writer.h +++ b/xfa/fxbarcode/oned/BC_OnedCode39Writer.h @@ -7,13 +7,15 @@ #ifndef XFA_FXBARCODE_ONED_BC_ONEDCODE39WRITER_H_ #define XFA_FXBARCODE_ONED_BC_ONEDCODE39WRITER_H_ -enum BC_TEXT_LOC; -class CBC_OneDimWriter; +#include "xfa/fxbarcode/include/BC_Library.h" +#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" + class CBC_OnedCode39Writer : public CBC_OneDimWriter { public: CBC_OnedCode39Writer(); - CBC_OnedCode39Writer(FX_BOOL extendedMode); + explicit CBC_OnedCode39Writer(FX_BOOL extendedMode); virtual ~CBC_OnedCode39Writer(); + uint8_t* Encode(const CFX_ByteString& contents, BCFORMAT format, int32_t& outWidth, @@ -33,6 +35,7 @@ class CBC_OnedCode39Writer : public CBC_OneDimWriter { int32_t codeLength, FX_BOOL isDevice, int32_t& e); + CFX_WideString encodedContents(const CFX_WideStringC& contents, int32_t& e); FX_BOOL CheckContentValidity(const CFX_WideStringC& contents); FX_BOOL CheckExtendedContentValidity(const CFX_WideStringC& contents); @@ -46,6 +49,7 @@ class CBC_OnedCode39Writer : public CBC_OneDimWriter { private: void ToIntArray(int32_t a, int32_t* toReturn); FX_CHAR CalcCheckSum(const CFX_ByteString& contents, int32_t& e); + int32_t m_iWideNarrRatio; FX_BOOL m_extendedMode; }; diff --git a/xfa/fxbarcode/oned/BC_OnedEAN13Reader.h b/xfa/fxbarcode/oned/BC_OnedEAN13Reader.h index 0d9d614901..4d01e42abf 100644 --- a/xfa/fxbarcode/oned/BC_OnedEAN13Reader.h +++ b/xfa/fxbarcode/oned/BC_OnedEAN13Reader.h @@ -6,12 +6,18 @@ #ifndef XFA_FXBARCODE_ONED_BC_ONEDEAN13READER_H_ #define XFA_FXBARCODE_ONED_BC_ONEDEAN13READER_H_ -class CBC_OneDimReader; + +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "xfa/fxbarcode/oned/BC_OneDimReader.h" + class CBC_CommonBitArray; -class CBC_OnedEAN13Reader; +class CBC_OnedUPCAReader; + class CBC_OnedEAN13Reader : public CBC_OneDimReader { public: static const int32_t FIRST_DIGIT_ENCODINGS[10]; + CBC_OnedEAN13Reader(); virtual ~CBC_OnedEAN13Reader(); @@ -21,11 +27,12 @@ class CBC_OnedEAN13Reader : public CBC_OneDimReader { int32_t& e); protected: + friend class CBC_OnedUPCAReader; + int32_t DecodeMiddle(CBC_CommonBitArray* row, CFX_Int32Array* startRange, CFX_ByteString& resultString, int32_t& e); - friend class CBC_OnedUPCAReader; }; #endif // XFA_FXBARCODE_ONED_BC_ONEDEAN13READER_H_ diff --git a/xfa/fxbarcode/oned/BC_OnedEAN13Writer.h b/xfa/fxbarcode/oned/BC_OnedEAN13Writer.h index fd23129975..de17ac713e 100644 --- a/xfa/fxbarcode/oned/BC_OnedEAN13Writer.h +++ b/xfa/fxbarcode/oned/BC_OnedEAN13Writer.h @@ -7,12 +7,14 @@ #ifndef XFA_FXBARCODE_ONED_BC_ONEDEAN13WRITER_H_ #define XFA_FXBARCODE_ONED_BC_ONEDEAN13WRITER_H_ -class CBC_OneDimWriter; -class CBC_OnedEAN13Writer; -class CBC_OnedEAN13Writer : public CBC_OneDimWriter { - private: - int32_t m_codeWidth; +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" +class CFX_DIBitmap; +class CFX_RenderDevice; + +class CBC_OnedEAN13Writer : public CBC_OneDimWriter { public: CBC_OnedEAN13Writer(); virtual ~CBC_OnedEAN13Writer(); @@ -31,6 +33,7 @@ class CBC_OnedEAN13Writer : public CBC_OneDimWriter { uint8_t* Encode(const CFX_ByteString& contents, int32_t& outLength, int32_t& e); + void RenderResult(const CFX_WideStringC& contents, uint8_t* code, int32_t codeLength, @@ -48,6 +51,9 @@ class CBC_OnedEAN13Writer : public CBC_OneDimWriter { int32_t barWidth, int32_t multiple, int32_t& e); + + private: + int32_t m_codeWidth; }; #endif // XFA_FXBARCODE_ONED_BC_ONEDEAN13WRITER_H_ diff --git a/xfa/fxbarcode/oned/BC_OnedEAN8Reader.h b/xfa/fxbarcode/oned/BC_OnedEAN8Reader.h index fe2d33d66f..ab2d5e3178 100644 --- a/xfa/fxbarcode/oned/BC_OnedEAN8Reader.h +++ b/xfa/fxbarcode/oned/BC_OnedEAN8Reader.h @@ -7,9 +7,10 @@ #ifndef XFA_FXBARCODE_ONED_BC_ONEDEAN8READER_H_ #define XFA_FXBARCODE_ONED_BC_ONEDEAN8READER_H_ -class CBC_OneDimReader; +#include "xfa/fxbarcode/oned/BC_OneDimReader.h" + class CBC_CommonBitArray; -class CBC_OnedEAN8Reader; + class CBC_OnedEAN8Reader : public CBC_OneDimReader { public: CBC_OnedEAN8Reader(); diff --git a/xfa/fxbarcode/oned/BC_OnedEAN8Writer.h b/xfa/fxbarcode/oned/BC_OnedEAN8Writer.h index fc033ffcbf..9110d94e20 100644 --- a/xfa/fxbarcode/oned/BC_OnedEAN8Writer.h +++ b/xfa/fxbarcode/oned/BC_OnedEAN8Writer.h @@ -7,9 +7,14 @@ #ifndef XFA_FXBARCODE_ONED_BC_ONEDEAN8WRITER_H_ #define XFA_FXBARCODE_ONED_BC_ONEDEAN8WRITER_H_ -enum BC_TEXT_LOC; -class CBC_OneDimWriter; -class CBC_OnedEAN8Writer; +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "xfa/fxbarcode/include/BC_Library.h" +#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" + +class CFX_DIBitmap; +class CFX_RenderDevice; + class CBC_OnedEAN8Writer : public CBC_OneDimWriter { private: int32_t m_codeWidth; @@ -17,6 +22,7 @@ class CBC_OnedEAN8Writer : public CBC_OneDimWriter { public: CBC_OnedEAN8Writer(); virtual ~CBC_OnedEAN8Writer(); + uint8_t* Encode(const CFX_ByteString& contents, BCFORMAT format, int32_t& outWidth, @@ -31,6 +37,7 @@ class CBC_OnedEAN8Writer : public CBC_OneDimWriter { uint8_t* Encode(const CFX_ByteString& contents, int32_t& outLength, int32_t& e); + void RenderResult(const CFX_WideStringC& contents, uint8_t* code, int32_t codeLength, diff --git a/xfa/fxbarcode/oned/BC_OnedUPCAReader.h b/xfa/fxbarcode/oned/BC_OnedUPCAReader.h index 306683e1cc..4d3f479b71 100644 --- a/xfa/fxbarcode/oned/BC_OnedUPCAReader.h +++ b/xfa/fxbarcode/oned/BC_OnedUPCAReader.h @@ -7,18 +7,21 @@ #ifndef XFA_FXBARCODE_ONED_BC_ONEDUPCAREADER_H_ #define XFA_FXBARCODE_ONED_BC_ONEDUPCAREADER_H_ +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "xfa/fxbarcode/oned/BC_OneDimReader.h" + class CBC_BinaryBitmap; class CBC_CommonBitArray; -class CBC_OneDimReader; class CBC_OnedEAN13Reader; -class CBC_OnedUPCAReader; -class CBC_OnedUPCAReader : public CBC_OneDimReader { - private: - CBC_OnedEAN13Reader* m_ean13Reader; +class CBC_OnedUPCAReader : public CBC_OneDimReader { public: CBC_OnedUPCAReader(); virtual ~CBC_OnedUPCAReader(); + + virtual void Init(); + CFX_ByteString DecodeRow(int32_t rowNumber, CBC_CommonBitArray* row, int32_t hints, @@ -30,7 +33,6 @@ class CBC_OnedUPCAReader : public CBC_OneDimReader { int32_t& e); CFX_ByteString Decode(CBC_BinaryBitmap* image, int32_t& e); CFX_ByteString Decode(CBC_BinaryBitmap* image, int32_t hints, int32_t& e); - virtual void Init(); protected: int32_t DecodeMiddle(CBC_CommonBitArray* row, @@ -38,6 +40,10 @@ class CBC_OnedUPCAReader : public CBC_OneDimReader { CFX_ByteString& resultString, int32_t& e); CFX_ByteString MaybeReturnResult(CFX_ByteString& result, int32_t& e); + + private: + CBC_OnedEAN13Reader* m_ean13Reader; + }; #endif // XFA_FXBARCODE_ONED_BC_ONEDUPCAREADER_H_ diff --git a/xfa/fxbarcode/oned/BC_OnedUPCAWriter.h b/xfa/fxbarcode/oned/BC_OnedUPCAWriter.h index f376929b1b..38f3ca57dd 100644 --- a/xfa/fxbarcode/oned/BC_OnedUPCAWriter.h +++ b/xfa/fxbarcode/oned/BC_OnedUPCAWriter.h @@ -7,16 +7,22 @@ #ifndef XFA_FXBARCODE_ONED_BC_ONEDUPCAWRITER_H_ #define XFA_FXBARCODE_ONED_BC_ONEDUPCAWRITER_H_ +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" + class CBC_OnedEAN13Writer; -class CBC_OnedUPCAWriter; -class CBC_OnedUPCAWriter : public CBC_OneDimWriter { - private: - CBC_OnedEAN13Writer* m_subWriter; +class CFX_DIBitmap; +class CFX_Matrix; +class CFX_RenderDevice; +class CBC_OnedUPCAWriter : public CBC_OneDimWriter { public: CBC_OnedUPCAWriter(); virtual ~CBC_OnedUPCAWriter(); + virtual void Init(); + uint8_t* Encode(const CFX_ByteString& contents, BCFORMAT format, int32_t& outWidth, @@ -33,6 +39,7 @@ class CBC_OnedUPCAWriter : public CBC_OneDimWriter { int32_t& e) { return nullptr; } + void RenderResult(const CFX_WideStringC& contents, uint8_t* code, int32_t codeLength, @@ -50,6 +57,9 @@ class CBC_OnedUPCAWriter : public CBC_OneDimWriter { int32_t barWidth, int32_t multiple, int32_t& e); + + private: + CBC_OnedEAN13Writer* m_subWriter; }; #endif // XFA_FXBARCODE_ONED_BC_ONEDUPCAWRITER_H_ diff --git a/xfa/fxbarcode/pdf417/BC_PDF417Reader.h b/xfa/fxbarcode/pdf417/BC_PDF417Reader.h index 2a5c39bae2..f1e0eda8b6 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417Reader.h +++ b/xfa/fxbarcode/pdf417/BC_PDF417Reader.h @@ -7,9 +7,13 @@ #ifndef XFA_FXBARCODE_PDF417_BC_PDF417READER_H_ #define XFA_FXBARCODE_PDF417_BC_PDF417READER_H_ +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "xfa/fxbarcode/BC_Reader.h" + class CBC_BinaryBitmap; class CBC_ResultPoint; -class CBC_PDF417Reader; + class CBC_PDF417Reader : public CBC_Reader { public: CBC_PDF417Reader(); diff --git a/xfa/fxbarcode/pdf417/BC_PDF417Writer.h b/xfa/fxbarcode/pdf417/BC_PDF417Writer.h index f92f57b82c..bc646b8a49 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417Writer.h +++ b/xfa/fxbarcode/pdf417/BC_PDF417Writer.h @@ -7,8 +7,10 @@ #ifndef XFA_FXBARCODE_PDF417_BC_PDF417WRITER_H_ #define XFA_FXBARCODE_PDF417_BC_PDF417WRITER_H_ -class CBC_TwoDimWriter; -class CBC_PDF417Writer; +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "xfa/fxbarcode/BC_TwoDimWriter.h" + class CBC_PDF417Writer : public CBC_TwoDimWriter { public: CBC_PDF417Writer(); diff --git a/xfa/fxfa/app/xfa_ffbarcode.h b/xfa/fxfa/app/xfa_ffbarcode.h index 114a492e4d..cd390e8bcb 100644 --- a/xfa/fxfa/app/xfa_ffbarcode.h +++ b/xfa/fxfa/app/xfa_ffbarcode.h @@ -7,9 +7,9 @@ #ifndef XFA_FXFA_APP_XFA_FFBARCODE_H_ #define XFA_FXFA_APP_XFA_FFBARCODE_H_ +#include "xfa/fxbarcode/include/BC_Library.h" #include "xfa/fxfa/app/xfa_ffpageview.h" #include "xfa/fxfa/app/xfa_fftextedit.h" -#include "xfa/include/fxbarcode/BC_BarCode.h" class CXFA_FFBarcode : public CXFA_FFTextEdit { public: diff --git a/xfa/fxfa/parser/xfa_objectacc_imp.cpp b/xfa/fxfa/parser/xfa_objectacc_imp.cpp index 104fc044ff..1e86e73a22 100644 --- a/xfa/fxfa/parser/xfa_objectacc_imp.cpp +++ b/xfa/fxfa/parser/xfa_objectacc_imp.cpp @@ -5,6 +5,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include "core/include/fxcrt/fx_ext.h" +#include "xfa/fxbarcode/include/BC_Library.h" #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" #include "xfa/fxfa/parser/xfa_docdata.h" #include "xfa/fxfa/parser/xfa_doclayout.h" @@ -15,7 +16,6 @@ #include "xfa/fxfa/parser/xfa_parser.h" #include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_utils.h" -#include "xfa/include/fxbarcode/BC_BarCode.h" static FX_ARGB XFA_WStringToColor(const CFX_WideStringC& wsValue) { uint8_t r = 0, g = 0, b = 0; diff --git a/xfa/include/fwl/basewidget/fwl_barcode.h b/xfa/include/fwl/basewidget/fwl_barcode.h index 944dd4aa6c..0d3db83421 100644 --- a/xfa/include/fwl/basewidget/fwl_barcode.h +++ b/xfa/include/fwl/basewidget/fwl_barcode.h @@ -7,11 +7,11 @@ #ifndef XFA_INCLUDE_FWL_BASEWIDGET_FWL_BARCODE_H_ #define XFA_INCLUDE_FWL_BASEWIDGET_FWL_BARCODE_H_ +#include "xfa/fxbarcode/include/BC_Library.h" #include "xfa/include/fwl/basewidget/fwl_edit.h" -#include "xfa/include/fxbarcode/BC_BarCode.h" class CFWL_WidgetImpProperties; -class IFWL_Barcode; + #define FWL_CLASS_Barcode L"FWL_BARCODE" #define FWL_CLASSHASH_Barcode 366886968 #define FWL_BCDATTRIBUTE_CHARENCODING (1L << 0) @@ -31,6 +31,7 @@ class IFWL_Barcode; #define FWL_PART_BCD_Edge 2 #define FWL_PART_BCD_Background 3 #define FWL_BCUPDATECMD_Data FWL_WGTUPDATECMD_User + class IFWL_BarcodeDP : public IFWL_EditDP { public: virtual BC_CHAR_ENCODING GetCharEncoding() = 0; diff --git a/xfa/include/fwl/basewidget/fxmath_barcode.h b/xfa/include/fwl/basewidget/fxmath_barcode.h index c6ef766f7f..58ce11727c 100644 --- a/xfa/include/fwl/basewidget/fxmath_barcode.h +++ b/xfa/include/fwl/basewidget/fxmath_barcode.h @@ -7,12 +7,21 @@ #ifndef XFA_INCLUDE_FWL_BASEWIDGET_FXMATH_BARCODE_H_ #define XFA_INCLUDE_FWL_BASEWIDGET_FXMATH_BARCODE_H_ -#include "xfa/include/fxbarcode/BC_BarCode.h" +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "core/include/fxge/fx_dib.h" +#include "xfa/fxbarcode/include/BC_Library.h" + +class CFX_Font; +class CFX_Matrix; +class CFX_RenderDevice; class IFX_Barcode { public: virtual ~IFX_Barcode() {} + virtual void Release() = 0; + virtual BC_TYPE GetType() = 0; virtual FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, @@ -47,6 +56,7 @@ class IFX_Barcode { virtual FX_BOOL SetErrorCorrectionLevel(int32_t level) = 0; virtual FX_BOOL SetTruncated(FX_BOOL truncated) = 0; }; + IFX_Barcode* FX_Barcode_Create(BC_TYPE type); #endif // XFA_INCLUDE_FWL_BASEWIDGET_FXMATH_BARCODE_H_ diff --git a/xfa/include/fwl/lightwidget/barcode.h b/xfa/include/fwl/lightwidget/barcode.h index 2dec2a8806..7056f3ac58 100644 --- a/xfa/include/fwl/lightwidget/barcode.h +++ b/xfa/include/fwl/lightwidget/barcode.h @@ -10,7 +10,6 @@ #include "xfa/include/fwl/basewidget/fwl_barcode.h" #include "xfa/include/fwl/core/fwl_error.h" #include "xfa/include/fwl/lightwidget/edit.h" -#include "xfa/include/fxbarcode/BC_BarCode.h" class CFWL_Widget; class CFWL_WidgetProperties; diff --git a/xfa/include/fxbarcode/BC_BarCode.h b/xfa/include/fxbarcode/BC_BarCode.h deleted file mode 100644 index 84745acb77..0000000000 --- a/xfa/include/fxbarcode/BC_BarCode.h +++ /dev/null @@ -1,257 +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_INCLUDE_FXBARCODE_BC_BARCODE_H_ -#define XFA_INCLUDE_FXBARCODE_BC_BARCODE_H_ - -#include "core/include/fxcrt/fx_string.h" -#include "core/include/fxcrt/fx_system.h" -#include "core/include/fxge/fx_dib.h" - -class CBC_Reader; -class CBC_Writer; -class CFX_Font; -class CFX_RenderDevice; - -enum BC_TEXT_LOC { - BC_TEXT_LOC_NONE = 0, - BC_TEXT_LOC_ABOVE, - BC_TEXT_LOC_BELOW, - BC_TEXT_LOC_ABOVEEMBED, - BC_TEXT_LOC_BELOWEMBED -}; - -enum BC_CHAR_ENCODING { CHAR_ENCODING_UTF8 = 0, CHAR_ENCODING_UNICODE }; - -enum BC_TYPE { - BC_UNKNOWN = -1, - BC_CODE39 = 0, - BC_CODABAR, - BC_CODE128, - BC_CODE128_B, - BC_CODE128_C, - BC_EAN8, - BC_UPCA, - BC_EAN13, - BC_QR_CODE, - BC_PDF417, - BC_DATAMATRIX -}; - -void BC_Library_Init(); -void BC_Library_Destory(); - -class CBC_CodeBase { - public: - CBC_CodeBase(); - virtual ~CBC_CodeBase(); - virtual BC_TYPE GetType() = 0; - virtual FX_BOOL Encode(const CFX_WideStringC& contents, - FX_BOOL isDevice, - int32_t& e) = 0; - virtual FX_BOOL RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e) = 0; - virtual FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) = 0; - virtual CFX_WideString Decode(uint8_t* buf, - int32_t width, - int32_t hight, - int32_t& e) = 0; - virtual CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e) = 0; - - virtual FX_BOOL SetCharEncoding(int32_t encoding); - virtual FX_BOOL SetModuleHeight(int32_t moduleHeight); - virtual FX_BOOL SetModuleWidth(int32_t moduleWidth); - - virtual FX_BOOL SetHeight(int32_t height); - virtual FX_BOOL SetWidth(int32_t width); - virtual void SetBackgroundColor(FX_ARGB backgroundColor); - virtual void SetBarcodeColor(FX_ARGB foregroundColor); - - protected: - CBC_Writer* m_pBCWriter; - CBC_Reader* m_pBCReader; -}; -class CBC_OneCode : public CBC_CodeBase { - public: - CBC_OneCode(); - virtual ~CBC_OneCode(); - virtual BC_TYPE GetType() = 0; - virtual FX_BOOL Encode(const CFX_WideStringC& contents, - FX_BOOL isDevice, - int32_t& e) = 0; - virtual FX_BOOL RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e) = 0; - virtual FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) = 0; - virtual CFX_WideString Decode(uint8_t* buf, - int32_t width, - int32_t hight, - int32_t& e) = 0; - virtual CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e) = 0; - virtual FX_BOOL CheckContentValidity(const CFX_WideStringC& contents); - virtual CFX_WideString FilterContents(const CFX_WideStringC& contents); - virtual void SetPrintChecksum(FX_BOOL checksum); - virtual void SetDataLength(int32_t length); - virtual void SetCalChecksum(FX_BOOL calc); - virtual FX_BOOL SetFont(CFX_Font* cFont); - virtual void SetFontSize(FX_FLOAT size); - virtual void SetFontStyle(int32_t style); - virtual void SetFontColor(FX_ARGB color); -}; -class CBC_Code39 : public CBC_OneCode { - public: - CBC_Code39(); - CBC_Code39(FX_BOOL usingCheckDigit); - CBC_Code39(FX_BOOL usingCheckDigit, FX_BOOL extendedMode); - virtual ~CBC_Code39(); - FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); - FX_BOOL RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e); - FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); - CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); - CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); - BC_TYPE GetType() { return BC_CODE39; } - FX_BOOL SetTextLocation(BC_TEXT_LOC location); - FX_BOOL SetWideNarrowRatio(int32_t ratio); - - private: - CFX_WideString m_renderContents; -}; -class CBC_Codabar : public CBC_OneCode { - public: - CBC_Codabar(); - virtual ~CBC_Codabar(); - FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); - FX_BOOL RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e); - FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); - CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); - CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); - BC_TYPE GetType() { return BC_CODABAR; } - FX_BOOL SetStartChar(FX_CHAR start); - FX_BOOL SetEndChar(FX_CHAR end); - FX_BOOL SetTextLocation(BC_TEXT_LOC location); - FX_BOOL SetWideNarrowRatio(int32_t ratio); - - private: - CFX_WideString m_renderContents; -}; -class CBC_Code128 : public CBC_OneCode { - public: - CBC_Code128(BC_TYPE type); - virtual ~CBC_Code128(); - FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); - FX_BOOL RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e); - FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); - CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); - CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); - BC_TYPE GetType() { return BC_CODE128; } - FX_BOOL SetTextLocation(BC_TEXT_LOC loction); - - private: - CFX_WideString m_renderContents; -}; -class CBC_EAN8 : public CBC_OneCode { - public: - CBC_EAN8(); - virtual ~CBC_EAN8(); - FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); - FX_BOOL RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e); - FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); - CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); - CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); - BC_TYPE GetType() { return BC_EAN8; } - - private: - CFX_WideString Preprocess(const CFX_WideStringC& contents); - CFX_WideString m_renderContents; -}; -class CBC_EAN13 : public CBC_OneCode { - public: - CBC_EAN13(); - virtual ~CBC_EAN13(); - FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); - FX_BOOL RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e); - FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); - CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); - CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); - BC_TYPE GetType() { return BC_EAN13; } - - private: - CFX_WideString Preprocess(const CFX_WideStringC& contents); - CFX_WideString m_renderContents; -}; -class CBC_UPCA : public CBC_OneCode { - public: - CBC_UPCA(); - virtual ~CBC_UPCA(); - FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); - FX_BOOL RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e); - FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); - CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); - CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); - BC_TYPE GetType() { return BC_UPCA; } - - private: - CFX_WideString Preprocess(const CFX_WideStringC& contents); - CFX_WideString m_renderContents; -}; -class CBC_QRCode : public CBC_CodeBase { - public: - CBC_QRCode(); - virtual ~CBC_QRCode(); - FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); - FX_BOOL RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e); - FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); - CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); - CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); - BC_TYPE GetType() { return BC_QR_CODE; } - FX_BOOL SetVersion(int32_t version); - FX_BOOL SetErrorCorrectionLevel(int32_t level); -}; -class CBC_PDF417I : public CBC_CodeBase { - public: - CBC_PDF417I(); - virtual ~CBC_PDF417I(); - FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); - FX_BOOL RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e); - FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); - CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); - CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); - BC_TYPE GetType() { return BC_PDF417; } - FX_BOOL SetErrorCorrectionLevel(int32_t level); - void SetTruncated(FX_BOOL truncated); -}; -class CBC_DataMatrix : public CBC_CodeBase { - public: - CBC_DataMatrix(); - virtual ~CBC_DataMatrix(); - FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); - FX_BOOL RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matirx, - int32_t& e); - FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); - CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); - CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); - BC_TYPE GetType() { return BC_DATAMATRIX; } -}; - -#endif // XFA_INCLUDE_FXBARCODE_BC_BARCODE_H_ -- cgit v1.2.3