summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-01-09 10:47:23 -0500
committerChromium commit bot <commit-bot@chromium.org>2018-01-09 17:58:39 +0000
commitef55c79650768a731c22038acd36b2a741706ed6 (patch)
tree496a6f9a063e950006d43d91c774a2e364791a4a /xfa/fxfa/parser
parent95bb9748c9292d282e2425d4500f15f5c48c2b34 (diff)
downloadpdfium-ef55c79650768a731c22038acd36b2a741706ed6.tar.xz
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 <rharrison@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp156
-rw-r--r--xfa/fxfa/parser/cxfa_node.h16
2 files changed, 172 insertions, 0 deletions
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<int32_t, bool> 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<BC_CHAR_ENCODING> CXFA_Node::GetBarcodeAttribute_CharEncoding() {
+ Optional<WideString> 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<bool> CXFA_Node::GetBarcodeAttribute_Checksum() {
+ Optional<XFA_AttributeEnum> 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<int32_t> CXFA_Node::GetBarcodeAttribute_DataLength() {
+ Optional<WideString> wsDataLength =
+ GetWidgetAcc()->GetUIChild()->JSObject()->TryCData(
+ XFA_Attribute::DataLength, true);
+ if (!wsDataLength)
+ return {};
+
+ return {FXSYS_wtoi(wsDataLength->c_str())};
+}
+
+Optional<char> CXFA_Node::GetBarcodeAttribute_StartChar() {
+ Optional<WideString> wsStartEndChar =
+ GetWidgetAcc()->GetUIChild()->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 =
+ GetWidgetAcc()->GetUIChild()->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 =
+ GetWidgetAcc()->GetUIChild()->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 =
+ GetWidgetAcc()->GetUIChild()->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 =
+ GetWidgetAcc()->GetUIChild()->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 GetWidgetAcc()->GetUIChild()->JSObject()->TryBoolean(
+ XFA_Attribute::PrintCheckDigit, true);
+}
+
+Optional<BC_TEXT_LOC> CXFA_Node::GetBarcodeAttribute_TextLocation() {
+ Optional<XFA_AttributeEnum> 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<bool> CXFA_Node::GetBarcodeAttribute_Truncate() {
+ return GetWidgetAcc()->GetUIChild()->JSObject()->TryBoolean(
+ XFA_Attribute::Truncate, true);
+}
+
+Optional<int8_t> CXFA_Node::GetBarcodeAttribute_WideNarrowRatio() {
+ Optional<WideString> wsWideNarrowRatio =
+ GetWidgetAcc()->GetUIChild()->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_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<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();
+
protected:
CXFA_Node(CXFA_Document* pDoc,
XFA_PacketType ePacket,