summaryrefslogtreecommitdiff
path: root/fxbarcode/oned/BC_OnedCode128Writer.cpp
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/BC_OnedCode128Writer.cpp
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/BC_OnedCode128Writer.cpp')
-rw-r--r--fxbarcode/oned/BC_OnedCode128Writer.cpp94
1 files changed, 38 insertions, 56 deletions
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;