8
9
10
11
12
13
14
15
16
17
18
19
20
21
23#include "fxbarcode/oned/BC_OneDimWriter.h"
31#include "build/build_config.h"
32#include "core/fxge/cfx_defaultrenderdevice.h"
33#include "core/fxge/cfx_fillrenderoptions.h"
34#include "core/fxge/cfx_font.h"
35#include "core/fxge/cfx_graphstatedata.h"
36#include "core/fxge/cfx_path.h"
37#include "core/fxge/cfx_renderdevice.h"
38#include "core/fxge/cfx_unicodeencodingex.h"
39#include "core/fxge/text_char_pos.h"
40#include "fxbarcode/BC_Writer.h"
46 static constexpr size_t kMaxInputLengthBytes = 8192;
48 size_t size = contents.GetLength();
49 return size > 0 && size <= kMaxInputLengthBytes;
89 pdfium::span<uint8_t> target,
90 pdfium::span<
const uint8_t> pattern,
92 bool color = startColor;
95 for (
const int8_t pattern_value : pattern) {
96 for (int32_t i = 0; i < pattern_value; ++i)
97 target[pos++] = color ? 1 : 0;
98 added += pattern_value;
101 return target.subspan(added);
110 std::unique_ptr<CFX_UnicodeEncodingEx> encoding =
111 FX_CreateFontEncodingEx(cFont);
113 const size_t length = text.GetLength();
114 std::vector<uint32_t> charcodes(length);
116 for (size_t i = 0; i < length; ++i) {
117 charcodes[i] = encoding->CharCodeFromUnicode(text[i]);
118 int32_t glyph_code = encoding->GlyphFromCharCode(charcodes[i]);
120 float temp = glyph_value * fontSize / 1000.0;
123 charsLen = charWidth;
124 float leftPositon = (
float)(geWidth - charsLen) / 2.0f;
125 if (leftPositon < 0 && geWidth == 0) {
129 float penY = (
float)abs(cFont
->GetDescent()) * (
float)fontSize / 1000.0f;
130 float left = leftPositon;
132 charPos[0].m_Origin = CFX_PointF(penX + left, penY + top);
133 charPos[0]
.m_GlyphIndex = encoding->GlyphFromCharCode(charcodes[0]);
135#if BUILDFLAG(IS_APPLE)
136 charPos[0].m_ExtGID = charPos[0].m_GlyphIndex;
139 for (size_t i = 1; i < length; i++) {
140 charPos[i].m_Origin = CFX_PointF(penX + left, penY + top);
141 charPos[i].m_GlyphIndex = encoding->GlyphFromCharCode(charcodes[i]);
142 charPos[i].m_FontCharWidth = cFont->GetGlyphWidth(charPos[i].m_GlyphIndex);
143#if BUILDFLAG(IS_APPLE)
144 charPos[i].m_ExtGID = charPos[i].m_GlyphIndex;
146 penX += (
float)(charPos[i].m_FontCharWidth) * (
float)fontSize / 1000.0f;
152 const ByteString str,
158 int32_t iFontSize =
static_cast<int32_t>(fabs(
m_fFontSize));
159 int32_t iTextHeight = iFontSize + 1;
161 (
float)(locY + iTextHeight)
);
168 (
float)(locY + iFontSize)
);
170 device->DrawNormalText(pdfium::make_span(pCharPos, str.GetLength()), m_pFont,
171 static_cast<
float>(iFontSize), affine_matrix,
172 m_fontColor, GetTextRenderOptions());
179 if (!device || !m_pFont)
182 ByteString str = FX_UTF8Encode(contents);
183 std::vector<TextCharPos> charpos(str.GetLength());
191 geWidth = (
float)barWidth;
193 int32_t iFontSize =
static_cast<int32_t>(fabs(
m_fFontSize));
194 int32_t iTextHeight = iFontSize + 1;
195 CalcTextInfo(str, charpos.data(), m_pFont, geWidth, iFontSize, charsLen);
203 locX =
static_cast<int32_t>(barWidth - charsLen) / 2;
210 geWidth = (
float)barWidth;
213 locX =
static_cast<int32_t>(barWidth - charsLen) / 2;
221 geWidth = (
float)barWidth;
225 (
float)locY
, barWidth
);
231 WideStringView contents) {
232 if (m_output.empty())
244 for (
const auto& rect : m_output) {
245 CFX_GraphStateData data;
246 device->DrawPath(rect, &scaledMatrix, &data, kBarColor, 0,
247 CFX_FillRenderOptions::WindingOptions());
255 pdfium::span<
const uint8_t> code) {
260 const size_t original_codelength = code.size();
263 const size_t codelength = code.size() + leftPadding + rightPadding;
265 m_Width > 0 ?
static_cast<
float>(
m_Width) /
static_cast<
float>(codelength)
270 m_output.reserve(original_codelength);
271 for (size_t i = 0; i < original_codelength; ++i) {
275 size_t output_index = i + leftPadding;
276 if (output_index >= codelength)
279 m_output.emplace_back();
280 m_output.back().AppendRect(output_index, 0.0f, output_index + 1, 1.0f);
void SetFontSize(float size)
void SetFontColor(FX_ARGB color)
void ShowDeviceChars(CFX_RenderDevice *device, const CFX_Matrix &matrix, const ByteString str, float geWidth, TextCharPos *pCharPos, float locX, float locY, int32_t barWidth)
~CBC_OneDimWriter() override
void SetFontStyle(int32_t style)
virtual void SetDataLength(int32_t length)
virtual bool ShowChars(WideStringView contents, CFX_RenderDevice *device, const CFX_Matrix &matrix, int32_t barWidth)
static bool HasValidContentSize(WideStringView contents)
bool RenderDeviceResult(CFX_RenderDevice *device, const CFX_Matrix &matrix, WideStringView contents)
virtual bool RenderResult(WideStringView contents, pdfium::span< const uint8_t > code)
void CalcTextInfo(const ByteString &text, TextCharPos *charPos, CFX_Font *cFont, float geWidth, int32_t fontSize, float &charsLen)
void SetCalcChecksum(bool state)
void SetPrintChecksum(bool checksum)
pdfium::span< uint8_t > AppendPattern(pdfium::span< uint8_t > target, pdfium::span< const uint8_t > pattern, bool startColor)
bool SetFont(CFX_Font *cFont)
static const FX_ARGB kBackgroundColor
constexpr CFX_FloatRect(float l, float b, float r, float t)
FX_RECT GetOuterRect() const
int GetGlyphWidth(uint32_t glyph_index) 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)
void AppendRect(float left, float bottom, float right, float top)
bool FillRect(const FX_RECT &rect, uint32_t color)
bool DrawPath(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_GraphStateData *pGraphState, uint32_t fill_color, uint32_t stroke_color, const CFX_FillRenderOptions &fill_options)
static constexpr CFX_FillRenderOptions EvenOddOptions()