diff options
Diffstat (limited to 'xfa/fwl/cfwl_barcode.cpp')
-rw-r--r-- | xfa/fwl/cfwl_barcode.cpp | 100 |
1 files changed, 40 insertions, 60 deletions
diff --git a/xfa/fwl/cfwl_barcode.cpp b/xfa/fwl/cfwl_barcode.cpp index 008424d82..1802c7fce 100644 --- a/xfa/fwl/cfwl_barcode.cpp +++ b/xfa/fwl/cfwl_barcode.cpp @@ -1,4 +1,4 @@ -// Copyright 2014 PDFium Authors. All rights reserved. +// Copyright 2014 The PDFium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,18 +6,15 @@ #include "xfa/fwl/cfwl_barcode.h" -#include <utility> - #include "fxbarcode/cfx_barcode.h" -#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/ifwl_themeprovider.h" #include "xfa/fwl/theme/cfwl_utils.h" -CFWL_Barcode::CFWL_Barcode(const CFWL_App* app) - : CFWL_Edit(app, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr) {} +CFWL_Barcode::CFWL_Barcode(CFWL_App* app) + : CFWL_Edit(app, Properties(), nullptr) {} CFWL_Barcode::~CFWL_Barcode() = default; @@ -33,13 +30,12 @@ void CFWL_Barcode::Update() { GenerateBarcodeImageCache(); } -void CFWL_Barcode::DrawWidget(CXFA_Graphics* pGraphics, +void CFWL_Barcode::DrawWidget(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& matrix) { if (!pGraphics) return; - if (!m_pProperties->m_pThemeProvider) - return; - if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { + + if ((m_Properties.m_dwStates & FWL_STATE_WGT_Focused) == 0) { GenerateBarcodeImageCache(); if (!m_pBarcodeEngine || m_eStatus != Status::kEncodeSuccess) return; @@ -49,7 +45,8 @@ void CFWL_Barcode::DrawWidget(CXFA_Graphics* pGraphics, mt.f = GetRTClient().top; mt.Concat(matrix); - m_pBarcodeEngine->RenderDevice(pGraphics->GetRenderDevice(), &matrix); + // TODO(tsepez): Curious as to why |mt| is unused? + m_pBarcodeEngine->RenderDevice(pGraphics->GetRenderDevice(), matrix); return; } CFWL_Edit::DrawWidget(pGraphics, matrix); @@ -81,8 +78,8 @@ bool CFWL_Barcode::IsProtectedType() const { return true; BC_TYPE tEngineType = m_pBarcodeEngine->GetType(); - return tEngineType == BC_QR_CODE || tEngineType == BC_PDF417 || - tEngineType == BC_DATAMATRIX; + return tEngineType == BC_TYPE::kQRCode || tEngineType == BC_TYPE::kPDF417 || + tEngineType == BC_TYPE::kDataMatrix; } void CFWL_Barcode::OnProcessEvent(CFWL_Event* pEvent) { @@ -94,58 +91,47 @@ void CFWL_Barcode::OnProcessEvent(CFWL_Event* 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(int8_t ratio) { - m_dwAttributeMask |= FWL_BCDATTRIBUTE_WIDENARROWRATIO; m_nWideNarrowRatio = ratio; } void CFWL_Barcode::SetStartChar(char startChar) { - m_dwAttributeMask |= FWL_BCDATTRIBUTE_STARTCHAR; m_cStartChar = startChar; } void CFWL_Barcode::SetEndChar(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; } @@ -158,44 +144,38 @@ void CFWL_Barcode::GenerateBarcodeImageCache() { if (!m_pBarcodeEngine) return; - IFWL_ThemeProvider* pTheme = GetAvailableTheme(); - if (pTheme) { - CFWL_ThemePart part; - part.m_pWidget = this; - if (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); + IFWL_ThemeProvider* pTheme = GetThemeProvider(); + CFWL_ThemePart part(CFWL_ThemePart::Part::kNone, this); + if (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)); 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_ECLEVEL) - m_pBarcodeEngine->SetErrorCorrectionLevel(m_nECLevel); + if (m_eCharEncoding.has_value()) + m_pBarcodeEngine->SetCharEncoding(m_eCharEncoding.value()); + if (m_nModuleHeight.has_value()) + m_pBarcodeEngine->SetModuleHeight(m_nModuleHeight.value()); + if (m_nModuleWidth.has_value()) + m_pBarcodeEngine->SetModuleWidth(m_nModuleWidth.value()); + if (m_nDataLength.has_value()) + m_pBarcodeEngine->SetDataLength(m_nDataLength.value()); + if (m_bCalChecksum.has_value()) + m_pBarcodeEngine->SetCalChecksum(m_bCalChecksum.value()); + if (m_bPrintChecksum.has_value()) + m_pBarcodeEngine->SetPrintChecksum(m_bPrintChecksum.value()); + if (m_eTextLocation.has_value()) + m_pBarcodeEngine->SetTextLocation(m_eTextLocation.value()); + if (m_nWideNarrowRatio.has_value()) + m_pBarcodeEngine->SetWideNarrowRatio(m_nWideNarrowRatio.value()); + if (m_cStartChar.has_value()) + m_pBarcodeEngine->SetStartChar(m_cStartChar.value()); + if (m_cEndChar.has_value()) + m_pBarcodeEngine->SetEndChar(m_cEndChar.value()); + if (m_nECLevel.has_value()) + m_pBarcodeEngine->SetErrorCorrectionLevel(m_nECLevel.value()); m_eStatus = m_pBarcodeEngine->Encode(GetText().AsStringView()) ? Status::kEncodeSuccess @@ -203,7 +183,7 @@ void CFWL_Barcode::GenerateBarcodeImageCache() { } void CFWL_Barcode::CreateBarcodeEngine() { - if (m_pBarcodeEngine || m_type == BC_UNKNOWN) + if (m_pBarcodeEngine || m_type == BC_TYPE::kUnknown) return; m_pBarcodeEngine = CFX_Barcode::Create(m_type); |