diff options
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r-- | xfa/fxfa/parser/cxfa_barcode.cpp | 142 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_barcode.h | 14 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 149 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.h | 15 |
4 files changed, 156 insertions, 164 deletions
diff --git a/xfa/fxfa/parser/cxfa_barcode.cpp b/xfa/fxfa/parser/cxfa_barcode.cpp index 8c77c571f0..9fb7082754 100644 --- a/xfa/fxfa/parser/cxfa_barcode.cpp +++ b/xfa/fxfa/parser/cxfa_barcode.cpp @@ -8,6 +8,7 @@ #include "fxjs/xfa/cjx_barcode.h" #include "third_party/base/ptr_util.h" +#include "xfa/fxfa/parser/cxfa_measurement.h" namespace { @@ -59,3 +60,144 @@ CXFA_Barcode::~CXFA_Barcode() {} XFA_FFWidgetType CXFA_Barcode::GetDefaultFFWidgetType() const { return XFA_FFWidgetType::kBarcode; } + +WideString CXFA_Barcode::GetBarcodeType() { + return WideString(JSObject()->GetCData(XFA_Attribute::Type)); +} + +Optional<BC_CHAR_ENCODING> CXFA_Barcode::GetCharEncoding() { + Optional<WideString> wsCharEncoding = + 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<bool> CXFA_Barcode::GetChecksum() { + Optional<XFA_AttributeEnum> checksum = + 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<int32_t> CXFA_Barcode::GetDataLength() { + Optional<WideString> wsDataLength = + JSObject()->TryCData(XFA_Attribute::DataLength, true); + if (!wsDataLength) + return {}; + + return {FXSYS_wtoi(wsDataLength->c_str())}; +} + +Optional<char> CXFA_Barcode::GetStartChar() { + Optional<WideString> wsStartEndChar = + JSObject()->TryCData(XFA_Attribute::StartChar, true); + if (!wsStartEndChar || wsStartEndChar->IsEmpty()) + return {}; + + return {static_cast<char>((*wsStartEndChar)[0])}; +} + +Optional<char> CXFA_Barcode::GetEndChar() { + Optional<WideString> wsStartEndChar = + JSObject()->TryCData(XFA_Attribute::EndChar, true); + if (!wsStartEndChar || wsStartEndChar->IsEmpty()) + return {}; + + return {static_cast<char>((*wsStartEndChar)[0])}; +} + +Optional<int32_t> CXFA_Barcode::GetECLevel() { + Optional<WideString> wsECLevel = + JSObject()->TryCData(XFA_Attribute::ErrorCorrectionLevel, true); + if (!wsECLevel) + return {}; + return {FXSYS_wtoi(wsECLevel->c_str())}; +} + +Optional<int32_t> CXFA_Barcode::GetModuleWidth() { + Optional<CXFA_Measurement> moduleWidthHeight = + JSObject()->TryMeasure(XFA_Attribute::ModuleWidth, true); + if (!moduleWidthHeight) + return {}; + + return {static_cast<int32_t>(moduleWidthHeight->ToUnit(XFA_Unit::Pt))}; +} + +Optional<int32_t> CXFA_Barcode::GetModuleHeight() { + Optional<CXFA_Measurement> moduleWidthHeight = + JSObject()->TryMeasure(XFA_Attribute::ModuleHeight, true); + if (!moduleWidthHeight) + return {}; + + return {static_cast<int32_t>(moduleWidthHeight->ToUnit(XFA_Unit::Pt))}; +} + +Optional<bool> CXFA_Barcode::GetPrintChecksum() { + return JSObject()->TryBoolean(XFA_Attribute::PrintCheckDigit, true); +} + +Optional<BC_TEXT_LOC> CXFA_Barcode::GetTextLocation() { + Optional<XFA_AttributeEnum> textLocation = + 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<bool> CXFA_Barcode::GetTruncate() { + return JSObject()->TryBoolean(XFA_Attribute::Truncate, true); +} + +Optional<int8_t> CXFA_Barcode::GetWideNarrowRatio() { + Optional<WideString> wsWideNarrowRatio = + JSObject()->TryCData(XFA_Attribute::WideNarrowRatio, true); + if (!wsWideNarrowRatio) + return {}; + + Optional<size_t> ptPos = wsWideNarrowRatio->Find(':'); + if (!ptPos) + return {static_cast<int8_t>(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<float>(fA) / static_cast<float>(fB); + return {static_cast<int8_t>(result)}; +} diff --git a/xfa/fxfa/parser/cxfa_barcode.h b/xfa/fxfa/parser/cxfa_barcode.h index 056196f3ac..0899740424 100644 --- a/xfa/fxfa/parser/cxfa_barcode.h +++ b/xfa/fxfa/parser/cxfa_barcode.h @@ -15,6 +15,20 @@ class CXFA_Barcode : public CXFA_Node { ~CXFA_Barcode() override; XFA_FFWidgetType GetDefaultFFWidgetType() const override; + + WideString GetBarcodeType(); + Optional<BC_CHAR_ENCODING> GetCharEncoding(); + Optional<bool> GetChecksum(); + Optional<int32_t> GetDataLength(); + Optional<char> GetStartChar(); + Optional<char> GetEndChar(); + Optional<int32_t> GetECLevel(); + Optional<int32_t> GetModuleWidth(); + Optional<int32_t> GetModuleHeight(); + Optional<bool> GetPrintChecksum(); + Optional<BC_TEXT_LOC> GetTextLocation(); + Optional<bool> GetTruncate(); + Optional<int8_t> GetWideNarrowRatio(); }; #endif // XFA_FXFA_PARSER_CXFA_BARCODE_H_ diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 5b04700010..2ccdd1d919 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -2371,155 +2371,6 @@ std::pair<int32_t, bool> CXFA_Node::ExecuteBoolScript( return {iRet, pTmpRetValue->IsBoolean() ? pTmpRetValue->ToBoolean() : false}; } -WideString CXFA_Node::GetBarcodeType() { - CXFA_Node* pUIChild = GetUIChildNode(); - return pUIChild - ? WideString(pUIChild->JSObject()->GetCData(XFA_Attribute::Type)) - : WideString(); -} - -Optional<BC_CHAR_ENCODING> CXFA_Node::GetBarcodeAttribute_CharEncoding() { - Optional<WideString> wsCharEncoding = - GetUIChildNode()->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<bool> CXFA_Node::GetBarcodeAttribute_Checksum() { - Optional<XFA_AttributeEnum> checksum = - GetUIChildNode()->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<int32_t> CXFA_Node::GetBarcodeAttribute_DataLength() { - Optional<WideString> wsDataLength = - GetUIChildNode()->JSObject()->TryCData(XFA_Attribute::DataLength, true); - if (!wsDataLength) - return {}; - - return {FXSYS_wtoi(wsDataLength->c_str())}; -} - -Optional<char> CXFA_Node::GetBarcodeAttribute_StartChar() { - Optional<WideString> wsStartEndChar = - GetUIChildNode()->JSObject()->TryCData(XFA_Attribute::StartChar, true); - if (!wsStartEndChar || wsStartEndChar->IsEmpty()) - return {}; - - return {static_cast<char>((*wsStartEndChar)[0])}; -} - -Optional<char> CXFA_Node::GetBarcodeAttribute_EndChar() { - Optional<WideString> wsStartEndChar = - GetUIChildNode()->JSObject()->TryCData(XFA_Attribute::EndChar, true); - if (!wsStartEndChar || wsStartEndChar->IsEmpty()) - return {}; - - return {static_cast<char>((*wsStartEndChar)[0])}; -} - -Optional<int32_t> CXFA_Node::GetBarcodeAttribute_ECLevel() { - Optional<WideString> wsECLevel = GetUIChildNode()->JSObject()->TryCData( - XFA_Attribute::ErrorCorrectionLevel, true); - if (!wsECLevel) - return {}; - return {FXSYS_wtoi(wsECLevel->c_str())}; -} - -Optional<int32_t> CXFA_Node::GetBarcodeAttribute_ModuleWidth() { - Optional<CXFA_Measurement> moduleWidthHeight = - GetUIChildNode()->JSObject()->TryMeasure(XFA_Attribute::ModuleWidth, - true); - if (!moduleWidthHeight) - return {}; - - return {static_cast<int32_t>(moduleWidthHeight->ToUnit(XFA_Unit::Pt))}; -} - -Optional<int32_t> CXFA_Node::GetBarcodeAttribute_ModuleHeight() { - Optional<CXFA_Measurement> moduleWidthHeight = - GetUIChildNode()->JSObject()->TryMeasure(XFA_Attribute::ModuleHeight, - true); - if (!moduleWidthHeight) - return {}; - - return {static_cast<int32_t>(moduleWidthHeight->ToUnit(XFA_Unit::Pt))}; -} - -Optional<bool> CXFA_Node::GetBarcodeAttribute_PrintChecksum() { - return GetUIChildNode()->JSObject()->TryBoolean( - XFA_Attribute::PrintCheckDigit, true); -} - -Optional<BC_TEXT_LOC> CXFA_Node::GetBarcodeAttribute_TextLocation() { - Optional<XFA_AttributeEnum> textLocation = - GetUIChildNode()->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<bool> CXFA_Node::GetBarcodeAttribute_Truncate() { - return GetUIChildNode()->JSObject()->TryBoolean(XFA_Attribute::Truncate, - true); -} - -Optional<int8_t> CXFA_Node::GetBarcodeAttribute_WideNarrowRatio() { - Optional<WideString> wsWideNarrowRatio = - GetUIChildNode()->JSObject()->TryCData(XFA_Attribute::WideNarrowRatio, - true); - if (!wsWideNarrowRatio) - return {}; - - Optional<size_t> ptPos = wsWideNarrowRatio->Find(':'); - if (!ptPos) - return {static_cast<int8_t>(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<float>(fA) / static_cast<float>(fB); - return {static_cast<int8_t>(result)}; -} - std::pair<XFA_FFWidgetType, CXFA_Ui*> CXFA_Node::CreateChildUIAndValueNodesIfNeeded() { XFA_Element eType = GetElementType(); diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h index ae7f4bae99..99b035dfc7 100644 --- a/xfa/fxfa/parser/cxfa_node.h +++ b/xfa/fxfa/parser/cxfa_node.h @@ -299,21 +299,6 @@ 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<BC_CHAR_ENCODING> GetBarcodeAttribute_CharEncoding(); - Optional<bool> GetBarcodeAttribute_Checksum(); - Optional<int32_t> GetBarcodeAttribute_DataLength(); - Optional<char> GetBarcodeAttribute_StartChar(); - Optional<char> GetBarcodeAttribute_EndChar(); - Optional<int32_t> GetBarcodeAttribute_ECLevel(); - Optional<int32_t> GetBarcodeAttribute_ModuleWidth(); - Optional<int32_t> GetBarcodeAttribute_ModuleHeight(); - Optional<bool> GetBarcodeAttribute_PrintChecksum(); - Optional<BC_TEXT_LOC> GetBarcodeAttribute_TextLocation(); - Optional<bool> GetBarcodeAttribute_Truncate(); - Optional<int8_t> GetBarcodeAttribute_WideNarrowRatio(); - CXFA_Node* GetUIChildNode(); XFA_FFWidgetType GetFFWidgetType(); |