From 9647614a5dcd00d50aacf4e000fd23a5ebb13931 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 3 Jan 2018 11:25:05 -0500 Subject: Fold CXFA_OccurData into CXFA_Occur This CL folds the CXFA_OccurData wrapper into CXFA_Occur. Change-Id: I52e237e4f6b76f6915c397e924037562fd9eda6a Reviewed-on: https://pdfium-review.googlesource.com/22130 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- xfa/fxfa/parser/cxfa_occur.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'xfa/fxfa/parser/cxfa_occur.cpp') diff --git a/xfa/fxfa/parser/cxfa_occur.cpp b/xfa/fxfa/parser/cxfa_occur.cpp index 82424d6d6d..441394c567 100644 --- a/xfa/fxfa/parser/cxfa_occur.cpp +++ b/xfa/fxfa/parser/cxfa_occur.cpp @@ -38,3 +38,46 @@ CXFA_Occur::CXFA_Occur(CXFA_Document* doc, XFA_PacketType packet) pdfium::MakeUnique(this)) {} CXFA_Occur::~CXFA_Occur() {} + +int32_t CXFA_Occur::GetMax() { + pdfium::Optional max = + JSObject()->TryInteger(XFA_Attribute::Max, true); + return max ? *max : GetMin(); +} + +int32_t CXFA_Occur::GetMin() { + pdfium::Optional min = + JSObject()->TryInteger(XFA_Attribute::Min, true); + return min && *min >= 0 ? *min : 1; +} + +std::tuple CXFA_Occur::GetOccurInfo() { + int32_t iMin = GetMin(); + int32_t iMax = GetMax(); + + pdfium::Optional init = + JSObject()->TryInteger(XFA_Attribute::Initial, false); + return {iMin, iMax, init && *init >= iMin ? *init : iMin}; +} + +void CXFA_Occur::SetMax(int32_t iMax) { + iMax = (iMax != -1 && iMax < 1) ? 1 : iMax; + JSObject()->SetInteger(XFA_Attribute::Max, iMax, false); + + int32_t iMin = GetMin(); + if (iMax != -1 && iMax < iMin) { + iMin = iMax; + JSObject()->SetInteger(XFA_Attribute::Min, iMin, false); + } +} + +void CXFA_Occur::SetMin(int32_t iMin) { + iMin = (iMin < 0) ? 1 : iMin; + JSObject()->SetInteger(XFA_Attribute::Min, iMin, false); + + int32_t iMax = GetMax(); + if (iMax > 0 && iMax < iMin) { + iMax = iMin; + JSObject()->SetInteger(XFA_Attribute::Max, iMax, false); + } +} -- cgit v1.2.3