summaryrefslogtreecommitdiff
path: root/fxbarcode/datamatrix
diff options
context:
space:
mode:
Diffstat (limited to 'fxbarcode/datamatrix')
-rw-r--r--fxbarcode/datamatrix/BC_C40Encoder.cpp40
-rw-r--r--fxbarcode/datamatrix/BC_C40Encoder.h12
2 files changed, 28 insertions, 24 deletions
diff --git a/fxbarcode/datamatrix/BC_C40Encoder.cpp b/fxbarcode/datamatrix/BC_C40Encoder.cpp
index e8aa679e28..8d352b1a98 100644
--- a/fxbarcode/datamatrix/BC_C40Encoder.cpp
+++ b/fxbarcode/datamatrix/BC_C40Encoder.cpp
@@ -67,21 +67,20 @@ void CBC_C40Encoder::Encode(CBC_EncoderContext& context, int32_t& e) {
}
int32_t available = context.m_symbolInfo->m_dataCapacity - curCodewordCount;
if (!context.hasMoreCharacters()) {
- CFX_WideString removed;
if ((buffer.GetLength() % 3) == 2) {
if (available < 2 || available > 2) {
- lastCharSize =
- backtrackOneCharacter(context, buffer, removed, lastCharSize, e);
- if (e != BCExceptionNO) {
+ lastCharSize = BacktrackOneCharacter(&context, &buffer, lastCharSize);
+ if (lastCharSize < 0) {
+ e = BCExceptionGeneric;
return;
}
}
}
while ((buffer.GetLength() % 3) == 1 &&
((lastCharSize <= 3 && available != 1) || lastCharSize > 3)) {
- lastCharSize =
- backtrackOneCharacter(context, buffer, removed, lastCharSize, e);
- if (e != BCExceptionNO) {
+ lastCharSize = BacktrackOneCharacter(&context, &buffer, lastCharSize);
+ if (lastCharSize < 0) {
+ e = BCExceptionGeneric;
return;
}
}
@@ -187,18 +186,21 @@ int32_t CBC_C40Encoder::encodeChar(wchar_t c, CFX_WideString& sb, int32_t& e) {
return 0;
}
}
-int32_t CBC_C40Encoder::backtrackOneCharacter(CBC_EncoderContext& context,
- CFX_WideString& buffer,
- CFX_WideString& removed,
- int32_t lastCharSize,
- int32_t& e) {
- int32_t count = buffer.GetLength();
- buffer.Delete(count - lastCharSize, count);
- context.m_pos--;
- wchar_t c = context.getCurrentChar();
- lastCharSize = encodeChar(c, removed, e);
+
+int32_t CBC_C40Encoder::BacktrackOneCharacter(CBC_EncoderContext* context,
+ CFX_WideString* buffer,
+ int32_t lastCharSize) {
+ int32_t count = buffer->GetLength();
+ buffer->Delete(count - lastCharSize, count);
+ context->m_pos--;
+ wchar_t c = context->getCurrentChar();
+ int32_t e = BCExceptionNO;
+ CFX_WideString removed;
+ int32_t len = encodeChar(c, removed, e);
if (e != BCExceptionNO)
return -1;
- context.resetSymbolInfo();
- return lastCharSize;
+
+ assert(len > 0);
+ context->resetSymbolInfo();
+ return len;
}
diff --git a/fxbarcode/datamatrix/BC_C40Encoder.h b/fxbarcode/datamatrix/BC_C40Encoder.h
index ad8669d412..550d226efb 100644
--- a/fxbarcode/datamatrix/BC_C40Encoder.h
+++ b/fxbarcode/datamatrix/BC_C40Encoder.h
@@ -29,11 +29,13 @@ class CBC_C40Encoder : public CBC_Encoder {
virtual int32_t encodeChar(wchar_t c, CFX_WideString& sb, int32_t& e);
private:
- int32_t backtrackOneCharacter(CBC_EncoderContext& context,
- CFX_WideString& buffer,
- CFX_WideString& removed,
- int32_t lastCharSize,
- int32_t& e);
+ // Moves back by 1 position in |context| and adjusts |buffer| accordingly
+ // using |lastCharSize|. Returns the length of the current character in
+ // |context| after adjusting the position. If the character cannot be encoded,
+ // return -1.
+ int32_t BacktrackOneCharacter(CBC_EncoderContext* context,
+ CFX_WideString* buffer,
+ int32_t lastCharSize);
};
#endif // FXBARCODE_DATAMATRIX_BC_C40ENCODER_H_