Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cfwl_barcode.cpp
Go to the documentation of this file.
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#include "xfa/fwl/cfwl_barcode.h"
8
9#include "fxbarcode/cfx_barcode.h"
10#include "xfa/fgas/font/cfgas_gefont.h"
11#include "xfa/fwl/cfwl_notedriver.h"
12#include "xfa/fwl/cfwl_themepart.h"
13#include "xfa/fwl/ifwl_themeprovider.h"
14#include "xfa/fwl/theme/cfwl_utils.h"
15
16CFWL_Barcode::CFWL_Barcode(CFWL_App* app)
17 : CFWL_Edit(app, Properties(), nullptr) {}
18
19CFWL_Barcode::~CFWL_Barcode() = default;
20
21FWL_Type CFWL_Barcode::GetClassID() const {
22 return FWL_Type::Barcode;
23}
24
25void CFWL_Barcode::Update() {
26 if (IsLocked())
27 return;
28
30 GenerateBarcodeImageCache();
31}
32
33void CFWL_Barcode::DrawWidget(CFGAS_GEGraphics* pGraphics,
34 const CFX_Matrix& matrix) {
35 if (!pGraphics)
36 return;
37
39 GenerateBarcodeImageCache();
40 if (!m_pBarcodeEngine || m_eStatus != Status::kEncodeSuccess)
41 return;
42
43 CFX_Matrix mt;
44 mt.e = GetRTClient().left;
45 mt.f = GetRTClient().top;
46 mt.Concat(matrix);
47
48 // TODO(tsepez): Curious as to why |mt| is unused?
49 m_pBarcodeEngine->RenderDevice(pGraphics->GetRenderDevice(), matrix);
50 return;
51 }
52 CFWL_Edit::DrawWidget(pGraphics, matrix);
53}
54
55void CFWL_Barcode::SetType(BC_TYPE type) {
56 if (m_type == type)
57 return;
58
59 m_pBarcodeEngine.reset();
60 m_type = type;
61 m_eStatus = Status::kNeedUpdate;
62}
63
64void CFWL_Barcode::SetText(const WideString& wsText) {
65 m_pBarcodeEngine.reset();
66 m_eStatus = Status::kNeedUpdate;
67 CFWL_Edit::SetText(wsText);
68}
69
70void CFWL_Barcode::SetTextSkipNotify(const WideString& wsText) {
71 m_pBarcodeEngine.reset();
72 m_eStatus = Status::kNeedUpdate;
74}
75
76bool CFWL_Barcode::IsProtectedType() const {
77 if (!m_pBarcodeEngine)
78 return true;
79
80 BC_TYPE tEngineType = m_pBarcodeEngine->GetType();
81 return tEngineType == BC_TYPE::kQRCode || tEngineType == BC_TYPE::kPDF417 ||
82 tEngineType == BC_TYPE::kDataMatrix;
83}
84
85void CFWL_Barcode::OnProcessEvent(CFWL_Event* pEvent) {
87 m_pBarcodeEngine.reset();
88 m_eStatus = Status::kNeedUpdate;
89 }
91}
92
93void CFWL_Barcode::SetCharEncoding(BC_CHAR_ENCODING encoding) {
94 m_eCharEncoding = encoding;
95}
96
97void CFWL_Barcode::SetModuleHeight(int32_t height) {
98 m_nModuleHeight = height;
99}
100
101void CFWL_Barcode::SetModuleWidth(int32_t width) {
102 m_nModuleWidth = width;
103}
104
105void CFWL_Barcode::SetDataLength(int32_t dataLength) {
106 m_nDataLength = dataLength;
107 SetLimit(dataLength);
108}
109
110void CFWL_Barcode::SetCalChecksum(bool calChecksum) {
111 m_bCalChecksum = calChecksum;
112}
113
114void CFWL_Barcode::SetPrintChecksum(bool printChecksum) {
115 m_bPrintChecksum = printChecksum;
116}
117
118void CFWL_Barcode::SetTextLocation(BC_TEXT_LOC location) {
119 m_eTextLocation = location;
120}
121
122void CFWL_Barcode::SetWideNarrowRatio(int8_t ratio) {
123 m_nWideNarrowRatio = ratio;
124}
125
126void CFWL_Barcode::SetStartChar(char startChar) {
127 m_cStartChar = startChar;
128}
129
130void CFWL_Barcode::SetEndChar(char endChar) {
131 m_cEndChar = endChar;
132}
133
134void CFWL_Barcode::SetErrorCorrectionLevel(int32_t ecLevel) {
135 m_nECLevel = ecLevel;
136}
137
138void CFWL_Barcode::GenerateBarcodeImageCache() {
139 if (m_eStatus != Status::kNeedUpdate)
140 return;
141
142 m_eStatus = Status::kNormal;
143 CreateBarcodeEngine();
144 if (!m_pBarcodeEngine)
145 return;
146
149 if (RetainPtr<CFGAS_GEFont> pFont = pTheme->GetFont(part)) {
150 if (CFX_Font* pCXFont = pFont->GetDevFont())
151 m_pBarcodeEngine->SetFont(pCXFont);
152 }
153 m_pBarcodeEngine->SetFontSize(pTheme->GetFontSize(part));
154 m_pBarcodeEngine->SetFontColor(pTheme->GetTextColor(part));
155 m_pBarcodeEngine->SetHeight(int32_t(GetRTClient().height));
156 m_pBarcodeEngine->SetWidth(int32_t(GetRTClient().width));
157 if (m_eCharEncoding.has_value())
158 m_pBarcodeEngine->SetCharEncoding(m_eCharEncoding.value());
159 if (m_nModuleHeight.has_value())
160 m_pBarcodeEngine->SetModuleHeight(m_nModuleHeight.value());
161 if (m_nModuleWidth.has_value())
162 m_pBarcodeEngine->SetModuleWidth(m_nModuleWidth.value());
163 if (m_nDataLength.has_value())
164 m_pBarcodeEngine->SetDataLength(m_nDataLength.value());
165 if (m_bCalChecksum.has_value())
166 m_pBarcodeEngine->SetCalChecksum(m_bCalChecksum.value());
167 if (m_bPrintChecksum.has_value())
168 m_pBarcodeEngine->SetPrintChecksum(m_bPrintChecksum.value());
169 if (m_eTextLocation.has_value())
170 m_pBarcodeEngine->SetTextLocation(m_eTextLocation.value());
171 if (m_nWideNarrowRatio.has_value())
172 m_pBarcodeEngine->SetWideNarrowRatio(m_nWideNarrowRatio.value());
173 if (m_cStartChar.has_value())
174 m_pBarcodeEngine->SetStartChar(m_cStartChar.value());
175 if (m_cEndChar.has_value())
176 m_pBarcodeEngine->SetEndChar(m_cEndChar.value());
177 if (m_nECLevel.has_value())
178 m_pBarcodeEngine->SetErrorCorrectionLevel(m_nECLevel.value());
179
180 m_eStatus = m_pBarcodeEngine->Encode(GetText().AsStringView())
181 ? Status::kEncodeSuccess
182 : Status::kNormal;
183}
184
185void CFWL_Barcode::CreateBarcodeEngine() {
186 if (m_pBarcodeEngine || m_type == BC_TYPE::kUnknown)
187 return;
188
189 m_pBarcodeEngine = CFX_Barcode::Create(m_type);
190}
BC_TEXT_LOC
Definition BC_Library.h:12
BC_TYPE
Definition BC_Library.h:25
BC_CHAR_ENCODING
Definition BC_Library.h:20
FWL_Type
Definition cfwl_widget.h:46
#define FWL_STATE_WGT_Focused
Definition cfwl_widget.h:42
void SetDataLength(int32_t dataLength)
FWL_Type GetClassID() const override
void SetType(BC_TYPE type)
void SetCalChecksum(bool calChecksum)
void SetWideNarrowRatio(int8_t ratio)
~CFWL_Barcode() override
void OnProcessEvent(CFWL_Event *pEvent) override
void Update() override
void DrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
void SetPrintChecksum(bool printChecksum)
void SetTextLocation(BC_TEXT_LOC location)
void SetStartChar(char startChar)
void SetText(const WideString &wsText) override
void SetEndChar(char endChar)
void SetModuleHeight(int32_t height)
void SetErrorCorrectionLevel(int32_t ecLevel)
void SetTextSkipNotify(const WideString &wsText) override
void SetModuleWidth(int32_t width)
bool IsProtectedType() const
void SetCharEncoding(BC_CHAR_ENCODING encoding)
virtual void SetText(const WideString &wsText)
void SetLimit(int32_t nLimit)
const CFX_RectF & GetRTClient() const
Definition cfwl_edit.h:105
void DrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
CFWL_Edit(CFWL_App *app, const Properties &properties, CFWL_Widget *pOuter)
Definition cfwl_edit.cpp:50
void Update() override
void OnProcessEvent(CFWL_Event *pEvent) override
virtual void SetTextSkipNotify(const WideString &wsText)
Type GetType() const
Definition cfwl_event.h:39
Properties m_Properties
IFWL_ThemeProvider * GetThemeProvider() const
bool IsLocked() const
void Concat(const CFX_Matrix &right)