| 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/cfwl_barcode.h" | 7 #include "xfa/fwl/core/cfwl_barcode.h" |
| 8 | 8 |
| 9 #include <memory> | |
| 10 #include <utility> | 9 #include <utility> |
| 11 | 10 |
| 12 #include "third_party/base/ptr_util.h" | 11 #include "third_party/base/ptr_util.h" |
| 13 | 12 #include "xfa/fgas/font/cfgas_gefont.h" |
| 14 namespace { | 13 #include "xfa/fwl/core/cfwl_notedriver.h" |
| 15 | 14 #include "xfa/fwl/core/cfwl_themepart.h" |
| 16 IFWL_Barcode* ToBarcode(IFWL_Widget* widget) { | 15 #include "xfa/fwl/core/cfx_barcode.h" |
| 17 return static_cast<IFWL_Barcode*>(widget); | 16 #include "xfa/fwl/core/ifwl_themeprovider.h" |
| 18 } | |
| 19 | |
| 20 } // namespace | |
| 21 | 17 |
| 22 CFWL_Barcode::CFWL_Barcode(const CFWL_App* app) | 18 CFWL_Barcode::CFWL_Barcode(const CFWL_App* app) |
| 23 : CFWL_Edit(app), m_dwAttributeMask(FWL_BCDATTRIBUTE_NONE) {} | 19 : CFWL_Edit(app, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr), |
| 20 m_dwStatus(0), |
| 21 m_type(BC_UNKNOWN), |
| 22 m_dwAttributeMask(FWL_BCDATTRIBUTE_NONE) {} |
| 24 | 23 |
| 25 CFWL_Barcode::~CFWL_Barcode() {} | 24 CFWL_Barcode::~CFWL_Barcode() {} |
| 26 | 25 |
| 27 void CFWL_Barcode::Initialize() { | 26 FWL_Type CFWL_Barcode::GetClassID() const { |
| 28 ASSERT(!m_pIface); | 27 return FWL_Type::Barcode; |
| 28 } |
| 29 | 29 |
| 30 auto iface = pdfium::MakeUnique<IFWL_Barcode>( | 30 void CFWL_Barcode::Update() { |
| 31 m_pApp, pdfium::MakeUnique<CFWL_WidgetProperties>()); | 31 if (IsLocked()) |
| 32 iface->SetDataProvider(this); | 32 return; |
| 33 m_pIface = std::move(iface); | |
| 34 | 33 |
| 35 CFWL_Widget::Initialize(); | 34 CFWL_Edit::Update(); |
| 35 GenerateBarcodeImageCache(); |
| 36 } |
| 37 |
| 38 void CFWL_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 CFWL_Edit::DrawWidget(pGraphics, pMatrix); |
| 61 } |
| 62 |
| 63 void CFWL_Barcode::SetType(BC_TYPE type) { |
| 64 if (m_type == type) |
| 65 return; |
| 66 |
| 67 m_pBarcodeEngine.reset(); |
| 68 m_type = type; |
| 69 m_dwStatus = XFA_BCS_NeedUpdate; |
| 70 } |
| 71 |
| 72 void CFWL_Barcode::SetText(const CFX_WideString& wsText) { |
| 73 m_pBarcodeEngine.reset(); |
| 74 m_dwStatus = XFA_BCS_NeedUpdate; |
| 75 CFWL_Edit::SetText(wsText); |
| 76 } |
| 77 |
| 78 bool CFWL_Barcode::IsProtectedType() const { |
| 79 if (!m_pBarcodeEngine) |
| 80 return true; |
| 81 |
| 82 BC_TYPE tEngineType = m_pBarcodeEngine->GetType(); |
| 83 if (tEngineType == BC_QR_CODE || tEngineType == BC_PDF417 || |
| 84 tEngineType == BC_DATAMATRIX) { |
| 85 return true; |
| 86 } |
| 87 return false; |
| 88 } |
| 89 |
| 90 void CFWL_Barcode::OnProcessEvent(CFWL_Event* pEvent) { |
| 91 if (pEvent->GetClassID() == CFWL_EventType::TextChanged) { |
| 92 m_pBarcodeEngine.reset(); |
| 93 m_dwStatus = XFA_BCS_NeedUpdate; |
| 94 } |
| 95 CFWL_Edit::OnProcessEvent(pEvent); |
| 36 } | 96 } |
| 37 | 97 |
| 38 void CFWL_Barcode::SetCharEncoding(BC_CHAR_ENCODING encoding) { | 98 void CFWL_Barcode::SetCharEncoding(BC_CHAR_ENCODING encoding) { |
| 39 m_dwAttributeMask |= FWL_BCDATTRIBUTE_CHARENCODING; | 99 m_dwAttributeMask |= FWL_BCDATTRIBUTE_CHARENCODING; |
| 40 m_eCharEncoding = encoding; | 100 m_eCharEncoding = encoding; |
| 41 } | 101 } |
| 42 | 102 |
| 43 void CFWL_Barcode::SetModuleHeight(int32_t height) { | 103 void CFWL_Barcode::SetModuleHeight(int32_t height) { |
| 44 m_dwAttributeMask |= FWL_BCDATTRIBUTE_MODULEHEIGHT; | 104 m_dwAttributeMask |= FWL_BCDATTRIBUTE_MODULEHEIGHT; |
| 45 m_nModuleHeight = height; | 105 m_nModuleHeight = height; |
| 46 } | 106 } |
| 47 | 107 |
| 48 void CFWL_Barcode::SetModuleWidth(int32_t width) { | 108 void CFWL_Barcode::SetModuleWidth(int32_t width) { |
| 49 m_dwAttributeMask |= FWL_BCDATTRIBUTE_MODULEWIDTH; | 109 m_dwAttributeMask |= FWL_BCDATTRIBUTE_MODULEWIDTH; |
| 50 m_nModuleWidth = width; | 110 m_nModuleWidth = width; |
| 51 } | 111 } |
| 52 | 112 |
| 53 void CFWL_Barcode::SetDataLength(int32_t dataLength) { | 113 void CFWL_Barcode::SetDataLength(int32_t dataLength) { |
| 54 m_dwAttributeMask |= FWL_BCDATTRIBUTE_DATALENGTH; | 114 m_dwAttributeMask |= FWL_BCDATTRIBUTE_DATALENGTH; |
| 55 m_nDataLength = dataLength; | 115 m_nDataLength = dataLength; |
| 56 ToBarcode(GetWidget())->SetLimit(dataLength); | 116 SetLimit(dataLength); |
| 57 } | 117 } |
| 58 | 118 |
| 59 void CFWL_Barcode::SetCalChecksum(bool calChecksum) { | 119 void CFWL_Barcode::SetCalChecksum(bool calChecksum) { |
| 60 m_dwAttributeMask |= FWL_BCDATTRIBUTE_CALCHECKSUM; | 120 m_dwAttributeMask |= FWL_BCDATTRIBUTE_CALCHECKSUM; |
| 61 m_bCalChecksum = calChecksum; | 121 m_bCalChecksum = calChecksum; |
| 62 } | 122 } |
| 63 | 123 |
| 64 void CFWL_Barcode::SetPrintChecksum(bool printChecksum) { | 124 void CFWL_Barcode::SetPrintChecksum(bool printChecksum) { |
| 65 m_dwAttributeMask |= FWL_BCDATTRIBUTE_PRINTCHECKSUM; | 125 m_dwAttributeMask |= FWL_BCDATTRIBUTE_PRINTCHECKSUM; |
| 66 m_bPrintChecksum = printChecksum; | 126 m_bPrintChecksum = printChecksum; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 89 void CFWL_Barcode::SetErrorCorrectionLevel(int32_t ecLevel) { | 149 void CFWL_Barcode::SetErrorCorrectionLevel(int32_t ecLevel) { |
| 90 m_dwAttributeMask |= FWL_BCDATTRIBUTE_ECLEVEL; | 150 m_dwAttributeMask |= FWL_BCDATTRIBUTE_ECLEVEL; |
| 91 m_nECLevel = ecLevel; | 151 m_nECLevel = ecLevel; |
| 92 } | 152 } |
| 93 | 153 |
| 94 void CFWL_Barcode::SetTruncated(bool truncated) { | 154 void CFWL_Barcode::SetTruncated(bool truncated) { |
| 95 m_dwAttributeMask |= FWL_BCDATTRIBUTE_TRUNCATED; | 155 m_dwAttributeMask |= FWL_BCDATTRIBUTE_TRUNCATED; |
| 96 m_bTruncated = truncated; | 156 m_bTruncated = truncated; |
| 97 } | 157 } |
| 98 | 158 |
| 99 void CFWL_Barcode::SetType(BC_TYPE type) { | 159 void CFWL_Barcode::GenerateBarcodeImageCache() { |
| 100 if (GetWidget()) | 160 if ((m_dwStatus & XFA_BCS_NeedUpdate) == 0) |
| 101 ToBarcode(GetWidget())->SetType(type); | 161 return; |
| 162 |
| 163 m_dwStatus = 0; |
| 164 CreateBarcodeEngine(); |
| 165 if (!m_pBarcodeEngine) |
| 166 return; |
| 167 |
| 168 CFX_WideString wsText; |
| 169 GetText(wsText); |
| 170 |
| 171 CFWL_ThemePart part; |
| 172 part.m_pWidget = this; |
| 173 |
| 174 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); |
| 175 CFGAS_GEFont* pFont = static_cast<CFGAS_GEFont*>( |
| 176 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Font)); |
| 177 CFX_Font* pCXFont = pFont ? pFont->GetDevFont() : nullptr; |
| 178 if (pCXFont) |
| 179 m_pBarcodeEngine->SetFont(pCXFont); |
| 180 |
| 181 FX_FLOAT* pFontSize = static_cast<FX_FLOAT*>( |
| 182 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::FontSize)); |
| 183 if (pFontSize) |
| 184 m_pBarcodeEngine->SetFontSize(*pFontSize); |
| 185 |
| 186 FX_ARGB* pFontColor = static_cast<FX_ARGB*>( |
| 187 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TextColor)); |
| 188 if (pFontColor) |
| 189 m_pBarcodeEngine->SetFontColor(*pFontColor); |
| 190 |
| 191 m_pBarcodeEngine->SetHeight(int32_t(GetRTClient().height)); |
| 192 m_pBarcodeEngine->SetWidth(int32_t(GetRTClient().width)); |
| 193 if (m_dwAttributeMask & FWL_BCDATTRIBUTE_CHARENCODING) |
| 194 m_pBarcodeEngine->SetCharEncoding(m_eCharEncoding); |
| 195 if (m_dwAttributeMask & FWL_BCDATTRIBUTE_MODULEHEIGHT) |
| 196 m_pBarcodeEngine->SetModuleHeight(m_nModuleHeight); |
| 197 if (m_dwAttributeMask & FWL_BCDATTRIBUTE_MODULEWIDTH) |
| 198 m_pBarcodeEngine->SetModuleWidth(m_nModuleWidth); |
| 199 if (m_dwAttributeMask & FWL_BCDATTRIBUTE_DATALENGTH) |
| 200 m_pBarcodeEngine->SetDataLength(m_nDataLength); |
| 201 if (m_dwAttributeMask & FWL_BCDATTRIBUTE_CALCHECKSUM) |
| 202 m_pBarcodeEngine->SetCalChecksum(m_bCalChecksum); |
| 203 if (m_dwAttributeMask & FWL_BCDATTRIBUTE_PRINTCHECKSUM) |
| 204 m_pBarcodeEngine->SetPrintChecksum(m_bPrintChecksum); |
| 205 if (m_dwAttributeMask & FWL_BCDATTRIBUTE_TEXTLOCATION) |
| 206 m_pBarcodeEngine->SetTextLocation(m_eTextLocation); |
| 207 if (m_dwAttributeMask & FWL_BCDATTRIBUTE_WIDENARROWRATIO) |
| 208 m_pBarcodeEngine->SetWideNarrowRatio(m_nWideNarrowRatio); |
| 209 if (m_dwAttributeMask & FWL_BCDATTRIBUTE_STARTCHAR) |
| 210 m_pBarcodeEngine->SetStartChar(m_cStartChar); |
| 211 if (m_dwAttributeMask & FWL_BCDATTRIBUTE_ENDCHAR) |
| 212 m_pBarcodeEngine->SetEndChar(m_cEndChar); |
| 213 if (m_dwAttributeMask & FWL_BCDATTRIBUTE_VERSION) |
| 214 m_pBarcodeEngine->SetVersion(0); |
| 215 if (m_dwAttributeMask & FWL_BCDATTRIBUTE_ECLEVEL) |
| 216 m_pBarcodeEngine->SetErrorCorrectionLevel(m_nECLevel); |
| 217 if (m_dwAttributeMask & FWL_BCDATTRIBUTE_TRUNCATED) |
| 218 m_pBarcodeEngine->SetTruncated(m_bTruncated); |
| 219 |
| 220 int32_t errorCode = 0; |
| 221 m_dwStatus = m_pBarcodeEngine->Encode(wsText.AsStringC(), true, errorCode) |
| 222 ? XFA_BCS_EncodeSuccess |
| 223 : 0; |
| 102 } | 224 } |
| 103 | 225 |
| 104 bool CFWL_Barcode::IsProtectedType() { | 226 void CFWL_Barcode::CreateBarcodeEngine() { |
| 105 return GetWidget() ? ToBarcode(GetWidget())->IsProtectedType() : false; | 227 if (m_pBarcodeEngine || m_type == BC_UNKNOWN) |
| 228 return; |
| 229 |
| 230 std::unique_ptr<CFX_Barcode> pBarcode(new CFX_Barcode); |
| 231 if (pBarcode->Create(m_type)) |
| 232 m_pBarcodeEngine = std::move(pBarcode); |
| 106 } | 233 } |
| 107 | |
| 108 BC_CHAR_ENCODING CFWL_Barcode::GetCharEncoding() const { | |
| 109 return m_eCharEncoding; | |
| 110 } | |
| 111 | |
| 112 int32_t CFWL_Barcode::GetModuleHeight() const { | |
| 113 return m_nModuleHeight; | |
| 114 } | |
| 115 | |
| 116 int32_t CFWL_Barcode::GetModuleWidth() const { | |
| 117 return m_nModuleWidth; | |
| 118 } | |
| 119 | |
| 120 int32_t CFWL_Barcode::GetDataLength() const { | |
| 121 return m_nDataLength; | |
| 122 } | |
| 123 | |
| 124 bool CFWL_Barcode::GetCalChecksum() const { | |
| 125 return m_bCalChecksum; | |
| 126 } | |
| 127 | |
| 128 bool CFWL_Barcode::GetPrintChecksum() const { | |
| 129 return m_bPrintChecksum; | |
| 130 } | |
| 131 | |
| 132 BC_TEXT_LOC CFWL_Barcode::GetTextLocation() const { | |
| 133 return m_eTextLocation; | |
| 134 } | |
| 135 | |
| 136 int32_t CFWL_Barcode::GetWideNarrowRatio() const { | |
| 137 return m_nWideNarrowRatio; | |
| 138 } | |
| 139 | |
| 140 FX_CHAR CFWL_Barcode::GetStartChar() const { | |
| 141 return m_cStartChar; | |
| 142 } | |
| 143 | |
| 144 FX_CHAR CFWL_Barcode::GetEndChar() const { | |
| 145 return m_cEndChar; | |
| 146 } | |
| 147 | |
| 148 int32_t CFWL_Barcode::GetVersion() const { | |
| 149 return 0; | |
| 150 } | |
| 151 | |
| 152 int32_t CFWL_Barcode::GetErrorCorrectionLevel() const { | |
| 153 return m_nECLevel; | |
| 154 } | |
| 155 | |
| 156 bool CFWL_Barcode::GetTruncated() const { | |
| 157 return m_bTruncated; | |
| 158 } | |
| 159 | |
| 160 uint32_t CFWL_Barcode::GetBarcodeAttributeMask() const { | |
| 161 return m_dwAttributeMask; | |
| 162 } | |
| OLD | NEW |