summaryrefslogtreecommitdiff
path: root/xfa/fxbarcode/oned
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxbarcode/oned')
-rw-r--r--xfa/fxbarcode/oned/BC_OneDimWriter.cpp482
-rw-r--r--xfa/fxbarcode/oned/BC_OneDimWriter.h118
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCodaBarWriter.cpp239
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h58
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCode128Writer.cpp276
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCode128Writer.h55
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp284
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCode39Writer.h54
-rw-r--r--xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp306
-rw-r--r--xfa/fxbarcode/oned/BC_OnedEAN13Writer.h60
-rw-r--r--xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp268
-rw-r--r--xfa/fxbarcode/oned/BC_OnedEAN8Writer.h64
-rw-r--r--xfa/fxbarcode/oned/BC_OnedUPCAWriter.cpp286
-rw-r--r--xfa/fxbarcode/oned/BC_OnedUPCAWriter.h66
14 files changed, 0 insertions, 2616 deletions
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_