summaryrefslogtreecommitdiff
path: root/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.cpp
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2015-08-04 13:00:21 -0700
committerNico Weber <thakis@chromium.org>2015-08-04 13:00:21 -0700
commit9d8ec5a6e37e8d1d4d4edca9040de234e2d4728f (patch)
treec97037f398d714665aefccb6eb54d0969ad7030c /xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.cpp
parent780cee82236d1b3b0f9b01a22424e4b8ec9a6f12 (diff)
downloadpdfium-9d8ec5a6e37e8d1d4d4edca9040de234e2d4728f.tar.xz
XFA: clang-format all pdfium code.
No behavior change. Generated by: find . -name '*.cpp' -o -name '*.h' | \ grep -E -v 'third_party|thirdparties|lpng_v163|tiff_v403' | \ xargs ../../buildtools/mac/clang-format -i Then manually merged https://codereview.chromium.org/1269223002/ See thread "tabs vs spaces" on pdfium@googlegroups.com for discussion. BUG=none
Diffstat (limited to 'xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.cpp')
-rw-r--r--xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.cpp113
1 files changed, 55 insertions, 58 deletions
diff --git a/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.cpp
index 7a68fcaef6..9df28e1b5b 100644
--- a/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.cpp
+++ b/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.cpp
@@ -3,7 +3,7 @@
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-// Original code is licensed as follows:
+// Original code is licensed as follows:
/*
* Copyright 2006-2007 Jeremias Maerki.
*
@@ -28,68 +28,65 @@
#include "BC_EncoderContext.h"
#include "BC_HighLevelEncoder.h"
#include "BC_Base256Encoder.h"
-CBC_Base256Encoder::CBC_Base256Encoder()
-{
+CBC_Base256Encoder::CBC_Base256Encoder() {}
+CBC_Base256Encoder::~CBC_Base256Encoder() {}
+int32_t CBC_Base256Encoder::getEncodingMode() {
+ return BASE256_ENCODATION;
}
-CBC_Base256Encoder::~CBC_Base256Encoder()
-{
-}
-int32_t CBC_Base256Encoder::getEncodingMode()
-{
- return BASE256_ENCODATION;
-}
-void CBC_Base256Encoder::Encode(CBC_EncoderContext &context, int32_t &e)
-{
- CFX_WideString buffer;
- buffer += (FX_WCHAR)'\0';
- while (context.hasMoreCharacters()) {
- FX_WCHAR c = context.getCurrentChar();
- buffer += c;
- context.m_pos++;
- int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(context.m_msg, context.m_pos, getEncodingMode());
- if (newMode != getEncodingMode()) {
- context.signalEncoderChange(newMode);
- break;
- }
+void CBC_Base256Encoder::Encode(CBC_EncoderContext& context, int32_t& e) {
+ CFX_WideString buffer;
+ buffer += (FX_WCHAR)'\0';
+ while (context.hasMoreCharacters()) {
+ FX_WCHAR c = context.getCurrentChar();
+ buffer += c;
+ context.m_pos++;
+ int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(
+ context.m_msg, context.m_pos, getEncodingMode());
+ if (newMode != getEncodingMode()) {
+ context.signalEncoderChange(newMode);
+ break;
}
- int32_t dataCount = buffer.GetLength() - 1;
- FX_CHAR buf[128];
+ }
+ int32_t dataCount = buffer.GetLength() - 1;
+ FX_CHAR buf[128];
#if defined(_FX_WINAPI_PARTITION_APP_)
- memset(buf, 0, sizeof(FX_CHAR) * 128);
- _itoa_s(dataCount, buf, 128, 10);
+ memset(buf, 0, sizeof(FX_CHAR) * 128);
+ _itoa_s(dataCount, buf, 128, 10);
#else
- FXSYS_itoa(dataCount, buf, 10);
+ FXSYS_itoa(dataCount, buf, 10);
#endif
- buffer.SetAt(0, FX_WCHAR(*buf) - '0');
- int32_t lengthFieldSize = 1;
- int32_t currentSize = context.getCodewordCount() + dataCount + lengthFieldSize;
- context.updateSymbolInfo(currentSize, e);
- if (e != BCExceptionNO) {
- return;
- }
- FX_BOOL mustPad = (context.m_symbolInfo->m_dataCapacity - currentSize) > 0;
- if (context.hasMoreCharacters() || mustPad) {
- if (dataCount <= 249) {
- buffer.SetAt(0, (FX_WCHAR) dataCount);
- } else if (dataCount > 249 && dataCount <= 1555) {
- buffer.SetAt(0, (FX_WCHAR) ((dataCount / 250) + 249));
- buffer.Insert(1, (FX_WCHAR) (dataCount % 250));
- } else {
- e = BCExceptionIllegalStateMessageLengthInvalid;
- return;
- }
- }
- for (int32_t i = 0, c = buffer.GetLength(); i < c; i++) {
- context.writeCodeword(randomize255State(buffer.GetAt(i), context.getCodewordCount() + 1));
- }
-}
-FX_WCHAR CBC_Base256Encoder::randomize255State(FX_WCHAR ch, int32_t codewordPosition)
-{
- int32_t pseudoRandom = ((149 * codewordPosition) % 255) + 1;
- int32_t tempVariable = ch + pseudoRandom;
- if (tempVariable <= 255) {
- return (FX_WCHAR) tempVariable;
+ buffer.SetAt(0, FX_WCHAR(*buf) - '0');
+ int32_t lengthFieldSize = 1;
+ int32_t currentSize =
+ context.getCodewordCount() + dataCount + lengthFieldSize;
+ context.updateSymbolInfo(currentSize, e);
+ if (e != BCExceptionNO) {
+ return;
+ }
+ FX_BOOL mustPad = (context.m_symbolInfo->m_dataCapacity - currentSize) > 0;
+ if (context.hasMoreCharacters() || mustPad) {
+ if (dataCount <= 249) {
+ buffer.SetAt(0, (FX_WCHAR)dataCount);
+ } else if (dataCount > 249 && dataCount <= 1555) {
+ buffer.SetAt(0, (FX_WCHAR)((dataCount / 250) + 249));
+ buffer.Insert(1, (FX_WCHAR)(dataCount % 250));
} else {
- return (FX_WCHAR) (tempVariable - 256);
+ e = BCExceptionIllegalStateMessageLengthInvalid;
+ return;
}
+ }
+ for (int32_t i = 0, c = buffer.GetLength(); i < c; i++) {
+ context.writeCodeword(
+ randomize255State(buffer.GetAt(i), context.getCodewordCount() + 1));
+ }
+}
+FX_WCHAR CBC_Base256Encoder::randomize255State(FX_WCHAR ch,
+ int32_t codewordPosition) {
+ int32_t pseudoRandom = ((149 * codewordPosition) % 255) + 1;
+ int32_t tempVariable = ch + pseudoRandom;
+ if (tempVariable <= 255) {
+ return (FX_WCHAR)tempVariable;
+ } else {
+ return (FX_WCHAR)(tempVariable - 256);
+ }
}