diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-03-29 15:18:41 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-03-29 21:01:07 +0000 |
commit | e778668fe92b8c60e0537ee48f79d5af6c1a2f1e (patch) | |
tree | ce7ce115b6f7306a6363f4a3d26d0de2c5646aea /xfa/fxbarcode | |
parent | b929ab0886a2b0ceb701989ef126e5b0cabf6997 (diff) | |
download | pdfium-e778668fe92b8c60e0537ee48f79d5af6c1a2f1e.tar.xz |
Move xfa/fxbarcode fxbarcode/
Nothing in fxbarcode/ depends on XFA code. This CL moves xfa/fxbarcode
to be fxbarcode/ and creates a static_library for fxbarcode which is
depend on by the xfa library.
Change-Id: I0b708737b07efb94b769a5238d92af92bc62880d
Reviewed-on: https://pdfium-review.googlesource.com/3291
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxbarcode')
132 files changed, 0 insertions, 14412 deletions
diff --git a/xfa/fxbarcode/BC_Dimension.cpp b/xfa/fxbarcode/BC_Dimension.cpp deleted file mode 100644 index 7a4b256f31..0000000000 --- a/xfa/fxbarcode/BC_Dimension.cpp +++ /dev/null @@ -1,46 +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 2012 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_Dimension.h" -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" - -CBC_Dimension::CBC_Dimension() {} -CBC_Dimension::CBC_Dimension(int32_t width, int32_t height, int32_t& e) { - if (width < 0 || height < 0) { - e = BCExceptionHeightAndWidthMustBeAtLeast1; - } - m_width = width; - m_height = height; -} -CBC_Dimension::~CBC_Dimension() {} -int32_t CBC_Dimension::getWidth() { - return m_width; -} -int32_t CBC_Dimension::getHeight() { - return m_height; -} -int32_t CBC_Dimension::hashCode() { - return m_width * 32713 + m_height; -} -CFX_WideString CBC_Dimension::toString() { - return (wchar_t)(m_width + (wchar_t)'x' + m_height); -} diff --git a/xfa/fxbarcode/BC_Dimension.h b/xfa/fxbarcode/BC_Dimension.h deleted file mode 100644 index 2050b0faaf..0000000000 --- a/xfa/fxbarcode/BC_Dimension.h +++ /dev/null @@ -1,29 +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_FXBARCODE_BC_DIMENSION_H_ -#define XFA_FXBARCODE_BC_DIMENSION_H_ - -#include <cstdint> - -#include "core/fxcrt/fx_string.h" - -class CBC_Dimension { - public: - CBC_Dimension(); - CBC_Dimension(int32_t width, int32_t height, int32_t& e); - virtual ~CBC_Dimension(); - int32_t getWidth(); - int32_t getHeight(); - int32_t hashCode(); - CFX_WideString toString(); - - private: - int32_t m_width; - int32_t m_height; -}; - -#endif // XFA_FXBARCODE_BC_DIMENSION_H_ diff --git a/xfa/fxbarcode/BC_Library.cpp b/xfa/fxbarcode/BC_Library.cpp deleted file mode 100644 index 075bc2247d..0000000000 --- a/xfa/fxbarcode/BC_Library.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxbarcode/BC_Library.h" - -#include <stdint.h> - -#include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" -#include "xfa/fxbarcode/datamatrix/BC_ErrorCorrection.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderMode.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderVersion.h" - -void BC_Library_Init() { - CBC_QRCoderErrorCorrectionLevel::Initialize(); - CBC_QRCoderMode::Initialize(); - CBC_QRCoderVersion::Initialize(); - CBC_ReedSolomonGF256::Initialize(); - CBC_SymbolInfo::Initialize(); - CBC_ErrorCorrection::Initialize(); - CBC_PDF417HighLevelEncoder::Initialize(); -} -void BC_Library_Destory() { - CBC_QRCoderErrorCorrectionLevel::Finalize(); - CBC_QRCoderMode::Finalize(); - CBC_QRCoderVersion::Finalize(); - CBC_ReedSolomonGF256::Finalize(); - CBC_SymbolInfo::Finalize(); - CBC_ErrorCorrection::Finalize(); - CBC_PDF417HighLevelEncoder::Finalize(); -} diff --git a/xfa/fxbarcode/BC_Library.h b/xfa/fxbarcode/BC_Library.h deleted file mode 100644 index 47ef9d1532..0000000000 --- a/xfa/fxbarcode/BC_Library.h +++ /dev/null @@ -1,38 +0,0 @@ -// 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_BC_LIBRARY_H_ -#define XFA_FXBARCODE_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_BC_LIBRARY_H_ diff --git a/xfa/fxbarcode/BC_TwoDimWriter.cpp b/xfa/fxbarcode/BC_TwoDimWriter.cpp deleted file mode 100644 index 9c9427aaa5..0000000000 --- a/xfa/fxbarcode/BC_TwoDimWriter.cpp +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include <algorithm> - -#include "core/fxge/cfx_graphstatedata.h" -#include "core/fxge/cfx_pathdata.h" -#include "core/fxge/cfx_renderdevice.h" -#include "third_party/base/numerics/safe_math.h" -#include "third_party/base/ptr_util.h" -#include "xfa/fxbarcode/BC_TwoDimWriter.h" -#include "xfa/fxbarcode/BC_Writer.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" - -CBC_TwoDimWriter::CBC_TwoDimWriter() : m_iCorrectLevel(1), m_bFixedSize(true) {} - -CBC_TwoDimWriter::~CBC_TwoDimWriter() {} - -void CBC_TwoDimWriter::RenderDeviceResult(CFX_RenderDevice* device, - const CFX_Matrix* matrix) { - CFX_GraphStateData stateData; - CFX_PathData path; - path.AppendRect(0, 0, (float)m_Width, (float)m_Height); - device->DrawPath(&path, matrix, &stateData, m_backgroundColor, - m_backgroundColor, FXFILL_ALTERNATE); - int32_t leftPos = 0; - int32_t topPos = 0; - if (m_bFixedSize) { - leftPos = (m_Width - m_output->GetWidth()) / 2; - topPos = (m_Height - m_output->GetHeight()) / 2; - } - CFX_Matrix matri = *matrix; - if (m_Width < m_output->GetWidth() && m_Height < m_output->GetHeight()) { - CFX_Matrix matriScale((float)m_Width / (float)m_output->GetWidth(), 0.0, - 0.0, (float)m_Height / (float)m_output->GetHeight(), - 0.0, 0.0); - matriScale.Concat(*matrix); - matri = matriScale; - } - for (int32_t x = 0; x < m_output->GetWidth(); x++) { - for (int32_t y = 0; y < m_output->GetHeight(); y++) { - CFX_PathData rect; - rect.AppendRect((float)leftPos + x, (float)topPos + y, - (float)(leftPos + x + 1), (float)(topPos + y + 1)); - if (m_output->Get(x, y)) { - CFX_GraphStateData data; - device->DrawPath(&rect, &matri, &data, m_barColor, 0, FXFILL_WINDING); - } - } - } -} - -int32_t CBC_TwoDimWriter::GetErrorCorrectionLevel() const { - return m_iCorrectLevel; -} - -void CBC_TwoDimWriter::RenderBitmapResult( - CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) { - if (m_bFixedSize) { - pOutBitmap = CreateDIBitmap(m_Width, m_Height); - } else { - pOutBitmap = CreateDIBitmap(m_output->GetWidth(), m_output->GetHeight()); - } - if (!pOutBitmap) { - e = BCExceptionFailToCreateBitmap; - return; - } - pOutBitmap->Clear(m_backgroundColor); - int32_t leftPos = 0; - int32_t topPos = 0; - if (m_bFixedSize) { - leftPos = (m_Width - m_output->GetWidth()) / 2; - topPos = (m_Height - m_output->GetHeight()) / 2; - } - for (int32_t x = 0; x < m_output->GetWidth(); x++) { - for (int32_t y = 0; y < m_output->GetHeight(); y++) { - if (m_output->Get(x, y)) { - pOutBitmap->SetPixel(leftPos + x, topPos + y, m_barColor); - } - } - } - if (!m_bFixedSize) - pOutBitmap = pOutBitmap->StretchTo(m_Width, m_Height); -} - -void CBC_TwoDimWriter::RenderResult(uint8_t* code, - int32_t codeWidth, - int32_t codeHeight, - int32_t& e) { - int32_t inputWidth = codeWidth; - int32_t inputHeight = codeHeight; - int32_t tempWidth = inputWidth + 2; - int32_t tempHeight = inputHeight + 2; - float moduleHSize = std::min(m_ModuleWidth, m_ModuleHeight); - moduleHSize = std::min(moduleHSize, 8.0f); - moduleHSize = std::max(moduleHSize, 1.0f); - pdfium::base::CheckedNumeric<int32_t> scaledWidth = tempWidth; - pdfium::base::CheckedNumeric<int32_t> scaledHeight = tempHeight; - scaledWidth *= moduleHSize; - scaledHeight *= moduleHSize; - - int32_t outputWidth = scaledWidth.ValueOrDie(); - int32_t outputHeight = scaledHeight.ValueOrDie(); - if (m_bFixedSize) { - if (m_Width < outputWidth || m_Height < outputHeight) { - e = BCExceptionBitmapSizeError; - return; - } - } else { - if (m_Width > outputWidth || m_Height > outputHeight) { - outputWidth = - (int32_t)(outputWidth * ceil((float)m_Width / (float)outputWidth)); - outputHeight = - (int32_t)(outputHeight * ceil((float)m_Height / (float)outputHeight)); - } - } - int32_t multiX = (int32_t)ceil((float)outputWidth / (float)tempWidth); - int32_t multiY = (int32_t)ceil((float)outputHeight / (float)tempHeight); - if (m_bFixedSize) { - multiX = std::min(multiX, multiY); - multiY = multiX; - } - int32_t leftPadding = (outputWidth - (inputWidth * multiX)) / 2; - int32_t topPadding = (outputHeight - (inputHeight * multiY)) / 2; - if (leftPadding < 0) { - leftPadding = 0; - } - if (topPadding < 0) { - topPadding = 0; - } - m_output = pdfium::MakeUnique<CBC_CommonBitMatrix>(); - m_output->Init(outputWidth, outputHeight); - for (int32_t inputY = 0, outputY = topPadding; - (inputY < inputHeight) && (outputY < outputHeight - multiY); - inputY++, outputY += multiY) { - for (int32_t inputX = 0, outputX = leftPadding; - (inputX < inputWidth) && (outputX < outputWidth - multiX); - inputX++, outputX += multiX) { - if (code[inputX + inputY * inputWidth] == 1) { - m_output->SetRegion(outputX, outputY, multiX, multiY, e); - if (e != BCExceptionNO) - return; - } - } - } -} diff --git a/xfa/fxbarcode/BC_TwoDimWriter.h b/xfa/fxbarcode/BC_TwoDimWriter.h deleted file mode 100644 index c6e0495aec..0000000000 --- a/xfa/fxbarcode/BC_TwoDimWriter.h +++ /dev/null @@ -1,39 +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_FXBARCODE_BC_TWODIMWRITER_H_ -#define XFA_FXBARCODE_BC_TWODIMWRITER_H_ - -#include <memory> - -#include "xfa/fxbarcode/BC_Writer.h" - -class CBC_CommonBitMatrix; -class CFX_RenderDevice; - -class CBC_TwoDimWriter : public CBC_Writer { - public: - CBC_TwoDimWriter(); - ~CBC_TwoDimWriter() override; - - virtual void RenderResult(uint8_t* code, - int32_t codeWidth, - int32_t codeHeight, - int32_t& e); - virtual void RenderBitmapResult(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e); - virtual void RenderDeviceResult(CFX_RenderDevice* device, - const CFX_Matrix* matrix); - virtual bool SetErrorCorrectionLevel(int32_t level) = 0; - int32_t GetErrorCorrectionLevel() const; - - protected: - int32_t m_iCorrectLevel; - bool m_bFixedSize; - std::unique_ptr<CBC_CommonBitMatrix> m_output; -}; - -#endif // XFA_FXBARCODE_BC_TWODIMWRITER_H_ diff --git a/xfa/fxbarcode/BC_UtilCodingConvert.cpp b/xfa/fxbarcode/BC_UtilCodingConvert.cpp deleted file mode 100644 index 159bced47a..0000000000 --- a/xfa/fxbarcode/BC_UtilCodingConvert.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxbarcode/BC_UtilCodingConvert.h" - -CBC_UtilCodingConvert::CBC_UtilCodingConvert() {} - -CBC_UtilCodingConvert::~CBC_UtilCodingConvert() {} - -void CBC_UtilCodingConvert::UnicodeToLocale(const CFX_WideString& src, - CFX_ByteString& dst) { - dst = CFX_ByteString::FromUnicode(src); -} - -void CBC_UtilCodingConvert::LocaleToUtf8(const CFX_ByteString& src, - CFX_ByteString& dst) { - CFX_WideString unicode = CFX_WideString::FromLocal(src.AsStringC()); - dst = unicode.UTF8Encode(); -} - -void CBC_UtilCodingConvert::LocaleToUtf8(const CFX_ByteString& src, - std::vector<uint8_t>& dst) { - CFX_WideString unicode = CFX_WideString::FromLocal(src.AsStringC()); - CFX_ByteString utf8 = unicode.UTF8Encode(); - for (int32_t i = 0; i < utf8.GetLength(); i++) { - dst.push_back(utf8[i]); - } -} - -void CBC_UtilCodingConvert::Utf8ToLocale(const std::vector<uint8_t>& src, - CFX_ByteString& dst) { - CFX_ByteString utf8; - for (uint8_t value : src) - utf8 += value; - - CFX_WideString unicode = CFX_WideString::FromUTF8(utf8.AsStringC()); - dst = CFX_ByteString::FromUnicode(unicode); -} - -void CBC_UtilCodingConvert::Utf8ToLocale(const uint8_t* src, - int32_t count, - CFX_ByteString& dst) { - CFX_WideString unicode = - CFX_WideString::FromUTF8(CFX_ByteStringC(src, count)); - dst = CFX_ByteString::FromUnicode(unicode); -} - -void CBC_UtilCodingConvert::UnicodeToUTF8(const CFX_WideString& src, - CFX_ByteString& dst) { - dst = src.UTF8Encode(); -} diff --git a/xfa/fxbarcode/BC_UtilCodingConvert.h b/xfa/fxbarcode/BC_UtilCodingConvert.h deleted file mode 100644 index 51cc93df19..0000000000 --- a/xfa/fxbarcode/BC_UtilCodingConvert.h +++ /dev/null @@ -1,33 +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_FXBARCODE_BC_UTILCODINGCONVERT_H_ -#define XFA_FXBARCODE_BC_UTILCODINGCONVERT_H_ - -#include <vector> - -#include "core/fxcrt/fx_basic.h" - -class CBC_UtilCodingConvert { - public: - CBC_UtilCodingConvert(); - virtual ~CBC_UtilCodingConvert(); - static void UnicodeToLocale(const CFX_WideString& source, - CFX_ByteString& result); - static void LocaleToUtf8(const CFX_ByteString& source, - CFX_ByteString& result); - static void LocaleToUtf8(const CFX_ByteString& source, - std::vector<uint8_t>& result); - static void Utf8ToLocale(const std::vector<uint8_t>& source, - CFX_ByteString& result); - static void Utf8ToLocale(const uint8_t* source, - int32_t count, - CFX_ByteString& result); - static void UnicodeToUTF8(const CFX_WideString& source, - CFX_ByteString& result); -}; - -#endif // XFA_FXBARCODE_BC_UTILCODINGCONVERT_H_ diff --git a/xfa/fxbarcode/BC_Utils.cpp b/xfa/fxbarcode/BC_Utils.cpp deleted file mode 100644 index d0e89dce10..0000000000 --- a/xfa/fxbarcode/BC_Utils.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include <vector> - -#include "core/fxcrt/fx_basic.h" -#include "xfa/fxbarcode/utils.h" - -bool BC_FX_ByteString_Replace(CFX_ByteString& dst, - uint32_t first, - uint32_t last, - int32_t count, - char c) { - if (first > last || count <= 0) { - return false; - } - dst.Delete(first, last - first); - for (int32_t i = 0; i < count; i++) { - dst.Insert(0, c); - } - return true; -} - -void BC_FX_ByteString_Append(CFX_ByteString& dst, int32_t count, char c) { - for (int32_t i = 0; i < count; i++) - dst += c; -} -void BC_FX_ByteString_Append(CFX_ByteString& dst, - const std::vector<uint8_t>& ba) { - for (uint8_t value : ba) - dst += value; -} diff --git a/xfa/fxbarcode/BC_Writer.cpp b/xfa/fxbarcode/BC_Writer.cpp deleted file mode 100644 index 69f34148f4..0000000000 --- a/xfa/fxbarcode/BC_Writer.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxbarcode/BC_Writer.h" - -CBC_Writer::CBC_Writer() { - m_CharEncoding = 0; - m_ModuleHeight = 1; - m_ModuleWidth = 1; - m_Height = 320; - m_Width = 640; - m_colorSpace = FXDIB_Argb; - m_barColor = 0xff000000; - m_backgroundColor = 0xffffffff; -} -CBC_Writer::~CBC_Writer() {} -bool CBC_Writer::SetCharEncoding(int32_t encoding) { - m_CharEncoding = encoding; - return true; -} -bool CBC_Writer::SetModuleHeight(int32_t moduleHeight) { - if (moduleHeight > 10 || moduleHeight < 1) { - return false; - } - m_ModuleHeight = moduleHeight; - return true; -} -bool CBC_Writer::SetModuleWidth(int32_t moduleWidth) { - if (moduleWidth > 10 || moduleWidth < 1) { - return false; - } - m_ModuleWidth = moduleWidth; - return true; -} -bool CBC_Writer::SetHeight(int32_t height) { - m_Height = height; - return true; -} -bool CBC_Writer::SetWidth(int32_t width) { - m_Width = width; - return true; -} -void CBC_Writer::SetBackgroundColor(FX_ARGB backgroundColor) { - m_backgroundColor = backgroundColor; -} -void CBC_Writer::SetBarcodeColor(FX_ARGB foregroundColor) { - m_barColor = foregroundColor; -} - -CFX_RetainPtr<CFX_DIBitmap> CBC_Writer::CreateDIBitmap(int32_t width, - int32_t height) { - auto pDIBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); - pDIBitmap->Create(width, height, m_colorSpace); - return pDIBitmap; -} diff --git a/xfa/fxbarcode/BC_Writer.h b/xfa/fxbarcode/BC_Writer.h deleted file mode 100644 index 8dd03ead58..0000000000 --- a/xfa/fxbarcode/BC_Writer.h +++ /dev/null @@ -1,38 +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_FXBARCODE_BC_WRITER_H_ -#define XFA_FXBARCODE_BC_WRITER_H_ - -#include "core/fxcrt/fx_string.h" -#include "core/fxge/fx_dib.h" -#include "xfa/fxbarcode/utils.h" - -class CBC_Writer { - public: - CBC_Writer(); - virtual ~CBC_Writer(); - virtual bool SetCharEncoding(int32_t encoding); - virtual bool SetModuleHeight(int32_t moduleHeight); - virtual bool SetModuleWidth(int32_t moduleWidth); - virtual bool SetHeight(int32_t height); - virtual bool SetWidth(int32_t width); - virtual void SetBackgroundColor(FX_ARGB backgroundColor); - virtual void SetBarcodeColor(FX_ARGB foregroundColor); - - protected: - CFX_RetainPtr<CFX_DIBitmap> CreateDIBitmap(int32_t width, int32_t height); - int32_t m_CharEncoding; - int32_t m_ModuleHeight; - int32_t m_ModuleWidth; - int32_t m_Height; - int32_t m_Width; - FXDIB_Format m_colorSpace; - FX_ARGB m_barColor; - FX_ARGB m_backgroundColor; -}; - -#endif // XFA_FXBARCODE_BC_WRITER_H_ diff --git a/xfa/fxbarcode/DEPS b/xfa/fxbarcode/DEPS deleted file mode 100644 index 1519ceaa93..0000000000 --- a/xfa/fxbarcode/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -include_rules = [ - '+core/fxcodec', -] diff --git a/xfa/fxbarcode/cbc_codabar.cpp b/xfa/fxbarcode/cbc_codabar.cpp deleted file mode 100644 index c49fe95948..0000000000 --- a/xfa/fxbarcode/cbc_codabar.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// 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/oned/BC_OnedCodaBarWriter.h" - -CBC_Codabar::CBC_Codabar() : CBC_OneCode(new CBC_OnedCodaBarWriter) {} - -CBC_Codabar::~CBC_Codabar() {} - -bool CBC_Codabar::SetStartChar(char start) { - if (!m_pBCWriter) - return false; - return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get()) - ->SetStartChar(start); -} - -bool CBC_Codabar::SetEndChar(char end) { - if (m_pBCWriter) - return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get()) - ->SetEndChar(end); - return false; -} - -bool CBC_Codabar::SetTextLocation(BC_TEXT_LOC location) { - return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get()) - ->SetTextLocation(location); -} - -bool CBC_Codabar::SetWideNarrowRatio(int32_t ratio) { - if (m_pBCWriter) - return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get()) - ->SetWideNarrowRatio(ratio); - return false; -} - -bool CBC_Codabar::Encode(const CFX_WideStringC& contents, - 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 = - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->FilterContents(contents); - CFX_ByteString byteString = filtercontents.UTF8Encode(); - m_renderContents = filtercontents; - uint8_t* data = static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get()) - ->Encode(byteString, format, outWidth, outHeight, e); - if (e != BCExceptionNO) - return false; - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderResult(filtercontents.AsStringC(), data, outWidth, isDevice, e); - FX_Free(data); - if (e != BCExceptionNO) - return false; - return true; -} - -bool CBC_Codabar::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) { - CFX_WideString renderCon = - static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get()) - ->encodedContents(m_renderContents.AsStringC()); - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderDeviceResult(device, matrix, renderCon.AsStringC(), e); - if (e != BCExceptionNO) - return false; - return true; -} - -bool CBC_Codabar::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) { - CFX_WideString renderCon = - static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get()) - ->encodedContents(m_renderContents.AsStringC()); - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderBitmapResult(pOutBitmap, renderCon.AsStringC(), e); - if (e != BCExceptionNO) - return false; - return true; -} - -BC_TYPE CBC_Codabar::GetType() { - return BC_CODABAR; -} diff --git a/xfa/fxbarcode/cbc_codabar.h b/xfa/fxbarcode/cbc_codabar.h deleted file mode 100644 index f00c295f44..0000000000 --- a/xfa/fxbarcode/cbc_codabar.h +++ /dev/null @@ -1,40 +0,0 @@ -// 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/fxcrt/fx_coordinates.h" -#include "core/fxcrt/fx_system.h" -#include "core/fxge/fx_dib.h" -#include "xfa/fxbarcode/cbc_onecode.h" - -class CBC_Codabar : public CBC_OneCode { - public: - CBC_Codabar(); - ~CBC_Codabar() override; - - // CBC_OneCode: - bool Encode(const CFX_WideStringC& contents, - bool isDevice, - int32_t& e) override; - bool RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) override; - bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) override; - BC_TYPE GetType() override; - - bool SetStartChar(char start); - bool SetEndChar(char end); - bool SetTextLocation(BC_TEXT_LOC location); - 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 deleted file mode 100644 index ea0bc56fce..0000000000 --- a/xfa/fxbarcode/cbc_code128.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// 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/oned/BC_OnedCode128Writer.h" - -CBC_Code128::CBC_Code128(BC_TYPE type) - : CBC_OneCode(new CBC_OnedCode128Writer(type)) {} - -CBC_Code128::~CBC_Code128() {} - -bool CBC_Code128::SetTextLocation(BC_TEXT_LOC location) { - if (m_pBCWriter) - return static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get()) - ->SetTextLocation(location); - return false; -} - -bool CBC_Code128::Encode(const CFX_WideStringC& contents, - 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 && - static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get())->GetType() == - BC_CODE128_C) { - content += '0'; - } - CFX_WideString encodeContents = - static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get()) - ->FilterContents(content.AsStringC()); - m_renderContents = encodeContents; - CFX_ByteString byteString = encodeContents.UTF8Encode(); - uint8_t* data = static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get()) - ->Encode(byteString, format, outWidth, outHeight, e); - if (e != BCExceptionNO) - return false; - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice, e); - FX_Free(data); - if (e != BCExceptionNO) - return false; - return true; -} - -bool CBC_Code128::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) { - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderDeviceResult(device, matrix, m_renderContents.AsStringC(), e); - if (e != BCExceptionNO) - return false; - return true; -} - -bool CBC_Code128::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) { - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e); - return e == BCExceptionNO; -} - -BC_TYPE CBC_Code128::GetType() { - return BC_CODE128; -} - diff --git a/xfa/fxbarcode/cbc_code128.h b/xfa/fxbarcode/cbc_code128.h deleted file mode 100644 index d8505760a6..0000000000 --- a/xfa/fxbarcode/cbc_code128.h +++ /dev/null @@ -1,37 +0,0 @@ -// 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/fxcrt/fx_coordinates.h" -#include "core/fxcrt/fx_system.h" -#include "core/fxge/fx_dib.h" -#include "xfa/fxbarcode/cbc_onecode.h" - -class CBC_Code128 : public CBC_OneCode { - public: - explicit CBC_Code128(BC_TYPE type); - ~CBC_Code128() override; - - // CBC_OneCode: - bool Encode(const CFX_WideStringC& contents, - bool isDevice, - int32_t& e) override; - bool RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) override; - bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) override; - BC_TYPE GetType() override; - - 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 deleted file mode 100644 index e3cfccbd90..0000000000 --- a/xfa/fxbarcode/cbc_code39.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// 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/oned/BC_OnedCode39Writer.h" - -CBC_Code39::CBC_Code39() : CBC_OneCode(new CBC_OnedCode39Writer) {} - -CBC_Code39::~CBC_Code39() {} - -bool CBC_Code39::Encode(const CFX_WideStringC& contents, - 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 = - static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) - ->FilterContents(contents); - CFX_WideString renderContents = - static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) - ->RenderTextContents(contents); - m_renderContents = renderContents; - CFX_ByteString byteString = filtercontents.UTF8Encode(); - uint8_t* data = static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) - ->Encode(byteString, format, outWidth, outHeight, e); - if (e != BCExceptionNO) - return false; - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderResult(renderContents.AsStringC(), data, outWidth, isDevice, e); - FX_Free(data); - if (e != BCExceptionNO) - return false; - return true; -} - -bool CBC_Code39::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) { - CFX_WideString renderCon = - static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) - ->encodedContents(m_renderContents.AsStringC(), e); - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderDeviceResult(device, matrix, renderCon.AsStringC(), e); - if (e != BCExceptionNO) - return false; - return true; -} - -bool CBC_Code39::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) { - CFX_WideString renderCon = - static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) - ->encodedContents(m_renderContents.AsStringC(), e); - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderBitmapResult(pOutBitmap, renderCon.AsStringC(), e); - return e == BCExceptionNO; -} - -BC_TYPE CBC_Code39::GetType() { - return BC_CODE39; -} - -bool CBC_Code39::SetTextLocation(BC_TEXT_LOC location) { - if (m_pBCWriter) - return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) - ->SetTextLocation(location); - return false; -} - -bool CBC_Code39::SetWideNarrowRatio(int32_t ratio) { - if (m_pBCWriter) - return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) - ->SetWideNarrowRatio(ratio); - return false; -} diff --git a/xfa/fxbarcode/cbc_code39.h b/xfa/fxbarcode/cbc_code39.h deleted file mode 100644 index 0320211631..0000000000 --- a/xfa/fxbarcode/cbc_code39.h +++ /dev/null @@ -1,38 +0,0 @@ -// 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/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "core/fxge/fx_dib.h" -#include "xfa/fxbarcode/cbc_onecode.h" - -class CBC_Code39 : public CBC_OneCode { - public: - CBC_Code39(); - ~CBC_Code39() override; - - // CBC_OneCode: - bool Encode(const CFX_WideStringC& contents, - bool isDevice, - int32_t& e) override; - bool RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) override; - bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) override; - BC_TYPE GetType() override; - - bool SetTextLocation(BC_TEXT_LOC location); - 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 deleted file mode 100644 index 5b4cb713bb..0000000000 --- a/xfa/fxbarcode/cbc_codebase.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// 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_Writer* pWriter) : m_pBCWriter(pWriter) {} - -CBC_CodeBase::~CBC_CodeBase() {} - -bool CBC_CodeBase::SetCharEncoding(int32_t encoding) { - return m_pBCWriter && m_pBCWriter->SetCharEncoding(encoding); -} - -bool CBC_CodeBase::SetModuleHeight(int32_t moduleHeight) { - return m_pBCWriter && m_pBCWriter->SetModuleHeight(moduleHeight); -} - -bool CBC_CodeBase::SetModuleWidth(int32_t moduleWidth) { - return m_pBCWriter && m_pBCWriter->SetModuleWidth(moduleWidth); -} - -bool CBC_CodeBase::SetHeight(int32_t height) { - return m_pBCWriter && m_pBCWriter->SetHeight(height); -} - -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 deleted file mode 100644 index 37a65d2cf6..0000000000 --- a/xfa/fxbarcode/cbc_codebase.h +++ /dev/null @@ -1,48 +0,0 @@ -// 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 <memory> - -#include "core/fxcrt/fx_system.h" -#include "core/fxge/fx_dib.h" -#include "xfa/fxbarcode/BC_Library.h" - -class CBC_Writer; -class CBC_Reader; -class CFX_DIBitmap; -class CFX_RenderDevice; - -class CBC_CodeBase { - public: - explicit CBC_CodeBase(CBC_Writer* pWriter); - virtual ~CBC_CodeBase(); - - virtual BC_TYPE GetType() = 0; - virtual bool Encode(const CFX_WideStringC& contents, - bool isDevice, - int32_t& e) = 0; - virtual bool RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) = 0; - virtual bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) = 0; - - bool SetCharEncoding(int32_t encoding); - bool SetModuleHeight(int32_t moduleHeight); - bool SetModuleWidth(int32_t moduleWidth); - bool SetHeight(int32_t height); - bool SetWidth(int32_t width); - void SetBackgroundColor(FX_ARGB backgroundColor); - void SetBarcodeColor(FX_ARGB foregroundColor); - - protected: - std::unique_ptr<CBC_Writer> m_pBCWriter; -}; - -#endif // XFA_FXBARCODE_CBC_CODEBASE_H_ diff --git a/xfa/fxbarcode/cbc_datamatrix.cpp b/xfa/fxbarcode/cbc_datamatrix.cpp deleted file mode 100644 index ebfa8b9901..0000000000 --- a/xfa/fxbarcode/cbc_datamatrix.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// 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/datamatrix/BC_DataMatrixWriter.h" - -CBC_DataMatrix::CBC_DataMatrix() : CBC_CodeBase(new CBC_DataMatrixWriter) {} - -CBC_DataMatrix::~CBC_DataMatrix() {} - -bool CBC_DataMatrix::Encode(const CFX_WideStringC& contents, - bool isDevice, - int32_t& e) { - int32_t outWidth = 0; - int32_t outHeight = 0; - uint8_t* data = - static_cast<CBC_DataMatrixWriter*>(m_pBCWriter.get()) - ->Encode(CFX_WideString(contents), outWidth, outHeight, e); - if (e != BCExceptionNO) - return false; - static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) - ->RenderResult(data, outWidth, outHeight, e); - FX_Free(data); - if (e != BCExceptionNO) - return false; - return true; -} - -bool CBC_DataMatrix::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) { - static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) - ->RenderDeviceResult(device, matrix); - return true; -} - -bool CBC_DataMatrix::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) { - static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) - ->RenderBitmapResult(pOutBitmap, e); - return e == BCExceptionNO; -} - -BC_TYPE CBC_DataMatrix::GetType() { - return BC_DATAMATRIX; -} diff --git a/xfa/fxbarcode/cbc_datamatrix.h b/xfa/fxbarcode/cbc_datamatrix.h deleted file mode 100644 index ebca372f3f..0000000000 --- a/xfa/fxbarcode/cbc_datamatrix.h +++ /dev/null @@ -1,32 +0,0 @@ -// 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/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "core/fxge/fx_dib.h" -#include "xfa/fxbarcode/cbc_codebase.h" - -class CBC_DataMatrix : public CBC_CodeBase { - public: - CBC_DataMatrix(); - ~CBC_DataMatrix() override; - - // CBC_OneCode: - bool Encode(const CFX_WideStringC& contents, - bool isDevice, - int32_t& e) override; - bool RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) override; - bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) override; - BC_TYPE GetType() override; -}; - -#endif // XFA_FXBARCODE_CBC_DATAMATRIX_H_ diff --git a/xfa/fxbarcode/cbc_ean13.cpp b/xfa/fxbarcode/cbc_ean13.cpp deleted file mode 100644 index afe52db9dd..0000000000 --- a/xfa/fxbarcode/cbc_ean13.cpp +++ /dev/null @@ -1,95 +0,0 @@ -// 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/oned/BC_OnedEAN13Writer.h" - -CBC_EAN13::CBC_EAN13() : CBC_OneCode(new CBC_OnedEAN13Writer) {} - -CBC_EAN13::~CBC_EAN13() {} - -CFX_WideString CBC_EAN13::Preprocess(const CFX_WideStringC& contents) { - CFX_WideString encodeContents = - static_cast<CBC_OnedEAN13Writer*>(m_pBCWriter.get()) - ->FilterContents(contents); - int32_t length = encodeContents.GetLength(); - if (length <= 12) { - for (int32_t i = 0; i < 12 - length; i++) - encodeContents = wchar_t('0') + encodeContents; - - CFX_ByteString byteString = encodeContents.UTF8Encode(); - int32_t checksum = static_cast<CBC_OnedEAN13Writer*>(m_pBCWriter.get()) - ->CalcChecksum(byteString); - byteString += checksum - 0 + '0'; - encodeContents = byteString.UTF8Decode(); - } - if (length > 13) - encodeContents = encodeContents.Mid(0, 13); - - return encodeContents; -} - -bool CBC_EAN13::Encode(const CFX_WideStringC& contents, - 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<CBC_OnedEAN13Writer*>(m_pBCWriter.get()) - ->Encode(byteString, format, outWidth, outHeight, e); - if (e != BCExceptionNO) - return false; - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice, e); - FX_Free(data); - if (e != BCExceptionNO) - return false; - return true; -} - -bool CBC_EAN13::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) { - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderDeviceResult(device, matrix, m_renderContents.AsStringC(), e); - if (e != BCExceptionNO) - return false; - return true; -} - -bool CBC_EAN13::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) { - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e); - return e == BCExceptionNO; -} - -BC_TYPE CBC_EAN13::GetType() { - return BC_EAN13; -} diff --git a/xfa/fxbarcode/cbc_ean13.h b/xfa/fxbarcode/cbc_ean13.h deleted file mode 100644 index 5f23855ead..0000000000 --- a/xfa/fxbarcode/cbc_ean13.h +++ /dev/null @@ -1,36 +0,0 @@ -// 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/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "core/fxge/fx_dib.h" -#include "xfa/fxbarcode/cbc_onecode.h" - -class CBC_EAN13 : public CBC_OneCode { - public: - CBC_EAN13(); - ~CBC_EAN13() override; - - // CBC_OneCode: - bool Encode(const CFX_WideStringC& contents, - bool isDevice, - int32_t& e) override; - bool RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) override; - bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) override; - BC_TYPE GetType() override; - - 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 deleted file mode 100644 index 408b43a608..0000000000 --- a/xfa/fxbarcode/cbc_ean8.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// 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/oned/BC_OnedEAN8Writer.h" - -CBC_EAN8::CBC_EAN8() : CBC_OneCode(new CBC_OnedEAN8Writer) {} - -CBC_EAN8::~CBC_EAN8() {} - -CFX_WideString CBC_EAN8::Preprocess(const CFX_WideStringC& contents) { - CFX_WideString encodeContents = - static_cast<CBC_OnedEAN8Writer*>(m_pBCWriter.get()) - ->FilterContents(contents); - int32_t length = encodeContents.GetLength(); - if (length <= 7) { - for (int32_t i = 0; i < 7 - length; i++) - encodeContents = wchar_t('0') + encodeContents; - - CFX_ByteString byteString = encodeContents.UTF8Encode(); - int32_t checksum = static_cast<CBC_OnedEAN8Writer*>(m_pBCWriter.get()) - ->CalcChecksum(byteString); - encodeContents += wchar_t(checksum - 0 + '0'); - } - if (length > 8) - encodeContents = encodeContents.Mid(0, 8); - - return encodeContents; -} - -bool CBC_EAN8::Encode(const CFX_WideStringC& contents, - 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<CBC_OnedEAN8Writer*>(m_pBCWriter.get()) - ->Encode(byteString, format, outWidth, outHeight, e); - if (e != BCExceptionNO) - return false; - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice, e); - FX_Free(data); - if (e != BCExceptionNO) - return false; - return true; -} - -bool CBC_EAN8::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) { - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderDeviceResult(device, matrix, m_renderContents.AsStringC(), e); - if (e != BCExceptionNO) - return false; - return true; -} - -bool CBC_EAN8::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) { - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e); - return e == BCExceptionNO; -} - -BC_TYPE CBC_EAN8::GetType() { - return BC_EAN8; -} diff --git a/xfa/fxbarcode/cbc_ean8.h b/xfa/fxbarcode/cbc_ean8.h deleted file mode 100644 index 478a67405c..0000000000 --- a/xfa/fxbarcode/cbc_ean8.h +++ /dev/null @@ -1,36 +0,0 @@ -// 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/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "core/fxge/fx_dib.h" -#include "xfa/fxbarcode/cbc_onecode.h" - -class CBC_EAN8 : public CBC_OneCode { - public: - CBC_EAN8(); - ~CBC_EAN8() override; - - // CBC_OneCode: - bool Encode(const CFX_WideStringC& contents, - bool isDevice, - int32_t& e) override; - bool RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) override; - bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) override; - BC_TYPE GetType() override; - - 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 deleted file mode 100644 index cf916402fb..0000000000 --- a/xfa/fxbarcode/cbc_onecode.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// 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_Writer* pWriter) : CBC_CodeBase(pWriter) {} - -CBC_OneCode::~CBC_OneCode() {} - -bool CBC_OneCode::CheckContentValidity(const CFX_WideStringC& contents) { - return m_pBCWriter && - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->CheckContentValidity(contents); -} - -CFX_WideString CBC_OneCode::FilterContents(const CFX_WideStringC& contents) { - if (!m_pBCWriter) - return CFX_WideString(); - return static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->FilterContents(contents); -} - -void CBC_OneCode::SetPrintChecksum(bool checksum) { - if (m_pBCWriter) - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->SetPrintChecksum(checksum); -} - -void CBC_OneCode::SetDataLength(int32_t length) { - if (m_pBCWriter) - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetDataLength(length); -} - -void CBC_OneCode::SetCalChecksum(bool calc) { - if (m_pBCWriter) - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetCalcChecksum(calc); -} - -bool CBC_OneCode::SetFont(CFX_Font* cFont) { - if (m_pBCWriter) - return static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetFont(cFont); - return false; -} - -void CBC_OneCode::SetFontSize(float size) { - if (m_pBCWriter) - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetFontSize(size); -} - -void CBC_OneCode::SetFontStyle(int32_t style) { - if (m_pBCWriter) - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetFontStyle(style); -} - -void CBC_OneCode::SetFontColor(FX_ARGB color) { - if (m_pBCWriter) - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetFontColor(color); -} diff --git a/xfa/fxbarcode/cbc_onecode.h b/xfa/fxbarcode/cbc_onecode.h deleted file mode 100644 index ac7eacebfb..0000000000 --- a/xfa/fxbarcode/cbc_onecode.h +++ /dev/null @@ -1,35 +0,0 @@ -// 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/fxcrt/fx_string.h" -#include "core/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: - explicit CBC_OneCode(CBC_Writer* pWriter); - ~CBC_OneCode() override; - - virtual bool CheckContentValidity(const CFX_WideStringC& contents); - virtual CFX_WideString FilterContents(const CFX_WideStringC& contents); - - virtual void SetPrintChecksum(bool checksum); - virtual void SetDataLength(int32_t length); - virtual void SetCalChecksum(bool calc); - virtual bool SetFont(CFX_Font* cFont); - virtual void SetFontSize(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 deleted file mode 100644 index a5e210757a..0000000000 --- a/xfa/fxbarcode/cbc_pdf417i.cpp +++ /dev/null @@ -1,75 +0,0 @@ -// 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/pdf417/BC_PDF417Writer.h" - -CBC_PDF417I::CBC_PDF417I() : CBC_CodeBase(new CBC_PDF417Writer) {} - -CBC_PDF417I::~CBC_PDF417I() {} - -bool CBC_PDF417I::SetErrorCorrectionLevel(int32_t level) { - static_cast<CBC_PDF417Writer*>(m_pBCWriter.get()) - ->SetErrorCorrectionLevel(level); - return true; -} - -void CBC_PDF417I::SetTruncated(bool truncated) { - static_cast<CBC_PDF417Writer*>(m_pBCWriter.get())->SetTruncated(truncated); -} - -bool CBC_PDF417I::Encode(const CFX_WideStringC& contents, - bool isDevice, - int32_t& e) { - int32_t outWidth = 0; - int32_t outHeight = 0; - uint8_t* data = - static_cast<CBC_PDF417Writer*>(m_pBCWriter.get()) - ->Encode(CFX_WideString(contents), outWidth, outHeight, e); - if (e != BCExceptionNO) - return false; - static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) - ->RenderResult(data, outWidth, outHeight, e); - FX_Free(data); - if (e != BCExceptionNO) - return false; - return true; -} - -bool CBC_PDF417I::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) { - static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) - ->RenderDeviceResult(device, matrix); - return true; -} - -bool CBC_PDF417I::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) { - static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) - ->RenderBitmapResult(pOutBitmap, e); - return e == BCExceptionNO; -} - -BC_TYPE CBC_PDF417I::GetType() { - return BC_PDF417; -} diff --git a/xfa/fxbarcode/cbc_pdf417i.h b/xfa/fxbarcode/cbc_pdf417i.h deleted file mode 100644 index c26dceeebd..0000000000 --- a/xfa/fxbarcode/cbc_pdf417i.h +++ /dev/null @@ -1,35 +0,0 @@ -// 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/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "core/fxge/fx_dib.h" -#include "xfa/fxbarcode/cbc_codebase.h" - -class CBC_PDF417I : public CBC_CodeBase { - public: - CBC_PDF417I(); - ~CBC_PDF417I() override; - - // CBC_CodeBase:: - bool Encode(const CFX_WideStringC& contents, - bool isDevice, - int32_t& e) override; - bool RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) override; - bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) override; - BC_TYPE GetType() override; - - bool SetErrorCorrectionLevel(int32_t level); - void SetTruncated(bool truncated); -}; - -#endif // XFA_FXBARCODE_CBC_PDF417I_H_ diff --git a/xfa/fxbarcode/cbc_qrcode.cpp b/xfa/fxbarcode/cbc_qrcode.cpp deleted file mode 100644 index e046857b6b..0000000000 --- a/xfa/fxbarcode/cbc_qrcode.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// 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/qrcode/BC_QRCodeWriter.h" - -CBC_QRCode::CBC_QRCode() : CBC_CodeBase(new CBC_QRCodeWriter) {} - -CBC_QRCode::~CBC_QRCode() {} - -bool CBC_QRCode::SetVersion(int32_t version) { - if (version < 0 || version > 40) - return false; - return m_pBCWriter && - static_cast<CBC_QRCodeWriter*>(m_pBCWriter.get())->SetVersion(version); -} - -bool CBC_QRCode::SetErrorCorrectionLevel(int32_t level) { - if (level < 0 || level > 3) - return false; - - return m_pBCWriter && - static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) - ->SetErrorCorrectionLevel(level); -} - -bool CBC_QRCode::Encode(const CFX_WideStringC& contents, - bool isDevice, - int32_t& e) { - int32_t outWidth = 0; - int32_t outHeight = 0; - CBC_QRCodeWriter* pWriter = static_cast<CBC_QRCodeWriter*>(m_pBCWriter.get()); - uint8_t* data = pWriter->Encode(CFX_WideString(contents), - pWriter->GetErrorCorrectionLevel(), outWidth, - outHeight, e); - if (e != BCExceptionNO) - return false; - pWriter->RenderResult(data, outWidth, outHeight, e); - FX_Free(data); - if (e != BCExceptionNO) - return false; - return true; -} - -bool CBC_QRCode::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) { - static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) - ->RenderDeviceResult(device, matrix); - return true; -} - -bool CBC_QRCode::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) { - static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) - ->RenderBitmapResult(pOutBitmap, e); - return e == BCExceptionNO; -} - -BC_TYPE CBC_QRCode::GetType() { - return BC_QR_CODE; -} diff --git a/xfa/fxbarcode/cbc_qrcode.h b/xfa/fxbarcode/cbc_qrcode.h deleted file mode 100644 index 05f3f6c415..0000000000 --- a/xfa/fxbarcode/cbc_qrcode.h +++ /dev/null @@ -1,35 +0,0 @@ -// 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/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "core/fxge/fx_dib.h" -#include "xfa/fxbarcode/cbc_codebase.h" - -class CBC_QRCode : public CBC_CodeBase { - public: - CBC_QRCode(); - ~CBC_QRCode() override; - - // CBC_CodeBase: - bool Encode(const CFX_WideStringC& contents, - bool isDevice, - int32_t& e) override; - bool RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) override; - bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) override; - BC_TYPE GetType() override; - - bool SetVersion(int32_t version); - 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 deleted file mode 100644 index 915a6aead5..0000000000 --- a/xfa/fxbarcode/cbc_upca.cpp +++ /dev/null @@ -1,98 +0,0 @@ -// 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/oned/BC_OnedUPCAWriter.h" - -CBC_UPCA::CBC_UPCA() : CBC_OneCode(new CBC_OnedUPCAWriter) {} - -CBC_UPCA::~CBC_UPCA() {} - -CFX_WideString CBC_UPCA::Preprocess(const CFX_WideStringC& contents) { - CBC_OnedUPCAWriter* pWriter = - static_cast<CBC_OnedUPCAWriter*>(m_pBCWriter.get()); - CFX_WideString encodeContents = pWriter->FilterContents(contents); - int32_t length = encodeContents.GetLength(); - if (length <= 11) { - for (int32_t i = 0; i < 11 - length; i++) - encodeContents = wchar_t('0') + encodeContents; - - CFX_ByteString byteString = encodeContents.UTF8Encode(); - int32_t checksum = pWriter->CalcChecksum(byteString); - byteString += checksum - 0 + '0'; - encodeContents = byteString.UTF8Decode(); - } - if (length > 12) - encodeContents = encodeContents.Mid(0, 12); - - return encodeContents; -} - -bool CBC_UPCA::Encode(const CFX_WideStringC& contents, - 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* pWriter = - static_cast<CBC_OnedUPCAWriter*>(m_pBCWriter.get()); - - pWriter->Init(); - uint8_t* data = pWriter->Encode(byteString, format, outWidth, outHeight, e); - if (e != BCExceptionNO) - return false; - pWriter->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice, - e); - FX_Free(data); - if (e != BCExceptionNO) - return false; - return true; -} - -bool CBC_UPCA::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) { - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderDeviceResult(device, matrix, m_renderContents.AsStringC(), e); - if (e != BCExceptionNO) - return false; - return true; -} - -bool CBC_UPCA::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) { - static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) - ->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e); - return e == BCExceptionNO; -} - -BC_TYPE CBC_UPCA::GetType() { - return BC_UPCA; -} diff --git a/xfa/fxbarcode/cbc_upca.h b/xfa/fxbarcode/cbc_upca.h deleted file mode 100644 index 4015a3143d..0000000000 --- a/xfa/fxbarcode/cbc_upca.h +++ /dev/null @@ -1,36 +0,0 @@ -// 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/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "core/fxge/fx_dib.h" -#include "xfa/fxbarcode/cbc_onecode.h" - -class CBC_UPCA : public CBC_OneCode { - public: - CBC_UPCA(); - ~CBC_UPCA() override; - - // CBC_CodeBase - bool Encode(const CFX_WideStringC& contents, - bool isDevice, - int32_t& e) override; - bool RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) override; - bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - int32_t& e) override; - BC_TYPE GetType() override; - - private: - CFX_WideString Preprocess(const CFX_WideStringC& contents); - CFX_WideString m_renderContents; -}; - -#endif // XFA_FXBARCODE_CBC_UPCA_H_ diff --git a/xfa/fxbarcode/common/BC_CommonBitArray.cpp b/xfa/fxbarcode/common/BC_CommonBitArray.cpp deleted file mode 100644 index f53e677389..0000000000 --- a/xfa/fxbarcode/common/BC_CommonBitArray.cpp +++ /dev/null @@ -1,124 +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 2007 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/common/BC_CommonBitArray.h" - -#include <utility> - -#include "xfa/fxbarcode/utils.h" - -CBC_CommonBitArray::CBC_CommonBitArray(CBC_CommonBitArray* array) { - m_size = array->GetSize(); - m_bits = array->GetBits(); -} - -CBC_CommonBitArray::CBC_CommonBitArray() { - m_bits.resize(1); - m_size = 0; -} - -CBC_CommonBitArray::CBC_CommonBitArray(int32_t size) { - m_bits.resize((size + 31) >> 5); - m_size = size; -} - -CBC_CommonBitArray::~CBC_CommonBitArray() {} - -size_t CBC_CommonBitArray::GetSize() { - return m_size; -} - -std::vector<int32_t>& CBC_CommonBitArray::GetBits() { - return m_bits; -} - -size_t CBC_CommonBitArray::GetSizeInBytes() { - return (m_size + 7) >> 3; -} - -bool CBC_CommonBitArray::Get(size_t i) { - return (m_bits[i >> 5] & (1 << (i & 0x1f))) != 0; -} - -void CBC_CommonBitArray::Set(size_t i) { - m_bits[i >> 5] |= 1 << (i & 0x1F); -} - -void CBC_CommonBitArray::Flip(size_t i) { - m_bits[i >> 5] ^= 1 << (i & 0x1F); -} - -void CBC_CommonBitArray::SetBulk(size_t i, int32_t newBits) { - m_bits[i >> 5] = newBits; -} - -void CBC_CommonBitArray::Clear() { - for (auto& value : m_bits) - value = 0; -} - -bool CBC_CommonBitArray::IsRange(size_t start, - size_t end, - bool value, - int32_t& e) { - if (end < start) { - e = BCExceptionEndLessThanStart; - return false; - } - if (end == start) { - return true; - } - end--; - int32_t firstInt = start >> 5; - int32_t lastInt = end >> 5; - int32_t i; - for (i = firstInt; i <= lastInt; i++) { - int32_t firstBit = i > firstInt ? 0 : start & 0x1F; - int32_t lastBit = i < lastInt ? 31 : end & 0x1F; - int32_t mask; - if (firstBit == 0 && lastBit == 31) { - mask = -1; - } else { - mask = 0; - for (int32_t j = firstBit; j <= lastBit; j++) { - mask |= 1 << j; - } - } - if ((m_bits[i] & mask) != (value ? mask : 0)) { - return false; - } - } - return true; -} - -int32_t* CBC_CommonBitArray::GetBitArray() { - return m_bits.data(); -} - -void CBC_CommonBitArray::Reverse() { - std::vector<int32_t> newBits(m_bits.size()); - for (size_t i = 0; i < m_size; i++) { - if (Get(m_size - i - 1)) - newBits[i >> 5] |= 1 << (i & 0x1F); - } - m_bits = std::move(newBits); -} diff --git a/xfa/fxbarcode/common/BC_CommonBitArray.h b/xfa/fxbarcode/common/BC_CommonBitArray.h deleted file mode 100644 index 841ca99149..0000000000 --- a/xfa/fxbarcode/common/BC_CommonBitArray.h +++ /dev/null @@ -1,38 +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_FXBARCODE_COMMON_BC_COMMONBITARRAY_H_ -#define XFA_FXBARCODE_COMMON_BC_COMMONBITARRAY_H_ - -#include <vector> - -#include "core/fxcrt/fx_basic.h" - -class CBC_CommonBitArray { - public: - explicit CBC_CommonBitArray(CBC_CommonBitArray* array); - explicit CBC_CommonBitArray(int32_t size); - CBC_CommonBitArray(); - virtual ~CBC_CommonBitArray(); - - size_t GetSize(); - size_t GetSizeInBytes(); - std::vector<int32_t>& GetBits(); - int32_t* GetBitArray(); - bool Get(size_t i); - void Set(size_t i); - void Flip(size_t i); - void SetBulk(size_t i, int32_t newBits); - bool IsRange(size_t start, size_t end, bool value, int32_t& e); - void Reverse(); - void Clear(); - - private: - size_t m_size; - std::vector<int32_t> m_bits; -}; - -#endif // XFA_FXBARCODE_COMMON_BC_COMMONBITARRAY_H_ diff --git a/xfa/fxbarcode/common/BC_CommonBitMatrix.cpp b/xfa/fxbarcode/common/BC_CommonBitMatrix.cpp deleted file mode 100644 index 5e65bd74cf..0000000000 --- a/xfa/fxbarcode/common/BC_CommonBitMatrix.cpp +++ /dev/null @@ -1,147 +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 2007 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/common/BC_CommonBitArray.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/utils.h" - -CBC_CommonBitMatrix::CBC_CommonBitMatrix() { - m_width = 0; - m_height = 0; - m_rowSize = 0; - m_bits = nullptr; -} -void CBC_CommonBitMatrix::Init(int32_t dimension) { - m_width = dimension; - m_height = dimension; - int32_t rowSize = (m_height + 31) >> 5; - m_rowSize = rowSize; - m_bits = FX_Alloc2D(int32_t, m_rowSize, m_height); - FXSYS_memset(m_bits, 0, m_rowSize * m_height * sizeof(int32_t)); -} -void CBC_CommonBitMatrix::Init(int32_t width, int32_t height) { - m_width = width; - m_height = height; - int32_t rowSize = (width + 31) >> 5; - m_rowSize = rowSize; - m_bits = FX_Alloc2D(int32_t, m_rowSize, m_height); - FXSYS_memset(m_bits, 0, m_rowSize * m_height * sizeof(int32_t)); -} -CBC_CommonBitMatrix::~CBC_CommonBitMatrix() { - FX_Free(m_bits); -} -bool CBC_CommonBitMatrix::Get(int32_t x, int32_t y) { - int32_t offset = y * m_rowSize + (x >> 5); - if (offset >= m_rowSize * m_height || offset < 0) { - return false; - } - return ((((uint32_t)m_bits[offset]) >> (x & 0x1f)) & 1) != 0; -} -int32_t* CBC_CommonBitMatrix::GetBits() { - return m_bits; -} -void CBC_CommonBitMatrix::Set(int32_t x, int32_t y) { - int32_t offset = y * m_rowSize + (x >> 5); - if (offset >= m_rowSize * m_height || offset < 0) { - return; - } - m_bits[offset] |= 1 << (x & 0x1f); -} -void CBC_CommonBitMatrix::Flip(int32_t x, int32_t y) { - int32_t offset = y * m_rowSize + (x >> 5); - m_bits[offset] ^= 1 << (x & 0x1f); -} -void CBC_CommonBitMatrix::Clear() { - FXSYS_memset(m_bits, 0, m_rowSize * m_height * sizeof(int32_t)); -} -void CBC_CommonBitMatrix::SetRegion(int32_t left, - int32_t top, - int32_t width, - int32_t height, - int32_t& e) { - if (top < 0 || left < 0) { - e = BCExceptionLeftAndTopMustBeNonnegative; - return; - } - if (height < 1 || width < 1) { - e = BCExceptionHeightAndWidthMustBeAtLeast1; - return; - } - int32_t right = left + width; - int32_t bottom = top + height; - if (m_height < bottom || m_width < right) { - e = BCExceptionRegionMustFitInsideMatrix; - return; - } - int32_t y; - for (y = top; y < bottom; y++) { - int32_t offset = y * m_rowSize; - int32_t x; - for (x = left; x < right; x++) { - m_bits[offset + (x >> 5)] |= 1 << (x & 0x1f); - } - } -} -CBC_CommonBitArray* CBC_CommonBitMatrix::GetRow(int32_t y, - CBC_CommonBitArray* row) { - CBC_CommonBitArray* rowArray = nullptr; - if (!row || static_cast<int32_t>(row->GetSize()) < m_width) { - rowArray = new CBC_CommonBitArray(m_width); - } else { - rowArray = new CBC_CommonBitArray(row); - } - int32_t offset = y * m_rowSize; - int32_t x; - for (x = 0; x < m_rowSize; x++) { - rowArray->SetBulk(x << 5, m_bits[offset + x]); - } - return rowArray; -} -void CBC_CommonBitMatrix::SetRow(int32_t y, CBC_CommonBitArray* row) { - int32_t l = y * m_rowSize; - for (int32_t i = 0; i < m_rowSize; i++) { - m_bits[l] = row->GetBitArray()[i]; - l++; - } -} - -void CBC_CommonBitMatrix::SetCol(int32_t y, CBC_CommonBitArray* col) { - for (size_t i = 0; i < col->GetBits().size(); ++i) - m_bits[i * m_rowSize + y] = col->GetBitArray()[i]; -} - -int32_t CBC_CommonBitMatrix::GetWidth() { - return m_width; -} -int32_t CBC_CommonBitMatrix::GetHeight() { - return m_height; -} -int32_t CBC_CommonBitMatrix::GetRowSize() { - return m_rowSize; -} -int32_t CBC_CommonBitMatrix::GetDimension(int32_t& e) { - if (m_width != m_height) { - e = BCExceptionCanNotCallGetDimensionOnNonSquareMatrix; - return 0; - } - return m_width; -} diff --git a/xfa/fxbarcode/common/BC_CommonBitMatrix.h b/xfa/fxbarcode/common/BC_CommonBitMatrix.h deleted file mode 100644 index ed1f684a37..0000000000 --- a/xfa/fxbarcode/common/BC_CommonBitMatrix.h +++ /dev/null @@ -1,48 +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_FXBARCODE_COMMON_BC_COMMONBITMATRIX_H_ -#define XFA_FXBARCODE_COMMON_BC_COMMONBITMATRIX_H_ - -#include "core/fxcrt/fx_system.h" - -class CBC_CommonBitArray; - -class CBC_CommonBitMatrix { - public: - CBC_CommonBitMatrix(); - virtual ~CBC_CommonBitMatrix(); - - virtual void Init(int32_t dimension); - virtual void Init(int32_t width, int32_t height); - - bool Get(int32_t x, int32_t y); - void Set(int32_t x, int32_t y); - void Flip(int32_t x, int32_t y); - void Clear(); - void SetRegion(int32_t left, - int32_t top, - int32_t width, - int32_t height, - int32_t& e); - CBC_CommonBitArray* GetRow(int32_t y, CBC_CommonBitArray* row); - void SetRow(int32_t y, CBC_CommonBitArray* row); - CBC_CommonBitArray* GetCol(int32_t y, CBC_CommonBitArray* row); - void SetCol(int32_t y, CBC_CommonBitArray* col); - int32_t GetWidth(); - int32_t GetHeight(); - int32_t GetRowSize(); - int32_t GetDimension(int32_t& e); - int32_t* GetBits(); - - private: - int32_t m_width; - int32_t m_height; - int32_t m_rowSize; - int32_t* m_bits; -}; - -#endif // XFA_FXBARCODE_COMMON_BC_COMMONBITMATRIX_H_ diff --git a/xfa/fxbarcode/common/BC_CommonByteArray.cpp b/xfa/fxbarcode/common/BC_CommonByteArray.cpp deleted file mode 100644 index e950f0f941..0000000000 --- a/xfa/fxbarcode/common/BC_CommonByteArray.cpp +++ /dev/null @@ -1,99 +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 2008 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 <algorithm> - -#include "xfa/fxbarcode/common/BC_CommonByteArray.h" - -CBC_CommonByteArray::CBC_CommonByteArray() { - m_bytes = nullptr; - m_size = 0; - m_index = 0; -} -CBC_CommonByteArray::CBC_CommonByteArray(int32_t size) { - m_size = size; - m_bytes = FX_Alloc(uint8_t, size); - FXSYS_memset(m_bytes, 0, size); - m_index = 0; -} -CBC_CommonByteArray::CBC_CommonByteArray(uint8_t* byteArray, int32_t size) { - m_size = size; - m_bytes = FX_Alloc(uint8_t, size); - FXSYS_memcpy(m_bytes, byteArray, size); - m_index = size; -} -CBC_CommonByteArray::~CBC_CommonByteArray() { - FX_Free(m_bytes); -} -int32_t CBC_CommonByteArray::At(int32_t index) const { - return m_bytes[index] & 0xff; -} -void CBC_CommonByteArray::Set(int32_t index, int32_t value) { - m_bytes[index] = (uint8_t)value; -} -int32_t CBC_CommonByteArray::Size() const { - return m_size; -} -bool CBC_CommonByteArray::IsEmpty() const { - return m_size == 0; -} -void CBC_CommonByteArray::AppendByte(int32_t value) { - if (m_size == 0 || m_index >= m_size) { - int32_t newSize = std::max(32, m_size << 1); - Reserve(newSize); - } - m_bytes[m_index] = (uint8_t)value; - m_index++; -} -void CBC_CommonByteArray::Reserve(int32_t capacity) { - if (!m_bytes || m_size < capacity) { - uint8_t* newArray = FX_Alloc(uint8_t, capacity); - if (m_bytes) { - FXSYS_memcpy(newArray, m_bytes, m_size); - FXSYS_memset(newArray + m_size, 0, capacity - m_size); - } else { - FXSYS_memset(newArray, 0, capacity); - } - FX_Free(m_bytes); - m_bytes = newArray; - m_size = capacity; - } -} -void CBC_CommonByteArray::Set(uint8_t* source, int32_t offset, int32_t count) { - FX_Free(m_bytes); - m_bytes = FX_Alloc(uint8_t, count); - m_size = count; - FXSYS_memcpy(m_bytes, source + offset, count); - m_index = count; -} -void CBC_CommonByteArray::Set(std::vector<uint8_t>* source, - int32_t offset, - int32_t count) { - FX_Free(m_bytes); - m_bytes = FX_Alloc(uint8_t, count); - m_size = count; - int32_t i; - for (i = 0; i < count; i++) { - m_bytes[i] = source->operator[](i + offset); - } - m_index = m_size; -} diff --git a/xfa/fxbarcode/common/BC_CommonByteArray.h b/xfa/fxbarcode/common/BC_CommonByteArray.h deleted file mode 100644 index e1fe4c7f2e..0000000000 --- a/xfa/fxbarcode/common/BC_CommonByteArray.h +++ /dev/null @@ -1,38 +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_FXBARCODE_COMMON_BC_COMMONBYTEARRAY_H_ -#define XFA_FXBARCODE_COMMON_BC_COMMONBYTEARRAY_H_ - -#include <vector> - -#include "core/fxcrt/fx_basic.h" - -// TODO(weili): The usage of this class should be replaced by -// std::vector<uint8_t>. -class CBC_CommonByteArray { - public: - CBC_CommonByteArray(); - explicit CBC_CommonByteArray(int32_t size); - CBC_CommonByteArray(uint8_t* byteArray, int32_t size); - virtual ~CBC_CommonByteArray(); - - int32_t At(int32_t index) const; - int32_t Size() const; - bool IsEmpty() const; - void Set(int32_t index, int32_t value); - void AppendByte(int32_t value); - void Reserve(int32_t capacity); - void Set(uint8_t* source, int32_t offset, int32_t count); - void Set(std::vector<uint8_t>* source, int32_t offset, int32_t count); - - private: - int32_t m_size; - int32_t m_index; - uint8_t* m_bytes; -}; - -#endif // XFA_FXBARCODE_COMMON_BC_COMMONBYTEARRAY_H_ diff --git a/xfa/fxbarcode/common/BC_CommonByteMatrix.cpp b/xfa/fxbarcode/common/BC_CommonByteMatrix.cpp deleted file mode 100644 index 0e7ce80e29..0000000000 --- a/xfa/fxbarcode/common/BC_CommonByteMatrix.cpp +++ /dev/null @@ -1,64 +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 2008 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 "core/fxcrt/fx_memory.h" -#include "xfa/fxbarcode/common/BC_CommonByteMatrix.h" - -CBC_CommonByteMatrix::CBC_CommonByteMatrix(int32_t width, int32_t height) { - m_height = height; - m_width = width; - m_bytes = nullptr; -} -void CBC_CommonByteMatrix::Init() { - m_bytes = FX_Alloc2D(uint8_t, m_height, m_width); - FXSYS_memset(m_bytes, 0xff, m_height * m_width); -} -CBC_CommonByteMatrix::~CBC_CommonByteMatrix() { - FX_Free(m_bytes); -} -int32_t CBC_CommonByteMatrix::GetHeight() { - return m_height; -} -int32_t CBC_CommonByteMatrix::GetWidth() { - return m_width; -} -uint8_t CBC_CommonByteMatrix::Get(int32_t x, int32_t y) { - return m_bytes[y * m_width + x]; -} -void CBC_CommonByteMatrix::Set(int32_t x, int32_t y, int32_t value) { - m_bytes[y * m_width + x] = (uint8_t)value; -} -void CBC_CommonByteMatrix::Set(int32_t x, int32_t y, uint8_t value) { - m_bytes[y * m_width + x] = value; -} -void CBC_CommonByteMatrix::clear(uint8_t value) { - int32_t y; - for (y = 0; y < m_height; y++) { - int32_t x; - for (x = 0; x < m_width; x++) { - m_bytes[y * m_width + x] = value; - } - } -} -uint8_t* CBC_CommonByteMatrix::GetArray() { - return m_bytes; -} diff --git a/xfa/fxbarcode/common/BC_CommonByteMatrix.h b/xfa/fxbarcode/common/BC_CommonByteMatrix.h deleted file mode 100644 index 13cf5c330e..0000000000 --- a/xfa/fxbarcode/common/BC_CommonByteMatrix.h +++ /dev/null @@ -1,35 +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_FXBARCODE_COMMON_BC_COMMONBYTEMATRIX_H_ -#define XFA_FXBARCODE_COMMON_BC_COMMONBYTEMATRIX_H_ - -#include <stdint.h> - -#include "core/fxcrt/fx_system.h" - -class CBC_CommonByteMatrix { - public: - CBC_CommonByteMatrix(int32_t width, int32_t height); - virtual ~CBC_CommonByteMatrix(); - - int32_t GetHeight(); - int32_t GetWidth(); - uint8_t Get(int32_t x, int32_t y); - uint8_t* GetArray(); - - void Set(int32_t x, int32_t y, int32_t value); - void Set(int32_t x, int32_t y, uint8_t value); - void clear(uint8_t value); - virtual void Init(); - - private: - uint8_t* m_bytes; - int32_t m_width; - int32_t m_height; -}; - -#endif // XFA_FXBARCODE_COMMON_BC_COMMONBYTEMATRIX_H_ diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp deleted file mode 100644 index 82a729b067..0000000000 --- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp +++ /dev/null @@ -1,105 +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 2007 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/common/reedsolomon/BC_ReedSolomon.h" - -#include <memory> - -#include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" -#include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h" - -CBC_ReedSolomonEncoder::CBC_ReedSolomonEncoder(CBC_ReedSolomonGF256* field) { - m_field = field; -} - -void CBC_ReedSolomonEncoder::Init() { - m_cachedGenerators.push_back(new CBC_ReedSolomonGF256Poly(m_field, 1)); -} - -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonEncoder::BuildGenerator(size_t degree, - int32_t& e) { - if (degree >= m_cachedGenerators.size()) { - CBC_ReedSolomonGF256Poly* lastGenerator = m_cachedGenerators.back(); - for (size_t d = m_cachedGenerators.size(); d <= degree; ++d) { - std::vector<int32_t> temp = {1, m_field->Exp(d - 1)}; - CBC_ReedSolomonGF256Poly temp_poly; - temp_poly.Init(m_field, &temp, e); - if (e != BCExceptionNO) - return nullptr; - CBC_ReedSolomonGF256Poly* nextGenerator = - lastGenerator->Multiply(&temp_poly, e); - if (e != BCExceptionNO) - return nullptr; - m_cachedGenerators.push_back(nextGenerator); - lastGenerator = nextGenerator; - } - } - return m_cachedGenerators[degree]; -} - -void CBC_ReedSolomonEncoder::Encode(std::vector<int32_t>* toEncode, - size_t ecBytes, - int32_t& e) { - if (ecBytes == 0) { - e = BCExceptionNoCorrectionBytes; - return; - } - if (toEncode->size() <= ecBytes) { - e = BCExceptionNoDataBytesProvided; - return; - } - CBC_ReedSolomonGF256Poly* generator = BuildGenerator(ecBytes, e); - if (e != BCExceptionNO) - return; - size_t dataBytes = toEncode->size() - ecBytes; - std::vector<int32_t> infoCoefficients(dataBytes); - for (size_t x = 0; x < dataBytes; x++) { - infoCoefficients[x] = (*toEncode)[x]; - } - CBC_ReedSolomonGF256Poly info; - info.Init(m_field, &infoCoefficients, e); - if (e != BCExceptionNO) - return; - std::unique_ptr<CBC_ReedSolomonGF256Poly> infoTemp( - info.MultiplyByMonomial(ecBytes, 1, e)); - if (e != BCExceptionNO) - return; - std::unique_ptr<std::vector<CBC_ReedSolomonGF256Poly*>> temp( - infoTemp->Divide(generator, e)); - if (e != BCExceptionNO) - return; - CBC_ReedSolomonGF256Poly* remainder = (*temp)[1]; - std::vector<int32_t>* coefficients = remainder->GetCoefficients(); - size_t numZeroCoefficients = - ecBytes > coefficients->size() ? ecBytes - coefficients->size() : 0; - for (size_t i = 0; i < numZeroCoefficients; i++) - (*toEncode)[dataBytes + i] = 0; - for (size_t y = 0; y < coefficients->size(); y++) - (*toEncode)[dataBytes + numZeroCoefficients + y] = (*coefficients)[y]; - for (size_t k = 0; k < temp->size(); k++) - delete (*temp)[k]; -} - -CBC_ReedSolomonEncoder::~CBC_ReedSolomonEncoder() { - for (size_t i = 0; i < m_cachedGenerators.size(); i++) - delete m_cachedGenerators[i]; -} diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.h b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.h deleted file mode 100644 index 5e5c7c52d3..0000000000 --- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.h +++ /dev/null @@ -1,32 +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_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMON_H_ -#define XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMON_H_ - -#include <vector> - -#include "core/fxcrt/fx_basic.h" - -class CBC_ReedSolomonGF256; -class CBC_ReedSolomonGF256Poly; - -class CBC_ReedSolomonEncoder { - public: - explicit CBC_ReedSolomonEncoder(CBC_ReedSolomonGF256* field); - virtual ~CBC_ReedSolomonEncoder(); - - void Encode(std::vector<int32_t>* toEncode, size_t ecBytes, int32_t& e); - virtual void Init(); - - private: - CBC_ReedSolomonGF256Poly* BuildGenerator(size_t degree, int32_t& e); - - CBC_ReedSolomonGF256* m_field; - std::vector<CBC_ReedSolomonGF256Poly*> m_cachedGenerators; -}; - -#endif // XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMON_H_ diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp deleted file mode 100644 index 349ed0789a..0000000000 --- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp +++ /dev/null @@ -1,135 +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 2007 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/common/reedsolomon/BC_ReedSolomonGF256.h" - -#include <vector> - -#include "third_party/base/ptr_util.h" -#include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h" - -CBC_ReedSolomonGF256* CBC_ReedSolomonGF256::QRCodeField = nullptr; -CBC_ReedSolomonGF256* CBC_ReedSolomonGF256::DataMatrixField = nullptr; - -void CBC_ReedSolomonGF256::Initialize() { - QRCodeField = new CBC_ReedSolomonGF256(0x011D); - QRCodeField->Init(); - DataMatrixField = new CBC_ReedSolomonGF256(0x012D); - DataMatrixField->Init(); -} - -void CBC_ReedSolomonGF256::Finalize() { - delete QRCodeField; - QRCodeField = nullptr; - delete DataMatrixField; - DataMatrixField = nullptr; -} - -CBC_ReedSolomonGF256::CBC_ReedSolomonGF256(int32_t primitive) { - int32_t x = 1; - for (int32_t j = 0; j < 256; j++) { - m_expTable[j] = x; - x <<= 1; - if (x >= 0x100) { - x ^= primitive; - } - } - for (int32_t i = 0; i < 255; i++) { - m_logTable[m_expTable[i]] = i; - } - m_logTable[0] = 0; -} - -void CBC_ReedSolomonGF256::Init() { - m_zero = pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>(this, 0); - m_one = pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>(this, 1); -} - -CBC_ReedSolomonGF256::~CBC_ReedSolomonGF256() {} - -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetZero() const { - return m_zero.get(); -} - -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetOne() const { - return m_one.get(); -} - -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::BuildMonomial( - int32_t degree, - int32_t coefficient, - int32_t& e) { - if (degree < 0) { - e = BCExceptionDegreeIsNegative; - return nullptr; - } - if (coefficient == 0) { - CBC_ReedSolomonGF256Poly* temp = m_zero->Clone(e); - if (e != BCExceptionNO) - return nullptr; - return temp; - } - std::vector<int32_t> coefficients(degree + 1); - coefficients[0] = coefficient; - CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); - temp->Init(this, &coefficients, e); - if (e != BCExceptionNO) - return nullptr; - return temp; -} - -int32_t CBC_ReedSolomonGF256::AddOrSubtract(int32_t a, int32_t b) { - return a ^ b; -} - -int32_t CBC_ReedSolomonGF256::Exp(int32_t a) { - return m_expTable[a]; -} - -int32_t CBC_ReedSolomonGF256::Log(int32_t a, int32_t& e) { - if (a == 0) { - e = BCExceptionAIsZero; - return 0; - } - return m_logTable[a]; -} - -int32_t CBC_ReedSolomonGF256::Inverse(int32_t a, int32_t& e) { - if (a == 0) { - e = BCExceptionAIsZero; - return 0; - } - return m_expTable[255 - m_logTable[a]]; -} - -int32_t CBC_ReedSolomonGF256::Multiply(int32_t a, int32_t b) { - if (a == 0 || b == 0) { - return 0; - } - if (a == 1) { - return b; - } - if (b == 1) { - return a; - } - return m_expTable[(m_logTable[a] + m_logTable[b]) % 255]; -} diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h deleted file mode 100644 index 16f1ad17f7..0000000000 --- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h +++ /dev/null @@ -1,47 +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_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256_H_ -#define XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256_H_ - -#include <memory> - -#include "core/fxcrt/fx_basic.h" -#include "xfa/fxbarcode/utils.h" - -class CBC_ReedSolomonGF256Poly; - -class CBC_ReedSolomonGF256 { - public: - explicit CBC_ReedSolomonGF256(int32_t primitive); - virtual ~CBC_ReedSolomonGF256(); - - static void Initialize(); - static void Finalize(); - - CBC_ReedSolomonGF256Poly* GetZero() const; - CBC_ReedSolomonGF256Poly* GetOne() const; - CBC_ReedSolomonGF256Poly* BuildMonomial(int32_t degree, - int32_t coefficient, - int32_t& e); - static int32_t AddOrSubtract(int32_t a, int32_t b); - int32_t Exp(int32_t a); - int32_t Log(int32_t a, int32_t& e); - int32_t Inverse(int32_t a, int32_t& e); - int32_t Multiply(int32_t a, int32_t b); - virtual void Init(); - - static CBC_ReedSolomonGF256* QRCodeField; - static CBC_ReedSolomonGF256* DataMatrixField; - - private: - int32_t m_expTable[256]; - int32_t m_logTable[256]; - std::unique_ptr<CBC_ReedSolomonGF256Poly> m_zero; - std::unique_ptr<CBC_ReedSolomonGF256Poly> m_one; -}; - -#endif // XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256_H_ diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp deleted file mode 100644 index e4ee30b586..0000000000 --- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp +++ /dev/null @@ -1,253 +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 2007 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/common/reedsolomon/BC_ReedSolomonGF256Poly.h" - -#include <memory> -#include <utility> - -#include "third_party/base/stl_util.h" -#include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" - -CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly(CBC_ReedSolomonGF256* field, - int32_t coefficients) { - if (!field) - return; - - m_field = field; - m_coefficients.push_back(coefficients); -} - -CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly() { - m_field = nullptr; -} - -void CBC_ReedSolomonGF256Poly::Init(CBC_ReedSolomonGF256* field, - std::vector<int32_t>* coefficients, - int32_t& e) { - if (!coefficients || coefficients->empty()) { - e = BCExceptionCoefficientsSizeIsNull; - return; - } - m_field = field; - size_t coefficientsLength = coefficients->size(); - if (coefficientsLength > 1 && coefficients->front() == 0) { - size_t firstNonZero = 1; - while (firstNonZero < coefficientsLength && - (*coefficients)[firstNonZero] == 0) { - firstNonZero++; - } - if (firstNonZero == coefficientsLength) { - m_coefficients = *(m_field->GetZero()->GetCoefficients()); - } else { - m_coefficients.resize(coefficientsLength - firstNonZero); - for (size_t i = firstNonZero, j = 0; i < coefficientsLength; i++, j++) - m_coefficients[j] = (*coefficients)[i]; - } - } else { - m_coefficients = *coefficients; - } -} - -std::vector<int32_t>* CBC_ReedSolomonGF256Poly::GetCoefficients() { - return &m_coefficients; -} - -int32_t CBC_ReedSolomonGF256Poly::GetDegree() { - return pdfium::CollectionSize<int32_t>(m_coefficients) - 1; -} - -bool CBC_ReedSolomonGF256Poly::IsZero() { - return m_coefficients.front() == 0; -} - -int32_t CBC_ReedSolomonGF256Poly::GetCoefficients(int32_t degree) { - return m_coefficients[m_coefficients.size() - 1 - degree]; -} - -int32_t CBC_ReedSolomonGF256Poly::EvaluateAt(int32_t a) { - if (a == 0) { - return GetCoefficients(0); - } - size_t size = m_coefficients.size(); - if (a == 1) { - int32_t result = 0; - for (size_t i = 0; i < size; i++) - result = CBC_ReedSolomonGF256::AddOrSubtract(result, m_coefficients[i]); - return result; - } - int32_t result = m_coefficients[0]; - for (size_t j = 1; j < size; j++) { - result = CBC_ReedSolomonGF256::AddOrSubtract(m_field->Multiply(a, result), - m_coefficients[j]); - } - return result; -} - -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Clone(int32_t& e) { - CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); - temp->Init(m_field, &m_coefficients, e); - if (e != BCExceptionNO) - return nullptr; - return temp; -} -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::AddOrSubtract( - CBC_ReedSolomonGF256Poly* other, - int32_t& e) { - if (IsZero()) - return other->Clone(e); - if (other->IsZero()) - return Clone(e); - - std::vector<int32_t> smallerCoefficients = m_coefficients; - std::vector<int32_t> largerCoefficients = *(other->GetCoefficients()); - if (smallerCoefficients.size() > largerCoefficients.size()) { - std::swap(smallerCoefficients, largerCoefficients); - } - std::vector<int32_t> sumDiff(largerCoefficients.size()); - size_t lengthDiff = largerCoefficients.size() - smallerCoefficients.size(); - for (size_t i = 0; i < lengthDiff; i++) { - sumDiff[i] = largerCoefficients[i]; - } - for (size_t j = lengthDiff; j < largerCoefficients.size(); j++) { - sumDiff[j] = CBC_ReedSolomonGF256::AddOrSubtract( - smallerCoefficients[j - lengthDiff], largerCoefficients[j]); - } - CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); - temp->Init(m_field, &sumDiff, e); - if (e != BCExceptionNO) - return nullptr; - return temp; -} -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply( - CBC_ReedSolomonGF256Poly* other, - int32_t& e) { - if (IsZero() || other->IsZero()) - return m_field->GetZero()->Clone(e); - - std::vector<int32_t> aCoefficients = m_coefficients; - std::vector<int32_t> bCoefficients = *(other->GetCoefficients()); - size_t aLength = aCoefficients.size(); - size_t bLength = bCoefficients.size(); - std::vector<int32_t> product(aLength + bLength - 1); - for (size_t i = 0; i < aLength; i++) { - int32_t aCoeff = m_coefficients[i]; - for (size_t j = 0; j < bLength; j++) { - product[i + j] = CBC_ReedSolomonGF256::AddOrSubtract( - product[i + j], - m_field->Multiply(aCoeff, (*other->GetCoefficients())[j])); - } - } - CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); - temp->Init(m_field, &product, e); - if (e != BCExceptionNO) - return nullptr; - return temp; -} -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(int32_t scalar, - int32_t& e) { - if (scalar == 0) - return m_field->GetZero()->Clone(e); - if (scalar == 1) - return Clone(e); - - size_t size = m_coefficients.size(); - std::vector<int32_t> product(size); - for (size_t i = 0; i < size; i++) { - product[i] = m_field->Multiply(m_coefficients[i], scalar); - } - CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); - temp->Init(m_field, &product, e); - if (e != BCExceptionNO) - return nullptr; - return temp; -} -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::MultiplyByMonomial( - int32_t degree, - int32_t coefficient, - int32_t& e) { - if (degree < 0) { - e = BCExceptionDegreeIsNegative; - return nullptr; - } - if (coefficient == 0) - return m_field->GetZero()->Clone(e); - - size_t size = m_coefficients.size(); - std::vector<int32_t> product(size + degree); - for (size_t i = 0; i < size; i++) { - product[i] = m_field->Multiply(m_coefficients[i], coefficient); - } - CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); - temp->Init(m_field, &product, e); - if (e != BCExceptionNO) - return nullptr; - return temp; -} - -std::vector<CBC_ReedSolomonGF256Poly*>* CBC_ReedSolomonGF256Poly::Divide( - CBC_ReedSolomonGF256Poly* other, - int32_t& e) { - if (other->IsZero()) { - e = BCExceptionDivideByZero; - return nullptr; - } - std::unique_ptr<CBC_ReedSolomonGF256Poly> quotient( - m_field->GetZero()->Clone(e)); - if (e != BCExceptionNO) - return nullptr; - std::unique_ptr<CBC_ReedSolomonGF256Poly> remainder(Clone(e)); - if (e != BCExceptionNO) - return nullptr; - int32_t denominatorLeadingTerm = other->GetCoefficients(other->GetDegree()); - int32_t inverseDenominatorLeadingTeam = - m_field->Inverse(denominatorLeadingTerm, e); - if (e != BCExceptionNO) - return nullptr; - while (remainder->GetDegree() >= other->GetDegree() && !remainder->IsZero()) { - int32_t degreeDifference = remainder->GetDegree() - other->GetDegree(); - int32_t scale = - m_field->Multiply(remainder->GetCoefficients((remainder->GetDegree())), - inverseDenominatorLeadingTeam); - std::unique_ptr<CBC_ReedSolomonGF256Poly> term( - other->MultiplyByMonomial(degreeDifference, scale, e)); - if (e != BCExceptionNO) - return nullptr; - std::unique_ptr<CBC_ReedSolomonGF256Poly> iteratorQuotient( - m_field->BuildMonomial(degreeDifference, scale, e)); - if (e != BCExceptionNO) - return nullptr; - quotient.reset(quotient->AddOrSubtract(iteratorQuotient.get(), e)); - if (e != BCExceptionNO) - return nullptr; - remainder.reset(remainder->AddOrSubtract(term.get(), e)); - if (e != BCExceptionNO) - return nullptr; - } - std::vector<CBC_ReedSolomonGF256Poly*>* tempPtrA = - new std::vector<CBC_ReedSolomonGF256Poly*>(); - tempPtrA->push_back(quotient.release()); - tempPtrA->push_back(remainder.release()); - return tempPtrA; -} - -CBC_ReedSolomonGF256Poly::~CBC_ReedSolomonGF256Poly() {} diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h deleted file mode 100644 index 6fc7509399..0000000000 --- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h +++ /dev/null @@ -1,49 +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_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256POLY_H_ -#define XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256POLY_H_ - -#include <vector> - -#include "core/fxcrt/fx_basic.h" - -class CBC_ReedSolomonGF256; - -class CBC_ReedSolomonGF256Poly final { - public: - CBC_ReedSolomonGF256Poly(CBC_ReedSolomonGF256* field, int32_t coefficients); - CBC_ReedSolomonGF256Poly(); - ~CBC_ReedSolomonGF256Poly(); - void Init(CBC_ReedSolomonGF256* field, - std::vector<int32_t>* coefficients, - int32_t& e); - - int32_t GetCoefficients(int32_t degree); - std::vector<int32_t>* GetCoefficients(); - int32_t GetDegree(); - bool IsZero(); - int32_t EvaluateAt(int32_t a); - CBC_ReedSolomonGF256Poly* AddOrSubtract(CBC_ReedSolomonGF256Poly* other, - int32_t& e); - CBC_ReedSolomonGF256Poly* Multiply(CBC_ReedSolomonGF256Poly* other, - int32_t& e); - CBC_ReedSolomonGF256Poly* Multiply(int32_t scalar, int32_t& e); - CBC_ReedSolomonGF256Poly* MultiplyByMonomial(int32_t degree, - int32_t coefficient, - int32_t& e); - std::vector<CBC_ReedSolomonGF256Poly*>* Divide( - CBC_ReedSolomonGF256Poly* other, - int32_t& e); - - CBC_ReedSolomonGF256Poly* Clone(int32_t& e); - - private: - CBC_ReedSolomonGF256* m_field; - std::vector<int32_t> m_coefficients; -}; - -#endif // XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256POLY_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp b/xfa/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp deleted file mode 100644 index 88a12b23a2..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp +++ /dev/null @@ -1,97 +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 2006-2007 Jeremias Maerki. - * - * 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_Dimension.h" -#include "xfa/fxbarcode/datamatrix/BC_ASCIIEncoder.h" -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_EncoderContext.h" -#include "xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h" - -CBC_ASCIIEncoder::CBC_ASCIIEncoder() {} -CBC_ASCIIEncoder::~CBC_ASCIIEncoder() {} -int32_t CBC_ASCIIEncoder::getEncodingMode() { - return ASCII_ENCODATION; -} -void CBC_ASCIIEncoder::Encode(CBC_EncoderContext& context, int32_t& e) { - int32_t n = CBC_HighLevelEncoder::determineConsecutiveDigitCount( - context.m_msg, context.m_pos); - if (n >= 2) { - wchar_t code = encodeASCIIDigits(context.m_msg.GetAt(context.m_pos), - context.m_msg.GetAt(context.m_pos + 1), e); - if (e != BCExceptionNO) { - return; - } - context.writeCodeword(code); - context.m_pos += 2; - } else { - wchar_t c = context.getCurrentChar(); - int32_t newMode = CBC_HighLevelEncoder::lookAheadTest( - context.m_msg, context.m_pos, getEncodingMode()); - if (newMode != getEncodingMode()) { - switch (newMode) { - case BASE256_ENCODATION: - context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_BASE256); - context.signalEncoderChange(BASE256_ENCODATION); - return; - case C40_ENCODATION: - context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_C40); - context.signalEncoderChange(C40_ENCODATION); - return; - case X12_ENCODATION: - context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_ANSIX12); - context.signalEncoderChange(X12_ENCODATION); - break; - case TEXT_ENCODATION: - context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_TEXT); - context.signalEncoderChange(TEXT_ENCODATION); - break; - case EDIFACT_ENCODATION: - context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_EDIFACT); - context.signalEncoderChange(EDIFACT_ENCODATION); - break; - default: - e = BCExceptionIllegalStateIllegalMode; - return; - } - } else if (CBC_HighLevelEncoder::isExtendedASCII(c)) { - context.writeCodeword(CBC_HighLevelEncoder::UPPER_SHIFT); - context.writeCodeword((wchar_t)(c - 128 + 1)); - context.m_pos++; - } else { - context.writeCodeword((wchar_t)(c + 1)); - context.m_pos++; - } - } -} -wchar_t CBC_ASCIIEncoder::encodeASCIIDigits(wchar_t digit1, - wchar_t digit2, - int32_t& e) { - if (CBC_HighLevelEncoder::isDigit(digit1) && - CBC_HighLevelEncoder::isDigit(digit2)) { - int32_t num = (digit1 - 48) * 10 + (digit2 - 48); - return (wchar_t)(num + 130); - } - e = BCExceptionIllegalArgumentNotGigits; - return 0; -} diff --git a/xfa/fxbarcode/datamatrix/BC_ASCIIEncoder.h b/xfa/fxbarcode/datamatrix/BC_ASCIIEncoder.h deleted file mode 100644 index a0cfaa76ed..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_ASCIIEncoder.h +++ /dev/null @@ -1,27 +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_FXBARCODE_DATAMATRIX_BC_ASCIIENCODER_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_ASCIIENCODER_H_ - -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" - -class CBC_EncoderContext; - -class CBC_ASCIIEncoder : public CBC_Encoder { - public: - CBC_ASCIIEncoder(); - ~CBC_ASCIIEncoder() override; - - // CBC_Encoder - int32_t getEncodingMode() override; - void Encode(CBC_EncoderContext& context, int32_t& e) override; - - private: - static wchar_t encodeASCIIDigits(wchar_t digit1, wchar_t digit2, int32_t& e); -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_ASCIIENCODER_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_Base256Encoder.cpp b/xfa/fxbarcode/datamatrix/BC_Base256Encoder.cpp deleted file mode 100644 index 333377e392..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_Base256Encoder.cpp +++ /dev/null @@ -1,87 +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 2006-2007 Jeremias Maerki. - * - * 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_Dimension.h" -#include "xfa/fxbarcode/datamatrix/BC_Base256Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_EncoderContext.h" -#include "xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h" - -CBC_Base256Encoder::CBC_Base256Encoder() {} -CBC_Base256Encoder::~CBC_Base256Encoder() {} -int32_t CBC_Base256Encoder::getEncodingMode() { - return BASE256_ENCODATION; -} -void CBC_Base256Encoder::Encode(CBC_EncoderContext& context, int32_t& e) { - CFX_WideString buffer; - buffer += (wchar_t)'\0'; - while (context.hasMoreCharacters()) { - wchar_t c = context.getCurrentChar(); - buffer += c; - context.m_pos++; - int32_t newMode = CBC_HighLevelEncoder::lookAheadTest( - context.m_msg, context.m_pos, getEncodingMode()); - if (newMode != getEncodingMode()) { - context.signalEncoderChange(newMode); - break; - } - } - int32_t dataCount = buffer.GetLength() - 1; - char buf[128]; - FXSYS_itoa(dataCount, buf, 10); - buffer.SetAt(0, wchar_t(*buf) - '0'); - int32_t lengthFieldSize = 1; - int32_t currentSize = - context.getCodewordCount() + dataCount + lengthFieldSize; - context.updateSymbolInfo(currentSize, e); - if (e != BCExceptionNO) { - return; - } - bool mustPad = (context.m_symbolInfo->m_dataCapacity - currentSize) > 0; - if (context.hasMoreCharacters() || mustPad) { - if (dataCount <= 249) { - buffer.SetAt(0, (wchar_t)dataCount); - } else if (dataCount > 249 && dataCount <= 1555) { - buffer.SetAt(0, (wchar_t)((dataCount / 250) + 249)); - buffer.Insert(1, (wchar_t)(dataCount % 250)); - } else { - e = BCExceptionIllegalStateMessageLengthInvalid; - return; - } - } - for (int32_t i = 0, c = buffer.GetLength(); i < c; i++) { - context.writeCodeword( - randomize255State(buffer.GetAt(i), context.getCodewordCount() + 1)); - } -} -wchar_t CBC_Base256Encoder::randomize255State(wchar_t ch, - int32_t codewordPosition) { - int32_t pseudoRandom = ((149 * codewordPosition) % 255) + 1; - int32_t tempVariable = ch + pseudoRandom; - if (tempVariable <= 255) { - return (wchar_t)tempVariable; - } else { - return (wchar_t)(tempVariable - 256); - } -} diff --git a/xfa/fxbarcode/datamatrix/BC_Base256Encoder.h b/xfa/fxbarcode/datamatrix/BC_Base256Encoder.h deleted file mode 100644 index 41229afb80..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_Base256Encoder.h +++ /dev/null @@ -1,25 +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_FXBARCODE_DATAMATRIX_BC_BASE256ENCODER_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_BASE256ENCODER_H_ - -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" - -class CBC_Base256Encoder : public CBC_Encoder { - public: - CBC_Base256Encoder(); - ~CBC_Base256Encoder() override; - - // CBC_Encoder - int32_t getEncodingMode() override; - void Encode(CBC_EncoderContext& context, int32_t& e) override; - - private: - static wchar_t randomize255State(wchar_t ch, int32_t codewordPosition); -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_BASE256ENCODER_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_C40Encoder.cpp b/xfa/fxbarcode/datamatrix/BC_C40Encoder.cpp deleted file mode 100644 index 04fcb6b541..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_C40Encoder.cpp +++ /dev/null @@ -1,200 +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 2006-2007 Jeremias Maerki. - * - * 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_Dimension.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/datamatrix/BC_C40Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_EncoderContext.h" -#include "xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h" - -CBC_C40Encoder::CBC_C40Encoder() {} -CBC_C40Encoder::~CBC_C40Encoder() {} -int32_t CBC_C40Encoder::getEncodingMode() { - return C40_ENCODATION; -} -void CBC_C40Encoder::Encode(CBC_EncoderContext& context, int32_t& e) { - CFX_WideString buffer; - while (context.hasMoreCharacters()) { - wchar_t c = context.getCurrentChar(); - context.m_pos++; - int32_t lastCharSize = encodeChar(c, buffer, e); - if (e != BCExceptionNO) { - return; - } - int32_t unwritten = (buffer.GetLength() / 3) * 2; - int32_t curCodewordCount = context.getCodewordCount() + unwritten; - context.updateSymbolInfo(curCodewordCount, e); - if (e != BCExceptionNO) { - return; - } - int32_t available = context.m_symbolInfo->m_dataCapacity - curCodewordCount; - if (!context.hasMoreCharacters()) { - CFX_WideString removed; - if ((buffer.GetLength() % 3) == 2) { - if (available < 2 || available > 2) { - lastCharSize = - backtrackOneCharacter(context, buffer, removed, lastCharSize, e); - if (e != BCExceptionNO) { - return; - } - } - } - while ((buffer.GetLength() % 3) == 1 && - ((lastCharSize <= 3 && available != 1) || lastCharSize > 3)) { - lastCharSize = - backtrackOneCharacter(context, buffer, removed, lastCharSize, e); - if (e != BCExceptionNO) { - return; - } - } - break; - } - int32_t count = buffer.GetLength(); - if ((count % 3) == 0) { - int32_t newMode = CBC_HighLevelEncoder::lookAheadTest( - context.m_msg, context.m_pos, getEncodingMode()); - if (newMode != getEncodingMode()) { - context.signalEncoderChange(newMode); - break; - } - } - } - handleEOD(context, buffer, e); -} -void CBC_C40Encoder::writeNextTriplet(CBC_EncoderContext& context, - CFX_WideString& buffer) { - context.writeCodewords(encodeToCodewords(buffer, 0)); - buffer.Delete(0, 3); -} -void CBC_C40Encoder::handleEOD(CBC_EncoderContext& context, - CFX_WideString& buffer, - int32_t& e) { - int32_t unwritten = (buffer.GetLength() / 3) * 2; - int32_t rest = buffer.GetLength() % 3; - int32_t curCodewordCount = context.getCodewordCount() + unwritten; - context.updateSymbolInfo(curCodewordCount, e); - if (e != BCExceptionNO) { - return; - } - int32_t available = context.m_symbolInfo->m_dataCapacity - curCodewordCount; - if (rest == 2) { - buffer += (wchar_t)'\0'; - while (buffer.GetLength() >= 3) { - writeNextTriplet(context, buffer); - } - if (context.hasMoreCharacters()) { - context.writeCodeword(CBC_HighLevelEncoder::C40_UNLATCH); - } - } else if (available == 1 && rest == 1) { - while (buffer.GetLength() >= 3) { - writeNextTriplet(context, buffer); - } - if (context.hasMoreCharacters()) { - context.writeCodeword(CBC_HighLevelEncoder::C40_UNLATCH); - } - context.m_pos--; - } else if (rest == 0) { - while (buffer.GetLength() >= 3) { - writeNextTriplet(context, buffer); - } - if (available > 0 || context.hasMoreCharacters()) { - context.writeCodeword(CBC_HighLevelEncoder::C40_UNLATCH); - } - } else { - e = BCExceptionIllegalStateUnexpectedCase; - return; - } - context.signalEncoderChange(ASCII_ENCODATION); -} -int32_t CBC_C40Encoder::encodeChar(wchar_t c, CFX_WideString& sb, int32_t& e) { - if (c == ' ') { - sb += (wchar_t)'\3'; - return 1; - } else if ((c >= '0') && (c <= '9')) { - sb += (wchar_t)(c - 48 + 4); - return 1; - } else if ((c >= 'A') && (c <= 'Z')) { - sb += (wchar_t)(c - 65 + 14); - return 1; - } else if (c <= 0x1f) { - sb += (wchar_t)'\0'; - sb += c; - return 2; - } else if ((c >= '!') && (c <= '/')) { - sb += (wchar_t)'\1'; - sb += (wchar_t)(c - 33); - return 2; - } else if ((c >= ':') && (c <= '@')) { - sb += (wchar_t)'\1'; - sb += (wchar_t)(c - 58 + 15); - return 2; - } else if ((c >= '[') && (c <= '_')) { - sb += (wchar_t)'\1'; - sb += (wchar_t)(c - 91 + 22); - return 2; - } else if ((c >= 60) && (c <= 0x7f)) { - sb += (wchar_t)'\2'; - sb += (wchar_t)(c - 96); - return 2; - } else if (c >= 80) { - sb += (wchar_t)'\1'; - sb += (wchar_t)0x001e; - int32_t len = 2; - len += encodeChar((c - 128), sb, e); - if (e != BCExceptionNO) - return 0; - return len; - } else { - e = BCExceptionIllegalArgument; - return 0; - } -} -int32_t CBC_C40Encoder::backtrackOneCharacter(CBC_EncoderContext& context, - CFX_WideString& buffer, - CFX_WideString& removed, - int32_t lastCharSize, - int32_t& e) { - int32_t count = buffer.GetLength(); - buffer.Delete(count - lastCharSize, count); - context.m_pos--; - wchar_t c = context.getCurrentChar(); - lastCharSize = encodeChar(c, removed, e); - if (e != BCExceptionNO) - return -1; - context.resetSymbolInfo(); - return lastCharSize; -} -CFX_WideString CBC_C40Encoder::encodeToCodewords(CFX_WideString sb, - int32_t startPos) { - wchar_t c1 = sb.GetAt(startPos); - wchar_t c2 = sb.GetAt(startPos + 1); - wchar_t c3 = sb.GetAt(startPos + 2); - int32_t v = (1600 * c1) + (40 * c2) + c3 + 1; - wchar_t cw1 = (wchar_t)(v / 256); - wchar_t cw2 = (wchar_t)(v % 256); - CFX_WideString b1(cw1); - CFX_WideString b2(cw2); - return b1 + b2; -} diff --git a/xfa/fxbarcode/datamatrix/BC_C40Encoder.h b/xfa/fxbarcode/datamatrix/BC_C40Encoder.h deleted file mode 100644 index 03dee140df..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_C40Encoder.h +++ /dev/null @@ -1,38 +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_FXBARCODE_DATAMATRIX_BC_C40ENCODER_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_C40ENCODER_H_ - -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" - -class CBC_C40Encoder : public CBC_Encoder { - public: - CBC_C40Encoder(); - ~CBC_C40Encoder() override; - - // CBC_Encoder - int32_t getEncodingMode() override; - void Encode(CBC_EncoderContext& context, int32_t& e) override; - - static void writeNextTriplet(CBC_EncoderContext& context, - CFX_WideString& buffer); - - virtual void handleEOD(CBC_EncoderContext& context, - CFX_WideString& buffer, - int32_t& e); - virtual int32_t encodeChar(wchar_t c, CFX_WideString& sb, int32_t& e); - - private: - int32_t backtrackOneCharacter(CBC_EncoderContext& context, - CFX_WideString& buffer, - CFX_WideString& removed, - int32_t lastCharSize, - int32_t& e); - static CFX_WideString encodeToCodewords(CFX_WideString sb, int32_t startPos); -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_C40ENCODER_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp b/xfa/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp deleted file mode 100644 index e580bb583f..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp +++ /dev/null @@ -1,40 +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 2006 Jeremias Maerki - * - * 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/datamatrix/BC_DataMatrixSymbolInfo144.h" -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h" - -CBC_DataMatrixSymbolInfo144::CBC_DataMatrixSymbolInfo144() - : CBC_SymbolInfo(false, 1558, 620, 22, 22, 36) { - m_rsBlockData = -1; - m_rsBlockError = 62; -} -CBC_DataMatrixSymbolInfo144::~CBC_DataMatrixSymbolInfo144() {} -int32_t CBC_DataMatrixSymbolInfo144::getInterleavedBlockCount() { - return 10; -} -int32_t CBC_DataMatrixSymbolInfo144getDataLengthForInterleavedBlock( - int32_t index) { - return (index <= 8) ? 156 : 155; -} diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h b/xfa/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h deleted file mode 100644 index 2cd0cd0e6f..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h +++ /dev/null @@ -1,20 +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_FXBARCODE_DATAMATRIX_BC_DATAMATRIXSYMBOLINFO144_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXSYMBOLINFO144_H_ - -#include "xfa/fxbarcode/datamatrix/BC_SymbolInfo.h" - -class CBC_DataMatrixSymbolInfo144 : public CBC_SymbolInfo { - public: - CBC_DataMatrixSymbolInfo144(); - ~CBC_DataMatrixSymbolInfo144() override; - - int32_t getInterleavedBlockCount(); -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXSYMBOLINFO144_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp b/xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp deleted file mode 100644 index f1ce798af0..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp +++ /dev/null @@ -1,143 +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 2008 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_Dimension.h" -#include "xfa/fxbarcode/BC_TwoDimWriter.h" -#include "xfa/fxbarcode/BC_UtilCodingConvert.h" -#include "xfa/fxbarcode/BC_Writer.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/common/BC_CommonByteMatrix.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_DataMatrixSymbolInfo144.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" - -CBC_DataMatrixWriter::CBC_DataMatrixWriter() {} -CBC_DataMatrixWriter::~CBC_DataMatrixWriter() {} -bool CBC_DataMatrixWriter::SetErrorCorrectionLevel(int32_t level) { - m_iCorrectLevel = level; - return true; -} -uint8_t* CBC_DataMatrixWriter::Encode(const CFX_WideString& contents, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) { - if (outWidth < 0 || outHeight < 0) { - e = BCExceptionHeightAndWidthMustBeAtLeast1; - return nullptr; - } - CBC_SymbolShapeHint::SymbolShapeHint shape = - CBC_SymbolShapeHint::FORCE_SQUARE; - CBC_Dimension* minSize = nullptr; - CBC_Dimension* maxSize = nullptr; - CFX_WideString ecLevel; - CFX_WideString encoded = CBC_HighLevelEncoder::encodeHighLevel( - contents, ecLevel, shape, minSize, maxSize, e); - if (e != BCExceptionNO) - return nullptr; - CBC_SymbolInfo* symbolInfo = CBC_SymbolInfo::lookup( - encoded.GetLength(), shape, minSize, maxSize, true, e); - if (e != BCExceptionNO) - return nullptr; - CFX_WideString codewords = - CBC_ErrorCorrection::encodeECC200(encoded, symbolInfo, e); - if (e != BCExceptionNO) - return nullptr; - CBC_DefaultPlacement* placement = - new CBC_DefaultPlacement(codewords, symbolInfo->getSymbolDataWidth(e), - symbolInfo->getSymbolDataHeight(e)); - if (e != BCExceptionNO) - return nullptr; - placement->place(); - CBC_CommonByteMatrix* bytematrix = encodeLowLevel(placement, symbolInfo, e); - if (e != BCExceptionNO) - return nullptr; - outWidth = bytematrix->GetWidth(); - outHeight = bytematrix->GetHeight(); - uint8_t* result = FX_Alloc2D(uint8_t, outWidth, outHeight); - FXSYS_memcpy(result, bytematrix->GetArray(), outWidth * outHeight); - delete bytematrix; - delete placement; - return result; -} -CBC_CommonByteMatrix* CBC_DataMatrixWriter::encodeLowLevel( - CBC_DefaultPlacement* placement, - CBC_SymbolInfo* symbolInfo, - int32_t& e) { - int32_t symbolWidth = symbolInfo->getSymbolDataWidth(e); - if (e != BCExceptionNO) - return nullptr; - int32_t symbolHeight = symbolInfo->getSymbolDataHeight(e); - if (e != BCExceptionNO) - return nullptr; - CBC_CommonByteMatrix* matrix = new CBC_CommonByteMatrix( - symbolInfo->getSymbolWidth(e), symbolInfo->getSymbolHeight(e)); - if (e != BCExceptionNO) - return nullptr; - matrix->Init(); - int32_t matrixY = 0; - for (int32_t y = 0; y < symbolHeight; y++) { - int32_t matrixX; - if ((y % symbolInfo->m_matrixHeight) == 0) { - matrixX = 0; - for (int32_t x = 0; x < symbolInfo->getSymbolWidth(e); x++) { - matrix->Set(matrixX, matrixY, (x % 2) == 0); - matrixX++; - } - matrixY++; - } - matrixX = 0; - for (int32_t x = 0; x < symbolWidth; x++) { - if ((x % symbolInfo->m_matrixWidth) == 0) { - matrix->Set(matrixX, matrixY, true); - matrixX++; - } - matrix->Set(matrixX, matrixY, placement->getBit(x, y)); - matrixX++; - if ((x % symbolInfo->m_matrixWidth) == symbolInfo->m_matrixWidth - 1) { - matrix->Set(matrixX, matrixY, (y % 2) == 0); - matrixX++; - } - } - matrixY++; - if ((y % symbolInfo->m_matrixHeight) == symbolInfo->m_matrixHeight - 1) { - matrixX = 0; - for (int32_t x = 0; x < symbolInfo->getSymbolWidth(e); x++) { - matrix->Set(matrixX, matrixY, true); - matrixX++; - } - matrixY++; - } - } - return matrix; -} diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.h b/xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.h deleted file mode 100644 index af1417b588..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.h +++ /dev/null @@ -1,36 +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_FXBARCODE_DATAMATRIX_BC_DATAMATRIXWRITER_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXWRITER_H_ - -#include "xfa/fxbarcode/BC_TwoDimWriter.h" - -class CBC_CommonByteMatrix; -class CBC_DefaultPlacement; -class CBC_SymbolInfo; - -class CBC_DataMatrixWriter : public CBC_TwoDimWriter { - public: - CBC_DataMatrixWriter(); - ~CBC_DataMatrixWriter() override; - - virtual uint8_t* Encode(const CFX_WideString& contents, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e); - - // CBC_TwoDimWriter - bool SetErrorCorrectionLevel(int32_t level) override; - - private: - static CBC_CommonByteMatrix* encodeLowLevel(CBC_DefaultPlacement* placement, - CBC_SymbolInfo* symbolInfo, - int32_t& e); - int32_t m_iCorrectLevel; -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXWRITER_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_DefaultPlacement.cpp b/xfa/fxbarcode/datamatrix/BC_DefaultPlacement.cpp deleted file mode 100644 index f027486ee3..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DefaultPlacement.cpp +++ /dev/null @@ -1,163 +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 2006 Jeremias Maerki. - * - * 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/datamatrix/BC_DefaultPlacement.h" -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" - -CBC_DefaultPlacement::CBC_DefaultPlacement(CFX_WideString codewords, - int32_t numcols, - int32_t numrows) { - m_codewords = codewords; - m_numcols = numcols; - m_numrows = numrows; - m_bits.resize(numcols * numrows); - for (int32_t i = 0; i < numcols * numrows; i++) { - m_bits[i] = (uint8_t)2; - } -} -CBC_DefaultPlacement::~CBC_DefaultPlacement() {} - -int32_t CBC_DefaultPlacement::getNumrows() { - return m_numrows; -} -int32_t CBC_DefaultPlacement::getNumcols() { - return m_numcols; -} -std::vector<uint8_t>& CBC_DefaultPlacement::getBits() { - return m_bits; -} -bool CBC_DefaultPlacement::getBit(int32_t col, int32_t row) { - return m_bits[row * m_numcols + col] == 1; -} -void CBC_DefaultPlacement::setBit(int32_t col, int32_t row, bool bit) { - m_bits[row * m_numcols + col] = bit ? (uint8_t)1 : (uint8_t)0; -} -bool CBC_DefaultPlacement::hasBit(int32_t col, int32_t row) { - return m_bits[row * m_numcols + col] != 2; -} -void CBC_DefaultPlacement::place() { - int32_t pos = 0; - int32_t row = 4; - int32_t col = 0; - do { - if ((row == m_numrows) && (col == 0)) { - corner1(pos++); - } - if ((row == m_numrows - 2) && (col == 0) && ((m_numcols % 4) != 0)) { - corner2(pos++); - } - if ((row == m_numrows - 2) && (col == 0) && (m_numcols % 8 == 4)) { - corner3(pos++); - } - if ((row == m_numrows + 4) && (col == 2) && ((m_numcols % 8) == 0)) { - corner4(pos++); - } - do { - if ((row < m_numrows) && (col >= 0) && !hasBit(col, row)) { - utah(row, col, pos++); - } - row -= 2; - col += 2; - } while (row >= 0 && (col < m_numcols)); - row++; - col += 3; - do { - if ((row >= 0) && (col < m_numcols) && !hasBit(col, row)) { - utah(row, col, pos++); - } - row += 2; - col -= 2; - } while ((row < m_numrows) && (col >= 0)); - row += 3; - col++; - } while ((row < m_numrows) || (col < m_numcols)); - if (!hasBit(m_numcols - 1, m_numrows - 1)) { - setBit(m_numcols - 1, m_numrows - 1, true); - setBit(m_numcols - 2, m_numrows - 2, true); - } -} -void CBC_DefaultPlacement::module(int32_t row, - int32_t col, - int32_t pos, - int32_t bit) { - if (row < 0) { - row += m_numrows; - col += 4 - ((m_numrows + 4) % 8); - } - if (col < 0) { - col += m_numcols; - row += 4 - ((m_numcols + 4) % 8); - } - int32_t v = m_codewords.GetAt(pos); - v &= 1 << (8 - bit); - setBit(col, row, v != 0); -} -void CBC_DefaultPlacement::utah(int32_t row, int32_t col, int32_t pos) { - module(row - 2, col - 2, pos, 1); - module(row - 2, col - 1, pos, 2); - module(row - 1, col - 2, pos, 3); - module(row - 1, col - 1, pos, 4); - module(row - 1, col, pos, 5); - module(row, col - 2, pos, 6); - module(row, col - 1, pos, 7); - module(row, col, pos, 8); -} -void CBC_DefaultPlacement::corner1(int32_t pos) { - module(m_numrows - 1, 0, pos, 1); - module(m_numrows - 1, 1, pos, 2); - module(m_numrows - 1, 2, pos, 3); - module(0, m_numcols - 2, pos, 4); - module(0, m_numcols - 1, pos, 5); - module(1, m_numcols - 1, pos, 6); - module(2, m_numcols - 1, pos, 7); - module(3, m_numcols - 1, pos, 8); -} -void CBC_DefaultPlacement::corner2(int32_t pos) { - module(m_numrows - 3, 0, pos, 1); - module(m_numrows - 2, 0, pos, 2); - module(m_numrows - 1, 0, pos, 3); - module(0, m_numcols - 4, pos, 4); - module(0, m_numcols - 3, pos, 5); - module(0, m_numcols - 2, pos, 6); - module(0, m_numcols - 1, pos, 7); - module(1, m_numcols - 1, pos, 8); -} -void CBC_DefaultPlacement::corner3(int32_t pos) { - module(m_numrows - 3, 0, pos, 1); - module(m_numrows - 2, 0, pos, 2); - module(m_numrows - 1, 0, pos, 3); - module(0, m_numcols - 2, pos, 4); - module(0, m_numcols - 1, pos, 5); - module(1, m_numcols - 1, pos, 6); - module(2, m_numcols - 1, pos, 7); - module(3, m_numcols - 1, pos, 8); -} -void CBC_DefaultPlacement::corner4(int32_t pos) { - module(m_numrows - 1, 0, pos, 1); - module(m_numrows - 1, m_numcols - 1, pos, 2); - module(0, m_numcols - 3, pos, 3); - module(0, m_numcols - 2, pos, 4); - module(0, m_numcols - 1, pos, 5); - module(1, m_numcols - 3, pos, 6); - module(1, m_numcols - 2, pos, 7); - module(1, m_numcols - 1, pos, 8); -} diff --git a/xfa/fxbarcode/datamatrix/BC_DefaultPlacement.h b/xfa/fxbarcode/datamatrix/BC_DefaultPlacement.h deleted file mode 100644 index d3c38ca13d..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DefaultPlacement.h +++ /dev/null @@ -1,42 +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_FXBARCODE_DATAMATRIX_BC_DEFAULTPLACEMENT_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_DEFAULTPLACEMENT_H_ - -#include <vector> - -#include "core/fxcrt/fx_basic.h" - -class CBC_DefaultPlacement { - public: - CBC_DefaultPlacement(CFX_WideString codewords, - int32_t numcols, - int32_t numrows); - virtual ~CBC_DefaultPlacement(); - - int32_t getNumrows(); - int32_t getNumcols(); - std::vector<uint8_t>& getBits(); - bool getBit(int32_t col, int32_t row); - void setBit(int32_t col, int32_t row, bool bit); - bool hasBit(int32_t col, int32_t row); - void place(); - - private: - CFX_WideString m_codewords; - int32_t m_numrows; - int32_t m_numcols; - std::vector<uint8_t> m_bits; - void module(int32_t row, int32_t col, int32_t pos, int32_t bit); - void utah(int32_t row, int32_t col, int32_t pos); - void corner1(int32_t pos); - void corner2(int32_t pos); - void corner3(int32_t pos); - void corner4(int32_t pos); -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_DEFAULTPLACEMENT_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_EdifactEncoder.cpp b/xfa/fxbarcode/datamatrix/BC_EdifactEncoder.cpp deleted file mode 100644 index 2ffc8413a3..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_EdifactEncoder.cpp +++ /dev/null @@ -1,152 +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 2006-2007 Jeremias Maerki. - * - * 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_Dimension.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.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_HighLevelEncoder.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h" - -CBC_EdifactEncoder::CBC_EdifactEncoder() {} -CBC_EdifactEncoder::~CBC_EdifactEncoder() {} -int32_t CBC_EdifactEncoder::getEncodingMode() { - return EDIFACT_ENCODATION; -} -void CBC_EdifactEncoder::Encode(CBC_EncoderContext& context, int32_t& e) { - CFX_WideString buffer; - while (context.hasMoreCharacters()) { - wchar_t c = context.getCurrentChar(); - encodeChar(c, buffer, e); - if (e != BCExceptionNO) { - return; - } - context.m_pos++; - int32_t count = buffer.GetLength(); - if (count >= 4) { - context.writeCodewords(encodeToCodewords(buffer, 0, e)); - if (e != BCExceptionNO) { - return; - } - buffer.Delete(0, 4); - int32_t newMode = CBC_HighLevelEncoder::lookAheadTest( - context.m_msg, context.m_pos, getEncodingMode()); - if (newMode != getEncodingMode()) { - context.signalEncoderChange(ASCII_ENCODATION); - break; - } - } - } - buffer += (wchar_t)31; - handleEOD(context, buffer, e); -} -void CBC_EdifactEncoder::handleEOD(CBC_EncoderContext& context, - CFX_WideString buffer, - int32_t& e) { - int32_t count = buffer.GetLength(); - if (count == 0) { - return; - } - if (count == 1) { - context.updateSymbolInfo(e); - if (e != BCExceptionNO) { - return; - } - int32_t available = - context.m_symbolInfo->m_dataCapacity - context.getCodewordCount(); - int32_t remaining = context.getRemainingCharacters(); - if (remaining == 0 && available <= 2) { - return; - } - } - if (count > 4) { - e = BCExceptionIllegalStateCountMustNotExceed4; - return; - } - int32_t restChars = count - 1; - CFX_WideString encoded = encodeToCodewords(buffer, 0, e); - if (e != BCExceptionNO) { - return; - } - bool endOfSymbolReached = !context.hasMoreCharacters(); - bool restInAscii = endOfSymbolReached && restChars <= 2; - if (restChars <= 2) { - context.updateSymbolInfo(context.getCodewordCount() + restChars, e); - if (e != BCExceptionNO) { - return; - } - int32_t available = - context.m_symbolInfo->m_dataCapacity - context.getCodewordCount(); - if (available >= 3) { - restInAscii = false; - context.updateSymbolInfo(context.getCodewordCount() + encoded.GetLength(), - e); - if (e != BCExceptionNO) { - return; - } - } - } - if (restInAscii) { - context.resetSymbolInfo(); - context.m_pos -= restChars; - } else { - context.writeCodewords(encoded); - } - context.signalEncoderChange(ASCII_ENCODATION); -} -void CBC_EdifactEncoder::encodeChar(wchar_t c, CFX_WideString& sb, int32_t& e) { - if (c >= ' ' && c <= '?') { - sb += c; - } else if (c >= '@' && c <= '^') { - sb += (wchar_t)(c - 64); - } else { - CBC_HighLevelEncoder::illegalCharacter(c, e); - } -} -CFX_WideString CBC_EdifactEncoder::encodeToCodewords(CFX_WideString sb, - int32_t startPos, - int32_t& e) { - int32_t len = sb.GetLength() - startPos; - if (len == 0) { - e = BCExceptionNoContents; - return CFX_WideString(); - } - wchar_t c1 = sb.GetAt(startPos); - wchar_t c2 = len >= 2 ? sb.GetAt(startPos + 1) : 0; - wchar_t c3 = len >= 3 ? sb.GetAt(startPos + 2) : 0; - wchar_t c4 = len >= 4 ? sb.GetAt(startPos + 3) : 0; - int32_t v = (c1 << 18) + (c2 << 12) + (c3 << 6) + c4; - wchar_t cw1 = (wchar_t)((v >> 16) & 255); - wchar_t cw2 = (wchar_t)((v >> 8) & 255); - wchar_t cw3 = (wchar_t)(v & 255); - CFX_WideString res; - res += cw1; - if (len >= 2) { - res += cw2; - } - if (len >= 3) { - res += cw3; - } - return res; -} diff --git a/xfa/fxbarcode/datamatrix/BC_EdifactEncoder.h b/xfa/fxbarcode/datamatrix/BC_EdifactEncoder.h deleted file mode 100644 index afe013e02e..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_EdifactEncoder.h +++ /dev/null @@ -1,31 +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_FXBARCODE_DATAMATRIX_BC_EDIFACTENCODER_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_EDIFACTENCODER_H_ - -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" - -class CBC_EdifactEncoder : public CBC_Encoder { - public: - CBC_EdifactEncoder(); - ~CBC_EdifactEncoder() override; - - // CBC_Encoder - int32_t getEncodingMode() override; - void Encode(CBC_EncoderContext& context, int32_t& e) override; - - private: - static void handleEOD(CBC_EncoderContext& context, - CFX_WideString buffer, - int32_t& e); - static void encodeChar(wchar_t c, CFX_WideString& sb, int32_t& e); - static CFX_WideString encodeToCodewords(CFX_WideString sb, - int32_t startPos, - int32_t& e); -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_EDIFACTENCODER_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_Encoder.cpp b/xfa/fxbarcode/datamatrix/BC_Encoder.cpp deleted file mode 100644 index bf815bdfa7..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_Encoder.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" - -CBC_Encoder::CBC_Encoder() {} -CBC_Encoder::~CBC_Encoder() {} diff --git a/xfa/fxbarcode/datamatrix/BC_Encoder.h b/xfa/fxbarcode/datamatrix/BC_Encoder.h deleted file mode 100644 index 68a223fee1..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_Encoder.h +++ /dev/null @@ -1,23 +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_FXBARCODE_DATAMATRIX_BC_ENCODER_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_ENCODER_H_ - -#include "xfa/fxbarcode/utils.h" - -class CBC_EncoderContext; - -class CBC_Encoder { - public: - CBC_Encoder(); - virtual ~CBC_Encoder(); - - virtual int32_t getEncodingMode() = 0; - virtual void Encode(CBC_EncoderContext& context, int32_t& e) = 0; -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_ENCODER_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_EncoderContext.cpp b/xfa/fxbarcode/datamatrix/BC_EncoderContext.cpp deleted file mode 100644 index 6af2bc4e83..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_EncoderContext.cpp +++ /dev/null @@ -1,112 +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 2006-2007 Jeremias Maerki. - * - * 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_Dimension.h" -#include "xfa/fxbarcode/BC_UtilCodingConvert.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_EncoderContext.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h" - -CBC_EncoderContext::CBC_EncoderContext(const CFX_WideString msg, - CFX_WideString ecLevel, - int32_t& e) { - CFX_ByteString dststr; - CBC_UtilCodingConvert::UnicodeToUTF8(msg, dststr); - CFX_WideString sb; - int32_t c = dststr.GetLength(); - for (int32_t i = 0; i < c; i++) { - wchar_t ch = (wchar_t)(dststr.GetAt(i) & 0xff); - if (ch == '?' && dststr.GetAt(i) != '?') { - e = BCExceptionCharactersOutsideISO88591Encoding; - } - sb += ch; - } - m_msg = sb; - m_shape = FORCE_NONE; - m_newEncoding = -1; - m_pos = 0; - m_symbolInfo = nullptr; - m_skipAtEnd = 0; - m_maxSize = nullptr; - m_minSize = nullptr; -} -CBC_EncoderContext::~CBC_EncoderContext() {} -void CBC_EncoderContext::setSymbolShape(SymbolShapeHint shape) { - m_shape = shape; -} -void CBC_EncoderContext::setSizeConstraints(CBC_Dimension* minSize, - CBC_Dimension* maxSize) { - m_maxSize = maxSize; - m_minSize = minSize; -} -CFX_WideString CBC_EncoderContext::getMessage() { - return m_msg; -} -void CBC_EncoderContext::setSkipAtEnd(int32_t count) { - m_skipAtEnd = count; -} -wchar_t CBC_EncoderContext::getCurrentChar() { - return m_msg.GetAt(m_pos); -} -wchar_t CBC_EncoderContext::getCurrent() { - return m_msg.GetAt(m_pos); -} -void CBC_EncoderContext::writeCodewords(CFX_WideString codewords) { - m_codewords += codewords; -} -void CBC_EncoderContext::writeCodeword(wchar_t codeword) { - m_codewords += codeword; -} -int32_t CBC_EncoderContext::getCodewordCount() { - return m_codewords.GetLength(); -} -void CBC_EncoderContext::signalEncoderChange(int32_t encoding) { - m_newEncoding = encoding; -} -void CBC_EncoderContext::resetEncoderSignal() { - m_newEncoding = -1; -} -bool CBC_EncoderContext::hasMoreCharacters() { - return m_pos < getTotalMessageCharCount(); -} -int32_t CBC_EncoderContext::getRemainingCharacters() { - return getTotalMessageCharCount() - m_pos; -} -void CBC_EncoderContext::updateSymbolInfo(int32_t& e) { - updateSymbolInfo(getCodewordCount(), e); -} -void CBC_EncoderContext::updateSymbolInfo(int32_t len, int32_t& e) { - if (!m_symbolInfo || len > m_symbolInfo->m_dataCapacity) { - m_symbolInfo = - CBC_SymbolInfo::lookup(len, m_shape, m_minSize, m_maxSize, true, e); - if (e != BCExceptionNO) - return; - } -} -void CBC_EncoderContext::resetSymbolInfo() { - m_shape = FORCE_NONE; -} -int32_t CBC_EncoderContext::getTotalMessageCharCount() { - return m_msg.GetLength() - m_skipAtEnd; -} diff --git a/xfa/fxbarcode/datamatrix/BC_EncoderContext.h b/xfa/fxbarcode/datamatrix/BC_EncoderContext.h deleted file mode 100644 index 03018b2ffe..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_EncoderContext.h +++ /dev/null @@ -1,56 +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_FXBARCODE_DATAMATRIX_BC_ENCODERCONTEXT_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_ENCODERCONTEXT_H_ - -#include "xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h" - -class CBC_SymbolInfo; -class CBC_Dimension; - -class CBC_EncoderContext : public CBC_SymbolShapeHint { - public: - CBC_EncoderContext(const CFX_WideString msg, - CFX_WideString ecLevel, - int32_t& e); - ~CBC_EncoderContext() override; - - void setSymbolShape(SymbolShapeHint shape); - void setSizeConstraints(CBC_Dimension* minSize, CBC_Dimension* maxSize); - CFX_WideString getMessage(); - void setSkipAtEnd(int32_t count); - wchar_t getCurrentChar(); - wchar_t getCurrent(); - void writeCodewords(CFX_WideString codewords); - void writeCodeword(wchar_t codeword); - int32_t getCodewordCount(); - void signalEncoderChange(int32_t encoding); - void resetEncoderSignal(); - bool hasMoreCharacters(); - int32_t getRemainingCharacters(); - void updateSymbolInfo(int32_t& e); - void updateSymbolInfo(int32_t len, int32_t& e); - void resetSymbolInfo(); - - public: - CFX_WideString m_msg; - CFX_WideString m_codewords; - int32_t m_pos; - int32_t m_newEncoding; - CBC_SymbolInfo* m_symbolInfo; - - private: - int32_t getTotalMessageCharCount(); - - private: - SymbolShapeHint m_shape; - CBC_Dimension* m_minSize; - CBC_Dimension* m_maxSize; - int32_t m_skipAtEnd; -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_ENCODERCONTEXT_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_ErrorCorrection.cpp b/xfa/fxbarcode/datamatrix/BC_ErrorCorrection.cpp deleted file mode 100644 index 0af52faedd..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_ErrorCorrection.cpp +++ /dev/null @@ -1,209 +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 2006 Jeremias Maerki. - * - * 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 <vector> - -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_ErrorCorrection.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h" - -namespace { - -const uint8_t FACTOR_SETS[] = {5, 7, 10, 11, 12, 14, 18, 20, - 24, 28, 36, 42, 48, 56, 62, 68}; - -const uint8_t FACTORS_0[5] = {228, 48, 15, 111, 62}; -const uint8_t FACTORS_1[7] = {23, 68, 144, 134, 240, 92, 254}; -const uint8_t FACTORS_2[10] = {28, 24, 185, 166, 223, 248, 116, 255, 110, 61}; -const uint8_t FACTORS_3[11] = {175, 138, 205, 12, 194, 168, - 39, 245, 60, 97, 120}; - -const uint8_t FACTORS_4[12] = {41, 153, 158, 91, 61, 42, - 142, 213, 97, 178, 100, 242}; - -const uint8_t FACTORS_5[14] = {156, 97, 192, 252, 95, 9, 157, - 119, 138, 45, 18, 186, 83, 185}; - -const uint8_t FACTORS_6[18] = {83, 195, 100, 39, 188, 75, 66, 61, 241, - 213, 109, 129, 94, 254, 225, 48, 90, 188}; - -const uint8_t FACTORS_7[20] = {15, 195, 244, 9, 233, 71, 168, 2, 188, 160, - 153, 145, 253, 79, 108, 82, 27, 174, 186, 172}; - -const uint8_t FACTORS_8[24] = {52, 190, 88, 205, 109, 39, 176, 21, - 155, 197, 251, 223, 155, 21, 5, 172, - 254, 124, 12, 181, 184, 96, 50, 193}; - -const uint8_t FACTORS_9[28] = {211, 231, 43, 97, 71, 96, 103, 174, 37, 151, - 170, 53, 75, 34, 249, 121, 17, 138, 110, 213, - 141, 136, 120, 151, 233, 168, 93, 255}; - -const uint8_t FACTORS_10[36] = {245, 127, 242, 218, 130, 250, 162, 181, 102, - 120, 84, 179, 220, 251, 80, 182, 229, 18, - 2, 4, 68, 33, 101, 137, 95, 119, 115, - 44, 175, 184, 59, 25, 225, 98, 81, 112}; - -const uint8_t FACTORS_11[42] = { - 77, 193, 137, 31, 19, 38, 22, 153, 247, 105, 122, 2, 245, 133, - 242, 8, 175, 95, 100, 9, 167, 105, 214, 111, 57, 121, 21, 1, - 253, 57, 54, 101, 248, 202, 69, 50, 150, 177, 226, 5, 9, 5}; - -const uint8_t FACTORS_12[48] = { - 245, 132, 172, 223, 96, 32, 117, 22, 238, 133, 238, 231, - 205, 188, 237, 87, 191, 106, 16, 147, 118, 23, 37, 90, - 170, 205, 131, 88, 120, 100, 66, 138, 186, 240, 82, 44, - 176, 87, 187, 147, 160, 175, 69, 213, 92, 253, 225, 19}; - -const uint8_t FACTORS_13[56] = { - 175, 9, 223, 238, 12, 17, 220, 208, 100, 29, 175, 170, 230, 192, - 215, 235, 150, 159, 36, 223, 38, 200, 132, 54, 228, 146, 218, 234, - 117, 203, 29, 232, 144, 238, 22, 150, 201, 117, 62, 207, 164, 13, - 137, 245, 127, 67, 247, 28, 155, 43, 203, 107, 233, 53, 143, 46}; - -const uint8_t FACTORS_14[62] = { - 242, 93, 169, 50, 144, 210, 39, 118, 202, 188, 201, 189, 143, - 108, 196, 37, 185, 112, 134, 230, 245, 63, 197, 190, 250, 106, - 185, 221, 175, 64, 114, 71, 161, 44, 147, 6, 27, 218, 51, - 63, 87, 10, 40, 130, 188, 17, 163, 31, 176, 170, 4, 107, - 232, 7, 94, 166, 224, 124, 86, 47, 11, 204}; - -const uint8_t FACTORS_15[68] = { - 220, 228, 173, 89, 251, 149, 159, 56, 89, 33, 147, 244, 154, 36, - 73, 127, 213, 136, 248, 180, 234, 197, 158, 177, 68, 122, 93, 213, - 15, 160, 227, 236, 66, 139, 153, 185, 202, 167, 179, 25, 220, 232, - 96, 210, 231, 136, 223, 239, 181, 241, 59, 52, 172, 25, 49, 232, - 211, 189, 64, 54, 108, 153, 132, 63, 96, 103, 82, 186}; - -const uint8_t* const FACTORS[16] = { - FACTORS_0, FACTORS_1, FACTORS_2, FACTORS_3, FACTORS_4, FACTORS_5, - FACTORS_6, FACTORS_7, FACTORS_8, FACTORS_9, FACTORS_10, FACTORS_11, - FACTORS_12, FACTORS_13, FACTORS_14, FACTORS_15}; - -} // namespace - -int32_t CBC_ErrorCorrection::MODULO_VALUE = 0x12D; -int32_t CBC_ErrorCorrection::LOG[256] = {0}; -int32_t CBC_ErrorCorrection::ALOG[256] = {0}; -void CBC_ErrorCorrection::Initialize() { - int32_t p = 1; - for (int32_t i = 0; i < 255; i++) { - ALOG[i] = p; - LOG[p] = i; - p <<= 1; - if (p >= 256) { - p ^= MODULO_VALUE; - } - } -} -void CBC_ErrorCorrection::Finalize() {} -CBC_ErrorCorrection::CBC_ErrorCorrection() {} -CBC_ErrorCorrection::~CBC_ErrorCorrection() {} -CFX_WideString CBC_ErrorCorrection::encodeECC200(CFX_WideString codewords, - CBC_SymbolInfo* symbolInfo, - int32_t& e) { - if (codewords.GetLength() != symbolInfo->m_dataCapacity) { - e = BCExceptionIllegalArgument; - return CFX_WideString(); - } - CFX_WideString sb; - sb += codewords; - int32_t blockCount = symbolInfo->getInterleavedBlockCount(); - if (blockCount == 1) { - CFX_WideString ecc = - createECCBlock(codewords, symbolInfo->m_errorCodewords, e); - if (e != BCExceptionNO) - return CFX_WideString(); - sb += ecc; - } else { - std::vector<int32_t> dataSizes(blockCount); - std::vector<int32_t> errorSizes(blockCount); - std::vector<int32_t> startPos(blockCount); - for (int32_t i = 0; i < blockCount; i++) { - dataSizes[i] = symbolInfo->getDataLengthForInterleavedBlock(i + 1); - errorSizes[i] = symbolInfo->getErrorLengthForInterleavedBlock(i + 1); - startPos[i] = 0; - if (i > 0) { - startPos[i] = startPos[i - 1] + dataSizes[i]; - } - } - for (int32_t block = 0; block < blockCount; block++) { - CFX_WideString temp; - for (int32_t d = block; d < symbolInfo->m_dataCapacity; d += blockCount) { - temp += (wchar_t)codewords.GetAt(d); - } - CFX_WideString ecc = createECCBlock(temp, errorSizes[block], e); - if (e != BCExceptionNO) - return CFX_WideString(); - int32_t pos = 0; - for (int32_t l = block; l < errorSizes[block] * blockCount; - l += blockCount) { - sb.SetAt(symbolInfo->m_dataCapacity + l, ecc.GetAt(pos++)); - } - } - } - return sb; -} -CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, - int32_t numECWords, - int32_t& e) { - return createECCBlock(codewords, 0, codewords.GetLength(), numECWords, e); -} -CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, - int32_t start, - int32_t len, - int32_t numECWords, - int32_t& e) { - static const size_t kFactorTableNum = sizeof(FACTOR_SETS) / sizeof(int32_t); - size_t table = 0; - while (table < kFactorTableNum && FACTOR_SETS[table] != numECWords) - table++; - - if (table >= kFactorTableNum) { - e = BCExceptionIllegalArgument; - return CFX_WideString(); - } - uint16_t* ecc = FX_Alloc(uint16_t, numECWords); - FXSYS_memset(ecc, 0, numECWords * sizeof(uint16_t)); - for (int32_t l = start; l < start + len; l++) { - uint16_t m = ecc[numECWords - 1] ^ codewords.GetAt(l); - for (int32_t k = numECWords - 1; k > 0; k--) { - if (m != 0 && FACTORS[table][k] != 0) { - ecc[k] = (uint16_t)(ecc[k - 1] ^ - ALOG[(LOG[m] + LOG[FACTORS[table][k]]) % 255]); - } else { - ecc[k] = ecc[k - 1]; - } - } - if (m != 0 && FACTORS[table][0] != 0) { - ecc[0] = (uint16_t)ALOG[(LOG[m] + LOG[FACTORS[table][0]]) % 255]; - } else { - ecc[0] = 0; - } - } - CFX_WideString strecc; - for (int32_t j = 0; j < numECWords; j++) { - strecc += (wchar_t)ecc[numECWords - j - 1]; - } - FX_Free(ecc); - return strecc; -} diff --git a/xfa/fxbarcode/datamatrix/BC_ErrorCorrection.h b/xfa/fxbarcode/datamatrix/BC_ErrorCorrection.h deleted file mode 100644 index d3b9da8056..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_ErrorCorrection.h +++ /dev/null @@ -1,39 +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_FXBARCODE_DATAMATRIX_BC_ERRORCORRECTION_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_ERRORCORRECTION_H_ - -class CBC_SymbolInfo; - -class CBC_ErrorCorrection { - public: - CBC_ErrorCorrection(); - virtual ~CBC_ErrorCorrection(); - - static void Initialize(); - static void Finalize(); - static CFX_WideString encodeECC200(CFX_WideString codewords, - CBC_SymbolInfo* symbolInfo, - int32_t& e); - - private: - static int32_t MODULO_VALUE; - static int32_t LOG[256]; - static int32_t ALOG[256]; - - private: - static CFX_WideString createECCBlock(CFX_WideString codewords, - int32_t numECWords, - int32_t& e); - static CFX_WideString createECCBlock(CFX_WideString codewords, - int32_t start, - int32_t len, - int32_t numECWords, - int32_t& e); -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_ERRORCORRECTION_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp deleted file mode 100644 index 3ece55f2e9..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp +++ /dev/null @@ -1,360 +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 2006-2007 Jeremias Maerki. - * - * 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 <limits> -#include <memory> -#include <vector> - -#include "xfa/fxbarcode/BC_Dimension.h" -#include "xfa/fxbarcode/BC_UtilCodingConvert.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.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_EdifactEncoder.h" -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_EncoderContext.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/utils.h" - -wchar_t CBC_HighLevelEncoder::LATCH_TO_C40 = 230; -wchar_t CBC_HighLevelEncoder::LATCH_TO_BASE256 = 231; -wchar_t CBC_HighLevelEncoder::UPPER_SHIFT = 235; -wchar_t CBC_HighLevelEncoder::LATCH_TO_ANSIX12 = 238; -wchar_t CBC_HighLevelEncoder::LATCH_TO_TEXT = 239; -wchar_t CBC_HighLevelEncoder::LATCH_TO_EDIFACT = 240; -wchar_t CBC_HighLevelEncoder::C40_UNLATCH = 254; -wchar_t CBC_HighLevelEncoder::X12_UNLATCH = 254; -wchar_t CBC_HighLevelEncoder::PAD = 129; -wchar_t CBC_HighLevelEncoder::MACRO_05 = 236; -wchar_t CBC_HighLevelEncoder::MACRO_06 = 237; -const wchar_t* CBC_HighLevelEncoder::MACRO_05_HEADER = L"[)>05"; -const wchar_t* CBC_HighLevelEncoder::MACRO_06_HEADER = L"[)>06"; -const wchar_t CBC_HighLevelEncoder::MACRO_TRAILER = 0x0004; - -CBC_HighLevelEncoder::CBC_HighLevelEncoder() {} -CBC_HighLevelEncoder::~CBC_HighLevelEncoder() {} - -std::vector<uint8_t>& CBC_HighLevelEncoder::getBytesForMessage( - CFX_WideString msg) { - CFX_ByteString bytestr; - CBC_UtilCodingConvert::UnicodeToUTF8(msg, bytestr); - for (int32_t i = 0; i < bytestr.GetLength(); i++) - m_bytearray.push_back(bytestr.GetAt(i)); - return m_bytearray; -} -CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg, - CFX_WideString ecLevel, - int32_t& e) { - return encodeHighLevel(msg, ecLevel, FORCE_NONE, nullptr, nullptr, e); -} -CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg, - CFX_WideString ecLevel, - SymbolShapeHint shape, - CBC_Dimension* minSize, - CBC_Dimension* maxSize, - int32_t& e) { - CBC_EncoderContext context(msg, ecLevel, e); - if (e != BCExceptionNO) - return CFX_WideString(); - context.setSymbolShape(shape); - context.setSizeConstraints(minSize, maxSize); - if ((msg.Mid(0, 6) == MACRO_05_HEADER) && - (msg.Mid(msg.GetLength() - 1, 1) == MACRO_TRAILER)) { - context.writeCodeword(MACRO_05); - context.setSkipAtEnd(2); - context.m_pos += 6; - } else if ((msg.Mid(0, 6) == MACRO_06_HEADER) && - (msg.Mid(msg.GetLength() - 1, 1) == MACRO_TRAILER)) { - context.writeCodeword(MACRO_06); - context.setSkipAtEnd(2); - context.m_pos += 6; - } - - std::vector<std::unique_ptr<CBC_Encoder>> encoders; - encoders.push_back(std::unique_ptr<CBC_Encoder>(new CBC_ASCIIEncoder())); - encoders.push_back(std::unique_ptr<CBC_Encoder>(new CBC_C40Encoder())); - encoders.push_back(std::unique_ptr<CBC_Encoder>(new CBC_TextEncoder())); - encoders.push_back(std::unique_ptr<CBC_Encoder>(new CBC_X12Encoder())); - encoders.push_back(std::unique_ptr<CBC_Encoder>(new CBC_EdifactEncoder())); - encoders.push_back(std::unique_ptr<CBC_Encoder>(new CBC_Base256Encoder())); - int32_t encodingMode = ASCII_ENCODATION; - while (context.hasMoreCharacters()) { - encoders[encodingMode]->Encode(context, e); - if (e != BCExceptionNO) - return L""; - - if (context.m_newEncoding >= 0) { - encodingMode = context.m_newEncoding; - context.resetEncoderSignal(); - } - } - int32_t len = context.m_codewords.GetLength(); - context.updateSymbolInfo(e); - if (e != BCExceptionNO) - return L""; - - int32_t capacity = context.m_symbolInfo->m_dataCapacity; - if (len < capacity) { - if (encodingMode != ASCII_ENCODATION && - encodingMode != BASE256_ENCODATION) { - context.writeCodeword(0x00fe); - } - } - CFX_WideString codewords = context.m_codewords; - if (codewords.GetLength() < capacity) { - codewords += PAD; - } - while (codewords.GetLength() < capacity) { - codewords += (randomize253State(PAD, codewords.GetLength() + 1)); - } - return codewords; -} -int32_t CBC_HighLevelEncoder::lookAheadTest(CFX_WideString msg, - int32_t startpos, - int32_t currentMode) { - if (startpos >= msg.GetLength()) { - return currentMode; - } - std::vector<float> charCounts; - if (currentMode == ASCII_ENCODATION) { - charCounts.push_back(0); - charCounts.push_back(1); - charCounts.push_back(1); - charCounts.push_back(1); - charCounts.push_back(1); - charCounts.push_back(1.25f); - } else { - charCounts.push_back(1); - charCounts.push_back(2); - charCounts.push_back(2); - charCounts.push_back(2); - charCounts.push_back(2); - charCounts.push_back(2.25f); - charCounts[currentMode] = 0; - } - int32_t charsProcessed = 0; - while (true) { - if ((startpos + charsProcessed) == msg.GetLength()) { - int32_t min = std::numeric_limits<int32_t>::max(); - std::vector<uint8_t> mins(6); - std::vector<int32_t> intCharCounts(6); - min = findMinimums(charCounts, intCharCounts, min, mins); - int32_t minCount = getMinimumCount(mins); - if (intCharCounts[ASCII_ENCODATION] == min) { - return ASCII_ENCODATION; - } - if (minCount == 1 && mins[BASE256_ENCODATION] > 0) { - return BASE256_ENCODATION; - } - if (minCount == 1 && mins[EDIFACT_ENCODATION] > 0) { - return EDIFACT_ENCODATION; - } - if (minCount == 1 && mins[TEXT_ENCODATION] > 0) { - return TEXT_ENCODATION; - } - if (minCount == 1 && mins[X12_ENCODATION] > 0) { - return X12_ENCODATION; - } - return C40_ENCODATION; - } - wchar_t c = msg.GetAt(startpos + charsProcessed); - charsProcessed++; - if (isDigit(c)) { - charCounts[ASCII_ENCODATION] += 0.5; - } else if (isExtendedASCII(c)) { - charCounts[ASCII_ENCODATION] = (float)ceil(charCounts[ASCII_ENCODATION]); - charCounts[ASCII_ENCODATION] += 2; - } else { - charCounts[ASCII_ENCODATION] = (float)ceil(charCounts[ASCII_ENCODATION]); - charCounts[ASCII_ENCODATION]++; - } - if (isNativeC40(c)) { - charCounts[C40_ENCODATION] += 2.0f / 3.0f; - } else if (isExtendedASCII(c)) { - charCounts[C40_ENCODATION] += 8.0f / 3.0f; - } else { - charCounts[C40_ENCODATION] += 4.0f / 3.0f; - } - if (isNativeText(c)) { - charCounts[TEXT_ENCODATION] += 2.0f / 3.0f; - } else if (isExtendedASCII(c)) { - charCounts[TEXT_ENCODATION] += 8.0f / 3.0f; - } else { - charCounts[TEXT_ENCODATION] += 4.0f / 3.0f; - } - if (isNativeX12(c)) { - charCounts[X12_ENCODATION] += 2.0f / 3.0f; - } else if (isExtendedASCII(c)) { - charCounts[X12_ENCODATION] += 13.0f / 3.0f; - } else { - charCounts[X12_ENCODATION] += 10.0f / 3.0f; - } - if (isNativeEDIFACT(c)) { - charCounts[EDIFACT_ENCODATION] += 3.0f / 4.0f; - } else if (isExtendedASCII(c)) { - charCounts[EDIFACT_ENCODATION] += 17.0f / 4.0f; - } else { - charCounts[EDIFACT_ENCODATION] += 13.0f / 4.0f; - } - if (isSpecialB256(c)) { - charCounts[BASE256_ENCODATION] += 4; - } else { - charCounts[BASE256_ENCODATION]++; - } - if (charsProcessed >= 4) { - std::vector<int32_t> intCharCounts(6); - std::vector<uint8_t> mins(6); - findMinimums(charCounts, intCharCounts, - std::numeric_limits<int32_t>::max(), mins); - int32_t minCount = getMinimumCount(mins); - if (intCharCounts[ASCII_ENCODATION] < intCharCounts[BASE256_ENCODATION] && - intCharCounts[ASCII_ENCODATION] < intCharCounts[C40_ENCODATION] && - intCharCounts[ASCII_ENCODATION] < intCharCounts[TEXT_ENCODATION] && - intCharCounts[ASCII_ENCODATION] < intCharCounts[X12_ENCODATION] && - intCharCounts[ASCII_ENCODATION] < intCharCounts[EDIFACT_ENCODATION]) { - return ASCII_ENCODATION; - } - if (intCharCounts[BASE256_ENCODATION] < intCharCounts[ASCII_ENCODATION] || - (mins[C40_ENCODATION] + mins[TEXT_ENCODATION] + mins[X12_ENCODATION] + - mins[EDIFACT_ENCODATION]) == 0) { - return BASE256_ENCODATION; - } - if (minCount == 1 && mins[EDIFACT_ENCODATION] > 0) { - return EDIFACT_ENCODATION; - } - if (minCount == 1 && mins[TEXT_ENCODATION] > 0) { - return TEXT_ENCODATION; - } - if (minCount == 1 && mins[X12_ENCODATION] > 0) { - return X12_ENCODATION; - } - if (intCharCounts[C40_ENCODATION] + 1 < intCharCounts[ASCII_ENCODATION] && - intCharCounts[C40_ENCODATION] + 1 < - intCharCounts[BASE256_ENCODATION] && - intCharCounts[C40_ENCODATION] + 1 < - intCharCounts[EDIFACT_ENCODATION] && - intCharCounts[C40_ENCODATION] + 1 < intCharCounts[TEXT_ENCODATION]) { - if (intCharCounts[C40_ENCODATION] < intCharCounts[X12_ENCODATION]) { - return C40_ENCODATION; - } - if (intCharCounts[C40_ENCODATION] == intCharCounts[X12_ENCODATION]) { - int32_t p = startpos + charsProcessed + 1; - while (p < msg.GetLength()) { - wchar_t tc = msg.GetAt(p); - if (isX12TermSep(tc)) { - return X12_ENCODATION; - } - if (!isNativeX12(tc)) { - break; - } - p++; - } - return C40_ENCODATION; - } - } - } - } -} -bool CBC_HighLevelEncoder::isDigit(wchar_t ch) { - return ch >= '0' && ch <= '9'; -} -bool CBC_HighLevelEncoder::isExtendedASCII(wchar_t ch) { - return ch >= 128 && ch <= 255; -} -int32_t CBC_HighLevelEncoder::determineConsecutiveDigitCount(CFX_WideString msg, - int32_t startpos) { - int32_t count = 0; - int32_t len = msg.GetLength(); - int32_t idx = startpos; - if (idx < len) { - wchar_t ch = msg.GetAt(idx); - while (isDigit(ch) && idx < len) { - count++; - idx++; - if (idx < len) { - ch = msg.GetAt(idx); - } - } - } - return count; -} -void CBC_HighLevelEncoder::illegalCharacter(wchar_t c, int32_t& e) { - e = BCExceptionIllegalArgument; -} -wchar_t CBC_HighLevelEncoder::randomize253State(wchar_t ch, - int32_t codewordPosition) { - int32_t pseudoRandom = ((149 * codewordPosition) % 253) + 1; - int32_t tempVariable = ch + pseudoRandom; - return tempVariable <= 254 ? (wchar_t)tempVariable - : (wchar_t)(tempVariable - 254); -} -int32_t CBC_HighLevelEncoder::findMinimums(std::vector<float>& charCounts, - std::vector<int32_t>& intCharCounts, - int32_t min, - std::vector<uint8_t>& mins) { - for (size_t l = 0; l < mins.size(); l++) - mins[l] = 0; - - for (size_t i = 0; i < 6; i++) { - intCharCounts[i] = static_cast<int32_t>(ceil(charCounts[i])); - int32_t current = intCharCounts[i]; - if (min > current) { - min = current; - for (size_t j = 0; j < mins.size(); j++) - mins[j] = 0; - } - if (min == current) - mins[i]++; - } - return min; -} -int32_t CBC_HighLevelEncoder::getMinimumCount(std::vector<uint8_t>& mins) { - int32_t minCount = 0; - for (int32_t i = 0; i < 6; i++) { - minCount += mins[i]; - } - return minCount; -} -bool CBC_HighLevelEncoder::isNativeC40(wchar_t ch) { - return (ch == ' ') || (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z'); -} -bool CBC_HighLevelEncoder::isNativeText(wchar_t ch) { - return (ch == ' ') || (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z'); -} -bool CBC_HighLevelEncoder::isNativeX12(wchar_t ch) { - return isX12TermSep(ch) || (ch == ' ') || (ch >= '0' && ch <= '9') || - (ch >= 'A' && ch <= 'Z'); -} -bool CBC_HighLevelEncoder::isX12TermSep(wchar_t ch) { - return (ch == '\r') || (ch == '*') || (ch == '>'); -} -bool CBC_HighLevelEncoder::isNativeEDIFACT(wchar_t ch) { - return ch >= ' ' && ch <= '^'; -} -bool CBC_HighLevelEncoder::isSpecialB256(wchar_t ch) { - return false; -} diff --git a/xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.h b/xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.h deleted file mode 100644 index 6819e29163..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.h +++ /dev/null @@ -1,79 +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_FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_ - -#include <vector> - -#include "xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h" - -#define ASCII_ENCODATION 0 -#define C40_ENCODATION 1 -#define TEXT_ENCODATION 2 -#define X12_ENCODATION 3 -#define EDIFACT_ENCODATION 4 -#define BASE256_ENCODATION 5 - -class CBC_HighLevelEncoder : public CBC_SymbolShapeHint { - public: - CBC_HighLevelEncoder(); - ~CBC_HighLevelEncoder() override; - - std::vector<uint8_t>& getBytesForMessage(CFX_WideString msg); - static CFX_WideString encodeHighLevel(CFX_WideString msg, - CFX_WideString ecLevel, - int32_t& e); - static CFX_WideString encodeHighLevel(CFX_WideString msg, - CFX_WideString ecLevel, - SymbolShapeHint shape, - CBC_Dimension* minSize, - CBC_Dimension* maxSize, - int32_t& e); - static int32_t lookAheadTest(CFX_WideString msg, - int32_t startpos, - int32_t currentMode); - static bool isDigit(wchar_t ch); - static bool isExtendedASCII(wchar_t ch); - static int32_t determineConsecutiveDigitCount(CFX_WideString msg, - int32_t startpos); - static void illegalCharacter(wchar_t c, int32_t& e); - - public: - static wchar_t LATCH_TO_C40; - static wchar_t LATCH_TO_BASE256; - static wchar_t UPPER_SHIFT; - static wchar_t LATCH_TO_ANSIX12; - static wchar_t LATCH_TO_TEXT; - static wchar_t LATCH_TO_EDIFACT; - static wchar_t C40_UNLATCH; - static wchar_t X12_UNLATCH; - - private: - static wchar_t PAD; - static wchar_t MACRO_05; - static wchar_t MACRO_06; - static const wchar_t* MACRO_05_HEADER; - static const wchar_t* MACRO_06_HEADER; - static const wchar_t MACRO_TRAILER; - std::vector<uint8_t> m_bytearray; - - private: - static wchar_t randomize253State(wchar_t ch, int32_t codewordPosition); - static int32_t findMinimums(std::vector<float>& charCounts, - std::vector<int32_t>& intCharCounts, - int32_t min, - std::vector<uint8_t>& mins); - static int32_t getMinimumCount(std::vector<uint8_t>& mins); - static bool isNativeC40(wchar_t ch); - static bool isNativeText(wchar_t ch); - static bool isNativeX12(wchar_t ch); - static bool isX12TermSep(wchar_t ch); - static bool isNativeEDIFACT(wchar_t ch); - static bool isSpecialB256(wchar_t ch); -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_SymbolInfo.cpp b/xfa/fxbarcode/datamatrix/BC_SymbolInfo.cpp deleted file mode 100644 index ae74b8b2d4..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_SymbolInfo.cpp +++ /dev/null @@ -1,230 +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 2006 Jeremias Maerki - * - * 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/datamatrix/BC_SymbolInfo.h" - -#include "xfa/fxbarcode/BC_Dimension.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h" -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h" - -namespace { - -const size_t kSymbolsCount = 30; - -CBC_SymbolInfo* g_symbols[kSymbolsCount] = { - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}; - -} // namespace - -void CBC_SymbolInfo::Initialize() { - g_symbols[0] = new CBC_SymbolInfo(false, 3, 5, 8, 8, 1); - g_symbols[1] = new CBC_SymbolInfo(false, 5, 7, 10, 10, 1); - g_symbols[2] = new CBC_SymbolInfo(true, 5, 7, 16, 6, 1); - g_symbols[3] = new CBC_SymbolInfo(false, 8, 10, 12, 12, 1); - g_symbols[4] = new CBC_SymbolInfo(true, 10, 11, 14, 6, 2); - g_symbols[5] = new CBC_SymbolInfo(false, 12, 12, 14, 14, 1); - g_symbols[6] = new CBC_SymbolInfo(true, 16, 14, 24, 10, 1); - g_symbols[7] = new CBC_SymbolInfo(false, 18, 14, 16, 16, 1); - g_symbols[8] = new CBC_SymbolInfo(false, 22, 18, 18, 18, 1); - g_symbols[9] = new CBC_SymbolInfo(true, 22, 18, 16, 10, 2); - g_symbols[10] = new CBC_SymbolInfo(false, 30, 20, 20, 20, 1); - g_symbols[11] = new CBC_SymbolInfo(true, 32, 24, 16, 14, 2); - g_symbols[12] = new CBC_SymbolInfo(false, 36, 24, 22, 22, 1); - g_symbols[13] = new CBC_SymbolInfo(false, 44, 28, 24, 24, 1); - g_symbols[14] = new CBC_SymbolInfo(true, 49, 28, 22, 14, 2); - g_symbols[15] = new CBC_SymbolInfo(false, 62, 36, 14, 14, 4); - g_symbols[16] = new CBC_SymbolInfo(false, 86, 42, 16, 16, 4); - g_symbols[17] = new CBC_SymbolInfo(false, 114, 48, 18, 18, 4); - g_symbols[18] = new CBC_SymbolInfo(false, 144, 56, 20, 20, 4); - g_symbols[19] = new CBC_SymbolInfo(false, 174, 68, 22, 22, 4); - g_symbols[20] = new CBC_SymbolInfo(false, 204, 84, 24, 24, 4, 102, 42); - g_symbols[21] = new CBC_SymbolInfo(false, 280, 112, 14, 14, 16, 140, 56); - g_symbols[22] = new CBC_SymbolInfo(false, 368, 144, 16, 16, 16, 92, 36); - g_symbols[23] = new CBC_SymbolInfo(false, 456, 192, 18, 18, 16, 114, 48); - g_symbols[24] = new CBC_SymbolInfo(false, 576, 224, 20, 20, 16, 144, 56); - g_symbols[25] = new CBC_SymbolInfo(false, 696, 272, 22, 22, 16, 174, 68); - g_symbols[26] = new CBC_SymbolInfo(false, 816, 336, 24, 24, 16, 136, 56); - g_symbols[27] = new CBC_SymbolInfo(false, 1050, 408, 18, 18, 36, 175, 68); - g_symbols[28] = new CBC_SymbolInfo(false, 1304, 496, 20, 20, 36, 163, 62); - g_symbols[29] = new CBC_DataMatrixSymbolInfo144(); -} - -void CBC_SymbolInfo::Finalize() { - for (size_t i = 0; i < kSymbolsCount; i++) { - delete g_symbols[i]; - g_symbols[i] = nullptr; - } -} - -CBC_SymbolInfo::CBC_SymbolInfo(bool rectangular, - int32_t dataCapacity, - int32_t errorCodewords, - int32_t matrixWidth, - int32_t matrixHeight, - int32_t dataRegions) { - m_rectangular = rectangular; - m_dataCapacity = dataCapacity; - m_errorCodewords = errorCodewords; - m_matrixWidth = matrixWidth; - m_matrixHeight = matrixHeight; - m_dataRegions = dataRegions; - m_rsBlockData = dataCapacity; - m_rsBlockError = errorCodewords; -} -CBC_SymbolInfo::CBC_SymbolInfo(bool rectangular, - int32_t dataCapacity, - int32_t errorCodewords, - int32_t matrixWidth, - int32_t matrixHeight, - int32_t dataRegions, - int32_t rsBlockData, - int32_t rsBlockError) { - m_rectangular = rectangular; - m_dataCapacity = dataCapacity; - m_errorCodewords = errorCodewords; - m_matrixWidth = matrixWidth; - m_matrixHeight = matrixHeight; - m_dataRegions = dataRegions; - m_rsBlockData = rsBlockData; - m_rsBlockError = rsBlockError; -} -CBC_SymbolInfo::~CBC_SymbolInfo() {} - -CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, int32_t& e) { - return lookup(dataCodewords, FORCE_NONE, true, e); -} -CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, - SymbolShapeHint shape, - int32_t& e) { - return lookup(dataCodewords, shape, true, e); -} -CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, - bool allowRectangular, - bool fail, - int32_t& e) { - SymbolShapeHint shape = allowRectangular ? FORCE_NONE : FORCE_SQUARE; - return lookup(dataCodewords, shape, fail, e); -} -CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, - SymbolShapeHint shape, - bool fail, - int32_t& e) { - return lookup(dataCodewords, shape, nullptr, nullptr, fail, e); -} -CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, - SymbolShapeHint shape, - CBC_Dimension* minSize, - CBC_Dimension* maxSize, - bool fail, - int32_t& e) { - for (size_t i = 0; i < kSymbolsCount; i++) { - CBC_SymbolInfo* symbol = g_symbols[i]; - if (shape == FORCE_SQUARE && symbol->m_rectangular) { - continue; - } - if (shape == FORCE_RECTANGLE && !symbol->m_rectangular) { - continue; - } - if (minSize && (symbol->getSymbolWidth(e) < minSize->getWidth() || - symbol->getSymbolHeight(e) < minSize->getHeight())) { - if (e != BCExceptionNO) - return nullptr; - continue; - } - if (maxSize && (symbol->getSymbolWidth(e) > maxSize->getWidth() || - symbol->getSymbolHeight(e) > maxSize->getHeight())) { - if (e != BCExceptionNO) - return nullptr; - continue; - } - if (dataCodewords <= symbol->m_dataCapacity) { - return symbol; - } - } - if (fail) - e = BCExceptionIllegalDataCodewords; - return nullptr; -} - -int32_t CBC_SymbolInfo::getHorizontalDataRegions(int32_t& e) { - switch (m_dataRegions) { - case 1: - return 1; - case 2: - return 2; - case 4: - return 2; - case 16: - return 4; - case 36: - return 6; - default: - e = BCExceptionCannotHandleThisNumberOfDataRegions; - return 0; - } -} -int32_t CBC_SymbolInfo::getVerticalDataRegions(int32_t& e) { - switch (m_dataRegions) { - case 1: - return 1; - case 2: - return 1; - case 4: - return 2; - case 16: - return 4; - case 36: - return 6; - default: - e = BCExceptionCannotHandleThisNumberOfDataRegions; - return 0; - } -} -int32_t CBC_SymbolInfo::getSymbolDataWidth(int32_t& e) { - return getHorizontalDataRegions(e) * m_matrixWidth; -} -int32_t CBC_SymbolInfo::getSymbolDataHeight(int32_t& e) { - return getVerticalDataRegions(e) * m_matrixHeight; -} -int32_t CBC_SymbolInfo::getSymbolWidth(int32_t& e) { - return getSymbolDataWidth(e) + (getHorizontalDataRegions(e) * 2); -} -int32_t CBC_SymbolInfo::getSymbolHeight(int32_t& e) { - return getSymbolDataHeight(e) + (getVerticalDataRegions(e) * 2); -} -int32_t CBC_SymbolInfo::getCodewordCount() { - return m_dataCapacity + m_errorCodewords; -} -int32_t CBC_SymbolInfo::getInterleavedBlockCount() { - return m_dataCapacity / m_rsBlockData; -} -int32_t CBC_SymbolInfo::getDataLengthForInterleavedBlock(int32_t index) { - return m_rsBlockData; -} -int32_t CBC_SymbolInfo::getErrorLengthForInterleavedBlock(int32_t index) { - return m_rsBlockError; -} diff --git a/xfa/fxbarcode/datamatrix/BC_SymbolInfo.h b/xfa/fxbarcode/datamatrix/BC_SymbolInfo.h deleted file mode 100644 index d2730025db..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_SymbolInfo.h +++ /dev/null @@ -1,79 +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_FXBARCODE_DATAMATRIX_BC_SYMBOLINFO_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_SYMBOLINFO_H_ - -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h" - -class CBC_Dimension; - -class CBC_SymbolInfo : public CBC_SymbolShapeHint { - public: - CBC_SymbolInfo(bool rectangular, - int32_t dataCapacity, - int32_t errorCodewords, - int32_t matrixWidth, - int32_t matrixHeight, - int32_t dataRegions); - ~CBC_SymbolInfo() override; - - static void Initialize(); - static void Finalize(); - static void overrideSymbolSet(CBC_SymbolInfo* override); - static CBC_SymbolInfo* lookup(int32_t dataCodewords, int32_t& e); - static CBC_SymbolInfo* lookup(int32_t dataCodewords, - SymbolShapeHint shape, - int32_t& e); - static CBC_SymbolInfo* lookup(int32_t dataCodewords, - bool allowRectangular, - bool fail, - int32_t& e); - static CBC_SymbolInfo* lookup(int32_t dataCodewords, - SymbolShapeHint shape, - bool fail, - int32_t& e); - static CBC_SymbolInfo* lookup(int32_t dataCodewords, - SymbolShapeHint shape, - CBC_Dimension* minSize, - CBC_Dimension* maxSize, - bool fail, - int32_t& e); - int32_t getHorizontalDataRegions(int32_t& e); - int32_t getVerticalDataRegions(int32_t& e); - int32_t getSymbolDataWidth(int32_t& e); - int32_t getSymbolDataHeight(int32_t& e); - int32_t getSymbolWidth(int32_t& e); - int32_t getSymbolHeight(int32_t& e); - int32_t getCodewordCount(); - int32_t getInterleavedBlockCount(); - int32_t getDataLengthForInterleavedBlock(int32_t index); - int32_t getErrorLengthForInterleavedBlock(int32_t index); - - int32_t m_dataCapacity; - int32_t m_errorCodewords; - int32_t m_matrixWidth; - int32_t m_matrixHeight; - int32_t m_rsBlockData; - int32_t m_rsBlockError; - - private: - CBC_SymbolInfo(bool rectangular, - int32_t dataCapacity, - int32_t errorCodewords, - int32_t matrixWidth, - int32_t matrixHeight, - int32_t dataRegions, - int32_t rsBlockData, - int32_t rsBlockError); - - bool m_rectangular; - int32_t m_dataRegions; -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_SYMBOLINFO_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.cpp b/xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.cpp deleted file mode 100644 index 8f91dd837a..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.cpp +++ /dev/null @@ -1,26 +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 2007 Jeremias Maerki. - * - * 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/datamatrix/BC_SymbolShapeHint.h" - -CBC_SymbolShapeHint::CBC_SymbolShapeHint() {} -CBC_SymbolShapeHint::~CBC_SymbolShapeHint() {} diff --git a/xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h b/xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h deleted file mode 100644 index 7cd4c86931..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h +++ /dev/null @@ -1,22 +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_FXBARCODE_DATAMATRIX_BC_SYMBOLSHAPEHINT_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_SYMBOLSHAPEHINT_H_ - -class CBC_SymbolShapeHint { - public: - CBC_SymbolShapeHint(); - virtual ~CBC_SymbolShapeHint(); - - enum SymbolShapeHint { - FORCE_NONE, - FORCE_SQUARE, - FORCE_RECTANGLE, - }; -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_SYMBOLSHAPEHINT_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_TextEncoder.cpp b/xfa/fxbarcode/datamatrix/BC_TextEncoder.cpp deleted file mode 100644 index cc02661c26..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_TextEncoder.cpp +++ /dev/null @@ -1,97 +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 2006-2007 Jeremias Maerki. - * - * 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_Dimension.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/datamatrix/BC_C40Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_EncoderContext.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" - -CBC_TextEncoder::CBC_TextEncoder() {} -CBC_TextEncoder::~CBC_TextEncoder() {} -int32_t CBC_TextEncoder::getEncodingMode() { - return TEXT_ENCODATION; -} -int32_t CBC_TextEncoder::encodeChar(wchar_t c, CFX_WideString& sb, int32_t& e) { - if (c == ' ') { - sb += (wchar_t)'\3'; - return 1; - } - if (c >= '0' && c <= '9') { - sb += (wchar_t)(c - 48 + 4); - return 1; - } - if (c >= 'a' && c <= 'z') { - sb += (wchar_t)(c - 97 + 14); - return 1; - } - if (c <= 0x1f) { - sb += (wchar_t)'\0'; - sb += c; - return 2; - } - if (c >= '!' && c <= '/') { - sb += (wchar_t)'\1'; - sb += (wchar_t)(c - 33); - return 2; - } - if (c >= ':' && c <= '@') { - sb += (wchar_t)'\1'; - sb += (wchar_t)(c - 58 + 15); - return 2; - } - if (c >= '[' && c <= '_') { - sb += (wchar_t)'\1'; - sb += (wchar_t)(c - 91 + 22); - return 2; - } - if (c == 0x0060) { - sb += (wchar_t)'\2'; - sb += (wchar_t)(c - 96); - return 2; - } - if (c >= 'A' && c <= 'Z') { - sb += (wchar_t)'\2'; - sb += (wchar_t)(c - 65 + 1); - return 2; - } - if (c >= '{' && c <= 0x007f) { - sb += (wchar_t)'\2'; - sb += (wchar_t)(c - 123 + 27); - return 2; - } - if (c >= 0x0080) { - sb += (wchar_t)'\1'; - sb += (wchar_t)0x001e; - int32_t len = 2; - len += encodeChar((wchar_t)(c - 128), sb, e); - if (e != BCExceptionNO) - return -1; - return len; - } - CBC_HighLevelEncoder::illegalCharacter(c, e); - return -1; -} diff --git a/xfa/fxbarcode/datamatrix/BC_TextEncoder.h b/xfa/fxbarcode/datamatrix/BC_TextEncoder.h deleted file mode 100644 index 71092023da..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_TextEncoder.h +++ /dev/null @@ -1,22 +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_FXBARCODE_DATAMATRIX_BC_TEXTENCODER_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_TEXTENCODER_H_ - -class CBC_TextEncoder; - -class CBC_TextEncoder : public CBC_C40Encoder { - public: - CBC_TextEncoder(); - ~CBC_TextEncoder() override; - - // CBC_C40Encoder - int32_t getEncodingMode() override; - int32_t encodeChar(wchar_t c, CFX_WideString& sb, int32_t& e) override; -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_TEXTENCODER_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_X12Encoder.cpp b/xfa/fxbarcode/datamatrix/BC_X12Encoder.cpp deleted file mode 100644 index 570076b348..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_X12Encoder.cpp +++ /dev/null @@ -1,101 +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 2006-2007 Jeremias Maerki. - * - * 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_Dimension.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/datamatrix/BC_C40Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_Encoder.h" -#include "xfa/fxbarcode/datamatrix/BC_EncoderContext.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_X12Encoder.h" - -CBC_X12Encoder::CBC_X12Encoder() {} -CBC_X12Encoder::~CBC_X12Encoder() {} -int32_t CBC_X12Encoder::getEncodingMode() { - return X12_ENCODATION; -} -void CBC_X12Encoder::Encode(CBC_EncoderContext& context, int32_t& e) { - CFX_WideString buffer; - while (context.hasMoreCharacters()) { - wchar_t c = context.getCurrentChar(); - context.m_pos++; - encodeChar(c, buffer, e); - if (e != BCExceptionNO) { - return; - } - int32_t count = buffer.GetLength(); - if ((count % 3) == 0) { - writeNextTriplet(context, buffer); - int32_t newMode = CBC_HighLevelEncoder::lookAheadTest( - context.m_msg, context.m_pos, getEncodingMode()); - if (newMode != getEncodingMode()) { - context.signalEncoderChange(newMode); - break; - } - } - } - handleEOD(context, buffer, e); -} -void CBC_X12Encoder::handleEOD(CBC_EncoderContext& context, - CFX_WideString& buffer, - int32_t& e) { - context.updateSymbolInfo(e); - if (e != BCExceptionNO) { - return; - } - int32_t available = - context.m_symbolInfo->m_dataCapacity - context.getCodewordCount(); - int32_t count = buffer.GetLength(); - if (count == 2) { - context.writeCodeword(CBC_HighLevelEncoder::X12_UNLATCH); - context.m_pos -= 2; - context.signalEncoderChange(ASCII_ENCODATION); - } else if (count == 1) { - context.m_pos--; - if (available > 1) { - context.writeCodeword(CBC_HighLevelEncoder::X12_UNLATCH); - } - context.signalEncoderChange(ASCII_ENCODATION); - } -} -int32_t CBC_X12Encoder::encodeChar(wchar_t c, CFX_WideString& sb, int32_t& e) { - if (c == '\r') { - sb += (wchar_t)'\0'; - } else if (c == '*') { - sb += (wchar_t)'\1'; - } else if (c == '>') { - sb += (wchar_t)'\2'; - } else if (c == ' ') { - sb += (wchar_t)'\3'; - } else if (c >= '0' && c <= '9') { - sb += (wchar_t)(c - 48 + 4); - } else if (c >= 'A' && c <= 'Z') { - sb += (wchar_t)(c - 65 + 14); - } else { - CBC_HighLevelEncoder::illegalCharacter(c, e); - if (e != BCExceptionNO) - return -1; - } - return 1; -} diff --git a/xfa/fxbarcode/datamatrix/BC_X12Encoder.h b/xfa/fxbarcode/datamatrix/BC_X12Encoder.h deleted file mode 100644 index 693b9bba6c..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_X12Encoder.h +++ /dev/null @@ -1,26 +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_FXBARCODE_DATAMATRIX_BC_X12ENCODER_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_X12ENCODER_H_ - -class CBC_C40Encoder; -class CBC_X12Encoder; -class CBC_X12Encoder : public CBC_C40Encoder { - public: - CBC_X12Encoder(); - ~CBC_X12Encoder() override; - - // CBC_C40Encoder - int32_t getEncodingMode() override; - void Encode(CBC_EncoderContext& context, int32_t& e) override; - void handleEOD(CBC_EncoderContext& context, - CFX_WideString& buffer, - int32_t& e) override; - int32_t encodeChar(wchar_t c, CFX_WideString& sb, int32_t& e) override; -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_X12ENCODER_H_ diff --git a/xfa/fxbarcode/oned/BC_OneDimWriter.cpp b/xfa/fxbarcode/oned/BC_OneDimWriter.cpp deleted file mode 100644 index 16eba2df10..0000000000 --- a/xfa/fxbarcode/oned/BC_OneDimWriter.cpp +++ /dev/null @@ -1,482 +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/oned/BC_OneDimWriter.h" - -#include <algorithm> -#include <memory> - -#include "core/fxge/cfx_fxgedevice.h" -#include "core/fxge/cfx_gemodule.h" -#include "core/fxge/cfx_graphstatedata.h" -#include "core/fxge/cfx_pathdata.h" -#include "core/fxge/cfx_renderdevice.h" -#include "core/fxge/cfx_unicodeencodingex.h" -#include "third_party/base/ptr_util.h" -#include "xfa/fxbarcode/BC_Writer.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" - -CBC_OneDimWriter::CBC_OneDimWriter() { - m_locTextLoc = BC_TEXT_LOC_BELOWEMBED; - m_bPrintChecksum = true; - m_iDataLenth = 0; - m_bCalcChecksum = false; - m_pFont = nullptr; - m_fFontSize = 10; - m_iFontStyle = 0; - m_fontColor = 0xff000000; - m_iContentLen = 0; - m_bLeftPadding = false; - m_bRightPadding = false; -} - -CBC_OneDimWriter::~CBC_OneDimWriter() {} - -void CBC_OneDimWriter::SetPrintChecksum(bool checksum) { - m_bPrintChecksum = checksum; -} - -void CBC_OneDimWriter::SetDataLength(int32_t length) { - m_iDataLenth = length; -} - -void CBC_OneDimWriter::SetCalcChecksum(bool state) { - m_bCalcChecksum = state; -} - -bool CBC_OneDimWriter::SetFont(CFX_Font* cFont) { - if (!cFont) - return false; - - m_pFont = cFont; - return true; -} - -void CBC_OneDimWriter::SetFontSize(float size) { - m_fFontSize = size; -} - -void CBC_OneDimWriter::SetFontStyle(int32_t style) { - m_iFontStyle = style; -} - -void CBC_OneDimWriter::SetFontColor(FX_ARGB color) { - m_fontColor = color; -} - -wchar_t CBC_OneDimWriter::Upper(wchar_t ch) { - if (ch >= 'a' && ch <= 'z') { - ch = ch - ('a' - 'A'); - } - return ch; -} - -uint8_t* CBC_OneDimWriter::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e) { - uint8_t* ret = nullptr; - outHeight = 1; - if (m_Width >= 20) { - ret = Encode(contents, outWidth, e); - } else { - ret = Encode(contents, outWidth, e); - } - if (e != BCExceptionNO) - return nullptr; - return ret; -} - -uint8_t* CBC_OneDimWriter::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) { - uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); - if (e != BCExceptionNO) - return nullptr; - return ret; -} - -uint8_t* CBC_OneDimWriter::Encode(const CFX_ByteString& contents, - int32_t& outLength, - int32_t& e) { - return nullptr; -} - -int32_t CBC_OneDimWriter::AppendPattern(uint8_t* target, - int32_t pos, - const int32_t* pattern, - int32_t patternLength, - int32_t startColor, - int32_t& e) { - if (startColor != 0 && startColor != 1) { - e = BCExceptionValueMustBeEither0or1; - return 0; - } - uint8_t color = (uint8_t)startColor; - int32_t numAdded = 0; - for (int32_t i = 0; i < patternLength; i++) { - for (int32_t j = 0; j < pattern[i]; j++) { - target[pos] = color; - pos += 1; - numAdded += 1; - } - color ^= 1; - } - return numAdded; -} - -void CBC_OneDimWriter::CalcTextInfo(const CFX_ByteString& text, - FXTEXT_CHARPOS* charPos, - CFX_Font* cFont, - float geWidth, - int32_t fontSize, - float& charsLen) { - std::unique_ptr<CFX_UnicodeEncodingEx> encoding( - FX_CreateFontEncodingEx(cFont)); - - int32_t length = text.GetLength(); - uint32_t* pCharCode = FX_Alloc(uint32_t, text.GetLength()); - float charWidth = 0; - for (int32_t j = 0; j < text.GetLength(); j++) { - pCharCode[j] = encoding->CharCodeFromUnicode(text[j]); - int32_t glyp_code = encoding->GlyphFromCharCode(pCharCode[j]); - int32_t glyp_value = cFont->GetGlyphWidth(glyp_code); - float temp = (float)((glyp_value)*fontSize / 1000.0); - charWidth += temp; - } - charsLen = charWidth; - float leftPositon = (float)(geWidth - charsLen) / 2.0f; - if (leftPositon < 0 && geWidth == 0) { - leftPositon = 0; - } - float penX = 0.0; - float penY = - (float)FXSYS_abs(cFont->GetDescent()) * (float)fontSize / 1000.0f; - float left = leftPositon; - float top = 0.0; - charPos[0].m_Origin = CFX_PointF(penX + left, penY + top); - charPos[0].m_GlyphIndex = encoding->GlyphFromCharCode(pCharCode[0]); - charPos[0].m_FontCharWidth = cFont->GetGlyphWidth(charPos[0].m_GlyphIndex); -#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - charPos[0].m_ExtGID = charPos[0].m_GlyphIndex; -#endif - penX += (float)(charPos[0].m_FontCharWidth) * (float)fontSize / 1000.0f; - for (int32_t i = 1; i < length; i++) { - charPos[i].m_Origin = CFX_PointF(penX + left, penY + top); - charPos[i].m_GlyphIndex = encoding->GlyphFromCharCode(pCharCode[i]); - charPos[i].m_FontCharWidth = cFont->GetGlyphWidth(charPos[i].m_GlyphIndex); -#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - charPos[i].m_ExtGID = charPos[i].m_GlyphIndex; -#endif - penX += (float)(charPos[i].m_FontCharWidth) * (float)fontSize / 1000.0f; - } - FX_Free(pCharCode); -} - -void CBC_OneDimWriter::ShowDeviceChars(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - const CFX_ByteString str, - float geWidth, - FXTEXT_CHARPOS* pCharPos, - float locX, - float locY, - int32_t barWidth) { - int32_t iFontSize = (int32_t)fabs(m_fFontSize); - int32_t iTextHeight = iFontSize + 1; - CFX_FloatRect rect((float)locX, (float)locY, (float)(locX + geWidth), - (float)(locY + iTextHeight)); - if (geWidth != m_Width) { - rect.right -= 1; - } - matrix->TransformRect(rect); - FX_RECT re = rect.GetOuterRect(); - device->FillRect(&re, m_backgroundColor); - CFX_Matrix affine_matrix(1.0, 0.0, 0.0, -1.0, (float)locX, - (float)(locY + iFontSize)); - if (matrix) { - affine_matrix.Concat(*matrix); - } - device->DrawNormalText(str.GetLength(), pCharPos, m_pFont, - static_cast<float>(iFontSize), &affine_matrix, - m_fontColor, FXTEXT_CLEARTYPE); -} - -void CBC_OneDimWriter::ShowBitmapChars( - const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - const CFX_ByteString str, - float geWidth, - FXTEXT_CHARPOS* pCharPos, - float locX, - float locY, - int32_t barWidth) { - int32_t iFontSize = (int32_t)fabs(m_fFontSize); - int32_t iTextHeight = iFontSize + 1; - CFX_FxgeDevice ge; - ge.Create((int)geWidth, iTextHeight, m_colorSpace, nullptr); - FX_RECT geRect(0, 0, (int)geWidth, iTextHeight); - ge.FillRect(&geRect, m_backgroundColor); - CFX_Matrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, - static_cast<float>(iFontSize)); - ge.DrawNormalText(str.GetLength(), pCharPos, m_pFont, - static_cast<float>(iFontSize), &affine_matrix, m_fontColor, - FXTEXT_CLEARTYPE); - CFX_FxgeDevice geBitmap; - geBitmap.Attach(pOutBitmap, false, nullptr, false); - geBitmap.SetDIBits(ge.GetBitmap(), (int)locX, (int)locY); -} - -void CBC_OneDimWriter::ShowChars(const CFX_WideStringC& contents, - const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t barWidth, - int32_t multiple, - int32_t& e) { - if (!device && !pOutBitmap) { - e = BCExceptionIllegalArgument; - return; - } - if (!m_pFont) { - e = BCExceptionNullPointer; - return; - } - CFX_ByteString str = FX_UTF8Encode(contents); - int32_t iLen = str.GetLength(); - FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLen); - FXSYS_memset(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLen); - float charsLen = 0; - float geWidth = 0; - if (m_locTextLoc == BC_TEXT_LOC_ABOVEEMBED || - m_locTextLoc == BC_TEXT_LOC_BELOWEMBED) { - geWidth = 0; - } else if (m_locTextLoc == BC_TEXT_LOC_ABOVE || - m_locTextLoc == BC_TEXT_LOC_BELOW) { - geWidth = (float)barWidth; - } - int32_t iFontSize = (int32_t)fabs(m_fFontSize); - int32_t iTextHeight = iFontSize + 1; - CalcTextInfo(str, pCharPos, m_pFont, geWidth, iFontSize, charsLen); - if (charsLen < 1) { - return; - } - int32_t locX = 0; - int32_t locY = 0; - switch (m_locTextLoc) { - case BC_TEXT_LOC_ABOVEEMBED: - locX = (int32_t)(barWidth - charsLen) / 2; - locY = 0; - geWidth = charsLen; - break; - case BC_TEXT_LOC_ABOVE: - locX = 0; - locY = 0; - geWidth = (float)barWidth; - break; - case BC_TEXT_LOC_BELOWEMBED: - locX = (int32_t)(barWidth - charsLen) / 2; - locY = m_Height - iTextHeight; - geWidth = charsLen; - break; - case BC_TEXT_LOC_BELOW: - default: - locX = 0; - locY = m_Height - iTextHeight; - geWidth = (float)barWidth; - break; - } - if (device) { - ShowDeviceChars(device, matrix, str, geWidth, pCharPos, (float)locX, - (float)locY, barWidth); - } else { - ShowBitmapChars(pOutBitmap, str, geWidth, pCharPos, (float)locX, - (float)locY, barWidth); - } - FX_Free(pCharPos); -} - -void CBC_OneDimWriter::RenderBitmapResult( - CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - const CFX_WideStringC& contents, - int32_t& e) { - if (!m_output) - if (e != BCExceptionNO) - return; - - pOutBitmap = CreateDIBitmap(m_output->GetWidth(), m_output->GetHeight()); - pOutBitmap->Clear(m_backgroundColor); - if (!pOutBitmap) { - e = BCExceptionFailToCreateBitmap; - return; - } - for (int32_t x = 0; x < m_output->GetWidth(); x++) { - for (int32_t y = 0; y < m_output->GetHeight(); y++) { - if (m_output->Get(x, y)) { - pOutBitmap->SetPixel(x, y, m_barColor); - } - } - } - int32_t i = 0; - for (; i < contents.GetLength(); i++) { - if (contents.GetAt(i) != ' ') - break; - } - if (m_locTextLoc != BC_TEXT_LOC_NONE && i < contents.GetLength()) { - ShowChars(contents, pOutBitmap, nullptr, nullptr, m_barWidth, m_multiple, - e); - if (e != BCExceptionNO) - return; - } - pOutBitmap = pOutBitmap->StretchTo(m_Width, m_Height); -} - -void CBC_OneDimWriter::RenderDeviceResult(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - const CFX_WideStringC& contents, - int32_t& e) { - if (!m_output) - if (e != BCExceptionNO) - return; - - CFX_GraphStateData stateData; - CFX_PathData path; - path.AppendRect(0, 0, (float)m_Width, (float)m_Height); - device->DrawPath(&path, matrix, &stateData, m_backgroundColor, - m_backgroundColor, FXFILL_ALTERNATE); - CFX_Matrix matri(m_outputHScale, 0.0, 0.0, (float)m_Height, 0.0, 0.0); - matri.Concat(*matrix); - for (int32_t x = 0; x < m_output->GetWidth(); x++) { - for (int32_t y = 0; y < m_output->GetHeight(); y++) { - CFX_PathData rect; - rect.AppendRect((float)x, (float)y, (float)(x + 1), (float)(y + 1)); - if (m_output->Get(x, y)) { - CFX_GraphStateData data; - device->DrawPath(&rect, &matri, &data, m_barColor, 0, FXFILL_WINDING); - } - } - } - int32_t i = 0; - for (; i < contents.GetLength(); i++) - if (contents.GetAt(i) != ' ') { - break; - } - if (m_locTextLoc != BC_TEXT_LOC_NONE && i < contents.GetLength()) { - ShowChars(contents, nullptr, device, matrix, m_barWidth, m_multiple, e); - if (e != BCExceptionNO) - return; - } -} - -void CBC_OneDimWriter::RenderResult(const CFX_WideStringC& contents, - uint8_t* code, - int32_t codeLength, - bool isDevice, - int32_t& e) { - if (codeLength < 1) { - if (e != BCExceptionNO) - return; - } - if (m_ModuleHeight < 20.0) { - m_ModuleHeight = 20; - } - int32_t codeOldLength = codeLength; - int32_t leftPadding = 0; - int32_t rightPadding = 0; - if (m_bLeftPadding) { - leftPadding = 7; - } - if (m_bRightPadding) { - rightPadding = 7; - } - codeLength += leftPadding; - codeLength += rightPadding; - m_outputHScale = 1.0; - if (m_Width > 0) { - m_outputHScale = (float)m_Width / (float)codeLength; - } - if (!isDevice) { - m_outputHScale = - std::max(m_outputHScale, static_cast<float>(m_ModuleWidth)); - } - float dataLengthScale = 1.0; - if (m_iDataLenth > 0 && contents.GetLength() != 0) { - dataLengthScale = float(contents.GetLength()) / float(m_iDataLenth); - } - if (m_iDataLenth > 0 && contents.GetLength() == 0) { - dataLengthScale = float(1) / float(m_iDataLenth); - } - m_multiple = 1; - if (!isDevice) { - m_multiple = (int32_t)ceil(m_outputHScale * dataLengthScale); - } - int32_t outputHeight = 1; - if (!isDevice) { - if (m_Height == 0) { - outputHeight = std::max(20, m_ModuleHeight); - } else { - outputHeight = m_Height; - } - } - int32_t outputWidth = codeLength; - if (!isDevice) { - outputWidth = (int32_t)(codeLength * m_multiple / dataLengthScale); - } - m_barWidth = m_Width; - if (!isDevice) { - m_barWidth = codeLength * m_multiple; - } - m_output = pdfium::MakeUnique<CBC_CommonBitMatrix>(); - m_output->Init(outputWidth, outputHeight); - int32_t outputX = leftPadding * m_multiple; - for (int32_t inputX = 0; inputX < codeOldLength; inputX++) { - if (code[inputX] == 1) { - if (outputX >= outputWidth) { - break; - } - if (outputX + m_multiple > outputWidth && outputWidth - outputX > 0) { - m_output->SetRegion(outputX, 0, outputWidth - outputX, outputHeight, e); - break; - } - m_output->SetRegion(outputX, 0, m_multiple, outputHeight, e); - if (e != BCExceptionNO) - return; - } - outputX += m_multiple; - } -} - -bool CBC_OneDimWriter::CheckContentValidity(const CFX_WideStringC& contents) { - return true; -} - -CFX_WideString CBC_OneDimWriter::FilterContents( - const CFX_WideStringC& contents) { - return CFX_WideString(); -} - -CFX_WideString CBC_OneDimWriter::RenderTextContents( - const CFX_WideStringC& contents) { - return CFX_WideString(); -} diff --git a/xfa/fxbarcode/oned/BC_OneDimWriter.h b/xfa/fxbarcode/oned/BC_OneDimWriter.h deleted file mode 100644 index 4892889ddb..0000000000 --- a/xfa/fxbarcode/oned/BC_OneDimWriter.h +++ /dev/null @@ -1,118 +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_FXBARCODE_ONED_BC_ONEDIMWRITER_H_ -#define XFA_FXBARCODE_ONED_BC_ONEDIMWRITER_H_ - -#include <memory> - -#include "core/fxge/cfx_renderdevice.h" -#include "xfa/fxbarcode/BC_Library.h" -#include "xfa/fxbarcode/BC_Writer.h" - -class CBC_CommonBitMatrix; -class CFX_Font; -class CFX_RenderDevice; - -class CBC_OneDimWriter : public CBC_Writer { - public: - CBC_OneDimWriter(); - ~CBC_OneDimWriter() override; - - virtual uint8_t* Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e); - virtual uint8_t* Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e); - virtual uint8_t* Encode(const CFX_ByteString& contents, - int32_t& outLength, - int32_t& e); - - virtual void RenderResult(const CFX_WideStringC& contents, - uint8_t* code, - int32_t codeLength, - bool isDevice, - int32_t& e); - virtual void RenderBitmapResult(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - const CFX_WideStringC& contents, - int32_t& e); - virtual void RenderDeviceResult(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - const CFX_WideStringC& contents, - int32_t& e); - virtual bool CheckContentValidity(const CFX_WideStringC& contents); - virtual CFX_WideString FilterContents(const CFX_WideStringC& contents); - virtual CFX_WideString RenderTextContents(const CFX_WideStringC& contents); - virtual void SetPrintChecksum(bool checksum); - virtual void SetDataLength(int32_t length); - virtual void SetCalcChecksum(bool state); - virtual void SetFontSize(float size); - virtual void SetFontStyle(int32_t style); - virtual void SetFontColor(FX_ARGB color); - bool SetFont(CFX_Font* cFont); - - protected: - virtual void CalcTextInfo(const CFX_ByteString& text, - FXTEXT_CHARPOS* charPos, - CFX_Font* cFont, - float geWidth, - int32_t fontSize, - float& charsLen); - virtual void ShowChars(const CFX_WideStringC& contents, - const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t barWidth, - int32_t multiple, - int32_t& e); - virtual void ShowBitmapChars(const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - const CFX_ByteString str, - float geWidth, - FXTEXT_CHARPOS* pCharPos, - float locX, - float locY, - int32_t barWidth); - virtual void ShowDeviceChars(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - const CFX_ByteString str, - float geWidth, - FXTEXT_CHARPOS* pCharPos, - float locX, - float locY, - int32_t barWidth); - virtual int32_t AppendPattern(uint8_t* target, - int32_t pos, - const int32_t* pattern, - int32_t patternLength, - int32_t startColor, - int32_t& e); - - wchar_t Upper(wchar_t ch); - - bool m_bPrintChecksum; - int32_t m_iDataLenth; - bool m_bCalcChecksum; - CFX_Font* m_pFont; - float m_fFontSize; - int32_t m_iFontStyle; - uint32_t m_fontColor; - BC_TEXT_LOC m_locTextLoc; - int32_t m_iContentLen; - bool m_bLeftPadding; - bool m_bRightPadding; - std::unique_ptr<CBC_CommonBitMatrix> m_output; - int32_t m_barWidth; - int32_t m_multiple; - float m_outputHScale; -}; - -#endif // XFA_FXBARCODE_ONED_BC_ONEDIMWRITER_H_ diff --git a/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.cpp b/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.cpp deleted file mode 100644 index 7d51fa8f94..0000000000 --- a/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.cpp +++ /dev/null @@ -1,239 +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_Writer.h" -#include "xfa/fxbarcode/common/BC_CommonBitArray.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" -#include "xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h" - -namespace { - -const char ALPHABET_STRING[] = "0123456789-$:/.+ABCDTN"; - -const int32_t CHARACTER_ENCODINGS[22] = { - 0x003, 0x006, 0x009, 0x060, 0x012, 0x042, 0x021, 0x024, - 0x030, 0x048, 0x00c, 0x018, 0x045, 0x051, 0x054, 0x015, - 0x01A, 0x029, 0x00B, 0x00E, 0x01A, 0x029}; - -const char START_END_CHARS[] = {'A', 'B', 'C', 'D', 'T', 'N', '*', 'E', - 'a', 'b', 'c', 'd', 't', 'n', 'e'}; -const char CONTENT_CHARS[] = {'0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', '-', '$', '/', ':', '+', '.'}; - -} // namespace - -CBC_OnedCodaBarWriter::CBC_OnedCodaBarWriter() { - m_chStart = 'A'; - m_chEnd = 'B'; - m_iWideNarrRatio = 2; -} -CBC_OnedCodaBarWriter::~CBC_OnedCodaBarWriter() {} -bool CBC_OnedCodaBarWriter::SetStartChar(char start) { - for (size_t i = 0; i < FX_ArraySize(START_END_CHARS); ++i) { - if (START_END_CHARS[i] == start) { - m_chStart = start; - return true; - } - } - return false; -} - -bool CBC_OnedCodaBarWriter::SetEndChar(char end) { - for (size_t i = 0; i < FX_ArraySize(START_END_CHARS); ++i) { - if (START_END_CHARS[i] == end) { - m_chEnd = end; - return true; - } - } - return false; -} -void CBC_OnedCodaBarWriter::SetDataLength(int32_t length) { - m_iDataLenth = length + 2; -} -bool CBC_OnedCodaBarWriter::SetTextLocation(BC_TEXT_LOC location) { - if (location < BC_TEXT_LOC_NONE || location > BC_TEXT_LOC_BELOWEMBED) { - return false; - } - m_locTextLoc = location; - return true; -} -bool CBC_OnedCodaBarWriter::SetWideNarrowRatio(int32_t ratio) { - if (ratio < 2 || ratio > 3) { - return false; - } - m_iWideNarrRatio = ratio; - return true; -} -bool CBC_OnedCodaBarWriter::FindChar(wchar_t ch, bool isContent) { - if (isContent) { - for (size_t i = 0; i < FX_ArraySize(CONTENT_CHARS); ++i) { - if (ch == (wchar_t)CONTENT_CHARS[i]) { - return true; - } - } - for (size_t j = 0; j < FX_ArraySize(START_END_CHARS); ++j) { - if (ch == (wchar_t)START_END_CHARS[j]) { - return true; - } - } - return false; - } else { - for (size_t i = 0; i < FX_ArraySize(CONTENT_CHARS); ++i) { - if (ch == (wchar_t)CONTENT_CHARS[i]) { - return true; - } - } - return false; - } -} -bool CBC_OnedCodaBarWriter::CheckContentValidity( - const CFX_WideStringC& contents) { - wchar_t ch; - int32_t index = 0; - for (index = 0; index < contents.GetLength(); index++) { - ch = contents.GetAt(index); - if (FindChar(ch, false)) { - continue; - } else { - return false; - } - } - return true; -} -CFX_WideString CBC_OnedCodaBarWriter::FilterContents( - const CFX_WideStringC& contents) { - CFX_WideString filtercontents; - wchar_t ch; - for (int32_t index = 0; index < contents.GetLength(); index++) { - ch = contents.GetAt(index); - if (ch > 175) { - index++; - continue; - } - if (FindChar(ch, true)) { - filtercontents += ch; - } else { - continue; - } - } - return filtercontents; -} -uint8_t* CBC_OnedCodaBarWriter::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) { - uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); - if (e != BCExceptionNO) - return nullptr; - return ret; -} -uint8_t* CBC_OnedCodaBarWriter::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e) { - if (format != BCFORMAT_CODABAR) { - e = BCExceptionOnlyEncodeCODEBAR; - return nullptr; - } - uint8_t* ret = - CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e); - if (e != BCExceptionNO) - return nullptr; - return ret; -} -uint8_t* CBC_OnedCodaBarWriter::Encode(const CFX_ByteString& contents, - int32_t& outLength, - int32_t& e) { - CFX_ByteString data = m_chStart + contents + m_chEnd; - m_iContentLen = data.GetLength(); - uint8_t* result = FX_Alloc2D(uint8_t, m_iWideNarrRatio * 7, data.GetLength()); - char ch; - int32_t position = 0; - for (int32_t index = 0; index < data.GetLength(); index++) { - ch = data.GetAt(index); - if (((ch >= 'a') && (ch <= 'z'))) { - ch = ch - 32; - } - switch (ch) { - case 'T': - ch = 'A'; - break; - case 'N': - ch = 'B'; - break; - case '*': - ch = 'C'; - break; - case 'E': - ch = 'D'; - break; - default: - break; - } - int32_t code = 0; - int32_t len = (int32_t)strlen(ALPHABET_STRING); - for (int32_t i = 0; i < len; i++) { - if (ch == ALPHABET_STRING[i]) { - code = CHARACTER_ENCODINGS[i]; - break; - } - } - uint8_t color = 1; - int32_t counter = 0; - int32_t bit = 0; - while (bit < 7) { - result[position] = color; - position++; - if (((code >> (6 - bit)) & 1) == 0 || counter == m_iWideNarrRatio - 1) { - color = !color; - bit++; - counter = 0; - } else { - counter++; - } - } - if (index < data.GetLength() - 1) { - result[position] = 0; - position++; - } - } - outLength = position; - return result; -} -CFX_WideString CBC_OnedCodaBarWriter::encodedContents( - const CFX_WideStringC& contents) { - CFX_WideString strStart(m_chStart); - CFX_WideString strEnd(m_chEnd); - return strStart + contents + strEnd; -} -void CBC_OnedCodaBarWriter::RenderResult(const CFX_WideStringC& contents, - uint8_t* code, - int32_t codeLength, - bool isDevice, - int32_t& e) { - CBC_OneDimWriter::RenderResult(encodedContents(contents).AsStringC(), code, - codeLength, isDevice, e); -} diff --git a/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h b/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h deleted file mode 100644 index 0d01ad9242..0000000000 --- a/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h +++ /dev/null @@ -1,58 +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_FXBARCODE_ONED_BC_ONEDCODABARWRITER_H_ -#define XFA_FXBARCODE_ONED_BC_ONEDCODABARWRITER_H_ - -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "xfa/fxbarcode/BC_Library.h" -#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" - -class CBC_OnedCodaBarWriter : public CBC_OneDimWriter { - public: - CBC_OnedCodaBarWriter(); - ~CBC_OnedCodaBarWriter() override; - - // CBC_OneDimWriter - uint8_t* Encode(const CFX_ByteString& contents, - int32_t& outLength, - int32_t& e) override; - uint8_t* Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) override; - uint8_t* Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e) override; - bool CheckContentValidity(const CFX_WideStringC& contents) override; - CFX_WideString FilterContents(const CFX_WideStringC& contents) override; - void SetDataLength(int32_t length) override; - - virtual CFX_WideString encodedContents(const CFX_WideStringC& contents); - virtual bool SetStartChar(char start); - virtual bool SetEndChar(char end); - virtual bool SetTextLocation(BC_TEXT_LOC location); - virtual bool SetWideNarrowRatio(int32_t ratio); - virtual bool FindChar(wchar_t ch, bool isContent); - - private: - void RenderResult(const CFX_WideStringC& contents, - uint8_t* code, - int32_t codeLength, - bool isDevice, - int32_t& e) override; - - char m_chStart; - char m_chEnd; - int32_t m_iWideNarrRatio; -}; - -#endif // XFA_FXBARCODE_ONED_BC_ONEDCODABARWRITER_H_ diff --git a/xfa/fxbarcode/oned/BC_OnedCode128Writer.cpp b/xfa/fxbarcode/oned/BC_OnedCode128Writer.cpp deleted file mode 100644 index 7adbb1f55c..0000000000 --- a/xfa/fxbarcode/oned/BC_OnedCode128Writer.cpp +++ /dev/null @@ -1,276 +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 2010 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_Writer.h" -#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" -#include "xfa/fxbarcode/oned/BC_OnedCode128Writer.h" - -namespace { - -const int32_t CODE_PATTERNS[107][7] = { - {2, 1, 2, 2, 2, 2, 0}, {2, 2, 2, 1, 2, 2, 0}, {2, 2, 2, 2, 2, 1, 0}, - {1, 2, 1, 2, 2, 3, 0}, {1, 2, 1, 3, 2, 2, 0}, {1, 3, 1, 2, 2, 2, 0}, - {1, 2, 2, 2, 1, 3, 0}, {1, 2, 2, 3, 1, 2, 0}, {1, 3, 2, 2, 1, 2, 0}, - {2, 2, 1, 2, 1, 3, 0}, {2, 2, 1, 3, 1, 2, 0}, {2, 3, 1, 2, 1, 2, 0}, - {1, 1, 2, 2, 3, 2, 0}, {1, 2, 2, 1, 3, 2, 0}, {1, 2, 2, 2, 3, 1, 0}, - {1, 1, 3, 2, 2, 2, 0}, {1, 2, 3, 1, 2, 2, 0}, {1, 2, 3, 2, 2, 1, 0}, - {2, 2, 3, 2, 1, 1, 0}, {2, 2, 1, 1, 3, 2, 0}, {2, 2, 1, 2, 3, 1, 0}, - {2, 1, 3, 2, 1, 2, 0}, {2, 2, 3, 1, 1, 2, 0}, {3, 1, 2, 1, 3, 1, 0}, - {3, 1, 1, 2, 2, 2, 0}, {3, 2, 1, 1, 2, 2, 0}, {3, 2, 1, 2, 2, 1, 0}, - {3, 1, 2, 2, 1, 2, 0}, {3, 2, 2, 1, 1, 2, 0}, {3, 2, 2, 2, 1, 1, 0}, - {2, 1, 2, 1, 2, 3, 0}, {2, 1, 2, 3, 2, 1, 0}, {2, 3, 2, 1, 2, 1, 0}, - {1, 1, 1, 3, 2, 3, 0}, {1, 3, 1, 1, 2, 3, 0}, {1, 3, 1, 3, 2, 1, 0}, - {1, 1, 2, 3, 1, 3, 0}, {1, 3, 2, 1, 1, 3, 0}, {1, 3, 2, 3, 1, 1, 0}, - {2, 1, 1, 3, 1, 3, 0}, {2, 3, 1, 1, 1, 3, 0}, {2, 3, 1, 3, 1, 1, 0}, - {1, 1, 2, 1, 3, 3, 0}, {1, 1, 2, 3, 3, 1, 0}, {1, 3, 2, 1, 3, 1, 0}, - {1, 1, 3, 1, 2, 3, 0}, {1, 1, 3, 3, 2, 1, 0}, {1, 3, 3, 1, 2, 1, 0}, - {3, 1, 3, 1, 2, 1, 0}, {2, 1, 1, 3, 3, 1, 0}, {2, 3, 1, 1, 3, 1, 0}, - {2, 1, 3, 1, 1, 3, 0}, {2, 1, 3, 3, 1, 1, 0}, {2, 1, 3, 1, 3, 1, 0}, - {3, 1, 1, 1, 2, 3, 0}, {3, 1, 1, 3, 2, 1, 0}, {3, 3, 1, 1, 2, 1, 0}, - {3, 1, 2, 1, 1, 3, 0}, {3, 1, 2, 3, 1, 1, 0}, {3, 3, 2, 1, 1, 1, 0}, - {3, 1, 4, 1, 1, 1, 0}, {2, 2, 1, 4, 1, 1, 0}, {4, 3, 1, 1, 1, 1, 0}, - {1, 1, 1, 2, 2, 4, 0}, {1, 1, 1, 4, 2, 2, 0}, {1, 2, 1, 1, 2, 4, 0}, - {1, 2, 1, 4, 2, 1, 0}, {1, 4, 1, 1, 2, 2, 0}, {1, 4, 1, 2, 2, 1, 0}, - {1, 1, 2, 2, 1, 4, 0}, {1, 1, 2, 4, 1, 2, 0}, {1, 2, 2, 1, 1, 4, 0}, - {1, 2, 2, 4, 1, 1, 0}, {1, 4, 2, 1, 1, 2, 0}, {1, 4, 2, 2, 1, 1, 0}, - {2, 4, 1, 2, 1, 1, 0}, {2, 2, 1, 1, 1, 4, 0}, {4, 1, 3, 1, 1, 1, 0}, - {2, 4, 1, 1, 1, 2, 0}, {1, 3, 4, 1, 1, 1, 0}, {1, 1, 1, 2, 4, 2, 0}, - {1, 2, 1, 1, 4, 2, 0}, {1, 2, 1, 2, 4, 1, 0}, {1, 1, 4, 2, 1, 2, 0}, - {1, 2, 4, 1, 1, 2, 0}, {1, 2, 4, 2, 1, 1, 0}, {4, 1, 1, 2, 1, 2, 0}, - {4, 2, 1, 1, 1, 2, 0}, {4, 2, 1, 2, 1, 1, 0}, {2, 1, 2, 1, 4, 1, 0}, - {2, 1, 4, 1, 2, 1, 0}, {4, 1, 2, 1, 2, 1, 0}, {1, 1, 1, 1, 4, 3, 0}, - {1, 1, 1, 3, 4, 1, 0}, {1, 3, 1, 1, 4, 1, 0}, {1, 1, 4, 1, 1, 3, 0}, - {1, 1, 4, 3, 1, 1, 0}, {4, 1, 1, 1, 1, 3, 0}, {4, 1, 1, 3, 1, 1, 0}, - {1, 1, 3, 1, 4, 1, 0}, {1, 1, 4, 1, 3, 1, 0}, {3, 1, 1, 1, 4, 1, 0}, - {4, 1, 1, 1, 3, 1, 0}, {2, 1, 1, 4, 1, 2, 0}, {2, 1, 1, 2, 1, 4, 0}, - {2, 1, 1, 2, 3, 2, 0}, {2, 3, 3, 1, 1, 1, 2}}; - -const int32_t CODE_START_B = 104; -const int32_t CODE_START_C = 105; -const int32_t CODE_STOP = 106; - -} // namespace - -CBC_OnedCode128Writer::CBC_OnedCode128Writer() { - m_codeFormat = BC_CODE128_B; -} -CBC_OnedCode128Writer::CBC_OnedCode128Writer(BC_TYPE type) { - m_codeFormat = type; -} -CBC_OnedCode128Writer::~CBC_OnedCode128Writer() {} -BC_TYPE CBC_OnedCode128Writer::GetType() { - return m_codeFormat; -} -bool CBC_OnedCode128Writer::CheckContentValidity( - const CFX_WideStringC& contents) { - bool ret = true; - int32_t position = 0; - int32_t patternIndex = -1; - if (m_codeFormat == BC_CODE128_B || m_codeFormat == BC_CODE128_C) { - while (position < contents.GetLength()) { - patternIndex = (int32_t)contents.GetAt(position); - if (patternIndex < 32 || patternIndex > 126 || patternIndex == 34) { - ret = false; - break; - } - position++; - } - } else { - ret = false; - } - return ret; -} -CFX_WideString CBC_OnedCode128Writer::FilterContents( - const CFX_WideStringC& contents) { - CFX_WideString filterChineseChar; - wchar_t ch; - for (int32_t i = 0; i < contents.GetLength(); i++) { - ch = contents.GetAt(i); - if (ch > 175) { - i++; - continue; - } - filterChineseChar += ch; - } - CFX_WideString filtercontents; - if (m_codeFormat == BC_CODE128_B) { - for (int32_t i = 0; i < filterChineseChar.GetLength(); i++) { - ch = filterChineseChar.GetAt(i); - if (ch >= 32 && ch <= 126) { - filtercontents += ch; - } else { - continue; - } - } - } else if (m_codeFormat == BC_CODE128_C) { - for (int32_t i = 0; i < filterChineseChar.GetLength(); i++) { - ch = filterChineseChar.GetAt(i); - if (ch >= 32 && ch <= 106) { - filtercontents += ch; - } else { - continue; - } - } - } else { - filtercontents = contents; - } - return filtercontents; -} -bool CBC_OnedCode128Writer::SetTextLocation(BC_TEXT_LOC location) { - if (location < BC_TEXT_LOC_NONE || location > BC_TEXT_LOC_BELOWEMBED) { - return false; - } - m_locTextLoc = location; - return true; -} -uint8_t* CBC_OnedCode128Writer::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e) { - if (format != BCFORMAT_CODE_128) { - e = BCExceptionOnlyEncodeCODE_128; - return nullptr; - } - uint8_t* ret = - CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e); - if (e != BCExceptionNO) - return nullptr; - return ret; -} -uint8_t* CBC_OnedCode128Writer::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) { - uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); - if (e != BCExceptionNO) - return nullptr; - return ret; -} -bool CBC_OnedCode128Writer::IsDigits(const CFX_ByteString& contents, - int32_t start, - int32_t length) { - int32_t end = start + length; - for (int32_t i = start; i < end; i++) { - if (contents[i] < '0' || contents[i] > '9') { - return false; - } - } - return true; -} - -uint8_t* CBC_OnedCode128Writer::Encode(const CFX_ByteString& contents, - int32_t& outLength, - int32_t& e) { - if (contents.GetLength() < 1 || contents.GetLength() > 80) { - e = BCExceptionContentsLengthShouldBetween1and80; - return nullptr; - } - std::vector<const int32_t*> patterns; - int32_t checkSum = 0; - if (m_codeFormat == BC_CODE128_B) { - checkSum = Encode128B(contents, &patterns); - } else if (m_codeFormat == BC_CODE128_C) { - checkSum = Encode128C(contents, &patterns); - } else { - e = BCExceptionFormatException; - return nullptr; - } - checkSum %= 103; - patterns.push_back(CODE_PATTERNS[checkSum]); - patterns.push_back(CODE_PATTERNS[CODE_STOP]); - m_iContentLen = contents.GetLength() + 3; - int32_t codeWidth = 0; - for (size_t k = 0; k < patterns.size(); k++) { - const int32_t* pattern = patterns[k]; - for (size_t j = 0; j < 7; j++) { - codeWidth += pattern[j]; - } - } - outLength = codeWidth; - uint8_t* result = FX_Alloc(uint8_t, outLength); - int32_t pos = 0; - for (size_t j = 0; j < patterns.size(); j++) { - const int32_t* pattern = patterns[j]; - pos += AppendPattern(result, pos, pattern, 7, 1, e); - if (e != BCExceptionNO) { - FX_Free(result); - return nullptr; - } - } - return result; -} - -int32_t CBC_OnedCode128Writer::Encode128B( - const CFX_ByteString& contents, - std::vector<const int32_t*>* patterns) { - int32_t checkSum = 0; - int32_t checkWeight = 1; - int32_t position = 0; - patterns->push_back(CODE_PATTERNS[CODE_START_B]); - checkSum += CODE_START_B * checkWeight; - while (position < contents.GetLength()) { - int32_t patternIndex = 0; - patternIndex = contents[position] - ' '; - position += 1; - patterns->push_back(CODE_PATTERNS[patternIndex]); - checkSum += patternIndex * checkWeight; - if (position != 0) { - checkWeight++; - } - } - return checkSum; -} - -int32_t CBC_OnedCode128Writer::Encode128C( - const CFX_ByteString& contents, - std::vector<const int32_t*>* patterns) { - int32_t checkSum = 0; - int32_t checkWeight = 1; - int32_t position = 0; - patterns->push_back(CODE_PATTERNS[CODE_START_C]); - checkSum += CODE_START_C * checkWeight; - while (position < contents.GetLength()) { - int32_t patternIndex = 0; - char ch = contents.GetAt(position); - if (ch < '0' || ch > '9') { - patternIndex = (int32_t)ch; - position++; - } else { - patternIndex = FXSYS_atoi(contents.Mid(position, 2).c_str()); - if (contents.GetAt(position + 1) < '0' || - contents.GetAt(position + 1) > '9') { - position += 1; - } else { - position += 2; - } - } - patterns->push_back(CODE_PATTERNS[patternIndex]); - checkSum += patternIndex * checkWeight; - if (position != 0) { - checkWeight++; - } - } - return checkSum; -} diff --git a/xfa/fxbarcode/oned/BC_OnedCode128Writer.h b/xfa/fxbarcode/oned/BC_OnedCode128Writer.h deleted file mode 100644 index ff6e4d0fa5..0000000000 --- a/xfa/fxbarcode/oned/BC_OnedCode128Writer.h +++ /dev/null @@ -1,55 +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_FXBARCODE_ONED_BC_ONEDCODE128WRITER_H_ -#define XFA_FXBARCODE_ONED_BC_ONEDCODE128WRITER_H_ - -#include <vector> - -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" - -class CBC_OnedCode128Writer : public CBC_OneDimWriter { - public: - CBC_OnedCode128Writer(); - explicit CBC_OnedCode128Writer(BC_TYPE type); - ~CBC_OnedCode128Writer() override; - - // CBC_OneDimWriter - uint8_t* Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e) override; - uint8_t* Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) override; - uint8_t* Encode(const CFX_ByteString& contents, - int32_t& outLength, - int32_t& e) override; - - bool CheckContentValidity(const CFX_WideStringC& contents) override; - CFX_WideString FilterContents(const CFX_WideStringC& contents) override; - - bool SetTextLocation(BC_TEXT_LOC location); - - BC_TYPE GetType(); - - private: - bool IsDigits(const CFX_ByteString& contents, int32_t start, int32_t length); - int32_t Encode128B(const CFX_ByteString& contents, - std::vector<const int32_t*>* patterns); - int32_t Encode128C(const CFX_ByteString& contents, - std::vector<const int32_t*>* patterns); - - BC_TYPE m_codeFormat; -}; - -#endif // XFA_FXBARCODE_ONED_BC_ONEDCODE128WRITER_H_ diff --git a/xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp b/xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp deleted file mode 100644 index bd0607d3cd..0000000000 --- a/xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp +++ /dev/null @@ -1,284 +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 2010 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_Writer.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" -#include "xfa/fxbarcode/oned/BC_OnedCode39Writer.h" - -namespace { - -const char ALPHABET_STRING[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%"; - -const char CHECKSUM_STRING[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"; - -const int32_t CHARACTER_ENCODINGS[44] = { - 0x034, 0x121, 0x061, 0x160, 0x031, 0x130, 0x070, 0x025, 0x124, - 0x064, 0x109, 0x049, 0x148, 0x019, 0x118, 0x058, 0x00D, 0x10C, - 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}; - -} // namespace - -CBC_OnedCode39Writer::CBC_OnedCode39Writer() { - m_iWideNarrRatio = 3; -} -CBC_OnedCode39Writer::~CBC_OnedCode39Writer() {} -bool CBC_OnedCode39Writer::CheckContentValidity( - const CFX_WideStringC& contents) { - for (int32_t i = 0; i < contents.GetLength(); i++) { - wchar_t ch = contents.GetAt(i); - if ((ch >= (wchar_t)'0' && ch <= (wchar_t)'9') || - (ch >= (wchar_t)'A' && ch <= (wchar_t)'Z') || ch == (wchar_t)'-' || - ch == (wchar_t)'.' || ch == (wchar_t)' ' || ch == (wchar_t)'*' || - ch == (wchar_t)'$' || ch == (wchar_t)'/' || ch == (wchar_t)'+' || - ch == (wchar_t)'%') { - continue; - } - return false; - } - return true; -} - -CFX_WideString CBC_OnedCode39Writer::FilterContents( - const CFX_WideStringC& contents) { - CFX_WideString filtercontents; - for (int32_t i = 0; i < contents.GetLength(); i++) { - wchar_t ch = contents.GetAt(i); - if (ch == (wchar_t)'*' && (i == 0 || i == contents.GetLength() - 1)) { - continue; - } - if (ch > 175) { - i++; - continue; - } else { - ch = Upper(ch); - } - if ((ch >= (wchar_t)'0' && ch <= (wchar_t)'9') || - (ch >= (wchar_t)'A' && ch <= (wchar_t)'Z') || ch == (wchar_t)'-' || - ch == (wchar_t)'.' || ch == (wchar_t)' ' || ch == (wchar_t)'*' || - ch == (wchar_t)'$' || ch == (wchar_t)'/' || ch == (wchar_t)'+' || - ch == (wchar_t)'%') { - filtercontents += ch; - } - } - return filtercontents; -} - -CFX_WideString CBC_OnedCode39Writer::RenderTextContents( - const CFX_WideStringC& contents) { - CFX_WideString renderContents; - for (int32_t i = 0; i < contents.GetLength(); i++) { - wchar_t ch = contents.GetAt(i); - if (ch == (wchar_t)'*' && (i == 0 || i == contents.GetLength() - 1)) { - continue; - } - if (ch > 175) { - i++; - continue; - } - if ((ch >= (wchar_t)'0' && ch <= (wchar_t)'9') || - (ch >= (wchar_t)'A' && ch <= (wchar_t)'Z') || - (ch >= (wchar_t)'a' && ch <= (wchar_t)'z') || ch == (wchar_t)'-' || - ch == (wchar_t)'.' || ch == (wchar_t)' ' || ch == (wchar_t)'*' || - ch == (wchar_t)'$' || ch == (wchar_t)'/' || ch == (wchar_t)'+' || - ch == (wchar_t)'%') { - renderContents += ch; - } - } - return renderContents; -} - -bool CBC_OnedCode39Writer::SetTextLocation(BC_TEXT_LOC location) { - if (location < BC_TEXT_LOC_NONE || location > BC_TEXT_LOC_BELOWEMBED) { - return false; - } - m_locTextLoc = location; - return true; -} -bool CBC_OnedCode39Writer::SetWideNarrowRatio(int32_t ratio) { - if (ratio < 2 || ratio > 3) { - return false; - } - m_iWideNarrRatio = ratio; - return true; -} -uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) { - uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); - if (e != BCExceptionNO) - return nullptr; - return ret; -} -uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e) { - if (format != BCFORMAT_CODE_39) { - e = BCExceptionOnlyEncodeCODE_39; - return nullptr; - } - uint8_t* ret = - CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e); - if (e != BCExceptionNO) - return nullptr; - return ret; -} -void CBC_OnedCode39Writer::ToIntArray(int32_t a, int32_t* toReturn) { - for (int32_t i = 0; i < 9; i++) { - toReturn[i] = (a & (1 << i)) == 0 ? 1 : m_iWideNarrRatio; - } -} -char CBC_OnedCode39Writer::CalcCheckSum(const CFX_ByteString& contents, - int32_t& e) { - int32_t length = contents.GetLength(); - if (length > 80) { - e = BCExceptionContentsLengthShouldBetween1and80; - return '*'; - } - int32_t checksum = 0; - int32_t len = (int32_t)strlen(ALPHABET_STRING); - for (int32_t i = 0; i < contents.GetLength(); i++) { - int32_t j = 0; - for (; j < len; j++) { - if (ALPHABET_STRING[j] == contents[i]) { - if (contents[i] != '*') { - checksum += j; - break; - } else { - break; - } - } - } - if (j >= len) { - e = BCExceptionUnSupportedString; - return '*'; - } - } - checksum = checksum % 43; - return CHECKSUM_STRING[checksum]; -} -uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents, - int32_t& outlength, - int32_t& e) { - char checksum = CalcCheckSum(contents, e); - if (checksum == '*') { - return nullptr; - } - int32_t widths[9] = {0}; - int32_t wideStrideNum = 3; - int32_t narrStrideNum = 9 - wideStrideNum; - CFX_ByteString encodedContents = contents; - if (m_bCalcChecksum) { - encodedContents += checksum; - } - m_iContentLen = encodedContents.GetLength(); - int32_t codeWidth = (wideStrideNum * m_iWideNarrRatio + narrStrideNum) * 2 + - 1 + m_iContentLen; - int32_t len = (int32_t)strlen(ALPHABET_STRING); - for (int32_t j = 0; j < m_iContentLen; j++) { - for (int32_t i = 0; i < len; i++) { - if (ALPHABET_STRING[i] == encodedContents[j]) { - ToIntArray(CHARACTER_ENCODINGS[i], widths); - for (int32_t k = 0; k < 9; k++) { - codeWidth += widths[k]; - } - } - } - } - outlength = codeWidth; - uint8_t* result = FX_Alloc(uint8_t, codeWidth); - ToIntArray(CHARACTER_ENCODINGS[39], widths); - int32_t pos = AppendPattern(result, 0, widths, 9, 1, e); - if (e != BCExceptionNO) { - FX_Free(result); - return nullptr; - } - int32_t narrowWhite[] = {1}; - pos += AppendPattern(result, pos, narrowWhite, 1, 0, e); - if (e != BCExceptionNO) { - FX_Free(result); - return nullptr; - } - for (int32_t l = m_iContentLen - 1; l >= 0; l--) { - for (int32_t i = 0; i < len; i++) { - if (ALPHABET_STRING[i] == encodedContents[l]) { - ToIntArray(CHARACTER_ENCODINGS[i], widths); - pos += AppendPattern(result, pos, widths, 9, 1, e); - if (e != BCExceptionNO) { - FX_Free(result); - return nullptr; - } - } - } - pos += AppendPattern(result, pos, narrowWhite, 1, 0, e); - if (e != BCExceptionNO) { - FX_Free(result); - return nullptr; - } - } - ToIntArray(CHARACTER_ENCODINGS[39], widths); - pos += AppendPattern(result, pos, widths, 9, 1, e); - if (e != BCExceptionNO) { - FX_Free(result); - return nullptr; - } - for (int32_t i = 0; i < codeWidth / 2; i++) { - result[i] ^= result[codeWidth - 1 - i]; - result[codeWidth - 1 - i] ^= result[i]; - result[i] ^= result[codeWidth - 1 - i]; - } - return result; -} -CFX_WideString CBC_OnedCode39Writer::encodedContents( - const CFX_WideStringC& contents, - int32_t& e) { - CFX_WideString encodedContents(contents); - if (m_bCalcChecksum && m_bPrintChecksum) { - CFX_WideString checksumContent = FilterContents(contents); - CFX_ByteString str = checksumContent.UTF8Encode(); - char checksum; - checksum = CalcCheckSum(str, e); - if (e != BCExceptionNO) - return CFX_WideString(); - str += checksum; - encodedContents += checksum; - } - return encodedContents; -} -void CBC_OnedCode39Writer::RenderResult(const CFX_WideStringC& contents, - uint8_t* code, - int32_t codeLength, - bool isDevice, - int32_t& e) { - CFX_WideString encodedCon = encodedContents(contents, e); - if (e != BCExceptionNO) - return; - CBC_OneDimWriter::RenderResult(encodedCon.AsStringC(), code, codeLength, - isDevice, e); -} diff --git a/xfa/fxbarcode/oned/BC_OnedCode39Writer.h b/xfa/fxbarcode/oned/BC_OnedCode39Writer.h deleted file mode 100644 index 5f7c294c2b..0000000000 --- a/xfa/fxbarcode/oned/BC_OnedCode39Writer.h +++ /dev/null @@ -1,54 +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_FXBARCODE_ONED_BC_ONEDCODE39WRITER_H_ -#define XFA_FXBARCODE_ONED_BC_ONEDCODE39WRITER_H_ - -#include "xfa/fxbarcode/BC_Library.h" -#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" - -class CBC_OnedCode39Writer : public CBC_OneDimWriter { - public: - CBC_OnedCode39Writer(); - ~CBC_OnedCode39Writer() override; - - // CBC_OneDimWriter - uint8_t* Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) override; - uint8_t* Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e) override; - uint8_t* Encode(const CFX_ByteString& contents, - int32_t& outLength, - int32_t& e) override; - void RenderResult(const CFX_WideStringC& contents, - uint8_t* code, - int32_t codeLength, - bool isDevice, - int32_t& e) override; - bool CheckContentValidity(const CFX_WideStringC& contents) override; - CFX_WideString FilterContents(const CFX_WideStringC& contents) override; - CFX_WideString RenderTextContents(const CFX_WideStringC& contents) override; - - virtual CFX_WideString encodedContents(const CFX_WideStringC& contents, - int32_t& e); - virtual bool SetTextLocation(BC_TEXT_LOC loction); - virtual bool SetWideNarrowRatio(int32_t ratio); - - private: - void ToIntArray(int32_t a, int32_t* toReturn); - char CalcCheckSum(const CFX_ByteString& contents, int32_t& e); - - int32_t m_iWideNarrRatio; -}; - -#endif // XFA_FXBARCODE_ONED_BC_ONEDCODE39WRITER_H_ diff --git a/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp deleted file mode 100644 index dcea777089..0000000000 --- a/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp +++ /dev/null @@ -1,306 +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 2009 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 "core/fxge/cfx_fxgedevice.h" -#include "core/fxge/cfx_gemodule.h" -#include "xfa/fxbarcode/BC_Writer.h" -#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" -#include "xfa/fxbarcode/oned/BC_OnedEAN13Writer.h" - -namespace { - -const int32_t FIRST_DIGIT_ENCODINGS[10] = {0x00, 0x0B, 0x0D, 0xE, 0x13, - 0x19, 0x1C, 0x15, 0x16, 0x1A}; -const int32_t START_END_PATTERN[3] = {1, 1, 1}; -const int32_t MIDDLE_PATTERN[5] = {1, 1, 1, 1, 1}; -const int32_t L_PATTERNS[10][4] = { - {3, 2, 1, 1}, {2, 2, 2, 1}, {2, 1, 2, 2}, {1, 4, 1, 1}, {1, 1, 3, 2}, - {1, 2, 3, 1}, {1, 1, 1, 4}, {1, 3, 1, 2}, {1, 2, 1, 3}, {3, 1, 1, 2}}; -const int32_t L_AND_G_PATTERNS[20][4] = { - {3, 2, 1, 1}, {2, 2, 2, 1}, {2, 1, 2, 2}, {1, 4, 1, 1}, {1, 1, 3, 2}, - {1, 2, 3, 1}, {1, 1, 1, 4}, {1, 3, 1, 2}, {1, 2, 1, 3}, {3, 1, 1, 2}, - {1, 1, 2, 3}, {1, 2, 2, 2}, {2, 2, 1, 2}, {1, 1, 4, 1}, {2, 3, 1, 1}, - {1, 3, 2, 1}, {4, 1, 1, 1}, {2, 1, 3, 1}, {3, 1, 2, 1}, {2, 1, 1, 3}}; - -} // namespace - -CBC_OnedEAN13Writer::CBC_OnedEAN13Writer() { - m_bLeftPadding = true; - m_codeWidth = 3 + (7 * 6) + 5 + (7 * 6) + 3; -} -CBC_OnedEAN13Writer::~CBC_OnedEAN13Writer() {} -bool CBC_OnedEAN13Writer::CheckContentValidity( - const CFX_WideStringC& contents) { - for (int32_t i = 0; i < contents.GetLength(); i++) { - if (contents.GetAt(i) >= '0' && contents.GetAt(i) <= '9') { - continue; - } else { - return false; - } - } - return true; -} -CFX_WideString CBC_OnedEAN13Writer::FilterContents( - const CFX_WideStringC& contents) { - CFX_WideString filtercontents; - wchar_t ch; - for (int32_t i = 0; i < contents.GetLength(); i++) { - ch = contents.GetAt(i); - if (ch > 175) { - i++; - continue; - } - if (ch >= '0' && ch <= '9') { - filtercontents += ch; - } - } - return filtercontents; -} -int32_t CBC_OnedEAN13Writer::CalcChecksum(const CFX_ByteString& contents) { - int32_t odd = 0; - int32_t even = 0; - int32_t j = 1; - for (int32_t i = contents.GetLength() - 1; i >= 0; i--) { - if (j % 2) { - odd += FXSYS_atoi(contents.Mid(i, 1).c_str()); - } else { - even += FXSYS_atoi(contents.Mid(i, 1).c_str()); - } - j++; - } - int32_t checksum = (odd * 3 + even) % 10; - checksum = (10 - checksum) % 10; - return (checksum); -} -uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) { - uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); - if (e != BCExceptionNO) - return nullptr; - return ret; -} -uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e) { - if (format != BCFORMAT_EAN_13) { - e = BCExceptionOnlyEncodeEAN_13; - } - uint8_t* ret = - CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e); - if (e != BCExceptionNO) - return nullptr; - return ret; -} -uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents, - int32_t& outLength, - int32_t& e) { - if (contents.GetLength() != 13) { - e = BCExceptionDigitLengthShould13; - return nullptr; - } - m_iDataLenth = 13; - int32_t firstDigit = FXSYS_atoi(contents.Mid(0, 1).c_str()); - int32_t parities = FIRST_DIGIT_ENCODINGS[firstDigit]; - outLength = m_codeWidth; - uint8_t* result = FX_Alloc(uint8_t, m_codeWidth); - int32_t pos = 0; - pos += AppendPattern(result, pos, START_END_PATTERN, 3, 1, e); - if (e != BCExceptionNO) { - FX_Free(result); - return nullptr; - } - int32_t i = 0; - for (i = 1; i <= 6; i++) { - int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str()); - if ((parities >> (6 - i) & 1) == 1) { - digit += 10; - } - pos += AppendPattern(result, pos, L_AND_G_PATTERNS[digit], 4, 0, e); - if (e != BCExceptionNO) { - FX_Free(result); - return nullptr; - } - } - pos += AppendPattern(result, pos, MIDDLE_PATTERN, 5, 0, e); - if (e != BCExceptionNO) { - FX_Free(result); - return nullptr; - } - for (i = 7; i <= 12; i++) { - int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str()); - pos += AppendPattern(result, pos, L_PATTERNS[digit], 4, 1, e); - if (e != BCExceptionNO) { - FX_Free(result); - return nullptr; - } - } - pos += AppendPattern(result, pos, START_END_PATTERN, 3, 1, e); - if (e != BCExceptionNO) { - FX_Free(result); - return nullptr; - } - return result; -} - -void CBC_OnedEAN13Writer::ShowChars( - const CFX_WideStringC& contents, - const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t barWidth, - int32_t multiple, - int32_t& e) { - if (!device && !pOutBitmap) { - e = BCExceptionIllegalArgument; - return; - } - int32_t leftPadding = 7 * multiple; - int32_t leftPosition = 3 * multiple + leftPadding; - CFX_ByteString str = FX_UTF8Encode(contents); - int32_t iLen = str.GetLength(); - FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLen); - FXSYS_memset(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLen); - CFX_FxgeDevice geBitmap; - if (pOutBitmap) - geBitmap.Attach(pOutBitmap, false, nullptr, false); - - int32_t iFontSize = (int32_t)fabs(m_fFontSize); - int32_t iTextHeight = iFontSize + 1; - CFX_ByteString tempStr = str.Mid(1, 6); - int32_t strWidth = multiple * 42; - if (!pOutBitmap) { - CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); - CFX_FloatRect rect((float)leftPosition, (float)(m_Height - iTextHeight), - (float)(leftPosition + strWidth - 0.5), (float)m_Height); - matr.Concat(*matrix); - matr.TransformRect(rect); - FX_RECT re = rect.GetOuterRect(); - device->FillRect(&re, m_backgroundColor); - CFX_FloatRect rect1((float)(leftPosition + 47 * multiple), - (float)(m_Height - iTextHeight), - (float)(leftPosition + 47 * multiple + strWidth - 0.5), - (float)m_Height); - CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); - matr1.Concat(*matrix); - matr1.TransformRect(rect1); - re = rect1.GetOuterRect(); - device->FillRect(&re, m_backgroundColor); - int32_t strWidth1 = multiple * 7; - CFX_Matrix matr2(m_outputHScale, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f); - CFX_FloatRect rect2(0.0f, (float)(m_Height - iTextHeight), - (float)strWidth1 - 0.5f, (float)m_Height); - matr2.Concat(*matrix); - matr2.TransformRect(rect2); - re = rect2.GetOuterRect(); - device->FillRect(&re, m_backgroundColor); - } - float blank = 0.0; - iLen = tempStr.GetLength(); - if (!pOutBitmap) { - strWidth = (int32_t)(strWidth * m_outputHScale); - } - CalcTextInfo(tempStr, pCharPos + 1, m_pFont, (float)strWidth, iFontSize, - blank); - CFX_Matrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (float)iFontSize); - CFX_FxgeDevice ge; - if (pOutBitmap) { - ge.Create(strWidth, iTextHeight, FXDIB_Argb, nullptr); - FX_RECT rect(0, 0, strWidth, iTextHeight); - ge.FillRect(&rect, m_backgroundColor); - ge.DrawNormalText(iLen, pCharPos + 1, m_pFont, - static_cast<float>(iFontSize), &affine_matrix, - m_fontColor, FXTEXT_CLEARTYPE); - geBitmap.SetDIBits(ge.GetBitmap(), leftPosition, m_Height - iTextHeight); - } else { - CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, - (float)leftPosition * m_outputHScale, - (float)(m_Height - iTextHeight) + iFontSize); - if (matrix) { - affine_matrix1.Concat(*matrix); - } - device->DrawNormalText(iLen, pCharPos + 1, m_pFont, - static_cast<float>(iFontSize), &affine_matrix1, - m_fontColor, FXTEXT_CLEARTYPE); - } - tempStr = str.Mid(7, 6); - iLen = tempStr.GetLength(); - CalcTextInfo(tempStr, pCharPos + 7, m_pFont, (float)strWidth, iFontSize, - blank); - if (pOutBitmap) { - FX_RECT rect1(0, 0, strWidth, iTextHeight); - ge.FillRect(&rect1, m_backgroundColor); - ge.DrawNormalText(iLen, pCharPos + 7, m_pFont, - static_cast<float>(iFontSize), &affine_matrix, - m_fontColor, FXTEXT_CLEARTYPE); - geBitmap.SetDIBits(ge.GetBitmap(), leftPosition + 47 * multiple, - m_Height - iTextHeight); - } else { - CFX_Matrix affine_matrix1( - 1.0, 0.0, 0.0, -1.0, - (float)(leftPosition + 47 * multiple) * m_outputHScale, - (float)(m_Height - iTextHeight + iFontSize)); - if (matrix) { - affine_matrix1.Concat(*matrix); - } - device->DrawNormalText(iLen, pCharPos + 7, m_pFont, - static_cast<float>(iFontSize), &affine_matrix1, - m_fontColor, FXTEXT_CLEARTYPE); - } - tempStr = str.Mid(0, 1); - iLen = tempStr.GetLength(); - strWidth = multiple * 7; - if (!pOutBitmap) - strWidth = (int32_t)(strWidth * m_outputHScale); - - CalcTextInfo(tempStr, pCharPos, m_pFont, (float)strWidth, iFontSize, blank); - if (pOutBitmap) { - ge.Create(strWidth, iTextHeight, FXDIB_Argb, nullptr); - ge.GetBitmap()->Clear(m_backgroundColor); - ge.DrawNormalText(iLen, pCharPos, m_pFont, static_cast<float>(iFontSize), - &affine_matrix, m_fontColor, FXTEXT_CLEARTYPE); - geBitmap.SetDIBits(ge.GetBitmap(), 0, m_Height - iTextHeight); - } else { - CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, 0.0, - (float)(m_Height - iTextHeight + iFontSize)); - if (matrix) { - affine_matrix1.Concat(*matrix); - } - device->DrawNormalText(iLen, pCharPos, m_pFont, - static_cast<float>(iFontSize), &affine_matrix1, - m_fontColor, FXTEXT_CLEARTYPE); - } - FX_Free(pCharPos); -} - -void CBC_OnedEAN13Writer::RenderResult(const CFX_WideStringC& contents, - uint8_t* code, - int32_t codeLength, - bool isDevice, - int32_t& e) { - CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e); -} diff --git a/xfa/fxbarcode/oned/BC_OnedEAN13Writer.h b/xfa/fxbarcode/oned/BC_OnedEAN13Writer.h deleted file mode 100644 index 8336259568..0000000000 --- a/xfa/fxbarcode/oned/BC_OnedEAN13Writer.h +++ /dev/null @@ -1,60 +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_FXBARCODE_ONED_BC_ONEDEAN13WRITER_H_ -#define XFA_FXBARCODE_ONED_BC_ONEDEAN13WRITER_H_ - -#include "core/fxcrt/fx_string.h" -#include "core/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(); - ~CBC_OnedEAN13Writer() override; - - // CBC_OneDimWriter - uint8_t* Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) override; - uint8_t* Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e) override; - uint8_t* Encode(const CFX_ByteString& contents, - int32_t& outLength, - int32_t& e) override; - void RenderResult(const CFX_WideStringC& contents, - uint8_t* code, - int32_t codeLength, - bool isDevice, - int32_t& e) override; - bool CheckContentValidity(const CFX_WideStringC& contents) override; - CFX_WideString FilterContents(const CFX_WideStringC& contents) override; - - int32_t CalcChecksum(const CFX_ByteString& contents); - - protected: - void ShowChars(const CFX_WideStringC& contents, - const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t barWidth, - int32_t multiple, - int32_t& e) override; - - private: - int32_t m_codeWidth; -}; - -#endif // XFA_FXBARCODE_ONED_BC_ONEDEAN13WRITER_H_ diff --git a/xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp deleted file mode 100644 index a7fa30c811..0000000000 --- a/xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp +++ /dev/null @@ -1,268 +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 2009 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 "core/fxge/cfx_fxgedevice.h" -#include "core/fxge/cfx_gemodule.h" -#include "xfa/fxbarcode/BC_Writer.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" -#include "xfa/fxbarcode/oned/BC_OnedEAN8Writer.h" - -namespace { - -const int32_t START_END_PATTERN[3] = {1, 1, 1}; -const int32_t MIDDLE_PATTERN[5] = {1, 1, 1, 1, 1}; -const int32_t L_PATTERNS[10][4] = { - {3, 2, 1, 1}, {2, 2, 2, 1}, {2, 1, 2, 2}, {1, 4, 1, 1}, {1, 1, 3, 2}, - {1, 2, 3, 1}, {1, 1, 1, 4}, {1, 3, 1, 2}, {1, 2, 1, 3}, {3, 1, 1, 2}}; - -} // namespace - -CBC_OnedEAN8Writer::CBC_OnedEAN8Writer() { - m_iDataLenth = 8; - m_codeWidth = 3 + (7 * 4) + 5 + (7 * 4) + 3; -} -CBC_OnedEAN8Writer::~CBC_OnedEAN8Writer() {} -void CBC_OnedEAN8Writer::SetDataLength(int32_t length) { - m_iDataLenth = 8; -} -bool CBC_OnedEAN8Writer::SetTextLocation(BC_TEXT_LOC location) { - if (location == BC_TEXT_LOC_BELOWEMBED) { - m_locTextLoc = location; - return true; - } - return false; -} -bool CBC_OnedEAN8Writer::CheckContentValidity(const CFX_WideStringC& contents) { - for (int32_t i = 0; i < contents.GetLength(); i++) { - if (contents.GetAt(i) >= '0' && contents.GetAt(i) <= '9') { - continue; - } else { - return false; - } - } - return true; -} -CFX_WideString CBC_OnedEAN8Writer::FilterContents( - const CFX_WideStringC& contents) { - CFX_WideString filtercontents; - wchar_t ch; - for (int32_t i = 0; i < contents.GetLength(); i++) { - ch = contents.GetAt(i); - if (ch > 175) { - i++; - continue; - } - if (ch >= '0' && ch <= '9') { - filtercontents += ch; - } - } - return filtercontents; -} -int32_t CBC_OnedEAN8Writer::CalcChecksum(const CFX_ByteString& contents) { - int32_t odd = 0; - int32_t even = 0; - int32_t j = 1; - for (int32_t i = contents.GetLength() - 1; i >= 0; i--) { - if (j % 2) { - odd += FXSYS_atoi(contents.Mid(i, 1).c_str()); - } else { - even += FXSYS_atoi(contents.Mid(i, 1).c_str()); - } - j++; - } - int32_t checksum = (odd * 3 + even) % 10; - checksum = (10 - checksum) % 10; - return (checksum); -} -uint8_t* CBC_OnedEAN8Writer::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) { - uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); - if (e != BCExceptionNO) - return nullptr; - return ret; -} -uint8_t* CBC_OnedEAN8Writer::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e) { - if (format != BCFORMAT_EAN_8) { - e = BCExceptionOnlyEncodeEAN_8; - return nullptr; - } - uint8_t* ret = - CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e); - if (e != BCExceptionNO) - return nullptr; - return ret; -} -uint8_t* CBC_OnedEAN8Writer::Encode(const CFX_ByteString& contents, - int32_t& outLength, - int32_t& e) { - if (contents.GetLength() != 8) { - e = BCExceptionDigitLengthMustBe8; - return nullptr; - } - outLength = m_codeWidth; - uint8_t* result = FX_Alloc(uint8_t, m_codeWidth); - int32_t pos = 0; - pos += AppendPattern(result, pos, START_END_PATTERN, 3, 1, e); - if (e != BCExceptionNO) { - FX_Free(result); - return nullptr; - } - int32_t i = 0; - for (i = 0; i <= 3; i++) { - int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str()); - pos += AppendPattern(result, pos, L_PATTERNS[digit], 4, 0, e); - if (e != BCExceptionNO) { - FX_Free(result); - return nullptr; - } - } - pos += AppendPattern(result, pos, MIDDLE_PATTERN, 5, 0, e); - if (e != BCExceptionNO) { - FX_Free(result); - return nullptr; - } - for (i = 4; i <= 7; i++) { - int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str()); - pos += AppendPattern(result, pos, L_PATTERNS[digit], 4, 1, e); - if (e != BCExceptionNO) { - FX_Free(result); - return nullptr; - } - } - pos += AppendPattern(result, pos, START_END_PATTERN, 3, 1, e); - if (e != BCExceptionNO) { - FX_Free(result); - return nullptr; - } - return result; -} - -void CBC_OnedEAN8Writer::ShowChars( - const CFX_WideStringC& contents, - const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t barWidth, - int32_t multiple, - int32_t& e) { - if (!device && !pOutBitmap) { - e = BCExceptionIllegalArgument; - return; - } - - int32_t leftPosition = 3 * multiple; - CFX_ByteString str = FX_UTF8Encode(contents); - int32_t iLength = str.GetLength(); - FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLength); - FXSYS_memset(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLength); - CFX_ByteString tempStr = str.Mid(0, 4); - int32_t iLen = tempStr.GetLength(); - int32_t strWidth = 7 * multiple * 4; - float blank = 0.0; - CFX_FxgeDevice geBitmap; - if (pOutBitmap) - geBitmap.Attach(pOutBitmap, false, nullptr, false); - - int32_t iFontSize = (int32_t)fabs(m_fFontSize); - int32_t iTextHeight = iFontSize + 1; - if (!pOutBitmap) { - CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); - CFX_FloatRect rect((float)leftPosition, (float)(m_Height - iTextHeight), - (float)(leftPosition + strWidth - 0.5), (float)m_Height); - matr.Concat(*matrix); - matr.TransformRect(rect); - FX_RECT re = rect.GetOuterRect(); - device->FillRect(&re, m_backgroundColor); - CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); - CFX_FloatRect rect1((float)(leftPosition + 33 * multiple), - (float)(m_Height - iTextHeight), - (float)(leftPosition + 33 * multiple + strWidth - 0.5), - (float)m_Height); - matr1.Concat(*matrix); - matr1.TransformRect(rect1); - re = rect1.GetOuterRect(); - device->FillRect(&re, m_backgroundColor); - } - if (!pOutBitmap) - strWidth = (int32_t)(strWidth * m_outputHScale); - - CalcTextInfo(tempStr, pCharPos, m_pFont, (float)strWidth, iFontSize, blank); - CFX_Matrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (float)iFontSize); - CFX_FxgeDevice ge; - if (pOutBitmap) { - ge.Create(strWidth, iTextHeight, FXDIB_Argb, nullptr); - ge.GetBitmap()->Clear(m_backgroundColor); - ge.DrawNormalText(iLen, pCharPos, m_pFont, static_cast<float>(iFontSize), - &affine_matrix, m_fontColor, FXTEXT_CLEARTYPE); - geBitmap.SetDIBits(ge.GetBitmap(), leftPosition, m_Height - iTextHeight); - } else { - CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, - (float)leftPosition * m_outputHScale, - (float)(m_Height - iTextHeight + iFontSize)); - affine_matrix1.Concat(*matrix); - device->DrawNormalText(iLen, pCharPos, m_pFont, - static_cast<float>(iFontSize), &affine_matrix1, - m_fontColor, FXTEXT_CLEARTYPE); - } - tempStr = str.Mid(4, 4); - iLen = tempStr.GetLength(); - CalcTextInfo(tempStr, pCharPos + 4, m_pFont, (float)strWidth, iFontSize, - blank); - if (pOutBitmap) { - ge.Create(strWidth, iTextHeight, FXDIB_Argb, nullptr); - ge.GetBitmap()->Clear(m_backgroundColor); - ge.DrawNormalText(iLen, pCharPos + 4, m_pFont, - static_cast<float>(iFontSize), &affine_matrix, - m_fontColor, FXTEXT_CLEARTYPE); - geBitmap.SetDIBits(ge.GetBitmap(), leftPosition + 33 * multiple, - m_Height - iTextHeight); - } else { - CFX_Matrix affine_matrix1( - 1.0, 0.0, 0.0, -1.0, - (float)(leftPosition + 33 * multiple) * m_outputHScale, - (float)(m_Height - iTextHeight + iFontSize)); - if (matrix) { - affine_matrix1.Concat(*matrix); - } - device->DrawNormalText(iLen, pCharPos + 4, m_pFont, - static_cast<float>(iFontSize), &affine_matrix1, - m_fontColor, FXTEXT_CLEARTYPE); - } - FX_Free(pCharPos); -} - -void CBC_OnedEAN8Writer::RenderResult(const CFX_WideStringC& contents, - uint8_t* code, - int32_t codeLength, - bool isDevice, - int32_t& e) { - CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e); -} diff --git a/xfa/fxbarcode/oned/BC_OnedEAN8Writer.h b/xfa/fxbarcode/oned/BC_OnedEAN8Writer.h deleted file mode 100644 index b9921babc3..0000000000 --- a/xfa/fxbarcode/oned/BC_OnedEAN8Writer.h +++ /dev/null @@ -1,64 +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_FXBARCODE_ONED_BC_ONEDEAN8WRITER_H_ -#define XFA_FXBARCODE_ONED_BC_ONEDEAN8WRITER_H_ - -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "xfa/fxbarcode/BC_Library.h" -#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" - -class CFX_DIBitmap; -class CFX_RenderDevice; - -class CBC_OnedEAN8Writer : public CBC_OneDimWriter { - public: - CBC_OnedEAN8Writer(); - ~CBC_OnedEAN8Writer() override; - - // CBC_OneDimWriter - uint8_t* Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) override; - uint8_t* Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e) override; - uint8_t* Encode(const CFX_ByteString& contents, - int32_t& outLength, - int32_t& e) override; - - void RenderResult(const CFX_WideStringC& contents, - uint8_t* code, - int32_t codeLength, - bool isDevice, - int32_t& e) override; - bool CheckContentValidity(const CFX_WideStringC& contents) override; - CFX_WideString FilterContents(const CFX_WideStringC& contents) override; - void SetDataLength(int32_t length) override; - - bool SetTextLocation(BC_TEXT_LOC location); - int32_t CalcChecksum(const CFX_ByteString& contents); - - protected: - void ShowChars(const CFX_WideStringC& contents, - const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t barWidth, - int32_t multiple, - int32_t& e) override; - - private: - int32_t m_codeWidth; -}; - -#endif // XFA_FXBARCODE_ONED_BC_ONEDEAN8WRITER_H_ diff --git a/xfa/fxbarcode/oned/BC_OnedUPCAWriter.cpp b/xfa/fxbarcode/oned/BC_OnedUPCAWriter.cpp deleted file mode 100644 index 540e852d5d..0000000000 --- a/xfa/fxbarcode/oned/BC_OnedUPCAWriter.cpp +++ /dev/null @@ -1,286 +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 2010 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 "core/fxge/cfx_fxgedevice.h" -#include "core/fxge/cfx_gemodule.h" -#include "third_party/base/ptr_util.h" -#include "xfa/fxbarcode/BC_Writer.h" -#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" -#include "xfa/fxbarcode/oned/BC_OnedEAN13Writer.h" -#include "xfa/fxbarcode/oned/BC_OnedUPCAWriter.h" - -CBC_OnedUPCAWriter::CBC_OnedUPCAWriter() { - m_bLeftPadding = true; - m_bRightPadding = true; -} - -void CBC_OnedUPCAWriter::Init() { - m_subWriter = pdfium::MakeUnique<CBC_OnedEAN13Writer>(); -} - -CBC_OnedUPCAWriter::~CBC_OnedUPCAWriter() {} - -bool CBC_OnedUPCAWriter::CheckContentValidity(const CFX_WideStringC& contents) { - for (FX_STRSIZE i = 0; i < contents.GetLength(); ++i) { - if (contents.GetAt(i) < '0' || contents.GetAt(i) > '9') - return false; - } - return true; -} - -CFX_WideString CBC_OnedUPCAWriter::FilterContents( - const CFX_WideStringC& contents) { - CFX_WideString filtercontents; - wchar_t ch; - for (int32_t i = 0; i < contents.GetLength(); i++) { - ch = contents.GetAt(i); - if (ch > 175) { - i++; - continue; - } - if (ch >= '0' && ch <= '9') { - filtercontents += ch; - } - } - return filtercontents; -} - -int32_t CBC_OnedUPCAWriter::CalcChecksum(const CFX_ByteString& contents) { - int32_t odd = 0; - int32_t even = 0; - int32_t j = 1; - for (int32_t i = contents.GetLength() - 1; i >= 0; i--) { - if (j % 2) { - odd += FXSYS_atoi(contents.Mid(i, 1).c_str()); - } else { - even += FXSYS_atoi(contents.Mid(i, 1).c_str()); - } - j++; - } - int32_t checksum = (odd * 3 + even) % 10; - checksum = (10 - checksum) % 10; - return (checksum); -} - -uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) { - uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); - if (e != BCExceptionNO) - return nullptr; - return ret; -} - -uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e) { - if (format != BCFORMAT_UPC_A) { - e = BCExceptionOnlyEncodeUPC_A; - return nullptr; - } - CFX_ByteString toEAN13String = '0' + contents; - m_iDataLenth = 13; - uint8_t* ret = m_subWriter->Encode(toEAN13String, BCFORMAT_EAN_13, outWidth, - outHeight, hints, e); - if (e != BCExceptionNO) - return nullptr; - return ret; -} - -uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents, - int32_t& outLength, - int32_t& e) { - return nullptr; -} - -void CBC_OnedUPCAWriter::ShowChars( - const CFX_WideStringC& contents, - const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t barWidth, - int32_t multiple, - int32_t& e) { - if (!device && !pOutBitmap) { - e = BCExceptionIllegalArgument; - return; - } - - int32_t leftPadding = 7 * multiple; - int32_t leftPosition = 10 * multiple + leftPadding; - CFX_ByteString str = FX_UTF8Encode(contents); - int32_t iLen = str.GetLength(); - FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLen); - FXSYS_memset(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLen); - CFX_ByteString tempStr = str.Mid(1, 5); - float strWidth = (float)35 * multiple; - float blank = 0.0; - CFX_FxgeDevice geBitmap; - if (pOutBitmap) - geBitmap.Attach(pOutBitmap, false, nullptr, false); - - iLen = tempStr.GetLength(); - int32_t iFontSize = (int32_t)fabs(m_fFontSize); - int32_t iTextHeight = iFontSize + 1; - if (!pOutBitmap) { - CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); - CFX_FloatRect rect((float)leftPosition, (float)(m_Height - iTextHeight), - (float)(leftPosition + strWidth - 0.5), (float)m_Height); - matr.Concat(*matrix); - matr.TransformRect(rect); - FX_RECT re = rect.GetOuterRect(); - device->FillRect(&re, m_backgroundColor); - CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); - CFX_FloatRect rect1( - (float)(leftPosition + 40 * multiple), (float)(m_Height - iTextHeight), - (float)((leftPosition + 40 * multiple) + strWidth - 0.5), - (float)m_Height); - matr1.Concat(*matrix); - matr1.TransformRect(rect1); - re = rect1.GetOuterRect(); - device->FillRect(&re, m_backgroundColor); - float strWidth1 = (float)multiple * 7; - CFX_Matrix matr2(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); - CFX_FloatRect rect2(0.0, (float)(m_Height - iTextHeight), - (float)strWidth1 - 1, (float)m_Height); - matr2.Concat(*matrix); - matr2.TransformRect(rect2); - re = rect2.GetOuterRect(); - device->FillRect(&re, m_backgroundColor); - CFX_Matrix matr3(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); - CFX_FloatRect rect3( - (float)(leftPosition + 85 * multiple), (float)(m_Height - iTextHeight), - (float)((leftPosition + 85 * multiple) + strWidth1 - 0.5), - (float)m_Height); - matr3.Concat(*matrix); - matr3.TransformRect(rect3); - re = rect3.GetOuterRect(); - device->FillRect(&re, m_backgroundColor); - } - if (!pOutBitmap) - strWidth = strWidth * m_outputHScale; - - CalcTextInfo(tempStr, pCharPos + 1, m_pFont, strWidth, iFontSize, blank); - CFX_Matrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (float)iFontSize); - CFX_FxgeDevice ge; - if (pOutBitmap) { - ge.Create((int)strWidth, iTextHeight, FXDIB_Argb, nullptr); - ge.GetBitmap()->Clear(m_backgroundColor); - ge.DrawNormalText(iLen, pCharPos + 1, m_pFont, - static_cast<float>(iFontSize), &affine_matrix, - m_fontColor, FXTEXT_CLEARTYPE); - geBitmap.SetDIBits(ge.GetBitmap(), leftPosition, m_Height - iTextHeight); - } else { - CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, - (float)leftPosition * m_outputHScale, - (float)(m_Height - iTextHeight + iFontSize)); - if (matrix) { - affine_matrix1.Concat(*matrix); - } - device->DrawNormalText(iLen, pCharPos + 1, m_pFont, - static_cast<float>(iFontSize), &affine_matrix1, - m_fontColor, FXTEXT_CLEARTYPE); - } - tempStr = str.Mid(6, 5); - iLen = tempStr.GetLength(); - CalcTextInfo(tempStr, pCharPos + 6, m_pFont, strWidth, iFontSize, blank); - if (pOutBitmap) { - FX_RECT rect2(0, 0, (int)strWidth, iTextHeight); - ge.FillRect(&rect2, m_backgroundColor); - ge.DrawNormalText(iLen, pCharPos + 6, m_pFont, - static_cast<float>(iFontSize), &affine_matrix, - m_fontColor, FXTEXT_CLEARTYPE); - geBitmap.SetDIBits(ge.GetBitmap(), leftPosition + 40 * multiple, - m_Height - iTextHeight); - } else { - CFX_Matrix affine_matrix1( - 1.0, 0.0, 0.0, -1.0, - (float)(leftPosition + 40 * multiple) * m_outputHScale, - (float)(m_Height - iTextHeight + iFontSize)); - if (matrix) { - affine_matrix1.Concat(*matrix); - } - device->DrawNormalText(iLen, pCharPos + 6, m_pFont, - static_cast<float>(iFontSize), &affine_matrix1, - m_fontColor, FXTEXT_CLEARTYPE); - } - tempStr = str.Mid(0, 1); - iLen = tempStr.GetLength(); - strWidth = (float)multiple * 7; - if (!pOutBitmap) - strWidth = strWidth * m_outputHScale; - - CalcTextInfo(tempStr, pCharPos, m_pFont, strWidth, iFontSize, blank); - if (pOutBitmap) { - ge.Create((int)strWidth, iTextHeight, FXDIB_Argb, nullptr); - ge.GetBitmap()->Clear(m_backgroundColor); - ge.DrawNormalText(iLen, pCharPos, m_pFont, static_cast<float>(iFontSize), - &affine_matrix, m_fontColor, FXTEXT_CLEARTYPE); - geBitmap.SetDIBits(ge.GetBitmap(), 0, m_Height - iTextHeight); - } else { - CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, 0, - (float)(m_Height - iTextHeight + iFontSize)); - if (matrix) { - affine_matrix1.Concat(*matrix); - } - device->DrawNormalText(iLen, pCharPos, m_pFont, - static_cast<float>(iFontSize), &affine_matrix1, - m_fontColor, FXTEXT_CLEARTYPE); - } - tempStr = str.Mid(11, 1); - iLen = tempStr.GetLength(); - CalcTextInfo(tempStr, pCharPos + 11, m_pFont, strWidth, iFontSize, blank); - if (pOutBitmap) { - ge.Create((int)strWidth, iTextHeight, FXDIB_Argb, nullptr); - ge.GetBitmap()->Clear(m_backgroundColor); - ge.DrawNormalText(iLen, pCharPos + 11, m_pFont, - static_cast<float>(iFontSize), &affine_matrix, - m_fontColor, FXTEXT_CLEARTYPE); - geBitmap.SetDIBits(ge.GetBitmap(), leftPosition + 85 * multiple, - m_Height - iTextHeight); - } else { - CFX_Matrix affine_matrix1( - 1.0, 0.0, 0.0, -1.0, - (float)(leftPosition + 85 * multiple) * m_outputHScale, - (float)(m_Height - iTextHeight + iFontSize)); - if (matrix) { - affine_matrix1.Concat(*matrix); - } - device->DrawNormalText(iLen, pCharPos + 11, m_pFont, - static_cast<float>(iFontSize), &affine_matrix1, - m_fontColor, FXTEXT_CLEARTYPE); - } - FX_Free(pCharPos); -} - -void CBC_OnedUPCAWriter::RenderResult(const CFX_WideStringC& contents, - uint8_t* code, - int32_t codeLength, - bool isDevice, - int32_t& e) { - CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e); -} diff --git a/xfa/fxbarcode/oned/BC_OnedUPCAWriter.h b/xfa/fxbarcode/oned/BC_OnedUPCAWriter.h deleted file mode 100644 index 6c0929a051..0000000000 --- a/xfa/fxbarcode/oned/BC_OnedUPCAWriter.h +++ /dev/null @@ -1,66 +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_FXBARCODE_ONED_BC_ONEDUPCAWRITER_H_ -#define XFA_FXBARCODE_ONED_BC_ONEDUPCAWRITER_H_ - -#include <memory> - -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "xfa/fxbarcode/oned/BC_OneDimWriter.h" - -class CBC_OnedEAN13Writer; -class CFX_DIBitmap; -class CFX_Matrix; -class CFX_RenderDevice; - -class CBC_OnedUPCAWriter : public CBC_OneDimWriter { - public: - CBC_OnedUPCAWriter(); - ~CBC_OnedUPCAWriter() override; - - // CBC_OneDimWriter - uint8_t* Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) override; - uint8_t* Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e) override; - uint8_t* Encode(const CFX_ByteString& contents, - int32_t& outLength, - int32_t& e) override; - - void RenderResult(const CFX_WideStringC& contents, - uint8_t* code, - int32_t codeLength, - bool isDevice, - int32_t& e) override; - bool CheckContentValidity(const CFX_WideStringC& contents) override; - CFX_WideString FilterContents(const CFX_WideStringC& contents) override; - - void Init(); - int32_t CalcChecksum(const CFX_ByteString& contents); - - protected: - void ShowChars(const CFX_WideStringC& contents, - const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, - CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t barWidth, - int32_t multiple, - int32_t& e) override; - - private: - std::unique_ptr<CBC_OnedEAN13Writer> m_subWriter; -}; - -#endif // XFA_FXBARCODE_ONED_BC_ONEDUPCAWRITER_H_ diff --git a/xfa/fxbarcode/pdf417/BC_PDF417.cpp b/xfa/fxbarcode/pdf417/BC_PDF417.cpp deleted file mode 100644 index 0bc6680108..0000000000 --- a/xfa/fxbarcode/pdf417/BC_PDF417.cpp +++ /dev/null @@ -1,584 +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 2006 Jeremias Maerki in part, and ZXing Authors in part - * - * 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/pdf417/BC_PDF417.h" - -#include "third_party/base/ptr_util.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417BarcodeRow.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Compaction.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h" -#include "xfa/fxbarcode/utils.h" - -const int32_t CBC_PDF417::CODEWORD_TABLE[][929] = { - {0x1d5c0, 0x1eaf0, 0x1f57c, 0x1d4e0, 0x1ea78, 0x1f53e, 0x1a8c0, 0x1d470, - 0x1a860, 0x15040, 0x1a830, 0x15020, 0x1adc0, 0x1d6f0, 0x1eb7c, 0x1ace0, - 0x1d678, 0x1eb3e, 0x158c0, 0x1ac70, 0x15860, 0x15dc0, 0x1aef0, 0x1d77c, - 0x15ce0, 0x1ae78, 0x1d73e, 0x15c70, 0x1ae3c, 0x15ef0, 0x1af7c, 0x15e78, - 0x1af3e, 0x15f7c, 0x1f5fa, 0x1d2e0, 0x1e978, 0x1f4be, 0x1a4c0, 0x1d270, - 0x1e93c, 0x1a460, 0x1d238, 0x14840, 0x1a430, 0x1d21c, 0x14820, 0x1a418, - 0x14810, 0x1a6e0, 0x1d378, 0x1e9be, 0x14cc0, 0x1a670, 0x1d33c, 0x14c60, - 0x1a638, 0x1d31e, 0x14c30, 0x1a61c, 0x14ee0, 0x1a778, 0x1d3be, 0x14e70, - 0x1a73c, 0x14e38, 0x1a71e, 0x14f78, 0x1a7be, 0x14f3c, 0x14f1e, 0x1a2c0, - 0x1d170, 0x1e8bc, 0x1a260, 0x1d138, 0x1e89e, 0x14440, 0x1a230, 0x1d11c, - 0x14420, 0x1a218, 0x14410, 0x14408, 0x146c0, 0x1a370, 0x1d1bc, 0x14660, - 0x1a338, 0x1d19e, 0x14630, 0x1a31c, 0x14618, 0x1460c, 0x14770, 0x1a3bc, - 0x14738, 0x1a39e, 0x1471c, 0x147bc, 0x1a160, 0x1d0b8, 0x1e85e, 0x14240, - 0x1a130, 0x1d09c, 0x14220, 0x1a118, 0x1d08e, 0x14210, 0x1a10c, 0x14208, - 0x1a106, 0x14360, 0x1a1b8, 0x1d0de, 0x14330, 0x1a19c, 0x14318, 0x1a18e, - 0x1430c, 0x14306, 0x1a1de, 0x1438e, 0x14140, 0x1a0b0, 0x1d05c, 0x14120, - 0x1a098, 0x1d04e, 0x14110, 0x1a08c, 0x14108, 0x1a086, 0x14104, 0x141b0, - 0x14198, 0x1418c, 0x140a0, 0x1d02e, 0x1a04c, 0x1a046, 0x14082, 0x1cae0, - 0x1e578, 0x1f2be, 0x194c0, 0x1ca70, 0x1e53c, 0x19460, 0x1ca38, 0x1e51e, - 0x12840, 0x19430, 0x12820, 0x196e0, 0x1cb78, 0x1e5be, 0x12cc0, 0x19670, - 0x1cb3c, 0x12c60, 0x19638, 0x12c30, 0x12c18, 0x12ee0, 0x19778, 0x1cbbe, - 0x12e70, 0x1973c, 0x12e38, 0x12e1c, 0x12f78, 0x197be, 0x12f3c, 0x12fbe, - 0x1dac0, 0x1ed70, 0x1f6bc, 0x1da60, 0x1ed38, 0x1f69e, 0x1b440, 0x1da30, - 0x1ed1c, 0x1b420, 0x1da18, 0x1ed0e, 0x1b410, 0x1da0c, 0x192c0, 0x1c970, - 0x1e4bc, 0x1b6c0, 0x19260, 0x1c938, 0x1e49e, 0x1b660, 0x1db38, 0x1ed9e, - 0x16c40, 0x12420, 0x19218, 0x1c90e, 0x16c20, 0x1b618, 0x16c10, 0x126c0, - 0x19370, 0x1c9bc, 0x16ec0, 0x12660, 0x19338, 0x1c99e, 0x16e60, 0x1b738, - 0x1db9e, 0x16e30, 0x12618, 0x16e18, 0x12770, 0x193bc, 0x16f70, 0x12738, - 0x1939e, 0x16f38, 0x1b79e, 0x16f1c, 0x127bc, 0x16fbc, 0x1279e, 0x16f9e, - 0x1d960, 0x1ecb8, 0x1f65e, 0x1b240, 0x1d930, 0x1ec9c, 0x1b220, 0x1d918, - 0x1ec8e, 0x1b210, 0x1d90c, 0x1b208, 0x1b204, 0x19160, 0x1c8b8, 0x1e45e, - 0x1b360, 0x19130, 0x1c89c, 0x16640, 0x12220, 0x1d99c, 0x1c88e, 0x16620, - 0x12210, 0x1910c, 0x16610, 0x1b30c, 0x19106, 0x12204, 0x12360, 0x191b8, - 0x1c8de, 0x16760, 0x12330, 0x1919c, 0x16730, 0x1b39c, 0x1918e, 0x16718, - 0x1230c, 0x12306, 0x123b8, 0x191de, 0x167b8, 0x1239c, 0x1679c, 0x1238e, - 0x1678e, 0x167de, 0x1b140, 0x1d8b0, 0x1ec5c, 0x1b120, 0x1d898, 0x1ec4e, - 0x1b110, 0x1d88c, 0x1b108, 0x1d886, 0x1b104, 0x1b102, 0x12140, 0x190b0, - 0x1c85c, 0x16340, 0x12120, 0x19098, 0x1c84e, 0x16320, 0x1b198, 0x1d8ce, - 0x16310, 0x12108, 0x19086, 0x16308, 0x1b186, 0x16304, 0x121b0, 0x190dc, - 0x163b0, 0x12198, 0x190ce, 0x16398, 0x1b1ce, 0x1638c, 0x12186, 0x16386, - 0x163dc, 0x163ce, 0x1b0a0, 0x1d858, 0x1ec2e, 0x1b090, 0x1d84c, 0x1b088, - 0x1d846, 0x1b084, 0x1b082, 0x120a0, 0x19058, 0x1c82e, 0x161a0, 0x12090, - 0x1904c, 0x16190, 0x1b0cc, 0x19046, 0x16188, 0x12084, 0x16184, 0x12082, - 0x120d8, 0x161d8, 0x161cc, 0x161c6, 0x1d82c, 0x1d826, 0x1b042, 0x1902c, - 0x12048, 0x160c8, 0x160c4, 0x160c2, 0x18ac0, 0x1c570, 0x1e2bc, 0x18a60, - 0x1c538, 0x11440, 0x18a30, 0x1c51c, 0x11420, 0x18a18, 0x11410, 0x11408, - 0x116c0, 0x18b70, 0x1c5bc, 0x11660, 0x18b38, 0x1c59e, 0x11630, 0x18b1c, - 0x11618, 0x1160c, 0x11770, 0x18bbc, 0x11738, 0x18b9e, 0x1171c, 0x117bc, - 0x1179e, 0x1cd60, 0x1e6b8, 0x1f35e, 0x19a40, 0x1cd30, 0x1e69c, 0x19a20, - 0x1cd18, 0x1e68e, 0x19a10, 0x1cd0c, 0x19a08, 0x1cd06, 0x18960, 0x1c4b8, - 0x1e25e, 0x19b60, 0x18930, 0x1c49c, 0x13640, 0x11220, 0x1cd9c, 0x1c48e, - 0x13620, 0x19b18, 0x1890c, 0x13610, 0x11208, 0x13608, 0x11360, 0x189b8, - 0x1c4de, 0x13760, 0x11330, 0x1cdde, 0x13730, 0x19b9c, 0x1898e, 0x13718, - 0x1130c, 0x1370c, 0x113b8, 0x189de, 0x137b8, 0x1139c, 0x1379c, 0x1138e, - 0x113de, 0x137de, 0x1dd40, 0x1eeb0, 0x1f75c, 0x1dd20, 0x1ee98, 0x1f74e, - 0x1dd10, 0x1ee8c, 0x1dd08, 0x1ee86, 0x1dd04, 0x19940, 0x1ccb0, 0x1e65c, - 0x1bb40, 0x19920, 0x1eedc, 0x1e64e, 0x1bb20, 0x1dd98, 0x1eece, 0x1bb10, - 0x19908, 0x1cc86, 0x1bb08, 0x1dd86, 0x19902, 0x11140, 0x188b0, 0x1c45c, - 0x13340, 0x11120, 0x18898, 0x1c44e, 0x17740, 0x13320, 0x19998, 0x1ccce, - 0x17720, 0x1bb98, 0x1ddce, 0x18886, 0x17710, 0x13308, 0x19986, 0x17708, - 0x11102, 0x111b0, 0x188dc, 0x133b0, 0x11198, 0x188ce, 0x177b0, 0x13398, - 0x199ce, 0x17798, 0x1bbce, 0x11186, 0x13386, 0x111dc, 0x133dc, 0x111ce, - 0x177dc, 0x133ce, 0x1dca0, 0x1ee58, 0x1f72e, 0x1dc90, 0x1ee4c, 0x1dc88, - 0x1ee46, 0x1dc84, 0x1dc82, 0x198a0, 0x1cc58, 0x1e62e, 0x1b9a0, 0x19890, - 0x1ee6e, 0x1b990, 0x1dccc, 0x1cc46, 0x1b988, 0x19884, 0x1b984, 0x19882, - 0x1b982, 0x110a0, 0x18858, 0x1c42e, 0x131a0, 0x11090, 0x1884c, 0x173a0, - 0x13190, 0x198cc, 0x18846, 0x17390, 0x1b9cc, 0x11084, 0x17388, 0x13184, - 0x11082, 0x13182, 0x110d8, 0x1886e, 0x131d8, 0x110cc, 0x173d8, 0x131cc, - 0x110c6, 0x173cc, 0x131c6, 0x110ee, 0x173ee, 0x1dc50, 0x1ee2c, 0x1dc48, - 0x1ee26, 0x1dc44, 0x1dc42, 0x19850, 0x1cc2c, 0x1b8d0, 0x19848, 0x1cc26, - 0x1b8c8, 0x1dc66, 0x1b8c4, 0x19842, 0x1b8c2, 0x11050, 0x1882c, 0x130d0, - 0x11048, 0x18826, 0x171d0, 0x130c8, 0x19866, 0x171c8, 0x1b8e6, 0x11042, - 0x171c4, 0x130c2, 0x171c2, 0x130ec, 0x171ec, 0x171e6, 0x1ee16, 0x1dc22, - 0x1cc16, 0x19824, 0x19822, 0x11028, 0x13068, 0x170e8, 0x11022, 0x13062, - 0x18560, 0x10a40, 0x18530, 0x10a20, 0x18518, 0x1c28e, 0x10a10, 0x1850c, - 0x10a08, 0x18506, 0x10b60, 0x185b8, 0x1c2de, 0x10b30, 0x1859c, 0x10b18, - 0x1858e, 0x10b0c, 0x10b06, 0x10bb8, 0x185de, 0x10b9c, 0x10b8e, 0x10bde, - 0x18d40, 0x1c6b0, 0x1e35c, 0x18d20, 0x1c698, 0x18d10, 0x1c68c, 0x18d08, - 0x1c686, 0x18d04, 0x10940, 0x184b0, 0x1c25c, 0x11b40, 0x10920, 0x1c6dc, - 0x1c24e, 0x11b20, 0x18d98, 0x1c6ce, 0x11b10, 0x10908, 0x18486, 0x11b08, - 0x18d86, 0x10902, 0x109b0, 0x184dc, 0x11bb0, 0x10998, 0x184ce, 0x11b98, - 0x18dce, 0x11b8c, 0x10986, 0x109dc, 0x11bdc, 0x109ce, 0x11bce, 0x1cea0, - 0x1e758, 0x1f3ae, 0x1ce90, 0x1e74c, 0x1ce88, 0x1e746, 0x1ce84, 0x1ce82, - 0x18ca0, 0x1c658, 0x19da0, 0x18c90, 0x1c64c, 0x19d90, 0x1cecc, 0x1c646, - 0x19d88, 0x18c84, 0x19d84, 0x18c82, 0x19d82, 0x108a0, 0x18458, 0x119a0, - 0x10890, 0x1c66e, 0x13ba0, 0x11990, 0x18ccc, 0x18446, 0x13b90, 0x19dcc, - 0x10884, 0x13b88, 0x11984, 0x10882, 0x11982, 0x108d8, 0x1846e, 0x119d8, - 0x108cc, 0x13bd8, 0x119cc, 0x108c6, 0x13bcc, 0x119c6, 0x108ee, 0x119ee, - 0x13bee, 0x1ef50, 0x1f7ac, 0x1ef48, 0x1f7a6, 0x1ef44, 0x1ef42, 0x1ce50, - 0x1e72c, 0x1ded0, 0x1ef6c, 0x1e726, 0x1dec8, 0x1ef66, 0x1dec4, 0x1ce42, - 0x1dec2, 0x18c50, 0x1c62c, 0x19cd0, 0x18c48, 0x1c626, 0x1bdd0, 0x19cc8, - 0x1ce66, 0x1bdc8, 0x1dee6, 0x18c42, 0x1bdc4, 0x19cc2, 0x1bdc2, 0x10850, - 0x1842c, 0x118d0, 0x10848, 0x18426, 0x139d0, 0x118c8, 0x18c66, 0x17bd0, - 0x139c8, 0x19ce6, 0x10842, 0x17bc8, 0x1bde6, 0x118c2, 0x17bc4, 0x1086c, - 0x118ec, 0x10866, 0x139ec, 0x118e6, 0x17bec, 0x139e6, 0x17be6, 0x1ef28, - 0x1f796, 0x1ef24, 0x1ef22, 0x1ce28, 0x1e716, 0x1de68, 0x1ef36, 0x1de64, - 0x1ce22, 0x1de62, 0x18c28, 0x1c616, 0x19c68, 0x18c24, 0x1bce8, 0x19c64, - 0x18c22, 0x1bce4, 0x19c62, 0x1bce2, 0x10828, 0x18416, 0x11868, 0x18c36, - 0x138e8, 0x11864, 0x10822, 0x179e8, 0x138e4, 0x11862, 0x179e4, 0x138e2, - 0x179e2, 0x11876, 0x179f6, 0x1ef12, 0x1de34, 0x1de32, 0x19c34, 0x1bc74, - 0x1bc72, 0x11834, 0x13874, 0x178f4, 0x178f2, 0x10540, 0x10520, 0x18298, - 0x10510, 0x10508, 0x10504, 0x105b0, 0x10598, 0x1058c, 0x10586, 0x105dc, - 0x105ce, 0x186a0, 0x18690, 0x1c34c, 0x18688, 0x1c346, 0x18684, 0x18682, - 0x104a0, 0x18258, 0x10da0, 0x186d8, 0x1824c, 0x10d90, 0x186cc, 0x10d88, - 0x186c6, 0x10d84, 0x10482, 0x10d82, 0x104d8, 0x1826e, 0x10dd8, 0x186ee, - 0x10dcc, 0x104c6, 0x10dc6, 0x104ee, 0x10dee, 0x1c750, 0x1c748, 0x1c744, - 0x1c742, 0x18650, 0x18ed0, 0x1c76c, 0x1c326, 0x18ec8, 0x1c766, 0x18ec4, - 0x18642, 0x18ec2, 0x10450, 0x10cd0, 0x10448, 0x18226, 0x11dd0, 0x10cc8, - 0x10444, 0x11dc8, 0x10cc4, 0x10442, 0x11dc4, 0x10cc2, 0x1046c, 0x10cec, - 0x10466, 0x11dec, 0x10ce6, 0x11de6, 0x1e7a8, 0x1e7a4, 0x1e7a2, 0x1c728, - 0x1cf68, 0x1e7b6, 0x1cf64, 0x1c722, 0x1cf62, 0x18628, 0x1c316, 0x18e68, - 0x1c736, 0x19ee8, 0x18e64, 0x18622, 0x19ee4, 0x18e62, 0x19ee2, 0x10428, - 0x18216, 0x10c68, 0x18636, 0x11ce8, 0x10c64, 0x10422, 0x13de8, 0x11ce4, - 0x10c62, 0x13de4, 0x11ce2, 0x10436, 0x10c76, 0x11cf6, 0x13df6, 0x1f7d4, - 0x1f7d2, 0x1e794, 0x1efb4, 0x1e792, 0x1efb2, 0x1c714, 0x1cf34, 0x1c712, - 0x1df74, 0x1cf32, 0x1df72, 0x18614, 0x18e34, 0x18612, 0x19e74, 0x18e32, - 0x1bef4}, - {0x1f560, 0x1fab8, 0x1ea40, 0x1f530, 0x1fa9c, 0x1ea20, 0x1f518, 0x1fa8e, - 0x1ea10, 0x1f50c, 0x1ea08, 0x1f506, 0x1ea04, 0x1eb60, 0x1f5b8, 0x1fade, - 0x1d640, 0x1eb30, 0x1f59c, 0x1d620, 0x1eb18, 0x1f58e, 0x1d610, 0x1eb0c, - 0x1d608, 0x1eb06, 0x1d604, 0x1d760, 0x1ebb8, 0x1f5de, 0x1ae40, 0x1d730, - 0x1eb9c, 0x1ae20, 0x1d718, 0x1eb8e, 0x1ae10, 0x1d70c, 0x1ae08, 0x1d706, - 0x1ae04, 0x1af60, 0x1d7b8, 0x1ebde, 0x15e40, 0x1af30, 0x1d79c, 0x15e20, - 0x1af18, 0x1d78e, 0x15e10, 0x1af0c, 0x15e08, 0x1af06, 0x15f60, 0x1afb8, - 0x1d7de, 0x15f30, 0x1af9c, 0x15f18, 0x1af8e, 0x15f0c, 0x15fb8, 0x1afde, - 0x15f9c, 0x15f8e, 0x1e940, 0x1f4b0, 0x1fa5c, 0x1e920, 0x1f498, 0x1fa4e, - 0x1e910, 0x1f48c, 0x1e908, 0x1f486, 0x1e904, 0x1e902, 0x1d340, 0x1e9b0, - 0x1f4dc, 0x1d320, 0x1e998, 0x1f4ce, 0x1d310, 0x1e98c, 0x1d308, 0x1e986, - 0x1d304, 0x1d302, 0x1a740, 0x1d3b0, 0x1e9dc, 0x1a720, 0x1d398, 0x1e9ce, - 0x1a710, 0x1d38c, 0x1a708, 0x1d386, 0x1a704, 0x1a702, 0x14f40, 0x1a7b0, - 0x1d3dc, 0x14f20, 0x1a798, 0x1d3ce, 0x14f10, 0x1a78c, 0x14f08, 0x1a786, - 0x14f04, 0x14fb0, 0x1a7dc, 0x14f98, 0x1a7ce, 0x14f8c, 0x14f86, 0x14fdc, - 0x14fce, 0x1e8a0, 0x1f458, 0x1fa2e, 0x1e890, 0x1f44c, 0x1e888, 0x1f446, - 0x1e884, 0x1e882, 0x1d1a0, 0x1e8d8, 0x1f46e, 0x1d190, 0x1e8cc, 0x1d188, - 0x1e8c6, 0x1d184, 0x1d182, 0x1a3a0, 0x1d1d8, 0x1e8ee, 0x1a390, 0x1d1cc, - 0x1a388, 0x1d1c6, 0x1a384, 0x1a382, 0x147a0, 0x1a3d8, 0x1d1ee, 0x14790, - 0x1a3cc, 0x14788, 0x1a3c6, 0x14784, 0x14782, 0x147d8, 0x1a3ee, 0x147cc, - 0x147c6, 0x147ee, 0x1e850, 0x1f42c, 0x1e848, 0x1f426, 0x1e844, 0x1e842, - 0x1d0d0, 0x1e86c, 0x1d0c8, 0x1e866, 0x1d0c4, 0x1d0c2, 0x1a1d0, 0x1d0ec, - 0x1a1c8, 0x1d0e6, 0x1a1c4, 0x1a1c2, 0x143d0, 0x1a1ec, 0x143c8, 0x1a1e6, - 0x143c4, 0x143c2, 0x143ec, 0x143e6, 0x1e828, 0x1f416, 0x1e824, 0x1e822, - 0x1d068, 0x1e836, 0x1d064, 0x1d062, 0x1a0e8, 0x1d076, 0x1a0e4, 0x1a0e2, - 0x141e8, 0x1a0f6, 0x141e4, 0x141e2, 0x1e814, 0x1e812, 0x1d034, 0x1d032, - 0x1a074, 0x1a072, 0x1e540, 0x1f2b0, 0x1f95c, 0x1e520, 0x1f298, 0x1f94e, - 0x1e510, 0x1f28c, 0x1e508, 0x1f286, 0x1e504, 0x1e502, 0x1cb40, 0x1e5b0, - 0x1f2dc, 0x1cb20, 0x1e598, 0x1f2ce, 0x1cb10, 0x1e58c, 0x1cb08, 0x1e586, - 0x1cb04, 0x1cb02, 0x19740, 0x1cbb0, 0x1e5dc, 0x19720, 0x1cb98, 0x1e5ce, - 0x19710, 0x1cb8c, 0x19708, 0x1cb86, 0x19704, 0x19702, 0x12f40, 0x197b0, - 0x1cbdc, 0x12f20, 0x19798, 0x1cbce, 0x12f10, 0x1978c, 0x12f08, 0x19786, - 0x12f04, 0x12fb0, 0x197dc, 0x12f98, 0x197ce, 0x12f8c, 0x12f86, 0x12fdc, - 0x12fce, 0x1f6a0, 0x1fb58, 0x16bf0, 0x1f690, 0x1fb4c, 0x169f8, 0x1f688, - 0x1fb46, 0x168fc, 0x1f684, 0x1f682, 0x1e4a0, 0x1f258, 0x1f92e, 0x1eda0, - 0x1e490, 0x1fb6e, 0x1ed90, 0x1f6cc, 0x1f246, 0x1ed88, 0x1e484, 0x1ed84, - 0x1e482, 0x1ed82, 0x1c9a0, 0x1e4d8, 0x1f26e, 0x1dba0, 0x1c990, 0x1e4cc, - 0x1db90, 0x1edcc, 0x1e4c6, 0x1db88, 0x1c984, 0x1db84, 0x1c982, 0x1db82, - 0x193a0, 0x1c9d8, 0x1e4ee, 0x1b7a0, 0x19390, 0x1c9cc, 0x1b790, 0x1dbcc, - 0x1c9c6, 0x1b788, 0x19384, 0x1b784, 0x19382, 0x1b782, 0x127a0, 0x193d8, - 0x1c9ee, 0x16fa0, 0x12790, 0x193cc, 0x16f90, 0x1b7cc, 0x193c6, 0x16f88, - 0x12784, 0x16f84, 0x12782, 0x127d8, 0x193ee, 0x16fd8, 0x127cc, 0x16fcc, - 0x127c6, 0x16fc6, 0x127ee, 0x1f650, 0x1fb2c, 0x165f8, 0x1f648, 0x1fb26, - 0x164fc, 0x1f644, 0x1647e, 0x1f642, 0x1e450, 0x1f22c, 0x1ecd0, 0x1e448, - 0x1f226, 0x1ecc8, 0x1f666, 0x1ecc4, 0x1e442, 0x1ecc2, 0x1c8d0, 0x1e46c, - 0x1d9d0, 0x1c8c8, 0x1e466, 0x1d9c8, 0x1ece6, 0x1d9c4, 0x1c8c2, 0x1d9c2, - 0x191d0, 0x1c8ec, 0x1b3d0, 0x191c8, 0x1c8e6, 0x1b3c8, 0x1d9e6, 0x1b3c4, - 0x191c2, 0x1b3c2, 0x123d0, 0x191ec, 0x167d0, 0x123c8, 0x191e6, 0x167c8, - 0x1b3e6, 0x167c4, 0x123c2, 0x167c2, 0x123ec, 0x167ec, 0x123e6, 0x167e6, - 0x1f628, 0x1fb16, 0x162fc, 0x1f624, 0x1627e, 0x1f622, 0x1e428, 0x1f216, - 0x1ec68, 0x1f636, 0x1ec64, 0x1e422, 0x1ec62, 0x1c868, 0x1e436, 0x1d8e8, - 0x1c864, 0x1d8e4, 0x1c862, 0x1d8e2, 0x190e8, 0x1c876, 0x1b1e8, 0x1d8f6, - 0x1b1e4, 0x190e2, 0x1b1e2, 0x121e8, 0x190f6, 0x163e8, 0x121e4, 0x163e4, - 0x121e2, 0x163e2, 0x121f6, 0x163f6, 0x1f614, 0x1617e, 0x1f612, 0x1e414, - 0x1ec34, 0x1e412, 0x1ec32, 0x1c834, 0x1d874, 0x1c832, 0x1d872, 0x19074, - 0x1b0f4, 0x19072, 0x1b0f2, 0x120f4, 0x161f4, 0x120f2, 0x161f2, 0x1f60a, - 0x1e40a, 0x1ec1a, 0x1c81a, 0x1d83a, 0x1903a, 0x1b07a, 0x1e2a0, 0x1f158, - 0x1f8ae, 0x1e290, 0x1f14c, 0x1e288, 0x1f146, 0x1e284, 0x1e282, 0x1c5a0, - 0x1e2d8, 0x1f16e, 0x1c590, 0x1e2cc, 0x1c588, 0x1e2c6, 0x1c584, 0x1c582, - 0x18ba0, 0x1c5d8, 0x1e2ee, 0x18b90, 0x1c5cc, 0x18b88, 0x1c5c6, 0x18b84, - 0x18b82, 0x117a0, 0x18bd8, 0x1c5ee, 0x11790, 0x18bcc, 0x11788, 0x18bc6, - 0x11784, 0x11782, 0x117d8, 0x18bee, 0x117cc, 0x117c6, 0x117ee, 0x1f350, - 0x1f9ac, 0x135f8, 0x1f348, 0x1f9a6, 0x134fc, 0x1f344, 0x1347e, 0x1f342, - 0x1e250, 0x1f12c, 0x1e6d0, 0x1e248, 0x1f126, 0x1e6c8, 0x1f366, 0x1e6c4, - 0x1e242, 0x1e6c2, 0x1c4d0, 0x1e26c, 0x1cdd0, 0x1c4c8, 0x1e266, 0x1cdc8, - 0x1e6e6, 0x1cdc4, 0x1c4c2, 0x1cdc2, 0x189d0, 0x1c4ec, 0x19bd0, 0x189c8, - 0x1c4e6, 0x19bc8, 0x1cde6, 0x19bc4, 0x189c2, 0x19bc2, 0x113d0, 0x189ec, - 0x137d0, 0x113c8, 0x189e6, 0x137c8, 0x19be6, 0x137c4, 0x113c2, 0x137c2, - 0x113ec, 0x137ec, 0x113e6, 0x137e6, 0x1fba8, 0x175f0, 0x1bafc, 0x1fba4, - 0x174f8, 0x1ba7e, 0x1fba2, 0x1747c, 0x1743e, 0x1f328, 0x1f996, 0x132fc, - 0x1f768, 0x1fbb6, 0x176fc, 0x1327e, 0x1f764, 0x1f322, 0x1767e, 0x1f762, - 0x1e228, 0x1f116, 0x1e668, 0x1e224, 0x1eee8, 0x1f776, 0x1e222, 0x1eee4, - 0x1e662, 0x1eee2, 0x1c468, 0x1e236, 0x1cce8, 0x1c464, 0x1dde8, 0x1cce4, - 0x1c462, 0x1dde4, 0x1cce2, 0x1dde2, 0x188e8, 0x1c476, 0x199e8, 0x188e4, - 0x1bbe8, 0x199e4, 0x188e2, 0x1bbe4, 0x199e2, 0x1bbe2, 0x111e8, 0x188f6, - 0x133e8, 0x111e4, 0x177e8, 0x133e4, 0x111e2, 0x177e4, 0x133e2, 0x177e2, - 0x111f6, 0x133f6, 0x1fb94, 0x172f8, 0x1b97e, 0x1fb92, 0x1727c, 0x1723e, - 0x1f314, 0x1317e, 0x1f734, 0x1f312, 0x1737e, 0x1f732, 0x1e214, 0x1e634, - 0x1e212, 0x1ee74, 0x1e632, 0x1ee72, 0x1c434, 0x1cc74, 0x1c432, 0x1dcf4, - 0x1cc72, 0x1dcf2, 0x18874, 0x198f4, 0x18872, 0x1b9f4, 0x198f2, 0x1b9f2, - 0x110f4, 0x131f4, 0x110f2, 0x173f4, 0x131f2, 0x173f2, 0x1fb8a, 0x1717c, - 0x1713e, 0x1f30a, 0x1f71a, 0x1e20a, 0x1e61a, 0x1ee3a, 0x1c41a, 0x1cc3a, - 0x1dc7a, 0x1883a, 0x1987a, 0x1b8fa, 0x1107a, 0x130fa, 0x171fa, 0x170be, - 0x1e150, 0x1f0ac, 0x1e148, 0x1f0a6, 0x1e144, 0x1e142, 0x1c2d0, 0x1e16c, - 0x1c2c8, 0x1e166, 0x1c2c4, 0x1c2c2, 0x185d0, 0x1c2ec, 0x185c8, 0x1c2e6, - 0x185c4, 0x185c2, 0x10bd0, 0x185ec, 0x10bc8, 0x185e6, 0x10bc4, 0x10bc2, - 0x10bec, 0x10be6, 0x1f1a8, 0x1f8d6, 0x11afc, 0x1f1a4, 0x11a7e, 0x1f1a2, - 0x1e128, 0x1f096, 0x1e368, 0x1e124, 0x1e364, 0x1e122, 0x1e362, 0x1c268, - 0x1e136, 0x1c6e8, 0x1c264, 0x1c6e4, 0x1c262, 0x1c6e2, 0x184e8, 0x1c276, - 0x18de8, 0x184e4, 0x18de4, 0x184e2, 0x18de2, 0x109e8, 0x184f6, 0x11be8, - 0x109e4, 0x11be4, 0x109e2, 0x11be2, 0x109f6, 0x11bf6, 0x1f9d4, 0x13af8, - 0x19d7e, 0x1f9d2, 0x13a7c, 0x13a3e, 0x1f194, 0x1197e, 0x1f3b4, 0x1f192, - 0x13b7e, 0x1f3b2, 0x1e114, 0x1e334, 0x1e112, 0x1e774, 0x1e332, 0x1e772, - 0x1c234, 0x1c674, 0x1c232, 0x1cef4, 0x1c672, 0x1cef2, 0x18474, 0x18cf4, - 0x18472, 0x19df4, 0x18cf2, 0x19df2, 0x108f4, 0x119f4, 0x108f2, 0x13bf4, - 0x119f2, 0x13bf2, 0x17af0, 0x1bd7c, 0x17a78, 0x1bd3e, 0x17a3c, 0x17a1e, - 0x1f9ca, 0x1397c, 0x1fbda, 0x17b7c, 0x1393e, 0x17b3e, 0x1f18a, 0x1f39a, - 0x1f7ba, 0x1e10a, 0x1e31a, 0x1e73a, 0x1ef7a, 0x1c21a, 0x1c63a, 0x1ce7a, - 0x1defa, 0x1843a, 0x18c7a, 0x19cfa, 0x1bdfa, 0x1087a, 0x118fa, 0x139fa, - 0x17978, 0x1bcbe, 0x1793c, 0x1791e, 0x138be, 0x179be, 0x178bc, 0x1789e, - 0x1785e, 0x1e0a8, 0x1e0a4, 0x1e0a2, 0x1c168, 0x1e0b6, 0x1c164, 0x1c162, - 0x182e8, 0x1c176, 0x182e4, 0x182e2, 0x105e8, 0x182f6, 0x105e4, 0x105e2, - 0x105f6, 0x1f0d4, 0x10d7e, 0x1f0d2, 0x1e094, 0x1e1b4, 0x1e092, 0x1e1b2, - 0x1c134, 0x1c374, 0x1c132, 0x1c372, 0x18274, 0x186f4, 0x18272, 0x186f2, - 0x104f4, 0x10df4, 0x104f2, 0x10df2, 0x1f8ea, 0x11d7c, 0x11d3e, 0x1f0ca, - 0x1f1da, 0x1e08a, 0x1e19a, 0x1e3ba, 0x1c11a, 0x1c33a, 0x1c77a, 0x1823a, - 0x1867a, 0x18efa, 0x1047a, 0x10cfa, 0x11dfa, 0x13d78, 0x19ebe, 0x13d3c, - 0x13d1e, 0x11cbe, 0x13dbe, 0x17d70, 0x1bebc, 0x17d38, 0x1be9e, 0x17d1c, - 0x17d0e, 0x13cbc, 0x17dbc, 0x13c9e, 0x17d9e, 0x17cb8, 0x1be5e, 0x17c9c, - 0x17c8e, 0x13c5e, 0x17cde, 0x17c5c, 0x17c4e, 0x17c2e, 0x1c0b4, 0x1c0b2, - 0x18174, 0x18172, 0x102f4, 0x102f2, 0x1e0da, 0x1c09a, 0x1c1ba, 0x1813a, - 0x1837a, 0x1027a, 0x106fa, 0x10ebe, 0x11ebc, 0x11e9e, 0x13eb8, 0x19f5e, - 0x13e9c, 0x13e8e, 0x11e5e, 0x13ede, 0x17eb0, 0x1bf5c, 0x17e98, 0x1bf4e, - 0x17e8c, 0x17e86, 0x13e5c, 0x17edc, 0x13e4e, 0x17ece, 0x17e58, 0x1bf2e, - 0x17e4c, 0x17e46, 0x13e2e, 0x17e6e, 0x17e2c, 0x17e26, 0x10f5e, 0x11f5c, - 0x11f4e, 0x13f58, 0x19fae, 0x13f4c, 0x13f46, 0x11f2e, 0x13f6e, 0x13f2c, - 0x13f26}, - {0x1abe0, 0x1d5f8, 0x153c0, 0x1a9f0, 0x1d4fc, 0x151e0, 0x1a8f8, 0x1d47e, - 0x150f0, 0x1a87c, 0x15078, 0x1fad0, 0x15be0, 0x1adf8, 0x1fac8, 0x159f0, - 0x1acfc, 0x1fac4, 0x158f8, 0x1ac7e, 0x1fac2, 0x1587c, 0x1f5d0, 0x1faec, - 0x15df8, 0x1f5c8, 0x1fae6, 0x15cfc, 0x1f5c4, 0x15c7e, 0x1f5c2, 0x1ebd0, - 0x1f5ec, 0x1ebc8, 0x1f5e6, 0x1ebc4, 0x1ebc2, 0x1d7d0, 0x1ebec, 0x1d7c8, - 0x1ebe6, 0x1d7c4, 0x1d7c2, 0x1afd0, 0x1d7ec, 0x1afc8, 0x1d7e6, 0x1afc4, - 0x14bc0, 0x1a5f0, 0x1d2fc, 0x149e0, 0x1a4f8, 0x1d27e, 0x148f0, 0x1a47c, - 0x14878, 0x1a43e, 0x1483c, 0x1fa68, 0x14df0, 0x1a6fc, 0x1fa64, 0x14cf8, - 0x1a67e, 0x1fa62, 0x14c7c, 0x14c3e, 0x1f4e8, 0x1fa76, 0x14efc, 0x1f4e4, - 0x14e7e, 0x1f4e2, 0x1e9e8, 0x1f4f6, 0x1e9e4, 0x1e9e2, 0x1d3e8, 0x1e9f6, - 0x1d3e4, 0x1d3e2, 0x1a7e8, 0x1d3f6, 0x1a7e4, 0x1a7e2, 0x145e0, 0x1a2f8, - 0x1d17e, 0x144f0, 0x1a27c, 0x14478, 0x1a23e, 0x1443c, 0x1441e, 0x1fa34, - 0x146f8, 0x1a37e, 0x1fa32, 0x1467c, 0x1463e, 0x1f474, 0x1477e, 0x1f472, - 0x1e8f4, 0x1e8f2, 0x1d1f4, 0x1d1f2, 0x1a3f4, 0x1a3f2, 0x142f0, 0x1a17c, - 0x14278, 0x1a13e, 0x1423c, 0x1421e, 0x1fa1a, 0x1437c, 0x1433e, 0x1f43a, - 0x1e87a, 0x1d0fa, 0x14178, 0x1a0be, 0x1413c, 0x1411e, 0x141be, 0x140bc, - 0x1409e, 0x12bc0, 0x195f0, 0x1cafc, 0x129e0, 0x194f8, 0x1ca7e, 0x128f0, - 0x1947c, 0x12878, 0x1943e, 0x1283c, 0x1f968, 0x12df0, 0x196fc, 0x1f964, - 0x12cf8, 0x1967e, 0x1f962, 0x12c7c, 0x12c3e, 0x1f2e8, 0x1f976, 0x12efc, - 0x1f2e4, 0x12e7e, 0x1f2e2, 0x1e5e8, 0x1f2f6, 0x1e5e4, 0x1e5e2, 0x1cbe8, - 0x1e5f6, 0x1cbe4, 0x1cbe2, 0x197e8, 0x1cbf6, 0x197e4, 0x197e2, 0x1b5e0, - 0x1daf8, 0x1ed7e, 0x169c0, 0x1b4f0, 0x1da7c, 0x168e0, 0x1b478, 0x1da3e, - 0x16870, 0x1b43c, 0x16838, 0x1b41e, 0x1681c, 0x125e0, 0x192f8, 0x1c97e, - 0x16de0, 0x124f0, 0x1927c, 0x16cf0, 0x1b67c, 0x1923e, 0x16c78, 0x1243c, - 0x16c3c, 0x1241e, 0x16c1e, 0x1f934, 0x126f8, 0x1937e, 0x1fb74, 0x1f932, - 0x16ef8, 0x1267c, 0x1fb72, 0x16e7c, 0x1263e, 0x16e3e, 0x1f274, 0x1277e, - 0x1f6f4, 0x1f272, 0x16f7e, 0x1f6f2, 0x1e4f4, 0x1edf4, 0x1e4f2, 0x1edf2, - 0x1c9f4, 0x1dbf4, 0x1c9f2, 0x1dbf2, 0x193f4, 0x193f2, 0x165c0, 0x1b2f0, - 0x1d97c, 0x164e0, 0x1b278, 0x1d93e, 0x16470, 0x1b23c, 0x16438, 0x1b21e, - 0x1641c, 0x1640e, 0x122f0, 0x1917c, 0x166f0, 0x12278, 0x1913e, 0x16678, - 0x1b33e, 0x1663c, 0x1221e, 0x1661e, 0x1f91a, 0x1237c, 0x1fb3a, 0x1677c, - 0x1233e, 0x1673e, 0x1f23a, 0x1f67a, 0x1e47a, 0x1ecfa, 0x1c8fa, 0x1d9fa, - 0x191fa, 0x162e0, 0x1b178, 0x1d8be, 0x16270, 0x1b13c, 0x16238, 0x1b11e, - 0x1621c, 0x1620e, 0x12178, 0x190be, 0x16378, 0x1213c, 0x1633c, 0x1211e, - 0x1631e, 0x121be, 0x163be, 0x16170, 0x1b0bc, 0x16138, 0x1b09e, 0x1611c, - 0x1610e, 0x120bc, 0x161bc, 0x1209e, 0x1619e, 0x160b8, 0x1b05e, 0x1609c, - 0x1608e, 0x1205e, 0x160de, 0x1605c, 0x1604e, 0x115e0, 0x18af8, 0x1c57e, - 0x114f0, 0x18a7c, 0x11478, 0x18a3e, 0x1143c, 0x1141e, 0x1f8b4, 0x116f8, - 0x18b7e, 0x1f8b2, 0x1167c, 0x1163e, 0x1f174, 0x1177e, 0x1f172, 0x1e2f4, - 0x1e2f2, 0x1c5f4, 0x1c5f2, 0x18bf4, 0x18bf2, 0x135c0, 0x19af0, 0x1cd7c, - 0x134e0, 0x19a78, 0x1cd3e, 0x13470, 0x19a3c, 0x13438, 0x19a1e, 0x1341c, - 0x1340e, 0x112f0, 0x1897c, 0x136f0, 0x11278, 0x1893e, 0x13678, 0x19b3e, - 0x1363c, 0x1121e, 0x1361e, 0x1f89a, 0x1137c, 0x1f9ba, 0x1377c, 0x1133e, - 0x1373e, 0x1f13a, 0x1f37a, 0x1e27a, 0x1e6fa, 0x1c4fa, 0x1cdfa, 0x189fa, - 0x1bae0, 0x1dd78, 0x1eebe, 0x174c0, 0x1ba70, 0x1dd3c, 0x17460, 0x1ba38, - 0x1dd1e, 0x17430, 0x1ba1c, 0x17418, 0x1ba0e, 0x1740c, 0x132e0, 0x19978, - 0x1ccbe, 0x176e0, 0x13270, 0x1993c, 0x17670, 0x1bb3c, 0x1991e, 0x17638, - 0x1321c, 0x1761c, 0x1320e, 0x1760e, 0x11178, 0x188be, 0x13378, 0x1113c, - 0x17778, 0x1333c, 0x1111e, 0x1773c, 0x1331e, 0x1771e, 0x111be, 0x133be, - 0x177be, 0x172c0, 0x1b970, 0x1dcbc, 0x17260, 0x1b938, 0x1dc9e, 0x17230, - 0x1b91c, 0x17218, 0x1b90e, 0x1720c, 0x17206, 0x13170, 0x198bc, 0x17370, - 0x13138, 0x1989e, 0x17338, 0x1b99e, 0x1731c, 0x1310e, 0x1730e, 0x110bc, - 0x131bc, 0x1109e, 0x173bc, 0x1319e, 0x1739e, 0x17160, 0x1b8b8, 0x1dc5e, - 0x17130, 0x1b89c, 0x17118, 0x1b88e, 0x1710c, 0x17106, 0x130b8, 0x1985e, - 0x171b8, 0x1309c, 0x1719c, 0x1308e, 0x1718e, 0x1105e, 0x130de, 0x171de, - 0x170b0, 0x1b85c, 0x17098, 0x1b84e, 0x1708c, 0x17086, 0x1305c, 0x170dc, - 0x1304e, 0x170ce, 0x17058, 0x1b82e, 0x1704c, 0x17046, 0x1302e, 0x1706e, - 0x1702c, 0x17026, 0x10af0, 0x1857c, 0x10a78, 0x1853e, 0x10a3c, 0x10a1e, - 0x10b7c, 0x10b3e, 0x1f0ba, 0x1e17a, 0x1c2fa, 0x185fa, 0x11ae0, 0x18d78, - 0x1c6be, 0x11a70, 0x18d3c, 0x11a38, 0x18d1e, 0x11a1c, 0x11a0e, 0x10978, - 0x184be, 0x11b78, 0x1093c, 0x11b3c, 0x1091e, 0x11b1e, 0x109be, 0x11bbe, - 0x13ac0, 0x19d70, 0x1cebc, 0x13a60, 0x19d38, 0x1ce9e, 0x13a30, 0x19d1c, - 0x13a18, 0x19d0e, 0x13a0c, 0x13a06, 0x11970, 0x18cbc, 0x13b70, 0x11938, - 0x18c9e, 0x13b38, 0x1191c, 0x13b1c, 0x1190e, 0x13b0e, 0x108bc, 0x119bc, - 0x1089e, 0x13bbc, 0x1199e, 0x13b9e, 0x1bd60, 0x1deb8, 0x1ef5e, 0x17a40, - 0x1bd30, 0x1de9c, 0x17a20, 0x1bd18, 0x1de8e, 0x17a10, 0x1bd0c, 0x17a08, - 0x1bd06, 0x17a04, 0x13960, 0x19cb8, 0x1ce5e, 0x17b60, 0x13930, 0x19c9c, - 0x17b30, 0x1bd9c, 0x19c8e, 0x17b18, 0x1390c, 0x17b0c, 0x13906, 0x17b06, - 0x118b8, 0x18c5e, 0x139b8, 0x1189c, 0x17bb8, 0x1399c, 0x1188e, 0x17b9c, - 0x1398e, 0x17b8e, 0x1085e, 0x118de, 0x139de, 0x17bde, 0x17940, 0x1bcb0, - 0x1de5c, 0x17920, 0x1bc98, 0x1de4e, 0x17910, 0x1bc8c, 0x17908, 0x1bc86, - 0x17904, 0x17902, 0x138b0, 0x19c5c, 0x179b0, 0x13898, 0x19c4e, 0x17998, - 0x1bcce, 0x1798c, 0x13886, 0x17986, 0x1185c, 0x138dc, 0x1184e, 0x179dc, - 0x138ce, 0x179ce, 0x178a0, 0x1bc58, 0x1de2e, 0x17890, 0x1bc4c, 0x17888, - 0x1bc46, 0x17884, 0x17882, 0x13858, 0x19c2e, 0x178d8, 0x1384c, 0x178cc, - 0x13846, 0x178c6, 0x1182e, 0x1386e, 0x178ee, 0x17850, 0x1bc2c, 0x17848, - 0x1bc26, 0x17844, 0x17842, 0x1382c, 0x1786c, 0x13826, 0x17866, 0x17828, - 0x1bc16, 0x17824, 0x17822, 0x13816, 0x17836, 0x10578, 0x182be, 0x1053c, - 0x1051e, 0x105be, 0x10d70, 0x186bc, 0x10d38, 0x1869e, 0x10d1c, 0x10d0e, - 0x104bc, 0x10dbc, 0x1049e, 0x10d9e, 0x11d60, 0x18eb8, 0x1c75e, 0x11d30, - 0x18e9c, 0x11d18, 0x18e8e, 0x11d0c, 0x11d06, 0x10cb8, 0x1865e, 0x11db8, - 0x10c9c, 0x11d9c, 0x10c8e, 0x11d8e, 0x1045e, 0x10cde, 0x11dde, 0x13d40, - 0x19eb0, 0x1cf5c, 0x13d20, 0x19e98, 0x1cf4e, 0x13d10, 0x19e8c, 0x13d08, - 0x19e86, 0x13d04, 0x13d02, 0x11cb0, 0x18e5c, 0x13db0, 0x11c98, 0x18e4e, - 0x13d98, 0x19ece, 0x13d8c, 0x11c86, 0x13d86, 0x10c5c, 0x11cdc, 0x10c4e, - 0x13ddc, 0x11cce, 0x13dce, 0x1bea0, 0x1df58, 0x1efae, 0x1be90, 0x1df4c, - 0x1be88, 0x1df46, 0x1be84, 0x1be82, 0x13ca0, 0x19e58, 0x1cf2e, 0x17da0, - 0x13c90, 0x19e4c, 0x17d90, 0x1becc, 0x19e46, 0x17d88, 0x13c84, 0x17d84, - 0x13c82, 0x17d82, 0x11c58, 0x18e2e, 0x13cd8, 0x11c4c, 0x17dd8, 0x13ccc, - 0x11c46, 0x17dcc, 0x13cc6, 0x17dc6, 0x10c2e, 0x11c6e, 0x13cee, 0x17dee, - 0x1be50, 0x1df2c, 0x1be48, 0x1df26, 0x1be44, 0x1be42, 0x13c50, 0x19e2c, - 0x17cd0, 0x13c48, 0x19e26, 0x17cc8, 0x1be66, 0x17cc4, 0x13c42, 0x17cc2, - 0x11c2c, 0x13c6c, 0x11c26, 0x17cec, 0x13c66, 0x17ce6, 0x1be28, 0x1df16, - 0x1be24, 0x1be22, 0x13c28, 0x19e16, 0x17c68, 0x13c24, 0x17c64, 0x13c22, - 0x17c62, 0x11c16, 0x13c36, 0x17c76, 0x1be14, 0x1be12, 0x13c14, 0x17c34, - 0x13c12, 0x17c32, 0x102bc, 0x1029e, 0x106b8, 0x1835e, 0x1069c, 0x1068e, - 0x1025e, 0x106de, 0x10eb0, 0x1875c, 0x10e98, 0x1874e, 0x10e8c, 0x10e86, - 0x1065c, 0x10edc, 0x1064e, 0x10ece, 0x11ea0, 0x18f58, 0x1c7ae, 0x11e90, - 0x18f4c, 0x11e88, 0x18f46, 0x11e84, 0x11e82, 0x10e58, 0x1872e, 0x11ed8, - 0x18f6e, 0x11ecc, 0x10e46, 0x11ec6, 0x1062e, 0x10e6e, 0x11eee, 0x19f50, - 0x1cfac, 0x19f48, 0x1cfa6, 0x19f44, 0x19f42, 0x11e50, 0x18f2c, 0x13ed0, - 0x19f6c, 0x18f26, 0x13ec8, 0x11e44, 0x13ec4, 0x11e42, 0x13ec2, 0x10e2c, - 0x11e6c, 0x10e26, 0x13eec, 0x11e66, 0x13ee6, 0x1dfa8, 0x1efd6, 0x1dfa4, - 0x1dfa2, 0x19f28, 0x1cf96, 0x1bf68, 0x19f24, 0x1bf64, 0x19f22, 0x1bf62, - 0x11e28, 0x18f16, 0x13e68, 0x11e24, 0x17ee8, 0x13e64, 0x11e22, 0x17ee4, - 0x13e62, 0x17ee2, 0x10e16, 0x11e36, 0x13e76, 0x17ef6, 0x1df94, 0x1df92, - 0x19f14, 0x1bf34, 0x19f12, 0x1bf32, 0x11e14, 0x13e34, 0x11e12, 0x17e74, - 0x13e32, 0x17e72, 0x1df8a, 0x19f0a, 0x1bf1a, 0x11e0a, 0x13e1a, 0x17e3a, - 0x1035c, 0x1034e, 0x10758, 0x183ae, 0x1074c, 0x10746, 0x1032e, 0x1076e, - 0x10f50, 0x187ac, 0x10f48, 0x187a6, 0x10f44, 0x10f42, 0x1072c, 0x10f6c, - 0x10726, 0x10f66, 0x18fa8, 0x1c7d6, 0x18fa4, 0x18fa2, 0x10f28, 0x18796, - 0x11f68, 0x18fb6, 0x11f64, 0x10f22, 0x11f62, 0x10716, 0x10f36, 0x11f76, - 0x1cfd4, 0x1cfd2, 0x18f94, 0x19fb4, 0x18f92, 0x19fb2, 0x10f14, 0x11f34, - 0x10f12, 0x13f74, 0x11f32, 0x13f72, 0x1cfca, 0x18f8a, 0x19f9a, 0x10f0a, - 0x11f1a, 0x13f3a, 0x103ac, 0x103a6, 0x107a8, 0x183d6, 0x107a4, 0x107a2, - 0x10396, 0x107b6, 0x187d4, 0x187d2, 0x10794, 0x10fb4, 0x10792, 0x10fb2, - 0x1c7ea}}; - -CBC_PDF417::CBC_PDF417() : CBC_PDF417(false) {} - -CBC_PDF417::CBC_PDF417(bool compact) - : m_compact(compact), - m_compaction(AUTO), - m_minCols(1), - m_maxCols(30), - m_maxRows(90), - m_minRows(3) {} - -CBC_PDF417::~CBC_PDF417() {} - -CBC_BarcodeMatrix* CBC_PDF417::getBarcodeMatrix() { - return m_barcodeMatrix.get(); -} - -void CBC_PDF417::generateBarcodeLogic(CFX_WideString msg, - int32_t errorCorrectionLevel, - int32_t& e) { - int32_t errorCorrectionCodeWords = - CBC_PDF417ErrorCorrection::getErrorCorrectionCodewordCount( - errorCorrectionLevel, e); - if (e != BCExceptionNO) - return; - CFX_WideString highLevel = - CBC_PDF417HighLevelEncoder::encodeHighLevel(msg, m_compaction, e); - if (e != BCExceptionNO) - return; - int32_t sourceCodeWords = highLevel.GetLength(); - std::vector<int32_t>* dimension = - determineDimensions(sourceCodeWords, errorCorrectionCodeWords, e); - if (e != BCExceptionNO) - return; - int32_t cols = (*dimension)[0]; - int32_t rows = (*dimension)[1]; - delete dimension; - int32_t pad = getNumberOfPadCodewords(sourceCodeWords, - errorCorrectionCodeWords, cols, rows); - if (sourceCodeWords + errorCorrectionCodeWords + 1 > 929) { - e = BCExceptionEncodedMessageContainsTooManyCodeWords; - return; - } - int32_t n = sourceCodeWords + pad + 1; - CFX_WideString sb; - sb += (wchar_t)n; - sb += highLevel; - for (int32_t i = 0; i < pad; i++) { - sb += (wchar_t)900; - } - CFX_WideString dataCodewords(sb); - CFX_WideString ec = CBC_PDF417ErrorCorrection::generateErrorCorrection( - dataCodewords, errorCorrectionLevel, e); - if (e != BCExceptionNO) - return; - CFX_WideString fullCodewords = dataCodewords + ec; - m_barcodeMatrix = pdfium::MakeUnique<CBC_BarcodeMatrix>(rows, cols); - encodeLowLevel(fullCodewords, cols, rows, errorCorrectionLevel, - m_barcodeMatrix.get()); -} - -void CBC_PDF417::setDimensions(int32_t maxCols, - int32_t minCols, - int32_t maxRows, - int32_t minRows) { - m_maxCols = maxCols; - m_minCols = minCols; - m_maxRows = maxRows; - m_minRows = minRows; -} - -void CBC_PDF417::setCompaction(Compaction compaction) { - m_compaction = compaction; -} - -void CBC_PDF417::setCompact(bool compact) { - m_compact = compact; -} - -int32_t CBC_PDF417::calculateNumberOfRows(int32_t m, int32_t k, int32_t c) { - int32_t r = ((m + 1 + k) / c) + 1; - if (c * r >= (m + 1 + k + c)) { - r--; - } - return r; -} - -int32_t CBC_PDF417::getNumberOfPadCodewords(int32_t m, - int32_t k, - int32_t c, - int32_t r) { - int32_t n = c * r - k; - return n > m + 1 ? n - m - 1 : 0; -} - -void CBC_PDF417::encodeChar(int32_t pattern, - int32_t len, - CBC_BarcodeRow* logic) { - int32_t map = 1 << (len - 1); - bool last = ((pattern & map) != 0); - int32_t width = 0; - for (int32_t i = 0; i < len; i++) { - bool black = ((pattern & map) != 0); - if (last == black) { - width++; - } else { - logic->addBar(last, width); - last = black; - width = 1; - } - map >>= 1; - } - logic->addBar(last, width); -} - -void CBC_PDF417::encodeLowLevel(CFX_WideString fullCodewords, - int32_t c, - int32_t r, - int32_t errorCorrectionLevel, - CBC_BarcodeMatrix* logic) { - int32_t idx = 0; - for (int32_t y = 0; y < r; y++) { - int32_t cluster = y % 3; - logic->startRow(); - encodeChar(START_PATTERN, 17, logic->getCurrentRow()); - int32_t left; - int32_t right; - if (cluster == 0) { - left = (30 * (y / 3)) + ((r - 1) / 3); - right = (30 * (y / 3)) + (c - 1); - } else if (cluster == 1) { - left = (30 * (y / 3)) + (errorCorrectionLevel * 3) + ((r - 1) % 3); - right = (30 * (y / 3)) + ((r - 1) / 3); - } else { - left = (30 * (y / 3)) + (c - 1); - right = (30 * (y / 3)) + (errorCorrectionLevel * 3) + ((r - 1) % 3); - } - int32_t pattern = CODEWORD_TABLE[cluster][left]; - encodeChar(pattern, 17, logic->getCurrentRow()); - for (int32_t x = 0; x < c; x++) { - pattern = CODEWORD_TABLE[cluster][fullCodewords.GetAt(idx)]; - encodeChar(pattern, 17, logic->getCurrentRow()); - idx++; - } - if (m_compact) { - encodeChar(STOP_PATTERN, 1, logic->getCurrentRow()); - } else { - pattern = CODEWORD_TABLE[cluster][right]; - encodeChar(pattern, 17, logic->getCurrentRow()); - encodeChar(STOP_PATTERN, 18, logic->getCurrentRow()); - } - } -} - -std::vector<int32_t>* CBC_PDF417::determineDimensions( - int32_t sourceCodeWords, - int32_t errorCorrectionCodeWords, - int32_t& e) { - float ratio = 0.0f; - std::vector<int32_t>* dimension = nullptr; - for (int32_t cols = m_minCols; cols <= m_maxCols; cols++) { - int32_t rows = - calculateNumberOfRows(sourceCodeWords, errorCorrectionCodeWords, cols); - if (rows < m_minRows) { - break; - } - if (rows > m_maxRows) { - continue; - } - float newRatio = - ((17 * cols + 69) * DEFAULT_MODULE_WIDTH) / (rows * HEIGHT); - if (dimension && - fabsf(newRatio - PREFERRED_RATIO) > fabsf(ratio - PREFERRED_RATIO)) { - continue; - } - ratio = newRatio; - delete dimension; - dimension = new std::vector<int32_t>; - dimension->push_back(cols); - dimension->push_back(rows); - } - if (!dimension) { - int32_t rows = calculateNumberOfRows(sourceCodeWords, - errorCorrectionCodeWords, m_minCols); - if (rows < m_minRows) { - dimension = new std::vector<int32_t>; - dimension->push_back(m_minCols); - dimension->push_back(m_minRows); - } else if (rows >= 3 && rows <= 90) { - dimension = new std::vector<int32_t>; - dimension->push_back(m_minCols); - dimension->push_back(rows); - } - } - if (!dimension) { - e = BCExceptionUnableToFitMessageInColumns; - return nullptr; - } - return dimension; -} diff --git a/xfa/fxbarcode/pdf417/BC_PDF417.h b/xfa/fxbarcode/pdf417/BC_PDF417.h deleted file mode 100644 index 0d8fbfaf5f..0000000000 --- a/xfa/fxbarcode/pdf417/BC_PDF417.h +++ /dev/null @@ -1,68 +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_FXBARCODE_PDF417_BC_PDF417_H_ -#define XFA_FXBARCODE_PDF417_BC_PDF417_H_ - -#include <memory> -#include <vector> - -#include "core/fxcrt/fx_basic.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Compaction.h" - -class CBC_BarcodeRow; -class CBC_BarcodeMatrix; - -class CBC_PDF417 { - public: - CBC_PDF417(); - explicit CBC_PDF417(bool compact); - virtual ~CBC_PDF417(); - - CBC_BarcodeMatrix* getBarcodeMatrix(); - void generateBarcodeLogic(CFX_WideString msg, - int32_t errorCorrectionLevel, - int32_t& e); - void setDimensions(int32_t maxCols, - int32_t minCols, - int32_t maxRows, - int32_t minRows); - void setCompaction(Compaction compaction); - void setCompact(bool compact); - - private: - static const int32_t START_PATTERN = 0x1fea8; - static const int32_t STOP_PATTERN = 0x3fa29; - static const int32_t CODEWORD_TABLE[][929]; - static constexpr float PREFERRED_RATIO = 3.0f; - static constexpr float DEFAULT_MODULE_WIDTH = 0.357f; - static constexpr float HEIGHT = 2.0f; - - static int32_t calculateNumberOfRows(int32_t m, int32_t k, int32_t c); - static int32_t getNumberOfPadCodewords(int32_t m, - int32_t k, - int32_t c, - int32_t r); - static void encodeChar(int32_t pattern, int32_t len, CBC_BarcodeRow* logic); - void encodeLowLevel(CFX_WideString fullCodewords, - int32_t c, - int32_t r, - int32_t errorCorrectionLevel, - CBC_BarcodeMatrix* logic); - std::vector<int32_t>* determineDimensions(int32_t sourceCodeWords, - int32_t errorCorrectionCodeWords, - int32_t& e); - - std::unique_ptr<CBC_BarcodeMatrix> m_barcodeMatrix; - bool m_compact; - Compaction m_compaction; - int32_t m_minCols; - int32_t m_maxCols; - int32_t m_maxRows; - int32_t m_minRows; -}; - -#endif // XFA_FXBARCODE_PDF417_BC_PDF417_H_ diff --git a/xfa/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp b/xfa/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp deleted file mode 100644 index 68bc799ec0..0000000000 --- a/xfa/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp +++ /dev/null @@ -1,84 +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/pdf417/BC_PDF417BarcodeMatrix.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417BarcodeRow.h" - -CBC_BarcodeMatrix::CBC_BarcodeMatrix(int32_t height, int32_t width) { - m_matrix.resize(height + 2); - for (size_t i = 0, matrixLength = m_matrix.size(); i < matrixLength; ++i) - m_matrix[i] = new CBC_BarcodeRow((width + 4) * 17 + 1); - - m_width = width * 17; - m_height = height + 2; - m_currentRow = 0; - m_outHeight = 0; - m_outWidth = 0; -} - -CBC_BarcodeMatrix::~CBC_BarcodeMatrix() { - for (size_t i = 0; i < m_matrix.size(); i++) - delete m_matrix[i]; -} - -void CBC_BarcodeMatrix::set(int32_t x, int32_t y, uint8_t value) { - m_matrix[y]->set(x, value); -} -void CBC_BarcodeMatrix::setMatrix(int32_t x, int32_t y, bool black) { - set(x, y, (uint8_t)(black ? 1 : 0)); -} -void CBC_BarcodeMatrix::startRow() { - ++m_currentRow; -} -CBC_BarcodeRow* CBC_BarcodeMatrix::getCurrentRow() { - return m_matrix[m_currentRow]; -} -int32_t CBC_BarcodeMatrix::getWidth() { - return m_outWidth; -} -int32_t CBC_BarcodeMatrix::getHeight() { - return m_outHeight; -} -std::vector<uint8_t>& CBC_BarcodeMatrix::getMatrix() { - return getScaledMatrix(1, 1); -} -std::vector<uint8_t>& CBC_BarcodeMatrix::getScaledMatrix(int32_t scale) { - return getScaledMatrix(scale, scale); -} -std::vector<uint8_t>& CBC_BarcodeMatrix::getScaledMatrix(int32_t xScale, - int32_t yScale) { - size_t yMax = m_height * yScale; - std::vector<uint8_t> bytearray = m_matrix[0]->getScaledRow(xScale); - size_t xMax = bytearray.size(); - m_matrixOut.resize(xMax * yMax); - m_outWidth = xMax; - m_outHeight = yMax; - int32_t k = 0; - for (size_t i = 0; i < yMax; i++) { - if (i != 0) - bytearray = m_matrix[i / yScale]->getScaledRow(xScale); - k = i * xMax; - for (size_t l = 0; l < xMax; l++) - m_matrixOut[k + l] = bytearray[l]; - } - return m_matrixOut; -} diff --git a/xfa/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h b/xfa/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h deleted file mode 100644 index bf86b7b55a..0000000000 --- a/xfa/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h +++ /dev/null @@ -1,42 +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_FXBARCODE_PDF417_BC_PDF417BARCODEMATRIX_H_ -#define XFA_FXBARCODE_PDF417_BC_PDF417BARCODEMATRIX_H_ - -#include <vector> - -#include "core/fxcrt/fx_basic.h" - -class CBC_BarcodeRow; - -class CBC_BarcodeMatrix { - public: - CBC_BarcodeMatrix(); - CBC_BarcodeMatrix(int32_t height, int32_t width); - virtual ~CBC_BarcodeMatrix(); - - void set(int32_t x, int32_t y, uint8_t value); - void setMatrix(int32_t x, int32_t y, bool black); - void startRow(); - CBC_BarcodeRow* getCurrentRow(); - std::vector<uint8_t>& getMatrix(); - std::vector<uint8_t>& getScaledMatrix(int32_t scale); - std::vector<uint8_t>& getScaledMatrix(int32_t xScale, int32_t yScale); - int32_t getWidth(); - int32_t getHeight(); - - private: - std::vector<CBC_BarcodeRow*> m_matrix; - std::vector<uint8_t> m_matrixOut; - int32_t m_currentRow; - int32_t m_height; - int32_t m_width; - int32_t m_outWidth; - int32_t m_outHeight; -}; - -#endif // XFA_FXBARCODE_PDF417_BC_PDF417BARCODEMATRIX_H_ diff --git a/xfa/fxbarcode/pdf417/BC_PDF417BarcodeRow.cpp b/xfa/fxbarcode/pdf417/BC_PDF417BarcodeRow.cpp deleted file mode 100644 index 427da9d588..0000000000 --- a/xfa/fxbarcode/pdf417/BC_PDF417BarcodeRow.cpp +++ /dev/null @@ -1,52 +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/pdf417/BC_PDF417BarcodeRow.h" - -CBC_BarcodeRow::CBC_BarcodeRow(size_t width) - : m_row(width), m_currentLocation(0) {} - -CBC_BarcodeRow::~CBC_BarcodeRow() {} - -void CBC_BarcodeRow::set(int32_t x, uint8_t value) { - m_row[x] = value; -} - -void CBC_BarcodeRow::set(int32_t x, bool black) { - m_row[x] = black ? 1 : 0; -} - -void CBC_BarcodeRow::addBar(bool black, int32_t width) { - for (int32_t ii = 0; ii < width; ii++) - set(m_currentLocation++, black); -} - -std::vector<uint8_t>& CBC_BarcodeRow::getRow() { - return m_row; -} - -std::vector<uint8_t>& CBC_BarcodeRow::getScaledRow(int32_t scale) { - m_output.resize(m_row.size() * scale); - for (size_t i = 0; i < m_output.size(); i++) - m_output[i] = m_row[i / scale]; - return m_output; -} diff --git a/xfa/fxbarcode/pdf417/BC_PDF417BarcodeRow.h b/xfa/fxbarcode/pdf417/BC_PDF417BarcodeRow.h deleted file mode 100644 index 9130a0c38f..0000000000 --- a/xfa/fxbarcode/pdf417/BC_PDF417BarcodeRow.h +++ /dev/null @@ -1,31 +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_FXBARCODE_PDF417_BC_PDF417BARCODEROW_H_ -#define XFA_FXBARCODE_PDF417_BC_PDF417BARCODEROW_H_ - -#include <vector> - -#include "core/fxcrt/fx_basic.h" - -class CBC_BarcodeRow { - public: - explicit CBC_BarcodeRow(size_t width); - virtual ~CBC_BarcodeRow(); - - void set(int32_t x, uint8_t value); - void set(int32_t x, bool black); - void addBar(bool black, int32_t width); - std::vector<uint8_t>& getRow(); - std::vector<uint8_t>& getScaledRow(int32_t scale); - - private: - std::vector<uint8_t> m_row; - std::vector<uint8_t> m_output; - int32_t m_currentLocation; -}; - -#endif // XFA_FXBARCODE_PDF417_BC_PDF417BARCODEROW_H_ diff --git a/xfa/fxbarcode/pdf417/BC_PDF417Compaction.cpp b/xfa/fxbarcode/pdf417/BC_PDF417Compaction.cpp deleted file mode 100644 index d3a1663eb6..0000000000 --- a/xfa/fxbarcode/pdf417/BC_PDF417Compaction.cpp +++ /dev/null @@ -1,26 +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/pdf417/BC_PDF417Compaction.h" - -CBC_Compaction::CBC_Compaction() {} -CBC_Compaction::~CBC_Compaction() {} diff --git a/xfa/fxbarcode/pdf417/BC_PDF417Compaction.h b/xfa/fxbarcode/pdf417/BC_PDF417Compaction.h deleted file mode 100644 index 2df0fce303..0000000000 --- a/xfa/fxbarcode/pdf417/BC_PDF417Compaction.h +++ /dev/null @@ -1,18 +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_FXBARCODE_PDF417_BC_PDF417COMPACTION_H_ -#define XFA_FXBARCODE_PDF417_BC_PDF417COMPACTION_H_ - -class CBC_Compaction; -enum Compaction { AUTO, TEXT, BYTES, NUMERIC }; -class CBC_Compaction { - public: - CBC_Compaction(); - virtual ~CBC_Compaction(); -}; - -#endif // XFA_FXBARCODE_PDF417_BC_PDF417COMPACTION_H_ diff --git a/xfa/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp b/xfa/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp deleted file mode 100644 index 71cdc351db..0000000000 --- a/xfa/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp +++ /dev/null @@ -1,191 +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 2006 Jeremias Maerki in part, and ZXing Authors in part - * - * 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/pdf417/BC_PDF417ErrorCorrection.h" -#include "xfa/fxbarcode/utils.h" - -namespace { - -const uint16_t EC_LEVEL_0_COEFFICIENTS[2] = {27, 917}; -const uint16_t EC_LEVEL_1_COEFFICIENTS[4] = {522, 568, 723, 809}; -const uint16_t EC_LEVEL_2_COEFFICIENTS[8] = {237, 308, 436, 284, - 646, 653, 428, 379}; - -const uint16_t EC_LEVEL_3_COEFFICIENTS[16] = {274, 562, 232, 755, 599, 524, - 801, 132, 295, 116, 442, 428, - 295, 42, 176, 65}; - -const uint16_t EC_LEVEL_4_COEFFICIENTS[32] = { - 361, 575, 922, 525, 176, 586, 640, 321, 536, 742, 677, - 742, 687, 284, 193, 517, 273, 494, 263, 147, 593, 800, - 571, 320, 803, 133, 231, 390, 685, 330, 63, 410}; - -const uint16_t EC_LEVEL_5_COEFFICIENTS[64] = { - 539, 422, 6, 93, 862, 771, 453, 106, 610, 287, 107, 505, 733, - 877, 381, 612, 723, 476, 462, 172, 430, 609, 858, 822, 543, 376, - 511, 400, 672, 762, 283, 184, 440, 35, 519, 31, 460, 594, 225, - 535, 517, 352, 605, 158, 651, 201, 488, 502, 648, 733, 717, 83, - 404, 97, 280, 771, 840, 629, 4, 381, 843, 623, 264, 543}; - -const uint16_t EC_LEVEL_6_COEFFICIENTS[128] = { - 521, 310, 864, 547, 858, 580, 296, 379, 53, 779, 897, 444, 400, 925, 749, - 415, 822, 93, 217, 208, 928, 244, 583, 620, 246, 148, 447, 631, 292, 908, - 490, 704, 516, 258, 457, 907, 594, 723, 674, 292, 272, 96, 684, 432, 686, - 606, 860, 569, 193, 219, 129, 186, 236, 287, 192, 775, 278, 173, 40, 379, - 712, 463, 646, 776, 171, 491, 297, 763, 156, 732, 95, 270, 447, 90, 507, - 48, 228, 821, 808, 898, 784, 663, 627, 378, 382, 262, 380, 602, 754, 336, - 89, 614, 87, 432, 670, 616, 157, 374, 242, 726, 600, 269, 375, 898, 845, - 454, 354, 130, 814, 587, 804, 34, 211, 330, 539, 297, 827, 865, 37, 517, - 834, 315, 550, 86, 801, 4, 108, 539}; - -const uint16_t EC_LEVEL_7_COEFFICIENTS[256] = { - 524, 894, 75, 766, 882, 857, 74, 204, 82, 586, 708, 250, 905, 786, 138, - 720, 858, 194, 311, 913, 275, 190, 375, 850, 438, 733, 194, 280, 201, 280, - 828, 757, 710, 814, 919, 89, 68, 569, 11, 204, 796, 605, 540, 913, 801, - 700, 799, 137, 439, 418, 592, 668, 353, 859, 370, 694, 325, 240, 216, 257, - 284, 549, 209, 884, 315, 70, 329, 793, 490, 274, 877, 162, 749, 812, 684, - 461, 334, 376, 849, 521, 307, 291, 803, 712, 19, 358, 399, 908, 103, 511, - 51, 8, 517, 225, 289, 470, 637, 731, 66, 255, 917, 269, 463, 830, 730, - 433, 848, 585, 136, 538, 906, 90, 2, 290, 743, 199, 655, 903, 329, 49, - 802, 580, 355, 588, 188, 462, 10, 134, 628, 320, 479, 130, 739, 71, 263, - 318, 374, 601, 192, 605, 142, 673, 687, 234, 722, 384, 177, 752, 607, 640, - 455, 193, 689, 707, 805, 641, 48, 60, 732, 621, 895, 544, 261, 852, 655, - 309, 697, 755, 756, 60, 231, 773, 434, 421, 726, 528, 503, 118, 49, 795, - 32, 144, 500, 238, 836, 394, 280, 566, 319, 9, 647, 550, 73, 914, 342, - 126, 32, 681, 331, 792, 620, 60, 609, 441, 180, 791, 893, 754, 605, 383, - 228, 749, 760, 213, 54, 297, 134, 54, 834, 299, 922, 191, 910, 532, 609, - 829, 189, 20, 167, 29, 872, 449, 83, 402, 41, 656, 505, 579, 481, 173, - 404, 251, 688, 95, 497, 555, 642, 543, 307, 159, 924, 558, 648, 55, 497, - 10}; - -const uint16_t EC_LEVEL_8_COEFFICIENTS[512] = { - 352, 77, 373, 504, 35, 599, 428, 207, 409, 574, 118, 498, 285, 380, 350, - 492, 197, 265, 920, 155, 914, 299, 229, 643, 294, 871, 306, 88, 87, 193, - 352, 781, 846, 75, 327, 520, 435, 543, 203, 666, 249, 346, 781, 621, 640, - 268, 794, 534, 539, 781, 408, 390, 644, 102, 476, 499, 290, 632, 545, 37, - 858, 916, 552, 41, 542, 289, 122, 272, 383, 800, 485, 98, 752, 472, 761, - 107, 784, 860, 658, 741, 290, 204, 681, 407, 855, 85, 99, 62, 482, 180, - 20, 297, 451, 593, 913, 142, 808, 684, 287, 536, 561, 76, 653, 899, 729, - 567, 744, 390, 513, 192, 516, 258, 240, 518, 794, 395, 768, 848, 51, 610, - 384, 168, 190, 826, 328, 596, 786, 303, 570, 381, 415, 641, 156, 237, 151, - 429, 531, 207, 676, 710, 89, 168, 304, 402, 40, 708, 575, 162, 864, 229, - 65, 861, 841, 512, 164, 477, 221, 92, 358, 785, 288, 357, 850, 836, 827, - 736, 707, 94, 8, 494, 114, 521, 2, 499, 851, 543, 152, 729, 771, 95, - 248, 361, 578, 323, 856, 797, 289, 51, 684, 466, 533, 820, 669, 45, 902, - 452, 167, 342, 244, 173, 35, 463, 651, 51, 699, 591, 452, 578, 37, 124, - 298, 332, 552, 43, 427, 119, 662, 777, 475, 850, 764, 364, 578, 911, 283, - 711, 472, 420, 245, 288, 594, 394, 511, 327, 589, 777, 699, 688, 43, 408, - 842, 383, 721, 521, 560, 644, 714, 559, 62, 145, 873, 663, 713, 159, 672, - 729, 624, 59, 193, 417, 158, 209, 563, 564, 343, 693, 109, 608, 563, 365, - 181, 772, 677, 310, 248, 353, 708, 410, 579, 870, 617, 841, 632, 860, 289, - 536, 35, 777, 618, 586, 424, 833, 77, 597, 346, 269, 757, 632, 695, 751, - 331, 247, 184, 45, 787, 680, 18, 66, 407, 369, 54, 492, 228, 613, 830, - 922, 437, 519, 644, 905, 789, 420, 305, 441, 207, 300, 892, 827, 141, 537, - 381, 662, 513, 56, 252, 341, 242, 797, 838, 837, 720, 224, 307, 631, 61, - 87, 560, 310, 756, 665, 397, 808, 851, 309, 473, 795, 378, 31, 647, 915, - 459, 806, 590, 731, 425, 216, 548, 249, 321, 881, 699, 535, 673, 782, 210, - 815, 905, 303, 843, 922, 281, 73, 469, 791, 660, 162, 498, 308, 155, 422, - 907, 817, 187, 62, 16, 425, 535, 336, 286, 437, 375, 273, 610, 296, 183, - 923, 116, 667, 751, 353, 62, 366, 691, 379, 687, 842, 37, 357, 720, 742, - 330, 5, 39, 923, 311, 424, 242, 749, 321, 54, 669, 316, 342, 299, 534, - 105, 667, 488, 640, 672, 576, 540, 316, 486, 721, 610, 46, 656, 447, 171, - 616, 464, 190, 531, 297, 321, 762, 752, 533, 175, 134, 14, 381, 433, 717, - 45, 111, 20, 596, 284, 736, 138, 646, 411, 877, 669, 141, 919, 45, 780, - 407, 164, 332, 899, 165, 726, 600, 325, 498, 655, 357, 752, 768, 223, 849, - 647, 63, 310, 863, 251, 366, 304, 282, 738, 675, 410, 389, 244, 31, 121, - 303, 263}; - -const uint16_t* const EC_COEFFICIENTS[9] = { - EC_LEVEL_0_COEFFICIENTS, EC_LEVEL_1_COEFFICIENTS, EC_LEVEL_2_COEFFICIENTS, - EC_LEVEL_3_COEFFICIENTS, EC_LEVEL_4_COEFFICIENTS, EC_LEVEL_5_COEFFICIENTS, - EC_LEVEL_6_COEFFICIENTS, EC_LEVEL_7_COEFFICIENTS, EC_LEVEL_8_COEFFICIENTS}; - -} // namespace - -CBC_PDF417ErrorCorrection::CBC_PDF417ErrorCorrection() {} -CBC_PDF417ErrorCorrection::~CBC_PDF417ErrorCorrection() {} -int32_t CBC_PDF417ErrorCorrection::getErrorCorrectionCodewordCount( - int32_t errorCorrectionLevel, - int32_t& e) { - if (errorCorrectionLevel < 0 || errorCorrectionLevel > 8) { - e = BCExceptionErrorCorrectionLevelMustBeBetween0And8; - return -1; - } - return 1 << (errorCorrectionLevel + 1); -} - -int32_t CBC_PDF417ErrorCorrection::getRecommendedMinimumErrorCorrectionLevel( - int32_t n, - int32_t& e) { - if (n <= 0) { - e = BCExceptionIllegalArgumentnMustBeAbove0; - return -1; - } - if (n <= 40) { - return 2; - } - if (n <= 160) { - return 3; - } - if (n <= 320) { - return 4; - } - if (n <= 863) { - return 5; - } - e = BCExceptionNoRecommendationPossible; - return -1; -} - -CFX_WideString CBC_PDF417ErrorCorrection::generateErrorCorrection( - CFX_WideString dataCodewords, - int32_t errorCorrectionLevel, - int32_t& e) { - int32_t k = getErrorCorrectionCodewordCount(errorCorrectionLevel, e); - if (e != BCExceptionNO) - return L" "; - wchar_t* ech = FX_Alloc(wchar_t, k); - FXSYS_memset(ech, 0, k * sizeof(wchar_t)); - int32_t sld = dataCodewords.GetLength(); - for (int32_t i = 0; i < sld; i++) { - int32_t t1 = (dataCodewords.GetAt(i) + ech[k - 1]) % 929; - int32_t t2; - int32_t t3; - for (int32_t j = k - 1; j >= 1; j--) { - t2 = (t1 * EC_COEFFICIENTS[errorCorrectionLevel][j]) % 929; - t3 = 929 - t2; - ech[j] = (wchar_t)((ech[j - 1] + t3) % 929); - } - t2 = (t1 * EC_COEFFICIENTS[errorCorrectionLevel][0]) % 929; - t3 = 929 - t2; - ech[0] = (wchar_t)(t3 % 929); - } - CFX_WideString sb; - for (int32_t j = k - 1; j >= 0; j--) { - if (ech[j] != 0) { - ech[j] = (wchar_t)(929 - ech[j]); - } - sb += (wchar_t)ech[j]; - } - FX_Free(ech); - return sb; -} diff --git a/xfa/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h b/xfa/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h deleted file mode 100644 index 6822ae4e11..0000000000 --- a/xfa/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h +++ /dev/null @@ -1,28 +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_FXBARCODE_PDF417_BC_PDF417ERRORCORRECTION_H_ -#define XFA_FXBARCODE_PDF417_BC_PDF417ERRORCORRECTION_H_ - -#include <stdint.h> - -#include "core/fxcrt/fx_string.h" - -class CBC_PDF417ErrorCorrection { - public: - CBC_PDF417ErrorCorrection(); - virtual ~CBC_PDF417ErrorCorrection(); - - static int32_t getErrorCorrectionCodewordCount(int32_t errorCorrectionLevel, - int32_t& e); - static int32_t getRecommendedMinimumErrorCorrectionLevel(int32_t n, - int32_t& e); - static CFX_WideString generateErrorCorrection(CFX_WideString dataCodewords, - int32_t errorCorrectionLevel, - int32_t& e); -}; - -#endif // XFA_FXBARCODE_PDF417_BC_PDF417ERRORCORRECTION_H_ diff --git a/xfa/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp b/xfa/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp deleted file mode 100644 index 5402f3d7f7..0000000000 --- a/xfa/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp +++ /dev/null @@ -1,430 +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 2006 Jeremias Maerki in part, and ZXing Authors in part - * - * 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/pdf417/BC_PDF417HighLevelEncoder.h" - -#include "third_party/bigint/BigIntegerLibrary.hh" -#include "xfa/fxbarcode/BC_UtilCodingConvert.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Compaction.h" -#include "xfa/fxbarcode/utils.h" - -#define SUBMODE_ALPHA 0 -#define SUBMODE_LOWER 1 -#define SUBMODE_MIXED 2 - -int32_t CBC_PDF417HighLevelEncoder::TEXT_COMPACTION = 0; -int32_t CBC_PDF417HighLevelEncoder::BYTE_COMPACTION = 1; -int32_t CBC_PDF417HighLevelEncoder::NUMERIC_COMPACTION = 2; -int32_t CBC_PDF417HighLevelEncoder::SUBMODE_PUNCTUATION = 3; -int32_t CBC_PDF417HighLevelEncoder::LATCH_TO_TEXT = 900; -int32_t CBC_PDF417HighLevelEncoder::LATCH_TO_BYTE_PADDED = 901; -int32_t CBC_PDF417HighLevelEncoder::LATCH_TO_NUMERIC = 902; -int32_t CBC_PDF417HighLevelEncoder::SHIFT_TO_BYTE = 913; -int32_t CBC_PDF417HighLevelEncoder::LATCH_TO_BYTE = 924; -uint8_t CBC_PDF417HighLevelEncoder::TEXT_MIXED_RAW[] = { - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 38, 13, 9, 44, 58, - 35, 45, 46, 36, 47, 43, 37, 42, 61, 94, 0, 32, 0, 0, 0}; -uint8_t CBC_PDF417HighLevelEncoder::TEXT_PUNCTUATION_RAW[] = { - 59, 60, 62, 64, 91, 92, 93, 95, 96, 126, 33, 13, 9, 44, 58, - 10, 45, 46, 36, 47, 34, 124, 42, 40, 41, 63, 123, 125, 39, 0}; -int32_t CBC_PDF417HighLevelEncoder::MIXED[128] = {0}; -int32_t CBC_PDF417HighLevelEncoder::PUNCTUATION[128] = {0}; - -void CBC_PDF417HighLevelEncoder::Initialize() { - Inverse(); -} - -void CBC_PDF417HighLevelEncoder::Finalize() {} - -CFX_WideString CBC_PDF417HighLevelEncoder::encodeHighLevel( - CFX_WideString wideMsg, - Compaction compaction, - int32_t& e) { - CFX_ByteString bytes; - CBC_UtilCodingConvert::UnicodeToUTF8(wideMsg, bytes); - CFX_WideString msg; - int32_t len = bytes.GetLength(); - for (int32_t i = 0; i < len; i++) { - wchar_t ch = (wchar_t)(bytes.GetAt(i) & 0xff); - if (ch == '?' && bytes.GetAt(i) != '?') { - e = BCExceptionCharactersOutsideISO88591Encoding; - return CFX_WideString(); - } - msg += ch; - } - std::vector<uint8_t> byteArr; - for (int32_t k = 0; k < bytes.GetLength(); k++) { - byteArr.push_back(bytes.GetAt(k)); - } - CFX_WideString sb; - len = msg.GetLength(); - int32_t p = 0; - int32_t textSubMode = SUBMODE_ALPHA; - if (compaction == TEXT) { - encodeText(msg, p, len, sb, textSubMode); - } else if (compaction == BYTES) { - encodeBinary(&byteArr, p, byteArr.size(), BYTE_COMPACTION, sb); - } else if (compaction == NUMERIC) { - sb += (wchar_t)LATCH_TO_NUMERIC; - encodeNumeric(msg, p, len, sb); - } else { - int32_t encodingMode = LATCH_TO_TEXT; - while (p < len) { - int32_t n = determineConsecutiveDigitCount(msg, p); - if (n >= 13) { - sb += (wchar_t)LATCH_TO_NUMERIC; - encodingMode = NUMERIC_COMPACTION; - textSubMode = SUBMODE_ALPHA; - encodeNumeric(msg, p, n, sb); - p += n; - } else { - int32_t t = determineConsecutiveTextCount(msg, p); - if (t >= 5 || n == len) { - if (encodingMode != TEXT_COMPACTION) { - sb += (wchar_t)LATCH_TO_TEXT; - encodingMode = TEXT_COMPACTION; - textSubMode = SUBMODE_ALPHA; - } - textSubMode = encodeText(msg, p, t, sb, textSubMode); - p += t; - } else { - int32_t b = determineConsecutiveBinaryCount(msg, &byteArr, p, e); - if (e != BCExceptionNO) - return L" "; - if (b == 0) { - b = 1; - } - if (b == 1 && encodingMode == TEXT_COMPACTION) { - encodeBinary(&byteArr, p, 1, TEXT_COMPACTION, sb); - } else { - encodeBinary(&byteArr, p, b, encodingMode, sb); - encodingMode = BYTE_COMPACTION; - textSubMode = SUBMODE_ALPHA; - } - p += b; - } - } - } - } - return sb; -} - -void CBC_PDF417HighLevelEncoder::Inverse() { - for (size_t l = 0; l < FX_ArraySize(MIXED); ++l) - MIXED[l] = -1; - - for (uint8_t i = 0; i < FX_ArraySize(TEXT_MIXED_RAW); ++i) { - uint8_t b = TEXT_MIXED_RAW[i]; - if (b != 0) - MIXED[b] = i; - } - - for (size_t l = 0; l < FX_ArraySize(PUNCTUATION); ++l) - PUNCTUATION[l] = -1; - - for (uint8_t i = 0; i < FX_ArraySize(TEXT_PUNCTUATION_RAW); ++i) { - uint8_t b = TEXT_PUNCTUATION_RAW[i]; - if (b != 0) - PUNCTUATION[b] = i; - } -} - -int32_t CBC_PDF417HighLevelEncoder::encodeText(CFX_WideString msg, - int32_t startpos, - int32_t count, - CFX_WideString& sb, - int32_t initialSubmode) { - CFX_WideString tmp; - int32_t submode = initialSubmode; - int32_t idx = 0; - while (true) { - wchar_t ch = msg.GetAt(startpos + idx); - switch (submode) { - case SUBMODE_ALPHA: - if (isAlphaUpper(ch)) { - if (ch == ' ') { - tmp += (wchar_t)26; - } else { - tmp += (wchar_t)(ch - 65); - } - } else { - if (isAlphaLower(ch)) { - submode = SUBMODE_LOWER; - tmp += (wchar_t)27; - continue; - } else if (isMixed(ch)) { - submode = SUBMODE_MIXED; - tmp += (wchar_t)28; - continue; - } else { - tmp += (wchar_t)29; - tmp += PUNCTUATION[ch]; - break; - } - } - break; - case SUBMODE_LOWER: - if (isAlphaLower(ch)) { - if (ch == ' ') { - tmp += (wchar_t)26; - } else { - tmp += (wchar_t)(ch - 97); - } - } else { - if (isAlphaUpper(ch)) { - tmp += (wchar_t)27; - tmp += (wchar_t)(ch - 65); - break; - } else if (isMixed(ch)) { - submode = SUBMODE_MIXED; - tmp += (wchar_t)28; - continue; - } else { - tmp += (wchar_t)29; - tmp += PUNCTUATION[ch]; - break; - } - } - break; - case SUBMODE_MIXED: - if (isMixed(ch)) { - tmp += MIXED[ch]; - } else { - if (isAlphaUpper(ch)) { - submode = SUBMODE_ALPHA; - tmp += (wchar_t)28; - continue; - } else if (isAlphaLower(ch)) { - submode = SUBMODE_LOWER; - tmp += (wchar_t)27; - continue; - } else { - if (startpos + idx + 1 < count) { - wchar_t next = msg.GetAt(startpos + idx + 1); - if (isPunctuation(next)) { - submode = SUBMODE_PUNCTUATION; - tmp += (wchar_t)25; - continue; - } - } - tmp += (wchar_t)29; - tmp += PUNCTUATION[ch]; - } - } - break; - default: - if (isPunctuation(ch)) { - tmp += PUNCTUATION[ch]; - } else { - submode = SUBMODE_ALPHA; - tmp += (wchar_t)29; - continue; - } - } - idx++; - if (idx >= count) { - break; - } - } - wchar_t h = 0; - int32_t len = tmp.GetLength(); - for (int32_t i = 0; i < len; i++) { - bool odd = (i % 2) != 0; - if (odd) { - h = (wchar_t)((h * 30) + tmp.GetAt(i)); - sb += h; - } else { - h = tmp.GetAt(i); - } - } - if ((len % 2) != 0) { - sb += (wchar_t)((h * 30) + 29); - } - return submode; -} -void CBC_PDF417HighLevelEncoder::encodeBinary(std::vector<uint8_t>* bytes, - int32_t startpos, - int32_t count, - int32_t startmode, - CFX_WideString& sb) { - if (count == 1 && startmode == TEXT_COMPACTION) { - sb += (wchar_t)SHIFT_TO_BYTE; - } - int32_t idx = startpos; - int32_t i = 0; - if (count >= 6) { - sb += (wchar_t)LATCH_TO_BYTE; - wchar_t chars[5]; - while ((startpos + count - idx) >= 6) { - int64_t t = 0; - for (i = 0; i < 6; i++) { - t <<= 8; - t += (*bytes)[idx + i] & 0xff; - } - for (i = 0; i < 5; i++) { - chars[i] = (wchar_t)(t % 900); - t /= 900; - } - for (i = 4; i >= 0; i--) { - sb += (chars[i]); - } - idx += 6; - } - } - if (idx < startpos + count) { - sb += (wchar_t)LATCH_TO_BYTE_PADDED; - } - for (i = idx; i < startpos + count; i++) { - int32_t ch = (*bytes)[i] & 0xff; - sb += (wchar_t)ch; - } -} -void CBC_PDF417HighLevelEncoder::encodeNumeric(CFX_WideString msg, - int32_t startpos, - int32_t count, - CFX_WideString& sb) { - int32_t idx = 0; - BigInteger num900 = 900; - while (idx < count) { - CFX_WideString tmp; - int32_t len = 44 < count - idx ? 44 : count - idx; - CFX_ByteString part = - ((wchar_t)'1' + msg.Mid(startpos + idx, len)).UTF8Encode(); - BigInteger bigint = stringToBigInteger(part.c_str()); - do { - int32_t c = (bigint % num900).toInt(); - tmp += (wchar_t)(c); - bigint = bigint / num900; - } while (!bigint.isZero()); - for (int32_t i = tmp.GetLength() - 1; i >= 0; i--) { - sb += tmp.GetAt(i); - } - idx += len; - } -} -bool CBC_PDF417HighLevelEncoder::isDigit(wchar_t ch) { - return ch >= '0' && ch <= '9'; -} -bool CBC_PDF417HighLevelEncoder::isAlphaUpper(wchar_t ch) { - return ch == ' ' || (ch >= 'A' && ch <= 'Z'); -} -bool CBC_PDF417HighLevelEncoder::isAlphaLower(wchar_t ch) { - return ch == ' ' || (ch >= 'a' && ch <= 'z'); -} -bool CBC_PDF417HighLevelEncoder::isMixed(wchar_t ch) { - return MIXED[ch] != -1; -} -bool CBC_PDF417HighLevelEncoder::isPunctuation(wchar_t ch) { - return PUNCTUATION[ch] != -1; -} -bool CBC_PDF417HighLevelEncoder::isText(wchar_t ch) { - return ch == '\t' || ch == '\n' || ch == '\r' || (ch >= 32 && ch <= 126); -} -int32_t CBC_PDF417HighLevelEncoder::determineConsecutiveDigitCount( - CFX_WideString msg, - int32_t startpos) { - int32_t count = 0; - int32_t len = msg.GetLength(); - int32_t idx = startpos; - if (idx < len) { - wchar_t ch = msg.GetAt(idx); - while (isDigit(ch) && idx < len) { - count++; - idx++; - if (idx < len) { - ch = msg.GetAt(idx); - } - } - } - return count; -} -int32_t CBC_PDF417HighLevelEncoder::determineConsecutiveTextCount( - CFX_WideString msg, - int32_t startpos) { - int32_t len = msg.GetLength(); - int32_t idx = startpos; - while (idx < len) { - wchar_t ch = msg.GetAt(idx); - int32_t numericCount = 0; - while (numericCount < 13 && isDigit(ch) && idx < len) { - numericCount++; - idx++; - if (idx < len) { - ch = msg.GetAt(idx); - } - } - if (numericCount >= 13) { - return idx - startpos - numericCount; - } - if (numericCount > 0) { - continue; - } - ch = msg.GetAt(idx); - if (!isText(ch)) { - break; - } - idx++; - } - return idx - startpos; -} -int32_t CBC_PDF417HighLevelEncoder::determineConsecutiveBinaryCount( - CFX_WideString msg, - std::vector<uint8_t>* bytes, - int32_t startpos, - int32_t& e) { - int32_t len = msg.GetLength(); - int32_t idx = startpos; - while (idx < len) { - wchar_t ch = msg.GetAt(idx); - int32_t numericCount = 0; - while (numericCount < 13 && isDigit(ch)) { - numericCount++; - int32_t i = idx + numericCount; - if (i >= len) { - break; - } - ch = msg.GetAt(i); - } - if (numericCount >= 13) { - return idx - startpos; - } - int32_t textCount = 0; - while (textCount < 5 && isText(ch)) { - textCount++; - int32_t i = idx + textCount; - if (i >= len) { - break; - } - ch = msg.GetAt(i); - } - if (textCount >= 5) { - return idx - startpos; - } - ch = msg.GetAt(idx); - if ((*bytes)[idx] == 63 && ch != '?') { - e = BCExceptionNonEncodableCharacterDetected; - return -1; - } - idx++; - } - return idx - startpos; -} diff --git a/xfa/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h b/xfa/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h deleted file mode 100644 index 48b8d009fc..0000000000 --- a/xfa/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h +++ /dev/null @@ -1,76 +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_FXBARCODE_PDF417_BC_PDF417HIGHLEVELENCODER_H_ -#define XFA_FXBARCODE_PDF417_BC_PDF417HIGHLEVELENCODER_H_ - -#include <vector> - -#include "core/fxcrt/fx_basic.h" -#include "core/fxcrt/fx_string.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Compaction.h" - -class CBC_PDF417HighLevelEncoder { - public: - static CFX_WideString encodeHighLevel(CFX_WideString msg, - Compaction compaction, - int32_t& e); - static void Inverse(); - static void Initialize(); - static void Finalize(); - - private: - static int32_t TEXT_COMPACTION; - static int32_t BYTE_COMPACTION; - static int32_t NUMERIC_COMPACTION; - static int32_t SUBMODE_PUNCTUATION; - static int32_t LATCH_TO_TEXT; - static int32_t LATCH_TO_BYTE_PADDED; - static int32_t LATCH_TO_NUMERIC; - static int32_t SHIFT_TO_BYTE; - static int32_t LATCH_TO_BYTE; - static uint8_t TEXT_MIXED_RAW[]; - static uint8_t TEXT_PUNCTUATION_RAW[]; - static int32_t MIXED[128]; - static int32_t PUNCTUATION[128]; - static int32_t encodeText(CFX_WideString msg, - int32_t startpos, - int32_t count, - CFX_WideString& sb, - int32_t initialSubmode); - static void encodeBinary(std::vector<uint8_t>* bytes, - int32_t startpos, - int32_t count, - int32_t startmode, - CFX_WideString& sb); - static void encodeNumeric(CFX_WideString msg, - int32_t startpos, - int32_t count, - CFX_WideString& sb); - static bool isDigit(wchar_t ch); - static bool isAlphaUpper(wchar_t ch); - static bool isAlphaLower(wchar_t ch); - static bool isMixed(wchar_t ch); - static bool isPunctuation(wchar_t ch); - static bool isText(wchar_t ch); - static int32_t determineConsecutiveDigitCount(CFX_WideString msg, - int32_t startpos); - static int32_t determineConsecutiveTextCount(CFX_WideString msg, - int32_t startpos); - static int32_t determineConsecutiveBinaryCount(CFX_WideString msg, - std::vector<uint8_t>* bytes, - int32_t startpos, - int32_t& e); - - friend class PDF417HighLevelEncoder_EncodeNumeric_Test; - friend class PDF417HighLevelEncoder_EncodeBinary_Test; - friend class PDF417HighLevelEncoder_EncodeText_Test; - friend class PDF417HighLevelEncoder_ConsecutiveDigitCount_Test; - friend class PDF417HighLevelEncoder_ConsecutiveTextCount_Test; - friend class PDF417HighLevelEncoder_ConsecutiveBinaryCount_Test; -}; - -#endif // XFA_FXBARCODE_PDF417_BC_PDF417HIGHLEVELENCODER_H_ diff --git a/xfa/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp b/xfa/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp deleted file mode 100644 index a1f3283dd8..0000000000 --- a/xfa/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp +++ /dev/null @@ -1,231 +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. - -#include "core/fxcrt/fx_basic.h" -#include "testing/fx_string_testhelpers.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h" - -TEST(PDF417HighLevelEncoder, EncodeHighLevel) { - // TODO(tsepez): implement test cases. -} - -TEST(PDF417HighLevelEncoder, EncodeText) { - // TODO(tsepez): implement test cases. -} - -TEST(PDF417HighLevelEncoder, EncodeBinary) { - struct EncodeBinaryCase { - const char* input; - int offset; - int count; - int startmode; - const wchar_t* expected; - int expected_length; - } encode_binary_cases[] = { - // Empty string encodes as empty string. - {"", 0, 0, CBC_PDF417HighLevelEncoder::TEXT_COMPACTION, L"", 0}, - - // Fewer than 6 characters encodes as prefix without compaction. - {"xxxxx", 0, 5, CBC_PDF417HighLevelEncoder::TEXT_COMPACTION, - L"\x0385xxxxx", 6}, - - // 6 charcters triggerst text encoding compaction. - {"xxxxxx", 0, 6, CBC_PDF417HighLevelEncoder::TEXT_COMPACTION, - L"\u039c\u00c9\u031f\u012a\u00d2\u02d0", 6}, - - // Same result if initially in numeric compaction mode. - {"xxxxxx", 0, 6, CBC_PDF417HighLevelEncoder::NUMERIC_COMPACTION, - L"\u039c\u00c9\u031f\u012a\u00d2\u02d0", 6}, - }; - - CBC_PDF417HighLevelEncoder::Initialize(); - for (size_t i = 0; i < FX_ArraySize(encode_binary_cases); ++i) { - EncodeBinaryCase* ptr = &encode_binary_cases[i]; - std::vector<uint8_t> input_array; - size_t input_length = strlen(ptr->input); - input_array.resize(input_length); - for (size_t j = 0; j < input_length; ++j) { - input_array[j] = ptr->input[j]; - } - CFX_WideString expected(ptr->expected, ptr->expected_length); - CFX_WideString result; - CBC_PDF417HighLevelEncoder::encodeBinary( - &input_array, ptr->offset, ptr->count, ptr->startmode, result); - EXPECT_EQ(expected, result) << " for case number " << i; - } - CBC_PDF417HighLevelEncoder::Finalize(); -} - -TEST(PDF417HighLevelEncoder, EncodeNumeric) { - struct EncodeNumericCase { - const wchar_t* input; - int offset; - int count; - const wchar_t* expected; - int expected_length; - } encode_numeric_cases[] = { - // Empty string encodes as empty string. - {L"", 0, 0, L"", 0}, - - // Single 0 should encode as 10 base-900 == a. - {L"0", 0, 1, L"\x000a", 1}, - - // 800 should encode as 1800 base-900 == 2,0. - {L"800", 0, 3, L"\x0002\x0000", 2}, - - // Test longer strings and sub-strings. - {L"123456", 0, 6, L"\x0001\x015c\x0100", 3}, - {L"123456", 0, 5, L"\x007c\x02e9", 2}, - {L"123456", 1, 5, L"\x0089\x009c", 2}, - {L"123456", 2, 2, L"\x0086", 1}, - - // Up to 44 characters encodes as 15 base-900 words. - {L"00000000000000000000000000000000000000000000", 0, 44, - L"\x01b5\x006f\x02cc\x0084\x01bc\x0076\x00b3\x005c\x01f0\x034f\x01e6" - L"\x0090\x020b\x019b\x0064", - 15}, - - // 45 characters should encode as same 15 words followed by one additional - // word. - {L"000000000000000000000000000000000000000000000", 0, 45, - L"\x01b5\x006f\x02cc\x0084\x01bc\x0076\x00b3\x005c\x01f0\x034f\x01e6" - L"\x0090\x020b\x019b\x0064\x000a", - 16}, - - // 44 characters followed by 800 should encode as 15 words followed by - // 1800 base-900 == 2,0. - {L"00000000000000000000000000000000000000000000800", 0, 47, - L"\x01b5\x006f\x02cc\x0084\x01bc\x0076\x00b3\x005c\x01f0\x034f\x01e6" - L"\x0090\x020b\x019b\x0064\x0002\x0000", - 17}, - - // Even longer input. - {L"10000000000000000000000000000000000000000000000000", 0, 50, - L"\x01e0\x02f0\x036d\x02ad\x029c\x01ea\x0011\x000b\x02d6\x023c\x0108" - L"\x02bb\x0023\x02d2\x00c8\x0001\x00d3\x0064", - 18}, - }; - - CBC_PDF417HighLevelEncoder::Initialize(); - for (size_t i = 0; i < FX_ArraySize(encode_numeric_cases); ++i) { - EncodeNumericCase* ptr = &encode_numeric_cases[i]; - CFX_WideString input(ptr->input); - CFX_WideString expected(ptr->expected, ptr->expected_length); - CFX_WideString result; - CBC_PDF417HighLevelEncoder::encodeNumeric(input, ptr->offset, ptr->count, - result); - EXPECT_EQ(expected, result) << " for case number " << i; - } - CBC_PDF417HighLevelEncoder::Finalize(); -} - -TEST(PDF417HighLevelEncoder, ConsecutiveDigitCount) { - struct ConsecutiveDigitCase { - const wchar_t* input; - int offset; - int expected_count; - } consecutive_digit_cases[] = { - // Empty string contains 0 consecuitve digits. - {L"", 0, 0}, - - // Single non-digit character contains 0 consecutive digits. - {L"X", 0, 0}, - - // Leading non-digit followed by digits contains 0 consecutive. - {L"X123", 0, 0}, - - // Single digit contains 1 consecutive digit. - {L"1", 0, 1}, - - // Single digit followe by non-digit contains 1 consecutive digit. - {L"1Z", 0, 1}, - - // Test longer strings. - {L"123FOO45678", 0, 3}, - - // Test subtring starting in digits field. - {L"123FOO45678", 3, 0}, - - // Test subtring starting in non-digits field. - {L"123FOO45678", 3, 0}, - - // Test substring starting in digits field following non-digit field. - {L"123FOO45678", 6, 5}, - }; - - CBC_PDF417HighLevelEncoder::Initialize(); - for (size_t i = 0; i < FX_ArraySize(consecutive_digit_cases); ++i) { - ConsecutiveDigitCase* ptr = &consecutive_digit_cases[i]; - CFX_WideString input(ptr->input); - int actual_count = - CBC_PDF417HighLevelEncoder::determineConsecutiveDigitCount(input, - ptr->offset); - EXPECT_EQ(ptr->expected_count, actual_count) << " for case number " << i; - } - CBC_PDF417HighLevelEncoder::Finalize(); -} - -TEST(PDF417HighLevelEncoder, ConsecutiveTextCount) { - struct ConsecutiveTextCase { - const wchar_t* input; - int offset; - int expected_count; - } consecutive_text_cases[] = { - // Empty string contains 0 consecutive text characters. - {L"", 0, 0}, - - // Single text character is 1 consecutive text characters. - {L"X", 0, 1}, - - // Trailing numbers count as text characters. - {L"X123", 0, 4}, - - // Leading numbers count as text characters. - {L"123X", 0, 4}, - - // Embedded lo-value binary characters terminate text runs. - {L"ABC\x0001XXXX", 0, 3}, - - // Embedded hi-value binary characters terminate text runs. - {L"ABC\x0100XXXX", 0, 3}, - - // Text run still found after indexing past lo-value character. - {L"ABC\x0001XXXX", 4, 4}, - - // Text run still found after indexing past hi-value character. - {L"ABC\x0100XXXX", 4, 4}, - - // Leading hi-value character results in 0 consecutive characters. - {L"\x0100XXX", 0, 0}, - - // Up to 12 numbers count as text. - {L"123456789012", 0, 12}, - - // 13 or more numbers are compresssed using numeric compression, not text. - {L"1234567890123", 0, 0}, - - // Leading Text character doesn't affect the 12 character case. - {L"X123456789012", 0, 13}, - - // Leading Text character doesn't affect the 13 character case. - {L"X1234567890123", 0, 1}, - - // Jumping between numbers and letters works properly. - {L"XXX121XXX12345678901234", 0, 9}, - }; - - CBC_PDF417HighLevelEncoder::Initialize(); - for (size_t i = 0; i < FX_ArraySize(consecutive_text_cases); ++i) { - ConsecutiveTextCase* ptr = &consecutive_text_cases[i]; - CFX_WideString input(ptr->input); - int actual_count = - CBC_PDF417HighLevelEncoder::determineConsecutiveTextCount(input, - ptr->offset); - EXPECT_EQ(ptr->expected_count, actual_count) << " for case number " << i; - } - CBC_PDF417HighLevelEncoder::Finalize(); -} - -TEST(PDF417HighLevelEncoder, ConsecutiveBinaryCount) {} diff --git a/xfa/fxbarcode/pdf417/BC_PDF417Writer.cpp b/xfa/fxbarcode/pdf417/BC_PDF417Writer.cpp deleted file mode 100644 index ddd740d12e..0000000000 --- a/xfa/fxbarcode/pdf417/BC_PDF417Writer.cpp +++ /dev/null @@ -1,113 +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 2012 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_TwoDimWriter.h" -#include "xfa/fxbarcode/common/BC_CommonBitArray.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Compaction.h" -#include "xfa/fxbarcode/pdf417/BC_PDF417Writer.h" - -CBC_PDF417Writer::CBC_PDF417Writer() { - m_bFixedSize = false; -} -CBC_PDF417Writer::~CBC_PDF417Writer() { - m_bTruncated = true; -} -bool CBC_PDF417Writer::SetErrorCorrectionLevel(int32_t level) { - if (level < 0 || level > 8) { - return false; - } - m_iCorrectLevel = level; - return true; -} -void CBC_PDF417Writer::SetTruncated(bool truncated) { - m_bTruncated = truncated; -} -uint8_t* CBC_PDF417Writer::Encode(const CFX_WideString& contents, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) { - CBC_PDF417 encoder; - int32_t col = (m_Width / m_ModuleWidth - 69) / 17; - int32_t row = m_Height / (m_ModuleWidth * 20); - if (row >= 3 && row <= 90 && col >= 1 && col <= 30) { - encoder.setDimensions(col, col, row, row); - } else if (col >= 1 && col <= 30) { - encoder.setDimensions(col, col, 90, 3); - } else if (row >= 3 && row <= 90) { - encoder.setDimensions(30, 1, row, row); - } - encoder.generateBarcodeLogic(contents, m_iCorrectLevel, e); - if (e != BCExceptionNO) - return nullptr; - int32_t lineThickness = 2; - int32_t aspectRatio = 4; - CBC_BarcodeMatrix* barcodeMatrix = encoder.getBarcodeMatrix(); - std::vector<uint8_t> originalScale = barcodeMatrix->getScaledMatrix( - lineThickness, aspectRatio * lineThickness); - int32_t width = outWidth; - int32_t height = outHeight; - outWidth = barcodeMatrix->getWidth(); - outHeight = barcodeMatrix->getHeight(); - bool rotated = false; - if ((height > width) ^ (outWidth < outHeight)) { - rotateArray(originalScale, outHeight, outWidth); - rotated = true; - int32_t temp = outHeight; - outHeight = outWidth; - outWidth = temp; - } - int32_t scaleX = width / outWidth; - int32_t scaleY = height / outHeight; - int32_t scale; - if (scaleX < scaleY) { - scale = scaleX; - } else { - scale = scaleY; - } - if (scale > 1) { - originalScale = barcodeMatrix->getScaledMatrix( - scale * lineThickness, scale * aspectRatio * lineThickness); - if (rotated) { - rotateArray(originalScale, outHeight, outWidth); - int32_t temp = outHeight; - outHeight = outWidth; - outWidth = temp; - } - } - uint8_t* result = FX_Alloc2D(uint8_t, outHeight, outWidth); - FXSYS_memcpy(result, originalScale.data(), outHeight * outWidth); - return result; -} -void CBC_PDF417Writer::rotateArray(std::vector<uint8_t>& bitarray, - int32_t height, - int32_t width) { - std::vector<uint8_t> temp = bitarray; - for (int32_t ii = 0; ii < height; ii++) { - int32_t inverseii = height - ii - 1; - for (int32_t jj = 0; jj < width; jj++) { - bitarray[jj * height + inverseii] = temp[ii * width + jj]; - } - } -} diff --git a/xfa/fxbarcode/pdf417/BC_PDF417Writer.h b/xfa/fxbarcode/pdf417/BC_PDF417Writer.h deleted file mode 100644 index 564f80849c..0000000000 --- a/xfa/fxbarcode/pdf417/BC_PDF417Writer.h +++ /dev/null @@ -1,38 +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_FXBARCODE_PDF417_BC_PDF417WRITER_H_ -#define XFA_FXBARCODE_PDF417_BC_PDF417WRITER_H_ - -#include <vector> - -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "xfa/fxbarcode/BC_TwoDimWriter.h" - -class CBC_PDF417Writer : public CBC_TwoDimWriter { - public: - CBC_PDF417Writer(); - ~CBC_PDF417Writer() override; - - uint8_t* Encode(const CFX_WideString& contents, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e); - - // CBC_TwoDimWriter - bool SetErrorCorrectionLevel(int32_t level) override; - - void SetTruncated(bool truncated); - - private: - void rotateArray(std::vector<uint8_t>& bitarray, - int32_t width, - int32_t height); - bool m_bTruncated; -}; - -#endif // XFA_FXBARCODE_PDF417_BC_PDF417WRITER_H_ diff --git a/xfa/fxbarcode/qrcode/BC_QRCodeWriter.cpp b/xfa/fxbarcode/qrcode/BC_QRCodeWriter.cpp deleted file mode 100644 index 8a6499cbb7..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCodeWriter.cpp +++ /dev/null @@ -1,122 +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 2008 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_TwoDimWriter.h" -#include "xfa/fxbarcode/common/BC_CommonByteMatrix.h" -#include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" -#include "xfa/fxbarcode/qrcode/BC_QRCodeWriter.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoder.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderEncoder.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderMode.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderVersion.h" - -CBC_QRCodeWriter::CBC_QRCodeWriter() { - m_bFixedSize = true; - m_iCorrectLevel = 1; - m_iVersion = 0; -} - -CBC_QRCodeWriter::~CBC_QRCodeWriter() {} - -void CBC_QRCodeWriter::ReleaseAll() { - delete CBC_ReedSolomonGF256::QRCodeField; - CBC_ReedSolomonGF256::QRCodeField = nullptr; - delete CBC_ReedSolomonGF256::DataMatrixField; - CBC_ReedSolomonGF256::DataMatrixField = nullptr; - CBC_QRCoderMode::Destroy(); - CBC_QRCoderErrorCorrectionLevel::Destroy(); - CBC_QRCoderVersion::Destroy(); -} - -bool CBC_QRCodeWriter::SetVersion(int32_t version) { - if (version < 0 || version > 40) { - return false; - } - m_iVersion = version; - return true; -} - -bool CBC_QRCodeWriter::SetErrorCorrectionLevel(int32_t level) { - if (level < 0 || level > 3) { - return false; - } - m_iCorrectLevel = level; - return true; -} - -uint8_t* CBC_QRCodeWriter::Encode(const CFX_WideString& contents, - int32_t ecLevel, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) { - CBC_QRCoderErrorCorrectionLevel* ec = nullptr; - switch (ecLevel) { - case 0: - ec = CBC_QRCoderErrorCorrectionLevel::L; - break; - case 1: - ec = CBC_QRCoderErrorCorrectionLevel::M; - break; - case 2: - ec = CBC_QRCoderErrorCorrectionLevel::Q; - break; - case 3: - ec = CBC_QRCoderErrorCorrectionLevel::H; - break; - default: { - e = BCExceptionUnSupportEclevel; - return nullptr; - } - } - CBC_QRCoder qr; - if (m_iVersion > 0 && m_iVersion < 41) { - CFX_ByteString byteStr = contents.UTF8Encode(); - CBC_QRCoderEncoder::Encode(byteStr, ec, &qr, e, m_iVersion); - } else { - CBC_QRCoderEncoder::Encode(contents, ec, &qr, e); - } - if (e != BCExceptionNO) - return nullptr; - outWidth = qr.GetMatrixWidth(); - outHeight = qr.GetMatrixWidth(); - uint8_t* result = FX_Alloc2D(uint8_t, outWidth, outHeight); - FXSYS_memcpy(result, qr.GetMatrix()->GetArray(), outWidth * outHeight); - return result; -} - -uint8_t* CBC_QRCodeWriter::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e) { - return nullptr; -} - -uint8_t* CBC_QRCodeWriter::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) { - return nullptr; -} diff --git a/xfa/fxbarcode/qrcode/BC_QRCodeWriter.h b/xfa/fxbarcode/qrcode/BC_QRCodeWriter.h deleted file mode 100644 index 5585fa55c1..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCodeWriter.h +++ /dev/null @@ -1,45 +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_FXBARCODE_QRCODE_BC_QRCODEWRITER_H_ -#define XFA_FXBARCODE_QRCODE_BC_QRCODEWRITER_H_ - -#include "xfa/fxbarcode/BC_TwoDimWriter.h" - -class CBC_TwoDimWriter; -class CBC_QRCodeWriter : public CBC_TwoDimWriter { - public: - CBC_QRCodeWriter(); - ~CBC_QRCodeWriter() override; - - uint8_t* Encode(const CFX_WideString& contents, - int32_t ecLevel, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e); - uint8_t* Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e); - uint8_t* Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e); - bool SetVersion(int32_t version); - - // CBC_TwoDimWriter - bool SetErrorCorrectionLevel(int32_t level) override; - - static void ReleaseAll(); - - private: - int32_t m_iVersion; -}; - -#endif // XFA_FXBARCODE_QRCODE_BC_QRCODEWRITER_H_ diff --git a/xfa/fxbarcode/qrcode/BC_QRCoder.cpp b/xfa/fxbarcode/qrcode/BC_QRCoder.cpp deleted file mode 100644 index a5c849780d..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoder.cpp +++ /dev/null @@ -1,145 +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 2008 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 <utility> - -#include "xfa/fxbarcode/common/BC_CommonByteMatrix.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoder.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderMode.h" -#include "xfa/fxbarcode/utils.h" - -CBC_QRCoder::CBC_QRCoder() - : m_mode(nullptr), - m_ecLevel(nullptr), - m_version(-1), - m_matrixWidth(-1), - m_maskPattern(-1), - m_numTotalBytes(-1), - m_numDataBytes(-1), - m_numECBytes(-1), - m_numRSBlocks(-1) {} - -CBC_QRCoder::~CBC_QRCoder() {} - -CBC_QRCoderMode* CBC_QRCoder::GetMode() const { - return m_mode; -} - -CBC_QRCoderErrorCorrectionLevel* CBC_QRCoder::GetECLevel() const { - return m_ecLevel; -} - -int32_t CBC_QRCoder::GetVersion() const { - return m_version; -} - -int32_t CBC_QRCoder::GetMatrixWidth() const { - return m_matrixWidth; -} - -int32_t CBC_QRCoder::GetMaskPattern() const { - return m_maskPattern; -} - -int32_t CBC_QRCoder::GetNumTotalBytes() const { - return m_numTotalBytes; -} - -int32_t CBC_QRCoder::GetNumDataBytes() const { - return m_numDataBytes; -} - -int32_t CBC_QRCoder::GetNumECBytes() const { - return m_numECBytes; -} - -int32_t CBC_QRCoder::GetNumRSBlocks() const { - return m_numRSBlocks; -} - -CBC_CommonByteMatrix* CBC_QRCoder::GetMatrix() const { - return m_matrix.get(); -} - -int32_t CBC_QRCoder::At(int32_t x, int32_t y, int32_t& e) { - int32_t value = m_matrix->Get(x, y); - if (!(value == 0 || value == 1)) { - e = BCExceptionValueMustBeEither0or1; - return 0; - } - return value; -} - -bool CBC_QRCoder::IsValid() { - return m_mode && m_ecLevel && m_version != -1 && m_matrixWidth != -1 && - m_maskPattern != -1 && m_numTotalBytes != -1 && m_numDataBytes != -1 && - m_numECBytes != -1 && m_numRSBlocks != -1 && - IsValidMaskPattern(m_maskPattern) && - m_numTotalBytes == m_numDataBytes + m_numECBytes && m_matrix && - m_matrixWidth == m_matrix->GetWidth() && - m_matrix->GetWidth() == m_matrix->GetHeight(); -} - -void CBC_QRCoder::SetMode(CBC_QRCoderMode* value) { - m_mode = value; -} - -void CBC_QRCoder::SetECLevel(CBC_QRCoderErrorCorrectionLevel* ecLevel) { - m_ecLevel = ecLevel; -} - -void CBC_QRCoder::SetVersion(int32_t version) { - m_version = version; -} - -void CBC_QRCoder::SetMatrixWidth(int32_t width) { - m_matrixWidth = width; -} - -void CBC_QRCoder::SetMaskPattern(int32_t pattern) { - m_maskPattern = pattern; -} - -void CBC_QRCoder::SetNumDataBytes(int32_t bytes) { - m_numDataBytes = bytes; -} - -void CBC_QRCoder::SetNumTotalBytes(int32_t value) { - m_numTotalBytes = value; -} - -void CBC_QRCoder::SetNumRSBlocks(int32_t block) { - m_numRSBlocks = block; -} - -void CBC_QRCoder::SetNumECBytes(int32_t value) { - m_numECBytes = value; -} - -bool CBC_QRCoder::IsValidMaskPattern(int32_t maskPattern) { - return maskPattern >= 0 && maskPattern < kNumMaskPatterns; -} - -void CBC_QRCoder::SetMatrix(std::unique_ptr<CBC_CommonByteMatrix> pMatrix) { - m_matrix = std::move(pMatrix); -} diff --git a/xfa/fxbarcode/qrcode/BC_QRCoder.h b/xfa/fxbarcode/qrcode/BC_QRCoder.h deleted file mode 100644 index 5e949920a7..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoder.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXBARCODE_QRCODE_BC_QRCODER_H_ -#define XFA_FXBARCODE_QRCODE_BC_QRCODER_H_ - -#include <memory> - -class CBC_QRCoderErrorCorrectionLevel; -class CBC_QRCoderMode; -class CBC_CommonByteMatrix; - -class CBC_QRCoder { - public: - static constexpr int32_t kNumMaskPatterns = 8; - - CBC_QRCoder(); - virtual ~CBC_QRCoder(); - - static bool IsValidMaskPattern(int32_t maskPattern); - - CBC_QRCoderMode* GetMode() const; - CBC_QRCoderErrorCorrectionLevel* GetECLevel() const; - int32_t GetVersion() const; - int32_t GetMatrixWidth() const; - int32_t GetMaskPattern() const; - int32_t GetNumTotalBytes() const; - int32_t GetNumDataBytes() const; - int32_t GetNumECBytes() const; - int32_t GetNumRSBlocks() const; - CBC_CommonByteMatrix* GetMatrix() const; - - int32_t At(int32_t x, int32_t y, int32_t& e); - bool IsValid(); - - void SetMode(CBC_QRCoderMode* value); - void SetECLevel(CBC_QRCoderErrorCorrectionLevel* ecLevel); - void SetVersion(int32_t version); - void SetMatrixWidth(int32_t width); - void SetMaskPattern(int32_t pattern); - void SetNumDataBytes(int32_t bytes); - void SetNumTotalBytes(int32_t value); - void SetNumECBytes(int32_t value); - void SetNumRSBlocks(int32_t block); - void SetMatrix(std::unique_ptr<CBC_CommonByteMatrix> pMatrix); - - private: - CBC_QRCoderMode* m_mode; - CBC_QRCoderErrorCorrectionLevel* m_ecLevel; - int32_t m_version; - int32_t m_matrixWidth; - int32_t m_maskPattern; - int32_t m_numTotalBytes; - int32_t m_numDataBytes; - int32_t m_numECBytes; - int32_t m_numRSBlocks; - std::unique_ptr<CBC_CommonByteMatrix> m_matrix; -}; - -#endif // XFA_FXBARCODE_QRCODE_BC_QRCODER_H_ diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderBitVector.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderBitVector.cpp deleted file mode 100644 index e4140a87a0..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderBitVector.cpp +++ /dev/null @@ -1,127 +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 2007 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 "core/fxcrt/fx_memory.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderBitVector.h" -#include "xfa/fxbarcode/utils.h" - -CBC_QRCoderBitVector::CBC_QRCoderBitVector() { - m_sizeInBits = 0; - m_size = 32; -} -void CBC_QRCoderBitVector::Init() { - m_array = FX_Alloc(uint8_t, m_size); -} -CBC_QRCoderBitVector::~CBC_QRCoderBitVector() { - FX_Free(m_array); -} -void CBC_QRCoderBitVector::Clear() { - FX_Free(m_array); - m_sizeInBits = 0; - m_size = 32; - m_array = FX_Alloc(uint8_t, m_size); -} -int32_t CBC_QRCoderBitVector::At(int32_t index, int32_t& e) { - if (index < 0 || index >= m_sizeInBits) { - e = BCExceptionBadIndexException; - return 0; - } - int32_t value = m_array[index >> 3] & 0xff; - return (value >> (7 - (index & 0x7))) & 1; -} -int32_t CBC_QRCoderBitVector::sizeInBytes() { - return (m_sizeInBits + 7) >> 3; -} -int32_t CBC_QRCoderBitVector::Size() { - return m_sizeInBits; -} -void CBC_QRCoderBitVector::AppendBit(int32_t bit, int32_t& e) { - if (!(bit == 0 || bit == 1)) { - e = BCExceptionBadValueException; - return; - } - int32_t numBitsInLastByte = m_sizeInBits & 0x7; - if (numBitsInLastByte == 0) { - AppendByte(0); - m_sizeInBits -= 8; - } - m_array[m_sizeInBits >> 3] |= (bit << (7 - numBitsInLastByte)); - ++m_sizeInBits; -} -void CBC_QRCoderBitVector::AppendBits(int32_t value, - int32_t numBits, - int32_t& e) { - if (numBits < 0 || numBits > 32) { - e = BCExceptionBadNumBitsException; - return; - } - int32_t numBitsLeft = numBits; - while (numBitsLeft > 0) { - if ((m_sizeInBits & 0x7) == 0 && numBitsLeft >= 8) { - int32_t newByte = (value >> (numBitsLeft - 8)) & 0xff; - AppendByte(newByte); - numBitsLeft -= 8; - } else { - int32_t bit = (value >> (numBitsLeft - 1)) & 1; - AppendBit(bit, e); - if (e != BCExceptionNO) - return; - --numBitsLeft; - } - } -} -void CBC_QRCoderBitVector::AppendBitVector(CBC_QRCoderBitVector* bits, - int32_t& e) { - int32_t size = bits->Size(); - for (int32_t i = 0; i < size; i++) { - int32_t num = bits->At(i, e); - if (e != BCExceptionNO) - return; - AppendBit(num, e); - if (e != BCExceptionNO) - return; - } -} -void CBC_QRCoderBitVector::XOR(CBC_QRCoderBitVector* other, int32_t& e) { - if (m_sizeInBits != other->Size()) { - e = BCExceptioncanNotOperatexorOperator; - return; - } - int32_t sizeInBytes = (m_sizeInBits + 7) >> 3; - for (int32_t i = 0; i < sizeInBytes; ++i) { - m_array[i] ^= (other->GetArray())[i]; - } -} -uint8_t* CBC_QRCoderBitVector::GetArray() { - return m_array; -} -void CBC_QRCoderBitVector::AppendByte(int32_t value) { - if ((m_sizeInBits >> 3) == m_size) { - uint8_t* newArray = FX_Alloc(uint8_t, m_size << 1); - FXSYS_memcpy(newArray, m_array, m_size); - FX_Free(m_array); - m_array = newArray; - m_size = m_size << 1; - } - m_array[m_sizeInBits >> 3] = (uint8_t)value; - m_sizeInBits += 8; -} diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderBitVector.h b/xfa/fxbarcode/qrcode/BC_QRCoderBitVector.h deleted file mode 100644 index 7742541a06..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderBitVector.h +++ /dev/null @@ -1,35 +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_FXBARCODE_QRCODE_BC_QRCODERBITVECTOR_H_ -#define XFA_FXBARCODE_QRCODE_BC_QRCODERBITVECTOR_H_ - -#include <stdint.h> - -class CBC_QRCoderBitVector { - private: - int32_t m_sizeInBits; - uint8_t* m_array; - int32_t m_size; - - void AppendByte(int32_t value); - - public: - CBC_QRCoderBitVector(); - virtual ~CBC_QRCoderBitVector(); - int32_t At(int32_t index, int32_t& e); - int32_t Size(); - int32_t sizeInBytes(); - void AppendBit(int32_t bit, int32_t& e); - void AppendBits(int32_t value, int32_t numBits, int32_t& e); - void AppendBitVector(CBC_QRCoderBitVector* bits, int32_t& e); - void XOR(CBC_QRCoderBitVector* other, int32_t& e); - uint8_t* GetArray(); - void Clear(); - virtual void Init(); -}; - -#endif // XFA_FXBARCODE_QRCODE_BC_QRCODERBITVECTOR_H_ diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.cpp deleted file mode 100644 index 8dc73c4be4..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.cpp +++ /dev/null @@ -1,44 +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 2008 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/qrcode/BC_QRCoderBlockPair.h" - -#include <utility> - -#include "xfa/fxbarcode/common/BC_CommonByteArray.h" - -CBC_QRCoderBlockPair::CBC_QRCoderBlockPair( - std::unique_ptr<CBC_CommonByteArray> data, - std::unique_ptr<CBC_CommonByteArray> errorCorrection) - : m_dataBytes(std::move(data)), - m_errorCorrectionBytes(std::move(errorCorrection)) {} - -CBC_QRCoderBlockPair::~CBC_QRCoderBlockPair() {} - -const CBC_CommonByteArray* CBC_QRCoderBlockPair::GetDataBytes() const { - return m_dataBytes.get(); -} - -const CBC_CommonByteArray* CBC_QRCoderBlockPair::GetErrorCorrectionBytes() - const { - return m_errorCorrectionBytes.get(); -} diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h b/xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h deleted file mode 100644 index 4259d6badd..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h +++ /dev/null @@ -1,28 +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_FXBARCODE_QRCODE_BC_QRCODERBLOCKPAIR_H_ -#define XFA_FXBARCODE_QRCODE_BC_QRCODERBLOCKPAIR_H_ - -#include <memory> - -class CBC_CommonByteArray; - -class CBC_QRCoderBlockPair { - public: - CBC_QRCoderBlockPair(std::unique_ptr<CBC_CommonByteArray> data, - std::unique_ptr<CBC_CommonByteArray> errorCorrection); - virtual ~CBC_QRCoderBlockPair(); - - const CBC_CommonByteArray* GetDataBytes() const; - const CBC_CommonByteArray* GetErrorCorrectionBytes() const; - - private: - std::unique_ptr<CBC_CommonByteArray> m_dataBytes; - std::unique_ptr<CBC_CommonByteArray> m_errorCorrectionBytes; -}; - -#endif // XFA_FXBARCODE_QRCODE_BC_QRCODERBLOCKPAIR_H_ diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderECB.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderECB.cpp deleted file mode 100644 index 2b5a2a6fef..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderECB.cpp +++ /dev/null @@ -1,35 +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 2007 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/qrcode/BC_QRCoderECB.h" - -CBC_QRCoderECB::CBC_QRCoderECB(int32_t count, int32_t dataCodeWords) { - m_dataCodeWords = dataCodeWords; - m_count = count; -} -CBC_QRCoderECB::~CBC_QRCoderECB() {} -int32_t CBC_QRCoderECB::GetCount() { - return m_count; -} -int32_t CBC_QRCoderECB::GetDataCodeWords() { - return m_dataCodeWords; -} diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderECB.h b/xfa/fxbarcode/qrcode/BC_QRCoderECB.h deleted file mode 100644 index 25b0b20fe3..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderECB.h +++ /dev/null @@ -1,24 +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_FXBARCODE_QRCODE_BC_QRCODERECB_H_ -#define XFA_FXBARCODE_QRCODE_BC_QRCODERECB_H_ - -#include <stdint.h> - -class CBC_QRCoderECB { - private: - int32_t m_count; - int32_t m_dataCodeWords; - - public: - CBC_QRCoderECB(int32_t count, int32_t dataCodeWords); - virtual ~CBC_QRCoderECB(); - int32_t GetCount(); - int32_t GetDataCodeWords(); -}; - -#endif // XFA_FXBARCODE_QRCODE_BC_QRCODERECB_H_ diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderECBlocks.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderECBlocks.cpp deleted file mode 100644 index 8894695e95..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderECBlocks.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -// Original code is licensed as follows: -/* - * Copyright 2007 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/qrcode/BC_QRCoderECB.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderECBlocks.h" - -CBC_QRCoderECBlocks::CBC_QRCoderECBlocks(int32_t ecCodeWordsPerBlock, - CBC_QRCoderECB* ecBlocks) - : m_ecCodeWordsPerBlock(ecCodeWordsPerBlock) { - m_ecBlocksArray.push_back(ecBlocks); -} - -CBC_QRCoderECBlocks::CBC_QRCoderECBlocks(int32_t ecCodeWordsPerBlock, - CBC_QRCoderECB* ecBlocks1, - CBC_QRCoderECB* ecBlocks2) - : m_ecCodeWordsPerBlock(ecCodeWordsPerBlock) { - m_ecBlocksArray.push_back(ecBlocks1); - m_ecBlocksArray.push_back(ecBlocks2); -} - -CBC_QRCoderECBlocks::~CBC_QRCoderECBlocks() { - for (size_t i = 0; i < m_ecBlocksArray.size(); i++) - delete m_ecBlocksArray[i]; -} - -int32_t CBC_QRCoderECBlocks::GetECCodeWordsPerBlock() const { - return m_ecCodeWordsPerBlock; -} - -int32_t CBC_QRCoderECBlocks::GetNumBlocks() const { - int32_t total = 0; - for (size_t i = 0; i < m_ecBlocksArray.size(); i++) - total += m_ecBlocksArray[i]->GetCount(); - - return total; -} - -int32_t CBC_QRCoderECBlocks::GetTotalECCodeWords() const { - return m_ecCodeWordsPerBlock * GetNumBlocks(); -} - -std::vector<CBC_QRCoderECB*>* CBC_QRCoderECBlocks::GetECBlocks() { - return &m_ecBlocksArray; -} diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderECBlocks.h b/xfa/fxbarcode/qrcode/BC_QRCoderECBlocks.h deleted file mode 100644 index 816a983ce5..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderECBlocks.h +++ /dev/null @@ -1,34 +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_FXBARCODE_QRCODE_BC_QRCODERECBLOCKS_H_ -#define XFA_FXBARCODE_QRCODE_BC_QRCODERECBLOCKS_H_ - -#include <vector> - -#include "core/fxcrt/fx_basic.h" - -class CBC_QRCoderECB; - -class CBC_QRCoderECBlocks { - public: - CBC_QRCoderECBlocks(int32_t ecCodeWordsPerBlock, CBC_QRCoderECB* ecBlocks); - CBC_QRCoderECBlocks(int32_t ecCodeWordsPerBlock, - CBC_QRCoderECB* ecBlocks1, - CBC_QRCoderECB* ecBlocks2); - ~CBC_QRCoderECBlocks(); - - int32_t GetECCodeWordsPerBlock() const; - int32_t GetNumBlocks() const; - int32_t GetTotalECCodeWords() const; - std::vector<CBC_QRCoderECB*>* GetECBlocks(); - - private: - int32_t m_ecCodeWordsPerBlock; - std::vector<CBC_QRCoderECB*> m_ecBlocksArray; -}; - -#endif // XFA_FXBARCODE_QRCODE_BC_QRCODERECBLOCKS_H_ diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp deleted file mode 100644 index 2534675877..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp +++ /dev/null @@ -1,970 +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 2008 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/qrcode/BC_QRCoderEncoder.h" - -#include <algorithm> -#include <memory> -#include <utility> - -#include "xfa/fxbarcode/BC_UtilCodingConvert.h" -#include "xfa/fxbarcode/common/BC_CommonByteArray.h" -#include "xfa/fxbarcode/common/BC_CommonByteMatrix.h" -#include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.h" -#include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoder.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderBitVector.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderECBlocks.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderMode.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderVersion.h" - -namespace { - -const int8_t g_alphaNumericTable[] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, - -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1}; - -} // namespace - -CBC_QRCoderEncoder::CBC_QRCoderEncoder() {} - -CBC_QRCoderEncoder::~CBC_QRCoderEncoder() {} - -void CBC_QRCoderEncoder::Encode(const CFX_ByteString& content, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - CBC_QRCoder* qrCode, - int32_t& e, - int32_t versionSpecify) { - if (versionSpecify == 0) { - EncodeWithAutoVersion(content, ecLevel, qrCode, e); - if (e != BCExceptionNO) - return; - } else if (versionSpecify > 0 && versionSpecify <= 40) { - EncodeWithSpecifyVersion(content, ecLevel, qrCode, versionSpecify, e); - if (e != BCExceptionNO) - return; - } else { - e = BCExceptionVersionMust1_40; - if (e != BCExceptionNO) - return; - } -} - -void CBC_QRCoderEncoder::AppendECI(CBC_QRCoderBitVector* bits) {} - -void CBC_QRCoderEncoder::AppendDataModeLenghInfo( - const std::vector<std::pair<CBC_QRCoderMode*, CFX_ByteString>>& - splitResults, - CBC_QRCoderBitVector& headerAndDataBits, - CBC_QRCoderMode* tempMode, - CBC_QRCoder* qrCode, - CFX_ByteString& encoding, - int32_t& e) { - for (const auto& splitResult : splitResults) { - tempMode = splitResult.first; - if (tempMode == CBC_QRCoderMode::sGBK) { - AppendModeInfo(tempMode, &headerAndDataBits, e); - if (e != BCExceptionNO) - return; - AppendLengthInfo(splitResult.second.GetLength(), qrCode->GetVersion(), - tempMode, &headerAndDataBits, e); - if (e != BCExceptionNO) - return; - AppendBytes(splitResult.second, tempMode, &headerAndDataBits, encoding, - e); - if (e != BCExceptionNO) - return; - } else if (tempMode == CBC_QRCoderMode::sBYTE) { - std::vector<uint8_t> bytes; - CBC_UtilCodingConvert::LocaleToUtf8(splitResult.second, bytes); - AppendModeInfo(tempMode, &headerAndDataBits, e); - if (e != BCExceptionNO) - return; - AppendLengthInfo(bytes.size(), qrCode->GetVersion(), tempMode, - &headerAndDataBits, e); - if (e != BCExceptionNO) - return; - Append8BitBytes(bytes, &headerAndDataBits, e); - if (e != BCExceptionNO) - return; - } else if (tempMode == CBC_QRCoderMode::sALPHANUMERIC) { - AppendModeInfo(tempMode, &headerAndDataBits, e); - if (e != BCExceptionNO) - return; - AppendLengthInfo(splitResult.second.GetLength(), qrCode->GetVersion(), - tempMode, &headerAndDataBits, e); - if (e != BCExceptionNO) - return; - AppendBytes(splitResult.second, tempMode, &headerAndDataBits, encoding, - e); - if (e != BCExceptionNO) - return; - } else if (tempMode == CBC_QRCoderMode::sNUMERIC) { - AppendModeInfo(tempMode, &headerAndDataBits, e); - if (e != BCExceptionNO) - return; - AppendLengthInfo(splitResult.second.GetLength(), qrCode->GetVersion(), - tempMode, &headerAndDataBits, e); - if (e != BCExceptionNO) - return; - AppendBytes(splitResult.second, tempMode, &headerAndDataBits, encoding, - e); - if (e != BCExceptionNO) - return; - } else { - e = BCExceptionUnknown; - return; - } - } -} - -void CBC_QRCoderEncoder::SplitString( - const CFX_ByteString& content, - std::vector<std::pair<CBC_QRCoderMode*, CFX_ByteString>>* result) { - int32_t index = 0, flag = 0; - while ( - (((uint8_t)content[index] >= 0xA1 && (uint8_t)content[index] <= 0xAA) || - ((uint8_t)content[index] >= 0xB0 && (uint8_t)content[index] <= 0xFA)) && - (index < content.GetLength())) { - index += 2; - } - if (index != flag) { - result->push_back({CBC_QRCoderMode::sGBK, content.Mid(flag, index - flag)}); - } - flag = index; - if (index >= content.GetLength()) { - return; - } - while ( - GetAlphaNumericCode((uint8_t)content[index]) == -1 && - !(((uint8_t)content[index] >= 0xA1 && (uint8_t)content[index] <= 0xAA) || - ((uint8_t)content[index] >= 0xB0 && (uint8_t)content[index] <= 0xFA)) && - (index < content.GetLength())) { -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - if (IsDBCSLeadByte((uint8_t)content[index])) -#else - if ((uint8_t)content[index] > 127) -#endif - { - index += 2; - } else { - index++; - } - } - if (index != flag) { - result->push_back( - {CBC_QRCoderMode::sBYTE, content.Mid(flag, index - flag)}); - } - flag = index; - if (index >= content.GetLength()) { - return; - } - while (FXSYS_Isdigit((uint8_t)content[index]) && - (index < content.GetLength())) { - index++; - } - if (index != flag) { - result->push_back( - {CBC_QRCoderMode::sNUMERIC, content.Mid(flag, index - flag)}); - } - flag = index; - if (index >= content.GetLength()) { - return; - } - while (GetAlphaNumericCode((uint8_t)content[index]) != -1 && - (index < content.GetLength())) { - index++; - } - if (index != flag) { - result->push_back( - {CBC_QRCoderMode::sALPHANUMERIC, content.Mid(flag, index - flag)}); - } - flag = index; - if (index < content.GetLength()) - SplitString(content.Mid(index, content.GetLength() - index), result); -} - -int32_t CBC_QRCoderEncoder::GetSpanByVersion(CBC_QRCoderMode* modeFirst, - CBC_QRCoderMode* modeSecond, - int32_t versionNum, - int32_t& e) { - if (versionNum == 0) - return 0; - - if (modeFirst == CBC_QRCoderMode::sALPHANUMERIC && - modeSecond == CBC_QRCoderMode::sBYTE) { - if (versionNum >= 1 && versionNum <= 9) - return 11; - if (versionNum >= 10 && versionNum <= 26) - return 15; - if (versionNum >= 27 && versionNum <= 40) - return 16; - e = BCExceptionNoSuchVersion; - return 0; - } - if (modeSecond == CBC_QRCoderMode::sALPHANUMERIC && - modeFirst == CBC_QRCoderMode::sNUMERIC) { - if (versionNum >= 1 && versionNum <= 9) - return 13; - if (versionNum >= 10 && versionNum <= 26) - return 15; - if (versionNum >= 27 && versionNum <= 40) - return 17; - e = BCExceptionNoSuchVersion; - return 0; - } - if (modeSecond == CBC_QRCoderMode::sBYTE && - modeFirst == CBC_QRCoderMode::sNUMERIC) { - if (versionNum >= 1 && versionNum <= 9) - return 6; - if (versionNum >= 10 && versionNum <= 26) - return 8; - if (versionNum >= 27 && versionNum <= 40) - return 9; - e = BCExceptionNoSuchVersion; - return 0; - } - return -1; -} - -void CBC_QRCoderEncoder::MergeString( - std::vector<std::pair<CBC_QRCoderMode*, CFX_ByteString>>* result, - int32_t versionNum, - int32_t& e) { - size_t mergeNum = 0; - for (size_t i = 0; i + 1 < result->size(); i++) { - auto* element1 = &(*result)[i]; - auto* element2 = &(*result)[i + 1]; - if (element1->first == CBC_QRCoderMode::sALPHANUMERIC) { - int32_t tmp = GetSpanByVersion(CBC_QRCoderMode::sALPHANUMERIC, - CBC_QRCoderMode::sBYTE, versionNum, e); - if (e != BCExceptionNO) - return; - if (element2->first == CBC_QRCoderMode::sBYTE && - element1->second.GetLength() < tmp) { - element2->second = element1->second + element2->second; - result->erase(result->begin() + i); - i--; - mergeNum++; - } - } else if (element1->first == CBC_QRCoderMode::sBYTE) { - if (element2->first == CBC_QRCoderMode::sBYTE) { - element1->second += element2->second; - result->erase(result->begin() + i + 1); - i--; - mergeNum++; - } - } else if (element1->first == CBC_QRCoderMode::sNUMERIC) { - int32_t tmp = GetSpanByVersion(CBC_QRCoderMode::sNUMERIC, - CBC_QRCoderMode::sBYTE, versionNum, e); - if (e != BCExceptionNO) - return; - if (element2->first == CBC_QRCoderMode::sBYTE && - element1->second.GetLength() < tmp) { - element2->second = element1->second + element2->second; - result->erase(result->begin() + i); - i--; - mergeNum++; - } - tmp = GetSpanByVersion(CBC_QRCoderMode::sNUMERIC, - CBC_QRCoderMode::sALPHANUMERIC, versionNum, e); - if (e != BCExceptionNO) - return; - if (element2->first == CBC_QRCoderMode::sALPHANUMERIC && - element1->second.GetLength() < tmp) { - element2->second = element1->second + element2->second; - result->erase(result->begin() + i); - i--; - mergeNum++; - } - } - } - if (mergeNum == 0) { - return; - } - MergeString(result, versionNum, e); - if (e != BCExceptionNO) - return; -} - -void CBC_QRCoderEncoder::InitQRCode(int32_t numInputBytes, - int32_t versionNumber, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - CBC_QRCoderMode* mode, - CBC_QRCoder* qrCode, - int32_t& e) { - qrCode->SetECLevel(ecLevel); - qrCode->SetMode(mode); - CBC_QRCoderVersion* version = - CBC_QRCoderVersion::GetVersionForNumber(versionNumber, e); - if (e != BCExceptionNO) - return; - int32_t numBytes = version->GetTotalCodeWords(); - CBC_QRCoderECBlocks* ecBlocks = version->GetECBlocksForLevel(ecLevel); - int32_t numEcBytes = ecBlocks->GetTotalECCodeWords(); - int32_t numRSBlocks = ecBlocks->GetNumBlocks(); - int32_t numDataBytes = numBytes - numEcBytes; - if (numDataBytes < numInputBytes + 3) { - e = BCExceptionCannotFindBlockInfo; - return; - } - qrCode->SetVersion(versionNumber); - qrCode->SetNumTotalBytes(numBytes); - qrCode->SetNumDataBytes(numDataBytes); - qrCode->SetNumRSBlocks(numRSBlocks); - qrCode->SetNumECBytes(numEcBytes); - qrCode->SetMatrixWidth(version->GetDimensionForVersion()); -} - -void CBC_QRCoderEncoder::EncodeWithSpecifyVersion( - const CFX_ByteString& content, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - CBC_QRCoder* qrCode, - int32_t versionSpecify, - int32_t& e) { - CFX_ByteString encoding = "utf8"; - CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; - std::vector<std::pair<CBC_QRCoderMode*, CFX_ByteString>> splitResult; - CBC_QRCoderBitVector dataBits; - dataBits.Init(); - SplitString(content, &splitResult); - MergeString(&splitResult, versionSpecify, e); - if (e != BCExceptionNO) - return; - CBC_QRCoderMode* tempMode = nullptr; - for (const auto& result : splitResult) { - AppendBytes(result.second, result.first, &dataBits, encoding, e); - if (e != BCExceptionNO) - return; - } - int32_t numInputBytes = dataBits.sizeInBytes(); - CBC_QRCoderBitVector headerAndDataBits; - headerAndDataBits.Init(); - InitQRCode(numInputBytes, versionSpecify, ecLevel, mode, qrCode, e); - if (e != BCExceptionNO) - return; - - AppendDataModeLenghInfo(splitResult, headerAndDataBits, tempMode, qrCode, - encoding, e); - if (e != BCExceptionNO) - return; - - numInputBytes = headerAndDataBits.sizeInBytes(); - TerminateBits(qrCode->GetNumDataBytes(), &headerAndDataBits, e); - if (e != BCExceptionNO) - return; - - CBC_QRCoderBitVector finalBits; - finalBits.Init(); - InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), - qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(), - &finalBits, e); - if (e != BCExceptionNO) - return; - - std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix( - qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); - matrix->Init(); - int32_t maskPattern = ChooseMaskPattern( - &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e); - if (e != BCExceptionNO) - return; - - qrCode->SetMaskPattern(maskPattern); - CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(), - qrCode->GetVersion(), - qrCode->GetMaskPattern(), matrix.get(), e); - if (e != BCExceptionNO) - return; - - qrCode->SetMatrix(std::move(matrix)); - if (!qrCode->IsValid()) - e = BCExceptionInvalidQRCode; -} - -void CBC_QRCoderEncoder::EncodeWithAutoVersion( - const CFX_ByteString& content, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - CBC_QRCoder* qrCode, - int32_t& e) { - CFX_ByteString encoding = "utf8"; - CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; - std::vector<std::pair<CBC_QRCoderMode*, CFX_ByteString>> splitResult; - CBC_QRCoderBitVector dataBits; - dataBits.Init(); - SplitString(content, &splitResult); - MergeString(&splitResult, 8, e); - if (e != BCExceptionNO) - return; - CBC_QRCoderMode* tempMode = nullptr; - for (const auto& result : splitResult) { - AppendBytes(result.second, result.first, &dataBits, encoding, e); - if (e != BCExceptionNO) - return; - } - int32_t numInputBytes = dataBits.sizeInBytes(); - InitQRCode(numInputBytes, ecLevel, mode, qrCode, e); - if (e != BCExceptionNO) - return; - CBC_QRCoderBitVector headerAndDataBits; - headerAndDataBits.Init(); - tempMode = nullptr; - int32_t versionNum = qrCode->GetVersion(); -sign: - AppendDataModeLenghInfo(splitResult, headerAndDataBits, tempMode, qrCode, - encoding, e); - if (e != BCExceptionNO) { - goto catchException; - } - numInputBytes = headerAndDataBits.sizeInBytes(); - TerminateBits(qrCode->GetNumDataBytes(), &headerAndDataBits, e); - if (e != BCExceptionNO) { - goto catchException; - } -catchException: - if (e != BCExceptionNO) { - int32_t e1 = BCExceptionNO; - InitQRCode(numInputBytes, ecLevel, mode, qrCode, e1); - if (e1 != BCExceptionNO) { - e = e1; - return; - } - versionNum++; - if (versionNum <= 40) { - headerAndDataBits.Clear(); - e = BCExceptionNO; - goto sign; - } else { - return; - } - } - - CBC_QRCoderBitVector finalBits; - finalBits.Init(); - InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), - qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(), - &finalBits, e); - if (e != BCExceptionNO) - return; - - std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix( - qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); - matrix->Init(); - int32_t maskPattern = ChooseMaskPattern( - &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e); - if (e != BCExceptionNO) - return; - - qrCode->SetMaskPattern(maskPattern); - CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(), - qrCode->GetVersion(), - qrCode->GetMaskPattern(), matrix.get(), e); - if (e != BCExceptionNO) - return qrCode->SetMatrix(std::move(matrix)); - - if (!qrCode->IsValid()) - e = BCExceptionInvalidQRCode; -} - -void CBC_QRCoderEncoder::Encode(const CFX_WideString& content, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - CBC_QRCoder* qrCode, - int32_t& e) { - CFX_ByteString encoding = "utf8"; - CFX_ByteString utf8Data; - CBC_UtilCodingConvert::UnicodeToUTF8(content, utf8Data); - CBC_QRCoderMode* mode = ChooseMode(utf8Data, encoding); - CBC_QRCoderBitVector dataBits; - dataBits.Init(); - AppendBytes(utf8Data, mode, &dataBits, encoding, e); - if (e != BCExceptionNO) - return; - int32_t numInputBytes = dataBits.sizeInBytes(); - InitQRCode(numInputBytes, ecLevel, mode, qrCode, e); - if (e != BCExceptionNO) - return; - CBC_QRCoderBitVector headerAndDataBits; - headerAndDataBits.Init(); - AppendModeInfo(mode, &headerAndDataBits, e); - if (e != BCExceptionNO) - return; - int32_t numLetters = mode == CBC_QRCoderMode::sBYTE ? dataBits.sizeInBytes() - : content.GetLength(); - AppendLengthInfo(numLetters, qrCode->GetVersion(), mode, &headerAndDataBits, - e); - if (e != BCExceptionNO) - return; - headerAndDataBits.AppendBitVector(&dataBits, e); - if (e != BCExceptionNO) - return TerminateBits(qrCode->GetNumDataBytes(), &headerAndDataBits, e); - if (e != BCExceptionNO) - return; - CBC_QRCoderBitVector finalBits; - finalBits.Init(); - InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), - qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(), - &finalBits, e); - if (e != BCExceptionNO) - return; - - std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix( - qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); - matrix->Init(); - int32_t maskPattern = ChooseMaskPattern( - &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e); - if (e != BCExceptionNO) - return; - - qrCode->SetMaskPattern(maskPattern); - CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(), - qrCode->GetVersion(), - qrCode->GetMaskPattern(), matrix.get(), e); - if (e != BCExceptionNO) - return qrCode->SetMatrix(std::move(matrix)); - - if (!qrCode->IsValid()) - e = BCExceptionInvalidQRCode; -} - -void CBC_QRCoderEncoder::TerminateBits(int32_t numDataBytes, - CBC_QRCoderBitVector* bits, - int32_t& e) { - int32_t capacity = numDataBytes << 3; - if (bits->Size() > capacity) { - e = BCExceptionDataTooMany; - return; - } - for (int32_t i = 0; i < 4 && bits->Size() < capacity; ++i) { - bits->AppendBit(0, e); - if (e != BCExceptionNO) - return; - } - int32_t numBitsInLastByte = bits->Size() % 8; - if (numBitsInLastByte > 0) { - int32_t numPaddingBits = 8 - numBitsInLastByte; - for (int32_t j = 0; j < numPaddingBits; ++j) { - bits->AppendBit(0, e); - if (e != BCExceptionNO) - return; - } - } - if (bits->Size() % 8 != 0) { - e = BCExceptionDigitLengthMustBe8; - return; - } - int32_t numPaddingBytes = numDataBytes - bits->sizeInBytes(); - for (int32_t k = 0; k < numPaddingBytes; ++k) { - if (k % 2 == 0) { - bits->AppendBits(0xec, 8, e); - if (e != BCExceptionNO) - return; - } else { - bits->AppendBits(0x11, 8, e); - if (e != BCExceptionNO) - return; - } - } - if (bits->Size() != capacity) - e = BCExceptionBitsNotEqualCacity; -} - -int32_t CBC_QRCoderEncoder::ChooseMaskPattern( - CBC_QRCoderBitVector* bits, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - int32_t version, - CBC_CommonByteMatrix* matrix, - int32_t& e) { - int32_t minPenalty = 65535; - int32_t bestMaskPattern = -1; - for (int32_t maskPattern = 0; maskPattern < CBC_QRCoder::kNumMaskPatterns; - maskPattern++) { - CBC_QRCoderMatrixUtil::BuildMatrix(bits, ecLevel, version, maskPattern, - matrix, e); - if (e != BCExceptionNO) - return 0; - int32_t penalty = CalculateMaskPenalty(matrix); - if (penalty < minPenalty) { - minPenalty = penalty; - bestMaskPattern = maskPattern; - } - } - return bestMaskPattern; -} - -int32_t CBC_QRCoderEncoder::CalculateMaskPenalty(CBC_CommonByteMatrix* matrix) { - int32_t penalty = 0; - penalty += CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule1(matrix); - penalty += CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule2(matrix); - penalty += CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule3(matrix); - penalty += CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule4(matrix); - return penalty; -} - -CBC_QRCoderMode* CBC_QRCoderEncoder::ChooseMode(const CFX_ByteString& content, - CFX_ByteString encoding) { - if (encoding.Compare("SHIFT_JIS") == 0) { - return CBC_QRCoderMode::sKANJI; - } - bool hasNumeric = false; - bool hasAlphaNumeric = false; - for (int32_t i = 0; i < content.GetLength(); i++) { - if (isdigit((uint8_t)content[i])) { - hasNumeric = true; - } else if (GetAlphaNumericCode((uint8_t)content[i]) != -1) { - hasAlphaNumeric = true; - } else { - return CBC_QRCoderMode::sBYTE; - } - } - if (hasAlphaNumeric) { - return CBC_QRCoderMode::sALPHANUMERIC; - } else if (hasNumeric) { - return CBC_QRCoderMode::sNUMERIC; - } - return CBC_QRCoderMode::sBYTE; -} - -int32_t CBC_QRCoderEncoder::GetAlphaNumericCode(int32_t code) { - return (code >= 0 && code < 96) ? g_alphaNumericTable[code] : -1; -} - -void CBC_QRCoderEncoder::AppendBytes(const CFX_ByteString& content, - CBC_QRCoderMode* mode, - CBC_QRCoderBitVector* bits, - CFX_ByteString encoding, - int32_t& e) { - if (mode == CBC_QRCoderMode::sNUMERIC) - AppendNumericBytes(content, bits, e); - else if (mode == CBC_QRCoderMode::sALPHANUMERIC) - AppendAlphaNumericBytes(content, bits, e); - else if (mode == CBC_QRCoderMode::sBYTE) - Append8BitBytes(content, bits, encoding, e); - else if (mode == CBC_QRCoderMode::sKANJI) - AppendKanjiBytes(content, bits, e); - else if (mode == CBC_QRCoderMode::sGBK) - AppendGBKBytes(content, bits, e); - else - e = BCExceptionUnsupportedMode; -} - -void CBC_QRCoderEncoder::AppendNumericBytes(const CFX_ByteString& content, - CBC_QRCoderBitVector* bits, - int32_t& e) { - int32_t length = content.GetLength(); - int32_t i = 0; - while (i < length) { - int32_t num1 = content[i] - '0'; - if (i + 2 < length) { - int32_t num2 = content[i + 1] - '0'; - int32_t num3 = content[i + 2] - '0'; - bits->AppendBits(num1 * 100 + num2 * 10 + num3, 10, e); - if (e != BCExceptionNO) - return; - i += 3; - } else if (i + 1 < length) { - int32_t num2 = content[i + 1] - '0'; - bits->AppendBits(num1 * 10 + num2, 7, e); - if (e != BCExceptionNO) - return; - i += 2; - } else { - bits->AppendBits(num1, 4, e); - if (e != BCExceptionNO) - return; - i++; - } - } -} - -void CBC_QRCoderEncoder::AppendAlphaNumericBytes(const CFX_ByteString& content, - CBC_QRCoderBitVector* bits, - int32_t& e) { - int32_t length = content.GetLength(); - int32_t i = 0; - while (i < length) { - int32_t code1 = GetAlphaNumericCode(content[i]); - if (code1 == -1) { - e = BCExceptionInvalidateCharacter; - return; - } - if (i + 1 < length) { - int32_t code2 = GetAlphaNumericCode(content[i + 1]); - if (code2 == -1) { - e = BCExceptionInvalidateCharacter; - return; - } - bits->AppendBits(code1 * 45 + code2, 11, e); - if (e != BCExceptionNO) - return; - i += 2; - } else { - bits->AppendBits(code1, 6, e); - if (e != BCExceptionNO) - return; - i++; - } - } -} - -void CBC_QRCoderEncoder::AppendGBKBytes(const CFX_ByteString& content, - CBC_QRCoderBitVector* bits, - int32_t& e) { - int32_t length = content.GetLength(); - uint32_t value = 0; - for (int32_t i = 0; i < length; i += 2) { - value = (uint32_t)((uint8_t)content[i] << 8 | (uint8_t)content[i + 1]); - if (value <= 0xAAFE && value >= 0xA1A1) { - value -= 0xA1A1; - } else if (value <= 0xFAFE && value >= 0xB0A1) { - value -= 0xA6A1; - } else { - e = BCExceptionInvalidateCharacter; - return; - } - value = (uint32_t)((value >> 8) * 0x60) + (uint32_t)(value & 0xff); - bits->AppendBits(value, 13, e); - if (e != BCExceptionNO) - return; - } -} - -void CBC_QRCoderEncoder::Append8BitBytes(const CFX_ByteString& content, - CBC_QRCoderBitVector* bits, - CFX_ByteString encoding, - int32_t& e) { - for (int32_t i = 0; i < content.GetLength(); i++) { - bits->AppendBits(content[i], 8, e); - if (e != BCExceptionNO) - return; - } -} - -void CBC_QRCoderEncoder::Append8BitBytes(std::vector<uint8_t>& bytes, - CBC_QRCoderBitVector* bits, - int32_t& e) { - for (size_t i = 0; i < bytes.size(); i++) { - bits->AppendBits(bytes[i], 8, e); - if (e != BCExceptionNO) - return; - } -} - -void CBC_QRCoderEncoder::AppendKanjiBytes(const CFX_ByteString& content, - CBC_QRCoderBitVector* bits, - int32_t& e) { - std::vector<uint8_t> bytes; - uint32_t value = 0; - for (size_t i = 0; i < bytes.size(); i += 2) { - value = (uint32_t)((uint8_t)(content[i] << 8) | (uint8_t)content[i + 1]); - if (value <= 0x9ffc && value >= 0x8140) { - value -= 0x8140; - } else if (value <= 0xebbf && value >= 0xe040) { - value -= 0xc140; - } else { - e = BCExceptionInvalidateCharacter; - return; - } - value = (uint32_t)((value >> 8) * 0xc0) + (uint32_t)(value & 0xff); - bits->AppendBits(value, 13, e); - if (e != BCExceptionNO) - return; - } -} - -void CBC_QRCoderEncoder::InitQRCode(int32_t numInputBytes, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - CBC_QRCoderMode* mode, - CBC_QRCoder* qrCode, - int32_t& e) { - qrCode->SetECLevel(ecLevel); - qrCode->SetMode(mode); - for (int32_t versionNum = 1; versionNum <= 40; versionNum++) { - CBC_QRCoderVersion* version = - CBC_QRCoderVersion::GetVersionForNumber(versionNum, e); - if (e != BCExceptionNO) - return; - int32_t numBytes = version->GetTotalCodeWords(); - CBC_QRCoderECBlocks* ecBlocks = version->GetECBlocksForLevel(ecLevel); - int32_t numEcBytes = ecBlocks->GetTotalECCodeWords(); - int32_t numRSBlocks = ecBlocks->GetNumBlocks(); - int32_t numDataBytes = numBytes - numEcBytes; - if (numDataBytes >= numInputBytes + 3) { - qrCode->SetVersion(versionNum); - qrCode->SetNumTotalBytes(numBytes); - qrCode->SetNumDataBytes(numDataBytes); - qrCode->SetNumRSBlocks(numRSBlocks); - qrCode->SetNumECBytes(numEcBytes); - qrCode->SetMatrixWidth(version->GetDimensionForVersion()); - return; - } - } - e = BCExceptionCannotFindBlockInfo; -} - -void CBC_QRCoderEncoder::AppendModeInfo(CBC_QRCoderMode* mode, - CBC_QRCoderBitVector* bits, - int32_t& e) { - bits->AppendBits(mode->GetBits(), 4, e); - if (mode == CBC_QRCoderMode::sGBK) - bits->AppendBits(1, 4, e); -} - -void CBC_QRCoderEncoder::AppendLengthInfo(int32_t numLetters, - int32_t version, - CBC_QRCoderMode* mode, - CBC_QRCoderBitVector* bits, - int32_t& e) { - CBC_QRCoderVersion* qcv = CBC_QRCoderVersion::GetVersionForNumber(version, e); - if (e != BCExceptionNO) - return; - int32_t numBits = mode->GetCharacterCountBits(qcv, e); - if (e != BCExceptionNO) - return; - if (numBits > ((1 << numBits) - 1)) { - return; - } - if (mode == CBC_QRCoderMode::sGBK) { - bits->AppendBits(numLetters / 2, numBits, e); - if (e != BCExceptionNO) - return; - } - bits->AppendBits(numLetters, numBits, e); -} - -void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits, - int32_t numTotalBytes, - int32_t numDataBytes, - int32_t numRSBlocks, - CBC_QRCoderBitVector* result, - int32_t& e) { - if (bits->sizeInBytes() != numDataBytes) { - e = BCExceptionBitsBytesNotMatch; - return; - } - int32_t dataBytesOffset = 0; - int32_t maxNumDataBytes = 0; - int32_t maxNumEcBytes = 0; - std::vector<CBC_QRCoderBlockPair*> blocks; - int32_t i; - for (i = 0; i < numRSBlocks; i++) { - int32_t numDataBytesInBlock; - int32_t numEcBytesInBlosk; - GetNumDataBytesAndNumECBytesForBlockID(numTotalBytes, numDataBytes, - numRSBlocks, i, numDataBytesInBlock, - numEcBytesInBlosk); - std::unique_ptr<CBC_CommonByteArray> dataBytes(new CBC_CommonByteArray); - dataBytes->Set(bits->GetArray(), dataBytesOffset, numDataBytesInBlock); - std::unique_ptr<CBC_CommonByteArray> ecBytes( - GenerateECBytes(dataBytes.get(), numEcBytesInBlosk, e)); - if (e != BCExceptionNO) - return; - maxNumDataBytes = std::max(maxNumDataBytes, dataBytes->Size()); - maxNumEcBytes = std::max(maxNumEcBytes, ecBytes->Size()); - blocks.push_back( - new CBC_QRCoderBlockPair(std::move(dataBytes), std::move(ecBytes))); - dataBytesOffset += numDataBytesInBlock; - } - if (numDataBytes != dataBytesOffset) { - e = BCExceptionBytesNotMatchOffset; - return; - } - for (int32_t x = 0; x < maxNumDataBytes; x++) { - for (size_t j = 0; j < blocks.size(); j++) { - const CBC_CommonByteArray* dataBytes = blocks[j]->GetDataBytes(); - if (x < dataBytes->Size()) { - result->AppendBits(dataBytes->At(x), 8, e); - if (e != BCExceptionNO) - return; - } - } - } - for (int32_t y = 0; y < maxNumEcBytes; y++) { - for (size_t l = 0; l < blocks.size(); l++) { - const CBC_CommonByteArray* ecBytes = blocks[l]->GetErrorCorrectionBytes(); - if (y < ecBytes->Size()) { - result->AppendBits(ecBytes->At(y), 8, e); - if (e != BCExceptionNO) - return; - } - } - } - for (size_t k = 0; k < blocks.size(); k++) { - delete blocks[k]; - } - if (numTotalBytes != result->sizeInBytes()) - e = BCExceptionSizeInBytesDiffer; -} - -void CBC_QRCoderEncoder::GetNumDataBytesAndNumECBytesForBlockID( - int32_t numTotalBytes, - int32_t numDataBytes, - int32_t numRSBlocks, - int32_t blockID, - int32_t& numDataBytesInBlock, - int32_t& numECBytesInBlock) { - if (blockID >= numRSBlocks) { - return; - } - int32_t numRsBlocksInGroup2 = numTotalBytes % numRSBlocks; - int32_t numRsBlocksInGroup1 = numRSBlocks - numRsBlocksInGroup2; - int32_t numTotalBytesInGroup1 = numTotalBytes / numRSBlocks; - int32_t numTotalBytesInGroup2 = numTotalBytesInGroup1 + 1; - int32_t numDataBytesInGroup1 = numDataBytes / numRSBlocks; - int32_t numDataBytesInGroup2 = numDataBytesInGroup1 + 1; - int32_t numEcBytesInGroup1 = numTotalBytesInGroup1 - numDataBytesInGroup1; - int32_t numEcBytesInGroup2 = numTotalBytesInGroup2 - numDataBytesInGroup2; - if (blockID < numRsBlocksInGroup1) { - numDataBytesInBlock = numDataBytesInGroup1; - numECBytesInBlock = numEcBytesInGroup1; - } else { - numDataBytesInBlock = numDataBytesInGroup2; - numECBytesInBlock = numEcBytesInGroup2; - } -} - -CBC_CommonByteArray* CBC_QRCoderEncoder::GenerateECBytes( - CBC_CommonByteArray* dataBytes, - int32_t numEcBytesInBlock, - int32_t& e) { - int32_t numDataBytes = dataBytes->Size(); - std::vector<int32_t> toEncode(numDataBytes + numEcBytesInBlock); - for (int32_t i = 0; i < numDataBytes; i++) { - toEncode[i] = (dataBytes->At(i)); - } - CBC_ReedSolomonEncoder encode(CBC_ReedSolomonGF256::QRCodeField); - encode.Init(); - encode.Encode(&toEncode, numEcBytesInBlock, e); - if (e != BCExceptionNO) - return nullptr; - CBC_CommonByteArray* ecBytes = new CBC_CommonByteArray(numEcBytesInBlock); - for (int32_t j = 0; j < numEcBytesInBlock; j++) { - ecBytes->Set(j, toEncode[numDataBytes + j]); - } - return ecBytes; -} diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.h b/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.h deleted file mode 100644 index 77de6e5e40..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.h +++ /dev/null @@ -1,140 +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_FXBARCODE_QRCODE_BC_QRCODERENCODER_H_ -#define XFA_FXBARCODE_QRCODE_BC_QRCODERENCODER_H_ - -#include <utility> -#include <vector> - -#include "core/fxcrt/fx_basic.h" -#include "core/fxcrt/fx_string.h" - -class CBC_QRCoder; -class CBC_QRCoderErrorCorrectionLevel; -class CBC_QRCoderMode; -class CBC_QRCoderBitVector; -class CBC_CommonByteArray; -class CBC_CommonByteMatrix; - -class CBC_QRCoderEncoder { - public: - CBC_QRCoderEncoder(); - virtual ~CBC_QRCoderEncoder(); - - static void Encode(const CFX_ByteString& content, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - CBC_QRCoder* qrCode, - int32_t& e, - int32_t versionSpecify = 0); - static void Encode(const CFX_WideString& content, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - CBC_QRCoder* qrCode, - int32_t& e); - static void EncodeWithSpecifyVersion(const CFX_ByteString& content, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - CBC_QRCoder* qrCode, - int32_t versionSpecify, - int32_t& e); - static void EncodeWithAutoVersion(const CFX_ByteString& content, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - CBC_QRCoder* qrCode, - int32_t& e); - static CBC_QRCoderMode* ChooseMode(const CFX_ByteString& content, - CFX_ByteString encoding); - static int32_t GetAlphaNumericCode(int32_t code); - static void AppendECI(CBC_QRCoderBitVector* bits); - static void AppendBytes(const CFX_ByteString& content, - CBC_QRCoderMode* mode, - CBC_QRCoderBitVector* bits, - CFX_ByteString encoding, - int32_t& e); - static void AppendNumericBytes(const CFX_ByteString& content, - CBC_QRCoderBitVector* bits, - int32_t& e); - static void AppendAlphaNumericBytes(const CFX_ByteString& content, - CBC_QRCoderBitVector* bits, - int32_t& e); - static void Append8BitBytes(const CFX_ByteString& content, - CBC_QRCoderBitVector* bits, - CFX_ByteString encoding, - int32_t& e); - static void Append8BitBytes(std::vector<uint8_t>& bytes, - CBC_QRCoderBitVector* bits, - int32_t& e); - static void AppendKanjiBytes(const CFX_ByteString& content, - CBC_QRCoderBitVector* bits, - int32_t& e); - static void AppendGBKBytes(const CFX_ByteString& content, - CBC_QRCoderBitVector* bits, - int32_t& e); - static void InitQRCode(int32_t numInputBytes, - int32_t versionNumber, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - CBC_QRCoderMode* mode, - CBC_QRCoder* qrCode, - int32_t& e); - static void InitQRCode(int32_t numInputBytes, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - CBC_QRCoderMode* mode, - CBC_QRCoder* qrCode, - int32_t& e); - static void AppendModeInfo(CBC_QRCoderMode* mode, - CBC_QRCoderBitVector* bits, - int32_t& e); - static void AppendLengthInfo(int32_t numLetters, - int32_t version, - CBC_QRCoderMode* mode, - CBC_QRCoderBitVector* bits, - int32_t& e); - - static void InterleaveWithECBytes(CBC_QRCoderBitVector* bits, - int32_t numTotalBytes, - int32_t numDataBytes, - int32_t numRSBlocks, - CBC_QRCoderBitVector* result, - int32_t& e); - static void GetNumDataBytesAndNumECBytesForBlockID( - int32_t numTotalBytes, - int32_t numDataBytes, - int32_t numRSBlocks, - int32_t blockID, - int32_t& numDataBytesInBlock, - int32_t& numECBytesInBlocks); - static CBC_CommonByteArray* GenerateECBytes(CBC_CommonByteArray* dataBytes, - int32_t numEcBytesInBlock, - int32_t& e); - static int32_t ChooseMaskPattern(CBC_QRCoderBitVector* bits, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - int32_t version, - CBC_CommonByteMatrix* matrix, - int32_t& e); - static int32_t CalculateMaskPenalty(CBC_CommonByteMatrix* matrix); - static void TerminateBits(int32_t numDataBytes, - CBC_QRCoderBitVector* bits, - int32_t& e); - static int32_t GetSpanByVersion(CBC_QRCoderMode* modeFirst, - CBC_QRCoderMode* modeSecond, - int32_t versionNum, - int32_t& e); - static void MergeString( - std::vector<std::pair<CBC_QRCoderMode*, CFX_ByteString>>* result, - int32_t versionNum, - int32_t& e); - static void SplitString( - const CFX_ByteString& content, - std::vector<std::pair<CBC_QRCoderMode*, CFX_ByteString>>* result); - static void AppendDataModeLenghInfo( - const std::vector<std::pair<CBC_QRCoderMode*, CFX_ByteString>>& - splitResult, - CBC_QRCoderBitVector& headerAndDataBits, - CBC_QRCoderMode* tempMode, - CBC_QRCoder* qrCode, - CFX_ByteString& encoding, - int32_t& e); -}; - -#endif // XFA_FXBARCODE_QRCODE_BC_QRCODERENCODER_H_ diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.cpp deleted file mode 100644 index 2990d980fc..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.cpp +++ /dev/null @@ -1,84 +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 2007 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/qrcode/BC_QRCoderErrorCorrectionLevel.h" - -CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::L = nullptr; -CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::M = nullptr; -CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::Q = nullptr; -CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::H = nullptr; - -CBC_QRCoderErrorCorrectionLevel::CBC_QRCoderErrorCorrectionLevel( - int32_t ordinal, - int32_t bits, - const char* name) - : m_ordinal(ordinal), m_bits(bits), m_name(name) {} - -CBC_QRCoderErrorCorrectionLevel::~CBC_QRCoderErrorCorrectionLevel() {} - -void CBC_QRCoderErrorCorrectionLevel::Initialize() { - L = new CBC_QRCoderErrorCorrectionLevel(0, 0x01, "L"); - M = new CBC_QRCoderErrorCorrectionLevel(1, 0x00, "M"); - Q = new CBC_QRCoderErrorCorrectionLevel(2, 0x03, "Q"); - H = new CBC_QRCoderErrorCorrectionLevel(3, 0x02, "H"); -} - -void CBC_QRCoderErrorCorrectionLevel::Finalize() { - delete L; - delete M; - delete Q; - delete H; -} - -CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::ForBits( - int32_t bits) { - switch (bits) { - case 0x00: - return M; - case 0x01: - return L; - case 0x02: - return H; - case 0x03: - return Q; - default: - return nullptr; - } -} -void CBC_QRCoderErrorCorrectionLevel::Destroy() { - if (L) { - delete CBC_QRCoderErrorCorrectionLevel::L; - L = nullptr; - } - if (M) { - delete CBC_QRCoderErrorCorrectionLevel::M; - M = nullptr; - } - if (H) { - delete CBC_QRCoderErrorCorrectionLevel::H; - H = nullptr; - } - if (Q) { - delete CBC_QRCoderErrorCorrectionLevel::Q; - Q = nullptr; - } -} diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h b/xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h deleted file mode 100644 index 2f0d22eb29..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h +++ /dev/null @@ -1,41 +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_FXBARCODE_QRCODE_BC_QRCODERERRORCORRECTIONLEVEL_H_ -#define XFA_FXBARCODE_QRCODE_BC_QRCODERERRORCORRECTIONLEVEL_H_ - -#include "core/fxcrt/fx_string.h" - -class CBC_QRCoderErrorCorrectionLevel { - public: - static CBC_QRCoderErrorCorrectionLevel* L; - static CBC_QRCoderErrorCorrectionLevel* M; - static CBC_QRCoderErrorCorrectionLevel* Q; - static CBC_QRCoderErrorCorrectionLevel* H; - - static void Initialize(); - static void Finalize(); - static void Destroy(); - static CBC_QRCoderErrorCorrectionLevel* ForBits(int32_t bits); - - ~CBC_QRCoderErrorCorrectionLevel(); - - int32_t Ordinal() const { return m_ordinal; } - int32_t GetBits() const { return m_bits; } - CFX_ByteString GetName() const { return m_name; } - - private: - CBC_QRCoderErrorCorrectionLevel(int32_t ordinal, - int32_t bits, - const char* name); - CBC_QRCoderErrorCorrectionLevel(); - - int32_t m_ordinal; - int32_t m_bits; - CFX_ByteString m_name; -}; - -#endif // XFA_FXBARCODE_QRCODE_BC_QRCODERERRORCORRECTIONLEVEL_H_ diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.cpp deleted file mode 100644 index 7953701bb2..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.cpp +++ /dev/null @@ -1,198 +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 2008 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/common/BC_CommonByteMatrix.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoder.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.h" -#include "xfa/fxbarcode/utils.h" - -CBC_QRCoderMaskUtil::CBC_QRCoderMaskUtil() {} -CBC_QRCoderMaskUtil::~CBC_QRCoderMaskUtil() {} -int32_t CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule1( - CBC_CommonByteMatrix* matrix) { - return ApplyMaskPenaltyRule1Internal(matrix, true) + - ApplyMaskPenaltyRule1Internal(matrix, false); -} - -int32_t CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule2( - CBC_CommonByteMatrix* matrix) { - int32_t penalty = 0; - uint8_t* array = matrix->GetArray(); - int32_t width = matrix->GetWidth(); - int32_t height = matrix->GetHeight(); - for (int32_t y = 0; y < height - 1; y++) { - for (int32_t x = 0; x < width - 1; x++) { - int32_t value = array[y * width + x]; - if (value == array[y * width + x + 1] && - value == array[(y + 1) * width + x] && - value == array[(y + 1) * width + x + 1]) { - penalty++; - } - } - } - return 3 * penalty; -} - -int32_t CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule3( - CBC_CommonByteMatrix* matrix) { - int32_t penalty = 0; - uint8_t* array = matrix->GetArray(); - int32_t width = matrix->GetWidth(); - int32_t height = matrix->GetHeight(); - for (int32_t y = 0; y < height; ++y) { - for (int32_t x = 0; x < width; ++x) { - if (x == 0 && - ((y >= 0 && y <= 6) || (y >= height - 7 && y <= height - 1))) { - continue; - } - if (x == width - 7 && (y >= 0 && y <= 6)) { - continue; - } - if (y == 0 && - ((x >= 0 && x <= 6) || (x >= width - 7 && x <= width - 1))) { - continue; - } - if (y == height - 7 && (x >= 0 && x <= 6)) { - continue; - } - if (x + 6 < width && array[y * width + x] == 1 && - array[y * width + x + 1] == 0 && array[y * width + x + 2] == 1 && - array[y * width + x + 3] == 1 && array[y * width + x + 4] == 1 && - array[y * width + x + 5] == 0 && array[y * width + x + 6] == 1 && - ((x + 10 < width && array[y * width + x + 7] == 0 && - array[y * width + x + 8] == 0 && array[y * width + x + 9] == 0 && - array[y * width + x + 10] == 0) || - (x - 4 >= 0 && array[y * width + x - 1] == 0 && - array[y * width + x - 2] == 0 && array[y * width + x - 3] == 0 && - array[y * width + x - 4] == 0))) { - penalty += 40; - } - if (y + 6 < height && array[y * width + x] == 1 && - array[(y + 1) * width + x] == 0 && array[(y + 2) * width + x] == 1 && - array[(y + 3) * width + x] == 1 && array[(y + 4) * width + x] == 1 && - array[(y + 5) * width + x] == 0 && array[(y + 6) * width + x] == 1 && - ((y + 10 < height && array[(y + 7) * width + x] == 0 && - array[(y + 8) * width + x] == 0 && - array[(y + 9) * width + x] == 0 && - array[(y + 10) * width + x] == 0) || - (y - 4 >= 0 && array[(y - 1) * width + x] == 0 && - array[(y - 2) * width + x] == 0 && - array[(y - 3) * width + x] == 0 && - array[(y - 4) * width + x] == 0))) { - penalty += 40; - } - } - } - return penalty; -} -int32_t CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule4( - CBC_CommonByteMatrix* matrix) { - int32_t numDarkCells = 0; - uint8_t* array = matrix->GetArray(); - int32_t width = matrix->GetWidth(); - int32_t height = matrix->GetHeight(); - for (int32_t y = 0; y < height; ++y) { - for (int32_t x = 0; x < width; ++x) { - if (array[y * width + x] == 1) { - numDarkCells += 1; - } - } - } - int32_t numTotalCells = matrix->GetHeight() * matrix->GetWidth(); - double darkRatio = (double)numDarkCells / numTotalCells; - return abs((int32_t)(darkRatio * 100 - 50) / 5) * 5 * 10; -} -bool CBC_QRCoderMaskUtil::GetDataMaskBit(int32_t maskPattern, - int32_t x, - int32_t y, - int32_t& e) { - if (!CBC_QRCoder::IsValidMaskPattern(maskPattern)) { - e = (BCExceptionInvalidateMaskPattern); - return false; - } - int32_t intermediate = 0, temp = 0; - switch (maskPattern) { - case 0: - intermediate = (y + x) & 0x1; - break; - case 1: - intermediate = y & 0x1; - break; - case 2: - intermediate = x % 3; - break; - case 3: - intermediate = (y + x) % 3; - break; - case 4: - intermediate = ((y >> 1) + (x / 3)) & 0x1; - break; - case 5: - temp = y * x; - intermediate = (temp & 0x1) + (temp % 3); - break; - case 6: - temp = y * x; - intermediate = (((temp & 0x1) + (temp % 3)) & 0x1); - break; - case 7: - temp = y * x; - intermediate = (((temp % 3) + ((y + x) & 0x1)) & 0x1); - break; - default: { - e = BCExceptionInvalidateMaskPattern; - return false; - } - } - return intermediate == 0; -} -int32_t CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule1Internal( - CBC_CommonByteMatrix* matrix, - bool isHorizontal) { - int32_t penalty = 0; - int32_t numSameBitCells = 0; - int32_t prevBit = -1; - int32_t width = matrix->GetWidth(); - int32_t height = matrix->GetHeight(); - int32_t iLimit = isHorizontal ? height : width; - int32_t jLimit = isHorizontal ? width : height; - uint8_t* array = matrix->GetArray(); - for (int32_t i = 0; i < iLimit; ++i) { - for (int32_t j = 0; j < jLimit; ++j) { - int32_t bit = isHorizontal ? array[i * width + j] : array[j * width + i]; - if (bit == prevBit) { - numSameBitCells += 1; - if (numSameBitCells == 5) { - penalty += 3; - } else if (numSameBitCells > 5) { - penalty += 1; - } - } else { - numSameBitCells = 1; - prevBit = bit; - } - } - numSameBitCells = 0; - } - return penalty; -} diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.h b/xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.h deleted file mode 100644 index 9fbe073e7e..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.h +++ /dev/null @@ -1,27 +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_FXBARCODE_QRCODE_BC_QRCODERMASKUTIL_H_ -#define XFA_FXBARCODE_QRCODE_BC_QRCODERMASKUTIL_H_ -class CBC_CommonByteMatrix; -class CBC_QRCoderMaskUtil { - public: - CBC_QRCoderMaskUtil(); - virtual ~CBC_QRCoderMaskUtil(); - static bool GetDataMaskBit(int32_t maskPattern, - int32_t x, - int32_t y, - int32_t& e); - - static int32_t ApplyMaskPenaltyRule1(CBC_CommonByteMatrix* matrix); - static int32_t ApplyMaskPenaltyRule2(CBC_CommonByteMatrix* matrix); - static int32_t ApplyMaskPenaltyRule3(CBC_CommonByteMatrix* matrix); - static int32_t ApplyMaskPenaltyRule4(CBC_CommonByteMatrix* matrix); - static int32_t ApplyMaskPenaltyRule1Internal(CBC_CommonByteMatrix* matrix, - bool isHorizontal); -}; - -#endif // XFA_FXBARCODE_QRCODE_BC_QRCODERMASKUTIL_H_ diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderMatrixUtil.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderMatrixUtil.cpp deleted file mode 100644 index d48d81c091..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderMatrixUtil.cpp +++ /dev/null @@ -1,506 +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 2008 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/common/BC_CommonByteMatrix.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoder.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderBitVector.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h" -#include "xfa/fxbarcode/utils.h" - -const int32_t CBC_QRCoderMatrixUtil::POSITION_DETECTION_PATTERN[7][7] = { - {1, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 1}, {1, 0, 1, 1, 1, 0, 1}, - {1, 0, 1, 1, 1, 0, 1}, {1, 0, 1, 1, 1, 0, 1}, {1, 0, 0, 0, 0, 0, 1}, - {1, 1, 1, 1, 1, 1, 1}}; -const int32_t CBC_QRCoderMatrixUtil::HORIZONTAL_SEPARATION_PATTERN[1][8] = { - {0, 0, 0, 0, 0, 0, 0, 0}}; -const int32_t CBC_QRCoderMatrixUtil::VERTICAL_SEPARATION_PATTERN[7][1] = { - {0}, {0}, {0}, {0}, {0}, {0}, {0}}; -const int32_t CBC_QRCoderMatrixUtil::POSITION_ADJUSTMENT_PATTERN[5][5] = { - {1, 1, 1, 1, 1}, - {1, 0, 0, 0, 1}, - {1, 0, 1, 0, 1}, - {1, 0, 0, 0, 1}, - {1, 1, 1, 1, 1}}; -const int32_t - CBC_QRCoderMatrixUtil::POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[40][7] = - // NOLINTNEXTLINE - { - {-1, -1, -1, -1, -1, -1, -1}, {6, 18, -1, -1, -1, -1, -1}, - {6, 22, -1, -1, -1, -1, -1}, {6, 26, -1, -1, -1, -1, -1}, - {6, 30, -1, -1, -1, -1, -1}, {6, 34, -1, -1, -1, -1, -1}, - {6, 22, 38, -1, -1, -1, -1}, {6, 24, 42, -1, -1, -1, -1}, - {6, 26, 46, -1, -1, -1, -1}, {6, 28, 50, -1, -1, -1, -1}, - {6, 30, 54, -1, -1, -1, -1}, {6, 32, 58, -1, -1, -1, -1}, - {6, 34, 62, -1, -1, -1, -1}, {6, 26, 46, 66, -1, -1, -1}, - {6, 26, 48, 70, -1, -1, -1}, {6, 26, 50, 74, -1, -1, -1}, - {6, 30, 54, 78, -1, -1, -1}, {6, 30, 56, 82, -1, -1, -1}, - {6, 30, 58, 86, -1, -1, -1}, {6, 34, 62, 90, -1, -1, -1}, - {6, 28, 50, 72, 94, -1, -1}, {6, 26, 50, 74, 98, -1, -1}, - {6, 30, 54, 78, 102, -1, -1}, {6, 28, 54, 80, 106, -1, -1}, - {6, 32, 58, 84, 110, -1, -1}, {6, 30, 58, 86, 114, -1, -1}, - {6, 34, 62, 90, 118, -1, -1}, {6, 26, 50, 74, 98, 122, -1}, - {6, 30, 54, 78, 102, 126, -1}, {6, 26, 52, 78, 104, 130, -1}, - {6, 30, 56, 82, 108, 134, -1}, {6, 34, 60, 86, 112, 138, -1}, - {6, 30, 58, 86, 114, 142, -1}, {6, 34, 62, 90, 118, 146, -1}, - {6, 30, 54, 78, 102, 126, 150}, {6, 24, 50, 76, 102, 128, 154}, - {6, 28, 54, 80, 106, 132, 158}, {6, 32, 58, 84, 110, 136, 162}, - {6, 26, 54, 82, 110, 138, 166}, {6, 30, 58, 86, 114, 142, 170}, -}; -const int32_t CBC_QRCoderMatrixUtil::TYPE_INFO_COORDINATES[15][2] = { - {8, 0}, {8, 1}, {8, 2}, {8, 3}, {8, 4}, {8, 5}, {8, 7}, {8, 8}, - {7, 8}, {5, 8}, {4, 8}, {3, 8}, {2, 8}, {1, 8}, {0, 8}, -}; -const int32_t CBC_QRCoderMatrixUtil::VERSION_INFO_POLY = 0x1f25; -const int32_t CBC_QRCoderMatrixUtil::TYPE_INFO_POLY = 0x0537; -const int32_t CBC_QRCoderMatrixUtil::TYPE_INFO_MASK_PATTERN = 0x5412; - -void CBC_QRCoderMatrixUtil::ClearMatrix(CBC_CommonByteMatrix* matrix, - int32_t& e) { - if (!matrix) { - e = BCExceptionNullPointer; - return; - } - matrix->clear((uint8_t)-1); -} -void CBC_QRCoderMatrixUtil::BuildMatrix( - CBC_QRCoderBitVector* dataBits, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - int32_t version, - int32_t maskPattern, - CBC_CommonByteMatrix* matrix, - int32_t& e) { - if (!matrix) { - e = BCExceptionNullPointer; - return; - } - ClearMatrix(matrix, e); - if (e != BCExceptionNO) - return; - EmbedBasicPatterns(version, matrix, e); - if (e != BCExceptionNO) - return; - EmbedTypeInfo(ecLevel, maskPattern, matrix, e); - if (e != BCExceptionNO) - return; - MaybeEmbedVersionInfo(version, matrix, e); - if (e != BCExceptionNO) - return; - EmbedDataBits(dataBits, maskPattern, matrix, e); - if (e != BCExceptionNO) - return; -} -void CBC_QRCoderMatrixUtil::EmbedBasicPatterns(int32_t version, - CBC_CommonByteMatrix* matrix, - int32_t& e) { - if (!matrix) { - e = BCExceptionNullPointer; - return; - } - EmbedPositionDetectionPatternsAndSeparators(matrix, e); - if (e != BCExceptionNO) - return; - EmbedDarkDotAtLeftBottomCorner(matrix, e); - if (e != BCExceptionNO) - return; - MaybeEmbedPositionAdjustmentPatterns(version, matrix, e); - if (e != BCExceptionNO) - return; - EmbedTimingPatterns(matrix, e); - if (e != BCExceptionNO) - return; -} -void CBC_QRCoderMatrixUtil::EmbedTypeInfo( - CBC_QRCoderErrorCorrectionLevel* ecLevel, - int32_t maskPattern, - CBC_CommonByteMatrix* matrix, - int32_t& e) { - if (!matrix) { - e = BCExceptionNullPointer; - return; - } - CBC_QRCoderBitVector typeInfoBits; - typeInfoBits.Init(); - MakeTypeInfoBits(ecLevel, maskPattern, &typeInfoBits, e); - if (e != BCExceptionNO) - return; - for (int32_t i = 0; i < typeInfoBits.Size(); i++) { - int32_t bit = typeInfoBits.At(typeInfoBits.Size() - 1 - i, e); - if (e != BCExceptionNO) - return; - int32_t x1 = TYPE_INFO_COORDINATES[i][0]; - int32_t y1 = TYPE_INFO_COORDINATES[i][1]; - matrix->Set(x1, y1, bit); - if (i < 8) { - int32_t x2 = matrix->GetWidth() - i - 1; - int32_t y2 = 8; - matrix->Set(x2, y2, bit); - } else { - int32_t x2 = 8; - int32_t y2 = matrix->GetHeight() - 7 + (i - 8); - matrix->Set(x2, y2, bit); - } - } -} -void CBC_QRCoderMatrixUtil::MaybeEmbedVersionInfo(int32_t version, - CBC_CommonByteMatrix* matrix, - int32_t& e) { - if (!matrix) { - e = BCExceptionNullPointer; - return; - } - if (version < 7) { - return; - } - CBC_QRCoderBitVector versionInfoBits; - versionInfoBits.Init(); - MakeVersionInfoBits(version, &versionInfoBits, e); - if (e != BCExceptionNO) - return; - int32_t bitIndex = 6 * 3 - 1; - for (int32_t i = 0; i < 6; i++) { - for (int32_t j = 0; j < 3; j++) { - int32_t bit = versionInfoBits.At(bitIndex, e); - if (e != BCExceptionNO) - return; - bitIndex--; - matrix->Set(i, matrix->GetHeight() - 11 + j, bit); - matrix->Set(matrix->GetHeight() - 11 + j, i, bit); - } - } -} -void CBC_QRCoderMatrixUtil::EmbedDataBits(CBC_QRCoderBitVector* dataBits, - int32_t maskPattern, - CBC_CommonByteMatrix* matrix, - int32_t& e) { - if (!matrix || !dataBits) { - e = BCExceptionNullPointer; - return; - } - int32_t bitIndex = 0; - int32_t direction = -1; - int32_t x = matrix->GetWidth() - 1; - int32_t y = matrix->GetHeight() - 1; - while (x > 0) { - if (x == 6) { - x -= 1; - } - while (y >= 0 && y < matrix->GetHeight()) { - if (y == 6) { - y += direction; - continue; - } - for (int32_t i = 0; i < 2; i++) { - int32_t xx = x - i; - if (!IsEmpty(matrix->Get(xx, y))) { - continue; - } - int32_t bit; - if (bitIndex < dataBits->Size()) { - bit = dataBits->At(bitIndex, e); - if (e != BCExceptionNO) - return; - bitIndex++; - } else { - bit = 0; - } - if (maskPattern != -1) { - bool bol = CBC_QRCoderMaskUtil::GetDataMaskBit(maskPattern, xx, y, e); - if (e != BCExceptionNO) - return; - if (bol) { - bit ^= 0x01; - } - } - matrix->Set(xx, y, bit); - } - y += direction; - } - direction = -direction; - y += direction; - x -= 2; - } - if (bitIndex != dataBits->Size()) { - return; - } -} -int32_t CBC_QRCoderMatrixUtil::CalculateBCHCode(int32_t value, int32_t poly) { - int32_t msbSetInPoly = FindMSBSet(poly); - value <<= msbSetInPoly - 1; - while (FindMSBSet(value) >= msbSetInPoly) { - value ^= poly << (FindMSBSet(value) - msbSetInPoly); - } - return value; -} -void CBC_QRCoderMatrixUtil::MakeTypeInfoBits( - CBC_QRCoderErrorCorrectionLevel* ecLevel, - int32_t maskPattern, - CBC_QRCoderBitVector* bits, - int32_t& e) { - if (!bits) { - e = BCExceptionNullPointer; - return; - } - if (!CBC_QRCoder::IsValidMaskPattern(maskPattern)) { - e = BCExceptionBadMask; - return; - } - int32_t typeInfo = (ecLevel->GetBits() << 3) | maskPattern; - if (e != BCExceptionNO) - return; - bits->AppendBits(typeInfo, 5, e); - int32_t bchCode = CalculateBCHCode(typeInfo, TYPE_INFO_POLY); - if (e != BCExceptionNO) - return; - bits->AppendBits(bchCode, 10, e); - CBC_QRCoderBitVector maskBits; - maskBits.Init(); - maskBits.AppendBits(TYPE_INFO_MASK_PATTERN, 15, e); - if (e != BCExceptionNO) - return; - bits->XOR(&maskBits, e); - if (e != BCExceptionNO) - return; - if (bits->Size() != 15) - e = BCExceptionBitSizeNot15; -} - -void CBC_QRCoderMatrixUtil::MakeVersionInfoBits(int32_t version, - CBC_QRCoderBitVector* bits, - int32_t& e) { - if (!bits) { - e = BCExceptionNullPointer; - return; - } - bits->AppendBits(version, 6, e); - if (e != BCExceptionNO) - return; - - int32_t bchCode = CalculateBCHCode(version, VERSION_INFO_POLY); - bits->AppendBits(bchCode, 12, e); - if (e != BCExceptionNO) - return; - - if (bits->Size() != 18) - e = BCExceptionBitSizeNot18; -} - -bool CBC_QRCoderMatrixUtil::IsEmpty(int32_t value) { - return (uint8_t)value == 0xff; -} -bool CBC_QRCoderMatrixUtil::IsValidValue(int32_t value) { - return ((uint8_t)value == 0xff || (uint8_t)value == 0x00 || - (uint8_t)value == 0x01); -} - -void CBC_QRCoderMatrixUtil::EmbedTimingPatterns(CBC_CommonByteMatrix* matrix, - int32_t& e) { - if (!matrix) { - e = BCExceptionNullPointer; - return; - } - for (int32_t i = 8; i < matrix->GetWidth() - 8; i++) { - int32_t bit = (i + 1) % 2; - if (!IsValidValue(matrix->Get(i, 6))) { - e = BCExceptionInvalidateImageData; - return; - } - if (IsEmpty(matrix->Get(i, 6))) { - matrix->Set(i, 6, bit); - } - if (!IsValidValue(matrix->Get(6, i))) { - e = BCExceptionInvalidateImageData; - return; - } - if (IsEmpty(matrix->Get(6, i))) { - matrix->Set(6, i, bit); - } - } -} -void CBC_QRCoderMatrixUtil::EmbedDarkDotAtLeftBottomCorner( - CBC_CommonByteMatrix* matrix, - int32_t& e) { - if (!matrix) { - e = BCExceptionNullPointer; - return; - } - if (matrix->Get(8, matrix->GetHeight() - 8) == 0) { - e = BCExceptionHeight_8BeZero; - return; - } - matrix->Set(8, matrix->GetHeight() - 8, 1); -} -void CBC_QRCoderMatrixUtil::EmbedHorizontalSeparationPattern( - int32_t xStart, - int32_t yStart, - CBC_CommonByteMatrix* matrix, - int32_t& e) { - if (!matrix) { - e = BCExceptionNullPointer; - return; - } - for (int32_t x = 0; x < 8; x++) { - if (!IsEmpty(matrix->Get(xStart + x, yStart))) { - e = BCExceptionInvalidateData; - return; - } - matrix->Set(xStart + x, yStart, HORIZONTAL_SEPARATION_PATTERN[0][x]); - } -} -void CBC_QRCoderMatrixUtil::EmbedVerticalSeparationPattern( - int32_t xStart, - int32_t yStart, - CBC_CommonByteMatrix* matrix, - int32_t& e) { - if (!matrix) { - e = BCExceptionNullPointer; - return; - } - for (int32_t y = 0; y < 7; y++) { - if (!IsEmpty(matrix->Get(xStart, yStart + y))) { - e = BCExceptionInvalidateData; - return; - } - matrix->Set(xStart, yStart + y, VERTICAL_SEPARATION_PATTERN[y][0]); - } -} -void CBC_QRCoderMatrixUtil::EmbedPositionAdjustmentPattern( - int32_t xStart, - int32_t yStart, - CBC_CommonByteMatrix* matrix, - int32_t& e) { - if (!matrix) { - e = BCExceptionNullPointer; - if (e != BCExceptionNO) - return; - } - for (int32_t y = 0; y < 5; y++) { - for (int32_t x = 0; x < 5; x++) { - if (!IsEmpty(matrix->Get(xStart + x, y + yStart))) { - e = BCExceptionInvalidateData; - return; - } - matrix->Set(xStart + x, yStart + y, POSITION_ADJUSTMENT_PATTERN[y][x]); - } - } -} -void CBC_QRCoderMatrixUtil::EmbedPositionDetectionPattern( - int32_t xStart, - int32_t yStart, - CBC_CommonByteMatrix* matrix, - int32_t& e) { - if (!matrix) { - e = BCExceptionNullPointer; - return; - } - for (int32_t y = 0; y < 7; y++) { - for (int32_t x = 0; x < 7; x++) { - if (!IsEmpty(matrix->Get(xStart + x, yStart + y))) { - e = BCExceptionInvalidateData; - return; - } - matrix->Set(xStart + x, yStart + y, POSITION_DETECTION_PATTERN[y][x]); - } - } -} -void CBC_QRCoderMatrixUtil::EmbedPositionDetectionPatternsAndSeparators( - CBC_CommonByteMatrix* matrix, - int32_t& e) { - if (!matrix) { - e = BCExceptionNullPointer; - return; - } - int32_t pdpWidth = 7; - EmbedPositionDetectionPattern(0, 0, matrix, e); - if (e != BCExceptionNO) - return; - EmbedPositionDetectionPattern(matrix->GetWidth() - pdpWidth, 0, matrix, e); - if (e != BCExceptionNO) - return; - EmbedPositionDetectionPattern(0, matrix->GetWidth() - pdpWidth, matrix, e); - if (e != BCExceptionNO) - return; - int32_t hspWidth = 8; - EmbedHorizontalSeparationPattern(0, hspWidth - 1, matrix, e); - if (e != BCExceptionNO) - return; - EmbedHorizontalSeparationPattern(matrix->GetWidth() - hspWidth, hspWidth - 1, - matrix, e); - if (e != BCExceptionNO) - return; - EmbedHorizontalSeparationPattern(0, matrix->GetWidth() - hspWidth, matrix, e); - if (e != BCExceptionNO) - return; - int32_t vspSize = 7; - EmbedVerticalSeparationPattern(vspSize, 0, matrix, e); - if (e != BCExceptionNO) - return; - EmbedVerticalSeparationPattern(matrix->GetHeight() - vspSize - 1, 0, matrix, - e); - if (e != BCExceptionNO) - return; - EmbedVerticalSeparationPattern(vspSize, matrix->GetHeight() - vspSize, matrix, - e); - if (e != BCExceptionNO) - return; -} -void CBC_QRCoderMatrixUtil::MaybeEmbedPositionAdjustmentPatterns( - int32_t version, - CBC_CommonByteMatrix* matrix, - int32_t& e) { - if (!matrix) { - e = BCExceptionNullPointer; - return; - } - if (version < 2) { - return; - } - int32_t index = version - 1; - int32_t const* coordinates = - &(POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index][0]); - int32_t numCoordinate = 7; - for (int32_t i = 0; i < numCoordinate; i++) { - for (int32_t j = 0; j < numCoordinate; j++) { - int32_t y = coordinates[i]; - int32_t x = coordinates[j]; - if (x == -1 || y == -1) { - continue; - } - if (IsEmpty(matrix->Get(x, y))) { - EmbedPositionAdjustmentPattern(x - 2, y - 2, matrix, e); - if (e != BCExceptionNO) - return; - } - } - } -} -int32_t CBC_QRCoderMatrixUtil::FindMSBSet(int32_t value) { - int32_t numDigits = 0; - while (value != 0) { - value >>= 1; - ++numDigits; - } - return numDigits; -} -CBC_QRCoderMatrixUtil::CBC_QRCoderMatrixUtil() {} -CBC_QRCoderMatrixUtil::~CBC_QRCoderMatrixUtil() {} diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h b/xfa/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h deleted file mode 100644 index 3ce4b7510b..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h +++ /dev/null @@ -1,87 +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_FXBARCODE_QRCODE_BC_QRCODERMATRIXUTIL_H_ -#define XFA_FXBARCODE_QRCODE_BC_QRCODERMATRIXUTIL_H_ - -class CBC_CommonByteMatrix; -class CBC_QRCoderErrorCorrectionLevel; -class CBC_QRCoderBitVector; -class CBC_QRCoderMatrixUtil { - private: - static const int32_t POSITION_DETECTION_PATTERN[7][7]; - static const int32_t VERTICAL_SEPARATION_PATTERN[7][1]; - static const int32_t HORIZONTAL_SEPARATION_PATTERN[1][8]; - static const int32_t POSITION_ADJUSTMENT_PATTERN[5][5]; - static const int32_t POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[40][7]; - static const int32_t TYPE_INFO_COORDINATES[15][2]; - static const int32_t VERSION_INFO_POLY; - static const int32_t TYPE_INFO_POLY; - static const int32_t TYPE_INFO_MASK_PATTERN; - - public: - CBC_QRCoderMatrixUtil(); - virtual ~CBC_QRCoderMatrixUtil(); - static void ClearMatrix(CBC_CommonByteMatrix* matrix, int32_t& e); - static void BuildMatrix(CBC_QRCoderBitVector* dataBits, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - int32_t version, - int32_t maskPattern, - CBC_CommonByteMatrix* matrix, - int32_t& e); - static void EmbedBasicPatterns(int32_t version, - CBC_CommonByteMatrix* matrix, - int32_t& e); - static void EmbedTypeInfo(CBC_QRCoderErrorCorrectionLevel* ecLevel, - int32_t maskPattern, - CBC_CommonByteMatrix* matrix, - int32_t& e); - static void EmbedDataBits(CBC_QRCoderBitVector* dataBits, - int32_t maskPattern, - CBC_CommonByteMatrix* matrix, - int32_t& e); - static void MaybeEmbedVersionInfo(int32_t version, - CBC_CommonByteMatrix* matrix, - int32_t& e); - static int32_t FindMSBSet(int32_t value); - static int32_t CalculateBCHCode(int32_t code, int32_t poly); - static void MakeTypeInfoBits(CBC_QRCoderErrorCorrectionLevel* ecLevel, - int32_t maskPattern, - CBC_QRCoderBitVector* bits, - int32_t& e); - static void MakeVersionInfoBits(int32_t version, - CBC_QRCoderBitVector* bits, - int32_t& e); - static bool IsEmpty(int32_t value); - static bool IsValidValue(int32_t value); - static void EmbedTimingPatterns(CBC_CommonByteMatrix* matrix, int32_t& e); - static void EmbedDarkDotAtLeftBottomCorner(CBC_CommonByteMatrix* matrix, - int32_t& e); - static void EmbedHorizontalSeparationPattern(int32_t xStart, - int32_t yStart, - CBC_CommonByteMatrix* matrix, - int32_t& e); - static void EmbedVerticalSeparationPattern(int32_t xStart, - int32_t yStart, - CBC_CommonByteMatrix* matrix, - int32_t& e); - static void EmbedPositionAdjustmentPattern(int32_t xStart, - int32_t yStart, - CBC_CommonByteMatrix* matrix, - int32_t& e); - static void EmbedPositionDetectionPattern(int32_t xStart, - int32_t yStart, - CBC_CommonByteMatrix* matrix, - int32_t& e); - static void EmbedPositionDetectionPatternsAndSeparators( - CBC_CommonByteMatrix* matrix, - int32_t& e); - static void MaybeEmbedPositionAdjustmentPatterns(int32_t version, - CBC_CommonByteMatrix* matrix, - int32_t& e); -}; - -#endif // XFA_FXBARCODE_QRCODE_BC_QRCODERMATRIXUTIL_H_ diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderMode.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderMode.cpp deleted file mode 100644 index a1283dda93..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderMode.cpp +++ /dev/null @@ -1,174 +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 2007 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/qrcode/BC_QRCoderMode.h" - -#include <utility> - -#include "xfa/fxbarcode/qrcode/BC_QRCoderVersion.h" -#include "xfa/fxbarcode/utils.h" - -CBC_QRCoderMode* CBC_QRCoderMode::sBYTE = nullptr; -CBC_QRCoderMode* CBC_QRCoderMode::sNUMERIC = nullptr; -CBC_QRCoderMode* CBC_QRCoderMode::sALPHANUMERIC = nullptr; -CBC_QRCoderMode* CBC_QRCoderMode::sKANJI = nullptr; -CBC_QRCoderMode* CBC_QRCoderMode::sECI = nullptr; -CBC_QRCoderMode* CBC_QRCoderMode::sGBK = nullptr; -CBC_QRCoderMode* CBC_QRCoderMode::sTERMINATOR = nullptr; -CBC_QRCoderMode* CBC_QRCoderMode::sFNC1_FIRST_POSITION = nullptr; -CBC_QRCoderMode* CBC_QRCoderMode::sFNC1_SECOND_POSITION = nullptr; -CBC_QRCoderMode* CBC_QRCoderMode::sSTRUCTURED_APPEND = nullptr; - -CBC_QRCoderMode::CBC_QRCoderMode(std::vector<int32_t> charCountBits, - int32_t bits, - CFX_ByteString name) - : m_characterCountBitsForVersions(std::move(charCountBits)), - m_bits(bits), - m_name(name) {} - -CBC_QRCoderMode::~CBC_QRCoderMode() {} - -void CBC_QRCoderMode::Initialize() { - sBYTE = new CBC_QRCoderMode({8, 16, 16}, 0x4, "BYTE"); - sALPHANUMERIC = new CBC_QRCoderMode({9, 11, 13}, 0x2, "ALPHANUMERIC"); - sECI = new CBC_QRCoderMode(std::vector<int32_t>(), 0x7, "ECI"); - sKANJI = new CBC_QRCoderMode({8, 10, 12}, 0x8, "KANJI"); - sNUMERIC = new CBC_QRCoderMode({10, 12, 14}, 0x1, "NUMERIC"); - sGBK = new CBC_QRCoderMode({8, 10, 12}, 0x0D, "GBK"); - sTERMINATOR = new CBC_QRCoderMode(std::vector<int32_t>(), 0x00, "TERMINATOR"); - sFNC1_FIRST_POSITION = - new CBC_QRCoderMode(std::vector<int32_t>(), 0x05, "FNC1_FIRST_POSITION"); - sFNC1_SECOND_POSITION = - new CBC_QRCoderMode(std::vector<int32_t>(), 0x09, "FNC1_SECOND_POSITION"); - sSTRUCTURED_APPEND = - new CBC_QRCoderMode(std::vector<int32_t>(), 0x03, "STRUCTURED_APPEND"); -} - -void CBC_QRCoderMode::Finalize() { - delete sBYTE; - delete sALPHANUMERIC; - delete sECI; - delete sKANJI; - delete sNUMERIC; - delete sGBK; - delete sTERMINATOR; - delete sFNC1_FIRST_POSITION; - delete sFNC1_SECOND_POSITION; - delete sSTRUCTURED_APPEND; -} - -CBC_QRCoderMode* CBC_QRCoderMode::ForBits(int32_t bits, int32_t& e) { - switch (bits) { - case 0x0: - return sTERMINATOR; - case 0x1: - return sNUMERIC; - case 0x2: - return sALPHANUMERIC; - case 0x3: - return sSTRUCTURED_APPEND; - case 0x4: - return sBYTE; - case 0x5: - return sFNC1_FIRST_POSITION; - case 0x7: - return sECI; - case 0x8: - return sKANJI; - case 0x9: - return sFNC1_SECOND_POSITION; - case 0x0D: - return sGBK; - default: - e = BCExceptionUnsupportedMode; - return nullptr; - } -} - -int32_t CBC_QRCoderMode::GetBits() const { - return m_bits; -} - -CFX_ByteString CBC_QRCoderMode::GetName() const { - return m_name; -} - -int32_t CBC_QRCoderMode::GetCharacterCountBits(CBC_QRCoderVersion* version, - int32_t& e) const { - if (m_characterCountBitsForVersions.empty()) { - e = BCExceptionCharacterNotThisMode; - return 0; - } - int32_t number = version->GetVersionNumber(); - int32_t offset; - if (number <= 9) { - offset = 0; - } else if (number <= 26) { - offset = 1; - } else { - offset = 2; - } - return m_characterCountBitsForVersions[offset]; -} - -void CBC_QRCoderMode::Destroy() { - if (sBYTE) { - delete CBC_QRCoderMode::sBYTE; - sBYTE = nullptr; - } - if (sNUMERIC) { - delete CBC_QRCoderMode::sNUMERIC; - sNUMERIC = nullptr; - } - if (sALPHANUMERIC) { - delete CBC_QRCoderMode::sALPHANUMERIC; - sALPHANUMERIC = nullptr; - } - if (sKANJI) { - delete CBC_QRCoderMode::sKANJI; - sKANJI = nullptr; - } - if (sECI) { - delete CBC_QRCoderMode::sECI; - sECI = nullptr; - } - if (sGBK) { - delete CBC_QRCoderMode::sGBK; - sGBK = nullptr; - } - if (sTERMINATOR) { - delete CBC_QRCoderMode::sTERMINATOR; - sTERMINATOR = nullptr; - } - if (sFNC1_FIRST_POSITION) { - delete CBC_QRCoderMode::sFNC1_FIRST_POSITION; - sFNC1_FIRST_POSITION = nullptr; - } - if (sFNC1_SECOND_POSITION) { - delete CBC_QRCoderMode::sFNC1_SECOND_POSITION; - sFNC1_SECOND_POSITION = nullptr; - } - if (sSTRUCTURED_APPEND) { - delete CBC_QRCoderMode::sSTRUCTURED_APPEND; - sSTRUCTURED_APPEND = nullptr; - } -} diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderMode.h b/xfa/fxbarcode/qrcode/BC_QRCoderMode.h deleted file mode 100644 index f876d81f03..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderMode.h +++ /dev/null @@ -1,53 +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_FXBARCODE_QRCODE_BC_QRCODERMODE_H_ -#define XFA_FXBARCODE_QRCODE_BC_QRCODERMODE_H_ - -#include <stdint.h> - -#include <vector> - -#include "core/fxcrt/fx_string.h" - -class CBC_QRCoderVersion; - -class CBC_QRCoderMode { - public: - virtual ~CBC_QRCoderMode(); - - static void Initialize(); - static void Finalize(); - static CBC_QRCoderMode* ForBits(int32_t bits, int32_t& e); - static void Destroy(); - - int32_t GetCharacterCountBits(CBC_QRCoderVersion* version, int32_t& e) const; - int32_t GetBits() const; - CFX_ByteString GetName() const; - - static CBC_QRCoderMode* sBYTE; - static CBC_QRCoderMode* sNUMERIC; - static CBC_QRCoderMode* sALPHANUMERIC; - static CBC_QRCoderMode* sKANJI; - static CBC_QRCoderMode* sECI; - static CBC_QRCoderMode* sGBK; - static CBC_QRCoderMode* sTERMINATOR; - static CBC_QRCoderMode* sFNC1_FIRST_POSITION; - static CBC_QRCoderMode* sFNC1_SECOND_POSITION; - static CBC_QRCoderMode* sSTRUCTURED_APPEND; - - private: - CBC_QRCoderMode(); - CBC_QRCoderMode(std::vector<int32_t> charCountBits, - int32_t bits, - CFX_ByteString name); - - std::vector<int32_t> m_characterCountBitsForVersions; - const int32_t m_bits; - const CFX_ByteString m_name; -}; - -#endif // XFA_FXBARCODE_QRCODE_BC_QRCODERMODE_H_ diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderVersion.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderVersion.cpp deleted file mode 100644 index da13700ae2..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderVersion.cpp +++ /dev/null @@ -1,794 +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 2007 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/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderBitVector.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderECB.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderECBlocks.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h" -#include "xfa/fxbarcode/qrcode/BC_QRCoderVersion.h" -#include "xfa/fxbarcode/utils.h" - -namespace { - -const uint8_t BITS_SET_IN_HALF_BYTE[] = {0, 1, 1, 2, 1, 2, 2, 3, - 1, 2, 2, 3, 2, 3, 3, 4}; - -int32_t NumBitsDiffering(int32_t a, int32_t b) { - a ^= b; - return BITS_SET_IN_HALF_BYTE[a & 0x0F] + - BITS_SET_IN_HALF_BYTE[(a >> 4) & 0x0F] + - BITS_SET_IN_HALF_BYTE[(a >> 8) & 0x0F] + - BITS_SET_IN_HALF_BYTE[(a >> 12) & 0x0F] + - BITS_SET_IN_HALF_BYTE[(a >> 16) & 0x0F] + - BITS_SET_IN_HALF_BYTE[(a >> 20) & 0x0F] + - BITS_SET_IN_HALF_BYTE[(a >> 24) & 0x0F] + - BITS_SET_IN_HALF_BYTE[(a >> 28) & 0x0F]; -} - -} // namespace - -const int32_t CBC_QRCoderVersion::VERSION_DECODE_INFO[] = { - 0x07C94, 0x085BC, 0x09A99, 0x0A4D3, 0x0BBF6, 0x0C762, 0x0D847, - 0x0E60D, 0x0F928, 0x10B78, 0x1145D, 0x12A17, 0x13532, 0x149A6, - 0x15683, 0x168C9, 0x177EC, 0x18EC4, 0x191E1, 0x1AFAB, 0x1B08E, - 0x1CC1A, 0x1D33F, 0x1ED75, 0x1F250, 0x209D5, 0x216F0, 0x228BA, - 0x2379F, 0x24B0B, 0x2542E, 0x26A64, 0x27541, 0x28C69}; - -std::vector<CBC_QRCoderVersion*>* CBC_QRCoderVersion::VERSION = nullptr; - -void CBC_QRCoderVersion::Initialize() { - VERSION = new std::vector<CBC_QRCoderVersion*>(); -} -void CBC_QRCoderVersion::Finalize() { - for (size_t i = 0; i < VERSION->size(); i++) - delete (*VERSION)[i]; - - delete VERSION; - VERSION = nullptr; -} -CBC_QRCoderVersion::CBC_QRCoderVersion(int32_t versionNumber, - CBC_QRCoderECBlocks* ecBlocks1, - CBC_QRCoderECBlocks* ecBlocks2, - CBC_QRCoderECBlocks* ecBlocks3, - CBC_QRCoderECBlocks* ecBlocks4) { - m_versionNumber = versionNumber; - m_ecBlocksArray.push_back(ecBlocks1); - m_ecBlocksArray.push_back(ecBlocks2); - m_ecBlocksArray.push_back(ecBlocks3); - m_ecBlocksArray.push_back(ecBlocks4); - int32_t total = 0; - int32_t ecCodeWords = ecBlocks1->GetECCodeWordsPerBlock(); - std::vector<CBC_QRCoderECB*>* ecbArray = ecBlocks1->GetECBlocks(); - for (size_t i = 0; i < ecbArray->size(); i++) { - CBC_QRCoderECB* ecBlock = (*ecbArray)[i]; - total += ecBlock->GetCount() * (ecBlock->GetDataCodeWords() + ecCodeWords); - } - m_totalCodeWords = total; - switch (versionNumber) { - case 1: - break; - case 2: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(18); - break; - case 3: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(22); - break; - case 4: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(26); - break; - case 5: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(30); - break; - case 6: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(34); - break; - case 7: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(22); - m_alignmentPatternCenters.push_back(38); - break; - case 8: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(24); - m_alignmentPatternCenters.push_back(42); - break; - case 9: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(26); - m_alignmentPatternCenters.push_back(46); - break; - case 10: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(28); - m_alignmentPatternCenters.push_back(50); - break; - case 11: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(30); - m_alignmentPatternCenters.push_back(54); - break; - case 12: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(32); - m_alignmentPatternCenters.push_back(58); - break; - case 13: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(34); - m_alignmentPatternCenters.push_back(62); - break; - case 14: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(26); - m_alignmentPatternCenters.push_back(46); - m_alignmentPatternCenters.push_back(66); - break; - case 15: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(26); - m_alignmentPatternCenters.push_back(48); - m_alignmentPatternCenters.push_back(70); - break; - case 16: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(26); - m_alignmentPatternCenters.push_back(50); - m_alignmentPatternCenters.push_back(74); - break; - case 17: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(30); - m_alignmentPatternCenters.push_back(54); - m_alignmentPatternCenters.push_back(78); - break; - case 18: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(30); - m_alignmentPatternCenters.push_back(56); - m_alignmentPatternCenters.push_back(82); - break; - case 19: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(30); - m_alignmentPatternCenters.push_back(58); - m_alignmentPatternCenters.push_back(86); - break; - case 20: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(34); - m_alignmentPatternCenters.push_back(62); - m_alignmentPatternCenters.push_back(90); - break; - case 21: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(28); - m_alignmentPatternCenters.push_back(50); - m_alignmentPatternCenters.push_back(72); - m_alignmentPatternCenters.push_back(94); - break; - case 22: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(26); - m_alignmentPatternCenters.push_back(50); - m_alignmentPatternCenters.push_back(74); - m_alignmentPatternCenters.push_back(98); - break; - case 23: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(30); - m_alignmentPatternCenters.push_back(54); - m_alignmentPatternCenters.push_back(74); - m_alignmentPatternCenters.push_back(102); - break; - case 24: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(28); - m_alignmentPatternCenters.push_back(54); - m_alignmentPatternCenters.push_back(80); - m_alignmentPatternCenters.push_back(106); - break; - case 25: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(32); - m_alignmentPatternCenters.push_back(58); - m_alignmentPatternCenters.push_back(84); - m_alignmentPatternCenters.push_back(110); - break; - case 26: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(30); - m_alignmentPatternCenters.push_back(58); - m_alignmentPatternCenters.push_back(86); - m_alignmentPatternCenters.push_back(114); - break; - case 27: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(34); - m_alignmentPatternCenters.push_back(62); - m_alignmentPatternCenters.push_back(90); - m_alignmentPatternCenters.push_back(118); - break; - case 28: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(26); - m_alignmentPatternCenters.push_back(50); - m_alignmentPatternCenters.push_back(74); - m_alignmentPatternCenters.push_back(98); - m_alignmentPatternCenters.push_back(122); - break; - case 29: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(30); - m_alignmentPatternCenters.push_back(54); - m_alignmentPatternCenters.push_back(78); - m_alignmentPatternCenters.push_back(102); - m_alignmentPatternCenters.push_back(126); - break; - case 30: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(26); - m_alignmentPatternCenters.push_back(52); - m_alignmentPatternCenters.push_back(78); - m_alignmentPatternCenters.push_back(104); - m_alignmentPatternCenters.push_back(130); - break; - case 31: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(30); - m_alignmentPatternCenters.push_back(56); - m_alignmentPatternCenters.push_back(82); - m_alignmentPatternCenters.push_back(108); - m_alignmentPatternCenters.push_back(134); - break; - case 32: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(34); - m_alignmentPatternCenters.push_back(60); - m_alignmentPatternCenters.push_back(86); - m_alignmentPatternCenters.push_back(112); - m_alignmentPatternCenters.push_back(138); - break; - case 33: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(30); - m_alignmentPatternCenters.push_back(58); - m_alignmentPatternCenters.push_back(86); - m_alignmentPatternCenters.push_back(114); - m_alignmentPatternCenters.push_back(142); - break; - case 34: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(34); - m_alignmentPatternCenters.push_back(62); - m_alignmentPatternCenters.push_back(90); - m_alignmentPatternCenters.push_back(118); - m_alignmentPatternCenters.push_back(146); - break; - case 35: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(30); - m_alignmentPatternCenters.push_back(54); - m_alignmentPatternCenters.push_back(78); - m_alignmentPatternCenters.push_back(102); - m_alignmentPatternCenters.push_back(126); - m_alignmentPatternCenters.push_back(150); - break; - case 36: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(24); - m_alignmentPatternCenters.push_back(50); - m_alignmentPatternCenters.push_back(76); - m_alignmentPatternCenters.push_back(102); - m_alignmentPatternCenters.push_back(128); - m_alignmentPatternCenters.push_back(154); - break; - case 37: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(28); - m_alignmentPatternCenters.push_back(54); - m_alignmentPatternCenters.push_back(80); - m_alignmentPatternCenters.push_back(106); - m_alignmentPatternCenters.push_back(132); - m_alignmentPatternCenters.push_back(158); - break; - case 38: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(32); - m_alignmentPatternCenters.push_back(58); - m_alignmentPatternCenters.push_back(84); - m_alignmentPatternCenters.push_back(110); - m_alignmentPatternCenters.push_back(136); - m_alignmentPatternCenters.push_back(162); - break; - case 39: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(26); - m_alignmentPatternCenters.push_back(54); - m_alignmentPatternCenters.push_back(82); - m_alignmentPatternCenters.push_back(110); - m_alignmentPatternCenters.push_back(138); - m_alignmentPatternCenters.push_back(166); - break; - case 40: - m_alignmentPatternCenters.push_back(6); - m_alignmentPatternCenters.push_back(30); - m_alignmentPatternCenters.push_back(58); - m_alignmentPatternCenters.push_back(86); - m_alignmentPatternCenters.push_back(114); - m_alignmentPatternCenters.push_back(142); - m_alignmentPatternCenters.push_back(170); - break; - } -} - -CBC_QRCoderVersion::~CBC_QRCoderVersion() { - for (size_t i = 0; i < m_ecBlocksArray.size(); ++i) - delete m_ecBlocksArray[i]; -} - -int32_t CBC_QRCoderVersion::GetVersionNumber() { - return m_versionNumber; -} -std::vector<int32_t>* CBC_QRCoderVersion::GetAlignmentPatternCenters() { - return &m_alignmentPatternCenters; -} -int32_t CBC_QRCoderVersion::GetTotalCodeWords() { - return m_totalCodeWords; -} -int32_t CBC_QRCoderVersion::GetDimensionForVersion() { - return 17 + 4 * m_versionNumber; -} -CBC_QRCoderECBlocks* CBC_QRCoderVersion::GetECBlocksForLevel( - CBC_QRCoderErrorCorrectionLevel* ecLevel) { - return m_ecBlocksArray[ecLevel->Ordinal()]; -} -CBC_QRCoderVersion* CBC_QRCoderVersion::GetProvisionalVersionForDimension( - int32_t dimension, - int32_t& e) { - if ((dimension % 4) != 1) { - e = BCExceptionRead; - return nullptr; - } - CBC_QRCoderVersion* qcv = GetVersionForNumber((dimension - 17) >> 2, e); - if (e != BCExceptionNO) - return nullptr; - return qcv; -} -CBC_QRCoderVersion* CBC_QRCoderVersion::DecodeVersionInformation( - int32_t versionBits, - int32_t& e) { - int32_t bestDifference = FXSYS_IntMax; - int32_t bestVersion = 0; - for (int32_t i = 0; i < 34; i++) { - int32_t targetVersion = VERSION_DECODE_INFO[i]; - if (targetVersion == versionBits) { - CBC_QRCoderVersion* qcv = GetVersionForNumber(i + 7, e); - if (e != BCExceptionNO) - return nullptr; - return qcv; - } - int32_t bitsDifference = NumBitsDiffering(versionBits, targetVersion); - if (bitsDifference < bestDifference) { - bestVersion = i + 7; - bestDifference = bitsDifference; - } - } - if (bestDifference <= 3) { - CBC_QRCoderVersion* qcv = GetVersionForNumber(bestVersion, e); - if (e != BCExceptionNO) - return nullptr; - return qcv; - } - return nullptr; -} -CBC_CommonBitMatrix* CBC_QRCoderVersion::BuildFunctionPattern(int32_t& e) { - int32_t dimension = GetDimensionForVersion(); - CBC_CommonBitMatrix* bitMatrix = new CBC_CommonBitMatrix(); - bitMatrix->Init(dimension); - bitMatrix->SetRegion(0, 0, 9, 9, e); - if (e != BCExceptionNO) - return nullptr; - bitMatrix->SetRegion(dimension - 8, 0, 8, 9, e); - if (e != BCExceptionNO) - return nullptr; - bitMatrix->SetRegion(0, dimension - 8, 9, 8, e); - if (e != BCExceptionNO) - return nullptr; - size_t max = m_alignmentPatternCenters.size(); - for (size_t x = 0; x < max; x++) { - int32_t i = m_alignmentPatternCenters[x] - 2; - for (size_t y = 0; y < max; y++) { - if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) { - continue; - } - bitMatrix->SetRegion(m_alignmentPatternCenters[y] - 2, i, 5, 5, e); - if (e != BCExceptionNO) - return nullptr; - } - } - bitMatrix->SetRegion(6, 9, 1, dimension - 17, e); - if (e != BCExceptionNO) - return nullptr; - bitMatrix->SetRegion(9, 6, dimension - 17, 1, e); - if (e != BCExceptionNO) - return nullptr; - if (m_versionNumber > 6) { - bitMatrix->SetRegion(dimension - 11, 0, 3, 6, e); - if (e != BCExceptionNO) - return nullptr; - bitMatrix->SetRegion(0, dimension - 11, 6, 3, e); - if (e != BCExceptionNO) - return nullptr; - } - return bitMatrix; -} -CBC_QRCoderVersion* CBC_QRCoderVersion::GetVersionForNumber( - int32_t versionNumber, - int32_t& e) { - if (VERSION->empty()) { - VERSION->push_back(new CBC_QRCoderVersion( - 1, new CBC_QRCoderECBlocks(7, new CBC_QRCoderECB(1, 19)), - new CBC_QRCoderECBlocks(10, new CBC_QRCoderECB(1, 16)), - new CBC_QRCoderECBlocks(13, new CBC_QRCoderECB(1, 13)), - new CBC_QRCoderECBlocks(17, new CBC_QRCoderECB(1, 9)))); - VERSION->push_back(new CBC_QRCoderVersion( - 2, new CBC_QRCoderECBlocks(10, new CBC_QRCoderECB(1, 34)), - new CBC_QRCoderECBlocks(16, new CBC_QRCoderECB(1, 28)), - new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(1, 22)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(1, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 3, new CBC_QRCoderECBlocks(15, new CBC_QRCoderECB(1, 55)), - new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(1, 44)), - new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 17)), - new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(2, 13)))); - VERSION->push_back(new CBC_QRCoderVersion( - 4, new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(1, 80)), - new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 32)), - new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(2, 24)), - new CBC_QRCoderECBlocks(16, new CBC_QRCoderECB(4, 9)))); - VERSION->push_back(new CBC_QRCoderVersion( - 5, new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(1, 108)), - new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(2, 43)), - new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 15), - new CBC_QRCoderECB(2, 16)), - new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(2, 11), - new CBC_QRCoderECB(2, 12)))); - VERSION->push_back(new CBC_QRCoderVersion( - 6, new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 68)), - new CBC_QRCoderECBlocks(16, new CBC_QRCoderECB(4, 27)), - new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(4, 19)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(4, 15)))); - VERSION->push_back(new CBC_QRCoderVersion( - 7, new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(2, 78)), - new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(4, 31)), - new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 14), - new CBC_QRCoderECB(4, 15)), - new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 13), - new CBC_QRCoderECB(1, 14)))); - VERSION->push_back(new CBC_QRCoderVersion( - 8, new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(2, 97)), - new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(2, 38), - new CBC_QRCoderECB(2, 39)), - new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(4, 18), - new CBC_QRCoderECB(2, 19)), - new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 14), - new CBC_QRCoderECB(2, 15)))); - VERSION->push_back(new CBC_QRCoderVersion( - 9, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(2, 116)), - new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(3, 36), - new CBC_QRCoderECB(2, 37)), - new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(4, 16), - new CBC_QRCoderECB(4, 17)), - new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(4, 12), - new CBC_QRCoderECB(4, 13)))); - VERSION->push_back(new CBC_QRCoderVersion( - 10, new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 68), - new CBC_QRCoderECB(2, 69)), - new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 43), - new CBC_QRCoderECB(1, 44)), - new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(6, 19), - new CBC_QRCoderECB(2, 20)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(6, 15), - new CBC_QRCoderECB(2, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 11, new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(4, 81)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(1, 50), - new CBC_QRCoderECB(4, 51)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(4, 22), - new CBC_QRCoderECB(4, 23)), - new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(3, 12), - new CBC_QRCoderECB(8, 13)))); - VERSION->push_back(new CBC_QRCoderVersion( - 12, new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(2, 92), - new CBC_QRCoderECB(2, 93)), - new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(6, 36), - new CBC_QRCoderECB(2, 37)), - new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 20), - new CBC_QRCoderECB(6, 21)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(7, 14), - new CBC_QRCoderECB(4, 15)))); - VERSION->push_back(new CBC_QRCoderVersion( - 13, new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 107)), - new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(8, 37), - new CBC_QRCoderECB(1, 38)), - new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(8, 20), - new CBC_QRCoderECB(4, 21)), - new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(12, 11), - new CBC_QRCoderECB(4, 12)))); - VERSION->push_back(new CBC_QRCoderVersion( - 14, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(3, 115), - new CBC_QRCoderECB(1, 116)), - new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(4, 40), - new CBC_QRCoderECB(5, 41)), - new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(11, 16), - new CBC_QRCoderECB(5, 17)), - new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(11, 12), - new CBC_QRCoderECB(5, 13)))); - VERSION->push_back(new CBC_QRCoderVersion( - 15, new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(5, 87), - new CBC_QRCoderECB(1, 88)), - new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(5, 41), - new CBC_QRCoderECB(5, 42)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(5, 24), - new CBC_QRCoderECB(7, 25)), - new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(11, 12), - new CBC_QRCoderECB(7, 13)))); - VERSION->push_back(new CBC_QRCoderVersion( - 16, new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(5, 98), - new CBC_QRCoderECB(1, 99)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(7, 45), - new CBC_QRCoderECB(3, 46)), - new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(15, 19), - new CBC_QRCoderECB(2, 20)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(3, 15), - new CBC_QRCoderECB(13, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 17, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(1, 107), - new CBC_QRCoderECB(5, 108)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(10, 46), - new CBC_QRCoderECB(1, 47)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(1, 22), - new CBC_QRCoderECB(15, 23)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(2, 14), - new CBC_QRCoderECB(17, 15)))); - VERSION->push_back(new CBC_QRCoderVersion( - 18, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(5, 120), - new CBC_QRCoderECB(1, 121)), - new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(9, 43), - new CBC_QRCoderECB(4, 44)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(17, 22), - new CBC_QRCoderECB(1, 23)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(2, 14), - new CBC_QRCoderECB(19, 15)))); - VERSION->push_back(new CBC_QRCoderVersion( - 19, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(3, 113), - new CBC_QRCoderECB(4, 114)), - new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(3, 44), - new CBC_QRCoderECB(11, 45)), - new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(17, 21), - new CBC_QRCoderECB(4, 22)), - new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(9, 13), - new CBC_QRCoderECB(16, 14)))); - VERSION->push_back(new CBC_QRCoderVersion( - 20, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(3, 107), - new CBC_QRCoderECB(5, 108)), - new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(3, 41), - new CBC_QRCoderECB(13, 42)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(15, 24), - new CBC_QRCoderECB(5, 25)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(15, 15), - new CBC_QRCoderECB(10, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 21, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(4, 116), - new CBC_QRCoderECB(4, 117)), - new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(17, 42)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(17, 22), - new CBC_QRCoderECB(6, 23)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(19, 16), - new CBC_QRCoderECB(6, 17)))); - VERSION->push_back(new CBC_QRCoderVersion( - 22, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(2, 111), - new CBC_QRCoderECB(7, 112)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(17, 46)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(7, 24), - new CBC_QRCoderECB(16, 25)), - new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(34, 13)))); - VERSION->push_back(new CBC_QRCoderVersion( - 23, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(4, 121), - new CBC_QRCoderECB(5, 122)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(4, 47), - new CBC_QRCoderECB(14, 48)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(11, 24), - new CBC_QRCoderECB(14, 25)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(16, 15), - new CBC_QRCoderECB(14, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 24, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(6, 117), - new CBC_QRCoderECB(4, 118)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(6, 45), - new CBC_QRCoderECB(14, 46)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(11, 24), - new CBC_QRCoderECB(16, 25)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(30, 16), - new CBC_QRCoderECB(2, 17)))); - VERSION->push_back(new CBC_QRCoderVersion( - 25, new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(8, 106), - new CBC_QRCoderECB(4, 107)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(8, 47), - new CBC_QRCoderECB(13, 48)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(7, 24), - new CBC_QRCoderECB(22, 25)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(22, 15), - new CBC_QRCoderECB(13, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 26, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(10, 114), - new CBC_QRCoderECB(2, 115)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(19, 46), - new CBC_QRCoderECB(4, 47)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(28, 22), - new CBC_QRCoderECB(6, 23)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(33, 16), - new CBC_QRCoderECB(4, 17)))); - VERSION->push_back(new CBC_QRCoderVersion( - 27, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(8, 122), - new CBC_QRCoderECB(4, 123)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(22, 45), - new CBC_QRCoderECB(3, 46)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(8, 23), - new CBC_QRCoderECB(26, 24)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(12, 15), - new CBC_QRCoderECB(28, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 28, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(3, 117), - new CBC_QRCoderECB(10, 118)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(3, 45), - new CBC_QRCoderECB(23, 46)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(4, 24), - new CBC_QRCoderECB(31, 25)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(11, 15), - new CBC_QRCoderECB(31, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 29, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(7, 116), - new CBC_QRCoderECB(7, 117)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(21, 45), - new CBC_QRCoderECB(7, 46)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(1, 23), - new CBC_QRCoderECB(37, 24)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(19, 15), - new CBC_QRCoderECB(26, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 30, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(5, 115), - new CBC_QRCoderECB(10, 116)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(19, 47), - new CBC_QRCoderECB(10, 48)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(15, 24), - new CBC_QRCoderECB(25, 25)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(23, 15), - new CBC_QRCoderECB(25, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 31, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(13, 115), - new CBC_QRCoderECB(3, 116)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(2, 46), - new CBC_QRCoderECB(29, 47)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(42, 24), - new CBC_QRCoderECB(1, 25)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(23, 15), - new CBC_QRCoderECB(28, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 32, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(17, 115)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(10, 46), - new CBC_QRCoderECB(23, 47)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(10, 24), - new CBC_QRCoderECB(35, 25)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(19, 15), - new CBC_QRCoderECB(35, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 33, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(17, 115), - new CBC_QRCoderECB(1, 116)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(14, 46), - new CBC_QRCoderECB(21, 47)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(29, 24), - new CBC_QRCoderECB(19, 25)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(11, 15), - new CBC_QRCoderECB(46, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 34, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(13, 115), - new CBC_QRCoderECB(6, 116)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(14, 46), - new CBC_QRCoderECB(23, 47)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(44, 24), - new CBC_QRCoderECB(7, 25)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(59, 16), - new CBC_QRCoderECB(1, 17)))); - VERSION->push_back(new CBC_QRCoderVersion( - 35, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(12, 121), - new CBC_QRCoderECB(7, 122)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(12, 47), - new CBC_QRCoderECB(26, 48)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(39, 24), - new CBC_QRCoderECB(14, 25)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(22, 15), - new CBC_QRCoderECB(41, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 36, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(6, 121), - new CBC_QRCoderECB(14, 122)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(6, 47), - new CBC_QRCoderECB(34, 48)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(46, 24), - new CBC_QRCoderECB(10, 25)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(2, 15), - new CBC_QRCoderECB(64, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 37, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(17, 122), - new CBC_QRCoderECB(4, 123)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(29, 46), - new CBC_QRCoderECB(14, 47)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(49, 24), - new CBC_QRCoderECB(10, 25)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(24, 15), - new CBC_QRCoderECB(46, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 38, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(4, 122), - new CBC_QRCoderECB(18, 123)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(13, 46), - new CBC_QRCoderECB(32, 47)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(48, 24), - new CBC_QRCoderECB(14, 25)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(42, 15), - new CBC_QRCoderECB(32, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 39, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(20, 117), - new CBC_QRCoderECB(4, 118)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(40, 47), - new CBC_QRCoderECB(7, 48)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(43, 24), - new CBC_QRCoderECB(22, 25)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(10, 15), - new CBC_QRCoderECB(67, 16)))); - VERSION->push_back(new CBC_QRCoderVersion( - 40, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(19, 118), - new CBC_QRCoderECB(6, 119)), - new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(18, 47), - new CBC_QRCoderECB(31, 48)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(34, 24), - new CBC_QRCoderECB(34, 25)), - new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(20, 15), - new CBC_QRCoderECB(61, 16)))); - } - if (versionNumber < 1 || versionNumber > 40) { - e = BCExceptionIllegalArgument; - return nullptr; - } - return (*VERSION)[versionNumber - 1]; -} - -void CBC_QRCoderVersion::Destroy() { - for (size_t i = 0; i < VERSION->size(); i++) - delete (*VERSION)[i]; - VERSION->clear(); -} diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderVersion.h b/xfa/fxbarcode/qrcode/BC_QRCoderVersion.h deleted file mode 100644 index 853a93ed0c..0000000000 --- a/xfa/fxbarcode/qrcode/BC_QRCoderVersion.h +++ /dev/null @@ -1,57 +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_FXBARCODE_QRCODE_BC_QRCODERVERSION_H_ -#define XFA_FXBARCODE_QRCODE_BC_QRCODERVERSION_H_ - -#include <vector> - -#include "core/fxcrt/fx_basic.h" - -class CBC_CommonBitMatrix; -class CBC_QRCoderECBlocks; -class CBC_QRCoderErrorCorrectionLevel; - -class CBC_QRCoderVersion { - public: - virtual ~CBC_QRCoderVersion(); - static void Initialize(); - static void Finalize(); - - int32_t GetVersionNumber(); - int32_t GetTotalCodeWords(); - int32_t GetDimensionForVersion(); - CBC_CommonBitMatrix* BuildFunctionPattern(int32_t& e); - std::vector<int32_t>* GetAlignmentPatternCenters(); - CBC_QRCoderECBlocks* GetECBlocksForLevel( - CBC_QRCoderErrorCorrectionLevel* ecLevel); - static CBC_QRCoderVersion* GetVersionForNumber(int32_t versionNumber, - int32_t& e); - static CBC_QRCoderVersion* GetProvisionalVersionForDimension( - int32_t dimension, - int32_t& e); - static CBC_QRCoderVersion* DecodeVersionInformation(int32_t versionBits, - int32_t& e); - static void Destroy(); - - private: - CBC_QRCoderVersion(); - CBC_QRCoderVersion(int32_t versionNumber, - CBC_QRCoderECBlocks* ecBlocks1, - CBC_QRCoderECBlocks* ecBlocks2, - CBC_QRCoderECBlocks* ecBlocks3, - CBC_QRCoderECBlocks* ecBlocks4); - - static const int32_t VERSION_DECODE_INFO[34]; - static std::vector<CBC_QRCoderVersion*>* VERSION; - - int32_t m_versionNumber; - int32_t m_totalCodeWords; - std::vector<int32_t> m_alignmentPatternCenters; - std::vector<CBC_QRCoderECBlocks*> m_ecBlocksArray; -}; - -#endif // XFA_FXBARCODE_QRCODE_BC_QRCODERVERSION_H_ diff --git a/xfa/fxbarcode/utils.h b/xfa/fxbarcode/utils.h deleted file mode 100644 index 93a3c576cb..0000000000 --- a/xfa/fxbarcode/utils.h +++ /dev/null @@ -1,171 +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_FXBARCODE_UTILS_H_ -#define XFA_FXBARCODE_UTILS_H_ - -#include <vector> - -#include "core/fxcrt/fx_basic.h" - -bool BC_FX_ByteString_Replace(CFX_ByteString& dst, - uint32_t first, - uint32_t last, - int32_t count, - char c); -void BC_FX_ByteString_Append(CFX_ByteString& dst, int32_t count, char c); -void BC_FX_ByteString_Append(CFX_ByteString& dst, - const std::vector<uint8_t>& ba); - -#if (_FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_) -#include <limits> -#elif(_FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_LINUX_DESKTOP_ || \ - _FX_OS_ == _FX_IOS_) -#include <limits.h> -#endif -#if (_FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_) -#define FXSYS_isnan(x) _isnan(x) -#elif(_FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_IOS_ || \ - _FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_ANDROID_) -#include <cmath> -#define FXSYS_isnan(x) std::isnan(x) -#endif -#if (_FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_) -#define FXSYS_nan() (std::numeric_limits<float>::quiet_NaN()) -#elif(_FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_LINUX_DESKTOP_ || \ - _FX_OS_ == _FX_IOS_ || _FX_OS_ == _FX_ANDROID_) -#define FXSYS_nan() NAN -#endif -enum BCFORMAT { - BCFORMAT_UNSPECIFY = -1, - BCFORMAT_CODABAR, - BCFORMAT_CODE_39, - BCFORMAT_CODE_128, - BCFORMAT_CODE_128B, - BCFORMAT_CODE_128C, - BCFORMAT_EAN_8, - BCFORMAT_UPC_A, - BCFORMAT_EAN_13, - BCFORMAT_PDF_417, - BCFORMAT_DATAMATRIX, - BCFORMAT_QR_CODE -}; -#define BCFORMAT_ECLEVEL_L 0 -#define BCFORMAT_ECLEVEL_M 1 -#define BCFORMAT_ECLEVEL_Q 2 -#define BCFORMAT_ECLEVEL_H 3 -#include <ctype.h> -#define FXSYS_IntMax INT_MAX -#define FXSYS_Isdigit isdigit -#define BCExceptionNO 0 -#define BCExceptionNotFound 1 -#define BCExceptionEndLessThanStart 2 -#define BCExceptionUnknownDecoder 3 -#define BCExceptionRotateNotSupported 4 -#define BCExceptionHeightAndWidthMustBeAtLeast1 5 -#define BCExceptionRegionMustFitInsideMatrix 6 -#define BCExceptionCanNotCallGetDimensionOnNonSquareMatrix 7 -#define BCExceptionFormatException 8 -#define BCExceptionIllegalArgumentMustMatchVersionSize 9 -#define BCExceptionChecksumException 10 -#define BCExceptionIllegalArgumentInvalidFirstDigit 11 -#define BCExceptionIllegalArgumentInvalidSecondDigit 12 -#define BCExceptionRuntimeDecodingInvalidISO_IEC 13 -#define BCExceptionRuntimeDecodingInvalidAlphanumeric 14 -#define BCExceptionLeftAndTopMustBeNonnegative 15 -#define BCExceptionIllegalArgument 16 -#define BCExceptionBadECI 17 -#define BCExceptionUnSupportedBarcode 18 -#define BCExceptionUnSupportedString 19 -#define BCExceptionDigitLengthMustBe8 20 -#define BCExceptionDataCheckException 21 -#define BCExceptionExtractNumberValueFromBitArray 22 -#define BCExceptionRead 23 -#define BCExceptionRequestedRowIsOutSizeTheImage 24 -#define BCExceptionNoContents 26 -#define BCExceptionUnSupportEclevel 27 -#define BCExceptionUnSupportMode 28 -#define BCExceptionReferenceMustBeBetween0And7 29 -#define BCExceptionBadErrorLocation 30 -#define BCExceptionDegreeIsNegative 31 -#define BCExceptionDivideByZero 32 -#define BCExceptionCoefficientsSizeIsNull 33 -#define BCExceptionNoCorrectionBytes 34 -#define BCExceptionNoDataBytesProvided 35 -#define BCExceptionR_I_1IsZero 36 -#define BCExceptionAIsZero 37 -#define BCExceptionIsZero 38 -#define BCExceptionDegreeNotMatchRoots 39 -#define BCExceptionContentsLengthShouldBetween1and80 40 -#define BCExceptionOnlyEncodeCODE_128 41 -#define BCExceptionOnlyEncodeCODE_39 42 -#define BCExceptionOnlyEncodeEAN_13 43 -#define BCExceptionOnlyEncodeEAN_8 44 -#define BCExceptionOnlyEncodeITF 45 -#define BCExceptionDigitLengthShould13 46 -#define BCExceptionDigitLengthMustBe6or8or10or12or14or16or20or24or44 47 -#define BCExceptionOnlyEncodeUPC_A 48 -#define BCExceptionDigitLengthShouldBe12 49 -#define BCExceptionValueMustBeEither0or1 50 -#define BCExceptionReedsolomnDecodeException 51 -#define BCExceptionBadIndexException 52 -#define BCExceptionBadValueException 53 -#define BCExceptionBadNumBitsException 54 -#define BCExceptioncanNotOperatexorOperator 55 -#define BCExceptionVersionMust1_40 56 -#define BCExceptionUnknown 57 -#define BCExceptionNoSuchVersion 58 -#define BCExceptionCannotFindBlockInfo 59 -#define BCExceptionDataTooBig 60 -#define BCExceptionInvalidQRCode 61 -#define BCExceptionDataTooMany 62 -#define BCExceptionBitsNotEqualCacity 63 -#define BCExceptionUnsupportedMode 64 -#define BCExceptionInvalidateCharacter 65 -#define BCExceptionBytesNotMatchOffset 66 -#define BCExceptionSizeInBytesDiffer 67 -#define BCExceptionInvalidateMaskPattern 68 -#define BCExceptionNullPointer 69 -#define BCExceptionBadMask 70 -#define BCExceptionBitSizeNot15 71 -#define BCExceptionBitSizeNot18 72 -#define BCExceptionInvalidateImageData 73 -#define BCExceptionHeight_8BeZero 74 -#define BCExceptionCharacterNotThisMode 75 -#define BCExceptionBitsBytesNotMatch 76 -#define BCExceptionInvalidateData 77 -#define BCExceptionLoadFile 78 -#define BCExceptionPDF417EncodeFail 79 -#define BCExceptionFailToCreateBitmap 80 -#define BCExceptionLoadFontFail 81 -#define BCExceptionOnlyEncodeCODEBAR 82 -#define BCExceptionCodabarShouldStartWithOneOfABCD 83 -#define BCExceptionCodabarShouldEndWithOneOfTNE 84 -#define BCExceptionCodabarEncodeCharsInvalid 85 -#define BCExceptionOnlyEncodeDATAMATRIX 86 -#define BCExceptionCharactersOutsideISO88591Encoding 87 -#define BCExceptionIllegalDataCodewords 88 -#define BCExceptionCannotHandleThisNumberOfDataRegions 89 -#define BCExceptionIllegalStateUnexpectedCase 90 -#define BCExceptionIllegalStateCountMustNotExceed4 91 -#define BCExceptionIllegalStateMessageLengthInvalid 92 -#define BCExceptionIllegalArgumentNotGigits 93 -#define BCExceptionIllegalStateIllegalMode 94 -#define BCExceptionOnlyEncodePDF417 95 -#define BCExceptionNonEncodableCharacterDetected 96 -#define BCExceptionErrorCorrectionLevelMustBeBetween0And8 97 -#define BCExceptionNoRecommendationPossible 98 -#define BCExceptionIllegalArgumentnMustBeAbove0 99 -#define BCExceptionUnableToFitMessageInColumns 100 -#define BCExceptionEncodedMessageContainsTooManyCodeWords 101 -#define BCExceptionBitmapSizeError 102 -#define BCExceptionFormatInstance 102 -#define BCExceptionChecksumInstance 103 -#define BCExceptiontNotFoundInstance 104 -#define BCExceptionNotFoundInstance 105 -#define BCExceptionCannotMetadata 106 - -#endif // XFA_FXBARCODE_UTILS_H_ |