blob: 0412b86958b1e24a70012f8e1f9f0fadacaf61fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "xfa/fwl/cfwl_barcode.h"
#include <utility>
#include "third_party/base/ptr_util.h"
#include "xfa/fgas/font/cfgas_gefont.h"
#include "xfa/fwl/cfwl_notedriver.h"
#include "xfa/fwl/cfwl_themepart.h"
#include "xfa/fwl/cfx_barcode.h"
#include "xfa/fwl/ifwl_themeprovider.h"
CFWL_Barcode::CFWL_Barcode(const CFWL_App* app)
: CFWL_Edit(app, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr),
m_dwStatus(0),
m_type(BC_UNKNOWN),
m_dwAttributeMask(FWL_BCDATTRIBUTE_NONE) {}
CFWL_Barcode::~CFWL_Barcode() {}
FWL_Type CFWL_Barcode::GetClassID() const {
return FWL_Type::Barcode;
}
void CFWL_Barcode::Update() {
if (IsLocked())
return;
CFWL_Edit::Update();
GenerateBarcodeImageCache();
}
void CFWL_Barcode::DrawWidget(CFX_Graphics* pGraphics,
const CFX_Matrix* pMatrix) {
if (!pGraphics)
return;
if (!m_pProperties->m_pThemeProvider)
return;
if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) {
GenerateBarcodeImageCache();
if (!m_pBarcodeEngine || (m_dwStatus & XFA_BCS_EncodeSuccess) == 0)
return;
CFX_Matrix mt;
mt.e = GetRTClient().left;
mt.f = GetRTClient().top;
if (pMatrix)
mt.Concat(*pMatrix);
int32_t errorCode = 0;
m_pBarcodeEngine->RenderDevice(pGraphics->GetRenderDevice(), pMatrix,
errorCode);
return;
}
CFWL_Edit::DrawWidget(pGraphics, pMatrix);
}
void CFWL_Barcode::SetType(BC_TYPE type) {
if (m_type == type)
return;
m_pBarcodeEngine.reset();
m_type = type;
m_dwStatus = XFA_BCS_NeedUpdate;
}
void CFWL_Barcode::SetText(const CFX_WideString& wsText) {
m_pBarcodeEngine.reset();
m_dwStatus = XFA_BCS_NeedUpdate;
CFWL_Edit::SetText(wsText);
}
bool CFWL_Barcode::IsProtectedType() const {
if (!m_pBarcodeEngine)
return true;
BC_TYPE tEngineType = m_pBarcodeEngine->GetType();
if (tEngineType == BC_QR_CODE || tEngineType == BC_PDF417 ||
tEngineType == BC_DATAMATRIX) {
return true;
}
return false;
}
void CFWL_Barcode::OnProcessEvent(CFWL_Event* pEvent) {
if (pEvent->GetType() == CFWL_Event::Type::TextChanged) {
m_pBarcodeEngine.reset();
m_dwStatus = XFA_BCS_NeedUpdate;
}
CFWL_Edit::OnProcessEvent(pEvent);
}
void CFWL_Barcode::SetCharEncoding(BC_CHAR_ENCODING encoding) {
m_dwAttributeMask |= FWL_BCDATTRIBUTE_CHARENCODING;
m_eCharEncoding = encoding;
}
void CFWL_Barcode::SetModuleHeight(int32_t height) {
m_dwAttributeMask |= FWL_BCDATTRIBUTE_MODULEHEIGHT;
m_nModuleHeight = height;
}
void CFWL_Barcode::SetModuleWidth(int32_t width) {
m_dwAttributeMask |= FWL_BCDATTRIBUTE_MODULEWIDTH;
m_nModuleWidth = width;
}
void CFWL_Barcode::SetDataLength(int32_t dataLength) {
m_dwAttributeMask |= FWL_BCDATTRIBUTE_DATALENGTH;
m_nDataLength = dataLength;
SetLimit(dataLength);
}
void CFWL_Barcode::SetCalChecksum(bool calChecksum) {
m_dwAttributeMask |= FWL_BCDATTRIBUTE_CALCHECKSUM;
m_bCalChecksum = calChecksum;
}
void CFWL_Barcode::SetPrintChecksum(bool printChecksum) {
m_dwAttributeMask |= FWL_BCDATTRIBUTE_PRINTCHECKSUM;
m_bPrintChecksum = printChecksum;
}
void CFWL_Barcode::SetTextLocation(BC_TEXT_LOC location) {
m_dwAttributeMask |= FWL_BCDATTRIBUTE_TEXTLOCATION;
m_eTextLocation = location;
}
void CFWL_Barcode::SetWideNarrowRatio(int32_t ratio) {
m_dwAttributeMask |= FWL_BCDATTRIBUTE_WIDENARROWRATIO;
m_nWideNarrowRatio = ratio;
}
void CFWL_Barcode::SetStartChar(FX_CHAR startChar) {
m_dwAttributeMask |= FWL_BCDATTRIBUTE_STARTCHAR;
m_cStartChar = startChar;
}
void CFWL_Barcode::SetEndChar(FX_CHAR endChar) {
m_dwAttributeMask |= FWL_BCDATTRIBUTE_ENDCHAR;
m_cEndChar = endChar;
}
void CFWL_Barcode::SetErrorCorrectionLevel(int32_t ecLevel) {
m_dwAttributeMask |= FWL_BCDATTRIBUTE_ECLEVEL;
m_nECLevel = ecLevel;
}
void CFWL_Barcode::SetTruncated(bool truncated) {
m_dwAttributeMask |= FWL_BCDATTRIBUTE_TRUNCATED;
m_bTruncated = truncated;
}
void CFWL_Barcode::GenerateBarcodeImageCache() {
if ((m_dwStatus & XFA_BCS_NeedUpdate) == 0)
return;
m_dwStatus = 0;
CreateBarcodeEngine();
if (!m_pBarcodeEngine)
return;
IFWL_ThemeProvider* pTheme = GetAvailableTheme();
if (pTheme) {
CFWL_ThemePart part;
part.m_pWidget = this;
if (CFX_RetainPtr<CFGAS_GEFont> pFont = pTheme->GetFont(&part)) {
if (CFX_Font* pCXFont = pFont->GetDevFont())
m_pBarcodeEngine->SetFont(pCXFont);
}
m_pBarcodeEngine->SetFontSize(pTheme->GetFontSize(&part));
m_pBarcodeEngine->SetFontColor(pTheme->GetTextColor(&part));
} else {
m_pBarcodeEngine->SetFontSize(FWLTHEME_CAPACITY_FontSize);
}
m_pBarcodeEngine->SetHeight(int32_t(GetRTClient().height));
m_pBarcodeEngine->SetWidth(int32_t(GetRTClient().width));
if (m_dwAttributeMask & FWL_BCDATTRIBUTE_CHARENCODING)
m_pBarcodeEngine->SetCharEncoding(m_eCharEncoding);
if (m_dwAttributeMask & FWL_BCDATTRIBUTE_MODULEHEIGHT)
m_pBarcodeEngine->SetModuleHeight(m_nModuleHeight);
if (m_dwAttributeMask & FWL_BCDATTRIBUTE_MODULEWIDTH)
m_pBarcodeEngine->SetModuleWidth(m_nModuleWidth);
if (m_dwAttributeMask & FWL_BCDATTRIBUTE_DATALENGTH)
m_pBarcodeEngine->SetDataLength(m_nDataLength);
if (m_dwAttributeMask & FWL_BCDATTRIBUTE_CALCHECKSUM)
m_pBarcodeEngine->SetCalChecksum(m_bCalChecksum);
if (m_dwAttributeMask & FWL_BCDATTRIBUTE_PRINTCHECKSUM)
m_pBarcodeEngine->SetPrintChecksum(m_bPrintChecksum);
if (m_dwAttributeMask & FWL_BCDATTRIBUTE_TEXTLOCATION)
m_pBarcodeEngine->SetTextLocation(m_eTextLocation);
if (m_dwAttributeMask & FWL_BCDATTRIBUTE_WIDENARROWRATIO)
m_pBarcodeEngine->SetWideNarrowRatio(m_nWideNarrowRatio);
if (m_dwAttributeMask & FWL_BCDATTRIBUTE_STARTCHAR)
m_pBarcodeEngine->SetStartChar(m_cStartChar);
if (m_dwAttributeMask & FWL_BCDATTRIBUTE_ENDCHAR)
m_pBarcodeEngine->SetEndChar(m_cEndChar);
if (m_dwAttributeMask & FWL_BCDATTRIBUTE_VERSION)
m_pBarcodeEngine->SetVersion(0);
if (m_dwAttributeMask & FWL_BCDATTRIBUTE_ECLEVEL)
m_pBarcodeEngine->SetErrorCorrectionLevel(m_nECLevel);
if (m_dwAttributeMask & FWL_BCDATTRIBUTE_TRUNCATED)
m_pBarcodeEngine->SetTruncated(m_bTruncated);
int32_t errorCode = 0;
m_dwStatus = m_pBarcodeEngine->Encode(GetText().AsStringC(), true, errorCode)
? XFA_BCS_EncodeSuccess
: 0;
}
void CFWL_Barcode::CreateBarcodeEngine() {
if (m_pBarcodeEngine || m_type == BC_UNKNOWN)
return;
std::unique_ptr<CFX_Barcode> pBarcode(new CFX_Barcode);
if (pBarcode->Create(m_type))
m_pBarcodeEngine = std::move(pBarcode);
}
|