summaryrefslogtreecommitdiff
path: root/fxbarcode/oned
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-04-20 15:58:56 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-21 00:54:04 +0000
commit1badb85e5c3a4b4cd42ca1a2b223d6b3bc67cc4a (patch)
tree55bf63857592387531797b0f08e0a6effc0f40c9 /fxbarcode/oned
parentaeee187c927c07f47a9e5886a417dcc58badefb6 (diff)
downloadpdfium-1badb85e5c3a4b4cd42ca1a2b223d6b3bc67cc4a.tar.xz
Change more fxbarcode to use return values.
Change-Id: Idcc05fb8c5a1448f552b4db5ae131ad82aef4d59 Reviewed-on: https://pdfium-review.googlesource.com/4258 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fxbarcode/oned')
-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
14 files changed, 444 insertions, 720 deletions
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;