diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2018-01-03 11:25:05 -0500 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-01-03 18:16:30 +0000 |
commit | 9647614a5dcd00d50aacf4e000fd23a5ebb13931 (patch) | |
tree | 2b05d094e17bde6a1464e92850dd67ef50e949f6 /xfa/fxfa/parser/cxfa_occur.cpp | |
parent | cbd4410908e2a4898fdd5e0d6d17591fc2c71f54 (diff) | |
download | pdfium-9647614a5dcd00d50aacf4e000fd23a5ebb13931.tar.xz |
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 <rharrison@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser/cxfa_occur.cpp')
-rw-r--r-- | xfa/fxfa/parser/cxfa_occur.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
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<CJX_Occur>(this)) {} CXFA_Occur::~CXFA_Occur() {} + +int32_t CXFA_Occur::GetMax() { + pdfium::Optional<int32_t> max = + JSObject()->TryInteger(XFA_Attribute::Max, true); + return max ? *max : GetMin(); +} + +int32_t CXFA_Occur::GetMin() { + pdfium::Optional<int32_t> min = + JSObject()->TryInteger(XFA_Attribute::Min, true); + return min && *min >= 0 ? *min : 1; +} + +std::tuple<int32_t, int32_t, int32_t> CXFA_Occur::GetOccurInfo() { + int32_t iMin = GetMin(); + int32_t iMax = GetMax(); + + pdfium::Optional<int32_t> 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); + } +} |