• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef FXBARCODE_ONED_BC_ONEDIMWRITER_H_
8 #define FXBARCODE_ONED_BC_ONEDIMWRITER_H_
9 
10 #include <stddef.h>
11 #include <stdint.h>
12 
13 #include <vector>
14 
15 #include "core/fxcrt/data_vector.h"
16 #include "core/fxcrt/fx_string.h"
17 #include "core/fxcrt/unowned_ptr.h"
18 #include "core/fxge/cfx_textrenderoptions.h"
19 #include "fxbarcode/BC_Library.h"
20 #include "fxbarcode/BC_Writer.h"
21 #include "third_party/base/span.h"
22 
23 class CFX_Font;
24 class CFX_Matrix;
25 class CFX_Path;
26 class CFX_RenderDevice;
27 class TextCharPos;
28 
29 class CBC_OneDimWriter : public CBC_Writer {
30  public:
GetTextRenderOptions()31   static constexpr CFX_TextRenderOptions GetTextRenderOptions() {
32     return CFX_TextRenderOptions(CFX_TextRenderOptions::kLcd);
33   }
34   static bool HasValidContentSize(WideStringView contents);
35 
36   CBC_OneDimWriter();
37   ~CBC_OneDimWriter() override;
38 
39   virtual bool RenderResult(WideStringView contents,
40                             pdfium::span<const uint8_t> code);
41   virtual bool CheckContentValidity(WideStringView contents) = 0;
42   virtual WideString FilterContents(WideStringView contents) = 0;
43   virtual void SetDataLength(int32_t length);
44 
45   void SetPrintChecksum(bool checksum);
46   void SetCalcChecksum(bool state);
47   void SetFontSize(float size);
48   void SetFontStyle(int32_t style);
49   void SetFontColor(FX_ARGB color);
50 
51   virtual DataVector<uint8_t> Encode(const ByteString& contents) = 0;
52   bool RenderDeviceResult(CFX_RenderDevice* device,
53                           const CFX_Matrix& matrix,
54                           WideStringView contents);
55   bool SetFont(CFX_Font* cFont);
56 
57  protected:
58   virtual bool ShowChars(WideStringView contents,
59                          CFX_RenderDevice* device,
60                          const CFX_Matrix& matrix,
61                          int32_t barWidth);
62   void ShowDeviceChars(CFX_RenderDevice* device,
63                        const CFX_Matrix& matrix,
64                        const ByteString str,
65                        float geWidth,
66                        TextCharPos* pCharPos,
67                        float locX,
68                        float locY,
69                        int32_t barWidth);
70   void CalcTextInfo(const ByteString& text,
71                     TextCharPos* charPos,
72                     CFX_Font* cFont,
73                     float geWidth,
74                     int32_t fontSize,
75                     float& charsLen);
76   pdfium::span<uint8_t> AppendPattern(pdfium::span<uint8_t> target,
77                                       pdfium::span<const uint8_t> pattern,
78                                       bool startColor);
79 
80   bool m_bPrintChecksum = true;
81   bool m_bCalcChecksum = false;
82   bool m_bLeftPadding = false;
83   bool m_bRightPadding = false;
84 
85   UnownedPtr<CFX_Font> m_pFont;
86   float m_fFontSize = 10.0f;
87   int32_t m_iFontStyle = 0;
88   uint32_t m_fontColor = 0xff000000;
89   BC_TEXT_LOC m_locTextLoc = BC_TEXT_LOC::kBelowEmbed;
90 
91   int32_t m_iDataLenth = 0;
92   size_t m_iContentLen = 0;
93 
94   std::vector<CFX_Path> m_output;
95   int32_t m_barWidth;
96   float m_outputHScale;
97 };
98 
99 #endif  // FXBARCODE_ONED_BC_ONEDIMWRITER_H_
100