• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
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 <memory>
11 #include <vector>
12 
13 #include "core/fxcrt/unowned_ptr.h"
14 #include "core/fxge/cfx_renderdevice.h"
15 #include "fxbarcode/BC_Library.h"
16 #include "fxbarcode/BC_Writer.h"
17 
18 class CFX_Font;
19 class CFX_PathData;
20 class CFX_RenderDevice;
21 
22 class CBC_OneDimWriter : public CBC_Writer {
23  public:
24   CBC_OneDimWriter();
25   ~CBC_OneDimWriter() override;
26 
27   virtual bool RenderResult(const WideStringView& contents,
28                             uint8_t* code,
29                             int32_t codeLength);
30   virtual bool CheckContentValidity(const WideStringView& contents) = 0;
31   virtual WideString FilterContents(const WideStringView& contents) = 0;
32   virtual WideString RenderTextContents(const WideStringView& contents);
33   virtual void SetPrintChecksum(bool checksum);
34   virtual void SetDataLength(int32_t length);
35   virtual void SetCalcChecksum(bool state);
36   virtual void SetFontSize(float size);
37   virtual void SetFontStyle(int32_t style);
38   virtual void SetFontColor(FX_ARGB color);
39 
40   uint8_t* Encode(const ByteString& contents,
41                   BCFORMAT format,
42                   int32_t& outWidth,
43                   int32_t& outHeight);
44   bool RenderDeviceResult(CFX_RenderDevice* device,
45                           const CFX_Matrix* matrix,
46                           const WideStringView& contents);
47   bool SetFont(CFX_Font* cFont);
48 
49  protected:
50   virtual uint8_t* EncodeWithHint(const ByteString& contents,
51                                   BCFORMAT format,
52                                   int32_t& outWidth,
53                                   int32_t& outHeight,
54                                   int32_t hints);
55   virtual uint8_t* EncodeImpl(const ByteString& contents,
56                               int32_t& outLength) = 0;
57   virtual void CalcTextInfo(const ByteString& text,
58                             FXTEXT_CHARPOS* charPos,
59                             CFX_Font* cFont,
60                             float geWidth,
61                             int32_t fontSize,
62                             float& charsLen);
63   virtual bool ShowChars(const WideStringView& contents,
64                          CFX_RenderDevice* device,
65                          const CFX_Matrix* matrix,
66                          int32_t barWidth,
67                          int32_t multiple);
68   virtual void ShowDeviceChars(CFX_RenderDevice* device,
69                                const CFX_Matrix* matrix,
70                                const ByteString str,
71                                float geWidth,
72                                FXTEXT_CHARPOS* pCharPos,
73                                float locX,
74                                float locY,
75                                int32_t barWidth);
76   virtual int32_t AppendPattern(uint8_t* target,
77                                 int32_t pos,
78                                 const int8_t* pattern,
79                                 int32_t patternLength,
80                                 int32_t startColor,
81                                 int32_t& e);
82 
83   wchar_t Upper(wchar_t ch);
84   void RenderVerticalBars(int32_t outputX, int32_t width, int32_t height);
85 
86   bool m_bPrintChecksum;
87   int32_t m_iDataLenth;
88   bool m_bCalcChecksum;
89   UnownedPtr<CFX_Font> m_pFont;
90   float m_fFontSize;
91   int32_t m_iFontStyle;
92   uint32_t m_fontColor;
93   BC_TEXT_LOC m_locTextLoc;
94   size_t m_iContentLen;
95   bool m_bLeftPadding;
96   bool m_bRightPadding;
97   std::vector<CFX_PathData> m_output;
98   int32_t m_barWidth;
99   int32_t m_multiple;
100   float m_outputHScale;
101 };
102 
103 #endif  // FXBARCODE_ONED_BC_ONEDIMWRITER_H_
104