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