8
9
10
11
12
13
14
15
16
17
18
19
20
21
23#include "fxbarcode/oned/BC_OnedEAN13Writer.h"
32#include "core/fxcrt/fx_extension.h"
33#include "core/fxge/cfx_defaultrenderdevice.h"
34#include "core/fxge/text_char_pos.h"
35#include "fxbarcode/BC_Writer.h"
36#include "fxbarcode/oned/BC_OneDimWriter.h"
37#include "fxbarcode/oned/BC_OnedEANChecksum.h"
41constexpr std::array<
const int8_t, 10> kFirstDigitEncodings = {
42 {0x00, 0x0B, 0x0D, 0xE, 0x13, 0x19, 0x1C, 0x15, 0x16, 0x1A}};
44const uint8_t kOnedEAN13StartPattern[3] = {1, 1, 1};
45const uint8_t kOnedEAN13MiddlePattern[5] = {1, 1, 1, 1, 1};
47using LPatternRow =
std::array<uint8_t, 4>;
48constexpr std::array<
const LPatternRow, 10> kOnedEAN13LPatternTable = {
60using LGPatternRow =
std::array<uint8_t, 4>;
61constexpr std::array<
const LGPatternRow, 20> kOnedEAN13LGPatternTable = {
62 {{3, 2, 1, 1}, {2, 2, 2, 1}, {2, 1, 2, 2}, {1, 4, 1, 1}, {1, 1, 3, 2},
63 {1, 2, 3, 1}, {1, 1, 1, 4}, {1, 3, 1, 2}, {1, 2, 1, 3}, {3, 1, 1, 2},
64 {1, 1, 2, 3}, {1, 2, 2, 2}, {2, 2, 1, 2}, {1, 1, 4, 1}, {2, 3, 1, 1},
65 {1, 3, 2, 1}, {4, 1, 1, 1}, {2, 1, 3, 1}, {3, 1, 2, 1}, {2, 1, 1, 3}}};
70 m_bLeftPadding =
true;
71 m_codeWidth = 3 + (7 * 6) + 5 + (7 * 6) + 3;
77 std::all_of(contents.begin(), contents.end(),
83 filtercontents.Reserve(contents.GetLength());
85 for (size_t i = 0; i < contents.GetLength(); i++) {
94 return filtercontents;
102 if (contents.GetLength() != 13)
103 return DataVector<uint8_t>();
106 int32_t firstDigit = FXSYS_DecimalCharToInt(contents.Front());
107 int32_t parities = kFirstDigitEncodings[firstDigit];
108 DataVector<uint8_t> result(m_codeWidth);
109 auto result_span =
pdfium::make_span(result);
110 result_span = AppendPattern(result_span, kOnedEAN13StartPattern,
true);
112 for (
int i = 1; i <= 6; i++) {
113 int32_t digit = FXSYS_DecimalCharToInt(contents[i]);
114 if ((parities >> (6 - i) & 1) == 1) {
118 AppendPattern(result_span, kOnedEAN13LGPatternTable[digit],
false);
120 result_span = AppendPattern(result_span, kOnedEAN13MiddlePattern,
false);
122 for (
int i = 7; i <= 12; i++) {
123 int32_t digit = FXSYS_DecimalCharToInt(contents[i]);
125 AppendPattern(result_span, kOnedEAN13LPatternTable[digit],
true);
127 AppendPattern(result_span, kOnedEAN13StartPattern,
true);
138 constexpr float kLeftPosition = 10.0f;
140 size_t length = str.GetLength();
141 std::vector<TextCharPos> charpos(length);
142 int32_t iFontSize =
static_cast<int32_t>(fabs(m_fFontSize));
143 int32_t iTextHeight = iFontSize + 1;
145 constexpr int32_t kWidth = 42;
147 CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
148 CFX_FloatRect rect(kLeftPosition, (
float)(m_Height - iTextHeight),
149 kLeftPosition + kWidth - 0.5, (
float)m_Height);
153 CFX_FloatRect rect1(kLeftPosition + 47, (
float)(m_Height - iTextHeight),
154 kLeftPosition + 47 + kWidth - 0.5, (
float)m_Height);
155 CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
159 CFX_Matrix matr2(m_outputHScale, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
160 CFX_FloatRect rect2(0.0f, (
float)(m_Height - iTextHeight), 6.5f,
167 length = tempStr.GetLength();
168 int32_t strWidth =
static_cast<int32_t>(kWidth * m_outputHScale);
170 pdfium::span<TextCharPos> charpos_span =
pdfium::make_span(charpos);
171 CalcTextInfo(tempStr, charpos_span.subspan(1), m_pFont, (
float)strWidth,
174 CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0,
175 kLeftPosition * m_outputHScale,
176 (
float)(m_Height - iTextHeight) + iFontSize);
178 device->DrawNormalText(charpos_span.subspan(1, length), m_pFont,
179 static_cast<
float>(iFontSize), affine_matrix1,
182 tempStr = str.Substr(7, 6);
183 length = tempStr.GetLength();
184 CalcTextInfo(tempStr, charpos_span.subspan(7), m_pFont, (
float)strWidth,
187 CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0,
188 (kLeftPosition + 47) * m_outputHScale,
189 (
float)(m_Height - iTextHeight + iFontSize));
191 device->DrawNormalText(charpos_span.subspan(7, length), m_pFont,
192 static_cast<
float>(iFontSize), affine_matrix1,
195 tempStr = str.First(1);
196 length = tempStr.GetLength();
197 strWidth = 7 *
static_cast<int32_t>(strWidth * m_outputHScale);
199 CalcTextInfo(tempStr, charpos, m_pFont, (
float)strWidth, iFontSize, blank);
201 CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, 0.0,
202 (
float)(m_Height - iTextHeight + iFontSize));
204 device->DrawNormalText(charpos_span.first(length), m_pFont,
205 static_cast<
float>(iFontSize), affine_matrix1,
int32_t EANCalcChecksum(const ByteString &contents)
fxcrt::ByteString ByteString
static bool HasValidContentSize(WideStringView contents)
static constexpr CFX_TextRenderOptions GetTextRenderOptions()
~CBC_OnedEAN13Writer() override
DataVector< uint8_t > Encode(const ByteString &contents) override
int32_t CalcChecksum(const ByteString &contents) override
WideString FilterContents(WideStringView contents) override
bool CheckContentValidity(WideStringView contents) override
bool ShowChars(WideStringView contents, CFX_RenderDevice *device, const CFX_Matrix &matrix, int32_t barWidth) override
static const FX_ARGB kBackgroundColor
FX_RECT GetOuterRect() const
CFX_FloatRect TransformRect(const CFX_FloatRect &rect) const
void Concat(const CFX_Matrix &right)
bool FillRect(const FX_RECT &rect, uint32_t color)
WideString & operator+=(wchar_t ch)
bool FXSYS_IsDecimalDigit(wchar_t c)
fxcrt::WideStringView WideStringView
FX_RECT & operator=(const FX_RECT &that)=default
fxcrt::WideString WideString