• 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 XFA_FWL_CFWL_BARCODE_H_
8 #define XFA_FWL_CFWL_BARCODE_H_
9 
10 #include <stdint.h>
11 
12 #include <memory>
13 #include <optional>
14 
15 #include "fxbarcode/BC_Library.h"
16 #include "xfa/fwl/cfwl_edit.h"
17 
18 class CFX_Barcode;
19 
20 namespace pdfium {
21 
22 class CFWL_Barcode final : public CFWL_Edit {
23  public:
24   CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
25   ~CFWL_Barcode() override;
26 
27   // CFWL_Widget
28   FWL_Type GetClassID() const override;
29   void Update() override;
30   void DrawWidget(CFGAS_GEGraphics* pGraphics,
31                   const CFX_Matrix& matrix) override;
32   void OnProcessEvent(CFWL_Event* pEvent) override;
33 
34   // CFWL_Edit
35   void SetText(const WideString& wsText) override;
36   void SetTextSkipNotify(const WideString& wsText) override;
37 
38   void SetType(BC_TYPE type);
39   bool IsProtectedType() const;
40 
41   void SetModuleHeight(int32_t height);
42   void SetModuleWidth(int32_t width);
43   void SetDataLength(int32_t dataLength);
44   void SetCalChecksum(bool calChecksum);
45   void SetPrintChecksum(bool printChecksum);
46   void SetTextLocation(BC_TEXT_LOC location);
47   void SetWideNarrowRatio(int8_t ratio);
48   void SetStartChar(char startChar);
49   void SetEndChar(char endChar);
50   void SetErrorCorrectionLevel(int32_t ecLevel);
51 
52  private:
53   enum class Status : uint8_t {
54     kNormal,
55     kNeedUpdate,
56     kEncodeSuccess,
57   };
58 
59   explicit CFWL_Barcode(CFWL_App* pApp);
60 
61   void GenerateBarcodeImageCache();
62   void CreateBarcodeEngine();
63 
64   BC_TYPE m_type = BC_TYPE::kUnknown;
65   Status m_eStatus = Status::kNormal;
66   std::optional<BC_TEXT_LOC> m_eTextLocation;
67   std::optional<bool> m_bCalChecksum;
68   std::optional<bool> m_bPrintChecksum;
69   std::optional<char> m_cStartChar;
70   std::optional<char> m_cEndChar;
71   std::optional<int8_t> m_nWideNarrowRatio;
72   std::optional<int32_t> m_nModuleHeight;
73   std::optional<int32_t> m_nModuleWidth;
74   std::optional<int32_t> m_nDataLength;
75   std::optional<int32_t> m_nECLevel;
76   std::unique_ptr<CFX_Barcode> m_pBarcodeEngine;
77 };
78 
79 }  // namespace pdfium
80 
81 // TODO(crbug.com/42271761): Remove.
82 using pdfium::CFWL_Barcode;
83 
84 #endif  // XFA_FWL_CFWL_BARCODE_H_
85