From ef55c79650768a731c22038acd36b2a741706ed6 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 9 Jan 2018 10:47:23 -0500 Subject: Move barcode code from WidgetAcc to Node This CL moves the barcode related code from CXFA_WidgetAcc to CXFA_Node. Change-Id: Id3f5f30222535a69a0bf4d59416e57d452c7d8e8 Reviewed-on: https://pdfium-review.googlesource.com/22551 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- xfa/fxfa/cxfa_ffbarcode.cpp | 48 +++++++------ xfa/fxfa/cxfa_ffbarcode.h | 2 +- xfa/fxfa/cxfa_fftextedit.cpp | 6 +- xfa/fxfa/cxfa_widgetacc.cpp | 145 --------------------------------------- xfa/fxfa/cxfa_widgetacc.h | 15 ---- xfa/fxfa/parser/cxfa_node.cpp | 156 ++++++++++++++++++++++++++++++++++++++++++ xfa/fxfa/parser/cxfa_node.h | 16 +++++ 7 files changed, 198 insertions(+), 190 deletions(-) (limited to 'xfa/fxfa') diff --git a/xfa/fxfa/cxfa_ffbarcode.cpp b/xfa/fxfa/cxfa_ffbarcode.cpp index c18344f3d4..005fe402fb 100644 --- a/xfa/fxfa/cxfa_ffbarcode.cpp +++ b/xfa/fxfa/cxfa_ffbarcode.cpp @@ -96,16 +96,16 @@ const BarCodeInfo g_BarCodeData[] = { // static const BarCodeInfo* CXFA_FFBarcode::GetBarcodeTypeByName( - const WideStringView& wsName) { + const WideString& wsName) { if (wsName.IsEmpty()) return nullptr; auto* it = std::lower_bound( std::begin(g_BarCodeData), std::end(g_BarCodeData), - FX_HashCode_GetW(wsName, true), + FX_HashCode_GetW(wsName.AsStringView(), true), [](const BarCodeInfo& arg, uint32_t hash) { return arg.uHash < hash; }); - if (it != std::end(g_BarCodeData) && wsName == it->pName) + if (it != std::end(g_BarCodeData) && wsName.AsStringView() == it->pName) return it; return nullptr; @@ -158,68 +158,66 @@ void CXFA_FFBarcode::RenderWidget(CXFA_Graphics* pGS, void CXFA_FFBarcode::UpdateWidgetProperty() { CXFA_FFTextEdit::UpdateWidgetProperty(); - auto* pBarCodeWidget = static_cast(m_pNormalWidget.get()); - WideString wsType = GetNode()->GetWidgetAcc()->GetBarcodeType(); - const BarCodeInfo* pBarcodeInfo = GetBarcodeTypeByName(wsType.AsStringView()); - if (!pBarcodeInfo) + auto* node = GetNode()->GetWidgetAcc()->GetNode(); + const BarCodeInfo* info = GetBarcodeTypeByName(node->GetBarcodeType()); + if (!info) return; - pBarCodeWidget->SetType(pBarcodeInfo->eBCType); + auto* pBarCodeWidget = static_cast(m_pNormalWidget.get()); + pBarCodeWidget->SetType(info->eBCType); - CXFA_WidgetAcc* pAcc = GetNode()->GetWidgetAcc(); Optional encoding = - pAcc->GetBarcodeAttribute_CharEncoding(); + node->GetBarcodeAttribute_CharEncoding(); if (encoding) pBarCodeWidget->SetCharEncoding(*encoding); - Optional calcChecksum = pAcc->GetBarcodeAttribute_Checksum(); + Optional calcChecksum = node->GetBarcodeAttribute_Checksum(); if (calcChecksum) pBarCodeWidget->SetCalChecksum(*calcChecksum); - Optional dataLen = pAcc->GetBarcodeAttribute_DataLength(); + Optional dataLen = node->GetBarcodeAttribute_DataLength(); if (dataLen) pBarCodeWidget->SetDataLength(*dataLen); - Optional startChar = pAcc->GetBarcodeAttribute_StartChar(); + Optional startChar = node->GetBarcodeAttribute_StartChar(); if (startChar) pBarCodeWidget->SetStartChar(*startChar); - Optional endChar = pAcc->GetBarcodeAttribute_EndChar(); + Optional endChar = node->GetBarcodeAttribute_EndChar(); if (endChar) pBarCodeWidget->SetEndChar(*endChar); - Optional ecLevel = pAcc->GetBarcodeAttribute_ECLevel(); + Optional ecLevel = node->GetBarcodeAttribute_ECLevel(); if (ecLevel) pBarCodeWidget->SetErrorCorrectionLevel(*ecLevel); - Optional width = pAcc->GetBarcodeAttribute_ModuleWidth(); + Optional width = node->GetBarcodeAttribute_ModuleWidth(); if (width) pBarCodeWidget->SetModuleWidth(*width); - Optional height = pAcc->GetBarcodeAttribute_ModuleHeight(); + Optional height = node->GetBarcodeAttribute_ModuleHeight(); if (height) pBarCodeWidget->SetModuleHeight(*height); - Optional printCheck = pAcc->GetBarcodeAttribute_PrintChecksum(); + Optional printCheck = node->GetBarcodeAttribute_PrintChecksum(); if (printCheck) pBarCodeWidget->SetPrintChecksum(*printCheck); - Optional textLoc = pAcc->GetBarcodeAttribute_TextLocation(); + Optional textLoc = node->GetBarcodeAttribute_TextLocation(); if (textLoc) pBarCodeWidget->SetTextLocation(*textLoc); - Optional truncate = pAcc->GetBarcodeAttribute_Truncate(); + Optional truncate = node->GetBarcodeAttribute_Truncate(); if (truncate) pBarCodeWidget->SetTruncated(*truncate); - Optional ratio = pAcc->GetBarcodeAttribute_WideNarrowRatio(); + Optional ratio = node->GetBarcodeAttribute_WideNarrowRatio(); if (ratio) pBarCodeWidget->SetWideNarrowRatio(*ratio); - if (pBarcodeInfo->eName == BarcodeType::code3Of9 || - pBarcodeInfo->eName == BarcodeType::ean8 || - pBarcodeInfo->eName == BarcodeType::ean13 || - pBarcodeInfo->eName == BarcodeType::upcA) { + if (info->eName == BarcodeType::code3Of9 || + info->eName == BarcodeType::ean8 || info->eName == BarcodeType::ean13 || + info->eName == BarcodeType::upcA) { pBarCodeWidget->SetPrintChecksum(true); } } diff --git a/xfa/fxfa/cxfa_ffbarcode.h b/xfa/fxfa/cxfa_ffbarcode.h index 85140a10bf..93984700da 100644 --- a/xfa/fxfa/cxfa_ffbarcode.h +++ b/xfa/fxfa/cxfa_ffbarcode.h @@ -85,7 +85,7 @@ struct BarCodeInfo { class CXFA_FFBarcode : public CXFA_FFTextEdit { public: - static const BarCodeInfo* GetBarcodeTypeByName(const WideStringView& wsName); + static const BarCodeInfo* GetBarcodeTypeByName(const WideString& wsName); explicit CXFA_FFBarcode(CXFA_Node* pNode); ~CXFA_FFBarcode() override; diff --git a/xfa/fxfa/cxfa_fftextedit.cpp b/xfa/fxfa/cxfa_fftextedit.cpp index 8f84b185ca..706a9a84cf 100644 --- a/xfa/fxfa/cxfa_fftextedit.cpp +++ b/xfa/fxfa/cxfa_fftextedit.cpp @@ -273,10 +273,8 @@ bool CXFA_FFTextEdit::UpdateFWLData() { } } else if (m_pNode->GetWidgetAcc()->GetUIType() == XFA_Element::Barcode) { int32_t nDataLen = 0; - if (eType == XFA_VALUEPICTURE_Edit) { - nDataLen = - m_pNode->GetWidgetAcc()->GetBarcodeAttribute_DataLength().value_or(0); - } + if (eType == XFA_VALUEPICTURE_Edit) + nDataLen = m_pNode->GetBarcodeAttribute_DataLength().value_or(0); pEdit->SetLimit(nDataLen); bUpdate = true; diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp index 870dc53ff9..0531c0fcb0 100644 --- a/xfa/fxfa/cxfa_widgetacc.cpp +++ b/xfa/fxfa/cxfa_widgetacc.cpp @@ -2124,151 +2124,6 @@ Optional CXFA_WidgetAcc::GetNumberOfCells() { return {}; } -WideString CXFA_WidgetAcc::GetBarcodeType() { - CXFA_Node* pUIChild = GetUIChild(); - return pUIChild - ? WideString(pUIChild->JSObject()->GetCData(XFA_Attribute::Type)) - : WideString(); -} - -Optional CXFA_WidgetAcc::GetBarcodeAttribute_CharEncoding() { - Optional wsCharEncoding = - GetUIChild()->JSObject()->TryCData(XFA_Attribute::CharEncoding, true); - if (!wsCharEncoding) - return {}; - if (wsCharEncoding->CompareNoCase(L"UTF-16")) - return {CHAR_ENCODING_UNICODE}; - if (wsCharEncoding->CompareNoCase(L"UTF-8")) - return {CHAR_ENCODING_UTF8}; - return {}; -} - -Optional CXFA_WidgetAcc::GetBarcodeAttribute_Checksum() { - Optional checksum = - GetUIChild()->JSObject()->TryEnum(XFA_Attribute::Checksum, true); - if (!checksum) - return {}; - - switch (*checksum) { - case XFA_AttributeEnum::None: - return {false}; - case XFA_AttributeEnum::Auto: - return {true}; - case XFA_AttributeEnum::Checksum_1mod10: - case XFA_AttributeEnum::Checksum_1mod10_1mod11: - case XFA_AttributeEnum::Checksum_2mod10: - default: - break; - } - return {}; -} - -Optional CXFA_WidgetAcc::GetBarcodeAttribute_DataLength() { - Optional wsDataLength = - GetUIChild()->JSObject()->TryCData(XFA_Attribute::DataLength, true); - if (!wsDataLength) - return {}; - - return {FXSYS_wtoi(wsDataLength->c_str())}; -} - -Optional CXFA_WidgetAcc::GetBarcodeAttribute_StartChar() { - Optional wsStartEndChar = - GetUIChild()->JSObject()->TryCData(XFA_Attribute::StartChar, true); - if (!wsStartEndChar || wsStartEndChar->IsEmpty()) - return {}; - - return {static_cast((*wsStartEndChar)[0])}; -} - -Optional CXFA_WidgetAcc::GetBarcodeAttribute_EndChar() { - Optional wsStartEndChar = - GetUIChild()->JSObject()->TryCData(XFA_Attribute::EndChar, true); - if (!wsStartEndChar || wsStartEndChar->IsEmpty()) - return {}; - - return {static_cast((*wsStartEndChar)[0])}; -} - -Optional CXFA_WidgetAcc::GetBarcodeAttribute_ECLevel() { - Optional wsECLevel = GetUIChild()->JSObject()->TryCData( - XFA_Attribute::ErrorCorrectionLevel, true); - if (!wsECLevel) - return {}; - return {FXSYS_wtoi(wsECLevel->c_str())}; -} - -Optional CXFA_WidgetAcc::GetBarcodeAttribute_ModuleWidth() { - Optional moduleWidthHeight = - GetUIChild()->JSObject()->TryMeasure(XFA_Attribute::ModuleWidth, true); - if (!moduleWidthHeight) - return {}; - - return {static_cast(moduleWidthHeight->ToUnit(XFA_Unit::Pt))}; -} - -Optional CXFA_WidgetAcc::GetBarcodeAttribute_ModuleHeight() { - Optional moduleWidthHeight = - GetUIChild()->JSObject()->TryMeasure(XFA_Attribute::ModuleHeight, true); - if (!moduleWidthHeight) - return {}; - - return {static_cast(moduleWidthHeight->ToUnit(XFA_Unit::Pt))}; -} - -Optional CXFA_WidgetAcc::GetBarcodeAttribute_PrintChecksum() { - return GetUIChild()->JSObject()->TryBoolean(XFA_Attribute::PrintCheckDigit, - true); -} - -Optional CXFA_WidgetAcc::GetBarcodeAttribute_TextLocation() { - Optional textLocation = - GetUIChild()->JSObject()->TryEnum(XFA_Attribute::TextLocation, true); - if (!textLocation) - return {}; - - switch (*textLocation) { - case XFA_AttributeEnum::None: - return {BC_TEXT_LOC_NONE}; - case XFA_AttributeEnum::Above: - return {BC_TEXT_LOC_ABOVE}; - case XFA_AttributeEnum::Below: - return {BC_TEXT_LOC_BELOW}; - case XFA_AttributeEnum::AboveEmbedded: - return {BC_TEXT_LOC_ABOVEEMBED}; - case XFA_AttributeEnum::BelowEmbedded: - return {BC_TEXT_LOC_BELOWEMBED}; - default: - break; - } - return {}; -} - -Optional CXFA_WidgetAcc::GetBarcodeAttribute_Truncate() { - return GetUIChild()->JSObject()->TryBoolean(XFA_Attribute::Truncate, true); -} - -Optional CXFA_WidgetAcc::GetBarcodeAttribute_WideNarrowRatio() { - Optional wsWideNarrowRatio = - GetUIChild()->JSObject()->TryCData(XFA_Attribute::WideNarrowRatio, true); - if (!wsWideNarrowRatio) - return {}; - - Optional ptPos = wsWideNarrowRatio->Find(':'); - if (!ptPos) - return {static_cast(FXSYS_wtoi(wsWideNarrowRatio->c_str()))}; - - int32_t fB = FXSYS_wtoi( - wsWideNarrowRatio->Right(wsWideNarrowRatio->GetLength() - (*ptPos + 1)) - .c_str()); - if (!fB) - return {0}; - - int32_t fA = FXSYS_wtoi(wsWideNarrowRatio->Left(*ptPos).c_str()); - float result = static_cast(fA) / static_cast(fB); - return {static_cast(result)}; -} - WideString CXFA_WidgetAcc::GetPasswordChar() { CXFA_Node* pUIChild = GetUIChild(); return pUIChild ? pUIChild->JSObject()->GetCData(XFA_Attribute::PasswordChar) diff --git a/xfa/fxfa/cxfa_widgetacc.h b/xfa/fxfa/cxfa_widgetacc.h index 6031d9be26..f21ace9d95 100644 --- a/xfa/fxfa/cxfa_widgetacc.h +++ b/xfa/fxfa/cxfa_widgetacc.h @@ -17,7 +17,6 @@ #include "core/fxcrt/retain_ptr.h" #include "core/fxge/dib/cfx_dibitmap.h" #include "core/fxge/fx_dib.h" -#include "fxbarcode/BC_Library.h" #include "xfa/fxfa/fxfa_basic.h" enum XFA_CHECKSTATE { @@ -174,20 +173,6 @@ class CXFA_WidgetAcc { WideString GetFormatDataValue(const WideString& wsValue); WideString NormalizeNumStr(const WideString& wsValue); - WideString GetBarcodeType(); - Optional GetBarcodeAttribute_CharEncoding(); - Optional GetBarcodeAttribute_Checksum(); - Optional GetBarcodeAttribute_DataLength(); - Optional GetBarcodeAttribute_StartChar(); - Optional GetBarcodeAttribute_EndChar(); - Optional GetBarcodeAttribute_ECLevel(); - Optional GetBarcodeAttribute_ModuleWidth(); - Optional GetBarcodeAttribute_ModuleHeight(); - Optional GetBarcodeAttribute_PrintChecksum(); - Optional GetBarcodeAttribute_TextLocation(); - Optional GetBarcodeAttribute_Truncate(); - Optional GetBarcodeAttribute_WideNarrowRatio(); - WideString GetPasswordChar(); std::pair GetMaxChars(); int32_t GetFracDigits(); diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 8c8f0c69f2..1da6f56781 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -2054,3 +2054,159 @@ std::pair CXFA_Node::ExecuteBoolScript( return {iRet, pTmpRetValue->IsBoolean() ? pTmpRetValue->ToBoolean() : false}; } + +WideString CXFA_Node::GetBarcodeType() { + CXFA_Node* pUIChild = GetWidgetAcc()->GetUIChild(); + return pUIChild + ? WideString(pUIChild->JSObject()->GetCData(XFA_Attribute::Type)) + : WideString(); +} + +Optional CXFA_Node::GetBarcodeAttribute_CharEncoding() { + Optional wsCharEncoding = + GetWidgetAcc()->GetUIChild()->JSObject()->TryCData( + XFA_Attribute::CharEncoding, true); + if (!wsCharEncoding) + return {}; + if (wsCharEncoding->CompareNoCase(L"UTF-16")) + return {CHAR_ENCODING_UNICODE}; + if (wsCharEncoding->CompareNoCase(L"UTF-8")) + return {CHAR_ENCODING_UTF8}; + return {}; +} + +Optional CXFA_Node::GetBarcodeAttribute_Checksum() { + Optional checksum = + GetWidgetAcc()->GetUIChild()->JSObject()->TryEnum(XFA_Attribute::Checksum, + true); + if (!checksum) + return {}; + + switch (*checksum) { + case XFA_AttributeEnum::None: + return {false}; + case XFA_AttributeEnum::Auto: + return {true}; + case XFA_AttributeEnum::Checksum_1mod10: + case XFA_AttributeEnum::Checksum_1mod10_1mod11: + case XFA_AttributeEnum::Checksum_2mod10: + default: + break; + } + return {}; +} + +Optional CXFA_Node::GetBarcodeAttribute_DataLength() { + Optional wsDataLength = + GetWidgetAcc()->GetUIChild()->JSObject()->TryCData( + XFA_Attribute::DataLength, true); + if (!wsDataLength) + return {}; + + return {FXSYS_wtoi(wsDataLength->c_str())}; +} + +Optional CXFA_Node::GetBarcodeAttribute_StartChar() { + Optional wsStartEndChar = + GetWidgetAcc()->GetUIChild()->JSObject()->TryCData( + XFA_Attribute::StartChar, true); + if (!wsStartEndChar || wsStartEndChar->IsEmpty()) + return {}; + + return {static_cast((*wsStartEndChar)[0])}; +} + +Optional CXFA_Node::GetBarcodeAttribute_EndChar() { + Optional wsStartEndChar = + GetWidgetAcc()->GetUIChild()->JSObject()->TryCData(XFA_Attribute::EndChar, + true); + if (!wsStartEndChar || wsStartEndChar->IsEmpty()) + return {}; + + return {static_cast((*wsStartEndChar)[0])}; +} + +Optional CXFA_Node::GetBarcodeAttribute_ECLevel() { + Optional wsECLevel = + GetWidgetAcc()->GetUIChild()->JSObject()->TryCData( + XFA_Attribute::ErrorCorrectionLevel, true); + if (!wsECLevel) + return {}; + return {FXSYS_wtoi(wsECLevel->c_str())}; +} + +Optional CXFA_Node::GetBarcodeAttribute_ModuleWidth() { + Optional moduleWidthHeight = + GetWidgetAcc()->GetUIChild()->JSObject()->TryMeasure( + XFA_Attribute::ModuleWidth, true); + if (!moduleWidthHeight) + return {}; + + return {static_cast(moduleWidthHeight->ToUnit(XFA_Unit::Pt))}; +} + +Optional CXFA_Node::GetBarcodeAttribute_ModuleHeight() { + Optional moduleWidthHeight = + GetWidgetAcc()->GetUIChild()->JSObject()->TryMeasure( + XFA_Attribute::ModuleHeight, true); + if (!moduleWidthHeight) + return {}; + + return {static_cast(moduleWidthHeight->ToUnit(XFA_Unit::Pt))}; +} + +Optional CXFA_Node::GetBarcodeAttribute_PrintChecksum() { + return GetWidgetAcc()->GetUIChild()->JSObject()->TryBoolean( + XFA_Attribute::PrintCheckDigit, true); +} + +Optional CXFA_Node::GetBarcodeAttribute_TextLocation() { + Optional textLocation = + GetWidgetAcc()->GetUIChild()->JSObject()->TryEnum( + XFA_Attribute::TextLocation, true); + if (!textLocation) + return {}; + + switch (*textLocation) { + case XFA_AttributeEnum::None: + return {BC_TEXT_LOC_NONE}; + case XFA_AttributeEnum::Above: + return {BC_TEXT_LOC_ABOVE}; + case XFA_AttributeEnum::Below: + return {BC_TEXT_LOC_BELOW}; + case XFA_AttributeEnum::AboveEmbedded: + return {BC_TEXT_LOC_ABOVEEMBED}; + case XFA_AttributeEnum::BelowEmbedded: + return {BC_TEXT_LOC_BELOWEMBED}; + default: + break; + } + return {}; +} + +Optional CXFA_Node::GetBarcodeAttribute_Truncate() { + return GetWidgetAcc()->GetUIChild()->JSObject()->TryBoolean( + XFA_Attribute::Truncate, true); +} + +Optional CXFA_Node::GetBarcodeAttribute_WideNarrowRatio() { + Optional wsWideNarrowRatio = + GetWidgetAcc()->GetUIChild()->JSObject()->TryCData( + XFA_Attribute::WideNarrowRatio, true); + if (!wsWideNarrowRatio) + return {}; + + Optional ptPos = wsWideNarrowRatio->Find(':'); + if (!ptPos) + return {static_cast(FXSYS_wtoi(wsWideNarrowRatio->c_str()))}; + + int32_t fB = FXSYS_wtoi( + wsWideNarrowRatio->Right(wsWideNarrowRatio->GetLength() - (*ptPos + 1)) + .c_str()); + if (!fB) + return {0}; + + int32_t fA = FXSYS_wtoi(wsWideNarrowRatio->Left(*ptPos).c_str()); + float result = static_cast(fA) / static_cast(fB); + return {static_cast(result)}; +} diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h index 7bf0654b58..1f11a2372f 100644 --- a/xfa/fxfa/parser/cxfa_node.h +++ b/xfa/fxfa/parser/cxfa_node.h @@ -15,6 +15,7 @@ #include "core/fxcrt/fx_string.h" #include "core/fxcrt/ifx_locale.h" #include "core/fxge/fx_dib.h" +#include "fxbarcode/BC_Library.h" #include "fxjs/xfa/cjx_node.h" #include "third_party/base/optional.h" #include "xfa/fxfa/parser/cxfa_object.h" @@ -279,6 +280,21 @@ class CXFA_Node : public CXFA_Object { CXFA_Script* script, CXFA_EventParam* pEventParam); + // TODO(dsinclair): Figure out how to move this to cxfa_barcode. + WideString GetBarcodeType(); + Optional GetBarcodeAttribute_CharEncoding(); + Optional GetBarcodeAttribute_Checksum(); + Optional GetBarcodeAttribute_DataLength(); + Optional GetBarcodeAttribute_StartChar(); + Optional GetBarcodeAttribute_EndChar(); + Optional GetBarcodeAttribute_ECLevel(); + Optional GetBarcodeAttribute_ModuleWidth(); + Optional GetBarcodeAttribute_ModuleHeight(); + Optional GetBarcodeAttribute_PrintChecksum(); + Optional GetBarcodeAttribute_TextLocation(); + Optional GetBarcodeAttribute_Truncate(); + Optional GetBarcodeAttribute_WideNarrowRatio(); + protected: CXFA_Node(CXFA_Document* pDoc, XFA_PacketType ePacket, -- cgit v1.2.3