OLD | NEW |
| (Empty) |
1 // 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 | |
7 #include "xfa/fwl/core/ifwl_barcode.h" | |
8 | |
9 #include <utility> | |
10 | |
11 #include "third_party/base/ptr_util.h" | |
12 #include "xfa/fgas/font/cfgas_gefont.h" | |
13 #include "xfa/fwl/core/cfwl_notedriver.h" | |
14 #include "xfa/fwl/core/cfwl_themepart.h" | |
15 #include "xfa/fwl/core/cfx_barcode.h" | |
16 #include "xfa/fwl/core/ifwl_themeprovider.h" | |
17 | |
18 IFWL_Barcode::IFWL_Barcode(const CFWL_App* app, | |
19 std::unique_ptr<CFWL_WidgetProperties> properties) | |
20 : IFWL_Edit(app, std::move(properties), nullptr), | |
21 m_dwStatus(0), | |
22 m_type(BC_UNKNOWN) {} | |
23 | |
24 IFWL_Barcode::~IFWL_Barcode() {} | |
25 | |
26 FWL_Type IFWL_Barcode::GetClassID() const { | |
27 return FWL_Type::Barcode; | |
28 } | |
29 | |
30 void IFWL_Barcode::Update() { | |
31 if (IsLocked()) | |
32 return; | |
33 | |
34 IFWL_Edit::Update(); | |
35 GenerateBarcodeImageCache(); | |
36 } | |
37 | |
38 void IFWL_Barcode::DrawWidget(CFX_Graphics* pGraphics, | |
39 const CFX_Matrix* pMatrix) { | |
40 if (!pGraphics) | |
41 return; | |
42 if (!m_pProperties->m_pThemeProvider) | |
43 return; | |
44 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { | |
45 GenerateBarcodeImageCache(); | |
46 if (!m_pBarcodeEngine || (m_dwStatus & XFA_BCS_EncodeSuccess) == 0) | |
47 return; | |
48 | |
49 CFX_Matrix mt; | |
50 mt.e = GetRTClient().left; | |
51 mt.f = GetRTClient().top; | |
52 if (pMatrix) | |
53 mt.Concat(*pMatrix); | |
54 | |
55 int32_t errorCode = 0; | |
56 m_pBarcodeEngine->RenderDevice(pGraphics->GetRenderDevice(), pMatrix, | |
57 errorCode); | |
58 return; | |
59 } | |
60 IFWL_Edit::DrawWidget(pGraphics, pMatrix); | |
61 } | |
62 | |
63 void IFWL_Barcode::GenerateBarcodeImageCache() { | |
64 if ((m_dwStatus & XFA_BCS_NeedUpdate) == 0) | |
65 return; | |
66 | |
67 m_dwStatus = 0; | |
68 CreateBarcodeEngine(); | |
69 if (!m_pBarcodeEngine) | |
70 return; | |
71 | |
72 CFX_WideString wsText; | |
73 GetText(wsText); | |
74 | |
75 CFWL_ThemePart part; | |
76 part.m_pWidget = this; | |
77 | |
78 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); | |
79 CFGAS_GEFont* pFont = static_cast<CFGAS_GEFont*>( | |
80 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Font)); | |
81 CFX_Font* pCXFont = pFont ? pFont->GetDevFont() : nullptr; | |
82 if (pCXFont) | |
83 m_pBarcodeEngine->SetFont(pCXFont); | |
84 | |
85 FX_FLOAT* pFontSize = static_cast<FX_FLOAT*>( | |
86 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::FontSize)); | |
87 if (pFontSize) | |
88 m_pBarcodeEngine->SetFontSize(*pFontSize); | |
89 | |
90 FX_ARGB* pFontColor = static_cast<FX_ARGB*>( | |
91 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TextColor)); | |
92 if (pFontColor) | |
93 m_pBarcodeEngine->SetFontColor(*pFontColor); | |
94 | |
95 m_pBarcodeEngine->SetHeight(int32_t(GetRTClient().height)); | |
96 m_pBarcodeEngine->SetWidth(int32_t(GetRTClient().width)); | |
97 uint32_t dwAttributeMask = m_pDataProvider->GetBarcodeAttributeMask(); | |
98 if (dwAttributeMask & FWL_BCDATTRIBUTE_CHARENCODING) | |
99 m_pBarcodeEngine->SetCharEncoding(m_pDataProvider->GetCharEncoding()); | |
100 if (dwAttributeMask & FWL_BCDATTRIBUTE_MODULEHEIGHT) | |
101 m_pBarcodeEngine->SetModuleHeight(m_pDataProvider->GetModuleHeight()); | |
102 if (dwAttributeMask & FWL_BCDATTRIBUTE_MODULEWIDTH) | |
103 m_pBarcodeEngine->SetModuleWidth(m_pDataProvider->GetModuleWidth()); | |
104 if (dwAttributeMask & FWL_BCDATTRIBUTE_DATALENGTH) | |
105 m_pBarcodeEngine->SetDataLength(m_pDataProvider->GetDataLength()); | |
106 if (dwAttributeMask & FWL_BCDATTRIBUTE_CALCHECKSUM) | |
107 m_pBarcodeEngine->SetCalChecksum(m_pDataProvider->GetCalChecksum()); | |
108 if (dwAttributeMask & FWL_BCDATTRIBUTE_PRINTCHECKSUM) | |
109 m_pBarcodeEngine->SetPrintChecksum(m_pDataProvider->GetPrintChecksum()); | |
110 if (dwAttributeMask & FWL_BCDATTRIBUTE_TEXTLOCATION) | |
111 m_pBarcodeEngine->SetTextLocation(m_pDataProvider->GetTextLocation()); | |
112 if (dwAttributeMask & FWL_BCDATTRIBUTE_WIDENARROWRATIO) | |
113 m_pBarcodeEngine->SetWideNarrowRatio(m_pDataProvider->GetWideNarrowRatio()); | |
114 if (dwAttributeMask & FWL_BCDATTRIBUTE_STARTCHAR) | |
115 m_pBarcodeEngine->SetStartChar(m_pDataProvider->GetStartChar()); | |
116 if (dwAttributeMask & FWL_BCDATTRIBUTE_ENDCHAR) | |
117 m_pBarcodeEngine->SetEndChar(m_pDataProvider->GetEndChar()); | |
118 if (dwAttributeMask & FWL_BCDATTRIBUTE_VERSION) | |
119 m_pBarcodeEngine->SetVersion(m_pDataProvider->GetVersion()); | |
120 if (dwAttributeMask & FWL_BCDATTRIBUTE_ECLEVEL) { | |
121 m_pBarcodeEngine->SetErrorCorrectionLevel( | |
122 m_pDataProvider->GetErrorCorrectionLevel()); | |
123 } | |
124 if (dwAttributeMask & FWL_BCDATTRIBUTE_TRUNCATED) | |
125 m_pBarcodeEngine->SetTruncated(m_pDataProvider->GetTruncated()); | |
126 | |
127 int32_t errorCode = 0; | |
128 m_dwStatus = m_pBarcodeEngine->Encode(wsText.AsStringC(), true, errorCode) | |
129 ? XFA_BCS_EncodeSuccess | |
130 : 0; | |
131 } | |
132 | |
133 void IFWL_Barcode::CreateBarcodeEngine() { | |
134 if (m_pBarcodeEngine || m_type == BC_UNKNOWN) | |
135 return; | |
136 | |
137 std::unique_ptr<CFX_Barcode> pBarcode(new CFX_Barcode); | |
138 if (pBarcode->Create(m_type)) | |
139 m_pBarcodeEngine = std::move(pBarcode); | |
140 } | |
141 | |
142 void IFWL_Barcode::SetType(BC_TYPE type) { | |
143 if (m_type == type) | |
144 return; | |
145 | |
146 m_pBarcodeEngine.reset(); | |
147 m_type = type; | |
148 m_dwStatus = XFA_BCS_NeedUpdate; | |
149 } | |
150 | |
151 void IFWL_Barcode::SetText(const CFX_WideString& wsText) { | |
152 m_pBarcodeEngine.reset(); | |
153 m_dwStatus = XFA_BCS_NeedUpdate; | |
154 IFWL_Edit::SetText(wsText); | |
155 } | |
156 | |
157 bool IFWL_Barcode::IsProtectedType() const { | |
158 if (!m_pBarcodeEngine) | |
159 return true; | |
160 | |
161 BC_TYPE tEngineType = m_pBarcodeEngine->GetType(); | |
162 if (tEngineType == BC_QR_CODE || tEngineType == BC_PDF417 || | |
163 tEngineType == BC_DATAMATRIX) { | |
164 return true; | |
165 } | |
166 return false; | |
167 } | |
168 | |
169 void IFWL_Barcode::OnProcessEvent(CFWL_Event* pEvent) { | |
170 if (pEvent->GetClassID() == CFWL_EventType::TextChanged) { | |
171 m_pBarcodeEngine.reset(); | |
172 m_dwStatus = XFA_BCS_NeedUpdate; | |
173 } | |
174 IFWL_Edit::OnProcessEvent(pEvent); | |
175 } | |
OLD | NEW |