summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fxbarcode/BC_TwoDimWriter.cpp17
-rw-r--r--fxbarcode/BC_TwoDimWriter.h5
-rw-r--r--fxbarcode/cbc_codabar.cpp67
-rw-r--r--fxbarcode/cbc_codabar.h13
-rw-r--r--fxbarcode/cbc_code128.cpp55
-rw-r--r--fxbarcode/cbc_code128.h11
-rw-r--r--fxbarcode/cbc_code39.cpp64
-rw-r--r--fxbarcode/cbc_code39.h13
-rw-r--r--fxbarcode/cbc_codebase.cpp16
-rw-r--r--fxbarcode/cbc_codebase.h11
-rw-r--r--fxbarcode/cbc_datamatrix.cpp31
-rw-r--r--fxbarcode/cbc_datamatrix.h13
-rw-r--r--fxbarcode/cbc_ean13.cpp48
-rw-r--r--fxbarcode/cbc_ean13.h11
-rw-r--r--fxbarcode/cbc_ean8.cpp48
-rw-r--r--fxbarcode/cbc_ean8.h10
-rw-r--r--fxbarcode/cbc_onecode.cpp36
-rw-r--r--fxbarcode/cbc_onecode.h6
-rw-r--r--fxbarcode/cbc_pdf417i.cpp36
-rw-r--r--fxbarcode/cbc_pdf417i.h14
-rw-r--r--fxbarcode/cbc_qrcode.cpp26
-rw-r--r--fxbarcode/cbc_qrcode.h9
-rw-r--r--fxbarcode/cbc_upca.cpp45
-rw-r--r--fxbarcode/cbc_upca.h12
-rw-r--r--fxbarcode/datamatrix/BC_DataMatrixWriter.cpp126
-rw-r--r--fxbarcode/datamatrix/BC_DataMatrixWriter.h10
-rw-r--r--fxbarcode/oned/BC_OneDimWriter.cpp175
-rw-r--r--fxbarcode/oned/BC_OneDimWriter.h50
-rw-r--r--fxbarcode/oned/BC_OnedCodaBarWriter.cpp68
-rw-r--r--fxbarcode/oned/BC_OnedCodaBarWriter.h38
-rw-r--r--fxbarcode/oned/BC_OnedCode128Writer.cpp94
-rw-r--r--fxbarcode/oned/BC_OnedCode128Writer.h26
-rw-r--r--fxbarcode/oned/BC_OnedCode39Writer.cpp195
-rw-r--r--fxbarcode/oned/BC_OnedCode39Writer.h38
-rw-r--r--fxbarcode/oned/BC_OnedEAN13Writer.cpp145
-rw-r--r--fxbarcode/oned/BC_OnedEAN13Writer.h31
-rw-r--r--fxbarcode/oned/BC_OnedEAN8Writer.cpp151
-rw-r--r--fxbarcode/oned/BC_OnedEAN8Writer.h32
-rw-r--r--fxbarcode/oned/BC_OnedUPCAWriter.cpp89
-rw-r--r--fxbarcode/oned/BC_OnedUPCAWriter.h32
-rw-r--r--fxbarcode/pdf417/BC_PDF417Writer.cpp26
-rw-r--r--fxbarcode/pdf417/BC_PDF417Writer.h3
-rw-r--r--fxbarcode/qrcode/BC_QRCodeWriter.cpp10
-rw-r--r--fxbarcode/qrcode/BC_QRCodeWriter.h3
-rw-r--r--fxbarcode/qrcode/BC_QRCoderEncoder.cpp99
-rw-r--r--fxbarcode/qrcode/BC_QRCoderEncoder.h5
-rw-r--r--fxbarcode/utils.h19
-rw-r--r--xfa/fwl/cfwl_barcode.cpp9
-rw-r--r--xfa/fwl/cfwl_barcode.h4
-rw-r--r--xfa/fwl/cfx_barcode.cpp16
-rw-r--r--xfa/fwl/cfx_barcode.h8
-rw-r--r--xfa/fxfa/app/xfa_ffbarcode.cpp2
52 files changed, 863 insertions, 1258 deletions
diff --git a/fxbarcode/BC_TwoDimWriter.cpp b/fxbarcode/BC_TwoDimWriter.cpp
index 9906f35bd5..6852fee35c 100644
--- a/fxbarcode/BC_TwoDimWriter.cpp
+++ b/fxbarcode/BC_TwoDimWriter.cpp
@@ -57,10 +57,9 @@ int32_t CBC_TwoDimWriter::GetErrorCorrectionLevel() const {
return m_iCorrectLevel;
}
-void CBC_TwoDimWriter::RenderResult(uint8_t* code,
+bool CBC_TwoDimWriter::RenderResult(uint8_t* code,
int32_t codeWidth,
- int32_t codeHeight,
- int32_t& e) {
+ int32_t codeHeight) {
int32_t inputWidth = codeWidth;
int32_t inputHeight = codeHeight;
int32_t tempWidth = inputWidth + 2;
@@ -77,8 +76,7 @@ void CBC_TwoDimWriter::RenderResult(uint8_t* code,
int32_t outputHeight = scaledHeight.ValueOrDie();
if (m_bFixedSize) {
if (m_Width < outputWidth || m_Height < outputHeight) {
- e = BCExceptionBitmapSizeError;
- return;
+ return false;
}
} else {
if (m_Width > outputWidth || m_Height > outputHeight) {
@@ -104,12 +102,11 @@ void CBC_TwoDimWriter::RenderResult(uint8_t* code,
for (int32_t inputX = 0, outputX = leftPadding;
(inputX < inputWidth) && (outputX < outputWidth - multiX);
inputX++, outputX += multiX) {
- if (code[inputX + inputY * inputWidth] == 1) {
- if (!m_output->SetRegion(outputX, outputY, multiX, multiY)) {
- e = BCExceptionGeneric;
- return;
- }
+ if (code[inputX + inputY * inputWidth] == 1 &&
+ !m_output->SetRegion(outputX, outputY, multiX, multiY)) {
+ return false;
}
}
}
+ return true;
}
diff --git a/fxbarcode/BC_TwoDimWriter.h b/fxbarcode/BC_TwoDimWriter.h
index f7d02de2b1..e554805fcf 100644
--- a/fxbarcode/BC_TwoDimWriter.h
+++ b/fxbarcode/BC_TwoDimWriter.h
@@ -20,10 +20,9 @@ class CBC_TwoDimWriter : public CBC_Writer {
CBC_TwoDimWriter();
~CBC_TwoDimWriter() override;
- virtual void RenderResult(uint8_t* code,
+ virtual bool RenderResult(uint8_t* code,
int32_t codeWidth,
- int32_t codeHeight,
- int32_t& e);
+ int32_t codeHeight);
virtual void RenderDeviceResult(CFX_RenderDevice* device,
const CFX_Matrix* matrix);
virtual bool SetErrorCorrectionLevel(int32_t level) = 0;
diff --git a/fxbarcode/cbc_codabar.cpp b/fxbarcode/cbc_codabar.cpp
index c10491707f..1d671cebb3 100644
--- a/fxbarcode/cbc_codabar.cpp
+++ b/fxbarcode/cbc_codabar.cpp
@@ -21,6 +21,8 @@
#include "fxbarcode/cbc_codabar.h"
+#include <memory>
+
#include "fxbarcode/oned/BC_OnedCodaBarWriter.h"
CBC_Codabar::CBC_Codabar() : CBC_OneCode(new CBC_OnedCodaBarWriter) {}
@@ -28,71 +30,54 @@ 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);
+ return GetOnedCodaBarWriter()->SetStartChar(start);
}
bool CBC_Codabar::SetEndChar(char end) {
- if (m_pBCWriter)
- return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
- ->SetEndChar(end);
- return false;
+ return GetOnedCodaBarWriter()->SetEndChar(end);
}
bool CBC_Codabar::SetTextLocation(BC_TEXT_LOC location) {
- return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
- ->SetTextLocation(location);
+ return GetOnedCodaBarWriter()->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::SetWideNarrowRatio(int8_t ratio) {
+ return GetOnedCodaBarWriter()->SetWideNarrowRatio(ratio);
}
-bool CBC_Codabar::Encode(const CFX_WideStringC& contents,
- bool isDevice,
- int32_t& e) {
- if (contents.IsEmpty()) {
- e = BCExceptionNoContents;
+bool CBC_Codabar::Encode(const CFX_WideStringC& contents, bool isDevice) {
+ if (contents.IsEmpty())
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);
+ GetOnedCodaBarWriter()->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)
+ auto* pWriter = GetOnedCodaBarWriter();
+ std::unique_ptr<uint8_t, FxFreeDeleter> data(
+ pWriter->Encode(byteString, format, outWidth, outHeight));
+ if (!data)
return false;
- return true;
+
+ return pWriter->RenderResult(filtercontents.AsStringC(), data.get(), outWidth,
+ isDevice);
}
bool CBC_Codabar::RenderDevice(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t& e) {
+ const CFX_Matrix* matrix) {
+ auto* pWriter = GetOnedCodaBarWriter();
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;
+ pWriter->encodedContents(m_renderContents.AsStringC());
+ return pWriter->RenderDeviceResult(device, matrix, renderCon.AsStringC());
}
BC_TYPE CBC_Codabar::GetType() {
return BC_CODABAR;
}
+
+CBC_OnedCodaBarWriter* CBC_Codabar::GetOnedCodaBarWriter() {
+ return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get());
+}
diff --git a/fxbarcode/cbc_codabar.h b/fxbarcode/cbc_codabar.h
index 253a7aaaf1..3877819f8d 100644
--- a/fxbarcode/cbc_codabar.h
+++ b/fxbarcode/cbc_codabar.h
@@ -12,26 +12,27 @@
#include "core/fxge/fx_dib.h"
#include "fxbarcode/cbc_onecode.h"
+class CBC_OnedCodaBarWriter;
+
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 Encode(const CFX_WideStringC& contents, bool isDevice) override;
bool RenderDevice(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t& e) override;
+ const CFX_Matrix* matrix) override;
BC_TYPE GetType() override;
bool SetStartChar(char start);
bool SetEndChar(char end);
bool SetTextLocation(BC_TEXT_LOC location);
- bool SetWideNarrowRatio(int32_t ratio);
+ bool SetWideNarrowRatio(int8_t ratio);
private:
+ CBC_OnedCodaBarWriter* GetOnedCodaBarWriter();
+
CFX_WideString m_renderContents;
};
diff --git a/fxbarcode/cbc_code128.cpp b/fxbarcode/cbc_code128.cpp
index 5a4f556513..822aba06bc 100644
--- a/fxbarcode/cbc_code128.cpp
+++ b/fxbarcode/cbc_code128.cpp
@@ -21,6 +21,8 @@
#include "fxbarcode/cbc_code128.h"
+#include <memory>
+
#include "fxbarcode/oned/BC_OnedCode128Writer.h"
CBC_Code128::CBC_Code128(BC_TYPE type)
@@ -29,55 +31,42 @@ CBC_Code128::CBC_Code128(BC_TYPE 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;
+ return GetOnedCode128Writer()->SetTextLocation(location);
}
-bool CBC_Code128::Encode(const CFX_WideStringC& contents,
- bool isDevice,
- int32_t& e) {
- if (contents.IsEmpty()) {
- e = BCExceptionNoContents;
+bool CBC_Code128::Encode(const CFX_WideStringC& contents, bool isDevice) {
+ if (contents.IsEmpty())
return false;
- }
+
BCFORMAT format = BCFORMAT_CODE_128;
int32_t outWidth = 0;
int32_t outHeight = 0;
+ auto* pWriter = GetOnedCode128Writer();
CFX_WideString content(contents);
- if (contents.GetLength() % 2 &&
- static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get())->GetType() ==
- BC_CODE128_C) {
+ if (contents.GetLength() % 2 && pWriter->GetType() == BC_CODE128_C)
content += '0';
- }
- CFX_WideString encodeContents =
- static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get())
- ->FilterContents(content.AsStringC());
+
+ CFX_WideString encodeContents = pWriter->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)
+ std::unique_ptr<uint8_t, FxFreeDeleter> data(
+ pWriter->Encode(byteString, format, outWidth, outHeight));
+ if (!data)
return false;
- return true;
+ return pWriter->RenderResult(encodeContents.AsStringC(), data.get(), outWidth,
+ isDevice);
}
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;
+ const CFX_Matrix* matrix) {
+ return GetOnedCode128Writer()->RenderDeviceResult(
+ device, matrix, m_renderContents.AsStringC());
}
BC_TYPE CBC_Code128::GetType() {
return BC_CODE128;
}
+
+CBC_OnedCode128Writer* CBC_Code128::GetOnedCode128Writer() {
+ return static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get());
+}
diff --git a/fxbarcode/cbc_code128.h b/fxbarcode/cbc_code128.h
index 4bff4a7aa4..603587f908 100644
--- a/fxbarcode/cbc_code128.h
+++ b/fxbarcode/cbc_code128.h
@@ -12,23 +12,24 @@
#include "core/fxge/fx_dib.h"
#include "fxbarcode/cbc_onecode.h"
+class CBC_OnedCode128Writer;
+
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 Encode(const CFX_WideStringC& contents, bool isDevice) override;
bool RenderDevice(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t& e) override;
+ const CFX_Matrix* matrix) override;
BC_TYPE GetType() override;
bool SetTextLocation(BC_TEXT_LOC loction);
private:
+ CBC_OnedCode128Writer* GetOnedCode128Writer();
+
CFX_WideString m_renderContents;
};
diff --git a/fxbarcode/cbc_code39.cpp b/fxbarcode/cbc_code39.cpp
index 94b7602974..8b7e08b67e 100644
--- a/fxbarcode/cbc_code39.cpp
+++ b/fxbarcode/cbc_code39.cpp
@@ -21,53 +21,41 @@
#include "fxbarcode/cbc_code39.h"
+#include <memory>
+
#include "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;
+bool CBC_Code39::Encode(const CFX_WideStringC& contents, bool isDevice) {
+ if (contents.IsEmpty())
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);
+ auto* pWriter = GetOnedCode39Writer();
+ CFX_WideString filtercontents = pWriter->FilterContents(contents);
+ CFX_WideString renderContents = pWriter->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)
+ std::unique_ptr<uint8_t, FxFreeDeleter> data(
+ pWriter->Encode(byteString, format, outWidth, outHeight));
+ if (!data)
return false;
- return true;
+ return pWriter->RenderResult(renderContents.AsStringC(), data.get(), outWidth,
+ isDevice);
}
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)
+ const CFX_Matrix* matrix) {
+ auto* pWriter = GetOnedCode39Writer();
+ CFX_WideString renderCon;
+ if (!pWriter->encodedContents(m_renderContents.AsStringC(), &renderCon))
return false;
- return true;
+ return pWriter->RenderDeviceResult(device, matrix, renderCon.AsStringC());
}
BC_TYPE CBC_Code39::GetType() {
@@ -75,15 +63,13 @@ BC_TYPE CBC_Code39::GetType() {
}
bool CBC_Code39::SetTextLocation(BC_TEXT_LOC location) {
- if (m_pBCWriter)
- return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
- ->SetTextLocation(location);
- return false;
+ return GetOnedCode39Writer()->SetTextLocation(location);
+}
+
+bool CBC_Code39::SetWideNarrowRatio(int8_t ratio) {
+ return GetOnedCode39Writer()->SetWideNarrowRatio(ratio);
}
-bool CBC_Code39::SetWideNarrowRatio(int32_t ratio) {
- if (m_pBCWriter)
- return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
- ->SetWideNarrowRatio(ratio);
- return false;
+CBC_OnedCode39Writer* CBC_Code39::GetOnedCode39Writer() {
+ return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get());
}
diff --git a/fxbarcode/cbc_code39.h b/fxbarcode/cbc_code39.h
index f1e6acc848..4dea641a4f 100644
--- a/fxbarcode/cbc_code39.h
+++ b/fxbarcode/cbc_code39.h
@@ -13,24 +13,25 @@
#include "core/fxge/fx_dib.h"
#include "fxbarcode/cbc_onecode.h"
+class CBC_OnedCode39Writer;
+
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 Encode(const CFX_WideStringC& contents, bool isDevice) override;
bool RenderDevice(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t& e) override;
+ const CFX_Matrix* matrix) override;
BC_TYPE GetType() override;
bool SetTextLocation(BC_TEXT_LOC location);
- bool SetWideNarrowRatio(int32_t ratio);
+ bool SetWideNarrowRatio(int8_t ratio);
private:
+ CBC_OnedCode39Writer* GetOnedCode39Writer();
+
CFX_WideString m_renderContents;
};
diff --git a/fxbarcode/cbc_codebase.cpp b/fxbarcode/cbc_codebase.cpp
index df237c9136..f283473775 100644
--- a/fxbarcode/cbc_codebase.cpp
+++ b/fxbarcode/cbc_codebase.cpp
@@ -28,31 +28,29 @@ 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);
+ return m_pBCWriter->SetCharEncoding(encoding);
}
bool CBC_CodeBase::SetModuleHeight(int32_t moduleHeight) {
- return m_pBCWriter && m_pBCWriter->SetModuleHeight(moduleHeight);
+ return m_pBCWriter->SetModuleHeight(moduleHeight);
}
bool CBC_CodeBase::SetModuleWidth(int32_t moduleWidth) {
- return m_pBCWriter && m_pBCWriter->SetModuleWidth(moduleWidth);
+ return m_pBCWriter->SetModuleWidth(moduleWidth);
}
bool CBC_CodeBase::SetHeight(int32_t height) {
- return m_pBCWriter && m_pBCWriter->SetHeight(height);
+ return m_pBCWriter->SetHeight(height);
}
bool CBC_CodeBase::SetWidth(int32_t width) {
- return m_pBCWriter && m_pBCWriter->SetWidth(width);
+ return m_pBCWriter->SetWidth(width);
}
void CBC_CodeBase::SetBackgroundColor(FX_ARGB backgroundColor) {
- if (m_pBCWriter)
- m_pBCWriter->SetBackgroundColor(backgroundColor);
+ m_pBCWriter->SetBackgroundColor(backgroundColor);
}
void CBC_CodeBase::SetBarcodeColor(FX_ARGB foregroundColor) {
- if (m_pBCWriter)
- m_pBCWriter->SetBarcodeColor(foregroundColor);
+ m_pBCWriter->SetBarcodeColor(foregroundColor);
}
diff --git a/fxbarcode/cbc_codebase.h b/fxbarcode/cbc_codebase.h
index 370ff2c723..3c6b05129d 100644
--- a/fxbarcode/cbc_codebase.h
+++ b/fxbarcode/cbc_codebase.h
@@ -9,14 +9,14 @@
#include <memory>
-#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxge/fx_dib.h"
#include "fxbarcode/BC_Library.h"
-class CBC_Writer;
class CBC_Reader;
+class CBC_Writer;
class CFX_DIBitmap;
+class CFX_Matrix;
class CFX_RenderDevice;
class CBC_CodeBase {
@@ -25,12 +25,9 @@ class CBC_CodeBase {
virtual ~CBC_CodeBase();
virtual BC_TYPE GetType() = 0;
- virtual bool Encode(const CFX_WideStringC& contents,
- bool isDevice,
- int32_t& e) = 0;
+ virtual bool Encode(const CFX_WideStringC& contents, bool isDevice) = 0;
virtual bool RenderDevice(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t& e) = 0;
+ const CFX_Matrix* matrix) = 0;
bool SetCharEncoding(int32_t encoding);
bool SetModuleHeight(int32_t moduleHeight);
diff --git a/fxbarcode/cbc_datamatrix.cpp b/fxbarcode/cbc_datamatrix.cpp
index 3c6f638614..60b1f72d03 100644
--- a/fxbarcode/cbc_datamatrix.cpp
+++ b/fxbarcode/cbc_datamatrix.cpp
@@ -21,38 +21,35 @@
#include "fxbarcode/cbc_datamatrix.h"
+#include <memory>
+
#include "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) {
+bool CBC_DataMatrix::Encode(const CFX_WideStringC& contents, bool isDevice) {
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)
+ auto* pWriter = GetDataMatrixWriter();
+ std::unique_ptr<uint8_t, FxFreeDeleter> data(
+ pWriter->Encode(CFX_WideString(contents), outWidth, outHeight));
+ if (!data)
return false;
- return true;
+ return pWriter->RenderResult(data.get(), outWidth, outHeight);
}
bool CBC_DataMatrix::RenderDevice(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t& e) {
- static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
- ->RenderDeviceResult(device, matrix);
+ const CFX_Matrix* matrix) {
+ GetDataMatrixWriter()->RenderDeviceResult(device, matrix);
return true;
}
BC_TYPE CBC_DataMatrix::GetType() {
return BC_DATAMATRIX;
}
+
+CBC_DataMatrixWriter* CBC_DataMatrix::GetDataMatrixWriter() {
+ return static_cast<CBC_DataMatrixWriter*>(m_pBCWriter.get());
+}
diff --git a/fxbarcode/cbc_datamatrix.h b/fxbarcode/cbc_datamatrix.h
index 0bd8063bcf..73294f1a9e 100644
--- a/fxbarcode/cbc_datamatrix.h
+++ b/fxbarcode/cbc_datamatrix.h
@@ -7,25 +7,26 @@
#ifndef FXBARCODE_CBC_DATAMATRIX_H_
#define FXBARCODE_CBC_DATAMATRIX_H_
-#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxge/fx_dib.h"
#include "fxbarcode/cbc_codebase.h"
+class CBC_DataMatrixWriter;
+
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 Encode(const CFX_WideStringC& contents, bool isDevice) override;
bool RenderDevice(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t& e) override;
+ const CFX_Matrix* matrix) override;
BC_TYPE GetType() override;
+
+ private:
+ CBC_DataMatrixWriter* GetDataMatrixWriter();
};
#endif // FXBARCODE_CBC_DATAMATRIX_H_
diff --git a/fxbarcode/cbc_ean13.cpp b/fxbarcode/cbc_ean13.cpp
index 0ac7fdbe6e..73638b951f 100644
--- a/fxbarcode/cbc_ean13.cpp
+++ b/fxbarcode/cbc_ean13.cpp
@@ -21,6 +21,8 @@
#include "fxbarcode/cbc_ean13.h"
+#include <memory>
+
#include "fxbarcode/oned/BC_OnedEAN13Writer.h"
CBC_EAN13::CBC_EAN13() : CBC_OneCode(new CBC_OnedEAN13Writer) {}
@@ -28,17 +30,15 @@ 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);
+ auto* pWriter = GetOnedEAN13Writer();
+ CFX_WideString encodeContents = pWriter->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);
+ int32_t checksum = pWriter->CalcChecksum(byteString);
byteString += checksum - 0 + '0';
encodeContents = byteString.UTF8Decode();
}
@@ -48,41 +48,35 @@ CFX_WideString CBC_EAN13::Preprocess(const CFX_WideStringC& contents) {
return encodeContents;
}
-bool CBC_EAN13::Encode(const CFX_WideStringC& contents,
- bool isDevice,
- int32_t& e) {
- if (contents.IsEmpty()) {
- e = BCExceptionNoContents;
+bool CBC_EAN13::Encode(const CFX_WideStringC& contents, bool isDevice) {
+ if (contents.IsEmpty())
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)
+ auto* pWriter = GetOnedEAN13Writer();
+ std::unique_ptr<uint8_t, FxFreeDeleter> data(
+ pWriter->Encode(byteString, format, outWidth, outHeight));
+ if (!data)
return false;
- return true;
+ return pWriter->RenderResult(encodeContents.AsStringC(), data.get(), outWidth,
+ isDevice);
}
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;
+ const CFX_Matrix* matrix) {
+ return GetOnedEAN13Writer()->RenderDeviceResult(device, matrix,
+ m_renderContents.AsStringC());
}
BC_TYPE CBC_EAN13::GetType() {
return BC_EAN13;
}
+
+CBC_OnedEAN13Writer* CBC_EAN13::GetOnedEAN13Writer() {
+ return static_cast<CBC_OnedEAN13Writer*>(m_pBCWriter.get());
+}
diff --git a/fxbarcode/cbc_ean13.h b/fxbarcode/cbc_ean13.h
index 86e5ea207a..11d40bb386 100644
--- a/fxbarcode/cbc_ean13.h
+++ b/fxbarcode/cbc_ean13.h
@@ -13,22 +13,23 @@
#include "core/fxge/fx_dib.h"
#include "fxbarcode/cbc_onecode.h"
+class CBC_OnedEAN13Writer;
+
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 Encode(const CFX_WideStringC& contents, bool isDevice) override;
bool RenderDevice(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t& e) override;
+ const CFX_Matrix* matrix) override;
BC_TYPE GetType() override;
private:
+ CBC_OnedEAN13Writer* GetOnedEAN13Writer();
CFX_WideString Preprocess(const CFX_WideStringC& contents);
+
CFX_WideString m_renderContents;
};
diff --git a/fxbarcode/cbc_ean8.cpp b/fxbarcode/cbc_ean8.cpp
index f267dbe22d..e5c26e6535 100644
--- a/fxbarcode/cbc_ean8.cpp
+++ b/fxbarcode/cbc_ean8.cpp
@@ -21,6 +21,8 @@
#include "fxbarcode/cbc_ean8.h"
+#include <memory>
+
#include "fxbarcode/oned/BC_OnedEAN8Writer.h"
CBC_EAN8::CBC_EAN8() : CBC_OneCode(new CBC_OnedEAN8Writer) {}
@@ -28,17 +30,15 @@ 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);
+ auto* pWriter = GetOnedEAN8Writer();
+ CFX_WideString encodeContents = pWriter->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);
+ int32_t checksum = pWriter->CalcChecksum(byteString);
encodeContents += wchar_t(checksum - 0 + '0');
}
if (length > 8)
@@ -47,41 +47,35 @@ CFX_WideString CBC_EAN8::Preprocess(const CFX_WideStringC& contents) {
return encodeContents;
}
-bool CBC_EAN8::Encode(const CFX_WideStringC& contents,
- bool isDevice,
- int32_t& e) {
- if (contents.IsEmpty()) {
- e = BCExceptionNoContents;
+bool CBC_EAN8::Encode(const CFX_WideStringC& contents, bool isDevice) {
+ if (contents.IsEmpty())
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)
+ auto* pWriter = GetOnedEAN8Writer();
+ std::unique_ptr<uint8_t, FxFreeDeleter> data(
+ pWriter->Encode(byteString, format, outWidth, outHeight));
+ if (!data)
return false;
- return true;
+ return pWriter->RenderResult(encodeContents.AsStringC(), data.get(), outWidth,
+ isDevice);
}
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;
+ const CFX_Matrix* matrix) {
+ return GetOnedEAN8Writer()->RenderDeviceResult(device, matrix,
+ m_renderContents.AsStringC());
}
BC_TYPE CBC_EAN8::GetType() {
return BC_EAN8;
}
+
+CBC_OnedEAN8Writer* CBC_EAN8::GetOnedEAN8Writer() {
+ return static_cast<CBC_OnedEAN8Writer*>(m_pBCWriter.get());
+}
diff --git a/fxbarcode/cbc_ean8.h b/fxbarcode/cbc_ean8.h
index 7ddd2dea8b..d0f6ff8965 100644
--- a/fxbarcode/cbc_ean8.h
+++ b/fxbarcode/cbc_ean8.h
@@ -12,21 +12,21 @@
#include "core/fxge/fx_dib.h"
#include "fxbarcode/cbc_onecode.h"
+class CBC_OnedEAN8Writer;
+
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 Encode(const CFX_WideStringC& contents, bool isDevice) override;
bool RenderDevice(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t& e) override;
+ const CFX_Matrix* matrix) override;
BC_TYPE GetType() override;
private:
+ CBC_OnedEAN8Writer* GetOnedEAN8Writer();
CFX_WideString Preprocess(const CFX_WideStringC& contents);
CFX_WideString m_renderContents;
};
diff --git a/fxbarcode/cbc_onecode.cpp b/fxbarcode/cbc_onecode.cpp
index 1b4db0a170..ec7033a1f1 100644
--- a/fxbarcode/cbc_onecode.cpp
+++ b/fxbarcode/cbc_onecode.cpp
@@ -28,51 +28,41 @@ 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);
+ return GetOneDimWriter()->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);
+ return GetOneDimWriter()->FilterContents(contents);
}
void CBC_OneCode::SetPrintChecksum(bool checksum) {
- if (m_pBCWriter)
- static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
- ->SetPrintChecksum(checksum);
+ GetOneDimWriter()->SetPrintChecksum(checksum);
}
void CBC_OneCode::SetDataLength(int32_t length) {
- if (m_pBCWriter)
- static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetDataLength(length);
+ GetOneDimWriter()->SetDataLength(length);
}
void CBC_OneCode::SetCalChecksum(bool calc) {
- if (m_pBCWriter)
- static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetCalcChecksum(calc);
+ GetOneDimWriter()->SetCalcChecksum(calc);
}
bool CBC_OneCode::SetFont(CFX_Font* cFont) {
- if (m_pBCWriter)
- return static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetFont(cFont);
- return false;
+ return GetOneDimWriter()->SetFont(cFont);
}
void CBC_OneCode::SetFontSize(float size) {
- if (m_pBCWriter)
- static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetFontSize(size);
+ GetOneDimWriter()->SetFontSize(size);
}
void CBC_OneCode::SetFontStyle(int32_t style) {
- if (m_pBCWriter)
- static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetFontStyle(style);
+ GetOneDimWriter()->SetFontStyle(style);
}
void CBC_OneCode::SetFontColor(FX_ARGB color) {
- if (m_pBCWriter)
- static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetFontColor(color);
+ GetOneDimWriter()->SetFontColor(color);
+}
+
+CBC_OneDimWriter* CBC_OneCode::GetOneDimWriter() {
+ return static_cast<CBC_OneDimWriter*>(m_pBCWriter.get());
}
diff --git a/fxbarcode/cbc_onecode.h b/fxbarcode/cbc_onecode.h
index 8da46113db..08abe6677d 100644
--- a/fxbarcode/cbc_onecode.h
+++ b/fxbarcode/cbc_onecode.h
@@ -11,9 +11,8 @@
#include "core/fxcrt/fx_system.h"
#include "fxbarcode/cbc_codebase.h"
-class CFX_DIBitmap;
+class CBC_OneDimWriter;
class CFX_Font;
-class CFX_RenderDevice;
class CBC_OneCode : public CBC_CodeBase {
public:
@@ -30,6 +29,9 @@ class CBC_OneCode : public CBC_CodeBase {
virtual void SetFontSize(float size);
virtual void SetFontStyle(int32_t style);
virtual void SetFontColor(FX_ARGB color);
+
+ private:
+ CBC_OneDimWriter* GetOneDimWriter();
};
#endif // FXBARCODE_CBC_ONECODE_H_
diff --git a/fxbarcode/cbc_pdf417i.cpp b/fxbarcode/cbc_pdf417i.cpp
index 5536c307c7..51a3643c8b 100644
--- a/fxbarcode/cbc_pdf417i.cpp
+++ b/fxbarcode/cbc_pdf417i.cpp
@@ -21,6 +21,8 @@
#include "fxbarcode/cbc_pdf417i.h"
+#include <memory>
+
#include "fxbarcode/pdf417/BC_PDF417Writer.h"
CBC_PDF417I::CBC_PDF417I() : CBC_CodeBase(new CBC_PDF417Writer) {}
@@ -28,41 +30,35 @@ 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);
+ GetPDF417Writer()->SetErrorCorrectionLevel(level);
return true;
}
void CBC_PDF417I::SetTruncated(bool truncated) {
- static_cast<CBC_PDF417Writer*>(m_pBCWriter.get())->SetTruncated(truncated);
+ GetPDF417Writer()->SetTruncated(truncated);
}
-bool CBC_PDF417I::Encode(const CFX_WideStringC& contents,
- bool isDevice,
- int32_t& e) {
+bool CBC_PDF417I::Encode(const CFX_WideStringC& contents, bool isDevice) {
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)
+ auto* pWriter = GetPDF417Writer();
+ std::unique_ptr<uint8_t, FxFreeDeleter> data(
+ pWriter->Encode(CFX_WideString(contents), outWidth, outHeight));
+ if (!data)
return false;
- return true;
+ return pWriter->RenderResult(data.get(), outWidth, outHeight);
}
bool CBC_PDF417I::RenderDevice(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t& e) {
- static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
- ->RenderDeviceResult(device, matrix);
+ const CFX_Matrix* matrix) {
+ GetPDF417Writer()->RenderDeviceResult(device, matrix);
return true;
}
BC_TYPE CBC_PDF417I::GetType() {
return BC_PDF417;
}
+
+CBC_PDF417Writer* CBC_PDF417I::GetPDF417Writer() {
+ return static_cast<CBC_PDF417Writer*>(m_pBCWriter.get());
+}
diff --git a/fxbarcode/cbc_pdf417i.h b/fxbarcode/cbc_pdf417i.h
index 957154d888..2d1c8d3284 100644
--- a/fxbarcode/cbc_pdf417i.h
+++ b/fxbarcode/cbc_pdf417i.h
@@ -12,22 +12,24 @@
#include "core/fxge/fx_dib.h"
#include "fxbarcode/cbc_codebase.h"
+class CBC_PDF417Writer;
+
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;
+ // CBC_CodeBase:
+ bool Encode(const CFX_WideStringC& contents, bool isDevice) override;
bool RenderDevice(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t& e) override;
+ const CFX_Matrix* matrix) override;
BC_TYPE GetType() override;
bool SetErrorCorrectionLevel(int32_t level);
void SetTruncated(bool truncated);
+
+ private:
+ CBC_PDF417Writer* GetPDF417Writer();
};
#endif // FXBARCODE_CBC_PDF417I_H_
diff --git a/fxbarcode/cbc_qrcode.cpp b/fxbarcode/cbc_qrcode.cpp
index 3da35b2c7b..5bdc9768f0 100644
--- a/fxbarcode/cbc_qrcode.cpp
+++ b/fxbarcode/cbc_qrcode.cpp
@@ -32,28 +32,24 @@ CBC_QRCode::~CBC_QRCode() {}
bool CBC_QRCode::SetErrorCorrectionLevel(int32_t level) {
if (level < 0 || level > 3)
return false;
- return m_pBCWriter && writer()->SetErrorCorrectionLevel(level);
+ return GetQRCodeWriter()->SetErrorCorrectionLevel(level);
}
-bool CBC_QRCode::Encode(const CFX_WideStringC& contents,
- bool isDevice,
- int32_t& e) {
+bool CBC_QRCode::Encode(const CFX_WideStringC& contents, bool isDevice) {
int32_t outWidth = 0;
int32_t outHeight = 0;
- CBC_QRCodeWriter* pWriter = writer();
- std::unique_ptr<uint8_t, FxFreeDeleter> data(pWriter->Encode(
- CFX_WideString(contents), pWriter->GetErrorCorrectionLevel(), outWidth,
- outHeight, e));
- if (e != BCExceptionNO)
+ CBC_QRCodeWriter* pWriter = GetQRCodeWriter();
+ std::unique_ptr<uint8_t, FxFreeDeleter> data(
+ pWriter->Encode(CFX_WideString(contents),
+ pWriter->GetErrorCorrectionLevel(), outWidth, outHeight));
+ if (!data)
return false;
- pWriter->RenderResult(data.get(), outWidth, outHeight, e);
- return e == BCExceptionNO;
+ return pWriter->RenderResult(data.get(), outWidth, outHeight);
}
bool CBC_QRCode::RenderDevice(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t& e) {
- writer()->RenderDeviceResult(device, matrix);
+ const CFX_Matrix* matrix) {
+ GetQRCodeWriter()->RenderDeviceResult(device, matrix);
return true;
}
@@ -61,6 +57,6 @@ BC_TYPE CBC_QRCode::GetType() {
return BC_QR_CODE;
}
-CBC_QRCodeWriter* CBC_QRCode::writer() {
+CBC_QRCodeWriter* CBC_QRCode::GetQRCodeWriter() {
return static_cast<CBC_QRCodeWriter*>(m_pBCWriter.get());
}
diff --git a/fxbarcode/cbc_qrcode.h b/fxbarcode/cbc_qrcode.h
index c3388d17f4..684993364e 100644
--- a/fxbarcode/cbc_qrcode.h
+++ b/fxbarcode/cbc_qrcode.h
@@ -20,18 +20,15 @@ class CBC_QRCode : public CBC_CodeBase {
~CBC_QRCode() override;
// CBC_CodeBase:
- bool Encode(const CFX_WideStringC& contents,
- bool isDevice,
- int32_t& e) override;
+ bool Encode(const CFX_WideStringC& contents, bool isDevice) override;
bool RenderDevice(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t& e) override;
+ const CFX_Matrix* matrix) override;
BC_TYPE GetType() override;
bool SetErrorCorrectionLevel(int32_t level);
private:
- CBC_QRCodeWriter* writer();
+ CBC_QRCodeWriter* GetQRCodeWriter();
};
#endif // FXBARCODE_CBC_QRCODE_H_
diff --git a/fxbarcode/cbc_upca.cpp b/fxbarcode/cbc_upca.cpp
index 98e71615c2..da22469c47 100644
--- a/fxbarcode/cbc_upca.cpp
+++ b/fxbarcode/cbc_upca.cpp
@@ -21,6 +21,8 @@
#include "fxbarcode/cbc_upca.h"
+#include <memory>
+
#include "fxbarcode/oned/BC_OnedUPCAWriter.h"
CBC_UPCA::CBC_UPCA() : CBC_OneCode(new CBC_OnedUPCAWriter) {}
@@ -28,8 +30,7 @@ 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());
+ CBC_OnedUPCAWriter* pWriter = GetOnedUPCAWriter();
CFX_WideString encodeContents = pWriter->FilterContents(contents);
int32_t length = encodeContents.GetLength();
if (length <= 11) {
@@ -47,13 +48,10 @@ CFX_WideString CBC_UPCA::Preprocess(const CFX_WideStringC& contents) {
return encodeContents;
}
-bool CBC_UPCA::Encode(const CFX_WideStringC& contents,
- bool isDevice,
- int32_t& e) {
- if (contents.IsEmpty()) {
- e = BCExceptionNoContents;
+bool CBC_UPCA::Encode(const CFX_WideStringC& contents, bool isDevice) {
+ if (contents.IsEmpty())
return false;
- }
+
BCFORMAT format = BCFORMAT_UPC_A;
int32_t outWidth = 0;
int32_t outHeight = 0;
@@ -61,31 +59,26 @@ bool CBC_UPCA::Encode(const CFX_WideStringC& contents,
CFX_ByteString byteString = encodeContents.UTF8Encode();
m_renderContents = encodeContents;
- CBC_OnedUPCAWriter* pWriter =
- static_cast<CBC_OnedUPCAWriter*>(m_pBCWriter.get());
-
+ CBC_OnedUPCAWriter* pWriter = GetOnedUPCAWriter();
pWriter->Init();
- uint8_t* data = pWriter->Encode(byteString, format, outWidth, outHeight, e);
- if (e != BCExceptionNO)
+ std::unique_ptr<uint8_t, FxFreeDeleter> data(
+ pWriter->Encode(byteString, format, outWidth, outHeight));
+ if (!data)
return false;
- pWriter->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice,
- e);
- FX_Free(data);
- if (e != BCExceptionNO)
- return false;
- return true;
+ return pWriter->RenderResult(encodeContents.AsStringC(), data.get(), outWidth,
+ isDevice);
}
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;
+ const CFX_Matrix* matrix) {
+ return GetOnedUPCAWriter()->RenderDeviceResult(device, matrix,
+ m_renderContents.AsStringC());
}
BC_TYPE CBC_UPCA::GetType() {
return BC_UPCA;
}
+
+CBC_OnedUPCAWriter* CBC_UPCA::GetOnedUPCAWriter() {
+ return static_cast<CBC_OnedUPCAWriter*>(m_pBCWriter.get());
+}
diff --git a/fxbarcode/cbc_upca.h b/fxbarcode/cbc_upca.h
index 221c1d4242..ef77297be2 100644
--- a/fxbarcode/cbc_upca.h
+++ b/fxbarcode/cbc_upca.h
@@ -12,21 +12,21 @@
#include "core/fxge/fx_dib.h"
#include "fxbarcode/cbc_onecode.h"
+class CBC_OnedUPCAWriter;
+
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;
+ // CBC_CodeBase:
+ bool Encode(const CFX_WideStringC& contents, bool isDevice) override;
bool RenderDevice(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t& e) override;
+ const CFX_Matrix* matrix) override;
BC_TYPE GetType() override;
private:
+ CBC_OnedUPCAWriter* GetOnedUPCAWriter();
CFX_WideString Preprocess(const CFX_WideStringC& contents);
CFX_WideString m_renderContents;
};
diff --git a/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp b/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
index 0dcba84979..54b7312abc 100644
--- a/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
+++ b/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
@@ -20,6 +20,10 @@
* limitations under the License.
*/
+#include "fxbarcode/datamatrix/BC_DataMatrixWriter.h"
+
+#include <memory>
+
#include "fxbarcode/BC_Dimension.h"
#include "fxbarcode/BC_TwoDimWriter.h"
#include "fxbarcode/BC_UtilCodingConvert.h"
@@ -30,7 +34,6 @@
#include "fxbarcode/datamatrix/BC_Base256Encoder.h"
#include "fxbarcode/datamatrix/BC_C40Encoder.h"
#include "fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h"
-#include "fxbarcode/datamatrix/BC_DataMatrixWriter.h"
#include "fxbarcode/datamatrix/BC_DefaultPlacement.h"
#include "fxbarcode/datamatrix/BC_EdifactEncoder.h"
#include "fxbarcode/datamatrix/BC_Encoder.h"
@@ -41,69 +44,28 @@
#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
#include "fxbarcode/datamatrix/BC_TextEncoder.h"
#include "fxbarcode/datamatrix/BC_X12Encoder.h"
+#include "third_party/base/ptr_util.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);
- memcpy(result, bytematrix->GetArray(), outWidth * outHeight);
- delete bytematrix;
- delete placement;
- return result;
-}
-CBC_CommonByteMatrix* CBC_DataMatrixWriter::encodeLowLevel(
+namespace {
+
+std::unique_ptr<CBC_CommonByteMatrix> encodeLowLevel(
CBC_DefaultPlacement* placement,
- CBC_SymbolInfo* symbolInfo,
- int32_t& e) {
+ CBC_SymbolInfo* symbolInfo) {
+ int32_t e = BCExceptionNO;
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));
+ int32_t width = symbolInfo->getSymbolWidth(e);
if (e != BCExceptionNO)
return nullptr;
+ int32_t height = symbolInfo->getSymbolHeight(e);
+ if (e != BCExceptionNO)
+ return nullptr;
+
+ auto matrix = pdfium::MakeUnique<CBC_CommonByteMatrix>(width, height);
matrix->Init();
int32_t matrixY = 0;
for (int32_t y = 0; y < symbolHeight; y++) {
@@ -141,3 +103,59 @@ CBC_CommonByteMatrix* CBC_DataMatrixWriter::encodeLowLevel(
}
return matrix;
}
+
+} // namespace
+
+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) {
+ if (outWidth < 0 || outHeight < 0)
+ return nullptr;
+
+ CBC_SymbolShapeHint::SymbolShapeHint shape =
+ CBC_SymbolShapeHint::FORCE_SQUARE;
+ CBC_Dimension* minSize = nullptr;
+ CBC_Dimension* maxSize = nullptr;
+ CFX_WideString ecLevel;
+ int32_t e = BCExceptionNO;
+ 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;
+
+ int32_t width = symbolInfo->getSymbolDataWidth(e);
+ if (e != BCExceptionNO)
+ return nullptr;
+
+ int32_t height = symbolInfo->getSymbolDataHeight(e);
+ if (e != BCExceptionNO)
+ return nullptr;
+
+ auto placement =
+ pdfium::MakeUnique<CBC_DefaultPlacement>(codewords, width, height);
+ placement->place();
+ auto bytematrix = encodeLowLevel(placement.get(), symbolInfo);
+ if (!bytematrix)
+ return nullptr;
+
+ outWidth = bytematrix->GetWidth();
+ outHeight = bytematrix->GetHeight();
+ uint8_t* result = FX_Alloc2D(uint8_t, outWidth, outHeight);
+ memcpy(result, bytematrix->GetArray(), outWidth * outHeight);
+ return result;
+}
diff --git a/fxbarcode/datamatrix/BC_DataMatrixWriter.h b/fxbarcode/datamatrix/BC_DataMatrixWriter.h
index cf5f6e4c4d..84b83fe7a3 100644
--- a/fxbarcode/datamatrix/BC_DataMatrixWriter.h
+++ b/fxbarcode/datamatrix/BC_DataMatrixWriter.h
@@ -18,18 +18,14 @@ class CBC_DataMatrixWriter : public CBC_TwoDimWriter {
CBC_DataMatrixWriter();
~CBC_DataMatrixWriter() override;
- virtual uint8_t* Encode(const CFX_WideString& contents,
- int32_t& outWidth,
- int32_t& outHeight,
- int32_t& e);
+ uint8_t* Encode(const CFX_WideString& contents,
+ int32_t& outWidth,
+ int32_t& outHeight);
// 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;
};
diff --git a/fxbarcode/oned/BC_OneDimWriter.cpp b/fxbarcode/oned/BC_OneDimWriter.cpp
index 57b6c22a93..b898340519 100644
--- a/fxbarcode/oned/BC_OneDimWriter.cpp
+++ b/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -24,6 +24,7 @@
#include <algorithm>
#include <memory>
+#include <vector>
#include "core/fxge/cfx_fxgedevice.h"
#include "core/fxge/cfx_gemodule.h"
@@ -90,44 +91,25 @@ wchar_t CBC_OneDimWriter::Upper(wchar_t ch) {
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;
+uint8_t* CBC_OneDimWriter::EncodeWithHint(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints) {
outHeight = 1;
- if (m_Width >= 20) {
- ret = Encode(contents, outWidth, e);
- } else {
- ret = Encode(contents, outWidth, e);
- }
- if (e != BCExceptionNO)
- return nullptr;
- return ret;
+ return EncodeImpl(contents, outWidth);
}
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& outHeight) {
+ return EncodeWithHint(contents, format, outWidth, outHeight, 0);
}
int32_t CBC_OneDimWriter::AppendPattern(uint8_t* target,
int32_t pos,
- const int32_t* pattern,
+ const int8_t* pattern,
int32_t patternLength,
int32_t startColor,
int32_t& e) {
@@ -139,8 +121,7 @@ int32_t CBC_OneDimWriter::AppendPattern(uint8_t* target,
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;
+ target[pos++] = color;
numAdded += 1;
}
color ^= 1;
@@ -223,24 +204,17 @@ void CBC_OneDimWriter::ShowDeviceChars(CFX_RenderDevice* device,
m_fontColor, FXTEXT_CLEARTYPE);
}
-void CBC_OneDimWriter::ShowChars(const CFX_WideStringC& contents,
+bool CBC_OneDimWriter::ShowChars(const CFX_WideStringC& contents,
CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t barWidth,
- int32_t multiple,
- int32_t& e) {
- if (!device) {
- e = BCExceptionIllegalArgument;
- return;
- }
- if (!m_pFont) {
- e = BCExceptionNullPointer;
- return;
- }
+ int32_t multiple) {
+ if (!device || !m_pFont)
+ return false;
+
CFX_ByteString str = FX_UTF8Encode(contents);
int32_t iLen = str.GetLength();
- FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLen);
- memset(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLen);
+ std::vector<FXTEXT_CHARPOS> charpos(iLen);
float charsLen = 0;
float geWidth = 0;
if (m_locTextLoc == BC_TEXT_LOC_ABOVEEMBED ||
@@ -252,10 +226,10 @@ void CBC_OneDimWriter::ShowChars(const CFX_WideStringC& contents,
}
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;
- }
+ CalcTextInfo(str, charpos.data(), m_pFont, geWidth, iFontSize, charsLen);
+ if (charsLen < 1)
+ return true;
+
int32_t locX = 0;
int32_t locY = 0;
switch (m_locTextLoc) {
@@ -281,18 +255,16 @@ void CBC_OneDimWriter::ShowChars(const CFX_WideStringC& contents,
geWidth = (float)barWidth;
break;
}
- ShowDeviceChars(device, matrix, str, geWidth, pCharPos, (float)locX,
+ ShowDeviceChars(device, matrix, str, geWidth, charpos.data(), (float)locX,
(float)locY, barWidth);
- FX_Free(pCharPos);
+ return true;
}
-void CBC_OneDimWriter::RenderDeviceResult(CFX_RenderDevice* device,
+bool CBC_OneDimWriter::RenderDeviceResult(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
- const CFX_WideStringC& contents,
- int32_t& e) {
+ const CFX_WideStringC& contents) {
if (!m_output)
- if (e != BCExceptionNO)
- return;
+ return false;
CFX_GraphStateData stateData;
CFX_PathData path;
@@ -311,109 +283,68 @@ void CBC_OneDimWriter::RenderDeviceResult(CFX_RenderDevice* device,
}
}
}
- 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, device, matrix, m_barWidth, m_multiple, e);
- if (e != BCExceptionNO)
- return;
- }
+ return m_locTextLoc == BC_TEXT_LOC_NONE || contents.Find(' ') == -1 ||
+ ShowChars(contents, device, matrix, m_barWidth, m_multiple);
}
-void CBC_OneDimWriter::RenderResult(const CFX_WideStringC& contents,
+bool 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;
- }
+ bool isDevice) {
+ if (codeLength < 1)
+ return false;
+
+ m_ModuleHeight = std::max(m_ModuleHeight, 20);
+ const int32_t codeOldLength = codeLength;
+ const int32_t leftPadding = m_bLeftPadding ? 7 : 0;
+ const int32_t rightPadding = m_bRightPadding ? 7 : 0;
codeLength += leftPadding;
codeLength += rightPadding;
- m_outputHScale = 1.0;
- if (m_Width > 0) {
- m_outputHScale = (float)m_Width / (float)codeLength;
- }
+ m_outputHScale =
+ m_Width > 0 ? static_cast<float>(m_Width) / static_cast<float>(codeLength)
+ : 1.0;
if (!isDevice) {
m_outputHScale =
std::max(m_outputHScale, static_cast<float>(m_ModuleWidth));
}
float dataLengthScale = 1.0;
- if (m_iDataLenth > 0 && contents.GetLength() != 0) {
+ if (m_iDataLenth > 0 && contents.GetLength() != 0)
dataLengthScale = float(contents.GetLength()) / float(m_iDataLenth);
- }
- if (m_iDataLenth > 0 && contents.GetLength() == 0) {
+ 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;
- }
- }
+ if (!isDevice)
+ outputHeight = m_Height ? m_Height : std::max(20, m_ModuleHeight);
int32_t outputWidth = codeLength;
- if (!isDevice) {
+ if (!isDevice)
outputWidth = (int32_t)(codeLength * m_multiple / dataLengthScale);
- }
m_barWidth = m_Width;
- if (!isDevice) {
+ 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 >= outputWidth)
+ return true;
+
if (outputX + m_multiple > outputWidth && outputWidth - outputX > 0) {
- if (!m_output->SetRegion(outputX, 0, outputWidth - outputX,
- outputHeight)) {
- e = BCExceptionGeneric;
- }
- break;
- }
- if (!m_output->SetRegion(outputX, 0, m_multiple, outputHeight)) {
- e = BCExceptionGeneric;
- return;
+ return m_output->SetRegion(outputX, 0, outputWidth - outputX,
+ outputHeight);
}
+ if (!m_output->SetRegion(outputX, 0, m_multiple, outputHeight))
+ return false;
}
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/fxbarcode/oned/BC_OneDimWriter.h b/fxbarcode/oned/BC_OneDimWriter.h
index 15ae8e7bc8..f1cbcf23df 100644
--- a/fxbarcode/oned/BC_OneDimWriter.h
+++ b/fxbarcode/oned/BC_OneDimWriter.h
@@ -22,32 +22,12 @@ class CBC_OneDimWriter : public CBC_Writer {
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,
+ virtual bool RenderResult(const CFX_WideStringC& contents,
uint8_t* code,
int32_t codeLength,
- bool isDevice,
- 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);
+ bool isDevice);
+ virtual bool CheckContentValidity(const CFX_WideStringC& contents) = 0;
+ virtual CFX_WideString FilterContents(const CFX_WideStringC& contents) = 0;
virtual CFX_WideString RenderTextContents(const CFX_WideStringC& contents);
virtual void SetPrintChecksum(bool checksum);
virtual void SetDataLength(int32_t length);
@@ -55,21 +35,35 @@ class CBC_OneDimWriter : public CBC_Writer {
virtual void SetFontSize(float size);
virtual void SetFontStyle(int32_t style);
virtual void SetFontColor(FX_ARGB color);
+
+ uint8_t* Encode(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight);
+ bool RenderDeviceResult(CFX_RenderDevice* device,
+ const CFX_Matrix* matrix,
+ const CFX_WideStringC& contents);
bool SetFont(CFX_Font* cFont);
protected:
+ virtual uint8_t* EncodeWithHint(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints);
+ virtual uint8_t* EncodeImpl(const CFX_ByteString& contents,
+ int32_t& outLength) = 0;
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,
+ virtual bool ShowChars(const CFX_WideStringC& contents,
CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t barWidth,
- int32_t multiple,
- int32_t& e);
+ int32_t multiple);
virtual void ShowDeviceChars(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
const CFX_ByteString str,
@@ -80,7 +74,7 @@ class CBC_OneDimWriter : public CBC_Writer {
int32_t barWidth);
virtual int32_t AppendPattern(uint8_t* target,
int32_t pos,
- const int32_t* pattern,
+ const int8_t* pattern,
int32_t patternLength,
int32_t startColor,
int32_t& e);
diff --git a/fxbarcode/oned/BC_OnedCodaBarWriter.cpp b/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
index d3706ab96d..029a6ec37c 100644
--- a/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
+++ b/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
@@ -77,13 +77,15 @@ bool CBC_OnedCodaBarWriter::SetTextLocation(BC_TEXT_LOC location) {
m_locTextLoc = location;
return true;
}
-bool CBC_OnedCodaBarWriter::SetWideNarrowRatio(int32_t ratio) {
- if (ratio < 2 || ratio > 3) {
+
+bool CBC_OnedCodaBarWriter::SetWideNarrowRatio(int8_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) {
@@ -123,43 +125,26 @@ CFX_WideString CBC_OnedCodaBarWriter::FilterContents(
index++;
continue;
}
- if (FindChar(ch, true)) {
- filtercontents += ch;
- } else {
+ if (!FindChar(ch, true))
continue;
- }
+ filtercontents += ch;
}
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)
+
+uint8_t* CBC_OnedCodaBarWriter::EncodeWithHint(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints) {
+ if (format != BCFORMAT_CODABAR)
return nullptr;
- return ret;
+ return CBC_OneDimWriter::EncodeWithHint(contents, format, outWidth, outHeight,
+ hints);
}
-uint8_t* CBC_OnedCodaBarWriter::Encode(const CFX_ByteString& contents,
- int32_t& outLength,
- int32_t& e) {
+
+uint8_t* CBC_OnedCodaBarWriter::EncodeImpl(const CFX_ByteString& contents,
+ int32_t& outLength) {
CFX_ByteString data = m_chStart + contents + m_chEnd;
m_iContentLen = data.GetLength();
uint8_t* result = FX_Alloc2D(uint8_t, m_iWideNarrRatio * 7, data.GetLength());
@@ -187,8 +172,8 @@ uint8_t* CBC_OnedCodaBarWriter::Encode(const CFX_ByteString& contents,
break;
}
int32_t code = 0;
- int32_t len = (int32_t)strlen(ALPHABET_STRING);
- for (int32_t i = 0; i < len; i++) {
+ size_t len = strlen(ALPHABET_STRING);
+ for (size_t i = 0; i < len; i++) {
if (ch == ALPHABET_STRING[i]) {
code = CHARACTER_ENCODINGS[i];
break;
@@ -216,17 +201,18 @@ uint8_t* CBC_OnedCodaBarWriter::Encode(const CFX_ByteString& contents,
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,
+
+bool 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);
+ bool isDevice) {
+ return CBC_OneDimWriter::RenderResult(encodedContents(contents).AsStringC(),
+ code, codeLength, isDevice);
}
diff --git a/fxbarcode/oned/BC_OnedCodaBarWriter.h b/fxbarcode/oned/BC_OnedCodaBarWriter.h
index f9ecc1b11a..94933612f5 100644
--- a/fxbarcode/oned/BC_OnedCodaBarWriter.h
+++ b/fxbarcode/oned/BC_OnedCodaBarWriter.h
@@ -18,41 +18,33 @@ class CBC_OnedCodaBarWriter : public CBC_OneDimWriter {
~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;
+ uint8_t* EncodeImpl(const CFX_ByteString& contents,
+ int32_t& outLength) override;
+ uint8_t* EncodeWithHint(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints) override;
+ bool RenderResult(const CFX_WideStringC& contents,
+ uint8_t* code,
+ int32_t codeLength,
+ bool isDevice) 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 SetWideNarrowRatio(int8_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;
+ CFX_WideString encodedContents(const CFX_WideStringC& contents);
+ private:
char m_chStart;
char m_chEnd;
- int32_t m_iWideNarrRatio;
+ int8_t m_iWideNarrRatio;
};
#endif // FXBARCODE_ONED_BC_ONEDCODABARWRITER_H_
diff --git a/fxbarcode/oned/BC_OnedCode128Writer.cpp b/fxbarcode/oned/BC_OnedCode128Writer.cpp
index e2b6823414..9cdebfd112 100644
--- a/fxbarcode/oned/BC_OnedCode128Writer.cpp
+++ b/fxbarcode/oned/BC_OnedCode128Writer.cpp
@@ -20,13 +20,16 @@
* limitations under the License.
*/
+#include "fxbarcode/oned/BC_OnedCode128Writer.h"
+
+#include <memory>
+
#include "fxbarcode/BC_Writer.h"
#include "fxbarcode/oned/BC_OneDimWriter.h"
-#include "fxbarcode/oned/BC_OnedCode128Writer.h"
namespace {
-const int32_t CODE_PATTERNS[107][7] = {
+const int8_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},
@@ -82,22 +85,19 @@ BC_TYPE CBC_OnedCode128Writer::GetType() {
}
bool CBC_OnedCode128Writer::CheckContentValidity(
const CFX_WideStringC& contents) {
- bool ret = true;
+ if (m_codeFormat != BC_CODE128_B && m_codeFormat != BC_CODE128_C)
+ return false;
+
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++;
+ while (position < contents.GetLength()) {
+ patternIndex = (int32_t)contents.GetAt(position);
+ if (patternIndex < 32 || patternIndex > 126 || patternIndex == 34) {
+ return false;
}
- } else {
- ret = false;
+ position++;
}
- return ret;
+ return true;
}
CFX_WideString CBC_OnedCode128Writer::FilterContents(
const CFX_WideStringC& contents) {
@@ -134,32 +134,18 @@ bool CBC_OnedCode128Writer::SetTextLocation(BC_TEXT_LOC location) {
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)
+
+uint8_t* CBC_OnedCode128Writer::EncodeWithHint(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints) {
+ if (format != BCFORMAT_CODE_128)
return nullptr;
- return ret;
+ return CBC_OneDimWriter::EncodeWithHint(contents, format, outWidth, outHeight,
+ hints);
}
+
bool CBC_OnedCode128Writer::IsDigits(const CFX_ByteString& contents,
int32_t start,
int32_t length) {
@@ -172,21 +158,18 @@ bool CBC_OnedCode128Writer::IsDigits(const CFX_ByteString& contents,
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 = BCExceptionGeneric;
+uint8_t* CBC_OnedCode128Writer::EncodeImpl(const CFX_ByteString& contents,
+ int32_t& outLength) {
+ if (contents.GetLength() < 1 || contents.GetLength() > 80)
return nullptr;
- }
- std::vector<const int32_t*> patterns;
+
+ std::vector<const int8_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;
@@ -195,28 +178,27 @@ uint8_t* CBC_OnedCode128Writer::Encode(const CFX_ByteString& contents,
m_iContentLen = contents.GetLength() + 3;
int32_t codeWidth = 0;
for (size_t k = 0; k < patterns.size(); k++) {
- const int32_t* pattern = patterns[k];
+ const int8_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);
+ std::unique_ptr<uint8_t, FxFreeDeleter> 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);
+ const int8_t* pattern = patterns[j];
+ int32_t e = BCExceptionNO;
+ pos += AppendPattern(result.get(), pos, pattern, 7, 1, e);
+ if (e != BCExceptionNO)
return nullptr;
- }
}
- return result;
+ return result.release();
}
int32_t CBC_OnedCode128Writer::Encode128B(
const CFX_ByteString& contents,
- std::vector<const int32_t*>* patterns) {
+ std::vector<const int8_t*>* patterns) {
int32_t checkSum = 0;
int32_t checkWeight = 1;
int32_t position = 0;
@@ -237,7 +219,7 @@ int32_t CBC_OnedCode128Writer::Encode128B(
int32_t CBC_OnedCode128Writer::Encode128C(
const CFX_ByteString& contents,
- std::vector<const int32_t*>* patterns) {
+ std::vector<const int8_t*>* patterns) {
int32_t checkSum = 0;
int32_t checkWeight = 1;
int32_t position = 0;
diff --git a/fxbarcode/oned/BC_OnedCode128Writer.h b/fxbarcode/oned/BC_OnedCode128Writer.h
index 34b22876b6..c4c0bf0037 100644
--- a/fxbarcode/oned/BC_OnedCode128Writer.h
+++ b/fxbarcode/oned/BC_OnedCode128Writer.h
@@ -20,21 +20,13 @@ class CBC_OnedCode128Writer : public CBC_OneDimWriter {
~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;
-
+ uint8_t* EncodeWithHint(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints) override;
+ uint8_t* EncodeImpl(const CFX_ByteString& contents,
+ int32_t& outLength) override;
bool CheckContentValidity(const CFX_WideStringC& contents) override;
CFX_WideString FilterContents(const CFX_WideStringC& contents) override;
@@ -45,9 +37,9 @@ class CBC_OnedCode128Writer : public CBC_OneDimWriter {
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);
+ std::vector<const int8_t*>* patterns);
int32_t Encode128C(const CFX_ByteString& contents,
- std::vector<const int32_t*>* patterns);
+ std::vector<const int8_t*>* patterns);
BC_TYPE m_codeFormat;
};
diff --git a/fxbarcode/oned/BC_OnedCode39Writer.cpp b/fxbarcode/oned/BC_OnedCode39Writer.cpp
index b1a56cad40..b9d594a028 100644
--- a/fxbarcode/oned/BC_OnedCode39Writer.cpp
+++ b/fxbarcode/oned/BC_OnedCode39Writer.cpp
@@ -20,10 +20,13 @@
* limitations under the License.
*/
+#include "fxbarcode/oned/BC_OnedCode39Writer.h"
+
+#include <memory>
+
#include "fxbarcode/BC_Writer.h"
#include "fxbarcode/common/BC_CommonBitMatrix.h"
#include "fxbarcode/oned/BC_OneDimWriter.h"
-#include "fxbarcode/oned/BC_OnedCode39Writer.h"
namespace {
@@ -40,10 +43,10 @@ const int32_t CHARACTER_ENCODINGS[44] = {
} // namespace
-CBC_OnedCode39Writer::CBC_OnedCode39Writer() {
- m_iWideNarrRatio = 3;
-}
+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++) {
@@ -116,55 +119,40 @@ bool CBC_OnedCode39Writer::SetTextLocation(BC_TEXT_LOC location) {
m_locTextLoc = location;
return true;
}
-bool CBC_OnedCode39Writer::SetWideNarrowRatio(int32_t ratio) {
- if (ratio < 2 || ratio > 3) {
+bool CBC_OnedCode39Writer::SetWideNarrowRatio(int8_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)
+
+uint8_t* CBC_OnedCode39Writer::EncodeWithHint(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints) {
+ if (format != BCFORMAT_CODE_39)
return nullptr;
- return ret;
+ return CBC_OneDimWriter::EncodeWithHint(contents, format, outWidth, outHeight,
+ hints);
}
-void CBC_OnedCode39Writer::ToIntArray(int32_t a, int32_t* toReturn) {
+
+void CBC_OnedCode39Writer::ToIntArray(int32_t a, int8_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) {
+
+char CBC_OnedCode39Writer::CalcCheckSum(const CFX_ByteString& contents) {
int32_t length = contents.GetLength();
- if (length > 80) {
- e = BCExceptionGeneric;
+ if (length > 80)
return '*';
- }
+
int32_t checksum = 0;
- int32_t len = (int32_t)strlen(ALPHABET_STRING);
+ size_t len = strlen(ALPHABET_STRING);
for (const auto& c : contents) {
- int32_t j = 0;
+ size_t j = 0;
for (; j < len; j++) {
if (ALPHABET_STRING[j] == c) {
if (c != '*')
@@ -172,110 +160,103 @@ char CBC_OnedCode39Writer::CalcCheckSum(const CFX_ByteString& contents,
break;
}
}
- if (j >= len) {
- e = BCExceptionGeneric;
+ if (j >= len)
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 == '*') {
+
+uint8_t* CBC_OnedCode39Writer::EncodeImpl(const CFX_ByteString& contents,
+ int32_t& outlength) {
+ char checksum = CalcCheckSum(contents);
+ if (checksum == '*')
return nullptr;
- }
- int32_t widths[9] = {0};
+
+ int8_t widths[9] = {0};
int32_t wideStrideNum = 3;
int32_t narrStrideNum = 9 - wideStrideNum;
CFX_ByteString encodedContents = contents;
- if (m_bCalcChecksum) {
+ 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);
+ size_t len = 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];
- }
- }
+ for (size_t i = 0; i < len; i++) {
+ if (ALPHABET_STRING[i] != encodedContents[j])
+ continue;
+
+ ToIntArray(CHARACTER_ENCODINGS[i], widths);
+ for (size_t k = 0; k < 9; k++)
+ codeWidth += widths[k];
}
}
outlength = codeWidth;
- uint8_t* result = FX_Alloc(uint8_t, codeWidth);
+ std::unique_ptr<uint8_t, FxFreeDeleter> 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);
+ int32_t e = BCExceptionNO;
+ int32_t pos = AppendPattern(result.get(), 0, widths, 9, 1, e);
+ if (e != BCExceptionNO)
return nullptr;
- }
- int32_t narrowWhite[] = {1};
- pos += AppendPattern(result, pos, narrowWhite, 1, 0, e);
- if (e != BCExceptionNO) {
- FX_Free(result);
+
+ int8_t narrowWhite[] = {1};
+ pos += AppendPattern(result.get(), pos, narrowWhite, 1, 0, e);
+ if (e != BCExceptionNO)
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;
- }
- }
+ for (size_t i = 0; i < len; i++) {
+ if (ALPHABET_STRING[i] != encodedContents[l])
+ continue;
+
+ ToIntArray(CHARACTER_ENCODINGS[i], widths);
+ pos += AppendPattern(result.get(), pos, widths, 9, 1, e);
+ if (e != BCExceptionNO)
+ return nullptr;
}
- pos += AppendPattern(result, pos, narrowWhite, 1, 0, e);
- if (e != BCExceptionNO) {
- FX_Free(result);
+ pos += AppendPattern(result.get(), pos, narrowWhite, 1, 0, e);
+ if (e != BCExceptionNO)
return nullptr;
- }
}
ToIntArray(CHARACTER_ENCODINGS[39], widths);
- pos += AppendPattern(result, pos, widths, 9, 1, e);
- if (e != BCExceptionNO) {
- FX_Free(result);
+ pos += AppendPattern(result.get(), pos, widths, 9, 1, e);
+ if (e != BCExceptionNO)
return nullptr;
- }
+
+ auto* result_ptr = result.get();
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];
+ result_ptr[i] ^= result_ptr[codeWidth - 1 - i];
+ result_ptr[codeWidth - 1 - i] ^= result_ptr[i];
+ result_ptr[i] ^= result_ptr[codeWidth - 1 - i];
}
- return result;
+ return result.release();
}
-CFX_WideString CBC_OnedCode39Writer::encodedContents(
- const CFX_WideStringC& contents,
- int32_t& e) {
- CFX_WideString encodedContents(contents);
+
+bool CBC_OnedCode39Writer::encodedContents(const CFX_WideStringC& contents,
+ CFX_WideString* result) {
+ *result = CFX_WideString(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();
+ checksum = CalcCheckSum(str);
+ if (checksum == '*')
+ return false;
str += checksum;
- encodedContents += checksum;
+ *result += checksum;
}
- return encodedContents;
+ return true;
}
-void CBC_OnedCode39Writer::RenderResult(const CFX_WideStringC& contents,
+
+bool 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);
+ bool isDevice) {
+ CFX_WideString encodedCon;
+ if (!encodedContents(contents, &encodedCon))
+ return false;
+ return CBC_OneDimWriter::RenderResult(encodedCon.AsStringC(), code,
+ codeLength, isDevice);
}
diff --git a/fxbarcode/oned/BC_OnedCode39Writer.h b/fxbarcode/oned/BC_OnedCode39Writer.h
index 6926d93f20..4892a1f8d5 100644
--- a/fxbarcode/oned/BC_OnedCode39Writer.h
+++ b/fxbarcode/oned/BC_OnedCode39Writer.h
@@ -16,39 +16,31 @@ class CBC_OnedCode39Writer : public CBC_OneDimWriter {
~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* EncodeWithHint(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints) override;
+ uint8_t* EncodeImpl(const CFX_ByteString& contents,
+ int32_t& outLength) override;
+ bool RenderResult(const CFX_WideStringC& contents,
uint8_t* code,
int32_t codeLength,
- bool isDevice,
- int32_t& e) override;
+ bool isDevice) 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);
+ virtual bool SetWideNarrowRatio(int8_t ratio);
+
+ bool encodedContents(const CFX_WideStringC& contents, CFX_WideString* result);
private:
- void ToIntArray(int32_t a, int32_t* toReturn);
- char CalcCheckSum(const CFX_ByteString& contents, int32_t& e);
+ void ToIntArray(int32_t a, int8_t* toReturn);
+ char CalcCheckSum(const CFX_ByteString& contents);
- int32_t m_iWideNarrRatio;
+ int8_t m_iWideNarrRatio;
};
#endif // FXBARCODE_ONED_BC_ONEDCODE39WRITER_H_
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
index 96b51b0570..7f38661079 100644
--- a/fxbarcode/oned/BC_OnedEAN13Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
@@ -20,22 +20,26 @@
* limitations under the License.
*/
+#include "fxbarcode/oned/BC_OnedEAN13Writer.h"
+
+#include <memory>
+#include <vector>
+
#include "core/fxge/cfx_fxgedevice.h"
#include "core/fxge/cfx_gemodule.h"
#include "fxbarcode/BC_Writer.h"
#include "fxbarcode/oned/BC_OneDimWriter.h"
-#include "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] = {
+const int8_t FIRST_DIGIT_ENCODINGS[10] = {0x00, 0x0B, 0x0D, 0xE, 0x13,
+ 0x19, 0x1C, 0x15, 0x16, 0x1A};
+const int8_t START_END_PATTERN[3] = {1, 1, 1};
+const int8_t MIDDLE_PATTERN[5] = {1, 1, 1, 1, 1};
+const int8_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] = {
+const int8_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},
@@ -87,100 +91,74 @@ int32_t CBC_OnedEAN13Writer::CalcChecksum(const CFX_ByteString& contents) {
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)
+
+uint8_t* CBC_OnedEAN13Writer::EncodeWithHint(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints) {
+ if (format != BCFORMAT_EAN_13)
return nullptr;
- return ret;
+ return CBC_OneDimWriter::EncodeWithHint(contents, format, outWidth, outHeight,
+ hints);
}
-uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents,
- int32_t& outLength,
- int32_t& e) {
- if (contents.GetLength() != 13) {
- e = BCExceptionDigitLengthShould13;
+
+uint8_t* CBC_OnedEAN13Writer::EncodeImpl(const CFX_ByteString& contents,
+ int32_t& outLength) {
+ if (contents.GetLength() != 13)
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);
+ std::unique_ptr<uint8_t, FxFreeDeleter> 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);
+ int32_t e = BCExceptionNO;
+ pos += AppendPattern(result.get(), pos, START_END_PATTERN, 3, 1, e);
+ if (e != BCExceptionNO)
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);
+ pos += AppendPattern(result.get(), pos, L_AND_G_PATTERNS[digit], 4, 0, e);
+ if (e != BCExceptionNO)
return nullptr;
- }
}
- pos += AppendPattern(result, pos, MIDDLE_PATTERN, 5, 0, e);
- if (e != BCExceptionNO) {
- FX_Free(result);
+ pos += AppendPattern(result.get(), pos, MIDDLE_PATTERN, 5, 0, e);
+ if (e != BCExceptionNO)
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);
+ pos += AppendPattern(result.get(), pos, L_PATTERNS[digit], 4, 1, e);
+ if (e != BCExceptionNO)
return nullptr;
- }
}
- pos += AppendPattern(result, pos, START_END_PATTERN, 3, 1, e);
- if (e != BCExceptionNO) {
- FX_Free(result);
+ pos += AppendPattern(result.get(), pos, START_END_PATTERN, 3, 1, e);
+ if (e != BCExceptionNO)
return nullptr;
- }
- return result;
+ return result.release();
}
-void CBC_OnedEAN13Writer::ShowChars(
- const CFX_WideStringC& contents,
- CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t barWidth,
- int32_t multiple,
- int32_t& e) {
- if (!device) {
- e = BCExceptionIllegalArgument;
- return;
- }
+bool CBC_OnedEAN13Writer::ShowChars(const CFX_WideStringC& contents,
+ CFX_RenderDevice* device,
+ const CFX_Matrix* matrix,
+ int32_t barWidth,
+ int32_t multiple) {
+ if (!device)
+ return false;
+
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);
- memset(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLen);
-
+ std::vector<FXTEXT_CHARPOS> charpos(iLen);
int32_t iFontSize = (int32_t)fabs(m_fFontSize);
int32_t iTextHeight = iFontSize + 1;
CFX_ByteString tempStr = str.Mid(1, 6);
@@ -214,7 +192,7 @@ void CBC_OnedEAN13Writer::ShowChars(
iLen = tempStr.GetLength();
strWidth = (int32_t)(strWidth * m_outputHScale);
- CalcTextInfo(tempStr, pCharPos + 1, m_pFont, (float)strWidth, iFontSize,
+ CalcTextInfo(tempStr, &charpos[1], m_pFont, (float)strWidth, iFontSize,
blank);
{
CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0,
@@ -222,13 +200,13 @@ void CBC_OnedEAN13Writer::ShowChars(
(float)(m_Height - iTextHeight) + iFontSize);
if (matrix)
affine_matrix1.Concat(*matrix);
- device->DrawNormalText(iLen, pCharPos + 1, m_pFont,
+ device->DrawNormalText(iLen, &charpos[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,
+ CalcTextInfo(tempStr, &charpos[7], m_pFont, (float)strWidth, iFontSize,
blank);
{
CFX_Matrix affine_matrix1(
@@ -237,7 +215,7 @@ void CBC_OnedEAN13Writer::ShowChars(
(float)(m_Height - iTextHeight + iFontSize));
if (matrix)
affine_matrix1.Concat(*matrix);
- device->DrawNormalText(iLen, pCharPos + 7, m_pFont,
+ device->DrawNormalText(iLen, &charpos[7], m_pFont,
static_cast<float>(iFontSize), &affine_matrix1,
m_fontColor, FXTEXT_CLEARTYPE);
}
@@ -246,23 +224,16 @@ void CBC_OnedEAN13Writer::ShowChars(
strWidth = multiple * 7;
strWidth = (int32_t)(strWidth * m_outputHScale);
- CalcTextInfo(tempStr, pCharPos, m_pFont, (float)strWidth, iFontSize, blank);
+ CalcTextInfo(tempStr, charpos.data(), m_pFont, (float)strWidth, iFontSize,
+ blank);
{
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,
+ device->DrawNormalText(iLen, charpos.data(), 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);
+ return true;
}
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.h b/fxbarcode/oned/BC_OnedEAN13Writer.h
index 377d18a916..826d1610a0 100644
--- a/fxbarcode/oned/BC_OnedEAN13Writer.h
+++ b/fxbarcode/oned/BC_OnedEAN13Writer.h
@@ -20,37 +20,24 @@ class CBC_OnedEAN13Writer : public CBC_OneDimWriter {
~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;
+ uint8_t* EncodeWithHint(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints) override;
+ uint8_t* EncodeImpl(const CFX_ByteString& contents,
+ int32_t& outLength) 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,
+ bool ShowChars(const CFX_WideStringC& contents,
CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t barWidth,
- int32_t multiple,
- int32_t& e) override;
+ int32_t multiple) override;
private:
int32_t m_codeWidth;
diff --git a/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
index 5ebc699c2c..052e0d0508 100644
--- a/fxbarcode/oned/BC_OnedEAN8Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
@@ -20,18 +20,24 @@
* limitations under the License.
*/
+#include "fxbarcode/oned/BC_OnedEAN8Writer.h"
+
+#include <algorithm>
+#include <cwctype>
+#include <memory>
+#include <vector>
+
#include "core/fxge/cfx_fxgedevice.h"
#include "core/fxge/cfx_gemodule.h"
#include "fxbarcode/BC_Writer.h"
#include "fxbarcode/common/BC_CommonBitMatrix.h"
#include "fxbarcode/oned/BC_OneDimWriter.h"
-#include "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] = {
+const int8_t START_END_PATTERN[3] = {1, 1, 1};
+const int8_t MIDDLE_PATTERN[5] = {1, 1, 1, 1, 1};
+const int8_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}};
@@ -41,10 +47,13 @@ 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;
@@ -52,16 +61,11 @@ bool CBC_OnedEAN8Writer::SetTextLocation(BC_TEXT_LOC location) {
}
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;
+ return std::all_of(contents.begin(), contents.end(), std::iswdigit);
}
+
CFX_WideString CBC_OnedEAN8Writer::FilterContents(
const CFX_WideStringC& contents) {
CFX_WideString filtercontents;
@@ -78,6 +82,7 @@ CFX_WideString CBC_OnedEAN8Writer::FilterContents(
}
return filtercontents;
}
+
int32_t CBC_OnedEAN8Writer::CalcChecksum(const CFX_ByteString& contents) {
int32_t odd = 0;
int32_t even = 0;
@@ -94,94 +99,67 @@ int32_t CBC_OnedEAN8Writer::CalcChecksum(const CFX_ByteString& contents) {
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)
+
+uint8_t* CBC_OnedEAN8Writer::EncodeWithHint(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints) {
+ if (format != BCFORMAT_EAN_8)
return nullptr;
- return ret;
+ return CBC_OneDimWriter::EncodeWithHint(contents, format, outWidth, outHeight,
+ hints);
}
-uint8_t* CBC_OnedEAN8Writer::Encode(const CFX_ByteString& contents,
- int32_t& outLength,
- int32_t& e) {
- if (contents.GetLength() != 8) {
- e = BCExceptionDigitLengthMustBe8;
+
+uint8_t* CBC_OnedEAN8Writer::EncodeImpl(const CFX_ByteString& contents,
+ int32_t& outLength) {
+ if (contents.GetLength() != 8)
return nullptr;
- }
+
outLength = m_codeWidth;
- uint8_t* result = FX_Alloc(uint8_t, m_codeWidth);
+ std::unique_ptr<uint8_t, FxFreeDeleter> 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);
+ int32_t e = BCExceptionNO;
+ pos += AppendPattern(result.get(), pos, START_END_PATTERN, 3, 1, e);
+ if (e != BCExceptionNO)
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);
+ pos += AppendPattern(result.get(), pos, L_PATTERNS[digit], 4, 0, e);
+ if (e != BCExceptionNO)
return nullptr;
- }
}
- pos += AppendPattern(result, pos, MIDDLE_PATTERN, 5, 0, e);
- if (e != BCExceptionNO) {
- FX_Free(result);
+ pos += AppendPattern(result.get(), pos, MIDDLE_PATTERN, 5, 0, e);
+ if (e != BCExceptionNO)
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);
+ pos += AppendPattern(result.get(), pos, L_PATTERNS[digit], 4, 1, e);
+ if (e != BCExceptionNO)
return nullptr;
- }
}
- pos += AppendPattern(result, pos, START_END_PATTERN, 3, 1, e);
- if (e != BCExceptionNO) {
- FX_Free(result);
+ pos += AppendPattern(result.get(), pos, START_END_PATTERN, 3, 1, e);
+ if (e != BCExceptionNO)
return nullptr;
- }
- return result;
+ return result.release();
}
-void CBC_OnedEAN8Writer::ShowChars(
- const CFX_WideStringC& contents,
- CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t barWidth,
- int32_t multiple,
- int32_t& e) {
- if (!device) {
- e = BCExceptionIllegalArgument;
- return;
- }
+bool CBC_OnedEAN8Writer::ShowChars(const CFX_WideStringC& contents,
+ CFX_RenderDevice* device,
+ const CFX_Matrix* matrix,
+ int32_t barWidth,
+ int32_t multiple) {
+ if (!device)
+ return false;
int32_t leftPosition = 3 * multiple;
CFX_ByteString str = FX_UTF8Encode(contents);
int32_t iLength = str.GetLength();
- FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLength);
- memset(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLength);
+ std::vector<FXTEXT_CHARPOS> charpos(iLength);
CFX_ByteString tempStr = str.Mid(0, 4);
int32_t iLen = tempStr.GetLength();
int32_t strWidth = 7 * multiple * 4;
@@ -207,19 +185,20 @@ void CBC_OnedEAN8Writer::ShowChars(
device->FillRect(&re, m_backgroundColor);
strWidth = (int32_t)(strWidth * m_outputHScale);
- CalcTextInfo(tempStr, pCharPos, m_pFont, (float)strWidth, iFontSize, blank);
+ CalcTextInfo(tempStr, charpos.data(), m_pFont, (float)strWidth, iFontSize,
+ blank);
{
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,
+ device->DrawNormalText(iLen, charpos.data(), 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,
+ CalcTextInfo(tempStr, &charpos[4], m_pFont, (float)strWidth, iFontSize,
blank);
{
CFX_Matrix affine_matrix1(
@@ -228,17 +207,9 @@ void CBC_OnedEAN8Writer::ShowChars(
(float)(m_Height - iTextHeight + iFontSize));
if (matrix)
affine_matrix1.Concat(*matrix);
- device->DrawNormalText(iLen, pCharPos + 4, m_pFont,
+ device->DrawNormalText(iLen, &charpos[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);
+ return true;
}
diff --git a/fxbarcode/oned/BC_OnedEAN8Writer.h b/fxbarcode/oned/BC_OnedEAN8Writer.h
index 57f3b44f7c..70c8fd4641 100644
--- a/fxbarcode/oned/BC_OnedEAN8Writer.h
+++ b/fxbarcode/oned/BC_OnedEAN8Writer.h
@@ -21,26 +21,13 @@ class CBC_OnedEAN8Writer : public CBC_OneDimWriter {
~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;
+ uint8_t* EncodeWithHint(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints) override;
+ uint8_t* EncodeImpl(const CFX_ByteString& contents,
+ int32_t& outLength) override;
bool CheckContentValidity(const CFX_WideStringC& contents) override;
CFX_WideString FilterContents(const CFX_WideStringC& contents) override;
void SetDataLength(int32_t length) override;
@@ -49,12 +36,11 @@ class CBC_OnedEAN8Writer : public CBC_OneDimWriter {
int32_t CalcChecksum(const CFX_ByteString& contents);
protected:
- void ShowChars(const CFX_WideStringC& contents,
+ bool ShowChars(const CFX_WideStringC& contents,
CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t barWidth,
- int32_t multiple,
- int32_t& e) override;
+ int32_t multiple) override;
private:
int32_t m_codeWidth;
diff --git a/fxbarcode/oned/BC_OnedUPCAWriter.cpp b/fxbarcode/oned/BC_OnedUPCAWriter.cpp
index 3d31e2d389..e5062a62be 100644
--- a/fxbarcode/oned/BC_OnedUPCAWriter.cpp
+++ b/fxbarcode/oned/BC_OnedUPCAWriter.cpp
@@ -20,12 +20,15 @@
* limitations under the License.
*/
+#include "fxbarcode/oned/BC_OnedUPCAWriter.h"
+
+#include <vector>
+
#include "core/fxge/cfx_fxgedevice.h"
#include "core/fxge/cfx_gemodule.h"
#include "fxbarcode/BC_Writer.h"
#include "fxbarcode/oned/BC_OneDimWriter.h"
#include "fxbarcode/oned/BC_OnedEAN13Writer.h"
-#include "fxbarcode/oned/BC_OnedUPCAWriter.h"
#include "third_party/base/ptr_util.h"
CBC_OnedUPCAWriter::CBC_OnedUPCAWriter() {
@@ -81,60 +84,38 @@ int32_t CBC_OnedUPCAWriter::CalcChecksum(const CFX_ByteString& contents) {
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)
+uint8_t* CBC_OnedUPCAWriter::EncodeWithHint(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints) {
+ if (format != BCFORMAT_UPC_A)
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;
+ return m_subWriter->EncodeWithHint(toEAN13String, BCFORMAT_EAN_13, outWidth,
+ outHeight, hints);
}
-uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents,
- int32_t& outLength,
- int32_t& e) {
+uint8_t* CBC_OnedUPCAWriter::EncodeImpl(const CFX_ByteString& contents,
+ int32_t& outLength) {
return nullptr;
}
-void CBC_OnedUPCAWriter::ShowChars(
- const CFX_WideStringC& contents,
- CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t barWidth,
- int32_t multiple,
- int32_t& e) {
- if (!device) {
- e = BCExceptionIllegalArgument;
- return;
- }
+bool CBC_OnedUPCAWriter::ShowChars(const CFX_WideStringC& contents,
+ CFX_RenderDevice* device,
+ const CFX_Matrix* matrix,
+ int32_t barWidth,
+ int32_t multiple) {
+ if (!device)
+ return false;
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);
- memset(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLen);
+ std::vector<FXTEXT_CHARPOS> charpos(iLen);
CFX_ByteString tempStr = str.Mid(1, 5);
float strWidth = (float)35 * multiple;
float blank = 0.0;
@@ -178,20 +159,20 @@ void CBC_OnedUPCAWriter::ShowChars(
device->FillRect(&re, m_backgroundColor);
strWidth = strWidth * m_outputHScale;
- CalcTextInfo(tempStr, pCharPos + 1, m_pFont, strWidth, iFontSize, blank);
+ CalcTextInfo(tempStr, &charpos[1], m_pFont, strWidth, iFontSize, blank);
{
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,
+ device->DrawNormalText(iLen, &charpos[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);
+ CalcTextInfo(tempStr, &charpos[6], m_pFont, strWidth, iFontSize, blank);
{
CFX_Matrix affine_matrix1(
1.0, 0.0, 0.0, -1.0,
@@ -199,7 +180,7 @@ void CBC_OnedUPCAWriter::ShowChars(
(float)(m_Height - iTextHeight + iFontSize));
if (matrix)
affine_matrix1.Concat(*matrix);
- device->DrawNormalText(iLen, pCharPos + 6, m_pFont,
+ device->DrawNormalText(iLen, &charpos[6], m_pFont,
static_cast<float>(iFontSize), &affine_matrix1,
m_fontColor, FXTEXT_CLEARTYPE);
}
@@ -208,19 +189,19 @@ void CBC_OnedUPCAWriter::ShowChars(
strWidth = (float)multiple * 7;
strWidth = strWidth * m_outputHScale;
- CalcTextInfo(tempStr, pCharPos, m_pFont, strWidth, iFontSize, blank);
+ CalcTextInfo(tempStr, charpos.data(), m_pFont, strWidth, iFontSize, blank);
{
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,
+ device->DrawNormalText(iLen, charpos.data(), 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);
+ CalcTextInfo(tempStr, &charpos[11], m_pFont, strWidth, iFontSize, blank);
{
CFX_Matrix affine_matrix1(
1.0, 0.0, 0.0, -1.0,
@@ -228,17 +209,9 @@ void CBC_OnedUPCAWriter::ShowChars(
(float)(m_Height - iTextHeight + iFontSize));
if (matrix)
affine_matrix1.Concat(*matrix);
- device->DrawNormalText(iLen, pCharPos + 11, m_pFont,
+ device->DrawNormalText(iLen, &charpos[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);
+ return true;
}
diff --git a/fxbarcode/oned/BC_OnedUPCAWriter.h b/fxbarcode/oned/BC_OnedUPCAWriter.h
index c52f4e0ecd..80f6196748 100644
--- a/fxbarcode/oned/BC_OnedUPCAWriter.h
+++ b/fxbarcode/oned/BC_OnedUPCAWriter.h
@@ -24,26 +24,13 @@ class CBC_OnedUPCAWriter : public CBC_OneDimWriter {
~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;
+ uint8_t* EncodeWithHint(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints) override;
+ uint8_t* EncodeImpl(const CFX_ByteString& contents,
+ int32_t& outLength) override;
bool CheckContentValidity(const CFX_WideStringC& contents) override;
CFX_WideString FilterContents(const CFX_WideStringC& contents) override;
@@ -51,12 +38,11 @@ class CBC_OnedUPCAWriter : public CBC_OneDimWriter {
int32_t CalcChecksum(const CFX_ByteString& contents);
protected:
- void ShowChars(const CFX_WideStringC& contents,
+ bool ShowChars(const CFX_WideStringC& contents,
CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t barWidth,
- int32_t multiple,
- int32_t& e) override;
+ int32_t multiple) override;
private:
std::unique_ptr<CBC_OnedEAN13Writer> m_subWriter;
diff --git a/fxbarcode/pdf417/BC_PDF417Writer.cpp b/fxbarcode/pdf417/BC_PDF417Writer.cpp
index 5344b8aecf..6f06321e82 100644
--- a/fxbarcode/pdf417/BC_PDF417Writer.cpp
+++ b/fxbarcode/pdf417/BC_PDF417Writer.cpp
@@ -20,13 +20,16 @@
* limitations under the License.
*/
+#include "fxbarcode/pdf417/BC_PDF417Writer.h"
+
+#include <algorithm>
+
#include "fxbarcode/BC_TwoDimWriter.h"
#include "fxbarcode/common/BC_CommonBitArray.h"
#include "fxbarcode/common/BC_CommonBitMatrix.h"
#include "fxbarcode/pdf417/BC_PDF417.h"
#include "fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h"
#include "fxbarcode/pdf417/BC_PDF417Compaction.h"
-#include "fxbarcode/pdf417/BC_PDF417Writer.h"
CBC_PDF417Writer::CBC_PDF417Writer() {
m_bFixedSize = false;
@@ -44,23 +47,24 @@ bool CBC_PDF417Writer::SetErrorCorrectionLevel(int32_t level) {
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) {
+ int32_t& outHeight) {
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) {
+ if (row >= 3 && row <= 90 && col >= 1 && col <= 30)
encoder.setDimensions(col, col, row, row);
- } else if (col >= 1 && col <= 30) {
+ else if (col >= 1 && col <= 30)
encoder.setDimensions(col, col, 90, 3);
- } else if (row >= 3 && row <= 90) {
+ else if (row >= 3 && row <= 90)
encoder.setDimensions(30, 1, row, row);
- }
+ int32_t e = BCExceptionNO;
encoder.generateBarcodeLogic(contents, m_iCorrectLevel, e);
if (e != BCExceptionNO)
return nullptr;
+
int32_t lineThickness = 2;
int32_t aspectRatio = 4;
CBC_BarcodeMatrix* barcodeMatrix = encoder.getBarcodeMatrix();
@@ -80,12 +84,7 @@ uint8_t* CBC_PDF417Writer::Encode(const CFX_WideString& contents,
}
int32_t scaleX = width / outWidth;
int32_t scaleY = height / outHeight;
- int32_t scale;
- if (scaleX < scaleY) {
- scale = scaleX;
- } else {
- scale = scaleY;
- }
+ int32_t scale = std::min(scaleX, scaleY);
if (scale > 1) {
originalScale = barcodeMatrix->getScaledMatrix(
scale * lineThickness, scale * aspectRatio * lineThickness);
@@ -100,6 +99,7 @@ uint8_t* CBC_PDF417Writer::Encode(const CFX_WideString& contents,
memcpy(result, originalScale.data(), outHeight * outWidth);
return result;
}
+
void CBC_PDF417Writer::rotateArray(std::vector<uint8_t>& bitarray,
int32_t height,
int32_t width) {
diff --git a/fxbarcode/pdf417/BC_PDF417Writer.h b/fxbarcode/pdf417/BC_PDF417Writer.h
index ddfdc9be24..39418715ce 100644
--- a/fxbarcode/pdf417/BC_PDF417Writer.h
+++ b/fxbarcode/pdf417/BC_PDF417Writer.h
@@ -20,8 +20,7 @@ class CBC_PDF417Writer : public CBC_TwoDimWriter {
uint8_t* Encode(const CFX_WideString& contents,
int32_t& outWidth,
- int32_t& outHeight,
- int32_t& e);
+ int32_t& outHeight);
// CBC_TwoDimWriter
bool SetErrorCorrectionLevel(int32_t level) override;
diff --git a/fxbarcode/qrcode/BC_QRCodeWriter.cpp b/fxbarcode/qrcode/BC_QRCodeWriter.cpp
index b7d5359830..c679e9fca6 100644
--- a/fxbarcode/qrcode/BC_QRCodeWriter.cpp
+++ b/fxbarcode/qrcode/BC_QRCodeWriter.cpp
@@ -58,8 +58,7 @@ bool CBC_QRCodeWriter::SetErrorCorrectionLevel(int32_t level) {
uint8_t* CBC_QRCodeWriter::Encode(const CFX_WideString& contents,
int32_t ecLevel,
int32_t& outWidth,
- int32_t& outHeight,
- int32_t& e) {
+ int32_t& outHeight) {
CBC_QRCoderErrorCorrectionLevel* ec = nullptr;
switch (ecLevel) {
case 0:
@@ -74,14 +73,11 @@ uint8_t* CBC_QRCodeWriter::Encode(const CFX_WideString& contents,
case 3:
ec = CBC_QRCoderErrorCorrectionLevel::H;
break;
- default: {
- e = BCExceptionUnSupportEclevel;
+ default:
return nullptr;
- }
}
CBC_QRCoder qr;
- CBC_QRCoderEncoder::Encode(contents, ec, &qr, e);
- if (e != BCExceptionNO)
+ if (!CBC_QRCoderEncoder::Encode(contents, ec, &qr))
return nullptr;
outWidth = qr.GetMatrixWidth();
diff --git a/fxbarcode/qrcode/BC_QRCodeWriter.h b/fxbarcode/qrcode/BC_QRCodeWriter.h
index 42d77fc9f2..1a0502d72e 100644
--- a/fxbarcode/qrcode/BC_QRCodeWriter.h
+++ b/fxbarcode/qrcode/BC_QRCodeWriter.h
@@ -20,8 +20,7 @@ class CBC_QRCodeWriter : public CBC_TwoDimWriter {
uint8_t* Encode(const CFX_WideString& contents,
int32_t ecLevel,
int32_t& outWidth,
- int32_t& outHeight,
- int32_t& e);
+ int32_t& outHeight);
// CBC_TwoDimWriter
bool SetErrorCorrectionLevel(int32_t level) override;
diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
index a08bf31ea4..955e2c7295 100644
--- a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
@@ -203,17 +203,14 @@ void AppendBytes(const CFX_ByteString& content,
e = BCExceptionUnsupportedMode;
}
-void InitQRCode(int32_t numInputBytes,
+bool InitQRCode(int32_t numInputBytes,
const CBC_QRCoderErrorCorrectionLevel* ecLevel,
CBC_QRCoderMode* mode,
- CBC_QRCoder* qrCode,
- int32_t& e) {
+ CBC_QRCoder* qrCode) {
qrCode->SetECLevel(ecLevel);
qrCode->SetMode(mode);
for (int32_t i = 1; i <= CBC_QRCoderVersion::kMaxVersion; ++i) {
const auto* version = CBC_QRCoderVersion::GetVersionForNumber(i);
- if (!version)
- return;
int32_t numBytes = version->GetTotalCodeWords();
const auto* ecBlocks = version->GetECBlocksForLevel(*ecLevel);
int32_t numEcBytes = ecBlocks->GetTotalECCodeWords();
@@ -226,10 +223,10 @@ void InitQRCode(int32_t numInputBytes,
qrCode->SetNumRSBlocks(numRSBlocks);
qrCode->SetNumECBytes(numEcBytes);
qrCode->SetMatrixWidth(version->GetDimensionForVersion());
- return;
+ return true;
}
}
- e = BCExceptionCannotFindBlockInfo;
+ return false;
}
std::unique_ptr<CBC_CommonByteArray> GenerateECBytes(
@@ -347,14 +344,10 @@ void GetNumDataBytesAndNumECBytesForBlockID(int32_t numTotalBytes,
}
}
-void TerminateBits(int32_t numDataBytes,
- CBC_QRCoderBitVector* bits,
- int32_t& e) {
+bool TerminateBits(int32_t numDataBytes, CBC_QRCoderBitVector* bits) {
size_t capacity = numDataBytes << 3;
- if (bits->Size() > capacity) {
- e = BCExceptionDataTooMany;
- return;
- }
+ if (bits->Size() > capacity)
+ return false;
for (int32_t i = 0; i < 4 && bits->Size() < capacity; ++i)
bits->AppendBit(0);
@@ -366,15 +359,13 @@ void TerminateBits(int32_t numDataBytes,
bits->AppendBit(0);
}
- if (bits->Size() % 8 != 0) {
- e = BCExceptionDigitLengthMustBe8;
- return;
- }
+ if (bits->Size() % 8 != 0)
+ return false;
+
int32_t numPaddingBytes = numDataBytes - bits->sizeInBytes();
for (int32_t k = 0; k < numPaddingBytes; ++k)
bits->AppendBits(k % 2 ? 0x11 : 0xec, 8);
- if (bits->Size() != capacity)
- e = BCExceptionBitsNotEqualCacity;
+ return bits->Size() == capacity;
}
void MergeString(std::vector<ModeStringPair>* result,
@@ -514,18 +505,16 @@ CBC_QRCoderMode* ChooseMode(const CFX_ByteString& content,
return CBC_QRCoderMode::sBYTE;
}
-void InterleaveWithECBytes(CBC_QRCoderBitVector* bits,
+bool InterleaveWithECBytes(CBC_QRCoderBitVector* bits,
int32_t numTotalBytes,
int32_t numDataBytes,
int32_t numRSBlocks,
- CBC_QRCoderBitVector* result,
- int32_t& e) {
+ CBC_QRCoderBitVector* result) {
ASSERT(numTotalBytes >= 0);
ASSERT(numDataBytes >= 0);
- if (bits->sizeInBytes() != static_cast<size_t>(numDataBytes)) {
- e = BCExceptionBitsBytesNotMatch;
- return;
- }
+ if (bits->sizeInBytes() != static_cast<size_t>(numDataBytes))
+ return false;
+
int32_t dataBytesOffset = 0;
int32_t maxNumDataBytes = 0;
int32_t maxNumEcBytes = 0;
@@ -540,19 +529,17 @@ void InterleaveWithECBytes(CBC_QRCoderBitVector* bits,
dataBytes->Set(bits->GetArray(), dataBytesOffset, numDataBytesInBlock);
std::unique_ptr<CBC_CommonByteArray> ecBytes =
GenerateECBytes(dataBytes.get(), numEcBytesInBlosk);
- if (!ecBytes) {
- e = BCExceptionGeneric;
- return;
- }
+ if (!ecBytes)
+ return false;
+
maxNumDataBytes = std::max(maxNumDataBytes, dataBytes->Size());
maxNumEcBytes = std::max(maxNumEcBytes, ecBytes->Size());
blocks[i].SetData(std::move(dataBytes), std::move(ecBytes));
dataBytesOffset += numDataBytesInBlock;
}
- if (numDataBytes != dataBytesOffset) {
- e = BCExceptionBytesNotMatchOffset;
- return;
- }
+ if (numDataBytes != dataBytesOffset)
+ return false;
+
for (int32_t x = 0; x < maxNumDataBytes; x++) {
for (size_t j = 0; j < blocks.size(); j++) {
const CBC_CommonByteArray* dataBytes = blocks[j].GetDataBytes();
@@ -567,8 +554,7 @@ void InterleaveWithECBytes(CBC_QRCoderBitVector* bits,
result->AppendBits(ecBytes->At(y), 8);
}
}
- if (static_cast<size_t>(numTotalBytes) != result->sizeInBytes())
- e = BCExceptionSizeInBytesDiffer;
+ return static_cast<size_t>(numTotalBytes) == result->sizeInBytes();
}
} // namespace
@@ -577,41 +563,39 @@ CBC_QRCoderEncoder::CBC_QRCoderEncoder() {}
CBC_QRCoderEncoder::~CBC_QRCoderEncoder() {}
-void CBC_QRCoderEncoder::Encode(const CFX_WideString& content,
+// static
+bool CBC_QRCoderEncoder::Encode(const CFX_WideString& content,
const CBC_QRCoderErrorCorrectionLevel* ecLevel,
- CBC_QRCoder* qrCode,
- int32_t& e) {
+ CBC_QRCoder* qrCode) {
CFX_ByteString encoding = "utf8";
CFX_ByteString utf8Data;
CBC_UtilCodingConvert::UnicodeToUTF8(content, utf8Data);
CBC_QRCoderMode* mode = ChooseMode(utf8Data, encoding);
CBC_QRCoderBitVector dataBits;
+ int32_t e = BCExceptionNO;
AppendBytes(utf8Data, mode, &dataBits, encoding, e);
if (e != BCExceptionNO)
- return;
+ return false;
int32_t numInputBytes = dataBits.sizeInBytes();
- InitQRCode(numInputBytes, ecLevel, mode, qrCode, e);
- if (e != BCExceptionNO)
- return;
+ if (!InitQRCode(numInputBytes, ecLevel, mode, qrCode))
+ return false;
CBC_QRCoderBitVector headerAndDataBits;
AppendModeInfo(mode, &headerAndDataBits);
int32_t numLetters = mode == CBC_QRCoderMode::sBYTE ? dataBits.sizeInBytes()
: content.GetLength();
if (!AppendLengthInfo(numLetters, qrCode->GetVersion(), mode,
&headerAndDataBits)) {
- e = BCExceptionGeneric;
- return;
+ return false;
}
headerAndDataBits.AppendBitVector(&dataBits);
- TerminateBits(qrCode->GetNumDataBytes(), &headerAndDataBits, e);
- if (e != BCExceptionNO)
- return;
+ if (!TerminateBits(qrCode->GetNumDataBytes(), &headerAndDataBits))
+ return false;
CBC_QRCoderBitVector finalBits;
- InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(),
- qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(),
- &finalBits, e);
- if (e != BCExceptionNO)
- return;
+ if (!InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(),
+ qrCode->GetNumDataBytes(),
+ qrCode->GetNumRSBlocks(), &finalBits)) {
+ return false;
+ }
auto matrix = pdfium::MakeUnique<CBC_CommonByteMatrix>(
qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth());
@@ -619,16 +603,15 @@ void CBC_QRCoderEncoder::Encode(const CFX_WideString& content,
int32_t maskPattern = ChooseMaskPattern(
&finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e);
if (e != BCExceptionNO)
- return;
+ return false;
qrCode->SetMaskPattern(maskPattern);
CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(),
qrCode->GetVersion(),
qrCode->GetMaskPattern(), matrix.get(), e);
if (e != BCExceptionNO)
- return;
+ return false;
qrCode->SetMatrix(std::move(matrix));
- if (!qrCode->IsValid())
- e = BCExceptionInvalidQRCode;
+ return qrCode->IsValid();
}
diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.h b/fxbarcode/qrcode/BC_QRCoderEncoder.h
index 46ee05b43b..1c68b3b883 100644
--- a/fxbarcode/qrcode/BC_QRCoderEncoder.h
+++ b/fxbarcode/qrcode/BC_QRCoderEncoder.h
@@ -21,10 +21,9 @@ class CBC_QRCoderEncoder {
CBC_QRCoderEncoder();
~CBC_QRCoderEncoder();
- static void Encode(const CFX_WideString& content,
+ static bool Encode(const CFX_WideString& content,
const CBC_QRCoderErrorCorrectionLevel* ecLevel,
- CBC_QRCoder* qrCode,
- int32_t& e);
+ CBC_QRCoder* qrCode);
};
#endif // FXBARCODE_QRCODE_BC_QRCODERENCODER_H_
diff --git a/fxbarcode/utils.h b/fxbarcode/utils.h
index 442e327784..6f4969505c 100644
--- a/fxbarcode/utils.h
+++ b/fxbarcode/utils.h
@@ -60,40 +60,22 @@ enum BCFORMAT {
#include <ctype.h>
#define BCExceptionNO 0
#define BCExceptionHeightAndWidthMustBeAtLeast1 5
-#define BCExceptionFormatException 8
#define BCExceptionIllegalArgument 16
-#define BCExceptionDigitLengthMustBe8 20
#define BCExceptionNoContents 26
-#define BCExceptionUnSupportEclevel 27
#define BCExceptionDegreeIsNegative 31
#define BCExceptionAIsZero 37
-#define BCExceptionOnlyEncodeCODE_128 41
-#define BCExceptionOnlyEncodeCODE_39 42
-#define BCExceptionOnlyEncodeEAN_13 43
-#define BCExceptionOnlyEncodeEAN_8 44
-#define BCExceptionDigitLengthShould13 46
-#define BCExceptionOnlyEncodeUPC_A 48
#define BCExceptionValueMustBeEither0or1 50
#define BCExceptionBadIndexException 52
#define BCExceptionNoSuchVersion 58
-#define BCExceptionCannotFindBlockInfo 59
-#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 BCExceptionInvalidateImageData 73
#define BCExceptionHeight_8BeZero 74
#define BCExceptionCharacterNotThisMode 75
-#define BCExceptionBitsBytesNotMatch 76
#define BCExceptionInvalidateData 77
-#define BCExceptionFailToCreateBitmap 80
-#define BCExceptionOnlyEncodeCODEBAR 82
#define BCExceptionCharactersOutsideISO88591Encoding 87
#define BCExceptionIllegalDataCodewords 88
#define BCExceptionCannotHandleThisNumberOfDataRegions 89
@@ -108,7 +90,6 @@ enum BCFORMAT {
#define BCExceptionIllegalArgumentnMustBeAbove0 99
#define BCExceptionUnableToFitMessageInColumns 100
#define BCExceptionEncodedMessageContainsTooManyCodeWords 101
-#define BCExceptionBitmapSizeError 102
#define BCExceptionGeneric 107
#endif // FXBARCODE_UTILS_H_
diff --git a/xfa/fwl/cfwl_barcode.cpp b/xfa/fwl/cfwl_barcode.cpp
index 87ecee13b5..378bb8e06b 100644
--- a/xfa/fwl/cfwl_barcode.cpp
+++ b/xfa/fwl/cfwl_barcode.cpp
@@ -52,9 +52,7 @@ void CFWL_Barcode::DrawWidget(CFX_Graphics* pGraphics,
if (pMatrix)
mt.Concat(*pMatrix);
- int32_t errorCode = 0;
- m_pBarcodeEngine->RenderDevice(pGraphics->GetRenderDevice(), pMatrix,
- errorCode);
+ m_pBarcodeEngine->RenderDevice(pGraphics->GetRenderDevice(), pMatrix);
return;
}
CFWL_Edit::DrawWidget(pGraphics, pMatrix);
@@ -131,7 +129,7 @@ void CFWL_Barcode::SetTextLocation(BC_TEXT_LOC location) {
m_eTextLocation = location;
}
-void CFWL_Barcode::SetWideNarrowRatio(int32_t ratio) {
+void CFWL_Barcode::SetWideNarrowRatio(int8_t ratio) {
m_dwAttributeMask |= FWL_BCDATTRIBUTE_WIDENARROWRATIO;
m_nWideNarrowRatio = ratio;
}
@@ -206,8 +204,7 @@ void CFWL_Barcode::GenerateBarcodeImageCache() {
if (m_dwAttributeMask & FWL_BCDATTRIBUTE_TRUNCATED)
m_pBarcodeEngine->SetTruncated(m_bTruncated);
- int32_t errorCode = 0;
- m_dwStatus = m_pBarcodeEngine->Encode(GetText().AsStringC(), true, errorCode)
+ m_dwStatus = m_pBarcodeEngine->Encode(GetText().AsStringC(), true)
? XFA_BCS_EncodeSuccess
: 0;
}
diff --git a/xfa/fwl/cfwl_barcode.h b/xfa/fwl/cfwl_barcode.h
index ce62d73dde..0620541c2f 100644
--- a/xfa/fwl/cfwl_barcode.h
+++ b/xfa/fwl/cfwl_barcode.h
@@ -61,7 +61,7 @@ class CFWL_Barcode : public CFWL_Edit {
void SetCalChecksum(bool calChecksum);
void SetPrintChecksum(bool printChecksum);
void SetTextLocation(BC_TEXT_LOC location);
- void SetWideNarrowRatio(int32_t ratio);
+ void SetWideNarrowRatio(int8_t ratio);
void SetStartChar(char startChar);
void SetEndChar(char endChar);
void SetErrorCorrectionLevel(int32_t ecLevel);
@@ -81,7 +81,7 @@ class CFWL_Barcode : public CFWL_Edit {
bool m_bCalChecksum;
bool m_bPrintChecksum;
BC_TEXT_LOC m_eTextLocation;
- int32_t m_nWideNarrowRatio;
+ int8_t m_nWideNarrowRatio;
char m_cStartChar;
char m_cEndChar;
int32_t m_nECLevel;
diff --git a/xfa/fwl/cfx_barcode.cpp b/xfa/fwl/cfx_barcode.cpp
index 9d01ae26ef..e999d3a509 100644
--- a/xfa/fwl/cfx_barcode.cpp
+++ b/xfa/fwl/cfx_barcode.cpp
@@ -219,8 +219,8 @@ bool CFX_Barcode::SetTextLocation(BC_TEXT_LOC location) {
return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(location) : false;
}
-bool CFX_Barcode::SetWideNarrowRatio(int32_t ratio) {
- typedef bool (CBC_CodeBase::*memptrtype)(int32_t);
+bool CFX_Barcode::SetWideNarrowRatio(int8_t ratio) {
+ typedef bool (CBC_CodeBase::*memptrtype)(int8_t);
memptrtype memptr = nullptr;
switch (GetType()) {
case BC_CODE39:
@@ -276,6 +276,7 @@ bool CFX_Barcode::SetErrorCorrectionLevel(int32_t level) {
}
return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(level) : false;
}
+
bool CFX_Barcode::SetTruncated(bool truncated) {
typedef void (CBC_CodeBase::*memptrtype)(bool);
memptrtype memptr = nullptr;
@@ -290,14 +291,11 @@ bool CFX_Barcode::SetTruncated(bool truncated) {
: false;
}
-bool CFX_Barcode::Encode(const CFX_WideStringC& contents,
- bool isDevice,
- int32_t& e) {
- return m_pBCEngine && m_pBCEngine->Encode(contents, isDevice, e);
+bool CFX_Barcode::Encode(const CFX_WideStringC& contents, bool isDevice) {
+ return m_pBCEngine && m_pBCEngine->Encode(contents, isDevice);
}
bool CFX_Barcode::RenderDevice(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t& e) {
- return m_pBCEngine && m_pBCEngine->RenderDevice(device, matrix, e);
+ const CFX_Matrix* matrix) {
+ return m_pBCEngine && m_pBCEngine->RenderDevice(device, matrix);
}
diff --git a/xfa/fwl/cfx_barcode.h b/xfa/fwl/cfx_barcode.h
index 20155ca0a2..83cb23437f 100644
--- a/xfa/fwl/cfx_barcode.h
+++ b/xfa/fwl/cfx_barcode.h
@@ -27,11 +27,9 @@ class CFX_Barcode {
bool Create(BC_TYPE type);
BC_TYPE GetType();
- bool Encode(const CFX_WideStringC& contents, bool isDevice, int32_t& e);
+ bool Encode(const CFX_WideStringC& contents, bool isDevice);
- bool RenderDevice(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t& e);
+ bool RenderDevice(CFX_RenderDevice* device, const CFX_Matrix* matrix);
bool SetCharEncoding(BC_CHAR_ENCODING encoding);
@@ -51,7 +49,7 @@ class CFX_Barcode {
bool SetTextLocation(BC_TEXT_LOC location);
- bool SetWideNarrowRatio(int32_t ratio);
+ bool SetWideNarrowRatio(int8_t ratio);
bool SetStartChar(char start);
bool SetEndChar(char end);
bool SetErrorCorrectionLevel(int32_t level);
diff --git a/xfa/fxfa/app/xfa_ffbarcode.cpp b/xfa/fxfa/app/xfa_ffbarcode.cpp
index 4e5e1f0a41..d15ec8c24f 100644
--- a/xfa/fxfa/app/xfa_ffbarcode.cpp
+++ b/xfa/fxfa/app/xfa_ffbarcode.cpp
@@ -216,7 +216,7 @@ void CXFA_FFBarcode::UpdateWidgetProperty() {
pBarCodeWidget->SetTruncated(boolVal);
}
if (pAcc->GetBarcodeAttribute_WideNarrowRatio(floatVal)) {
- pBarCodeWidget->SetWideNarrowRatio((int32_t)floatVal);
+ pBarCodeWidget->SetWideNarrowRatio(static_cast<int8_t>(floatVal));
}
if (pBarcodeTypeInfo->eName == XFA_BARCODETYPE_code3Of9 ||
pBarcodeTypeInfo->eName == XFA_BARCODETYPE_ean8 ||