8
9
10
11
12
13
14
15
16
17
18
19
20
21
23#include "fxbarcode/datamatrix/BC_EdifactEncoder.h"
27#include "fxbarcode/common/BC_CommonBitMatrix.h"
28#include "fxbarcode/datamatrix/BC_Encoder.h"
29#include "fxbarcode/datamatrix/BC_EncoderContext.h"
30#include "fxbarcode/datamatrix/BC_HighLevelEncoder.h"
31#include "fxbarcode/datamatrix/BC_SymbolInfo.h"
35WideString EncodeToEdifactCodewords(
const WideString& sb) {
36 size_t len = sb.GetLength();
41 wchar_t c2 = len >= 2 ? sb
[1
] : 0;
42 wchar_t c3 = len >= 3 ? sb
[2
] : 0;
43 wchar_t c4 = len >= 4 ? sb
[3
] : 0;
44 int32_t v = (c1 << 18) + (c2 << 12) + (c3 << 6) + c4;
45 constexpr size_t kBuflen = 3;
47 cw[0] =
static_cast<
wchar_t>((v >> 16) & 255);
48 cw[1] =
static_cast<
wchar_t>((v >> 8) & 255);
49 cw[2] =
static_cast<
wchar_t>(v & 255);
50 return WideString(cw,
std::min(len, kBuflen));
54 size_t count = buffer.GetLength();
65 context->m_symbolInfo->data_capacity() - context->getCodewordCount();
66 int32_t remaining = context->getRemainingCharacters();
67 if (remaining == 0 && available <= 2)
71 int32_t restChars = count - 1;
72 WideString encoded = EncodeToEdifactCodewords(buffer);
77 bool restInAscii = endOfSymbolReached && restChars <= 2;
83 context->m_symbolInfo->data_capacity() - context->getCodewordCount();
87 encoded.GetLength()
)) {
95 context->m_pos -= restChars;
103bool AppendEncodedChar(
wchar_t c, WideString* sb) {
104 if (c >=
' ' && c <=
'?') {
109 if (c >=
'@' && c <=
'^') {
131 if (!AppendEncodedChar(c, &buffer))
135 size_t count = buffer.GetLength();
137 WideString encoded = EncodeToEdifactCodewords(buffer);
144 CBC_HighLevelEncoder::LookAheadTest(context->m_msg, context->m_pos,
152 buffer
+= static_cast<
wchar_t>(31);
153 return HandleEOD(context, buffer);
~CBC_EdifactEncoder() override
CBC_HighLevelEncoder::Encoding GetEncodingMode() override
bool Encode(CBC_EncoderContext *context) override
void writeCodewords(const WideString &codewords)
void SignalEncoderChange(CBC_HighLevelEncoder::Encoding encoding)
WideString & operator+=(wchar_t ch)
CharType operator[](const size_t index) const