8
9
10
11
12
13
14
15
16
17
18
19
20
21
23#include "fxbarcode/oned/BC_OnedEAN8Writer.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/common/BC_CommonBitMatrix.h"
37#include "fxbarcode/oned/BC_OneDimWriter.h"
38#include "fxbarcode/oned/BC_OnedEANChecksum.h"
42const uint8_t kOnedEAN8StartPattern[3] = {1, 1, 1};
43const uint8_t kOnedEAN8MiddlePattern[5] = {1, 1, 1, 1, 1};
44const uint8_t kOnedEAN8LPattern[10][4] = {
45 {3, 2, 1, 1}, {2, 2, 2, 1}, {2, 1, 2, 2}, {1, 4, 1, 1}, {1, 1, 3, 2},
46 {1, 2, 3, 1}, {1, 1, 1, 4}, {1, 3, 1, 2}, {1, 2, 1, 3}, {3, 1, 1, 2}};
67 std::all_of(contents.begin(), contents.end(),
72 WideString filtercontents;
73 filtercontents.Reserve(contents.GetLength());
75 for (size_t i = 0; i < contents.GetLength(); i++) {
84 return filtercontents;
87int32_t CBC_OnedEAN8Writer::
CalcChecksum(
const ByteString& contents) {
92 if (contents.GetLength() != 8)
95 DataVector<uint8_t> result(m_codeWidth);
96 auto result_span = pdfium::make_span(result);
99 for (
int i = 0; i <= 3; i++) {
105 for (
int i = 4; i <= 7; i++) {
113bool CBC_OnedEAN8Writer::
ShowChars(WideStringView contents,
120 constexpr float kLeftPosition = 3.0f;
121 ByteString str = FX_UTF8Encode(contents);
122 size_t iLength = str.GetLength();
123 std::vector<TextCharPos> charpos(iLength);
124 ByteString tempStr = str.First(4);
125 size_t iLen = tempStr.GetLength();
126 constexpr int32_t kWidth = 28;
129 int32_t iFontSize =
static_cast<int32_t>(fabs(
m_fFontSize));
130 int32_t iTextHeight = iFontSize + 1;
134 kLeftPosition + kWidth - 0.5
, (
float)
m_Height);
140 kLeftPosition + 33 + kWidth - 0.5
, (
float)
m_Height);
146 CalcTextInfo(tempStr, charpos.data(), m_pFont, (
float)strWidth, iFontSize,
151 (
float)(
m_Height - iTextHeight + iFontSize)
);
153 device->DrawNormalText(pdfium::make_span(charpos).first(iLen), m_pFont,
154 static_cast<
float>(iFontSize), affine_matrix1,
155 m_fontColor, GetTextRenderOptions());
157 tempStr = str.Substr(4, 4);
158 iLen = tempStr.GetLength();
159 CalcTextInfo(tempStr, &charpos[4], m_pFont, (
float)strWidth, iFontSize,
164 (
float)(
m_Height - iTextHeight + iFontSize)
);
166 device->DrawNormalText(pdfium::make_span(charpos).subspan(4, iLen), m_pFont,
167 static_cast<
float>(iFontSize), affine_matrix1,
168 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)
int32_t CalcChecksum(const ByteString &contents) override
bool ShowChars(WideStringView contents, CFX_RenderDevice *device, const CFX_Matrix &matrix, int32_t barWidth) override
~CBC_OnedEAN8Writer() override
bool CheckContentValidity(WideStringView contents) override
void SetTextLocation(BC_TEXT_LOC location) override
void SetDataLength(int32_t length) override
WideString FilterContents(WideStringView contents) override
DataVector< uint8_t > Encode(const ByteString &contents) 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