8
9
10
11
12
13
14
15
16
17
18
19
20
21
23#include "fxbarcode/datamatrix/BC_C40Encoder.h"
27#include "core/fxcrt/fx_extension.h"
28#include "fxbarcode/common/BC_CommonBitMatrix.h"
29#include "fxbarcode/datamatrix/BC_Encoder.h"
30#include "fxbarcode/datamatrix/BC_EncoderContext.h"
31#include "fxbarcode/datamatrix/BC_HighLevelEncoder.h"
32#include "fxbarcode/datamatrix/BC_SymbolInfo.h"
33#include "third_party/base/check.h"
37WideString EncodeToC40Codewords(
const WideString& sb) {
41 int32_t v = (1600 * c1) + (40 * c2) + c3 + 1;
43 cw[0] =
static_cast<
wchar_t>(v / 256);
44 cw[1] =
static_cast<
wchar_t>(v % 256);
45 return WideString(cw,
std::size(cw));
64 if (lastCharSize <= 0)
67 size_t unwritten = (buffer.GetLength() / 3) * 2;
68 int32_t curCodewordCount = context->getCodewordCount() + unwritten;
73 context->m_symbolInfo->data_capacity() - curCodewordCount;
75 if ((buffer.GetLength() % 3) == 2) {
76 if (available < 2 || available > 2) {
77 lastCharSize = BacktrackOneCharacter(context, &buffer, lastCharSize);
82 while ((buffer.GetLength() % 3) == 1 &&
83 ((lastCharSize <= 3 && available != 1) || lastCharSize > 3)) {
84 lastCharSize = BacktrackOneCharacter(context, &buffer, lastCharSize);
90 size_t count = buffer.GetLength();
91 if ((count % 3) == 0) {
93 CBC_HighLevelEncoder::LookAheadTest(context->m_msg, context->m_pos,
105 WideString* buffer) {
107 buffer->Delete(0, 3);
111 WideString* buffer) {
112 size_t unwritten = (buffer->GetLength() / 3) * 2;
113 size_t rest = buffer->GetLength() % 3;
114 int32_t curCodewordCount = context->getCodewordCount() + unwritten;
118 int32_t available = context->m_symbolInfo->data_capacity() - curCodewordCount;
120 *buffer
+= (
wchar_t)
'\0';
121 while (buffer->GetLength() >= 3)
126 }
else if (available == 1 && rest == 1) {
127 while (buffer->GetLength() >= 3)
133 }
else if (rest == 0) {
134 while (buffer->GetLength() >= 3)
148 *sb
+= (
wchar_t)
'\3';
152 *sb
+= (
wchar_t)(c - 48 + 4);
156 *sb
+= (
wchar_t)(c - 65 + 14);
160 *sb
+= (
wchar_t)
'\0';
164 if ((c >=
'!') && (c <=
'/')) {
165 *sb
+= (
wchar_t)
'\1';
166 *sb
+= (
wchar_t)(c - 33);
169 if ((c >=
':') && (c <=
'@')) {
170 *sb
+= (
wchar_t)
'\1';
171 *sb
+= (
wchar_t)(c - 58 + 15);
174 if ((c >=
'[') && (c <=
'_')) {
175 *sb
+= (
wchar_t)
'\1';
176 *sb
+= (
wchar_t)(c - 91 + 22);
179 if ((c >= 60) && (c <= 0x7f)) {
180 *sb
+= (
wchar_t)
'\2';
181 *sb
+= (
wchar_t)(c - 96);
185 *sb
+= (
wchar_t)
'\1';
186 *sb
+= (
wchar_t)0x001e;
188 return encode_result > 0 ? encode_result + 2 : 0;
195 int32_t lastCharSize) {
196 DCHECK(lastCharSize >= 0);
198 if (context->m_pos < 1)
201 size_t count = buffer->GetLength();
202 if (count <
static_cast<size_t>(lastCharSize))
205 buffer->Delete(count - lastCharSize, lastCharSize);
static void WriteNextTriplet(CBC_EncoderContext *context, WideString *buffer)
virtual int32_t EncodeChar(wchar_t c, WideString *sb)
CBC_HighLevelEncoder::Encoding GetEncodingMode() override
virtual bool HandleEOD(CBC_EncoderContext *context, WideString *buffer)
bool Encode(CBC_EncoderContext *context) override
~CBC_C40Encoder() override
void writeCodewords(const WideString &codewords)
void writeCodeword(wchar_t codeword)
void SignalEncoderChange(CBC_HighLevelEncoder::Encoding encoding)
static const wchar_t C40_UNLATCH
WideString & operator+=(wchar_t ch)
CharType operator[](const size_t index) const
bool FXSYS_IsDecimalDigit(wchar_t c)
bool FXSYS_IsUpperASCII(int32_t c)