8
9
10
11
12
13
14
15
16
17
18
19
20
21
23#include "fxbarcode/oned/BC_OnedEAN13Writer.h"
31#include "core/fxcrt/fx_extension.h"
32#include "core/fxcrt/fx_memory_wrappers.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"
41const int8_t kFirstDigitEncodings[10] = {0x00, 0x0B, 0x0D, 0xE, 0x13,
42 0x19, 0x1C, 0x15, 0x16, 0x1A};
43const uint8_t kOnedEAN13StartPattern[3] = {1, 1, 1};
44const uint8_t kOnedEAN13MiddlePattern[5] = {1, 1, 1, 1, 1};
45const uint8_t kOnedEAN13LPattern[10][4] = {
46 {3, 2, 1, 1}, {2, 2, 2, 1}, {2, 1, 2, 2}, {1, 4, 1, 1}, {1, 1, 3, 2},
47 {1, 2, 3, 1}, {1, 1, 1, 4}, {1, 3, 1, 2}, {1, 2, 1, 3}, {3, 1, 1, 2}};
48const uint8_t kOnedEAN13LGPattern[20][4] = {
49 {3, 2, 1, 1}, {2, 2, 2, 1}, {2, 1, 2, 2}, {1, 4, 1, 1}, {1, 1, 3, 2},
50 {1, 2, 3, 1}, {1, 1, 1, 4}, {1, 3, 1, 2}, {1, 2, 1, 3}, {3, 1, 1, 2},
51 {1, 1, 2, 3}, {1, 2, 2, 2}, {2, 2, 1, 2}, {1, 1, 4, 1}, {2, 3, 1, 1},
52 {1, 3, 2, 1}, {4, 1, 1, 1}, {2, 1, 3, 1}, {3, 1, 2, 1}, {2, 1, 1, 3}};
58 m_codeWidth = 3 + (7 * 6) + 5 + (7 * 6) + 3;
64 std::all_of(contents.begin(), contents.end(),
69 WideString filtercontents;
70 filtercontents.Reserve(contents.GetLength());
72 for (size_t i = 0; i < contents.GetLength(); i++) {
81 return filtercontents;
84int32_t CBC_OnedEAN13Writer::
CalcChecksum(
const ByteString& contents) {
89 if (contents.GetLength() != 13)
90 return DataVector<uint8_t>();
94 int32_t parities = kFirstDigitEncodings[firstDigit];
95 DataVector<uint8_t> result(m_codeWidth);
96 auto result_span = pdfium::make_span(result);
99 for (
int i = 1; i <= 6; i++) {
101 if ((parities >> (6 - i) & 1) == 1) {
108 for (
int i = 7; i <= 12; i++) {
116bool CBC_OnedEAN13Writer::
ShowChars(WideStringView contents,
123 constexpr float kLeftPosition = 10.0f;
124 ByteString str = FX_UTF8Encode(contents);
125 size_t length = str.GetLength();
126 std::vector<TextCharPos> charpos(length);
127 int32_t iFontSize =
static_cast<int32_t>(fabs(
m_fFontSize));
128 int32_t iTextHeight = iFontSize + 1;
129 ByteString tempStr = str.Substr(1, 6);
130 constexpr int32_t kWidth = 42;
134 kLeftPosition + kWidth - 0.5
, (
float)
m_Height);
139 kLeftPosition + 47 + kWidth - 0.5
, (
float)
m_Height);
152 length = tempStr.GetLength();
155 CalcTextInfo(tempStr, &charpos[1], m_pFont, (
float)strWidth, iFontSize,
160 (
float)(
m_Height - iTextHeight) + iFontSize
);
162 device->DrawNormalText(pdfium::make_span(charpos).subspan(1, length),
163 m_pFont,
static_cast<
float>(iFontSize),
164 affine_matrix1, m_fontColor, GetTextRenderOptions());
166 tempStr = str.Substr(7, 6);
167 length = tempStr.GetLength();
168 CalcTextInfo(tempStr, &charpos[7], m_pFont, (
float)strWidth, iFontSize,
173 (
float)(
m_Height - iTextHeight + iFontSize)
);
175 device->DrawNormalText(pdfium::make_span(charpos).subspan(7, length),
176 m_pFont,
static_cast<
float>(iFontSize),
177 affine_matrix1, m_fontColor, GetTextRenderOptions());
179 tempStr = str.First(1);
180 length = tempStr.GetLength();
183 CalcTextInfo(tempStr, charpos.data(), m_pFont, (
float)strWidth, iFontSize,
187 (
float)(
m_Height - iTextHeight + iFontSize)
);
189 device->DrawNormalText(pdfium::make_span(charpos).first(length), m_pFont,
190 static_cast<
float>(iFontSize), affine_matrix1,
191 m_fontColor, GetTextRenderOptions());
int32_t EANCalcChecksum(const ByteString &contents)
static bool HasValidContentSize(WideStringView contents)
pdfium::span< uint8_t > AppendPattern(pdfium::span< uint8_t > target, pdfium::span< const uint8_t > pattern, bool startColor)
~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
constexpr CFX_FloatRect(float l, float b, float r, float t)
FX_RECT GetOuterRect() const
CFX_FloatRect TransformRect(const CFX_FloatRect &rect) const
CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
void Concat(const CFX_Matrix &right)
bool FillRect(const FX_RECT &rect, uint32_t color)
CharType operator[](const size_t index) const
WideString & operator+=(wchar_t ch)
bool FXSYS_IsDecimalDigit(wchar_t c)
int FXSYS_DecimalCharToInt(char c)
FX_RECT & operator=(const FX_RECT &that)=default