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