8
9
10
11
12
13
14
15
16
17
18
19
20
21
23#include "fxbarcode/oned/BC_OnedCodaBarWriter.h"
27#include "core/fxcrt/fx_2d_size.h"
28#include "core/fxcrt/fx_extension.h"
29#include "fxbarcode/BC_Writer.h"
30#include "fxbarcode/common/BC_CommonBitMatrix.h"
31#include "fxbarcode/oned/BC_OneDimWriter.h"
32#include "third_party/base/containers/contains.h"
36const char kOnedCodaAlphabet[] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
37 '8',
'9',
'-',
'$',
':',
'/',
'.',
'+',
38 'A',
'B',
'C',
'D',
'T',
'N'};
40const int8_t kOnedCodaCharacterEncoding[] = {
41 0x03, 0x06, 0x09, 0x60, 0x12, 0x42, 0x21, 0x24, 0x30, 0x48, 0x0c,
42 0x18, 0x45, 0x51, 0x54, 0x15, 0x1A, 0x29, 0x0B, 0x0E, 0x1A, 0x29};
43static_assert(
std::size(kOnedCodaCharacterEncoding) == 22,
"Wrong size");
44static_assert(
std::size(kOnedCodaCharacterEncoding) ==
45 std::size(kOnedCodaAlphabet),
48const char kStartEndChars[] = {
'A',
'B',
'C',
'D',
'T',
'N',
'*',
'E',
49 'a',
'b',
'c',
'd',
't',
'n',
'e'};
50const char kContentChars[] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
51 '8',
'9',
'-',
'$',
'/',
':',
'+',
'.'};
53bool IsValidChar(
wchar_t ch,
bool isContent) {
57 char narrow_ch =
static_cast<
char>(ch);
58 return pdfium::Contains(kContentChars, narrow_ch) ||
59 (isContent && pdfium::Contains(kStartEndChars, narrow_ch));
69 if (!pdfium::Contains(kStartEndChars, start))
77 if (!pdfium::Contains(kStartEndChars, end))
93 if (ratio < 2 || ratio > 3)
96 m_iWideNarrRatio = ratio;
102 std::all_of(contents.begin(), contents.end(),
103 [](
const wchar_t& ch) {
return IsValidChar(ch,
false); });
107 WideString filtercontents;
108 filtercontents.Reserve(contents.GetLength());
110 for (size_t index = 0; index < contents.GetLength(); index++) {
111 ch = contents[index];
116 if (!IsValidChar(ch,
true))
118 filtercontents
+= ch;
120 return filtercontents;
124 ByteString data = m_chStart
+ contents
+ m_chEnd;
125 m_iContentLen = data.GetLength();
126 DataVector<uint8_t> result(
127 Fx2DSizeOrDie(m_iWideNarrRatio * 7, data.GetLength()));
129 int32_t position = 0;
130 for (size_t index = 0; index < data.GetLength(); index++) {
131 ch = FXSYS_ToUpperASCII(data[index]);
149 for (size_t i = 0; i <
std::size(kOnedCodaAlphabet); i++) {
150 if (ch == kOnedCodaAlphabet[i]) {
151 code = kOnedCodaCharacterEncoding[i];
159 result[position] = color;
161 if (((code >> (6 - bit)) & 1) == 0 || counter == m_iWideNarrRatio - 1) {
169 if (index < data.GetLength() - 1) {
170 result[position] = 0;
174 result.resize(position);
179 WideString strStart
(static_cast<
wchar_t>(m_chStart)
);
180 WideString strEnd
(static_cast<
wchar_t>(m_chEnd)
);
181 return strStart + contents + strEnd;
185 pdfium::span<
const uint8_t> code) {
static bool HasValidContentSize(WideStringView contents)
virtual bool RenderResult(WideStringView contents, pdfium::span< const uint8_t > code)
bool SetEndChar(char end) override
WideString encodedContents(WideStringView contents)
void SetTextLocation(BC_TEXT_LOC location) override
void SetDataLength(int32_t length) override
bool SetWideNarrowRatio(int8_t ratio) override
bool RenderResult(WideStringView contents, pdfium::span< const uint8_t > code) override
DataVector< uint8_t > Encode(const ByteString &contents) override
bool CheckContentValidity(WideStringView contents) override
bool SetStartChar(char start) override
~CBC_OnedCodaBarWriter() override
WideString FilterContents(WideStringView contents) override
WideString & operator+=(wchar_t ch)
ByteString operator+(const ByteString &str1, char ch)
ByteString operator+(char ch, const ByteString &str2)