blob: d2cd716d471db792ab01ab45d51a8519d05d819b [file] [log] [blame]
Tom Sepez99ffdb02016-01-26 14:51:21 -08001// 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
dsinclair447b1f32016-12-08 10:06:32 -08007#ifndef XFA_FWL_CFWL_BARCODE_H_
8#define XFA_FWL_CFWL_BARCODE_H_
Dan Sinclairc7cd8092016-02-18 15:02:55 -05009
dsinclair2c489cc2016-11-23 16:17:20 -080010#include <memory>
Dan Sinclair880962c2016-02-23 09:09:24 -050011
Dan Sinclaire7786682017-03-29 15:18:41 -040012#include "fxbarcode/BC_Library.h"
dsinclair447b1f32016-12-08 10:06:32 -080013#include "xfa/fwl/cfwl_edit.h"
dsinclair2c489cc2016-11-23 16:17:20 -080014
dsinclair2c489cc2016-11-23 16:17:20 -080015class CFX_Barcode;
dsinclair2c489cc2016-11-23 16:17:20 -080016
17enum FWL_BCDAttribute {
18 FWL_BCDATTRIBUTE_NONE = 0,
19 FWL_BCDATTRIBUTE_CHARENCODING = 1 << 0,
20 FWL_BCDATTRIBUTE_MODULEHEIGHT = 1 << 1,
21 FWL_BCDATTRIBUTE_MODULEWIDTH = 1 << 2,
22 FWL_BCDATTRIBUTE_DATALENGTH = 1 << 3,
23 FWL_BCDATTRIBUTE_CALCHECKSUM = 1 << 4,
24 FWL_BCDATTRIBUTE_PRINTCHECKSUM = 1 << 5,
25 FWL_BCDATTRIBUTE_TEXTLOCATION = 1 << 6,
26 FWL_BCDATTRIBUTE_WIDENARROWRATIO = 1 << 7,
27 FWL_BCDATTRIBUTE_STARTCHAR = 1 << 8,
28 FWL_BCDATTRIBUTE_ENDCHAR = 1 << 9,
Lei Zhang03d58932017-04-03 16:40:51 -070029 FWL_BCDATTRIBUTE_ECLEVEL = 1 << 10,
dsinclair2c489cc2016-11-23 16:17:20 -080030};
31
Tom Sepez55865452018-08-27 20:18:04 +000032class CFWL_Barcode final : public CFWL_Edit {
Tom Sepez99ffdb02016-01-26 14:51:21 -080033 public:
dsinclair1a7534a2016-11-22 15:56:11 -080034 explicit CFWL_Barcode(const CFWL_App* pApp);
dsinclair0ca71ec2016-10-19 07:59:25 -070035 ~CFWL_Barcode() override;
weili5d8e5aa2016-08-08 17:30:37 -070036
dsinclair2c489cc2016-11-23 16:17:20 -080037 // CFWL_Widget
38 FWL_Type GetClassID() const override;
39 void Update() override;
Lei Zhang4b472142017-08-17 14:30:08 -070040 void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
dsinclair2c489cc2016-11-23 16:17:20 -080041 void OnProcessEvent(CFWL_Event* pEvent) override;
dsinclair20855382016-10-31 07:29:34 -070042
dsinclair2c489cc2016-11-23 16:17:20 -080043 // CFWL_Edit
Lei Zhangb600f152019-01-25 23:21:50 +000044 void SetText(const WideString& wsText) override;
45 void SetTextSkipNotify(const WideString& wsText) override;
weili4ce94e12016-06-18 06:21:57 -070046
dsinclairc64b76c2016-11-14 09:01:37 -080047 void SetType(BC_TYPE type);
dsinclair2c489cc2016-11-23 16:17:20 -080048 bool IsProtectedType() const;
dsinclairc64b76c2016-11-14 09:01:37 -080049
50 void SetCharEncoding(BC_CHAR_ENCODING encoding);
51 void SetModuleHeight(int32_t height);
52 void SetModuleWidth(int32_t width);
53 void SetDataLength(int32_t dataLength);
54 void SetCalChecksum(bool calChecksum);
55 void SetPrintChecksum(bool printChecksum);
56 void SetTextLocation(BC_TEXT_LOC location);
Lei Zhang1badb852017-04-20 15:58:56 -070057 void SetWideNarrowRatio(int8_t ratio);
Dan Sinclair812e96c2017-03-13 16:43:37 -040058 void SetStartChar(char startChar);
59 void SetEndChar(char endChar);
dsinclairc64b76c2016-11-14 09:01:37 -080060 void SetErrorCorrectionLevel(int32_t ecLevel);
dsinclairc64b76c2016-11-14 09:01:37 -080061
dsinclaireb3f68c2016-11-07 10:28:47 -080062 private:
Lei Zhang41f22be2019-01-25 23:18:50 +000063 enum class Status : uint8_t {
64 kNormal,
65 kNeedUpdate,
66 kEncodeSuccess,
67 };
68
dsinclair2c489cc2016-11-23 16:17:20 -080069 void GenerateBarcodeImageCache();
70 void CreateBarcodeEngine();
71
Lei Zhang41f22be2019-01-25 23:18:50 +000072 BC_TYPE m_type = BC_UNKNOWN;
Tom Sepezc58babd2020-01-14 20:04:16 +000073 BC_CHAR_ENCODING m_eCharEncoding = CHAR_ENCODING_UTF8;
74 BC_TEXT_LOC m_eTextLocation = BC_TEXT_LOC_NONE;
75 Status m_eStatus = Status::kNormal;
76 bool m_bCalChecksum = false;
77 bool m_bPrintChecksum = false;
78 char m_cStartChar = 0;
79 char m_cEndChar = 0;
80 int8_t m_nWideNarrowRatio = 1;
81 int32_t m_nModuleHeight = -1;
82 int32_t m_nModuleWidth = -1;
83 int32_t m_nDataLength = 0;
84 int32_t m_nECLevel = 0;
Lei Zhang41f22be2019-01-25 23:18:50 +000085 uint32_t m_dwAttributeMask = 0;
Tom Sepezc58babd2020-01-14 20:04:16 +000086 std::unique_ptr<CFX_Barcode> m_pBarcodeEngine;
Tom Sepez99ffdb02016-01-26 14:51:21 -080087};
Dan Sinclairc7cd8092016-02-18 15:02:55 -050088
dsinclair447b1f32016-12-08 10:06:32 -080089#endif // XFA_FWL_CFWL_BARCODE_H_